diff options
author | Shawn Landden <shawn@churchofgit.com> | 2015-03-07 01:43:32 -0800 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2015-03-07 08:10:51 -0500 |
commit | 6829cec4dce1b41c895425a120b70d0a3ed677ab (patch) | |
tree | 6e8eb28e4688c007d0e27fd28da196c6a416e18b /src | |
parent | 1eb37584a899f84bd1e5fd55c5efb36146c04eb1 (diff) |
adjust for time spent in timedated even without dbus timestamp
it is trivial to fall back to our own timestamp
v2: use now()
v3: remove useless if ()
v4: add comment
Diffstat (limited to 'src')
-rw-r--r-- | src/timedate/timedated.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/timedate/timedated.c b/src/timedate/timedated.c index 88d57e9d54..97b535f564 100644 --- a/src/timedate/timedated.c +++ b/src/timedate/timedated.c @@ -551,6 +551,9 @@ static int method_set_time(sd_bus *bus, sd_bus_message *m, void *userdata, sd_bu if (c->use_ntp) return sd_bus_error_setf(error, BUS_ERROR_AUTOMATIC_TIME_SYNC_ENABLED, "Automatic time synchronization is enabled"); + /* this only gets used if dbus does not provide a timestamp */ + start = now(CLOCK_MONOTONIC); + r = sd_bus_message_read(m, "xbb", &utc, &relative, &interactive); if (r < 0) return r; @@ -590,10 +593,11 @@ static int method_set_time(sd_bus *bus, sd_bus_message *m, void *userdata, sd_bu /* adjust ts for time spent in program */ r = sd_bus_message_get_monotonic_usec(m, &start); + /* when sd_bus_message_get_monotonic_usec() returns -ENODATA it does not modify &start */ if (r < 0 && r != -ENODATA) return r; - if (r >= 0) - timespec_store(&ts, timespec_load(&ts) + (now(CLOCK_MONOTONIC) - start)); + + timespec_store(&ts, timespec_load(&ts) + (now(CLOCK_MONOTONIC) - start)); /* Set system clock */ if (clock_settime(CLOCK_REALTIME, &ts) < 0) { |