]> Sergey Matveev's repositories - public-inbox.git/commitdiff
processpipe: preserve native close behavior
authorEric Wong <e@80x24.org>
Tue, 1 Mar 2016 04:15:59 +0000 (04:15 +0000)
committerEric Wong <e@80x24.org>
Tue, 1 Mar 2016 04:16:07 +0000 (04:16 +0000)
We need to ensure close on handles tied to this class
get the same errors a normal "close" in Perl gets.

lib/PublicInbox/ProcessPipe.pm

index e088c1053f0b08877a277f281f3192925bac791d..943405ff07bd56692d8919ad3f3537407b7c3643 100644 (file)
@@ -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} }