Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: EXIT trap not executed on error
- X-seq: zsh-workers 51210
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxx>
- Cc: Martijn Dekker <martijn@xxxxxxxx>
- Subject: Re: EXIT trap not executed on error
- Date: Tue, 13 Dec 2022 20:47:08 -0800
- Archived-at: <https://zsh.org/workers/51210>
- In-reply-to: <CAH+w=7ZBiyGz20aY1_v0Yy9Cvcb1rrdZC6OjQ1u39iG+TECArw@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <1939278e-89c4-812d-5dea-e836568dc100@inlv.org> <CAH+w=7ZBiyGz20aY1_v0Yy9Cvcb1rrdZC6OjQ1u39iG+TECArw@mail.gmail.com>
On Sun, Dec 11, 2022 at 8:52 PM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
>
> I don't recall why this suppresses traps on errflag, if I ever knew.
> However, the comment suggests the calling code should be clearing
> errflag around the dotrap().
>
> The question is whether its OK here to just clear errflag like this,
> or if it should be saved and restored?
Seems reasonable to errflag on the side of safety (ahem) and do the restore.
The new first hunk covers another possible case; immediately outside
that diff context we call realexit(), so there is no possibility of
errflag being referenced again.
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();
Messages sorted by:
Reverse Date,
Date,
Thread,
Author