diff options
author | Nathan Straz <nstraz@redhat.com> | 2008-10-14 12:43:52 -0400 |
---|---|---|
committer | Nathan Straz <nstraz@redhat.com> | 2008-10-14 12:43:52 -0400 |
commit | 8a27c58c9e809b7b175af7f6e91360766e20184c (patch) | |
tree | 08c4614206bc26450ea22f37e97f13b9d211740e /btimed.c | |
parent | 8f2a8ffe94c2ef480a77dbbb3c40021571aa404e (diff) | |
download | qarsh-8a27c58c9e809b7b175af7f6e91360766e20184c.tar.gz qarsh-8a27c58c9e809b7b175af7f6e91360766e20184c.tar.xz qarsh-8a27c58c9e809b7b175af7f6e91360766e20184c.zip |
[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.
Diffstat (limited to 'btimed.c')
-rw-r--r-- | btimed.c | 17 |
1 files changed, 15 insertions, 2 deletions
@@ -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; } |