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

Re: trap problem.



> Perhaps zsh's tests for whether the last command can be `exec'd should
> include testing whether there are any user-defined traps in effect?

Hope this will work.  I think I've found everywhere the `signal trapped'
bit of elements of the sigtrapped array can change.  I'm sure the person
who wrote the trap-saving code has... errr... his fingers crossed.

Index: Src/exec.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/exec.c,v
retrieving revision 1.25
diff -u -r1.25 exec.c
--- Src/exec.c	2001/03/22 12:13:16	1.25
+++ Src/exec.c	2001/03/30 09:28:18
@@ -1954,7 +1954,7 @@
      *    be needed after the current command.  This is typically the case    *
      *    when when the command is the last stage in a subshell, or is the    *
      *    last command after the option `-c'.                                 *
-     * 2) We are not trapping EXIT or ZERR.                                   *
+     * 2) We don't have any traps set.                                        *
      * 3) We don't have any files to delete.                                  *
      *                                                                        *
      * The condition above for a `fake exec' will also work for a current     *
@@ -1966,8 +1966,7 @@
     if ((how & Z_ASYNC) ||
 	(!do_exec &&
 	 (((is_builtin || is_shfunc) && output) ||
-	  (!is_cursh && (last1 != 1 || sigtrapped[SIGZERR] ||
-			 sigtrapped[SIGEXIT] || havefiles()))))) {
+	  (!is_cursh && (last1 != 1 || nsigtrapped || havefiles()))))) {
 
 	pid_t pid;
 	int synch[2];
Index: Src/signals.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/signals.c,v
retrieving revision 1.15
diff -u -r1.15 signals.c
--- Src/signals.c	2001/01/25 09:20:13	1.15
+++ Src/signals.c	2001/03/30 09:28:18
@@ -41,6 +41,11 @@
 /**/
 mod_export Eprog sigfuncs[VSIGCOUNT];
 
+/* Total count of trapped signals */
+
+/**/
+mod_export int nsigtrapped;
+
 /* Variables used by signal queueing */
 
 /**/
@@ -716,6 +721,7 @@
             sig != SIGCHLD)
             signal_ignore(sig);
     } else {
+	nsigtrapped++;
         sigtrapped[sig] = ZSIG_TRAPPED;
         if (sig && sig <= SIGCOUNT &&
 #ifdef SIGWINCH
@@ -773,6 +779,8 @@
 	unqueue_signals();
         return NULL;
     }
+    if (sigtrapped[sig] & ZSIG_TRAPPED)
+	nsigtrapped--;
     sigtrapped[sig] = 0;
     if (sig == SIGINT && interact) {
 	/* PWS 1995/05/16:  added test for interactive, also noholdintr() *
@@ -860,6 +868,8 @@
 	    exitfn = sigfuncs[SIGEXIT];
 	}
 	sigfuncs[SIGEXIT] = NULL;
+	if (sigtrapped[SIGEXIT] & ZSIG_TRAPPED)
+	    nsigtrapped--;
 	sigtrapped[SIGEXIT] = 0;
     }
 
@@ -878,6 +888,12 @@
 		dontsavetrap++;
 		settrap(sig, prog);
 		dontsavetrap--;
+		/*
+		 * counting of nsigtrapped should presumably be handled
+		 * in settrap...
+		 */
+		DPUTS((sigtrapped[sig] ^ st->flags) & ZSIG_TRAPPED,
+		      "BUG: settrap didn't restore correct ZSIG_TRAPPED");
 		if ((sigtrapped[sig] = st->flags) & ZSIG_FUNC)
 		    shfunctab->addnode(shfunctab, ((Shfunc)st->list)->nam,
 				       (Shfunc) st->list);

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR Ltd., Unit 300, Science Park, Milton Road,
Cambridge, CB4 0XL, UK                          Tel: +44 (0)1223 392070



Messages sorted by: Reverse Date, Date, Thread, Author