From 2479df30946dd327b0745ec5f9b7d3542b9538e3 Mon Sep 17 00:00:00 2001 From: Shawn Landden Date: Mon, 16 Feb 2015 11:47:08 -0800 Subject: [PATCH] timedated: when performing "SetTime" compensate for program lag (David: fix up compile-failure and simplify code a bit) --- TODO | 2 -- src/timedate/timedated.c | 10 ++++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/TODO b/TODO index cb83a3eb2..ca91b123c 100644 --- a/TODO +++ b/TODO @@ -168,8 +168,6 @@ Features: * in systemctl list-unit-files: show the install value the presets would suggest for a service in a third column -* timedated should compensate on SetTime for the time spent in polkit - * figure out when we can use the coarse timers * sd-resolve: drop res_query wrapping, people should call via the bus to resolved instead diff --git a/src/timedate/timedated.c b/src/timedate/timedated.c index 18dcd18b0..88d57e9d5 100644 --- a/src/timedate/timedated.c +++ b/src/timedate/timedated.c @@ -540,6 +540,7 @@ static int method_set_time(sd_bus *bus, sd_bus_message *m, void *userdata, sd_bu Context *c = userdata; int64_t utc; struct timespec ts; + usec_t start; struct tm* tm; int r; @@ -587,6 +588,13 @@ static int method_set_time(sd_bus *bus, sd_bus_message *m, void *userdata, sd_bu if (r == 0) return 1; + /* adjust ts for time spent in program */ + r = sd_bus_message_get_monotonic_usec(m, &start); + if (r < 0 && r != -ENODATA) + return r; + if (r >= 0) + timespec_store(&ts, timespec_load(&ts) + (now(CLOCK_MONOTONIC) - start)); + /* Set system clock */ if (clock_settime(CLOCK_REALTIME, &ts) < 0) { log_error_errno(errno, "Failed to set local time: %m"); @@ -727,6 +735,8 @@ int main(int argc, char *argv[]) { if (r < 0) goto finish; + (void)sd_bus_negotiate_timestamp(bus, true); + r = context_read_data(&context); if (r < 0) { log_error_errno(r, "Failed to read time zone data: %m"); -- 2.30.2