X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Frrdtool.c;h=1f354218624518f1af702171d672c6d1be351b72;hb=8e5e2e927f9cf051ef210473b1b48ff62d81f585;hp=5f42561aa39842ab999c920d1a06c3fab9087fbd;hpb=0eff2a882a9265fd59d4f7a265c6b6810acb0032;p=collectd.git diff --git a/src/rrdtool.c b/src/rrdtool.c index 5f42561a..1f354218 100644 --- a/src/rrdtool.c +++ b/src/rrdtool.c @@ -520,10 +520,7 @@ static void rrd_cache_flush(cdtime_t timeout) { { char **tmp = realloc(keys, (keys_num + 1) * sizeof(char *)); if (tmp == NULL) { - char errbuf[1024]; - ERROR("rrdtool plugin: " - "realloc failed: %s", - sstrerror(errno, errbuf, sizeof(errbuf))); + ERROR("rrdtool plugin: realloc failed: %s", STRERRNO); c_avl_iterator_destroy(iter); sfree(keys); return; @@ -623,9 +620,8 @@ static int rrd_cache_insert(const char *filename, const char *value, return -1; } - c_avl_get(cache, filename, (void *)&rc); - - if (rc == NULL) { + int status = c_avl_get(cache, filename, (void *)&rc); + if ((status != 0) || (rc == NULL)) { rc = malloc(sizeof(*rc)); if (rc == NULL) { pthread_mutex_unlock(&cache_lock); @@ -652,15 +648,12 @@ static int rrd_cache_insert(const char *filename, const char *value, values_new = realloc((void *)rc->values, (rc->values_num + 1) * sizeof(char *)); if (values_new == NULL) { - char errbuf[1024]; void *cache_key = NULL; - sstrerror(errno, errbuf, sizeof(errbuf)); - c_avl_remove(cache, filename, &cache_key, NULL); pthread_mutex_unlock(&cache_lock); - ERROR("rrdtool plugin: realloc failed: %s", errbuf); + ERROR("rrdtool plugin: realloc failed: %s", STRERRNO); sfree(cache_key); sfree(rc->values); @@ -682,12 +675,9 @@ static int rrd_cache_insert(const char *filename, const char *value, void *cache_key = strdup(filename); if (cache_key == NULL) { - char errbuf[1024]; - sstrerror(errno, errbuf, sizeof(errbuf)); - pthread_mutex_unlock(&cache_lock); - ERROR("rrdtool plugin: strdup failed: %s", errbuf); + ERROR("rrdtool plugin: strdup failed: %s", STRERRNO); sfree(rc->values[0]); sfree(rc->values); @@ -803,7 +793,7 @@ static int rrd_write(const data_set_t *ds, const value_list_t *vl, if (value_list_to_filename(filename, sizeof(filename), vl) != 0) return -1; - char values[32 * ds->ds_num]; + char values[32 * (ds->ds_num + 1)]; if (value_list_to_string(values, sizeof(values), ds, vl) != 0) return -1; @@ -816,9 +806,7 @@ static int rrd_write(const data_set_t *ds, const value_list_t *vl, return 0; } } else { - char errbuf[1024]; - ERROR("rrdtool plugin: stat(%s) failed: %s", filename, - sstrerror(errno, errbuf, sizeof(errbuf))); + ERROR("rrdtool plugin: stat(%s) failed: %s", filename, STRERRNO); return -1; } } else if (!S_ISREG(statbuf.st_mode)) { @@ -1047,8 +1035,7 @@ static int rrd_init(void) { cache_flush_timeout = 0; } else if (cache_flush_timeout < cache_timeout) { INFO("rrdtool plugin: \"CacheFlush %.3f\" is less than \"CacheTimeout " - "%.3f\". " - "Ajusting \"CacheFlush\" to %.3f seconds.", + "%.3f\". Adjusting \"CacheFlush\" to %.3f seconds.", CDTIME_T_TO_DOUBLE(cache_flush_timeout), CDTIME_T_TO_DOUBLE(cache_timeout), CDTIME_T_TO_DOUBLE(cache_timeout * 10));