summaryrefslogtreecommitdiff
path: root/src/shared/time-util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared/time-util.c')
-rw-r--r--src/shared/time-util.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/shared/time-util.c b/src/shared/time-util.c
index fc79c569f4..76ab143f34 100644
--- a/src/shared/time-util.c
+++ b/src/shared/time-util.c
@@ -22,6 +22,7 @@
#include <time.h>
#include <string.h>
#include <sys/timex.h>
+#include <sys/timerfd.h>
#include "util.h"
#include "time-util.h"
@@ -929,3 +930,21 @@ bool timezone_is_valid(const char *name) {
return true;
}
+
+clockid_t clock_boottime_or_monotonic(void) {
+ static clockid_t clock = -1;
+ int fd;
+
+ if (clock != -1)
+ return clock;
+
+ fd = timerfd_create(CLOCK_BOOTTIME, TFD_NONBLOCK|TFD_CLOEXEC);
+ if (fd < 0)
+ clock = CLOCK_MONOTONIC;
+ else {
+ safe_close(fd);
+ clock = CLOCK_BOOTTIME;
+ }
+
+ return clock;
+}