dumping ground for random patches and texts
 help / color / mirror / Atom feed
* [PATCH] io: avoid redundant waitpid in DESTROY
@ 2024-04-12 17:39 Eric Wong
  0 siblings, 0 replies; 2+ messages in thread
From: Eric Wong @ 2024-04-12 17:39 UTC (permalink / raw)
  To: spew

We shouldn't attempt to reap a process again after it's been
reaped asynchronously in the SIGCHLD handler.
---
 lib/PublicInbox/IO.pm | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/PublicInbox/IO.pm b/lib/PublicInbox/IO.pm
index 02057600..106489be 100644
--- a/lib/PublicInbox/IO.pm
+++ b/lib/PublicInbox/IO.pm
@@ -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;
 }

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH] io: avoid redundant waitpid in DESTROY
@ 2024-04-12 17:50 Eric Wong
  0 siblings, 0 replies; 2+ messages in thread
From: Eric Wong @ 2024-04-12 17:50 UTC (permalink / raw)
  To: spew

We shouldn't attempt to reap a process again after it's been
reaped asynchronously in the SIGCHLD handler.
---
 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;
 }

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-04-12 17:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-12 17:50 [PATCH] io: avoid redundant waitpid in DESTROY Eric Wong
  -- strict thread matches above, loose matches on Subject: below --
2024-04-12 17:39 Eric Wong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).