All of lore.kernel.org
 help / color / mirror / Atom feed
From: Abhijit Menon-Sen <ams@toroid.org>
To: Junio C Hamano <gitster@pobox.com>
Cc: Petr Baudis <pasky@suse.cz>, git@vger.kernel.org
Subject: [PATCH] Git.pm: localise $? in command_close_bidi_pipe()
Date: Mon, 4 Aug 2008 17:08:27 +0530	[thread overview]
Message-ID: <20080804113827.GA1239@toroid.org> (raw)
In-Reply-To: <7vhca12n2l.fsf@gitster.siamese.dyndns.org>

Git::DESTROY calls _close_cat_blob and _close_hash_and_insert_object,
which in turn call command_close_bidi_pipe, which calls waitpid, which
alters $?. If this happens during global destruction, it may alter the
program's exit status unexpectedly. Making $? local to the function
solves the problem.

(The problem was discovered due to a failure of test #8 in
t9106-git-svn-commit-diff-clobber.sh.)

Signed-off-by: Abhijit Menon-Sen <ams@toroid.org>
---

At 2008-08-04 01:37:06 -0700, gitster@pobox.com wrote:
>
> After queueing it, I actually had to revert it, because it seems to
> break git-svn (t9106-git-svn-commit-diff-clobber.sh, test #8), and I
> am about to go to bed.

This patch in addition to my earlier one should solve the problem.

For test #8 to fail, the "git svn dcommit" must succeed, but in both
cases (i.e. without my patch applied, or with), the rebase fails:

    rebase refs/remotes/git-svn: command returned error: 1

This results in a call to "fatal $@" on git-svn.perl:254, which calls
"exit 1", and test_must_fail is happy.

With my patch, however, Git::DESTROY calls the two _close functions
during global destruction, which in turn call command_close_bidi_pipe,
which calls waitpid with sensible arguments this time, which alters $?,
thus altering the exit status of the dcommit itself to 0. Oops.

All of "make test" passes for me after this change.

-- ams

 perl/Git.pm |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/perl/Git.pm b/perl/Git.pm
index 2ef437f..3b6707b 100644
--- a/perl/Git.pm
+++ b/perl/Git.pm
@@ -417,6 +417,7 @@ have more complicated structure.
 =cut
 
 sub command_close_bidi_pipe {
+	local $?;
 	my ($pid, $in, $out, $ctx) = @_;
 	foreach my $fh ($in, $out) {
 		unless (close $fh) {
-- 
1.6.0.rc0.43.g2aa74

  reply	other threads:[~2008-08-04 11:39 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-04  4:49 [git/perl] unusual syntax? Ray Chuan
2008-08-04  5:02 ` [PATCH] Fix hash slice syntax error Abhijit Menon-Sen
2008-08-04  7:56 ` [PATCH] Git.pm: Fix internal git_command_bidi_pipe() users Petr Baudis
2008-08-04  8:05   ` Junio C Hamano
2008-08-04  8:21     ` Petr Baudis
2008-08-04  8:37       ` Junio C Hamano
2008-08-04 11:38         ` Abhijit Menon-Sen [this message]
2008-08-05  6:12           ` [PATCH] Git.pm: localise $? in command_close_bidi_pipe() Junio C Hamano
2008-08-04 15:01 ` [git/perl] unusual syntax? David Christensen

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080804113827.GA1239@toroid.org \
    --to=ams@toroid.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=pasky@suse.cz \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.