summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: d98703f)
raw | patch | inline | side by side (parent: d98703f)
author | Claudius Zingerli <gitmail@zeuz.ch> | |
Mon, 7 Sep 2015 14:18:48 +0000 (16:18 +0200) | ||
committer | Claudius Zingerli <gitmail@zeuz.ch> | |
Fri, 29 Apr 2016 15:34:30 +0000 (17:34 +0200) |
src/chrony.c | patch | blob | history |
diff --git a/src/chrony.c b/src/chrony.c
index 7e99aa05b4040dfc642294ea36e2741717d4e854..c39c48bed08a583a8abead1693f4f78538df969c 100644 (file)
--- a/src/chrony.c
+++ b/src/chrony.c
STT_BADPKTLENGTH = 19,
} eChrony_Status;
-static int g_is_connected = 0;
-static int g_chrony_socket = -1;
-static time_t g_chrony_timeout = 0;
-static char *g_chrony_host = NULL;
-static char *g_chrony_port = NULL;
-static uint32_t g_chrony_seq = 0;
-//static char ntpd_port[16];
-
typedef struct ATTRIB_PACKED
{
uint32_t f_n_sources;
uint16_t f_state;
uint16_t f_mode;
uint16_t f_flags;
- uint16_t dummy; //FIXME: Strange dummy space. Needed on gcc 4.8.3 on x86_64
+ uint16_t dummy; /* FIXME: Strange dummy space. Needed on gcc 4.8.3 on x86_64 */
uint16_t f_reachability;
uint32_t f_since_sample;
{
uint32_t f_ref_id;
tChrony_IPAddr addr;
- uint16_t dummy; //FIXME: Strange dummy space. Needed on gcc 4.8.3 on x86_64
+ uint16_t dummy; /* FIXME: Strange dummy space. Needed on gcc 4.8.3 on x86_64 */
uint32_t f_n_samples; //Number of measurements done
uint32_t f_n_runs; //How many measurements to come
uint32_t f_span_seconds; //For how long we're measuring
uint32_t f_dummy2;
uint32_t f_dummy3;
- } header; //Packed: 20Bytes
+ } header; /* Packed: 20Bytes */
union
{
- tChrony_N_Sources n_sources; //Packed: 8 Bytes
+ tChrony_N_Sources n_sources; /* Packed: 4 Bytes */
tChrony_Req_Source_data source_data;
tChrony_Req_Source_stats source_stats;
} body;
- uint8_t padding[4+16]; //Padding to match minimal response size
+ uint8_t padding[4+16]; /* Padding to match minimal response size */
} tChrony_Request;
typedef struct ATTRIB_PACKED
uint32_t f_seq;
uint32_t f_dummy5;
uint32_t f_dummy6;
- } header; //Packed: 24 Bytes
+ } header; /* Packed: 28 Bytes */
/*uint32_t EOR;*/
uint8_t padding[1024];
} tChrony_Response;
+static int g_is_connected = 0;
+static int g_chrony_socket = -1;
+static time_t g_chrony_timeout = 0;
+static char *g_chrony_host = NULL;
+static char *g_chrony_port = NULL;
+static uint32_t g_chrony_seq = 0;
+
/*****************************************************************************/
/* Internal functions */
/*****************************************************************************/
case IPADDR_INET6:
ip6 = addr->addr.ip6;
#if 0
-//FIXME: Detect little endian systems
+/* FIXME: Detect little endian systems */
snprintf(p_buf, p_buf_size, "%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x",
ip6[0], ip6[1], ip6[2], ip6[3], ip6[4], ip6[5], ip6[6], ip6[7],
ip6[8], ip6[9], ip6[10], ip6[11], ip6[12], ip6[13], ip6[14], ip6[15]);
ERROR ("chrony plugin: Error connecting to daemon. Errno = %d", errno);
return (1);
}
- //TODO: Set timeouts!
DEBUG("chrony plugin: Connected");
g_chrony_socket = socket;
}
if (p_resp->header.f_seq != p_req->header.f_seq)
{
- //FIXME: Implement sequence number handling
+ /* FIXME: Implement sequence number handling */
ERROR("chrony plugin: Unexpected sequence number (Was: %d, expected: %d)", p_resp->header.f_seq, p_req->header.f_seq);
return 1;
}
p_req->header.f_dummy3 = 0;
}
-//Code from: https://github.com/mlichvar/chrony/blob/master/util.c (GPLv2)
+/* Code from: https://github.com/mlichvar/chrony/blob/master/util.c (GPLv2) */
/*BEGIN*/
#define FLOAT_EXP_BITS 7
#define FLOAT_EXP_MIN (-(1 << (FLOAT_EXP_BITS - 1)))
#define FLOAT_COEF_MIN (-(1 << (FLOAT_COEF_BITS - 1)))
#define FLOAT_COEF_MAX (-FLOAT_COEF_MIN - 1)
-//double UTI_FloatNetworkToHost(Float f)
+/* double UTI_FloatNetworkToHost(Float f) */
double ntohf(Float f)
{
int32_t exp, coef, x;
{
assert(p_key);
assert(p_value);
- //Parse config variables
+ /* Parse config variables */
if (strcasecmp(p_key, "Host") == 0)
{
if (g_chrony_host != NULL)
static int chrony_read (void)
{
- //plugin_dispatch_values (&vl);
int status,now_src;
char ip_addr_str0[ IPV6_STR_MAX_SIZE];
char ip_addr_str1[IPV6_STR_MAX_SIZE];
chrony_push_data("clock_reachability",ip_addr_str0,ntohs(chrony_resp.body.source_data.f_reachability));
chrony_push_data("clock_last_meas", ip_addr_str0,ntohs(chrony_resp.body.source_data.f_since_sample));
chrony_push_data("clock_skew_ppm", ip_addr_str1,ntohf(chrony_resp1.body.source_stats.f_skew_ppm));
- chrony_push_data("frequency_error", ip_addr_str1,ntohf(chrony_resp1.body.source_stats.f_rtc_gain_rate_ppm)); //unit: ppm
- chrony_push_data("time_offset", ip_addr_str1,ntohf(chrony_resp1.body.source_stats.f_est_offset)); //unit: s
+ chrony_push_data("frequency_error", ip_addr_str1,ntohf(chrony_resp1.body.source_stats.f_rtc_gain_rate_ppm)); /* unit: ppm */
+ chrony_push_data("time_offset", ip_addr_str1,ntohf(chrony_resp1.body.source_stats.f_est_offset)); /* unit: s */
#endif
}
return (0);