diff options
author | Jake Hunsaker <jhunsake@redhat.com> | 2020-01-28 10:05:05 +0100 |
---|---|---|
committer | Pavel Moravec <pmoravec@redhat.com> | 2020-01-28 10:05:05 +0100 |
commit | c5e82990a728f77d46de770f0a168b0b37313510 (patch) | |
tree | 97bc9d29f5712e34c301c0b8b101b8ff5264d8ca | |
parent | f867f783d333679ad871c77b473bd4e6a258ab4a (diff) | |
download | sos-c5e82990a728f77d46de770f0a168b0b37313510.tar.gz |
[utilities] Add --foreground to timeout commands optionally
A small number of recent issues have been identified that revolved
around certain commands hanging when run by sos unless `timeout=None`
was specified for those commands.
This patch adds `--foreground` to the `timeout` command that we use to
wrap any collected commands, so as to not disconnect the TTY which was
resulting in the hanging behavior. This addition is controlled by the
use of the new `foreground` parameter in any `add_cmd_output()` or
`collect_cmd_output()` call.
Resolves: #1909
Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
Signed-off-by: Pavel Moravec <pmoravec@redhat.com>
-rw-r--r-- | sos/plugins/__init__.py | 13 | ||||
-rw-r--r-- | sos/utilities.py | 8 |
2 files changed, 13 insertions, 8 deletions
diff --git a/sos/plugins/__init__.py b/sos/plugins/__init__.py index e1ac2deb..1ab0dfc2 100644 --- a/sos/plugins/__init__.py +++ b/sos/plugins/__init__.py @@ -1043,7 +1043,7 @@ class Plugin(object): root_symlink=None, timeout=300, stderr=True, chroot=True, runat=None, env=None, binary=False, sizelimit=None, pred=None, subdir=None, - changes=False): + changes=False, foreground=False): """Run a program or a list of programs and collect the output""" if isinstance(cmds, six.string_types): cmds = [cmds] @@ -1059,7 +1059,7 @@ class Plugin(object): stderr=stderr, chroot=chroot, runat=runat, env=env, binary=binary, sizelimit=sizelimit, pred=pred, subdir=subdir, - changes=changes) + changes=changes, foreground=foreground) def get_cmd_output_path(self, name=None, make=True): """Return a path into which this module should store collected @@ -1149,7 +1149,7 @@ class Plugin(object): root_symlink=False, timeout=300, stderr=True, chroot=True, runat=None, env=None, binary=False, sizelimit=None, subdir=None, - changes=False): + changes=False, foreground=False): """Execute a command and save the output to a file for inclusion in the report. @@ -1189,7 +1189,7 @@ class Plugin(object): result = sos_get_command_output( cmd, timeout=timeout, stderr=stderr, chroot=root, chdir=runat, env=env, binary=binary, sizelimit=sizelimit, - poller=self.check_timeout + poller=self.check_timeout, foreground=foreground ) if result['status'] == 124: @@ -1263,7 +1263,7 @@ class Plugin(object): ) def exec_cmd(self, cmd, timeout=300, stderr=True, chroot=True, runat=None, - env=None, binary=False, pred=None): + env=None, binary=False, pred=None, foreground=False): """Execute a command right now and return the output and status, but do not save the output within the archive. @@ -1282,7 +1282,8 @@ class Plugin(object): root = None return sos_get_command_output(cmd, timeout=timeout, chroot=root, - chdir=runat, binary=binary, env=env) + chdir=runat, binary=binary, env=env, + foreground=foreground) def is_module_loaded(self, module_name): """Return whether specified module as module_name is loaded or not""" diff --git a/sos/utilities.py b/sos/utilities.py index 8befbdf6..871956c1 100644 --- a/sos/utilities.py +++ b/sos/utilities.py @@ -106,7 +106,7 @@ def is_executable(command): def sos_get_command_output(command, timeout=300, stderr=False, - chroot=None, chdir=None, env=None, + chroot=None, chdir=None, env=None, foreground=False, binary=False, sizelimit=None, poller=None): """Execute a command and return a dictionary of status and output, optionally changing root or current working directory before @@ -133,7 +133,11 @@ def sos_get_command_output(command, timeout=300, stderr=False, 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) + command = "timeout %s %ds %s" % ( + '--foreground' if foreground else '', + timeout, + command + ) # shlex.split() reacts badly to unicode on older python runtimes. if not six.PY3: |