doczkal / rpms / abrt

Forked from rpms/abrt 4 years ago
Clone

Blame SOURCES/0021-abrt-action-check-oops-for-hw-error-i18n-add-error-c.patch

a60cd7
From 56c3d6950f300e98460fe196e0fe138f89ead83d Mon Sep 17 00:00:00 2001
a60cd7
From: Denys Vlasenko <dvlasenk@redhat.com>
a60cd7
Date: Mon, 6 Jan 2014 16:47:52 +0100
a60cd7
Subject: [ABRT PATCH 21/27] abrt-action-check-oops-for-hw-error: i18n, add
a60cd7
 error check on open()
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
 src/plugins/abrt-action-check-oops-for-hw-error.in | 23 ++++++++++++++++------
a60cd7
 1 file changed, 17 insertions(+), 6 deletions(-)
a60cd7
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
index 83c0f22..ce13caf 100644
a60cd7
--- a/src/plugins/abrt-action-check-oops-for-hw-error.in
a60cd7
+++ b/src/plugins/abrt-action-check-oops-for-hw-error.in
a60cd7
@@ -39,6 +39,15 @@ def tail_with_search(filename, string, maxlen):
a60cd7
     return l
a60cd7
 
a60cd7
 
a60cd7
+def open_or_die(filename, mode):
a60cd7
+    try:
a60cd7
+        f = open(filename, mode)
a60cd7
+    except IOError as e:
a60cd7
+        sys.stderr.write(str(e) + "\n")
a60cd7
+        sys.exit(1)
a60cd7
+    return f
a60cd7
+
a60cd7
+
a60cd7
 if __name__ == "__main__":
a60cd7
     try:
a60cd7
         locale.setlocale(locale.LC_ALL, "")
a60cd7
@@ -65,16 +74,18 @@ if __name__ == "__main__":
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 = open_or_die("not-reportable", "w")
a60cd7
+    f.write(_(
a60cd7
+                "The kernel log indicates that hardware errors were detected.\n"
a60cd7
+                "This is most likely not a software problem.\n"
a60cd7
+    ))
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 = open_or_die("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
@@ -89,7 +100,7 @@ if __name__ == "__main__":
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 = open_or_die("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
@@ -103,7 +114,7 @@ if __name__ == "__main__":
a60cd7
     #
a60cd7
     # Apparently, there is no running mcelog daemon!
a60cd7
     # Let user know that he needs one.
a60cd7
-    f = open("comment", "w")
a60cd7
+    f = open_or_die("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
-- 
a60cd7
1.8.3.1
a60cd7