5 #include <sys/socket.h>
9 #define COMMAND_SIZE 4096
11 int setup_connection(int *fd_in, int *fd_out, char *remote_prog,
12 char *url, int rmt_argc, char **rmt_argv)
17 char command[COMMAND_SIZE];
21 if (!strcmp(url, "-")) {
27 host = strstr(url, "//");
29 return error("Bad URL: %s", url);
32 path = strchr(host, '/');
34 return error("Bad URL: %s", url);
37 /* ssh <host> 'cd /<path>; stdio-pull <arg...> <commit-id>' */
38 snprintf(command, COMMAND_SIZE,
39 "cd /%s; %s=objects %s",
40 path, DB_ENVIRONMENT, remote_prog);
41 posn = command + strlen(command);
42 for (i = 0; i < rmt_argc; i++) {
44 strncpy(posn, rmt_argv[i], COMMAND_SIZE - (posn - command));
45 posn += strlen(rmt_argv[i]);
46 if (posn - command + 4 >= COMMAND_SIZE) {
47 return error("Command line too long");
51 if (socketpair(AF_UNIX, SOCK_STREAM, 0, sv)) {
52 return error("Couldn't create socket");
58 execlp("ssh", "ssh", host, command, NULL);