From: Zac Medico Date: Sun, 23 Jun 2013 22:56:58 +0000 (-0700) Subject: Use /proc//fd for solaris compat, bug 474536 X-Git-Tag: v2.2.0_alpha185~11 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=76ebfcf74e09bf40bfc790bbc7a917d71a1a0c00;p=portage.git Use /proc//fd for solaris compat, bug 474536 --- diff --git a/bin/helper-functions.sh b/bin/helper-functions.sh index 65f41f6d0..eb6066f7a 100644 --- a/bin/helper-functions.sh +++ b/bin/helper-functions.sh @@ -76,10 +76,14 @@ __redirect_alloc_fd() { else # Need to provide the functionality ourselves. local fd=10 + local fddir=/dev/fd + # Use /proc//fd if available (/dev/fd + # doesn't work on solaris, see bug #474536). + [[ -d /proc/${BASHPID}/fd ]] && fddir=/proc/${BASHPID}/fd while :; do # Make sure the fd isn't open. It could be a char device, # or a symlink (possibly broken) to something else. - if [[ ! -e /dev/fd/${fd} ]] && [[ ! -L /dev/fd/${fd} ]] ; then + if [[ ! -e ${fddir}/${fd} ]] && [[ ! -L ${fddir}/${fd} ]] ; then eval "exec ${fd}${redir}'${file}'" && break fi [[ ${fd} -gt 1024 ]] && die "__redirect_alloc_fd failed" diff --git a/pym/portage/process.py b/pym/portage/process.py index 7104552c4..6969370d2 100644 --- a/pym/portage/process.py +++ b/pym/portage/process.py @@ -37,7 +37,9 @@ for _fd_dir in ("/dev/fd", "/proc/self/fd"): else: _fd_dir = None -if _fd_dir is not None: +# Use /proc//fd for SunOS (/dev/fd +# doesn't work on solaris, see bug #474536). +if _fd_dir is not None and platform.system() not in ('SunOS',): def get_open_fds(): return (int(fd) for fd in os.listdir(_fd_dir) if fd.isdigit()) @@ -52,6 +54,13 @@ if _fd_dir is not None: raise return range(max_fd_limit) +elif os.path.isdir("/proc/%s/fd" % os.getpid()): + # In order for this function to work in forked subprocesses, + # os.getpid() must be called from inside the function. + def get_open_fds(): + return (int(fd) for fd in os.listdir("/proc/%s/fd" % os.getpid()) + if fd.isdigit()) + else: def get_open_fds(): return range(max_fd_limit)