X-Git-Url: https://git.octo.it/?p=collectd.git;a=blobdiff_plain;f=src%2Fdns.c;h=e64af0dd8440ac3bb63c9ae632ecc54404834701;hp=1541c31bab0e6757b456915b1df80824cf786b70;hb=1159cb5d383c55a80a0db100b8f7aadcf44740a5;hpb=79963d13c1884d1d92667cc502ad20758b084a12 diff --git a/src/dns.c b/src/dns.c index 1541c31b..e64af0dd 100644 --- a/src/dns.c +++ b/src/dns.c @@ -84,7 +84,7 @@ static counter_list_t *counter_list_search(counter_list_t **list, if (entry->key == key) break; - return (entry); + return entry; } static counter_list_t *counter_list_create(counter_list_t **list, @@ -94,7 +94,7 @@ static counter_list_t *counter_list_create(counter_list_t **list, entry = calloc(1, sizeof(*entry)); if (entry == NULL) - return (NULL); + return NULL; entry->key = key; entry->value = value; @@ -111,7 +111,7 @@ static counter_list_t *counter_list_create(counter_list_t **list, last->next = entry; } - return (entry); + return entry; } static void counter_list_add(counter_list_t **list, unsigned int key, @@ -132,7 +132,7 @@ static int dns_config(const char *key, const char *value) { if (pcap_device != NULL) free(pcap_device); if ((pcap_device = strdup(value)) == NULL) - return (1); + return 1; } else if (strcasecmp(key, "IgnoreSource") == 0) { if (value != NULL) ignore_list_add_name(value); @@ -142,10 +142,10 @@ static int dns_config(const char *key, const char *value) { else select_numeric_qtype = 1; } else { - return (-1); + return -1; } - return (0); + return 0; } static void dns_child_callback(const rfc1035_header_t *dns) { @@ -208,19 +208,19 @@ static int dns_run_pcap_loop(void) { ERROR("dns plugin: Opening interface `%s' " "failed: %s", (pcap_device != NULL) ? pcap_device : "any", pcap_error); - return (PCAP_ERROR); + return PCAP_ERROR; } status = pcap_compile(pcap_obj, &fp, "udp port 53", 1, 0); if (status < 0) { ERROR("dns plugin: pcap_compile failed: %s", pcap_statustostr(status)); - return (status); + return status; } status = pcap_setfilter(pcap_obj, &fp); if (status < 0) { ERROR("dns plugin: pcap_setfilter failed: %s", pcap_statustostr(status)); - return (status); + return status; } DEBUG("dns plugin: PCAP object created."); @@ -237,32 +237,20 @@ static int dns_run_pcap_loop(void) { status = PCAP_ERROR_IFACE_NOT_UP; pcap_close(pcap_obj); - return (status); + 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; + struct timespec ts = CDTIME_T_TO_TIMESPEC(plugin_get_interval()); + while (nanosleep(&ts, &ts) != 0) { + if ((errno == EINTR) || (errno == EAGAIN)) continue; - } else - break; + + return errno; } - return (status); + return 0; } /* }}} int dns_sleep_one_interval */ static void *dns_child_loop(__attribute__((unused)) void *dummy) /* {{{ */ @@ -281,7 +269,7 @@ static void *dns_child_loop(__attribute__((unused)) void *dummy) /* {{{ */ ERROR("dns plugin: PCAP returned error %s.", pcap_statustostr(status)); listen_thread_init = 0; - return (NULL); + return NULL; } /* }}} void *dns_child_loop */ static int dns_init(void) { @@ -294,15 +282,15 @@ static int dns_init(void) { pthread_mutex_unlock(&traffic_mutex); if (listen_thread_init != 0) - return (-1); + return -1; - status = - plugin_thread_create(&listen_thread, NULL, dns_child_loop, (void *)0); + status = plugin_thread_create(&listen_thread, NULL, dns_child_loop, (void *)0, + "dns listen"); if (status != 0) { char errbuf[1024]; ERROR("dns plugin: pthread_create failed: %s", sstrerror(errno, errbuf, sizeof(errbuf))); - return (-1); + return -1; } listen_thread_init = 1; @@ -320,19 +308,15 @@ static int dns_init(void) { } #endif - return (0); + return 0; } /* int dns_init */ static void submit_derive(const char *type, const char *type_instance, derive_t value) { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].derive = value; - - vl.values = values; + vl.values = &(value_t){.derive = value}; vl.values_len = 1; - sstrncpy(vl.host, hostname_g, sizeof(vl.host)); sstrncpy(vl.plugin, "dns", sizeof(vl.plugin)); sstrncpy(vl.type, type, sizeof(vl.type)); sstrncpy(vl.type_instance, type_instance, sizeof(vl.type_instance)); @@ -341,15 +325,13 @@ static void submit_derive(const char *type, const char *type_instance, } /* void submit_derive */ static void submit_octets(derive_t queries, derive_t responses) { - value_t values[2]; + value_t values[] = { + {.derive = queries}, {.derive = responses}, + }; value_list_t vl = VALUE_LIST_INIT; - values[0].derive = queries; - values[1].derive = responses; - vl.values = values; - vl.values_len = 2; - sstrncpy(vl.host, hostname_g, sizeof(vl.host)); + vl.values_len = STATIC_ARRAY_SIZE(values); sstrncpy(vl.plugin, "dns", sizeof(vl.plugin)); sstrncpy(vl.type, "dns_octets", sizeof(vl.type)); @@ -410,7 +392,7 @@ static int dns_read(void) { submit_derive("dns_rcode", rcode_str(keys[i]), values[i]); } - return (0); + return 0; } /* int dns_read */ void module_register(void) {