**/
#include "collectd.h"
+
#include "plugin.h"
#include "common.h"
#include "utils_avltree.h"
#include <rrd.h>
-#if HAVE_PTHREAD_H
-# include <pthread.h>
-#endif
-
/*
* Private types
*/
assert (template == NULL);
new_argc = 2 + argc;
- new_argv = (char **) malloc ((new_argc + 1) * sizeof (char *));
+ new_argv = malloc ((new_argc + 1) * sizeof (*new_argv));
if (new_argv == NULL)
{
ERROR ("rrdtool plugin: malloc failed.");
int offset;
int status;
time_t tt;
- size_t i;
memset (buffer, '\0', buffer_len);
return (-1);
offset = status;
- for (i = 0; i < ds->ds_num; i++)
+ for (size_t i = 0; i < ds->ds_num; i++)
{
if ((ds->ds[i].type != DS_TYPE_COUNTER)
&& (ds->ds[i].type != DS_TYPE_GAUGE)
char **values;
int values_num;
int status;
- int i;
values = NULL;
values_num = 0;
pthread_mutex_unlock (&queue_lock);
/* We now need the cache lock so the entry isn't updated while
- * we make a copy of it's values */
+ * we make a copy of its values */
pthread_mutex_lock (&cache_lock);
status = c_avl_get (cache, queue_entry->filename,
}
/* Update `tv_next_update' */
- if (write_rate > 0.0)
+ if (write_rate > 0.0)
{
gettimeofday (&tv_now, /* timezone = */ NULL);
tv_next_update.tv_sec = tv_now.tv_sec;
values_num, (values_num == 1) ? "" : "s",
queue_entry->filename);
- for (i = 0; i < values_num; i++)
+ for (int i = 0; i < values_num; i++)
{
sfree (values[i]);
}
{
rrd_queue_t *queue_entry;
- queue_entry = (rrd_queue_t *) malloc (sizeof (rrd_queue_t));
+ queue_entry = malloc (sizeof (*queue_entry));
if (queue_entry == NULL)
return (-1);
{
if (strcmp (this->filename, filename) == 0)
break;
-
+
prev = this;
this = this->next;
}
char *key;
c_avl_iterator_t *iter;
- int i;
DEBUG ("rrdtool plugin: Flushing cache, timeout = %.3f",
CDTIME_T_TO_DOUBLE (timeout));
}
else /* ancient and no values -> waste of memory */
{
- char **tmp = (char **) realloc ((void *) keys,
+ char **tmp = realloc (keys,
(keys_num + 1) * sizeof (char *));
if (tmp == NULL)
{
}
} /* while (c_avl_iterator_next) */
c_avl_iterator_destroy (iter);
-
- for (i = 0; i < keys_num; i++)
+
+ for (int i = 0; i < keys_num; i++)
{
if (c_avl_remove (cache, keys[i], (void *) &key, (void *) &rc) != 0)
{
long min;
long max;
- if (random_timeout <= 0)
+ if (random_timeout == 0)
return (0);
/* Assure that "cache_timeout + random_variation" is never negative. */
return (-1);
}
- values_new = (char **) realloc ((void *) rc->values,
+ values_new = realloc ((void *) rc->values,
(rc->values_num + 1) * sizeof (char *));
if (values_new == NULL)
{
while (c_avl_pick (cache, &key, &value) == 0)
{
rrd_cache_t *rc;
- int i;
sfree (key);
key = NULL;
if (rc->values_num > 0)
non_empty++;
- for (i = 0; i < rc->values_num; i++)
+ for (int i = 0; i < rc->values_num; i++)
sfree (rc->values[i]);
sfree (rc->values);
sfree (rc);
}
else if (strcasecmp ("DataDir", key) == 0)
{
- if (datadir != NULL)
- free (datadir);
- datadir = strdup (value);
+ char *tmp;
+ size_t len;
+
+ tmp = strdup (value);
+ if (tmp == NULL)
+ {
+ ERROR ("rrdtool plugin: strdup failed.");
+ return (1);
+ }
+
+ len = strlen (tmp);
+ while ((len > 0) && (tmp[len - 1] == '/'))
+ {
+ len--;
+ tmp[len] = 0;
+ }
+
+ if (len == 0)
+ {
+ ERROR ("rrdtool plugin: Invalid \"DataDir\" option.");
+ sfree (tmp);
+ return (1);
+ }
+
if (datadir != NULL)
{
- int len = strlen (datadir);
- while ((len > 0) && (datadir[len - 1] == '/'))
- {
- len--;
- datadir[len] = '\0';
- }
- if (len <= 0)
- {
- free (datadir);
- datadir = NULL;
- }
+ sfree (datadir);
}
+
+ datadir = tmp;
}
else if (strcasecmp ("StepSize", key) == 0)
{
while ((ptr = strtok_r (dummy, ", \t", &saveptr)) != NULL)
{
dummy = NULL;
-
+
tmp_alloc = realloc (rrdcreate_config.timespans,
sizeof (int) * (rrdcreate_config.timespans_num + 1));
if (tmp_alloc == NULL)