summaryrefslogtreecommitdiffstats
path: root/src/detection/loadavg/loadavg_bsd.c
diff options
context:
space:
mode:
authorsumuel <samuel@yakubos.org>2026-08-17 20:44:55 +0000
committersumuel <samuel@yakubos.org>2026-08-17 20:44:55 +0000
commit76424950e373d3b04ac3dd13019151bfba3e8423 (patch)
tree4c3cfdbda039e592b9186be3e28f8d7cfd439e8a /src/detection/loadavg/loadavg_bsd.c
Add the files
Diffstat (limited to 'src/detection/loadavg/loadavg_bsd.c')
-rw-r--r--src/detection/loadavg/loadavg_bsd.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/detection/loadavg/loadavg_bsd.c b/src/detection/loadavg/loadavg_bsd.c
new file mode 100644
index 0000000..83896b2
--- /dev/null
+++ b/src/detection/loadavg/loadavg_bsd.c
@@ -0,0 +1,23 @@
+#include "detection/loadavg/loadavg.h"
+
+#include <sys/sysctl.h>
+
+#if __FreeBSD__ || __OpenBSD__ || __NetBSD__
+ #include <sys/types.h>
+ #include <sys/resource.h>
+ #if __FreeBSD__
+ #include <vm/vm_param.h>
+ #endif
+#endif
+
+const char* ffDetectLoadavg(double result[3]) {
+ 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;
+}