From 7bd32b25ec04164f33edd016a570aea1d5241f46 Mon Sep 17 00:00:00 2001 From: "Bryn M. Reeves" Date: Wed, 30 Oct 2013 12:02:51 +0000 Subject: Check for usable temporary directory A user may override the sos temporary directory via --tmp-dir to a non-existent or unwritable location. Check for this before initialising temporary files and exit with an error message. Signed-off-by: Bryn M. Reeves --- sos/sosreport.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sos/sosreport.py b/sos/sosreport.py index 88c67301..3fb60c70 100644 --- a/sos/sosreport.py +++ b/sos/sosreport.py @@ -534,6 +534,12 @@ class SoSReport(object): self.policy = sos.policies.load() self._is_root = self.policy.is_root() self.tmpdir = self.policy.get_tmp_dir(self.opts.tmp_dir) + if not os.path.isdir(self.tmpdir) \ + or not os.access(self.tmpdir, os.W_OK): + # write directly to stderr as logging is not initialised yet + sys.stderr.write("temporary directory %s " % self.tmpdir \ + + "does not exist or is not writable\n") + self._exit(1) self.tempfile_util = TempFileUtil(self.tmpdir) self._set_directories() -- cgit