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

69165ba
From 56c3d6950f300e98460fe196e0fe138f89ead83d Mon Sep 17 00:00:00 2001
69165ba
From: Denys Vlasenko <dvlasenk@redhat.com>
69165ba
Date: Mon, 6 Jan 2014 16:47:52 +0100
69165ba
Subject: [ABRT PATCH 21/27] abrt-action-check-oops-for-hw-error: i18n, add
69165ba
 error check on open()
69165ba
69165ba
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
69165ba
69165ba
Related to rhbz#1032077
69165ba
69165ba
Signed-off-by: Jakub Filak <jfilak@redhat.com>
69165ba
---
69165ba
 src/plugins/abrt-action-check-oops-for-hw-error.in | 23 ++++++++++++++++------
69165ba
 1 file changed, 17 insertions(+), 6 deletions(-)
69165ba
69165ba
diff --git a/src/plugins/abrt-action-check-oops-for-hw-error.in b/src/plugins/abrt-action-check-oops-for-hw-error.in
69165ba
index 83c0f22..ce13caf 100644
69165ba
--- a/src/plugins/abrt-action-check-oops-for-hw-error.in
69165ba
+++ b/src/plugins/abrt-action-check-oops-for-hw-error.in
69165ba
@@ -39,6 +39,15 @@ def tail_with_search(filename, string, maxlen):
69165ba
     return l
69165ba
 
69165ba
 
69165ba
+def open_or_die(filename, mode):
69165ba
+    try:
69165ba
+        f = open(filename, mode)
69165ba
+    except IOError as e:
69165ba
+        sys.stderr.write(str(e) + "\n")
69165ba
+        sys.exit(1)
69165ba
+    return f
69165ba
+
69165ba
+
69165ba
 if __name__ == "__main__":
69165ba
     try:
69165ba
         locale.setlocale(locale.LC_ALL, "")
69165ba
@@ -65,16 +74,18 @@ if __name__ == "__main__":
69165ba
         sys.exit(0)
69165ba
     #
69165ba
     # There was an MCE. IOW: it's not a bug, it's a HW error.
69165ba
-    f = open("not-reportable", "w")
69165ba
-    f.write("The kernel log indicates that hardware errors were detected.\n");
69165ba
-    f.write("This is most likely not a software problem.\n");
69165ba
+    f = open_or_die("not-reportable", "w")
69165ba
+    f.write(_(
69165ba
+                "The kernel log indicates that hardware errors were detected.\n"
69165ba
+                "This is most likely not a software problem.\n"
69165ba
+    ))
69165ba
     f.close()
69165ba
 
69165ba
     #
69165ba
     # Did mcelog logged it to /var/log/mcelog
69165ba
     # (RHEL6 by default does this)?
69165ba
     if os.path.exists("/var/log/mcelog"):
69165ba
-        f = open("comment", "w")
69165ba
+        f = open_or_die("comment", "w")
69165ba
         f.write("The kernel log indicates that hardware errors were detected.\n")
69165ba
         f.write("/var/log/mcelog file may have more information.\n")
69165ba
         f.write("The last 20 lines of /var/log/mcelog are:\n")
69165ba
@@ -89,7 +100,7 @@ if __name__ == "__main__":
69165ba
     # On RHEL7, mcelog is run so that its output ends up in syslog.
69165ba
     # Do we see that?
69165ba
     if file_has_string("/var/log/messages", "mcelog: Hardware event"):
69165ba
-        f = open("comment", "w")
69165ba
+        f = open_or_die("comment", "w")
69165ba
         f.write("The kernel log indicates that hardware errors were detected.\n")
69165ba
         f.write("System log may have more information.\n")
69165ba
         f.write("The last 20 mcelog lines of system log are:\n")
69165ba
@@ -103,7 +114,7 @@ if __name__ == "__main__":
69165ba
     #
69165ba
     # Apparently, there is no running mcelog daemon!
69165ba
     # Let user know that he needs one.
69165ba
-    f = open("comment", "w")
69165ba
+    f = open_or_die("comment", "w")
69165ba
     f.write("The kernel log indicates that hardware errors were detected.\n")
69165ba
     f.write("The data was saved by kernel for processing by the mcelog tool.\n")
69165ba
     f.write("However, neither /var/log/mcelog nor system log contain mcelog messages.\n")
69165ba
-- 
69165ba
1.8.3.1
69165ba