summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Stephenson <p.w.stephenson@ntlworld.com>2015-04-15 21:16:17 +0100
committerPeter Stephenson <p.w.stephenson@ntlworld.com>2015-04-15 21:16:17 +0100
commit3bf8cab82e32fc6903be995a5b6d7276307b22fe (patch)
tree81476eaff8d26e9004c9e977bf9927a8f57f06c7
parent493fe2b4440679ca73d9022d94129039b9eacfeb (diff)
downloadzsh-3bf8cab82e32fc6903be995a5b6d7276307b22fe.tar.gz
zsh-3bf8cab82e32fc6903be995a5b6d7276307b22fe.tar.xz
zsh-3bf8cab82e32fc6903be995a5b6d7276307b22fe.zip
34900: assignment before an "exec".
Without POSXIBUILTIN: restore after, so we only get side effects.

With POSXIBUILTIN: keep set variable
-rw-r--r--ChangeLog5
-rw-r--r--Src/exec.c21
2 files changed, 19 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index 0d4521453..e41d8b893 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2015-04-15  Peter Stephenson  <p.w.stephenson@ntlworld.com>
+
+	* 34900: Src/exec.c: assignment before an "exec" with
+	a redirection, with and without POSIXBUILTINS.
+
 2015-04-15  Peter Stephenson  <p.stephenson@samsung.com>
 
 	* unposted: Src/math.c: rewrite last commit to look more
diff --git a/Src/exec.c b/Src/exec.c
index 2ee37d09f..2a8185cbc 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -3305,6 +3305,20 @@ execcmd(Estate state, int input, int output, int how, int last1)
 	    closemn(mfds, i, REDIR_CLOSE);
 
     if (nullexec) {
+	/*
+	 * If nullexec is 2, we have variables to add with the redirections
+	 * in place.  If nullexec is 1, we may have variables but they
+	 * need the standard restore logic.
+	 */
+	if (varspc) {
+	    LinkList restorelist = 0, removelist = 0;
+	    if (!isset(POSIXBUILTINS) && nullexec != 2)
+		save_params(state, varspc, &restorelist, &removelist);
+	    addvars(state, varspc, 0);
+	    if (restorelist)
+		restore_params(restorelist, removelist);
+	}
+	lastval = errflag ? errflag : cmdoutval;
 	if (nullexec == 1) {
 	    /*
 	     * If nullexec is 1 we specifically *don't* restore the original
@@ -3315,13 +3329,6 @@ execcmd(Estate state, int input, int output, int how, int last1)
 		    zclose(save[i]);
 	    goto done;
 	}
-	/*
-	 * If nullexec is 2, we have variables to add with the redirections
-	 * in place.
-	 */
-	if (varspc)
-	    addvars(state, varspc, 0);
-	lastval = errflag ? errflag : cmdoutval;
 	if (isset(XTRACE)) {
 	    fputc('\n', xtrerr);
 	    fflush(xtrerr);