zsh-workers
 help / color / mirror / code / Atom feed
* 'exit' in trap handler does not execute EXIT trap
@ 2016-11-07 18:18 ` Martijn Dekker
  2016-11-08 12:47   ` Peter Stephenson
  0 siblings, 1 reply; 2+ messages in thread
From: Martijn Dekker @ 2016-11-07 18:18 UTC (permalink / raw)
  To: Zsh hackers list

zsh does not execute the EXIT trap if the trap handler for another trap
exits the shell. I cannot find anything about this in the POSIX spec,
but this is different from all the other shells, which do execute the
EXIT trap.

Test script:

trap 'echo TERM; exit' TERM
trap 'echo EXIT' EXIT
kill -s TERM "$$"
echo 'FATAL: we should never get here!' 1>&2
exit 1

Actual output: TERM
Expected output: TERM\nEXIT

Thanks,

- M.


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: 'exit' in trap handler does not execute EXIT trap
  2016-11-07 18:18 ` 'exit' in trap handler does not execute EXIT trap Martijn Dekker
@ 2016-11-08 12:47   ` Peter Stephenson
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Stephenson @ 2016-11-08 12:47 UTC (permalink / raw)
  To: Zsh hackers list

On Mon, 7 Nov 2016 18:18:47 +0000
Martijn Dekker <martijn@inlv.org> wrote:
> zsh does not execute the EXIT trap if the trap handler for another trap
> exits the shell. I cannot find anything about this in the POSIX spec,
> but this is different from all the other shells, which do execute the
> EXIT trap.

diff --git a/Src/builtin.c b/Src/builtin.c
index 6c9d058..6969719 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -5435,6 +5435,11 @@ zexit(int val, int from_where)
 	}
     }
     lastval = val;
+    /*
+     * Now we are committed to exiting any previous state
+     * is irrelevant.  Ensure trap can run.
+     */
+    errflag = intrap = 0;
     if (sigtrapped[SIGEXIT])
 	dotrap(SIGEXIT);
     callhookfunc("zshexit", NULL, 1, NULL);
diff --git a/Test/C03traps.ztst b/Test/C03traps.ztst
index 74b83f3..828a3d1 100644
--- a/Test/C03traps.ztst
+++ b/Test/C03traps.ztst
@@ -626,6 +626,21 @@ F:Must be tested with a top-level script rather than source or function
 >before-out
 >before-in
 
+  if zmodload zsh/system 2>/dev/null; then
+  (
+    trap 'echo TERM; exit 2' TERM
+    trap 'echo EXIT' EXIT
+    kill -s TERM "$sysparams[pid]"
+    echo 'FATAL: we should never get here!' 1>&2
+    exit 1
+  )
+  else
+    ZTST_skip="zsh/system library not found."
+  fi
+2:EXIT trap from TERM trap
+>TERM
+>EXIT
+
 %clean
 
   rm -f TRAPEXIT


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-11-08 12:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20161107184855epcas2p40d3b5bf0dbe89e79bcc94c501a4d1562@epcas2p4.samsung.com>
2016-11-07 18:18 ` 'exit' in trap handler does not execute EXIT trap Martijn Dekker
2016-11-08 12:47   ` Peter Stephenson

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).