diff options
author | Jeff King <peff@peff.net> | 2013-03-21 11:45:00 -0400 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2013-03-21 14:06:48 -0700 |
commit | 25043d8aea7859497c12cb035e6688f76e32ac13 (patch) | |
tree | 0621e1d54279ecf24e125dd11e93201f6c9f24e2 | |
parent | transport: drop "int cmp = cmp" hack (diff) | |
download | tgif-25043d8aea7859497c12cb035e6688f76e32ac13.tar.xz |
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>
-rw-r--r-- | run-command.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/run-command.c b/run-command.c index 07e27ff4c8..765c2ce056 100644 --- a/run-command.c +++ b/run-command.c @@ -273,7 +273,7 @@ int start_command(struct child_process *cmd) { int need_in, need_out, need_err; int fdin[2], fdout[2], fderr[2]; - int failed_errno = failed_errno; + int failed_errno; char *str; /* @@ -341,6 +341,7 @@ fail_pipe: notify_pipe[0] = notify_pipe[1] = -1; cmd->pid = fork(); + failed_errno = errno; if (!cmd->pid) { /* * Redirect the channel to write syscall error messages to @@ -420,7 +421,7 @@ fail_pipe: } if (cmd->pid < 0) error("cannot fork() for %s: %s", cmd->argv[0], - strerror(failed_errno = errno)); + strerror(errno)); else if (cmd->clean_on_exit) mark_child_for_cleanup(cmd->pid); |