Blame SOURCES/sos-bz1051009-fix-fd-leaks-on-popen.patch

629484
commit 4f7231a897fb65aaf6ec7f079784ff9d3da44266
629484
Author: Bryn M. Reeves <bmr@redhat.com>
629484
Date:   Tue Feb 4 11:37:15 2014 +0000
629484
629484
    Ensure unused fds are closed when calling subprocesses via Popen
629484
    
629484
    When sos communicates with a child process using Popen all IO
629484
    takes place on stdin/stdout/stderr (or a subset). No other open
629484
    file descriptors should be inherited by the child.
629484
    
629484
    Make all calls to Popen set close_fds=True.
629484
    
629484
    Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
629484
629484
diff --git a/sos/archive.py b/sos/archive.py
629484
index 28bf197..67270db 100644
629484
--- a/sos/archive.py
629484
+++ b/sos/archive.py
629484
@@ -250,8 +250,12 @@ class TarFileArchive(FileCacheArchive):
629484
             if cmd != "gzip":
629484
                 cmd = "%s -1" % cmd
629484
             try:
629484
-                command = shlex.split("%s %s" % (cmd,self.name()))
629484
-                p = Popen(command, stdout=PIPE, stderr=PIPE, bufsize=-1)
629484
+                command = shlex.split("%s %s" % (cmd, self.name()))
629484
+                p = Popen(command,
629484
+                          stdout=PIPE,
629484
+                          stderr=PIPE,
629484
+                          bufsize=-1,
629484
+                          close_fds=True)
629484
                 stdout, stderr = p.communicate()
629484
                 if stdout:
629484
                     log.info(stdout)
629484
diff --git a/sos/plugins/emc.py b/sos/plugins/emc.py
629484
index 89d0734..f73bccd 100644
629484
--- a/sos/plugins/emc.py
629484
+++ b/sos/plugins/emc.py
629484
@@ -196,7 +196,8 @@ class Emc(Plugin, RedHatPlugin):
629484
             while CLARiiON_IP_loop == "stay_in":
629484
                 ans = raw_input("CLARiiON SP IP Address or [Enter] to exit: ")
629484
                 ## Check to make sure the CLARiiON SP IP address provided is valid
629484
-                p = Popen("navicli -h %s getsptime" % (ans,), shell=True, stdout=PIPE, stderr=PIPE)
629484
+                p = Popen("navicli -h %s getsptime" % (ans,),
629484
+                            shell=True, stdout=PIPE, stderr=PIPE, close_fds=True)
629484
                 out, err = p.communicate()
629484
                 if p.returncode == 0:
629484
                     CLARiiON_IP_address_list.append(ans)
629484
diff --git a/sos/policies/redhat.py b/sos/policies/redhat.py
629484
index 5b3a446..4e5b363 100644
629484
--- a/sos/policies/redhat.py
629484
+++ b/sos/policies/redhat.py
629484
@@ -68,7 +68,8 @@ class RedHatPolicy(LinuxPolicy):
629484
                   shell=True,
629484
                   stdout=PIPE,
629484
                   stderr=PIPE,
629484
-                  bufsize=-1)
629484
+                  bufsize=-1,
629484
+                  close_fds=True)
629484
         out, err = p.communicate()
629484
         if err:
629484
             return ret
629484
diff --git a/sos/utilities.py b/sos/utilities.py
629484
index fcc78c5..f1728fd 100644
629484
--- a/sos/utilities.py
629484
+++ b/sos/utilities.py
629484
@@ -159,7 +159,7 @@ def sos_get_command_output(command, timeout=300):
629484
 
629484
         p = Popen(command, shell=True,
629484
                 stdout=PIPE, stderr=STDOUT,
629484
-                bufsize=-1, env = cmd_env)
629484
+                bufsize=-1, env = cmd_env, close_fds = True)
629484
         stdout, stderr = p.communicate()
629484
         return (p.returncode, stdout, 0)
629484
     else: