From ebab281471296b4b7aace255e11ba0ec1e807f5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Wed, 11 Oct 2023 21:09:43 +0800 Subject: [PATCH] Processes (Linux): fix implementation `sysinfo.procs` reports number of all running threads, instead of processes --- CHANGELOG.md | 1 + src/detection/processes/processes_linux.c | 22 +++++++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7effc2ceb..2a663a8f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ Bugfixes: * Fix possible crashes caused by uninitialized strings (Users, Windows) * Improve support of `--help *-format` and several bugs are found and fixed * Don't incorrectly print `No active sound devices found` when using a non-controllable sound device (Sound, macOS) +* Fix implementation processes counting (Processes, Linux) Logo: * Add Chimera Linux diff --git a/src/detection/processes/processes_linux.c b/src/detection/processes/processes_linux.c index 7e17fbc9a..cff71038c 100644 --- a/src/detection/processes/processes_linux.c +++ b/src/detection/processes/processes_linux.c @@ -1,13 +1,25 @@ #include "processes.h" -#include +#include "common/io/io.h" + +#include const char* ffDetectProcesses(uint32_t* result) { - struct sysinfo info; - if(sysinfo(&info) != 0) - return "sysinfo() failed"; + FF_AUTO_CLOSE_DIR DIR* dir = opendir("/proc"); + if(dir == NULL) + return "opendir(\"/proc\") failed"; + + uint32_t num = 0; + + struct dirent* entry; + while ((entry = readdir(dir)) != NULL) + { + if (entry->d_type == DT_DIR && isdigit(entry->d_name[0])) + ++num; + } + + *result = num; - *result = (uint32_t) info.procs; return NULL; }