# 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;
}
/* 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 <Process '%s'> 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 <ProcessMatch '%s' '%s'> "
+ "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);
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 */