Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: EXIT trap not executed on error
- X-seq: zsh-workers 51211
- From: Philippe Altherr <philippe.altherr@xxxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Cc: Zsh hackers list <zsh-workers@xxxxxxx>, Martijn Dekker <martijn@xxxxxxxx>
- Subject: Re: EXIT trap not executed on error
- Date: Wed, 14 Dec 2022 09:35:10 +0100
- Archived-at: <https://zsh.org/workers/51211>
- In-reply-to: <CAH+w=7ZTE=Y2gznhxfAByTGHuWriu5aiCev_8Fas-UOf1gWboQ@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> <CAH+w=7ZTE=Y2gznhxfAByTGHuWriu5aiCev_8Fas-UOf1gWboQ@mail.gmail.com>
I had a look at the errflag logic and admittedly I don't understand everything/much. However I noticed that
other places that restore the errflag preserve the ERRFLAG_INT bit. Maybe the same should be done here, even though it may not be that important as we are on the exit path anyway.
I also wondered whether
signals.c/dotraps would be a better place for the new logic. It already has special logic for SIGEXIT and this way the new logic would be guaranteed to apply to all runs of SIGEXIT.
Philippe
diff --git a/Src/signals.c b/Src/signals.c
index a61368554..684394520 100644
--- a/Src/signals.c
+++ b/Src/signals.c
@@ -1306,9 +1306,7 @@ dotrapargs(int sig, int *sigtr, void *sigfn)
* function will test for this, but this way we keep status flags *
* intact without working too hard. Special cases (e.g. calling *
* a trap for SIGINT after the error flag was set) are handled *
- * by the calling code. (PWS 1995/06/08). *
- * *
- * This test is now replicated in dotrap(). */
+ * by the calling code. (PWS 1995/06/08). */
if ((*sigtr & ZSIG_IGNORED) || !sigfn || errflag)
return;
@@ -1471,23 +1469,20 @@ dotrap(int sig)
} else
funcprog = siglists[sig];
- /*
- * Copied from dotrapargs().
- * (In fact, the gain from duplicating this appears to be virtually
- * zero. Not sure why it's here.)
- */
- if ((sigtrapped[sig] & ZSIG_IGNORED) || !funcprog || errflag)
- return;
-
dont_queue_signals();
- if (sig == SIGEXIT)
+ int prev_errflag = errflag;
+ if (sig == SIGEXIT) {
++in_exit_trap;
+ errflag = 0;
+ }
dotrapargs(sig, sigtrapped+sig, funcprog);
- if (sig == SIGEXIT)
+ if (sig == SIGEXIT) {
+ errflag = prev_errflag | (errflag & ERRFLAG_INT);
--in_exit_trap;
+ }
restore_queue_signals(q);
}
Messages sorted by:
Reverse Date,
Date,
Thread,
Author