You are viewing a plain text version of this content. The canonical link for it is here.
Posted to bugs@httpd.apache.org by bu...@apache.org on 2002/11/07 16:43:33 UTC
DO NOT REPLY [Bug 14358] New: -
rotatelogs using TZ settings
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=14358>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND
INSERTED IN THE BUG DATABASE.
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=14358
rotatelogs using TZ settings
Summary: rotatelogs using TZ settings
Product: Apache httpd-1.3
Version: 1.3.26
Platform: All
OS/Version: Other
Status: NEW
Severity: Enhancement
Priority: Other
Component: Other
AssignedTo: bugs@httpd.apache.org
ReportedBy: robert.widmer@omv.com
The supplied rotatelogs tool in Apache 1.3 only allows a fixed UTC offset
value. So 2 times a year the config has to be changed.
I added some code in rotatelogs.c to use the local TZ settings automatically.
On the command line the last option is utc_offset in minutes. I added a new
value of "TZ" instead of minutes to use the local time UTC offset with daylight
savings.
This is the diff -C3 old.c new.c:
*** rotatelogs.c.orig Wed Dec 26 18:14:06 2001
--- rotatelogs.c Tue Oct 29 22:21:49 2002
***************
*** 4,9 ****
--- 4,12 ----
* Contributed by Ben Laurie <be...@algroup.co.uk>
*
* 12 Mar 1996
+ *
+ * 28 Oct 2002: added UTC offset using TZ settings
+ * by Robert Widmer <ro...@omv.com>
*/
***************
*** 18,29 ****
#define MAX_PATH 1024
#endif
int main (int argc, char **argv)
{
char buf[BUFSIZE], buf2[MAX_PATH], errbuf[ERRMSGSZ];
time_t tLogEnd = 0, tRotation;
int nLogFD = -1, nLogFDprev = -1, nMessCount = 0, nRead, nWrite;
! int utc_offset = 0;
int use_strftime = 0;
time_t now;
char *szLogRoot;
--- 21,43 ----
#define MAX_PATH 1024
#endif
+ /* RW: return current locale UTC offset */
+ int local_offset (void)
+ {
+ time_t now = time(NULL);
+ struct tm *local_tm = localtime(&now);
+ struct tm *gm_tm = gmtime(&now);
+ time_t local_t = mktime(local_tm);
+ time_t gm_t = mktime(gm_tm);
+ return (local_t - gm_t);
+ }
+
int main (int argc, char **argv)
{
char buf[BUFSIZE], buf2[MAX_PATH], errbuf[ERRMSGSZ];
time_t tLogEnd = 0, tRotation;
int nLogFD = -1, nLogFDprev = -1, nMessCount = 0, nRead, nWrite;
! int utc_offset = 0, use_TZ = 0;
int use_strftime = 0;
time_t now;
char *szLogRoot;
***************
*** 54,65 ****
"starts (N.B. this time will always be a\nmultiple of the "
"rotation time, so you can synchronize cron scripts with
it).\n"
"At the end of each rotation time a new log is started.\n");
exit(1);
}
szLogRoot = argv[1];
if (argc >= 4) {
! utc_offset = atoi(argv[3]) * 60;
}
tRotation = atoi(argv[2]);
if (tRotation <= 0) {
--- 68,91 ----
"starts (N.B. this time will always be a\nmultiple of the "
"rotation time, so you can synchronize cron scripts with
it).\n"
"At the end of each rotation time a new log is started.\n");
+
+ /* RW: additional usage info for the offset parameter*/
+ fprintf(stderr,
+ "\nAn offset value of \"TZ\" will use the TZ settings "
+ "to calculate the UTC offset.\n");
exit(1);
}
szLogRoot = argv[1];
if (argc >= 4) {
! /* RW: UTC offset may be a number or the string "TZ" */
! if (argv[3][0] == 'T') {
! utc_offset = local_offset();
! use_TZ = 1;
! }
! else {
! utc_offset = atoi(argv[3]) * 60;
! }
}
tRotation = atoi(argv[2]);
if (tRotation <= 0) {
***************
*** 82,87 ****
--- 108,116 ----
}
if (nLogFD < 0) {
time_t tLogStart = (now / tRotation) * tRotation;
+ /* RW: refresh utc offset for the new file */
+ if (use_TZ)
+ utc_offset = local_offset();
if (use_strftime) {
struct tm *tm_now;
tm_now = gmtime(&tLogStart);
---------------------------------------------------------------------
To unsubscribe, e-mail: bugs-unsubscribe@httpd.apache.org
For additional commands, e-mail: bugs-help@httpd.apache.org