1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-09 01:18:19 +03:00

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
This commit is contained in:
Michael Biebl 2017-05-21 03:22:43 +02:00
parent d82c4b9a7b
commit 3745770ae4
5 changed files with 15 additions and 4 deletions

View File

@ -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,

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -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"