summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/time-util.c13
-rw-r--r--src/shared/time-util.h2
2 files changed, 15 insertions, 0 deletions
diff --git a/src/shared/time-util.c b/src/shared/time-util.c
index 860be61e8b..4b4cd7a270 100644
--- a/src/shared/time-util.c
+++ b/src/shared/time-util.c
@@ -21,6 +21,7 @@
#include <time.h>
#include <string.h>
+#include <sys/timex.h>
#include "util.h"
#include "time-util.h"
@@ -792,3 +793,15 @@ int parse_nsec(const char *t, nsec_t *nsec) {
return 0;
}
+
+bool ntp_synced(void) {
+ struct timex txc = {};
+
+ if (adjtimex(&txc) < 0)
+ return false;
+
+ if (txc.status & STA_UNSYNC)
+ return false;
+
+ return true;
+}
diff --git a/src/shared/time-util.h b/src/shared/time-util.h
index 7660fe1872..a51317dbd6 100644
--- a/src/shared/time-util.h
+++ b/src/shared/time-util.h
@@ -84,3 +84,5 @@ int parse_timestamp(const char *t, usec_t *usec);
int parse_sec(const char *t, usec_t *usec);
int parse_nsec(const char *t, nsec_t *nsec);
+
+bool ntp_synced(void);