[Toybox] [PATCH] fix hwclock -w
enh
enh at google.com
Thu May 28 21:24:38 PDT 2015
ping? i still have an M-triaged bug for this, but it's not high enough
severity to stay that way for long...
On Sat, May 9, 2015 at 11:03 PM, enh <enh at google.com> wrote:
> 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.
>
> Bug: 20902704
>
> 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");
> }
>
>
> --
> Elliott Hughes - http://who/enh - http://jessies.org/~enh/
> Android native code/tools questions? Mail me/drop by/add me as a reviewer.
>
--
Elliott Hughes - http://who/enh - http://jessies.org/~enh/
Android native code/tools questions? Mail me/drop by/add me as a reviewer.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20150528/790c992e/attachment-0001.htm>
More information about the Toybox
mailing list