We can rely on timely auto-destruction based on reference
counting; reducing the chance of redundant close(2) calls
which may hit the wront FD.
We do care about certain close calls (e.g. writing to a buffered
IO handle) if we require error-checking for write-integrity. In
other cases, let things go out-of-scope so it can be freed
automatically after use.
if (open(my $fh, '<', $path)) {
local $/;
$rv = <$fh>;
if (open(my $fh, '<', $path)) {
local $/;
$rv = <$fh>;
- close $log; # we may EPIPE here
# for pagination
($first_commit, $last_commit);
}
# for pagination
($first_commit, $last_commit);
}
my %rv;
if (open my $fh, '<', "$ctx->{git_dir}/description") {
chomp($rv{description} = <$fh>);
my %rv;
if (open my $fh, '<', "$ctx->{git_dir}/description") {
chomp($rv{description} = <$fh>);
} else {
$rv{description} = '($GIT_DIR/description missing)';
}
} else {
$rv{description} = '($GIT_DIR/description missing)';
}
my @cmd = ('git', "--git-dir=$self->{git_dir}", qw(cat-file), $batch);
my $redir = { 0 => fileno($out_r), 1 => fileno($in_w) };
$self->{$pid} = spawn(\@cmd, undef, $redir);
my @cmd = ('git', "--git-dir=$self->{git_dir}", qw(cat-file), $batch);
my $redir = { 0 => fileno($out_r), 1 => fileno($in_w) };
$self->{$pid} = spawn(\@cmd, undef, $redir);
- close $out_r or fail($self, "close failed: $!");
- close $in_w or fail($self, "close failed: $!");
$out_w->autoflush(1);
$self->{$out} = $out_w;
$self->{$in} = $in_r;
$out_w->autoflush(1);
$self->{$out} = $out_w;
$self->{$in} = $in_r;
sub _destroy {
my ($self, $in, $out, $pid) = @_;
sub _destroy {
my ($self, $in, $out, $pid) = @_;
- my $p = $self->{$pid} or return;
- $self->{$pid} = undef;
+ my $p = delete $self->{$pid} or return;
foreach my $f ($in, $out) {
foreach my $f ($in, $out) {
- my $fh = $self->{$f};
- defined $fh or next;
- close $fh;
- $self->{$f} = undef;
sub READLINE { readline($_[0]->{fh}) }
sub READLINE { readline($_[0]->{fh}) }
-sub CLOSE { close($_[0]->{fh}) }
+sub CLOSE { delete($_[0]->{fh}) }
sub FILENO { fileno($_[0]->{fh}) }
sub DESTROY {
sub FILENO { fileno($_[0]->{fh}) }
sub DESTROY {
- my $fh = delete($_[0]->{fh});
- close $fh if $fh;
waitpid($_[0]->{pid}, 0);
}
waitpid($_[0]->{pid}, 0);
}
my @cmd = qw(config core.sharedRepository);
my $fh = PublicInbox::Git->new($self->{git_dir})->popen(@cmd);
my $perm = <$fh>;
my @cmd = qw(config core.sharedRepository);
my $fh = PublicInbox::Git->new($self->{git_dir})->popen(@cmd);
my $perm = <$fh>;
chomp $perm if defined $perm;
$perm;
}
chomp $perm if defined $perm;
$perm;
}
$r->blocking($blocking) if defined $blocking;
$opts->{1} = fileno($w);
my $pid = spawn($cmd, $env, $opts);
$r->blocking($blocking) if defined $blocking;
$opts->{1} = fileno($w);
my $pid = spawn($cmd, $env, $opts);
return ($r, $pid) if wantarray;
my $ret = gensym;
tie *$ret, 'PublicInbox::ProcessPipe', $pid, $r;
return ($r, $pid) if wantarray;
my $ret = gensym;
tie *$ret, 'PublicInbox::ProcessPipe', $pid, $r;