[systemd-devel] [PATCH] timer: order OnCalendar units after timer-sync.target if DefaultDependencies=no

Tobias Geerinckx-Rice tobias.geerinckx.rice at gmail.com
Mon Aug 4 10:31:31 PDT 2014


Avoids prematurely triggering timers on systems with significantly inaccurate
clocks, or some embedded platforms that lack one entirely.
---
 TODO                  |  2 --
 man/systemd.timer.xml | 10 ++++++----
 src/core/timer.c      |  6 ++++++
 src/shared/special.h  |  2 +-
 4 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/TODO b/TODO
index 1dbb9ff..7dad2ce 100644
--- a/TODO
+++ b/TODO
@@ -60,8 +60,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
diff --git a/man/systemd.timer.xml b/man/systemd.timer.xml
index d82b9bd..559b4cb 100644
--- a/man/systemd.timer.xml
+++ b/man/systemd.timer.xml
@@ -80,13 +80,15 @@
                 <para>Unless <varname>DefaultDependencies=</varname>
                 is set to <option>false</option>, timer units will
                 implicitly have dependencies of type
+                <varname>After=</varname> on
+                <filename>timer-sync.target</filename>, and 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>
+                that timer units are started at the correct time,
+                and are stopped cleanly prior to system shutdown.
+                Only timer units involved with early boot or late
+                system shutdown should disable this option.</para>
         </refsect1>
 
         <refsect1>
diff --git a/src/core/timer.c b/src/core/timer.c
index a5a33a6..d116a30 100644
--- a/src/core/timer.c
+++ b/src/core/timer.c
@@ -106,6 +106,12 @@ 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;
+
+                if (t->values->base == TIMER_CALENDAR) {
+                        r = unit_add_dependency_by_name(UNIT(t), UNIT_AFTER, SPECIAL_TIME_SYNC_TARGET, NULL, true);
+                        if (r < 0)
+                                return r;
+                }
         }
 
         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 2fe5db5..b045047 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:
-- 
2.0.4



More information about the systemd-devel mailing list