]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Fix stdio: log module segfaults on rotate
authorAmos Jeffries <squid3@treenet.co.nz>
Fri, 25 Mar 2011 15:17:08 +0000 (04:17 +1300)
committerAmos Jeffries <squid3@treenet.co.nz>
Fri, 25 Mar 2011 15:17:08 +0000 (04:17 +1300)
The stdio module was still assuming old format for the parameter.

 * update the parser to detect old format and upgrade-warn.
 * update the stdio module to ignore the stdio: prefix on its parameter

src/log/File.cc
src/log/ModStdio.cc

index 861446f55c6ce78ea814003e0c13ed1d8590d17a..b45aeacd6254f1b4803878e3d982d404abfa8114 100644 (file)
@@ -74,13 +74,15 @@ logfileOpen(const char *path, size_t bufsz, int fatal_flag)
         ret = logfile_mod_syslog_open(lf, patharg, bufsz, fatal_flag);
 #endif
     } else {
+        debugs(50, DBG_IMPORTANT, "WARNING: log parameters now start with a module name. Use 'stdio:" << patharg << "'");
+        snprintf(lf->path, MAXPATHLEN, "stdio:%s", patharg);
         ret = logfile_mod_stdio_open(lf, patharg, bufsz, fatal_flag);
     }
     if (!ret) {
         if (fatal_flag)
-            fatalf("logfileOpen: path %s: couldn't open!\n", path);
+            fatalf("logfileOpen: %s: couldn't open!\n", path);
         else
-            debugs(50, 1, "logfileOpen: path " << path << ": couldn't open!");
+            debugs(50, 1, "logfileOpen: " << path << ": couldn't open!");
         lf->f_close(lf);
         cbdataFree(lf);
         return NULL;
index ec646d35b0ff9b4d539d202e2c55753a6003a5bf..05d09a1a9d6464043aadc029e83fdccaf230e62c 100644 (file)
@@ -60,7 +60,7 @@ logfileWriteWrapper(Logfile * lf, const void *buf, size_t len)
     if (!lf->flags.fatal)
         return;
 
-    fatalf("logfileWrite (stdio): %s: %s\n", lf->path, xstrerror());
+    fatalf("logfileWrite: %s: %s\n", lf->path, xstrerror());
 }
 
 static void
@@ -125,22 +125,24 @@ logfile_mod_stdio_rotate(Logfile * lf)
     char to[MAXPATHLEN];
     l_stdio_t *ll = (l_stdio_t *) lf->data;
     assert(lf->path);
+    const char *realpath = lf->path+6; // skip 'stdio:' prefix.
+    assert(realpath);
 
 #ifdef S_ISREG
 
-    if (stat(lf->path, &sb) == 0)
+    if (stat(realpath, &sb) == 0)
         if (S_ISREG(sb.st_mode) == 0)
             return;
 
 #endif
 
-    debugs(0, DBG_IMPORTANT, "logfileRotate (stdio): " << lf->path);
+    debugs(0, DBG_IMPORTANT, "Rotate log file " << lf->path);
 
     /* Rotate numbers 0 through N up one */
     for (i = Config.Log.rotateNumber; i > 1;) {
         i--;
-        snprintf(from, MAXPATHLEN, "%s.%d", lf->path, i - 1);
-        snprintf(to, MAXPATHLEN, "%s.%d", lf->path, i);
+        snprintf(from, MAXPATHLEN, "%s.%d", realpath, i - 1);
+        snprintf(to, MAXPATHLEN, "%s.%d", realpath, i);
         xrename(from, to);
     }
 
@@ -150,14 +152,14 @@ logfile_mod_stdio_rotate(Logfile * lf)
     file_close(ll->fd);                /* always close */
 
     if (Config.Log.rotateNumber > 0) {
-        snprintf(to, MAXPATHLEN, "%s.%d", lf->path, 0);
-        xrename(lf->path, to);
+        snprintf(to, MAXPATHLEN, "%s.%d", realpath, 0);
+        xrename(realpath, to);
     }
     /* Reopen the log.  It may have been renamed "manually" */
-    ll->fd = file_open(lf->path, O_WRONLY | O_CREAT | O_TEXT);
+    ll->fd = file_open(realpath, O_WRONLY | O_CREAT | O_TEXT);
 
     if (DISK_ERROR == ll->fd && lf->flags.fatal) {
-        debugs(50, DBG_CRITICAL, "logfileRotate (stdio): " << lf->path << ": " << xstrerror());
+        debugs(50, DBG_CRITICAL, "ERROR: logfileRotate: " << lf->path << ": " << xstrerror());
         fatalf("Cannot open %s: %s", lf->path, xstrerror());
     }
 }
@@ -209,7 +211,7 @@ logfile_mod_stdio_open(Logfile * lf, const char *path, size_t bufsz, int fatal_f
         } else if (EISDIR == errno && fatal_flag) {
             fatalf("Cannot open '%s' because it is a directory, not a file.\n", path);
         } else {
-            debugs(50, DBG_IMPORTANT, "logfileOpen (stdio): " <<  path << ": " << xstrerror());
+            debugs(50, DBG_IMPORTANT, "ERROR: logfileOpen " << lf->path << ": " << xstrerror());
             return 0;
         }
     }