Skip to content

Commit

Permalink
Uptime (Linux): don't use syscall
Browse files Browse the repository at this point in the history
Fix #620
  • Loading branch information
CarterLi committed Nov 24, 2023
1 parent a846780 commit 41fed1d
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/detection/uptime/uptime_linux.c
@@ -1,13 +1,18 @@
#include "uptime.h"
#include "common/time.h"
#include "common/io/io.h"

#include <inttypes.h>

const char* ffDetectUptime(FFUptimeResult* result)
{
struct timespec uptime;
if (clock_gettime(CLOCK_BOOTTIME, &uptime) != 0)
return "clock_gettime(CLOCK_BOOTTIME) failed";
// #620
FF_AUTO_CLOSE_FILE FILE* uptime = fopen("/proc/uptime", "r");
if (!uptime) return "fopen(\"/proc/uptime\", \"r\") failed";

result->uptime = (uint64_t) uptime.tv_sec * 1000 + (uint64_t) uptime.tv_nsec / 1000000;
double sec;
if (fscanf(uptime, "%lf", &sec) > 0)
result->uptime = (uint64_t) (sec * 1000);

result->bootTime = ffTimeGetNow() + result->uptime;

Expand Down

0 comments on commit 41fed1d

Please sign in to comment.