From 3c771f9e4ba46d3e39334cb20eab98221043f1e2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rafa=C5=82=20Mi=C5=82ecki?= Date: Tue, 5 Jul 2016 15:40:56 +0200 Subject: [PATCH] system: fix localtime value in ubus info method output MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Function mktime respects current time zone and calling it results in converting time back to the UTC. It means we were never returning a time for local zone but GMT one. The easiest solution is to use tm_gmtoff from struct tm. Unfortunately this isn't part of POSIX but it seems to be the best idea anyway. Alternative (worse?) solutions: 1) Use timegm that is nonstandard GNU extension 2) Work with TZ env (getenv & (un)setenv) that is not thread-safe 3) Use timegm (next to localtime) and implement function comparing two struct tm. This is what glibc does internally (tm_diff) when compiled without HAVE_TM_GMTOFF. Signed-off-by: Rafał Miłecki --- system.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system.c b/system.c index 504cdc0..569a75d 100644 --- a/system.c +++ b/system.c @@ -205,7 +205,7 @@ static int system_info(struct ubus_context *ctx, struct ubus_object *obj, blob_buf_init(&b, 0); - blobmsg_add_u32(&b, "localtime", mktime(tm)); + blobmsg_add_u32(&b, "localtime", now + tm->tm_gmtoff); #ifdef linux blobmsg_add_u32(&b, "uptime", info.uptime); -- 2.25.1