Use run_command for proxy connections

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
Shawn O. Pearce 2007-03-12 19:00:19 -04:00 committed by Junio C Hamano
parent df91ba36b1
commit 15a1c01263

View File

@ -3,6 +3,7 @@
#include "pkt-line.h" #include "pkt-line.h"
#include "quote.h" #include "quote.h"
#include "refs.h" #include "refs.h"
#include "run-command.h"
static char *server_capabilities; static char *server_capabilities;
@ -598,8 +599,8 @@ static void git_proxy_connect(int fd[2], char *host)
{ {
const char *port = STR(DEFAULT_GIT_PORT); const char *port = STR(DEFAULT_GIT_PORT);
char *colon, *end; char *colon, *end;
int pipefd[2][2]; const char *argv[4];
pid_t pid; struct child_process proxy;
if (host[0] == '[') { if (host[0] == '[') {
end = strchr(host + 1, ']'); end = strchr(host + 1, ']');
@ -618,25 +619,18 @@ static void git_proxy_connect(int fd[2], char *host)
port = colon + 1; port = colon + 1;
} }
if (pipe(pipefd[0]) < 0 || pipe(pipefd[1]) < 0) argv[0] = git_proxy_command;
die("unable to create pipe pair for communication"); argv[1] = host;
pid = fork(); argv[2] = port;
if (!pid) { argv[3] = NULL;
dup2(pipefd[1][0], 0); memset(&proxy, 0, sizeof(proxy));
dup2(pipefd[0][1], 1); proxy.argv = argv;
close(pipefd[0][0]); proxy.in = -1;
close(pipefd[0][1]); proxy.out = -1;
close(pipefd[1][0]); if (start_command(&proxy))
close(pipefd[1][1]); die("cannot start proxy %s", argv[0]);
execlp(git_proxy_command, git_proxy_command, host, port, NULL); fd[0] = proxy.out; /* read from proxy stdout */
die("exec failed"); fd[1] = proxy.in; /* write to proxy stdin */
}
if (pid < 0)
die("fork failed");
fd[0] = pipefd[0][0];
fd[1] = pipefd[1][1];
close(pipefd[0][1]);
close(pipefd[1][0]);
} }
#define MAX_CMD_LEN 1024 #define MAX_CMD_LEN 1024