Blob Blame History Raw
From 81cda098bae00968091d50596d14880a78b893fb Mon Sep 17 00:00:00 2001
From: "Bryn M. Reeves" <bmr@redhat.com>
Date: Tue, 27 Jan 2015 12:54:31 -0500
Subject: [PATCH 88/93] [policies/redhat] automatically set tmp_dir in
 containers

Now that policies have the infrastructure to detect that they
are running in a container and to use the HOST environment
variable if present enable automatic setting of self._tmp_dir in
appriate container environments.

This causes reports to be automatically written to $HOST/var/tmp
when $HOST is set while still allowing users to override the tmp
path manually by specificying --tmp-dir=PATH.

Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
---
 sos/policies/redhat.py | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/sos/policies/redhat.py b/sos/policies/redhat.py
index 81ed8ad..c057e6e 100644
--- a/sos/policies/redhat.py
+++ b/sos/policies/redhat.py
@@ -71,14 +71,17 @@ class RedHatPolicy(LinuxPolicy):
         return False
 
     def _container_init(self):
-        """Check if sos is running in a container and if a host sysroot
-        has been passed in the environment.
+        """Check if sos is running in a container and perform container
+        specific initialisation based on ENV_HOST_SYSROOT.
         """
         if ENV_CONTAINER_UUID in os.environ:
             self._in_container = True
         if ENV_HOST_SYSROOT in os.environ:
             self._host_sysroot = os.environ[ENV_HOST_SYSROOT]
         use_sysroot = self._in_container and self._host_sysroot != '/'
+        if use_sysroot:
+            host_tmp_dir = os.path.abspath(self._host_sysroot + self._tmp_dir)
+            self._tmp_dir = host_tmp_dir
         return self._host_sysroot if use_sysroot else None
 
     def runlevel_by_service(self, name):
-- 
1.9.3