chiark / gitweb /
timedated: expose time and NTP sync flag via the bus
[elogind.git] / src / shared / time-util.c
index 860be61e8b7b8af74a9e13c9b50da782776bf182..4b4cd7a2700472385f420a1b177a693e55f034f5 100644 (file)
@@ -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;
+}