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