diff options
author | Jake Hunsaker <jhunsake@redhat.com> | 2022-04-20 11:27:10 -0400 |
---|---|---|
committer | Jake Hunsaker <jhunsake@redhat.com> | 2022-04-26 09:44:49 -0400 |
commit | 95912b2ff2430700e659caaee66bd292322eb964 (patch) | |
tree | 8e56dc11ff6bfbc081636439a463fe87bb981ddc | |
parent | a705fb1ce4f77d40f1dc40e535d49409d3681ed2 (diff) | |
download | sos-95912b2ff2430700e659caaee66bd292322eb964.tar.gz |
[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 <jhunsake@redhat.com>
-rw-r--r-- | sos/policies/distros/__init__.py | 16 |
1 files 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 |