squid-1331

Version:

2.5.STABLE9

How it is diagnosed (reproduced or source analysis)?

semi reproduced. For the same symptom, but different root cause.

Bug link:

http://bugs.squid-cache.org/show_bug.cgi?id=1331

How to reproduce?

1). set chroot in the squid.conf

2). Start the squid with root:

squid-2.5.STABLE9/bin/sbin

./squid -N

3). run squid -k without root

Symptom:

When use ‘squid -k’ to send SIGHUP reconfigure signal to the already running copy, the ‘squid -k’ instance failed with:  

FATAL: MIME Config Table squid-2.5.STABLE9/bin/etc/mime.conf: (2) No such file or directory

Squid Cache (Version 2.5.STABLE9): Terminated abnormally.

The particular failure is triggered when the following conditions are met at the same time:

1. enable ‘chroot’ in the config file.

2. run at the first time using ‘root’

3. and later run ‘squid -k’ without root.

Under the correct semantic, it should be perfectly OK for ‘squid -k’ to run without root even when originally it was run with root and ‘chroot’

Root cause:

Let’s see the patch first:

--- src/cache_cf.c.orig      

+++ src/cache_cf.c    

@@ -2545,7 +2545,7 @@

    struct stat sb;

    char pathbuf[BUFSIZ];

    assert(path != NULL);

-   if (Config.chroot_dir) {

+   if (Config.chroot_dir && geteuid() == 0) {

       snprintf(pathbuf, BUFSIZ, "%s/%s", Config.chroot_dir, path);

       path = pathbuf;

    }

   if (stat(path, &sb) < 0)

        fatalf("%s %s: %s", name, path, xstrerror());

This is in function ‘requirePathnameExists’, called from ‘configDoConfigure’. The trick is that only ‘chroot’ when uid==0, that is when running as ‘root’.

Is there Error Message?

Yes.

Can Errlog anticipate this error msg?

Yes. The pattern is system call return error (stat).