X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fconfigfile.c;h=df04289446ccfba23d598d14e80c29ce5a5fa882;hb=275bc6640dfc2ba747dd64884d9e91191f06fa82;hp=bb1770d2ab13e8c8a26c84901dd9e012dd0fc9a7;hpb=e8999694aac7184ac4eea29564a2892f188c4171;p=collectd.git diff --git a/src/configfile.c b/src/configfile.c index bb1770d2..df042894 100644 --- a/src/configfile.c +++ b/src/configfile.c @@ -172,7 +172,7 @@ static int cf_dispatch (const char *type, const char *orig_key, free (key); free (value); - DEBUG ("return (%i)", ret); + DEBUG ("cf_dispatch: return (%i)", ret); return (ret); } /* int cf_dispatch */ @@ -208,13 +208,18 @@ static int dispatch_value_typesdb (const oconfig_item_t *ci) cf_default_typesdb = 0; - if (ci->values_num < 1) + if (ci->values_num < 1) { + ERROR ("configfile: `TypesDB' needs at least one argument."); return (-1); + } for (i = 0; i < ci->values_num; ++i) { - if (OCONFIG_TYPE_STRING != ci->values[i].type) + if (OCONFIG_TYPE_STRING != ci->values[i].type) { + WARNING ("configfile: TypesDB: Skipping %i. argument which " + "is not a string.", i + 1); continue; + } read_types_list (ci->values[i].value.string); } @@ -331,7 +336,15 @@ static int dispatch_block_plugin (oconfig_item_t *ci) if (ci->children[i].children == NULL) dispatch_value_plugin (name, ci->children + i); else - {DEBUG ("No nested config blocks allowed for this plugin.");} + { + WARNING ("There is a `%s' block within the " + "configuration for the %s plugin. " + "The plugin either only expects " + "\"simple\" configuration statements " + "or wasn't loaded using `LoadPlugin'." + " Please check your configuration.", + ci->children[i].key, name); + } } return (0); @@ -373,12 +386,12 @@ static int cf_ci_replace_child (oconfig_item_t *dst, oconfig_item_t *src, temp = NULL; /* If (src->children_num == 0) the array size is decreased. If offset - * is _not_ the last element, (offset < (src->children_num - 1)), then + * is _not_ the last element, (offset < (dst->children_num - 1)), then * we need to move the trailing elements before resizing the array. */ - if ((src->children_num == 0) && (offset < (src->children_num - 1))) + if ((src->children_num == 0) && (offset < (dst->children_num - 1))) { - int nmemb = src->children_num - (offset + 1); - memmove (src->children + offset, src->children + offset + 1, + int nmemb = dst->children_num - (offset + 1); + memmove (dst->children + offset, dst->children + offset + 1, sizeof (oconfig_item_t) * nmemb); } @@ -410,7 +423,7 @@ static int cf_ci_replace_child (oconfig_item_t *dst, oconfig_item_t *src, sizeof (oconfig_item_t) * nmemb); } - /* Last but not least: If there are new childrem, copy them to the + /* Last but not least: If there are new children, copy them to the * memory reserved for them. */ if (src->children_num > 0) { @@ -486,6 +499,9 @@ static int cf_include_all (oconfig_item_t *root, int depth) /* Now replace the i'th child in `root' with `new'. */ cf_ci_replace_child (root, new, i); + /* ... and go back to the new i'th child. */ + --i; + sfree (new->values); sfree (new); } /* for (i = 0; i < root->children_num; i++) */ @@ -901,3 +917,28 @@ int cf_read (char *filename) return (0); } /* int cf_read */ + +/* Assures the config option is a string, duplicates it and returns the copy in + * "ret_string". If necessary "*ret_string" is freed first. Returns zero upon + * success. */ +int cf_util_get_string (const oconfig_item_t *ci, char **ret_string) /* {{{ */ +{ + char *string; + + if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) + { + ERROR ("cf_util_get_string: The %s plugin requires " + "exactly one string argument.", ci->key); + return (-1); + } + + string = strdup (ci->values[0].value.string); + if (string == NULL) + return (-1); + + if (*ret_string != NULL) + sfree (*ret_string); + *ret_string = string; + + return (0); +} /* }}} int cf_util_get_string */