fix for too-aggressive optimizing forks away in an `eval' command inside a (command) subshell

This commit is contained in:
Chet Ramey
2022-11-21 11:43:19 -05:00
parent 407d9afca0
commit 94d25f57f1
10 changed files with 52 additions and 20 deletions
+29
View File
@@ -4466,3 +4466,32 @@ lib/glob/sm_loop.c
Updates from Koichi Murase <myoga.murase@gmail.com>
- BRACKMATCH: if a range expression is incomplete (no end char),
treat the bracket as an ordinary character
11/18
-----
doc/bashref.texi
- Reporting Bugs: add mention of the Savannah project page. Suggested
by Loïc Yhuel <loic.yhuel@gmail.com>
11/20
-----
builtins/common.h
- SEVAL_NOOPTIMIZE: new flag for parse_and_execute: means don't try to
optimize forks out of any simple or conditional commands
builtins/evalstring.c
- parse_and_execute: if FLAGS includes SEVAL_NOOPTIMIZE, don't try to
call can_optimize_connection to optimize away forks from AND_AND or
OR_OR commands
builtins/eval.def,trap.c,parse.y,jobs.c
- parse_and_execute: include SEVAL_NOOPTIMIZE in any calls to
parse_and_execute. Fixes bug reported by
Frode Nordahl <frode.nordahl@canonical.com>
11/21
-----
lib/readline/readline.c
- readline_initialize_everything: use xmalloc to initialize
rl_executing_keyseq, since we use xrealloc to reallocate it and
don't check it for NULL anywhere
+1
View File
@@ -51,6 +51,7 @@ do { \
#define SEVAL_FUNCDEF 0x080 /* only allow function definitions */
#define SEVAL_ONECMD 0x100 /* only allow a single command */
#define SEVAL_NOHISTEXP 0x200 /* inhibit history expansion */
#define SEVAL_NOOPTIMIZE 0x400 /* don't try to set optimization flags */
/* Flags for describe_command, shared between type.def and command.def */
#define CDESC_ALL 0x001 /* type -a */
+1 -1
View File
@@ -53,5 +53,5 @@ eval_builtin (list)
return (EX_USAGE);
list = loptend; /* skip over possible `--' */
return (list ? evalstring (string_list (list), "eval", SEVAL_NOHIST) : EXECUTION_SUCCESS);
return (list ? evalstring (string_list (list), "eval", SEVAL_NOHIST|SEVAL_NOOPTIMIZE) : EXECUTION_SUCCESS);
}
+6 -3
View File
@@ -132,8 +132,8 @@ optimize_connection_fork (command)
if (command->type == cm_connection &&
(command->value.Connection->connector == AND_AND || command->value.Connection->connector == OR_OR || command->value.Connection->connector == ';') &&
(command->value.Connection->second->flags & CMD_TRY_OPTIMIZING) &&
((startup_state == 2 && should_suppress_fork (command->value.Connection->second)) ||
((subshell_environment & SUBSHELL_PAREN) && should_optimize_fork (command->value.Connection->second, 0))))
(should_suppress_fork (command->value.Connection->second) ||
((subshell_environment & SUBSHELL_PAREN) && should_optimize_fork (command->value.Connection->second, 0))))
{
command->value.Connection->second->flags |= CMD_NO_FORK;
command->value.Connection->second->value.Simple->flags |= CMD_NO_FORK;
@@ -290,6 +290,7 @@ parse_prologue (string, flags, tag)
(flags & SEVAL_NOFREE) -> don't free STRING when finished
(flags & SEVAL_RESETLINE) -> reset line_number to 1
(flags & SEVAL_NOHISTEXP) -> history_expansion_inhibited -> 1
(flags & SEVAL_NOOPTIMIZE) -> don't try to turn on optimizing flags
*/
int
@@ -502,7 +503,9 @@ parse_and_execute (string, from_file, flags)
if we are at the end of the command string, the last in a
series of connection commands is
command->value.Connection->second. */
else if (command->type == cm_connection && can_optimize_connection (command))
else if (command->type == cm_connection &&
(flags & SEVAL_NOOPTIMIZE) == 0 &&
can_optimize_connection (command))
{
command->value.Connection->second->flags |= CMD_TRY_OPTIMIZING;
command->value.Connection->second->value.Simple->flags |= CMD_TRY_OPTIMIZING;
+5 -5
View File
@@ -2163,7 +2163,7 @@ introduce indirection.
In each of the cases below, @var{word} is subject to tilde expansion,
parameter expansion, command substitution, and arithmetic expansion.
When not performing substring expansion, using the form described
When not performing substring expansion, using the forms described
below (e.g., @samp{:-}), Bash tests for a parameter that is unset or null.
Omitting the colon results in a test only for a parameter that is unset.
Put another way, if the colon is included,
@@ -9592,11 +9592,11 @@ The latest version of Bash is always available for FTP from
@uref{http://git.savannah.gnu.org/cgit/bash.git/snapshot/bash-master.tar.gz}.
Once you have determined that a bug actually exists, use the
@code{bashbug} command to submit a bug report.
If you have a fix, you are encouraged to mail that as well!
@code{bashbug} command to submit a bug report or use the form at the
<a href="https://savannah.gnu.org/projects/bash/">Bash project page</a>.
If you have a fix, you are encouraged to submit that as well!
Suggestions and `philosophical' bug reports may be mailed
to @email{bug-bash@@gnu.org} or posted to the Usenet
newsgroup @code{gnu.bash.bug}.
to @email{bug-bash@@gnu.org} or @email{help-bash@gnu.org}.
All bug reports should include:
@itemize @bullet
+3 -3
View File
@@ -2,10 +2,10 @@
Copyright (C) 1988-2022 Free Software Foundation, Inc.
@end ignore
@set LASTCHANGE Mon Sep 19 11:13:51 EDT 2022
@set LASTCHANGE Fri Nov 18 11:09:41 EST 2022
@set EDITION 5.2
@set VERSION 5.2
@set UPDATED 19 September 2022
@set UPDATED-MONTH September 2022
@set UPDATED 18 November 2022
@set UPDATED-MONTH November 2022
+1 -1
View File
@@ -4242,7 +4242,7 @@ run_sigchld_trap (nchild)
jobs_list_frozen = 1;
for (i = 0; i < nchild; i++)
{
parse_and_execute (savestring (trap_command), "trap", SEVAL_NOHIST|SEVAL_RESETLINE);
parse_and_execute (savestring (trap_command), "trap", SEVAL_NOHIST|SEVAL_RESETLINE|SEVAL_NOOPTIMIZE);
}
run_unwind_frame ("SIGCHLD trap");
+2 -3
View File
@@ -1327,9 +1327,8 @@ readline_initialize_everything (void)
_rl_parse_colors ();
#endif
rl_executing_keyseq = malloc (_rl_executing_keyseq_size = 16);
if (rl_executing_keyseq)
rl_executing_keyseq[rl_key_sequence_length = 0] = '\0';
rl_executing_keyseq = xmalloc (_rl_executing_keyseq_size = 16);
rl_executing_keyseq[rl_key_sequence_length = 0] = '\0';
}
/* If this system allows us to look at the values of the regular
+1 -1
View File
@@ -2843,7 +2843,7 @@ execute_variable_command (command, vname)
if (last_lastarg)
last_lastarg = savestring (last_lastarg);
parse_and_execute (savestring (command), vname, SEVAL_NONINT|SEVAL_NOHIST);
parse_and_execute (savestring (command), vname, SEVAL_NONINT|SEVAL_NOHIST|SEVAL_NOOPTIMIZE);
restore_parser_state (&ps);
bind_variable ("_", last_lastarg, 0);
+3 -3
View File
@@ -453,7 +453,7 @@ run_pending_traps ()
if (function_code == 0)
/* XXX is x always last_command_exit_value? */
x = parse_and_execute (trap_command, "trap", SEVAL_NONINT|SEVAL_NOHIST|SEVAL_RESETLINE);
x = parse_and_execute (trap_command, "trap", SEVAL_NONINT|SEVAL_NOHIST|SEVAL_RESETLINE|SEVAL_NOOPTIMIZE);
else
{
parse_and_execute_cleanup (sig + 1); /* XXX - could use -1 */
@@ -1017,7 +1017,7 @@ run_exit_trap ()
if (code == 0 && function_code == 0)
{
reset_parser ();
parse_and_execute (trap_command, "exit trap", SEVAL_NONINT|SEVAL_NOHIST|SEVAL_RESETLINE);
parse_and_execute (trap_command, "exit trap", SEVAL_NONINT|SEVAL_NOHIST|SEVAL_RESETLINE|SEVAL_NOOPTIMIZE);
}
else if (code == ERREXIT)
retval = last_command_exit_value;
@@ -1130,7 +1130,7 @@ _run_trap_internal (sig, tag)
function_code = setjmp_nosigs (return_catch);
}
flags = SEVAL_NONINT|SEVAL_NOHIST;
flags = SEVAL_NONINT|SEVAL_NOHIST|SEVAL_NOOPTIMIZE;
if (sig != DEBUG_TRAP && sig != RETURN_TRAP && sig != ERROR_TRAP)
flags |= SEVAL_RESETLINE;
if (function_code == 0)