zsh-workers
 help / color / mirror / code / Atom feed
From: Philippe Altherr <philippe.altherr@gmail.com>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: Zsh hackers list <zsh-workers@zsh.org>,
	Martijn Dekker <martijn@inlv.org>
Subject: Re: EXIT trap not executed on error
Date: Wed, 14 Dec 2022 09:35:10 +0100	[thread overview]
Message-ID: <CAGdYchuroqX0=owcipX0ChvxxK-ASVY1PO7H_duVP=DcGMindA@mail.gmail.com> (raw)
In-Reply-To: <CAH+w=7ZTE=Y2gznhxfAByTGHuWriu5aiCev_8Fas-UOf1gWboQ@mail.gmail.com>


[-- Attachment #1.1: Type: text/plain, Size: 802 bytes --]

I had a look at the errflag logic and admittedly I don't understand
everything/much. However I noticed that other
<https://github.com/zsh-users/zsh/blob/6d49734d46a66b572cf064f60dac8d9e0ad309d0/Src/exec.c#L1935>
places
<https://github.com/zsh-users/zsh/blob/6d49734d46a66b572cf064f60dac8d9e0ad309d0/Src/exec.c#L4598>
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
<https://github.com/zsh-users/zsh/blob/6d49734d46a66b572cf064f60dac8d9e0ad309d0/Src/signals.c#L1456>
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

[-- Attachment #1.2: Type: text/html, Size: 954 bytes --]

[-- Attachment #2: patch-run-exit-trap-also-on-error.txt --]
[-- Type: text/plain, Size: 1437 bytes --]

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);
 }

  reply	other threads:[~2022-12-14  8:35 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
2022-12-14  8:35     ` Philippe Altherr [this message]
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='CAGdYchuroqX0=owcipX0ChvxxK-ASVY1PO7H_duVP=DcGMindA@mail.gmail.com' \
    --to=philippe.altherr@gmail.com \
    --cc=martijn@inlv.org \
    --cc=schaefer@brasslantern.com \
    --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).