summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog3
-rw-r--r--Src/exec.c15
-rw-r--r--Test/E02xtrace.ztst16
3 files changed, 19 insertions, 15 deletions
diff --git a/ChangeLog b/ChangeLog
index 4ad0b5d95..82796996f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2008-06-11  Peter Stephenson  <pws@csr.com>
 
+	* 25145: Src/exec.c, Test/E02xtrace.ztst: make sure XTRACE output
+	follows stderr redirections.
+
 	* 25143: Mikael: Doc/Zsh/mod_zprof.yo: missing descendants.
 
 2008-06-10  Peter Stephenson  <p.w.stephenson@ntlworld.com>
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);
     }
diff --git a/Test/E02xtrace.ztst b/Test/E02xtrace.ztst
index 9b38227ff..1375daa67 100644
--- a/Test/E02xtrace.ztst
+++ b/Test/E02xtrace.ztst
@@ -55,16 +55,21 @@
 >Tracing: function 2>file
 >Tracing: source
 >Tracing: source 2>file
+>+(eval):3> print 'Tracing: builtin 2>file'
+>+(eval):5> cat
 >+(eval):7> print 'Tracing: ( builtin ) 2>file'
 >+(eval):9> cat
 >+(eval):11> print 'Tracing: { builtin } 2>file'
 >+(eval):13> cat
 >+(eval):15> print 'Tracing: do builtin done 2>file'
 >+(eval):17> cat
+>+(eval):19> xtf 'Tracing: function 2>file'
+>+xtf:1> local regression_test_dummy_variable
+>+xtf:2> print 'Tracing: function 2>file'
+>+(eval):21> . ./xt.in 'Tracing: source 2>file'
+>+./xt.in:1> print 'Tracing: source 2>file'
 ?+(eval):2> print 'Tracing: builtin'
-?+(eval):3> print 'Tracing: builtin 2>file'
 ?+(eval):4> cat
-?+(eval):5> cat
 ?+(eval):6> print 'Tracing: ( builtin )'
 ?+(eval):8> cat
 ?+(eval):10> print 'Tracing: { builtin }'
@@ -74,18 +79,13 @@
 ?+(eval):18> xtf 'Tracing: function'
 ?+xtf:1> local regression_test_dummy_variable
 ?+xtf:2> print 'Tracing: function'
-?+(eval):19> xtf 'Tracing: function 2>file'
-?+xtf:1> local regression_test_dummy_variable
-?+xtf:2> print 'Tracing: function 2>file'
 ?+(eval):20> . ./xt.in 'Tracing: source'
 ?+./xt.in:1> print 'Tracing: source'
-?+(eval):21> . ./xt.in 'Tracing: source 2>file'
-?+./xt.in:1> print 'Tracing: source 2>file'
 ?+(eval):22> set +x
 
  typeset -ft xtf
  xtf 'Tracing: function'
-0:
+0:tracing function
 >Tracing: function
 ?+xtf:1> local regression_test_dummy_variable
 ?+xtf:2> print 'Tracing: function'