Saturday, September 26, 2020

net/ntp: fix for negative adjtv.tv_usec

Hi,

I've tried to use net/ntp on a machine (for reasons...) syslog fills
up with messages like:

ntpd[27058]: adj_systime: Invalid argument

a bit of debugging shows that xntpd calls adjtime(2) with negative
tv_usec values when it wants to slow down the clock.

The patch below is taken for ntpd(8) to adjust the adjtv value so that
tv_used is not negative.

Does it look ok ?

Index: Makefile
===================================================================
RCS file: /cvs/OpenBSD/ports/net/ntp/Makefile,v
retrieving revision 1.80
diff -u -p -u -r1.80 Makefile
--- Makefile 20 Mar 2020 16:44:26 -0000 1.80
+++ Makefile 26 Sep 2020 17:27:46 -0000
@@ -7,7 +7,7 @@ COMMENT= Network Time Protocol reference
# 'pl' for local use.

VERSION= 4.2.8p10
-REVISION= 5
+REVISION= 6
DISTNAME= ntp-${VERSION}
PKGNAME= ntp-${VERSION:S/p/pl/}
CATEGORIES= net
Index: patches/patch-libntp_systime_c
===================================================================
RCS file: patches/patch-libntp_systime_c
diff -N patches/patch-libntp_systime_c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ patches/patch-libntp_systime_c 26 Sep 2020 17:21:15 -0000
@@ -0,0 +1,18 @@
+$OpenBSD$
+
+fix negative adjtv.tv_usec
+
+Index: libntp/systime.c
+--- libntp/systime.c.orig
++++ libntp/systime.c
+@@ -346,6 +346,10 @@ adj_systime(
+ adjtv.tv_usec = -adjtv.tv_usec;
+ sys_residual = -sys_residual;
+ }
++ while (adjtv.tv_usec < 0) {
++ adjtv.tv_usec += 1000000;
++ adjtv.tv_sec -= 1;
++ }
+ if (adjtv.tv_sec != 0 || adjtv.tv_usec != 0) {
+ if (adjtime(&adjtv, &oadjtv) < 0) {
+ msyslog(LOG_ERR, "adj_systime: %m");

--
Matthieu Herrb

No comments:

Post a Comment