diff options
| author | sumuel <samuel@yakubos.org> | 2026-08-17 20:44:55 +0000 |
|---|---|---|
| committer | sumuel <samuel@yakubos.org> | 2026-08-17 20:44:55 +0000 |
| commit | 76424950e373d3b04ac3dd13019151bfba3e8423 (patch) | |
| tree | 4c3cfdbda039e592b9186be3e28f8d7cfd439e8a /src/detection/uptime/uptime_linux.c | |
Add the files
Diffstat (limited to 'src/detection/uptime/uptime_linux.c')
| -rw-r--r-- | src/detection/uptime/uptime_linux.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/detection/uptime/uptime_linux.c b/src/detection/uptime/uptime_linux.c new file mode 100644 index 0000000..75c7768 --- /dev/null +++ b/src/detection/uptime/uptime_linux.c @@ -0,0 +1,38 @@ +#include "uptime.h" +#include "common/time.h" +#include "common/io.h" + +#include <inttypes.h> + +const char* ffDetectUptime(FFUptimeResult* result) { +#ifndef __ANDROID__ // cat: /proc/uptime: Permission denied + + // #620 + char buf[64]; + ssize_t nRead = ffReadFileData("/proc/uptime", ARRAY_SIZE(buf) - 1, buf); + if (nRead > 0) { + buf[nRead] = '\0'; + + char* err = NULL; + double sec = strtod(buf, &err); + if (err != buf) { + result->uptime = (uint64_t) (sec * 1000); + result->bootTime = ffTimeGetNow() - result->uptime; + return NULL; + } + } + +#endif +#ifndef __GNU__ + struct timespec uptime; + if (clock_gettime(CLOCK_BOOTTIME, &uptime) != 0) { + return "clock_gettime(CLOCK_BOOTTIME) failed"; + } + + result->uptime = (uint64_t) uptime.tv_sec * 1000 + (uint64_t) uptime.tv_nsec / 1000000; + result->bootTime = ffTimeGetNow() - result->uptime; + return NULL; +#else + return "read(/proc/uptime) failed"; +#endif +} |