git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Git.pm: localise $? in command_close_bidi_pipe()

From
AMAbhijit Menon-Sen <ams@toroid.org>
Date
Aug 4, 2008, 11:38 UTC
Message-ID
<20080804113827.GA1239@toroid.org>
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
Previous: Junio C HamanoNext: Junio C Hamano
Message 7 of 9 in “[git/perl] unusual syntax?”
  1. Ray ChuanAug 4, 2008
  2. Fix hash slice syntax errorAbhijit Menon-Sen, Aug 4, 2008
  3. Git.pm: Fix internal git_command_bidi_pipe() usersPetr Baudis, Aug 4, 2008
  4. Junio C HamanoAug 4, 2008
  5. Petr BaudisAug 4, 2008
  6. Junio C HamanoAug 4, 2008
  7. Git.pm: localise $? in command_close_bidi_pipe()Abhijit Menon-Sen, Aug 4, 2008
  8. Junio C HamanoAug 5, 2008
  9. David ChristensenAug 4, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.