summaryrefslogtreecommitdiffstats
path: root/sys/kern/subr_rtc.c
diff options
context:
space:
mode:
authorjkim <jkim@FreeBSD.org>2009-03-23 21:16:21 +0000
committerjkim <jkim@FreeBSD.org>2009-03-23 21:16:21 +0000
commiteffc07786848c7b478bb8e15b037c04f268a8e26 (patch)
tree6a8b22ada28738b54ab6222e342bdec16b8e4b4f /sys/kern/subr_rtc.c
parentffcd13a80f2cc9f565bfd652dc71d19a4c2467c6 (diff)
downloadFreeBSD-src-effc07786848c7b478bb8e15b037c04f268a8e26.zip
FreeBSD-src-effc07786848c7b478bb8e15b037c04f268a8e26.tar.gz
Clean up MI inittodr(9) and kill noop code.
It was derived from i386 version long ago but never resync'ed again. Originally, i386 version compared the current time from realtime clock with time_second (which was just `time' in the old days). When this MI version was written, it was wrongly compared against `base' AND never used because of a bug (typo?) in the code. This check was killed in i386 version when home-rolled calendaric calculation was removed. Now, we just remove the code here as well to make the code simpler.
Diffstat (limited to 'sys/kern/subr_rtc.c')
-rw-r--r--sys/kern/subr_rtc.c34
1 files changed, 13 insertions, 21 deletions
diff --git a/sys/kern/subr_rtc.c b/sys/kern/subr_rtc.c
index 0f3ec17..e919bf0 100644
--- a/sys/kern/subr_rtc.c
+++ b/sys/kern/subr_rtc.c
@@ -109,44 +109,36 @@ clock_register(device_t dev, long res) /* res has units of microseconds */
void
inittodr(time_t base)
{
- struct timespec diff, ref, ts;
+ struct timespec ref, ts;
int error;
- if (base) {
- ref.tv_sec = base;
- ref.tv_nsec = 0;
- tc_setclock(&ref);
- }
-
if (clock_dev == NULL) {
printf("warning: no time-of-day clock registered, system time "
"will not be set accurately\n");
- return;
+ goto wrong_time;
}
/* XXX: We should poll all registered RTCs in case of failure */
error = CLOCK_GETTIME(clock_dev, &ts);
if (error != 0 && error != EINVAL) {
printf("warning: clock_gettime failed (%d), the system time "
"will not be set accurately\n", error);
- return;
+ goto wrong_time;
}
if (error == EINVAL || ts.tv_sec < 0) {
- printf("Invalid time in real time clock.\n");
- printf("Check and reset the date immediately!\n");
+ printf("Invalid time in real time clock.\n"
+ "Check and reset the date immediately!\n");
+ goto wrong_time;
}
ts.tv_sec += utc_offset();
+ tc_setclock(&ts);
+ return;
- if (timespeccmp(&ref, &ts, >)) {
- diff = ref;
- timespecsub(&ref, &ts);
- } else {
- diff = ts;
- timespecsub(&diff, &ref);
- }
- if (ts.tv_sec >= 2) {
- /* badly off, adjust it */
- tc_setclock(&ts);
+wrong_time:
+ if (base > 0) {
+ ref.tv_sec = base;
+ ref.tv_nsec = 0;
+ tc_setclock(&ref);
}
}
OpenPOWER on IntegriCloud