From: Juergen Perlinger Date: Sun, 11 Nov 2018 08:56:34 +0000 (+0100) Subject: [Bug 3541] patch to fix STA_NANO struct timex units X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=78d5bd2cb58517751dde42a699c827eb22708493;p=thirdparty%2Fntp.git [Bug 3541] patch to fix STA_NANO struct timex units bk: 5be7eec2X6cG-sMjumaa5w1nNzPakw --- diff --git a/ChangeLog b/ChangeLog index f381a093c..fc90b3a50 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +--- +* [Bug 3541] patch to fix STA_NANO struct timex units + - applied patch by Maciej Szmigiero + --- (4.2.8p12) 2018/08/14 Released by Harlan Stenn diff --git a/ntpd/ntp_control.c b/ntpd/ntp_control.c index 48cd908f9..63f9980ac 100644 --- a/ntpd/ntp_control.c +++ b/ntpd/ntp_control.c @@ -1910,11 +1910,13 @@ ctl_putsys( static struct timex ntx; static u_long ntp_adjtime_time; - static const double to_ms = + static const double to_ms_usec = + 1.0e-3; /* usec to msec */ + static const double to_ms_nusec = # ifdef STA_NANO 1.0e-6; /* nsec to msec */ # else - 1.0e-3; /* usec to msec */ + to_ms_usec; # endif /* @@ -2319,7 +2321,7 @@ ctl_putsys( case CS_K_OFFSET: CTL_IF_KERNLOOP( ctl_putdblf, - (sys_var[varid].text, 0, -1, to_ms * ntx.offset) + (sys_var[varid].text, 0, -1, to_ms_nusec * ntx.offset) ); break; @@ -2334,7 +2336,7 @@ ctl_putsys( CTL_IF_KERNLOOP( ctl_putdblf, (sys_var[varid].text, 0, 6, - to_ms * ntx.maxerror) + to_ms_usec * ntx.maxerror) ); break; @@ -2342,7 +2344,7 @@ ctl_putsys( CTL_IF_KERNLOOP( ctl_putdblf, (sys_var[varid].text, 0, 6, - to_ms * ntx.esterror) + to_ms_usec * ntx.esterror) ); break; @@ -2366,7 +2368,7 @@ ctl_putsys( CTL_IF_KERNLOOP( ctl_putdblf, (sys_var[varid].text, 0, 6, - to_ms * ntx.precision) + to_ms_usec * ntx.precision) ); break; @@ -2394,7 +2396,7 @@ ctl_putsys( case CS_K_PPS_JITTER: CTL_IF_KERNPPS( ctl_putdbl, - (sys_var[varid].text, to_ms * ntx.jitter) + (sys_var[varid].text, to_ms_nusec * ntx.jitter) ); break; diff --git a/ntpdc/ntpdc_ops.c b/ntpdc/ntpdc_ops.c index 586ed7f05..1f2396d31 100644 --- a/ntpdc/ntpdc_ops.c +++ b/ntpdc/ntpdc_ops.c @@ -2920,7 +2920,7 @@ kerninfo( size_t itemsize; int res; unsigned status; - double tscale = 1e-6; + double tscale_usec = 1e-6, tscale_unano = 1e-6; again: res = doquery(impl_ver, REQ_GET_KERNEL, 0, 0, 0, (char *)NULL, @@ -2945,16 +2945,16 @@ again: */ #ifdef STA_NANO if (status & STA_NANO) - tscale = 1e-9; + tscale_unano = 1e-9; #endif (void)fprintf(fp, "pll offset: %g s\n", - (int32)ntohl(ik->offset) * tscale); + (int32)ntohl(ik->offset) * tscale_unano); (void)fprintf(fp, "pll frequency: %s ppm\n", fptoa((s_fp)ntohl(ik->freq), 3)); (void)fprintf(fp, "maximum error: %g s\n", - (u_long)ntohl(ik->maxerror) * tscale); + (u_long)ntohl(ik->maxerror) * tscale_usec); (void)fprintf(fp, "estimated error: %g s\n", - (u_long)ntohl(ik->esterror) * tscale); + (u_long)ntohl(ik->esterror) * tscale_usec); (void)fprintf(fp, "status: %04x ", status); #ifdef STA_PLL if (status & STA_PLL) (void)fprintf(fp, " pll"); @@ -3008,7 +3008,7 @@ again: (void)fprintf(fp, "pll time constant: %ld\n", (u_long)ntohl(ik->constant)); (void)fprintf(fp, "precision: %g s\n", - (u_long)ntohl(ik->precision) * tscale); + (u_long)ntohl(ik->precision) * tscale_usec); (void)fprintf(fp, "frequency tolerance: %s ppm\n", fptoa((s_fp)ntohl(ik->tolerance), 0)); @@ -3027,7 +3027,7 @@ again: (void)fprintf(fp, "pps stability: %s ppm\n", fptoa((s_fp)ntohl(ik->stabil), 3)); (void)fprintf(fp, "pps jitter: %g s\n", - (u_long)ntohl(ik->jitter) * tscale); + (u_long)ntohl(ik->jitter) * tscale_unano); (void)fprintf(fp, "calibration interval: %d s\n", 1 << ntohs(ik->shift)); (void)fprintf(fp, "calibration cycles: %ld\n", diff --git a/util/ntptime.c b/util/ntptime.c index c47e356dd..35896e909 100644 --- a/util/ntptime.c +++ b/util/ntptime.c @@ -349,10 +349,6 @@ main( printf(" status %s,\n", sprintb((u_int)ntx.status, TIMEX_STA_BITS)); ftemp = (double)ntx.tolerance / SCALE_FREQ; gtemp = (double)ntx.precision; -#ifdef STA_NANO - if (flash & STA_NANO) - gtemp /= 1000.0; -#endif printf( " time constant %lu, precision %.3f us, tolerance %.0f ppm,\n", (u_long)ntx.constant, gtemp, ftemp);