From 2c8ac78cbb5a8556221b05e0031c50b629ee2696 Mon Sep 17 00:00:00 2001 From: Chet Ramey Date: Thu, 21 Oct 2021 16:02:37 -0400 Subject: [PATCH] minor documentation update on SIGINT handling --- CWRU/CWRU.chlog | 14 +++++++++++ doc/bash.1 | 63 ++++++++++++++++++++++++++++++++++++++++++++-- doc/bashref.texi | 31 +++++++++++++++++++++++ doc/version.texi | 4 +-- subst.c | 6 ++++- tests/RUN-ONE-TEST | 2 +- 6 files changed, 114 insertions(+), 6 deletions(-) diff --git a/CWRU/CWRU.chlog b/CWRU/CWRU.chlog index 139e3e5b..83323392 100644 --- a/CWRU/CWRU.chlog +++ b/CWRU/CWRU.chlog @@ -2310,3 +2310,17 @@ doc/bashref.texi doc/{mkposix,mkinst,mkrbash},doc/Makefile.in - changes to allow scripts to be run outside the source directory + + 10/18 + ----- +subst.c + - patsub_replacement: controls whether pattern substitution expands `&' + in the replacement string. Initialized to 1 by default + + 10/19 + ----- +doc/{bash.1,bashref.texi} + - document bash's WCE SIGINT behavior when job control is not enabled + and the shell receives a SIGINT while waiting for the foreground + command to complete. Added at Red Hat's request. A complete + discussion is at https://www.cons.org/cracauer/sigint.html diff --git a/doc/bash.1 b/doc/bash.1 index 7f226c05..537337d2 100644 --- a/doc/bash.1 +++ b/doc/bash.1 @@ -5,12 +5,12 @@ .\" Case Western Reserve University .\" chet.ramey@case.edu .\" -.\" Last Change: Fri Oct 8 14:10:30 EDT 2021 +.\" Last Change: Tue Oct 19 11:34:57 EDT 2021 .\" .\" bash_builtins, strip all but Built-Ins section .if \n(zZ=1 .ig zZ .if \n(zY=1 .ig zY -.TH BASH 1 "2021 October 8" "GNU Bash 5.1" +.TH BASH 1 "2021 October 19" "GNU Bash 5.1" .\" .\" There's some problem with having a `@' .\" in a tagged paragraph with the BSD man macros. @@ -5214,6 +5214,63 @@ When \fBbash\fP is waiting for an asynchronous command via the \fBwait\fP builtin, the reception of a signal for which a trap has been set will cause the \fBwait\fP builtin to return immediately with an exit status greater than 128, immediately after which the trap is executed. +.PP +When job control is not enabled, and \fBbash\fP is waiting for a foreground +command to complete, the shell receives keyboard-generated signals +such as +.SM +.B SIGINT +(usually generated by \fB^C\fP) that users commonly intend to send +to that command. +This happens because the shell and the command are in the +same process group as the terminal, and \fB^C\fP sends +.SM +.B SIGINT +to all processes in that process group. +.PP +When \fBbash\fP is running without job control enabled and receives +.SM +.B SIGINT +while waiting for a foreground command, it waits until that foreground +command terminates and then decides what to do about the +.SM +.BR SIGINT : +.IP 1. +If the command terminates due to the +.SM +.BR SIGINT , +\fBbash\fP concludes +that the user meant to end the entire script, and acts on the +.SM +.B SIGINT +(e.g., by running a +.SM +.B SIGINT +trap or exiting itself); +.IP 2. +If the command does not terminate due to +.SM +.BR SIGINT , +the program handled the +.SM +.B SIGINT +itself and did not treat it as a fatal signal. +In that case, \fBbash\fP does not treat +.SM +.B SIGINT +as a fatal signal, either, instead assuming that the +.SM +.B SIGINT +was used as part of the program's normal operation +(e.g., emacs uses it to abort editing +commands) or deliberately discarded. +However, \fBbash\fP will run any +trap set on +.SM +.BR SIGINT , +as it does with any other trapped signal it +receives while it is waiting for the foreground command to +complete, for compatibility. .SH "JOB CONTROL" .I Job control refers to the ability to selectively stop (\fIsuspend\fP) @@ -10131,6 +10188,8 @@ history is enabled, as described above under .B compat43 .TP 8 .B compat44 +.TP 8 +.B compat50 .PD These control aspects of the shell's compatibility mode (see diff --git a/doc/bashref.texi b/doc/bashref.texi index 33a35147..eff82cee 100644 --- a/doc/bashref.texi +++ b/doc/bashref.texi @@ -3549,6 +3549,37 @@ which a trap has been set will cause the @code{wait} builtin to return immediately with an exit status greater than 128, immediately after which the trap is executed. +When job control is not enabled, and Bash is waiting for a foreground +command to complete, the shell receives keyboard-generated signals +such as @code{SIGINT} (usually generated by @samp{^C}) that users +commonly intend to send to that command. +This happens because the shell and the command are in the same process +group as the terminal, and @samp{^C} sends @code{SIGINT} to all processes +in that process group. +See @ref{Job Control}, for a more in-depth discussion of process groups. + +When Bash is running without job control enabled and receives @code{SIGINT} +while waiting for a foreground command, it waits until that foreground +command terminates and then decides what to do about the @code{SIGINT}: + +@enumerate +@item +If the command terminates due to the @code{SIGINT}, Bash concludes +that the user meant to end the entire script, and acts on the +@code{SIGINT} (e.g., by running a @code{SIGINT} trap or exiting itself); + +@item +If the pipeline does not terminate due to @code{SIGINT}, the program +handled the @code{SIGINT} itself and did not treat it as a fatal signal. +In that case, Bash does not treat @code{SIGINT} as a fatal signal, +either, instead assuming that the @code{SIGINT} was used as part of the +program's normal operation (e.g., @command{emacs} uses it to abort editing +commands) or deliberately discarded. However, Bash will run any +trap set on @code{SIGINT}, as it does with any other trapped signal it +receives while it is waiting for the foreground command to +complete, for compatibility. +@end enumerate + @node Shell Scripts @section Shell Scripts @cindex shell script diff --git a/doc/version.texi b/doc/version.texi index dfa59e54..c65f9885 100644 --- a/doc/version.texi +++ b/doc/version.texi @@ -2,10 +2,10 @@ Copyright (C) 1988-2021 Free Software Foundation, Inc. @end ignore -@set LASTCHANGE Fri Oct 15 15:24:19 EDT 2021 +@set LASTCHANGE Tue Oct 19 11:34:34 EDT 2021 @set EDITION 5.1 @set VERSION 5.1 -@set UPDATED 15 October 2021 +@set UPDATED 19 October 2021 @set UPDATED-MONTH October 2021 diff --git a/subst.c b/subst.c index 052c7991..c5855f3b 100644 --- a/subst.c +++ b/subst.c @@ -187,6 +187,10 @@ int allow_null_glob_expansion; /* Non-zero means to throw an error when globbing fails to match anything. */ int fail_glob_expansion; +/* If non-zero, perform `&' substitution on the replacement string in the + pattern substitution word expansion. */ +int patsub_replacement = 1; + /* Extern functions and variables from different files. */ extern struct fd_bitmap *current_fds_to_close; extern int wordexp_only; @@ -8680,7 +8684,7 @@ parameter_brace_patsub (varname, value, ind, patsub, quoted, pflags, flags) consistently. The replacement string already undergoes quote removal above, so users need to make sure any desired backslash makes it through that. */ - if (rep && *rep && shouldexp_replacement (rep)) + if (patsub_replacement && rep && *rep && shouldexp_replacement (rep)) mflags |= MATCH_EXPREP; } 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