Code

fetch: do not leak a refspec
[git.git] / run-command.c
index 61b153987b0efb9d9c5c53e2a4aa6893a9362f01..70e8a249d0fe07b6a32b4da4ac8224d1c2f06b1b 100644 (file)
@@ -67,7 +67,12 @@ static int child_notifier = -1;
 
 static void notify_parent(void)
 {
-       write(child_notifier, "", 1);
+       /*
+        * execvp failed.  If possible, we'd like to let start_command
+        * know, so failures like ENOENT can be handled right away; but
+        * otherwise, finish_command will still report the error.
+        */
+       xwrite(child_notifier, "", 1);
 }
 
 static NORETURN void die_child(const char *err, va_list params)
@@ -77,9 +82,9 @@ static NORETURN void die_child(const char *err, va_list params)
        if (len > sizeof(msg))
                len = sizeof(msg);
 
-       write(child_err, "fatal: ", 7);
-       write(child_err, msg, len);
-       write(child_err, "\n", 1);
+       write_in_full(child_err, "fatal: ", 7);
+       write_in_full(child_err, msg, len);
+       write_in_full(child_err, "\n", 1);
        exit(128);
 }
 #endif
@@ -192,6 +197,7 @@ fail_pipe:
        }
 
        trace_argv_printf(cmd->argv, "trace: run_command:");
+       fflush(NULL);
 
 #ifndef WIN32
 {
@@ -199,7 +205,6 @@ fail_pipe:
        if (pipe(notify_pipe))
                notify_pipe[0] = notify_pipe[1] = -1;
 
-       fflush(NULL);
        cmd->pid = fork();
        if (!cmd->pid) {
                /*
@@ -340,8 +345,6 @@ fail_pipe:
        else if (cmd->out > 1)
                fhout = dup(cmd->out);
 
-       if (cmd->dir)
-               die("chdir in start_command() not implemented");
        if (cmd->env)
                env = make_augmented_environ(cmd->env);
 
@@ -351,7 +354,7 @@ fail_pipe:
                cmd->argv = prepare_shell_cmd(cmd->argv);
        }
 
-       cmd->pid = mingw_spawnvpe(cmd->argv[0], cmd->argv, env,
+       cmd->pid = mingw_spawnvpe(cmd->argv[0], cmd->argv, env, cmd->dir,
                                  fhin, fhout, fherr);
        failed_errno = errno;
        if (cmd->pid < 0 && (!cmd->silent_exec_failure || errno != ENOENT))
@@ -383,6 +386,8 @@ fail_pipe:
                        close(cmd->out);
                if (need_err)
                        close_pair(fderr);
+               else if (cmd->err)
+                       close(cmd->err);
                errno = failed_errno;
                return -1;
        }