Skip to content

Commit d809d05

Browse files
committed
Merge branch 'tr/perl-keep-stderr-open'
Closing (not redirecting to /dev/null) the standard error stream is not a very smart thing to do. Later open may return file descriptor #2 for unrelated purpose, and error reporting code may write into them. * tr/perl-keep-stderr-open: t9700: do not close STDERR perl: redirect stderr to /dev/null instead of closing
2 parents 85e7e81 + a749c0b commit d809d05

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

perl/Git.pm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,12 +1489,12 @@ sub _command_common_pipe {
14891489
if (not defined $pid) {
14901490
throw Error::Simple("open failed: $!");
14911491
} elsif ($pid == 0) {
1492-
if (defined $opts{STDERR}) {
1493-
close STDERR;
1494-
}
14951492
if ($opts{STDERR}) {
14961493
open (STDERR, '>&', $opts{STDERR})
14971494
or die "dup failed: $!";
1495+
} elsif (defined $opts{STDERR}) {
1496+
open (STDERR, '>', '/dev/null')
1497+
or die "opening /dev/null failed: $!";
14981498
}
14991499
_cmd_exec($self, $cmd, @args);
15001500
}

t/t9700/test.pl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ BEGIN
4545
# Failure cases for config:
4646
# Save and restore STDERR; we will probably extract this into a
4747
# "dies_ok" method and possibly move the STDERR handling to Git.pm.
48-
open our $tmpstderr, ">&STDERR" or die "cannot save STDERR"; close STDERR;
48+
open our $tmpstderr, ">&STDERR" or die "cannot save STDERR";
49+
open STDERR, ">", "/dev/null" or die "cannot redirect STDERR to /dev/null";
4950
is($r->config("test.dupstring"), "value2", "config: multivar");
5051
eval { $r->config_bool("test.boolother") };
5152
ok($@, "config_bool: non-boolean values fail");

0 commit comments

Comments
 (0)