aboutsummaryrefslogtreecommitdiff
path: root/util-linux/hwclock.c
diff options
context:
space:
mode:
Diffstat (limited to 'util-linux/hwclock.c')
-rw-r--r--util-linux/hwclock.c13
1 files changed, 5 insertions, 8 deletions
diff --git a/util-linux/hwclock.c b/util-linux/hwclock.c
index 204a103c3..8b65df6a6 100644
--- a/util-linux/hwclock.c
+++ b/util-linux/hwclock.c
@@ -59,25 +59,23 @@ static time_t read_rtc(int utc)
59 int rtc = xopen_rtc(O_RDONLY); 59 int rtc = xopen_rtc(O_RDONLY);
60 60
61 memset(&tm, 0, sizeof(struct tm)); 61 memset(&tm, 0, sizeof(struct tm));
62 if (ioctl(rtc, RTC_RD_TIME, &tm) < 0) 62 xioctl(rtc, RTC_RD_TIME, &tm);
63 bb_perror_msg_and_die("cannot read time from RTC");
64 tm.tm_isdst = -1; /* not known */ 63 tm.tm_isdst = -1; /* not known */
65 64
66 close(rtc); 65 close(rtc);
67 66
68 if (utc) { 67 if (utc) {
69 oldtz = getenv("TZ"); 68 oldtz = getenv("TZ");
70 setenv("TZ", "UTC 0", 1); 69 putenv((char*)"TZ=UTC0");
71 tzset(); 70 tzset();
72 } 71 }
73 72
74 t = mktime(&tm); 73 t = mktime(&tm);
75 74
76 if (utc) { 75 if (utc) {
76 unsetenv("TZ");
77 if (oldtz) 77 if (oldtz)
78 setenv("TZ", oldtz, 1); 78 putenv(oldtz - 3);
79 else
80 unsetenv("TZ");
81 tzset(); 79 tzset();
82 } 80 }
83 return t; 81 return t;
@@ -91,8 +89,7 @@ static void write_rtc(time_t t, int utc)
91 tm = *(utc ? gmtime(&t) : localtime(&t)); 89 tm = *(utc ? gmtime(&t) : localtime(&t));
92 tm.tm_isdst = 0; 90 tm.tm_isdst = 0;
93 91
94 if (ioctl(rtc, RTC_SET_TIME, &tm) < 0) 92 xioctl(rtc, RTC_SET_TIME, &tm);
95 bb_perror_msg_and_die("cannot set the RTC time");
96 93
97 close(rtc); 94 close(rtc);
98} 95}