3 #include <sys/socket.h>
9 #define COMMAND_SIZE 4096
11 int setup_connection(int *fd_in
, int *fd_out
, const char *remote_prog
,
12 char *url
, int rmt_argc
, char **rmt_argv
)
17 char command
[COMMAND_SIZE
];
24 if (!strcmp(url
, "-")) {
30 host
= strstr(url
, "//");
33 path
= strchr(host
, '/');
36 path
= strchr(host
, ':');
41 return error("Bad URL: %s", url
);
43 /* $GIT_RSH <host> "env GIT_DIR=<path> <remote_prog> <args...>" */
47 of
|= add_to_string(&posn
, &sizen
, "env ", 0);
48 of
|= add_to_string(&posn
, &sizen
, GIT_DIR_ENVIRONMENT
"=", 0);
49 of
|= add_to_string(&posn
, &sizen
, path
, 1);
50 of
|= add_to_string(&posn
, &sizen
, " ", 0);
51 of
|= add_to_string(&posn
, &sizen
, remote_prog
, 1);
53 for ( i
= 0 ; i
< rmt_argc
; i
++ ) {
54 of
|= add_to_string(&posn
, &sizen
, " ", 0);
55 of
|= add_to_string(&posn
, &sizen
, rmt_argv
[i
], 1);
58 of
|= add_to_string(&posn
, &sizen
, " -", 0);
61 return error("Command line too long");
63 if (socketpair(AF_UNIX
, SOCK_STREAM
, 0, sv
))
64 return error("Couldn't create socket");
68 return error("Couldn't fork");
70 const char *ssh
, *ssh_basename
;
71 ssh
= getenv("GIT_SSH");
72 if (!ssh
) ssh
= "ssh";
73 ssh_basename
= strrchr(ssh
, '/');
81 execlp(ssh
, ssh_basename
, host
, command
, NULL
);