X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fchrony.c;h=f6294e49112dabdcf70a0c84c78e96e40b2a5945;hb=4d370741101aeb037ae52f3529a4a0869e0dc08a;hp=012fd9a9bcb28bb02a37ff9845a5aabb712b5342;hpb=d3bb71e733c1cc86a1d2c5d6da3057d5926003e1;p=collectd.git diff --git a/src/chrony.c b/src/chrony.c index 012fd9a9..f6294e49 100644 --- a/src/chrony.c +++ b/src/chrony.c @@ -26,6 +26,7 @@ */ #include "collectd.h" + #include "common.h" /* auxiliary functions */ #include "plugin.h" /* plugin_register_*, plugin_dispatch_values */ @@ -306,15 +307,15 @@ static int connect_client(const char *p_hostname, const char *p_service, int p_family, int p_socktype) { - struct addrinfo hints, *res = NULL, *ressave = NULL; + struct addrinfo *res, *ressave; int n, sockfd; - memset(&hints, 0, sizeof(struct addrinfo)); - - hints.ai_family = p_family; - hints.ai_socktype = p_socktype; + struct addrinfo ai_hints = { + .ai_family = p_family, + .ai_socktype = p_socktype + }; - n = getaddrinfo(p_hostname, p_service, &hints, &res); + n = getaddrinfo(p_hostname, p_service, &ai_hints, &res); if (n < 0) { @@ -451,8 +452,8 @@ chrony_connect(void) if (chrony_set_timeout()) { - ERROR(PLUGIN_NAME ": Error setting timeout to %lds. Errno = %d", - g_chrony_timeout, errno); + ERROR(PLUGIN_NAME ": Error setting timeout to %llds. Errno = %d", + (long long)g_chrony_timeout, errno); return CHRONY_RC_FAIL; } return CHRONY_RC_OK; @@ -852,8 +853,7 @@ chrony_request_daemon_stats(void) } #if COLLECT_DEBUG { - char src_addr[IPV6_STR_MAX_SIZE]; - memset(src_addr, 0, sizeof(src_addr)); + char src_addr[IPV6_STR_MAX_SIZE] = { 0 }; niptoha(&chrony_resp.body.tracking.addr, src_addr, sizeof(src_addr)); DEBUG(PLUGIN_NAME ": Daemon stat: .addr = %s, .ref_id= %u, .stratum = %u, .leap_status = %u, .ref_time = %u:%u:%u, .current_correction = %f, .last_offset = %f, .rms_offset = %f, .freq_ppm = %f, .skew_ppm = %f, .root_delay = %f, .root_dispersion = %f, .last_update_interval = %f", src_addr, ntohs(chrony_resp.body.tracking.f_ref_id), ntohs(chrony_resp.body.tracking.f_stratum), @@ -937,8 +937,7 @@ chrony_request_source_data(int p_src_idx, int *p_is_reachable) tChrony_Request chrony_req; tChrony_Response chrony_resp; - char src_addr[IPV6_STR_MAX_SIZE]; - memset(src_addr, 0, sizeof(src_addr)); + char src_addr[IPV6_STR_MAX_SIZE] = { 0 }; chrony_init_req(&chrony_req); chrony_req.body.source_data.f_index = htonl(p_src_idx); @@ -997,8 +996,7 @@ chrony_request_source_stats(int p_src_idx, const int *p_is_reachable) tChrony_Response chrony_resp; double skew_ppm, frequency_error, time_offset; - char src_addr[IPV6_STR_MAX_SIZE]; - memset(src_addr, 0, sizeof(src_addr)); + char src_addr[IPV6_STR_MAX_SIZE] = { 0 }; if (*p_is_reachable == 0) { @@ -1055,7 +1053,7 @@ chrony_read(void) { /* collectd read callback: Perform data acquisition */ int rc; - unsigned int now_src, n_sources; + unsigned int n_sources; if (g_chrony_seq_is_initialized == 0) { @@ -1077,7 +1075,7 @@ chrony_read(void) if (rc != CHRONY_RC_OK) return rc; - for (now_src = 0; now_src < n_sources; ++now_src) + for (unsigned int now_src = 0; now_src < n_sources; ++now_src) { int is_reachable; rc = chrony_request_source_data(now_src, &is_reachable);