chiark / gitweb /
timer: make sure we restart timers even if units are still running or if one of their...
authorLennart Poettering <lennart@poettering.net>
Tue, 23 Apr 2013 20:42:31 +0000 (17:42 -0300)
committerLennart Poettering <lennart@poettering.net>
Tue, 23 Apr 2013 20:42:31 +0000 (17:42 -0300)
TODO
src/core/timer.c
src/core/timer.h

diff --git a/TODO b/TODO
index de950d7a881993970a2a212db341323f44723a81..fe27d2b2a0b1dbf8e46a0ea22187b58121cb6bf1 100644 (file)
--- a/TODO
+++ b/TODO
@@ -24,12 +24,6 @@ Fedora 19:
 * localed:
   - localectl: support new converted x11→console keymaps
 
-* timer logic is confused by units which are skipped due to failing condition
-  http://lists.freedesktop.org/archives/systemd-devel/2013-February/008816.html
-
-* timer logic is also confused if a service it triggers hasn't finished when the next timer elapses:
-  http://lists.freedesktop.org/archives/systemd-devel/2013-February/009021.html
-
 Features:
 
 * see if we can fix https://bugs.freedesktop.org/show_bug.cgi?id=63672
index b5d895f048ca99596eeeb50c5ac6d2f2119a7b24..b8039d82ec3549bf98ff11a96f5f3daa752e4c5b 100644 (file)
@@ -251,11 +251,6 @@ static void timer_enter_waiting(Timer *t, bool initial) {
                         if (r < 0)
                                 continue;
 
-                        if (!initial && v->next_elapse < ts.realtime) {
-                                v->disabled = true;
-                                continue;
-                        }
-
                         if (!found_realtime)
                                 t->next_elapse_realtime = v->next_elapse;
                         else
@@ -284,18 +279,26 @@ static void timer_enter_waiting(Timer *t, bool initial) {
 
                         case TIMER_UNIT_ACTIVE:
 
-                                if (UNIT_TRIGGER(UNIT(t))->inactive_exit_timestamp.monotonic <= 0)
+                                base = UNIT_TRIGGER(UNIT(t))->inactive_exit_timestamp.monotonic;
+
+                                if (base <= 0)
+                                        base = t->last_trigger_monotonic;
+
+                                if (base <= 0)
                                         continue;
 
-                                base = UNIT_TRIGGER(UNIT(t))->inactive_exit_timestamp.monotonic;
                                 break;
 
                         case TIMER_UNIT_INACTIVE:
 
-                                if (UNIT_TRIGGER(UNIT(t))->inactive_enter_timestamp.monotonic <= 0)
+                                base = UNIT_TRIGGER(UNIT(t))->inactive_enter_timestamp.monotonic;
+
+                                if (base <= 0)
+                                        base = t->last_trigger_monotonic;
+
+                                if (base <= 0)
                                         continue;
 
-                                base = UNIT_TRIGGER(UNIT(t))->inactive_enter_timestamp.monotonic;
                                 break;
 
                         default:
@@ -304,7 +307,10 @@ static void timer_enter_waiting(Timer *t, bool initial) {
 
                         v->next_elapse = base + v->value;
 
-                        if (!initial && v->next_elapse < ts.monotonic) {
+                        if (!initial &&
+                            v->next_elapse < ts.monotonic &&
+                            (v->base == TIMER_ACTIVE || v->base == TIMER_BOOT || v->base == TIMER_STARTUP)) {
+                                /* This is a one time trigger, disable it now */
                                 v->disabled = true;
                                 continue;
                         }
@@ -376,6 +382,8 @@ static void timer_enter_running(Timer *t) {
         if (r < 0)
                 goto fail;
 
+        t->last_trigger_monotonic = now(CLOCK_MONOTONIC);
+
         timer_set_state(t, TIMER_RUNNING);
         return;
 
@@ -488,8 +496,6 @@ static void timer_trigger_notify(Unit *u, Unit *other) {
         assert(u);
         assert(other);
 
-        log_error("NOTIFY!");
-
         if (other->load_state != UNIT_LOADED)
                 return;
 
index 163bd6c3bee2fc510ce7285a1e212c515a744bc5..fed15e9165aef2fafc8f4c0e6e750a31f7b2c1d0 100644 (file)
@@ -79,6 +79,8 @@ struct Timer {
         Watch realtime_watch;
 
         TimerResult result;
+
+        usec_t last_trigger_monotonic;
 };
 
 void timer_free_values(Timer *t);