From 5e4bf69196488a32a68e445c8ccdf064c69b401b Mon Sep 17 00:00:00 2001 From: Ruediger Pluem Date: Sat, 1 Dec 2007 16:14:21 +0000 Subject: [PATCH] - 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 Reviewed by: rpluem git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@600154 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES | 3 +++ support/rotatelogs.c | 38 +++++++++++++++++--------------------- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/CHANGES b/CHANGES index 28bea9750c..eb91f13b96 100644 --- a/CHANGES +++ b/CHANGES @@ -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 , Joe Orton] diff --git a/support/rotatelogs.c b/support/rotatelogs.c index a408540a1b..c339c3b6c8 100644 --- a/support/rotatelogs.c +++ b/support/rotatelogs.c @@ -92,6 +92,21 @@ static void usage(const char *argv0, const char *reason) 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(<, 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 @@ int main (int argc, const char * const argv[]) 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(<, 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 @@ int main (int argc, const char * const argv[]) 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(<, 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) { -- 2.40.0