From 9f97033415fa59eed422d48a1e788e2e74bcbb78 Mon Sep 17 00:00:00 2001 From: Nate Straz Date: Thu, 2 Nov 2006 23:21:42 +0000 Subject: Use time() - times() instead of reading /proc/stat. --- btimed.c | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/btimed.c b/btimed.c index acc8b69..67f9e30 100644 --- a/btimed.c +++ b/btimed.c @@ -25,12 +25,12 @@ #include #include #include -#include -#include #include #include #include #include +#include +#include #include "btime_int.h" @@ -103,7 +103,7 @@ main(int argc, char **argv) * * get_btime -- * - * Return machine's boot time. + * Return machine's boot time rounded up to the nearest minute. * * Returns: * 0 on failure @@ -115,24 +115,11 @@ main(int argc, char **argv) static unsigned int get_btime(void) { - FILE *statf; - char line[1024]; unsigned int btime = 0; + long hertz = sysconf(_SC_CLK_TCK); + struct tms tms; - if ((statf = fopen("/proc/stat", "r")) == NULL) { - syslog(LOG_ERR, "/proc/stat open failure: %s\n", - strerror(errno)); - exit(1); - } - - while (fgets(line, 1024, statf) != NULL) { - if (strstr(line, "btime") != NULL) { - sscanf(line, "%*s%u", &btime); - } - - } - - fclose(statf); - + btime = time(0) - (times(&tms) / hertz); + btime = btime - (btime % 60) + 60; return btime; } -- cgit