From b5897f784f2f87eeb98d2974b479bcacf09d7205 Mon Sep 17 00:00:00 2001 From: Carter Li Date: Mon, 24 Aug 2026 22:43:37 +0800 Subject: [PATCH] Processes (GNU): uses native impl --- CMakeLists.txt | 2 +- src/detection/processes/processes_gnu.c | 33 +++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 src/detection/processes/processes_gnu.c diff --git a/CMakeLists.txt b/CMakeLists.txt index d8313c345..94177dc51 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1388,7 +1388,7 @@ elseif(GNU) src/detection/packages/packages_linux.c src/detection/packages/packages_nix.c src/detection/poweradapter/poweradapter_nosupport.c - src/detection/processes/processes_linux.c + src/detection/processes/processes_gnu.c src/detection/gtk_qt/qt.c src/detection/sound/sound_linux.c src/detection/swap/swap_linux.c diff --git a/src/detection/processes/processes_gnu.c b/src/detection/processes/processes_gnu.c new file mode 100644 index 000000000..7dc739d2b --- /dev/null +++ b/src/detection/processes/processes_gnu.c @@ -0,0 +1,33 @@ +#include "processes.h" + +#include +#include + +const char* ffDetectProcesses(uint32_t* result) { + struct ps_context* context = nullptr; + if (ps_context_create(getproc(), &context) != 0) { + return "ps_context_create(getproc()) failed"; + } + + const char* error = nullptr; + struct proc_stat_list* list = nullptr; + if (proc_stat_list_create(context, &list) != 0) { + error = "proc_stat_list_create() failed"; + goto done; + } + + // No flags are needed; we only count the processes. + if (proc_stat_list_add_all(list, nullptr, nullptr) != 0) { + error = "proc_stat_list_add_all() failed"; + goto done; + } + + *result = (uint32_t) list->num_procs; + +done: + if (list) { + proc_stat_list_free(list); + } + ps_context_free(context); + return error; +}