<div dir="ltr">Fix hwclock -w.<div><br></div><div>The gmtime_r/localtime_r error check was backwards, and the wrong argument was being passed to the RTC_SET_TIME ioctl.</div><div><br></div><div>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.</div><div><br></div><div>Bug: 20902704</div><div><br></div><div><div>diff --git a/toys/pending/hwclock.c b/toys/pending/hwclock.c</div><div>index d9ced6f..d87266a 100644</div><div>--- a/toys/pending/hwclock.c</div><div>+++ b/toys/pending/hwclock.c</div><div>@@ -90,7 +90,7 @@ void hwclock_main()</div><div> </div><div> xioctl(fd, RTC_RD_TIME, &tm);</div><div> if (TT.utc) s = xtzset("UTC0");</div><div>- if ((time = mktime(&tm)) < 0) goto bad;</div><div>+ if ((time = mktime(&tm)) < 0) error_exit("mktime failed");</div><div> if (TT.utc) {</div><div> free(xtzset(s));</div><div> free(s);</div><div>@@ -98,16 +98,18 @@ void hwclock_main()</div><div> }</div><div> }</div><div> </div><div>- if (toys.optflags & (FLAG_w|FLAG_t))</div><div>- if (gettimeofday(&timeval, 0)</div><div>- || (TT.utc ? gmtime_r : localtime_r)(&timeval.tv_sec, &tm)) goto bad;</div><div>+ if (toys.optflags & (FLAG_w|FLAG_t)) {</div><div>+ if (gettimeofday(&timeval, 0)) perror_exit("gettimeofday failed");</div><div>+ if (!(TT.utc ? gmtime_r : localtime_r)(&timeval.tv_sec, &tm))</div><div>+ error_exit(TT.utc ? "gmtime_r failed" : "localtime_r failed");</div><div>+ }</div><div> </div><div> if (toys.optflags & FLAG_w) {</div><div> /* The value of tm_isdst will positive if daylight saving time is in effect,</div><div> * zero if it is not and negative if the information is not available. </div><div> * todo: so why isn't this negative...? */</div><div> tm.tm_isdst = 0;</div><div>- xioctl(fd, RTC_SET_TIME, &time);</div><div>+ xioctl(fd, RTC_SET_TIME, &tm);</div><div> } else if (toys.optflags & FLAG_s) {</div><div> tzone.tz_minuteswest = timezone / 60 - 60 * daylight;</div><div> timeval.tv_sec = time;</div><div>@@ -127,12 +129,8 @@ void hwclock_main()</div><div> }</div><div> if (toys.optflags & (FLAG_t|FLAG_s)) {</div><div> tzone.tz_dsttime = 0;</div><div>- if (settimeofday(&timeval, &tzone)) goto bad;</div><div>+ if (settimeofday(&timeval, &tzone)) perror_exit("settimeofday failed");</div><div> }</div><div> </div><div> if (fd != -1) close(fd);</div><div>-</div><div>- return;</div><div>-bad:</div><div>- perror_exit("failed");</div><div> }</div><div><br></div><div><br></div>-- <br><div class="gmail_signature">Elliott Hughes - <a href="http://who/enh" target="_blank">http://who/enh</a> - <a href="http://jessies.org/~enh/" target="_blank">http://jessies.org/~enh/</a><br>Android native code/tools questions? Mail me/drop by/add me as a reviewer.</div>
</div></div>