From ebf0acfefa318b8404f30bb69008183478640f0e Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 1 Mar 2016 04:15:59 +0000 Subject: processpipe: preserve native close behavior 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 | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'lib') 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} } -- cgit v1.2.3-24-ge0c7