diff options
-rw-r--r-- | usr.sbin/ntpd/ntp.c | 75 | ||||
-rw-r--r-- | usr.sbin/ntpd/ntpd.8 | 10 | ||||
-rw-r--r-- | usr.sbin/ntpd/ntpd.h | 3 |
3 files changed, 83 insertions, 5 deletions
diff --git a/usr.sbin/ntpd/ntp.c b/usr.sbin/ntpd/ntp.c index 26bd5669fe3..3673bb8d0fe 100644 --- a/usr.sbin/ntpd/ntp.c +++ b/usr.sbin/ntpd/ntp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ntp.c,v 1.99 2007/08/04 02:58:02 ckuethe Exp $ */ +/* $OpenBSD: ntp.c,v 1.100 2007/10/15 06:59:31 otto Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -38,14 +38,18 @@ #define PFD_MAX 2 volatile sig_atomic_t ntp_quit = 0; +volatile sig_atomic_t ntp_report = 0; struct imsgbuf *ibuf_main; struct ntpd_conf *conf; u_int peer_cnt; +u_int sensors_cnt; +time_t lastreport; void ntp_sighdlr(int); int ntp_dispatch_imsg(void); void peer_add(struct ntp_peer *); void peer_remove(struct ntp_peer *); +void report_peers(int); void ntp_sighdlr(int sig) @@ -55,6 +59,9 @@ ntp_sighdlr(int sig) case SIGTERM: ntp_quit = 1; break; + case SIGINFO: + ntp_report = 1; + break; } } @@ -65,7 +72,6 @@ ntp_main(int pipe_prnt[2], struct ntpd_conf *nconf) int hotplugfd, nullfd; u_int pfd_elms = 0, idx2peer_elms = 0; u_int listener_cnt, new_cnt, sent_cnt, trial_cnt; - u_int sensors_cnt = 0; pid_t pid; struct pollfd *pfd = NULL; struct passwd *pw; @@ -135,6 +141,7 @@ ntp_main(int pipe_prnt[2], struct ntpd_conf *nconf) signal(SIGTERM, ntp_sighdlr); signal(SIGINT, ntp_sighdlr); + signal(SIGINFO, ntp_sighdlr); signal(SIGPIPE, SIG_IGN); signal(SIGHUP, SIG_IGN); signal(SIGCHLD, SIG_DFL); @@ -173,6 +180,9 @@ ntp_main(int pipe_prnt[2], struct ntpd_conf *nconf) TAILQ_FOREACH(p, &conf->ntp_peers, entry) peer_cnt++; + /* wait 5 min before reporting first status to let things settle down */ + lastreport = time(NULL) + (5 * 60) - REPORT_INTERVAL; + while (ntp_quit == 0) { if (peer_cnt > idx2peer_elms) { if ((newp = realloc(idx2peer, sizeof(void *) * @@ -324,6 +334,8 @@ ntp_main(int pipe_prnt[2], struct ntpd_conf *nconf) if (s->next <= getmonotime()) sensor_query(s); } + report_peers(ntp_report); + ntp_report = 0; } msgbuf_write(&ibuf_main->w); @@ -403,6 +415,9 @@ ntp_dispatch_imsg(void) h->next = NULL; npeer->addr = h; npeer->addr_head.a = h; + npeer->addr_head.name = + peer->addr_head.name; + npeer->addr_head.pool = 1; client_peer_init(npeer); npeer->state = STATE_DNS_DONE; peer_add(npeer); @@ -654,3 +669,59 @@ error_interval(void) return (interval + r); } +void +report_peers(int always) +{ + time_t now; + u_int badpeers = 0; + u_int badsensors = 0; + struct ntp_peer *p; + struct ntp_sensor *s; + + TAILQ_FOREACH(p, &conf->ntp_peers, entry) { + if (p->trustlevel < TRUSTLEVEL_BADPEER) + badpeers++; + } + TAILQ_FOREACH(s, &conf->ntp_sensors, entry) { + if (!s->update.good) + badsensors++; + } + + now = time(NULL); + if (!always) { + if ((peer_cnt == 0 || badpeers == 0 || badpeers < peer_cnt / 2) + && (sensors_cnt == 0 || badsensors == 0 || + badsensors < sensors_cnt / 2)) + return; + + if (lastreport + REPORT_INTERVAL > now) + return; + } + lastreport = now; + if (peer_cnt > 0) { + log_warnx("%u out of %u peers valid", peer_cnt - badpeers, + peer_cnt); + TAILQ_FOREACH(p, &conf->ntp_peers, entry) { + if (p->trustlevel < TRUSTLEVEL_BADPEER) { + const char *a = "not resolved"; + const char *pool = ""; + if (p->addr) + a = log_sockaddr( + (struct sockaddr *)&p->addr->ss); + if (p->addr_head.pool) + pool = "from pool "; + log_warnx("bad peer %s%s (%s)", pool, + p->addr_head.name, a); + } + } + } + if (sensors_cnt > 0) { + log_warnx("%u out of %u sensors valid", + sensors_cnt - badsensors, sensors_cnt); + TAILQ_FOREACH(s, &conf->ntp_sensors, entry) { + if (!s->update.good) + log_warnx("bad sensor %s", s->device); + } + } +} + diff --git a/usr.sbin/ntpd/ntpd.8 b/usr.sbin/ntpd/ntpd.8 index 1bcc6821ee6..8cea88f2060 100644 --- a/usr.sbin/ntpd/ntpd.8 +++ b/usr.sbin/ntpd/ntpd.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: ntpd.8,v 1.20 2007/09/13 14:34:36 pyr Exp $ +.\" $OpenBSD: ntpd.8,v 1.21 2007/10/15 06:59:32 otto Exp $ .\" .\" Copyright (c) 2003, 2004, 2006 Henning Brauer <henning@openbsd.org> .\" @@ -14,7 +14,7 @@ .\" AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT .\" OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: September 13 2007 $ +.Dd $Mdocdate: October 15 2007 $ .Dt NTPD 8 .Os .Sh NAME @@ -108,6 +108,12 @@ This option allows .Nm to send DEBUG priority messages to syslog. .El +.Pp +When +.Nm +receives a +.Dv SIGINFO +signal, it will write its peer and sensor status to syslog. .Sh FILES .Bl -tag -width "/var/db/ntpd.driftXXX" -compact .It Pa /etc/ntpd.conf diff --git a/usr.sbin/ntpd/ntpd.h b/usr.sbin/ntpd/ntpd.h index 1ab2ffa3ed1..73c017526b6 100644 --- a/usr.sbin/ntpd/ntpd.h +++ b/usr.sbin/ntpd/ntpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ntpd.h,v 1.87 2007/09/13 14:34:36 pyr Exp $ */ +/* $OpenBSD: ntpd.h,v 1.88 2007/10/15 06:59:32 otto Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -61,6 +61,7 @@ #define LOG_NEGLIGEE 32 /* negligible drift to not log (ms) */ #define FREQUENCY_SAMPLES 8 /* samples for est. of permanent drift */ #define MAX_FREQUENCY_ADJUST 128e-5 /* max correction per iteration */ +#define REPORT_INTERVAL (24*60*60) /* interval between status reports */ #define SENSOR_DATA_MAXAGE (15*60) |