about summary refs log tree commit diff
path: root/Src/builtin.c
diff options
context:
space:
mode:
Diffstat (limited to 'Src/builtin.c')
-rw-r--r--Src/builtin.c11
1 files changed, 11 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);