]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
minor tweak to -n with size rotation
authorEric Covener <covener@apache.org>
Fri, 6 Jan 2023 20:45:16 +0000 (20:45 +0000)
committerEric Covener <covener@apache.org>
Fri, 6 Jan 2023 20:45:16 +0000 (20:45 +0000)
Without -t, One line can be added to base "logfile" even when
it's over the size limit already.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1906428 13f79535-47bb-0310-9956-ffa450edef68

support/rotatelogs.c

index 3ebd67c1a63a26905489249a6d1aa6eda699df10..5430f9e2e3c73d6cb15f56d6f87fbf865b97ea46 100644 (file)
@@ -378,6 +378,7 @@ static void doRotate(rotate_config_t *config, rotate_status_t *status)
     apr_status_t rv;
     struct logfile newlog;
     int thisLogNum = -1;
+    int oldreason = status->rotateReason;
 
     /* Retrieve local-time-adjusted-Unix-time. */
     now = get_now(config, &offset);
@@ -472,6 +473,19 @@ static void doRotate(rotate_config_t *config, rotate_status_t *status)
 
         /* New log file is now 'current'. */
         status->current = newlog;
+
+        /* The first write to to the initial file hasn't checked for size
+         * In the normalized timestamp case and the custom strftime case with
+         * any reasonable accuracy, it's futile as the rotation will pick the
+         * same filename again. 
+         * For -n, when not truncating, check and rotate.
+         */
+        if (config->num_files > 0 && oldreason == ROTATE_NEW && !config->truncate) {
+            checkRotate(config, status);
+            if (status->rotateReason != ROTATE_NONE) {
+                doRotate(config, status);
+            }
+        }
     }
     else {
         char *error = apr_psprintf(newlog.pool, "%pm", &rv);