From d2004ee56877039183508d8d3dcbdb247a2c1002 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 17 Dec 2020 20:19:44 +0100 Subject: [PATCH 1/3] units: don't pull in time-sync.target from systemd-timesyncd.service systemd-timesyncd.service only applies the much weaker monotonic clock from file logic, i.e should pull in and order itself before time-set.target. The strong time-sync.target unit is pulled in by systemd-time-wait-sync.service. --- units/systemd-timesyncd.service.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/units/systemd-timesyncd.service.in b/units/systemd-timesyncd.service.in index 62120d8190..c0d63f5c70 100644 --- a/units/systemd-timesyncd.service.in +++ b/units/systemd-timesyncd.service.in @@ -16,7 +16,7 @@ DefaultDependencies=no After=systemd-sysusers.service Before=time-set.target sysinit.target shutdown.target Conflicts=shutdown.target -Wants=time-set.target time-sync.target +Wants=time-set.target [Service] AmbientCapabilities=CAP_SYS_TIME From fe934b42e480473afba8a29a4a0d3d0e789543ac Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 17 Dec 2020 20:21:46 +0100 Subject: [PATCH 2/3] 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. --- src/basic/special.h | 1 + src/core/timer.c | 15 +++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/basic/special.h b/src/basic/special.h index d55b3289de..b9b7be7a7d 100644 --- a/src/basic/special.h +++ b/src/basic/special.h @@ -42,6 +42,7 @@ #define SPECIAL_SWAP_TARGET "swap.target" #define SPECIAL_NETWORK_ONLINE_TARGET "network-online.target" #define SPECIAL_TIME_SYNC_TARGET "time-sync.target" /* LSB's $time */ +#define SPECIAL_TIME_SET_TARGET "time-set.target" #define SPECIAL_BASIC_TARGET "basic.target" /* LSB compatibility */ 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); From 08e77eb88d0c518d0ad9d5dad44b0b5ea036a229 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 17 Dec 2020 20:26:24 +0100 Subject: [PATCH 3/3] man: document that .timer units now have After= on both time-set.target + time-sync.target --- man/systemd.timer.xml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/man/systemd.timer.xml b/man/systemd.timer.xml index 9fe7ff3255..84c5bb564c 100644 --- a/man/systemd.timer.xml +++ b/man/systemd.timer.xml @@ -81,10 +81,12 @@ units involved with early boot or late system shutdown should disable the DefaultDependencies= option. - Timer units - with at least one OnCalendar= directive will have an additional After= - dependency on time-sync.target to avoid being started before the system clock has been - correctly set. + Timer units with at least one OnCalendar= directive acquire a pair + of additional After= dependencies on time-set.target and + time-sync.target, in order to avoid being started before the system clock has + been correctly set. See + systemd.special7 + for details on these two targets.