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