From fa3a424e63ab923acd97889150690673c80290c1 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Sun, 2 Apr 2006 05:53:03 +0000 Subject: [PATCH] Add a portage_exec.get_open_fds() function for bug #128284. Thanks to Brian Harring for this patch. svn path=/main/trunk/; revision=3054 --- pym/portage_exec.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pym/portage_exec.py b/pym/portage_exec.py index 31b379396..e800376dc 100644 --- a/pym/portage_exec.py +++ b/pym/portage_exec.py @@ -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) -- 2.26.2