From: Florian Forster Date: Tue, 27 May 2008 15:27:15 +0000 (+0200) Subject: processes plugin: ps_list_match: If a regex is configures, only use that regex. X-Git-Tag: collectd-4.5.0~136 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=5f6cbebb5f47e7605777baed71cede3207666437;p=collectd.git processes plugin: ps_list_match: If a regex is configures, only use that regex. --- diff --git a/src/processes.c b/src/processes.c index 79451d32..14fe1d8c 100644 --- a/src/processes.c +++ b/src/processes.c @@ -247,13 +247,32 @@ static void ps_list_register (const char *name, const char *regexp) /* try to match name against entry, returns 1 if success */ static int ps_list_match (const char *name, const char *cmdline, procstat_t *ps) { - if ((ps->re != NULL) && (regexec(ps->re, (strlen(cmdline)!=0)?cmdline:name, 0, NULL, 0) == 0)) - return (1); - if (strcmp (ps->name, name) == 0) { - return (1); +#if HAVE_REGEX_H + if (ps->re != NULL) + { + int status; + const char *str; + + str = cmdline; + if ((str == NULL) || (str[0] == 0)) + str = name; + + assert (str != NULL); + + status = regexec (ps->re, str, + /* nmatch = */ 0, + /* pmatch = */ NULL, + /* eflags = */ 0); + if (status == 0) + return (1); } + else +#endif + if (strcmp (ps->name, name) == 0) + return (1); + return (0); -} +} /* int ps_list_match */ /* add process entry to 'instances' of process 'name' (or refresh it) */ static void ps_list_add (const char *name, const char *cmdline, procstat_entry_t *entry)