X-Git-Url: https://git.octo.it/?p=collectd.git;a=blobdiff_plain;f=src%2Fprocesses.c;h=8f4eb88fc168f3c1b36835c5ed294c95dd31ed08;hp=0c24cb70bb5a83f72543c949a0f37e021cf5280c;hb=61fba41289decabc1a18c855fcd462fece9ab983;hpb=a709b786e18b745526873780c0eabfed10a31d2a diff --git a/src/processes.c b/src/processes.c index 0c24cb70..8f4eb88f 100644 --- a/src/processes.c +++ b/src/processes.c @@ -121,13 +121,6 @@ # define ARG_MAX 4096 #endif -static const char *config_keys[] = -{ - "Process", - "ProcessMatch" -}; -static int config_keys_num = STATIC_ARRAY_SIZE (config_keys); - typedef struct procstat_entry_s { unsigned long id; @@ -520,42 +513,61 @@ static void ps_list_reset (void) } /* put all pre-defined 'Process' names from config to list_head_g tree */ -static int ps_config (const char *key, const char *value) +static int ps_config (oconfig_item_t *ci) { - if (strcasecmp (key, "Process") == 0) - { - ps_list_register (value, NULL); - } - else if (strcasecmp (key, "ProcessMatch") == 0) - { - char *new_val; - char *fields[3]; - int fields_num; - - new_val = strdup (value); - if (new_val == NULL) { - ERROR ("processes plugin: strdup failed when processing " - "`ProcessMatch %s'.", value); - return (1); + int i; + + for (i = 0; i < ci->children_num; ++i) { + oconfig_item_t *c = ci->children + i; + + if (strcasecmp (c->key, "Process") == 0) + { + if ((c->values_num != 1) + || (OCONFIG_TYPE_STRING != c->values[0].type)) { + ERROR ("processes plugin: `Process' expects exactly " + "one string argument (got %i).", + c->values_num); + continue; + } + + if (c->children_num != 0) { + WARNING ("processes plugin: the `Process' config option " + "does not expect any child elements -- ignoring " + "content (%i elements) of the block.", + c->children_num, c->values[0].value.string); + } + + ps_list_register (c->values[0].value.string, NULL); } + else if (strcasecmp (c->key, "ProcessMatch") == 0) + { + if ((c->values_num != 2) + || (OCONFIG_TYPE_STRING != c->values[0].type) + || (OCONFIG_TYPE_STRING != c->values[1].type)) + { + ERROR ("processes plugin: `ProcessMatch' needs exactly " + "two string arguments (got %i).", + c->values_num); + continue; + } - fields_num = strsplit (new_val, fields, - STATIC_ARRAY_SIZE (fields)); - if (fields_num != 2) + if (c->children_num != 0) { + WARNING ("processes plugin: the `ProcessMatch' config option " + "does not expect any child elements -- ignoring " + "content (%i elements) of the " + "block.", c->children_num, c->values[0].value.string, + c->values[1].value.string); + } + + ps_list_register (c->values[0].value.string, + c->values[1].value.string); + } + else { - ERROR ("processes plugin: `ProcessMatch' needs exactly " - "two string arguments."); - sfree (new_val); - return (1); + ERROR ("processes plugin: The `%s' configuration option is not " + "understood and will be ignored.", c->key); + continue; } - ps_list_register (fields[0], fields[1]); - sfree (new_val); - } - else - { - ERROR ("processes plugin: The `%s' configuration option is not " - "understood and will be ignored.", key); - return (-1); } return (0); @@ -1827,8 +1839,7 @@ static int ps_read (void) void module_register (void) { - plugin_register_config ("processes", ps_config, - config_keys, config_keys_num); + plugin_register_complex_config ("processes", ps_config); plugin_register_init ("processes", ps_init); plugin_register_read ("processes", ps_read); } /* void module_register */