]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/log/ModStdio.cc
Source Format Enforcement (#763)
[thirdparty/squid.git] / src / log / ModStdio.cc
index b4c5c720c83d4a67a4a224eae69aa613df165fcd..fc95307ec6ed9462966838fcf559edaedd60482b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
+ * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
  *
  * Squid software is distributed under GPLv2+ license and includes
  * contributions from numerous individuals and organizations.
@@ -106,8 +106,6 @@ logfile_mod_stdio_rotate(Logfile * lf, const int16_t nRotate)
     struct stat sb;
 #endif
 
-    char from[MAXPATHLEN];
-    char to[MAXPATHLEN];
     l_stdio_t *ll = (l_stdio_t *) lf->data;
     const char *realpath = lf->path+6; // skip 'stdio:' prefix.
     assert(realpath);
@@ -122,12 +120,17 @@ logfile_mod_stdio_rotate(Logfile * lf, const int16_t nRotate)
 
     debugs(0, DBG_IMPORTANT, "Rotate log file " << lf->path);
 
+    SBuf basePath(realpath);
+
     /* Rotate numbers 0 through N up one */
     for (int16_t i = nRotate; i > 1;) {
         --i;
-        snprintf(from, MAXPATHLEN, "%s.%d", realpath, i - 1);
-        snprintf(to, MAXPATHLEN, "%s.%d", realpath, i);
-        xrename(from, to);
+        SBuf from(basePath);
+        from.appendf(".%d", i-1);
+        SBuf to(basePath);
+        to.appendf(".%d", i);
+        FileRename(from, to);
+        // TODO handle rename errors
     }
 
     /* Rotate the current log to .0 */
@@ -136,8 +139,10 @@ logfile_mod_stdio_rotate(Logfile * lf, const int16_t nRotate)
     file_close(ll->fd);     /* always close */
 
     if (nRotate > 0) {
-        snprintf(to, MAXPATHLEN, "%s.%d", realpath, 0);
-        xrename(realpath, to);
+        SBuf to(basePath);
+        to.appendf(".0");
+        FileRename(basePath, to);
+        // TODO handle rename errors
     }
     /* Reopen the log.  It may have been renamed "manually" */
     ll->fd = file_open(realpath, O_WRONLY | O_CREAT | O_TEXT);