]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
process_pipe: don't run `close' unless requested
authorEric Wong <e@80x24.org>
Sun, 1 Oct 2023 09:54:19 +0000 (09:54 +0000)
committerEric Wong <e@80x24.org>
Sun, 1 Oct 2023 22:41:42 +0000 (22:41 +0000)
If a user is relying on reference counts to invalidate FDs
(as we do in many places), rely on them instead of explicit
`close'.  This forces us to do a better job of managing refs
and avoiding redundant fields which make our code more fragile.

lib/PublicInbox/ProcessPipe.pm

index 16971801947dcedd168c828722c8f90b89a4b39f..ba2c1ecb9662cc58f3eec089c051e20faae0e098 100644 (file)
@@ -58,7 +58,7 @@ sub FILENO { fileno($_[0]->{fh}) }
 sub _close ($;$) {
        my ($self, $wait) = @_;
        my ($fh, $pid) = delete(@$self{qw(fh pid)});
-       my $ret = defined($fh) ? close($fh) : '';
+       my $ret = (defined($fh) && $wait) ? close($fh) : ($fh = '');
        return $ret unless defined($pid) && $self->{ppid} == $$;
        if ($wait) { # caller cares about the exit status:
                # synchronous wait via defined(wantarray) on awaitpid: