]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/timesync/timesyncd-conf.c
Merge pull request #5164 from Werkov/ordering-for-_netdev-devices
[thirdparty/systemd.git] / src / timesync / timesyncd-conf.c
1 /***
2 This file is part of systemd.
3
4 Copyright 2014 Kay Sievers, Lennart Poettering
5
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
10
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
18 ***/
19
20 #include "alloc-util.h"
21 #include "def.h"
22 #include "extract-word.h"
23 #include "string-util.h"
24 #include "timesyncd-conf.h"
25 #include "timesyncd-manager.h"
26 #include "timesyncd-server.h"
27
28 int manager_parse_server_string(Manager *m, ServerType type, const char *string) {
29 ServerName *first;
30 int r;
31
32 assert(m);
33 assert(string);
34
35 first = type == SERVER_FALLBACK ? m->fallback_servers : m->system_servers;
36
37 for (;;) {
38 _cleanup_free_ char *word = NULL;
39 bool found = false;
40 ServerName *n;
41
42 r = extract_first_word(&string, &word, NULL, 0);
43 if (r < 0)
44 return log_error_errno(r, "Failed to parse timesyncd server syntax \"%s\": %m", string);
45 if (r == 0)
46 break;
47
48 /* Filter out duplicates */
49 LIST_FOREACH(names, n, first)
50 if (streq_ptr(n->string, word)) {
51 found = true;
52 break;
53 }
54
55 if (found)
56 continue;
57
58 r = server_name_new(m, NULL, type, word);
59 if (r < 0)
60 return r;
61 }
62
63 return 0;
64 }
65
66 int config_parse_servers(
67 const char *unit,
68 const char *filename,
69 unsigned line,
70 const char *section,
71 unsigned section_line,
72 const char *lvalue,
73 int ltype,
74 const char *rvalue,
75 void *data,
76 void *userdata) {
77
78 Manager *m = userdata;
79 int r;
80
81 assert(filename);
82 assert(lvalue);
83 assert(rvalue);
84
85 if (isempty(rvalue))
86 manager_flush_server_names(m, ltype);
87 else {
88 r = manager_parse_server_string(m, ltype, rvalue);
89 if (r < 0) {
90 log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse NTP server string '%s'. Ignoring.", rvalue);
91 return 0;
92 }
93 }
94
95 return 0;
96 }
97
98 int manager_parse_config_file(Manager *m) {
99 assert(m);
100
101 return config_parse_many_nulstr(PKGSYSCONFDIR "/timesyncd.conf",
102 CONF_PATHS_NULSTR("systemd/timesyncd.conf.d"),
103 "Time\0",
104 config_item_perf_lookup, timesyncd_gperf_lookup,
105 false, m);
106 }