projects
/
collectd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Initial support of GPSd in collectd.
[collectd.git]
/
src
/
network.c
diff --git
a/src/network.c
b/src/network.c
index
9fbba96
..
af24911
100644
(file)
--- a/
src/network.c
+++ b/
src/network.c
@@
-77,7
+77,9
@@
/* Re enable deprecation warnings */
# pragma GCC diagnostic warning "-Wdeprecated-declarations"
# endif
/* Re enable deprecation warnings */
# pragma GCC diagnostic warning "-Wdeprecated-declarations"
# endif
+# if GCRYPT_VERSION_NUMBER < 0x010600
GCRY_THREAD_OPTION_PTHREAD_IMPL;
GCRY_THREAD_OPTION_PTHREAD_IMPL;
+# endif
#endif
#ifndef IPV6_ADD_MEMBERSHIP
#endif
#ifndef IPV6_ADD_MEMBERSHIP
@@
-511,7
+513,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. */
* 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);
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);
gcry_check_version (NULL);
gcry_control (GCRYCTL_INIT_SECMEM, 32768);
gcry_control (GCRYCTL_INITIALIZATION_FINISHED);
@@
-2023,6
+2027,7
@@
static sockent_t *sockent_create (int type) /* {{{ */
if (type == SOCKENT_TYPE_SERVER)
{
se->data.server.fd = NULL;
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;
#if HAVE_LIBGCRYPT
se->data.server.security_level = SECURITY_LEVEL_NONE;
se->data.server.auth_file = NULL;
@@
-2236,6
+2241,9
@@
static int sockent_server_listen (sockent_t *se) /* {{{ */
if (se == NULL)
return (-1);
if (se == NULL)
return (-1);
+ assert (se->data.server.fd == NULL);
+ assert (se->data.server.fd_num == 0);
+
node = se->node;
service = se->service;
node = se->node;
service = se->service;
@@
-2435,13
+2443,13
@@
static int network_receive (void) /* {{{ */
int buffer_len;
int i;
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;
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;
private_list_head = NULL;
private_list_tail = NULL;
@@
-2450,15
+2458,14
@@
static int network_receive (void) /* {{{ */
while (listen_loop == 0)
{
status = poll (listen_sockets_pollfd, listen_sockets_num, -1);
while (listen_loop == 0)
{
status = poll (listen_sockets_pollfd, listen_sockets_num, -1);
-
if (status <= 0)
{
char errbuf[1024];
if (errno == EINTR)
continue;
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)));
sstrerror (errno, errbuf, sizeof (errbuf)));
-
return (-1)
;
+
break
;
}
for (i = 0; (i < listen_sockets_num) && (status > 0); i++)
}
for (i = 0; (i < listen_sockets_num) && (status > 0); i++)
@@
-2476,10
+2483,10
@@
static int network_receive (void) /* {{{ */
if (buffer_len < 0)
{
char errbuf[1024];
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);
}
stats_octets_rx += ((uint64_t) buffer_len);
@@
-2493,7
+2500,8
@@
static int network_receive (void) /* {{{ */
if (ent == NULL)
{
ERROR ("network plugin: malloc failed.");
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);
}
memset (ent, 0, sizeof (receive_list_entry_t));
ent->data = malloc (network_config_packet_size);
@@
-2501,7
+2509,8
@@
static int network_receive (void) /* {{{ */
{
sfree (ent);
ERROR ("network plugin: malloc failed.");
{
sfree (ent);
ERROR ("network plugin: malloc failed.");
- return (-1);
+ status = ENOMEM;
+ break;
}
ent->fd = listen_sockets_pollfd[i].fd;
ent->next = NULL;
}
ent->fd = listen_sockets_pollfd[i].fd;
ent->next = NULL;
@@
-2537,7
+2546,12
@@
static int network_receive (void) /* {{{ */
private_list_tail = NULL;
private_list_length = 0;
}
private_list_tail = NULL;
private_list_length = 0;
}
+
+ status = 0;
} /* for (listen_sockets_pollfd) */
} /* for (listen_sockets_pollfd) */
+
+ if (status != 0)
+ break;
} /* while (listen_loop == 0) */
/* Make sure everything is dispatched before exiting. */
} /* while (listen_loop == 0) */
/* Make sure everything is dispatched before exiting. */
@@
-2552,15
+2566,11
@@
static int network_receive (void) /* {{{ */
receive_list_tail = private_list_tail;
receive_list_length += private_list_length;
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);
}
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)
} /* }}} int network_receive */
static void *receive_thread (void __attribute__((unused)) *arg)