From: Rainer Gerhards Date: Wed, 4 Mar 2015 17:50:30 +0000 (+0100) Subject: logger: fix invalid timestamp in rfc5425 format X-Git-Tag: v2.27-rc1~405^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2f267611f0d8d1ea6e9a2f404521e9208390bb21;p=thirdparty%2Futil-linux.git logger: fix invalid timestamp in rfc5425 format 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") --- diff --git a/misc-utils/logger.c b/misc-utils/logger.c index db6fd448a3..7abfcf1222 100644 --- a/misc-utils/logger.c +++ b/misc-utils/logger.c @@ -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"));