X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fdns.c;h=3421c475d7e6fc49c2419332dbcd8e5d3dd09f06;hb=43a771aa5443266cca4cb7aecaf70eb75100a32c;hp=aea41c438de44430d35236aec0ec7d9d9a9c4d7a;hpb=b8f9530ad6ba3a55f129d259c705d9b5d4d3f4e5;p=collectd.git diff --git a/src/dns.c b/src/dns.c index aea41c43..3421c475 100644 --- a/src/dns.c +++ b/src/dns.c @@ -21,6 +21,7 @@ * Mirko Buffoni **/ +#define _DEFAULT_SOURCE #define _BSD_SOURCE #include "collectd.h" @@ -33,7 +34,6 @@ #include #include -#include /* * Private data types @@ -275,12 +275,47 @@ static int dns_run_pcap_loop (void) return (status); } /* int dns_run_pcap_loop */ +static int dns_sleep_one_interval (void) /* {{{ */ +{ + cdtime_t interval; + struct timespec ts = { 0, 0 }; + int status = 0; + + interval = plugin_get_interval (); + CDTIME_T_TO_TIMESPEC (interval, &ts); + + while (42) + { + struct timespec rem = { 0, 0 }; + + status = nanosleep (&ts, &rem); + if (status == 0) + break; + else if ((errno == EINTR) || (errno == EAGAIN)) + { + ts = rem; + continue; + } + else + break; + } + + return (status); +} /* }}} int dns_sleep_one_interval */ + static void *dns_child_loop (__attribute__((unused)) void *dummy) /* {{{ */ { - int status = PCAP_ERROR_IFACE_NOT_UP; + int status; - while (status == PCAP_ERROR_IFACE_NOT_UP) + while (42) + { status = dns_run_pcap_loop (); + if (status != PCAP_ERROR_IFACE_NOT_UP) + break; + + dns_sleep_one_interval (); + } + if (status != PCAP_ERROR_BREAK) ERROR ("dns plugin: PCAP returned error %s.", pcap_statustostr (status));