summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Straz <nstraz@redhat.com>2008-10-14 12:43:52 -0400
committerNathan Straz <nstraz@redhat.com>2008-10-14 12:43:52 -0400
commit8a27c58c9e809b7b175af7f6e91360766e20184c (patch)
tree08c4614206bc26450ea22f37e97f13b9d211740e
parent8f2a8ffe94c2ef480a77dbbb3c40021571aa404e (diff)
downloadqarsh-8a27c58c9e809b7b175af7f6e91360766e20184c.zip
qarsh-8a27c58c9e809b7b175af7f6e91360766e20184c.tar.gz
qarsh-8a27c58c9e809b7b175af7f6e91360766e20184c.tar.xz
[btimed] Use /proc/uptime when available
It turns out the boot time being returned to btimec is has not been correct for quite a while. There was probably a change to HZ which isn't reflected properly in _SC_CLK_TCK. This needs some more error checking, but it works for now.
-rw-r--r--btimed.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/btimed.c b/btimed.c
index 68a045a..83a5af6 100644
--- a/btimed.c
+++ b/btimed.c
@@ -112,9 +112,22 @@ get_btime(void)
{
unsigned int btime = 0;
long hertz = sysconf(_SC_CLK_TCK);
- struct tms tms;
- btime = time(0) - (times(&tms) / hertz);
+ btime = time(0);
+
+ if (access("/proc/uptime", F_OK | R_OK) == 0) {
+ FILE *proc_uptime;
+ unsigned long upsec = 0;
+ proc_uptime = fopen("/proc/uptime", "r");
+ fscanf(proc_uptime, "%lu.%*u %*u.%*u\n", &upsec);
+ fclose(proc_uptime);
+
+ btime -= upsec;
+ } else {
+ struct tms tms;
+
+ btime -= (times(&tms) / hertz);
+ }
btime = btime - (btime % 5) + 5;
return btime;
}