summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBart Schaefer <schaefer@zsh.org>2022-12-13 21:11:33 -0800
committerBart Schaefer <schaefer@zsh.org>2022-12-13 21:11:33 -0800
commit6d49734d46a66b572cf064f60dac8d9e0ad309d0 (patch)
tree16ec8ac27550c244ae75e1490a271e5b5dc3ea2e
parent727079f7e547fe17e73fa6e240fe5c07ab01abe9 (diff)
downloadzsh-6d49734d46a66b572cf064f60dac8d9e0ad309d0.tar.gz
zsh-6d49734d46a66b572cf064f60dac8d9e0ad309d0.zip
51210: Clear errflag before calling EXIT trap
If this is not done, special cases such as failures in special builtins or errors in math expressions skip the trap execution.
-rw-r--r--ChangeLog3
-rw-r--r--Src/exec.c4
2 files changed, 7 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index cea087a01..3536d0b1e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
2022-12-13 Bart Schaefer <schaefer@zsh.org>
+ * 51210: Src/exec.c: Clear errflag before calling EXIT trap,
+ otherwise the trap is skipped for special-case errors in builtins
+
* Philippe Altherr: 51198: Doc/Zsh/options.yo: Clarify and expand
ERR_EXIT and ERR_RETURN documentation to include updated behavior
diff --git a/Src/exec.c b/Src/exec.c
index 7001fd615..2b7e0c7c5 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -1598,6 +1598,7 @@ sublist_done:
(isset(ERRRETURN) && !errreturn)) &&
!(noerrexit & NOERREXIT_EXIT);
if (errexit) {
+ errflag = 0;
if (sigtrapped[SIGEXIT])
dotrap(SIGEXIT);
if (mypid != getpid())
@@ -1630,9 +1631,12 @@ sublist_done:
thisjob = cj;
if (exiting && sigtrapped[SIGEXIT]) {
+ int eflag = errflag;
+ errflag = 0; /* Clear the context for trap */
dotrap(SIGEXIT);
/* Make sure this doesn't get executed again. */
sigtrapped[SIGEXIT] = 0;
+ errflag = eflag;
}
unqueue_signals();