2017-09-17 23:45:03 +08:00
|
|
|
/* See LICENSE file for copyright and license details. */
|
2018-07-07 17:08:26 +08:00
|
|
|
#include <stdint.h>
|
2018-03-20 07:48:10 +08:00
|
|
|
#include <stdio.h>
|
2018-07-07 05:47:52 +08:00
|
|
|
#include <time.h>
|
2017-09-17 22:18:17 +08:00
|
|
|
|
2022-10-27 04:14:53 +08:00
|
|
|
#include "../slstatus.h"
|
2022-10-28 05:18:30 +08:00
|
|
|
#include "../util.h"
|
2017-09-17 22:18:17 +08:00
|
|
|
|
2019-02-05 10:44:37 +08:00
|
|
|
#if defined(CLOCK_BOOTTIME)
|
|
|
|
#define UPTIME_FLAG CLOCK_BOOTTIME
|
|
|
|
#elif defined(CLOCK_UPTIME)
|
|
|
|
#define UPTIME_FLAG CLOCK_UPTIME
|
|
|
|
#else
|
|
|
|
#define UPTIME_FLAG CLOCK_MONOTONIC
|
|
|
|
#endif
|
|
|
|
|
2018-06-02 02:10:34 +08:00
|
|
|
const char *
|
2022-10-27 04:16:05 +08:00
|
|
|
uptime(const char *unused)
|
2018-05-02 14:41:06 +08:00
|
|
|
{
|
2019-02-05 10:44:37 +08:00
|
|
|
char warn_buf[256];
|
2018-07-07 16:50:25 +08:00
|
|
|
uintmax_t h, m;
|
2018-06-02 02:10:34 +08:00
|
|
|
struct timespec uptime;
|
2018-07-07 05:47:52 +08:00
|
|
|
|
2019-02-05 10:44:37 +08:00
|
|
|
if (clock_gettime(UPTIME_FLAG, &uptime) < 0) {
|
|
|
|
snprintf(warn_buf, 256, "clock_gettime %d", UPTIME_FLAG);
|
|
|
|
warn(warn_buf);
|
2018-06-02 02:10:34 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
2018-07-07 05:47:52 +08:00
|
|
|
|
2018-06-02 02:10:34 +08:00
|
|
|
h = uptime.tv_sec / 3600;
|
|
|
|
m = uptime.tv_sec % 3600 / 60;
|
2018-07-07 05:47:52 +08:00
|
|
|
|
2018-07-07 17:08:26 +08:00
|
|
|
return bprintf("%juh %jum", h, m);
|
2018-05-02 14:41:06 +08:00
|
|
|
}
|