diff --git a/src/core/timer.c b/src/core/timer.c index 4e7fade999c..1527aab1582 100644 --- a/src/core/timer.c +++ b/src/core/timer.c @@ -263,7 +263,7 @@ static void timer_set_state(Timer *t, TimerState state) { unit_notify(UNIT(t), state_translation_table[old_state], state_translation_table[state], 0); } -static void timer_enter_waiting(Timer *t, bool initial, bool time_change); +static void timer_enter_waiting(Timer *t, bool time_change); static int timer_coldplug(Unit *u) { Timer *t = TIMER(u); @@ -275,7 +275,7 @@ static int timer_coldplug(Unit *u) { return 0; if (t->deserialized_state == TIMER_WAITING) - timer_enter_waiting(t, false, false); + timer_enter_waiting(t, false); else timer_set_state(t, t->deserialized_state); @@ -331,7 +331,7 @@ static void add_random(Timer *t, usec_t *v) { log_unit_debug(UNIT(t), "Adding %s random time.", format_timespan(s, sizeof(s), add, 0)); } -static void timer_enter_waiting(Timer *t, bool initial, bool time_change) { +static void timer_enter_waiting(Timer *t, bool time_change) { bool found_monotonic = false, found_realtime = false; bool leave_around = false; triple_timestamp ts; @@ -441,7 +441,8 @@ static void timer_enter_waiting(Timer *t, bool initial, bool time_change) { v->next_elapse = usec_add(usec_shift_clock(base, CLOCK_MONOTONIC, TIMER_MONOTONIC_CLOCK(t)), v->value); - if (!initial && !time_change && + if (dual_timestamp_is_set(&t->last_trigger) && + !time_change && v->next_elapse < triple_timestamp_by_clock(&ts, TIMER_MONOTONIC_CLOCK(t)) && IN_SET(v->base, TIMER_ACTIVE, TIMER_BOOT, TIMER_STARTUP)) { /* This is a one time trigger, disable it now */ @@ -639,7 +640,7 @@ static int timer_start(Unit *u) { } t->result = TIMER_SUCCESS; - timer_enter_waiting(t, true, false); + timer_enter_waiting(t, false); return 1; } @@ -754,14 +755,14 @@ static void timer_trigger_notify(Unit *u, Unit *other) { case TIMER_ELAPSED: /* Recalculate sleep time */ - timer_enter_waiting(t, false, false); + timer_enter_waiting(t, false); break; case TIMER_RUNNING: if (UNIT_IS_INACTIVE_OR_FAILED(unit_active_state(other))) { log_unit_debug(UNIT(t), "Got notified about unit deactivation."); - timer_enter_waiting(t, false, false); + timer_enter_waiting(t, false); } break; @@ -803,7 +804,7 @@ static void timer_time_change(Unit *u) { t->last_trigger.realtime = ts; log_unit_debug(u, "Time change, recalculating next elapse."); - timer_enter_waiting(t, false, true); + timer_enter_waiting(t, true); } static void timer_timezone_change(Unit *u) { @@ -815,7 +816,7 @@ static void timer_timezone_change(Unit *u) { return; log_unit_debug(u, "Timezone change, recalculating next elapse."); - timer_enter_waiting(t, false, false); + timer_enter_waiting(t, false); } static const char* const timer_base_table[_TIMER_BASE_MAX] = {