summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Stephenson <pws@zsh.org>2016-02-25 14:20:26 +0000
committerPeter Stephenson <pws@zsh.org>2016-02-25 14:20:26 +0000
commitc55d8551718bcf2fc7661c31c13e934060a5f1a7 (patch)
treeea5362983b67d3c471e54beae6495d928d81eb21
parent3195003cde3287300b75903f5266721bd04e0e31 (diff)
downloadzsh-c55d8551718bcf2fc7661c31c13e934060a5f1a7.tar.gz
zsh-c55d8551718bcf2fc7661c31c13e934060a5f1a7.zip
38024: Improve POSIX and native EXIT traps compatibility.
Allow a nested function trap to leave save and restore a POSIX trap. Still fails if the POSIX trap was defined in a function.
-rw-r--r--ChangeLog6
-rw-r--r--Src/signals.c7
-rw-r--r--Test/C03traps.ztst17
3 files changed, 29 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 2bc3631c8..5e3162f21 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2016-02-25 Peter Stephenson <p.stephenson@samsung.com>
+
+ * 38024: Src/signals.c, Test/C03traps.ztst: improve 37999 to
+ allow nested zsh-mode EXIT traps not to remove a POSIX EXIT
+ trap.
+
2016-02-19 Daniel Shahaf <d.s@daniel.shahaf.name>
* unposted: Etc/completion-style-guide: Clarify the term "variant".
diff --git a/Src/signals.c b/Src/signals.c
index 32452ae4f..1344395f7 100644
--- a/Src/signals.c
+++ b/Src/signals.c
@@ -920,9 +920,14 @@ removetrap(int sig)
* Note that we save the trap here even if there isn't an existing
* one, to aid in removing this one. However, if there's
* already one at the current locallevel we just overwrite it.
+ *
+ * Note we save EXIT traps based on the *current* setting of
+ * POSIXTRAPS --- so if there is POSIX EXIT trap set but
+ * we are in native mode it can be saved, replaced by a function
+ * trap, and then restored.
*/
if (!dontsavetrap &&
- (sig == SIGEXIT ? !exit_trap_posix : isset(LOCALTRAPS)) &&
+ (sig == SIGEXIT ? !isset(POSIXTRAPS) : isset(LOCALTRAPS)) &&
locallevel &&
(!trapped || locallevel > (sigtrapped[sig] >> ZSIG_SHIFT)))
dosavetrap(sig, locallevel);
diff --git a/Test/C03traps.ztst b/Test/C03traps.ztst
index d8183a428..f4466b556 100644
--- a/Test/C03traps.ztst
+++ b/Test/C03traps.ztst
@@ -419,6 +419,23 @@
>end of program
>EXIT TRAP TRIGGERED
+ (cd ..; $ZTST_exe -fc '
+ echo entering program
+ emulate sh -c '\''trap "echo POSIX exit trap triggered" EXIT'\''
+ fn() {
+ trap "echo native zsh function-local exit trap triggered" EXIT
+ echo entering native zsh function
+ }
+ fn
+ echo exiting program
+ ')
+0:POSX EXIT trap can have nested native mode EXIT trap
+>entering program
+>entering native zsh function
+>native zsh function-local exit trap triggered
+>exiting program
+>POSIX exit trap triggered
+
(set -e
printf "a\nb\n" | while read line
do