740af9
From 026e7f75e549280d43cdb4c8a1b2faa6e9db0fa3 Mon Sep 17 00:00:00 2001
740af9
From: Panu Matilainen <pmatilai@redhat.com>
740af9
Date: Wed, 15 Nov 2023 09:24:28 +0200
740af9
Subject: [PATCH 1/2] Fix %{getncpus proc/thread} potentially returning zero
740af9
740af9
Add the missing sanity check/fixup for memory starved systems where
740af9
we end up returning zero cpus. Should've been in commit
740af9
deaebd0c89a6d453bb971fd8f5a3b858e7a95733 originally.
740af9
740af9
Reported in https://issues.redhat.com/browse/RHEL-16557
740af9
---
740af9
 rpmio/macro.c | 3 +++
740af9
 1 file changed, 3 insertions(+)
740af9
740af9
diff --git a/rpmio/macro.c b/rpmio/macro.c
740af9
index 1cccaa98a88c56ed27701f820be01c3f8e7615d1..98067442555f7c458ea4976d96b5438db01bd031 100644
740af9
--- a/rpmio/macro.c
740af9
+++ b/rpmio/macro.c
740af9
@@ -1255,6 +1255,9 @@ static void doGetncpus(MacroBuf mb, rpmMacroEntry me, ARGV_t argv, size_t *parse
740af9
 	if (mcpus < ncpus)
740af9
 	    ncpus = mcpus;
740af9
     }
740af9
+    /* Ensure at least one CPU, no matter how starved */
740af9
+    if (ncpus < 1)
740af9
+	ncpus = 1;
740af9
 
740af9
     sprintf(buf, "%u", ncpus);
740af9
     mbAppendStr(mb, buf);
740af9
-- 
740af9
2.43.0
740af9