about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2000-06-14 22:00:39 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2000-06-14 22:00:39 +0000
commita777f021a2101c90335f6f88eb31895df0e6f0a6 (patch)
treea68ca0da21ba9b467590e9764bc634b2ed1e4771
parent545c0647701f8a677c40394c23700a229ca38003 (diff)
downloadzsh-a777f021a2101c90335f6f88eb31895df0e6f0a6.tar.gz
zsh-a777f021a2101c90335f6f88eb31895df0e6f0a6.tar.xz
zsh-a777f021a2101c90335f6f88eb31895df0e6f0a6.zip
11906: yet two more saving trap bugs
-rw-r--r--ChangeLog6
-rw-r--r--Src/signals.c22
2 files changed, 20 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index 9a5c9610c..0d1e70ba3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2000-06-14  Peter Stephenson  <pws@pwstephenson.fsnet.co.uk>
+
+	* 11906: Src/signals.c: yet another two bugs with saving traps:
+	flags were prematurely restored when resetting and TRAPEXIT
+	was sometimes saved incorrectly when exitting the scope.
+
 2000-06-14  Oliver Kiddle  <opk@zsh.org>
 
 	* 11903: Completion/Core/_expand: handle suffix style for arrays
diff --git a/Src/signals.c b/Src/signals.c
index 7ec517b7f..a45dac5e6 100644
--- a/Src/signals.c
+++ b/Src/signals.c
@@ -642,6 +642,7 @@ struct savetrap {
 };
 
 static LinkList savetraps;
+static int dontsavetrap;
 
 /*
  * Save the current trap by copying it.  This does nothing to
@@ -670,6 +671,10 @@ dosavetrap(int sig, int level)
 	    newshf->flags = shf->flags;
 	    newshf->funcdef = dupeprog(shf->funcdef, 0);
 	}
+#ifdef DEBUG
+	else dputs("BUG: no function present with function trap flag set.");
+#endif
+	    
 	st->list = newshf;
     } else if (sigtrapped[sig]) {
 	st->list = sigfuncs[sig] ? dupeprog(sigfuncs[sig], 0) : NULL;
@@ -754,7 +759,8 @@ removetrap(int sig)
      * one, to aid in removing this one.  However, if there's
      * already one at the current locallevel we just overwrite it.
      */
-    if ((isset(LOCALTRAPS) || sig == SIGEXIT) && locallevel &&
+    if (!dontsavetrap && (isset(LOCALTRAPS) || sig == SIGEXIT) &&
+	locallevel &&
 	(!trapped || locallevel > (sigtrapped[sig] >> ZSIG_SHIFT)))
 	dosavetrap(sig, locallevel);
 
@@ -854,21 +860,19 @@ endtrapscope(void)
 
 	    remnode(savetraps, ln);
 
-	    if (sigtrapped[sig])
-		unsettrap(sig);
-	    sigtrapped[sig] = st->flags;
 	    if (st->flags && (st->list != NULL)) {
 		Eprog prog = (st->flags & ZSIG_FUNC) ?
 		    ((Shfunc) st->list)->funcdef : (Eprog) st->list;
 		/* prevent settrap from saving this */
-		int oldlt = opts[LOCALTRAPS];
-		opts[LOCALTRAPS] = 0;
+		dontsavetrap++;
 		settrap(sig, prog);
-		opts[LOCALTRAPS] = oldlt;
+		dontsavetrap--;
 		if ((sigtrapped[sig] = st->flags) & ZSIG_FUNC)
 		    shfunctab->addnode(shfunctab, ((Shfunc)st->list)->nam,
 				       (Shfunc) st->list);
-	    }
+	    } else if (sigtrapped[sig])
+		unsettrap(sig);
+
 	    zfree(st, sizeof(*st));
 	}
     }
@@ -881,6 +885,8 @@ endtrapscope(void)
 	else
 	    freeeprog(exitfn);
     }
+    DPUTS(!locallevel && savetraps && firstnode(savetraps),
+	  "BUG: still saved traps outside all function scope");
 }
 
 /* Execute a trap function for a given signal, possibly