Commit 5267c49f by Christian Brauner Committed by Stéphane Graber

log: make sure that date is correctly formatted

- single digit months, days, hours, minutes, and seconds should always be preceded by a 0. Signed-off-by: 's avatarChristian Brauner <christian.brauner@ubuntu.com>
parent 8b79a8fe
...@@ -157,8 +157,9 @@ int lxc_unix_epoch_to_utc(char *buf, size_t bufsize, const struct timespec *time ...@@ -157,8 +157,9 @@ int lxc_unix_epoch_to_utc(char *buf, size_t bufsize, const struct timespec *time
/* Create final timestamp for the log and shorten nanoseconds to 3 /* Create final timestamp for the log and shorten nanoseconds to 3
* digit precision. * digit precision.
*/ */
ret = snprintf(buf, bufsize, "%" PRId64 "%" PRId64 "%" PRId64 "%" PRId64 ret = snprintf(buf, bufsize,
"%" PRId64 "%" PRId64 ".%.3s", "%" PRId64 "%02" PRId64 "%02" PRId64 "%02" PRId64
"%02" PRId64 "%02" PRId64 ".%.3s",
year, month, day, hours, minutes, seconds, nanosec); year, month, day, hours, minutes, seconds, nanosec);
if (ret < 0 || (size_t)ret >= bufsize) if (ret < 0 || (size_t)ret >= bufsize)
return -1; return -1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment