3 #include <sys/socket.h>
9 #define COMMAND_SIZE 4096
12 * Append a string to a string buffer, with or without shell quoting.
13 * Return true if the buffer overflowed.
15 static int add_to_string(char **ptrp, int *sizep, const char *str, int quote)
23 oc = sq_quote_buf(p, size, str);
26 memcpy(p, str, (oc >= size) ? size-1 : oc);
40 int setup_connection(int *fd_in, int *fd_out, const char *remote_prog,
41 char *url, int rmt_argc, char **rmt_argv)
46 char command[COMMAND_SIZE];
53 if (!strcmp(url, "-")) {
59 host = strstr(url, "//");
62 path = strchr(host, '/');
65 path = strchr(host, ':');
70 return error("Bad URL: %s", url);
72 /* $GIT_RSH <host> "env GIT_DIR=<path> <remote_prog> <args...>" */
76 of |= add_to_string(&posn, &sizen, "env ", 0);
77 of |= add_to_string(&posn, &sizen, GIT_DIR_ENVIRONMENT "=", 0);
78 of |= add_to_string(&posn, &sizen, path, 1);
79 of |= add_to_string(&posn, &sizen, " ", 0);
80 of |= add_to_string(&posn, &sizen, remote_prog, 1);
82 for ( i = 0 ; i < rmt_argc ; i++ ) {
83 of |= add_to_string(&posn, &sizen, " ", 0);
84 of |= add_to_string(&posn, &sizen, rmt_argv[i], 1);
87 of |= add_to_string(&posn, &sizen, " -", 0);
90 return error("Command line too long");
92 if (socketpair(AF_UNIX, SOCK_STREAM, 0, sv))
93 return error("Couldn't create socket");
97 return error("Couldn't fork");
99 const char *ssh, *ssh_basename;
100 ssh = getenv("GIT_SSH");
101 if (!ssh) ssh = "ssh";
102 ssh_basename = strrchr(ssh, '/');
110 execlp(ssh, ssh_basename, host, command, NULL);