summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--btimed.c27
1 files 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 <errno.h>
#include <signal.h>
#include <syslog.h>
-#include <sys/types.h>
-#include <sys/stat.h>
#include <sys/wait.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
+#include <time.h>
+#include <sys/times.h>
#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;
}