]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
merge from 2.1-dev:
authorJeff Trawick <trawick@apache.org>
Sat, 4 Sep 2004 11:36:14 +0000 (11:36 +0000)
committerJeff Trawick <trawick@apache.org>
Sat, 4 Sep 2004 11:36:14 +0000 (11:36 +0000)
Add -l option to rotatelogs to let it use local time rather than
UTC.

PR:             24417
Submitted by: Ken Coar, Uli Zappe <uli ritual.org>
Reviewed by: trawick, nd, stoddard

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

CHANGES
STATUS
support/rotatelogs.c

diff --git a/CHANGES b/CHANGES
index 58a4f23d2eb2a15bcbcaceadd2c54b36c2f8d706..ee5b0ee8e577e12ccfe815d532d472d4828144a9 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,5 +1,8 @@
 Changes with Apache 2.0.51
 
+  *) Add -l option to rotatelogs to let it use local time rather than
+     UTC.  PR 24417.  [Ken Coar, Uli Zappe <uli ritual.org>]
+
   *) mod_log_config: Fix a bug which prevented request completion time
      from being logged for I_INSIST_ON_EXTRA_CYCLES_FOR_CLF_COMPLIANCE
      processing.  PR 29696.  [Alois Treindl <alois astro.ch>]
diff --git a/STATUS b/STATUS
index 71867dfa73e6d5222607415e4113e6bf44293d29..97841d55f6f26aecfb19e53c8fe94546e84c132b 100644 (file)
--- a/STATUS
+++ b/STATUS
@@ -1,5 +1,5 @@
 APACHE 2.0 STATUS:                                              -*-text-*-
-Last modified at [$Date: 2004/09/03 20:57:53 $]
+Last modified at [$Date: 2004/09/04 11:36:13 $]
 
 Release:
 
@@ -104,11 +104,6 @@ PATCHES TO BACKPORT FROM 2.1
              native chars here and it will be converted later? (I'm not sure)
          (2) I'd put out (null) only if val is NULL, not if it's empty.
 
-    *) Add -l option to rotatelogs to let it use local time rather than
-       UTC.  PR 24417.  [Ken Coar, Uli Zappe <uli ritual.org>]
-         support/rotatelogs.c: r1.33, r1.34, r1.35
-       +1: trawick, nd, stoddard
-
     *) Fix the handling of URIs containing %2F when AllowEncodedSlashes
        is enabled.  Previously, such urls would still be rejected with
        404.
index f64c9967b3a33cf72d47b7c376ceb12d5370305d..10e21209789b374a6ebe7cdbdd274cf544afceea 100644 (file)
  * Ported to APR by Mladen Turk <mturk@mappingsoft.com>
  *
  * 23 Sep 2001
+ *
+ * -l option added 2004-06-11
+ *
+ * -l causes the use of local time rather than GMT as the base for the
+ * interval.  NB: Using -l in an environment which changes the GMT offset
+ * (such as for BST or DST) can lead to unpredictable results!
+ *
  */
 
 
@@ -60,19 +67,31 @@ int main (int argc, const char * const argv[])
     int nMessCount = 0;
     apr_size_t nRead, nWrite;
     int use_strftime = 0;
+    int use_localtime = 0;
     int now = 0;
     const char *szLogRoot;
     apr_file_t *f_stdin, *nLogFD = NULL, *nLogFDprev = NULL;
     apr_pool_t *pool;
     char *ptr = NULL;
+    int argBase = 0;
+    int argFile = 1;
+    int argIntv = 2;
+    int argOffset = 3;
 
     apr_app_initialize(&argc, &argv, NULL);
     atexit(apr_terminate);
 
     apr_pool_create(&pool, NULL);
-    if (argc < 3 || argc > 4) {
+    if ((argc > 2) && (strcmp(argv[1], "-l") == 0)) {
+        argBase++;
+        argFile += argBase;
+        argIntv += argBase;
+        argOffset += argBase;
+        use_localtime = 1;
+    }
+    if (argc < (argBase + 3) || argc > (argBase + 4)) {
         fprintf(stderr,
-                "Usage: %s <logfile> <rotation time in seconds> "
+                "Usage: %s [-l] <logfile> <rotation time in seconds> "
                 "[offset minutes from UTC] or <rotation size in megabytes>\n\n",
                 argv[0]);
 #ifdef OS2
@@ -96,12 +115,12 @@ int main (int argc, const char * const argv[])
         exit(1);
     }
 
-    szLogRoot = argv[1];
+    szLogRoot = argv[argFile];
 
-    ptr = strchr (argv[2], 'M');
+    ptr = strchr(argv[argIntv], 'M');
     if (ptr) {
         if (*(ptr+1) == '\0') {
-            sRotation = atoi(argv[2]) * 1048576;
+            sRotation = atoi(argv[argIntv]) * 1048576;
         }
         if (sRotation == 0) {
             fprintf(stderr, "Invalid rotation size parameter\n");
@@ -109,10 +128,10 @@ int main (int argc, const char * const argv[])
         }
     }
     else {
-        if (argc >= 4) {
-            utc_offset = atoi(argv[3]) * 60;
+        if (argc >= (argBase + 4)) {
+            utc_offset = atoi(argv[argOffset]) * 60;
         }
-        tRotation = atoi(argv[2]);
+        tRotation = atoi(argv[argIntv]);
         if (tRotation <= 0) {
             fprintf(stderr, "Rotation time must be > 0\n");
             exit(6);
@@ -127,9 +146,20 @@ int main (int argc, const char * const argv[])
 
     for (;;) {
         nRead = sizeof(buf);
-        if (apr_file_read(f_stdin, buf, &nRead) != APR_SUCCESS)
+        if (apr_file_read(f_stdin, buf, &nRead) != APR_SUCCESS) {
             exit(3);
+        }
         if (tRotation) {
+            /*
+             * Check for our UTC offset every time through the loop, since
+             * it might change if there's a switch between standard and
+             * daylight savings time.
+             */
+            if (use_localtime) {
+                apr_time_exp_t lt;
+                apr_time_exp_lt(&lt, apr_time_now());
+                utc_offset = lt.tm_gmtoff;
+            }
             now = (int)(apr_time_now() / APR_USEC_PER_SEC) + utc_offset;
             if (nLogFD != NULL && now >= tLogEnd) {
                 nLogFDprev = nLogFD;
@@ -158,10 +188,12 @@ int main (int argc, const char * const argv[])
         if (nLogFD == NULL) {
             int tLogStart;
                 
-            if (tRotation)
+            if (tRotation) {
                 tLogStart = (now / tRotation) * tRotation;
-            else
+            }
+            else {
                 tLogStart = (int)apr_time_sec(apr_time_now());
+            }
 
             if (use_strftime) {
                 apr_time_t tNow = apr_time_from_sec(tLogStart);