diff --git a/src/usr.sbin/ntpd/ntp.c b/src/usr.sbin/ntpd/ntp.c index b9dfda43..2cf725a4 100644 --- a/src/usr.sbin/ntpd/ntp.c +++ b/src/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 @@ -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/src/usr.sbin/ntpd/ntpd.c b/src/usr.sbin/ntpd/ntpd.c index f8b04c3c..6c635953 100644 --- a/src/usr.sbin/ntpd/ntpd.c +++ b/src/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 @@ -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