X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fnetwork.c;h=ae5ed09652729b2fd7b679d8f90936c07eec59f3;hb=74fa9577b1acbb965488aa0a48c140d8ece437bf;hp=ce9b0cc71fe32f871a63e1f4f75e7039314238f2;hpb=61adba6f19b8f6ec08b996f4b2ddc9d6fa5d7fc7;p=collectd.git diff --git a/src/network.c b/src/network.c index ce9b0cc7..ae5ed096 100644 --- a/src/network.c +++ b/src/network.c @@ -76,7 +76,9 @@ /* Re enable deprecation warnings */ # pragma GCC diagnostic warning "-Wdeprecated-declarations" # endif +# if GCRYPT_VERSION_NUMBER < 0x010600 GCRY_THREAD_OPTION_PTHREAD_IMPL; +# endif #endif #ifndef IPV6_ADD_MEMBERSHIP @@ -508,7 +510,9 @@ static void network_init_gcrypt (void) /* {{{ */ * above doesn't count, as it doesn't implicitly initalize Libgcrypt. * * tl;dr: keep all these gry_* statements in this exact order please. */ +# if GCRYPT_VERSION_NUMBER < 0x010600 gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread); +# endif gcry_check_version (NULL); gcry_control (GCRYCTL_INIT_SECMEM, 32768); gcry_control (GCRYCTL_INITIALIZATION_FINISHED); @@ -1996,7 +2000,7 @@ static sockent_t *sockent_create (int type) /* {{{ */ { sockent_t *se; - if ((type != SOCKENT_TYPE_CLIENT) || (type != SOCKENT_TYPE_SERVER)) + if ((type != SOCKENT_TYPE_CLIENT) && (type != SOCKENT_TYPE_SERVER)) return (NULL); se = malloc (sizeof (*se)); @@ -2013,6 +2017,7 @@ static sockent_t *sockent_create (int type) /* {{{ */ if (type == SOCKENT_TYPE_SERVER) { se->data.server.fd = NULL; + se->data.server.fd_num = 0; #if HAVE_LIBGCRYPT se->data.server.security_level = SECURITY_LEVEL_NONE; se->data.server.auth_file = NULL; @@ -2208,6 +2213,9 @@ static int sockent_server_listen (sockent_t *se) /* {{{ */ if (se == NULL) return (-1); + assert (se->data.server.fd == NULL); + assert (se->data.server.fd_num == 0); + node = se->node; service = se->service; @@ -2407,13 +2415,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; @@ -2422,15 +2430,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++) @@ -2448,10 +2455,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); @@ -2465,7 +2472,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); @@ -2473,7 +2481,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; @@ -2509,7 +2518,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. */ @@ -2524,15 +2538,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) @@ -2973,6 +2983,10 @@ static int network_config_set_ttl (const oconfig_item_t *ci) /* {{{ */ tmp = (int) ci->values[0].value.number; if ((tmp > 0) && (tmp <= 255)) network_config_ttl = tmp; + else { + WARNING ("network plugin: The `TimeToLive' must be between 1 and 255."); + return (-1); + } return (0); } /* }}} int network_config_set_ttl */ @@ -3244,6 +3258,14 @@ static int network_config (oconfig_item_t *ci) /* {{{ */ { int i; + /* The options need to be applied first */ + for (i = 0; i < ci->children_num; i++) + { + oconfig_item_t *child = ci->children + i; + if (strcasecmp ("TimeToLive", child->key) == 0) + network_config_set_ttl (child); + } + for (i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -3252,8 +3274,9 @@ static int network_config (oconfig_item_t *ci) /* {{{ */ network_config_add_listen (child); else if (strcasecmp ("Server", child->key) == 0) network_config_add_server (child); - else if (strcasecmp ("TimeToLive", child->key) == 0) - network_config_set_ttl (child); + else if (strcasecmp ("TimeToLive", child->key) == 0) { + /* Handled earlier */ + } else if (strcasecmp ("MaxPacketSize", child->key) == 0) network_config_set_buffer_size (child); else if (strcasecmp ("Forward", child->key) == 0)