]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
timer: convert property_get_next_elapse_monotonic() to use usec_shift_clock()
authorLennart Poettering <lennart@poettering.net>
Thu, 22 Jun 2017 18:59:48 +0000 (20:59 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 22 Jun 2017 18:59:48 +0000 (20:59 +0200)
Let's use the generic clock shifting logic here.

src/core/dbus-timer.c
src/core/timer.h

index efbb0e8915ce5a4d44f80feeb7ab87a6dd3fa547..c98282a5d4cece08f9784883eb45f23fd9252953 100644 (file)
@@ -144,28 +144,14 @@ static int property_get_next_elapse_monotonic(
                 sd_bus_error *error) {
 
         Timer *t = userdata;
-        usec_t x;
 
         assert(bus);
         assert(reply);
         assert(t);
 
-        if (t->next_elapse_monotonic_or_boottime <= 0)
-                x = 0;
-        else if (t->wake_system) {
-                usec_t a, b;
-
-                a = now(CLOCK_MONOTONIC);
-                b = now(clock_boottime_or_monotonic());
-
-                if (t->next_elapse_monotonic_or_boottime + a > b)
-                        x = t->next_elapse_monotonic_or_boottime + a - b;
-                else
-                        x = 0;
-        } else
-                x = t->next_elapse_monotonic_or_boottime;
-
-        return sd_bus_message_append(reply, "t", x);
+        return sd_bus_message_append(reply, "t",
+                                     (uint64_t) usec_shift_clock(t->next_elapse_monotonic_or_boottime,
+                                                                 TIMER_MONOTONIC_CLOCK(t), CLOCK_MONOTONIC));
 }
 
 const sd_bus_vtable bus_timer_vtable[] = {
index 9c4b64f8981ba2b2fc53485a877091113966d0b2..546c60d75075e5abf611c21eb2df3fa3506f8ab0 100644 (file)
@@ -78,6 +78,8 @@ struct Timer {
         char *stamp_path;
 };
 
+#define TIMER_MONOTONIC_CLOCK(t) ((t)->wake_system && clock_boottime_supported() ? CLOCK_BOOTTIME_ALARM : CLOCK_MONOTONIC)
+
 void timer_free_values(Timer *t);
 
 extern const UnitVTable timer_vtable;