[systemd-commits] src/shared src/timedate

Lennart Poettering lennart at kemper.freedesktop.org
Wed Oct 16 16:06:19 PDT 2013


 src/shared/time-util.c     |   13 +++++++++++++
 src/shared/time-util.h     |    2 ++
 src/timedate/timedatectl.c |   12 ------------
 src/timedate/timedated.c   |   38 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 53 insertions(+), 12 deletions(-)

New commits:
commit 03cc26dda4cb59207fea3dd4fd1fa4608746739c
Author: Lennart Poettering <lennart at poettering.net>
Date:   Thu Oct 17 01:03:39 2013 +0200

    timedated: expose time and NTP sync flag via the bus
    
    This way, timedatectl can be run over the network and determine all
    properties correctly from the server rather than the client.

diff --git a/src/shared/time-util.c b/src/shared/time-util.c
index 860be61..4b4cd7a 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 7660fe1..a51317d 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);
diff --git a/src/timedate/timedatectl.c b/src/timedate/timedatectl.c
index 141180c..80afc57 100644
--- a/src/timedate/timedatectl.c
+++ b/src/timedate/timedatectl.c
@@ -72,18 +72,6 @@ typedef struct StatusInfo {
         bool can_ntp;
 } StatusInfo;
 
-static bool ntp_synced(void) {
-        struct timex txc = {};
-
-        if (adjtimex(&txc) < 0)
-                return false;
-
-        if (txc.status & STA_UNSYNC)
-                return false;
-
-        return true;
-}
-
 static const char *jump_str(int delta_minutes, char *s, size_t size) {
         if (delta_minutes == 60)
                 return "one hour forward";
diff --git a/src/timedate/timedated.c b/src/timedate/timedated.c
index 16e24c1..48c6a13 100644
--- a/src/timedate/timedated.c
+++ b/src/timedate/timedated.c
@@ -481,6 +481,42 @@ static int property_get_rtc_time(
         return 1;
 }
 
+static int property_get_time(
+                sd_bus *bus,
+                const char *path,
+                const char *interface,
+                const char *property,
+                sd_bus_message *reply,
+                sd_bus_error *error,
+                void *userdata) {
+
+        int r;
+
+        r = sd_bus_message_append(reply, "t", now(CLOCK_REALTIME));
+        if (r < 0)
+                return r;
+
+        return 1;
+}
+
+static int property_get_ntp_sync(
+                sd_bus *bus,
+                const char *path,
+                const char *interface,
+                const char *property,
+                sd_bus_message *reply,
+                sd_bus_error *error,
+                void *userdata) {
+
+        int r;
+
+        r = sd_bus_message_append(reply, "b", ntp_synced());
+        if (r < 0)
+                return r;
+
+        return 1;
+}
+
 static int method_set_timezone(sd_bus *bus, sd_bus_message *m, void *userdata) {
         _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
         Context *c = userdata;
@@ -735,6 +771,8 @@ static const sd_bus_vtable timedate_vtable[] = {
         SD_BUS_PROPERTY("LocalRTC", "b", NULL, offsetof(Context, local_rtc), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
         SD_BUS_PROPERTY("CanNTP", "b", bus_property_get_tristate, offsetof(Context, can_ntp), 0),
         SD_BUS_PROPERTY("NTP", "b", bus_property_get_tristate, offsetof(Context, use_ntp), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
+        SD_BUS_PROPERTY("NTPSynchronized", "b", property_get_ntp_sync, 0, 0),
+        SD_BUS_PROPERTY("TimeUSec", "t", property_get_time, 0, 0),
         SD_BUS_PROPERTY("RTCTimeUSec", "t", property_get_rtc_time, 0, 0),
         SD_BUS_METHOD("SetTime", "xbb", NULL, method_set_time, 0),
         SD_BUS_METHOD("SetTimezone", "sb", NULL, method_set_timezone, 0),



More information about the systemd-commits mailing list