X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fnetwork.c;h=0ee6ed0b9834f96a9ad1cd885657c0e5f9719c89;hb=5d9d056df591e3a8e7e434e15c65a5565d2fe52d;hp=c5fd256f135c6b83e1a9eea749bd5752cf61b61d;hpb=6efc94f59c38e86309078fb9e20c78a2e9c8ff59;p=collectd.git diff --git a/src/network.c b/src/network.c index c5fd256f..0ee6ed0b 100644 --- a/src/network.c +++ b/src/network.c @@ -22,6 +22,7 @@ * Aman Gupta **/ +#define _DEFAULT_SOURCE #define _BSD_SOURCE /* For struct ip_mreq */ #include "collectd.h" @@ -2415,13 +2416,13 @@ static int network_receive (void) /* {{{ */ int buffer_len; int i; - int status; + int status = 0; receive_list_entry_t *private_list_head; receive_list_entry_t *private_list_tail; uint64_t private_list_length; - assert (listen_sockets_num > 0); + assert (listen_sockets_num > 0); private_list_head = NULL; private_list_tail = NULL; @@ -2430,15 +2431,14 @@ static int network_receive (void) /* {{{ */ while (listen_loop == 0) { status = poll (listen_sockets_pollfd, listen_sockets_num, -1); - if (status <= 0) { char errbuf[1024]; if (errno == EINTR) continue; - ERROR ("poll failed: %s", + ERROR ("network plugin: poll(2) failed: %s", sstrerror (errno, errbuf, sizeof (errbuf))); - return (-1); + break; } for (i = 0; (i < listen_sockets_num) && (status > 0); i++) @@ -2456,10 +2456,10 @@ static int network_receive (void) /* {{{ */ if (buffer_len < 0) { char errbuf[1024]; - ERROR ("recv failed: %s", - sstrerror (errno, errbuf, - sizeof (errbuf))); - return (-1); + status = (errno != 0) ? errno : -1; + ERROR ("network plugin: recv(2) failed: %s", + sstrerror (errno, errbuf, sizeof (errbuf))); + break; } stats_octets_rx += ((uint64_t) buffer_len); @@ -2473,7 +2473,8 @@ static int network_receive (void) /* {{{ */ if (ent == NULL) { ERROR ("network plugin: malloc failed."); - return (-1); + status = ENOMEM; + break; } memset (ent, 0, sizeof (receive_list_entry_t)); ent->data = malloc (network_config_packet_size); @@ -2481,7 +2482,8 @@ static int network_receive (void) /* {{{ */ { sfree (ent); ERROR ("network plugin: malloc failed."); - return (-1); + status = ENOMEM; + break; } ent->fd = listen_sockets_pollfd[i].fd; ent->next = NULL; @@ -2517,7 +2519,12 @@ static int network_receive (void) /* {{{ */ private_list_tail = NULL; private_list_length = 0; } + + status = 0; } /* for (listen_sockets_pollfd) */ + + if (status != 0) + break; } /* while (listen_loop == 0) */ /* Make sure everything is dispatched before exiting. */ @@ -2532,15 +2539,11 @@ static int network_receive (void) /* {{{ */ receive_list_tail = private_list_tail; receive_list_length += private_list_length; - private_list_head = NULL; - private_list_tail = NULL; - private_list_length = 0; - pthread_cond_signal (&receive_list_cond); pthread_mutex_unlock (&receive_list_lock); } - return (0); + return (status); } /* }}} int network_receive */ static void *receive_thread (void __attribute__((unused)) *arg) @@ -2983,7 +2986,7 @@ static int network_config_set_ttl (const oconfig_item_t *ci) /* {{{ */ network_config_ttl = tmp; else { WARNING ("network plugin: The `TimeToLive' must be between 1 and 255."); - return (-1); + return (-1); } return (0);