aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/vmstat
diff options
context:
space:
mode:
authorAndre Oppermann <andre@FreeBSD.org>2005-10-17 15:37:22 +0000
committerAndre Oppermann <andre@FreeBSD.org>2005-10-17 15:37:22 +0000
commita21cbcb876be978fa69925a758fcb12c4153e960 (patch)
tree9623cd1f5d463a40b1bd4dc6d6ba5383ea694375 /usr.bin/vmstat
parent4773bde95ef83fea66b1677ee49d469cf1800888 (diff)
downloadsrc-a21cbcb876be978fa69925a758fcb12c4153e960.tar.gz
src-a21cbcb876be978fa69925a758fcb12c4153e960.zip
Obtain true uptime through clock_gettime(CLOCK_MONOTONIC, struct *timespec)
instead of subtracting 'bootime' from 'now'. Sponsored by: TCP/IP Optimization Fundraise 2005
Notes
Notes: svn path=/head/; revision=151417
Diffstat (limited to 'usr.bin/vmstat')
-rw-r--r--usr.bin/vmstat/vmstat.c20
1 files changed, 4 insertions, 16 deletions
diff --git a/usr.bin/vmstat/vmstat.c b/usr.bin/vmstat/vmstat.c
index f52f7bfdf148..605319c68dcd 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);
}