Skip to contentSkip to conversation

start_command: close cmd->err descriptor when fork/spawn fails

PATCH In review bert Dvornik 4 participants 6 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 start_command: close cmd->err descriptor when fork/spawn fails

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.

I'm not sure why (or if) this problem hasn't cropped up under Linux. The non-Windows code *does* try to check for execve() failures in the child, in addition to the fork() failures.

---
 run-command.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
run-command.c +2 -0
index d1a8ceb..41666ac 100644
@@ -383,6 +383,8 @@ fail_pipe:
 			close(cmd->out);
 		if (need_err)
 			close_pair(fderr);
+		else if (cmd->err)
+			close(cmd->err);
 		errno = failed_errno;
 		return -1;
 	}
Signature · 1 line
1.7.1.rc1.1794.g4bea1
Acked-by on v1 1/1
#1 lore raw

Am 4/26/2010 3:15, schrieb bert Dvornik:

Quoted 9 lines

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.)

run-command.c +0 -0
index d1a8ceb..41666ac 100644

run-command.c fail_pipe: · line 390

Quoted 8 lines
run-command.c +2 -0
@@ -383,6 +383,8 @@ fail_pipe:
 			close(cmd->out);
 		if (need_err)
 			close_pair(fderr);
+		else if (cmd->err)
+			close(cmd->err);
 		errno = failed_errno;
 		return -1;
 	}

Good catch! This should go on maint (1.7.0).

-- Hannes

#2 lore raw
In reply to bert Dvornik

Am 4/26/2010 3:15, schrieb bert Dvornik:

Quoted 12 lines

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.

Quoted 3 lines

I'm not sure why (or if) this problem hasn't cropped up under Linux. The non-Windows code *does* try to check for execve() failures in the child, in addition to the fork() failures.

The problem does show up on Linux if you trigger the right error, such as with this patch:

t/t5516-fetch-push.sh +2 -1
index 2de98e6..2515a96 100755
@@ -528,7 +528,8 @@ test_expect_success 'push does not update local refs
 	mk_test heads/master &&
 	mk_child child &&
 	mkdir testrepo/.git/hooks &&
-	echo exit 1 >testrepo/.git/hooks/pre-receive &&
+	echo "#!/bin/frobnicuty" >testrepo/.git/hooks/pre-receive &&
+	echo exit 1 >>testrepo/.git/hooks/pre-receive &&
 	chmod +x testrepo/.git/hooks/pre-receive &&
 	(cd child &&
 		git pull .. master
#3 lore raw
Quoted 1 line · Johannes Sixt

Am 4/26/2010 3:15, schrieb bert Dvornik:

[...]

Quoted 6 lines
Quoted 3 lines

I'm not sure why (or if) this problem hasn't cropped up under Linux. The non-Windows code *does* try to check for execve() failures in the child, in addition to the fork() failures.

The problem does show up on Linux if you trigger the right error, such as with this patch:

[...]

Quoted 2 lines

+       echo "#!/bin/frobnicuty" >testrepo/.git/hooks/pre-receive &&
+       echo exit 1 >>testrepo/.git/hooks/pre-receive &&

Ah, that makes sense! Thank you for clearing up the mystery.

Junio: would you like me to resend with an updated commit message, and maybe the addition of Hannes's test as well?

--bert

#4 lore raw
Quoted 2 lines · Albert Dvornik

Junio: would you like me to resend with an updated commit message, and maybe the addition of Hannes's test as well?

I am out of town right now and suspect my mail reception for coming few days would be leaky --- as Dscho seems on top of this series, I suspect that the patch flow would be more reliable if I get your change via a pull request from him when I return.

Thanks.

#5 lore raw
In reply to bert Dvornik

Hi,

Quoted 12 lines · bert Dvornik

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.

Quoted 3 lines

I'm not sure why (or if) this problem hasn't cropped up under Linux. The non-Windows code *does* try to check for execve() failures in the child, in addition to the fork() failures.

Thanks. Both patches applied and pushed to 4msysgit.git.

Ciao,
Dscho