Blame SOURCES/0093-plugins-automatically-re-try-chroot-ed-commands-in-t.patch

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