Fix %{getncpus proc/thread} potentially returning zero

Add the missing sanity check/fixup for memory starved systems where
we end up returning zero cpus. Should've been in commit
deaebd0c89 originally.

Reported in https://issues.redhat.com/browse/RHEL-16557
This commit is contained in:
Panu Matilainen 2023-11-15 09:24:28 +02:00
parent 0091214d2f
commit 6714ec7068
1 changed files with 3 additions and 0 deletions

View File

@ -1253,6 +1253,9 @@ static void doGetncpus(rpmMacroBuf mb, rpmMacroEntry me, ARGV_t argv, size_t *pa
if (mcpus < ncpus)
ncpus = mcpus;
}
/* Ensure at least one CPU, no matter how starved */
if (ncpus < 1)
ncpus = 1;
sprintf(buf, "%u", ncpus);
rpmMacroBufAppendStr(mb, buf);