From 9ee404e0a2140d69a72db1cecf02bcecec4e3a51 Mon Sep 17 00:00:00 2001 From: Amos Jeffries Date: Tue, 17 Aug 2010 19:41:34 -0600 Subject: [PATCH] Bug 2997: visible_hostname directive no longer matches docs --- src/tools.cc | 57 ++++++++++++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 29 deletions(-) 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 * -- 2.47.2