From 9fd0a7a96c8525289d7072fa688579be6418ec30 Mon Sep 17 00:00:00 2001 From: J William Piggott Date: Sun, 8 Oct 2017 16:06:24 -0400 Subject: lib/timeutils: add get_gmtoff() This new function returns the GMT offset relative to its argument. It is used in this patch to fix two bugs: 1) On platforms that the tm struct excludes tm_gmtoff, hwclock assumes a one hour DST offset. This can cause an incorrect kernel timezone setting. For example: Master branch tested with tm_gmtoff illustrates the correct offset: $ TZ="Australia/Lord_Howe" hwclock --hctosys --test | grep settimeofday Calling settimeofday(1507494204.192398, -660) Master branch tested without tm_gmtoff has an incorrect offset: $ TZ="Australia/Lord_Howe" hwclock --hctosys --test | grep settimeofday Calling settimeofday(1507494249.193852, -690) Patched tested without tm_gmtoff has the correct offset: $ TZ="Australia/Lord_Howe" hwclock --hctosys --test | grep settimeofday Calling settimeofday(1507494260.194208, -660) 2) ISO 8601 'extended' format requires all time elements to use a colon (:). Current invalid ISO 8601: $ hwclock 2017-10-08 16:25:17.895462-0400 Patched: $ hwclock 2017-10-08 16:25:34.141895-04:00 Also required by this change: login-utils/last.c: increase ISO out_len and in_len by one to accommodate the addition of the timezone colon. Signed-off-by: J William Piggott --- sys-utils/hwclock.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'sys-utils/hwclock.c') diff --git a/sys-utils/hwclock.c b/sys-utils/hwclock.c index c2c20812c..3ac43efee 100644 --- a/sys-utils/hwclock.c +++ b/sys-utils/hwclock.c @@ -608,13 +608,7 @@ set_system_clock(const struct hwclock_control *ctl, const struct timezone tz_utc = { 0 }; broken = localtime(&newtime.tv_sec); -#ifdef HAVE_TM_GMTOFF - minuteswest = -broken->tm_gmtoff / 60; /* GNU extension */ -#else - minuteswest = timezone / 60; - if (broken->tm_isdst) - minuteswest -= 60; -#endif + minuteswest = -get_gmtoff(broken) / 60; if (ctl->debug) { if (ctl->hctosys && !ctl->universal) -- cgit v1.2.3-55-g7522