X-Git-Url: https://git.octo.it/?p=collectd.git;a=blobdiff_plain;f=src%2Fntpd.c;h=33acc69fe1b0631d28f65e49a4144d111d77be7d;hp=baa1988b26596665b0a5936042de5ecd9a113f80;hb=48efd3deb4c9139fd060ff3d289896e9031bcc7c;hpb=614660f40c32b5af9b6c4852e4e370fc3953a5c8 diff --git a/src/ntpd.c b/src/ntpd.c index baa1988b..33acc69f 100644 --- a/src/ntpd.c +++ b/src/ntpd.c @@ -29,8 +29,8 @@ #include "collectd.h" -#include "common.h" #include "plugin.h" +#include "utils/common/common.h" #if HAVE_NETDB_H #include @@ -251,7 +251,7 @@ static const char *refclock_names[] = { "CHRONOLOG", "DUMBCLOCK", "ULINK_M320", "PCF", /* 32-35 */ "WWV_AUDIO", "GPS_FG", "HOPF_S", "HOPF_P", /* 36-39 */ "JJY", "TT_IRIG", "GPS_ZYFER", "GPS_RIPENCC", /* 40-43 */ - "NEOCLK4X" /* 44 */ + "NEOCLK4X", "PCI_TSYNC", "GPSD_JSON" /* 44-46 */ }; static size_t refclock_names_num = STATIC_ARRAY_SIZE(refclock_names); /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * @@ -779,17 +779,6 @@ static int ntpd_get_name_refclock(char *buffer, size_t buffer_size, return 0; } /* int ntpd_get_name_refclock */ -static int ntpd_get_name(char *buffer, size_t buffer_size, - struct info_peer_summary const *peer_info) { - uint32_t addr = ntohl(peer_info->srcadr); - - if (!peer_info->v6_flag && ((addr & REFCLOCK_MASK) == REFCLOCK_ADDR)) - return ntpd_get_name_refclock(buffer, buffer_size, peer_info); - else - return ntpd_get_name_from_address(buffer, buffer_size, peer_info, - do_reverse_lookups); -} /* int ntpd_addr_to_name */ - static int ntpd_read(void) { struct info_kernel *ik; int ik_num; @@ -821,11 +810,13 @@ static int ntpd_read(void) { if (status != 0) { ERROR("ntpd plugin: ntpd_do_query (REQ_GET_KERNEL) failed with status %i", status); + free(ik); return status; } else if ((ik == NULL) || (ik_num == 0) || (ik_size == 0)) { ERROR("ntpd plugin: ntpd_do_query returned unexpected data. " "(ik = %p; ik_num = %i; ik_size = %i)", (void *)ik, ik_num, ik_size); + free(ik); return -1; } @@ -860,11 +851,13 @@ static int ntpd_read(void) { ERROR( "ntpd plugin: ntpd_do_query (REQ_PEER_LIST_SUM) failed with status %i", status); + free(ps); return status; } else if ((ps == NULL) || (ps_num == 0) || (ps_size == 0)) { ERROR("ntpd plugin: ntpd_do_query returned unexpected data. " "(ps = %p; ps_num = %i; ps_size = %i)", (void *)ps, ps_num, ps_size); + free(ps); return -1; } @@ -877,7 +870,15 @@ static int ntpd_read(void) { ptr = ps + i; - status = ntpd_get_name(peername, sizeof(peername), ptr); + int is_refclock = !ptr->v6_flag && + ((ntohl(ptr->srcadr) & REFCLOCK_MASK) == REFCLOCK_ADDR); + + if (is_refclock) + status = ntpd_get_name_refclock(peername, sizeof(peername), ptr); + else + status = ntpd_get_name_from_address(peername, sizeof(peername), ptr, + do_reverse_lookups); + if (status != 0) { ERROR("ntpd plugin: Determining name of peer failed."); continue; @@ -895,6 +896,8 @@ static int ntpd_read(void) { M_LFPTOD(ntohl(ptr->offset_int), ntohl(ptr->offset_frc), offset); DEBUG("peer %i:\n" + " is_refclock= %d\n" + " refclock_id= %d\n" " peername = %s\n" " srcadr = 0x%08x\n" " reach = 0%03o\n" @@ -903,16 +906,19 @@ static int ntpd_read(void) { " offset_frc = %i\n" " offset = %f\n" " dispersion = %f\n", - i, peername, ntohl(ptr->srcadr), ptr->reach, ntpd_read_fp(ptr->delay), + i, is_refclock, (is_refclock > 0) ? refclock_id : 0, peername, + ntohl(ptr->srcadr), ptr->reach, ntpd_read_fp(ptr->delay), ntohl(ptr->offset_int), ntohl(ptr->offset_frc), offset, ntpd_read_fp(ptr->dispersion)); - if (refclock_id != - 1) /* not the system clock (offset will always be zero.. */ - ntpd_submit_reach("time_offset", peername, ptr->reach, offset); ntpd_submit_reach("time_dispersion", peername, ptr->reach, ntpd_read_fp(ptr->dispersion)); - if (refclock_id == 0) /* not a reference clock */ + + /* not the system clock (offset will always be zero) */ + if (!(is_refclock && refclock_id == 1)) + ntpd_submit_reach("time_offset", peername, ptr->reach, offset); + + if (!is_refclock) /* not a reference clock */ ntpd_submit_reach("delay", peername, ptr->reach, ntpd_read_fp(ptr->delay)); }