Browse Source

Ensure previous adjust has completed before clearing alarm flag; ok henning@

OPENBSD_3_8
dtucker 19 years ago
parent
commit
f5ecdec08b
2 changed files with 24 additions and 8 deletions
  1. +11
    -2
      src/usr.sbin/ntpd/ntp.c
  2. +13
    -6
      src/usr.sbin/ntpd/ntpd.c

+ 11
- 2
src/usr.sbin/ntpd/ntp.c View File

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


+ 13
- 6
src/usr.sbin/ntpd/ntpd.c View File

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


Loading…
Cancel
Save