Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

[BUG & PATCH] USR2 traps aren't reset in subshells



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

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: bug.zsh
Description: Binary data



Messages sorted by: Reverse Date, Date, Thread, Author