X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=connect.c;h=51990fa0cb300a95b125b0727f10133961d0167b;hb=b43ba7891422127eb3ec7bd88c9a8ea102b19d0c;hp=2119c3f74edcd2a976ff0e375c5d8d60d40da2ec;hpb=ed36a48e6d246f4f60d44b27e8c1e660151cd0b4;p=git.git diff --git a/connect.c b/connect.c index 2119c3f74..51990fa0c 100644 --- a/connect.c +++ b/connect.c @@ -22,7 +22,7 @@ static int check_ref(const char *name, int len, unsigned int flags) len -= 5; /* REF_NORMAL means that we don't want the magic fake tag refs */ - if ((flags & REF_NORMAL) && check_ref_format(name) < 0) + if ((flags & REF_NORMAL) && check_refname_format(name, 0)) return 0; /* REF_HEADS means that we want regular branch heads */ @@ -192,7 +192,8 @@ static const char *ai_name(const struct addrinfo *ai) */ static int git_tcp_connect_sock(char *host, int flags) { - int sockfd = -1, saved_errno = 0; + struct strbuf error_message = STRBUF_INIT; + int sockfd = -1; const char *port = STR(DEFAULT_GIT_PORT); struct addrinfo hints, *ai0, *ai; int gai; @@ -216,21 +217,15 @@ static int git_tcp_connect_sock(char *host, int flags) if (flags & CONNECT_VERBOSE) fprintf(stderr, "done.\nConnecting to %s (port %s) ... ", host, port); - for (ai0 = ai; ai; ai = ai->ai_next) { + for (ai0 = ai; ai; ai = ai->ai_next, cnt++) { sockfd = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); - if (sockfd < 0) { - saved_errno = errno; - continue; - } - if (connect(sockfd, ai->ai_addr, ai->ai_addrlen) < 0) { - saved_errno = errno; - fprintf(stderr, "%s[%d: %s]: errno=%s\n", - host, - cnt, - ai_name(ai), - strerror(saved_errno)); - close(sockfd); + if ((sockfd < 0) || + (connect(sockfd, ai->ai_addr, ai->ai_addrlen) < 0)) { + strbuf_addf(&error_message, "%s[%d: %s]: errno=%s\n", + host, cnt, ai_name(ai), strerror(errno)); + if (0 <= sockfd) + close(sockfd); sockfd = -1; continue; } @@ -242,11 +237,13 @@ static int git_tcp_connect_sock(char *host, int flags) freeaddrinfo(ai0); if (sockfd < 0) - die("unable to connect a socket (%s)", strerror(saved_errno)); + die("unable to connect to %s:\n%s", host, error_message.buf); if (flags & CONNECT_VERBOSE) fprintf(stderr, "done.\n"); + strbuf_release(&error_message); + return sockfd; } @@ -257,7 +254,8 @@ static int git_tcp_connect_sock(char *host, int flags) */ static int git_tcp_connect_sock(char *host, int flags) { - int sockfd = -1, saved_errno = 0; + struct strbuf error_message = STRBUF_INIT; + int sockfd = -1; const char *port = STR(DEFAULT_GIT_PORT); char *ep; struct hostent *he; @@ -287,25 +285,21 @@ static int git_tcp_connect_sock(char *host, int flags) fprintf(stderr, "done.\nConnecting to %s (port %s) ... ", host, port); for (cnt = 0, ap = he->h_addr_list; *ap; ap++, cnt++) { - sockfd = socket(he->h_addrtype, SOCK_STREAM, 0); - if (sockfd < 0) { - saved_errno = errno; - continue; - } - memset(&sa, 0, sizeof sa); sa.sin_family = he->h_addrtype; sa.sin_port = htons(nport); memcpy(&sa.sin_addr, *ap, he->h_length); - if (connect(sockfd, (struct sockaddr *)&sa, sizeof sa) < 0) { - saved_errno = errno; - fprintf(stderr, "%s[%d: %s]: errno=%s\n", + sockfd = socket(he->h_addrtype, SOCK_STREAM, 0); + if ((sockfd < 0) || + connect(sockfd, (struct sockaddr *)&sa, sizeof sa) < 0) { + strbuf_addf(&error_message, "%s[%d: %s]: errno=%s\n", host, cnt, inet_ntoa(*(struct in_addr *)&sa.sin_addr), - strerror(saved_errno)); - close(sockfd); + strerror(errno)); + if (0 <= sockfd) + close(sockfd); sockfd = -1; continue; } @@ -316,7 +310,7 @@ static int git_tcp_connect_sock(char *host, int flags) } if (sockfd < 0) - die("unable to connect a socket (%s)", strerror(saved_errno)); + die("unable to connect to %s:\n%s", host, error_message.buf); if (flags & CONNECT_VERBOSE) fprintf(stderr, "done.\n");