Use /proc/<pid>/fd for solaris compat, bug 474536
authorZac Medico <zmedico@gentoo.org>
Sun, 23 Jun 2013 22:56:58 +0000 (15:56 -0700)
committerZac Medico <zmedico@gentoo.org>
Sun, 23 Jun 2013 22:56:58 +0000 (15:56 -0700)
bin/helper-functions.sh
pym/portage/process.py

index 65f41f6d035ad38c1d38791e494132eb1b39881b..eb6066f7ab4dd0fd017075cbfbfd8897738635db 100644 (file)
@@ -76,10 +76,14 @@ __redirect_alloc_fd() {
        else
                        # Need to provide the functionality ourselves.
                        local fd=10
+                       local fddir=/dev/fd
+                       # Use /proc/<pid>/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"
index 7104552c41e5ee8b9b1a7e87a32e55478738e6b1..6969370d2398b423e7f21f3ea17cd4fe393f5916 100644 (file)
@@ -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/<pid>/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)