From 8f9e40a3964d003f04e56520ad7b18a1abda13c6 Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Mon, 8 Jan 2007 17:49:34 +0100 Subject: [PATCH] Use the spawn workhorse instead of a fork()/exec() pair. --- diff.c | 13 +++---------- merge-index.c | 20 +++----------------- 2 files changed, 6 insertions(+), 27 deletions(-) diff --git a/diff.c b/diff.c index f11a633da5..12161b6f87 100644 --- a/diff.c +++ b/diff.c @@ -8,6 +8,7 @@ #include "delta.h" #include "xdiff-interface.h" #include "color.h" +#include "spawn-pipe.h" #ifdef NO_FAST_WORKING_DIRECTORY #define FAST_WORKING_DIRECTORY 0 @@ -1498,13 +1499,7 @@ static int spawn_prog(const char *pgm, const char **arg) int status; fflush(NULL); - pid = fork(); - if (pid < 0) - die("unable to fork"); - if (!pid) { - execvp(pgm, (char *const*) arg); - exit(255); - } + pid = spawnvpe_pipe(pgm, arg, environ, NULL, NULL); while (waitpid(pid, &status, 0) < 0) { if (errno == EINTR) @@ -1545,7 +1540,7 @@ static void run_external_diff(const char *pgm, int retval; static int atexit_asked = 0; const char *othername; - const char **arg = &spawn_arg[0]; + const char **arg = &spawn_arg[1]; othername = (other? other : name); if (one && two) { @@ -1561,7 +1556,6 @@ static void run_external_diff(const char *pgm, } if (one && two) { - *arg++ = pgm; *arg++ = name; *arg++ = temp[0].name; *arg++ = temp[0].hex; @@ -1574,7 +1568,6 @@ static void run_external_diff(const char *pgm, *arg++ = xfrm_msg; } } else { - *arg++ = pgm; *arg++ = name; } *arg = NULL; diff --git a/merge-index.c b/merge-index.c index a9983dd78a..6c2e00842e 100644 --- a/merge-index.c +++ b/merge-index.c @@ -1,29 +1,16 @@ #include "cache.h" +#include "spawn-pipe.h" static const char *pgm; -static const char *arguments[8]; +static const char *arguments[9]; /* last one is always NULL */ static int one_shot, quiet; static int err; static void run_program(void) { - pid_t pid = fork(); + pid_t pid = spawnvpe_pipe(pgm, arguments, environ, NULL, NULL); int status; - if (pid < 0) - die("unable to fork"); - if (!pid) { - execlp(pgm, arguments[0], - arguments[1], - arguments[2], - arguments[3], - arguments[4], - arguments[5], - arguments[6], - arguments[7], - NULL); - die("unable to execute '%s'", pgm); - } if (waitpid(pid, &status, 0) < 0 || !WIFEXITED(status) || WEXITSTATUS(status)) { if (one_shot) { err++; @@ -41,7 +28,6 @@ static int merge_entry(int pos, const char *path) if (pos >= active_nr) die("git-merge-index: %s not in the cache", path); - arguments[0] = pgm; arguments[1] = ""; arguments[2] = ""; arguments[3] = ""; -- 2.11.4.GIT