projects
/
collectd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
varnish plugin: Add informative warnings to the config handling.
[collectd.git]
/
src
/
ntpd.c
diff --git
a/src/ntpd.c
b/src/ntpd.c
index
ceb1442
..
f8f4f04
100644
(file)
--- a/
src/ntpd.c
+++ b/
src/ntpd.c
@@
-38,9
+38,6
@@
#if HAVE_NETDB_H
# include <netdb.h>
#endif
#if HAVE_NETDB_H
# include <netdb.h>
#endif
-#if HAVE_SYS_SOCKET_H
-# include <sys/socket.h>
-#endif
#if HAVE_NETINET_IN_H
# include <netinet/in.h>
#endif
#if HAVE_NETINET_IN_H
# include <netinet/in.h>
#endif
@@
-54,6
+51,10
@@
# include <poll.h>
#endif
# include <poll.h>
#endif
+#ifndef STA_NANO
+# define STA_NANO 0x2000
+#endif
+
static const char *config_keys[] =
{
"Host",
static const char *config_keys[] =
{
"Host",
@@
-166,16
+167,16
@@
struct resp_pkt
/* l_fp to double */
#define M_LFPTOD(r_i, r_uf, d) \
do { \
/* l_fp to double */
#define M_LFPTOD(r_i, r_uf, d) \
do { \
- register int32_t i; \
- register uint32_t f; \
+ register int32_t
r
i; \
+ register uint32_t
r
f; \
\
\
- i = (r_i); \
- f = (r_uf); \
- if (i < 0) { \
- M_NEG(
i,
f); \
- (d) = -((double)
i + ((double)
f) / 4294967296.0); \
+
r
i = (r_i); \
+
r
f = (r_uf); \
+ if (
r
i < 0) { \
+ M_NEG(
ri, r
f); \
+ (d) = -((double)
ri + ((double) r
f) / 4294967296.0); \
} else { \
} else { \
- (d) = (double)
i + ((double)
f) / 4294967296.0; \
+ (d) = (double)
ri + ((double) r
f) / 4294967296.0; \
} \
} while (0)
} \
} while (0)
@@
-250,7
+251,7
@@
struct info_kernel
};
/* List of reference clock names */
};
/* List of reference clock names */
-static char *refclock_names[] =
+static c
onst c
har *refclock_names[] =
{
"UNKNOWN", "LOCAL", "GPS_TRAK", "WWV_PST", /* 0- 3 */
"SPECTRACOM", "TRUETIME", "IRIG_AUDIO", "CHU_AUDIO", /* 4- 7 */
{
"UNKNOWN", "LOCAL", "GPS_TRAK", "WWV_PST", /* 0- 3 */
"SPECTRACOM", "TRUETIME", "IRIG_AUDIO", "CHU_AUDIO", /* 4- 7 */
@@
-265,7
+266,7
@@
static char *refclock_names[] =
"JJY", "TT_IRIG", "GPS_ZYFER", "GPS_RIPENCC", /* 40-43 */
"NEOCLK4X" /* 44 */
};
"JJY", "TT_IRIG", "GPS_ZYFER", "GPS_RIPENCC", /* 40-43 */
"NEOCLK4X" /* 44 */
};
-static
in
t refclock_names_num = STATIC_ARRAY_SIZE (refclock_names);
+static
size_
t refclock_names_num = STATIC_ARRAY_SIZE (refclock_names);
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* End of the copied stuff.. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* End of the copied stuff.. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
@@
-310,7
+311,7
@@
static int ntpd_config (const char *key, const char *value)
return (0);
}
return (0);
}
-static void ntpd_submit (c
har *type,
char *type_inst, gauge_t value)
+static void ntpd_submit (c
onst char *type, const
char *type_inst, gauge_t value)
{
value_t values[1];
value_list_t vl = VALUE_LIST_INIT;
{
value_t values[1];
value_list_t vl = VALUE_LIST_INIT;
@@
-331,8
+332,8
@@
static void ntpd_submit (char *type, char *type_inst, gauge_t value)
/* Each time a peer is polled, ntpd shifts the reach register to the left and
* sets the LSB based on whether the peer was reachable. If the LSB is zero,
* the values are out of date. */
/* Each time a peer is polled, ntpd shifts the reach register to the left and
* sets the LSB based on whether the peer was reachable. If the LSB is zero,
* the values are out of date. */
-static void ntpd_submit_reach (c
har *type, char *type_inst, uint8_t reach
,
- gauge_t value)
+static void ntpd_submit_reach (c
onst char *type, const char *type_inst
,
+
uint8_t reach,
gauge_t value)
{
if (!(reach & 1))
value = NAN;
{
if (!(reach & 1))
value = NAN;
@@
-342,8
+343,8
@@
static void ntpd_submit_reach (char *type, char *type_inst, uint8_t reach,
static int ntpd_connect (void)
{
static int ntpd_connect (void)
{
- char *host;
- char *port;
+ c
onst c
har *host;
+ c
onst c
har *port;
struct addrinfo ai_hints;
struct addrinfo *ai_list;
struct addrinfo ai_hints;
struct addrinfo *ai_list;
@@
-508,7
+509,7
@@
static int ntpd_receive_response (int *res_items, int *res_size,
break;
}
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)))
status = recv (sd, (void *) &res, sizeof (res), 0 /* no flags */);
if ((status < 0) && ((errno == EAGAIN) || (errno == EINTR)))
@@
-666,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);
*/
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)
{
(items_num + pkt_item_num) * res_item_size);
if (items == NULL)
{
@@
-723,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);
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;
req.rm_vn_mode = RM_VN_MODE(0, 0, 0);
req.auth_seq = AUTH_SEQ (0, 0);
req.implementation = IMPL_XNTPD;
@@
-868,7
+869,7
@@
static int ntpd_get_name_refclock (char *buffer, size_t buffer_size,
uint32_t refclock_id = ntpd_get_refclock_id (peer_info);
uint32_t unit_id = ntohl (peer_info->srcadr) & 0x00FF;
uint32_t refclock_id = ntpd_get_refclock_id (peer_info);
uint32_t unit_id = ntohl (peer_info->srcadr) & 0x00FF;
- if (
refclock_id
>= refclock_names_num)
+ if (
((size_t) refclock_id)
>= refclock_names_num)
return (ntpd_get_name_from_address (buffer, buffer_size,
peer_info,
/* do_reverse_lookup = */ 0));
return (ntpd_get_name_from_address (buffer, buffer_size,
peer_info,
/* do_reverse_lookup = */ 0));
@@
-913,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
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 <sys/timex.h> header. */
+ * is is nanoseconds, otherwise it's microseconds. */
double scale_loop = 1e-6;
double scale_error = 1e-6;
double scale_loop = 1e-6;
double scale_error = 1e-6;
@@
-939,6
+939,11
@@
static int ntpd_read (void)
return (-1);
}
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);
/* kerninfo -> estimated error */
offset_loop = scale_loop * ((gauge_t) ntohl (ik->offset));
freq_loop = ntpd_read_fp (ik->freq);