Skip to content

Commit fe934b4

Browse files
committed
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.
1 parent d2004ee commit fe934b4

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/basic/special.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#define SPECIAL_SWAP_TARGET "swap.target"
4343
#define SPECIAL_NETWORK_ONLINE_TARGET "network-online.target"
4444
#define SPECIAL_TIME_SYNC_TARGET "time-sync.target" /* LSB's $time */
45+
#define SPECIAL_TIME_SET_TARGET "time-set.target"
4546
#define SPECIAL_BASIC_TARGET "basic.target"
4647

4748
/* LSB compatibility */

src/core/timer.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,20 @@ static int timer_add_default_dependencies(Timer *t) {
9999
if (r < 0)
100100
return r;
101101

102-
LIST_FOREACH(value, v, t->values)
103-
if (v->base == TIMER_CALENDAR) {
104-
r = unit_add_dependency_by_name(UNIT(t), UNIT_AFTER, SPECIAL_TIME_SYNC_TARGET, true, UNIT_DEPENDENCY_DEFAULT);
102+
LIST_FOREACH(value, v, t->values) {
103+
const char *target;
104+
105+
if (v->base != TIMER_CALENDAR)
106+
continue;
107+
108+
FOREACH_STRING(target, SPECIAL_TIME_SYNC_TARGET, SPECIAL_TIME_SET_TARGET) {
109+
r = unit_add_dependency_by_name(UNIT(t), UNIT_AFTER, target, true, UNIT_DEPENDENCY_DEFAULT);
105110
if (r < 0)
106111
return r;
107-
break;
108112
}
113+
114+
break;
115+
}
109116
}
110117

111118
return unit_add_two_dependencies_by_name(UNIT(t), UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_SHUTDOWN_TARGET, true, UNIT_DEPENDENCY_DEFAULT);

0 commit comments

Comments
 (0)