Browse Source

Use start_comand() in builtin-fetch-pack.c instead of explicit fork/exec.

Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
maint
Johannes Sixt 18 years ago committed by Shawn O. Pearce
parent
commit
477822c35d
  1. 56
      builtin-fetch-pack.c

56
builtin-fetch-pack.c

@ -7,6 +7,7 @@ @@ -7,6 +7,7 @@
#include "pack.h"
#include "sideband.h"
#include "fetch-pack.h"
#include "run-command.h"

static int transfer_unpack_limit = -1;
static int fetch_unpack_limit = -1;
@ -491,18 +492,19 @@ static pid_t setup_sideband(int fd[2], int xd[2]) @@ -491,18 +492,19 @@ static pid_t setup_sideband(int fd[2], int xd[2])

static int get_pack(int xd[2], char **pack_lockfile)
{
int status;
pid_t pid, side_pid;
pid_t side_pid;
int fd[2];
const char *argv[20];
char keep_arg[256];
char hdr_arg[256];
const char **av;
int do_keep = args.keep_pack;
int keep_pipe[2];
struct child_process cmd;

side_pid = setup_sideband(fd, xd);

memset(&cmd, 0, sizeof(cmd));
cmd.argv = argv;
av = argv;
*hdr_arg = 0;
if (!args.keep_pack && unpack_limit) {
@ -519,8 +521,8 @@ static int get_pack(int xd[2], char **pack_lockfile) @@ -519,8 +521,8 @@ static int get_pack(int xd[2], char **pack_lockfile)
}

if (do_keep) {
if (pack_lockfile && pipe(keep_pipe))
die("fetch-pack: pipe setup failure: %s", strerror(errno));
if (pack_lockfile)
cmd.out = -1;
*av++ = "index-pack";
*av++ = "--stdin";
if (!args.quiet && !args.no_progress)
@ -544,43 +546,17 @@ static int get_pack(int xd[2], char **pack_lockfile) @@ -544,43 +546,17 @@ static int get_pack(int xd[2], char **pack_lockfile)
*av++ = hdr_arg;
*av++ = NULL;

pid = fork();
if (pid < 0)
cmd.in = fd[0];
cmd.git_cmd = 1;
if (start_command(&cmd))
die("fetch-pack: unable to fork off %s", argv[0]);
if (!pid) {
dup2(fd[0], 0);
if (do_keep && pack_lockfile) {
dup2(keep_pipe[1], 1);
close(keep_pipe[0]);
close(keep_pipe[1]);
}
close(fd[0]);
close(fd[1]);
execv_git_cmd(argv);
die("%s exec failed", argv[0]);
}
close(fd[0]);
close(fd[1]);
if (do_keep && pack_lockfile) {
close(keep_pipe[1]);
*pack_lockfile = index_pack_lockfile(keep_pipe[0]);
close(keep_pipe[0]);
}
while (waitpid(pid, &status, 0) < 0) {
if (errno != EINTR)
die("waiting for %s: %s", argv[0], strerror(errno));
}
if (WIFEXITED(status)) {
int code = WEXITSTATUS(status);
if (code)
die("%s died with error code %d", argv[0], code);
return 0;
}
if (WIFSIGNALED(status)) {
int sig = WTERMSIG(status);
die("%s died of signal %d", argv[0], sig);
}
die("%s died of unnatural causes %d", argv[0], status);
if (do_keep && pack_lockfile)
*pack_lockfile = index_pack_lockfile(cmd.out);

if (finish_command(&cmd))
die("%s failed", argv[0]);
return 0;
}

static struct ref *do_fetch_pack(int fd[2],

Loading…
Cancel
Save