From 5b38c1a3b807a7e7094b895635177a40b4bd257f Mon Sep 17 00:00:00 2001 From: Arran Cudbard-Bell Date: Wed, 31 May 2023 18:17:45 -0400 Subject: [PATCH] Warn when we can't retrieve a core count --- src/lib/server/main_config.c | 4 ++++ src/lib/util/hw.c | 10 ++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/lib/server/main_config.c b/src/lib/server/main_config.c index 7ab4be48c957c..a1377ac0a40e4 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 c6a92646fdd0d..17ef9d1157369 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_const("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);