Skip to content

Commit

Permalink
start_command: close cmd->err descriptor when fork/spawn fails
Browse files Browse the repository at this point in the history
Fix the problem where the cmd->err passed into start_command wasn't
being properly closed when certain types of errors occurr.  (Compare
the affected code with the clean shutdown code later in the function.)

On Windows, this problem would be triggered if mingw_spawnvpe()
failed, which would happen if the command to be executed was malformed
(e.g. a text file that didn't start with a #! line).  If cmd->err was
a pipe, the failure to close it could result in a hang while the other
side was waiting (forever) for either input or pipe close, e.g. while
trying to shove the output into the side band.  On msysGit, this
problem was causing a hang in t5516-fetch-push.

[J6t: With a slight adjustment of the test case, the hang is also
observed on Linux.]

Signed-off-by: bert Dvornik <dvornik+git@gmail.com>
Signed-off-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
bert Dvornik authored and Junio C Hamano committed May 20, 2010
1 parent 60890cc commit fc012c2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions run-command.c
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,8 @@ int start_command(struct child_process *cmd)
close(cmd->out);
if (need_err)
close_pair(fderr);
else if (cmd->err)
close(cmd->err);
errno = failed_errno;
return -1;
}
Expand Down
2 changes: 1 addition & 1 deletion t/t5516-fetch-push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ test_expect_success 'push does not update local refs on failure' '
mk_test heads/master &&
mk_child child &&
mkdir testrepo/.git/hooks &&
echo exit 1 >testrepo/.git/hooks/pre-receive &&
echo "#!/no/frobnication/today" >testrepo/.git/hooks/pre-receive &&
chmod +x testrepo/.git/hooks/pre-receive &&
(cd child &&
git pull .. master
Expand Down

0 comments on commit fc012c2

Please sign in to comment.