altarch-user / rpms / httpd

Forked from rpms/httpd 2 years ago
Clone

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

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