{"thread":{"id":"27977","subject":"[PATCH 1/2] connect: correctly number ipv6 network adapter","startedAt":"2011-08-01T11:16:09Z","lastAt":"2011-08-01T11:16:10Z","messageCount":2,"participants":["Erik Faye-Lund"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"172520","messageId":"1312197370-5112-1-git-send-email-kusmabite@gmail.com","threadId":"27977","inReplyTo":null,"subject":"[PATCH 1/2] connect: correctly number ipv6 network adapter","fromName":"Erik Faye-Lund","fromEmail":"kusmabite@gmail.com","sentAt":"2011-08-01T11:16:09Z","receivedAt":"2011-08-01T11:16:09Z","isPatch":true,"sender":{"key":"kusmabite@gmail.com","avatar":"https://avatars.githubusercontent.com/u/47073?v=4"},"body":"In ba50532, the variable 'cnt' was added to both the IPv6 and the\nIPv4 version of git_tcp_connect_sock, intended to identify which\nnetwork adapter the connection failed on. But in the IPv6 version,\nthe variable was never increased, leaving it constantly at zero.\n\nThis behaviour isn't very useful, so let's fix it by increasing\nthe variable at every loop-iteration.\n\nSigned-off-by: Erik Faye-Lund <kusmabite@gmail.com>\n---\n connect.c |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\ndiff --git a/connect.c b/connect.c\nindex 844107e..d2ce57f 100644\n--- a/connect.c\n+++ b/connect.c\n@@ -217,7 +217,7 @@ static int git_tcp_connect_sock(char *host, int flags)\n \tif (flags & CONNECT_VERBOSE)\n \t\tfprintf(stderr, \"done.\\nConnecting to %s (port %s) ... \", host, port);\n \n-\tfor (ai0 = ai; ai; ai = ai->ai_next) {\n+\tfor (ai0 = ai; ai; ai = ai->ai_next, cnt++) {\n \t\tsockfd = socket(ai->ai_family,\n \t\t\t\tai->ai_socktype, ai->ai_protocol);\n \t\tif ((sockfd < 0) ||\n-- \n1.7.6.347.g4db0d\n"},{"id":"172521","messageId":"1312197370-5112-2-git-send-email-kusmabite@gmail.com","threadId":"27977","inReplyTo":"1312197370-5112-1-git-send-email-kusmabite@gmail.com","subject":"[PATCH 2/2] connect: only log if all attempts failed (ipv4)","fromName":"Erik Faye-Lund","fromEmail":"kusmabite@gmail.com","sentAt":"2011-08-01T11:16:10Z","receivedAt":"2011-08-01T11:16:10Z","isPatch":true,"sender":{"key":"kusmabite@gmail.com","avatar":"https://avatars.githubusercontent.com/u/47073?v=4"},"body":"In 63a995b (Do not log unless all connect() attempts fail), a\nmechanism to only log connection errors if all attempts failed\nwas introduced for the IPv6 code-path, but not for the IPv4 one.\n\nIntroduce a matching mechanism so IPv4-users also benefit from\nthis noise-reduction.\n\nMove the call to socket after filling in sa, to make it more\napparent that errno can't change in between.\n\nSigned-off-by: Erik Faye-Lund <kusmabite@gmail.com>\n---\n connect.c |   23 ++++++++++-------------\n 1 files changed, 10 insertions(+), 13 deletions(-)\n\ndiff --git a/connect.c b/connect.c\nindex d2ce57f..ee1d4b4 100644\n--- a/connect.c\n+++ b/connect.c\n@@ -254,7 +254,8 @@ static int git_tcp_connect_sock(char *host, int flags)\n  */\n static int git_tcp_connect_sock(char *host, int flags)\n {\n-\tint sockfd = -1, saved_errno = 0;\n+\tstruct strbuf error_message = STRBUF_INIT;\n+\tint sockfd = -1;\n \tconst char *port = STR(DEFAULT_GIT_PORT);\n \tchar *ep;\n \tstruct hostent *he;\n@@ -284,25 +285,21 @@ static int git_tcp_connect_sock(char *host, int flags)\n \t\tfprintf(stderr, \"done.\\nConnecting to %s (port %s) ... \", host, port);\n \n \tfor (cnt = 0, ap = he->h_addr_list; *ap; ap++, cnt++) {\n-\t\tsockfd = socket(he->h_addrtype, SOCK_STREAM, 0);\n-\t\tif (sockfd < 0) {\n-\t\t\tsaved_errno = errno;\n-\t\t\tcontinue;\n-\t\t}\n-\n \t\tmemset(&sa, 0, sizeof sa);\n \t\tsa.sin_family = he->h_addrtype;\n \t\tsa.sin_port = htons(nport);\n \t\tmemcpy(&sa.sin_addr, *ap, he->h_length);\n \n-\t\tif (connect(sockfd, (struct sockaddr *)&sa, sizeof sa) < 0) {\n-\t\t\tsaved_errno = errno;\n-\t\t\tfprintf(stderr, \"%s[%d: %s]: errno=%s\\n\",\n+\t\tsockfd = socket(he->h_addrtype, SOCK_STREAM, 0);\n+\t\tif ((sockfd < 0) ||\n+\t\t    connect(sockfd, (struct sockaddr *)&sa, sizeof sa) < 0) {\n+\t\t\tstrbuf_addf(&error_message, \"%s[%d: %s]: errno=%s\\n\",\n \t\t\t\thost,\n \t\t\t\tcnt,\n \t\t\t\tinet_ntoa(*(struct in_addr *)&sa.sin_addr),\n-\t\t\t\tstrerror(saved_errno));\n-\t\t\tclose(sockfd);\n+\t\t\t\tstrerror(errno));\n+\t\t\tif (0 <= sockfd)\n+\t\t\t\tclose(sockfd);\n \t\t\tsockfd = -1;\n \t\t\tcontinue;\n \t\t}\n@@ -313,7 +310,7 @@ static int git_tcp_connect_sock(char *host, int flags)\n \t}\n \n \tif (sockfd < 0)\n-\t\tdie(\"unable to connect a socket (%s)\", strerror(saved_errno));\n+\t\tdie(\"unable to connect to %s:\\n%s\", host, error_message.buf);\n \n \tif (flags & CONNECT_VERBOSE)\n \t\tfprintf(stderr, \"done.\\n\");\n-- \n1.7.6.347.g4db0d\n"}]}