summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--Src/exec.c9
-rw-r--r--Test/D04parameter.ztst9
3 files changed, 23 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 6a3d18bf2..678b561ac 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2014-11-02  Peter Stephenson  <p.w.stephenson@ntlworld.com>
+
+	* 33591: Src/exec.c, Test/D04parameter.ztst: don't treat an exec
+	within an subshell as an exec of the parent shell even if about
+	to exit.  Fixes incorrect SHLVL in subshell.
+
 2014-10-31  Oliver Kiddle  <opk@zsh.org>
 
 	* unposted: Src/jobs.c: quash compiler warning
diff --git a/Src/exec.c b/Src/exec.c
index 5bbd4e15d..d2d4e800b 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -2995,6 +2995,15 @@ execcmd(Estate state, int input, int output, int how, int last1)
 	 * Note that any form of exec means that the subshell is fake *
 	 * (but we may be in a subshell already).                     */
 	is_exec = 1;
+	/*
+	 * If we are in a subshell environment anyway, say we're forked,
+	 * even if we're actually not forked because we know the
+	 * subshell is exiting.  This ensures SHLVL reflects the current
+	 * shell, and also optimises out any save/restore we'd need to
+	 * do if we were returning to the main shell.
+	 */
+	if (type == WC_SUBSH)
+	    forked = 1;
     }
 
     if ((esglob = !(cflags & BINF_NOGLOB)) && args && htok) {
diff --git a/Test/D04parameter.ztst b/Test/D04parameter.ztst
index d7f39cb37..0cbe6c95d 100644
--- a/Test/D04parameter.ztst
+++ b/Test/D04parameter.ztst
@@ -1548,7 +1548,7 @@
    foo=
    print ${foo:wq}
    print ${:wq}
-0:Empty parameter shouldn't cause modifiers to crash the shell
+0:Empty parameter should not cause modifiers to crash the shell
 >
 >
 
@@ -1656,3 +1656,10 @@
 >h:i
 >j,k
 >l
+
+  SHLVL=1
+  $ZTST_testdir/../Src/zsh -c 'echo $SHLVL'
+  $ZTST_testdir/../Src/zsh -c '(echo $SHLVL)'
+0:SHLVL appears sensible when about to exit shell
+>2
+>2