diff options
-rw-r--r-- | sos/plugins/__init__.py | 50 |
1 files changed, 29 insertions, 21 deletions
diff --git a/sos/plugins/__init__.py b/sos/plugins/__init__.py index 9d04939b..c1b659d3 100644 --- a/sos/plugins/__init__.py +++ b/sos/plugins/__init__.py @@ -498,12 +498,13 @@ class Plugin(object): self._add_copy_paths(copy_paths) self._log_info("added copyspec '%s'" % copy_paths) - def get_command_output(self, prog, timeout=300, runat=None, stderr=True): - if self.commons['cmdlineopts'].chroot == 'always': + def get_command_output(self, prog, timeout=300, stderr=True, + chroot=True, runat=None): + if chroot or self.commons['cmdlineopts'].chroot == 'always': root = self.sysroot else: root = None - result = sos_get_command_output(prog, timeout=timeout, stderr=stderr + result = sos_get_command_output(prog, timeout=timeout, stderr=stderr, chroot=root, chdir=runat) if result['status'] == 124: self._log_warn("command '%s' timed out after %ds" @@ -513,12 +514,13 @@ class Plugin(object): self._log_debug("could not run '%s': command not found" % prog) return result - def call_ext_prog(self, prog, timeout=300, runat=None, stderr=True): + def call_ext_prog(self, prog, timeout=300, stderr=True, + chroot=True, runat=None): """Execute a command independantly of the output gathering part of sosreport. """ - return self.get_command_output(prog, timeout=timeout, runat=runat, - stderr=True) + return self.get_command_output(prog, timeout=timeout, stderr=stderr, + chroot=chroot, runat=runat) def check_ext_prog(self, prog): """Execute a command independently of the output gathering part of @@ -528,8 +530,8 @@ class Plugin(object): return self.call_ext_prog(prog)['status'] == 0 def add_cmd_output(self, cmds, suggest_filename=None, - root_symlink=None, timeout=300, runat=None, - stderr=True): + root_symlink=None, timeout=300, stderr=True, + chroot=True, runat=None): """Run a program or a list of programs and collect the output""" if isinstance(cmds, six.string_types): cmds = [cmds] @@ -537,9 +539,10 @@ class Plugin(object): self._log_warn("ambiguous filename or symlink for command list") for cmd in cmds: cmdt = ( - cmd, suggest_filename, root_symlink, timeout, runat, stderr + cmd, suggest_filename, root_symlink, timeout, stderr, + chroot, runat ) - _tuplefmt = "('%s', '%s', '%s', %s, '%s', '%s')" + _tuplefmt = "('%s', '%s', '%s', %s, '%s', '%s', '%s')" _logstr = "packed command tuple: " + _tuplefmt self._log_debug(_logstr % cmdt) self.collect_cmds.append(cmdt) @@ -594,14 +597,14 @@ class Plugin(object): self._log_debug("added string '%s' as '%s'" % (content, filename)) def get_cmd_output_now(self, exe, suggest_filename=None, - root_symlink=False, timeout=300, - runat=None, stderr=True): + root_symlink=False, timeout=300, stderr=True, + chroot=True, runat=None): """Execute a command and save the output to a file for inclusion in the report. """ start = time() - result = self.get_command_output(exe, timeout=timeout, runat=runat, - stderr=stderr) + result = self.get_command_output(exe, timeout=timeout, stderr=stderr, + chroot=chroot, runat=runat) # 126 means 'found but not executable' if result['status'] == 126 or result['status'] == 127: return None @@ -650,15 +653,20 @@ class Plugin(object): def _collect_cmd_output(self): for progs in zip(self.collect_cmds): - (prog, suggest_filename, root_symlink, timeout, runat, stderr - ) = progs[0] - self._log_debug("unpacked command tuple: " - "('%s', '%s', '%s', %s, '%s', %s)" % progs[0]) + ( + prog, + suggest_filename, root_symlink, + timeout, + stderr, + chroot, runat + ) = progs[0] + self._log_debug("unpacked command tuple: " + + "('%s', '%s', '%s', %s, '%s', '%s', '%s')" % + progs[0]) self._log_info("collecting output of '%s'" % prog) self.get_cmd_output_now(prog, suggest_filename=suggest_filename, - root_symlink=root_symlink, - timeout=timeout, runat=runat, - stderr=stderr) + root_symlink=root_symlink, timeout=timeout, + chroot=chroot, runat=runat) def _collect_strings(self): for string, file_name in self.copy_strings: |