diff --git a/src/usr.sbin/ntpd/Makefile b/src/usr.sbin/ntpd/Makefile index 20582ce6..d9acd258 100644 --- a/src/usr.sbin/ntpd/Makefile +++ b/src/usr.sbin/ntpd/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.15 2015/10/05 17:26:22 deraadt Exp $ +# $OpenBSD: Makefile,v 1.16 2015/11/20 18:53:42 tedu Exp $ PROG= ntpd SRCS= ntpd.c log.c ntp.c ntp_msg.c parse.y config.c \ @@ -11,7 +11,7 @@ CFLAGS+= -Wmissing-declarations CFLAGS+= -Wshadow -Wpointer-arith -Wcast-qual CFLAGS+= -Wsign-compare YFLAGS= -LDADD+= -lutil -ltls -lssl -lcrypto +LDADD+= -lm -lutil -ltls -lssl -lcrypto DPADD+= ${LIBUTIL} ${LIBCRYPTO} ${LIBSSL} ${LIBTLS} LINKS= ${BINDIR}/ntpd ${BINDIR}/ntpctl MAN= ntpd.8 ntpd.conf.5 ntpctl.8 diff --git a/src/usr.sbin/ntpd/control.c b/src/usr.sbin/ntpd/control.c index 08740ba9..4f31836b 100644 --- a/src/usr.sbin/ntpd/control.c +++ b/src/usr.sbin/ntpd/control.c @@ -1,4 +1,4 @@ -/* $OpenBSD: control.c,v 1.7 2015/10/23 14:52:20 phessler Exp $ */ +/* $OpenBSD: control.c,v 1.8 2015/11/20 18:53:42 tedu Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -33,6 +34,8 @@ #define CONTROL_BACKLOG 5 +#define square(x) ((x) * (x)) + int control_init(char *path) { @@ -354,21 +357,18 @@ build_show_peer(struct ctl_show_peer *cp, struct ntp_peer *p) cp->delay /= validdelaycnt; } - /* - * use simple average for jitter calculation, as the - * RFC5905-recommended RMS average needs the math library - */ jittercnt = 0; cp->jitter = 0.0; for (shift = 0; shift < OFFSET_ARRAY_SIZE; shift++) { if (p->reply[shift].delay > 0.0 && shift != best) { - cp->jitter += p->reply[shift].delay - - p->reply[best].delay; + cp->jitter += square(p->reply[shift].delay - + p->reply[best].delay); jittercnt++; } } if (jittercnt > 1) cp->jitter /= jittercnt; + cp->jitter = sqrt(cp->jitter); if (p->shift == 0) shift = OFFSET_ARRAY_SIZE - 1;