From: Florian Forster Date: Thu, 30 May 2013 06:58:06 +0000 (+0200) Subject: src/configfile.c: Let errors in included files propagate up to cf_read(). X-Git-Tag: collectd-5.3.1~4^2 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=178db08806318e0b01de2e7a9261f18d6f7ca72d;p=collectd.git src/configfile.c: Let errors in included files propagate up to cf_read(). cf_read_generic() returned NULL in two cases: Unable to read file and file was empty. Since we wanted to allow empty includes, the "include file with errors" case was not handled properly. Github: #323 --- diff --git a/src/configfile.c b/src/configfile.c index 5920c531..be777c52 100644 --- a/src/configfile.c +++ b/src/configfile.c @@ -564,7 +564,7 @@ static int cf_include_all (oconfig_item_t *root, int depth) new = cf_read_generic (old->values[0].value.string, depth + 1); if (new == NULL) - continue; + return (-1); /* Now replace the i'th child in `root' with `new'. */ cf_ci_replace_child (root, new, i); @@ -582,6 +582,7 @@ static int cf_include_all (oconfig_item_t *root, int depth) static oconfig_item_t *cf_read_file (const char *file, int depth) { oconfig_item_t *root; + int status; assert (depth < CF_MAX_DEPTH); @@ -592,7 +593,12 @@ static oconfig_item_t *cf_read_file (const char *file, int depth) return (NULL); } - cf_include_all (root, depth); + status = cf_include_all (root, depth); + if (status != 0) + { + oconfig_free (root); + return (NULL); + } return (root); } /* oconfig_item_t *cf_read_file */ @@ -783,12 +789,6 @@ static oconfig_item_t *cf_read_generic (const char *path, int depth) wordfree (&we); - if (root->children == NULL) - { - oconfig_free (root); - return (NULL); - } - return (root); } /* oconfig_item_t *cf_read_generic */ /* #endif HAVE_WORDEXP_H */ @@ -999,6 +999,12 @@ int cf_read (char *filename) ERROR ("Unable to read config file %s.", filename); return (-1); } + else if (conf->children_num == 0) + { + ERROR ("Configuration file %s is empty.", filename); + oconfig_free (conf); + return (-1); + } for (i = 0; i < conf->children_num; i++) {