From 5dd3e60c55345c3c477492323a4395799e30e02b Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Mon, 10 Jun 2019 22:11:11 +0200 Subject: [PATCH] =?utf8?q?nproc:=20Ensure=20nproc(NPROC=5FALL)=20=E2=89=A5?= =?utf8?q?=20nproc(NPROC=5FCURRENT)=20with=20glibc=20=E2=89=A5=202.26.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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. --- ChangeLog | 8 ++++++++ lib/nproc.c | 11 ++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) 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 -- 2.39.5