From: Sebastian Harl Date: Wed, 28 Nov 2012 08:32:43 +0000 (+0100) Subject: config: Implemented include filter pattern as sub-option in a block. X-Git-Tag: collectd-5.3.0~68^2~1 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=67aba0fb1e3a301d61b6c410be6a03d83243dc39;p=collectd.git config: Implemented include filter pattern as sub-option in a block. This has the advantage of being more easy to read/understand and also being more flexible. E.g. multiple filters and other options may be specified in the future. Thanks to octo for suggesting this! --- diff --git a/src/configfile.c b/src/configfile.c index 1a9e28a6..d6aa72de 100644 --- a/src/configfile.c +++ b/src/configfile.c @@ -555,27 +555,34 @@ static int cf_include_all (oconfig_item_t *root, int depth) oconfig_item_t *new; oconfig_item_t *old; - /* Ignore all blocks, including `Include' blocks. */ - if (root->children[i].children_num != 0) - continue; + char *pattern = NULL; + + int j; if (strcasecmp (root->children[i].key, "Include") != 0) continue; old = root->children + i; - if ((old->values_num < 1) || (old->values_num > 2) - || (old->values[0].type != OCONFIG_TYPE_STRING) - || ((old->values_num == 2) - && (old->values[1].type != OCONFIG_TYPE_STRING))) + if ((old->values_num != 1) + || (old->values[0].type != OCONFIG_TYPE_STRING)) { - ERROR ("configfile: `Include' needs exactly one or two string argument."); + ERROR ("configfile: `Include' needs exactly one string argument."); continue; } - new = cf_read_generic (old->values[0].value.string, - (old->values_num == 2) ? old->values[1].value.string : NULL, - depth + 1); + for (j = 0; j < old->children_num; ++j) + { + oconfig_item_t *child = old->children + j; + + if (strcasecmp (child->key, "Filter") == 0) + cf_util_get_string (child, &pattern); + else + ERROR ("configfile: Option `%s' not allowed in block.", + child->key); + } + + new = cf_read_generic (old->values[0].value.string, pattern, depth + 1); if (new == NULL) continue; @@ -605,6 +612,9 @@ static oconfig_item_t *cf_read_file (const char *file, char *filename = basename (tmp); if ((filename != NULL) && (fnmatch (pattern, filename, 0) != 0)) { + DEBUG ("configfile: Not including `%s' because it " + "does not match pattern `%s'.", + filename, pattern); free (tmp); return (NULL); }