summaryrefslogtreecommitdiffstats
path: root/tests/util.sh
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2024-02-01 16:14:19 -0500
committerTavian Barnes <tavianator@tavianator.com>2024-02-01 16:33:18 -0500
commitc4334184502c25a41b5cab060681229b2b570c0a (patch)
tree3db277045e38a35a375f41900cb1dbffeed1b39a /tests/util.sh
parentf8b22f20147d872aef9fa1037139c39e4dd0e687 (diff)
downloadbfs-c4334184502c25a41b5cab060681229b2b570c0a.tar.xz
tests: Don't clobber inherited FDs
Rather than attempting to close any unexpected FDs, just count them and adjust our ulimit -n calls to account for them.
Diffstat (limited to 'tests/util.sh')
-rw-r--r--tests/util.sh17
1 files changed, 5 insertions, 12 deletions
diff --git a/tests/util.sh b/tests/util.sh
index 686cc77..ec24958 100644
--- a/tests/util.sh
+++ b/tests/util.sh
@@ -48,23 +48,16 @@ stdenv() {
export MallocNanoZone=0
fi
- # Close non-standard inherited fds
+ # Count the inherited FDs
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
-
- local fd="${fd##*/}"
- if ((fd > 2)); then
- eval "exec ${fd}<&-"
- fi
- done
+ # We use ls $fds on purpose, rather than e.g. ($fds/*), to avoid counting
+ # internal bash fds that are not exposed to spawned processes
+ NOPENFD=$(ls -1q "$fds/" 2>/dev/null | wc -l)
+ NOPENFD=$((NOPENFD > 3 ? NOPENFD - 1 : 3))
# Close stdin so bfs doesn't think we're interactive
# dup() the standard fds for logging even when redirected