From: Tomi Ollila Date: Sun, 1 Apr 2012 18:28:42 +0000 (+0300) Subject: [PATCH] nmbug: check whether every forked process exit with (non)zero value X-Git-Url: http://git.tremily.us/gitweb.cgi?a=commitdiff_plain;h=e441c4682fb6b076b9cb96fca494b93596cd7aac;p=notmuch-archives.git [PATCH] nmbug: check whether every forked process exit with (non)zero value --- diff --git a/4d/95e0078424db6da10329fceab075d1833bf9b9 b/4d/95e0078424db6da10329fceab075d1833bf9b9 new file mode 100644 index 000000000..ff17f93aa --- /dev/null +++ b/4d/95e0078424db6da10329fceab075d1833bf9b9 @@ -0,0 +1,160 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 765EB429E54 + for ; Sun, 1 Apr 2012 11:28:47 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: 0 +X-Spam-Level: +X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] + autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id Yp9cGc0CS2Z6 for ; + Sun, 1 Apr 2012 11:28:46 -0700 (PDT) +Received: from guru.guru-group.fi (guru-group.fi [87.108.86.66]) + by olra.theworths.org (Postfix) with ESMTP id 578CF431FAF + for ; Sun, 1 Apr 2012 11:28:46 -0700 (PDT) +Received: by guru.guru-group.fi (Postfix, from userid 501) + id 1AB9668055; Sun, 1 Apr 2012 21:28:44 +0300 (EEST) +From: Tomi Ollila +To: notmuch@notmuchmail.org +Subject: [PATCH] nmbug: check whether every forked process exit with (non)zero + value +Date: Sun, 1 Apr 2012 21:28:42 +0300 +Message-Id: <1333304922-30681-1-git-send-email-tomi.ollila@iki.fi> +X-Mailer: git-send-email 1.7.6.1 +In-Reply-To: <1333195960-31359-1-git-send-email-david@tethera.net> +References: <1333195960-31359-1-git-send-email-david@tethera.net> +Cc: Tomi Ollila +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Sun, 01 Apr 2012 18:28:47 -0000 + +If any of the forked process exits with nonzero value, terminate +current operation -- nonzero exit value indicates failure and +then there is no point continuing. +--- + + I tested this by using most of the commands (pushed few tags in + addtion to pull, log, status & checkout). I haven't encountered + any failures yet in real environment but mangling nmbug to fail + does make it fail as expected (s/git/false/ or s/exec @_/exit 1/ + -- exit ! close $fh could not be tested as there is currently + no code paths to arrive there). + + contrib/nmbug | 37 ++++++++++++++++++++++++++++++++----- + 1 files changed, 32 insertions(+), 5 deletions(-) + +diff --git a/contrib/nmbug b/contrib/nmbug +index bb0739f..f003ef9 100755 +--- a/contrib/nmbug ++++ b/contrib/nmbug +@@ -60,6 +60,9 @@ sub git_pipe { + sub git { + my $fh = git_pipe (@_); + my $str = join ('', <$fh>); ++ unless (close $fh) { ++ die "'git @_' exited with nonzero value\n"; ++ } + chomp($str); + return $str; + } +@@ -84,7 +87,7 @@ sub spawn { + foreach my $line (@{$ioref}) { + print $fh $line, "\n"; + } +- exit 0; ++ exit ! close $fh; + } else { + if ($dir ne '|-') { + open STDIN, '<', '/dev/null' or die "reopening stdin: $!" +@@ -106,6 +109,9 @@ sub get_tags { + chomp (); + push @tags, $_ if (m/^$prefix/); + } ++ unless (close $fh) { ++ die "'notmuch search --output=tags *' exited with nonzero value\n"; ++ } + return @tags; + } + +@@ -173,6 +179,10 @@ sub update_index { + foreach my $pair (@{$status->{added}}) { + index_tags_for_msg ($git, $pair->{id}, 'A', $pair->{tag}); + } ++ unless (close $git) { ++ die "'git update-index --index-info' exited with nonzero value\n"; ++ } ++ + } + + +@@ -211,8 +221,12 @@ sub index_tags { + my @tags = grep { s/^$TAGPREFIX//; } split (' ', $rest); + index_tags_for_msg ($git,$id, 'A', @tags); + } +- +- close $git; ++ unless (close $git) { ++ die "'git update-index --index-info' exited with nonzero value\n"; ++ } ++ unless (close $fh) { ++ die "'notmuch dump -- $query' exited with nonzero value\n"; ++ } + return $index; + } + +@@ -395,6 +409,9 @@ sub compute_status { + } else { + push @deleted, $pair; + } ++ unless (close $fh) { ++ die "'notmuch search --output=files id:$id' exited with nonzero value\n"; ++ } + } + + +@@ -414,7 +431,12 @@ sub diff_index { + qw/diff-index --cached/, + "--diff-filter=$filter", qw/--name-only HEAD/ ); + +- return unpack_diff_lines ($fh); ++ my @lines = unpack_diff_lines ($fh); ++ unless (close $fh) { ++ die "'git diff-index --cached --diff-filter=$filter --name-only HEAD' ", ++ "exited with nonzero value\n"; ++ } ++ return @lines; + } + + +@@ -426,7 +448,12 @@ sub diff_refs { + my $fh= git_pipe ( 'diff', "--diff-filter=$filter", '--name-only', + $ref1, $ref2); + +- return unpack_diff_lines ($fh); ++ my @lines = unpack_diff_lines ($fh); ++ unless (close $fh) { ++ die "'git diff --diff-filter=$filter --name-only $ref1 $ref2' ", ++ "exited with nonzero value\n"; ++ } ++ return @lines; + } + + +-- +1.7.8.2 +