[systemd-devel] [PATCH] timedated: add LocalTimeUSec via dbus

Shawn Landden shawn at churchofgit.com
Mon Mar 23 04:24:38 PDT 2015


---
 src/timedate/timedated.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/src/timedate/timedated.c b/src/timedate/timedated.c
index ca771d5..f83b99c 100644
--- a/src/timedate/timedated.c
+++ b/src/timedate/timedated.c
@@ -38,6 +38,7 @@
 #include "bus-common-errors.h"
 #include "event-util.h"
 #include "selinux-util.h"
+#include "time-util.h"
 
 #define NULL_ADJTIME_UTC "0.0 0 0\n0\nUTC\n"
 #define NULL_ADJTIME_LOCAL "0.0 0 0\n0\nLOCAL\n"
@@ -361,6 +362,28 @@ static int property_get_time(
         return sd_bus_message_append(reply, "t", now(CLOCK_REALTIME));
 }
 
+/* gmtime(LocalTimeUSec % USEC_PER_SEC) is useful as long as you ignore GNU
+ * extensions of tm_gmtoff and tm_zone, and their ourgrowth in strftime(3)
+ */
+static int property_get_local_time(
+                sd_bus *bus,
+                const char *path,
+                const char *interface,
+                const char *property,
+                sd_bus_message *reply,
+                void *userdata,
+                sd_bus_error *error)
+{
+        struct tm tm;
+        struct timespec ts;
+        usec_t t;
+
+        t = now(CLOCK_REALTIME);
+        (void)timespec_store(&ts, t);
+        assert_se(localtime_r(&dummy, &ts.tv_sec));
+        return sd_bus_message_append(reply, "t", t + (tm->tm_gmtoff * USEC_PER_SEC));
+}
+
 static int property_get_ntp_sync(
                 sd_bus *bus,
                 const char *path,
@@ -671,6 +694,7 @@ static const sd_bus_vtable timedate_vtable[] = {
         SD_BUS_PROPERTY("NTP", "b", bus_property_get_bool, 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("LocalTimeUSec", "t", property_get_local_time, 0, 0),
         SD_BUS_PROPERTY("RTCTimeUSec", "t", property_get_rtc_time, 0, 0),
         SD_BUS_METHOD("SetTime", "xbb", NULL, method_set_time, SD_BUS_VTABLE_UNPRIVILEGED),
         SD_BUS_METHOD("SetTimezone", "sb", NULL, method_set_timezone, SD_BUS_VTABLE_UNPRIVILEGED),
-- 
2.2.1.209.g41e5f3a



More information about the systemd-devel mailing list