chiark / gitweb /
timer: order OnCalendar units after timer-sync.target if DefaultDependencies=no
authorTobias Geerinckx-Rice <tobias.geerinckx.rice@gmail.com>
Mon, 4 Aug 2014 20:15:52 +0000 (22:15 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 13 Aug 2014 23:49:40 +0000 (01:49 +0200)
Avoids triggering timers prematurely on systems with significantly inaccurate
clocks, or some embedded platforms that lack one entirely.

TODO
man/systemd.timer.xml
src/core/timer.c
src/shared/special.h

diff --git a/TODO b/TODO
index 4404a53abd6752931bc906df6936db9748f708eb..81f302328192a8379a3873c400af83c0a2be6dff 100644 (file)
--- a/TODO
+++ b/TODO
@@ -71,8 +71,6 @@ Features:
 
 * Add a new verb "systemctl top"
 
-* order OnCalendar timer units after timer-sync.target if DefaultDependencies=no so that we don't trigger them prematurely
-
 * refuse mounting on symlinks
 
 * logind: allow users to kill or lock their own sessions
index d82b9bdc973b09846231bbef88799a855ab8e557..9fcf5ccb978d2ed139e56fa34cb7866019b7b61f 100644 (file)
                 <varname>Unit=</varname> (see below).</para>
 
                 <para>Unless <varname>DefaultDependencies=</varname>
-                is set to <option>false</option>, timer units will
+                is set to <option>false</option>, all timer units will
                 implicitly have dependencies of type
                 <varname>Conflicts=</varname> and
                 <varname>Before=</varname> on
-                <filename>shutdown.target</filename>. These ensure
-                that timer units are stopped cleanly prior to system
-                shutdown. Only timer units involved with early boot or
-                late system shutdown should disable this
-                option.</para>
+                <filename>shutdown.target</filename> to ensure that
+                they are stopped cleanly prior to system shutdown.
+                Timer units with at least one
+                <varname>OnCalendar=</varname> directive will have an
+                additional <varname>After=</varname> dependency on
+                <filename>timer-sync.target</filename> to avoid
+                being started before the system clock has been
+                correctly set. Only timer units involved with early
+                boot or late system shutdown should disable the
+                <varname>DefaultDependencies=</varname> option.</para>
         </refsect1>
 
         <refsect1>
index a5a33a6e6f479a23a674dc545bd8d6973b324b6a..dc0f289c7afafc943e8d742ac88d4f1663a15fff 100644 (file)
@@ -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);
index 2fe5db55584cb8aa1daf1db9a01565d034e19b4e..b045047d36afac59ef3e95176c0d5b8706afcb87 100644 (file)
 #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: