freebsd: obtain true uptime through clock_gettime()
Obtain true uptime through clock_gettime() instead of subtracting 'bootime' from 'now'. PR-URL: https://github.com/libuv/libuv/pull/497 Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
This commit is contained in:
parent
9ef523e281
commit
030b6e1a40
@ -240,17 +240,13 @@ error:
|
||||
|
||||
|
||||
int uv_uptime(double* uptime) {
|
||||
time_t now;
|
||||
struct timeval info;
|
||||
size_t size = sizeof(info);
|
||||
static int which[] = {CTL_KERN, KERN_BOOTTIME};
|
||||
|
||||
if (sysctl(which, 2, &info, &size, NULL, 0))
|
||||
int r;
|
||||
struct timespec sp;
|
||||
r = clock_gettime(CLOCK_MONOTONIC, &sp);
|
||||
if (r)
|
||||
return -errno;
|
||||
|
||||
now = time(NULL);
|
||||
|
||||
*uptime = (double)(now - info.tv_sec);
|
||||
*uptime = sp.tv_sec;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user