{"thread":{"id":"7222","subject":"[PATCH 4/7] Use run_command for proxy connections","startedAt":"2007-03-12T23:00:19Z","lastAt":"2007-03-12T23:00:19Z","messageCount":1,"participants":["Shawn O. Pearce"],"isPatch":true,"patchVersion":1,"patchTotal":7},"messages":[{"id":"36968","messageId":"20070312230019.GD16840@spearce.org","threadId":"7222","inReplyTo":null,"subject":"[PATCH 4/7] Use run_command for proxy connections","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2007-03-12T23:00:19Z","receivedAt":"2007-03-12T23:00:19Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Signed-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n connect.c |   36 +++++++++++++++---------------------\n 1 files changed, 15 insertions(+), 21 deletions(-)\n\ndiff --git a/connect.c b/connect.c\nindex 8a8a13b..5048653 100644\n--- a/connect.c\n+++ b/connect.c\n@@ -3,6 +3,7 @@\n #include \"pkt-line.h\"\n #include \"quote.h\"\n #include \"refs.h\"\n+#include \"run-command.h\"\n \n static char *server_capabilities;\n \n@@ -598,8 +599,8 @@ static void git_proxy_connect(int fd[2], char *host)\n {\n \tconst char *port = STR(DEFAULT_GIT_PORT);\n \tchar *colon, *end;\n-\tint pipefd[2][2];\n-\tpid_t pid;\n+\tconst char *argv[4];\n+\tstruct child_process proxy;\n \n \tif (host[0] == '[') {\n \t\tend = strchr(host + 1, ']');\n@@ -618,25 +619,18 @@ static void git_proxy_connect(int fd[2], char *host)\n \t\tport = colon + 1;\n \t}\n \n-\tif (pipe(pipefd[0]) < 0 || pipe(pipefd[1]) < 0)\n-\t\tdie(\"unable to create pipe pair for communication\");\n-\tpid = fork();\n-\tif (!pid) {\n-\t\tdup2(pipefd[1][0], 0);\n-\t\tdup2(pipefd[0][1], 1);\n-\t\tclose(pipefd[0][0]);\n-\t\tclose(pipefd[0][1]);\n-\t\tclose(pipefd[1][0]);\n-\t\tclose(pipefd[1][1]);\n-\t\texeclp(git_proxy_command, git_proxy_command, host, port, NULL);\n-\t\tdie(\"exec failed\");\n-\t}\n-\tif (pid < 0)\n-\t\tdie(\"fork failed\");\n-\tfd[0] = pipefd[0][0];\n-\tfd[1] = pipefd[1][1];\n-\tclose(pipefd[0][1]);\n-\tclose(pipefd[1][0]);\n+\targv[0] = git_proxy_command;\n+\targv[1] = host;\n+\targv[2] = port;\n+\targv[3] = NULL;\n+\tmemset(&proxy, 0, sizeof(proxy));\n+\tproxy.argv = argv;\n+\tproxy.in = -1;\n+\tproxy.out = -1;\n+\tif (start_command(&proxy))\n+\t\tdie(\"cannot start proxy %s\", argv[0]);\n+\tfd[0] = proxy.out; /* read from proxy stdout */\n+\tfd[1] = proxy.in;  /* write to proxy stdin */\n }\n \n #define MAX_CMD_LEN 1024\n-- \n1.5.0.3.985.gcf0b4\n"}]}