2017-09-17 15:45:03 +00:00
|
|
|
/* See LICENSE file for copyright and license details. */
|
2018-03-19 23:48:10 +00:00
|
|
|
#include <stdio.h>
|
2018-03-18 22:26:13 +00:00
|
|
|
#ifdef __linux__
|
2017-09-17 14:18:17 +00:00
|
|
|
#include <sys/sysinfo.h>
|
2018-03-19 23:48:10 +00:00
|
|
|
#elif __OpenBSD__
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#endif
|
2017-09-17 14:18:17 +00:00
|
|
|
|
2017-09-24 13:33:01 +00:00
|
|
|
#include "../util.h"
|
2017-09-17 14:18:17 +00:00
|
|
|
|
|
|
|
const char *
|
|
|
|
uptime(void)
|
|
|
|
{
|
2018-03-19 23:48:10 +00:00
|
|
|
int h;
|
|
|
|
int m;
|
|
|
|
int uptime = 0;
|
|
|
|
#ifdef __linux__
|
2017-09-17 14:18:17 +00:00
|
|
|
struct sysinfo info;
|
|
|
|
|
|
|
|
sysinfo(&info);
|
2018-03-19 23:48:10 +00:00
|
|
|
uptime = info.uptime;
|
|
|
|
#elif __OpenBSD__
|
|
|
|
int mib[2];
|
|
|
|
size_t size;
|
|
|
|
time_t now;
|
|
|
|
struct timeval boottime;
|
|
|
|
|
|
|
|
time(&now);
|
|
|
|
|
|
|
|
mib[0] = CTL_KERN;
|
|
|
|
mib[1] = KERN_BOOTTIME;
|
|
|
|
|
|
|
|
size = sizeof(boottime);
|
|
|
|
|
|
|
|
if (sysctl(mib, 2, &boottime, &size, NULL, 0) != -1)
|
|
|
|
uptime = now - boottime.tv_sec;
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
#endif
|
|
|
|
h = uptime / 3600;
|
|
|
|
m = (uptime - h * 3600) / 60;
|
2017-09-17 14:18:17 +00:00
|
|
|
|
|
|
|
return bprintf("%dh %dm", h, m);
|
|
|
|
}
|