diff --git a/src/network.c b/src/network.c
index 156028e27992239fb803bda104e35adafa2ca38b..109289e3a76d62924be53dce9902cd2e21c2273f 100644 (file)
--- a/src/network.c
+++ b/src/network.c
/**
* collectd - src/network.c
* Copyright (C) 2005-2009 Florian octo Forster
+ * Copyright (C) 2009 Aman Gupta
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
*
* Authors:
* Florian octo Forster <octo at verplant.org>
+ * Aman Gupta <aman at tmm1.net>
**/
#define _BSD_SOURCE /* For struct ip_mreq */
#if HAVE_LIBGCRYPT
# include <gcrypt.h>
+GCRY_THREAD_OPTION_PTHREAD_IMPL;
#endif
#ifndef IPV6_ADD_MEMBERSHIP
/* Lock and wait for more data to come in */
pthread_mutex_lock (&receive_list_lock);
while ((listen_loop == 0)
- && (receive_list_head == NULL))
+ && (receive_list_head == NULL))
pthread_cond_wait (&receive_list_cond, &receive_list_lock);
/* Remove the head entry and unlock */
if (se == NULL)
{
- ERROR ("network plugin: Got packet from FD %i, but can't "
- "find an appropriate socket entry.",
- ent->fd);
- sfree (ent);
- continue;
+ ERROR ("network plugin: Got packet from FD %i, but can't "
+ "find an appropriate socket entry.",
+ ent->fd);
+ sfree (ent->data);
+ sfree (ent);
+ continue;
}
parse_packet (se, ent->data, ent->data_len, /* flags = */ 0);
+ sfree (ent->data);
sfree (ent);
} /* while (42) */
ent->fd = listen_sockets_pollfd[i].fd;
ent->next = NULL;
- /* Hopefully this be optimized out by the compiler. It
- * might help prevent stupid bugs in the future though.
- */
- assert (sizeof (ent->data) == sizeof (buffer));
-
memcpy (ent->data, buffer, buffer_len);
ent->data_len = buffer_len;
static void network_init_buffer (void)
{
- memset (send_buffer, 0, sizeof (send_buffer));
+ memset (send_buffer, 0, network_config_packet_size);
send_buffer_ptr = send_buffer;
send_buffer_fill = 0;
pthread_mutex_lock (&send_buffer_lock);
status = add_to_buffer (send_buffer_ptr,
- sizeof (send_buffer) - (send_buffer_fill + BUFF_SIG_SIZE),
+ network_config_packet_size - (send_buffer_fill + BUFF_SIG_SIZE),
&send_buffer_vl,
ds, vl);
if (status >= 0)
flush_buffer ();
status = add_to_buffer (send_buffer_ptr,
- sizeof (send_buffer) - (send_buffer_fill + BUFF_SIG_SIZE),
+ network_config_packet_size - (send_buffer_fill + BUFF_SIG_SIZE),
&send_buffer_vl,
ds, vl);
ERROR ("network plugin: Unable to append to the "
"buffer for some weird reason");
}
- else if ((sizeof (send_buffer) - send_buffer_fill) < 15)
+ else if ((network_config_packet_size - send_buffer_fill) < 15)
{
flush_buffer ();
}
if (send_buffer_fill > 0)
flush_buffer ();
- free (send_buffer);
+ sfree (send_buffer);
/* TODO: Close `sending_sockets' */
return (0);
have_init = true;
+#if HAVE_LIBGCRYPT
+ gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);
+ gcry_control (GCRYCTL_INIT_SECMEM, 32768, 0);
+ gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
+#endif
+
plugin_register_shutdown ("network", network_shutdown);
send_buffer = malloc (network_config_packet_size);