X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fntpd.c;h=f8f4f04974bc2f241554d023e5687a8d458d0d4b;hb=290741f2e6de9e9b467463c1f0c6f031c4036428;hp=4a31e455eece36ad595f8bbc41ac7ee6985c35e7;hpb=4de248994479ec6b32a0beb39a7bf9aca1a18387;p=collectd.git diff --git a/src/ntpd.c b/src/ntpd.c index 4a31e455..f8f4f049 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", @@ -505,7 +509,7 @@ static int ntpd_receive_response (int *res_items, int *res_size, break; } - memset ((void *) &res, '\0', sizeof (res)); + memset (&res, '\0', sizeof (res)); status = recv (sd, (void *) &res, sizeof (res), 0 /* no flags */); if ((status < 0) && ((errno == EAGAIN) || (errno == EINTR))) @@ -663,7 +667,7 @@ static int ntpd_receive_response (int *res_items, int *res_size, */ DEBUG ("realloc (%p, %zu)", (void *) *res_data, (items_num + pkt_item_num) * res_item_size); - items = realloc ((void *) *res_data, + items = realloc (*res_data, (items_num + pkt_item_num) * res_item_size); if (items == NULL) { @@ -720,7 +724,7 @@ static int ntpd_send_request (int req_code, int req_items, int req_size, char *r if ((sd = ntpd_connect ()) < 0) return (-1); - memset ((void *) &req, '\0', sizeof (req)); + memset (&req, '\0', sizeof (req)); req.rm_vn_mode = RM_VN_MODE(0, 0, 0); req.auth_seq = AUTH_SEQ (0, 0); req.implementation = IMPL_XNTPD; @@ -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);