Do not use *printf() to report errors / debugging messages.
[collectd.git] / src / rrdtool.c
index 4e34d6a..ac81d55 100644 (file)
@@ -195,7 +195,7 @@ static int rra_get (char ***ret, const value_list_t *vl)
                span = rts[i];
 
                if ((span / ss) < rrarows)
-                       continue;
+                       span = ss * rrarows;
 
                if (cdp_len == 0)
                        cdp_len = 1;
@@ -285,7 +285,7 @@ static int ds_get (char ***ret, const data_set_t *ds, const value_list_t *vl)
 
                if (isnan (d->min))
                {
-                       strcpy (min, "U");
+                       sstrncpy (min, "U", sizeof (min));
                }
                else
                {
@@ -295,7 +295,7 @@ static int ds_get (char ***ret, const data_set_t *ds, const value_list_t *vl)
 
                if (isnan (d->max))
                {
-                       strcpy (max, "U");
+                       sstrncpy (max, "U", sizeof (max));
                }
                else
                {
@@ -342,7 +342,7 @@ static int srrd_create (char *filename, unsigned long pdp_step, time_t last_up,
        optind = 0; /* bug in librrd? */
        rrd_clear_error ();
 
-       status = rrd_create_r (filename, pdp_step, last_up, argc, argv);
+       status = rrd_create_r (filename, pdp_step, last_up, argc, (void *) argv);
 
        if (status != 0)
        {
@@ -360,7 +360,7 @@ static int srrd_update (char *filename, char *template, int argc, char **argv)
        optind = 0; /* bug in librrd? */
        rrd_clear_error ();
 
-       status = rrd_update_r (filename, template, argc, argv);
+       status = rrd_update_r (filename, template, argc, (void *) argv);
 
        if (status != 0)
        {
@@ -949,10 +949,13 @@ static int rrd_write (const data_set_t *ds, const value_list_t *vl)
 
 static int rrd_flush (const int timeout)
 {
-       if (cache == NULL)
+       pthread_mutex_lock (&cache_lock);
+
+       if (cache == NULL) {
+               pthread_mutex_unlock (&cache_lock);
                return (0);
+       }
 
-       pthread_mutex_lock (&cache_lock);
        rrd_cache_flush (timeout);
        pthread_mutex_unlock (&cache_lock);
        return (0);
@@ -967,6 +970,8 @@ static int rrd_config (const char *key, const char *value)
                {
                        fprintf (stderr, "rrdtool: `CacheTimeout' must "
                                        "be greater than 0.\n");
+                       ERROR ("rrdtool: `CacheTimeout' must "
+                                       "be greater than 0.\n");
                        return (1);
                }
                cache_timeout = tmp;
@@ -978,6 +983,8 @@ static int rrd_config (const char *key, const char *value)
                {
                        fprintf (stderr, "rrdtool: `CacheFlush' must "
                                        "be greater than 0.\n");
+                       ERROR ("rrdtool: `CacheFlush' must "
+                                       "be greater than 0.\n");
                        return (1);
                }
                cache_flush_timeout = tmp;
@@ -1021,6 +1028,8 @@ static int rrd_config (const char *key, const char *value)
                {
                        fprintf (stderr, "rrdtool: `RRARows' must "
                                        "be greater than 0.\n");
+                       ERROR ("rrdtool: `RRARows' must "
+                                       "be greater than 0.\n");
                        return (1);
                }
                rrarows = tmp;
@@ -1047,6 +1056,7 @@ static int rrd_config (const char *key, const char *value)
                        if (tmp_alloc == NULL)
                        {
                                fprintf (stderr, "rrdtool: realloc failed.\n");
+                               ERROR ("rrdtool: realloc failed.\n");
                                free (value_copy);
                                return (1);
                        }
@@ -1070,6 +1080,8 @@ static int rrd_config (const char *key, const char *value)
                {
                        fprintf (stderr, "rrdtool: `XFF' must "
                                        "be in the range 0 to 1 (exclusive).");
+                       ERROR ("rrdtool: `XFF' must "
+                                       "be in the range 0 to 1 (exclusive).");
                        return (1);
                }
                xff = tmp;