[lxc-devel] [lxc/master] log: fix lxc_unix_epoch_to_utc()
brauner on Github
lxc-bot at linuxcontainers.org
Mon Feb 27 15:03:38 UTC 2017
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 500 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20170227/10bb868b/attachment.bin>
-------------- next part --------------
From 86698d3885b8bf575b4f3d8e99d62b20f0682e5d Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Mon, 27 Feb 2017 16:02:24 +0100
Subject: [PATCH] log: fix lxc_unix_epoch_to_utc()
The conversion algorithm used uses a clever trick by letting a year start at 1
March. So we need to add 1 for January and February.
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/log.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/src/lxc/log.c b/src/lxc/log.c
index cdeec9f..339b81c 100644
--- a/src/lxc/log.c
+++ b/src/lxc/log.c
@@ -173,7 +173,7 @@ int lxc_unix_epoch_to_utc(char *buf, size_t bufsize, const struct timespec *time
yoe = (doe - doe / 1460 + doe / 36524 - doe / 146096) / 365;
/* Given year-of-era, and era, one can now compute the year. */
- year = (yoe) + era * 400;
+ year = yoe + era * 400;
/* Also the day-of-year, again with the year beginning on Mar. 1, can be
* computed from the day-of-era and year-of-era.
@@ -193,6 +193,11 @@ int lxc_unix_epoch_to_utc(char *buf, size_t bufsize, const struct timespec *time
*/
month = mp + (mp < 10 ? 3 : -9);
+ /* The algorithm assumes that a year begins on 1 March, so add 1 before
+ * that. */
+ if (month < 3)
+ year++;
+
/* Transform days in the epoch to seconds. */
d_in_s = epoch_to_days * 86400;
More information about the lxc-devel
mailing list