]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Warn when we can't retrieve a core count
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 31 May 2023 22:17:45 +0000 (18:17 -0400)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 31 May 2023 22:19:59 +0000 (18:19 -0400)
src/lib/server/main_config.c
src/lib/util/hw.c

index 7ab4be48c957cec44becfc37c7dd4bc5f676d402..a1377ac0a40e49e6535d0fccff198dd7ee4787e2 100644 (file)
@@ -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
index c6a92646fdd0dae2edb47f5723d602b3a7d59fa7..cdb7fccad8e2d446c6d01e1eaf87753bf3377945 100644 (file)
@@ -25,6 +25,9 @@
 #define CORES_DEFAULT          1
 
 #include <freeradius-devel/util/hw.h>
+#include <freeradius-devel/util/syserror.h>
+#include <freeradius-devel/util/strerror.h>
+#include <errno.h>
 
 #if defined(__APPLE__) || defined(__FreeBSD__)
 #include <sys/sysctl.h>
@@ -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);