#include "collectd.h"
-#include "common.h" /* auxiliary functions */
-#include "plugin.h" /* plugin_register_*, plugin_dispatch_values */
+#include "plugin.h" /* plugin_register_*, plugin_dispatch_values */
+#include "utils/common/common.h" /* auxiliary functions */
#if HAVE_NETDB_H
#include <netdb.h> /* struct addrinfo */
#include <arpa/inet.h> /* ntohs/ntohl */
#endif
+/* AIX doesn't have MSG_DONTWAIT */
+#ifndef MSG_DONTWAIT
+#define MSG_DONTWAIT MSG_NONBLOCK
+#endif
+
#define CONFIG_KEY_HOST "Host"
#define CONFIG_KEY_PORT "Port"
#define CONFIG_KEY_TIMEOUT "Timeout"
}
static void nreftostr(uint32_t nrefid, char *p_buf, size_t p_buf_size) {
- int i, j, c;
+ size_t j = 0;
- for (i = j = 0; i < 4; i++) {
- c = ntohl(nrefid) << i * 8 >> 24;
+ for (int i = 0; i < 4; i++) {
+ int c = ntohl(nrefid) << i * 8 >> 24;
if (!isalnum(c) || j + 1 >= p_buf_size)
continue;
p_buf[j++] = c;
}
}
+static void chrony_flush_recv_queue(void) {
+ char buf[1];
+
+ if (g_chrony_is_connected) {
+ while (recv(g_chrony_socket, buf, sizeof(buf), MSG_DONTWAIT) > 0)
+ ;
+ }
+}
+
static int chrony_query(const int p_command, tChrony_Request *p_req,
tChrony_Response *p_resp, size_t *p_resp_size) {
/* Check connection. We simply perform one try as collectd already handles
ntohs(chrony_resp.body.source_data.f_reachability));
chrony_push_data_valid("clock_last_meas", src_addr, is_reachable,
ntohl(chrony_resp.body.source_data.f_since_sample));
- chrony_push_data_valid("time_offset", src_addr, is_reachable,
- ntohf(chrony_resp.body.source_data.f_origin_latest_meas));
+ chrony_push_data_valid(
+ "time_offset", src_addr, is_reachable,
+ ntohf(chrony_resp.body.source_data.f_origin_latest_meas));
return CHRONY_RC_OK;
}
g_chrony_seq_is_initialized = 1;
}
+ /* Ignore late responses that may have been received */
+ chrony_flush_recv_queue();
+
/* Get daemon stats */
rc = chrony_request_daemon_stats();
if (rc != CHRONY_RC_OK)