From 76424950e373d3b04ac3dd13019151bfba3e8423 Mon Sep 17 00:00:00 2001 From: sumuel Date: Mon, 17 Aug 2026 20:44:55 +0000 Subject: Add the files --- src/detection/loadavg/loadavg_linux.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/detection/loadavg/loadavg_linux.c (limited to 'src/detection/loadavg/loadavg_linux.c') diff --git a/src/detection/loadavg/loadavg_linux.c b/src/detection/loadavg/loadavg_linux.c new file mode 100644 index 0000000..a169312 --- /dev/null +++ b/src/detection/loadavg/loadavg_linux.c @@ -0,0 +1,33 @@ +#include "detection/loadavg/loadavg.h" +#include "common/io.h" + +#include + +const char* ffDetectLoadavg(double result[3]) { +#ifndef __ANDROID__ // cat: /proc/loadavg: Permission denied + + // Don't use syscall for container compatibility. #620 + char buf[64]; + ssize_t nRead = ffReadFileData("/proc/loadavg", sizeof(buf) - 1, buf); + if (nRead > 0) { + buf[nRead] = '\0'; + + if (sscanf(buf, "%lf%lf%lf", &result[0], &result[1], &result[2]) == 3) { + return NULL; + } + } + +#endif +#ifndef __GNU__ + // getloadavg requires higher ANDROID_API version + struct sysinfo si; + if (sysinfo(&si) < 0) { + return "sysinfo() failed"; + } + + for (int i = 0; i < 3; i++) { + result[i] = (double) si.loads[i] / (1 << SI_LOAD_SHIFT); + } +#endif + return NULL; +} -- cgit v1.2.3