Skip to contentSkip to conversation

PATCH Make hwclock leap-second-aware

PATCH Applied Joseph Parmelee 2 participants 2 messages Mar 18, 2013 Util-Linux package

lore
Share & tools
lore
#0 lore raw

Hello:

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

hwclock.c renamed from hwclock.c.orig +9 -2
@@ -382,8 +382,15 @@
 	 */
 	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
maintainer Applied
#1 lore raw

hwclock.c

Quoted 2 lines · Joseph Parmelee
hwclock.c renamed from hwclock.c.orig +0 -0

Applied. (Please, use Signed-off-by: line in the commit message next time.)

Thanks.

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com