From 75c5460c4832ac1c75d7cea4333d0838203a708b Mon Sep 17 00:00:00 2001 From: Chet Ramey Date: Mon, 19 Oct 2020 09:04:00 -0400 Subject: [PATCH] commit bash-20201012 snapshot --- CWRU/CWRU.chlog | 22 ++++++++++++++++++++++ builtins/trap.def | 2 +- sig.c | 5 +++++ subst.c | 4 ++++ tests/RUN-ONE-TEST | 2 +- tests/run-vredir | 2 ++ trap.c | 15 ++++++++++++--- trap.h | 2 ++ 8 files changed, 49 insertions(+), 5 deletions(-) diff --git a/CWRU/CWRU.chlog b/CWRU/CWRU.chlog index 4413f996..98315d2f 100644 --- a/CWRU/CWRU.chlog +++ b/CWRU/CWRU.chlog @@ -9073,3 +9073,25 @@ lib/readline/terminal.c - _rl_init_terminal_io: if the terminal name is "dumb", disable bracketed paste mode. Suggested by Andreas Schwab + + 10/13 + ----- +trap.[ch] + - set_trap_state: new function to allow other signal handlers to set + the internal state that trap_handler would set to note that the + shell received a trapped signal. Used by sigint_sighandler(). + +sig.c + - sigint_sighandler: call set_trap_state to set the pending trap state + for SIGINT if trap_handler is not called. Needed because + throw_to_top_level now checks whether a signal is pending before + running the trap (change from 4/2020) + +builtins/trap.def + - trap_builtin: if the shell is interactive (interactive_shell != 0) + but running something like PROMPT_COMMAND that sets + parse_and_execute_level > 0 but interactive == 0, make sure to set + the signal handler to the default interactive shell SIGINT handler + (sigint_sighandler) instead of the default non-interactive one. + Fixes bug reported by Daniel Farina with a hint + from felix diff --git a/builtins/trap.def b/builtins/trap.def index 4fa39aef..daeec9ea 100644 --- a/builtins/trap.def +++ b/builtins/trap.def @@ -211,7 +211,7 @@ trap_builtin (list) if (interactive) set_signal_handler (SIGINT, sigint_sighandler); /* special cases for interactive == 0 */ - else if (interactive_shell && (sourcelevel||running_trap)) + else if (interactive_shell && (sourcelevel||running_trap||parse_and_execute_level)) set_signal_handler (SIGINT, sigint_sighandler); else set_signal_handler (SIGINT, termsig_sighandler); diff --git a/sig.c b/sig.c index 44aa9939..6964d862 100644 --- a/sig.c +++ b/sig.c @@ -669,6 +669,11 @@ sigint_sighandler (sig) SIGRETURN (0); } + /* In interactive shells, we will get here instead of trap_handler() so + note that we have a trap pending. */ + if (signal_is_trapped (sig)) + set_trap_state (sig); + /* This is no longer used, but this code block remains as a reminder. */ if (interrupt_immediately) { diff --git a/subst.c b/subst.c index b217885c..915fd50b 100644 --- a/subst.c +++ b/subst.c @@ -7953,7 +7953,11 @@ parameter_brace_transform (varname, value, ind, xform, rtype, quoted, pflags, fl if (valid_parameter_transform (xform) == 0) { this_command_name = oname; +#if 0 /* TAG: bash-5.2 Martin Schulte 10/2020 */ + return (interactive_shell ? &expand_param_error : &expand_param_fatal); +#else return &expand_param_error; +#endif } starsub = vtype & VT_STARSUB; diff --git a/tests/RUN-ONE-TEST b/tests/RUN-ONE-TEST index c8bef8dd..0b063810 100755 --- a/tests/RUN-ONE-TEST +++ b/tests/RUN-ONE-TEST @@ -1,4 +1,4 @@ -BUILD_DIR=/usr/local/build/bash/bash-current +BUILD_DIR=/usr/local/build/chet/bash/bash-current THIS_SH=$BUILD_DIR/bash PATH=$PATH:$BUILD_DIR diff --git a/tests/run-vredir b/tests/run-vredir index 2a4faf30..2bdc1b83 100644 --- a/tests/run-vredir +++ b/tests/run-vredir @@ -1,2 +1,4 @@ +echo "warning: the text of a system error message may vary between systems and" >&2 +echo "warning: produce diff output." >&2 ${THIS_SH} ./vredir.tests > ${BASH_TSTOUT} 2>&1 diff ${BASH_TSTOUT} vredir.right && rm -f ${BASH_TSTOUT} diff --git a/trap.c b/trap.c index da071b35..18740848 100644 --- a/trap.c +++ b/trap.c @@ -456,6 +456,17 @@ run_pending_traps () last_command_exit_value = old_exit_value; } +/* Set the private state variables noting that we received a signal SIG + for which we have a trap set. */ +void +set_trap_state (sig) + int sig; +{ + catch_flag = 1; + pending_traps[sig]++; + trapped_signal_received = sig; +} + sighandler trap_handler (sig) int sig; @@ -484,9 +495,7 @@ trap_handler (sig) set_signal_handler (sig, trap_handler); #endif /* MUST_REINSTALL_SIGHANDLERS */ - catch_flag = 1; - pending_traps[sig]++; - trapped_signal_received = sig; + set_trap_state (sig); if (this_shell_builtin && (this_shell_builtin == wait_builtin)) { diff --git a/trap.h b/trap.h index bf2c9a1e..ef64a680 100644 --- a/trap.h +++ b/trap.h @@ -116,6 +116,8 @@ extern void set_signal_hard_ignored PARAMS((int)); extern void set_signal_ignored PARAMS((int)); extern int signal_in_progress PARAMS((int)); +extern void set_trap_state PARAMS((int)); + extern int next_pending_trap PARAMS((int)); extern int first_pending_trap PARAMS((void)); extern void clear_pending_traps PARAMS((void));