X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fdaemon%2Fconfigfile.c;h=89b0be0b1cc780dc7e185bb232f7123b33344e31;hb=28fa063b625c772f45c99b618f498715fb98474b;hp=765a23c4d19acaf6b695f23fc909d972f56ec417;hpb=b2e0cf2ea4b094a96e8096c31897bdd98e798282;p=collectd.git diff --git a/src/daemon/configfile.c b/src/daemon/configfile.c index 765a23c4..89b0be0b 100644 --- a/src/daemon/configfile.c +++ b/src/daemon/configfile.c @@ -156,9 +156,12 @@ static int cf_dispatch (const char *type, const char *orig_key, int ret; int i; + if (orig_key == NULL) + return (EINVAL); + DEBUG ("type = %s, key = %s, value = %s", ESCAPE_NULL(type), - ESCAPE_NULL(orig_key), + orig_key, ESCAPE_NULL(orig_value)); if ((cf_cb = cf_search (type)) == NULL) @@ -199,8 +202,6 @@ static int cf_dispatch (const char *type, const char *orig_key, free (key); free (value); - DEBUG ("cf_dispatch: return (%i)", ret); - return (ret); } /* int cf_dispatch */ @@ -289,20 +290,25 @@ static int dispatch_loadplugin (oconfig_item_t *ci) /* default to the global interval set before loading this plugin */ memset (&ctx, 0, sizeof (ctx)); ctx.interval = cf_get_default_interval (); + ctx.flush_interval = 0; + ctx.flush_timeout = 0; - for (i = 0; i < ci->children_num; ++i) { - if (strcasecmp("Globals", ci->children[i].key) == 0) - cf_util_get_flag (ci->children + i, &flags, PLUGIN_FLAGS_GLOBAL); - else if (strcasecmp ("Interval", ci->children[i].key) == 0) { - if (cf_util_get_cdtime (ci->children + i, &ctx.interval) != 0) { - /* cf_util_get_cdtime will log an error */ - continue; - } - } + for (i = 0; i < ci->children_num; ++i) + { + oconfig_item_t *child = ci->children + i; + + if (strcasecmp("Globals", child->key) == 0) + cf_util_get_flag (child, &flags, PLUGIN_FLAGS_GLOBAL); + else if (strcasecmp ("Interval", child->key) == 0) + cf_util_get_cdtime (child, &ctx.interval); + else if (strcasecmp ("FlushInterval", child->key) == 0) + cf_util_get_cdtime (child, &ctx.flush_interval); + else if (strcasecmp ("FlushTimeout", child->key) == 0) + cf_util_get_cdtime (child, &ctx.flush_timeout); else { WARNING("Ignoring unknown LoadPlugin option \"%s\" " "for plugin \"%s\"", - ci->children[i].key, ci->values[0].value.string); + child->key, ci->values[0].value.string); } } @@ -622,8 +628,11 @@ static int cf_include_all (oconfig_item_t *root, int depth) return (-1); /* Now replace the i'th child in `root' with `new'. */ - if (cf_ci_replace_child (root, new, i) < 0) + if (cf_ci_replace_child (root, new, i) < 0) { + sfree (new->values); + sfree (new); return (-1); + } /* ... and go back to the new i'th child. */ --i; @@ -712,6 +721,7 @@ static oconfig_item_t *cf_read_dir (const char *dir, if (root == NULL) { ERROR ("configfile: malloc failed."); + closedir (dh); return (NULL); } memset (root, 0, sizeof (oconfig_item_t)); @@ -731,6 +741,7 @@ static oconfig_item_t *cf_read_dir (const char *dir, ERROR ("configfile: Not including `%s/%s' because its" " name is too long.", dir, de->d_name); + closedir (dh); for (i = 0; i < filenames_num; ++i) free (filenames[i]); free (filenames); @@ -743,6 +754,7 @@ static oconfig_item_t *cf_read_dir (const char *dir, filenames_num * sizeof (*filenames)); if (tmp == NULL) { ERROR ("configfile: realloc failed."); + closedir (dh); for (i = 0; i < filenames_num - 1; ++i) free (filenames[i]); free (filenames); @@ -754,6 +766,12 @@ static oconfig_item_t *cf_read_dir (const char *dir, filenames[filenames_num - 1] = sstrdup (name); } + if (filenames == NULL) + { + closedir (dh); + return (root); + } + qsort ((void *) filenames, filenames_num, sizeof (*filenames), cf_compare_string); @@ -777,11 +795,12 @@ static oconfig_item_t *cf_read_dir (const char *dir, free (name); } + closedir (dh); free(filenames); return (root); } /* oconfig_item_t *cf_read_dir */ -/* +/* * cf_read_generic * * Path is stat'ed and either cf_read_file or cf_read_dir is called