Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: 'exit' in trap handler does not execute EXIT trap
On Mon, 7 Nov 2016 18:18:47 +0000
Martijn Dekker <martijn@xxxxxxxx> 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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author