about summary refs log tree commit diff
path: root/Src
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2008-06-11 09:27:55 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2008-06-11 09:27:55 +0000
commitc17b4c8d77c7a2ec52168f471a262023ed2e437d (patch)
treec4646cacf8a87629798f44bea29749bb0d042651 /Src
parent4814830da2babe3f919d3c0331014c60b7a8ce07 (diff)
downloadzsh-c17b4c8d77c7a2ec52168f471a262023ed2e437d.tar.gz
zsh-c17b4c8d77c7a2ec52168f471a262023ed2e437d.tar.xz
zsh-c17b4c8d77c7a2ec52168f471a262023ed2e437d.zip
25145: make sure XTRACE output is redirected with stderr
Diffstat (limited to 'Src')
-rw-r--r--Src/exec.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/Src/exec.c b/Src/exec.c
index fd6f45f93..74f389a8d 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -2165,7 +2165,7 @@ execcmd(Estate state, int input, int output, int how, int last1)
     LinkList redir;
     wordcode code;
     Wordcode beg = state->pc, varspc;
-    FILE *oxtrerr = xtrerr;
+    FILE *oxtrerr = xtrerr, *newxtrerr = NULL;
 
     doneps4 = 0;
     redir = (wc_code(*state->pc) == WC_REDIR ? ecgetredirs(state) : NULL);
@@ -2675,10 +2675,10 @@ execcmd(Estate state, int input, int output, int how, int last1)
     fflush(xtrerr);
     if (isset(XTRACE) && xtrerr == stderr &&
 	(type < WC_SUBSH || type == WC_TIMED)) {
-	if (!(xtrerr = fdopen(movefd(dup(fileno(stderr))), "w")))
-	    xtrerr = stderr;
-	else
+	if ((newxtrerr = fdopen(movefd(dup(fileno(stderr))), "w"))) {
+	    xtrerr = newxtrerr;
 	    fdtable[fileno(xtrerr)] = FDT_XTRACE;
+	}
     }
 
     /* Add pipeline input/output to mnodes */
@@ -2885,6 +2885,7 @@ execcmd(Estate state, int input, int output, int how, int last1)
 	if (mfds[i] && mfds[i]->ct >= 2)
 	    closemn(mfds, i);
 
+    xtrerr = stderr;
     if (nullexec) {
 	if (nullexec == 1) {
 	    /*
@@ -3099,9 +3100,9 @@ execcmd(Estate state, int input, int output, int how, int last1)
     fixfds(save);
 
  done:
-    if (xtrerr != oxtrerr) {
-	fil = fileno(xtrerr);
-	fclose(xtrerr);
+    if (newxtrerr) {
+	fil = fileno(newxtrerr);
+	fclose(newxtrerr);
 	xtrerr = oxtrerr;
 	zclose(fil);
     }