From 154e490e5064733a139eae72ed37192016dcb52f Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Sun, 28 Apr 2013 15:39:24 -0700 Subject: [PATCH] get_open_fds: use /dev/fd or /proc/self/fd Since /dev/fd is supposed to be a fairly standard unix feature, try that first. --- pym/portage/process.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pym/portage/process.py b/pym/portage/process.py index f00775cf5..24e347c26 100644 --- a/pym/portage/process.py +++ b/pym/portage/process.py @@ -30,10 +30,15 @@ except ImportError: if sys.hexversion >= 0x3000000: basestring = str -if os.path.isdir("/proc/%i/fd" % os.getpid()): +for _fd_dir in ("/dev/fd", "/proc/self/fd"): + if os.path.isdir(_fd_dir): + break + else: + _fd_dir = None + +if _fd_dir is not None: def get_open_fds(): - return (int(fd) for fd in os.listdir("/proc/%i/fd" % os.getpid()) \ - if fd.isdigit()) + return (int(fd) for fd in os.listdir(_fd_dir) if fd.isdigit()) if platform.python_implementation() == 'PyPy': # EAGAIN observed with PyPy 1.8. -- 2.26.2