diff options
author | Elliott Hughes <enh@google.com> | 2015-07-10 00:57:22 -0500 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2015-07-10 00:57:22 -0500 |
commit | fd4b56a159b9080a329d4471313d636f2b292ad5 (patch) | |
tree | 26dfc07f93e06898a83960fb4049331daf346b03 | |
parent | 666b89d8c829b2f1d0301f78208b772645942e23 (diff) | |
download | toybox-fd4b56a159b9080a329d4471313d636f2b292ad5.tar.gz toybox-fd4b56a159b9080a329d4471313d636f2b292ad5.tar.bz2 toybox-fd4b56a159b9080a329d4471313d636f2b292ad5.zip |
Fix hwclock -w.
The gmtime_r/localtime_r error check was backwards, and the wrong argument
was being passed to the RTC_SET_TIME ioctl.
Also, the error reporting was misleading (showing errno for functions that
don't set errno) and too vague for the user to tell what failed.
-rw-r--r-- | toys/pending/hwclock.c | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/toys/pending/hwclock.c b/toys/pending/hwclock.c index d9ced6f..d87266a 100644 --- a/toys/pending/hwclock.c +++ b/toys/pending/hwclock.c @@ -90,7 +90,7 @@ void hwclock_main() xioctl(fd, RTC_RD_TIME, &tm); if (TT.utc) s = xtzset("UTC0"); - if ((time = mktime(&tm)) < 0) goto bad; + if ((time = mktime(&tm)) < 0) error_exit("mktime failed"); if (TT.utc) { free(xtzset(s)); free(s); @@ -98,16 +98,18 @@ void hwclock_main() } } - if (toys.optflags & (FLAG_w|FLAG_t)) - if (gettimeofday(&timeval, 0) - || (TT.utc ? gmtime_r : localtime_r)(&timeval.tv_sec, &tm)) goto bad; + if (toys.optflags & (FLAG_w|FLAG_t)) { + if (gettimeofday(&timeval, 0)) perror_exit("gettimeofday failed"); + if (!(TT.utc ? gmtime_r : localtime_r)(&timeval.tv_sec, &tm)) + error_exit(TT.utc ? "gmtime_r failed" : "localtime_r failed"); + } if (toys.optflags & FLAG_w) { /* The value of tm_isdst will positive if daylight saving time is in effect, * zero if it is not and negative if the information is not available. * todo: so why isn't this negative...? */ tm.tm_isdst = 0; - xioctl(fd, RTC_SET_TIME, &time); + xioctl(fd, RTC_SET_TIME, &tm); } else if (toys.optflags & FLAG_s) { tzone.tz_minuteswest = timezone / 60 - 60 * daylight; timeval.tv_sec = time; @@ -127,12 +129,8 @@ void hwclock_main() } if (toys.optflags & (FLAG_t|FLAG_s)) { tzone.tz_dsttime = 0; - if (settimeofday(&timeval, &tzone)) goto bad; + if (settimeofday(&timeval, &tzone)) perror_exit("settimeofday failed"); } if (fd != -1) close(fd); - - return; -bad: - perror_exit("failed"); } |