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 CF9811F568 for ; Sun, 1 Oct 2023 02:43:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1696128204; bh=pz4TDH+m+EodpJeXHjN4Af71fVvN6U21fXtM8J1QSQw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=2DlNC4iBMSMfmHkTR5jn1pQW/rgKSjJB7b+qsjFRKhCGtYtBFwdE5lAIgk4Z+7EH8 heY1FKcxjY6UjQPZ02ZCBnsEcijudoYm9sGX2MAA7ppLlLrJgFRHLsxuzuhGI63+nP zw1ttgEmwgRkYNyNv0XGcNnKFgE6XOitEfCxcPA4= From: Eric Wong To: spew@80x24.org Subject: [PATCH 06/16] process_pipe: do not run `close' perlop unless requested Date: Sun, 1 Oct 2023 02:43:13 +0000 Message-ID: <20231001024323.1960491-6-e@80x24.org> In-Reply-To: <20231001024323.1960491-1-e@80x24.org> References: <20231001024323.1960491-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: