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