squid-1196

Version:

2.5

How it is diagnosed (reproduced or source analysis)?

Partly Reproduced

How to reproduce?

$ gdb squid-2.4.STABLE4/src/squid

gdb> run -N // Run it as non-daemon mode

Then use another gdb on squid

$ gdb squid-2.4.STABLE4/src/squid

gdb> run -k rotate

and we can observe how the getMyHostname is called.

Symptom:

Squid -k fails to send a signal to the running copy. With the error message:

FATAL: Could not determine fully qualified hostname.  Please set 'visible_hostname'.

This only happens when running 'squid -k', the dns server can no longer resolve the server. In other words, the original squid server was running normally, and now user wants to rotate the log via executing ‘squid -k rotate’, but this‘squid -k rotate’ fails if dns cannot resolve host name.

Root cause:

Squid unnecessarily calls configDoConfigure, which is to re-apply the configurations. It should not call this function during ‘squid -k’.

(gdb) bt

#0  getMyHostname () at tools.c:444

#    in configDoConfigure at cache_cf.c:334

#1  0x000000000040e755 in parseConfigFile (

   file_name=0x380c <Address 0x380c out of bounds>) at cache_cf.c:250

#2  0x0000000000434e91 in main (argc=3, argv=0x7fff2621f858) at main.c:634

So the fix is simple: disable the call to configDoConfigure when it’s ‘squid -k’

diff -u -p -r1.396.2.23 cache_cf.c

--- src/cache_cf.c        

+++ src/cache_cf.c        

@@ -297,11 +297,13 @@ parseConfigFile(const char *file_name)

    }

    fclose(fp);

    defaults_if_none();

-   configDoConfigure();

-   cachemgrRegister("config",

-        "Current Squid Configuration",

-         dump_config,

-         1, 1);

+   if (opt_send_signal == -1) {

+        configDoConfigure();

+        cachemgrRegister("config",

+            "Current Squid Configuration",

+            dump_config,

+            1, 1);

+    }

    return err_count;

}

getMyHostname(void) {

   ... ...

   /*

    * Get the host name and store it in host to return

    */

   if (gethostname(host, SQUIDHOSTNAMELEN) < 0) { // gethostname is a syscall

        debug(50, 1) ("WARNING: gethostname failed: %s\n", xstrerror());

   } else if ((h = gethostbyname(host)) == NULL) {

        debug(50, 1) ("WARNING: gethostbyname failed for %s\n", host);

   } else {

         ... ...

   }

   fatal("Could not determine fully qualified hostname.  Please set 'visible_hostname'\n");

   return NULL;                /* keep compiler happy */

}

That only calls configDoConfigure when ‘opt_send_signal == 1’, (in ‘squid -k’, ‘opt_send_signal != -1’), but set to some signals.

Is there Error Message?

Yes.

Can Errlog automatically print this error msg?

Yes. The log message was printed because ‘gethostname’ failed -- system call returned failure.