X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Frrdtool.c;h=f5e01c81fe522d4fba76842156540594a24d3ef3;hb=41288c6a9ed050b41ad47184aa1b53668c3588cc;hp=b45f8d997fc4b7acb2882b645eebfb519a3b22b2;hpb=3dc0454f7bee3e852171d1f6944891693364ee01;p=collectd.git diff --git a/src/rrdtool.c b/src/rrdtool.c index b45f8d99..f5e01c81 100644 --- a/src/rrdtool.c +++ b/src/rrdtool.c @@ -24,6 +24,7 @@ **/ #include "collectd.h" + #include "plugin.h" #include "common.h" #include "utils_avltree.h" @@ -32,10 +33,6 @@ #include -#if HAVE_PTHREAD_H -# include -#endif - /* * Private types */ @@ -113,7 +110,7 @@ static rrdcreate_config_t rrdcreate_config = * ALWAYS lock `cache_lock' first! */ static cdtime_t cache_timeout = 0; static cdtime_t cache_flush_timeout = 0; -static cdtime_t random_timeout = TIME_T_TO_CDTIME_T (1); +static cdtime_t random_timeout = TIME_T_TO_CDTIME_T_STATIC (1); static cdtime_t cache_flush_last; static c_avl_tree_t *cache = NULL; static pthread_mutex_t cache_lock = PTHREAD_MUTEX_INITIALIZER; @@ -204,7 +201,6 @@ static int value_list_to_string_multiple (char *buffer, int buffer_len, int offset; int status; time_t tt; - size_t i; memset (buffer, '\0', buffer_len); @@ -214,7 +210,7 @@ static int value_list_to_string_multiple (char *buffer, int 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) @@ -335,7 +331,6 @@ static void *rrd_queue_thread (void __attribute__((unused)) *data) char **values; int values_num; int status; - int i; values = NULL; values_num = 0; @@ -416,7 +411,7 @@ static void *rrd_queue_thread (void __attribute__((unused)) *data) 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, @@ -462,7 +457,7 @@ static void *rrd_queue_thread (void __attribute__((unused)) *data) 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]); } @@ -560,7 +555,6 @@ static void rrd_cache_flush (cdtime_t timeout) char *key; c_avl_iterator_t *iter; - int i; DEBUG ("rrdtool plugin: Flushing cache, timeout = %.3f", CDTIME_T_TO_DOUBLE (timeout)); @@ -588,7 +582,7 @@ static void rrd_cache_flush (cdtime_t 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) { @@ -608,7 +602,7 @@ static void rrd_cache_flush (cdtime_t timeout) } /* 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) { @@ -692,7 +686,7 @@ static int64_t rrd_get_random_variation (void) long min; long max; - if (random_timeout <= 0) + if (random_timeout == 0) return (0); /* Assure that "cache_timeout + random_variation" is never negative. */ @@ -756,7 +750,7 @@ static int rrd_cache_insert (const char *filename, 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) { @@ -860,7 +854,6 @@ static int rrd_cache_destroy (void) /* {{{ */ while (c_avl_pick (cache, &key, &value) == 0) { rrd_cache_t *rc; - int i; sfree (key); key = NULL; @@ -871,7 +864,7 @@ static int rrd_cache_destroy (void) /* {{{ */ 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);