From: Pavel Rochnyack Date: Sun, 17 Jun 2018 06:30:24 +0000 (+0700) Subject: rrdtool plugin: Added more error reporting X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=cb8dfc382cc99823e58ca01ee55ea9e5f23bfc42;p=collectd.git rrdtool plugin: Added more error reporting Issue: #2823 --- diff --git a/src/daemon/common.c b/src/daemon/common.c index 582d6b23..2251d2e0 100644 --- a/src/daemon/common.c +++ b/src/daemon/common.c @@ -544,9 +544,8 @@ int timeval_cmp(struct timeval tv0, struct timeval tv1, struct timeval *delta) { int check_create_dir(const char *file_orig) { struct stat statbuf; - char file_copy[512]; - char dir[512]; - int dir_len = 512; + char file_copy[PATH_MAX]; + char dir[PATH_MAX]; char *fields[16]; int fields_num; char *ptr; @@ -563,8 +562,10 @@ int check_create_dir(const char *file_orig) { if ((len = strlen(file_orig)) < 1) return -1; - else if (len >= sizeof(file_copy)) + else if (len >= sizeof(file_copy)) { + ERROR("check_create_dir: name (%s) is too long.", file_orig); return -1; + } /* * If `file_orig' ends in a slash the last component is a directory, @@ -615,8 +616,9 @@ int check_create_dir(const char *file_orig) { * Join the components together again */ dir[0] = '/'; - if (strjoin(dir + path_is_absolute, (size_t)(dir_len - path_is_absolute), - fields, (size_t)(i + 1), "/") < 0) { + if (strjoin(dir + path_is_absolute, + (size_t)(sizeof(dir) - path_is_absolute), fields, + (size_t)(i + 1), "/") < 0) { ERROR("strjoin failed: `%s', component #%i", file_orig, i); return -1; } diff --git a/src/rrdtool.c b/src/rrdtool.c index 5c87a434..f6290d73 100644 --- a/src/rrdtool.c +++ b/src/rrdtool.c @@ -624,6 +624,7 @@ static int rrd_cache_insert(const char *filename, const char *value, if ((status != 0) || (rc == NULL)) { rc = malloc(sizeof(*rc)); if (rc == NULL) { + ERROR("rrdtool plugin: malloc failed: %s", STRERRNO); pthread_mutex_unlock(&cache_lock); return -1; } @@ -790,17 +791,22 @@ static int rrd_write(const data_set_t *ds, const value_list_t *vl, } char filename[PATH_MAX]; - if (value_list_to_filename(filename, sizeof(filename), vl) != 0) + if (value_list_to_filename(filename, sizeof(filename), vl) != 0) { + ERROR("rrdtool plugin: failed to build filename"); return -1; + } char values[32 * (ds->ds_num + 1)]; - if (value_list_to_string(values, sizeof(values), ds, vl) != 0) + if (value_list_to_string(values, sizeof(values), ds, vl) != 0) { + ERROR("rrdtool plugin: failed to build values string"); return -1; + } struct stat statbuf = {0}; if (stat(filename, &statbuf) == -1) { if (errno == ENOENT) { if (cu_rrd_create_file(filename, ds, vl, &rrdcreate_config) != 0) { + ERROR("rrdtool plugin: cu_rrd_create_file (%s) failed.", filename); return -1; } else if (rrdcreate_config.async) { return 0;