Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: EXIT trap not executed on error



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