about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2024-04-12 18:04:13 +0000
committerEric Wong <e@80x24.org>2024-04-13 10:06:15 +0000
commit1f17f55af8986d1724f5ea1318207f251d8642a5 (patch)
treec05abd0431e461d2d5f0a8d0238e5545a538fec1 /lib
parent7af35b29074567fcc8c7e59260e72b66ea8c8436 (diff)
downloadpublic-inbox-1f17f55af8986d1724f5ea1318207f251d8642a5.tar.gz
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.
Diffstat (limited to 'lib')
-rw-r--r--lib/PublicInbox/IO.pm10
1 files 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;
 }