File: | build-scan/../src/shared/conf-parser.c |
Warning: | line 1081, column 49 Potential leak of memory pointed to by 'a' |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* SPDX-License-Identifier: LGPL-2.1+ */ | ||||||||
2 | |||||||||
3 | #include <errno(*__errno_location ()).h> | ||||||||
4 | #include <limits.h> | ||||||||
5 | #include <stdint.h> | ||||||||
6 | #include <stdio.h> | ||||||||
7 | #include <stdlib.h> | ||||||||
8 | #include <string.h> | ||||||||
9 | #include <sys/types.h> | ||||||||
10 | |||||||||
11 | #include "alloc-util.h" | ||||||||
12 | #include "conf-files.h" | ||||||||
13 | #include "conf-parser.h" | ||||||||
14 | #include "def.h" | ||||||||
15 | #include "extract-word.h" | ||||||||
16 | #include "fd-util.h" | ||||||||
17 | #include "fileio.h" | ||||||||
18 | #include "fs-util.h" | ||||||||
19 | #include "log.h" | ||||||||
20 | #include "macro.h" | ||||||||
21 | #include "parse-util.h" | ||||||||
22 | #include "path-util.h" | ||||||||
23 | #include "process-util.h" | ||||||||
24 | #include "signal-util.h" | ||||||||
25 | #include "socket-util.h" | ||||||||
26 | #include "string-util.h" | ||||||||
27 | #include "strv.h" | ||||||||
28 | #include "syslog-util.h" | ||||||||
29 | #include "time-util.h" | ||||||||
30 | #include "utf8.h" | ||||||||
31 | #include "rlimit-util.h" | ||||||||
32 | |||||||||
33 | int config_item_table_lookup( | ||||||||
34 | const void *table, | ||||||||
35 | const char *section, | ||||||||
36 | const char *lvalue, | ||||||||
37 | ConfigParserCallback *func, | ||||||||
38 | int *ltype, | ||||||||
39 | void **data, | ||||||||
40 | void *userdata) { | ||||||||
41 | |||||||||
42 | const ConfigTableItem *t; | ||||||||
43 | |||||||||
44 | assert(table)do { if ((__builtin_expect(!!(!(table)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("table"), "../src/shared/conf-parser.c", 44, __PRETTY_FUNCTION__); } while (0); | ||||||||
45 | assert(lvalue)do { if ((__builtin_expect(!!(!(lvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("lvalue"), "../src/shared/conf-parser.c" , 45, __PRETTY_FUNCTION__); } while (0); | ||||||||
46 | assert(func)do { if ((__builtin_expect(!!(!(func)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("func"), "../src/shared/conf-parser.c", 46 , __PRETTY_FUNCTION__); } while (0); | ||||||||
47 | assert(ltype)do { if ((__builtin_expect(!!(!(ltype)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("ltype"), "../src/shared/conf-parser.c", 47, __PRETTY_FUNCTION__); } while (0); | ||||||||
48 | assert(data)do { if ((__builtin_expect(!!(!(data)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("data"), "../src/shared/conf-parser.c", 48 , __PRETTY_FUNCTION__); } while (0); | ||||||||
49 | |||||||||
50 | for (t = table; t->lvalue; t++) { | ||||||||
51 | |||||||||
52 | if (!streq(lvalue, t->lvalue)(strcmp((lvalue),(t->lvalue)) == 0)) | ||||||||
53 | continue; | ||||||||
54 | |||||||||
55 | if (!streq_ptr(section, t->section)) | ||||||||
56 | continue; | ||||||||
57 | |||||||||
58 | *func = t->parse; | ||||||||
59 | *ltype = t->ltype; | ||||||||
60 | *data = t->data; | ||||||||
61 | return 1; | ||||||||
62 | } | ||||||||
63 | |||||||||
64 | return 0; | ||||||||
65 | } | ||||||||
66 | |||||||||
67 | int config_item_perf_lookup( | ||||||||
68 | const void *table, | ||||||||
69 | const char *section, | ||||||||
70 | const char *lvalue, | ||||||||
71 | ConfigParserCallback *func, | ||||||||
72 | int *ltype, | ||||||||
73 | void **data, | ||||||||
74 | void *userdata) { | ||||||||
75 | |||||||||
76 | ConfigPerfItemLookup lookup = (ConfigPerfItemLookup) table; | ||||||||
77 | const ConfigPerfItem *p; | ||||||||
78 | |||||||||
79 | assert(table)do { if ((__builtin_expect(!!(!(table)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("table"), "../src/shared/conf-parser.c", 79, __PRETTY_FUNCTION__); } while (0); | ||||||||
80 | assert(lvalue)do { if ((__builtin_expect(!!(!(lvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("lvalue"), "../src/shared/conf-parser.c" , 80, __PRETTY_FUNCTION__); } while (0); | ||||||||
81 | assert(func)do { if ((__builtin_expect(!!(!(func)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("func"), "../src/shared/conf-parser.c", 81 , __PRETTY_FUNCTION__); } while (0); | ||||||||
82 | assert(ltype)do { if ((__builtin_expect(!!(!(ltype)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("ltype"), "../src/shared/conf-parser.c", 82, __PRETTY_FUNCTION__); } while (0); | ||||||||
83 | assert(data)do { if ((__builtin_expect(!!(!(data)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("data"), "../src/shared/conf-parser.c", 83 , __PRETTY_FUNCTION__); } while (0); | ||||||||
84 | |||||||||
85 | if (!section) | ||||||||
86 | p = lookup(lvalue, strlen(lvalue)); | ||||||||
87 | else { | ||||||||
88 | char *key; | ||||||||
89 | |||||||||
90 | key = strjoin(section, ".", lvalue)strjoin_real((section), ".", lvalue, ((void*)0)); | ||||||||
91 | if (!key) | ||||||||
92 | return -ENOMEM12; | ||||||||
93 | |||||||||
94 | p = lookup(key, strlen(key)); | ||||||||
95 | free(key); | ||||||||
96 | } | ||||||||
97 | |||||||||
98 | if (!p) | ||||||||
99 | return 0; | ||||||||
100 | |||||||||
101 | *func = p->parse; | ||||||||
102 | *ltype = p->ltype; | ||||||||
103 | *data = (uint8_t*) userdata + p->offset; | ||||||||
104 | return 1; | ||||||||
105 | } | ||||||||
106 | |||||||||
107 | /* Run the user supplied parser for an assignment */ | ||||||||
108 | static int next_assignment( | ||||||||
109 | const char *unit, | ||||||||
110 | const char *filename, | ||||||||
111 | unsigned line, | ||||||||
112 | ConfigItemLookup lookup, | ||||||||
113 | const void *table, | ||||||||
114 | const char *section, | ||||||||
115 | unsigned section_line, | ||||||||
116 | const char *lvalue, | ||||||||
117 | const char *rvalue, | ||||||||
118 | ConfigParseFlags flags, | ||||||||
119 | void *userdata) { | ||||||||
120 | |||||||||
121 | ConfigParserCallback func = NULL((void*)0); | ||||||||
122 | int ltype = 0; | ||||||||
123 | void *data = NULL((void*)0); | ||||||||
124 | int r; | ||||||||
125 | |||||||||
126 | assert(filename)do { if ((__builtin_expect(!!(!(filename)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("filename"), "../src/shared/conf-parser.c" , 126, __PRETTY_FUNCTION__); } while (0); | ||||||||
127 | assert(line > 0)do { if ((__builtin_expect(!!(!(line > 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("line > 0"), "../src/shared/conf-parser.c" , 127, __PRETTY_FUNCTION__); } while (0); | ||||||||
128 | assert(lookup)do { if ((__builtin_expect(!!(!(lookup)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("lookup"), "../src/shared/conf-parser.c" , 128, __PRETTY_FUNCTION__); } while (0); | ||||||||
129 | assert(lvalue)do { if ((__builtin_expect(!!(!(lvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("lvalue"), "../src/shared/conf-parser.c" , 129, __PRETTY_FUNCTION__); } while (0); | ||||||||
130 | assert(rvalue)do { if ((__builtin_expect(!!(!(rvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("rvalue"), "../src/shared/conf-parser.c" , 130, __PRETTY_FUNCTION__); } while (0); | ||||||||
131 | |||||||||
132 | r = lookup(table, section, lvalue, &func, <ype, &data, userdata); | ||||||||
133 | if (r < 0) | ||||||||
134 | return r; | ||||||||
135 | |||||||||
136 | if (r > 0) { | ||||||||
137 | if (func) | ||||||||
138 | return func(unit, filename, line, section, section_line, | ||||||||
139 | lvalue, ltype, rvalue, data, userdata); | ||||||||
140 | |||||||||
141 | return 0; | ||||||||
142 | } | ||||||||
143 | |||||||||
144 | /* Warn about unknown non-extension fields. */ | ||||||||
145 | if (!(flags & CONFIG_PARSE_RELAXED) && !startswith(lvalue, "X-")) | ||||||||
146 | log_syntax(unit, LOG_WARNING, filename, line, 0, "Unknown lvalue '%s' in section '%s'", lvalue, section)({ int _level = (4), _e = (0); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/shared/conf-parser.c", 146, __func__ , "Unknown lvalue '%s' in section '%s'", lvalue, section) : - abs(_e); }); | ||||||||
147 | |||||||||
148 | return 0; | ||||||||
149 | } | ||||||||
150 | |||||||||
151 | /* Parse a single logical line */ | ||||||||
152 | static int parse_line( | ||||||||
153 | const char* unit, | ||||||||
154 | const char *filename, | ||||||||
155 | unsigned line, | ||||||||
156 | const char *sections, | ||||||||
157 | ConfigItemLookup lookup, | ||||||||
158 | const void *table, | ||||||||
159 | ConfigParseFlags flags, | ||||||||
160 | char **section, | ||||||||
161 | unsigned *section_line, | ||||||||
162 | bool_Bool *section_ignored, | ||||||||
163 | char *l, | ||||||||
164 | void *userdata) { | ||||||||
165 | |||||||||
166 | char *e, *include; | ||||||||
167 | |||||||||
168 | assert(filename)do { if ((__builtin_expect(!!(!(filename)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("filename"), "../src/shared/conf-parser.c" , 168, __PRETTY_FUNCTION__); } while (0); | ||||||||
169 | assert(line > 0)do { if ((__builtin_expect(!!(!(line > 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("line > 0"), "../src/shared/conf-parser.c" , 169, __PRETTY_FUNCTION__); } while (0); | ||||||||
170 | assert(lookup)do { if ((__builtin_expect(!!(!(lookup)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("lookup"), "../src/shared/conf-parser.c" , 170, __PRETTY_FUNCTION__); } while (0); | ||||||||
171 | assert(l)do { if ((__builtin_expect(!!(!(l)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("l"), "../src/shared/conf-parser.c", 171 , __PRETTY_FUNCTION__); } while (0); | ||||||||
172 | |||||||||
173 | l = strstrip(l); | ||||||||
174 | if (!*l) | ||||||||
175 | return 0; | ||||||||
176 | |||||||||
177 | if (strchr(COMMENTS"#;" "\n", *l)) | ||||||||
178 | return 0; | ||||||||
179 | |||||||||
180 | include = first_word(l, ".include"); | ||||||||
181 | if (include) { | ||||||||
182 | _cleanup_free___attribute__((cleanup(freep))) char *fn = NULL((void*)0); | ||||||||
183 | |||||||||
184 | /* .includes are a bad idea, we only support them here | ||||||||
185 | * for historical reasons. They create cyclic include | ||||||||
186 | * problems and make it difficult to detect | ||||||||
187 | * configuration file changes with an easy | ||||||||
188 | * stat(). Better approaches, such as .d/ drop-in | ||||||||
189 | * snippets exist. | ||||||||
190 | * | ||||||||
191 | * Support for them should be eventually removed. */ | ||||||||
192 | |||||||||
193 | if (!(flags & CONFIG_PARSE_ALLOW_INCLUDE)) { | ||||||||
194 | log_syntax(unit, LOG_ERR, filename, line, 0, ".include not allowed here. Ignoring.")({ int _level = (3), _e = (0); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/shared/conf-parser.c", 194, __func__ , ".include not allowed here. Ignoring.") : -abs(_e); }); | ||||||||
195 | return 0; | ||||||||
196 | } | ||||||||
197 | |||||||||
198 | log_syntax(unit, LOG_WARNING, filename, line, 0,({ int _level = (4), _e = (0); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/shared/conf-parser.c", 200, __func__ , ".include directives are deprecated, and support for them will be removed in a future version of systemd. " "Please use drop-in files instead.") : -abs(_e); }) | ||||||||
199 | ".include directives are deprecated, and support for them will be removed in a future version of systemd. "({ int _level = (4), _e = (0); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/shared/conf-parser.c", 200, __func__ , ".include directives are deprecated, and support for them will be removed in a future version of systemd. " "Please use drop-in files instead.") : -abs(_e); }) | ||||||||
200 | "Please use drop-in files instead.")({ int _level = (4), _e = (0); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/shared/conf-parser.c", 200, __func__ , ".include directives are deprecated, and support for them will be removed in a future version of systemd. " "Please use drop-in files instead.") : -abs(_e); }); | ||||||||
201 | |||||||||
202 | fn = file_in_same_dir(filename, strstrip(include)); | ||||||||
203 | if (!fn) | ||||||||
204 | return -ENOMEM12; | ||||||||
205 | |||||||||
206 | return config_parse(unit, fn, NULL((void*)0), sections, lookup, table, flags, userdata); | ||||||||
207 | } | ||||||||
208 | |||||||||
209 | if (!utf8_is_valid(l)) | ||||||||
210 | return log_syntax_invalid_utf8(unit, LOG_WARNING, filename, line, l)({ int _level = (4); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_invalid_utf8_internal (unit, _level, filename, line, "../src/shared/conf-parser.c", 210, __func__, l) : -22; }); | ||||||||
211 | |||||||||
212 | if (*l == '[') { | ||||||||
213 | size_t k; | ||||||||
214 | char *n; | ||||||||
215 | |||||||||
216 | k = strlen(l); | ||||||||
217 | assert(k > 0)do { if ((__builtin_expect(!!(!(k > 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("k > 0"), "../src/shared/conf-parser.c" , 217, __PRETTY_FUNCTION__); } while (0); | ||||||||
218 | |||||||||
219 | if (l[k-1] != ']') { | ||||||||
220 | log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid section header '%s'", l)({ int _level = (3), _e = (0); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/shared/conf-parser.c", 220, __func__ , "Invalid section header '%s'", l) : -abs(_e); }); | ||||||||
221 | return -EBADMSG74; | ||||||||
222 | } | ||||||||
223 | |||||||||
224 | n = strndup(l+1, k-2); | ||||||||
225 | if (!n) | ||||||||
226 | return -ENOMEM12; | ||||||||
227 | |||||||||
228 | if (sections && !nulstr_contains(sections, n)) { | ||||||||
229 | |||||||||
230 | if (!(flags & CONFIG_PARSE_RELAXED) && !startswith(n, "X-")) | ||||||||
231 | log_syntax(unit, LOG_WARNING, filename, line, 0, "Unknown section '%s'. Ignoring.", n)({ int _level = (4), _e = (0); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/shared/conf-parser.c", 231, __func__ , "Unknown section '%s'. Ignoring.", n) : -abs(_e); }); | ||||||||
232 | |||||||||
233 | free(n); | ||||||||
234 | *section = mfree(*section); | ||||||||
235 | *section_line = 0; | ||||||||
236 | *section_ignored = true1; | ||||||||
237 | } else { | ||||||||
238 | free_and_replace(*section, n)({ free(*section); (*section) = (n); (n) = ((void*)0); 0; }); | ||||||||
239 | *section_line = line; | ||||||||
240 | *section_ignored = false0; | ||||||||
241 | } | ||||||||
242 | |||||||||
243 | return 0; | ||||||||
244 | } | ||||||||
245 | |||||||||
246 | if (sections && !*section) { | ||||||||
247 | |||||||||
248 | if (!(flags & CONFIG_PARSE_RELAXED) && !*section_ignored) | ||||||||
249 | log_syntax(unit, LOG_WARNING, filename, line, 0, "Assignment outside of section. Ignoring.")({ int _level = (4), _e = (0); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/shared/conf-parser.c", 249, __func__ , "Assignment outside of section. Ignoring.") : -abs(_e); }); | ||||||||
250 | |||||||||
251 | return 0; | ||||||||
252 | } | ||||||||
253 | |||||||||
254 | e = strchr(l, '='); | ||||||||
255 | if (!e) { | ||||||||
256 | log_syntax(unit, LOG_WARNING, filename, line, 0, "Missing '='.")({ int _level = (4), _e = (0); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/shared/conf-parser.c", 256, __func__ , "Missing '='.") : -abs(_e); }); | ||||||||
257 | return -EINVAL22; | ||||||||
258 | } | ||||||||
259 | |||||||||
260 | *e = 0; | ||||||||
261 | e++; | ||||||||
262 | |||||||||
263 | return next_assignment(unit, | ||||||||
264 | filename, | ||||||||
265 | line, | ||||||||
266 | lookup, | ||||||||
267 | table, | ||||||||
268 | *section, | ||||||||
269 | *section_line, | ||||||||
270 | strstrip(l), | ||||||||
271 | strstrip(e), | ||||||||
272 | flags, | ||||||||
273 | userdata); | ||||||||
274 | } | ||||||||
275 | |||||||||
276 | /* Go through the file and parse each line */ | ||||||||
277 | int config_parse(const char *unit, | ||||||||
278 | const char *filename, | ||||||||
279 | FILE *f, | ||||||||
280 | const char *sections, | ||||||||
281 | ConfigItemLookup lookup, | ||||||||
282 | const void *table, | ||||||||
283 | ConfigParseFlags flags, | ||||||||
284 | void *userdata) { | ||||||||
285 | |||||||||
286 | _cleanup_free___attribute__((cleanup(freep))) char *section = NULL((void*)0), *continuation = NULL((void*)0); | ||||||||
287 | _cleanup_fclose___attribute__((cleanup(fclosep))) FILE *ours = NULL((void*)0); | ||||||||
288 | unsigned line = 0, section_line = 0; | ||||||||
289 | bool_Bool section_ignored = false0; | ||||||||
290 | int r; | ||||||||
291 | |||||||||
292 | assert(filename)do { if ((__builtin_expect(!!(!(filename)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("filename"), "../src/shared/conf-parser.c" , 292, __PRETTY_FUNCTION__); } while (0); | ||||||||
293 | assert(lookup)do { if ((__builtin_expect(!!(!(lookup)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("lookup"), "../src/shared/conf-parser.c" , 293, __PRETTY_FUNCTION__); } while (0); | ||||||||
294 | |||||||||
295 | if (!f) { | ||||||||
296 | f = ours = fopen(filename, "re"); | ||||||||
297 | if (!f) { | ||||||||
298 | /* Only log on request, except for ENOENT, | ||||||||
299 | * since we return 0 to the caller. */ | ||||||||
300 | if ((flags & CONFIG_PARSE_WARN) || errno(*__errno_location ()) == ENOENT2) | ||||||||
301 | log_full_errno(errno == ENOENT ? LOG_DEBUG : LOG_ERR, errno,({ int _level = (((*__errno_location ()) == 2 ? 7 : 3)), _e = (((*__errno_location ()))), _realm = (LOG_REALM_SYSTEMD); (log_get_max_level_realm (_realm) >= ((_level) & 0x07)) ? log_internal_realm((( _realm) << 10 | (_level)), _e, "../src/shared/conf-parser.c" , 302, __func__, "Failed to open configuration file '%s': %m" , filename) : -abs(_e); }) | ||||||||
302 | "Failed to open configuration file '%s': %m", filename)({ int _level = (((*__errno_location ()) == 2 ? 7 : 3)), _e = (((*__errno_location ()))), _realm = (LOG_REALM_SYSTEMD); (log_get_max_level_realm (_realm) >= ((_level) & 0x07)) ? log_internal_realm((( _realm) << 10 | (_level)), _e, "../src/shared/conf-parser.c" , 302, __func__, "Failed to open configuration file '%s': %m" , filename) : -abs(_e); }); | ||||||||
303 | return errno(*__errno_location ()) == ENOENT2 ? 0 : -errno(*__errno_location ()); | ||||||||
304 | } | ||||||||
305 | } | ||||||||
306 | |||||||||
307 | fd_warn_permissions(filename, fileno(f)); | ||||||||
308 | |||||||||
309 | for (;;) { | ||||||||
310 | _cleanup_free___attribute__((cleanup(freep))) char *buf = NULL((void*)0); | ||||||||
311 | bool_Bool escaped = false0; | ||||||||
312 | char *l, *p, *e; | ||||||||
313 | |||||||||
314 | r = read_line(f, LONG_LINE_MAX(1U*1024U*1024U), &buf); | ||||||||
315 | if (r == 0) | ||||||||
316 | break; | ||||||||
317 | if (r == -ENOBUFS105) { | ||||||||
318 | if (flags & CONFIG_PARSE_WARN) | ||||||||
319 | log_error_errno(r, "%s:%u: Line too long", filename, line)({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/shared/conf-parser.c", 319, __func__, "%s:%u: Line too long" , filename, line) : -abs(_e); }); | ||||||||
320 | |||||||||
321 | return r; | ||||||||
322 | } | ||||||||
323 | if (r < 0) { | ||||||||
324 | if (CONFIG_PARSE_WARN) | ||||||||
325 | log_error_errno(r, "%s:%u: Error while reading configuration file: %m", filename, line)({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/shared/conf-parser.c", 325, __func__, "%s:%u: Error while reading configuration file: %m" , filename, line) : -abs(_e); }); | ||||||||
326 | |||||||||
327 | return r; | ||||||||
328 | } | ||||||||
329 | |||||||||
330 | l = buf; | ||||||||
331 | if (!(flags & CONFIG_PARSE_REFUSE_BOM)) { | ||||||||
332 | char *q; | ||||||||
333 | |||||||||
334 | q = startswith(buf, UTF8_BYTE_ORDER_MARK"\xef\xbb\xbf"); | ||||||||
335 | if (q) { | ||||||||
336 | l = q; | ||||||||
337 | flags |= CONFIG_PARSE_REFUSE_BOM; | ||||||||
338 | } | ||||||||
339 | } | ||||||||
340 | |||||||||
341 | if (continuation) { | ||||||||
342 | if (strlen(continuation) + strlen(l) > LONG_LINE_MAX(1U*1024U*1024U)) { | ||||||||
343 | if (flags & CONFIG_PARSE_WARN) | ||||||||
344 | log_error("%s:%u: Continuation line too long", filename, line)({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/shared/conf-parser.c", 344, __func__, "%s:%u: Continuation line too long" , filename, line) : -abs(_e); }); | ||||||||
345 | return -ENOBUFS105; | ||||||||
346 | } | ||||||||
347 | |||||||||
348 | if (!strextend(&continuation, l, NULL)strextend_with_separator(&continuation, ((void*)0), l, (( void*)0))) { | ||||||||
349 | if (flags & CONFIG_PARSE_WARN) | ||||||||
350 | log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/shared/conf-parser.c" , 350, __func__); | ||||||||
351 | return -ENOMEM12; | ||||||||
352 | } | ||||||||
353 | |||||||||
354 | p = continuation; | ||||||||
355 | } else | ||||||||
356 | p = l; | ||||||||
357 | |||||||||
358 | for (e = p; *e; e++) { | ||||||||
359 | if (escaped) | ||||||||
360 | escaped = false0; | ||||||||
361 | else if (*e == '\\') | ||||||||
362 | escaped = true1; | ||||||||
363 | } | ||||||||
364 | |||||||||
365 | if (escaped) { | ||||||||
366 | *(e-1) = ' '; | ||||||||
367 | |||||||||
368 | if (!continuation) { | ||||||||
369 | continuation = strdup(l); | ||||||||
370 | if (!continuation) { | ||||||||
371 | if (flags & CONFIG_PARSE_WARN) | ||||||||
372 | log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/shared/conf-parser.c" , 372, __func__); | ||||||||
373 | return -ENOMEM12; | ||||||||
374 | } | ||||||||
375 | } | ||||||||
376 | |||||||||
377 | continue; | ||||||||
378 | } | ||||||||
379 | |||||||||
380 | r = parse_line(unit, | ||||||||
381 | filename, | ||||||||
382 | ++line, | ||||||||
383 | sections, | ||||||||
384 | lookup, | ||||||||
385 | table, | ||||||||
386 | flags, | ||||||||
387 | §ion, | ||||||||
388 | §ion_line, | ||||||||
389 | §ion_ignored, | ||||||||
390 | p, | ||||||||
391 | userdata); | ||||||||
392 | if (r < 0) { | ||||||||
393 | if (flags & CONFIG_PARSE_WARN) | ||||||||
394 | log_warning_errno(r, "%s:%u: Failed to parse file: %m", filename, line)({ int _level = ((4)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/shared/conf-parser.c", 394, __func__, "%s:%u: Failed to parse file: %m" , filename, line) : -abs(_e); }); | ||||||||
395 | return r; | ||||||||
396 | } | ||||||||
397 | |||||||||
398 | continuation = mfree(continuation); | ||||||||
399 | } | ||||||||
400 | |||||||||
401 | if (continuation) { | ||||||||
402 | r = parse_line(unit, | ||||||||
403 | filename, | ||||||||
404 | ++line, | ||||||||
405 | sections, | ||||||||
406 | lookup, | ||||||||
407 | table, | ||||||||
408 | flags, | ||||||||
409 | §ion, | ||||||||
410 | §ion_line, | ||||||||
411 | §ion_ignored, | ||||||||
412 | continuation, | ||||||||
413 | userdata); | ||||||||
414 | if (r < 0) { | ||||||||
415 | if (flags & CONFIG_PARSE_WARN) | ||||||||
416 | log_warning_errno(r, "%s:%u: Failed to parse file: %m", filename, line)({ int _level = ((4)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/shared/conf-parser.c", 416, __func__, "%s:%u: Failed to parse file: %m" , filename, line) : -abs(_e); }); | ||||||||
417 | return r; | ||||||||
418 | } | ||||||||
419 | } | ||||||||
420 | |||||||||
421 | return 0; | ||||||||
422 | } | ||||||||
423 | |||||||||
424 | static int config_parse_many_files( | ||||||||
425 | const char *conf_file, | ||||||||
426 | char **files, | ||||||||
427 | const char *sections, | ||||||||
428 | ConfigItemLookup lookup, | ||||||||
429 | const void *table, | ||||||||
430 | ConfigParseFlags flags, | ||||||||
431 | void *userdata) { | ||||||||
432 | |||||||||
433 | char **fn; | ||||||||
434 | int r; | ||||||||
435 | |||||||||
436 | if (conf_file) { | ||||||||
437 | r = config_parse(NULL((void*)0), conf_file, NULL((void*)0), sections, lookup, table, flags, userdata); | ||||||||
438 | if (r < 0) | ||||||||
439 | return r; | ||||||||
440 | } | ||||||||
441 | |||||||||
442 | STRV_FOREACH(fn, files)for ((fn) = (files); (fn) && *(fn); (fn)++) { | ||||||||
443 | r = config_parse(NULL((void*)0), *fn, NULL((void*)0), sections, lookup, table, flags, userdata); | ||||||||
444 | if (r < 0) | ||||||||
445 | return r; | ||||||||
446 | } | ||||||||
447 | |||||||||
448 | return 0; | ||||||||
449 | } | ||||||||
450 | |||||||||
451 | /* Parse each config file in the directories specified as nulstr. */ | ||||||||
452 | int config_parse_many_nulstr( | ||||||||
453 | const char *conf_file, | ||||||||
454 | const char *conf_file_dirs, | ||||||||
455 | const char *sections, | ||||||||
456 | ConfigItemLookup lookup, | ||||||||
457 | const void *table, | ||||||||
458 | ConfigParseFlags flags, | ||||||||
459 | void *userdata) { | ||||||||
460 | |||||||||
461 | _cleanup_strv_free___attribute__((cleanup(strv_freep))) char **files = NULL((void*)0); | ||||||||
462 | int r; | ||||||||
463 | |||||||||
464 | r = conf_files_list_nulstr(&files, ".conf", NULL((void*)0), 0, conf_file_dirs); | ||||||||
465 | if (r < 0) | ||||||||
466 | return r; | ||||||||
467 | |||||||||
468 | return config_parse_many_files(conf_file, files, sections, lookup, table, flags, userdata); | ||||||||
469 | } | ||||||||
470 | |||||||||
471 | /* Parse each config file in the directories specified as strv. */ | ||||||||
472 | int config_parse_many( | ||||||||
473 | const char *conf_file, | ||||||||
474 | const char* const* conf_file_dirs, | ||||||||
475 | const char *dropin_dirname, | ||||||||
476 | const char *sections, | ||||||||
477 | ConfigItemLookup lookup, | ||||||||
478 | const void *table, | ||||||||
479 | ConfigParseFlags flags, | ||||||||
480 | void *userdata) { | ||||||||
481 | |||||||||
482 | _cleanup_strv_free___attribute__((cleanup(strv_freep))) char **dropin_dirs = NULL((void*)0); | ||||||||
483 | _cleanup_strv_free___attribute__((cleanup(strv_freep))) char **files = NULL((void*)0); | ||||||||
484 | const char *suffix; | ||||||||
485 | int r; | ||||||||
486 | |||||||||
487 | suffix = strjoina("/", dropin_dirname)({ const char *_appendees_[] = { "/", dropin_dirname }; char * _d_, *_p_; size_t _len_ = 0; size_t _i_; for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr( !__builtin_types_compatible_p (typeof(_appendees_), typeof(&*(_appendees_))), sizeof(_appendees_ )/sizeof((_appendees_)[0]), ((void)0))) && _appendees_ [_i_]; _i_++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca (_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr ( !__builtin_types_compatible_p(typeof(_appendees_), typeof(& *(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0] ), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy (_p_, _appendees_[_i_]); *_p_ = 0; _d_; }); | ||||||||
488 | r = strv_extend_strv_concat(&dropin_dirs, (char**) conf_file_dirs, suffix); | ||||||||
489 | if (r < 0) | ||||||||
490 | return r; | ||||||||
491 | |||||||||
492 | r = conf_files_list_strv(&files, ".conf", NULL((void*)0), 0, (const char* const*) dropin_dirs); | ||||||||
493 | if (r < 0) | ||||||||
494 | return r; | ||||||||
495 | |||||||||
496 | return config_parse_many_files(conf_file, files, sections, lookup, table, flags, userdata); | ||||||||
497 | } | ||||||||
498 | |||||||||
499 | #define DEFINE_PARSER(type, vartype, conv_func)int config_parse_type(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata) { vartype *i = data; int r; do { if ((__builtin_expect (!!(!(filename)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("filename"), "../src/shared/conf-parser.c", 499, __PRETTY_FUNCTION__ ); } while (0); do { if ((__builtin_expect(!!(!(lvalue)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("lvalue"), "../src/shared/conf-parser.c" , 499, __PRETTY_FUNCTION__); } while (0); do { if ((__builtin_expect (!!(!(rvalue)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("rvalue"), "../src/shared/conf-parser.c", 499, __PRETTY_FUNCTION__ ); } while (0); do { if ((__builtin_expect(!!(!(data)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("data"), "../src/shared/conf-parser.c", 499 , __PRETTY_FUNCTION__); } while (0); r = conv_func(rvalue, i) ; if (r < 0) ({ int _level = (3), _e = (r); (log_get_max_level_realm (LOG_REALM_SYSTEMD) >= ((_level) & 0x07)) ? log_syntax_internal (unit, _level, filename, line, _e, "../src/shared/conf-parser.c" , 499, __func__, "Failed to parse " "type" " value" ", ignoring: %s" , rvalue) : -abs(_e); }); return 0; } \ | ||||||||
500 | DEFINE_CONFIG_PARSE_PTR(config_parse_##type, conv_func, vartype, "Failed to parse " #type " value")int config_parse_##type(const char *unit, const char *filename , unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata) { vartype *i = data; int r; do { if ((__builtin_expect (!!(!(filename)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("filename"), "../src/shared/conf-parser.c", 500, __PRETTY_FUNCTION__ ); } while (0); do { if ((__builtin_expect(!!(!(lvalue)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("lvalue"), "../src/shared/conf-parser.c" , 500, __PRETTY_FUNCTION__); } while (0); do { if ((__builtin_expect (!!(!(rvalue)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("rvalue"), "../src/shared/conf-parser.c", 500, __PRETTY_FUNCTION__ ); } while (0); do { if ((__builtin_expect(!!(!(data)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("data"), "../src/shared/conf-parser.c", 500 , __PRETTY_FUNCTION__); } while (0); r = conv_func(rvalue, i) ; if (r < 0) ({ int _level = (3), _e = (r); (log_get_max_level_realm (LOG_REALM_SYSTEMD) >= ((_level) & 0x07)) ? log_syntax_internal (unit, _level, filename, line, _e, "../src/shared/conf-parser.c" , 500, __func__, "Failed to parse " #type " value" ", ignoring: %s" , rvalue) : -abs(_e); }); return 0; } | ||||||||
501 | |||||||||
502 | DEFINE_PARSER(int, int, safe_atoi)int config_parse_int(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata ) { int *i = data; int r; do { if ((__builtin_expect(!!(!(filename )),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("filename" ), "../src/shared/conf-parser.c", 502, __PRETTY_FUNCTION__); } while (0); do { if ((__builtin_expect(!!(!(lvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("lvalue"), "../src/shared/conf-parser.c" , 502, __PRETTY_FUNCTION__); } while (0); do { if ((__builtin_expect (!!(!(rvalue)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("rvalue"), "../src/shared/conf-parser.c", 502, __PRETTY_FUNCTION__ ); } while (0); do { if ((__builtin_expect(!!(!(data)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("data"), "../src/shared/conf-parser.c", 502 , __PRETTY_FUNCTION__); } while (0); r = safe_atoi(rvalue, i) ; if (r < 0) ({ int _level = (3), _e = (r); (log_get_max_level_realm (LOG_REALM_SYSTEMD) >= ((_level) & 0x07)) ? log_syntax_internal (unit, _level, filename, line, _e, "../src/shared/conf-parser.c" , 502, __func__, "Failed to parse " "int" " value" ", ignoring: %s" , rvalue) : -abs(_e); }); return 0; }; | ||||||||
503 | DEFINE_PARSER(long, long, safe_atoli)int config_parse_long(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata) { long *i = data; int r; do { if ((__builtin_expect (!!(!(filename)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("filename"), "../src/shared/conf-parser.c", 503, __PRETTY_FUNCTION__ ); } while (0); do { if ((__builtin_expect(!!(!(lvalue)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("lvalue"), "../src/shared/conf-parser.c" , 503, __PRETTY_FUNCTION__); } while (0); do { if ((__builtin_expect (!!(!(rvalue)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("rvalue"), "../src/shared/conf-parser.c", 503, __PRETTY_FUNCTION__ ); } while (0); do { if ((__builtin_expect(!!(!(data)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("data"), "../src/shared/conf-parser.c", 503 , __PRETTY_FUNCTION__); } while (0); r = safe_atoli(rvalue, i ); if (r < 0) ({ int _level = (3), _e = (r); (log_get_max_level_realm (LOG_REALM_SYSTEMD) >= ((_level) & 0x07)) ? log_syntax_internal (unit, _level, filename, line, _e, "../src/shared/conf-parser.c" , 503, __func__, "Failed to parse " "long" " value" ", ignoring: %s" , rvalue) : -abs(_e); }); return 0; }; | ||||||||
504 | DEFINE_PARSER(uint8, uint8_t, safe_atou8)int config_parse_uint8(const char *unit, const char *filename , unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata) { uint8_t *i = data; int r; do { if ((__builtin_expect (!!(!(filename)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("filename"), "../src/shared/conf-parser.c", 504, __PRETTY_FUNCTION__ ); } while (0); do { if ((__builtin_expect(!!(!(lvalue)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("lvalue"), "../src/shared/conf-parser.c" , 504, __PRETTY_FUNCTION__); } while (0); do { if ((__builtin_expect (!!(!(rvalue)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("rvalue"), "../src/shared/conf-parser.c", 504, __PRETTY_FUNCTION__ ); } while (0); do { if ((__builtin_expect(!!(!(data)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("data"), "../src/shared/conf-parser.c", 504 , __PRETTY_FUNCTION__); } while (0); r = safe_atou8(rvalue, i ); if (r < 0) ({ int _level = (3), _e = (r); (log_get_max_level_realm (LOG_REALM_SYSTEMD) >= ((_level) & 0x07)) ? log_syntax_internal (unit, _level, filename, line, _e, "../src/shared/conf-parser.c" , 504, __func__, "Failed to parse " "uint8" " value" ", ignoring: %s" , rvalue) : -abs(_e); }); return 0; }; | ||||||||
505 | DEFINE_PARSER(uint16, uint16_t, safe_atou16)int config_parse_uint16(const char *unit, const char *filename , unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata) { uint16_t *i = data; int r; do { if ((__builtin_expect (!!(!(filename)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("filename"), "../src/shared/conf-parser.c", 505, __PRETTY_FUNCTION__ ); } while (0); do { if ((__builtin_expect(!!(!(lvalue)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("lvalue"), "../src/shared/conf-parser.c" , 505, __PRETTY_FUNCTION__); } while (0); do { if ((__builtin_expect (!!(!(rvalue)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("rvalue"), "../src/shared/conf-parser.c", 505, __PRETTY_FUNCTION__ ); } while (0); do { if ((__builtin_expect(!!(!(data)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("data"), "../src/shared/conf-parser.c", 505 , __PRETTY_FUNCTION__); } while (0); r = safe_atou16(rvalue, i ); if (r < 0) ({ int _level = (3), _e = (r); (log_get_max_level_realm (LOG_REALM_SYSTEMD) >= ((_level) & 0x07)) ? log_syntax_internal (unit, _level, filename, line, _e, "../src/shared/conf-parser.c" , 505, __func__, "Failed to parse " "uint16" " value" ", ignoring: %s" , rvalue) : -abs(_e); }); return 0; }; | ||||||||
506 | DEFINE_PARSER(uint32, uint32_t, safe_atou32)int config_parse_uint32(const char *unit, const char *filename , unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata) { uint32_t *i = data; int r; do { if ((__builtin_expect (!!(!(filename)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("filename"), "../src/shared/conf-parser.c", 506, __PRETTY_FUNCTION__ ); } while (0); do { if ((__builtin_expect(!!(!(lvalue)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("lvalue"), "../src/shared/conf-parser.c" , 506, __PRETTY_FUNCTION__); } while (0); do { if ((__builtin_expect (!!(!(rvalue)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("rvalue"), "../src/shared/conf-parser.c", 506, __PRETTY_FUNCTION__ ); } while (0); do { if ((__builtin_expect(!!(!(data)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("data"), "../src/shared/conf-parser.c", 506 , __PRETTY_FUNCTION__); } while (0); r = safe_atou32(rvalue, i ); if (r < 0) ({ int _level = (3), _e = (r); (log_get_max_level_realm (LOG_REALM_SYSTEMD) >= ((_level) & 0x07)) ? log_syntax_internal (unit, _level, filename, line, _e, "../src/shared/conf-parser.c" , 506, __func__, "Failed to parse " "uint32" " value" ", ignoring: %s" , rvalue) : -abs(_e); }); return 0; }; | ||||||||
507 | DEFINE_PARSER(uint64, uint64_t, safe_atou64)int config_parse_uint64(const char *unit, const char *filename , unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata) { uint64_t *i = data; int r; do { if ((__builtin_expect (!!(!(filename)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("filename"), "../src/shared/conf-parser.c", 507, __PRETTY_FUNCTION__ ); } while (0); do { if ((__builtin_expect(!!(!(lvalue)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("lvalue"), "../src/shared/conf-parser.c" , 507, __PRETTY_FUNCTION__); } while (0); do { if ((__builtin_expect (!!(!(rvalue)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("rvalue"), "../src/shared/conf-parser.c", 507, __PRETTY_FUNCTION__ ); } while (0); do { if ((__builtin_expect(!!(!(data)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("data"), "../src/shared/conf-parser.c", 507 , __PRETTY_FUNCTION__); } while (0); r = safe_atou64(rvalue, i ); if (r < 0) ({ int _level = (3), _e = (r); (log_get_max_level_realm (LOG_REALM_SYSTEMD) >= ((_level) & 0x07)) ? log_syntax_internal (unit, _level, filename, line, _e, "../src/shared/conf-parser.c" , 507, __func__, "Failed to parse " "uint64" " value" ", ignoring: %s" , rvalue) : -abs(_e); }); return 0; }; | ||||||||
508 | DEFINE_PARSER(unsigned, unsigned, safe_atou)int config_parse_unsigned(const char *unit, const char *filename , unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata) { unsigned *i = data; int r; do { if ((__builtin_expect (!!(!(filename)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("filename"), "../src/shared/conf-parser.c", 508, __PRETTY_FUNCTION__ ); } while (0); do { if ((__builtin_expect(!!(!(lvalue)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("lvalue"), "../src/shared/conf-parser.c" , 508, __PRETTY_FUNCTION__); } while (0); do { if ((__builtin_expect (!!(!(rvalue)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("rvalue"), "../src/shared/conf-parser.c", 508, __PRETTY_FUNCTION__ ); } while (0); do { if ((__builtin_expect(!!(!(data)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("data"), "../src/shared/conf-parser.c", 508 , __PRETTY_FUNCTION__); } while (0); r = safe_atou(rvalue, i) ; if (r < 0) ({ int _level = (3), _e = (r); (log_get_max_level_realm (LOG_REALM_SYSTEMD) >= ((_level) & 0x07)) ? log_syntax_internal (unit, _level, filename, line, _e, "../src/shared/conf-parser.c" , 508, __func__, "Failed to parse " "unsigned" " value" ", ignoring: %s" , rvalue) : -abs(_e); }); return 0; }; | ||||||||
509 | DEFINE_PARSER(double, double, safe_atod)int config_parse_double(const char *unit, const char *filename , unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata) { double *i = data; int r; do { if ((__builtin_expect (!!(!(filename)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("filename"), "../src/shared/conf-parser.c", 509, __PRETTY_FUNCTION__ ); } while (0); do { if ((__builtin_expect(!!(!(lvalue)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("lvalue"), "../src/shared/conf-parser.c" , 509, __PRETTY_FUNCTION__); } while (0); do { if ((__builtin_expect (!!(!(rvalue)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("rvalue"), "../src/shared/conf-parser.c", 509, __PRETTY_FUNCTION__ ); } while (0); do { if ((__builtin_expect(!!(!(data)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("data"), "../src/shared/conf-parser.c", 509 , __PRETTY_FUNCTION__); } while (0); r = safe_atod(rvalue, i) ; if (r < 0) ({ int _level = (3), _e = (r); (log_get_max_level_realm (LOG_REALM_SYSTEMD) >= ((_level) & 0x07)) ? log_syntax_internal (unit, _level, filename, line, _e, "../src/shared/conf-parser.c" , 509, __func__, "Failed to parse " "double" " value" ", ignoring: %s" , rvalue) : -abs(_e); }); return 0; }; | ||||||||
510 | DEFINE_PARSER(nsec, nsec_t, parse_nsec)int config_parse_nsec(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata) { nsec_t *i = data; int r; do { if ((__builtin_expect (!!(!(filename)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("filename"), "../src/shared/conf-parser.c", 510, __PRETTY_FUNCTION__ ); } while (0); do { if ((__builtin_expect(!!(!(lvalue)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("lvalue"), "../src/shared/conf-parser.c" , 510, __PRETTY_FUNCTION__); } while (0); do { if ((__builtin_expect (!!(!(rvalue)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("rvalue"), "../src/shared/conf-parser.c", 510, __PRETTY_FUNCTION__ ); } while (0); do { if ((__builtin_expect(!!(!(data)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("data"), "../src/shared/conf-parser.c", 510 , __PRETTY_FUNCTION__); } while (0); r = parse_nsec(rvalue, i ); if (r < 0) ({ int _level = (3), _e = (r); (log_get_max_level_realm (LOG_REALM_SYSTEMD) >= ((_level) & 0x07)) ? log_syntax_internal (unit, _level, filename, line, _e, "../src/shared/conf-parser.c" , 510, __func__, "Failed to parse " "nsec" " value" ", ignoring: %s" , rvalue) : -abs(_e); }); return 0; }; | ||||||||
511 | DEFINE_PARSER(sec, usec_t, parse_sec)int config_parse_sec(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata ) { usec_t *i = data; int r; do { if ((__builtin_expect(!!(!( filename)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("filename" ), "../src/shared/conf-parser.c", 511, __PRETTY_FUNCTION__); } while (0); do { if ((__builtin_expect(!!(!(lvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("lvalue"), "../src/shared/conf-parser.c" , 511, __PRETTY_FUNCTION__); } while (0); do { if ((__builtin_expect (!!(!(rvalue)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("rvalue"), "../src/shared/conf-parser.c", 511, __PRETTY_FUNCTION__ ); } while (0); do { if ((__builtin_expect(!!(!(data)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("data"), "../src/shared/conf-parser.c", 511 , __PRETTY_FUNCTION__); } while (0); r = parse_sec(rvalue, i) ; if (r < 0) ({ int _level = (3), _e = (r); (log_get_max_level_realm (LOG_REALM_SYSTEMD) >= ((_level) & 0x07)) ? log_syntax_internal (unit, _level, filename, line, _e, "../src/shared/conf-parser.c" , 511, __func__, "Failed to parse " "sec" " value" ", ignoring: %s" , rvalue) : -abs(_e); }); return 0; }; | ||||||||
512 | DEFINE_PARSER(sec_def_infinity, usec_t, parse_sec_def_infinity)int config_parse_sec_def_infinity(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line , const char *lvalue, int ltype, const char *rvalue, void *data , void *userdata) { usec_t *i = data; int r; do { if ((__builtin_expect (!!(!(filename)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("filename"), "../src/shared/conf-parser.c", 512, __PRETTY_FUNCTION__ ); } while (0); do { if ((__builtin_expect(!!(!(lvalue)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("lvalue"), "../src/shared/conf-parser.c" , 512, __PRETTY_FUNCTION__); } while (0); do { if ((__builtin_expect (!!(!(rvalue)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("rvalue"), "../src/shared/conf-parser.c", 512, __PRETTY_FUNCTION__ ); } while (0); do { if ((__builtin_expect(!!(!(data)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("data"), "../src/shared/conf-parser.c", 512 , __PRETTY_FUNCTION__); } while (0); r = parse_sec_def_infinity (rvalue, i); if (r < 0) ({ int _level = (3), _e = (r); (log_get_max_level_realm (LOG_REALM_SYSTEMD) >= ((_level) & 0x07)) ? log_syntax_internal (unit, _level, filename, line, _e, "../src/shared/conf-parser.c" , 512, __func__, "Failed to parse " "sec_def_infinity" " value" ", ignoring: %s", rvalue) : -abs(_e); }); return 0; }; | ||||||||
513 | DEFINE_PARSER(mode, mode_t, parse_mode)int config_parse_mode(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata) { mode_t *i = data; int r; do { if ((__builtin_expect (!!(!(filename)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("filename"), "../src/shared/conf-parser.c", 513, __PRETTY_FUNCTION__ ); } while (0); do { if ((__builtin_expect(!!(!(lvalue)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("lvalue"), "../src/shared/conf-parser.c" , 513, __PRETTY_FUNCTION__); } while (0); do { if ((__builtin_expect (!!(!(rvalue)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("rvalue"), "../src/shared/conf-parser.c", 513, __PRETTY_FUNCTION__ ); } while (0); do { if ((__builtin_expect(!!(!(data)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("data"), "../src/shared/conf-parser.c", 513 , __PRETTY_FUNCTION__); } while (0); r = parse_mode(rvalue, i ); if (r < 0) ({ int _level = (3), _e = (r); (log_get_max_level_realm (LOG_REALM_SYSTEMD) >= ((_level) & 0x07)) ? log_syntax_internal (unit, _level, filename, line, _e, "../src/shared/conf-parser.c" , 513, __func__, "Failed to parse " "mode" " value" ", ignoring: %s" , rvalue) : -abs(_e); }); return 0; }; | ||||||||
514 | |||||||||
515 | int config_parse_iec_size(const char* unit, | ||||||||
516 | const char *filename, | ||||||||
517 | unsigned line, | ||||||||
518 | const char *section, | ||||||||
519 | unsigned section_line, | ||||||||
520 | const char *lvalue, | ||||||||
521 | int ltype, | ||||||||
522 | const char *rvalue, | ||||||||
523 | void *data, | ||||||||
524 | void *userdata) { | ||||||||
525 | |||||||||
526 | size_t *sz = data; | ||||||||
527 | uint64_t v; | ||||||||
528 | int r; | ||||||||
529 | |||||||||
530 | assert(filename)do { if ((__builtin_expect(!!(!(filename)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("filename"), "../src/shared/conf-parser.c" , 530, __PRETTY_FUNCTION__); } while (0); | ||||||||
531 | assert(lvalue)do { if ((__builtin_expect(!!(!(lvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("lvalue"), "../src/shared/conf-parser.c" , 531, __PRETTY_FUNCTION__); } while (0); | ||||||||
532 | assert(rvalue)do { if ((__builtin_expect(!!(!(rvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("rvalue"), "../src/shared/conf-parser.c" , 532, __PRETTY_FUNCTION__); } while (0); | ||||||||
533 | assert(data)do { if ((__builtin_expect(!!(!(data)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("data"), "../src/shared/conf-parser.c", 533 , __PRETTY_FUNCTION__); } while (0); | ||||||||
534 | |||||||||
535 | r = parse_size(rvalue, 1024, &v); | ||||||||
536 | if (r < 0 || (uint64_t) (size_t) v != v) { | ||||||||
537 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse size value, ignoring: %s", rvalue)({ int _level = (3), _e = (r); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/shared/conf-parser.c", 537, __func__ , "Failed to parse size value, ignoring: %s", rvalue) : -abs( _e); }); | ||||||||
538 | return 0; | ||||||||
539 | } | ||||||||
540 | |||||||||
541 | *sz = (size_t) v; | ||||||||
542 | return 0; | ||||||||
543 | } | ||||||||
544 | |||||||||
545 | int config_parse_si_size( | ||||||||
546 | const char* unit, | ||||||||
547 | const char *filename, | ||||||||
548 | unsigned line, | ||||||||
549 | const char *section, | ||||||||
550 | unsigned section_line, | ||||||||
551 | const char *lvalue, | ||||||||
552 | int ltype, | ||||||||
553 | const char *rvalue, | ||||||||
554 | void *data, | ||||||||
555 | void *userdata) { | ||||||||
556 | |||||||||
557 | size_t *sz = data; | ||||||||
558 | uint64_t v; | ||||||||
559 | int r; | ||||||||
560 | |||||||||
561 | assert(filename)do { if ((__builtin_expect(!!(!(filename)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("filename"), "../src/shared/conf-parser.c" , 561, __PRETTY_FUNCTION__); } while (0); | ||||||||
562 | assert(lvalue)do { if ((__builtin_expect(!!(!(lvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("lvalue"), "../src/shared/conf-parser.c" , 562, __PRETTY_FUNCTION__); } while (0); | ||||||||
563 | assert(rvalue)do { if ((__builtin_expect(!!(!(rvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("rvalue"), "../src/shared/conf-parser.c" , 563, __PRETTY_FUNCTION__); } while (0); | ||||||||
564 | assert(data)do { if ((__builtin_expect(!!(!(data)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("data"), "../src/shared/conf-parser.c", 564 , __PRETTY_FUNCTION__); } while (0); | ||||||||
565 | |||||||||
566 | r = parse_size(rvalue, 1000, &v); | ||||||||
567 | if (r < 0 || (uint64_t) (size_t) v != v) { | ||||||||
568 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse size value, ignoring: %s", rvalue)({ int _level = (3), _e = (r); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/shared/conf-parser.c", 568, __func__ , "Failed to parse size value, ignoring: %s", rvalue) : -abs( _e); }); | ||||||||
569 | return 0; | ||||||||
570 | } | ||||||||
571 | |||||||||
572 | *sz = (size_t) v; | ||||||||
573 | return 0; | ||||||||
574 | } | ||||||||
575 | |||||||||
576 | int config_parse_iec_uint64( | ||||||||
577 | const char* unit, | ||||||||
578 | const char *filename, | ||||||||
579 | unsigned line, | ||||||||
580 | const char *section, | ||||||||
581 | unsigned section_line, | ||||||||
582 | const char *lvalue, | ||||||||
583 | int ltype, | ||||||||
584 | const char *rvalue, | ||||||||
585 | void *data, | ||||||||
586 | void *userdata) { | ||||||||
587 | |||||||||
588 | uint64_t *bytes = data; | ||||||||
589 | int r; | ||||||||
590 | |||||||||
591 | assert(filename)do { if ((__builtin_expect(!!(!(filename)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("filename"), "../src/shared/conf-parser.c" , 591, __PRETTY_FUNCTION__); } while (0); | ||||||||
592 | assert(lvalue)do { if ((__builtin_expect(!!(!(lvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("lvalue"), "../src/shared/conf-parser.c" , 592, __PRETTY_FUNCTION__); } while (0); | ||||||||
593 | assert(rvalue)do { if ((__builtin_expect(!!(!(rvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("rvalue"), "../src/shared/conf-parser.c" , 593, __PRETTY_FUNCTION__); } while (0); | ||||||||
594 | assert(data)do { if ((__builtin_expect(!!(!(data)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("data"), "../src/shared/conf-parser.c", 594 , __PRETTY_FUNCTION__); } while (0); | ||||||||
595 | |||||||||
596 | r = parse_size(rvalue, 1024, bytes); | ||||||||
597 | if (r < 0) | ||||||||
598 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse size value, ignoring: %s", rvalue)({ int _level = (3), _e = (r); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/shared/conf-parser.c", 598, __func__ , "Failed to parse size value, ignoring: %s", rvalue) : -abs( _e); }); | ||||||||
599 | |||||||||
600 | return 0; | ||||||||
601 | } | ||||||||
602 | |||||||||
603 | int config_parse_bool(const char* unit, | ||||||||
604 | const char *filename, | ||||||||
605 | unsigned line, | ||||||||
606 | const char *section, | ||||||||
607 | unsigned section_line, | ||||||||
608 | const char *lvalue, | ||||||||
609 | int ltype, | ||||||||
610 | const char *rvalue, | ||||||||
611 | void *data, | ||||||||
612 | void *userdata) { | ||||||||
613 | |||||||||
614 | int k; | ||||||||
615 | bool_Bool *b = data; | ||||||||
616 | bool_Bool fatal = ltype; | ||||||||
617 | |||||||||
618 | assert(filename)do { if ((__builtin_expect(!!(!(filename)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("filename"), "../src/shared/conf-parser.c" , 618, __PRETTY_FUNCTION__); } while (0); | ||||||||
619 | assert(lvalue)do { if ((__builtin_expect(!!(!(lvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("lvalue"), "../src/shared/conf-parser.c" , 619, __PRETTY_FUNCTION__); } while (0); | ||||||||
620 | assert(rvalue)do { if ((__builtin_expect(!!(!(rvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("rvalue"), "../src/shared/conf-parser.c" , 620, __PRETTY_FUNCTION__); } while (0); | ||||||||
621 | assert(data)do { if ((__builtin_expect(!!(!(data)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("data"), "../src/shared/conf-parser.c", 621 , __PRETTY_FUNCTION__); } while (0); | ||||||||
622 | |||||||||
623 | k = parse_boolean(rvalue); | ||||||||
624 | if (k < 0) { | ||||||||
625 | log_syntax(unit, LOG_ERR, filename, line, k,({ int _level = (3), _e = (k); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/shared/conf-parser.c", 627, __func__ , "Failed to parse boolean value%s: %s", fatal ? "" : ", ignoring" , rvalue) : -abs(_e); }) | ||||||||
626 | "Failed to parse boolean value%s: %s",({ int _level = (3), _e = (k); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/shared/conf-parser.c", 627, __func__ , "Failed to parse boolean value%s: %s", fatal ? "" : ", ignoring" , rvalue) : -abs(_e); }) | ||||||||
627 | fatal ? "" : ", ignoring", rvalue)({ int _level = (3), _e = (k); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/shared/conf-parser.c", 627, __func__ , "Failed to parse boolean value%s: %s", fatal ? "" : ", ignoring" , rvalue) : -abs(_e); }); | ||||||||
628 | return fatal ? -ENOEXEC8 : 0; | ||||||||
629 | } | ||||||||
630 | |||||||||
631 | *b = k; | ||||||||
632 | return 0; | ||||||||
633 | } | ||||||||
634 | |||||||||
635 | int config_parse_tristate( | ||||||||
636 | const char* unit, | ||||||||
637 | const char *filename, | ||||||||
638 | unsigned line, | ||||||||
639 | const char *section, | ||||||||
640 | unsigned section_line, | ||||||||
641 | const char *lvalue, | ||||||||
642 | int ltype, | ||||||||
643 | const char *rvalue, | ||||||||
644 | void *data, | ||||||||
645 | void *userdata) { | ||||||||
646 | |||||||||
647 | int k, *t = data; | ||||||||
648 | |||||||||
649 | assert(filename)do { if ((__builtin_expect(!!(!(filename)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("filename"), "../src/shared/conf-parser.c" , 649, __PRETTY_FUNCTION__); } while (0); | ||||||||
650 | assert(lvalue)do { if ((__builtin_expect(!!(!(lvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("lvalue"), "../src/shared/conf-parser.c" , 650, __PRETTY_FUNCTION__); } while (0); | ||||||||
651 | assert(rvalue)do { if ((__builtin_expect(!!(!(rvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("rvalue"), "../src/shared/conf-parser.c" , 651, __PRETTY_FUNCTION__); } while (0); | ||||||||
652 | assert(data)do { if ((__builtin_expect(!!(!(data)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("data"), "../src/shared/conf-parser.c", 652 , __PRETTY_FUNCTION__); } while (0); | ||||||||
653 | |||||||||
654 | /* A tristate is pretty much a boolean, except that it can | ||||||||
655 | * also take the special value -1, indicating "uninitialized", | ||||||||
656 | * much like NULL is for a pointer type. */ | ||||||||
657 | |||||||||
658 | k = parse_boolean(rvalue); | ||||||||
659 | if (k < 0) { | ||||||||
660 | log_syntax(unit, LOG_ERR, filename, line, k, "Failed to parse boolean value, ignoring: %s", rvalue)({ int _level = (3), _e = (k); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/shared/conf-parser.c", 660, __func__ , "Failed to parse boolean value, ignoring: %s", rvalue) : -abs (_e); }); | ||||||||
661 | return 0; | ||||||||
662 | } | ||||||||
663 | |||||||||
664 | *t = !!k; | ||||||||
665 | return 0; | ||||||||
666 | } | ||||||||
667 | |||||||||
668 | int config_parse_string( | ||||||||
669 | const char *unit, | ||||||||
670 | const char *filename, | ||||||||
671 | unsigned line, | ||||||||
672 | const char *section, | ||||||||
673 | unsigned section_line, | ||||||||
674 | const char *lvalue, | ||||||||
675 | int ltype, | ||||||||
676 | const char *rvalue, | ||||||||
677 | void *data, | ||||||||
678 | void *userdata) { | ||||||||
679 | |||||||||
680 | char **s = data; | ||||||||
681 | |||||||||
682 | assert(filename)do { if ((__builtin_expect(!!(!(filename)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("filename"), "../src/shared/conf-parser.c" , 682, __PRETTY_FUNCTION__); } while (0); | ||||||||
683 | assert(lvalue)do { if ((__builtin_expect(!!(!(lvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("lvalue"), "../src/shared/conf-parser.c" , 683, __PRETTY_FUNCTION__); } while (0); | ||||||||
684 | assert(rvalue)do { if ((__builtin_expect(!!(!(rvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("rvalue"), "../src/shared/conf-parser.c" , 684, __PRETTY_FUNCTION__); } while (0); | ||||||||
685 | assert(data)do { if ((__builtin_expect(!!(!(data)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("data"), "../src/shared/conf-parser.c", 685 , __PRETTY_FUNCTION__); } while (0); | ||||||||
686 | |||||||||
687 | if (free_and_strdup(s, empty_to_null(rvalue)) < 0) | ||||||||
688 | return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/shared/conf-parser.c" , 688, __func__); | ||||||||
689 | |||||||||
690 | return 0; | ||||||||
691 | } | ||||||||
692 | |||||||||
693 | int config_parse_path( | ||||||||
694 | const char *unit, | ||||||||
695 | const char *filename, | ||||||||
696 | unsigned line, | ||||||||
697 | const char *section, | ||||||||
698 | unsigned section_line, | ||||||||
699 | const char *lvalue, | ||||||||
700 | int ltype, | ||||||||
701 | const char *rvalue, | ||||||||
702 | void *data, | ||||||||
703 | void *userdata) { | ||||||||
704 | |||||||||
705 | _cleanup_free___attribute__((cleanup(freep))) char *n = NULL((void*)0); | ||||||||
706 | bool_Bool fatal = ltype; | ||||||||
707 | char **s = data; | ||||||||
708 | int r; | ||||||||
709 | |||||||||
710 | assert(filename)do { if ((__builtin_expect(!!(!(filename)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("filename"), "../src/shared/conf-parser.c" , 710, __PRETTY_FUNCTION__); } while (0); | ||||||||
711 | assert(lvalue)do { if ((__builtin_expect(!!(!(lvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("lvalue"), "../src/shared/conf-parser.c" , 711, __PRETTY_FUNCTION__); } while (0); | ||||||||
712 | assert(rvalue)do { if ((__builtin_expect(!!(!(rvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("rvalue"), "../src/shared/conf-parser.c" , 712, __PRETTY_FUNCTION__); } while (0); | ||||||||
713 | assert(data)do { if ((__builtin_expect(!!(!(data)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("data"), "../src/shared/conf-parser.c", 713 , __PRETTY_FUNCTION__); } while (0); | ||||||||
714 | |||||||||
715 | if (isempty(rvalue)) | ||||||||
716 | goto finalize; | ||||||||
717 | |||||||||
718 | n = strdup(rvalue); | ||||||||
719 | if (!n) | ||||||||
720 | return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/shared/conf-parser.c" , 720, __func__); | ||||||||
721 | |||||||||
722 | r = path_simplify_and_warn(n, PATH_CHECK_ABSOLUTE | (fatal ? PATH_CHECK_FATAL : 0), unit, filename, line, lvalue); | ||||||||
723 | if (r < 0) | ||||||||
724 | return fatal ? -ENOEXEC8 : 0; | ||||||||
725 | |||||||||
726 | finalize: | ||||||||
727 | return free_and_replace(*s, n)({ free(*s); (*s) = (n); (n) = ((void*)0); 0; }); | ||||||||
728 | } | ||||||||
729 | |||||||||
730 | int config_parse_strv( | ||||||||
731 | const char *unit, | ||||||||
732 | const char *filename, | ||||||||
733 | unsigned line, | ||||||||
734 | const char *section, | ||||||||
735 | unsigned section_line, | ||||||||
736 | const char *lvalue, | ||||||||
737 | int ltype, | ||||||||
738 | const char *rvalue, | ||||||||
739 | void *data, | ||||||||
740 | void *userdata) { | ||||||||
741 | |||||||||
742 | char ***sv = data; | ||||||||
743 | int r; | ||||||||
744 | |||||||||
745 | assert(filename)do { if ((__builtin_expect(!!(!(filename)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("filename"), "../src/shared/conf-parser.c" , 745, __PRETTY_FUNCTION__); } while (0); | ||||||||
746 | assert(lvalue)do { if ((__builtin_expect(!!(!(lvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("lvalue"), "../src/shared/conf-parser.c" , 746, __PRETTY_FUNCTION__); } while (0); | ||||||||
747 | assert(rvalue)do { if ((__builtin_expect(!!(!(rvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("rvalue"), "../src/shared/conf-parser.c" , 747, __PRETTY_FUNCTION__); } while (0); | ||||||||
748 | assert(data)do { if ((__builtin_expect(!!(!(data)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("data"), "../src/shared/conf-parser.c", 748 , __PRETTY_FUNCTION__); } while (0); | ||||||||
749 | |||||||||
750 | if (isempty(rvalue)) { | ||||||||
751 | *sv = strv_free(*sv); | ||||||||
752 | return 0; | ||||||||
753 | } | ||||||||
754 | |||||||||
755 | for (;;) { | ||||||||
756 | char *word = NULL((void*)0); | ||||||||
757 | |||||||||
758 | r = extract_first_word(&rvalue, &word, NULL((void*)0), EXTRACT_QUOTES|EXTRACT_RETAIN_ESCAPE); | ||||||||
759 | if (r == 0) | ||||||||
760 | break; | ||||||||
761 | if (r == -ENOMEM12) | ||||||||
762 | return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/shared/conf-parser.c" , 762, __func__); | ||||||||
763 | if (r < 0) { | ||||||||
764 | log_syntax(unit, LOG_ERR, filename, line, r, "Invalid syntax, ignoring: %s", rvalue)({ int _level = (3), _e = (r); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/shared/conf-parser.c", 764, __func__ , "Invalid syntax, ignoring: %s", rvalue) : -abs(_e); }); | ||||||||
765 | break; | ||||||||
766 | } | ||||||||
767 | |||||||||
768 | r = strv_consume(sv, word); | ||||||||
769 | if (r < 0) | ||||||||
770 | return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/shared/conf-parser.c" , 770, __func__); | ||||||||
771 | } | ||||||||
772 | |||||||||
773 | return 0; | ||||||||
774 | } | ||||||||
775 | |||||||||
776 | int config_parse_warn_compat( | ||||||||
777 | const char *unit, | ||||||||
778 | const char *filename, | ||||||||
779 | unsigned line, | ||||||||
780 | const char *section, | ||||||||
781 | unsigned section_line, | ||||||||
782 | const char *lvalue, | ||||||||
783 | int ltype, | ||||||||
784 | const char *rvalue, | ||||||||
785 | void *data, | ||||||||
786 | void *userdata) { | ||||||||
787 | |||||||||
788 | Disabled reason = ltype; | ||||||||
789 | |||||||||
790 | switch(reason) { | ||||||||
791 | |||||||||
792 | case DISABLED_CONFIGURATION: | ||||||||
793 | log_syntax(unit, LOG_DEBUG, filename, line, 0,({ int _level = (7), _e = (0); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/shared/conf-parser.c", 794, __func__ , "Support for option %s= has been disabled at compile time and it is ignored" , lvalue) : -abs(_e); }) | ||||||||
794 | "Support for option %s= has been disabled at compile time and it is ignored", lvalue)({ int _level = (7), _e = (0); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/shared/conf-parser.c", 794, __func__ , "Support for option %s= has been disabled at compile time and it is ignored" , lvalue) : -abs(_e); }); | ||||||||
795 | break; | ||||||||
796 | |||||||||
797 | case DISABLED_LEGACY: | ||||||||
798 | log_syntax(unit, LOG_INFO, filename, line, 0,({ int _level = (6), _e = (0); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/shared/conf-parser.c", 799, __func__ , "Support for option %s= has been removed and it is ignored" , lvalue) : -abs(_e); }) | ||||||||
799 | "Support for option %s= has been removed and it is ignored", lvalue)({ int _level = (6), _e = (0); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/shared/conf-parser.c", 799, __func__ , "Support for option %s= has been removed and it is ignored" , lvalue) : -abs(_e); }); | ||||||||
800 | break; | ||||||||
801 | |||||||||
802 | case DISABLED_EXPERIMENTAL: | ||||||||
803 | log_syntax(unit, LOG_INFO, filename, line, 0,({ int _level = (6), _e = (0); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/shared/conf-parser.c", 804, __func__ , "Support for option %s= has not yet been enabled and it is ignored" , lvalue) : -abs(_e); }) | ||||||||
804 | "Support for option %s= has not yet been enabled and it is ignored", lvalue)({ int _level = (6), _e = (0); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/shared/conf-parser.c", 804, __func__ , "Support for option %s= has not yet been enabled and it is ignored" , lvalue) : -abs(_e); }); | ||||||||
805 | break; | ||||||||
806 | } | ||||||||
807 | |||||||||
808 | return 0; | ||||||||
809 | } | ||||||||
810 | |||||||||
811 | int config_parse_log_facility( | ||||||||
812 | const char *unit, | ||||||||
813 | const char *filename, | ||||||||
814 | unsigned line, | ||||||||
815 | const char *section, | ||||||||
816 | unsigned section_line, | ||||||||
817 | const char *lvalue, | ||||||||
818 | int ltype, | ||||||||
819 | const char *rvalue, | ||||||||
820 | void *data, | ||||||||
821 | void *userdata) { | ||||||||
822 | |||||||||
823 | int *o = data, x; | ||||||||
824 | |||||||||
825 | assert(filename)do { if ((__builtin_expect(!!(!(filename)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("filename"), "../src/shared/conf-parser.c" , 825, __PRETTY_FUNCTION__); } while (0); | ||||||||
826 | assert(lvalue)do { if ((__builtin_expect(!!(!(lvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("lvalue"), "../src/shared/conf-parser.c" , 826, __PRETTY_FUNCTION__); } while (0); | ||||||||
827 | assert(rvalue)do { if ((__builtin_expect(!!(!(rvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("rvalue"), "../src/shared/conf-parser.c" , 827, __PRETTY_FUNCTION__); } while (0); | ||||||||
828 | assert(data)do { if ((__builtin_expect(!!(!(data)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("data"), "../src/shared/conf-parser.c", 828 , __PRETTY_FUNCTION__); } while (0); | ||||||||
829 | |||||||||
830 | x = log_facility_unshifted_from_string(rvalue); | ||||||||
831 | if (x < 0) { | ||||||||
832 | log_syntax(unit, LOG_ERR, filename, line, 0, "Failed to parse log facility, ignoring: %s", rvalue)({ int _level = (3), _e = (0); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/shared/conf-parser.c", 832, __func__ , "Failed to parse log facility, ignoring: %s", rvalue) : -abs (_e); }); | ||||||||
833 | return 0; | ||||||||
834 | } | ||||||||
835 | |||||||||
836 | *o = (x << 3) | LOG_PRI(*o)((*o) & 0x07); | ||||||||
837 | |||||||||
838 | return 0; | ||||||||
839 | } | ||||||||
840 | |||||||||
841 | int config_parse_log_level( | ||||||||
842 | const char *unit, | ||||||||
843 | const char *filename, | ||||||||
844 | unsigned line, | ||||||||
845 | const char *section, | ||||||||
846 | unsigned section_line, | ||||||||
847 | const char *lvalue, | ||||||||
848 | int ltype, | ||||||||
849 | const char *rvalue, | ||||||||
850 | void *data, | ||||||||
851 | void *userdata) { | ||||||||
852 | |||||||||
853 | int *o = data, x; | ||||||||
854 | |||||||||
855 | assert(filename)do { if ((__builtin_expect(!!(!(filename)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("filename"), "../src/shared/conf-parser.c" , 855, __PRETTY_FUNCTION__); } while (0); | ||||||||
856 | assert(lvalue)do { if ((__builtin_expect(!!(!(lvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("lvalue"), "../src/shared/conf-parser.c" , 856, __PRETTY_FUNCTION__); } while (0); | ||||||||
857 | assert(rvalue)do { if ((__builtin_expect(!!(!(rvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("rvalue"), "../src/shared/conf-parser.c" , 857, __PRETTY_FUNCTION__); } while (0); | ||||||||
858 | assert(data)do { if ((__builtin_expect(!!(!(data)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("data"), "../src/shared/conf-parser.c", 858 , __PRETTY_FUNCTION__); } while (0); | ||||||||
859 | |||||||||
860 | x = log_level_from_string(rvalue); | ||||||||
861 | if (x < 0) { | ||||||||
862 | log_syntax(unit, LOG_ERR, filename, line, 0, "Failed to parse log level, ignoring: %s", rvalue)({ int _level = (3), _e = (0); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/shared/conf-parser.c", 862, __func__ , "Failed to parse log level, ignoring: %s", rvalue) : -abs(_e ); }); | ||||||||
863 | return 0; | ||||||||
864 | } | ||||||||
865 | |||||||||
866 | if (*o < 0) /* if it wasn't initialized so far, assume zero facility */ | ||||||||
867 | *o = x; | ||||||||
868 | else | ||||||||
869 | *o = (*o & LOG_FACMASK0x03f8) | x; | ||||||||
870 | |||||||||
871 | return 0; | ||||||||
872 | } | ||||||||
873 | |||||||||
874 | int config_parse_signal( | ||||||||
875 | const char *unit, | ||||||||
876 | const char *filename, | ||||||||
877 | unsigned line, | ||||||||
878 | const char *section, | ||||||||
879 | unsigned section_line, | ||||||||
880 | const char *lvalue, | ||||||||
881 | int ltype, | ||||||||
882 | const char *rvalue, | ||||||||
883 | void *data, | ||||||||
884 | void *userdata) { | ||||||||
885 | |||||||||
886 | int *sig = data, r; | ||||||||
887 | |||||||||
888 | assert(filename)do { if ((__builtin_expect(!!(!(filename)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("filename"), "../src/shared/conf-parser.c" , 888, __PRETTY_FUNCTION__); } while (0); | ||||||||
889 | assert(lvalue)do { if ((__builtin_expect(!!(!(lvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("lvalue"), "../src/shared/conf-parser.c" , 889, __PRETTY_FUNCTION__); } while (0); | ||||||||
890 | assert(rvalue)do { if ((__builtin_expect(!!(!(rvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("rvalue"), "../src/shared/conf-parser.c" , 890, __PRETTY_FUNCTION__); } while (0); | ||||||||
891 | assert(sig)do { if ((__builtin_expect(!!(!(sig)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("sig"), "../src/shared/conf-parser.c", 891 , __PRETTY_FUNCTION__); } while (0); | ||||||||
892 | |||||||||
893 | r = signal_from_string(rvalue); | ||||||||
894 | if (r <= 0) { | ||||||||
895 | log_syntax(unit, LOG_ERR, filename, line, 0, "Failed to parse signal name, ignoring: %s", rvalue)({ int _level = (3), _e = (0); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/shared/conf-parser.c", 895, __func__ , "Failed to parse signal name, ignoring: %s", rvalue) : -abs (_e); }); | ||||||||
896 | return 0; | ||||||||
897 | } | ||||||||
898 | |||||||||
899 | *sig = r; | ||||||||
900 | return 0; | ||||||||
901 | } | ||||||||
902 | |||||||||
903 | int config_parse_personality( | ||||||||
904 | const char *unit, | ||||||||
905 | const char *filename, | ||||||||
906 | unsigned line, | ||||||||
907 | const char *section, | ||||||||
908 | unsigned section_line, | ||||||||
909 | const char *lvalue, | ||||||||
910 | int ltype, | ||||||||
911 | const char *rvalue, | ||||||||
912 | void *data, | ||||||||
913 | void *userdata) { | ||||||||
914 | |||||||||
915 | unsigned long *personality = data, p; | ||||||||
916 | |||||||||
917 | assert(filename)do { if ((__builtin_expect(!!(!(filename)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("filename"), "../src/shared/conf-parser.c" , 917, __PRETTY_FUNCTION__); } while (0); | ||||||||
918 | assert(lvalue)do { if ((__builtin_expect(!!(!(lvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("lvalue"), "../src/shared/conf-parser.c" , 918, __PRETTY_FUNCTION__); } while (0); | ||||||||
919 | assert(rvalue)do { if ((__builtin_expect(!!(!(rvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("rvalue"), "../src/shared/conf-parser.c" , 919, __PRETTY_FUNCTION__); } while (0); | ||||||||
920 | assert(personality)do { if ((__builtin_expect(!!(!(personality)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("personality"), "../src/shared/conf-parser.c" , 920, __PRETTY_FUNCTION__); } while (0); | ||||||||
921 | |||||||||
922 | if (isempty(rvalue)) | ||||||||
923 | p = PERSONALITY_INVALID0xffffffffLU; | ||||||||
924 | else { | ||||||||
925 | p = personality_from_string(rvalue); | ||||||||
926 | if (p == PERSONALITY_INVALID0xffffffffLU) { | ||||||||
927 | log_syntax(unit, LOG_ERR, filename, line, 0, "Failed to parse personality, ignoring: %s", rvalue)({ int _level = (3), _e = (0); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/shared/conf-parser.c", 927, __func__ , "Failed to parse personality, ignoring: %s", rvalue) : -abs (_e); }); | ||||||||
928 | return 0; | ||||||||
929 | } | ||||||||
930 | } | ||||||||
931 | |||||||||
932 | *personality = p; | ||||||||
933 | return 0; | ||||||||
934 | } | ||||||||
935 | |||||||||
936 | int config_parse_ifname( | ||||||||
937 | const char *unit, | ||||||||
938 | const char *filename, | ||||||||
939 | unsigned line, | ||||||||
940 | const char *section, | ||||||||
941 | unsigned section_line, | ||||||||
942 | const char *lvalue, | ||||||||
943 | int ltype, | ||||||||
944 | const char *rvalue, | ||||||||
945 | void *data, | ||||||||
946 | void *userdata) { | ||||||||
947 | |||||||||
948 | char **s = data; | ||||||||
949 | int r; | ||||||||
950 | |||||||||
951 | assert(filename)do { if ((__builtin_expect(!!(!(filename)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("filename"), "../src/shared/conf-parser.c" , 951, __PRETTY_FUNCTION__); } while (0); | ||||||||
952 | assert(lvalue)do { if ((__builtin_expect(!!(!(lvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("lvalue"), "../src/shared/conf-parser.c" , 952, __PRETTY_FUNCTION__); } while (0); | ||||||||
953 | assert(rvalue)do { if ((__builtin_expect(!!(!(rvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("rvalue"), "../src/shared/conf-parser.c" , 953, __PRETTY_FUNCTION__); } while (0); | ||||||||
954 | assert(data)do { if ((__builtin_expect(!!(!(data)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("data"), "../src/shared/conf-parser.c", 954 , __PRETTY_FUNCTION__); } while (0); | ||||||||
955 | |||||||||
956 | if (isempty(rvalue)) { | ||||||||
957 | *s = mfree(*s); | ||||||||
958 | return 0; | ||||||||
959 | } | ||||||||
960 | |||||||||
961 | if (!ifname_valid(rvalue)) { | ||||||||
962 | log_syntax(unit, LOG_ERR, filename, line, 0, "Interface name is not valid or too long, ignoring assignment: %s", rvalue)({ int _level = (3), _e = (0); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/shared/conf-parser.c", 962, __func__ , "Interface name is not valid or too long, ignoring assignment: %s" , rvalue) : -abs(_e); }); | ||||||||
963 | return 0; | ||||||||
964 | } | ||||||||
965 | |||||||||
966 | r = free_and_strdup(s, rvalue); | ||||||||
967 | if (r < 0) | ||||||||
968 | return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/shared/conf-parser.c" , 968, __func__); | ||||||||
969 | |||||||||
970 | return 0; | ||||||||
971 | } | ||||||||
972 | |||||||||
973 | int config_parse_ip_port( | ||||||||
974 | const char *unit, | ||||||||
975 | const char *filename, | ||||||||
976 | unsigned line, | ||||||||
977 | const char *section, | ||||||||
978 | unsigned section_line, | ||||||||
979 | const char *lvalue, | ||||||||
980 | int ltype, | ||||||||
981 | const char *rvalue, | ||||||||
982 | void *data, | ||||||||
983 | void *userdata) { | ||||||||
984 | |||||||||
985 | uint16_t *s = data; | ||||||||
986 | uint16_t port; | ||||||||
987 | int r; | ||||||||
988 | |||||||||
989 | assert(filename)do { if ((__builtin_expect(!!(!(filename)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("filename"), "../src/shared/conf-parser.c" , 989, __PRETTY_FUNCTION__); } while (0); | ||||||||
990 | assert(lvalue)do { if ((__builtin_expect(!!(!(lvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("lvalue"), "../src/shared/conf-parser.c" , 990, __PRETTY_FUNCTION__); } while (0); | ||||||||
991 | assert(rvalue)do { if ((__builtin_expect(!!(!(rvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("rvalue"), "../src/shared/conf-parser.c" , 991, __PRETTY_FUNCTION__); } while (0); | ||||||||
992 | assert(data)do { if ((__builtin_expect(!!(!(data)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("data"), "../src/shared/conf-parser.c", 992 , __PRETTY_FUNCTION__); } while (0); | ||||||||
993 | |||||||||
994 | if (isempty(rvalue)) { | ||||||||
995 | *s = 0; | ||||||||
996 | return 0; | ||||||||
997 | } | ||||||||
998 | |||||||||
999 | r = parse_ip_port(rvalue, &port); | ||||||||
1000 | if (r < 0) { | ||||||||
1001 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse port '%s'.", rvalue)({ int _level = (3), _e = (r); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/shared/conf-parser.c", 1001, __func__ , "Failed to parse port '%s'.", rvalue) : -abs(_e); }); | ||||||||
1002 | return 0; | ||||||||
1003 | } | ||||||||
1004 | |||||||||
1005 | *s = port; | ||||||||
1006 | |||||||||
1007 | return 0; | ||||||||
1008 | } | ||||||||
1009 | |||||||||
1010 | int config_parse_join_controllers( | ||||||||
1011 | const char *unit, | ||||||||
1012 | const char *filename, | ||||||||
1013 | unsigned line, | ||||||||
1014 | const char *section, | ||||||||
1015 | unsigned section_line, | ||||||||
1016 | const char *lvalue, | ||||||||
1017 | int ltype, | ||||||||
1018 | const char *rvalue, | ||||||||
1019 | void *data, | ||||||||
1020 | void *userdata) { | ||||||||
1021 | |||||||||
1022 | char ****ret = data; | ||||||||
1023 | const char *whole_rvalue = rvalue; | ||||||||
1024 | unsigned n = 0; | ||||||||
1025 | _cleanup_(strv_free_freep)__attribute__((cleanup(strv_free_freep))) char ***controllers = NULL((void*)0); | ||||||||
1026 | |||||||||
1027 | assert(filename)do { if ((__builtin_expect(!!(!(filename)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("filename"), "../src/shared/conf-parser.c" , 1027, __PRETTY_FUNCTION__); } while (0); | ||||||||
| |||||||||
1028 | assert(lvalue)do { if ((__builtin_expect(!!(!(lvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("lvalue"), "../src/shared/conf-parser.c" , 1028, __PRETTY_FUNCTION__); } while (0); | ||||||||
1029 | assert(rvalue)do { if ((__builtin_expect(!!(!(rvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("rvalue"), "../src/shared/conf-parser.c" , 1029, __PRETTY_FUNCTION__); } while (0); | ||||||||
1030 | assert(ret)do { if ((__builtin_expect(!!(!(ret)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("ret"), "../src/shared/conf-parser.c", 1030 , __PRETTY_FUNCTION__); } while (0); | ||||||||
1031 | |||||||||
1032 | for (;;) { | ||||||||
1033 | _cleanup_free___attribute__((cleanup(freep))) char *word = NULL((void*)0); | ||||||||
1034 | char **l; | ||||||||
1035 | int r; | ||||||||
1036 | |||||||||
1037 | r = extract_first_word(&rvalue, &word, NULL((void*)0), EXTRACT_QUOTES); | ||||||||
1038 | if (r < 0) { | ||||||||
1039 | log_syntax(unit, LOG_ERR, filename, line, r, "Invalid value for %s: %s", lvalue, whole_rvalue)({ int _level = (3), _e = (r); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/shared/conf-parser.c", 1039, __func__ , "Invalid value for %s: %s", lvalue, whole_rvalue) : -abs(_e ); }); | ||||||||
1040 | return r; | ||||||||
1041 | } | ||||||||
1042 | if (r == 0) | ||||||||
1043 | break; | ||||||||
1044 | |||||||||
1045 | l = strv_split(word, ","); | ||||||||
1046 | if (!l) | ||||||||
1047 | return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/shared/conf-parser.c" , 1047, __func__); | ||||||||
1048 | strv_uniq(l); | ||||||||
1049 | |||||||||
1050 | if (strv_length(l) <= 1) { | ||||||||
1051 | strv_free(l); | ||||||||
1052 | continue; | ||||||||
1053 | } | ||||||||
1054 | |||||||||
1055 | if (!controllers
| ||||||||
1056 | controllers = new(char**, 2)((char***) malloc_multiply(sizeof(char**), (2))); | ||||||||
1057 | if (!controllers) { | ||||||||
1058 | strv_free(l); | ||||||||
1059 | return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/shared/conf-parser.c" , 1059, __func__); | ||||||||
1060 | } | ||||||||
1061 | |||||||||
1062 | controllers[0] = l; | ||||||||
1063 | controllers[1] = NULL((void*)0); | ||||||||
1064 | |||||||||
1065 | n = 1; | ||||||||
1066 | } else { | ||||||||
1067 | char ***a; | ||||||||
1068 | char ***t; | ||||||||
1069 | |||||||||
1070 | t = new0(char**, n+2)((char***) calloc((n+2), sizeof(char**))); | ||||||||
1071 | if (!t) { | ||||||||
1072 | strv_free(l); | ||||||||
1073 | return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/shared/conf-parser.c" , 1073, __func__); | ||||||||
1074 | } | ||||||||
1075 | |||||||||
1076 | n = 0; | ||||||||
1077 | |||||||||
1078 | for (a = controllers; *a; a++) | ||||||||
1079 | if (strv_overlap(*a, l)) { | ||||||||
1080 | if (strv_extend_strv(&l, *a, false0) < 0) { | ||||||||
1081 | strv_free(l); | ||||||||
| |||||||||
1082 | strv_free_free(t); | ||||||||
1083 | return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/shared/conf-parser.c" , 1083, __func__); | ||||||||
1084 | } | ||||||||
1085 | |||||||||
1086 | } else { | ||||||||
1087 | char **c; | ||||||||
1088 | |||||||||
1089 | c = strv_copy(*a); | ||||||||
1090 | if (!c) { | ||||||||
1091 | strv_free(l); | ||||||||
1092 | strv_free_free(t); | ||||||||
1093 | return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/shared/conf-parser.c" , 1093, __func__); | ||||||||
1094 | } | ||||||||
1095 | |||||||||
1096 | t[n++] = c; | ||||||||
1097 | } | ||||||||
1098 | |||||||||
1099 | t[n++] = strv_uniq(l); | ||||||||
1100 | |||||||||
1101 | strv_free_free(controllers); | ||||||||
1102 | controllers = t; | ||||||||
1103 | } | ||||||||
1104 | } | ||||||||
1105 | if (!isempty(rvalue)) | ||||||||
1106 | log_syntax(unit, LOG_ERR, filename, line, 0, "Trailing garbage, ignoring.")({ int _level = (3), _e = (0); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/shared/conf-parser.c", 1106, __func__ , "Trailing garbage, ignoring.") : -abs(_e); }); | ||||||||
1107 | |||||||||
1108 | /* As a special case, return a single empty strv, to override the default */ | ||||||||
1109 | if (!controllers) { | ||||||||
1110 | controllers = new(char**, 2)((char***) malloc_multiply(sizeof(char**), (2))); | ||||||||
1111 | if (!controllers) | ||||||||
1112 | return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/shared/conf-parser.c" , 1112, __func__); | ||||||||
1113 | controllers[0] = strv_new(NULL((void*)0), NULL((void*)0)); | ||||||||
1114 | if (!controllers[0]) | ||||||||
1115 | return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/shared/conf-parser.c" , 1115, __func__); | ||||||||
1116 | controllers[1] = NULL((void*)0); | ||||||||
1117 | } | ||||||||
1118 | |||||||||
1119 | strv_free_free(*ret); | ||||||||
1120 | *ret = TAKE_PTR(controllers)({ typeof(controllers) _ptr_ = (controllers); (controllers) = ((void*)0); _ptr_; }); | ||||||||
1121 | |||||||||
1122 | return 0; | ||||||||
1123 | } | ||||||||
1124 | |||||||||
1125 | int config_parse_mtu( | ||||||||
1126 | const char *unit, | ||||||||
1127 | const char *filename, | ||||||||
1128 | unsigned line, | ||||||||
1129 | const char *section, | ||||||||
1130 | unsigned section_line, | ||||||||
1131 | const char *lvalue, | ||||||||
1132 | int ltype, | ||||||||
1133 | const char *rvalue, | ||||||||
1134 | void *data, | ||||||||
1135 | void *userdata) { | ||||||||
1136 | |||||||||
1137 | uint32_t *mtu = data; | ||||||||
1138 | int r; | ||||||||
1139 | |||||||||
1140 | assert(rvalue)do { if ((__builtin_expect(!!(!(rvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("rvalue"), "../src/shared/conf-parser.c" , 1140, __PRETTY_FUNCTION__); } while (0); | ||||||||
1141 | assert(mtu)do { if ((__builtin_expect(!!(!(mtu)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("mtu"), "../src/shared/conf-parser.c", 1141 , __PRETTY_FUNCTION__); } while (0); | ||||||||
1142 | |||||||||
1143 | r = parse_mtu(ltype, rvalue, mtu); | ||||||||
1144 | if (r == -ERANGE34) { | ||||||||
1145 | log_syntax(unit, LOG_ERR, filename, line, r,({ int _level = (3), _e = (r); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/shared/conf-parser.c", 1148, __func__ , "Maximum transfer unit (MTU) value out of range. Permitted range is %" "u" "…%" "u" ", ignoring: %s", (uint32_t) (ltype == 10 ? 1280 : 68), (uint32_t) (4294967295U), rvalue) : -abs(_e); }) | ||||||||
1146 | "Maximum transfer unit (MTU) value out of range. Permitted range is %" PRIu32 "…%" PRIu32 ", ignoring: %s",({ int _level = (3), _e = (r); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/shared/conf-parser.c", 1148, __func__ , "Maximum transfer unit (MTU) value out of range. Permitted range is %" "u" "…%" "u" ", ignoring: %s", (uint32_t) (ltype == 10 ? 1280 : 68), (uint32_t) (4294967295U), rvalue) : -abs(_e); }) | ||||||||
1147 | (uint32_t) (ltype == AF_INET6 ? IPV6_MIN_MTU : IPV4_MIN_MTU), (uint32_t) UINT32_MAX,({ int _level = (3), _e = (r); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/shared/conf-parser.c", 1148, __func__ , "Maximum transfer unit (MTU) value out of range. Permitted range is %" "u" "…%" "u" ", ignoring: %s", (uint32_t) (ltype == 10 ? 1280 : 68), (uint32_t) (4294967295U), rvalue) : -abs(_e); }) | ||||||||
1148 | rvalue)({ int _level = (3), _e = (r); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/shared/conf-parser.c", 1148, __func__ , "Maximum transfer unit (MTU) value out of range. Permitted range is %" "u" "…%" "u" ", ignoring: %s", (uint32_t) (ltype == 10 ? 1280 : 68), (uint32_t) (4294967295U), rvalue) : -abs(_e); }); | ||||||||
1149 | return 0; | ||||||||
1150 | } | ||||||||
1151 | if (r < 0) { | ||||||||
1152 | log_syntax(unit, LOG_ERR, filename, line, r,({ int _level = (3), _e = (r); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/shared/conf-parser.c", 1153, __func__ , "Failed to parse MTU value '%s', ignoring: %m", rvalue) : - abs(_e); }) | ||||||||
1153 | "Failed to parse MTU value '%s', ignoring: %m", rvalue)({ int _level = (3), _e = (r); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/shared/conf-parser.c", 1153, __func__ , "Failed to parse MTU value '%s', ignoring: %m", rvalue) : - abs(_e); }); | ||||||||
1154 | return 0; | ||||||||
1155 | } | ||||||||
1156 | |||||||||
1157 | return 0; | ||||||||
1158 | } | ||||||||
1159 | |||||||||
1160 | int config_parse_rlimit( | ||||||||
1161 | const char *unit, | ||||||||
1162 | const char *filename, | ||||||||
1163 | unsigned line, | ||||||||
1164 | const char *section, | ||||||||
1165 | unsigned section_line, | ||||||||
1166 | const char *lvalue, | ||||||||
1167 | int ltype, | ||||||||
1168 | const char *rvalue, | ||||||||
1169 | void *data, | ||||||||
1170 | void *userdata) { | ||||||||
1171 | |||||||||
1172 | struct rlimit **rl = data, d = {}; | ||||||||
1173 | int r; | ||||||||
1174 | |||||||||
1175 | assert(rvalue)do { if ((__builtin_expect(!!(!(rvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("rvalue"), "../src/shared/conf-parser.c" , 1175, __PRETTY_FUNCTION__); } while (0); | ||||||||
1176 | assert(rl)do { if ((__builtin_expect(!!(!(rl)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("rl"), "../src/shared/conf-parser.c", 1176 , __PRETTY_FUNCTION__); } while (0); | ||||||||
1177 | |||||||||
1178 | r = rlimit_parse(ltype, rvalue, &d); | ||||||||
1179 | if (r == -EILSEQ84) { | ||||||||
1180 | log_syntax(unit, LOG_WARNING, filename, line, r, "Soft resource limit chosen higher than hard limit, ignoring: %s", rvalue)({ int _level = (4), _e = (r); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/shared/conf-parser.c", 1180, __func__ , "Soft resource limit chosen higher than hard limit, ignoring: %s" , rvalue) : -abs(_e); }); | ||||||||
1181 | return 0; | ||||||||
1182 | } | ||||||||
1183 | if (r < 0) { | ||||||||
1184 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse resource value, ignoring: %s", rvalue)({ int _level = (3), _e = (r); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/shared/conf-parser.c", 1184, __func__ , "Failed to parse resource value, ignoring: %s", rvalue) : - abs(_e); }); | ||||||||
1185 | return 0; | ||||||||
1186 | } | ||||||||
1187 | |||||||||
1188 | if (rl[ltype]) | ||||||||
1189 | *rl[ltype] = d; | ||||||||
1190 | else { | ||||||||
1191 | rl[ltype] = newdup(struct rlimit, &d, 1)((struct rlimit*) memdup_multiply(&d, sizeof(struct rlimit ), (1))); | ||||||||
1192 | if (!rl[ltype]) | ||||||||
1193 | return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/shared/conf-parser.c" , 1193, __func__); | ||||||||
1194 | } | ||||||||
1195 | |||||||||
1196 | return 0; | ||||||||
1197 | } | ||||||||
1198 | |||||||||
1199 | int config_parse_permille(const char* unit, | ||||||||
1200 | const char *filename, | ||||||||
1201 | unsigned line, | ||||||||
1202 | const char *section, | ||||||||
1203 | unsigned section_line, | ||||||||
1204 | const char *lvalue, | ||||||||
1205 | int ltype, | ||||||||
1206 | const char *rvalue, | ||||||||
1207 | void *data, | ||||||||
1208 | void *userdata) { | ||||||||
1209 | |||||||||
1210 | unsigned *permille = data; | ||||||||
1211 | int r; | ||||||||
1212 | |||||||||
1213 | assert(filename)do { if ((__builtin_expect(!!(!(filename)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("filename"), "../src/shared/conf-parser.c" , 1213, __PRETTY_FUNCTION__); } while (0); | ||||||||
1214 | assert(lvalue)do { if ((__builtin_expect(!!(!(lvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("lvalue"), "../src/shared/conf-parser.c" , 1214, __PRETTY_FUNCTION__); } while (0); | ||||||||
1215 | assert(rvalue)do { if ((__builtin_expect(!!(!(rvalue)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("rvalue"), "../src/shared/conf-parser.c" , 1215, __PRETTY_FUNCTION__); } while (0); | ||||||||
1216 | assert(permille)do { if ((__builtin_expect(!!(!(permille)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("permille"), "../src/shared/conf-parser.c" , 1216, __PRETTY_FUNCTION__); } while (0); | ||||||||
1217 | |||||||||
1218 | r = parse_permille(rvalue); | ||||||||
1219 | if (r < 0) { | ||||||||
1220 | log_syntax(unit, LOG_ERR, filename, line, r,({ int _level = (3), _e = (r); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/shared/conf-parser.c", 1221, __func__ , "Failed to parse permille value, ignoring: %s", rvalue) : - abs(_e); }) | ||||||||
1221 | "Failed to parse permille value, ignoring: %s", rvalue)({ int _level = (3), _e = (r); (log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level , filename, line, _e, "../src/shared/conf-parser.c", 1221, __func__ , "Failed to parse permille value, ignoring: %s", rvalue) : - abs(_e); }); | ||||||||
1222 | return 0; | ||||||||
1223 | } | ||||||||
1224 | |||||||||
1225 | *permille = (unsigned) r; | ||||||||
1226 | |||||||||
1227 | return 0; | ||||||||
1228 | } |
1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
2 | #pragma once |
3 | |
4 | #include <alloca.h> |
5 | #include <stddef.h> |
6 | #include <stdlib.h> |
7 | #include <string.h> |
8 | |
9 | #include "macro.h" |
10 | |
11 | #define new(t, n)((t*) malloc_multiply(sizeof(t), (n))) ((t*) malloc_multiply(sizeof(t), (n))) |
12 | |
13 | #define new0(t, n)((t*) calloc((n), sizeof(t))) ((t*) calloc((n), sizeof(t))) |
14 | |
15 | #define newa(t, n)({ do { if ((__builtin_expect(!!(!(!size_multiply_overflow(sizeof (t), n))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!size_multiply_overflow(sizeof(t), n)" ), "../src/basic/alloc-util.h", 15, __PRETTY_FUNCTION__); } while (0); (t*) __builtin_alloca (sizeof(t)*(n)); }) \ |
16 | ({ \ |
17 | assert(!size_multiply_overflow(sizeof(t), n))do { if ((__builtin_expect(!!(!(!size_multiply_overflow(sizeof (t), n))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!size_multiply_overflow(sizeof(t), n)" ), "../src/basic/alloc-util.h", 17, __PRETTY_FUNCTION__); } while (0); \ |
18 | (t*) alloca(sizeof(t)*(n))__builtin_alloca (sizeof(t)*(n)); \ |
19 | }) |
20 | |
21 | #define newa0(t, n)({ do { if ((__builtin_expect(!!(!(!size_multiply_overflow(sizeof (t), n))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!size_multiply_overflow(sizeof(t), n)" ), "../src/basic/alloc-util.h", 21, __PRETTY_FUNCTION__); } while (0); (t*) ({ char *_new_; size_t _len_ = sizeof(t)*(n); _new_ = __builtin_alloca (_len_); (void *) memset(_new_, 0, _len_) ; }); }) \ |
22 | ({ \ |
23 | assert(!size_multiply_overflow(sizeof(t), n))do { if ((__builtin_expect(!!(!(!size_multiply_overflow(sizeof (t), n))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!size_multiply_overflow(sizeof(t), n)" ), "../src/basic/alloc-util.h", 23, __PRETTY_FUNCTION__); } while (0); \ |
24 | (t*) alloca0(sizeof(t)*(n))({ char *_new_; size_t _len_ = sizeof(t)*(n); _new_ = __builtin_alloca (_len_); (void *) memset(_new_, 0, _len_); }); \ |
25 | }) |
26 | |
27 | #define newdup(t, p, n)((t*) memdup_multiply(p, sizeof(t), (n))) ((t*) memdup_multiply(p, sizeof(t), (n))) |
28 | |
29 | #define newdup_suffix0(t, p, n)((t*) memdup_suffix0_multiply(p, sizeof(t), (n))) ((t*) memdup_suffix0_multiply(p, sizeof(t), (n))) |
30 | |
31 | #define malloc0(n)(calloc(1, (n))) (calloc(1, (n))) |
32 | |
33 | static inline void *mfree(void *memory) { |
34 | free(memory); |
35 | return NULL((void*)0); |
36 | } |
37 | |
38 | #define free_and_replace(a, b)({ free(a); (a) = (b); (b) = ((void*)0); 0; }) \ |
39 | ({ \ |
40 | free(a); \ |
41 | (a) = (b); \ |
42 | (b) = NULL((void*)0); \ |
43 | 0; \ |
44 | }) |
45 | |
46 | void* memdup(const void *p, size_t l) _alloc_(2); |
47 | void* memdup_suffix0(const void *p, size_t l) _alloc_(2); |
48 | |
49 | static inline void freep(void *p) { |
50 | free(*(void**) p); |
51 | } |
52 | |
53 | #define _cleanup_free___attribute__((cleanup(freep))) _cleanup_(freep)__attribute__((cleanup(freep))) |
54 | |
55 | static inline bool_Bool size_multiply_overflow(size_t size, size_t need) { |
56 | return _unlikely_(need != 0 && size > (SIZE_MAX / need))(__builtin_expect(!!(need != 0 && size > ((18446744073709551615UL ) / need)),0)); |
57 | } |
58 | |
59 | _malloc___attribute__ ((malloc)) _alloc_(1, 2) static inline void *malloc_multiply(size_t size, size_t need) { |
60 | if (size_multiply_overflow(size, need)) |
61 | return NULL((void*)0); |
62 | |
63 | return malloc(size * need); |
64 | } |
65 | |
66 | #if !HAVE_REALLOCARRAY1 |
67 | _alloc_(2, 3) static inline void *reallocarray(void *p, size_t need, size_t size) { |
68 | if (size_multiply_overflow(size, need)) |
69 | return NULL((void*)0); |
70 | |
71 | return realloc(p, size * need); |
72 | } |
73 | #endif |
74 | |
75 | _alloc_(2, 3) static inline void *memdup_multiply(const void *p, size_t size, size_t need) { |
76 | if (size_multiply_overflow(size, need)) |
77 | return NULL((void*)0); |
78 | |
79 | return memdup(p, size * need); |
80 | } |
81 | |
82 | _alloc_(2, 3) static inline void *memdup_suffix0_multiply(const void *p, size_t size, size_t need) { |
83 | if (size_multiply_overflow(size, need)) |
84 | return NULL((void*)0); |
85 | |
86 | return memdup_suffix0(p, size * need); |
87 | } |
88 | |
89 | void* greedy_realloc(void **p, size_t *allocated, size_t need, size_t size); |
90 | void* greedy_realloc0(void **p, size_t *allocated, size_t need, size_t size); |
91 | |
92 | #define GREEDY_REALLOC(array, allocated, need)greedy_realloc((void**) &(array), &(allocated), (need ), sizeof((array)[0])) \ |
93 | greedy_realloc((void**) &(array), &(allocated), (need), sizeof((array)[0])) |
94 | |
95 | #define GREEDY_REALLOC0(array, allocated, need)greedy_realloc0((void**) &(array), &(allocated), (need ), sizeof((array)[0])) \ |
96 | greedy_realloc0((void**) &(array), &(allocated), (need), sizeof((array)[0])) |
97 | |
98 | #define alloca0(n)({ char *_new_; size_t _len_ = n; _new_ = __builtin_alloca (_len_ ); (void *) memset(_new_, 0, _len_); }) \ |
99 | ({ \ |
100 | char *_new_; \ |
101 | size_t _len_ = n; \ |
102 | _new_ = alloca(_len_)__builtin_alloca (_len_); \ |
103 | (void *) memset(_new_, 0, _len_); \ |
104 | }) |
105 | |
106 | /* It's not clear what alignment glibc/gcc alloca() guarantee, hence provide a guaranteed safe version */ |
107 | #define alloca_align(size, align)({ void *_ptr_; size_t _mask_ = (align) - 1; _ptr_ = __builtin_alloca ((size) + _mask_); (void*)(((uintptr_t)_ptr_ + _mask_) & ~_mask_); }) \ |
108 | ({ \ |
109 | void *_ptr_; \ |
110 | size_t _mask_ = (align) - 1; \ |
111 | _ptr_ = alloca((size) + _mask_)__builtin_alloca ((size) + _mask_); \ |
112 | (void*)(((uintptr_t)_ptr_ + _mask_) & ~_mask_); \ |
113 | }) |
114 | |
115 | #define alloca0_align(size, align)({ void *_new_; size_t _size_ = (size); _new_ = ({ void *_ptr_ ; size_t _mask_ = ((align)) - 1; _ptr_ = __builtin_alloca ((_size_ ) + _mask_); (void*)(((uintptr_t)_ptr_ + _mask_) & ~_mask_ ); }); (void*)memset(_new_, 0, _size_); }) \ |
116 | ({ \ |
117 | void *_new_; \ |
118 | size_t _size_ = (size); \ |
119 | _new_ = alloca_align(_size_, (align))({ void *_ptr_; size_t _mask_ = ((align)) - 1; _ptr_ = __builtin_alloca ((_size_) + _mask_); (void*)(((uintptr_t)_ptr_ + _mask_) & ~_mask_); }); \ |
120 | (void*)memset(_new_, 0, _size_); \ |
121 | }) |
122 | |
123 | /* Takes inspiration from Rusts's Option::take() method: reads and returns a pointer, but at the same time resets it to |
124 | * NULL. See: https://doc.rust-lang.org/std/option/enum.Option.html#method.take */ |
125 | #define TAKE_PTR(ptr)({ typeof(ptr) _ptr_ = (ptr); (ptr) = ((void*)0); _ptr_; }) \ |
126 | ({ \ |
127 | typeof(ptr) _ptr_ = (ptr); \ |
128 | (ptr) = NULL((void*)0); \ |
129 | _ptr_; \ |
130 | }) |