On Tue, Mar 24, 2015 at 5:34 AM, Shawn Landden <[email protected]> wrote: > On Mon, Mar 23, 2015 at 6:52 PM, Zbigniew Jędrzejewski-Szmek > <[email protected]> wrote: >> 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. > These are not for the same problem. We need both. I want to ship a > checksum of the zoneinfo file with the timezone, but its hard to do > this cleanly as using coreutils from C is a PITA.
Again, systemd is NOT a "remote glibc" API. We are not doing that. Kay _______________________________________________ systemd-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/systemd-devel
