Add a portage_exec.get_open_fds() function for bug #128284. Thanks to Brian Harring...
authorZac Medico <zmedico@gentoo.org>
Sun, 2 Apr 2006 05:53:03 +0000 (05:53 -0000)
committerZac Medico <zmedico@gentoo.org>
Sun, 2 Apr 2006 05:53:03 +0000 (05:53 -0000)
svn path=/main/trunk/; revision=3054

pym/portage_exec.py

index 31b3793968d5f856c343b528afdafcc2f4d4a4ba..e800376dcfd5e6c0728e64a677f91059c4c6fd6f 100644 (file)
@@ -17,6 +17,13 @@ try:
 except ImportError:
        max_fd_limit = 256
 
+if os.path.isdir("/proc/%i/fd" % os.getpid()):
+       def get_open_fds():
+               return map(int, os.listdir("/proc/%i/fd" % os.getpid()))
+else:
+       def get_open_fds():
+               return xrange(max_fd_limit)
+
 sandbox_capable = (os.path.isfile(SANDBOX_BINARY) and
                    os.access(SANDBOX_BINARY, os.X_OK))
 
@@ -222,7 +229,7 @@ def _exec(binary, mycommand, opt_name, fd_pipes, env, gid, groups, uid, umask):
                os.dup2(my_fds[fd], fd)
        # Then close _all_ fds that haven't been explictly
        # requested to be kept open.
-       for fd in range(max_fd_limit):
+       for fd in get_open_fds():
                if fd not in my_fds:
                        try:
                                os.close(fd)