mirror of
https://github.com/systemd/systemd.git
synced 2025-01-26 14:04:03 +03:00
core: don't drop timer expired but not yet processed when system date is changed
There is difference between time set by the user and real elapsed time because of accuracy feature. If you change the system date(or time) between these times, the timer drops. You can easily reproduce it with the following command. ----------------------------------------------------------- $ systemd-run --on-active=3s ls; sleep 3; date -s "`date`" ----------------------------------------------------------- In the following command, the problem is rarely reproduced. But it exists. --------------------------------------------------------------------------------------------- $ systemd-run --on-active=3s --timer-property=AccuracySec=1us ls ; sleep 1; date -s "`date`" --------------------------------------------------------------------------------------------- Note : Global AccuracySec value. ---------------------------------------------------------------------- $ cat /etc/systemd/system.conf DefaultTimerAccuracySec=1min ----------------------------------------------------------------------
This commit is contained in:
parent
c1b785bb66
commit
fee04d7f3a
@ -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);
|
||||
static void timer_enter_waiting(Timer *t, bool initial, 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);
|
||||
timer_enter_waiting(t, false, false);
|
||||
else
|
||||
timer_set_state(t, t->deserialized_state);
|
||||
|
||||
@ -333,7 +333,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) {
|
||||
static void timer_enter_waiting(Timer *t, bool initial, bool time_change) {
|
||||
bool found_monotonic = false, found_realtime = false;
|
||||
bool leave_around = false;
|
||||
triple_timestamp ts;
|
||||
@ -443,7 +443,7 @@ static void timer_enter_waiting(Timer *t, bool initial) {
|
||||
|
||||
v->next_elapse = usec_add(usec_shift_clock(base, CLOCK_MONOTONIC, TIMER_MONOTONIC_CLOCK(t)), v->value);
|
||||
|
||||
if (!initial &&
|
||||
if (!initial && !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 */
|
||||
@ -641,7 +641,7 @@ static int timer_start(Unit *u) {
|
||||
}
|
||||
|
||||
t->result = TIMER_SUCCESS;
|
||||
timer_enter_waiting(t, true);
|
||||
timer_enter_waiting(t, true, false);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -756,14 +756,14 @@ static void timer_trigger_notify(Unit *u, Unit *other) {
|
||||
case TIMER_ELAPSED:
|
||||
|
||||
/* Recalculate sleep time */
|
||||
timer_enter_waiting(t, false);
|
||||
timer_enter_waiting(t, false, 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);
|
||||
timer_enter_waiting(t, false, false);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -805,7 +805,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);
|
||||
timer_enter_waiting(t, false, true);
|
||||
}
|
||||
|
||||
static void timer_timezone_change(Unit *u) {
|
||||
@ -817,7 +817,7 @@ static void timer_timezone_change(Unit *u) {
|
||||
return;
|
||||
|
||||
log_unit_debug(u, "Timezone change, recalculating next elapse.");
|
||||
timer_enter_waiting(t, false);
|
||||
timer_enter_waiting(t, false, false);
|
||||
}
|
||||
|
||||
static const char* const timer_base_table[_TIMER_BASE_MAX] = {
|
||||
|
Loading…
x
Reference in New Issue
Block a user