From 95912b2ff2430700e659caaee66bd292322eb964 Mon Sep 17 00:00:00 2001 From: Jake Hunsaker Date: Wed, 20 Apr 2022 11:27:10 -0400 Subject: [policies] Simplify flow in _container_init() Simplifies the logic and flow of `LinuxPolicy._container_init()` so that it is both easier to follow and less prone to edge cases that could break in-container collections that are not setup to capture from the host system. Signed-off-by: Jake Hunsaker --- sos/policies/distros/__init__.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/sos/policies/distros/__init__.py b/sos/policies/distros/__init__.py index d8d62d34..f459689b 100644 --- a/sos/policies/distros/__init__.py +++ b/sos/policies/distros/__init__.py @@ -218,13 +218,15 @@ class LinuxPolicy(Policy): if ENV_CONTAINER in os.environ: if os.environ[ENV_CONTAINER] in ['docker', 'oci', 'podman']: self._in_container = True - if ENV_HOST_SYSROOT in os.environ: - _host_sysroot = os.environ[ENV_HOST_SYSROOT] - use_sysroot = self._in_container and _host_sysroot is not None - if use_sysroot: - host_tmp_dir = os.path.abspath(_host_sysroot + self._tmp_dir) - self._tmp_dir = host_tmp_dir - return _host_sysroot if use_sysroot else None + if ENV_HOST_SYSROOT in os.environ: + if not os.environ[ENV_HOST_SYSROOT]: + # guard against blank/improperly unset values + return None + self._tmp_dir = os.path.abspath( + os.environ[ENV_HOST_SYSROOT] + self._tmp_dir + ) + return os.environ[ENV_HOST_SYSROOT] + return None def init_kernel_modules(self): """Obtain a list of loaded kernel modules to reference later for plugin -- cgit