Blame SOURCES/sos-bz1019517-check-for-usable-temporary-directory.patch

6b17e9
commit 0c9eef9d1270b9197a609ac46fdd5837c04a90dd
6b17e9
Author: Bryn M. Reeves <bmr@redhat.com>
6b17e9
Date:   Wed Oct 30 12:02:51 2013 +0000
6b17e9
6b17e9
    Check for usable temporary directory
6b17e9
    
6b17e9
    A user may override the sos temporary directory via --tmp-dir to
6b17e9
    a non-existent or unwritable location. Check for this before
6b17e9
    initialising temporary files and exit with an error message.
6b17e9
    
6b17e9
    Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
6b17e9
6b17e9
diff --git a/sos/sosreport.py b/sos/sosreport.py
6b17e9
index 88c6730..3fb60c7 100644
6b17e9
--- a/sos/sosreport.py
6b17e9
+++ b/sos/sosreport.py
6b17e9
@@ -534,6 +534,12 @@ class SoSReport(object):
6b17e9
         self.policy = sos.policies.load()
6b17e9
         self._is_root = self.policy.is_root()
6b17e9
         self.tmpdir = self.policy.get_tmp_dir(self.opts.tmp_dir)
6b17e9
+        if not os.path.isdir(self.tmpdir) \
6b17e9
+        or not os.access(self.tmpdir, os.W_OK):
6b17e9
+            # write directly to stderr as logging is not initialised yet
6b17e9
+            sys.stderr.write("temporary directory %s " % self.tmpdir \
6b17e9
+                        + "does not exist or is not writable\n")
6b17e9
+            self._exit(1)
6b17e9
         self.tempfile_util = TempFileUtil(self.tmpdir)
6b17e9
         self._set_directories()
6b17e9