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
];
52 if (!strcmp(url
, "-")) {
58 host
= strstr(url
, "//");
61 path
= strchr(host
, '/');
64 path
= strchr(host
, ':');
69 return error("Bad URL: %s", url
);
71 /* $GIT_RSH <host> "env GIR_DIR=<path> <remote_prog> <args...>" */
75 of
|= add_to_string(&posn
, &sizen
, "env ", 0);
76 of
|= add_to_string(&posn
, &sizen
, GIT_DIR_ENVIRONMENT
"=", 0);
77 of
|= add_to_string(&posn
, &sizen
, path
, 1);
78 of
|= add_to_string(&posn
, &sizen
, " ", 0);
79 of
|= add_to_string(&posn
, &sizen
, remote_prog
, 1);
81 for ( i
= 0 ; i
< rmt_argc
; i
++ ) {
82 of
|= add_to_string(&posn
, &sizen
, " ", 0);
83 of
|= add_to_string(&posn
, &sizen
, rmt_argv
[i
], 1);
86 of
|= add_to_string(&posn
, &sizen
, " -", 0);
89 return error("Command line too long");
91 if (socketpair(AF_UNIX
, SOCK_STREAM
, 0, sv
))
92 return error("Couldn't create socket");
95 const char *ssh
, *ssh_basename
;
96 ssh
= getenv("GIT_SSH");
97 if (!ssh
) ssh
= "ssh";
98 ssh_basename
= strrchr(ssh
, '/');
106 execlp(ssh
, ssh_basename
, host
, command
, NULL
);