systemd/0060-timesyncd-don-t-use-compiled-in-list-if-FallbackNTP-.patch

98 lines
3.8 KiB
Diff
Raw Normal View History

From fff58beb5618e6cabdf716418de7e5976ed8d87f Mon Sep 17 00:00:00 2001
From: Michael Biebl <biebl@debian.org>
Date: Sun, 21 May 2017 03:22:43 +0200
Subject: [PATCH] timesyncd: don't use compiled-in list if FallbackNTP has been
configured explicitly
Parse the config files first and only apply the compiled-in list of
fallback servers if no NTP server was configured via FallbackNTP.
Closes: #5091
(cherry picked from commit 3745770ae4dcf262707882a38f6c5ba2684329a3)
---
src/timesync/timesyncd-conf.c | 10 ++++++++++
src/timesync/timesyncd-conf.h | 1 +
src/timesync/timesyncd-manager.c | 4 ----
src/timesync/timesyncd-manager.h | 2 ++
src/timesync/timesyncd.c | 2 ++
5 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/src/timesync/timesyncd-conf.c b/src/timesync/timesyncd-conf.c
index bf25b112e1..b4a4f19976 100644
--- a/src/timesync/timesyncd-conf.c
+++ b/src/timesync/timesyncd-conf.c
@@ -34,6 +34,9 @@ int manager_parse_server_string(Manager *m, ServerType type, const char *string)
first = type == SERVER_FALLBACK ? m->fallback_servers : m->system_servers;
+ if (type == SERVER_FALLBACK)
+ m->have_fallbacks = true;
+
for (;;) {
_cleanup_free_ char *word = NULL;
bool found = false;
@@ -63,6 +66,13 @@ int manager_parse_server_string(Manager *m, ServerType type, const char *string)
return 0;
}
+int manager_parse_fallback_string(Manager *m, const char *string) {
+ if (m->have_fallbacks)
+ return 0;
+
+ return manager_parse_server_string(m, SERVER_FALLBACK, string);
+}
+
int config_parse_servers(
const char *unit,
const char *filename,
diff --git a/src/timesync/timesyncd-conf.h b/src/timesync/timesyncd-conf.h
index 0280697e9c..0c4b44e707 100644
--- a/src/timesync/timesyncd-conf.h
+++ b/src/timesync/timesyncd-conf.h
@@ -29,3 +29,4 @@ int manager_parse_server_string(Manager *m, ServerType type, const char *string)
int config_parse_servers(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
int manager_parse_config_file(Manager *m);
+int manager_parse_fallback_string(Manager *m, const char *string);
diff --git a/src/timesync/timesyncd-manager.c b/src/timesync/timesyncd-manager.c
index ae8514550a..a24c821bdc 100644
--- a/src/timesync/timesyncd-manager.c
+++ b/src/timesync/timesyncd-manager.c
@@ -1124,10 +1124,6 @@ int manager_new(Manager **ret) {
RATELIMIT_INIT(m->ratelimit, RATELIMIT_INTERVAL_USEC, RATELIMIT_BURST);
- r = manager_parse_server_string(m, SERVER_FALLBACK, NTP_SERVERS);
- if (r < 0)
- return r;
-
r = sd_event_default(&m->event);
if (r < 0)
return r;
diff --git a/src/timesync/timesyncd-manager.h b/src/timesync/timesyncd-manager.h
index efe3e60d3e..cf681f6098 100644
--- a/src/timesync/timesyncd-manager.h
+++ b/src/timesync/timesyncd-manager.h
@@ -38,6 +38,8 @@ struct Manager {
LIST_HEAD(ServerName, link_servers);
LIST_HEAD(ServerName, fallback_servers);
+ bool have_fallbacks:1;
+
RateLimit ratelimit;
bool exhausted_servers;
diff --git a/src/timesync/timesyncd.c b/src/timesync/timesyncd.c
index b67d672a6a..052329f61e 100644
--- a/src/timesync/timesyncd.c
+++ b/src/timesync/timesyncd.c
@@ -132,6 +132,8 @@ int main(int argc, char *argv[]) {
if (r < 0)
log_warning_errno(r, "Failed to parse configuration file: %m");
+ assert_se(manager_parse_fallback_string(m, NTP_SERVERS) >= 0);
+
log_debug("systemd-timesyncd running as pid " PID_FMT, getpid());
sd_notify(false,
"READY=1\n"