From 3ba3d6fa6f5f2c3075041a1a0db4d07f86a4a517 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Thu, 27 Nov 2014 19:44:20 -0200 Subject: [PATCH] Add uptime calculation code. --- Makefile.am | 6 ++---- freebsd/Platform.c | 18 ++++++++++++++++++ freebsd/Platform.h | 1 + 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/Makefile.am b/Makefile.am index 15e8e1f1..0b36db70 100644 --- a/Makefile.am +++ b/Makefile.am @@ -43,12 +43,10 @@ endif if HTOP_FREEBSD myhtopplatsources = freebsd/Platform.c freebsd/FreeBSDProcessList.c \ -freebsd/FreeBSDCRT.c \ -freebsd/UptimeMeter.c +freebsd/FreeBSDCRT.c myhtopplatheaders = freebsd/Platform.h freebsd/FreeBSDProcessList.h \ -freebsd/FreeBSDCRT.h \ -freebsd/UptimeMeter.h +freebsd/FreeBSDCRT.h endif if HTOP_UNSUPPORTED diff --git a/freebsd/Platform.c b/freebsd/Platform.c index acc69595..b004b298 100644 --- a/freebsd/Platform.c +++ b/freebsd/Platform.c @@ -17,6 +17,11 @@ in the source distribution for its full text. #include "ClockMeter.h" #include "HostnameMeter.h" +#include +#include +#include +#include + /*{ #include "Action.h" }*/ @@ -46,3 +51,16 @@ MeterClass* Platform_meterTypes[] = { NULL }; +int Platform_getUptime() { + struct timeval bootTime, currTime; + int mib[2] = { CTL_KERN, KERN_BOOTTIME }; + size_t size = sizeof(bootTime); + + int err = sysctl(mib, 2, &bootTime, &size, NULL, 0); + if (err) { + return -1; + } + gettimeofday(&currTime, NULL); + + return (int) difftime(currTime.tv_sec, bootTime.tv_sec); +} diff --git a/freebsd/Platform.h b/freebsd/Platform.h index dc468b81..7435f631 100644 --- a/freebsd/Platform.h +++ b/freebsd/Platform.h @@ -15,5 +15,6 @@ void Platform_setBindings(Htop_Action* keys); extern MeterClass* Platform_meterTypes[]; +int Platform_getUptime(); #endif