4 #include <sys/socket.h>
8 #define COMMAND_SIZE 4096
10 int setup_connection(int *fd_in
, int *fd_out
, char *remote_prog
,
11 char *url
, int rmt_argc
, char **rmt_argv
)
16 char command
[COMMAND_SIZE
];
20 if (!strcmp(url
, "-")) {
26 host
= strstr(url
, "//");
28 return error("Bad URL: %s", url
);
31 path
= strchr(host
, '/');
33 return error("Bad URL: %s", url
);
36 /* ssh <host> 'cd /<path>; stdio-pull <arg...> <commit-id>' */
37 snprintf(command
, COMMAND_SIZE
,
38 "cd /%s; SHA1_FILE_DIRECTORY=objects %s",
40 posn
= command
+ strlen(command
);
41 for (i
= 0; i
< rmt_argc
; i
++) {
43 strncpy(posn
, rmt_argv
[i
], COMMAND_SIZE
- (posn
- command
));
44 posn
+= strlen(rmt_argv
[i
]);
45 if (posn
- command
+ 4 >= COMMAND_SIZE
) {
46 return error("Command line too long");
50 if (socketpair(AF_LOCAL
, SOCK_STREAM
, 0, sv
)) {
51 return error("Couldn't create socket");
57 execlp("ssh", "ssh", host
, command
, NULL
);