Jason Riedy | 731043f | 2006-01-25 12:38:36 -0800 | [diff] [blame] | 1 | #include "git-compat-util.h" |
Linus Torvalds | f719259 | 2005-07-04 11:57:58 -0700 | [diff] [blame] | 2 | #include "cache.h" |
Linus Torvalds | 41cb748 | 2005-07-05 15:44:09 -0700 | [diff] [blame] | 3 | #include "pkt-line.h" |
Junio C Hamano | b10d0ec | 2005-07-08 00:02:52 -0700 | [diff] [blame] | 4 | #include "quote.h" |
Junio C Hamano | 6abf5c0 | 2005-10-16 00:25:26 -0700 | [diff] [blame] | 5 | #include "refs.h" |
Shawn O. Pearce | 15a1c012 | 2007-03-12 19:00:19 -0400 | [diff] [blame] | 6 | #include "run-command.h" |
Daniel Barkalow | 6b62816 | 2007-05-12 11:45:59 -0400 | [diff] [blame] | 7 | #include "remote.h" |
Linus Torvalds | f719259 | 2005-07-04 11:57:58 -0700 | [diff] [blame] | 8 | |
David Rientjes | 96f1e58 | 2006-08-15 10:23:48 -0700 | [diff] [blame] | 9 | static char *server_capabilities; |
Johannes Schindelin | 211b5f9 | 2005-10-28 04:48:54 +0200 | [diff] [blame] | 10 | |
Linus Torvalds | 2718ff0 | 2006-07-04 12:29:10 -0700 | [diff] [blame] | 11 | static int check_ref(const char *name, int len, unsigned int flags) |
| 12 | { |
| 13 | if (!flags) |
| 14 | return 1; |
| 15 | |
Andy Whitcroft | c41e20b | 2006-09-05 20:00:17 +0100 | [diff] [blame] | 16 | if (len < 5 || memcmp(name, "refs/", 5)) |
Linus Torvalds | 2718ff0 | 2006-07-04 12:29:10 -0700 | [diff] [blame] | 17 | return 0; |
| 18 | |
| 19 | /* Skip the "refs/" part */ |
| 20 | name += 5; |
| 21 | len -= 5; |
| 22 | |
| 23 | /* REF_NORMAL means that we don't want the magic fake tag refs */ |
| 24 | if ((flags & REF_NORMAL) && check_ref_format(name) < 0) |
| 25 | return 0; |
| 26 | |
| 27 | /* REF_HEADS means that we want regular branch heads */ |
| 28 | if ((flags & REF_HEADS) && !memcmp(name, "heads/", 6)) |
| 29 | return 1; |
| 30 | |
| 31 | /* REF_TAGS means that we want tags */ |
| 32 | if ((flags & REF_TAGS) && !memcmp(name, "tags/", 5)) |
| 33 | return 1; |
| 34 | |
| 35 | /* All type bits clear means that we are ok with anything */ |
| 36 | return !(flags & ~REF_NORMAL); |
| 37 | } |
| 38 | |
Daniel Barkalow | 4577370 | 2007-10-29 21:05:40 -0400 | [diff] [blame] | 39 | int check_ref_type(const struct ref *ref, int flags) |
| 40 | { |
| 41 | return check_ref(ref->name, strlen(ref->name), flags); |
| 42 | } |
| 43 | |
Linus Torvalds | d1c133f | 2005-07-16 13:55:50 -0700 | [diff] [blame] | 44 | /* |
| 45 | * Read all the refs from the other end |
| 46 | */ |
Junio C Hamano | 1a7141f | 2005-10-13 18:57:40 -0700 | [diff] [blame] | 47 | struct ref **get_remote_heads(int in, struct ref **list, |
Linus Torvalds | 2718ff0 | 2006-07-04 12:29:10 -0700 | [diff] [blame] | 48 | int nr_match, char **match, |
| 49 | unsigned int flags) |
Linus Torvalds | d1c133f | 2005-07-16 13:55:50 -0700 | [diff] [blame] | 50 | { |
| 51 | *list = NULL; |
| 52 | for (;;) { |
| 53 | struct ref *ref; |
| 54 | unsigned char old_sha1[20]; |
| 55 | static char buffer[1000]; |
| 56 | char *name; |
Johannes Schindelin | 211b5f9 | 2005-10-28 04:48:54 +0200 | [diff] [blame] | 57 | int len, name_len; |
Linus Torvalds | d1c133f | 2005-07-16 13:55:50 -0700 | [diff] [blame] | 58 | |
| 59 | len = packet_read_line(in, buffer, sizeof(buffer)); |
| 60 | if (!len) |
| 61 | break; |
| 62 | if (buffer[len-1] == '\n') |
| 63 | buffer[--len] = 0; |
| 64 | |
| 65 | if (len < 42 || get_sha1_hex(buffer, old_sha1) || buffer[40] != ' ') |
| 66 | die("protocol error: expected sha/ref, got '%s'", buffer); |
| 67 | name = buffer + 41; |
Junio C Hamano | 1a7141f | 2005-10-13 18:57:40 -0700 | [diff] [blame] | 68 | |
Johannes Schindelin | 211b5f9 | 2005-10-28 04:48:54 +0200 | [diff] [blame] | 69 | name_len = strlen(name); |
| 70 | if (len != name_len + 41) { |
| 71 | if (server_capabilities) |
| 72 | free(server_capabilities); |
Shawn Pearce | 9befac4 | 2006-09-02 00:16:31 -0400 | [diff] [blame] | 73 | server_capabilities = xstrdup(name + name_len + 1); |
Johannes Schindelin | 211b5f9 | 2005-10-28 04:48:54 +0200 | [diff] [blame] | 74 | } |
| 75 | |
Linus Torvalds | 2718ff0 | 2006-07-04 12:29:10 -0700 | [diff] [blame] | 76 | if (!check_ref(name, name_len, flags)) |
Junio C Hamano | cfee10a | 2005-12-25 23:18:37 -0800 | [diff] [blame] | 77 | continue; |
Linus Torvalds | d1c133f | 2005-07-16 13:55:50 -0700 | [diff] [blame] | 78 | if (nr_match && !path_match(name, nr_match, match)) |
| 79 | continue; |
Junio C Hamano | 90446a0 | 2007-09-28 01:46:13 -0700 | [diff] [blame] | 80 | ref = alloc_ref(name_len + 1); |
Shawn Pearce | e702496 | 2006-08-23 02:49:00 -0400 | [diff] [blame] | 81 | hashcpy(ref->old_sha1, old_sha1); |
Junio C Hamano | 90446a0 | 2007-09-28 01:46:13 -0700 | [diff] [blame] | 82 | memcpy(ref->name, buffer + 41, name_len + 1); |
Linus Torvalds | d1c133f | 2005-07-16 13:55:50 -0700 | [diff] [blame] | 83 | *list = ref; |
| 84 | list = &ref->next; |
| 85 | } |
| 86 | return list; |
| 87 | } |
| 88 | |
Johannes Schindelin | 211b5f9 | 2005-10-28 04:48:54 +0200 | [diff] [blame] | 89 | int server_supports(const char *feature) |
| 90 | { |
Johannes Schindelin | 1f5881b | 2005-10-28 05:56:41 +0200 | [diff] [blame] | 91 | return server_capabilities && |
| 92 | strstr(server_capabilities, feature) != NULL; |
Johannes Schindelin | 211b5f9 | 2005-10-28 04:48:54 +0200 | [diff] [blame] | 93 | } |
| 94 | |
Linus Torvalds | 41cb748 | 2005-07-05 15:44:09 -0700 | [diff] [blame] | 95 | int get_ack(int fd, unsigned char *result_sha1) |
| 96 | { |
| 97 | static char line[1000]; |
| 98 | int len = packet_read_line(fd, line, sizeof(line)); |
| 99 | |
| 100 | if (!len) |
| 101 | die("git-fetch-pack: expected ACK/NAK, got EOF"); |
| 102 | if (line[len-1] == '\n') |
| 103 | line[--len] = 0; |
| 104 | if (!strcmp(line, "NAK")) |
| 105 | return 0; |
Junio C Hamano | cc44c76 | 2007-02-20 01:53:29 -0800 | [diff] [blame] | 106 | if (!prefixcmp(line, "ACK ")) { |
Johannes Schindelin | c4c86f0 | 2005-10-28 04:50:26 +0200 | [diff] [blame] | 107 | if (!get_sha1_hex(line+4, result_sha1)) { |
| 108 | if (strstr(line+45, "continue")) |
| 109 | return 2; |
Linus Torvalds | 41cb748 | 2005-07-05 15:44:09 -0700 | [diff] [blame] | 110 | return 1; |
Johannes Schindelin | c4c86f0 | 2005-10-28 04:50:26 +0200 | [diff] [blame] | 111 | } |
Linus Torvalds | 41cb748 | 2005-07-05 15:44:09 -0700 | [diff] [blame] | 112 | } |
| 113 | die("git-fetch_pack: expected ACK/NAK, got '%s'", line); |
| 114 | } |
| 115 | |
Linus Torvalds | 013e7c7 | 2005-07-04 13:24:30 -0700 | [diff] [blame] | 116 | int path_match(const char *path, int nr, char **match) |
| 117 | { |
| 118 | int i; |
| 119 | int pathlen = strlen(path); |
| 120 | |
| 121 | for (i = 0; i < nr; i++) { |
| 122 | char *s = match[i]; |
| 123 | int len = strlen(s); |
| 124 | |
| 125 | if (!len || len > pathlen) |
| 126 | continue; |
| 127 | if (memcmp(path + pathlen - len, s, len)) |
| 128 | continue; |
| 129 | if (pathlen > len && path[pathlen - len - 1] != '/') |
| 130 | continue; |
| 131 | *s = 0; |
Junio C Hamano | 9546010 | 2006-05-11 15:28:44 -0700 | [diff] [blame] | 132 | return (i + 1); |
Linus Torvalds | 013e7c7 | 2005-07-04 13:24:30 -0700 | [diff] [blame] | 133 | } |
| 134 | return 0; |
| 135 | } |
| 136 | |
Linus Torvalds | 2386d65 | 2005-07-13 18:46:20 -0700 | [diff] [blame] | 137 | enum protocol { |
| 138 | PROTO_LOCAL = 1, |
| 139 | PROTO_SSH, |
| 140 | PROTO_GIT, |
| 141 | }; |
| 142 | |
| 143 | static enum protocol get_protocol(const char *name) |
| 144 | { |
| 145 | if (!strcmp(name, "ssh")) |
| 146 | return PROTO_SSH; |
| 147 | if (!strcmp(name, "git")) |
| 148 | return PROTO_GIT; |
Linus Torvalds | c05186c | 2005-10-14 17:14:56 -0700 | [diff] [blame] | 149 | if (!strcmp(name, "git+ssh")) |
| 150 | return PROTO_SSH; |
| 151 | if (!strcmp(name, "ssh+git")) |
| 152 | return PROTO_SSH; |
Linus Torvalds | 72a4f4b | 2007-08-01 10:03:37 -0700 | [diff] [blame] | 153 | if (!strcmp(name, "file")) |
| 154 | return PROTO_LOCAL; |
Linus Torvalds | 2386d65 | 2005-07-13 18:46:20 -0700 | [diff] [blame] | 155 | die("I don't handle protocol '%s'", name); |
| 156 | } |
| 157 | |
YOSHIFUJI Hideaki | 5ba8844 | 2005-07-21 09:10:36 -0400 | [diff] [blame] | 158 | #define STR_(s) # s |
| 159 | #define STR(s) STR_(s) |
Linus Torvalds | 2386d65 | 2005-07-13 18:46:20 -0700 | [diff] [blame] | 160 | |
hpa | 49744d6 | 2005-09-28 16:52:21 -0700 | [diff] [blame] | 161 | #ifndef NO_IPV6 |
hpa | 4c505f7 | 2005-09-28 16:37:58 -0700 | [diff] [blame] | 162 | |
Alex Riesen | ba50532 | 2007-05-23 23:34:27 +0200 | [diff] [blame] | 163 | static const char *ai_name(const struct addrinfo *ai) |
| 164 | { |
| 165 | static char addr[INET_ADDRSTRLEN]; |
| 166 | if ( AF_INET == ai->ai_family ) { |
| 167 | struct sockaddr_in *in; |
| 168 | in = (struct sockaddr_in *)ai->ai_addr; |
| 169 | inet_ntop(ai->ai_family, &in->sin_addr, addr, sizeof(addr)); |
| 170 | } else if ( AF_INET6 == ai->ai_family ) { |
| 171 | struct sockaddr_in6 *in; |
| 172 | in = (struct sockaddr_in6 *)ai->ai_addr; |
| 173 | inet_ntop(ai->ai_family, &in->sin6_addr, addr, sizeof(addr)); |
| 174 | } else { |
| 175 | strcpy(addr, "(unknown)"); |
| 176 | } |
| 177 | return addr; |
| 178 | } |
| 179 | |
Jon Loeliger | 5ad312b | 2006-06-06 22:58:41 -0500 | [diff] [blame] | 180 | /* |
| 181 | * Returns a connected socket() fd, or else die()s. |
| 182 | */ |
Michael S. Tsirkin | 7841ce7 | 2007-05-16 20:09:41 +0300 | [diff] [blame] | 183 | static int git_tcp_connect_sock(char *host, int flags) |
Linus Torvalds | 2386d65 | 2005-07-13 18:46:20 -0700 | [diff] [blame] | 184 | { |
Petr Baudis | ac3bc6c | 2006-07-01 23:56:26 +0200 | [diff] [blame] | 185 | int sockfd = -1, saved_errno = 0; |
YOSHIFUJI Hideaki | 5ba8844 | 2005-07-21 09:10:36 -0400 | [diff] [blame] | 186 | char *colon, *end; |
Timo Hirvonen | 554fe20 | 2006-06-28 12:04:39 +0300 | [diff] [blame] | 187 | const char *port = STR(DEFAULT_GIT_PORT); |
YOSHIFUJI Hideaki | 5ba8844 | 2005-07-21 09:10:36 -0400 | [diff] [blame] | 188 | struct addrinfo hints, *ai0, *ai; |
| 189 | int gai; |
Alex Riesen | ba50532 | 2007-05-23 23:34:27 +0200 | [diff] [blame] | 190 | int cnt = 0; |
Linus Torvalds | 2386d65 | 2005-07-13 18:46:20 -0700 | [diff] [blame] | 191 | |
YOSHIFUJI Hideaki | 5ba8844 | 2005-07-21 09:10:36 -0400 | [diff] [blame] | 192 | if (host[0] == '[') { |
| 193 | end = strchr(host + 1, ']'); |
| 194 | if (end) { |
| 195 | *end = 0; |
| 196 | end++; |
| 197 | host++; |
| 198 | } else |
| 199 | end = host; |
| 200 | } else |
| 201 | end = host; |
| 202 | colon = strchr(end, ':'); |
| 203 | |
Linus Torvalds | ce6f8e7 | 2005-07-23 11:10:21 -0700 | [diff] [blame] | 204 | if (colon) { |
| 205 | *colon = 0; |
YOSHIFUJI Hideaki | 5ba8844 | 2005-07-21 09:10:36 -0400 | [diff] [blame] | 206 | port = colon + 1; |
Linus Torvalds | 608d48b | 2007-03-27 09:50:20 -0700 | [diff] [blame] | 207 | if (!*port) |
| 208 | port = "<none>"; |
Linus Torvalds | ce6f8e7 | 2005-07-23 11:10:21 -0700 | [diff] [blame] | 209 | } |
YOSHIFUJI Hideaki | 5ba8844 | 2005-07-21 09:10:36 -0400 | [diff] [blame] | 210 | |
| 211 | memset(&hints, 0, sizeof(hints)); |
| 212 | hints.ai_socktype = SOCK_STREAM; |
| 213 | hints.ai_protocol = IPPROTO_TCP; |
| 214 | |
Michael S. Tsirkin | 7841ce7 | 2007-05-16 20:09:41 +0300 | [diff] [blame] | 215 | if (flags & CONNECT_VERBOSE) |
| 216 | fprintf(stderr, "Looking up %s ... ", host); |
| 217 | |
YOSHIFUJI Hideaki | 5ba8844 | 2005-07-21 09:10:36 -0400 | [diff] [blame] | 218 | gai = getaddrinfo(host, port, &hints, &ai); |
| 219 | if (gai) |
Linus Torvalds | 608d48b | 2007-03-27 09:50:20 -0700 | [diff] [blame] | 220 | die("Unable to look up %s (port %s) (%s)", host, port, gai_strerror(gai)); |
YOSHIFUJI Hideaki | 5ba8844 | 2005-07-21 09:10:36 -0400 | [diff] [blame] | 221 | |
Michael S. Tsirkin | 7841ce7 | 2007-05-16 20:09:41 +0300 | [diff] [blame] | 222 | if (flags & CONNECT_VERBOSE) |
| 223 | fprintf(stderr, "done.\nConnecting to %s (port %s) ... ", host, port); |
| 224 | |
YOSHIFUJI Hideaki | 5ba8844 | 2005-07-21 09:10:36 -0400 | [diff] [blame] | 225 | for (ai0 = ai; ai; ai = ai->ai_next) { |
Jon Loeliger | 5ad312b | 2006-06-06 22:58:41 -0500 | [diff] [blame] | 226 | sockfd = socket(ai->ai_family, |
| 227 | ai->ai_socktype, ai->ai_protocol); |
Petr Baudis | ac3bc6c | 2006-07-01 23:56:26 +0200 | [diff] [blame] | 228 | if (sockfd < 0) { |
| 229 | saved_errno = errno; |
YOSHIFUJI Hideaki | 5ba8844 | 2005-07-21 09:10:36 -0400 | [diff] [blame] | 230 | continue; |
Petr Baudis | ac3bc6c | 2006-07-01 23:56:26 +0200 | [diff] [blame] | 231 | } |
YOSHIFUJI Hideaki | 5ba8844 | 2005-07-21 09:10:36 -0400 | [diff] [blame] | 232 | if (connect(sockfd, ai->ai_addr, ai->ai_addrlen) < 0) { |
Petr Baudis | ac3bc6c | 2006-07-01 23:56:26 +0200 | [diff] [blame] | 233 | saved_errno = errno; |
Alex Riesen | 7cbf2f2 | 2007-06-12 22:52:10 +0200 | [diff] [blame] | 234 | fprintf(stderr, "%s[%d: %s]: errno=%s\n", |
Alex Riesen | ba50532 | 2007-05-23 23:34:27 +0200 | [diff] [blame] | 235 | host, |
| 236 | cnt, |
| 237 | ai_name(ai), |
Alex Riesen | ba50532 | 2007-05-23 23:34:27 +0200 | [diff] [blame] | 238 | strerror(saved_errno)); |
YOSHIFUJI Hideaki | 5ba8844 | 2005-07-21 09:10:36 -0400 | [diff] [blame] | 239 | close(sockfd); |
| 240 | sockfd = -1; |
| 241 | continue; |
Linus Torvalds | 2386d65 | 2005-07-13 18:46:20 -0700 | [diff] [blame] | 242 | } |
Alex Riesen | ba50532 | 2007-05-23 23:34:27 +0200 | [diff] [blame] | 243 | if (flags & CONNECT_VERBOSE) |
| 244 | fprintf(stderr, "%s ", ai_name(ai)); |
YOSHIFUJI Hideaki | 5ba8844 | 2005-07-21 09:10:36 -0400 | [diff] [blame] | 245 | break; |
Linus Torvalds | 2386d65 | 2005-07-13 18:46:20 -0700 | [diff] [blame] | 246 | } |
| 247 | |
YOSHIFUJI Hideaki | 5ba8844 | 2005-07-21 09:10:36 -0400 | [diff] [blame] | 248 | freeaddrinfo(ai0); |
Linus Torvalds | 2386d65 | 2005-07-13 18:46:20 -0700 | [diff] [blame] | 249 | |
Linus Torvalds | 2386d65 | 2005-07-13 18:46:20 -0700 | [diff] [blame] | 250 | if (sockfd < 0) |
Petr Baudis | ac3bc6c | 2006-07-01 23:56:26 +0200 | [diff] [blame] | 251 | die("unable to connect a socket (%s)", strerror(saved_errno)); |
YOSHIFUJI Hideaki | 5ba8844 | 2005-07-21 09:10:36 -0400 | [diff] [blame] | 252 | |
Michael S. Tsirkin | 7841ce7 | 2007-05-16 20:09:41 +0300 | [diff] [blame] | 253 | if (flags & CONNECT_VERBOSE) |
| 254 | fprintf(stderr, "done.\n"); |
| 255 | |
Jon Loeliger | 5ad312b | 2006-06-06 22:58:41 -0500 | [diff] [blame] | 256 | return sockfd; |
Linus Torvalds | 2386d65 | 2005-07-13 18:46:20 -0700 | [diff] [blame] | 257 | } |
| 258 | |
hpa | 49744d6 | 2005-09-28 16:52:21 -0700 | [diff] [blame] | 259 | #else /* NO_IPV6 */ |
hpa | 4c505f7 | 2005-09-28 16:37:58 -0700 | [diff] [blame] | 260 | |
Jon Loeliger | 5ad312b | 2006-06-06 22:58:41 -0500 | [diff] [blame] | 261 | /* |
| 262 | * Returns a connected socket() fd, or else die()s. |
| 263 | */ |
Michael S. Tsirkin | 7841ce7 | 2007-05-16 20:09:41 +0300 | [diff] [blame] | 264 | static int git_tcp_connect_sock(char *host, int flags) |
hpa | 4c505f7 | 2005-09-28 16:37:58 -0700 | [diff] [blame] | 265 | { |
Petr Baudis | ac3bc6c | 2006-07-01 23:56:26 +0200 | [diff] [blame] | 266 | int sockfd = -1, saved_errno = 0; |
hpa | 4c505f7 | 2005-09-28 16:37:58 -0700 | [diff] [blame] | 267 | char *colon, *end; |
| 268 | char *port = STR(DEFAULT_GIT_PORT), *ep; |
| 269 | struct hostent *he; |
| 270 | struct sockaddr_in sa; |
| 271 | char **ap; |
| 272 | unsigned int nport; |
Alex Riesen | ba50532 | 2007-05-23 23:34:27 +0200 | [diff] [blame] | 273 | int cnt; |
hpa | 4c505f7 | 2005-09-28 16:37:58 -0700 | [diff] [blame] | 274 | |
| 275 | if (host[0] == '[') { |
| 276 | end = strchr(host + 1, ']'); |
| 277 | if (end) { |
| 278 | *end = 0; |
| 279 | end++; |
| 280 | host++; |
| 281 | } else |
| 282 | end = host; |
| 283 | } else |
| 284 | end = host; |
| 285 | colon = strchr(end, ':'); |
| 286 | |
| 287 | if (colon) { |
| 288 | *colon = 0; |
| 289 | port = colon + 1; |
| 290 | } |
| 291 | |
Michael S. Tsirkin | 7841ce7 | 2007-05-16 20:09:41 +0300 | [diff] [blame] | 292 | if (flags & CONNECT_VERBOSE) |
| 293 | fprintf(stderr, "Looking up %s ... ", host); |
| 294 | |
hpa | 4c505f7 | 2005-09-28 16:37:58 -0700 | [diff] [blame] | 295 | he = gethostbyname(host); |
| 296 | if (!he) |
| 297 | die("Unable to look up %s (%s)", host, hstrerror(h_errno)); |
| 298 | nport = strtoul(port, &ep, 10); |
| 299 | if ( ep == port || *ep ) { |
| 300 | /* Not numeric */ |
| 301 | struct servent *se = getservbyname(port,"tcp"); |
| 302 | if ( !se ) |
| 303 | die("Unknown port %s\n", port); |
| 304 | nport = se->s_port; |
| 305 | } |
| 306 | |
Michael S. Tsirkin | 7841ce7 | 2007-05-16 20:09:41 +0300 | [diff] [blame] | 307 | if (flags & CONNECT_VERBOSE) |
| 308 | fprintf(stderr, "done.\nConnecting to %s (port %s) ... ", host, port); |
| 309 | |
Alex Riesen | ba50532 | 2007-05-23 23:34:27 +0200 | [diff] [blame] | 310 | for (cnt = 0, ap = he->h_addr_list; *ap; ap++, cnt++) { |
hpa | 4c505f7 | 2005-09-28 16:37:58 -0700 | [diff] [blame] | 311 | sockfd = socket(he->h_addrtype, SOCK_STREAM, 0); |
Petr Baudis | ac3bc6c | 2006-07-01 23:56:26 +0200 | [diff] [blame] | 312 | if (sockfd < 0) { |
| 313 | saved_errno = errno; |
hpa | 4c505f7 | 2005-09-28 16:37:58 -0700 | [diff] [blame] | 314 | continue; |
Petr Baudis | ac3bc6c | 2006-07-01 23:56:26 +0200 | [diff] [blame] | 315 | } |
hpa | 4c505f7 | 2005-09-28 16:37:58 -0700 | [diff] [blame] | 316 | |
| 317 | memset(&sa, 0, sizeof sa); |
| 318 | sa.sin_family = he->h_addrtype; |
Peter Anvin | 6573faf | 2005-09-28 17:26:44 -0700 | [diff] [blame] | 319 | sa.sin_port = htons(nport); |
Paul Serice | c616421 | 2005-11-22 07:54:23 -0600 | [diff] [blame] | 320 | memcpy(&sa.sin_addr, *ap, he->h_length); |
hpa | 4c505f7 | 2005-09-28 16:37:58 -0700 | [diff] [blame] | 321 | |
| 322 | if (connect(sockfd, (struct sockaddr *)&sa, sizeof sa) < 0) { |
Petr Baudis | ac3bc6c | 2006-07-01 23:56:26 +0200 | [diff] [blame] | 323 | saved_errno = errno; |
Alex Riesen | 7cbf2f2 | 2007-06-12 22:52:10 +0200 | [diff] [blame] | 324 | fprintf(stderr, "%s[%d: %s]: errno=%s\n", |
Alex Riesen | ba50532 | 2007-05-23 23:34:27 +0200 | [diff] [blame] | 325 | host, |
| 326 | cnt, |
| 327 | inet_ntoa(*(struct in_addr *)&sa.sin_addr), |
Alex Riesen | ba50532 | 2007-05-23 23:34:27 +0200 | [diff] [blame] | 328 | strerror(saved_errno)); |
hpa | 4c505f7 | 2005-09-28 16:37:58 -0700 | [diff] [blame] | 329 | close(sockfd); |
| 330 | sockfd = -1; |
| 331 | continue; |
| 332 | } |
Alex Riesen | ba50532 | 2007-05-23 23:34:27 +0200 | [diff] [blame] | 333 | if (flags & CONNECT_VERBOSE) |
| 334 | fprintf(stderr, "%s ", |
| 335 | inet_ntoa(*(struct in_addr *)&sa.sin_addr)); |
hpa | 4c505f7 | 2005-09-28 16:37:58 -0700 | [diff] [blame] | 336 | break; |
| 337 | } |
| 338 | |
| 339 | if (sockfd < 0) |
Petr Baudis | ac3bc6c | 2006-07-01 23:56:26 +0200 | [diff] [blame] | 340 | die("unable to connect a socket (%s)", strerror(saved_errno)); |
hpa | 4c505f7 | 2005-09-28 16:37:58 -0700 | [diff] [blame] | 341 | |
Michael S. Tsirkin | 7841ce7 | 2007-05-16 20:09:41 +0300 | [diff] [blame] | 342 | if (flags & CONNECT_VERBOSE) |
| 343 | fprintf(stderr, "done.\n"); |
| 344 | |
Jon Loeliger | 5ad312b | 2006-06-06 22:58:41 -0500 | [diff] [blame] | 345 | return sockfd; |
hpa | 4c505f7 | 2005-09-28 16:37:58 -0700 | [diff] [blame] | 346 | } |
| 347 | |
hpa | 49744d6 | 2005-09-28 16:52:21 -0700 | [diff] [blame] | 348 | #endif /* NO_IPV6 */ |
hpa | 4c505f7 | 2005-09-28 16:37:58 -0700 | [diff] [blame] | 349 | |
Jon Loeliger | 5ad312b | 2006-06-06 22:58:41 -0500 | [diff] [blame] | 350 | |
Michael S. Tsirkin | 7841ce7 | 2007-05-16 20:09:41 +0300 | [diff] [blame] | 351 | static void git_tcp_connect(int fd[2], char *host, int flags) |
Jon Loeliger | 5ad312b | 2006-06-06 22:58:41 -0500 | [diff] [blame] | 352 | { |
Michael S. Tsirkin | 7841ce7 | 2007-05-16 20:09:41 +0300 | [diff] [blame] | 353 | int sockfd = git_tcp_connect_sock(host, flags); |
Jon Loeliger | 5ad312b | 2006-06-06 22:58:41 -0500 | [diff] [blame] | 354 | |
| 355 | fd[0] = sockfd; |
Junio C Hamano | ec587fd | 2007-01-21 17:10:51 -0800 | [diff] [blame] | 356 | fd[1] = dup(sockfd); |
Jon Loeliger | 5ad312b | 2006-06-06 22:58:41 -0500 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | |
David Rientjes | 96f1e58 | 2006-08-15 10:23:48 -0700 | [diff] [blame] | 360 | static char *git_proxy_command; |
| 361 | static const char *rhost_name; |
Junio C Hamano | e814bc4 | 2005-11-19 03:48:56 -0800 | [diff] [blame] | 362 | static int rhost_len; |
Paul Collins | f801477 | 2005-11-04 14:57:16 +0000 | [diff] [blame] | 363 | |
| 364 | static int git_proxy_command_options(const char *var, const char *value) |
| 365 | { |
Junio C Hamano | e814bc4 | 2005-11-19 03:48:56 -0800 | [diff] [blame] | 366 | if (!strcmp(var, "core.gitproxy")) { |
YOSHIFUJI Hideaki / 吉藤英明 | c3df856 | 2005-11-22 12:18:23 +0900 | [diff] [blame] | 367 | const char *for_pos; |
| 368 | int matchlen = -1; |
| 369 | int hostlen; |
| 370 | |
Junio C Hamano | e814bc4 | 2005-11-19 03:48:56 -0800 | [diff] [blame] | 371 | if (git_proxy_command) |
Paul Collins | f801477 | 2005-11-04 14:57:16 +0000 | [diff] [blame] | 372 | return 0; |
Junio C Hamano | c64b9ad | 2008-02-11 10:52:15 -0800 | [diff] [blame] | 373 | if (!value) |
| 374 | return config_error_nonbool(var); |
Junio C Hamano | e814bc4 | 2005-11-19 03:48:56 -0800 | [diff] [blame] | 375 | /* [core] |
| 376 | * ;# matches www.kernel.org as well |
| 377 | * gitproxy = netcatter-1 for kernel.org |
| 378 | * gitproxy = netcatter-2 for sample.xz |
| 379 | * gitproxy = netcatter-default |
| 380 | */ |
YOSHIFUJI Hideaki / 吉藤英明 | c3df856 | 2005-11-22 12:18:23 +0900 | [diff] [blame] | 381 | for_pos = strstr(value, " for "); |
Junio C Hamano | e814bc4 | 2005-11-19 03:48:56 -0800 | [diff] [blame] | 382 | if (!for_pos) |
| 383 | /* matches everybody */ |
| 384 | matchlen = strlen(value); |
| 385 | else { |
| 386 | hostlen = strlen(for_pos + 5); |
| 387 | if (rhost_len < hostlen) |
| 388 | matchlen = -1; |
| 389 | else if (!strncmp(for_pos + 5, |
| 390 | rhost_name + rhost_len - hostlen, |
| 391 | hostlen) && |
| 392 | ((rhost_len == hostlen) || |
| 393 | rhost_name[rhost_len - hostlen -1] == '.')) |
| 394 | matchlen = for_pos - value; |
| 395 | else |
| 396 | matchlen = -1; |
Paul Collins | f801477 | 2005-11-04 14:57:16 +0000 | [diff] [blame] | 397 | } |
Junio C Hamano | e814bc4 | 2005-11-19 03:48:56 -0800 | [diff] [blame] | 398 | if (0 <= matchlen) { |
| 399 | /* core.gitproxy = none for kernel.org */ |
Junio C Hamano | a6080a0 | 2007-06-07 00:04:01 -0700 | [diff] [blame] | 400 | if (matchlen == 4 && |
Junio C Hamano | e814bc4 | 2005-11-19 03:48:56 -0800 | [diff] [blame] | 401 | !memcmp(value, "none", 4)) |
| 402 | matchlen = 0; |
Pierre Habouzit | 182af83 | 2007-09-16 00:32:36 +0200 | [diff] [blame] | 403 | git_proxy_command = xmemdupz(value, matchlen); |
Junio C Hamano | e814bc4 | 2005-11-19 03:48:56 -0800 | [diff] [blame] | 404 | } |
| 405 | return 0; |
Paul Collins | f801477 | 2005-11-04 14:57:16 +0000 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | return git_default_config(var, value); |
| 409 | } |
| 410 | |
Junio C Hamano | e814bc4 | 2005-11-19 03:48:56 -0800 | [diff] [blame] | 411 | static int git_use_proxy(const char *host) |
Paul Collins | f801477 | 2005-11-04 14:57:16 +0000 | [diff] [blame] | 412 | { |
Junio C Hamano | e814bc4 | 2005-11-19 03:48:56 -0800 | [diff] [blame] | 413 | rhost_name = host; |
| 414 | rhost_len = strlen(host); |
Paul Collins | f801477 | 2005-11-04 14:57:16 +0000 | [diff] [blame] | 415 | git_proxy_command = getenv("GIT_PROXY_COMMAND"); |
| 416 | git_config(git_proxy_command_options); |
Junio C Hamano | e814bc4 | 2005-11-19 03:48:56 -0800 | [diff] [blame] | 417 | rhost_name = NULL; |
| 418 | return (git_proxy_command && *git_proxy_command); |
Paul Collins | f801477 | 2005-11-04 14:57:16 +0000 | [diff] [blame] | 419 | } |
| 420 | |
Junio C Hamano | c78963d | 2006-06-28 03:50:33 -0700 | [diff] [blame] | 421 | static void git_proxy_connect(int fd[2], char *host) |
Paul Collins | f801477 | 2005-11-04 14:57:16 +0000 | [diff] [blame] | 422 | { |
Timo Hirvonen | 554fe20 | 2006-06-28 12:04:39 +0300 | [diff] [blame] | 423 | const char *port = STR(DEFAULT_GIT_PORT); |
Paul Collins | f801477 | 2005-11-04 14:57:16 +0000 | [diff] [blame] | 424 | char *colon, *end; |
Shawn O. Pearce | 15a1c012 | 2007-03-12 19:00:19 -0400 | [diff] [blame] | 425 | const char *argv[4]; |
| 426 | struct child_process proxy; |
Paul Collins | f801477 | 2005-11-04 14:57:16 +0000 | [diff] [blame] | 427 | |
| 428 | if (host[0] == '[') { |
| 429 | end = strchr(host + 1, ']'); |
| 430 | if (end) { |
| 431 | *end = 0; |
| 432 | end++; |
| 433 | host++; |
| 434 | } else |
| 435 | end = host; |
| 436 | } else |
| 437 | end = host; |
| 438 | colon = strchr(end, ':'); |
| 439 | |
| 440 | if (colon) { |
| 441 | *colon = 0; |
| 442 | port = colon + 1; |
| 443 | } |
| 444 | |
Shawn O. Pearce | 15a1c012 | 2007-03-12 19:00:19 -0400 | [diff] [blame] | 445 | argv[0] = git_proxy_command; |
| 446 | argv[1] = host; |
| 447 | argv[2] = port; |
| 448 | argv[3] = NULL; |
| 449 | memset(&proxy, 0, sizeof(proxy)); |
| 450 | proxy.argv = argv; |
| 451 | proxy.in = -1; |
| 452 | proxy.out = -1; |
| 453 | if (start_command(&proxy)) |
| 454 | die("cannot start proxy %s", argv[0]); |
| 455 | fd[0] = proxy.out; /* read from proxy stdout */ |
| 456 | fd[1] = proxy.in; /* write to proxy stdin */ |
Paul Collins | f801477 | 2005-11-04 14:57:16 +0000 | [diff] [blame] | 457 | } |
| 458 | |
Christian Couder | 0f503d7 | 2006-09-11 07:04:50 +0200 | [diff] [blame] | 459 | #define MAX_CMD_LEN 1024 |
| 460 | |
Luben Tuikov | 2e77666 | 2007-09-01 02:36:31 -0700 | [diff] [blame] | 461 | char *get_port(char *host) |
| 462 | { |
| 463 | char *end; |
| 464 | char *p = strchr(host, ':'); |
| 465 | |
| 466 | if (p) { |
| 467 | strtol(p+1, &end, 10); |
| 468 | if (*end == '\0') { |
| 469 | *p = '\0'; |
| 470 | return p+1; |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | return NULL; |
| 475 | } |
| 476 | |
Johannes Schindelin | fb32c91 | 2008-02-10 03:06:57 +0000 | [diff] [blame] | 477 | static struct child_process no_fork; |
| 478 | |
Linus Torvalds | f719259 | 2005-07-04 11:57:58 -0700 | [diff] [blame] | 479 | /* |
Johannes Schindelin | fb32c91 | 2008-02-10 03:06:57 +0000 | [diff] [blame] | 480 | * This returns a dummy child_process if the transport protocol does not |
| 481 | * need fork(2), or a struct child_process object if it does. Once done, |
| 482 | * finish the connection with finish_connect() with the value returned from |
| 483 | * this function (it is safe to call finish_connect() with NULL to support |
| 484 | * the former case). |
Franck Bui-Huu | f42a5c4 | 2006-09-12 11:00:13 +0200 | [diff] [blame] | 485 | * |
Johannes Schindelin | fb32c91 | 2008-02-10 03:06:57 +0000 | [diff] [blame] | 486 | * If it returns, the connect is successful; it just dies on errors (this |
| 487 | * will hopefully be changed in a libification effort, to return NULL when |
| 488 | * the connection failed). |
Linus Torvalds | f719259 | 2005-07-04 11:57:58 -0700 | [diff] [blame] | 489 | */ |
Daniel Barkalow | 4577370 | 2007-10-29 21:05:40 -0400 | [diff] [blame] | 490 | struct child_process *git_connect(int fd[2], const char *url_orig, |
Johannes Sixt | 98158e9 | 2007-10-19 21:47:53 +0200 | [diff] [blame] | 491 | const char *prog, int flags) |
Linus Torvalds | f719259 | 2005-07-04 11:57:58 -0700 | [diff] [blame] | 492 | { |
Daniel Barkalow | 4577370 | 2007-10-29 21:05:40 -0400 | [diff] [blame] | 493 | char *url = xstrdup(url_orig); |
Andreas Ericsson | faea9cc | 2005-11-17 20:37:14 +0100 | [diff] [blame] | 494 | char *host, *path = url; |
YOSHIFUJI Hideaki / 吉藤英明 | 356bece | 2005-12-21 19:23:42 +0900 | [diff] [blame] | 495 | char *end; |
| 496 | int c; |
Johannes Sixt | 98158e9 | 2007-10-19 21:47:53 +0200 | [diff] [blame] | 497 | struct child_process *conn; |
Andreas Ericsson | faea9cc | 2005-11-17 20:37:14 +0100 | [diff] [blame] | 498 | enum protocol protocol = PROTO_LOCAL; |
Serge E. Hallyn | da2a95b | 2006-04-17 10:14:47 -0500 | [diff] [blame] | 499 | int free_path = 0; |
Luben Tuikov | 2e77666 | 2007-09-01 02:36:31 -0700 | [diff] [blame] | 500 | char *port = NULL; |
Johannes Sixt | f364cb8 | 2007-10-19 21:47:54 +0200 | [diff] [blame] | 501 | const char **arg; |
| 502 | struct strbuf cmd; |
Linus Torvalds | f719259 | 2005-07-04 11:57:58 -0700 | [diff] [blame] | 503 | |
Junio C Hamano | f0b7367 | 2006-06-19 18:25:21 -0700 | [diff] [blame] | 504 | /* Without this we cannot rely on waitpid() to tell |
| 505 | * what happened to our children. |
| 506 | */ |
| 507 | signal(SIGCHLD, SIG_DFL); |
| 508 | |
Andreas Ericsson | faea9cc | 2005-11-17 20:37:14 +0100 | [diff] [blame] | 509 | host = strstr(url, "://"); |
| 510 | if(host) { |
| 511 | *host = '\0'; |
| 512 | protocol = get_protocol(url); |
| 513 | host += 3; |
YOSHIFUJI Hideaki / 吉藤英明 | 356bece | 2005-12-21 19:23:42 +0900 | [diff] [blame] | 514 | c = '/'; |
| 515 | } else { |
Linus Torvalds | f719259 | 2005-07-04 11:57:58 -0700 | [diff] [blame] | 516 | host = url; |
YOSHIFUJI Hideaki / 吉藤英明 | 356bece | 2005-12-21 19:23:42 +0900 | [diff] [blame] | 517 | c = ':'; |
| 518 | } |
| 519 | |
| 520 | if (host[0] == '[') { |
| 521 | end = strchr(host + 1, ']'); |
| 522 | if (end) { |
| 523 | *end = 0; |
| 524 | end++; |
| 525 | host++; |
| 526 | } else |
| 527 | end = host; |
| 528 | } else |
| 529 | end = host; |
| 530 | |
| 531 | path = strchr(end, c); |
Linus Torvalds | 72a4f4b | 2007-08-01 10:03:37 -0700 | [diff] [blame] | 532 | if (path) { |
| 533 | if (c == ':') { |
Andreas Ericsson | faea9cc | 2005-11-17 20:37:14 +0100 | [diff] [blame] | 534 | protocol = PROTO_SSH; |
YOSHIFUJI Hideaki / 吉藤英明 | 356bece | 2005-12-21 19:23:42 +0900 | [diff] [blame] | 535 | *path++ = '\0'; |
Linus Torvalds | 72a4f4b | 2007-08-01 10:03:37 -0700 | [diff] [blame] | 536 | } |
| 537 | } else |
| 538 | path = end; |
Linus Torvalds | 2386d65 | 2005-07-13 18:46:20 -0700 | [diff] [blame] | 539 | |
Andreas Ericsson | faea9cc | 2005-11-17 20:37:14 +0100 | [diff] [blame] | 540 | if (!path || !*path) |
| 541 | die("No path specified. See 'man git-pull' for valid url syntax"); |
| 542 | |
| 543 | /* |
| 544 | * null-terminate hostname and point path to ~ for URL's like this: |
| 545 | * ssh://host.xz/~user/repo |
| 546 | */ |
| 547 | if (protocol != PROTO_LOCAL && host != url) { |
| 548 | char *ptr = path; |
| 549 | if (path[1] == '~') |
| 550 | path++; |
Serge E. Hallyn | da2a95b | 2006-04-17 10:14:47 -0500 | [diff] [blame] | 551 | else { |
Shawn Pearce | 9befac4 | 2006-09-02 00:16:31 -0400 | [diff] [blame] | 552 | path = xstrdup(ptr); |
Serge E. Hallyn | da2a95b | 2006-04-17 10:14:47 -0500 | [diff] [blame] | 553 | free_path = 1; |
| 554 | } |
Andreas Ericsson | faea9cc | 2005-11-17 20:37:14 +0100 | [diff] [blame] | 555 | |
| 556 | *ptr = '\0'; |
| 557 | } |
| 558 | |
Luben Tuikov | 2e77666 | 2007-09-01 02:36:31 -0700 | [diff] [blame] | 559 | /* |
| 560 | * Add support for ssh port: ssh://host.xy:<port>/... |
| 561 | */ |
| 562 | if (protocol == PROTO_SSH && host != url) |
| 563 | port = get_port(host); |
| 564 | |
Paul Collins | f801477 | 2005-11-04 14:57:16 +0000 | [diff] [blame] | 565 | if (protocol == PROTO_GIT) { |
Jon Loeliger | 5ad312b | 2006-06-06 22:58:41 -0500 | [diff] [blame] | 566 | /* These underlying connection commands die() if they |
| 567 | * cannot connect. |
| 568 | */ |
Shawn Pearce | 9befac4 | 2006-09-02 00:16:31 -0400 | [diff] [blame] | 569 | char *target_host = xstrdup(host); |
Junio C Hamano | e814bc4 | 2005-11-19 03:48:56 -0800 | [diff] [blame] | 570 | if (git_use_proxy(host)) |
Junio C Hamano | c78963d | 2006-06-28 03:50:33 -0700 | [diff] [blame] | 571 | git_proxy_connect(fd, host); |
Serge E. Hallyn | da2a95b | 2006-04-17 10:14:47 -0500 | [diff] [blame] | 572 | else |
Michael S. Tsirkin | 7841ce7 | 2007-05-16 20:09:41 +0300 | [diff] [blame] | 573 | git_tcp_connect(fd, host, flags); |
Jon Loeliger | 5ad312b | 2006-06-06 22:58:41 -0500 | [diff] [blame] | 574 | /* |
| 575 | * Separate original protocol components prog and path |
| 576 | * from extended components with a NUL byte. |
| 577 | */ |
| 578 | packet_write(fd[1], |
| 579 | "%s %s%chost=%s%c", |
| 580 | prog, path, 0, |
| 581 | target_host, 0); |
| 582 | free(target_host); |
Daniel Barkalow | 4577370 | 2007-10-29 21:05:40 -0400 | [diff] [blame] | 583 | free(url); |
Serge E. Hallyn | da2a95b | 2006-04-17 10:14:47 -0500 | [diff] [blame] | 584 | if (free_path) |
| 585 | free(path); |
Johannes Schindelin | fb32c91 | 2008-02-10 03:06:57 +0000 | [diff] [blame] | 586 | return &no_fork; |
Paul Collins | f801477 | 2005-11-04 14:57:16 +0000 | [diff] [blame] | 587 | } |
Linus Torvalds | 2386d65 | 2005-07-13 18:46:20 -0700 | [diff] [blame] | 588 | |
Johannes Sixt | 98158e9 | 2007-10-19 21:47:53 +0200 | [diff] [blame] | 589 | conn = xcalloc(1, sizeof(*conn)); |
Christian Couder | 0f503d7 | 2006-09-11 07:04:50 +0200 | [diff] [blame] | 590 | |
Johannes Sixt | f364cb8 | 2007-10-19 21:47:54 +0200 | [diff] [blame] | 591 | strbuf_init(&cmd, MAX_CMD_LEN); |
| 592 | strbuf_addstr(&cmd, prog); |
| 593 | strbuf_addch(&cmd, ' '); |
| 594 | sq_quote_buf(&cmd, path); |
| 595 | if (cmd.len >= MAX_CMD_LEN) |
| 596 | die("command line too long"); |
Christian Couder | 0f503d7 | 2006-09-11 07:04:50 +0200 | [diff] [blame] | 597 | |
Johannes Sixt | f364cb8 | 2007-10-19 21:47:54 +0200 | [diff] [blame] | 598 | conn->in = conn->out = -1; |
| 599 | conn->argv = arg = xcalloc(6, sizeof(*arg)); |
| 600 | if (protocol == PROTO_SSH) { |
| 601 | const char *ssh = getenv("GIT_SSH"); |
| 602 | if (!ssh) ssh = "ssh"; |
Luben Tuikov | 2e77666 | 2007-09-01 02:36:31 -0700 | [diff] [blame] | 603 | |
Johannes Sixt | f364cb8 | 2007-10-19 21:47:54 +0200 | [diff] [blame] | 604 | *arg++ = ssh; |
| 605 | if (port) { |
| 606 | *arg++ = "-p"; |
| 607 | *arg++ = port; |
Martin Sivak | 4852f72 | 2005-08-03 17:15:42 +0200 | [diff] [blame] | 608 | } |
Johannes Sixt | f364cb8 | 2007-10-19 21:47:54 +0200 | [diff] [blame] | 609 | *arg++ = host; |
Matt Draisey | 016fb48 | 2006-01-19 15:58:03 -0500 | [diff] [blame] | 610 | } |
Johannes Sixt | f364cb8 | 2007-10-19 21:47:54 +0200 | [diff] [blame] | 611 | else { |
| 612 | /* remove these from the environment */ |
| 613 | const char *env[] = { |
| 614 | ALTERNATE_DB_ENVIRONMENT, |
| 615 | DB_ENVIRONMENT, |
| 616 | GIT_DIR_ENVIRONMENT, |
| 617 | GIT_WORK_TREE_ENVIRONMENT, |
| 618 | GRAFT_ENVIRONMENT, |
| 619 | INDEX_ENVIRONMENT, |
| 620 | NULL |
| 621 | }; |
| 622 | conn->env = env; |
| 623 | *arg++ = "sh"; |
| 624 | *arg++ = "-c"; |
| 625 | } |
| 626 | *arg++ = cmd.buf; |
| 627 | *arg = NULL; |
| 628 | |
| 629 | if (start_command(conn)) |
| 630 | die("unable to fork"); |
| 631 | |
| 632 | fd[0] = conn->out; /* read from child's stdout */ |
| 633 | fd[1] = conn->in; /* write to child's stdin */ |
| 634 | strbuf_release(&cmd); |
Daniel Barkalow | 4577370 | 2007-10-29 21:05:40 -0400 | [diff] [blame] | 635 | free(url); |
Serge E. Hallyn | da2a95b | 2006-04-17 10:14:47 -0500 | [diff] [blame] | 636 | if (free_path) |
| 637 | free(path); |
Johannes Sixt | 98158e9 | 2007-10-19 21:47:53 +0200 | [diff] [blame] | 638 | return conn; |
Linus Torvalds | f719259 | 2005-07-04 11:57:58 -0700 | [diff] [blame] | 639 | } |
| 640 | |
Johannes Sixt | 98158e9 | 2007-10-19 21:47:53 +0200 | [diff] [blame] | 641 | int finish_connect(struct child_process *conn) |
Linus Torvalds | f719259 | 2005-07-04 11:57:58 -0700 | [diff] [blame] | 642 | { |
Johannes Sixt | f364cb8 | 2007-10-19 21:47:54 +0200 | [diff] [blame] | 643 | int code; |
Johannes Schindelin | fb32c91 | 2008-02-10 03:06:57 +0000 | [diff] [blame] | 644 | if (!conn || conn == &no_fork) |
Franck Bui-Huu | f42a5c4 | 2006-09-12 11:00:13 +0200 | [diff] [blame] | 645 | return 0; |
| 646 | |
Johannes Sixt | f364cb8 | 2007-10-19 21:47:54 +0200 | [diff] [blame] | 647 | code = finish_command(conn); |
| 648 | free(conn->argv); |
Johannes Sixt | 98158e9 | 2007-10-19 21:47:53 +0200 | [diff] [blame] | 649 | free(conn); |
Johannes Sixt | f364cb8 | 2007-10-19 21:47:54 +0200 | [diff] [blame] | 650 | return code; |
Linus Torvalds | f719259 | 2005-07-04 11:57:58 -0700 | [diff] [blame] | 651 | } |