1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
3 #include "alloc-util.h"
5 #include "dns-domain.h"
6 #include "extract-word.h"
7 #include "string-util.h"
8 #include "timesyncd-conf.h"
9 #include "timesyncd-manager.h"
10 #include "timesyncd-server.h"
12 int manager_parse_server_string(Manager
*m
, ServerType type
, const char *string
) {
19 first
= type
== SERVER_FALLBACK
? m
->fallback_servers
: m
->system_servers
;
21 if (type
== SERVER_FALLBACK
)
22 m
->have_fallbacks
= true;
25 _cleanup_free_
char *word
= NULL
;
28 r
= extract_first_word(&string
, &word
, NULL
, 0);
30 return log_error_errno(r
, "Failed to parse timesyncd server syntax \"%s\": %m", string
);
34 r
= dns_name_is_valid_or_address(word
);
36 return log_error_errno(r
, "Failed to check validity of NTP server name or address '%s': %m", word
);
38 log_error("Invalid NTP server name or address, ignoring: %s", word
);
42 /* Filter out duplicates */
43 LIST_FOREACH(names
, n
, first
)
44 if (streq_ptr(n
->string
, word
)) {
52 r
= server_name_new(m
, NULL
, type
, word
);
60 int manager_parse_fallback_string(Manager
*m
, const char *string
) {
61 if (m
->have_fallbacks
)
64 return manager_parse_server_string(m
, SERVER_FALLBACK
, string
);
67 int config_parse_servers(
72 unsigned section_line
,
79 Manager
*m
= userdata
;
87 manager_flush_server_names(m
, ltype
);
89 r
= manager_parse_server_string(m
, ltype
, rvalue
);
91 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
92 "Failed to parse NTP server string '%s', ignoring: %m", rvalue
);
100 int manager_parse_config_file(Manager
*m
) {
105 r
= config_parse_many_nulstr(
106 PKGSYSCONFDIR
"/timesyncd.conf",
107 CONF_PATHS_NULSTR("systemd/timesyncd.conf.d"),
109 config_item_perf_lookup
, timesyncd_gperf_lookup
,
116 if (m
->poll_interval_min_usec
< 16 * USEC_PER_SEC
) {
117 log_warning("Invalid PollIntervalMinSec=. Using default value.");
118 m
->poll_interval_min_usec
= NTP_POLL_INTERVAL_MIN_USEC
;
121 if (m
->poll_interval_max_usec
< m
->poll_interval_min_usec
) {
122 log_warning("PollIntervalMaxSec= is smaller than PollIntervalMinSec=. Using default value.");
123 m
->poll_interval_max_usec
= MAX(NTP_POLL_INTERVAL_MAX_USEC
, m
->poll_interval_min_usec
* 32);
126 if (m
->connection_retry_usec
< 1 * USEC_PER_SEC
) {
127 log_warning("Invalid ConnectionRetrySec=. Using default value.");
128 m
->connection_retry_usec
= DEFAULT_CONNECTION_RETRY_USEC
;