[systemd-devel] [PATCH] timedated: add LocalTimeUSec via dbus
Zbigniew Jędrzejewski-Szmek
zbyszek at in.waw.pl
Mon Mar 23 18:52:36 PDT 2015
On Mon, Mar 23, 2015 at 04:24:38AM -0700, Shawn Landden wrote:
> ---
> 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)
This patch seems the most reasonable of the proposed solutions.
It answers the question "What does the remote host think local time is?"
unambigously.
The other patch proposed by Shawn mixes the remote UTC time with local
information about timezones, which doesn't seem as clean.
Kay said:
> Transmitting several absolute time stamps sounds wrong.
The second timestamp is what the user sees, so in some way it is a
very significant thing. It is the outcome of the remote knowledge
about the time and its config and timezone database. We aren't making
any promises about the accuracy of that, but just trying to accurately
convey that information. Seems fine to me to transmit this bit of
information.
Zbyszek
More information about the systemd-devel
mailing list