about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2016-03-01 04:15:59 +0000
committerEric Wong <e@80x24.org>2016-03-01 04:16:07 +0000
commitebf0acfefa318b8404f30bb69008183478640f0e (patch)
tree62d4fc4a0fe3b5956fc4f1ac7fe86a3cd375e155 /lib
parent472d39de46603b180ab6e739e0b31ab7ef559870 (diff)
downloadpublic-inbox-ebf0acfefa318b8404f30bb69008183478640f0e.tar.gz
We need to ensure close on handles tied to this class
get the same errors a normal "close" in Perl gets.
Diffstat (limited to 'lib')
-rw-r--r--lib/PublicInbox/ProcessPipe.pm15
1 files changed, 12 insertions, 3 deletions
diff --git a/lib/PublicInbox/ProcessPipe.pm b/lib/PublicInbox/ProcessPipe.pm
index e088c105..943405ff 100644
--- a/lib/PublicInbox/ProcessPipe.pm
+++ b/lib/PublicInbox/ProcessPipe.pm
@@ -15,13 +15,22 @@ sub READ { sysread($_[0]->{fh}, $_[1], $_[2], $_[3] || 0) }
 
 sub READLINE { readline($_[0]->{fh}) }
 
-sub CLOSE { delete($_[0]->{fh}) }
+sub CLOSE {
+        my $fh = delete($_[0]->{fh});
+        my $ret = defined $fh ? close($fh) : '';
+        my $pid = delete $_[0]->{pid};
+        if (defined $pid) {
+                waitpid($pid, 0);
+                $ret = '' if $?;
+        }
+        $ret;
+}
 
 sub FILENO { fileno($_[0]->{fh}) }
 
 sub DESTROY {
-        delete($_[0]->{fh});
-        waitpid($_[0]->{pid}, 0);
+        CLOSE(@_);
+        undef;
 }
 
 sub pid { $_[0]->{pid} }