From 74d3ddeb3259da19ebc6183d77ed2e47ac50eae1 Mon Sep 17 00:00:00 2001 From: andre Date: Mon, 17 Oct 2005 15:37:22 +0000 Subject: Obtain true uptime through clock_gettime(CLOCK_MONOTONIC, struct *timespec) instead of subtracting 'bootime' from 'now'. Sponsored by: TCP/IP Optimization Fundraise 2005 --- usr.bin/w/w.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'usr.bin/w/w.c') diff --git a/usr.bin/w/w.c b/usr.bin/w/w.c index 72559ba..8f69ab6 100644 --- a/usr.bin/w/w.c +++ b/usr.bin/w/w.c @@ -424,9 +424,8 @@ pr_header(time_t *nowp, int nusers) { double avenrun[3]; time_t uptime; + struct timespec tp; int days, hrs, i, mins, secs; - int mib[2]; - size_t size; char buf[256]; /* @@ -437,14 +436,9 @@ pr_header(time_t *nowp, int nusers) (void)printf("%s ", buf); /* * Print how long system has been up. - * (Found by looking getting "boottime" from the kernel) */ - mib[0] = CTL_KERN; - mib[1] = KERN_BOOTTIME; - size = sizeof(boottime); - if (sysctl(mib, 2, &boottime, &size, NULL, 0) != -1 && - boottime.tv_sec != 0) { - uptime = now - boottime.tv_sec; + if (clock_gettime(CLOCK_MONOTONIC, &tp) != -1) { + uptime = tp.tv_sec; if (uptime > 60) uptime += 30; days = uptime / 86400; -- cgit v1.1