adjtime and negative delta

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

adjtime and negative delta

detha-2
In trying to figure out why since upgrading to 6.5 ports/ntp was
spamming the logs with "adj_systime: Invalid argument" every 20 seconds
on some machines, I found this happened when it was calling adjtime(2)
with a small negative value in tv_usec.

The man page talks about negative deltas, but then goes on to say in the
errors section that the microsecond value must not be less than zero.

It looks like this behaviour was introduced in -r1.112, as part of a
patch to add locking around timers.

One can probably work around it by patching xntpd to use 'one second
back, 999950 microseconds forward' instead of 50 microseconds back, but
that sounds rather hacky.

Can I propose the following patch to allow negative deltas again?

-d


Index: kern_time.c
===================================================================
RCS file: /cvs/src/sys/kern/kern_time.c,v
retrieving revision 1.124
diff -u -p -u -r1.124 kern_time.c
--- kern_time.c 4 Sep 2019 14:27:55 -0000 1.124
+++ kern_time.c 9 Sep 2019 08:33:09 -0000
@@ -436,7 +436,7 @@ sys_adjtime(struct proc *p, void *v, reg
  return (error);
  if ((error = copyin(delta, &atv, sizeof(struct timeval))))
  return (error);
- if (!timerisvalid(&atv))
+ if (atv.tv_usec <= -1000000 || atv.tv_usec >= 1000000)
  return (EINVAL);

  if (atv.tv_sec >= 0) {