diff options
author | Lennart Poettering <lennart@poettering.net> | 2020-12-17 20:21:46 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2020-12-17 20:21:46 +0100 |
commit | fe934b42e480473afba8a29a4a0d3d0e789543ac (patch) | |
tree | e654b884b47d8cce19b8d3f7e88bbe24c30c0653 /src/core/timer.c | |
parent | units: don't pull in time-sync.target from systemd-timesyncd.service (diff) | |
download | systemd-fe934b42e480473afba8a29a4a0d3d0e789543ac.tar.xz systemd-fe934b42e480473afba8a29a4a0d3d0e789543ac.zip |
core: order timer units after both time-sync.target and time-set.target
If users do not enable a service like systemd-time-wait-sync.target
(because they don't want to delay boot for external events, such as an
NTP sync), then timers should still take the the weaker time-set.target
feature into account, so that the clock is at least monotonic.
Hence, order timer units after both of the targets: time-sync.target
*and* time-set.target. That way, the right thing will happen regardless
if people have no NTP server (and thus also no
systemd-time-wait-sync.service or equivalent) or, only have an NTP
server (and no systemd-time-wait-sync.service), or have both.
Ordering after time-set.target is basically "free". The logic it is
backed by should be instant, without communication with the outside
going on. It's useful still so that time servers that implement the
timestamp from /var/ logic can run in later boot.
Diffstat (limited to '')
-rw-r--r-- | src/core/timer.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/core/timer.c b/src/core/timer.c index f42c86da76..32abdb74d7 100644 --- a/src/core/timer.c +++ b/src/core/timer.c @@ -99,13 +99,20 @@ static int timer_add_default_dependencies(Timer *t) { if (r < 0) return r; - LIST_FOREACH(value, v, t->values) - if (v->base == TIMER_CALENDAR) { - r = unit_add_dependency_by_name(UNIT(t), UNIT_AFTER, SPECIAL_TIME_SYNC_TARGET, true, UNIT_DEPENDENCY_DEFAULT); + LIST_FOREACH(value, v, t->values) { + const char *target; + + if (v->base != TIMER_CALENDAR) + continue; + + FOREACH_STRING(target, SPECIAL_TIME_SYNC_TARGET, SPECIAL_TIME_SET_TARGET) { + r = unit_add_dependency_by_name(UNIT(t), UNIT_AFTER, target, true, UNIT_DEPENDENCY_DEFAULT); if (r < 0) return r; - break; } + + break; + } } return unit_add_two_dependencies_by_name(UNIT(t), UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_SHUTDOWN_TARGET, true, UNIT_DEPENDENCY_DEFAULT); |