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