Message ID | 20240308110158.2459219-1-aclopte@gmail.com (mailing list archive) |
---|---|
State | Superseded |
Delegated to: | Herbert Xu |
Headers | show |
Series | [RFC] Allow trap to override permanently-ignored signals in background shells | expand |
Hi, On 08/03/2024 11:01, Johannes Altmanninger wrote: > TL;DR: I think this job should exit on Control-C. > > ( trap - INT; sleep inf ) & The TL;DR is oversimplified: Control-C would not result in SIGINT being sent to the sleep command, because it runs in the background. Your fuller version, I agree, I think that is a bug in dash. There are some more known bugs in its handling of the trap command in subshells that require a bigger rework (particularly the one where, despite traps being reset in subshells, the 'trap' command should print the parent shell's traps if called in a subshell) that maybe should be looked at at the same time. > In general, I wonder if SIGINT is only for actual shells, and SIGTERM > is the signal to use in our situation. SIGINT is not limited to shells. At first glance, sending SIGINT to another process or process group upon receipt of SIGINT, because that other process or process group is what it was intended for, seems like an appropriate use to me. Cheers, Harald van Dijk
diff --git a/src/trap.c b/src/trap.c index cd84814..a6778e8 100644 --- a/src/trap.c +++ b/src/trap.c @@ -159,7 +159,7 @@ trapcmd(int argc, char **argv) } trap[signo] = action; if (signo != 0) - setsignal(signo); + setsignal_maybe_user(signo, 1); INTON; ap++; } @@ -175,6 +175,12 @@ trapcmd(int argc, char **argv) void setsignal(int signo) +{ + setsignal_maybe_user(signo, 0); +} + +void +setsignal_maybe_user(int signo, int user) { int action; int lvforked; @@ -234,7 +240,7 @@ setsignal(int signo) } if (act.sa_handler == SIG_IGN) { if (mflag && (signo == SIGTSTP || - signo == SIGTTIN || signo == SIGTTOU)) { + signo == SIGTTIN || signo == SIGTTOU)) { tsig = S_IGN; /* don't hard ignore these */ } else tsig = S_HARD_IGN; @@ -242,7 +248,7 @@ setsignal(int signo) tsig = S_RESET; /* force to be set */ } } - if (tsig == S_HARD_IGN || tsig == action) + if ((!user && tsig == S_HARD_IGN) || tsig == action) return; switch (action) { case S_CATCH: diff --git a/src/trap.h b/src/trap.h index beaf660..595992c 100644 --- a/src/trap.h +++ b/src/trap.h @@ -43,6 +43,7 @@ extern volatile sig_atomic_t gotsigchld; int trapcmd(int, char **); void setsignal(int); +void setsignal_maybe_user(int, int); void ignoresig(int); void onsig(int); void dotrap(void);