about summary refs log tree commit diff
path: root/Src
diff options
context:
space:
mode:
authorPaul Ackersviller <packersv@users.sourceforge.net>2007-11-05 02:38:53 +0000
committerPaul Ackersviller <packersv@users.sourceforge.net>2007-11-05 02:38:53 +0000
commit3cf23604b0327a698516eba7fcfaca99d6746f9d (patch)
tree1bd2d703144760333452613c2c90b92e54c8e1e3 /Src
parentd3a79df906f5f653f34a40ab9cd33a8e5f9600b9 (diff)
downloadzsh-3cf23604b0327a698516eba7fcfaca99d6746f9d.tar.gz
zsh-3cf23604b0327a698516eba7fcfaca99d6746f9d.tar.xz
zsh-3cf23604b0327a698516eba7fcfaca99d6746f9d.zip
Merge of 22983: exit could loop for ever in two different ways.
Diffstat (limited to 'Src')
-rw-r--r--Src/builtin.c11
-rw-r--r--Src/init.c9
2 files changed, 20 insertions, 0 deletions
diff --git a/Src/builtin.c b/Src/builtin.c
index 145cb8cad..40e2f8145 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -4186,6 +4186,10 @@ zexit(int val, int from_where)
 {
     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))
@@ -4195,9 +4199,16 @@ zexit(int val, int from_where)
 	    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);
diff --git a/Src/init.c b/Src/init.c
index 76797ab2a..0fde9f7ac 100644
--- a/Src/init.c
+++ b/Src/init.c
@@ -131,6 +131,15 @@ loop(int toplevel, int justonce)
 		(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;