Here's a patch to switch the drift file from an unscaled frequency offset to ppm. The latter format is compatible with that of ntp.org. This allows easy switching between ntpd daemons. (I asked PHK and ntimed will probably not have a drift file at all.)
Old drift files are handled automagically. All values greater than a threshold will be interpreted as ppm. I picked 5e-3 (== 5000 ppm) as the cut-off value, because that's the maximum adjtime() can handle and you are unlikely to find a higher frequency offset. In fact, the combination of ntp.org and ntp_adjtime() cannot correct offsets higher then 500 ppm. Conversely, offsets smaller than 0.005 ppm (== 5e-9) are improbable. This compatibility handling will be removed in a year. Index: ntpd.c =================================================================== RCS file: /cvs/src/usr.sbin/ntpd/ntpd.c,v retrieving revision 1.84 diff -u -p -r1.84 ntpd.c --- ntpd.c 13 Jan 2015 02:28:56 -0000 1.84 +++ ntpd.c 13 Jan 2015 18:21:49 -0000 @@ -474,6 +474,8 @@ ntpd_settime(double d) log_info("set local clock to %s (offset %fs)", buf, d); } +#define PPM_THRESHOLD 5e-3 + void readfreq(void) { @@ -494,9 +496,15 @@ readfreq(void) if (adjfreq(NULL, ¤t) == -1) log_warn("adjfreq failed"); else if (current == 0) { - if (fscanf(fp, "%le", &d) == 1) + if (fscanf(fp, "%lf", &d) == 1) { + if (d > PPM_THRESHOLD || d < -PPM_THRESHOLD) + /* drift file in ppm */ + d /= 1e6; + else + log_debug("assuming unscaled frequency " + "offset in drift file"); ntpd_adjfreq(d, 0); - else + } else log_warnx("can't read %s", DRIFTFILE); } fclose(fp); @@ -505,8 +513,9 @@ readfreq(void) int writefreq(double d) { - int r; FILE *fp; + double ppm; + int r; static int warnonce = 1; fp = fopen(DRIFTFILE, "w"); @@ -518,7 +527,8 @@ writefreq(double d) return 0; } - fprintf(fp, "%e\n", d); + ppm = d * 1e6; + fprintf(fp, "%.3f\n", ppm); r = ferror(fp); if (fclose(fp) != 0 || r != 0) { if (warnonce) { -- Christian "naddy" Weisgerber na...@mips.inka.de