]> granicus.if.org Git - apache/commitdiff
Allow local timestamps to be used when rotating based on file size.
authorJeff Trawick <trawick@apache.org>
Tue, 20 Nov 2007 19:38:13 +0000 (19:38 +0000)
committerJeff Trawick <trawick@apache.org>
Tue, 20 Nov 2007 19:38:13 +0000 (19:38 +0000)
IOW, accept and respect either -l or UTC offset when rotating
based on file size.

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

CHANGES
support/rotatelogs.c

diff --git a/CHANGES b/CHANGES
index 8cac46df66b94786a0d71930d4eb46b020e97ec3..4567dc1e128502f5b3977451d9a4e98cea25560b 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -3,7 +3,8 @@ Changes with Apache 2.3.0
 [ When backported to 2.2.x, remove entry from this file ]
 
   *) rotatelogs: Change command-line parsing to report more types
-     of errors.  [Jeff Trawick]
+     of errors.  Allow local timestamps to be used when rotating based
+     on file size.  [Jeff Trawick]
 
   *) mod_unique_id: Fix timestamp value in UNIQUE_ID.
      PR 37064 [Kobayashi <kobayashi firstserver.co.jp>]
index 451ea13a767d7e6e3a4f9ad3c4dcca6fa1fce499..a408540a1b6cdef93ced992602599f6f70a01b85 100644 (file)
@@ -67,8 +67,9 @@ static void usage(const char *argv0, const char *reason)
         fprintf(stderr, "%s\n", reason);
     }
     fprintf(stderr,
-            "Usage: %s [-l] <logfile> <rotation time in seconds> "
-            "[offset minutes from UTC] or <rotation size in megabytes>\n\n",
+            "Usage: %s [-l] <logfile> "
+            "{<rotation time in seconds>|<rotation size in megabytes>} "
+            "[offset minutes from UTC]\n\n",
             argv0);
 #ifdef OS2
     fprintf(stderr,
@@ -127,20 +128,14 @@ int main (int argc, const char * const argv[])
         usage(argv[0], NULL /* specific error message already issued */ );
     }
 
-    if (opt->ind + 2 > argc) { /* must have at least a filename and a rotation parameter */
-        usage(argv[0], "Too few arguments");
+    if (opt->ind + 2 != argc && opt->ind + 3 != argc) {
+        usage(argv[0], "Incorrect number of arguments");
     }
 
     szLogRoot = argv[opt->ind++];
 
     ptr = strchr(argv[opt->ind], 'M');
     if (ptr) { /* rotation based on file size */
-        if (opt->ind + 1 != argc) {
-            usage(argv[0], "Wrong number of arguments for size-based rotation");
-        }
-        if (use_localtime) {
-            usage(argv[0], "-l is not supported with size-based rotation");
-        }
         if (*(ptr+1) == '\0') {
             sRotation = atoi(argv[opt->ind]) * 1048576;
         }
@@ -149,20 +144,19 @@ int main (int argc, const char * const argv[])
         }
     }
     else { /* rotation based on elapsed time */
-        if (opt->ind + 1 != argc && opt->ind + 2 != argc) {
-            usage(argv[0], "Wrong number of arguments for time-based rotation");
-        }
-        if (opt->ind + 2 == argc) {
-            if (use_localtime) {
-                usage(argv[0], "UTC offset parameter is not valid with -l");
-            }
-            utc_offset = atoi(argv[opt->ind + 1]) * 60;
-        }
         tRotation = atoi(argv[opt->ind]);
         if (tRotation <= 0) {
             usage(argv[0], "Invalid rotation time parameter");
         }
     }
+    opt->ind++;
+
+    if (opt->ind < argc) { /* have UTC offset */
+        if (use_localtime) {
+            usage(argv[0], "UTC offset parameter is not valid with -l");
+        }
+        utc_offset = atoi(argv[opt->ind]) * 60;
+    }
 
     use_strftime = (strchr(szLogRoot, '%') != NULL);
     if (apr_file_open_stdin(&f_stdin, pool) != APR_SUCCESS) {
@@ -219,7 +213,16 @@ int main (int argc, const char * const argv[])
                 tLogStart = (now / tRotation) * tRotation;
             }
             else {
-                tLogStart = (int)apr_time_sec(apr_time_now());
+                if (use_localtime) {
+                    /* Check for our UTC offset before using it, since it might
+                     * change if there's a switch between standard and daylight
+                     * savings time.
+                     */
+                    apr_time_exp_t lt;
+                    apr_time_exp_lt(&lt, apr_time_now());
+                    utc_offset = lt.tm_gmtoff;
+                }
+                tLogStart = (int)apr_time_sec(apr_time_now()) + utc_offset;
             }
 
             if (use_strftime) {