]> git.itanic.dy.fi Git - rrdd/commitdiff
rrdtool.c: Improve error handling during database creation
authorTimo Kokkonen <timo.t.kokkonen@iki.fi>
Wed, 20 Jun 2012 19:22:23 +0000 (22:22 +0300)
committerTimo Kokkonen <timo.t.kokkonen@iki.fi>
Wed, 20 Jun 2012 19:29:38 +0000 (22:29 +0300)
The case of filename pointer being NULL was not handled. The logic for
testing whether the database file existed at all should not return
true in case the file name is zero. As this function can't return
failure code, the error of NULL filename pointer is handled later when
the database is being created.

As many missing databases are created as possible. In case of errors
we will continue hoping that we will be able to update at least
something.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
rrdtool.c

index 4a8348b3ac5f347bd7161a542ad51f5ec79f6016..3a8d9ab0f0e4581825755a8cd53678d499f1f159 100644 (file)
--- a/rrdtool.c
+++ b/rrdtool.c
@@ -203,7 +203,7 @@ static int database_exists(struct rrd_database *db)
        if (db->filename)
                return !stat(db->filename, &s);
 
-       return 1;
+       return 0;
 }
 
 static int create_database(struct rrd_database *db)
@@ -214,6 +214,11 @@ static int create_database(struct rrd_database *db)
        int idx = 0, argcnt = 0;
        int child, i;
 
+       if (!db->filename) {
+               pr_err("Database %s missing database filename\n", db->name);
+               return -1;
+       }
+
        if (!db->sources || !db->archives) {
                pr_err("Cannot create db \"%s\", insufficient source data\n",
                        db->filename);
@@ -253,7 +258,7 @@ static int create_database(struct rrd_database *db)
 int rrdtool_create_missing_databases(struct rrd_database *dbs[])
 {
        struct rrd_database *db;
-       int i;
+       int i, ret = 0;
 
        for (i = 0, db = dbs[i]; db; i++, db = dbs[i]) {
                if (database_exists(db)) {
@@ -261,8 +266,8 @@ int rrdtool_create_missing_databases(struct rrd_database *dbs[])
                        continue;
                }
                pr_info("Database %s missing, creating\n", db->filename);
-               create_database(db);
+               ret |= create_database(db);
        }
 
-       return 0;
+       return ret;
 }