summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authorandre <andre@FreeBSD.org>2005-10-17 15:37:22 +0000
committerandre <andre@FreeBSD.org>2005-10-17 15:37:22 +0000
commit74d3ddeb3259da19ebc6183d77ed2e47ac50eae1 (patch)
tree9623cd1f5d463a40b1bd4dc6d6ba5383ea694375 /usr.bin
parent58c0a29b889898bebdd9e7edd7455c798986821e (diff)
downloadFreeBSD-src-74d3ddeb3259da19ebc6183d77ed2e47ac50eae1.zip
FreeBSD-src-74d3ddeb3259da19ebc6183d77ed2e47ac50eae1.tar.gz
Obtain true uptime through clock_gettime(CLOCK_MONOTONIC, struct *timespec)
instead of subtracting 'bootime' from 'now'. Sponsored by: TCP/IP Optimization Fundraise 2005
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/vmstat/vmstat.c20
-rw-r--r--usr.bin/w/w.c12
2 files changed, 7 insertions, 25 deletions
diff --git a/usr.bin/vmstat/vmstat.c b/usr.bin/vmstat/vmstat.c
index f52f7bf..605319c 100644
--- a/usr.bin/vmstat/vmstat.c
+++ b/usr.bin/vmstat/vmstat.c
@@ -396,26 +396,14 @@ getdrivedata(char **argv)
static long
getuptime(void)
{
- static struct timeval boottime;
- static time_t now;
+ struct timespec sp;
time_t uptime;
- if (boottime.tv_sec == 0) {
- if (kd != NULL) {
- kread(X_BOOTTIME, &boottime, sizeof(boottime));
- } else {
- size_t size;
-
- size = sizeof(boottime);
- mysysctl("kern.boottime", &boottime, &size, NULL, 0);
- if (size != sizeof(boottime))
- errx(1, "kern.boottime size mismatch");
- }
- }
- (void)time(&now);
- uptime = now - boottime.tv_sec;
+ (void)clock_gettime(CLOCK_MONOTONIC, &sp);
+ uptime = sp.tv_sec;
if (uptime <= 0 || uptime > 60*60*24*365*10)
errx(1, "time makes no sense; namelist must be wrong");
+
return(uptime);
}
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;
OpenPOWER on IntegriCloud