Blame SOURCES/httpd-2.4.6-rotatelog-timezone.patch

6670f0
diff --git a/support/rotatelogs.c b/support/rotatelogs.c
6670f0
index c2373f56..14b0ec4 100644
6670f0
--- a/support/rotatelogs.c
6670f0
+++ b/support/rotatelogs.c
6670f0
@@ -151,14 +151,14 @@ static void usage(const char *argv0, const char *reason)
6670f0
     exit(1);
6670f0
 }
6670f0
 
6670f0
-/*
6670f0
- * Get the unix time with timezone corrections
6670f0
- * given in the config struct.
6670f0
- */
6670f0
-static int get_now(rotate_config_t *config)
6670f0
+/* This function returns the current Unix time (time_t) plus any
6670f0
+ * configured or derived local time offset.  The offset applied is
6670f0
+ * returned via *offset. */
6670f0
+static int get_now(rotate_config_t *config, apr_int32_t *offset)
6670f0
 {
6670f0
     apr_time_t tNow = apr_time_now();
6670f0
-    int utc_offset = config->utc_offset;
6670f0
+    int utc_offset;
6670f0
+
6670f0
     if (config->use_localtime) {
6670f0
         /* Check for our UTC offset before using it, since it might
6670f0
          * change if there's a switch between standard and daylight
6670f0
@@ -168,6 +168,13 @@ static int get_now(rotate_config_t *config)
6670f0
         apr_time_exp_lt(&lt, tNow);
6670f0
         utc_offset = lt.tm_gmtoff;
6670f0
     }
6670f0
+    else {
6670f0
+        utc_offset = config->utc_offset;
6670f0
+    }
6670f0
+
6670f0
+    if (offset)
6670f0
+        *offset = utc_offset;
6670f0
+
6670f0
     return (int)apr_time_sec(tNow) + utc_offset;
6670f0
 }
6670f0
 
6670f0
@@ -231,13 +238,13 @@ static void checkRotate(rotate_config_t *config, rotate_status_t *status)
6670f0
             status->rotateReason = ROTATE_SIZE;
6670f0
         }
6670f0
         else if (config->tRotation) {
6670f0
-            if (get_now(config) >= status->tLogEnd) {
6670f0
+            if (get_now(config, NULL) >= status->tLogEnd) {
6670f0
                 status->rotateReason = ROTATE_TIME;
6670f0
             }
6670f0
         }
6670f0
     }
6670f0
     else if (config->tRotation) {
6670f0
-        if (get_now(config) >= status->tLogEnd) {
6670f0
+        if (get_now(config, NULL) >= status->tLogEnd) {
6670f0
             status->rotateReason = ROTATE_TIME;
6670f0
         }
6670f0
     }
6670f0
@@ -361,12 +368,16 @@ static void truncate_and_write_error(rotate_status_t *status)
6670f0
 static void doRotate(rotate_config_t *config, rotate_status_t *status)
6670f0
 {
6670f0
 
6670f0
-    int now = get_now(config);
6670f0
+    apr_int32_t offset;
6670f0
+    int now;
6670f0
     int tLogStart;
6670f0
     apr_status_t rv;
6670f0
     struct logfile newlog;
6670f0
     int thisLogNum = -1;
6670f0
 
6670f0
+    /* Retrieve local-time-adjusted-Unix-time. */
6670f0
+    now = get_now(config, &offset);
6670f0
+
6670f0
     status->rotateReason = ROTATE_NONE;
6670f0
 
6670f0
     if (config->tRotation) {
6670f0
@@ -392,7 +403,13 @@ static void doRotate(rotate_config_t *config, rotate_status_t *status)
6670f0
         apr_time_exp_t e;
6670f0
         apr_size_t rs;
6670f0
 
6670f0
-        apr_time_exp_gmt(&e, tNow);
6670f0
+        /* Explode the local-time-adjusted-Unix-time into a struct tm,
6670f0
+         * first *reversing* local-time-adjustment applied by
6670f0
+         * get_now() if we are using localtime. */
6670f0
+        if (config->use_localtime)
6670f0
+            apr_time_exp_lt(&e, tNow - apr_time_from_sec(offset));
6670f0
+        else
6670f0
+            apr_time_exp_gmt(&e, tNow);
6670f0
         apr_strftime(newlog.name, &rs, sizeof(newlog.name), config->szLogRoot, &e);
6670f0
     }
6670f0
     else {
6670f0
@@ -660,7 +677,7 @@ int main (int argc, const char * const argv[])
6670f0
         nRead = sizeof(buf);
6670f0
 #if APR_FILES_AS_SOCKETS
6670f0
         if (config.create_empty && config.tRotation) {
6670f0
-            polltimeout = status.tLogEnd ? status.tLogEnd - get_now(&config) : config.tRotation;
6670f0
+            polltimeout = status.tLogEnd ? status.tLogEnd - get_now(&config, NULL) : config.tRotation;
6670f0
             if (polltimeout <= 0) {
6670f0
                 pollret = APR_TIMEUP;
6670f0
             }