On Fri, Mar 29, 2024 at 12:24:00PM +0100, Johannes Altmanninger wrote: > Unlike in Bash or Zsh, this asynchronous job ignores SIGINT, despite > builtin trap explicitly resetting the SIGINT handler. > dash -c '( trap - INT; sleep inf ) &' > POSIX[*] Section 2.11 on Signals and Error Handling says about > background execution: > > If job control is disabled (see the description of set -m) when > > the shell executes an asynchronous list, the commands in the list > > shall inherit from the shell a signal action of ignored (SIG_IGN) > > for the SIGINT and SIGQUIT signals. In all other cases, commands > > executed by the shell shall inherit the same signal actions as those > > inherited by the shell from its parent unless a signal action is > > modified by the trap special built-in (see trap) > It is not clear to me from this description whether the trap builtin is > supposed to un-ignore SIGINT and SIGQUIT in the above asynchronous job. > I think yes because processes like "sh -c 'trap ...'" can already > do that, so why treat subshells differently. The Bash maintainer > seems to agree when responding to a related bug report[**] > although that one is not about subshells specifically. > > The issue is that the processes in this list have to ignore SIGINT > > [...] but they have to be allowed to use trap to change the signal > > dispositions (POSIX interp 751) > This issue exists because we "hard-ignore" (meaning ignore > permanently) SIGINT and SIGQUIT in backgrounded subshells; I'm > not sure why. Git blame is not helpful since this existed since > the initial Git import. I failed to find a test suite; no luck at > http://www.opengroup.org/testing/testsuites/vscpcts2003.htm where I > get SSL errors. > Since I don't see any reason for hard-ignore logic, remove it > altogether. This means that either of > trap - INT; trap - QUIT > set -i > in a backgrounded subshell will now un-ignore SIGINT and SIGQUIT. > I did not find other behavior changes but maybe there is a good reason > for S_HARD_IGN? > [*]: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html > [**]: https://lists.gnu.org/archive/html/bug-bash/2023-01/msg00050.html There is definitely a good reason for S_HARD_IGN: it implements the following requirement of the trap builtin (XCU 2.14 Special Built-In Utilities -> trap): ] Signals that were ignored on entry to a non-interactive shell cannot ] be trapped or reset, although no error need be reported when ] attempting to do so. An interactive shell may reset or catch signals ] ignored on entry. The change that should be made is that the automatic ignore of SIGINT and SIGQUIT in background subshells should not use hard ignore. Hard ignore still applies if the shell inherits ignored signals from its parent. -- Jilles Tjoelker