From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH] processpipe: preserve native close behavior
Date: Tue, 1 Mar 2016 04:15:59 +0000 [thread overview]
Message-ID: <20160301041559.25482-1-e@80x24.org> (raw)
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
reply other threads:[~2016-03-01 4:15 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://public-inbox.org/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160301041559.25482-1-e@80x24.org \
--to=e@80x24.org \
--cc=meta@public-inbox.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).