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