From: Arran Cudbard-Bell Date: Wed, 31 May 2023 22:17:45 +0000 (-0400) Subject: Warn when we can't retrieve a core count X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fd3931aa20ce94e4e73474e63f95673a4956ce11;p=thirdparty%2Ffreeradius-server.git Warn when we can't retrieve a core count --- diff --git a/src/lib/server/main_config.c b/src/lib/server/main_config.c index 7ab4be48c95..a1377ac0a40 100644 --- a/src/lib/server/main_config.c +++ b/src/lib/server/main_config.c @@ -453,6 +453,10 @@ static int num_workers_dflt(CONF_PAIR **out, void *parent, CONF_SECTION *cs, fr_ main_config_t *conf = parent; value = fr_hw_num_cores_active(); + if (value < 0) { + cf_log_pwarn(parent, "Failed retrieving core count, defaulting to 1 worker"); + value = 1; + } /* * If we've got more than four times diff --git a/src/lib/util/hw.c b/src/lib/util/hw.c index c6a92646fdd..cdb7fccad8e 100644 --- a/src/lib/util/hw.c +++ b/src/lib/util/hw.c @@ -25,6 +25,9 @@ #define CORES_DEFAULT 1 #include +#include +#include +#include #if defined(__APPLE__) || defined(__FreeBSD__) #include @@ -96,13 +99,16 @@ uint32_t fr_hw_num_cores_active(void) * You'd think this'd be enough to quiet clang scan, * but it's not. */ - if (unlikely((tsibs == 0) || (lcores == 0) || (lcores > tsibs))) return 1; + if (unlikely((tsibs == 0) || (lcores == 0) || (lcores > tsibs))) { + fr_strerror_printf("Failed retrieving cpu topology info: %s", fr_syserror(errno)); + return -1; + } #ifdef STATIC_ANALYZER /* * Prevent static analyzer from warning about divide by zero */ - if ((tsibs / lcores) == 0) return 1; + if ((tsibs / lcores) == 0) return -1; #endif return lcores / (tsibs / lcores);