From 19f8d037833f2426f0ea6b06279d669ed69fcfd1 Mon Sep 17 00:00:00 2001 From: Tobias Geerinckx-Rice Date: Mon, 4 Aug 2014 22:15:52 +0200 Subject: timer: order OnCalendar units after timer-sync.target if DefaultDependencies=no Avoids triggering timers prematurely on systems with significantly inaccurate clocks, or some embedded platforms that lack one entirely. --- src/core/timer.c | 10 ++++++++++ src/shared/special.h | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/core/timer.c b/src/core/timer.c index a5a33a6e6f..dc0f289c7a 100644 --- a/src/core/timer.c +++ b/src/core/timer.c @@ -95,6 +95,7 @@ static int timer_verify(Timer *t) { static int timer_add_default_dependencies(Timer *t) { int r; + TimerValue *v; assert(t); @@ -106,6 +107,15 @@ static int timer_add_default_dependencies(Timer *t) { r = unit_add_two_dependencies_by_name(UNIT(t), UNIT_AFTER, UNIT_REQUIRES, SPECIAL_SYSINIT_TARGET, NULL, true); 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, NULL, true); + if (r < 0) + return r; + break; + } + } } return unit_add_two_dependencies_by_name(UNIT(t), UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_SHUTDOWN_TARGET, NULL, true); diff --git a/src/shared/special.h b/src/shared/special.h index 2fe5db5558..b045047d36 100644 --- a/src/shared/special.h +++ b/src/shared/special.h @@ -57,13 +57,13 @@ #define SPECIAL_REMOTE_FS_PRE_TARGET "remote-fs-pre.target" #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_BASIC_TARGET "basic.target" /* LSB compatibility */ #define SPECIAL_NETWORK_TARGET "network.target" /* LSB's $network */ #define SPECIAL_NSS_LOOKUP_TARGET "nss-lookup.target" /* LSB's $named */ #define SPECIAL_RPCBIND_TARGET "rpcbind.target" /* LSB's $portmap */ -#define SPECIAL_TIME_SYNC_TARGET "time-sync.target" /* LSB's $time */ /* * Rules regarding adding further high level targets like the above: -- cgit v1.2.3-54-g00ecf