aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJake Hunsaker <jhunsake@redhat.com>2018-06-23 19:31:28 -0400
committerBryn M. Reeves <bmr@redhat.com>2018-06-25 11:42:14 +0100
commitfb726230bfdda14fcf2f26eae748cf94df08493f (patch)
treec74b3b264f30b10f9f88bcb8dadd79041e1731eb
parent97454f9a3e3123ee5a1054de2c8032edc2a965fd (diff)
downloadsos-fb726230bfdda14fcf2f26eae748cf94df08493f.tar.gz
[utilities] Allow commands to filter environment variables
Allows commands that set their own environment variables to also filter out variables that are undesired for the given command. Plugins that need to do this should set the environment variable in question None when setting 'env' for an add_cmd_output() call. Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
-rw-r--r--sos/utilities.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/sos/utilities.py b/sos/utilities.py
index 42dceff6..d112e15a 100644
--- a/sos/utilities.py
+++ b/sos/utilities.py
@@ -121,13 +121,16 @@ def sos_get_command_output(command, timeout=300, stderr=False,
if (chdir):
os.chdir(chdir)
- cmd_env = os.environ
+ cmd_env = os.environ.copy()
# ensure consistent locale for collected command output
cmd_env['LC_ALL'] = 'C'
# optionally add an environment change for the command
if env:
for key, value in env.items():
- cmd_env[key] = value
+ if value:
+ cmd_env[key] = value
+ else:
+ cmd_env.pop(key, None)
# use /usr/bin/timeout to implement a timeout
if timeout and is_executable("timeout"):
command = "timeout %ds %s" % (timeout, command)