[lxc-devel] [lxc/master] log: make sure that date is correctly formatted

brauner on Github lxc-bot at linuxcontainers.org
Tue Nov 29 06:53:06 UTC 2016


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 461 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20161129/069d6c27/attachment.bin>
-------------- next part --------------
From 9d7468fdd3aa9b5e4a9da729a4dd6d78e58fed91 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 29 Nov 2016 07:50:29 +0100
Subject: [PATCH] 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: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/lxc/log.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/lxc/log.c b/src/lxc/log.c
index 549a160..17e81d2 100644
--- a/src/lxc/log.c
+++ b/src/lxc/log.c
@@ -224,8 +224,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
 	 * digit precision.
 	 */
-	ret = snprintf(buf, bufsize, "%" PRId64 "%" PRId64 "%" PRId64 "%" PRId64
-				     "%" PRId64 "%" PRId64 ".%.3s",
+	ret = snprintf(buf, bufsize,
+		       "%" PRId64 "%02" PRId64 "%02" PRId64 "%02" PRId64
+		       "%02" PRId64 "%02" PRId64 ".%.3s",
 		       year, month, day, hours, minutes, seconds, nanosec);
 	if (ret < 0 || (size_t)ret >= bufsize)
 		return -1;


More information about the lxc-devel mailing list