projects
/
collectd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge pull request #1454 from rubenk/libi2c-dev-mark-as-linux-only
[collectd.git]
/
src
/
network.c
diff --git
a/src/network.c
b/src/network.c
index
19ab4de
..
9169000
100644
(file)
--- a/
src/network.c
+++ b/
src/network.c
@@
-39,9
+39,6
@@
#if HAVE_PTHREAD_H
# include <pthread.h>
#endif
#if HAVE_PTHREAD_H
# include <pthread.h>
#endif
-#if HAVE_SYS_SOCKET_H
-# include <sys/socket.h>
-#endif
#if HAVE_NETDB_H
# include <netdb.h>
#endif
#if HAVE_NETDB_H
# include <netdb.h>
#endif
@@
-772,7
+769,7
@@
static int write_part_string (char **ret_buffer, int *ret_buffer_len,
} /* int write_part_string */
static int parse_part_values (void **ret_buffer, size_t *ret_buffer_len,
} /* int write_part_string */
static int parse_part_values (void **ret_buffer, size_t *ret_buffer_len,
- value_t **ret_values,
in
t *ret_num_values)
+ value_t **ret_values,
size_
t *ret_num_values)
{
char *buffer = *ret_buffer;
size_t buffer_len = *ret_buffer_len;
{
char *buffer = *ret_buffer;
size_t buffer_len = *ret_buffer_len;
@@
-876,7
+873,7
@@
static int parse_part_values (void **ret_buffer, size_t *ret_buffer_len,
*ret_buffer = buffer;
*ret_buffer_len = buffer_len - pkg_length;
*ret_buffer = buffer;
*ret_buffer_len = buffer_len - pkg_length;
- *ret_num_values = pkg_numval;
+ *ret_num_values =
(size_t)
pkg_numval;
*ret_values = pkg_values;
sfree (pkg_types);
*ret_values = pkg_values;
sfree (pkg_types);
@@
-2443,14
+2440,14
@@
static int network_receive (void) /* {{{ */
char buffer[network_config_packet_size];
int buffer_len;
char buffer[network_config_packet_size];
int buffer_len;
-
in
t i;
- int status;
+
size_
t i;
+ 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;
@@
-2459,15
+2456,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++)
@@
-2485,10
+2481,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);
@@
-2502,7
+2498,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);
@@
-2510,7
+2507,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;
@@
-2546,7
+2544,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. */
@@
-2561,15
+2564,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)
@@
-3103,7
+3102,7
@@
static int network_config_add_listen (const oconfig_item_t *ci) /* {{{ */
status = sockent_server_listen (se);
if (status != 0)
{
status = sockent_server_listen (se);
if (status != 0)
{
- ERROR ("network plugin: network_config_add_
server
: sockent_server_listen failed.");
+ ERROR ("network plugin: network_config_add_
listen
: sockent_server_listen failed.");
sockent_destroy (se);
return (-1);
}
sockent_destroy (se);
return (-1);
}