zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.stephenson@samsung.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: 'exit' in trap handler does not execute EXIT trap
Date: Tue, 08 Nov 2016 12:47:50 +0000	[thread overview]
Message-ID: <20161108124750.62932bd3@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <4d3151fc-715b-dbe3-86fe-89a8d9fe5d75@inlv.org>

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


      reply	other threads:[~2016-11-08 12:48 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20161107184855epcas2p40d3b5bf0dbe89e79bcc94c501a4d1562@epcas2p4.samsung.com>
2016-11-07 18:18 ` Martijn Dekker
2016-11-08 12:47   ` Peter Stephenson [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161108124750.62932bd3@pwslap01u.europe.root.pri \
    --to=p.stephenson@samsung.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).