From: Amos Jeffries Date: Fri, 25 Mar 2011 15:17:08 +0000 (+1300) Subject: Fix stdio: log module segfaults on rotate X-Git-Tag: take06~27^2~66 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8030a2a099a7a50dc05fab1190682741feb02ac6;p=thirdparty%2Fsquid.git Fix stdio: log module segfaults on rotate 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 --- diff --git a/src/log/File.cc b/src/log/File.cc index 861446f55c..b45aeacd62 100644 --- a/src/log/File.cc +++ b/src/log/File.cc @@ -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; diff --git a/src/log/ModStdio.cc b/src/log/ModStdio.cc index ec646d35b0..05d09a1a9d 100644 --- a/src/log/ModStdio.cc +++ b/src/log/ModStdio.cc @@ -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; } }