Hello,

After running ntpd for the first time on a machine with a bad clock, I
got the following in syslog:

    ntpd[24277]: adjusting local clock by 369307689.625505s
    ntpd[24277]: adjtime failed: Invalid argument

I think adjtime limits its argument to a maximum value. Apparently on
Unix this is 2 hours, and on Linux: (INT_MAX / 1000000 - 2).

If you're interested, below is a patch for 3.9p1 to limit the argument
to adjtime to 2000 seconds, so that it works bit by bit instead of
failing over and over again.

Mansour


diff -uprN openntpd-3.9p1.orig/ntpd.c openntpd-3.9p1/ntpd.c
--- openntpd-3.9p1.orig/ntpd.c  2012-09-17 02:41:45.615802521 -0400
+++ openntpd-3.9p1/ntpd.c       2001-01-03 15:04:58.250151486 -0500
@@ -35,6 +35,7 @@ RCSID("$Release: OpenNTPD "OPENNTPD_VERS
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <math.h>
 
 #include "ntpd.h"
 
@@ -332,6 +333,11 @@ ntpd_adjtime(double d)
        int             synced = 0;
        static int      firstadj = 1;
 
+       if (fabs(d) > (double)ADJTIME_MAX) {
+               log_debug("adjusting local clock by %fs (of %fs)",
+                   (double)ADJTIME_MAX, d);
+               d = copysign((double)ADJTIME_MAX, d);
+       }
        if (d >= (double)LOG_NEGLIGEE / 1000 ||
            d <= -1 * (double)LOG_NEGLIGEE / 1000)
                log_info("adjusting local clock by %fs", d);
diff -uprN openntpd-3.9p1.orig/ntpd.h openntpd-3.9p1/ntpd.h
--- openntpd-3.9p1.orig/ntpd.h  2012-09-17 02:41:45.575800776 -0400
+++ openntpd-3.9p1/ntpd.h       2012-09-17 02:41:29.084800742 -0400
@@ -59,6 +59,7 @@
 #define        SETTIME_MIN_OFFSET      180     /* min offset for settime at 
start */
 #define        SETTIME_TIMEOUT         15      /* max seconds to wait with -s 
*/
 #define        LOG_NEGLIGEE            128     /* negligible drift to not log 
(ms) */
+#define        ADJTIME_MAX             2000
 
 enum client_state {
        STATE_NONE,

Reply via email to