diff options
author | Shawn Landden <shawn@churchofgit.com> | 2015-02-16 11:47:08 -0800 |
---|---|---|
committer | David Herrmann <dh.herrmann@gmail.com> | 2015-02-26 11:53:33 +0100 |
commit | 2479df30946dd327b0745ec5f9b7d3542b9538e3 (patch) | |
tree | 2a4c81e880683832a16e2dcc4e55ed9ad6be67ea /src/timedate | |
parent | 33d25be0ef858ca07fc9843aec00c1f97a1b2e19 (diff) |
timedated: when performing "SetTime" compensate for program lag
(David: fix up compile-failure and simplify code a bit)
Diffstat (limited to 'src/timedate')
-rw-r--r-- | src/timedate/timedated.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/timedate/timedated.c b/src/timedate/timedated.c index 18dcd18b00..88d57e9d54 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"); |