[systemd-devel] [PATCH] adjust for time spent in timedated even without dbus timestamp

Shawn Landden shawn at churchofgit.com
Fri Mar 6 17:19:48 PST 2015


it is trivial to fall back to our own timestamp
---
 src/timedate/timedated.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/timedate/timedated.c b/src/timedate/timedated.c
index 88d57e9..7e47348 100644
--- a/src/timedate/timedated.c
+++ b/src/timedate/timedated.c
@@ -551,6 +551,13 @@ 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
+         * (and ts gets overriden below) */
+        r = clock_gettime(CLOCK_MONOTONIC, &ts);
+        if (r < 0)
+                return -errno;
+        start = timespec_load(&ts);
+
         r = sd_bus_message_read(m, "xbb", &utc, &relative, &interactive);
         if (r < 0)
                 return r;
@@ -592,7 +599,7 @@ static int method_set_time(sd_bus *bus, sd_bus_message *m, void *userdata, sd_bu
         r = sd_bus_message_get_monotonic_usec(m, &start);
         if (r < 0 && r != -ENODATA)
                 return r;
-        if (r >= 0)
+        if (r >= 0 || r == -ENODATA)
                 timespec_store(&ts, timespec_load(&ts) + (now(CLOCK_MONOTONIC) - start));
 
         /* Set system clock */
-- 
2.2.1.209.g41e5f3a



More information about the systemd-devel mailing list