From 7daf1c58a96137a3422fcf9c6fdd0cead9502d8d Mon Sep 17 00:00:00 2001 From: Jeff Trawick Date: Tue, 20 Nov 2007 19:38:13 +0000 Subject: [PATCH] Allow local timestamps to be used when rotating based on file size. IOW, accept and respect either -l or UTC offset when rotating based on file size. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@596796 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES | 3 ++- support/rotatelogs.c | 43 +++++++++++++++++++++++-------------------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/CHANGES b/CHANGES index 8cac46df66..4567dc1e12 100644 --- a/CHANGES +++ b/CHANGES @@ -3,7 +3,8 @@ Changes with Apache 2.3.0 [ When backported to 2.2.x, remove entry from this file ] *) rotatelogs: Change command-line parsing to report more types - of errors. [Jeff Trawick] + of errors. Allow local timestamps to be used when rotating based + on file size. [Jeff Trawick] *) mod_unique_id: Fix timestamp value in UNIQUE_ID. PR 37064 [Kobayashi ] diff --git a/support/rotatelogs.c b/support/rotatelogs.c index 451ea13a76..a408540a1b 100644 --- a/support/rotatelogs.c +++ b/support/rotatelogs.c @@ -67,8 +67,9 @@ static void usage(const char *argv0, const char *reason) fprintf(stderr, "%s\n", reason); } fprintf(stderr, - "Usage: %s [-l] " - "[offset minutes from UTC] or \n\n", + "Usage: %s [-l] " + "{|} " + "[offset minutes from UTC]\n\n", argv0); #ifdef OS2 fprintf(stderr, @@ -127,20 +128,14 @@ int main (int argc, const char * const argv[]) usage(argv[0], NULL /* specific error message already issued */ ); } - if (opt->ind + 2 > argc) { /* must have at least a filename and a rotation parameter */ - usage(argv[0], "Too few arguments"); + if (opt->ind + 2 != argc && opt->ind + 3 != argc) { + usage(argv[0], "Incorrect number of arguments"); } szLogRoot = argv[opt->ind++]; ptr = strchr(argv[opt->ind], 'M'); if (ptr) { /* rotation based on file size */ - if (opt->ind + 1 != argc) { - usage(argv[0], "Wrong number of arguments for size-based rotation"); - } - if (use_localtime) { - usage(argv[0], "-l is not supported with size-based rotation"); - } if (*(ptr+1) == '\0') { sRotation = atoi(argv[opt->ind]) * 1048576; } @@ -149,20 +144,19 @@ int main (int argc, const char * const argv[]) } } else { /* rotation based on elapsed time */ - if (opt->ind + 1 != argc && opt->ind + 2 != argc) { - usage(argv[0], "Wrong number of arguments for time-based rotation"); - } - if (opt->ind + 2 == argc) { - if (use_localtime) { - usage(argv[0], "UTC offset parameter is not valid with -l"); - } - utc_offset = atoi(argv[opt->ind + 1]) * 60; - } tRotation = atoi(argv[opt->ind]); if (tRotation <= 0) { usage(argv[0], "Invalid rotation time parameter"); } } + opt->ind++; + + if (opt->ind < argc) { /* have UTC offset */ + if (use_localtime) { + usage(argv[0], "UTC offset parameter is not valid with -l"); + } + utc_offset = atoi(argv[opt->ind]) * 60; + } use_strftime = (strchr(szLogRoot, '%') != NULL); if (apr_file_open_stdin(&f_stdin, pool) != APR_SUCCESS) { @@ -219,7 +213,16 @@ int main (int argc, const char * const argv[]) tLogStart = (now / tRotation) * tRotation; } else { - tLogStart = (int)apr_time_sec(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(<, apr_time_now()); + utc_offset = lt.tm_gmtoff; + } + tLogStart = (int)apr_time_sec(apr_time_now()) + utc_offset; } if (use_strftime) { -- 2.40.0