about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Stephenson <p.stephenson@samsung.com>2018-07-09 11:06:07 +0100
committerPeter Stephenson <p.stephenson@samsung.com>2018-07-09 11:07:53 +0100
commit17178db1a4d8700c9e10862d0dd496f92c53f1cd (patch)
tree8081ecb3dcd951f77ed4b4bbbc63eddd76b51190
parent8cb4fc00c29594aa6c497020b8ff5f7a4d4dd7ea (diff)
downloadzsh-17178db1a4d8700c9e10862d0dd496f92c53f1cd.tar.gz
zsh-17178db1a4d8700c9e10862d0dd496f92c53f1cd.tar.xz
zsh-17178db1a4d8700c9e10862d0dd496f92c53f1cd.zip
users/23531: Error exit/return fixes.
Fix regression with trap on left hand side of pipe.

Fix forced return from shell structure within nested function.

Fix tests exiting too early.

Add new test case.
-rw-r--r--ChangeLog7
-rw-r--r--Src/exec.c17
-rw-r--r--Test/C03traps.ztst17
3 files changed, 41 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 002f608be..babd2321e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2018-07-09  Peter Stephenson  <p.stephenson@samsung.com>
+
+	* users/23531: Src/exec.c, Test/C03traps.ztst: Fix error
+	exit/return from within shell construct inside nested function,
+	and in left hand side of pipe (regression due to broken tests);
+	stop tests from exiting too early and add new test for first fix.
+
 2018-07-07  Matthew Martin  <phy1729@gmail.com>
 
 	* 43106: Completion/BSD/Command/_ldap: Add ldap completer.
diff --git a/Src/exec.c b/Src/exec.c
index d44527841..586402070 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -2728,6 +2728,11 @@ execcmd_fork(Estate state, int how, int type, Wordcode varspc,
 
     if (sigtrapped[SIGINT] & ZSIG_IGNORED)
 	holdintr();
+    /*
+     * EXIT traps shouldn't be called even if we forked to run
+     * shell code as this isn't the main shell.
+     */
+    sigtrapped[SIGEXIT] = 0;
 #ifdef HAVE_NICE
     /* Check if we should run background jobs at a lower priority. */
     if ((how & Z_ASYNC) && isset(BGNICE))
@@ -5792,7 +5797,19 @@ doshfunc(Shfunc shfunc, LinkList doshargs, int noreturnval)
     undoshfunc:
 	--funcdepth;
 	if (retflag) {
+	    /*
+	     * This function is forced to return.
+	     */
 	    retflag = 0;
+	    /*
+	     * The calling function isn't necessarily forced to return,
+	     * but it should be made sensitive to ERR_EXIT and
+	     * ERR_RETURN as the assumptions we made at the end of
+	     * constructs within this function no longer apply.  If
+	     * there are cases where this is not true, they need adding
+	     * to C03traps.ztst.
+	     */
+	    this_noerrexit = 0;
 	    breaks = funcsave->breaks;
 	}
 	freearray(pparams);
diff --git a/Test/C03traps.ztst b/Test/C03traps.ztst
index f22962550..dce263f94 100644
--- a/Test/C03traps.ztst
+++ b/Test/C03traps.ztst
@@ -680,6 +680,22 @@ F:Must be tested with a top-level script rather than source or function
 >Better
 >In .zshenv
 
+  unsetopt errreturn
+  fn2() {
+    if true; then
+      false
+    fi
+  }
+  fn1() {
+    setopt localoptions errreturn
+    fn2
+    print $?
+  }
+  fn1
+  print fn1 done
+0:ERR_RETURN caused by function returning false from within shell construct
+>fn1 done
+
   fn2() {
     if false; then
       print Bad
@@ -741,6 +757,7 @@ F:Must be tested with a top-level script rather than source or function
 0:ERR_EXIT not triggered by status 1 at end of { }
 >OK
 
+  unsetopt err_exit err_return
   (setopt err_exit
   for x in y; do
     false