zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: fixes for exit
@ 2006-11-08 17:33 Peter Stephenson
  0 siblings, 0 replies; only message in thread
From: Peter Stephenson @ 2006-11-08 17:33 UTC (permalink / raw)
  To: Zsh hackers list

You might have thought that exiting the shell was simple enough that
there were know serious bugs.

1. Exiting from a zle function caused an infinite loop.

2. Code run at exit that called "exit" caused infinite regression.

Index: Src/builtin.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/builtin.c,v
retrieving revision 1.166
diff -u -r1.166 builtin.c
--- Src/builtin.c	8 Nov 2006 10:38:06 -0000	1.166
+++ Src/builtin.c	8 Nov 2006 17:30:48 -0000
@@ -4391,6 +4391,10 @@
 {
     static int in_exit;
 
+    /* Don't do anything recursively:  see below */
+    if (in_exit == -1)
+	return;
+
     if (isset(MONITOR) && !stopmsg && from_where != 1) {
 	scanjobs();    /* check if jobs need printing           */
 	if (isset(CHECKJOBS))
@@ -4400,9 +4404,16 @@
 	    return;
 	}
     }
+    /* Positive in_exit means we have been here before */
     if (from_where == 2 || (in_exit++ && from_where))
 	return;
 
+    /*
+     * We're now committed to exiting.  Set in_exit to -1 to
+     * indicate we shouldn't do any recursive processing.
+     */
+    in_exit = -1;
+
     if (isset(MONITOR)) {
 	/* send SIGHUP to any jobs left running  */
 	killrunjobs(from_where == 1);
Index: Src/init.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/init.c,v
retrieving revision 1.71
diff -u -r1.71 init.c
--- Src/init.c	8 Nov 2006 10:38:06 -0000	1.71
+++ Src/init.c	8 Nov 2006 17:30:48 -0000
@@ -131,6 +131,15 @@
 		(tok == LEXERR && (!isset(SHINSTDIN) || !toplevel)) ||
 		justonce)
 		break;
+	    if (exit_pending) {
+		/*
+		 * Something down there (a ZLE function?) decided
+		 * to exit when there was stuff to clear up.
+		 * Handle that now.
+		 */
+		stopmsg = 1;
+		zexit(exit_pending >> 1, 0);
+	    }
 	    if (tok == LEXERR && !lastval)
 		lastval = 1;
 	    continue;

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


To access the latest news from CSR copy this link into a web browser:  http://www.csr.com/email_sig.php


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2006-11-08 17:33 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-11-08 17:33 PATCH: fixes for exit Peter Stephenson

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).