[systemd-devel] [PATCH] timedated: Add a LocalOffset property for timezone offset
David Herrmann
dh.herrmann at gmail.com
Thu Mar 19 06:39:57 PDT 2015
Hi
On Thu, Mar 19, 2015 at 11:24 AM, Stef Walter <stefw at redhat.com> wrote:
> 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));
> +}
> +
Hmm, so this is a convenience call. You could just set tm.tm_zone
locally and use mktime() with the value retrieved by "Timezone"? Yeah,
the time-api is awful with global variables, but that's not really our
fault, is it?
I'm not really against this bus-call, but I also don't see the point.
There's much more information in a timezone file than the offset, so
why expose the offset but not the other data?
Thanks
David
> 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
>
> _______________________________________________
> systemd-devel mailing list
> systemd-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/systemd-devel
More information about the systemd-devel
mailing list