[systemd-devel] [PATCH] timedated: Add a LocalOffset property for timezone offset

Stef Walter stefw at redhat.com
Thu Mar 19 03:24:50 PDT 2015


This property is in usec (like the TimeUSec property) and allows
retrieving the timezone offset for the machine. This is particularly
usable for remote callers.
---
 src/timedate/timedated.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/src/timedate/timedated.c b/src/timedate/timedated.c
index ca771d5..e384b36 100644
--- a/src/timedate/timedated.c
+++ b/src/timedate/timedated.c
@@ -361,6 +361,22 @@ static int property_get_time(
         return sd_bus_message_append(reply, "t", now(CLOCK_REALTIME));
 }
 
+static int property_get_local_offset(
+                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;
+        time_t dummy = 0;
+
+        assert_se(tm = localtime(&dummy));
+        return sd_bus_message_append(reply, "t", (uint64_t)(tm->tm_gmtoff * 1000000));
+}
+
 static int property_get_ntp_sync(
                 sd_bus *bus,
                 const char *path,
@@ -440,7 +456,8 @@ static int method_set_timezone(sd_bus *bus, sd_bus_message *m, void *userdata, s
                    LOG_MESSAGE("Changed time zone to '%s'.", c->zone),
                    NULL);
 
-        sd_bus_emit_properties_changed(bus, "/org/freedesktop/timedate1", "org.freedesktop.timedate1", "Timezone", NULL);
+        sd_bus_emit_properties_changed(bus, "/org/freedesktop/timedate1", "org.freedesktop.timedate1",
+                                       "Timezone", "LocalOffset", NULL);
 
         return sd_bus_reply_method_return(m, NULL);
 }
@@ -666,6 +683,7 @@ static int method_set_ntp(sd_bus *bus, sd_bus_message *m, void *userdata, sd_bus
 static const sd_bus_vtable timedate_vtable[] = {
         SD_BUS_VTABLE_START(0),
         SD_BUS_PROPERTY("Timezone", "s", NULL, offsetof(Context, zone), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
+        SD_BUS_PROPERTY("LocalOffset", "t", property_get_local_offset, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
         SD_BUS_PROPERTY("LocalRTC", "b", bus_property_get_bool, offsetof(Context, local_rtc), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
         SD_BUS_PROPERTY("CanNTP", "b", bus_property_get_bool, offsetof(Context, can_ntp), 0),
         SD_BUS_PROPERTY("NTP", "b", bus_property_get_bool, offsetof(Context, use_ntp), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
-- 
2.3.3



More information about the systemd-devel mailing list