From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 394E71F566 for ; Sun, 1 Oct 2023 09:54:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1696154070; bh=pz4TDH+m+EodpJeXHjN4Af71fVvN6U21fXtM8J1QSQw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=XWN35mlMNXQ4ywVnls/1HjHoQxVW9j5lwlmEvs+tjikDOiMvzpZcAXuuU9iHTKJZ1 1kwtJCKgpJyOWv/nTKqkhpAXJWQTA5mBu36CWcp0foRmwwZG0W4C4b1hRWUYMlKRTY ddwQUpImTcy45bmz3kdqXUdIcyTLHdtRfY0QHFWg= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 03/13] process_pipe: don't run `close' unless requested Date: Sun, 1 Oct 2023 09:54:19 +0000 Message-ID: <20231001095429.2092610-4-e@80x24.org> In-Reply-To: <20231001095429.2092610-1-e@80x24.org> References: <20231001095429.2092610-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/PublicInbox/ProcessPipe.pm b/lib/PublicInbox/ProcessPipe.pm index 16971801..ba2c1ecb 100644 --- a/lib/PublicInbox/ProcessPipe.pm +++ b/lib/PublicInbox/ProcessPipe.pm @@ -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: