Subject: | STDERR may change |
Hi,
In applications that reopen STDERR (in order to redirect the output of some external program, for instance), the output of Devel::Trace may end in the wrong place.
The patch attached dups the STDERR file descriptor on startup and then uses it when tracing the program.
Subject: | 0001-Duplicate-STDERR-on-startup-in-order-to-avoid-confli.patch |
From 764d68ad306274d1cb6b115180c69bc0574dc6dc Mon Sep 17 00:00:00 2001
From: Salvador Fandino <sfandino@yahoo.com>
Date: Wed, 16 Mar 2016 11:27:35 +0100
Subject: [PATCH] Duplicate STDERR on startup in order to avoid conflicts with
code that manipulates that file descriptor
---
Trace.pm | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/Trace.pm b/Trace.pm
index e8ed796..03f60be 100644
--- a/Trace.pm
+++ b/Trace.pm
@@ -4,12 +4,15 @@ package Devel::Trace;
$VERSION = '0.12';
$TRACE = 1;
+open OUT, '>&', STDERR;
+$oldfh = select(OUT); $| = 1; select($oldfh);
+
# This is the important part. The rest is just fluff.
sub DB::DB {
return unless $TRACE;
my ($p, $f, $l) = caller;
my $code = \@{"::_<$f"};
- print STDERR ">> $f:$l: $code->[$l]";
+ print OUT ">> $f:$l: $code->[$l]";
}
--
2.7.0