diff options
author | Darren Tucker <dtucker@cvs.openbsd.org> | 2005-05-26 09:13:07 +0000 |
---|---|---|
committer | Darren Tucker <dtucker@cvs.openbsd.org> | 2005-05-26 09:13:07 +0000 |
commit | 22dc035d284e63e4170091dbb6fb8fd7cf5fe785 (patch) | |
tree | ec3804588c1c0073514b35e12f867488ffe483f9 | |
parent | ef4e471fad85afea64d1d307355079f9d3b64d2a (diff) |
Ensure previous adjust has completed before clearing alarm flag; ok henning@
-rw-r--r-- | usr.sbin/ntpd/ntp.c | 13 | ||||
-rw-r--r-- | usr.sbin/ntpd/ntpd.c | 19 |
2 files changed, 24 insertions, 8 deletions
diff --git a/usr.sbin/ntpd/ntp.c b/usr.sbin/ntpd/ntp.c index b9dfda43237..2cf725a4b76 100644 --- a/usr.sbin/ntpd/ntp.c +++ b/usr.sbin/ntpd/ntp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ntp.c,v 1.59 2005/05/23 22:46:43 henning Exp $ */ +/* $OpenBSD: ntp.c,v 1.60 2005/05/26 09:13:06 dtucker Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -304,6 +304,16 @@ ntp_dispatch_imsg(void) break; switch (imsg.hdr.type) { + case IMSG_ADJTIME: + memcpy(&n, imsg.data, sizeof(n)); + if (n == 1 && conf->status.leap == LI_ALARM) { + log_info("clock is now synced"); + conf->status.leap = LI_NOWARNING; + } else if (n == 0 && conf->status.leap != LI_ALARM) { + log_info("clock is now unsynced"); + conf->status.leap = LI_ALARM; + } + break; case IMSG_HOST_DNS: TAILQ_FOREACH(peer, &conf->ntp_peers, entry) if (peer->id == imsg.hdr.peerid) @@ -418,7 +428,6 @@ priv_adjtime(void) &offset_median, sizeof(offset_median)); conf->status.reftime = gettime(); - conf->status.leap = LI_NOWARNING; conf->status.stratum++; /* one more than selected peer */ update_scale(offset_median); diff --git a/usr.sbin/ntpd/ntpd.c b/usr.sbin/ntpd/ntpd.c index f8b04c3c17e..6c635953bec 100644 --- a/usr.sbin/ntpd/ntpd.c +++ b/usr.sbin/ntpd/ntpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ntpd.c,v 1.35 2005/04/18 20:46:02 henning Exp $ */ +/* $OpenBSD: ntpd.c,v 1.36 2005/05/26 09:13:06 dtucker Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -37,7 +37,7 @@ __dead void usage(void); int main(int, char *[]); int check_child(pid_t, const char *); int dispatch_imsg(struct ntpd_conf *); -void ntpd_adjtime(double); +int ntpd_adjtime(double); void ntpd_settime(double); volatile sig_atomic_t quit = 0; @@ -264,7 +264,8 @@ dispatch_imsg(struct ntpd_conf *conf) if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(d)) fatalx("invalid IMSG_ADJTIME received"); memcpy(&d, imsg.data, sizeof(d)); - ntpd_adjtime(d); + n = ntpd_adjtime(d); + imsg_compose(ibuf, IMSG_ADJTIME, 0, 0, &n, sizeof(n)); break; case IMSG_SETTIME: if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(d)) @@ -308,10 +309,12 @@ dispatch_imsg(struct ntpd_conf *conf) return (0); } -void +int ntpd_adjtime(double d) { - struct timeval tv; + struct timeval tv, olddelta; + int synced = 0; + static int firstadj = 1; if (d >= (double)LOG_NEGLIGEE / 1000 || d <= -1 * (double)LOG_NEGLIGEE / 1000) @@ -319,8 +322,12 @@ ntpd_adjtime(double d) else log_debug("adjusting local clock by %fs", d); d_to_tv(d, &tv); - if (adjtime(&tv, NULL) == -1) + if (adjtime(&tv, &olddelta) == -1) log_warn("adjtime failed"); + else if (!firstadj && olddelta.tv_sec == 0 && olddelta.tv_usec == 0) + synced = 1; + firstadj = 0; + return (synced); } void |