{"thread":{"id":"27596","subject":"[PATCH] Do not log unless all connect() attempts fail","startedAt":"2011-06-09T17:52:13Z","lastAt":"2011-06-09T17:52:13Z","messageCount":1,"participants":["Dave Zarzycki"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"169799","messageId":"FB214E8F-7C84-4EE1-9E7C-FC8499B688C1@apple.com","threadId":"27596","inReplyTo":null,"subject":"[PATCH] Do not log unless all connect() attempts fail","fromName":"Dave Zarzycki","fromEmail":"zarzycki@apple.com","sentAt":"2011-06-09T17:52:13Z","receivedAt":"2011-06-09T17:52:13Z","isPatch":true,"sender":{"key":"zarzycki@apple.com","avatar":"https://avatars.githubusercontent.com/u/1071982?v=4"},"body":"IPv6 hosts are often unreachable on the primarily IPv4 Internet and\ntherefore we shouldn't print an error if there are still other hosts we\ncan try to connect() to. This helps \"git fetch --quiet\" stay quiet.\n---\n connect.c |   12 ++++++------\n 1 files changed, 6 insertions(+), 6 deletions(-)\n\ndiff --git a/connect.c b/connect.c\nindex 2119c3f..8eb9f44 100644\n--- a/connect.c\n+++ b/connect.c\n@@ -192,6 +192,7 @@ static const char *ai_name(const struct addrinfo *ai)\n  */\n static int git_tcp_connect_sock(char *host, int flags)\n {\n+\tstruct strbuf error_message = STRBUF_INIT;\n \tint sockfd = -1, saved_errno = 0;\n \tconst char *port = STR(DEFAULT_GIT_PORT);\n \tstruct addrinfo hints, *ai0, *ai;\n@@ -225,11 +226,8 @@ static int git_tcp_connect_sock(char *host, int flags)\n \t\t}\n \t\tif (connect(sockfd, ai->ai_addr, ai->ai_addrlen) < 0) {\n \t\t\tsaved_errno = errno;\n-\t\t\tfprintf(stderr, \"%s[%d: %s]: errno=%s\\n\",\n-\t\t\t\thost,\n-\t\t\t\tcnt,\n-\t\t\t\tai_name(ai),\n-\t\t\t\tstrerror(saved_errno));\n+\t\t\tstrbuf_addf(&error_message, \"%s[%d: %s]: errno=%s\\n\",\n+\t\t\t\thost, cnt, ai_name(ai), strerror(saved_errno));\n \t\t\tclose(sockfd);\n \t\t\tsockfd = -1;\n \t\t\tcontinue;\n@@ -242,11 +240,13 @@ static int git_tcp_connect_sock(char *host, int flags)\n \tfreeaddrinfo(ai0);\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 \n+\tstrbuf_release(&error_message);\n+\n \treturn sockfd;\n }\n \n-- \n1.7.6.rc1.1.g2e27\n"}]}