1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 This file is part of systemd.
5 Copyright 2014 Kay Sievers, Lennart Poettering
7 systemd is free software; you can redistribute it and/or modify it
8 under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 2.1 of the License, or
10 (at your option) any later version.
12 systemd is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public License
18 along with systemd; If not, see <http://www.gnu.org/licenses/>.
21 #include "alloc-util.h"
23 #include "extract-word.h"
24 #include "string-util.h"
25 #include "timesyncd-conf.h"
26 #include "timesyncd-manager.h"
27 #include "timesyncd-server.h"
29 int manager_parse_server_string(Manager
*m
, ServerType type
, const char *string
) {
36 first
= type
== SERVER_FALLBACK
? m
->fallback_servers
: m
->system_servers
;
38 if (type
== SERVER_FALLBACK
)
39 m
->have_fallbacks
= true;
42 _cleanup_free_
char *word
= NULL
;
46 r
= extract_first_word(&string
, &word
, NULL
, 0);
48 return log_error_errno(r
, "Failed to parse timesyncd server syntax \"%s\": %m", string
);
52 /* Filter out duplicates */
53 LIST_FOREACH(names
, n
, first
)
54 if (streq_ptr(n
->string
, word
)) {
62 r
= server_name_new(m
, NULL
, type
, word
);
70 int manager_parse_fallback_string(Manager
*m
, const char *string
) {
71 if (m
->have_fallbacks
)
74 return manager_parse_server_string(m
, SERVER_FALLBACK
, string
);
77 int config_parse_servers(
82 unsigned section_line
,
89 Manager
*m
= userdata
;
97 manager_flush_server_names(m
, ltype
);
99 r
= manager_parse_server_string(m
, ltype
, rvalue
);
101 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse NTP server string '%s'. Ignoring.", rvalue
);
109 int manager_parse_config_file(Manager
*m
) {
114 r
= config_parse_many_nulstr(PKGSYSCONFDIR
"/timesyncd.conf",
115 CONF_PATHS_NULSTR("systemd/timesyncd.conf.d"),
117 config_item_perf_lookup
, timesyncd_gperf_lookup
,
118 CONFIG_PARSE_WARN
, m
);
122 if (m
->poll_interval_min_usec
< 16 * USEC_PER_SEC
) {
123 log_warning("Invalid PollIntervalMinSec=. Using default value.");
124 m
->poll_interval_min_usec
= NTP_POLL_INTERVAL_MIN_USEC
;
127 if (m
->poll_interval_max_usec
< m
->poll_interval_min_usec
) {
128 log_warning("PollIntervalMaxSec= is smaller than PollIntervalMinSec=. Using default value.");
129 m
->poll_interval_max_usec
= MAX(NTP_POLL_INTERVAL_MAX_USEC
, m
->poll_interval_min_usec
* 32);