]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Bug #1157: PID file check error when chrooting
authorserassio <>
Tue, 26 Apr 2005 00:43:00 +0000 (00:43 +0000)
committerserassio <>
Tue, 26 Apr 2005 00:43:00 +0000 (00:43 +0000)
Forward port of 2.5 patch

src/tools.cc

index cbab3aabbc0a4f9ac86e7581c0d4cde5cf6bd6af..1babe749267e36ce12889f1f0020e1fee3e51ecb 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: tools.cc,v 1.254 2005/04/18 21:52:43 hno Exp $
+ * $Id: tools.cc,v 1.255 2005/04/25 18:43:00 serassio Exp $
  *
  * DEBUG: section 21    Misc Functions
  * AUTHOR: Harvest Derived
@@ -774,6 +774,7 @@ readPidFile(void)
 {
     FILE *pid_fp = NULL;
     const char *f = Config.pidFilename;
+    char *chroot_f = NULL;
     pid_t pid = -1;
     int i;
 
@@ -782,6 +783,13 @@ readPidFile(void)
         exit(1);
     }
 
+    if (Config.chroot_dir && geteuid() == 0) {
+        int len = strlen(Config.chroot_dir) + 1 + strlen(f) + 1;
+        chroot_f = (char *)xmalloc(strlen(Config.chroot_dir) + 1 + strlen(f) + 1);
+        snprintf(chroot_f, len, "%s/%s", Config.chroot_dir, f);
+        f = chroot_f;
+    }
+
     pid_fp = fopen(f, "r");
 
     if (pid_fp != NULL) {
@@ -799,6 +807,7 @@ readPidFile(void)
         }
     }
 
+    safe_free(chroot_f);
     return pid;
 }