diff options
author | Ruediger Pluem <rpluem@apache.org> | 2007-12-01 17:14:21 +0100 |
---|---|---|
committer | Ruediger Pluem <rpluem@apache.org> | 2007-12-01 17:14:21 +0100 |
commit | 5e4bf69196488a32a68e445c8ccdf064c69b401b (patch) | |
tree | af46afd7084c7b7cb9dfbc26dc9c7d5980814bc6 /support | |
parent | Update transformations (diff) | |
download | apache2-5e4bf69196488a32a68e445c8ccdf064c69b401b.tar.xz apache2-5e4bf69196488a32a68e445c8ccdf064c69b401b.zip |
- 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
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@600154 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'support')
-rw-r--r-- | support/rotatelogs.c | 38 |
1 files changed, 17 insertions, 21 deletions
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) { |