Util-Linux package development
 help / color / mirror / Atom feed
* [PATCH] hwclock: remove UTC-0 localization hack
@ 2016-07-10 20:02 Sami Kerola
  2016-07-11 20:23 ` J William Piggott
  0 siblings, 1 reply; 13+ messages in thread
From: Sami Kerola @ 2016-07-10 20:02 UTC (permalink / raw)
  To: util-linux; +Cc: Sami Kerola

There is no need to re-implement timegm() by removing TZ localization for a
moment, just use timegm(3) instead.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 sys-utils/hwclock.c | 34 +++++-----------------------------
 1 file changed, 5 insertions(+), 29 deletions(-)

diff --git a/sys-utils/hwclock.c b/sys-utils/hwclock.c
index e98c2c0..bcaab8b 100644
--- a/sys-utils/hwclock.c
+++ b/sys-utils/hwclock.c
@@ -388,27 +388,11 @@ static void
 mktime_tz(struct tm tm, const bool universal,
 	  bool * valid_p, time_t * systime_p)
 {
-	time_t mktime_result;	/* The value returned by our mktime() call */
-	char *zone;		/* Local time zone name */
-
-	/*
-	 * We use the C library function mktime(), but since it only works
-	 * on local time zone input, we may have to fake it out by
-	 * temporarily changing the local time zone to UTC.
-	 */
-	zone = getenv("TZ");	/* remember original time zone */
-	if (universal) {
-		/* Set timezone to UTC */
-		setenv("TZ", "", TRUE);
-		/*
-		 * Note: tzset() gets called implicitly by the time code,
-		 * but only the first time. When changing the environment
-		 * variable, better call tzset() explicitly.
-		 */
-		tzset();
-	}
-	mktime_result = mktime(&tm);
-	if (mktime_result == -1) {
+	if (universal)
+		*systime_p = timegm(&tm);
+	else
+		*systime_p = mktime(&tm);
+	if (*systime_p == -1) {
 		/*
 		 * This apparently (not specified in mktime() documentation)
 		 * means the 'tm' structure does not contain valid values
@@ -416,7 +400,6 @@ mktime_tz(struct tm tm, const bool universal,
 		 * mktime() returns -1).
 		 */
 		*valid_p = FALSE;
-		*systime_p = 0;
 		if (debug)
 			printf(_("Invalid values in hardware clock: "
 				 "%4d/%.2d/%.2d %.2d:%.2d:%.2d\n"),
@@ -424,7 +407,6 @@ mktime_tz(struct tm tm, const bool universal,
 			       tm.tm_hour, tm.tm_min, tm.tm_sec);
 	} else {
 		*valid_p = TRUE;
-		*systime_p = mktime_result;
 		if (debug)
 			printf(_
 			       ("Hw clock time : %4d/%.2d/%.2d %.2d:%.2d:%.2d = "
@@ -432,12 +414,6 @@ mktime_tz(struct tm tm, const bool universal,
 			       tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min,
 			       tm.tm_sec, (long)*systime_p);
 	}
-	/* now put back the original zone. */
-	if (zone)
-		setenv("TZ", zone, TRUE);
-	else
-		unsetenv("TZ");
-	tzset();
 }
 
 /*
-- 
2.9.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2016-08-01 11:26 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-07-10 20:02 [PATCH] hwclock: remove UTC-0 localization hack Sami Kerola
2016-07-11 20:23 ` J William Piggott
2016-07-12 11:56   ` Sami Kerola
2016-07-12 14:23     ` Ruediger Meier
2016-07-12 20:03       ` Sami Kerola
2016-07-12 21:38         ` Ruediger Meier
2016-07-12 21:42           ` Sami Kerola
2016-07-14 10:01             ` Karel Zak
2016-07-14 22:37               ` Sami Kerola
2016-07-15 18:46               ` J William Piggott
2016-07-27 16:07                 ` Sami Kerola
2016-07-28 19:49                   ` J William Piggott
2016-08-01 11:26                   ` Karel Zak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox