From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 3B55D1FA19 for ; Sat, 2 Jan 2021 09:13:45 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 6/6] qspawn: switch to ProcessPipe via popen_rd Date: Fri, 1 Jan 2021 19:13:44 -1400 Message-Id: <20210102091344.13477-7-e@80x24.org> In-Reply-To: <20210102091344.13477-1-e@80x24.org> References: <20210102091344.13477-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: ProcessPipe has a built-in mechanism to prevent siblings from reaping children. --- lib/PublicInbox/Qspawn.pm | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/lib/PublicInbox/Qspawn.pm b/lib/PublicInbox/Qspawn.pm index 68b71112..7e50a59a 100644 --- a/lib/PublicInbox/Qspawn.pm +++ b/lib/PublicInbox/Qspawn.pm @@ -28,7 +28,6 @@ package PublicInbox::Qspawn; use strict; use PublicInbox::Spawn qw(popen_rd); use PublicInbox::GzipFilter; -use PublicInbox::DS qw(dwaitpid); # doesn't need event loop # n.b.: we get EAGAIN with public-inbox-httpd, and EINTR on other PSGI servers use Errno qw(EAGAIN EINTR); @@ -58,9 +57,9 @@ sub _do_spawn { $self->{cmd} = $o{quiet} ? undef : $cmd; eval { # popen_rd may die on EMFILE, ENFILE - ($self->{rpipe}, $self->{pid}) = popen_rd($cmd, $cmd_env, \%o); + $self->{rpipe} = popen_rd($cmd, $cmd_env, \%o); - die "E: $!" unless defined($self->{pid}); + die "E: $!" unless defined($self->{rpipe}); $limiter->{running}++; $start_cb->($self); # EPOLL_CTL_ADD may ENOSPC/ENOMEM @@ -117,16 +116,14 @@ sub finalize ($$) { } } -# callback for dwaitpid +# callback for dwaitpid or ProcessPipe sub waitpid_err { finalize($_[0], child_err($?)) } sub finish ($;$) { my ($self, $err) = @_; - if (delete $self->{rpipe}) { - dwaitpid $self->{pid}, \&waitpid_err, $self; - } else { - finalize($self, $err); - } + my $tied_pp = delete($self->{rpipe}) or return finalize($self, $err); + my PublicInbox::ProcessPipe $pp = tied *$tied_pp; + @$pp{qw(cb arg)} = (\&waitpid_err, $self); # for ->DESTROY } sub start ($$$) {