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"
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())
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)