diff options
author | Henning Brauer <henning@cvs.openbsd.org> | 2006-10-27 12:22:42 +0000 |
---|---|---|
committer | Henning Brauer <henning@cvs.openbsd.org> | 2006-10-27 12:22:42 +0000 |
commit | 8e5eefbcf96d76671659d38bf825aa70ba2c0533 (patch) | |
tree | 01c6b88c7c904fc0034beda0f7b1d9d2a1e84b09 /usr.sbin/ntpd/ntp.c | |
parent | 48c2cd8e159c1ac5fe694663c6cda325b4537771 (diff) |
use clock_gettime(CLOCK_MONOTONIC, ..) to get a monotonically increasing
time, and make ntpd use that to send the next uery to an ntp peer and the
like. this has the advantage that changes to the clock do not interfere
with the intervals. for example, when we start on machines without an
RTC and the initial settime (-s) kicks in, intervals were strange.
idea from amandal@entrisphere.com, this implementation by me
tested ckuethe, phessler, mbalmer, ok mbalmer
Diffstat (limited to 'usr.sbin/ntpd/ntp.c')
-rw-r--r-- | usr.sbin/ntpd/ntp.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/usr.sbin/ntpd/ntp.c b/usr.sbin/ntpd/ntp.c index 0c3f8d011e0..6b81c08805e 100644 --- a/usr.sbin/ntpd/ntp.c +++ b/usr.sbin/ntpd/ntp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ntp.c,v 1.93 2006/10/24 12:23:39 henning Exp $ */ +/* $OpenBSD: ntp.c,v 1.94 2006/10/27 12:22:41 henning Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -201,7 +201,7 @@ ntp_main(int pipe_prnt[2], struct ntpd_conf *nconf) bzero(pfd, sizeof(struct pollfd) * pfd_elms); bzero(idx2peer, sizeof(void *) * idx2peer_elms); - nextaction = time(NULL) + 3600; + nextaction = getmonotime() + 3600; pfd[PFD_PIPE_MAIN].fd = ibuf_main->fd; pfd[PFD_PIPE_MAIN].events = POLLIN; pfd[PFD_HOTPLUG].fd = hotplugfd; @@ -217,7 +217,7 @@ ntp_main(int pipe_prnt[2], struct ntpd_conf *nconf) idx_peers = i; sent_cnt = trial_cnt = 0; TAILQ_FOREACH(p, &conf->ntp_peers, entry) { - if (p->next > 0 && p->next <= time(NULL)) { + if (p->next > 0 && p->next <= getmonotime()) { if (p->state > STATE_DNS_INPROGRESS) trial_cnt++; if (client_query(p) == 0) @@ -228,7 +228,7 @@ ntp_main(int pipe_prnt[2], struct ntpd_conf *nconf) if (p->deadline > 0 && p->deadline < nextaction) nextaction = p->deadline; - if (p->deadline > 0 && p->deadline <= time(NULL)) { + if (p->deadline > 0 && p->deadline <= getmonotime()) { timeout = error_interval(); log_debug("no reply from %s received in time, " "next query %ds", log_sockaddr( @@ -251,9 +251,9 @@ ntp_main(int pipe_prnt[2], struct ntpd_conf *nconf) } } - if (last_sensor_scan + SENSOR_SCAN_INTERVAL < time(NULL)) { + if (last_sensor_scan + SENSOR_SCAN_INTERVAL < getmonotime()) { sensor_scan(); - last_sensor_scan = time(NULL); + last_sensor_scan = getmonotime(); } sensors_cnt = 0; TAILQ_FOREACH(s, &conf->ntp_sensors, entry) { @@ -270,7 +270,7 @@ ntp_main(int pipe_prnt[2], struct ntpd_conf *nconf) if (ibuf_main->w.queued > 0) pfd[PFD_PIPE_MAIN].events |= POLLOUT; - timeout = nextaction - time(NULL); + timeout = nextaction - getmonotime(); if (timeout < 0) timeout = 0; @@ -315,7 +315,7 @@ ntp_main(int pipe_prnt[2], struct ntpd_conf *nconf) for (s = TAILQ_FIRST(&conf->ntp_sensors); s != NULL; s = next_s) { next_s = TAILQ_NEXT(s, entry); - if (s->next <= time(NULL)) + if (s->next <= getmonotime()) sensor_query(s); } } |