Blame SOURCES/0037-sosreport-catch-OSError-exceptions-in-SoSReport.exec.patch

0cd6dc
From 95bb5df9eda253afed15fa81340d31e03c40fe94 Mon Sep 17 00:00:00 2001
0cd6dc
From: "Bryn M. Reeves" <bmr@redhat.com>
0cd6dc
Date: Tue, 13 Jan 2015 17:10:06 +0000
0cd6dc
Subject: [PATCH 37/93] [sosreport] catch OSError exceptions in
0cd6dc
 SoSReport.execute()
0cd6dc
0cd6dc
OSError exceptions during logging setup and tear down are not
0cd6dc
currently handled:
0cd6dc
0cd6dc
  Traceback (most recent call last):
0cd6dc
    File "/usr/sbin/sosreport", line 25, in <module>
0cd6dc
      main(sys.argv[1:])
0cd6dc
    File "/usr/lib/python2.7/site-packages/sos/sosreport.py", line 1409, in main
0cd6dc
      sos.execute()
0cd6dc
    File "/usr/lib/python2.7/site-packages/sos/sosreport.py", line 1366, in execute
0cd6dc
      self._setup_logging()
0cd6dc
    File "/usr/lib/python2.7/site-packages/sos/sosreport.py", line 739, in _setup_logging
0cd6dc
      self.sos_log_file = self.get_temp_file()
0cd6dc
    File "/usr/lib/python2.7/site-packages/sos/sosreport.py", line 670, in get_temp_file
0cd6dc
      return self.tempfile_util.new()
0cd6dc
    File "/usr/lib/python2.7/site-packages/sos/sosreport.py", line 82, in new
0cd6dc
      fd, fname = tempfile.mkstemp(dir=self.tmp_dir)
0cd6dc
    File "/usr/lib64/python2.7/tempfile.py", line 304, in mkstemp
0cd6dc
      return _mkstemp_inner(dir, prefix, suffix, flags)
0cd6dc
    File "/usr/lib64/python2.7/tempfile.py", line 239, in _mkstemp_inner
0cd6dc
      fd = _os.open(file, flags, 0600)
0cd6dc
  OSError: [Errno 28] No space left on device: '/tmp/tmp.4ejNitjwcr/nospace_tmp/tmpBjPTOm'
0cd6dc
0cd6dc
Address this by adding OSError to the list of caught exceptions
0cd6dc
in the main SoSReport.execute() method. Wrap the exception branch
0cd6dc
clean up in a try/except block to catch additional exceptions
0cd6dc
while attempting to clean up (e.g. unlink failures following an
0cd6dc
EROFS on the temporary archive path).
0cd6dc
0cd6dc
Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
0cd6dc
---
0cd6dc
 sos/sosreport.py | 19 +++++++++++++------
0cd6dc
 1 file changed, 13 insertions(+), 6 deletions(-)
0cd6dc
0cd6dc
diff --git a/sos/sosreport.py b/sos/sosreport.py
0cd6dc
index 0dd26ad..2a16555 100644
0cd6dc
--- a/sos/sosreport.py
0cd6dc
+++ b/sos/sosreport.py
0cd6dc
@@ -1395,12 +1395,19 @@ class SoSReport(object):
0cd6dc
             self.version()
0cd6dc
 
0cd6dc
             return self.final_work()
0cd6dc
-        except (SystemExit, KeyboardInterrupt):
0cd6dc
-            if self.archive:
0cd6dc
-                self.archive.cleanup()
0cd6dc
-            if self.tempfile_util:
0cd6dc
-                self.tempfile_util.clean()
0cd6dc
-            return False
0cd6dc
+
0cd6dc
+        except (OSError, SystemExit, KeyboardInterrupt):
0cd6dc
+            try:
0cd6dc
+                # archive and tempfile cleanup may fail due to a fatal
0cd6dc
+                # OSError exception (ENOSPC, EROFS etc.).
0cd6dc
+                if self.archive:
0cd6dc
+                    self.archive.cleanup()
0cd6dc
+                if self.tempfile_util:
0cd6dc
+                    self.tempfile_util.clean()
0cd6dc
+            except:
0cd6dc
+                pass
0cd6dc
+
0cd6dc
+        return False
0cd6dc
 
0cd6dc
 
0cd6dc
 def main(args):
0cd6dc
-- 
0cd6dc
1.9.3
0cd6dc