From e7630aef3411a93dee70e7e809c9183f0560af3f Mon Sep 17 00:00:00 2001 From: Carter Li Date: Mon, 28 Oct 2024 15:19:05 +0800 Subject: [PATCH] NetBSD: support CPUUsage / Memory / Swap --- CMakeLists.txt | 6 +++--- src/detection/cpuusage/cpuusage_bsd.c | 12 ++++++++---- src/detection/memory/memory_obsd.c | 4 ++++ 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5359ee9e6..e4d2281d0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -685,7 +685,7 @@ elseif(NetBSD) src/detection/chassis/chassis_nbsd.c src/detection/cpu/cpu_bsd.c src/detection/cpucache/cpucache_nosupport.c - src/detection/cpuusage/cpuusage_nosupport.c + src/detection/cpuusage/cpuusage_bsd.c src/detection/cursor/cursor_linux.c src/detection/disk/disk_nosupport.c src/detection/dns/dns_linux.c @@ -720,7 +720,7 @@ elseif(NetBSD) src/detection/localip/localip_linux.c src/detection/gamepad/gamepad_nosupport.c src/detection/media/media_linux.c - src/detection/memory/memory_bsd.c + src/detection/memory/memory_obsd.c src/detection/mouse/mouse_nosupport.c src/detection/netio/netio_nosupport.c src/detection/opengl/opengl_linux.c @@ -730,7 +730,7 @@ elseif(NetBSD) src/detection/processes/processes_nosupport.c src/detection/gtk_qt/qt.c src/detection/sound/sound_nosupport.c - src/detection/swap/swap_nosupport.c + src/detection/swap/swap_obsd.c src/detection/terminalfont/terminalfont_linux.c src/detection/terminalshell/terminalshell_linux.c src/detection/terminalsize/terminalsize_linux.c diff --git a/src/detection/cpuusage/cpuusage_bsd.c b/src/detection/cpuusage/cpuusage_bsd.c index a04c05b75..5b9312d9e 100644 --- a/src/detection/cpuusage/cpuusage_bsd.c +++ b/src/detection/cpuusage/cpuusage_bsd.c @@ -6,15 +6,19 @@ #include #include -#ifdef __OpenBSD__ +#if __OpenBSD__ || __NetBSD__ #include #endif const char* ffGetCpuUsageInfo(FFlist* cpuTimes) { size_t neededLength = 0; -#ifdef __OpenBSD__ - int ctls[] = {CTL_KERN, KERN_CPTIME}; +#if __OpenBSD__|| __NetBSD__ + #ifdef KERN_CPTIME + int ctls[] = {CTL_KERN, KERN_CPTIME}; + #else + int ctls[] = {CTL_KERN, KERN_CP_TIME}; + #endif if (sysctl(ctls, 2, NULL, &neededLength, NULL, 0) != 0) return "sysctl({CTL_KERN, KERN_CPTIME}, 2, NULL) failed"; #else @@ -27,7 +31,7 @@ const char* ffGetCpuUsageInfo(FFlist* cpuTimes) FF_AUTO_FREE uint64_t (*cpTimes)[CPUSTATES] = malloc(neededLength); -#ifdef __OpenBSD__ +#if __OpenBSD__ || __NetBSD__ if (sysctl(ctls, 2, cpTimes, &neededLength, NULL, 0) != 0) return "sysctl({CTL_KERN, KERN_CPTIME}, 2, NULL) failed"; #else diff --git a/src/detection/memory/memory_obsd.c b/src/detection/memory/memory_obsd.c index 9efc21ead..3dda7656a 100644 --- a/src/detection/memory/memory_obsd.c +++ b/src/detection/memory/memory_obsd.c @@ -3,6 +3,10 @@ #include +#if __NetBSD__ + #include +#endif + const char* ffDetectMemory(FFMemoryResult* ram) { struct uvmexp buf;