Hi,

syslogd(8) -Z generates log files in ISO format and UTC.  newsyslog(8)
still uses BSD syslog timstamps.  This looks a bit ugly when you
combine them this way.

Mar 12 01:00:01 t430s newsyslog[32158]: logfile turned over
2017-03-12T00:00:01.547Z t430s syslogd: restart

I think it is overkill to add a -Z option to newsyslog.  In fact
it would better if the creation year and the time zone delta is
always visible at the beginning of the file.  So you can still look
at the short timestamps from syslogd and figure out when it all
started.

2017-03-13T22:02:33+01:00 t430s newsyslog[42096]: logfile turned over
Mar 13 22:02:33 t430s syslogd: restart

Although this would be a bit inconsistent when used with syslogd -Z.

2017-03-13T22:30:04+01:00 t430s newsyslog[30641]: logfile turned over
2017-03-13T21:30:04.822Z t430s syslogd: restart

I think the combination of local time and time zone without fractions
of seconds is the best choice for newsyslog.  Or should we use
2017-03-13T21:30:04.822Z in newsyslogd?

comments/ok?

bluhm

Index: usr.bin/newsyslog/newsyslog.c
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/usr.bin/newsyslog/newsyslog.c,v
retrieving revision 1.101
diff -u -p -r1.101 newsyslog.c
--- usr.bin/newsyslog/newsyslog.c       1 Jun 2016 16:57:48 -0000       1.101
+++ usr.bin/newsyslog/newsyslog.c       13 Mar 2017 21:57:48 -0000
@@ -142,7 +142,7 @@ int force = 0;              /* Force the logs to be 
 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,23 @@ 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 = localtime(&now.tv_sec);
+       l = strftime(daytime, sizeof(daytime), "%FT%T%z", tm);
+       if (l == 24 && l+1 < sizeof(daytime)) {
+               /* syslog timestamp has colon in time zone, %z may be empty */
+               daytime[l+1] = '\0';
+               daytime[l+0] = daytime[l-1];
+               daytime[l-1] = daytime[l-2];
+               daytime[l-2] = ':';
+       }
 
        /* Let's get our hostname */
        (void)gethostname(hostname, sizeof(hostname));

Reply via email to