]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/ProcessPipe.pm
rename {pi_config} fields to {pi_cfg}
[public-inbox.git] / lib / PublicInbox / ProcessPipe.pm
index 2769e064ca21d1651fbace905a167ba17922802b..2ce7eb8f46d71e5c3b2cd84d8147d32ca253232c 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2016-2018 all contributors <meta@public-inbox.org>
+# Copyright (C) 2016-2020 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 
 # a tied handle for auto reaping of children tied to a pipe, see perltie(1)
@@ -20,8 +20,13 @@ sub CLOSE {
        my $ret = defined $fh ? close($fh) : '';
        my $pid = delete $_[0]->{pid};
        if (defined $pid) {
-               waitpid($pid, 0);
-               $ret = '' if $?;
+               # PublicInbox::DS may not be loaded
+               eval { PublicInbox::DS::dwaitpid($pid, undef, undef) };
+
+               if ($@) { # ok, not in the event loop, work synchronously
+                       waitpid($pid, 0);
+                       $ret = '' if $?;
+               }
        }
        $ret;
 }