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,AWL,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 CB3F11F51A for ; Fri, 12 Apr 2024 18:04:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1712945054; bh=E7CkoHlEuyMKucUvo4J85rNuOMhGGJRKEXnN4R9yJig=; h=From:To:Subject:Date:In-Reply-To:References:From; b=vLl1RzUNZyTMbodPhS6fOrpywGWUrXxHnDCG/OnYOqL28oNRFKO8sXPtkfNtcLzbR iFdhdnRRAmPorAj4ctZZG58yEvaiRE19pmm978Chr3zwRgXrOEHjpGugYZ4s5ilhCV mbrC9CG/0jt9eRUHxw3Io5DOh6uqvh5a3F3Lw+sU= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 2/3] io: avoid redundant waitpid in DESTROY Date: Fri, 12 Apr 2024 18:04:13 +0000 Message-ID: <20240412180414.2785898-3-e@80x24.org> In-Reply-To: <20240412180414.2785898-1-e@80x24.org> References: <20240412180414.2785898-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: We shouldn't attempt to reap a process again after it's been reaped asynchronously in the SIGCHLD handler. Noticed while working on changes to get lei/store to use checkpointing. --- lib/PublicInbox/IO.pm | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/PublicInbox/IO.pm b/lib/PublicInbox/IO.pm index 02057600..8640f112 100644 --- a/lib/PublicInbox/IO.pm +++ b/lib/PublicInbox/IO.pm @@ -16,7 +16,7 @@ use PublicInbox::OnDestroy; sub waitcb { # awaitpid callback my ($pid, $errref, $cb, @args) = @_; - $$errref = $? if $errref; # sets .cerr for _close + $$errref = $?; # sets .cerr for _close $cb->($pid, @args) if $cb; # may clobber $? } @@ -24,9 +24,9 @@ sub attach_pid { my ($io, $pid, @cb_arg) = @_; bless $io, __PACKAGE__; # we share $err (and not $self) with awaitpid to avoid a ref cycle - ${*$io}{pi_io_reap} = [ $PublicInbox::OnDestroy::fork_gen, - $pid, \(my $err) ]; - awaitpid($pid, \&waitcb, \$err, @cb_arg); + my $e = \(my $err); + ${*$io}{pi_io_reap} = [ $PublicInbox::OnDestroy::fork_gen, $pid, $e ]; + awaitpid($pid, \&waitcb, $e, @cb_arg); $io; } @@ -60,7 +60,7 @@ sub DESTROY { my $reap = delete ${*$io}{pi_io_reap}; if (($reap->[0] // -1) == $PublicInbox::OnDestroy::fork_gen) { $io->SUPER::close; - awaitpid($reap->[1]); + ${$reap->[2]} // awaitpid($reap->[1]); } $io->SUPER::DESTROY; }