summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHyotaek Shim <hyotaek.shim@samsung.com>2018-11-01 13:38:43 +0900
committerHyotaek Shim <hyotaek.shim@samsung.com>2018-11-02 03:11:25 +0000
commitda10dc5ea7d22666104a7c2dfda04e204beff67a (patch)
treee83dcde3794afd88072076a6c173f8a4a1a6e968
parent5ccd5b2efc60d9f775a812878528f06b01189da5 (diff)
downloadsystemd-da10dc5ea7d22666104a7c2dfda04e204beff67a.tar.gz
systemd-da10dc5ea7d22666104a7c2dfda04e204beff67a.tar.bz2
systemd-da10dc5ea7d22666104a7c2dfda04e204beff67a.zip
core: don't drop timer expired but not yet processed when system date is changedsubmit/tizen_4.0/20181105.044610submit/tizen_4.0/20181102.043250accepted/tizen/4.0/unified/20181105.115859
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 ---------------------------------------------------------------------- Origin source: https://github.com/systemd/systemd/commit/fee04d7f3ab810e99b97535ca5fda2f9517acda9 Change-Id: Ibaaa89bec9c55f43336388ee85f07b89c1a50ea4 Signed-off-by: Hyotaek Shim <hyotaek.shim@samsung.com> (cherry picked from commit bf843c82c0c714c884c67a01c561e75e58b77349)
-rw-r--r--src/core/timer.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/core/timer.c b/src/core/timer.c
index 3206296f09..8056f8dc34 100644
--- a/src/core/timer.c
+++ b/src/core/timer.c
@@ -269,7 +269,7 @@ static void timer_set_state(Timer *t, TimerState state) {
unit_notify(UNIT(t), state_translation_table[old_state], state_translation_table[state], true);
}
-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);
@@ -281,7 +281,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);
@@ -351,7 +351,7 @@ static void add_random(Timer *t, usec_t *v) {
log_unit_info(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;
usec_t ts_realtime, ts_monotonic;
usec_t base = 0;
@@ -458,7 +458,8 @@ static void timer_enter_waiting(Timer *t, bool initial) {
v->next_elapse = base + v->value;
- if (!initial && v->next_elapse < ts_monotonic && IN_SET(v->base, TIMER_ACTIVE, TIMER_BOOT, TIMER_STARTUP)) {
+ if (!initial && !time_change &&
+ v->next_elapse < ts_monotonic && IN_SET(v->base, TIMER_ACTIVE, TIMER_BOOT, TIMER_STARTUP)) {
/* This is a one time trigger, disable it now */
v->disabled = true;
continue;
@@ -636,7 +637,7 @@ static int timer_start(Unit *u) {
}
t->result = TIMER_SUCCESS;
- timer_enter_waiting(t, true);
+ timer_enter_waiting(t, true, false);
return 1;
}
@@ -759,14 +760,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;
@@ -799,7 +800,7 @@ static void timer_time_change(Unit *u) {
return;
log_unit_debug(u, "Time change, recalculating next elapse.");
- timer_enter_waiting(t, false);
+ timer_enter_waiting(t, false, true);
}
static const char* const timer_base_table[_TIMER_BASE_MAX] = {