* [BUG & PATCH] USR2 traps aren't reset in subshells
@ 2024-07-26 20:42 Philippe Altherr
0 siblings, 0 replies; only message in thread
From: Philippe Altherr @ 2024-07-26 20:42 UTC (permalink / raw)
To: Zsh hackers list
[-- Attachment #1.1: Type: text/plain, Size: 768 bytes --]
The documentation states that traps defined for signals are reset in
subshells. This doesn't happen for the signal USR2. I couldn't find an
exception for USR2 neither in the documentation nor in the source code. It
looks like the discrepancy is due to an off by one error, see the proposed
patch.
Here is the script used to exhibit the bug:
bug.zsh:
> #!/bin/zsh
zmodload zsh/system;
> trap "echo Caught $1" $1;
> kill -$1 $sysparams[pid];
> echo Still alive;
> (
> kill -$1 $sysparams[pid];
> echo Should NOT be reached;
> )
And here is a run log that exhibits the bug:
% ./bug.zsh HUP
> Caught HUP
> Still alive
> % ./bug.zsh USR1
> Caught USR1
> Still alive
> % ./bug.zsh USR2
> Caught USR2
> Still alive
> Caught USR2
> Should NOT be reached
Philippe
[-- Attachment #1.2: Type: text/html, Size: 1438 bytes --]
[-- Attachment #2: fix-off-by-one-error-that-misses-usr2.txt --]
[-- Type: text/plain, Size: 808 bytes --]
diff --git a/Src/exec.c b/Src/exec.c
index 097e0b368..00278ac50 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -1089,7 +1089,7 @@ entersubsh(int flags, struct entersubsh_ret *retp)
int i, sig, monitor, job_control_ok;
if (!(flags & ESUB_KEEPTRAP))
- for (sig = 0; sig < SIGCOUNT; sig++)
+ for (sig = 0; sig <= SIGCOUNT; sig++)
if (!(sigtrapped[sig] & ZSIG_FUNC) &&
!(isset(POSIXTRAPS) && (sigtrapped[sig] & ZSIG_IGNORED)))
unsettrap(sig);
@@ -1203,7 +1203,7 @@ entersubsh(int flags, struct entersubsh_ret *retp)
* Start loop at 1 because 0 is SIGEXIT
*/
if (intrap)
- for (sig = 1; sig < SIGCOUNT; sig++)
+ for (sig = 1; sig <= SIGCOUNT; sig++)
if (sigtrapped[sig] && sigtrapped[sig] != ZSIG_IGNORED)
signal_unblock(signal_mask(sig));
if (!job_control_ok)
[-- Attachment #3: bug.zsh --]
[-- Type: application/octet-stream, Size: 164 bytes --]
#!/bin/zsh
zmodload zsh/system;
trap "echo Caught $1" $1;
kill -$1 $sysparams[pid];
echo Still alive;
(
kill -$1 $sysparams[pid];
echo Should NOT be reached;
)
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2024-07-26 20:43 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-26 20:42 [BUG & PATCH] USR2 traps aren't reset in subshells Philippe Altherr
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).