X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fdaemon%2Fconfigfile.c;h=16e07247b3cf56d07937d677c1eddf861c5c2655;hb=9b7dee8838f56233cea2854a7ddbcad2790609ce;hp=2636a522bd45e5d50b3edb3ccd4ac8aab3264911;hpb=cedb6f147e94d0e952449f731313412ef4d67904;p=collectd.git diff --git a/src/daemon/configfile.c b/src/daemon/configfile.c index 2636a522..16e07247 100644 --- a/src/daemon/configfile.c +++ b/src/daemon/configfile.c @@ -73,7 +73,7 @@ typedef struct cf_complex_callback_s typedef struct cf_value_map_s { char *key; - int (*func) (const oconfig_item_t *); + int (*func) (oconfig_item_t *); } cf_value_map_t; typedef struct cf_global_option_s @@ -86,9 +86,10 @@ typedef struct cf_global_option_s /* * Prototypes of callback functions */ -static int dispatch_value_typesdb (const oconfig_item_t *ci); -static int dispatch_value_plugindir (const oconfig_item_t *ci); -static int dispatch_loadplugin (const oconfig_item_t *ci); +static int dispatch_value_typesdb (oconfig_item_t *ci); +static int dispatch_value_plugindir (oconfig_item_t *ci); +static int dispatch_loadplugin (oconfig_item_t *ci); +static int dispatch_block_plugin (oconfig_item_t *ci); /* * Private variables @@ -100,7 +101,8 @@ static cf_value_map_t cf_value_map[] = { {"TypesDB", dispatch_value_typesdb}, {"PluginDir", dispatch_value_plugindir}, - {"LoadPlugin", dispatch_loadplugin} + {"LoadPlugin", dispatch_loadplugin}, + {"Plugin", dispatch_block_plugin} }; static int cf_value_map_num = STATIC_ARRAY_SIZE (cf_value_map); @@ -154,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) @@ -197,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 */ @@ -225,7 +228,7 @@ static int dispatch_global_option (const oconfig_item_t *ci) return (-1); } /* int dispatch_global_option */ -static int dispatch_value_typesdb (const oconfig_item_t *ci) +static int dispatch_value_typesdb (oconfig_item_t *ci) { int i = 0; @@ -251,7 +254,7 @@ static int dispatch_value_typesdb (const oconfig_item_t *ci) return (0); } /* int dispatch_value_typesdb */ -static int dispatch_value_plugindir (const oconfig_item_t *ci) +static int dispatch_value_plugindir (oconfig_item_t *ci) { assert (strcasecmp (ci->key, "PluginDir") == 0); @@ -264,7 +267,7 @@ static int dispatch_value_plugindir (const oconfig_item_t *ci) return (0); } -static int dispatch_loadplugin (const oconfig_item_t *ci) +static int dispatch_loadplugin (oconfig_item_t *ci) { int i; const char *name; @@ -348,7 +351,7 @@ static int dispatch_value_plugin (const char *plugin, oconfig_item_t *ci) return (cf_dispatch (plugin, ci->key, buffer_ptr)); } /* int dispatch_value_plugin */ -static int dispatch_value (const oconfig_item_t *ci) +static int dispatch_value (oconfig_item_t *ci) { int ret = -2; int i; @@ -620,8 +623,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; @@ -710,6 +716,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)); @@ -729,6 +736,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); @@ -741,6 +749,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); @@ -752,6 +761,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); @@ -775,11 +790,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