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:
Jianghua Yang 2015-08-29 15:54:23 +08:00 committed by Saúl Ibarra Corretgé
parent 9ef523e281
commit 030b6e1a40

View File

@ -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;
}