Skip to content

Commit

Permalink
Merge branch 'tr/perl-keep-stderr-open'
Browse files Browse the repository at this point in the history
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
  • Loading branch information
gitster committed Apr 15, 2013
2 parents 85e7e81 + a749c0b commit d809d05
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 3 additions & 3 deletions perl/Git.pm
Expand Up @@ -1489,12 +1489,12 @@ sub _command_common_pipe {
if (not defined $pid) {
throw Error::Simple("open failed: $!");
} elsif ($pid == 0) {
if (defined $opts{STDERR}) {
close STDERR;
}
if ($opts{STDERR}) {
open (STDERR, '>&', $opts{STDERR})
or die "dup failed: $!";
} elsif (defined $opts{STDERR}) {
open (STDERR, '>', '/dev/null')
or die "opening /dev/null failed: $!";
}
_cmd_exec($self, $cmd, @args);
}
Expand Down
3 changes: 2 additions & 1 deletion t/t9700/test.pl
Expand Up @@ -45,7 +45,8 @@ BEGIN
# Failure cases for config:
# Save and restore STDERR; we will probably extract this into a
# "dies_ok" method and possibly move the STDERR handling to Git.pm.
open our $tmpstderr, ">&STDERR" or die "cannot save STDERR"; close STDERR;
open our $tmpstderr, ">&STDERR" or die "cannot save STDERR";
open STDERR, ">", "/dev/null" or die "cannot redirect STDERR to /dev/null";
is($r->config("test.dupstring"), "value2", "config: multivar");
eval { $r->config_bool("test.boolother") };
ok($@, "config_bool: non-boolean values fail");
Expand Down

0 comments on commit d809d05

Please sign in to comment.