From f9be32a0c55503a2b06bc42f5d0fd58d30a15d06 Mon Sep 17 00:00:00 2001 From: "Bryn M. Reeves" Date: Wed, 28 Jan 2015 22:54:48 +0000 Subject: [PATCH 93/93] [plugins] automatically re-try chroot'ed commands in the host Signed-off-by: Bryn M. Reeves --- sos/plugins/__init__.py | 12 +++++++++++- sos/utilities.py | 5 +---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/sos/plugins/__init__.py b/sos/plugins/__init__.py index 456bae0..29ce3b8 100644 --- a/sos/plugins/__init__.py +++ b/sos/plugins/__init__.py @@ -513,13 +513,23 @@ class Plugin(object): root = self.sysroot else: root = None + result = sos_get_command_output(prog, timeout=timeout, chroot=root, chdir=runat) + if result['status'] == 124: self._log_warn("command '%s' timed out after %ds" % (prog, timeout)) - # 126 means 'found but not executable' + + # command not found or not runnable if result['status'] == 126 or result['status'] == 127: + # automatically retry chroot'ed commands in the host namespace + if chroot and self.commons['cmdlineopts'].chroot != 'always': + self._log_info("command '%s' not found in %s - " + "re-trying in host root" + % (prog.split()[0], root)) + return self.get_command_output(prog, timeout=timeout, + chroot=False, runat=runat) self._log_debug("could not run '%s': command not found" % prog) return result diff --git a/sos/utilities.py b/sos/utilities.py index ef3e115..0781348 100644 --- a/sos/utilities.py +++ b/sos/utilities.py @@ -149,16 +149,13 @@ def sos_get_command_output(command, timeout=300, chroot=None, chdir=None): p = Popen(args, shell=False, stdout=PIPE, stderr=STDOUT, bufsize=-1, env=cmd_env, close_fds=True, preexec_fn=_child_prep_fn) + stdout, stderr = p.communicate() except OSError as e: if e.errno == errno.ENOENT: return {'status': 127, 'output': ""} else: raise e - stdout, stderr = p.communicate() - - # Required hack while we still pass shell=True to Popen; a Popen - # call with shell=False for a non-existant binary will raise OSError. if p.returncode == 126 or p.returncode == 127: stdout = six.binary_type(b"") -- 1.9.3