Blame SOURCES/0049-koops-add-an-option-controlling-MCE-detection.patch

44797e
From 0ec7f45a005a5faeb3d013710572d7b09fada376 Mon Sep 17 00:00:00 2001
44797e
From: Jakub Filak <jfilak@redhat.com>
44797e
Date: Fri, 21 Mar 2014 15:36:58 +0100
44797e
Subject: [ABRT PATCH 49/66] koops: add an option controlling MCE detection
44797e
44797e
It is necessary to be able to turn off the detection of Non-fatal MCEs
44797e
on a certain machine.
44797e
44797e
Related to #807
44797e
Resolves: rhbz#1076820
44797e
44797e
Signed-off-by: Jakub Filak <jfilak@redhat.com>
44797e
44797e
Conflicts:
44797e
	src/hooks/Makefile.am
44797e
---
44797e
 doc/abrt-dump-oops.txt                             |  5 ++++
44797e
 doc/dbus-configuration/Makefile.am                 |  1 +
44797e
 .../com.redhat.problems.configuration.oops.xml.in  | 11 ++++++++
44797e
 src/hooks/Makefile.am                              |  3 ++-
44797e
 src/hooks/oops.conf                                |  7 ++++++
44797e
 src/include/libabrt.h                              | 10 ++++++++
44797e
 src/lib/kernel.c                                   | 29 +++++++++++++++++++++-
44797e
 src/plugins/abrt-dump-oops.c                       | 25 ++++++++++++++++++-
44797e
 8 files changed, 88 insertions(+), 3 deletions(-)
44797e
 create mode 100644 doc/dbus-configuration/com.redhat.problems.configuration.oops.xml.in
44797e
 create mode 100644 src/hooks/oops.conf
44797e
44797e
diff --git a/doc/abrt-dump-oops.txt b/doc/abrt-dump-oops.txt
44797e
index cdb985c..5aa6bca 100644
44797e
--- a/doc/abrt-dump-oops.txt
44797e
+++ b/doc/abrt-dump-oops.txt
44797e
@@ -14,6 +14,11 @@ DESCRIPTION
44797e
 This tool creates problem directory from, updates problem directory with or
44797e
 prints oops extracted from FILE or standard input.
44797e
 
44797e
+FILES
44797e
+-----
44797e
+/etc/abrt/plugins/oops.conf::
44797e
+   Configuration file where user can disable detection of non-fatal MCEs
44797e
+
44797e
 OPTIONS
44797e
 -------
44797e
 -v, --verbose::
44797e
diff --git a/doc/dbus-configuration/Makefile.am b/doc/dbus-configuration/Makefile.am
44797e
index 2a3889d..15173de 100644
44797e
--- a/doc/dbus-configuration/Makefile.am
44797e
+++ b/doc/dbus-configuration/Makefile.am
44797e
@@ -8,6 +8,7 @@ dist_dbusabrtinterfaces_DATA = \
44797e
 	com.redhat.problems.configuration.xml \
44797e
 	com.redhat.problems.configuration.abrt.xml \
44797e
 	com.redhat.problems.configuration.ccpp.xml \
44797e
+	com.redhat.problems.configuration.oops.xml \
44797e
 	com.redhat.problems.configuration.python.xml \
44797e
 	com.redhat.problems.configuration.vmcore.xml \
44797e
 	com.redhat.problems.configuration.xorg.xml
44797e
diff --git a/doc/dbus-configuration/com.redhat.problems.configuration.oops.xml.in b/doc/dbus-configuration/com.redhat.problems.configuration.oops.xml.in
44797e
new file mode 100644
44797e
index 0000000..22bd166
44797e
--- /dev/null
44797e
+++ b/doc/dbus-configuration/com.redhat.problems.configuration.oops.xml.in
44797e
@@ -0,0 +1,11 @@
44797e
+
44797e
+ "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
44797e
+
44797e
+<node name="/com/redhat/problems/configuration/oops">
44797e
+    <annotation name="com.redhat.problems.ConfFile" value="/etc/abrt/plugins/oops.conf" />
44797e
+    <annotation name="com.redhat.problems.DefaultConfFile" value="/usr/share/abrt/conf.d/plugins/oops.conf" />
44797e
+
44797e
+    <interface name="com.redhat.problems.configuration.oops">
44797e
+        <property name="OnlyFatalMCE" type="b" access="readwrite" />
44797e
+    </interface>
44797e
+</node>
44797e
diff --git a/src/hooks/Makefile.am b/src/hooks/Makefile.am
44797e
index 1cce3d7..e536089 100644
44797e
--- a/src/hooks/Makefile.am
44797e
+++ b/src/hooks/Makefile.am
44797e
@@ -6,7 +6,8 @@ pluginsconfdir = $(PLUGINS_CONF_DIR)
44797e
 dist_pluginsconf_DATA = \
44797e
     CCpp.conf \
44797e
     python.conf \
44797e
-    vmcore.conf
44797e
+    vmcore.conf \
44797e
+    oops.conf
44797e
 
44797e
 defaultpluginsconfdir = $(DEFAULT_PLUGINS_CONF_DIR)
44797e
 dist_defaultpluginsconf_DATA = $(dist_pluginsconf_DATA)
44797e
diff --git a/src/hooks/oops.conf b/src/hooks/oops.conf
44797e
new file mode 100644
44797e
index 0000000..0e35a68
44797e
--- /dev/null
44797e
+++ b/src/hooks/oops.conf
44797e
@@ -0,0 +1,7 @@
44797e
+# Lot of Machine Check Exceptions are correctable and thus not interesting to
44797e
+# users. Moreover some hardware may produce plenty of MCEs by design.
44797e
+#
44797e
+# Setting the following option to 'yes' will configure ABRT to detect only
44797e
+# the fatal MCEs.
44797e
+#
44797e
+OnlyFatalMCE = no
44797e
diff --git a/src/include/libabrt.h b/src/include/libabrt.h
44797e
index 3e42a09..85a5a5c 100644
44797e
--- a/src/include/libabrt.h
44797e
+++ b/src/include/libabrt.h
44797e
@@ -9,6 +9,8 @@
44797e
 #ifndef LIBABRT_H_
44797e
 #define LIBABRT_H_
44797e
 
44797e
+#include <regex.h>
44797e
+
44797e
 #include <gio/gio.h> /* dbus */
44797e
 #include "abrt-dbus.h"
44797e
 /* libreport's internal functions we use: */
44797e
@@ -109,6 +111,14 @@ int koops_hash_str(char hash_str[SHA1_RESULT_LEN*2 + 1], const char *oops_buf);
44797e
 void koops_extract_oopses(GList **oops_list, char *buffer, size_t buflen);
44797e
 #define koops_print_suspicious_strings abrt_koops_print_suspicious_strings
44797e
 void koops_print_suspicious_strings(void);
44797e
+/**
44797e
+ * Prints all suspicious strings that do not match any of the regular
44797e
+ * expression in NULL terminated list.
44797e
+ *
44797e
+ * The regular expression should be compiled with REG_NOSUB flag.
44797e
+ */
44797e
+#define koops_print_suspicious_strings_filtered abrt_koops_print_suspicious_strings_filtered
44797e
+void koops_print_suspicious_strings_filtered(const regex_t **filterout);
44797e
 
44797e
 /* dbus client api */
44797e
 
44797e
diff --git a/src/lib/kernel.c b/src/lib/kernel.c
44797e
index ad20c65..799463d 100644
44797e
--- a/src/lib/kernel.c
44797e
+++ b/src/lib/kernel.c
44797e
@@ -158,8 +158,35 @@ static const char *const s_koops_suspicious_strings[] = {
44797e
 
44797e
 void koops_print_suspicious_strings(void)
44797e
 {
44797e
+    koops_print_suspicious_strings_filtered(NULL);
44797e
+}
44797e
+
44797e
+static bool match_any(const regex_t **res, const char *str)
44797e
+{
44797e
+    for (const regex_t **r = res; *r != NULL; ++r)
44797e
+    {
44797e
+        /* Regular expressions compiled with REG_NOSUB */
44797e
+        const int reti = regexec(*r, str, 0, NULL, 0);
44797e
+        if (reti == 0)
44797e
+            return true;
44797e
+        else if (reti != REG_NOMATCH)
44797e
+        {
44797e
+            char msgbuf[100];
44797e
+            regerror(reti, *r, msgbuf, sizeof(msgbuf));
44797e
+            error_msg_and_die("Regex match failed: %s", msgbuf);
44797e
+        }
44797e
+    }
44797e
+
44797e
+    return false;
44797e
+}
44797e
+
44797e
+void koops_print_suspicious_strings_filtered(const regex_t **filterout)
44797e
+{
44797e
     for (const char *const *str = s_koops_suspicious_strings; *str; ++str)
44797e
-        puts(*str);
44797e
+    {
44797e
+        if (filterout == NULL || !match_any(filterout, *str))
44797e
+            puts(*str);
44797e
+    }
44797e
 }
44797e
 
44797e
 void koops_extract_oopses(GList **oops_list, char *buffer, size_t buflen)
44797e
diff --git a/src/plugins/abrt-dump-oops.c b/src/plugins/abrt-dump-oops.c
44797e
index 12291be..9f0dc87 100644
44797e
--- a/src/plugins/abrt-dump-oops.c
44797e
+++ b/src/plugins/abrt-dump-oops.c
44797e
@@ -295,7 +295,30 @@ int main(int argc, char **argv)
44797e
 
44797e
     if (opts & OPT_m)
44797e
     {
44797e
-        koops_print_suspicious_strings();
44797e
+        map_string_t *settings = new_map_string();
44797e
+
44797e
+        load_abrt_plugin_conf_file("oops.conf", settings);
44797e
+
44797e
+        int only_fatal_mce = 1;
44797e
+        try_get_map_string_item_as_bool(settings, "OnlyFatalMCE", &only_fatal_mce);
44797e
+
44797e
+        free_map_string(settings);
44797e
+
44797e
+        if (only_fatal_mce)
44797e
+        {
44797e
+            regex_t mce_re;
44797e
+            if (regcomp(&mce_re, "^Machine .*$", REG_NOSUB) != 0)
44797e
+                perror_msg_and_die(_("Failed to compile regex"));
44797e
+
44797e
+            const regex_t *filter[] = { &mce_re, NULL };
44797e
+
44797e
+            koops_print_suspicious_strings_filtered(filter);
44797e
+
44797e
+            regfree(&mce_re);
44797e
+        }
44797e
+        else
44797e
+            koops_print_suspicious_strings();
44797e
+
44797e
         return 1;
44797e
     }
44797e
 
44797e
-- 
44797e
1.8.3.1
44797e