summaryrefslogtreecommitdiffstats
path: root/btimed.c
diff options
context:
space:
mode:
authorNate Straz <nstraz@redhat.com>2006-11-02 23:21:42 +0000
committerNathan Straz <nstraz@redhat.com>2008-09-23 09:37:46 -0400
commit9f97033415fa59eed422d48a1e788e2e74bcbb78 (patch)
tree58ba976efb430ef2b86b757b574267bcef9c69e5 /btimed.c
parente48d67a9c8ae00f613cc2cb449af6486bd8ba484 (diff)
downloadqarsh-9f97033415fa59eed422d48a1e788e2e74bcbb78.tar.gz
qarsh-9f97033415fa59eed422d48a1e788e2e74bcbb78.tar.xz
qarsh-9f97033415fa59eed422d48a1e788e2e74bcbb78.zip
Use time() - times() instead of reading /proc/stat.
Diffstat (limited to 'btimed.c')
-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;
}