From: Matwey V. Kornilov Date: Wed, 6 Jul 2016 13:00:55 +0000 (+0300) Subject: ntpd: Check STA_NANO in the server status X-Git-Tag: collectd-5.6.0~206^2 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=4aa1288e727433e92b00a595fd2a8e11e734d82e;p=collectd.git ntpd: Check STA_NANO in the server status When STA_NANO is set in ik->status, then results are expressed in nanoseconds (instead of microseconds by default). Signed-off-by: Matwey V. Kornilov --- diff --git a/src/ntpd.c b/src/ntpd.c index 1071d0b3..34a084b2 100644 --- a/src/ntpd.c +++ b/src/ntpd.c @@ -51,6 +51,10 @@ # include #endif +#ifndef STA_NANO +# define STA_NANO 0x2000 +#endif + static const char *config_keys[] = { "Host", @@ -910,8 +914,7 @@ static int ntpd_read (void) int i; /* On Linux, if the STA_NANO bit is set in ik->status, then ik->offset - * is is nanoseconds, otherwise it's microseconds. - * TODO(octo): STA_NANO is defined in the Linux specific header. */ + * is is nanoseconds, otherwise it's microseconds. */ double scale_loop = 1e-6; double scale_error = 1e-6; @@ -936,6 +939,11 @@ static int ntpd_read (void) return (-1); } + if (ntohs(ik->status) & STA_NANO) { + scale_loop = 1e-9; + scale_error = 1e-9; + } + /* kerninfo -> estimated error */ offset_loop = scale_loop * ((gauge_t) ntohl (ik->offset)); freq_loop = ntpd_read_fp (ik->freq);