run-command: always set failed_errno in start_command
When we fail to fork, we set the failed_errno variable to the value of errno so it is not clobbered by later syscalls. However, we do so in a conditional, and it is hard to see later under what conditions the variable has a valid value. Instead of setting it only when fork fails, let's just always set it after forking. This is more obvious for human readers (as we are no longer setting it as a side effect of a strerror call), and it is more obvious to gcc, which no longer generates a spurious -Wuninitialized warning. It also happens to match what the WIN32 half of the #ifdef does. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Mar 21, 2013 at 11:45 UTC
25043d8aea7859497c12cb035e6688f76e32ac13
1 file changed
+3
-2
run-command.c
+3
-2
@@ -273,7 +273,7 @@ int start_command(struct child_process *cmd)
273
{
274
int need_in, need_out, need_err;
275
int fdin[2], fdout[2], fderr[2];
276
- int failed_errno = failed_errno;
276
+ int failed_errno;
277
char *str;
278
279
/*
@@ -341,6 +341,7 @@ fail_pipe:
341
notify_pipe[0] = notify_pipe[1] = -1;
342
343
cmd->pid = fork();
344
+ failed_errno = errno;
345
if (!cmd->pid) {
346
/*
347
* Redirect the channel to write syscall error messages to
@@ -420,7 +421,7 @@ fail_pipe:
421
}
422
if (cmd->pid < 0)
423
error("cannot fork() for %s: %s", cmd->argv[0],
423
- strerror(failed_errno = errno));
424
+ strerror(errno));
425
else if (cmd->clean_on_exit)
426
mark_child_for_cleanup(cmd->pid);
427