Handle the case when there is no processor info in /proc/cpuinfo

`grep -c` would correctly output "0", which is handled specially later
on, but would also exit with a nonzero status which would abort the
script. Piping the output to `wc` to do the counting makes the exit
status of grep irrelevant.

Fixes #447
This commit is contained in:
Kelley Reynolds 2013-11-13 08:39:52 -05:00 committed by Mislav Marohnić
parent bc9adfdd5d
commit 35f9c62d1d

View file

@ -101,7 +101,7 @@ num_cpu_cores() {
if [ "Darwin" = "$(uname -s)" ]; then
num="$(sysctl -n hw.ncpu 2>/dev/null || true)"
elif [ -r /proc/cpuinfo ]; then
num="$(grep -c ^processor /proc/cpuinfo)"
num="$(grep ^processor /proc/cpuinfo | wc -l)"
[ "$num" -gt 0 ] || num=""
fi
echo "${num:-2}"