Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: One last (?!?) tweak to xtrace redirection



Saving and restoring of the xtrace descriptor should not occur until xtrace
is actually turned on.

Index: Src/exec.c
===================================================================
@@ -2012,7 +2012,8 @@
 
     /* Make a copy of stderr for xtrace output before redirecting */
     fflush(xtrerr);
-    if (xtrerr == stderr && (type < WC_SUBSH || type == WC_TIMED)) {
+    if (isset(XTRACE) && xtrerr == stderr &&
+	(type < WC_SUBSH || type == WC_TIMED)) {
 	if (!(xtrerr = fdopen(movefd(dup(fileno(stderr))), "w")))
 	    xtrerr = stderr;
 	else
Index: Test/51xtrace.ztst
===================================================================
@@ -2,6 +2,11 @@
 
 %prep
   mkdir xtrace.tmp && cd xtrace.tmp
+  function xtf {
+    local regression_test_dummy_variable
+    print "$*"
+  }
+  echo 'print "$*"' > xt.in
 
 %test
 
@@ -21,7 +26,11 @@
   repeat 1 do print 'Tracing: do builtin done'; done
   repeat 1 do print 'Tracing: do builtin done 2>file'; done 2>>xtrace.err
   repeat 1 do cat <<<'Tracing: do external done'; done
-  repeat 1 do cat <<<'Tracing: do external done'; done 2>>xtrace.err
+  repeat 1 do cat <<<'Tracing: do external done 2>file'; done 2>>xtrace.err
+  xtf 'Tracing: function'
+  xtf 'Tracing: function 2>file' 2>>xtrace.err
+  . ./xt.in 'Tracing: source'
+  . ./xt.in 'Tracing: source 2>file' 2>>xtrace.err
   set +x
   cat xtrace.err
 0:xtrace with and without redirection
@@ -40,7 +49,11 @@
 >Tracing: do builtin done
 >Tracing: do builtin done 2>file
 >Tracing: do external done
->Tracing: do external done
+>Tracing: do external done 2>file
+>Tracing: function
+>Tracing: function 2>file
+>Tracing: source
+>Tracing: source 2>file
 >+ZTST_execchunk:2> print Tracing: ( builtin ) 2>file
 >+ZTST_execchunk:2> cat
 >+ZTST_execchunk:2> print Tracing: { builtin } 2>file
@@ -57,4 +70,14 @@
 ?+ZTST_execchunk:2> cat
 ?+ZTST_execchunk:2> print Tracing: do builtin done
 ?+ZTST_execchunk:2> cat
+?+ZTST_execchunk:2> xtf Tracing: function
+?+xtf:0> local regression_test_dummy_variable
+?+xtf:0> print Tracing: function
+?+ZTST_execchunk:2> xtf Tracing: function 2>file
+?+xtf:0> local regression_test_dummy_variable
+?+xtf:0> print Tracing: function 2>file
+?+ZTST_execchunk:2> . ./xt.in Tracing: source
+?+./xt.in:1> print Tracing: source
+?+ZTST_execchunk:2> . ./xt.in Tracing: source 2>file
+?+./xt.in:1> print Tracing: source 2>file
 ?+ZTST_execchunk:2> set +x

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com



Messages sorted by: Reverse Date, Date, Thread, Author