From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-2.9 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00 shortcircuit=no autolearn=unavailable version=3.3.2 X-Original-To: meta@public-inbox.org Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 24716200FF for ; Fri, 25 Sep 2015 02:28:00 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 6/8] git: signal-safety for pipe writes Date: Fri, 25 Sep 2015 02:27:55 +0000 Message-Id: <20150925022757.6915-7-e@80x24.org> In-Reply-To: <20150925022757.6915-1-e@80x24.org> References: <20150925022757.6915-1-e@80x24.org> List-Id: I've yet to hit it, but syswrite has chance of returning EINTR on a blocking pipe. --- lib/PublicInbox/GitCatFile.pm | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/lib/PublicInbox/GitCatFile.pm b/lib/PublicInbox/GitCatFile.pm index 48ae673..3fced28 100644 --- a/lib/PublicInbox/GitCatFile.pm +++ b/lib/PublicInbox/GitCatFile.pm @@ -7,6 +7,7 @@ package PublicInbox::GitCatFile; use strict; use warnings; use POSIX qw(dup2); +require IO::Handle; sub new { my ($class, $git_dir) = @_; @@ -31,6 +32,7 @@ sub _cat_file_begin { } close $out_r or die "close failed: $!\n"; close $in_w or die "close failed: $!\n"; + $out_w->autoflush(1); $self->{in} = $in_r; $self->{out} = $out_w; @@ -40,16 +42,8 @@ sub _cat_file_begin { sub cat_file { my ($self, $object, $sizeref) = @_; - $object .= "\n"; - my $len = length($object); - $self->_cat_file_begin; - my $written = syswrite($self->{out}, $object); - if (!defined $written) { - die "pipe write error: $!\n"; - } elsif ($written != $len) { - die "wrote too little to pipe ($written < $len)\n"; - } + print { $self->{out} } $object, "\n" or die "pipe write error: $!\n"; my $in = $self->{in}; my $head = <$in>; -- EW