Use run_command for proxy connections
Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
Shawn O. Pearce committed
Mar 12, 2007 at 19:00 UTC
15a1c012635f2f57a8f0146e198b5e1334d527cf
1 file changed
+15
-21
connect.c
+15
-21
@@ -3,6 +3,7 @@
3
#include "pkt-line.h"
4
#include "quote.h"
5
#include "refs.h"
6
+#include "run-command.h"
7
8
static char *server_capabilities;
9
@@ -598,8 +599,8 @@ static void git_proxy_connect(int fd[2], char *host)
599
{
600
const char *port = STR(DEFAULT_GIT_PORT);
601
char *colon, *end;
601
- int pipefd[2][2];
602
- pid_t pid;
602
+ const char *argv[4];
603
+ struct child_process proxy;
604
605
if (host[0] == '[') {
606
end = strchr(host + 1, ']');
@@ -618,25 +619,18 @@ static void git_proxy_connect(int fd[2], char *host)
619
port = colon + 1;
620
}
621
621
- if (pipe(pipefd[0]) < 0 || pipe(pipefd[1]) < 0)
622
- die("unable to create pipe pair for communication");
623
- pid = fork();
624
- if (!pid) {
625
- dup2(pipefd[1][0], 0);
626
- dup2(pipefd[0][1], 1);
627
- close(pipefd[0][0]);
628
- close(pipefd[0][1]);
629
- close(pipefd[1][0]);
630
- close(pipefd[1][1]);
631
- execlp(git_proxy_command, git_proxy_command, host, port, NULL);
632
- die("exec failed");
633
- }
634
- if (pid < 0)
635
- die("fork failed");
636
- fd[0] = pipefd[0][0];
637
- fd[1] = pipefd[1][1];
638
- close(pipefd[0][1]);
639
- close(pipefd[1][0]);
622
+ argv[0] = git_proxy_command;
623
+ argv[1] = host;
624
+ argv[2] = port;
625
+ argv[3] = NULL;
626
+ memset(&proxy, 0, sizeof(proxy));
627
+ proxy.argv = argv;
628
+ proxy.in = -1;
629
+ proxy.out = -1;
630
+ if (start_command(&proxy))
631
+ die("cannot start proxy %s", argv[0]);
632
+ fd[0] = proxy.out; /* read from proxy stdout */
633
+ fd[1] = proxy.in; /* write to proxy stdin */
634
}
635
636
#define MAX_CMD_LEN 1024