Browse Source

signal time sync to the OS

This is used to ensure that the time is written to the RTC when it is
synced. Problem noticed and patched by Christian Weisgerber.
OPENBSD_5_8
Brent Cook 9 years ago
committed by Brent Cook
parent
commit
70b6d21af6
10 changed files with 123 additions and 1 deletions
  1. +4
    -0
      compat/Makefile.am
  2. +17
    -0
      compat/adjfreq_freebsd.c
  3. +17
    -0
      compat/adjfreq_linux.c
  4. +17
    -0
      compat/adjfreq_netbsd.c
  5. +10
    -0
      compat/adjfreq_openbsd.c
  6. +5
    -0
      compat/adjfreq_osx.c
  7. +17
    -0
      compat/adjfreq_solaris.c
  8. +2
    -0
      configure.ac
  9. +1
    -1
      ntpd.conf
  10. +33
    -0
      patches/0012-add-a-method-for-updating-the-realtime-clock-on-sync.patch

+ 4
- 0
compat/Makefile.am View File

@ -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


+ 17
- 0
compat/adjfreq_freebsd.c View File

@ -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;
}

+ 17
- 0
compat/adjfreq_linux.c View File

@ -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;
}

+ 17
- 0
compat/adjfreq_netbsd.c View File

@ -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;
}

+ 10
- 0
compat/adjfreq_openbsd.c View File

@ -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)
{
}

+ 5
- 0
compat/adjfreq_osx.c View File

@ -17,3 +17,8 @@ adjfreq(const int64_t *freq, int64_t *oldfreq)
errno = ENOSYS;
return -1;
}
void
update_time_sync_status(int synced)
{
}

+ 17
- 0
compat/adjfreq_solaris.c View File

@ -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;
}

+ 2
- 0
configure.ac View File

@ -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],,


+ 1
- 1
ntpd.conf View File

@ -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"

+ 33
- 0
patches/0012-add-a-method-for-updating-the-realtime-clock-on-sync.patch View File

@ -0,0 +1,33 @@
From 6d482d31602ce3fc0b17f155d2306a27bad09bec Mon Sep 17 00:00:00 2001
From: Brent Cook <busterb@gmail.com>
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

Loading…
Cancel
Save