From b62ad16aa6c2224cde7ca7bd4e3e7f22b67a272d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Thu, 9 May 2024 09:20:18 +0800 Subject: [PATCH] Loadavg (BSD): use sysctl --- src/detection/loadavg/loadavg_bsd.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/detection/loadavg/loadavg_bsd.c b/src/detection/loadavg/loadavg_bsd.c index 69a38e7db..95c0c49cb 100644 --- a/src/detection/loadavg/loadavg_bsd.c +++ b/src/detection/loadavg/loadavg_bsd.c @@ -1,8 +1,14 @@ #include "detection/loadavg/loadavg.h" -#include +#include const char* ffDetectLoadavg(double result[3]) { - return getloadavg(result, 3) < 0 ? "getloadavg() failed" : NULL; + struct loadavg load; + size_t size = sizeof(load); + if (sysctl((int []) { CTL_VM, VM_LOADAVG }, 2, &load, &size, NULL, 0) < 0) + return "sysctl({CTL_VM, VM_LOADAVG}) failed"; + for (int i = 0; i < 3; i++) + result[i] = (double) load.ldavg[i] / (double) load.fscale; + return NULL; }