Skip to content

Commit

Permalink
Fix %{getncpus proc/thread} potentially returning zero
Browse files Browse the repository at this point in the history
Add the missing sanity check/fixup for memory starved systems where
we end up returning zero cpus. Should've been in commit
deaebd0 originally.

Reported in https://issues.redhat.com/browse/RHEL-16557
  • Loading branch information
pmatilai committed Nov 15, 2023
1 parent 0091214 commit 6714ec7
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions rpmio/macro.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 6714ec7

Please sign in to comment.