]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/timesync/timesyncd-conf.c
Merge pull request #1762 from endocode/dongsu/l10n-ko-msgs
[thirdparty/systemd.git] / src / timesync / timesyncd-conf.c
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
22 #include "alloc-util.h"
23 #include "def.h"
24 #include "extract-word.h"
25 #include "string-util.h"
26 #include "timesyncd-conf.h"
27 #include "timesyncd-manager.h"
28 #include "timesyncd-server.h"
29
30 int manager_parse_server_string(Manager *m, ServerType type, const char *string) {
31 ServerName *first;
32 int r;
33
34 assert(m);
35 assert(string);
36
37 first = type == SERVER_FALLBACK ? m->fallback_servers : m->system_servers;
38
39 for (;;) {
40 _cleanup_free_ char *word = NULL;
41 bool found = false;
42 ServerName *n;
43
44 r = extract_first_word(&string, &word, NULL, 0);
45 if (r < 0)
46 return log_error_errno(r, "Failed to parse timesyncd server syntax \"%s\": %m", string);
47 if (r == 0)
48 break;
49
50 /* Filter out duplicates */
51 LIST_FOREACH(names, n, first)
52 if (streq_ptr(n->string, word)) {
53 found = true;
54 break;
55 }
56
57 if (found)
58 continue;
59
60 r = server_name_new(m, NULL, type, word);
61 if (r < 0)
62 return r;
63 }
64
65 return 0;
66 }
67
68 int config_parse_servers(
69 const char *unit,
70 const char *filename,
71 unsigned line,
72 const char *section,
73 unsigned section_line,
74 const char *lvalue,
75 int ltype,
76 const char *rvalue,
77 void *data,
78 void *userdata) {
79
80 Manager *m = userdata;
81 int r;
82
83 assert(filename);
84 assert(lvalue);
85 assert(rvalue);
86
87 if (isempty(rvalue))
88 manager_flush_server_names(m, ltype);
89 else {
90 r = manager_parse_server_string(m, ltype, rvalue);
91 if (r < 0) {
92 log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse NTP server string '%s'. Ignoring.", rvalue);
93 return 0;
94 }
95 }
96
97 return 0;
98 }
99
100 int manager_parse_config_file(Manager *m) {
101 assert(m);
102
103 return config_parse_many("/etc/systemd/timesyncd.conf",
104 CONF_DIRS_NULSTR("systemd/timesyncd.conf"),
105 "Time\0",
106 config_item_perf_lookup, timesyncd_gperf_lookup,
107 false, m);
108 }