From: Amos Jeffries Date: Wed, 18 Aug 2010 01:41:34 +0000 (-0600) Subject: Bug 2997: visible_hostname directive no longer matches docs X-Git-Tag: SQUID_3_1_7~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9ee404e0a2140d69a72db1cecf02bcecec4e3a51;p=thirdparty%2Fsquid.git Bug 2997: visible_hostname directive no longer matches docs --- diff --git a/src/tools.cc b/src/tools.cc index 9538908a13..00d9c576df 100644 --- a/src/tools.cc +++ b/src/tools.cc @@ -627,43 +627,42 @@ getMyHostname(void) } sa.FreeAddrInfo(AI); - debugs(50, 1, "WARNING: failed to resolve " << sa << " to a fully qualified hostname"); + debugs(50, 2, "WARNING: failed to resolve " << sa << " to a fully qualified hostname"); + } + + // still no host. fallback to gethostname() + if (gethostname(host, SQUIDHOSTNAMELEN) < 0) { + debugs(50, DBG_IMPORTANT, "WARNING: gethostname failed: " << xstrerror()); } else { - if (gethostname(host, SQUIDHOSTNAMELEN) < 0) { - debugs(50, 1, "WARNING: gethostname failed: " << xstrerror()); - } else { - /* Verify that the hostname given resolves properly */ - struct addrinfo hints; - memset(&hints, 0, sizeof(addrinfo)); - hints.ai_flags = AI_CANONNAME; - - if (xgetaddrinfo(host, NULL, NULL, &AI) == 0) { - /* DNS lookup successful */ - /* use the official name from DNS lookup */ - debugs(50, 6, "getMyHostname: '" << host << "' has rDNS."); - present = 1; - - /* AYJ: do we want to flag AI_ALL and cache the result anywhere. ie as our local host IPs? */ - if (AI) { - xfreeaddrinfo(AI); - AI = NULL; - } + /* Verify that the hostname given resolves properly */ + struct addrinfo hints; + memset(&hints, 0, sizeof(addrinfo)); + hints.ai_flags = AI_CANONNAME; - return host; + if (xgetaddrinfo(host, NULL, NULL, &AI) == 0) { + /* DNS lookup successful */ + /* use the official name from DNS lookup */ + debugs(50, 6, "getMyHostname: '" << host << "' has DNS resolution."); + present = 1; + + /* AYJ: do we want to flag AI_ALL and cache the result anywhere. ie as our local host IPs? */ + if (AI) { + xfreeaddrinfo(AI); + AI = NULL; } - if (AI) xfreeaddrinfo(AI); - debugs(50, 1, "WARNING: '" << host << "' rDNS test failed: " << xstrerror()); + return host; } + + if (AI) freeaddrinfo(AI); + debugs(50, DBG_IMPORTANT, "WARNING: '" << host << "' rDNS test failed: " << xstrerror()); } - /* throw a fatal configuration error when the Host/IP given has bad DNS/rDNS. */ - if (opt_send_signal == -1) - fatal("Could not determine fully qualified hostname. Please set 'visible_hostname'\n"); - else - return ("localhost"); + /* throw a configuration error when the Host/IP given has bad DNS/rDNS. */ + debugs(50, DBG_CRITICAL, "WARNING: Could not determine this machines public hostname. " << + "Please configure one or set 'visible_hostname'."); - return NULL; /* keep compiler happy */ + return ("localhost"); } const char *