* Florian octo Forster <octo at verplant.org>
**/
+#define _BSD_SOURCE /* For NI_MAXHOST */
+
#include "collectd.h"
#include "common.h"
#include "plugin.h"
}
else if (strcasecmp (key, "ReverseLookups") == 0)
{
- if ((strcasecmp (value, "True") == 0)
- || (strcasecmp (value, "Yes") == 0)
- || (strcasecmp (value, "On") == 0))
+ if (IS_TRUE (value))
do_reverse_lookups = 1;
else
do_reverse_lookups = 0;
vl.values = values;
vl.values_len = 1;
- vl.time = time (NULL);
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "ntpd", sizeof (vl.plugin));
sstrncpy (vl.plugin_instance, "", sizeof (vl.plugin_instance));
plugin_dispatch_values (&vl);
}
-/* returns `tv0 - tv1' in milliseconds or 0 if `tv1 > tv0' */
-static int timeval_sub (const struct timeval *tv0, const struct timeval *tv1)
-{
- int sec;
- int usec;
-
- if ((tv0->tv_sec < tv1->tv_sec)
- || ((tv0->tv_sec == tv1->tv_sec) && (tv0->tv_usec < tv1->tv_usec)))
- return (0);
-
- sec = tv0->tv_sec - tv1->tv_sec;
- usec = tv0->tv_usec - tv1->tv_usec;
-
- while (usec < 0)
- {
- usec += 1000000;
- sec -= 1;
- }
-
- if (sec < 0)
- return (0);
-
- return ((sec * 1000) + ((usec + 500) / 1000));
-}
-
static int ntpd_connect (void)
{
char *host;
done = 0;
while (done == 0)
{
+ struct timeval time_left;
+
if (gettimeofday (&time_now, NULL) < 0)
{
char errbuf[1024];
return (-1);
}
+ if (timeval_cmp (time_end, time_now, &time_left) <= 0)
+ timeout = 0;
+ else
+ timeout = 1000 * time_left.tv_sec
+ + ((time_left.tv_usec + 500) / 1000);
+
/* timeout reached */
- if ((timeout = timeval_sub (&time_end, &time_now)) == 0)
+ if (timeout <= 0)
break;
poll_s.fd = sd;
0, 0, NULL, /* request data */
&ik_num, &ik_size, (char **) ((void *) &ik), /* response data */
sizeof (struct info_kernel));
-
if (status != 0)
{
- DEBUG ("ntpd_do_query failed with status %i", status);
- return (-1);
+ ERROR ("ntpd plugin: ntpd_do_query (REQ_GET_KERNEL) failed with status %i", status);
+ return (status);
}
- if ((ik == NULL) || (ik_num == 0) || (ik_size == 0))
+ else if ((ik == NULL) || (ik_num == 0) || (ik_size == 0))
{
- DEBUG ("ntpd_do_query returned: ik = %p; ik_num = %i; ik_size = %i;",
+ ERROR ("ntpd plugin: ntpd_do_query returned unexpected data. "
+ "(ik = %p; ik_num = %i; ik_size = %i)",
(void *) ik, ik_num, ik_size);
return (-1);
}
sizeof (struct info_peer_summary));
if (status != 0)
{
- DEBUG ("ntpd_do_query failed with status %i", status);
- return (-1);
+ ERROR ("ntpd plugin: ntpd_do_query (REQ_PEER_LIST_SUM) failed with status %i", status);
+ return (status);
}
- if ((ps == NULL) || (ps_num == 0) || (ps_size == 0))
+ else if ((ps == NULL) || (ps_num == 0) || (ps_size == 0))
{
- DEBUG ("ntpd_do_query returned: ps = %p; ps_num = %i; ps_size = %i;",
+ ERROR ("ntpd plugin: ntpd_do_query returned unexpected data. "
+ "(ps = %p; ps_num = %i; ps_size = %i)",
(void *) ps, ps_num, ps_size);
return (-1);
}