From 500892f115aea9788da7649b59baaea38729aacf Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Sat, 9 Sep 2017 12:06:59 -0400 Subject: Try /proc/self/fd before /dev/fd On Solaris, /proc/self/fd is dynamic while /dev/fd is static. --- eval.c | 9 ++++++--- tests.sh | 10 ++++++++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/eval.c b/eval.c index a387bdc..6c25e18 100644 --- a/eval.c +++ b/eval.c @@ -1147,9 +1147,12 @@ static int infer_fdlimit(const struct cmdline *cmdline) { // 3 for std{in,out,err} int nopen = 3 + cmdline->nopen_files; - // Check /dev/fd for the current number of open fds, if possible (we may - // have inherited more than just the standard ones) - DIR *dir = opendir("/dev/fd"); + // Check /proc/self/fd for the current number of open fds, if possible + // (we may have inherited more than just the standard ones) + DIR *dir = opendir("/proc/self/fd"); + if (!dir) { + dir = opendir("/dev/fd"); + } if (dir) { // Account for 'dir' itself nopen = -1; diff --git a/tests.sh b/tests.sh index f4d4107..d664793 100755 --- a/tests.sh +++ b/tests.sh @@ -510,12 +510,18 @@ function bfs_diff() ( ) function closefrom() { - for fd in /dev/fd/*; do + if [ -d /proc/self/fd ]; then + local fds=/proc/self/fd + else + local fds=/dev/fd + fi + + for fd in "$fds"/*; do if [ ! -e "$fd" ]; then continue fi - fd="${fd##*/}" + local fd="${fd##*/}" if [ "$fd" -ge "$1" ]; then eval "exec ${fd}<&-" fi -- cgit v1.2.3