summaryrefslogtreecommitdiffstats
path: root/support
diff options
context:
space:
mode:
authorJeff Trawick <trawick@apache.org>2007-11-20 20:38:13 +0100
committerJeff Trawick <trawick@apache.org>2007-11-20 20:38:13 +0100
commit7daf1c58a96137a3422fcf9c6fdd0cead9502d8d (patch)
tree2733b740cd92d3040ba5e89ca05bef0284b6a029 /support
parentlatest docco xform updates (diff)
downloadapache2-7daf1c58a96137a3422fcf9c6fdd0cead9502d8d.tar.xz
apache2-7daf1c58a96137a3422fcf9c6fdd0cead9502d8d.zip
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
Diffstat (limited to 'support')
-rw-r--r--support/rotatelogs.c43
1 files changed, 23 insertions, 20 deletions
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] <logfile> <rotation time in seconds> "
- "[offset minutes from UTC] or <rotation size in megabytes>\n\n",
+ "Usage: %s [-l] <logfile> "
+ "{<rotation time in seconds>|<rotation size in megabytes>} "
+ "[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(&lt, apr_time_now());
+ utc_offset = lt.tm_gmtoff;
+ }
+ tLogStart = (int)apr_time_sec(apr_time_now()) + utc_offset;
}
if (use_strftime) {