diff options
author | Alexander Bluhm <bluhm@cvs.openbsd.org> | 2017-03-16 10:32:02 +0000 |
---|---|---|
committer | Alexander Bluhm <bluhm@cvs.openbsd.org> | 2017-03-16 10:32:02 +0000 |
commit | b4fa3d1490b67b060f904449ed443d1c4c7f062b (patch) | |
tree | 9b3fdf4399a50e715dbfa073ec63b1c98f976850 /usr.bin | |
parent | f7e973c3951e28c619305d67145ccfb71ae73d29 (diff) |
syslogd(8) -Z generates log files with time in ISO format and UTC.
newsyslog(8) still used the traditional BSD syslog timstamps in
local time zone. Convert the latter to the new format unconditionally.
It is usefull to have a distinct timestamp including the year at
the beginning of every logfile.
OK deraadt@ jung@
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/newsyslog/newsyslog.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/usr.bin/newsyslog/newsyslog.c b/usr.bin/newsyslog/newsyslog.c index 0120e56907f..b327c5379f3 100644 --- a/usr.bin/newsyslog/newsyslog.c +++ b/usr.bin/newsyslog/newsyslog.c @@ -1,4 +1,4 @@ -/* $OpenBSD: newsyslog.c,v 1.101 2016/06/01 16:57:48 tedu Exp $ */ +/* $OpenBSD: newsyslog.c,v 1.102 2017/03/16 10:32:01 bluhm Exp $ */ /* * Copyright (c) 1999, 2002, 2003 Todd C. Miller <Todd.Miller@courtesan.com> @@ -142,7 +142,7 @@ int force = 0; /* Force the logs to be rotated */ char *conf = CONF; /* Configuration file to use */ time_t timenow; char hostname[HOST_NAME_MAX+1]; /* Hostname */ -char *daytime; /* timenow in human readable form */ +char daytime[33]; /* timenow in human readable form */ char *arcdir; /* Dir to put archives in (if it exists) */ FILE *openmail(void); @@ -402,12 +402,18 @@ send_signal(char *pidfile, int signal) void parse_args(int argc, char **argv) { + struct timeval now; + struct tm *tm; + size_t l; char *p; int ch; - timenow = time(NULL); - daytime = ctime(&timenow) + 4; - daytime[15] = '\0'; + gettimeofday(&now, NULL); + timenow = now.tv_sec; + tm = gmtime(&now.tv_sec); + l = strftime(daytime, sizeof(daytime), "%FT%T", tm); + snprintf(daytime + l, sizeof(daytime) - l, ".%03ldZ", + now.tv_usec / 1000); /* Let's get our hostname */ (void)gethostname(hostname, sizeof(hostname)); |