]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
logger: fix invalid timestamp in rfc5425 format
authorRainer Gerhards <rgerhards@adiscon.com>
Wed, 4 Mar 2015 17:50:30 +0000 (18:50 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 12 Mar 2015 09:15:05 +0000 (10:15 +0100)
The timestamp is written as

2015-03-04T15:02:02.566782+0100

unfortunately, this is not an RFC3339 timestamp as demanded by rfc5424.
The colon in the time offset field is missing. The correct timestamp is

2015-03-04T15:02:02.566782+01:00

(Note "+0100" vs. "+01:00")

misc-utils/logger.c

index db6fd448a334e328bccbddf7b5fb93987dda8ef3..7abfcf12224b9231dc34f1a1580417baa93c73ad 100644 (file)
@@ -359,8 +359,12 @@ static void syslog_rfc5424(const  struct logger_ctl *ctl, const char *msg)
                if ((tm = localtime(&tv.tv_sec)) != NULL) {
                        char fmt[64];
 
-                       strftime(fmt, sizeof(fmt), " %Y-%m-%dT%H:%M:%S.%%06u%z",
-                                tm);
+                       const size_t i = strftime(fmt, sizeof(fmt),
+                                       " %Y-%m-%dT%H:%M:%S.%%06u%z ", tm);
+                       /* patch TZ info to comply with RFC3339 (we left SP at end) */
+                       fmt[i-1] = fmt[i-2];
+                       fmt[i-2] = fmt[i-3];
+                       fmt[i-3] = ':';
                        snprintf(time, sizeof(time), fmt, tv.tv_usec);
                } else
                        err(EXIT_FAILURE, _("localtime() failed"));