httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rpl...@apache.org
Subject svn commit: r600154 - in /httpd/httpd/trunk: CHANGES support/rotatelogs.c
Date Sat, 01 Dec 2007 16:14:22 GMT
Author: rpluem
Date: Sat Dec  1 08:14:21 2007
New Revision: 600154

URL: http://svn.apache.org/viewvc?rev=600154&view=rev
Log:
- when using "-l" reduce two consecutive calls to apr_time_now() to one.
  This will not change the logic if no "-l" gets used, and it will spare
  one call to apr_time_now() in case "-l" gets used and more important
  it gives the code better atomicity, because in fact between the two calls
  there is a slight change of jumping oder the DST boundary

- for historic reasons the same code block is used two times with a
  slightly different way of transforming apr_time_t to int
  (once division by APR_USEC_PER_SEC, once call to apr_time_sec()),
  so let's unify it.

- finally move the block into a function, because it gets used already
  two times.

PR: 44004
Submitted by: Rainer Jung <rainer.jung kippdata.de>
Reviewed by: rpluem

Modified:
    httpd/httpd/trunk/CHANGES
    httpd/httpd/trunk/support/rotatelogs.c

Modified: httpd/httpd/trunk/CHANGES
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/CHANGES?rev=600154&r1=600153&r2=600154&view=diff
==============================================================================
--- httpd/httpd/trunk/CHANGES [utf-8] (original)
+++ httpd/httpd/trunk/CHANGES [utf-8] Sat Dec  1 08:14:21 2007
@@ -2,6 +2,9 @@
 Changes with Apache 2.3.0
 [ When backported to 2.2.x, remove entry from this file ]
 
+  *) rotatelogs: Improve atomicity when using -l and cleaup code.
+     PR 44004 [Rainer Jung]
+
   *) mod_ssl: Add support for OCSP validation of client certificates.
      PR 41123.  [Marc Stern <marc.stern approach.be>, Joe Orton]
 

Modified: httpd/httpd/trunk/support/rotatelogs.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/support/rotatelogs.c?rev=600154&r1=600153&r2=600154&view=diff
==============================================================================
--- httpd/httpd/trunk/support/rotatelogs.c (original)
+++ httpd/httpd/trunk/support/rotatelogs.c Sat Dec  1 08:14:21 2007
@@ -92,6 +92,21 @@
     exit(1);
 }
 
+static int get_now(int use_localtime, int utc_offset)
+{
+    apr_time_t tNow = 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, tNow);
+        utc_offset = lt.tm_gmtoff;
+    }
+    return (int)apr_time_sec(tNow) + utc_offset;
+}
+
 int main (int argc, const char * const argv[])
 {
     char buf[BUFSIZE], buf2[MAX_PATH], errbuf[ERRMSGSZ];
@@ -170,17 +185,7 @@
             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;
+            now = get_now(use_localtime, utc_offset);
             if (nLogFD != NULL && now >= tLogEnd) {
                 nLogFDprev = nLogFD;
                 nLogFD = NULL;
@@ -213,16 +218,7 @@
                 tLogStart = (now / tRotation) * tRotation;
             }
             else {
-                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;
+                tLogStart = get_now(use_localtime, utc_offset);
             }
 
             if (use_strftime) {



Mime
View raw message