about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Stephenson <p.stephenson@samsung.com>2018-10-10 11:17:58 +0100
committerPeter Stephenson <p.stephenson@samsung.com>2018-10-10 11:17:58 +0100
commit0d3a786b7cff90868a586e5e3a491b82589a236d (patch)
tree80a33e6551153c3ec43e15bdac7aca33c896d560
parent46c448cf9b31f1d6bc3fdd86953550417cc78c75 (diff)
downloadzsh-0d3a786b7cff90868a586e5e3a491b82589a236d.tar.gz
zsh-0d3a786b7cff90868a586e5e3a491b82589a236d.tar.xz
zsh-0d3a786b7cff90868a586e5e3a491b82589a236d.zip
43669: ensure explicit exit status is used over implicit
-rw-r--r--ChangeLog5
-rw-r--r--Src/builtin.c4
-rw-r--r--Src/init.c2
-rw-r--r--Test/C03traps.ztst3
4 files changed, 11 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index ed01701f6..12cf3ebf2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2018-10-10  Peter Stephenson  <p.stephenson@samsung.com>
+
+	* 43669: Src/builtin.c, Src/init.c, Test/C03traps.ztst: ensure
+	explicit exit status is used rather than implicit.
+
 2018-10-09  Peter Stephenson  <p.stephenson@samsung.com>
 
 	* 43660: Src/builtin.c, Src/exec.c, Src/init.c,
diff --git a/Src/builtin.c b/Src/builtin.c
index e01e035cc..8dcdcc024 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -5723,7 +5723,7 @@ int exit_val;
 void
 realexit(void)
 {
-    exit(exit_val ? exit_val : lastval);
+    exit((shell_exiting || exit_pending) ? exit_val : lastval);
 }
 
 /* As realexit(), but call _exit instead */
@@ -5732,7 +5732,7 @@ realexit(void)
 void
 _realexit(void)
 {
-    _exit(exit_val ? exit_val : lastval);
+    _exit((shell_exiting || exit_pending) ? exit_val : lastval);
 }
 
 /* exit the shell.  val is the return value of the shell.  *
diff --git a/Src/init.c b/Src/init.c
index 838c2c2d1..cec914329 100644
--- a/Src/init.c
+++ b/Src/init.c
@@ -1358,7 +1358,7 @@ init_misc(char *cmd, char *zsh_name)
 	bshin = fdopen(SHIN, "r");
 	execstring(cmd, 0, 1, "cmdarg");
 	stopmsg = 1;
-	zexit(exit_val ? exit_val : lastval, 0);
+	zexit((exit_pending || shell_exiting) ? exit_val : lastval, 0);
     }
 
     if (interact && isset(RCS))
diff --git a/Test/C03traps.ztst b/Test/C03traps.ztst
index bab0b0a0c..57daf8ddf 100644
--- a/Test/C03traps.ztst
+++ b/Test/C03traps.ztst
@@ -872,6 +872,9 @@ F:Must be tested with a top-level script rather than source or function
   $ZTST_testdir/../Src/zsh -fc 'fn() { exit 13; }; trap fn EXIT'
 13:Explicit exit in exit trap overrides implicit exit status
 
+  $ZTST_testdir/../Src/zsh -fc 'fn() { exit 0; }; trap fn EXIT; false'
+0:Explicit exit status 0 in exit trap overrides implicit non-zero status
+
 %clean
 
   rm -f TRAPEXIT