]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
84e51726 LP |
2 | /*** |
3 | This file is part of systemd. | |
4 | ||
5 | Copyright 2014 Kay Sievers, Lennart Poettering | |
6 | ||
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. | |
11 | ||
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. | |
16 | ||
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/>. | |
19 | ***/ | |
20 | ||
b5efdb8a | 21 | #include "alloc-util.h" |
a0f29c76 LP |
22 | #include "def.h" |
23 | #include "extract-word.h" | |
07630cea | 24 | #include "string-util.h" |
a0f29c76 | 25 | #include "timesyncd-conf.h" |
84e51726 | 26 | #include "timesyncd-manager.h" |
874ff7bf | 27 | #include "timesyncd-server.h" |
84e51726 | 28 | |
874ff7bf | 29 | int manager_parse_server_string(Manager *m, ServerType type, const char *string) { |
874ff7bf LP |
30 | ServerName *first; |
31 | int r; | |
32 | ||
33 | assert(m); | |
34 | assert(string); | |
35 | ||
36 | first = type == SERVER_FALLBACK ? m->fallback_servers : m->system_servers; | |
37 | ||
3745770a MB |
38 | if (type == SERVER_FALLBACK) |
39 | m->have_fallbacks = true; | |
40 | ||
2e3c5854 | 41 | for (;;) { |
b5efdb8a | 42 | _cleanup_free_ char *word = NULL; |
874ff7bf LP |
43 | bool found = false; |
44 | ServerName *n; | |
45 | ||
2e3c5854 SS |
46 | r = extract_first_word(&string, &word, NULL, 0); |
47 | if (r < 0) | |
48 | return log_error_errno(r, "Failed to parse timesyncd server syntax \"%s\": %m", string); | |
2e3c5854 SS |
49 | if (r == 0) |
50 | break; | |
b5efdb8a | 51 | |
874ff7bf LP |
52 | /* Filter out duplicates */ |
53 | LIST_FOREACH(names, n, first) | |
2e3c5854 | 54 | if (streq_ptr(n->string, word)) { |
874ff7bf LP |
55 | found = true; |
56 | break; | |
57 | } | |
58 | ||
59 | if (found) | |
60 | continue; | |
61 | ||
2e3c5854 | 62 | r = server_name_new(m, NULL, type, word); |
874ff7bf LP |
63 | if (r < 0) |
64 | return r; | |
65 | } | |
66 | ||
67 | return 0; | |
68 | } | |
69 | ||
3745770a MB |
70 | int manager_parse_fallback_string(Manager *m, const char *string) { |
71 | if (m->have_fallbacks) | |
72 | return 0; | |
73 | ||
74 | return manager_parse_server_string(m, SERVER_FALLBACK, string); | |
75 | } | |
76 | ||
84e51726 LP |
77 | int config_parse_servers( |
78 | const char *unit, | |
79 | const char *filename, | |
80 | unsigned line, | |
81 | const char *section, | |
82 | unsigned section_line, | |
83 | const char *lvalue, | |
84 | int ltype, | |
85 | const char *rvalue, | |
86 | void *data, | |
87 | void *userdata) { | |
88 | ||
89 | Manager *m = userdata; | |
874ff7bf | 90 | int r; |
84e51726 LP |
91 | |
92 | assert(filename); | |
93 | assert(lvalue); | |
94 | assert(rvalue); | |
95 | ||
96 | if (isempty(rvalue)) | |
874ff7bf LP |
97 | manager_flush_server_names(m, ltype); |
98 | else { | |
99 | r = manager_parse_server_string(m, ltype, rvalue); | |
100 | if (r < 0) { | |
12ca818f | 101 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse NTP server string '%s'. Ignoring.", rvalue); |
874ff7bf LP |
102 | return 0; |
103 | } | |
104 | } | |
84e51726 LP |
105 | |
106 | return 0; | |
107 | } | |
874ff7bf LP |
108 | |
109 | int manager_parse_config_file(Manager *m) { | |
a4465d0d YW |
110 | int r; |
111 | ||
874ff7bf LP |
112 | assert(m); |
113 | ||
a4465d0d YW |
114 | r = config_parse_many_nulstr(PKGSYSCONFDIR "/timesyncd.conf", |
115 | CONF_PATHS_NULSTR("systemd/timesyncd.conf.d"), | |
116 | "Time\0", | |
117 | config_item_perf_lookup, timesyncd_gperf_lookup, | |
bcde742e | 118 | CONFIG_PARSE_WARN, m); |
a4465d0d YW |
119 | if (r < 0) |
120 | return r; | |
121 | ||
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; | |
125 | } | |
126 | ||
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); | |
130 | } | |
131 | ||
132 | return r; | |
874ff7bf | 133 | } |