summaryrefslogtreecommitdiff
path: root/sys/kern/kern_time.c
diff options
context:
space:
mode:
authorcheloha <cheloha@cvs.openbsd.org>2020-06-22 18:25:58 +0000
committercheloha <cheloha@cvs.openbsd.org>2020-06-22 18:25:58 +0000
commit735e7778ea8c9feb4e8e91cc0af877a06e188340 (patch)
tree9f4f89e92c9fdaa01f063f01f5b599ebbbaa938e /sys/kern/kern_time.c
parent968ef9b13a5a1bd03cd9bfe3bcd6181fe56b9720 (diff)
inittodr(9): introduce dedicated flag to enable writes from resettodr(9)
We don't want resettodr(9) to write the RTC until inittodr(9) has actually run. Until inittodr(9) calls tc_setclock() the system UTC clock will contain a meaningless value and there's no sense in overwriting a good value with a value we know is nonsense. This is not an uncommon problem if you're debugging a problem in early boot, e.g. a panic that occurs prior to inittodr(9). Currently we use the following logic in resettodr(9) to inhibit writes: if (time_second == 1) return; ... this is too magical. A better way to accomplish the same thing is to introduce a dedicated flag set from inittodr(9). Hence, "inittodr_done". Suggested by visa@. ok kettenis@
Diffstat (limited to 'sys/kern/kern_time.c')
-rw-r--r--sys/kern/kern_time.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/sys/kern/kern_time.c b/sys/kern/kern_time.c
index 6be556ecf2a..741bc2b9650 100644
--- a/sys/kern/kern_time.c
+++ b/sys/kern/kern_time.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_time.c,v 1.130 2020/05/20 17:23:01 cheloha Exp $ */
+/* $OpenBSD: kern_time.c,v 1.131 2020/06/22 18:25:57 cheloha Exp $ */
/* $NetBSD: kern_time.c,v 1.20 1996/02/18 11:57:06 fvdl Exp $ */
/*
@@ -778,6 +778,7 @@ ppsratecheck(struct timeval *lasttime, int *curpps, int maxpps)
}
todr_chip_handle_t todr_handle;
+int inittodr_done;
#define MINYEAR ((OpenBSD / 100) - 1) /* minimum plausible year */
@@ -794,6 +795,8 @@ inittodr(time_t base)
struct timespec ts;
int badbase;
+ inittodr_done = 1;
+
if (base < (MINYEAR - 1970) * SECYR) {
printf("WARNING: preposterous time in file system\n");
/* read the system clock anyway */
@@ -856,7 +859,11 @@ resettodr(void)
{
struct timeval rtctime;
- if (time_second == 1)
+ /*
+ * Skip writing the RTC if inittodr(9) never ran. We don't
+ * want to overwrite a reasonable value with a nonsense value.
+ */
+ if (!inittodr_done)
return;
microtime(&rtctime);