static char *send_buffer_ptr;
static int send_buffer_fill;
static value_list_t send_buffer_vl = VALUE_LIST_STATIC;
-static char send_buffer_type[DATA_MAX_NAME_LEN];
static pthread_mutex_t send_buffer_lock = PTHREAD_MUTEX_INITIALIZER;
static c_avl_tree_t *cache_tree = NULL;
static pthread_mutex_t cache_lock = PTHREAD_MUTEX_INITIALIZER;
-static time_t cache_flush_last;
+static time_t cache_flush_last = 0;
static int cache_flush_interval = 1800;
/*
*/
static int network_set_ttl (const sockent_t *se, const struct addrinfo *ai)
{
+ DEBUG ("network plugin: network_set_ttl: network_config_ttl = %i;",
+ network_config_ttl);
+
if ((network_config_ttl < 1) || (network_config_ttl > 255))
return (-1);
- DEBUG ("ttl = %i", network_config_ttl);
-
if (ai->ai_family == AF_INET)
{
struct sockaddr_in *addr = (struct sockaddr_in *) ai->ai_addr;
} /* void network_send_buffer */
static int add_to_buffer (char *buffer, int buffer_size,
- value_list_t *vl_def, char *type_def,
+ value_list_t *vl_def,
const data_set_t *ds, const value_list_t *vl)
{
char *buffer_orig = buffer;
if (write_part_string (&buffer, &buffer_size, TYPE_HOST,
vl->host, strlen (vl->host)) != 0)
return (-1);
- strcpy (vl_def->host, vl->host);
+ sstrncpy (vl_def->host, vl->host, sizeof (vl_def->host));
}
if (vl_def->time != vl->time)
if (write_part_string (&buffer, &buffer_size, TYPE_PLUGIN,
vl->plugin, strlen (vl->plugin)) != 0)
return (-1);
- strcpy (vl_def->plugin, vl->plugin);
+ sstrncpy (vl_def->plugin, vl->plugin, sizeof (vl_def->plugin));
}
if (strcmp (vl_def->plugin_instance, vl->plugin_instance) != 0)
vl->plugin_instance,
strlen (vl->plugin_instance)) != 0)
return (-1);
- strcpy (vl_def->plugin_instance, vl->plugin_instance);
+ sstrncpy (vl_def->plugin_instance, vl->plugin_instance, sizeof (vl_def->plugin_instance));
}
- if (strcmp (type_def, vl->type) != 0)
+ if (strcmp (vl_def->type, vl->type) != 0)
{
if (write_part_string (&buffer, &buffer_size, TYPE_TYPE,
vl->type, strlen (vl->type)) != 0)
return (-1);
- strcpy (type_def, vl->type);
+ sstrncpy (vl_def->type, ds->type, sizeof (vl_def->type));
}
if (strcmp (vl_def->type_instance, vl->type_instance) != 0)
vl->type_instance,
strlen (vl->type_instance)) != 0)
return (-1);
- strcpy (vl_def->type_instance, vl->type_instance);
+ sstrncpy (vl_def->type_instance, vl->type_instance, sizeof (vl_def->type_instance));
}
if (write_part_values (&buffer, &buffer_size, ds, vl) != 0)
network_send_buffer (send_buffer, send_buffer_fill);
send_buffer_ptr = send_buffer;
send_buffer_fill = 0;
- memset (&send_buffer_vl, '\0', sizeof (send_buffer_vl));
- memset (send_buffer_type, '\0', sizeof (send_buffer_type));
+ memset (&send_buffer_vl, 0, sizeof (send_buffer_vl));
}
static int network_write (const data_set_t *ds, const value_list_t *vl)
status = add_to_buffer (send_buffer_ptr,
sizeof (send_buffer) - send_buffer_fill,
- &send_buffer_vl, send_buffer_type,
+ &send_buffer_vl,
ds, vl);
if (status >= 0)
{
status = add_to_buffer (send_buffer_ptr,
sizeof (send_buffer) - send_buffer_fill,
- &send_buffer_vl, send_buffer_type,
+ &send_buffer_vl,
ds, vl);
if (status >= 0)
fields_num = strsplit (val_cpy, fields, 3);
if ((fields_num != 1)
&& (fields_num != 2))
+ {
+ sfree (val_cpy);
return (1);
+ }
else if (fields_num == 2)
{
if ((service = strchr (fields[1], '.')) != NULL)
network_add_listen_socket (node, service);
else
network_add_sending_socket (node, service);
+
+ sfree (val_cpy);
}
else if (strcasecmp ("TimeToLive", key) == 0)
{
plugin_unregister_write ("network");
plugin_unregister_shutdown ("network");
+ /* Let the init function do it's move again ;) */
+ cache_flush_last = 0;
+
return (0);
} /* int network_shutdown */
static int network_init (void)
{
+ /* Check if we were already initialized. If so, just return - there's
+ * nothing more to do (for now, that is). */
+ if (cache_flush_last != 0)
+ return (0);
+
plugin_register_shutdown ("network", network_shutdown);
send_buffer_ptr = send_buffer;
send_buffer_fill = 0;
- memset (&send_buffer_vl, '\0', sizeof (send_buffer_vl));
- memset (send_buffer_type, '\0', sizeof (send_buffer_type));
+ memset (&send_buffer_vl, 0, sizeof (send_buffer_vl));
cache_tree = c_avl_create ((int (*) (const void *, const void *)) strcmp);
cache_flush_last = time (NULL);
return (0);
} /* int network_init */
-static int network_flush (int timeout)
+/*
+ * The flush option of the network plugin cannot flush individual identifiers.
+ * All the values are added to a buffer and sent when the buffer is full, the
+ * requested value may or may not be in there, it's not worth finding out. We
+ * just send the buffer if `flush' is called - if the requested value was in
+ * there, good. If not, well, then there is nothing to flush.. -octo
+ */
+static int network_flush (int timeout, const char *identifier)
{
pthread_mutex_lock (&send_buffer_lock);