summaryrefslogtreecommitdiffstats
path: root/sys-utils/hwclock.c
diff options
context:
space:
mode:
authorJoseph Parmelee2013-03-18 05:48:57 +0100
committerKarel Zak2013-03-18 10:31:32 +0100
commitd53f8ecfbf036eddb2aef737dc0973a613d80ced (patch)
tree8530b3f24f23de976a01fbaec92e2693f2fbcebe /sys-utils/hwclock.c
parentfsck.cramfs: fix compiler warnings (diff)
downloadkernel-qcow2-util-linux-d53f8ecfbf036eddb2aef737dc0973a613d80ced.tar.gz
kernel-qcow2-util-linux-d53f8ecfbf036eddb2aef737dc0973a613d80ced.tar.xz
kernel-qcow2-util-linux-d53f8ecfbf036eddb2aef737dc0973a613d80ced.zip
hwclock: make hwclock leap-second-aware
Attached is a patch file leap_seconds.patch against util-linux-2.22.2 that allows leap seconds to be included in hwclock --show or --hctosys. The current code uses the default UTC zonefile in reading the hardware RTC with mktime(). This zonefile usually does not include leap seconds. As of this date there have been a total of 25 leap seconds added since the epoch (start of 1970). This is particularly a problem for systems using ntp to maintain their system clocks because ntp does take leap seconds into account. A user can specify a leap-second-aware zonefile via /etc/localtime. By defining the environment variable TZUTC, mktime() can be induced to use a matching UTC zonefile that includes leap seconds. The default behavior (TZUTC undefined) is unchanged. Regards, Joseph Parmelee jparmele at wildbear.com
Diffstat (limited to 'sys-utils/hwclock.c')
-rw-r--r--sys-utils/hwclock.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/sys-utils/hwclock.c b/sys-utils/hwclock.c
index 9256ec5bd..b7f569207 100644
--- a/sys-utils/hwclock.c
+++ b/sys-utils/hwclock.c
@@ -382,8 +382,15 @@ mktime_tz(struct tm tm, const bool universal,
*/
zone = getenv("TZ"); /* remember original time zone */
if (universal) {
- /* Set timezone to UTC */
- setenv("TZ", "", TRUE);
+ /* Set timezone to UTC as defined by the environment
+ * variable TZUTC. TZUTC undefined gives the default UTC
+ * zonefile which usually does not take into account leap
+ * seconds. Define TZUTC to select your UTC zonefile which
+ * does include leap seconds. For example, with recent GNU
+ * libc's:
+ * TZUTC=:/usr/share/zoneinfo/right/UTC
+ */
+ setenv("TZ", getenv("TZUTC"), TRUE);
/*
* Note: tzset() gets called implicitly by the time code,
* but only the first time. When changing the environment