summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_time.c
diff options
context:
space:
mode:
authornaddy <naddy@openbsd.org>2016-09-03 14:46:56 +0000
committernaddy <naddy@openbsd.org>2016-09-03 14:46:56 +0000
commit299e2953b1dda0740e3d7d5e0d558dd8197bcf8f (patch)
treecb4cb4c763f24bc0ab6d75732681ddd680a0f90a /sys/kern/kern_time.c
parentReplace [RELAY|SERVER]_MAXPROC with the new PROC_MAX_INSTANCES (diff)
downloadwireguard-openbsd-299e2953b1dda0740e3d7d5e0d558dd8197bcf8f.tar.xz
wireguard-openbsd-299e2953b1dda0740e3d7d5e0d558dd8197bcf8f.zip
Write the system time back to the RTC every 30 minutes.
This fixes the problem that long-running machines which were not shut down properly would reboot with a badly offset system time. hints and ok kettenis@
Diffstat (limited to 'sys/kern/kern_time.c')
-rw-r--r--sys/kern/kern_time.c38
1 files changed, 37 insertions, 1 deletions
diff --git a/sys/kern/kern_time.c b/sys/kern/kern_time.c
index 1477ad53d78..64083f9ccde 100644
--- a/sys/kern/kern_time.c
+++ b/sys/kern/kern_time.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_time.c,v 1.97 2016/04/28 20:11:20 tedu Exp $ */
+/* $OpenBSD: kern_time.c,v 1.98 2016/09/03 14:46:56 naddy Exp $ */
/* $NetBSD: kern_time.c,v 1.20 1996/02/18 11:57:06 fvdl Exp $ */
/*
@@ -41,6 +41,8 @@
#include <sys/vnode.h>
#include <sys/signalvar.h>
#include <sys/pledge.h>
+#include <sys/task.h>
+#include <sys/timeout.h>
#include <sys/timetc.h>
#include <sys/mount.h>
@@ -785,3 +787,37 @@ ppsratecheck(struct timeval *lasttime, int *curpps, int maxpps)
return (rv);
}
+
+#define RESETTODR_PERIOD 1800
+
+void periodic_resettodr(void *);
+void perform_resettodr(void *);
+
+struct timeout resettodr_to = TIMEOUT_INITIALIZER(periodic_resettodr, NULL);
+struct task resettodr_task = TASK_INITIALIZER(perform_resettodr, NULL);
+
+void
+periodic_resettodr(void *arg __unused)
+{
+ task_add(systq, &resettodr_task);
+}
+
+void
+perform_resettodr(void *arg __unused)
+{
+ resettodr();
+ timeout_add_sec(&resettodr_to, RESETTODR_PERIOD);
+}
+
+void
+start_periodic_resettodr(void)
+{
+ timeout_add_sec(&resettodr_to, RESETTODR_PERIOD);
+}
+
+void
+stop_periodic_resettodr(void)
+{
+ timeout_del(&resettodr_to);
+ task_del(systq, &resettodr_task);
+}