diff --git a/compat/Makefile.am b/compat/Makefile.am index d49786c..fd7242a 100644 --- a/compat/Makefile.am +++ b/compat/Makefile.am @@ -48,6 +48,10 @@ libcompat_la_SOURCES += adjfreq_solaris.c endif endif +if HOST_OPENBSD +libcompat_la_SOURCES += adjfreq_openbsd.c +endif + if !HAVE_ASPRINTF libcompat_la_SOURCES += bsd-asprintf.c endif diff --git a/compat/adjfreq_freebsd.c b/compat/adjfreq_freebsd.c index f631b17..8011dad 100644 --- a/compat/adjfreq_freebsd.c +++ b/compat/adjfreq_freebsd.c @@ -57,3 +57,20 @@ adjfreq(const int64_t *freq, int64_t *oldfreq) return 0; } + +/* + * The RTC is only updated if the clock is not marked as unsynced. + */ + +void +update_time_sync_status(int synced) +{ + struct timex txc = { 0 }; + + txc.modes = MOD_STATUS; + if (!synced) + txc.status = STA_UNSYNC; + if (ntp_adjtime(&txc) == -1) + log_warn("ntp_adjtime (3) failed"); + return; +} diff --git a/compat/adjfreq_linux.c b/compat/adjfreq_linux.c index 5c5e6e5..217b23a 100644 --- a/compat/adjfreq_linux.c +++ b/compat/adjfreq_linux.c @@ -57,3 +57,20 @@ adjfreq(const int64_t *freq, int64_t *oldfreq) return 0; } + +/* + * The RTC is only updated if the clock is not marked as unsynced. + */ + +void +update_time_sync_status(int synced) +{ + struct timex txc = { 0 }; + + txc.modes = MOD_STATUS; + if (!synced) + txc.status = STA_UNSYNC; + if (adjtimex(&txc) == -1) + log_warn("ntp_adjtime (3) failed"); + return; +} diff --git a/compat/adjfreq_netbsd.c b/compat/adjfreq_netbsd.c index 332ff2c..f533966 100644 --- a/compat/adjfreq_netbsd.c +++ b/compat/adjfreq_netbsd.c @@ -58,3 +58,20 @@ adjfreq(const int64_t *freq, int64_t *oldfreq) return 0; } + +/* + * The RTC is only updated if the clock is not marked as unsynced. + */ + +void +update_time_sync_status(int synced) +{ + struct timex txc = { 0 }; + + txc.modes = MOD_STATUS; + if (!synced) + txc.status = STA_UNSYNC; + if (ntp_adjtime(&txc) == -1) + log_warn("ntp_adjtime (3) failed"); + return; +} diff --git a/compat/adjfreq_openbsd.c b/compat/adjfreq_openbsd.c new file mode 100644 index 0000000..4d9fa6b --- /dev/null +++ b/compat/adjfreq_openbsd.c @@ -0,0 +1,10 @@ +/* + * This file is in the public domain. + * + * adjfreq is native on OpenBSD, but we need to stub in update_time_sync_status + */ + +void +update_time_sync_status(int synced) +{ +} diff --git a/compat/adjfreq_osx.c b/compat/adjfreq_osx.c index f8f0be4..c8a875b 100644 --- a/compat/adjfreq_osx.c +++ b/compat/adjfreq_osx.c @@ -17,3 +17,8 @@ adjfreq(const int64_t *freq, int64_t *oldfreq) errno = ENOSYS; return -1; } + +void +update_time_sync_status(int synced) +{ +} diff --git a/compat/adjfreq_solaris.c b/compat/adjfreq_solaris.c index f631b17..8011dad 100644 --- a/compat/adjfreq_solaris.c +++ b/compat/adjfreq_solaris.c @@ -57,3 +57,20 @@ adjfreq(const int64_t *freq, int64_t *oldfreq) return 0; } + +/* + * The RTC is only updated if the clock is not marked as unsynced. + */ + +void +update_time_sync_status(int synced) +{ + struct timex txc = { 0 }; + + txc.modes = MOD_STATUS; + if (!synced) + txc.status = STA_UNSYNC; + if (ntp_adjtime(&txc) == -1) + log_warn("ntp_adjtime (3) failed"); + return; +} diff --git a/configure.ac b/configure.ac index 4bbccae..8c142a2 100644 --- a/configure.ac +++ b/configure.ac @@ -50,6 +50,7 @@ case $host_os in HOST_OS=netbsd ;; *openbsd*) + HOST_OS=openbsd AC_DEFINE([HAVE_ATTRIBUTE__BOUNDED__], [1], [OpenBSD has __bounded__]) AC_DEFINE([HAVE_ATTRIBUTE__DEAD], [1], [OpenBSD has __dead]) ;; @@ -65,6 +66,7 @@ AM_CONDITIONAL([HOST_DARWIN], [test x$HOST_OS = xdarwin]) AM_CONDITIONAL([HOST_FREEBSD], [test x$HOST_OS = xfreebsd]) AM_CONDITIONAL([HOST_LINUX], [test x$HOST_OS = xlinux]) AM_CONDITIONAL([HOST_NETBSD], [test x$HOST_OS = xnetbsd]) +AM_CONDITIONAL([HOST_OPENBSD], [test x$HOST_OS = xopenbsd]) AM_CONDITIONAL([HOST_SOLARIS], [test x$HOST_OS = xsolaris]) AC_CHECK_FUNC([dl_iterate_phdr],, diff --git a/ntpd.conf b/ntpd.conf index 2446fc7..d403a71 100644 --- a/ntpd.conf +++ b/ntpd.conf @@ -18,4 +18,4 @@ servers pool.ntp.org #sensor * # get the time constraint from a well-known HTTPS site -#constraints from "https://www.google.com/search?q=openntpd" +constraints from "https://www.google.com/search?q=openntpd" diff --git a/patches/0012-add-a-method-for-updating-the-realtime-clock-on-sync.patch b/patches/0012-add-a-method-for-updating-the-realtime-clock-on-sync.patch new file mode 100644 index 0000000..2b0a27b --- /dev/null +++ b/patches/0012-add-a-method-for-updating-the-realtime-clock-on-sync.patch @@ -0,0 +1,33 @@ +From 6d482d31602ce3fc0b17f155d2306a27bad09bec Mon Sep 17 00:00:00 2001 +From: Brent Cook +Date: Mon, 4 May 2015 04:27:29 -0500 +Subject: [PATCH 12/12] add a method for updating the realtime clock on sync + +from Christian Weisgerber +--- + src/usr.sbin/ntpd/ntpd.c | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/src/usr.sbin/ntpd/ntpd.c b/src/usr.sbin/ntpd/ntpd.c +index 44caa80..fb9a8df 100644 +--- a/src/usr.sbin/ntpd/ntpd.c ++++ b/src/usr.sbin/ntpd/ntpd.c +@@ -53,6 +53,7 @@ const char *ctl_lookup_option(char *, const char **); + void show_status_msg(struct imsg *); + void show_peer_msg(struct imsg *, int); + void show_sensor_msg(struct imsg *, int); ++void update_time_sync_status(int); + + volatile sig_atomic_t quit = 0; + volatile sig_atomic_t reconfig = 0; +@@ -423,6 +424,7 @@ ntpd_adjtime(double d) + else if (!firstadj && olddelta.tv_sec == 0 && olddelta.tv_usec == 0) + synced = 1; + firstadj = 0; ++ update_time_sync_status(synced); + return (synced); + } + +-- +2.2.1.209.g41e5f3a +