From: Bart Schaefer <schaefer@brasslantern.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Cc: Martijn Dekker <martijn@inlv.org>
Subject: Re: EXIT trap not executed on error
Date: Tue, 13 Dec 2022 20:47:08 -0800 [thread overview]
Message-ID: <CAH+w=7ZTE=Y2gznhxfAByTGHuWriu5aiCev_8Fas-UOf1gWboQ@mail.gmail.com> (raw)
In-Reply-To: <CAH+w=7ZBiyGz20aY1_v0Yy9Cvcb1rrdZC6OjQ1u39iG+TECArw@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 615 bytes --]
On Sun, Dec 11, 2022 at 8:52 PM Bart Schaefer <schaefer@brasslantern.com> 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.
[-- Attachment #2: special_exit_trap.txt --]
[-- Type: text/plain, Size: 666 bytes --]
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();
next prev parent reply other threads:[~2022-12-14 4:47 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-08 20:08 Martijn Dekker
2022-12-12 4:52 ` Bart Schaefer
2022-12-14 4:47 ` Bart Schaefer [this message]
2022-12-14 8:35 ` Philippe Altherr
2022-12-15 6:40 ` Bart Schaefer
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='CAH+w=7ZTE=Y2gznhxfAByTGHuWriu5aiCev_8Fas-UOf1gWboQ@mail.gmail.com' \
--to=schaefer@brasslantern.com \
--cc=martijn@inlv.org \
--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).