aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryn M. Reeves <bmr@redhat.com>2012-12-18 18:46:27 +0000
committerBryn M. Reeves <bmr@redhat.com>2012-12-18 18:46:27 +0000
commitb3d4b9ffc54352b95702babd2f489f8a3f906e2d (patch)
tree729bd02af761e67cb24e615b37d402b7ec14ba42
parent9768a7695325bd72f3abc94d2a27327ac666824f (diff)
downloadsos-b3d4b9ffc54352b95702babd2f489f8a3f906e2d.tar.gz
Force LC_ALL=C for external commands
Commands run by sos inherit the environment of the user running the program. This includes locale settings meaning that collected output is subject to local language, sorting and formatting customisations that can be undesirable when post-processing or parsing of the gathered data is required. Force all external processes to use the 'C' locale.
-rw-r--r--sos/utilities.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/sos/utilities.py b/sos/utilities.py
index d287768e..7995ef0f 100644
--- a/sos/utilities.py
+++ b/sos/utilities.py
@@ -149,13 +149,18 @@ def sosGetCommandOutput(command, timeout=300):
# XXX: what is this doing this for?
cmdfile = command.strip("(").split()[0]
+ cmd_env = os.environ
+ # ensure consistent locale for collected command output
+ cmd_env['LC_ALL'] = 'C'
if is_executable(cmdfile):
# use /usr/bin/timeout to implement a timeout
if timeout and is_executable("/usr/bin/timeout"):
command = "/usr/bin/timeout %ds %s" % (timeout, command)
- p = Popen(command, shell=True, stdout=PIPE, stderr=STDOUT, bufsize=-1)
+ p = Popen(command, shell=True,
+ stdout=PIPE, stderr=STDOUT,
+ bufsize=-1, env = cmd_env)
stdout, stderr = p.communicate()
return (p.returncode, stdout, 0)
else: