summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2025-06-08 16:32:01 -0400
committerTavian Barnes <tavianator@tavianator.com>2025-06-15 10:23:27 -0400
commit38f3e3e7ba210bbc45c2077102c308ed8abae061 (patch)
treeb45afca281216cc833b99311c6e6fd3ddc55d045
parentcb40f51e4e6375a10265484b6959c6b1b0591378 (diff)
downloadbfs-38f3e3e7ba210bbc45c2077102c308ed8abae061.tar.xz
*.sh: Don't shadow the global nproc
This avoids the need for the bash 3 workaround of running command nproc in a subshell.
-rwxr-xr-xconfigure14
-rw-r--r--tests/getopts.sh2
-rw-r--r--tests/util.sh4
3 files changed, 9 insertions, 11 deletions
diff --git a/configure b/configure
index ab62aa6..7f0bd04 100755
--- a/configure
+++ b/configure
@@ -16,7 +16,7 @@ help() {
Usage:
\$ $0 [--enable-*|--disable-*] [--with-*|--without-*] [CC=...] [...]
- \$ $MAKE -j$(nproc)
+ \$ $MAKE -j$(_nproc)
Variables set in the environment or on the command line will be picked up:
@@ -66,7 +66,7 @@ Packaging:
This script is a thin wrapper around a makefile-based configuration system.
Any other arguments will be passed directly to the $MAKE invocation, e.g.
- \$ $0 -j$(nproc) V=1
+ \$ $0 -j$(_nproc) V=1
EOF
}
@@ -85,11 +85,9 @@ invalid() {
}
# Get the number of cores to use
-nproc() {
+_nproc() {
{
- # Run command nproc in a subshell to work around a bash 3 bug
- # https://stackoverflow.com/q/68143965
- (command nproc) \
+ nproc \
|| sysctl -n hw.ncpu \
|| getconf _NPROCESSORS_ONLN \
|| echo 1
@@ -233,7 +231,7 @@ for f in Makefile bench build completions docs src tests; do
test -e "$f" || ln -s "$DIR/$f" "$f"
done
-# Set MAKEFLAGS to -j$(nproc) if it's unset
-export MAKEFLAGS="${MAKEFLAGS--j$(nproc)}"
+# Set MAKEFLAGS to -j$(_nproc) if it's unset
+export MAKEFLAGS="${MAKEFLAGS--j$(_nproc)}"
$MAKE -rf build/config.mk "$@"
diff --git a/tests/getopts.sh b/tests/getopts.sh
index cbb3ce4..a16511f 100644
--- a/tests/getopts.sh
+++ b/tests/getopts.sh
@@ -5,7 +5,7 @@
## Argument parsing
-JOBS=$(nproc)
+JOBS=$(_nproc)
MAKE=
PATTERNS=()
SUDO=()
diff --git a/tests/util.sh b/tests/util.sh
index e3eca60..1718a1a 100644
--- a/tests/util.sh
+++ b/tests/util.sh
@@ -194,9 +194,9 @@ pop_defers() {
## Parallelism
# Get the number of processors
-nproc() {
+_nproc() {
{
- (command nproc) \
+ nproc \
|| sysctl -n hw.ncpu \
|| getconf _NPROCESSORS_ONLN \
|| echo 1