* [PATCH] processpipe: preserve native close behavior
@ 2016-03-01 4:15 Eric Wong
0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2016-03-01 4:15 UTC (permalink / raw)
To: meta
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(-)
diff --git a/lib/PublicInbox/ProcessPipe.pm b/lib/PublicInbox/ProcessPipe.pm
index e088c10..943405f 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} }
--
EW
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2016-03-01 4:15 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-01 4:15 [PATCH] processpipe: preserve native close behavior Eric Wong
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).