From: Bruno Haible Date: Mon, 10 Jun 2019 20:11:11 +0000 (+0200) Subject: nproc: Ensure nproc(NPROC_ALL) ≥ nproc(NPROC_CURRENT) with glibc ≥ 2.26. X-Git-Tag: v1.0~4877 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=5dd3e60c55345c3c477492323a4395799e30e02b;p=gnulib.git nproc: Ensure nproc(NPROC_ALL) ≥ nproc(NPROC_CURRENT) with glibc ≥ 2.26. Reported by Nikita Ermakov in . * lib/nproc.c (num_processors_ignoring_omp): Treat a return value of sysconf (_SC_NPROCESSORS_CONF) == 2 like a return value == 1. --- diff --git a/ChangeLog b/ChangeLog index 217779ef3d..18aecf7d2d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2019-06-10 Bruno Haible + + nproc: Ensure nproc(NPROC_ALL) ≥ nproc(NPROC_CURRENT) with glibc ≥ 2.26. + Reported by Nikita Ermakov in + . + * lib/nproc.c (num_processors_ignoring_omp): Treat a return value of + sysconf (_SC_NPROCESSORS_CONF) == 2 like a return value == 1. + 2019-06-10 Bruno Haible posix_spawn_file_actions_addchdir: Fix possible use-after-free bug. diff --git a/lib/nproc.c b/lib/nproc.c index 77b8760271..b11690b570 100644 --- a/lib/nproc.c +++ b/lib/nproc.c @@ -216,8 +216,9 @@ num_processors_ignoring_omp (enum nproc_query query) Note! On Linux systems with glibc, the first and second number come from the /sys and /proc file systems (see glibc/sysdeps/unix/sysv/linux/getsysstats.c). - In some situations these file systems are not mounted, and the sysconf - call returns 1, which does not reflect the reality. */ + In some situations these file systems are not mounted, and the sysconf call + returns 1 or 2 (), + which does not reflect the reality. */ if (query == NPROC_CURRENT) { @@ -249,13 +250,13 @@ num_processors_ignoring_omp (enum nproc_query query) /* On Linux systems with glibc, this information comes from the /sys and /proc file systems (see glibc/sysdeps/unix/sysv/linux/getsysstats.c). In some situations these file systems are not mounted, and the - sysconf call returns 1. But we wish to guarantee that + sysconf call returns 1 or 2. But we wish to guarantee that num_processors (NPROC_ALL) >= num_processors (NPROC_CURRENT). */ - if (nprocs == 1) + if (nprocs == 1 || nprocs == 2) { unsigned long nprocs_current = num_processors_via_affinity_mask (); - if (nprocs_current > 0) + if (/* nprocs_current > 0 && */ nprocs_current > nprocs) nprocs = nprocs_current; } # endif