about summary refs log tree commit diff
path: root/Src/builtin.c
diff options
context:
space:
mode:
authorPeter Stephenson <p.stephenson@samsung.com>2018-10-09 10:05:05 +0100
committerPeter Stephenson <p.stephenson@samsung.com>2018-10-09 10:05:05 +0100
commitd768a7492a850e8d1ccb00f2cc8eef0bd238b7ab (patch)
tree27a59d6605abdb9d32a2dd31c26fd147b181085d /Src/builtin.c
parent00baf08602705f1edc13266c24ecf2df5241143b (diff)
downloadzsh-d768a7492a850e8d1ccb00f2cc8eef0bd238b7ab.tar.gz
zsh-d768a7492a850e8d1ccb00f2cc8eef0bd238b7ab.tar.xz
zsh-d768a7492a850e8d1ccb00f2cc8eef0bd238b7ab.zip
43653: explicit exit from EXIT trap overrides exit status
Diffstat (limited to 'Src/builtin.c')
-rw-r--r--Src/builtin.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/Src/builtin.c b/Src/builtin.c
index c5b319b68..b81acdb53 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -5709,7 +5709,13 @@ int shell_exiting;
 mod_export void
 zexit(int val, int from_where)
 {
-    /* Don't do anything recursively:  see below */
+    static int exit_val;
+    /*
+     * Don't do anything recursively:  see below.
+     * Do, however, update exit status --- there's no nesting,
+     * a later value always overrides an earlier.
+     */
+    exit_val = val;
     if (shell_exiting == -1)
 	return;
 
@@ -5757,7 +5763,7 @@ zexit(int val, int from_where)
 #endif
 	}
     }
-    lastval = val;
+    lastval = exit_val;
     /*
      * Now we are committed to exiting any previous state
      * is irrelevant.  Ensure trap can run.
@@ -5771,9 +5777,9 @@ zexit(int val, int from_where)
        release_pgrp();
     }
     if (mypid != getpid())
-	_exit(val);
+	_exit(exit_val);
     else
-	exit(val);
+	exit(exit_val);
 }
 
 /* . (dot), source */