summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDenys Vlasenko <dvlasenk@redhat.com>2011-05-23 17:07:06 +0200
committerDenys Vlasenko <dvlasenk@redhat.com>2011-05-23 17:07:06 +0200
commit28e6bba1e2a35f6bca8f27b5397e1c7fa2171fd4 (patch)
treec379fded6e7499800ff37dd5cd637792bef7750c /src
parent2d94511dd4eae5b19f73080a3bdc5a36605262bd (diff)
downloadabrt-28e6bba1e2a35f6bca8f27b5397e1c7fa2171fd4.tar.gz
abrt-28e6bba1e2a35f6bca8f27b5397e1c7fa2171fd4.tar.xz
abrt-28e6bba1e2a35f6bca8f27b5397e1c7fa2171fd4.zip
run_event: support VAR~=REGEX match
This makes in possible to configure analyze_xsession_errors to appear only for X-related stuff Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
Diffstat (limited to 'src')
-rw-r--r--src/daemon/abrt_event.conf6
-rw-r--r--src/daemon/abrt_event.conf.56
-rw-r--r--src/lib/run_event.c39
-rw-r--r--src/plugins/ccpp_events.conf2
4 files changed, 44 insertions, 9 deletions
diff --git a/src/daemon/abrt_event.conf b/src/daemon/abrt_event.conf
index 73bfd63a..c378031d 100644
--- a/src/daemon/abrt_event.conf
+++ b/src/daemon/abrt_event.conf
@@ -23,9 +23,9 @@
# Rules specify which programs to run on the dump directory.
# Each rule may have conditions to be checked before the program is run.
#
-# Conditions have form VAR=VAL, where VAR is either word "EVENT"
-# or a name of dump directory element to be checked (for example,
-# "executable", "package", hostname" etc).
+# Conditions have form VAR=VAL or VAL~=REGEX, where VAR is either
+# word "EVENT" or a name of dump directory element to be checked
+# (for example, "executable", "package", hostname" etc).
#
# If all conditions match, the remaining part of the rule
# (the "program" part) is run in the shell.
diff --git a/src/daemon/abrt_event.conf.5 b/src/daemon/abrt_event.conf.5
index 9ba3e480..0ef4c4c7 100644
--- a/src/daemon/abrt_event.conf.5
+++ b/src/daemon/abrt_event.conf.5
@@ -29,9 +29,9 @@ even a multi-line rule (no need to comment out every line).
Rules specify which programs to run on the dump directory.
Each rule may have conditions to be checked before the program is run.
.P
-Conditions have form VAR=VAL, where VAR is either word "EVENT"
-or a name of dump directory element to be checked (for example,
-"executable", "package", hostname" etc).
+Conditions have form VAR=VAL or VAL~=REGEX, where VAR is either
+word "EVENT" or a name of dump directory element to be checked
+(for example, "executable", "package", hostname" etc).
.P
If all conditions match, the remaining part of the rule
(the "program" part) is run in the shell.
diff --git a/src/lib/run_event.c b/src/lib/run_event.c
index 8325ea28..856f3264 100644
--- a/src/lib/run_event.c
+++ b/src/lib/run_event.c
@@ -17,6 +17,7 @@
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <glob.h>
+#include <regex.h>
#include "abrtlib.h"
struct run_event_state *new_run_event_state()
@@ -209,6 +210,38 @@ static GList *load_rule_list(GList *rule_list,
return rule_list;
}
+static int regcmp_lines(char *val, const char *regex)
+{
+ regex_t rx;
+ int r = regcomp(&rx, regex, REG_NOSUB); //TODO: and REG_EXTENDED?
+ //log("REGEX:'%s':%d", regex, r);
+ if (r)
+ {
+ //char errbuf[256];
+ //size_t needsz = regerror(r, &rx, errbuf, sizeof(errbuf));
+ error_msg("Bad regexp '%s'", regex); // TODO: use errbuf?
+ return r;
+ }
+
+ /* Check every line */
+ while (1)
+ {
+ char *eol = strchr(val, '\n');
+ if (eol)
+ *eol = '\0';
+ r = regexec(&rx, val, 0, NULL, /*eflags:*/ 0);
+ //log("REGCMP:'%s':%d", val, r);
+ if (eol)
+ *eol = '\n';
+ if (r == 0 || !eol)
+ break;
+ val = eol + 1;
+ }
+ /* Here, r == 0 if match was found */
+ regfree(&rx);
+ return r;
+}
+
/* Deletes rules in *pp_rule_list, starting from first (remaining) rule,
* until it finds a rule with all conditions satisfied.
* In this case, it deletes this rule and returns this rule's cmd.
@@ -269,10 +302,12 @@ static char* pop_next_command(GList **pp_rule_list,
goto ret; /* error (note: dd_opendir logged error msg) */
}
}
- char *var_name = xstrndup(cond_str, eq_sign - cond_str);
+ /* Is it "VAR~=REGEX"? */
+ int regex = (eq_sign > cond_str && eq_sign[-1] == '~');
+ char *var_name = xstrndup(cond_str, eq_sign - cond_str - regex);
char *real_val = dd_load_text_ext(dd, var_name, DD_FAIL_QUIETLY_ENOENT);
free(var_name);
- int vals_differ = strcmp(real_val, eq_sign + 1);
+ int vals_differ = regex ? regcmp_lines(real_val, eq_sign + 1) : strcmp(real_val, eq_sign + 1);
free(real_val);
/* Do values match? */
diff --git a/src/plugins/ccpp_events.conf b/src/plugins/ccpp_events.conf
index 5daf71a1..19da043f 100644
--- a/src/plugins/ccpp_events.conf
+++ b/src/plugins/ccpp_events.conf
@@ -13,7 +13,7 @@ EVENT=post-create analyzer=CCpp
echo "Element 'var_log_messages' saved"
)
-EVENT=analyze_xsession_errors analyzer=CCpp
+EVENT=analyze_xsession_errors analyzer=CCpp dso_list~=.*/libX11.*
test -f ~/.xsession-errors || { echo "No ~/.xsession-errors"; exit 1; }
test -r ~/.xsession-errors || { echo "Can't read ~/.xsession-errors"; exit 1; }
executable=`cat executable` &&