summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcheloha <cheloha@openbsd.org>2020-06-22 18:25:57 +0000
committercheloha <cheloha@openbsd.org>2020-06-22 18:25:57 +0000
commitbf2d84a07eb2512358d130f21cd3f3c03b4c2d28 (patch)
tree81886a8022d8f218fffde7f683d953f584b38ff3
parentRemove unused variable (diff)
downloadwireguard-openbsd-bf2d84a07eb2512358d130f21cd3f3c03b4c2d28.tar.xz
wireguard-openbsd-bf2d84a07eb2512358d130f21cd3f3c03b4c2d28.zip
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@
-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);