On Wed, Sep 25, 2019 at 02:33:36PM -0500, Scott Cheloha wrote:
> 
> [...]

Whoops, forgot about this.

To recap, I'm fixing timeval negation so that the input is normalized
when calling adjtime(2).  I made OpenBSD's adjtime(2) more strict and
this broke backwards clock slewing in upstream ntpd because they don't
keep the timeval normalized.

Here's a better patch.  It compiles.  I can't test it because ntpd
segfaults before I can get it up and running.  But if there are people
out there who can get upstream ntpd up and running on OpenBSD this
patch will fix the adjtime(2) EINVAL issue.

I don't do much porting.  Apologies if this is wrong.

-Scott

Index: net/ntp/patches/patch-libntp_systime_c
===================================================================
RCS file: net/ntp/patches/patch-libntp_systime_c
diff -N net/ntp/patches/patch-libntp_systime_c
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ net/ntp/patches/patch-libntp_systime_c      24 Nov 2019 19:58:56 -0000
@@ -0,0 +1,20 @@
+$OpenBSD$
+
+Correctly negate adjtv.  OpenBSD's adjtime(2) rejects the input with
+EINVAL if it isn't normalized, i.e. 0 <= .tv_usec < 1000000.
+
+Index: libntp/systime.c
+--- libntp/systime.c.orig
++++ libntp/systime.c
+@@ -343,7 +343,10 @@ adj_systime(
+        */
+       if (isneg) {
+               adjtv.tv_sec = -adjtv.tv_sec;
+-              adjtv.tv_usec = -adjtv.tv_usec;
++              if (adjtv.tv_usec > 0) {
++                      adjtv.tv_sec--;
++                      adjtv.tv_usec = 1000000 - adjtv.tv_usec;
++              }
+               sys_residual = -sys_residual;
+       }
+       if (adjtv.tv_sec != 0 || adjtv.tv_usec != 0) {

Reply via email to