Skip to content

Commit

Permalink
Fix: utils: pass env to child process explicitly (bsc#1205925)
Browse files Browse the repository at this point in the history
A bug in python stardard library, python/cpython#100516, make
environment variables, `COLUMNS` and `ROWS` to be added at fork. These
environment variables may make some of the commands called by crmsh to
truncate its output even if those commands are not writing to the
terminal.

Passing argument `env` explicitly is a workaround for the python bug.
  • Loading branch information
nicholasyang2022 committed Mar 14, 2024
1 parent ca85c40 commit e5e88b7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 5 additions & 1 deletion crmsh/report/utillib.py
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,11 @@ def get_command_info_timeout(cmd, timeout=5):
# Python 101: How to timeout a subprocess
def kill(process):
process.kill()
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
proc = subprocess.Popen(
cmd,
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
env=os.environ, # bsc#1205925
)
my_timer = Timer(timeout, kill, [proc])
try:
my_timer.start()
Expand Down
8 changes: 6 additions & 2 deletions crmsh/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,9 @@ def get_stdout(cmd, input_s=None, stderr_on=True, shell=True, raw=False):
shell=shell,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=stderr)
stderr=stderr,
env=os.environ, # bsc#1205925
)
stdout_data, stderr_data = proc.communicate(input_s)
if raw:
return proc.returncode, stdout_data
Expand All @@ -845,7 +847,9 @@ def get_stdout_stderr(cmd, input_s=None, shell=True, raw=False, no_reg=False):
shell=shell,
stdin=input_s and subprocess.PIPE or None,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stderr=subprocess.PIPE,
env=os.environ, # bsc#1205925
)
stdout_data, stderr_data = proc.communicate(input_s)
if raw:
return proc.returncode, stdout_data, stderr_data
Expand Down

0 comments on commit e5e88b7

Please sign in to comment.