]> git.ipfire.org Git - ipfire-3.x.git/blob - bash/patches/bash-5.0-patch-5.patch
git: Update to 2.23.0
[ipfire-3.x.git] / bash / patches / bash-5.0-patch-5.patch
1 From 41f5420db7a911fb0833be693205f4db41f05434 Mon Sep 17 00:00:00 2001
2 From: Chet Ramey <chet.ramey@case.edu>
3 Date: Sat, 20 Apr 2019 14:25:52 -0400
4 Subject: [PATCH] Bash-5.0 patch 5: prevent optimizing forks away too
5 aggressively
6
7 ---
8 builtins/evalstring.c | 26 +++++++++++++++++++++++---
9 command.h | 1 +
10 execute_cmd.c | 2 ++
11 patchlevel.h | 2 +-
12 4 files changed, 27 insertions(+), 4 deletions(-)
13
14 diff --git a/builtins/evalstring.c b/builtins/evalstring.c
15 index 1496eeec..cadc9bc0 100644
16 --- a/builtins/evalstring.c
17 +++ b/builtins/evalstring.c
18 @@ -100,12 +100,22 @@ should_suppress_fork (command)
19 ((command->flags & CMD_INVERT_RETURN) == 0));
20 }
21
22 +int
23 +can_optimize_connection (command)
24 + COMMAND *command;
25 +{
26 + return (*bash_input.location.string == '\0' &&
27 + (command->value.Connection->connector == AND_AND || command->value.Connection->connector == OR_OR || command->value.Connection->connector == ';') &&
28 + command->value.Connection->second->type == cm_simple);
29 +}
30 +
31 void
32 optimize_fork (command)
33 COMMAND *command;
34 {
35 if (command->type == cm_connection &&
36 - (command->value.Connection->connector == AND_AND || command->value.Connection->connector == OR_OR) &&
37 + (command->value.Connection->connector == AND_AND || command->value.Connection->connector == OR_OR || command->value.Connection->connector == ';') &&
38 + (command->value.Connection->second->flags & CMD_TRY_OPTIMIZING) &&
39 should_suppress_fork (command->value.Connection->second))
40 {
41 command->value.Connection->second->flags |= CMD_NO_FORK;
42 @@ -412,8 +422,18 @@ parse_and_execute (string, from_file, flags)
43 command->flags |= CMD_NO_FORK;
44 command->value.Simple->flags |= CMD_NO_FORK;
45 }
46 - else if (command->type == cm_connection)
47 - optimize_fork (command);
48 +
49 + /* Can't optimize forks out here execept for simple commands.
50 + This knows that the parser sets up commands as left-side heavy
51 + (&& and || are left-associative) and after the single parse,
52 + if we are at the end of the command string, the last in a
53 + series of connection commands is
54 + command->value.Connection->second. */
55 + else if (command->type == cm_connection && can_optimize_connection (command))
56 + {
57 + command->value.Connection->second->flags |= CMD_TRY_OPTIMIZING;
58 + command->value.Connection->second->value.Simple->flags |= CMD_TRY_OPTIMIZING;
59 + }
60 #endif /* ONESHOT */
61
62 /* See if this is a candidate for $( <file ). */
63 diff --git a/command.h b/command.h
64 index 32495162..b9e9b669 100644
65 --- a/command.h
66 +++ b/command.h
67 @@ -186,6 +186,7 @@ typedef struct element {
68 #define CMD_COPROC_SUBSHELL 0x1000
69 #define CMD_LASTPIPE 0x2000
70 #define CMD_STDPATH 0x4000 /* use standard path for command lookup */
71 +#define CMD_TRY_OPTIMIZING 0x8000 /* try to optimize this simple command */
72
73 /* What a command looks like. */
74 typedef struct command {
75 diff --git a/execute_cmd.c b/execute_cmd.c
76 index 8b3c83aa..f1d74bfe 100644
77 --- a/execute_cmd.c
78 +++ b/execute_cmd.c
79 @@ -2767,6 +2767,8 @@ execute_connection (command, asynchronous, pipe_in, pipe_out, fds_to_close)
80 ((command->value.Connection->connector == OR_OR) &&
81 (exec_result != EXECUTION_SUCCESS)))
82 {
83 + optimize_fork (command);
84 +
85 second = command->value.Connection->second;
86 if (ignore_return && second)
87 second->flags |= CMD_IGNORE_RETURN;
88 diff --git a/patchlevel.h b/patchlevel.h
89 index c059f0bd..1bc098b8 100644
90 --- a/patchlevel.h
91 +++ b/patchlevel.h
92 @@ -25,6 +25,6 @@
93 regexp `^#define[ ]*PATCHLEVEL', since that's what support/mkversion.sh
94 looks for to find the patch level (for the sccs version string). */
95
96 -#define PATCHLEVEL 4
97 +#define PATCHLEVEL 5
98
99 #endif /* _PATCHLEVEL_H_ */
100 --
101 2.17.2
102