Hi.

Since it has bothered me that systemd-timesyncd unconditionally writes
the current clock value to disk everytime it got an NTP fix i filed a
BUG report (https://bugs.freedesktop.org/show_bug.cgi?id=86292).
Zbigniew asked me to send a patch to this mailing list. So here it
is. I also attached it to the BUG report mentioned above.

Philipp
-- 
Dipl.-Inform. Philipp Reinkemeier
OFFIS e.V.
Escherweg 2, D-26121 Oldenburg, Germany
Phone: +49 441 9722-400
E-Mail: philipp.reinkeme...@offis.de
PGP: 0x2DA75A6F or 0xCCB2AF14
From 8c03d37688a6163bdd0a7a6379b18f8c3c7a501b Mon Sep 17 00:00:00 2001
From: Philipp Reinkemeier <philipp.reinkeme...@offis.de>
Date: Wed, 28 Jan 2015 14:53:07 +0100
Subject: [PATCH] timesyncd: Make saving clock to disk on NTP fix optional

This introduces a new property "SaveClockOnNtpFix" in the
timesyncd.conf configuration file. It takes a boolean value.
If we get an NTP, the clock is saved to disk depending on that
value.

Previously, the clock was saved on every NTP fix. This commit
preserves this default behavior. If "SaveClockOnNtpFix" is disabled,
then the clock is only saved during shutdown of systemd-timesyncd.
This can be useful if one wants to keep disk accesses at a minimum
(save power, prevents disk spin-ups to improve their lifetime).
---
 man/timesyncd.conf.xml             | 14 ++++++++++++++
 src/timesync/timesyncd-gperf.gperf |  7 ++++---
 src/timesync/timesyncd-manager.c   |  5 ++++-
 src/timesync/timesyncd-manager.h   |  2 ++
 src/timesync/timesyncd.conf.in     |  1 +
 5 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/man/timesyncd.conf.xml b/man/timesyncd.conf.xml
index 1a56c2c..9a93737 100644
--- a/man/timesyncd.conf.xml
+++ b/man/timesyncd.conf.xml
@@ -105,6 +105,20 @@
                                 used instead.</para></listitem>
                         </varlistentry>
 
+                        <varlistentry>
+                                <term><varname>SaveClockOnNtpFix=</varname></term>
+                                <listitem><para>Takes a boolean value. If enabled
+                                (the default), then everytime an NTP fix is acquired,
+                                the new clock value is written to disk (the file
+                                <filename>/var/lib/systemd/clock</filename> is touched).
+                                The date of that file is used upon startup of
+                                <command>systemd-timesyncd</command> to initialize
+                                the system clock (useful for systems that lack an RTC).
+                                If not enabled, then the clock value is only written
+                                to disk upon shutdown of
+                                <command>systemd-timesyncd</command>.</para></listitem>
+                        </varlistentry>
+
                 </variablelist>
         </refsect1>
 
diff --git a/src/timesync/timesyncd-gperf.gperf b/src/timesync/timesyncd-gperf.gperf
index 29a2cfe..03dc828 100644
--- a/src/timesync/timesyncd-gperf.gperf
+++ b/src/timesync/timesyncd-gperf.gperf
@@ -14,6 +14,7 @@ struct ConfigPerfItem;
 %struct-type
 %includes
 %%
-Time.NTP,           config_parse_servers, SERVER_SYSTEM,   0
-Time.Servers,       config_parse_servers, SERVER_SYSTEM,   0
-Time.FallbackNTP,   config_parse_servers, SERVER_FALLBACK, 0
+Time.NTP,               config_parse_servers, SERVER_SYSTEM,   0
+Time.Servers,           config_parse_servers, SERVER_SYSTEM,   0
+Time.FallbackNTP,       config_parse_servers, SERVER_FALLBACK, 0
+Time.SaveClockOnNtpFix, config_parse_bool,    0,               offsetof(Manager, save_clock_on_ntp_fix)
diff --git a/src/timesync/timesyncd-manager.c b/src/timesync/timesyncd-manager.c
index bc35662..cf05a20 100644
--- a/src/timesync/timesyncd-manager.c
+++ b/src/timesync/timesyncd-manager.c
@@ -378,7 +378,8 @@ static int manager_adjust_clock(Manager *m, double offset, int leap_sec) {
         if (r < 0)
                 return r;
 
-        touch("/var/lib/systemd/clock");
+        if (m->save_clock_on_ntp_fix)
+                touch("/var/lib/systemd/clock");
 
         m->drift_ppm = tmx.freq / 65536;
 
@@ -1118,6 +1119,8 @@ int manager_new(Manager **ret) {
 
         RATELIMIT_INIT(m->ratelimit, RATELIMIT_INTERVAL_USEC, RATELIMIT_BURST);
 
+        m->save_clock_on_ntp_fix = true;
+
         r = manager_parse_server_string(m, SERVER_FALLBACK, NTP_SERVERS);
         if (r < 0)
                 return r;
diff --git a/src/timesync/timesyncd-manager.h b/src/timesync/timesyncd-manager.h
index c7efdc5..4cc1a31 100644
--- a/src/timesync/timesyncd-manager.h
+++ b/src/timesync/timesyncd-manager.h
@@ -40,6 +40,8 @@ struct Manager {
         LIST_HEAD(ServerName, link_servers);
         LIST_HEAD(ServerName, fallback_servers);
 
+        bool save_clock_on_ntp_fix;
+
         RateLimit ratelimit;
         bool exhausted_servers;
 
diff --git a/src/timesync/timesyncd.conf.in b/src/timesync/timesyncd.conf.in
index fc3c6c4..0e5d5fc 100644
--- a/src/timesync/timesyncd.conf.in
+++ b/src/timesync/timesyncd.conf.in
@@ -13,3 +13,4 @@
 [Time]
 #NTP=
 #FallbackNTP=@NTP_SERVERS@
+#SaveClockOnNtpFix=yes
-- 
2.2.2

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel

Reply via email to