X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FProcessPipe.pm;h=2ce7eb8f46d71e5c3b2cd84d8147d32ca253232c;hb=0d38f65c490466837ae091afa7a7b6f59d04ce7c;hp=7bb6ddee40b1728e8a082b2a48353522cd03108a;hpb=3d41aa23f35501ca92aab8aa42980fa73f7fa74f;p=public-inbox.git
diff --git a/lib/PublicInbox/ProcessPipe.pm b/lib/PublicInbox/ProcessPipe.pm
index 7bb6ddee..2ce7eb8f 100644
--- a/lib/PublicInbox/ProcessPipe.pm
+++ b/lib/PublicInbox/ProcessPipe.pm
@@ -1,4 +1,4 @@
-# Copyright (C) 2016-2018 all contributors
+# Copyright (C) 2016-2020 all contributors
# License: AGPL-3.0+
# a tied handle for auto reaping of children tied to a pipe, see perltie(1)
@@ -11,7 +11,7 @@ sub TIEHANDLE {
bless { pid => $pid, fh => $fh }, $class;
}
-sub READ { sysread($_[0]->{fh}, $_[1], $_[2], $_[3] || 0) }
+sub READ { read($_[0]->{fh}, $_[1], $_[2], $_[3] || 0) }
sub READLINE { readline($_[0]->{fh}) }
@@ -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;
}