Blame SOURCES/0020-move-MCE-handling-in-event-to-abrt-action-check-oops.patch

a60cd7
From d3ac6c888953d0bcd304d30dfa0f1c731987f358 Mon Sep 17 00:00:00 2001
a60cd7
From: Denys Vlasenko <dvlasenk@redhat.com>
a60cd7
Date: Mon, 6 Jan 2014 16:46:48 +0100
a60cd7
Subject: [ABRT PATCH 20/27] move MCE handling in event to
a60cd7
 abrt-action-check-oops-for-hw-error
a60cd7
a60cd7
Having a separate tool should help with internationalization
a60cd7
a60cd7
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
a60cd7
a60cd7
Related to rhbz#1032077
a60cd7
a60cd7
Signed-off-by: Jakub Filak <jfilak@redhat.com>
a60cd7
---
a60cd7
 configure.ac                                       |   1 +
a60cd7
 doc/Makefile.am                                    |   1 +
a60cd7
 po/POTFILES.in                                     |   1 +
a60cd7
 src/plugins/Makefile.am                            |   3 +
a60cd7
 src/plugins/abrt-action-check-oops-for-hw-error.in | 118 +++++++++++++++++++++
a60cd7
 src/plugins/koops_event.conf                       |  57 +---------
a60cd7
 8 files changed, 129 insertions(+), 55 deletions(-)
a60cd7
 create mode 100644 src/plugins/abrt-action-check-oops-for-hw-error.in
a60cd7
a60cd7
diff --git a/configure.ac b/configure.ac
a60cd7
index 3bd13bc..346faa8 100644
a60cd7
--- a/configure.ac
a60cd7
+++ b/configure.ac
a60cd7
@@ -279,6 +279,7 @@ AC_CONFIG_FILES([
a60cd7
 	src/dbus/Makefile
a60cd7
 	src/plugins/abrt-action-install-debuginfo
a60cd7
 	src/plugins/abrt-action-analyze-vmcore
a60cd7
+	src/plugins/abrt-action-check-oops-for-hw-error
a60cd7
 	src/python-problem/Makefile
a60cd7
 	src/python-problem/doc/Makefile
a60cd7
 	src/python-problem/tests/Makefile
a60cd7
diff --git a/doc/Makefile.am b/doc/Makefile.am
a60cd7
index f1abef8..e76abde 100644
a60cd7
--- a/doc/Makefile.am
a60cd7
+++ b/doc/Makefile.am
a60cd7
@@ -32,6 +32,7 @@ MAN1_TXT += abrt-action-save-package-data.txt
a60cd7
 MAN1_TXT += abrt-action-save-kernel-data.txt
a60cd7
 MAN1_TXT += abrt-install-ccpp-hook.txt
a60cd7
 MAN1_TXT += abrt-action-analyze-vmcore.txt
a60cd7
+MAN1_TXT += abrt-action-check-oops-for-hw-error.txt
a60cd7
 MAN1_TXT += abrt-action-analyze-ccpp-local.txt
a60cd7
 MAN1_TXT += abrt-watch-log.txt
a60cd7
 MAN1_TXT += abrt-upload-watch.txt
a60cd7
diff --git a/po/POTFILES.in b/po/POTFILES.in
a60cd7
index 5f883c0..6d90162 100644
a60cd7
--- a/po/POTFILES.in
a60cd7
+++ b/po/POTFILES.in
a60cd7
@@ -25,6 +25,7 @@ src/plugins/abrt-action-analyze-oops.c
a60cd7
 src/plugins/abrt-action-analyze-xorg.c
a60cd7
 src/plugins/abrt-action-analyze-python.c
a60cd7
 src/plugins/abrt-action-analyze-vmcore.in
a60cd7
+src/plugins/abrt-action-check-oops-for-hw-error.in
a60cd7
 src/plugins/abrt-action-generate-backtrace.c
a60cd7
 src/plugins/abrt-action-generate-core-backtrace.c
a60cd7
 src/plugins/abrt-action-install-debuginfo.in
a60cd7
diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am
a60cd7
index 60246f2..dd32c7d 100644
a60cd7
--- a/src/plugins/Makefile.am
a60cd7
+++ b/src/plugins/Makefile.am
a60cd7
@@ -5,6 +5,7 @@ bin_SCRIPTS = \
a60cd7
     abrt-action-analyze-core \
a60cd7
     abrt-action-analyze-vulnerability \
a60cd7
     abrt-action-analyze-vmcore \
a60cd7
+    abrt-action-check-oops-for-hw-error \
a60cd7
     abrt-action-list-dsos \
a60cd7
     abrt-action-perform-ccpp-analysis \
a60cd7
     abrt-action-save-kernel-data \
a60cd7
@@ -74,6 +75,7 @@ PYTHON_FILES = \
a60cd7
     abrt-action-analyze-core \
a60cd7
     abrt-action-analyze-vulnerability \
a60cd7
     abrt-action-analyze-vmcore.in \
a60cd7
+    abrt-action-check-oops-for-hw-error.in \
a60cd7
     abrt-action-perform-ccpp-analysis.in \
a60cd7
     abrt-action-notify
a60cd7
 
a60cd7
@@ -88,6 +90,7 @@ EXTRA_DIST = \
a60cd7
     analyze_RetraceServer.xml.in \
a60cd7
     analyze_VMcore.xml.in \
a60cd7
     abrt-action-analyze-vmcore \
a60cd7
+    abrt-action-check-oops-for-hw-error \
a60cd7
     abrt-action-save-kernel-data \
a60cd7
     abrt-action-ureport \
a60cd7
     abrt-gdb-exploitable \
a60cd7
diff --git a/src/plugins/abrt-action-check-oops-for-hw-error.in b/src/plugins/abrt-action-check-oops-for-hw-error.in
a60cd7
new file mode 100644
a60cd7
index 0000000..83c0f22
a60cd7
--- /dev/null
a60cd7
+++ b/src/plugins/abrt-action-check-oops-for-hw-error.in
a60cd7
@@ -0,0 +1,118 @@
a60cd7
+#!/usr/bin/python -u
a60cd7
+
a60cd7
+import sys
a60cd7
+import os
a60cd7
+import locale
a60cd7
+import gettext
a60cd7
+
a60cd7
+GETTEXT_PROGNAME = "abrt"
a60cd7
+
a60cd7
+_ = gettext.lgettext
a60cd7
+
a60cd7
+def file_has_string(filename, string):
a60cd7
+    try:
a60cd7
+        f = open(filename, "r")
a60cd7
+    except IOError as e:
a60cd7
+        #print e
a60cd7
+        return False
a60cd7
+    for line in f:
a60cd7
+        if string in line:
a60cd7
+            f.close()
a60cd7
+            return True
a60cd7
+    f.close()
a60cd7
+    return False
a60cd7
+
a60cd7
+
a60cd7
+def tail_with_search(filename, string, maxlen):
a60cd7
+    try:
a60cd7
+        f = open(filename, "r")
a60cd7
+    except IOError as e:
a60cd7
+        #print e
a60cd7
+        return []
a60cd7
+    l = []
a60cd7
+    for line in f:
a60cd7
+        if string in line:
a60cd7
+            l.append(line)
a60cd7
+            if len(l) > maxlen:
a60cd7
+                del l[0]
a60cd7
+    f.close()
a60cd7
+    return l
a60cd7
+
a60cd7
+
a60cd7
+if __name__ == "__main__":
a60cd7
+    try:
a60cd7
+        locale.setlocale(locale.LC_ALL, "")
a60cd7
+    except locale.Error:
a60cd7
+        os.environ['LC_ALL'] = 'C'
a60cd7
+        locale.setlocale(locale.LC_ALL, "")
a60cd7
+
a60cd7
+    # Defeat "AttributeError: 'module' object has no attribute 'nl_langinfo'"
a60cd7
+    try:
a60cd7
+        gettext.bind_textdomain_codeset(GETTEXT_PROGNAME,
a60cd7
+                                        locale.nl_langinfo(locale.CODESET))
a60cd7
+    except AttributeError:
a60cd7
+        pass
a60cd7
+
a60cd7
+    gettext.bindtextdomain(GETTEXT_PROGNAME, '/usr/share/locale')
a60cd7
+    gettext.textdomain(GETTEXT_PROGNAME)
a60cd7
+
a60cd7
+    #
a60cd7
+    # So far we only look for Machine Check Exceptions here.
a60cd7
+    #
a60cd7
+
a60cd7
+    # See if MCEs were seen
a60cd7
+    if not file_has_string("dmesg", "Machine check events logged"):
a60cd7
+        sys.exit(0)
a60cd7
+    #
a60cd7
+    # There was an MCE. IOW: it's not a bug, it's a HW error.
a60cd7
+    f = open("not-reportable", "w")
a60cd7
+    f.write("The kernel log indicates that hardware errors were detected.\n");
a60cd7
+    f.write("This is most likely not a software problem.\n");
a60cd7
+    f.close()
a60cd7
+
a60cd7
+    #
a60cd7
+    # Did mcelog logged it to /var/log/mcelog
a60cd7
+    # (RHEL6 by default does this)?
a60cd7
+    if os.path.exists("/var/log/mcelog"):
a60cd7
+        f = open("comment", "w")
a60cd7
+        f.write("The kernel log indicates that hardware errors were detected.\n")
a60cd7
+        f.write("/var/log/mcelog file may have more information.\n")
a60cd7
+        f.write("The last 20 lines of /var/log/mcelog are:\n")
a60cd7
+        f.write("=========================================\n")
a60cd7
+        #tail -n20 /var/log/mcelog 2>&1
a60cd7
+        l = tail_with_search("/var/log/mcelog", "", 20)
a60cd7
+        for line in l:
a60cd7
+            f.write(line)
a60cd7
+        f.close()
a60cd7
+        sys.exit(0)
a60cd7
+    #
a60cd7
+    # On RHEL7, mcelog is run so that its output ends up in syslog.
a60cd7
+    # Do we see that?
a60cd7
+    if file_has_string("/var/log/messages", "mcelog: Hardware event"):
a60cd7
+        f = open("comment", "w")
a60cd7
+        f.write("The kernel log indicates that hardware errors were detected.\n")
a60cd7
+        f.write("System log may have more information.\n")
a60cd7
+        f.write("The last 20 mcelog lines of system log are:\n")
a60cd7
+        f.write("==========================================\n")
a60cd7
+        #grep -Fi 'mcelog:' /var/log/messages | tail -n20 2>&1
a60cd7
+        l = tail_with_search("/var/log/messages", "mcelog:", 20)
a60cd7
+        for line in l:
a60cd7
+            f.write(line)
a60cd7
+        f.close()
a60cd7
+        sys.exit(0)
a60cd7
+    #
a60cd7
+    # Apparently, there is no running mcelog daemon!
a60cd7
+    # Let user know that he needs one.
a60cd7
+    f = open("comment", "w")
a60cd7
+    f.write("The kernel log indicates that hardware errors were detected.\n")
a60cd7
+    f.write("The data was saved by kernel for processing by the mcelog tool.\n")
a60cd7
+    f.write("However, neither /var/log/mcelog nor system log contain mcelog messages.\n")
a60cd7
+    f.write("Most likely reason is that mcelog is not installed or not configured\n")
a60cd7
+    f.write("to be started during boot.\n")
a60cd7
+    f.write("Without this tool running, the binary data saved by kernel\n")
a60cd7
+    f.write("is of limited usefulness.\n")
a60cd7
+    f.write("(You can save this data anyway by running 'cat </dev/mcelog >FILE').\n")
a60cd7
+    f.write("The recommended course of action is to install mcelog.\n")
a60cd7
+    f.write("If another hardware error would occur, a user-readable description\n")
a60cd7
+    f.write("of it will be saved in system log or /var/log/mcelog.\n")
a60cd7
+    f.close()
a60cd7
diff --git a/src/plugins/koops_event.conf b/src/plugins/koops_event.conf
a60cd7
index 7dfbe36..3740f65 100644
a60cd7
--- a/src/plugins/koops_event.conf
a60cd7
+++ b/src/plugins/koops_event.conf
a60cd7
@@ -3,61 +3,8 @@ EVENT=post-create analyzer=Kerneloops
a60cd7
         # >> instead of > is due to bugzilla.redhat.com/show_bug.cgi?id=854266
a60cd7
         abrt-action-analyze-oops &&
a60cd7
         dmesg >>dmesg &&
a60cd7
-        abrt-action-save-kernel-data
a60cd7
-        abrt-action-save-kernel-data || exit $?
a60cd7
-        #
a60cd7
-        # If it exists, we can save a copy of MCE log here:
a60cd7
-        #test -f /var/log/mcelog && cp /var/log/mcelog .
a60cd7
-        # but in current config, sosreport already does that.
a60cd7
-        #
a60cd7
-        # See if MCEs were seen but mcelog isn't installed or running
a60cd7
-        grep -qFi 'Machine check events logged' dmesg || exit 0
a60cd7
-        #
a60cd7
-        # There was an MCE. IOW: it's not a bug, it's a HW error.
a60cd7
-        # Did mcelog logged it to /var/log/mcelog
a60cd7
-        # (RHEL6 by default does this)?
a60cd7
-        test -f /var/log/mcelog &&
a60cd7
-        {
a60cd7
-                # (Ab)use user comment field to inform user about it.
a60cd7
-                echo "The kernel log indicates that hardware errors were detected."
a60cd7
-                echo "/var/log/mcelog file may have more information."
a60cd7
-                echo "The last 20 lines of /var/log/mcelog are:"
a60cd7
-                echo "========================================="
a60cd7
-                # Redirecting sterr in case selinux makes it unreadable
a60cd7
-                # (annoying anyway, but at least user knows what's going on):
a60cd7
-                tail -n20 /var/log/mcelog 2>&1
a60cd7
-                exit 0
a60cd7
-        } >comment
a60cd7
-        #
a60cd7
-        # On RHEL7, mcelog is run so that its output ends up in syslog.
a60cd7
-        # Do we see that?
a60cd7
-        grep -qFi 'mcelog: Hardware event' /var/log/messages &&
a60cd7
-        {
a60cd7
-                echo "The kernel log indicates that hardware errors were detected."
a60cd7
-                echo "System log may have more information."
a60cd7
-                echo "The last 20 mcelog lines of system log are:"
a60cd7
-                echo "========================================="
a60cd7
-                # Redirecting sterr in case selinux makes it unreadable
a60cd7
-                # (annoying anyway, but at least user knows what's going on):
a60cd7
-                grep -Fi 'mcelog:' /var/log/messages | tail -n20 2>&1
a60cd7
-                exit 0
a60cd7
-        } >comment
a60cd7
-        #
a60cd7
-        # Apparently, there is no running mcelog daemon!
a60cd7
-        # Let user know that he needs one.
a60cd7
-        {
a60cd7
-        echo "The kernel log indicates that hardware errors were detected."
a60cd7
-        echo "The data was saved by kernel for processing by the mcelog tool."
a60cd7
-        echo "However, neither /var/log/mcelog nor system log contain mcelog messages."
a60cd7
-        echo "Most likely reason is that mcelog is not installed or not configured"
a60cd7
-        echo "to be started during boot."
a60cd7
-        echo "Without this tool running, the binary data saved by kernel"
a60cd7
-        echo "is of limited usefulness."
a60cd7
-        echo "(You can save this data anyway by running 'cat </dev/mcelog >FILE')."
a60cd7
-        echo "The recommended course of action is to install mcelog."
a60cd7
-        echo "If another hardware error would occur, a user-readable description"
a60cd7
-        echo "of it will be saved in system log or /var/log/mcelog."
a60cd7
-        } >comment
a60cd7
+        abrt-action-save-kernel-data &&
a60cd7
+        abrt-action-check-oops-for-hw-error
a60cd7
 
a60cd7
 # If you want behavior similar to one provided by kerneloops daemon
a60cd7
 # distributed by kerneloops.org - that is, if you want
a60cd7
-- 
a60cd7
1.8.3.1
a60cd7