]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Gcf2Client.pm
update copyrights for 2021
[public-inbox.git] / lib / PublicInbox / Gcf2Client.pm
index 10820852b21d02761a49048b1dc31e8bc9f597cd..2022293d6b0a4684c6d72adf74e6413a426fc0bf 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2020 all contributors <meta@public-inbox.org>
+# Copyright (C) 2020-2021 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 
 # connects public-inbox processes to PublicInbox::Gcf2::loop()
@@ -15,6 +15,7 @@ use PublicInbox::DS qw(dwaitpid);
 #      sock => writable pipe to Gcf2::loop
 #      in => pipe we read from
 #      pid => PID of Gcf2::loop process
+#      owner_pid => process which spawned {pid}
 sub new  {
        my ($rdr) = @_;
        my $self = bless {}, __PACKAGE__;
@@ -25,6 +26,7 @@ sub new  {
        $rdr //= {};
        $rdr->{0} = $out_r;
        my $cmd = [$^X, qw[-MPublicInbox::Gcf2 -e PublicInbox::Gcf2::loop()]];
+       $self->{owner_pid} = $$;
        @$self{qw(in pid)} = popen_rd($cmd, $env, $rdr);
        fcntl($out_w, 1031, 4096) if $^O eq 'linux'; # 1031: F_SETPIPE_SZ
        $out_w->autoflush(1);
@@ -69,8 +71,10 @@ sub DESTROY {
        delete $self->{in};
        # GitAsyncCat::event_step may reap us with WNOHANG, too
        my $pid = delete $self->{pid} or return;
-       PublicInbox::DS->in_loop ? $self->close : delete($self->{sock});
-       dwaitpid $pid;
+       if ($$ == $self->{owner_pid}) {
+               PublicInbox::DS->in_loop ? $self->close : delete($self->{sock});
+               dwaitpid $pid;
+       }
 }
 
 # used by GitAsyncCat