]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
a7334b09 | 2 | /*** |
96b2fb93 | 3 | Copyright © 2012 Holger Hans Peter Freyther |
a7334b09 LP |
4 | ***/ |
5 | ||
3efd4195 | 6 | #include <errno.h> |
87f0e418 | 7 | #include <fcntl.h> |
25e870b5 | 8 | #include <linux/fs.h> |
5f5d8eab | 9 | #include <linux/oom.h> |
349cc4a5 | 10 | #if HAVE_SECCOMP |
618234a5 LP |
11 | #include <seccomp.h> |
12 | #endif | |
5f5d8eab LP |
13 | #include <sched.h> |
14 | #include <string.h> | |
3d57c6ab | 15 | #include <sys/resource.h> |
5f5d8eab | 16 | #include <sys/stat.h> |
3efd4195 | 17 | |
5f5d8eab | 18 | #include "af-list.h" |
cf0fbc49 | 19 | #include "alloc-util.h" |
57b7a260 | 20 | #include "all-units.h" |
fab34748 | 21 | #include "bpf-firewall.h" |
5f5d8eab LP |
22 | #include "bus-error.h" |
23 | #include "bus-internal.h" | |
24 | #include "bus-util.h" | |
25 | #include "cap-list.h" | |
a103496c | 26 | #include "capability-util.h" |
fdb3deca | 27 | #include "cgroup-setup.h" |
3efd4195 | 28 | #include "conf-parser.h" |
618234a5 | 29 | #include "cpu-set-util.h" |
5f5d8eab LP |
30 | #include "env-util.h" |
31 | #include "errno-list.h" | |
4f5dd394 | 32 | #include "escape.h" |
3ffd4af2 | 33 | #include "fd-util.h" |
f4f15635 | 34 | #include "fs-util.h" |
08f3be7a | 35 | #include "hexdecoct.h" |
d3070fbd | 36 | #include "io-util.h" |
9eba9da4 | 37 | #include "ioprio.h" |
da96ad5a | 38 | #include "ip-protocol-list.h" |
d3070fbd | 39 | #include "journal-util.h" |
eefc66aa | 40 | #include "limits-util.h" |
3ffd4af2 | 41 | #include "load-fragment.h" |
5f5d8eab | 42 | #include "log.h" |
94f04347 | 43 | #include "missing.h" |
049af8ad | 44 | #include "mountpoint-util.h" |
d8b4d14d | 45 | #include "nulstr-util.h" |
6bedfcbb | 46 | #include "parse-util.h" |
9eb977db | 47 | #include "path-util.h" |
7b3e062c | 48 | #include "process-util.h" |
349cc4a5 | 49 | #if HAVE_SECCOMP |
57183d11 LP |
50 | #include "seccomp-util.h" |
51 | #endif | |
07d46372 | 52 | #include "securebits-util.h" |
5f5d8eab | 53 | #include "signal-util.h" |
8fcde012 | 54 | #include "stat-util.h" |
07630cea | 55 | #include "string-util.h" |
5f5d8eab LP |
56 | #include "strv.h" |
57 | #include "unit-name.h" | |
58 | #include "unit-printf.h" | |
66dccd8d | 59 | #include "user-util.h" |
10f28641 | 60 | #include "time-util.h" |
49cf4170 | 61 | #include "web-util.h" |
57183d11 | 62 | |
d2b42d63 | 63 | static int parse_socket_protocol(const char *s) { |
53577580 YW |
64 | int r; |
65 | ||
d2b42d63 | 66 | r = parse_ip_protocol(s); |
53577580 | 67 | if (r < 0) |
acf4d158 | 68 | return r; |
53577580 YW |
69 | if (!IN_SET(r, IPPROTO_UDPLITE, IPPROTO_SCTP)) |
70 | return -EPROTONOSUPPORT; | |
71 | ||
72 | return r; | |
73 | } | |
74 | ||
a07a7324 FS |
75 | int parse_crash_chvt(const char *value, int *data) { |
76 | int b; | |
77 | ||
78 | if (safe_atoi(value, data) >= 0) | |
79 | return 0; | |
80 | ||
81 | b = parse_boolean(value); | |
82 | if (b < 0) | |
83 | return b; | |
84 | ||
85 | if (b > 0) | |
86 | *data = 0; /* switch to where kmsg goes */ | |
87 | else | |
88 | *data = -1; /* turn off switching */ | |
89 | ||
90 | return 0; | |
91 | } | |
92 | ||
93 | int parse_confirm_spawn(const char *value, char **console) { | |
94 | char *s; | |
95 | int r; | |
96 | ||
97 | r = value ? parse_boolean(value) : 1; | |
98 | if (r == 0) { | |
99 | *console = NULL; | |
100 | return 0; | |
4a8daee7 | 101 | } else if (r > 0) /* on with default tty */ |
a07a7324 FS |
102 | s = strdup("/dev/console"); |
103 | else if (is_path(value)) /* on with fully qualified path */ | |
104 | s = strdup(value); | |
105 | else /* on with only a tty file name, not a fully qualified path */ | |
4a8daee7 | 106 | s = path_join("/dev/", value); |
a07a7324 FS |
107 | if (!s) |
108 | return -ENOMEM; | |
109 | ||
110 | *console = s; | |
111 | return 0; | |
112 | } | |
113 | ||
d2b42d63 | 114 | DEFINE_CONFIG_PARSE(config_parse_socket_protocol, parse_socket_protocol, "Failed to parse socket protocol"); |
53577580 | 115 | DEFINE_CONFIG_PARSE(config_parse_exec_secure_bits, secure_bits_from_string, "Failed to parse secure bits"); |
5afe510c | 116 | DEFINE_CONFIG_PARSE_ENUM(config_parse_collect_mode, collect_mode, CollectMode, "Failed to parse garbage collection mode"); |
53577580 | 117 | DEFINE_CONFIG_PARSE_ENUM(config_parse_device_policy, cgroup_device_policy, CGroupDevicePolicy, "Failed to parse device policy"); |
53577580 YW |
118 | DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_keyring_mode, exec_keyring_mode, ExecKeyringMode, "Failed to parse keyring mode"); |
119 | DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_utmp_mode, exec_utmp_mode, ExecUtmpMode, "Failed to parse utmp mode"); | |
120 | DEFINE_CONFIG_PARSE_ENUM(config_parse_job_mode, job_mode, JobMode, "Failed to parse job mode"); | |
121 | DEFINE_CONFIG_PARSE_ENUM(config_parse_kill_mode, kill_mode, KillMode, "Failed to parse kill mode"); | |
122 | DEFINE_CONFIG_PARSE_ENUM(config_parse_notify_access, notify_access, NotifyAccess, "Failed to parse notify access specifier"); | |
1e8c7bd5 YW |
123 | DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_home, protect_home, ProtectHome, "Failed to parse protect home value"); |
124 | DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_system, protect_system, ProtectSystem, "Failed to parse protect system value"); | |
53577580 YW |
125 | DEFINE_CONFIG_PARSE_ENUM(config_parse_runtime_preserve_mode, exec_preserve_mode, ExecPreserveMode, "Failed to parse runtime directory preserve mode"); |
126 | DEFINE_CONFIG_PARSE_ENUM(config_parse_service_type, service_type, ServiceType, "Failed to parse service type"); | |
127 | DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart, service_restart, ServiceRestart, "Failed to parse service restart specifier"); | |
128 | DEFINE_CONFIG_PARSE_ENUM(config_parse_socket_bind, socket_address_bind_ipv6_only_or_bool, SocketAddressBindIPv6Only, "Failed to parse bind IPv6 only value"); | |
afcfaa69 | 129 | DEFINE_CONFIG_PARSE_ENUM(config_parse_oom_policy, oom_policy, OOMPolicy, "Failed to parse OOM policy"); |
53577580 YW |
130 | DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_ip_tos, ip_tos, int, -1, "Failed to parse IP TOS value"); |
131 | DEFINE_CONFIG_PARSE_PTR(config_parse_blockio_weight, cg_blkio_weight_parse, uint64_t, "Invalid block IO weight"); | |
132 | DEFINE_CONFIG_PARSE_PTR(config_parse_cg_weight, cg_weight_parse, uint64_t, "Invalid weight"); | |
133 | DEFINE_CONFIG_PARSE_PTR(config_parse_cpu_shares, cg_cpu_shares_parse, uint64_t, "Invalid CPU shares"); | |
134 | DEFINE_CONFIG_PARSE_PTR(config_parse_exec_mount_flags, mount_propagation_flags_from_string, unsigned long, "Failed to parse mount flag"); | |
b070c7c0 | 135 | DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_numa_policy, mpol, int, -1, "Invalid NUMA policy type"); |
6327aa9f | 136 | DEFINE_CONFIG_PARSE_ENUM(config_parse_status_unit_format, status_unit_format, StatusUnitFormat, "Failed to parse status unit format"); |
5afe510c | 137 | |
f32b43bd LP |
138 | int config_parse_unit_deps( |
139 | const char *unit, | |
140 | const char *filename, | |
141 | unsigned line, | |
142 | const char *section, | |
143 | unsigned section_line, | |
144 | const char *lvalue, | |
145 | int ltype, | |
146 | const char *rvalue, | |
147 | void *data, | |
148 | void *userdata) { | |
3efd4195 | 149 | |
f975e971 | 150 | UnitDependency d = ltype; |
87f0e418 | 151 | Unit *u = userdata; |
3d793d29 | 152 | const char *p; |
3efd4195 LP |
153 | |
154 | assert(filename); | |
155 | assert(lvalue); | |
156 | assert(rvalue); | |
3efd4195 | 157 | |
3d793d29 | 158 | p = rvalue; |
9ed794a3 | 159 | for (;;) { |
3d793d29 | 160 | _cleanup_free_ char *word = NULL, *k = NULL; |
3efd4195 | 161 | int r; |
3efd4195 | 162 | |
c89f52ac | 163 | r = extract_first_word(&p, &word, NULL, EXTRACT_RETAIN_ESCAPE); |
3d793d29 SS |
164 | if (r == 0) |
165 | break; | |
166 | if (r == -ENOMEM) | |
74051b9b | 167 | return log_oom(); |
3d793d29 SS |
168 | if (r < 0) { |
169 | log_syntax(unit, LOG_ERR, filename, line, r, "Invalid syntax, ignoring: %s", rvalue); | |
170 | break; | |
171 | } | |
3efd4195 | 172 | |
3d793d29 | 173 | r = unit_name_printf(u, word, &k); |
19f6d710 | 174 | if (r < 0) { |
063c4b1a | 175 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %m", word); |
19f6d710 LP |
176 | continue; |
177 | } | |
9e2f7c11 | 178 | |
35d8c19a | 179 | r = unit_add_dependency_by_name(u, d, k, true, UNIT_DEPENDENCY_FILE); |
57020a3a | 180 | if (r < 0) |
12ca818f | 181 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to add dependency on %s, ignoring: %m", k); |
3efd4195 LP |
182 | } |
183 | ||
184 | return 0; | |
185 | } | |
186 | ||
f32b43bd LP |
187 | int config_parse_obsolete_unit_deps( |
188 | const char *unit, | |
189 | const char *filename, | |
190 | unsigned line, | |
191 | const char *section, | |
192 | unsigned section_line, | |
193 | const char *lvalue, | |
194 | int ltype, | |
195 | const char *rvalue, | |
196 | void *data, | |
197 | void *userdata) { | |
198 | ||
199 | log_syntax(unit, LOG_WARNING, filename, line, 0, | |
200 | "Unit dependency type %s= is obsolete, replacing by %s=, please update your unit file", lvalue, unit_dependency_to_string(ltype)); | |
201 | ||
202 | return config_parse_unit_deps(unit, filename, line, section, section_line, lvalue, ltype, rvalue, data, userdata); | |
203 | } | |
204 | ||
b02cb41c LP |
205 | int config_parse_unit_string_printf( |
206 | const char *unit, | |
207 | const char *filename, | |
208 | unsigned line, | |
209 | const char *section, | |
210 | unsigned section_line, | |
211 | const char *lvalue, | |
212 | int ltype, | |
213 | const char *rvalue, | |
214 | void *data, | |
215 | void *userdata) { | |
932921b5 | 216 | |
74051b9b | 217 | _cleanup_free_ char *k = NULL; |
47538b76 | 218 | const Unit *u = userdata; |
19f6d710 | 219 | int r; |
932921b5 LP |
220 | |
221 | assert(filename); | |
222 | assert(lvalue); | |
223 | assert(rvalue); | |
f2d3769a | 224 | assert(u); |
932921b5 | 225 | |
19f6d710 | 226 | r = unit_full_printf(u, rvalue, &k); |
b02cb41c | 227 | if (r < 0) { |
063c4b1a | 228 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue); |
b02cb41c LP |
229 | return 0; |
230 | } | |
932921b5 | 231 | |
b02cb41c | 232 | return config_parse_string(unit, filename, line, section, section_line, lvalue, ltype, k, data, userdata); |
932921b5 LP |
233 | } |
234 | ||
12ca818f LP |
235 | int config_parse_unit_strv_printf( |
236 | const char *unit, | |
237 | const char *filename, | |
238 | unsigned line, | |
239 | const char *section, | |
240 | unsigned section_line, | |
241 | const char *lvalue, | |
242 | int ltype, | |
243 | const char *rvalue, | |
244 | void *data, | |
245 | void *userdata) { | |
8fef7659 | 246 | |
47538b76 | 247 | const Unit *u = userdata; |
74051b9b | 248 | _cleanup_free_ char *k = NULL; |
19f6d710 | 249 | int r; |
8fef7659 LP |
250 | |
251 | assert(filename); | |
252 | assert(lvalue); | |
253 | assert(rvalue); | |
254 | assert(u); | |
255 | ||
19f6d710 | 256 | r = unit_full_printf(u, rvalue, &k); |
12ca818f | 257 | if (r < 0) { |
063c4b1a | 258 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue); |
12ca818f LP |
259 | return 0; |
260 | } | |
8fef7659 | 261 | |
12ca818f | 262 | return config_parse_strv(unit, filename, line, section, section_line, lvalue, ltype, k, data, userdata); |
8fef7659 LP |
263 | } |
264 | ||
5f5d8eab LP |
265 | int config_parse_unit_path_printf( |
266 | const char *unit, | |
267 | const char *filename, | |
268 | unsigned line, | |
269 | const char *section, | |
270 | unsigned section_line, | |
271 | const char *lvalue, | |
272 | int ltype, | |
273 | const char *rvalue, | |
274 | void *data, | |
275 | void *userdata) { | |
6ea832a2 | 276 | |
74051b9b | 277 | _cleanup_free_ char *k = NULL; |
47538b76 | 278 | const Unit *u = userdata; |
19f6d710 | 279 | int r; |
2c75fb73 | 280 | bool fatal = ltype; |
6ea832a2 LP |
281 | |
282 | assert(filename); | |
283 | assert(lvalue); | |
284 | assert(rvalue); | |
6ea832a2 LP |
285 | assert(u); |
286 | ||
e3c3d676 ZJS |
287 | /* Let's not bother with anything that is too long */ |
288 | if (strlen(rvalue) >= PATH_MAX) { | |
289 | log_syntax(unit, LOG_ERR, filename, line, 0, | |
290 | "%s value too long%s.", | |
291 | lvalue, fatal ? "" : ", ignoring"); | |
292 | return fatal ? -ENAMETOOLONG : 0; | |
293 | } | |
294 | ||
19f6d710 | 295 | r = unit_full_printf(u, rvalue, &k); |
811ba7a0 | 296 | if (r < 0) { |
2c75fb73 | 297 | log_syntax(unit, LOG_ERR, filename, line, r, |
063c4b1a | 298 | "Failed to resolve unit specifiers in '%s'%s: %m", |
e3c3d676 | 299 | rvalue, fatal ? "" : ", ignoring"); |
2c75fb73 | 300 | return fatal ? -ENOEXEC : 0; |
811ba7a0 | 301 | } |
6ea832a2 | 302 | |
811ba7a0 LP |
303 | return config_parse_path(unit, filename, line, section, section_line, lvalue, ltype, k, data, userdata); |
304 | } | |
305 | ||
306 | int config_parse_unit_path_strv_printf( | |
307 | const char *unit, | |
308 | const char *filename, | |
309 | unsigned line, | |
310 | const char *section, | |
311 | unsigned section_line, | |
312 | const char *lvalue, | |
313 | int ltype, | |
314 | const char *rvalue, | |
315 | void *data, | |
316 | void *userdata) { | |
317 | ||
a2a5291b | 318 | char ***x = data; |
47538b76 | 319 | const Unit *u = userdata; |
811ba7a0 | 320 | int r; |
035fe294 | 321 | const char *p; |
811ba7a0 LP |
322 | |
323 | assert(filename); | |
324 | assert(lvalue); | |
325 | assert(rvalue); | |
326 | assert(u); | |
327 | ||
499295fb | 328 | if (isempty(rvalue)) { |
9f2d41a6 | 329 | *x = strv_free(*x); |
499295fb YW |
330 | return 0; |
331 | } | |
332 | ||
035fe294 ZJS |
333 | for (p = rvalue;;) { |
334 | _cleanup_free_ char *word = NULL, *k = NULL; | |
811ba7a0 | 335 | |
4ec85141 | 336 | r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE); |
035fe294 ZJS |
337 | if (r == 0) |
338 | return 0; | |
339 | if (r == -ENOMEM) | |
340 | return log_oom(); | |
341 | if (r < 0) { | |
342 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
343 | "Invalid syntax, ignoring: %s", rvalue); | |
344 | return 0; | |
345 | } | |
811ba7a0 | 346 | |
035fe294 | 347 | r = unit_full_printf(u, word, &k); |
811ba7a0 | 348 | if (r < 0) { |
035fe294 | 349 | log_syntax(unit, LOG_ERR, filename, line, r, |
063c4b1a | 350 | "Failed to resolve unit specifiers in '%s', ignoring: %m", word); |
811ba7a0 LP |
351 | return 0; |
352 | } | |
353 | ||
2f4d31c1 YW |
354 | r = path_simplify_and_warn(k, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue); |
355 | if (r < 0) | |
811ba7a0 | 356 | return 0; |
811ba7a0 | 357 | |
7d2c9c6b | 358 | r = strv_consume(x, TAKE_PTR(k)); |
811ba7a0 LP |
359 | if (r < 0) |
360 | return log_oom(); | |
811ba7a0 | 361 | } |
6ea832a2 LP |
362 | } |
363 | ||
4a66b5c9 LP |
364 | static int patch_var_run( |
365 | const char *unit, | |
366 | const char *filename, | |
367 | unsigned line, | |
368 | const char *lvalue, | |
369 | char **path) { | |
370 | ||
371 | const char *e; | |
372 | char *z; | |
373 | ||
374 | e = path_startswith(*path, "/var/run/"); | |
375 | if (!e) | |
376 | return 0; | |
377 | ||
378 | z = path_join("/run/", e); | |
379 | if (!z) | |
380 | return log_oom(); | |
381 | ||
382 | log_syntax(unit, LOG_NOTICE, filename, line, 0, | |
383 | "%s= references a path below legacy directory /var/run/, updating %s → %s; " | |
384 | "please update the unit file accordingly.", lvalue, *path, z); | |
385 | ||
386 | free_and_replace(*path, z); | |
387 | ||
388 | return 1; | |
389 | } | |
390 | ||
391 | int config_parse_socket_listen( | |
392 | const char *unit, | |
393 | const char *filename, | |
394 | unsigned line, | |
395 | const char *section, | |
396 | unsigned section_line, | |
397 | const char *lvalue, | |
398 | int ltype, | |
399 | const char *rvalue, | |
400 | void *data, | |
401 | void *userdata) { | |
42f4e3c4 | 402 | |
b1389b0d ZJS |
403 | _cleanup_free_ SocketPort *p = NULL; |
404 | SocketPort *tail; | |
542563ba | 405 | Socket *s; |
19f6d710 | 406 | int r; |
16354eff | 407 | |
42f4e3c4 LP |
408 | assert(filename); |
409 | assert(lvalue); | |
410 | assert(rvalue); | |
411 | assert(data); | |
412 | ||
595ed347 | 413 | s = SOCKET(data); |
542563ba | 414 | |
74051b9b LP |
415 | if (isempty(rvalue)) { |
416 | /* An empty assignment removes all ports */ | |
417 | socket_free_ports(s); | |
418 | return 0; | |
419 | } | |
420 | ||
7f110ff9 LP |
421 | p = new0(SocketPort, 1); |
422 | if (!p) | |
74051b9b | 423 | return log_oom(); |
916abb21 | 424 | |
74051b9b | 425 | if (ltype != SOCKET_SOCKET) { |
2f4d31c1 | 426 | _cleanup_free_ char *k = NULL; |
916abb21 | 427 | |
2f4d31c1 | 428 | r = unit_full_printf(UNIT(s), rvalue, &k); |
19f6d710 | 429 | if (r < 0) { |
063c4b1a | 430 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue); |
12ca818f | 431 | return 0; |
916abb21 LP |
432 | } |
433 | ||
2f4d31c1 YW |
434 | r = path_simplify_and_warn(k, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue); |
435 | if (r < 0) | |
436 | return 0; | |
437 | ||
4a66b5c9 LP |
438 | if (ltype == SOCKET_FIFO) { |
439 | r = patch_var_run(unit, filename, line, lvalue, &k); | |
440 | if (r < 0) | |
441 | return r; | |
442 | } | |
443 | ||
2f4d31c1 YW |
444 | free_and_replace(p->path, k); |
445 | p->type = ltype; | |
916abb21 | 446 | |
7a22745a | 447 | } else if (streq(lvalue, "ListenNetlink")) { |
74051b9b | 448 | _cleanup_free_ char *k = NULL; |
1fd45a90 | 449 | |
19f6d710 | 450 | r = unit_full_printf(UNIT(s), rvalue, &k); |
12ca818f | 451 | if (r < 0) { |
063c4b1a | 452 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue); |
12ca818f LP |
453 | return 0; |
454 | } | |
7a22745a | 455 | |
12ca818f | 456 | r = socket_address_parse_netlink(&p->address, k); |
1fd45a90 | 457 | if (r < 0) { |
063c4b1a | 458 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse address value in '%s', ignoring: %m", k); |
7a22745a LP |
459 | return 0; |
460 | } | |
461 | ||
2f4d31c1 YW |
462 | p->type = SOCKET_SOCKET; |
463 | ||
542563ba | 464 | } else { |
74051b9b | 465 | _cleanup_free_ char *k = NULL; |
1fd45a90 | 466 | |
19f6d710 | 467 | r = unit_full_printf(UNIT(s), rvalue, &k); |
12ca818f | 468 | if (r < 0) { |
063c4b1a | 469 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue); |
12ca818f LP |
470 | return 0; |
471 | } | |
542563ba | 472 | |
4a66b5c9 LP |
473 | if (k[0] == '/') { /* Only for AF_UNIX file system sockets… */ |
474 | r = patch_var_run(unit, filename, line, lvalue, &k); | |
475 | if (r < 0) | |
476 | return r; | |
477 | } | |
478 | ||
12ca818f | 479 | r = socket_address_parse_and_warn(&p->address, k); |
1fd45a90 | 480 | if (r < 0) { |
f847b8b7 | 481 | if (r != -EAFNOSUPPORT) |
063c4b1a | 482 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse address value in '%s', ignoring: %m", k); |
c0b34696 | 483 | return 0; |
542563ba LP |
484 | } |
485 | ||
486 | if (streq(lvalue, "ListenStream")) | |
487 | p->address.type = SOCK_STREAM; | |
488 | else if (streq(lvalue, "ListenDatagram")) | |
489 | p->address.type = SOCK_DGRAM; | |
490 | else { | |
491 | assert(streq(lvalue, "ListenSequentialPacket")); | |
492 | p->address.type = SOCK_SEQPACKET; | |
493 | } | |
494 | ||
495 | if (socket_address_family(&p->address) != AF_LOCAL && p->address.type == SOCK_SEQPACKET) { | |
12ca818f | 496 | log_syntax(unit, LOG_ERR, filename, line, 0, "Address family not supported, ignoring: %s", rvalue); |
c0b34696 | 497 | return 0; |
542563ba | 498 | } |
2f4d31c1 YW |
499 | |
500 | p->type = SOCKET_SOCKET; | |
16354eff LP |
501 | } |
502 | ||
542563ba | 503 | p->fd = -1; |
15087cdb PS |
504 | p->auxiliary_fds = NULL; |
505 | p->n_auxiliary_fds = 0; | |
2e41a51e | 506 | p->socket = s; |
49f91047 | 507 | |
533f8a67 YW |
508 | LIST_FIND_TAIL(port, s->ports, tail); |
509 | LIST_INSERT_AFTER(port, s->ports, tail, p); | |
510 | ||
b1389b0d | 511 | p = NULL; |
542563ba | 512 | |
16354eff | 513 | return 0; |
42f4e3c4 LP |
514 | } |
515 | ||
41bf0590 LP |
516 | int config_parse_exec_nice( |
517 | const char *unit, | |
518 | const char *filename, | |
519 | unsigned line, | |
520 | const char *section, | |
521 | unsigned section_line, | |
522 | const char *lvalue, | |
523 | int ltype, | |
524 | const char *rvalue, | |
525 | void *data, | |
526 | void *userdata) { | |
034c6ed7 | 527 | |
fb33a393 | 528 | ExecContext *c = data; |
e8e581bf | 529 | int priority, r; |
034c6ed7 LP |
530 | |
531 | assert(filename); | |
532 | assert(lvalue); | |
533 | assert(rvalue); | |
534 | assert(data); | |
535 | ||
de5e6038 YW |
536 | if (isempty(rvalue)) { |
537 | c->nice_set = false; | |
538 | return 0; | |
539 | } | |
540 | ||
41bf0590 | 541 | r = parse_nice(rvalue, &priority); |
e8e581bf | 542 | if (r < 0) { |
41bf0590 LP |
543 | if (r == -ERANGE) |
544 | log_syntax(unit, LOG_ERR, filename, line, r, "Nice priority out of range, ignoring: %s", rvalue); | |
545 | else | |
063c4b1a | 546 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse nice priority '%s', ignoring: %m", rvalue); |
c0b34696 | 547 | return 0; |
034c6ed7 LP |
548 | } |
549 | ||
fb33a393 | 550 | c->nice = priority; |
71155933 | 551 | c->nice_set = true; |
fb33a393 | 552 | |
034c6ed7 LP |
553 | return 0; |
554 | } | |
555 | ||
e9eb2c02 LP |
556 | int config_parse_exec_oom_score_adjust( |
557 | const char* unit, | |
558 | const char *filename, | |
559 | unsigned line, | |
560 | const char *section, | |
561 | unsigned section_line, | |
562 | const char *lvalue, | |
563 | int ltype, | |
564 | const char *rvalue, | |
565 | void *data, | |
566 | void *userdata) { | |
034c6ed7 | 567 | |
fb33a393 | 568 | ExecContext *c = data; |
e8e581bf | 569 | int oa, r; |
034c6ed7 LP |
570 | |
571 | assert(filename); | |
572 | assert(lvalue); | |
573 | assert(rvalue); | |
574 | assert(data); | |
575 | ||
e9eb2c02 LP |
576 | if (isempty(rvalue)) { |
577 | c->oom_score_adjust_set = false; | |
c0b34696 | 578 | return 0; |
034c6ed7 LP |
579 | } |
580 | ||
e9eb2c02 | 581 | r = parse_oom_score_adjust(rvalue, &oa); |
e9eb2c02 | 582 | if (r < 0) { |
063c4b1a YW |
583 | if (r == -ERANGE) |
584 | log_syntax(unit, LOG_ERR, filename, line, r, "OOM score adjust value out of range, ignoring: %s", rvalue); | |
585 | else | |
586 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse the OOM score adjust value '%s', ignoring: %m", rvalue); | |
c0b34696 | 587 | return 0; |
034c6ed7 LP |
588 | } |
589 | ||
dd6c17b1 LP |
590 | c->oom_score_adjust = oa; |
591 | c->oom_score_adjust_set = true; | |
fb33a393 | 592 | |
034c6ed7 LP |
593 | return 0; |
594 | } | |
595 | ||
527b7a42 LP |
596 | int config_parse_exec( |
597 | const char *unit, | |
598 | const char *filename, | |
599 | unsigned line, | |
600 | const char *section, | |
601 | unsigned section_line, | |
602 | const char *lvalue, | |
603 | int ltype, | |
604 | const char *rvalue, | |
605 | void *data, | |
606 | void *userdata) { | |
034c6ed7 | 607 | |
46a0d98a | 608 | ExecCommand **e = data; |
47538b76 | 609 | const Unit *u = userdata; |
46a0d98a FB |
610 | const char *p; |
611 | bool semicolon; | |
7f110ff9 | 612 | int r; |
034c6ed7 LP |
613 | |
614 | assert(filename); | |
615 | assert(lvalue); | |
616 | assert(rvalue); | |
61e5d8ed | 617 | assert(e); |
034c6ed7 | 618 | |
74051b9b | 619 | e += ltype; |
c83f1f30 | 620 | rvalue += strspn(rvalue, WHITESPACE); |
c83f1f30 | 621 | |
74051b9b LP |
622 | if (isempty(rvalue)) { |
623 | /* An empty assignment resets the list */ | |
f1acf85a | 624 | *e = exec_command_free_list(*e); |
74051b9b LP |
625 | return 0; |
626 | } | |
627 | ||
bd1b973f | 628 | p = rvalue; |
46a0d98a | 629 | do { |
dea7b6b0 | 630 | _cleanup_free_ char *path = NULL, *firstword = NULL; |
165a31c0 LP |
631 | ExecCommandFlags flags = 0; |
632 | bool ignore = false, separate_argv0 = false; | |
dea7b6b0 | 633 | _cleanup_free_ ExecCommand *nce = NULL; |
46a0d98a FB |
634 | _cleanup_strv_free_ char **n = NULL; |
635 | size_t nlen = 0, nbufsize = 0; | |
5125e762 | 636 | const char *f; |
6c666e26 | 637 | |
46a0d98a FB |
638 | semicolon = false; |
639 | ||
4ec85141 | 640 | r = extract_first_word_and_warn(&p, &firstword, NULL, EXTRACT_UNQUOTE|EXTRACT_CUNESCAPE, unit, filename, line, rvalue); |
46a0d98a FB |
641 | if (r <= 0) |
642 | return 0; | |
6c666e26 | 643 | |
46a0d98a | 644 | f = firstword; |
007f48bb | 645 | for (;;) { |
165a31c0 LP |
646 | /* We accept an absolute path as first argument. If it's prefixed with - and the path doesn't |
647 | * exist, we ignore it instead of erroring out; if it's prefixed with @, we allow overriding of | |
7ca69792 AZ |
648 | * argv[0]; if it's prefixed with :, we will not do environment variable substitution; |
649 | * if it's prefixed with +, it will be run with full privileges and no sandboxing; if | |
165a31c0 LP |
650 | * it's prefixed with '!' we apply sandboxing, but do not change user/group credentials; if |
651 | * it's prefixed with '!!', then we apply user/group credentials if the kernel supports ambient | |
652 | * capabilities -- if it doesn't we don't apply the credentials themselves, but do apply most | |
653 | * other sandboxing, with some special exceptions for changing UID. | |
654 | * | |
655 | * The idea is that '!!' may be used to write services that can take benefit of systemd's | |
656 | * UID/GID dropping if the kernel supports ambient creds, but provide an automatic fallback to | |
657 | * privilege dropping within the daemon if the kernel does not offer that. */ | |
658 | ||
659 | if (*f == '-' && !(flags & EXEC_COMMAND_IGNORE_FAILURE)) { | |
660 | flags |= EXEC_COMMAND_IGNORE_FAILURE; | |
46a0d98a | 661 | ignore = true; |
165a31c0 | 662 | } else if (*f == '@' && !separate_argv0) |
46a0d98a | 663 | separate_argv0 = true; |
7ca69792 AZ |
664 | else if (*f == ':' && !(flags & EXEC_COMMAND_NO_ENV_EXPAND)) |
665 | flags |= EXEC_COMMAND_NO_ENV_EXPAND; | |
165a31c0 LP |
666 | else if (*f == '+' && !(flags & (EXEC_COMMAND_FULLY_PRIVILEGED|EXEC_COMMAND_NO_SETUID|EXEC_COMMAND_AMBIENT_MAGIC))) |
667 | flags |= EXEC_COMMAND_FULLY_PRIVILEGED; | |
668 | else if (*f == '!' && !(flags & (EXEC_COMMAND_FULLY_PRIVILEGED|EXEC_COMMAND_NO_SETUID|EXEC_COMMAND_AMBIENT_MAGIC))) | |
669 | flags |= EXEC_COMMAND_NO_SETUID; | |
670 | else if (*f == '!' && !(flags & (EXEC_COMMAND_FULLY_PRIVILEGED|EXEC_COMMAND_AMBIENT_MAGIC))) { | |
671 | flags &= ~EXEC_COMMAND_NO_SETUID; | |
672 | flags |= EXEC_COMMAND_AMBIENT_MAGIC; | |
673 | } else | |
46a0d98a | 674 | break; |
313cefa1 | 675 | f++; |
61e5d8ed | 676 | } |
46a0d98a | 677 | |
5125e762 LP |
678 | r = unit_full_printf(u, f, &path); |
679 | if (r < 0) { | |
bb28e684 | 680 | log_syntax(unit, LOG_ERR, filename, line, r, |
063c4b1a | 681 | "Failed to resolve unit specifiers in '%s'%s: %m", |
bb28e684 ZJS |
682 | f, ignore ? ", ignoring" : ""); |
683 | return ignore ? 0 : -ENOEXEC; | |
5125e762 LP |
684 | } |
685 | ||
686 | if (isempty(path)) { | |
46a0d98a | 687 | /* First word is either "-" or "@" with no command. */ |
bb28e684 | 688 | log_syntax(unit, LOG_ERR, filename, line, 0, |
063c4b1a | 689 | "Empty path in command line%s: '%s'", |
bb28e684 ZJS |
690 | ignore ? ", ignoring" : "", rvalue); |
691 | return ignore ? 0 : -ENOEXEC; | |
b2fadec6 | 692 | } |
5125e762 | 693 | if (!string_is_safe(path)) { |
bb28e684 | 694 | log_syntax(unit, LOG_ERR, filename, line, 0, |
5008da1e ZJS |
695 | "Executable name contains special characters%s: %s", |
696 | ignore ? ", ignoring" : "", path); | |
bb28e684 | 697 | return ignore ? 0 : -ENOEXEC; |
46a0d98a | 698 | } |
5125e762 | 699 | if (endswith(path, "/")) { |
bb28e684 ZJS |
700 | log_syntax(unit, LOG_ERR, filename, line, 0, |
701 | "Executable path specifies a directory%s: %s", | |
5008da1e | 702 | ignore ? ", ignoring" : "", path); |
bb28e684 | 703 | return ignore ? 0 : -ENOEXEC; |
46a0d98a | 704 | } |
61e5d8ed | 705 | |
5008da1e ZJS |
706 | if (!path_is_absolute(path)) { |
707 | const char *prefix; | |
708 | bool found = false; | |
709 | ||
710 | if (!filename_is_valid(path)) { | |
711 | log_syntax(unit, LOG_ERR, filename, line, 0, | |
712 | "Neither a valid executable name nor an absolute path%s: %s", | |
713 | ignore ? ", ignoring" : "", path); | |
714 | return ignore ? 0 : -ENOEXEC; | |
715 | } | |
716 | ||
717 | /* Resolve a single-component name to a full path */ | |
718 | NULSTR_FOREACH(prefix, DEFAULT_PATH_NULSTR) { | |
719 | _cleanup_free_ char *fullpath = NULL; | |
720 | ||
657ee2d8 | 721 | fullpath = path_join(prefix, path); |
5008da1e ZJS |
722 | if (!fullpath) |
723 | return log_oom(); | |
724 | ||
725 | if (access(fullpath, F_OK) >= 0) { | |
726 | free_and_replace(path, fullpath); | |
727 | found = true; | |
728 | break; | |
729 | } | |
730 | } | |
731 | ||
732 | if (!found) { | |
733 | log_syntax(unit, LOG_ERR, filename, line, 0, | |
734 | "Executable \"%s\" not found in path \"%s\"%s", | |
735 | path, DEFAULT_PATH, ignore ? ", ignoring" : ""); | |
736 | return ignore ? 0 : -ENOEXEC; | |
737 | } | |
738 | } | |
739 | ||
46a0d98a | 740 | if (!separate_argv0) { |
5125e762 LP |
741 | char *w = NULL; |
742 | ||
46a0d98a FB |
743 | if (!GREEDY_REALLOC(n, nbufsize, nlen + 2)) |
744 | return log_oom(); | |
5125e762 LP |
745 | |
746 | w = strdup(path); | |
747 | if (!w) | |
46a0d98a | 748 | return log_oom(); |
5125e762 | 749 | n[nlen++] = w; |
46a0d98a FB |
750 | n[nlen] = NULL; |
751 | } | |
7f110ff9 | 752 | |
858d36c1 | 753 | path_simplify(path, false); |
46a0d98a | 754 | |
4b1c1753 | 755 | while (!isempty(p)) { |
5125e762 | 756 | _cleanup_free_ char *word = NULL, *resolved = NULL; |
46a0d98a FB |
757 | |
758 | /* Check explicitly for an unquoted semicolon as | |
759 | * command separator token. */ | |
760 | if (p[0] == ';' && (!p[1] || strchr(WHITESPACE, p[1]))) { | |
313cefa1 | 761 | p++; |
46a0d98a FB |
762 | p += strspn(p, WHITESPACE); |
763 | semicolon = true; | |
764 | break; | |
c8539536 | 765 | } |
7f110ff9 | 766 | |
5125e762 LP |
767 | /* Check for \; explicitly, to not confuse it with \\; or "\;" or "\\;" etc. |
768 | * extract_first_word() would return the same for all of those. */ | |
46a0d98a | 769 | if (p[0] == '\\' && p[1] == ';' && (!p[2] || strchr(WHITESPACE, p[2]))) { |
5125e762 LP |
770 | char *w; |
771 | ||
46a0d98a FB |
772 | p += 2; |
773 | p += strspn(p, WHITESPACE); | |
5125e762 | 774 | |
46a0d98a FB |
775 | if (!GREEDY_REALLOC(n, nbufsize, nlen + 2)) |
776 | return log_oom(); | |
5125e762 LP |
777 | |
778 | w = strdup(";"); | |
779 | if (!w) | |
46a0d98a | 780 | return log_oom(); |
5125e762 | 781 | n[nlen++] = w; |
46a0d98a FB |
782 | n[nlen] = NULL; |
783 | continue; | |
61e5d8ed | 784 | } |
c8539536 | 785 | |
4ec85141 | 786 | r = extract_first_word_and_warn(&p, &word, NULL, EXTRACT_UNQUOTE|EXTRACT_CUNESCAPE, unit, filename, line, rvalue); |
46a0d98a FB |
787 | if (r == 0) |
788 | break; | |
5125e762 | 789 | if (r < 0) |
bb28e684 | 790 | return ignore ? 0 : -ENOEXEC; |
5125e762 LP |
791 | |
792 | r = unit_full_printf(u, word, &resolved); | |
793 | if (r < 0) { | |
bb28e684 | 794 | log_syntax(unit, LOG_ERR, filename, line, r, |
063c4b1a | 795 | "Failed to resolve unit specifiers in %s%s: %m", |
bb28e684 ZJS |
796 | word, ignore ? ", ignoring" : ""); |
797 | return ignore ? 0 : -ENOEXEC; | |
5125e762 | 798 | } |
46a0d98a FB |
799 | |
800 | if (!GREEDY_REALLOC(n, nbufsize, nlen + 2)) | |
801 | return log_oom(); | |
1cc6c93a YW |
802 | |
803 | n[nlen++] = TAKE_PTR(resolved); | |
46a0d98a | 804 | n[nlen] = NULL; |
61e5d8ed LP |
805 | } |
806 | ||
46a0d98a | 807 | if (!n || !n[0]) { |
bb28e684 ZJS |
808 | log_syntax(unit, LOG_ERR, filename, line, 0, |
809 | "Empty executable name or zeroeth argument%s: %s", | |
810 | ignore ? ", ignoring" : "", rvalue); | |
811 | return ignore ? 0 : -ENOEXEC; | |
7f110ff9 | 812 | } |
6c666e26 | 813 | |
7f110ff9 | 814 | nce = new0(ExecCommand, 1); |
46a0d98a FB |
815 | if (!nce) |
816 | return log_oom(); | |
61e5d8ed | 817 | |
1cc6c93a YW |
818 | nce->argv = TAKE_PTR(n); |
819 | nce->path = TAKE_PTR(path); | |
165a31c0 | 820 | nce->flags = flags; |
034c6ed7 | 821 | |
61e5d8ed | 822 | exec_command_append_list(e, nce); |
01f78473 | 823 | |
46a0d98a | 824 | /* Do not _cleanup_free_ these. */ |
46a0d98a | 825 | nce = NULL; |
034c6ed7 | 826 | |
46a0d98a FB |
827 | rvalue = p; |
828 | } while (semicolon); | |
034c6ed7 | 829 | |
46a0d98a | 830 | return 0; |
034c6ed7 LP |
831 | } |
832 | ||
d31645ad LP |
833 | int config_parse_socket_bindtodevice( |
834 | const char* unit, | |
835 | const char *filename, | |
836 | unsigned line, | |
837 | const char *section, | |
838 | unsigned section_line, | |
839 | const char *lvalue, | |
840 | int ltype, | |
841 | const char *rvalue, | |
842 | void *data, | |
843 | void *userdata) { | |
acbb0225 LP |
844 | |
845 | Socket *s = data; | |
acbb0225 LP |
846 | |
847 | assert(filename); | |
848 | assert(lvalue); | |
849 | assert(rvalue); | |
850 | assert(data); | |
851 | ||
063c4b1a YW |
852 | if (isempty(rvalue) || streq(rvalue, "*")) { |
853 | s->bind_to_device = mfree(s->bind_to_device); | |
854 | return 0; | |
855 | } | |
d31645ad | 856 | |
063c4b1a YW |
857 | if (!ifname_valid(rvalue)) { |
858 | log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid interface name, ignoring: %s", rvalue); | |
859 | return 0; | |
860 | } | |
acbb0225 | 861 | |
3c381a67 YW |
862 | if (free_and_strdup(&s->bind_to_device, rvalue) < 0) |
863 | return log_oom(); | |
acbb0225 LP |
864 | |
865 | return 0; | |
866 | } | |
867 | ||
9bd6a50e LP |
868 | int config_parse_exec_input( |
869 | const char *unit, | |
870 | const char *filename, | |
871 | unsigned line, | |
872 | const char *section, | |
873 | unsigned section_line, | |
874 | const char *lvalue, | |
875 | int ltype, | |
876 | const char *rvalue, | |
877 | void *data, | |
878 | void *userdata) { | |
52c239d7 | 879 | |
52c239d7 | 880 | ExecContext *c = data; |
47538b76 | 881 | const Unit *u = userdata; |
2038c3f5 LP |
882 | const char *n; |
883 | ExecInput ei; | |
52c239d7 LB |
884 | int r; |
885 | ||
886 | assert(data); | |
887 | assert(filename); | |
888 | assert(line); | |
889 | assert(rvalue); | |
890 | ||
2038c3f5 LP |
891 | n = startswith(rvalue, "fd:"); |
892 | if (n) { | |
893 | _cleanup_free_ char *resolved = NULL; | |
894 | ||
895 | r = unit_full_printf(u, n, &resolved); | |
896 | if (r < 0) | |
063c4b1a | 897 | return log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in '%s': %m", n); |
2038c3f5 LP |
898 | |
899 | if (isempty(resolved)) | |
900 | resolved = mfree(resolved); | |
901 | else if (!fdname_is_valid(resolved)) { | |
902 | log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid file descriptor name: %s", resolved); | |
6f40aa45 | 903 | return -ENOEXEC; |
52c239d7 | 904 | } |
9bd6a50e | 905 | |
2038c3f5 LP |
906 | free_and_replace(c->stdio_fdname[STDIN_FILENO], resolved); |
907 | ||
908 | ei = EXEC_INPUT_NAMED_FD; | |
909 | ||
910 | } else if ((n = startswith(rvalue, "file:"))) { | |
911 | _cleanup_free_ char *resolved = NULL; | |
912 | ||
913 | r = unit_full_printf(u, n, &resolved); | |
52c239d7 | 914 | if (r < 0) |
063c4b1a | 915 | return log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in '%s': %m", n); |
9bd6a50e | 916 | |
2f4d31c1 YW |
917 | r = path_simplify_and_warn(resolved, PATH_CHECK_ABSOLUTE | PATH_CHECK_FATAL, unit, filename, line, lvalue); |
918 | if (r < 0) | |
6f40aa45 | 919 | return -ENOEXEC; |
2038c3f5 LP |
920 | |
921 | free_and_replace(c->stdio_file[STDIN_FILENO], resolved); | |
922 | ||
923 | ei = EXEC_INPUT_FILE; | |
9bd6a50e | 924 | |
52c239d7 | 925 | } else { |
9bd6a50e LP |
926 | ei = exec_input_from_string(rvalue); |
927 | if (ei < 0) { | |
52c239d7 | 928 | log_syntax(unit, LOG_ERR, filename, line, 0, "Failed to parse input specifier, ignoring: %s", rvalue); |
9bd6a50e LP |
929 | return 0; |
930 | } | |
52c239d7 | 931 | } |
9bd6a50e | 932 | |
2038c3f5 | 933 | c->std_input = ei; |
9bd6a50e | 934 | return 0; |
52c239d7 LB |
935 | } |
936 | ||
08f3be7a LP |
937 | int config_parse_exec_input_text( |
938 | const char *unit, | |
939 | const char *filename, | |
940 | unsigned line, | |
941 | const char *section, | |
942 | unsigned section_line, | |
943 | const char *lvalue, | |
944 | int ltype, | |
945 | const char *rvalue, | |
946 | void *data, | |
947 | void *userdata) { | |
948 | ||
949 | _cleanup_free_ char *unescaped = NULL, *resolved = NULL; | |
950 | ExecContext *c = data; | |
47538b76 | 951 | const Unit *u = userdata; |
08f3be7a LP |
952 | size_t sz; |
953 | void *p; | |
954 | int r; | |
955 | ||
956 | assert(data); | |
957 | assert(filename); | |
958 | assert(line); | |
959 | assert(rvalue); | |
960 | ||
961 | if (isempty(rvalue)) { | |
962 | /* Reset if the empty string is assigned */ | |
963 | c->stdin_data = mfree(c->stdin_data); | |
964 | c->stdin_data_size = 0; | |
52c239d7 LB |
965 | return 0; |
966 | } | |
08f3be7a LP |
967 | |
968 | r = cunescape(rvalue, 0, &unescaped); | |
2038c3f5 | 969 | if (r < 0) |
063c4b1a | 970 | return log_syntax(unit, LOG_ERR, filename, line, r, "Failed to decode C escaped text '%s': %m", rvalue); |
08f3be7a LP |
971 | |
972 | r = unit_full_printf(u, unescaped, &resolved); | |
2038c3f5 | 973 | if (r < 0) |
063c4b1a | 974 | return log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in '%s': %m", unescaped); |
08f3be7a LP |
975 | |
976 | sz = strlen(resolved); | |
977 | if (c->stdin_data_size + sz + 1 < c->stdin_data_size || /* check for overflow */ | |
978 | c->stdin_data_size + sz + 1 > EXEC_STDIN_DATA_MAX) { | |
2038c3f5 LP |
979 | log_syntax(unit, LOG_ERR, filename, line, 0, "Standard input data too large (%zu), maximum of %zu permitted, ignoring.", c->stdin_data_size + sz, (size_t) EXEC_STDIN_DATA_MAX); |
980 | return -E2BIG; | |
08f3be7a LP |
981 | } |
982 | ||
983 | p = realloc(c->stdin_data, c->stdin_data_size + sz + 1); | |
984 | if (!p) | |
985 | return log_oom(); | |
986 | ||
987 | *((char*) mempcpy((char*) p + c->stdin_data_size, resolved, sz)) = '\n'; | |
988 | ||
989 | c->stdin_data = p; | |
990 | c->stdin_data_size += sz + 1; | |
991 | ||
992 | return 0; | |
52c239d7 LB |
993 | } |
994 | ||
08f3be7a LP |
995 | int config_parse_exec_input_data( |
996 | const char *unit, | |
997 | const char *filename, | |
998 | unsigned line, | |
999 | const char *section, | |
1000 | unsigned section_line, | |
1001 | const char *lvalue, | |
1002 | int ltype, | |
1003 | const char *rvalue, | |
1004 | void *data, | |
1005 | void *userdata) { | |
1006 | ||
08f3be7a LP |
1007 | _cleanup_free_ void *p = NULL; |
1008 | ExecContext *c = data; | |
1009 | size_t sz; | |
1010 | void *q; | |
1011 | int r; | |
1012 | ||
1013 | assert(data); | |
1014 | assert(filename); | |
1015 | assert(line); | |
1016 | assert(rvalue); | |
1017 | ||
1018 | if (isempty(rvalue)) { | |
1019 | /* Reset if the empty string is assigned */ | |
1020 | c->stdin_data = mfree(c->stdin_data); | |
1021 | c->stdin_data_size = 0; | |
1022 | return 0; | |
1023 | } | |
1024 | ||
081f36d8 | 1025 | r = unbase64mem(rvalue, (size_t) -1, &p, &sz); |
2038c3f5 | 1026 | if (r < 0) |
081f36d8 | 1027 | return log_syntax(unit, LOG_ERR, filename, line, r, "Failed to decode base64 data, ignoring: %s", rvalue); |
08f3be7a LP |
1028 | |
1029 | assert(sz > 0); | |
1030 | ||
1031 | if (c->stdin_data_size + sz < c->stdin_data_size || /* check for overflow */ | |
1032 | c->stdin_data_size + sz > EXEC_STDIN_DATA_MAX) { | |
2038c3f5 LP |
1033 | log_syntax(unit, LOG_ERR, filename, line, 0, "Standard input data too large (%zu), maximum of %zu permitted, ignoring.", c->stdin_data_size + sz, (size_t) EXEC_STDIN_DATA_MAX); |
1034 | return -E2BIG; | |
08f3be7a LP |
1035 | } |
1036 | ||
1037 | q = realloc(c->stdin_data, c->stdin_data_size + sz); | |
1038 | if (!q) | |
1039 | return log_oom(); | |
1040 | ||
1041 | memcpy((uint8_t*) q + c->stdin_data_size, p, sz); | |
1042 | ||
1043 | c->stdin_data = q; | |
1044 | c->stdin_data_size += sz; | |
1045 | ||
1046 | return 0; | |
1047 | } | |
1048 | ||
2038c3f5 LP |
1049 | int config_parse_exec_output( |
1050 | const char *unit, | |
1051 | const char *filename, | |
1052 | unsigned line, | |
1053 | const char *section, | |
1054 | unsigned section_line, | |
1055 | const char *lvalue, | |
1056 | int ltype, | |
1057 | const char *rvalue, | |
1058 | void *data, | |
1059 | void *userdata) { | |
1060 | ||
1061 | _cleanup_free_ char *resolved = NULL; | |
1062 | const char *n; | |
52c239d7 | 1063 | ExecContext *c = data; |
47538b76 | 1064 | const Unit *u = userdata; |
52c239d7 | 1065 | ExecOutput eo; |
52c239d7 LB |
1066 | int r; |
1067 | ||
1068 | assert(data); | |
1069 | assert(filename); | |
1070 | assert(line); | |
1071 | assert(lvalue); | |
1072 | assert(rvalue); | |
1073 | ||
2038c3f5 LP |
1074 | n = startswith(rvalue, "fd:"); |
1075 | if (n) { | |
1076 | r = unit_full_printf(u, n, &resolved); | |
1077 | if (r < 0) | |
063c4b1a | 1078 | return log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in %s: %m", n); |
2038c3f5 LP |
1079 | |
1080 | if (isempty(resolved)) | |
1081 | resolved = mfree(resolved); | |
1082 | else if (!fdname_is_valid(resolved)) { | |
1083 | log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid file descriptor name: %s", resolved); | |
6f40aa45 | 1084 | return -ENOEXEC; |
52c239d7 | 1085 | } |
2038c3f5 | 1086 | |
52c239d7 | 1087 | eo = EXEC_OUTPUT_NAMED_FD; |
2038c3f5 LP |
1088 | |
1089 | } else if ((n = startswith(rvalue, "file:"))) { | |
1090 | ||
1091 | r = unit_full_printf(u, n, &resolved); | |
1092 | if (r < 0) | |
063c4b1a | 1093 | return log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in %s: %m", n); |
2038c3f5 | 1094 | |
2f4d31c1 YW |
1095 | r = path_simplify_and_warn(resolved, PATH_CHECK_ABSOLUTE | PATH_CHECK_FATAL, unit, filename, line, lvalue); |
1096 | if (r < 0) | |
6f40aa45 | 1097 | return -ENOEXEC; |
2038c3f5 LP |
1098 | |
1099 | eo = EXEC_OUTPUT_FILE; | |
1100 | ||
566b7d23 ZD |
1101 | } else if ((n = startswith(rvalue, "append:"))) { |
1102 | ||
1103 | r = unit_full_printf(u, n, &resolved); | |
1104 | if (r < 0) | |
1105 | return log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in %s: %m", n); | |
1106 | ||
1107 | r = path_simplify_and_warn(resolved, PATH_CHECK_ABSOLUTE | PATH_CHECK_FATAL, unit, filename, line, lvalue); | |
1108 | if (r < 0) | |
1109 | return -ENOEXEC; | |
1110 | ||
1111 | eo = EXEC_OUTPUT_FILE_APPEND; | |
52c239d7 LB |
1112 | } else { |
1113 | eo = exec_output_from_string(rvalue); | |
2038c3f5 | 1114 | if (eo < 0) { |
52c239d7 LB |
1115 | log_syntax(unit, LOG_ERR, filename, line, 0, "Failed to parse output specifier, ignoring: %s", rvalue); |
1116 | return 0; | |
1117 | } | |
1118 | } | |
1119 | ||
1120 | if (streq(lvalue, "StandardOutput")) { | |
2038c3f5 LP |
1121 | if (eo == EXEC_OUTPUT_NAMED_FD) |
1122 | free_and_replace(c->stdio_fdname[STDOUT_FILENO], resolved); | |
1123 | else | |
1124 | free_and_replace(c->stdio_file[STDOUT_FILENO], resolved); | |
1125 | ||
52c239d7 | 1126 | c->std_output = eo; |
2038c3f5 | 1127 | |
52c239d7 | 1128 | } else { |
2038c3f5 LP |
1129 | assert(streq(lvalue, "StandardError")); |
1130 | ||
1131 | if (eo == EXEC_OUTPUT_NAMED_FD) | |
1132 | free_and_replace(c->stdio_fdname[STDERR_FILENO], resolved); | |
1133 | else | |
1134 | free_and_replace(c->stdio_file[STDERR_FILENO], resolved); | |
1135 | ||
1136 | c->std_error = eo; | |
52c239d7 | 1137 | } |
2038c3f5 LP |
1138 | |
1139 | return 0; | |
52c239d7 | 1140 | } |
87f0e418 | 1141 | |
e8e581bf ZJS |
1142 | int config_parse_exec_io_class(const char *unit, |
1143 | const char *filename, | |
1144 | unsigned line, | |
1145 | const char *section, | |
71a61510 | 1146 | unsigned section_line, |
e8e581bf ZJS |
1147 | const char *lvalue, |
1148 | int ltype, | |
1149 | const char *rvalue, | |
1150 | void *data, | |
1151 | void *userdata) { | |
94f04347 LP |
1152 | |
1153 | ExecContext *c = data; | |
1154 | int x; | |
1155 | ||
1156 | assert(filename); | |
1157 | assert(lvalue); | |
1158 | assert(rvalue); | |
1159 | assert(data); | |
1160 | ||
617d253a YW |
1161 | if (isempty(rvalue)) { |
1162 | c->ioprio_set = false; | |
1163 | c->ioprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 0); | |
1164 | return 0; | |
1165 | } | |
1166 | ||
f8b69d1d MS |
1167 | x = ioprio_class_from_string(rvalue); |
1168 | if (x < 0) { | |
12ca818f | 1169 | log_syntax(unit, LOG_ERR, filename, line, 0, "Failed to parse IO scheduling class, ignoring: %s", rvalue); |
c0b34696 | 1170 | return 0; |
0d87eb42 | 1171 | } |
94f04347 LP |
1172 | |
1173 | c->ioprio = IOPRIO_PRIO_VALUE(x, IOPRIO_PRIO_DATA(c->ioprio)); | |
1174 | c->ioprio_set = true; | |
1175 | ||
1176 | return 0; | |
1177 | } | |
1178 | ||
e8e581bf ZJS |
1179 | int config_parse_exec_io_priority(const char *unit, |
1180 | const char *filename, | |
1181 | unsigned line, | |
1182 | const char *section, | |
71a61510 | 1183 | unsigned section_line, |
e8e581bf ZJS |
1184 | const char *lvalue, |
1185 | int ltype, | |
1186 | const char *rvalue, | |
1187 | void *data, | |
1188 | void *userdata) { | |
94f04347 LP |
1189 | |
1190 | ExecContext *c = data; | |
e8e581bf | 1191 | int i, r; |
94f04347 LP |
1192 | |
1193 | assert(filename); | |
1194 | assert(lvalue); | |
1195 | assert(rvalue); | |
1196 | assert(data); | |
1197 | ||
617d253a YW |
1198 | if (isempty(rvalue)) { |
1199 | c->ioprio_set = false; | |
1200 | c->ioprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 0); | |
1201 | return 0; | |
1202 | } | |
1203 | ||
7f452159 LP |
1204 | r = ioprio_parse_priority(rvalue, &i); |
1205 | if (r < 0) { | |
12ca818f | 1206 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse IO priority, ignoring: %s", rvalue); |
c0b34696 | 1207 | return 0; |
071830ff LP |
1208 | } |
1209 | ||
94f04347 LP |
1210 | c->ioprio = IOPRIO_PRIO_VALUE(IOPRIO_PRIO_CLASS(c->ioprio), i); |
1211 | c->ioprio_set = true; | |
1212 | ||
071830ff LP |
1213 | return 0; |
1214 | } | |
1215 | ||
e8e581bf ZJS |
1216 | int config_parse_exec_cpu_sched_policy(const char *unit, |
1217 | const char *filename, | |
1218 | unsigned line, | |
1219 | const char *section, | |
71a61510 | 1220 | unsigned section_line, |
e8e581bf ZJS |
1221 | const char *lvalue, |
1222 | int ltype, | |
1223 | const char *rvalue, | |
1224 | void *data, | |
1225 | void *userdata) { | |
9eba9da4 | 1226 | |
94f04347 LP |
1227 | ExecContext *c = data; |
1228 | int x; | |
1229 | ||
1230 | assert(filename); | |
1231 | assert(lvalue); | |
1232 | assert(rvalue); | |
1233 | assert(data); | |
1234 | ||
b00e1a9e YW |
1235 | if (isempty(rvalue)) { |
1236 | c->cpu_sched_set = false; | |
1237 | c->cpu_sched_policy = SCHED_OTHER; | |
1238 | c->cpu_sched_priority = 0; | |
1239 | return 0; | |
1240 | } | |
1241 | ||
f8b69d1d MS |
1242 | x = sched_policy_from_string(rvalue); |
1243 | if (x < 0) { | |
12ca818f | 1244 | log_syntax(unit, LOG_ERR, filename, line, 0, "Failed to parse CPU scheduling policy, ignoring: %s", rvalue); |
c0b34696 | 1245 | return 0; |
0d87eb42 | 1246 | } |
94f04347 LP |
1247 | |
1248 | c->cpu_sched_policy = x; | |
bb112710 HHPF |
1249 | /* Moving to or from real-time policy? We need to adjust the priority */ |
1250 | c->cpu_sched_priority = CLAMP(c->cpu_sched_priority, sched_get_priority_min(x), sched_get_priority_max(x)); | |
94f04347 LP |
1251 | c->cpu_sched_set = true; |
1252 | ||
1253 | return 0; | |
1254 | } | |
1255 | ||
b070c7c0 MS |
1256 | int config_parse_numa_mask(const char *unit, |
1257 | const char *filename, | |
1258 | unsigned line, | |
1259 | const char *section, | |
1260 | unsigned section_line, | |
1261 | const char *lvalue, | |
1262 | int ltype, | |
1263 | const char *rvalue, | |
1264 | void *data, | |
1265 | void *userdata) { | |
1266 | int r; | |
1267 | NUMAPolicy *p = data; | |
1268 | ||
1269 | assert(filename); | |
1270 | assert(lvalue); | |
1271 | assert(rvalue); | |
1272 | assert(data); | |
1273 | ||
1274 | r = parse_cpu_set_extend(rvalue, &p->nodes, true, unit, filename, line, lvalue); | |
1275 | if (r < 0) { | |
1276 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse NUMA node mask, ignoring: %s", rvalue); | |
1277 | return 0; | |
1278 | } | |
1279 | ||
1280 | return r; | |
1281 | } | |
1282 | ||
e8e581bf ZJS |
1283 | int config_parse_exec_cpu_sched_prio(const char *unit, |
1284 | const char *filename, | |
1285 | unsigned line, | |
1286 | const char *section, | |
71a61510 | 1287 | unsigned section_line, |
e8e581bf ZJS |
1288 | const char *lvalue, |
1289 | int ltype, | |
1290 | const char *rvalue, | |
1291 | void *data, | |
1292 | void *userdata) { | |
9eba9da4 LP |
1293 | |
1294 | ExecContext *c = data; | |
e8e581bf | 1295 | int i, min, max, r; |
9eba9da4 LP |
1296 | |
1297 | assert(filename); | |
1298 | assert(lvalue); | |
1299 | assert(rvalue); | |
1300 | assert(data); | |
1301 | ||
e8e581bf ZJS |
1302 | r = safe_atoi(rvalue, &i); |
1303 | if (r < 0) { | |
063c4b1a | 1304 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse CPU scheduling priority, ignoring: %s", rvalue); |
c0b34696 | 1305 | return 0; |
94f04347 | 1306 | } |
9eba9da4 | 1307 | |
bb112710 HHPF |
1308 | /* On Linux RR/FIFO range from 1 to 99 and OTHER/BATCH may only be 0 */ |
1309 | min = sched_get_priority_min(c->cpu_sched_policy); | |
1310 | max = sched_get_priority_max(c->cpu_sched_policy); | |
1311 | ||
1312 | if (i < min || i > max) { | |
12ca818f | 1313 | log_syntax(unit, LOG_ERR, filename, line, 0, "CPU scheduling priority is out of range, ignoring: %s", rvalue); |
bb112710 HHPF |
1314 | return 0; |
1315 | } | |
1316 | ||
94f04347 LP |
1317 | c->cpu_sched_priority = i; |
1318 | c->cpu_sched_set = true; | |
1319 | ||
1320 | return 0; | |
1321 | } | |
1322 | ||
e8e581bf ZJS |
1323 | int config_parse_exec_cpu_affinity(const char *unit, |
1324 | const char *filename, | |
1325 | unsigned line, | |
1326 | const char *section, | |
71a61510 | 1327 | unsigned section_line, |
e8e581bf ZJS |
1328 | const char *lvalue, |
1329 | int ltype, | |
1330 | const char *rvalue, | |
1331 | void *data, | |
1332 | void *userdata) { | |
94f04347 LP |
1333 | |
1334 | ExecContext *c = data; | |
94f04347 LP |
1335 | |
1336 | assert(filename); | |
1337 | assert(lvalue); | |
1338 | assert(rvalue); | |
1339 | assert(data); | |
1340 | ||
0985c7c4 | 1341 | return parse_cpu_set_extend(rvalue, &c->cpu_set, true, unit, filename, line, lvalue); |
94f04347 LP |
1342 | } |
1343 | ||
a103496c | 1344 | int config_parse_capability_set( |
65dce264 LP |
1345 | const char *unit, |
1346 | const char *filename, | |
1347 | unsigned line, | |
1348 | const char *section, | |
1349 | unsigned section_line, | |
1350 | const char *lvalue, | |
1351 | int ltype, | |
1352 | const char *rvalue, | |
1353 | void *data, | |
1354 | void *userdata) { | |
94f04347 | 1355 | |
a103496c IP |
1356 | uint64_t *capability_set = data; |
1357 | uint64_t sum = 0, initial = 0; | |
260abb78 | 1358 | bool invert = false; |
dd1f5bd0 | 1359 | int r; |
94f04347 LP |
1360 | |
1361 | assert(filename); | |
1362 | assert(lvalue); | |
1363 | assert(rvalue); | |
1364 | assert(data); | |
1365 | ||
260abb78 LP |
1366 | if (rvalue[0] == '~') { |
1367 | invert = true; | |
1368 | rvalue++; | |
1369 | } | |
1370 | ||
70d54d90 | 1371 | if (streq(lvalue, "CapabilityBoundingSet")) |
a103496c | 1372 | initial = CAP_ALL; /* initialized to all bits on */ |
755d4b67 | 1373 | /* else "AmbientCapabilities" initialized to all bits off */ |
260abb78 | 1374 | |
dd1f5bd0 | 1375 | r = capability_set_from_string(rvalue, &sum); |
dd1f5bd0 | 1376 | if (r < 0) { |
063c4b1a | 1377 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse %s= specifier '%s', ignoring: %m", lvalue, rvalue); |
dd1f5bd0 | 1378 | return 0; |
94f04347 | 1379 | } |
9eba9da4 | 1380 | |
a103496c | 1381 | if (sum == 0 || *capability_set == initial) |
c792ec2e IP |
1382 | /* "", "~" or uninitialized data -> replace */ |
1383 | *capability_set = invert ? ~sum : sum; | |
1384 | else { | |
a103496c | 1385 | /* previous data -> merge */ |
c792ec2e IP |
1386 | if (invert) |
1387 | *capability_set &= ~sum; | |
1388 | else | |
1389 | *capability_set |= sum; | |
1390 | } | |
260abb78 | 1391 | |
9eba9da4 LP |
1392 | return 0; |
1393 | } | |
1394 | ||
5f8640fb LP |
1395 | int config_parse_exec_selinux_context( |
1396 | const char *unit, | |
1397 | const char *filename, | |
1398 | unsigned line, | |
1399 | const char *section, | |
1400 | unsigned section_line, | |
1401 | const char *lvalue, | |
1402 | int ltype, | |
1403 | const char *rvalue, | |
1404 | void *data, | |
1405 | void *userdata) { | |
1406 | ||
1407 | ExecContext *c = data; | |
47538b76 | 1408 | const Unit *u = userdata; |
5f8640fb LP |
1409 | bool ignore; |
1410 | char *k; | |
1411 | int r; | |
1412 | ||
1413 | assert(filename); | |
1414 | assert(lvalue); | |
1415 | assert(rvalue); | |
1416 | assert(data); | |
1417 | ||
1418 | if (isempty(rvalue)) { | |
a1e58e8e | 1419 | c->selinux_context = mfree(c->selinux_context); |
5f8640fb LP |
1420 | c->selinux_context_ignore = false; |
1421 | return 0; | |
1422 | } | |
1423 | ||
1424 | if (rvalue[0] == '-') { | |
1425 | ignore = true; | |
1426 | rvalue++; | |
1427 | } else | |
1428 | ignore = false; | |
1429 | ||
18913df9 | 1430 | r = unit_full_printf(u, rvalue, &k); |
5f8640fb | 1431 | if (r < 0) { |
bb28e684 | 1432 | log_syntax(unit, LOG_ERR, filename, line, r, |
063c4b1a YW |
1433 | "Failed to resolve unit specifiers in '%s'%s: %m", |
1434 | rvalue, ignore ? ", ignoring" : ""); | |
bb28e684 | 1435 | return ignore ? 0 : -ENOEXEC; |
5f8640fb LP |
1436 | } |
1437 | ||
063c4b1a | 1438 | free_and_replace(c->selinux_context, k); |
5f8640fb LP |
1439 | c->selinux_context_ignore = ignore; |
1440 | ||
1441 | return 0; | |
1442 | } | |
1443 | ||
eef65bf3 MS |
1444 | int config_parse_exec_apparmor_profile( |
1445 | const char *unit, | |
1446 | const char *filename, | |
1447 | unsigned line, | |
1448 | const char *section, | |
1449 | unsigned section_line, | |
1450 | const char *lvalue, | |
1451 | int ltype, | |
1452 | const char *rvalue, | |
1453 | void *data, | |
1454 | void *userdata) { | |
1455 | ||
1456 | ExecContext *c = data; | |
47538b76 | 1457 | const Unit *u = userdata; |
eef65bf3 MS |
1458 | bool ignore; |
1459 | char *k; | |
1460 | int r; | |
1461 | ||
1462 | assert(filename); | |
1463 | assert(lvalue); | |
1464 | assert(rvalue); | |
1465 | assert(data); | |
1466 | ||
1467 | if (isempty(rvalue)) { | |
a1e58e8e | 1468 | c->apparmor_profile = mfree(c->apparmor_profile); |
eef65bf3 MS |
1469 | c->apparmor_profile_ignore = false; |
1470 | return 0; | |
1471 | } | |
1472 | ||
1473 | if (rvalue[0] == '-') { | |
1474 | ignore = true; | |
1475 | rvalue++; | |
1476 | } else | |
1477 | ignore = false; | |
1478 | ||
18913df9 | 1479 | r = unit_full_printf(u, rvalue, &k); |
eef65bf3 | 1480 | if (r < 0) { |
bb28e684 | 1481 | log_syntax(unit, LOG_ERR, filename, line, r, |
063c4b1a YW |
1482 | "Failed to resolve unit specifiers in '%s'%s: %m", |
1483 | rvalue, ignore ? ", ignoring" : ""); | |
bb28e684 | 1484 | return ignore ? 0 : -ENOEXEC; |
eef65bf3 MS |
1485 | } |
1486 | ||
063c4b1a | 1487 | free_and_replace(c->apparmor_profile, k); |
eef65bf3 MS |
1488 | c->apparmor_profile_ignore = ignore; |
1489 | ||
1490 | return 0; | |
1491 | } | |
1492 | ||
2ca620c4 WC |
1493 | int config_parse_exec_smack_process_label( |
1494 | const char *unit, | |
1495 | const char *filename, | |
1496 | unsigned line, | |
1497 | const char *section, | |
1498 | unsigned section_line, | |
1499 | const char *lvalue, | |
1500 | int ltype, | |
1501 | const char *rvalue, | |
1502 | void *data, | |
1503 | void *userdata) { | |
1504 | ||
1505 | ExecContext *c = data; | |
47538b76 | 1506 | const Unit *u = userdata; |
2ca620c4 WC |
1507 | bool ignore; |
1508 | char *k; | |
1509 | int r; | |
1510 | ||
1511 | assert(filename); | |
1512 | assert(lvalue); | |
1513 | assert(rvalue); | |
1514 | assert(data); | |
1515 | ||
1516 | if (isempty(rvalue)) { | |
a1e58e8e | 1517 | c->smack_process_label = mfree(c->smack_process_label); |
2ca620c4 WC |
1518 | c->smack_process_label_ignore = false; |
1519 | return 0; | |
1520 | } | |
1521 | ||
1522 | if (rvalue[0] == '-') { | |
1523 | ignore = true; | |
1524 | rvalue++; | |
1525 | } else | |
1526 | ignore = false; | |
1527 | ||
18913df9 | 1528 | r = unit_full_printf(u, rvalue, &k); |
2ca620c4 | 1529 | if (r < 0) { |
bb28e684 | 1530 | log_syntax(unit, LOG_ERR, filename, line, r, |
063c4b1a YW |
1531 | "Failed to resolve unit specifiers in '%s'%s: %m", |
1532 | rvalue, ignore ? ", ignoring" : ""); | |
bb28e684 | 1533 | return ignore ? 0 : -ENOEXEC; |
2ca620c4 WC |
1534 | } |
1535 | ||
063c4b1a | 1536 | free_and_replace(c->smack_process_label, k); |
2ca620c4 WC |
1537 | c->smack_process_label_ignore = ignore; |
1538 | ||
1539 | return 0; | |
1540 | } | |
1541 | ||
25a04ae5 LP |
1542 | int config_parse_timer( |
1543 | const char *unit, | |
1544 | const char *filename, | |
1545 | unsigned line, | |
1546 | const char *section, | |
1547 | unsigned section_line, | |
1548 | const char *lvalue, | |
1549 | int ltype, | |
1550 | const char *rvalue, | |
1551 | void *data, | |
1552 | void *userdata) { | |
871d7de4 | 1553 | |
25a04ae5 LP |
1554 | _cleanup_(calendar_spec_freep) CalendarSpec *c = NULL; |
1555 | _cleanup_free_ char *k = NULL; | |
47538b76 | 1556 | const Unit *u = userdata; |
871d7de4 | 1557 | Timer *t = data; |
2507992f | 1558 | usec_t usec = 0; |
871d7de4 | 1559 | TimerValue *v; |
2507992f | 1560 | int r; |
871d7de4 LP |
1561 | |
1562 | assert(filename); | |
1563 | assert(lvalue); | |
1564 | assert(rvalue); | |
1565 | assert(data); | |
1566 | ||
74051b9b LP |
1567 | if (isempty(rvalue)) { |
1568 | /* Empty assignment resets list */ | |
1569 | timer_free_values(t); | |
1570 | return 0; | |
1571 | } | |
1572 | ||
2507992f DC |
1573 | r = unit_full_printf(u, rvalue, &k); |
1574 | if (r < 0) { | |
063c4b1a | 1575 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue); |
2507992f DC |
1576 | return 0; |
1577 | } | |
1578 | ||
25a04ae5 | 1579 | if (ltype == TIMER_CALENDAR) { |
dc44c96d LP |
1580 | r = calendar_spec_from_string(k, &c); |
1581 | if (r < 0) { | |
1582 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse calendar specification, ignoring: %s", k); | |
36697dc0 LP |
1583 | return 0; |
1584 | } | |
dc44c96d LP |
1585 | } else { |
1586 | r = parse_sec(k, &usec); | |
1587 | if (r < 0) { | |
1588 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse timer value, ignoring: %s", k); | |
36697dc0 LP |
1589 | return 0; |
1590 | } | |
dc44c96d | 1591 | } |
871d7de4 | 1592 | |
25a04ae5 | 1593 | v = new(TimerValue, 1); |
921b5987 | 1594 | if (!v) |
74051b9b | 1595 | return log_oom(); |
871d7de4 | 1596 | |
25a04ae5 LP |
1597 | *v = (TimerValue) { |
1598 | .base = ltype, | |
1599 | .value = usec, | |
1600 | .calendar_spec = TAKE_PTR(c), | |
1601 | }; | |
871d7de4 | 1602 | |
71fda00f | 1603 | LIST_PREPEND(value, t->values, v); |
871d7de4 LP |
1604 | |
1605 | return 0; | |
1606 | } | |
1607 | ||
3ecaa09b LP |
1608 | int config_parse_trigger_unit( |
1609 | const char *unit, | |
1610 | const char *filename, | |
1611 | unsigned line, | |
1612 | const char *section, | |
71a61510 | 1613 | unsigned section_line, |
3ecaa09b LP |
1614 | const char *lvalue, |
1615 | int ltype, | |
1616 | const char *rvalue, | |
1617 | void *data, | |
1618 | void *userdata) { | |
871d7de4 | 1619 | |
74051b9b | 1620 | _cleanup_free_ char *p = NULL; |
3ecaa09b LP |
1621 | Unit *u = data; |
1622 | UnitType type; | |
1623 | int r; | |
398ef8ba LP |
1624 | |
1625 | assert(filename); | |
1626 | assert(lvalue); | |
1627 | assert(rvalue); | |
1628 | assert(data); | |
1629 | ||
eef85c4a | 1630 | if (!hashmap_isempty(u->dependencies[UNIT_TRIGGERS])) { |
12ca818f | 1631 | log_syntax(unit, LOG_ERR, filename, line, 0, "Multiple units to trigger specified, ignoring: %s", rvalue); |
3ecaa09b LP |
1632 | return 0; |
1633 | } | |
871d7de4 | 1634 | |
19f6d710 | 1635 | r = unit_name_printf(u, rvalue, &p); |
12ca818f | 1636 | if (r < 0) { |
063c4b1a | 1637 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue); |
12ca818f LP |
1638 | return 0; |
1639 | } | |
74051b9b | 1640 | |
12ca818f | 1641 | type = unit_name_to_type(p); |
3ecaa09b | 1642 | if (type < 0) { |
12ca818f | 1643 | log_syntax(unit, LOG_ERR, filename, line, 0, "Unit type not valid, ignoring: %s", rvalue); |
c0b34696 | 1644 | return 0; |
871d7de4 | 1645 | } |
49219a1c JR |
1646 | if (unit_has_name(u, p)) { |
1647 | log_syntax(unit, LOG_ERR, filename, line, 0, "Units cannot trigger themselves, ignoring: %s", rvalue); | |
3ecaa09b LP |
1648 | return 0; |
1649 | } | |
1650 | ||
5a724170 | 1651 | r = unit_add_two_dependencies_by_name(u, UNIT_BEFORE, UNIT_TRIGGERS, p, true, UNIT_DEPENDENCY_FILE); |
57020a3a | 1652 | if (r < 0) { |
12ca818f | 1653 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to add trigger on %s, ignoring: %m", p); |
c0b34696 | 1654 | return 0; |
871d7de4 LP |
1655 | } |
1656 | ||
1657 | return 0; | |
1658 | } | |
1659 | ||
e8e581bf ZJS |
1660 | int config_parse_path_spec(const char *unit, |
1661 | const char *filename, | |
1662 | unsigned line, | |
1663 | const char *section, | |
71a61510 | 1664 | unsigned section_line, |
e8e581bf ZJS |
1665 | const char *lvalue, |
1666 | int ltype, | |
1667 | const char *rvalue, | |
1668 | void *data, | |
1669 | void *userdata) { | |
01f78473 LP |
1670 | |
1671 | Path *p = data; | |
1672 | PathSpec *s; | |
1673 | PathType b; | |
7fd1b19b | 1674 | _cleanup_free_ char *k = NULL; |
19f6d710 | 1675 | int r; |
01f78473 LP |
1676 | |
1677 | assert(filename); | |
1678 | assert(lvalue); | |
1679 | assert(rvalue); | |
1680 | assert(data); | |
1681 | ||
74051b9b LP |
1682 | if (isempty(rvalue)) { |
1683 | /* Empty assignment clears list */ | |
1684 | path_free_specs(p); | |
1685 | return 0; | |
1686 | } | |
1687 | ||
93e4c84b LP |
1688 | b = path_type_from_string(lvalue); |
1689 | if (b < 0) { | |
12ca818f | 1690 | log_syntax(unit, LOG_ERR, filename, line, 0, "Failed to parse path type, ignoring: %s", lvalue); |
c0b34696 | 1691 | return 0; |
01f78473 LP |
1692 | } |
1693 | ||
19f6d710 LP |
1694 | r = unit_full_printf(UNIT(p), rvalue, &k); |
1695 | if (r < 0) { | |
063c4b1a | 1696 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue); |
12ca818f | 1697 | return 0; |
487060c2 | 1698 | } |
93e4c84b | 1699 | |
2f4d31c1 YW |
1700 | r = path_simplify_and_warn(k, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue); |
1701 | if (r < 0) | |
c0b34696 | 1702 | return 0; |
01f78473 | 1703 | |
93e4c84b | 1704 | s = new0(PathSpec, 1); |
543295ad | 1705 | if (!s) |
93e4c84b | 1706 | return log_oom(); |
01f78473 | 1707 | |
718db961 | 1708 | s->unit = UNIT(p); |
063c4b1a | 1709 | s->path = TAKE_PTR(k); |
01f78473 LP |
1710 | s->type = b; |
1711 | s->inotify_fd = -1; | |
1712 | ||
71fda00f | 1713 | LIST_PREPEND(spec, p->specs, s); |
01f78473 LP |
1714 | |
1715 | return 0; | |
1716 | } | |
1717 | ||
b02cb41c LP |
1718 | int config_parse_socket_service( |
1719 | const char *unit, | |
1720 | const char *filename, | |
1721 | unsigned line, | |
1722 | const char *section, | |
1723 | unsigned section_line, | |
1724 | const char *lvalue, | |
1725 | int ltype, | |
1726 | const char *rvalue, | |
1727 | void *data, | |
1728 | void *userdata) { | |
d9ff321a | 1729 | |
4afd3348 | 1730 | _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; |
8dd4c05b | 1731 | _cleanup_free_ char *p = NULL; |
d9ff321a | 1732 | Socket *s = data; |
4ff77f66 | 1733 | Unit *x; |
8dd4c05b | 1734 | int r; |
d9ff321a LP |
1735 | |
1736 | assert(filename); | |
1737 | assert(lvalue); | |
1738 | assert(rvalue); | |
1739 | assert(data); | |
1740 | ||
19f6d710 | 1741 | r = unit_name_printf(UNIT(s), rvalue, &p); |
613b411c | 1742 | if (r < 0) { |
063c4b1a | 1743 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in %s: %m", rvalue); |
bb28e684 | 1744 | return -ENOEXEC; |
613b411c | 1745 | } |
74051b9b | 1746 | |
613b411c | 1747 | if (!endswith(p, ".service")) { |
bb28e684 ZJS |
1748 | log_syntax(unit, LOG_ERR, filename, line, 0, "Unit must be of type service: %s", rvalue); |
1749 | return -ENOEXEC; | |
d9ff321a LP |
1750 | } |
1751 | ||
613b411c | 1752 | r = manager_load_unit(UNIT(s)->manager, p, NULL, &error, &x); |
4ff77f66 | 1753 | if (r < 0) { |
bb28e684 ZJS |
1754 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to load unit %s: %s", rvalue, bus_error_message(&error, r)); |
1755 | return -ENOEXEC; | |
d9ff321a LP |
1756 | } |
1757 | ||
7f7d01ed | 1758 | unit_ref_set(&s->service, UNIT(s), x); |
4ff77f66 | 1759 | |
d9ff321a LP |
1760 | return 0; |
1761 | } | |
1762 | ||
8dd4c05b LP |
1763 | int config_parse_fdname( |
1764 | const char *unit, | |
1765 | const char *filename, | |
1766 | unsigned line, | |
1767 | const char *section, | |
1768 | unsigned section_line, | |
1769 | const char *lvalue, | |
1770 | int ltype, | |
1771 | const char *rvalue, | |
1772 | void *data, | |
1773 | void *userdata) { | |
1774 | ||
1775 | _cleanup_free_ char *p = NULL; | |
1776 | Socket *s = data; | |
1777 | int r; | |
1778 | ||
1779 | assert(filename); | |
1780 | assert(lvalue); | |
1781 | assert(rvalue); | |
1782 | assert(data); | |
1783 | ||
1784 | if (isempty(rvalue)) { | |
1785 | s->fdname = mfree(s->fdname); | |
1786 | return 0; | |
1787 | } | |
1788 | ||
18913df9 | 1789 | r = unit_full_printf(UNIT(s), rvalue, &p); |
8dd4c05b | 1790 | if (r < 0) { |
063c4b1a | 1791 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue); |
8dd4c05b LP |
1792 | return 0; |
1793 | } | |
1794 | ||
1795 | if (!fdname_is_valid(p)) { | |
1796 | log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid file descriptor name, ignoring: %s", p); | |
1797 | return 0; | |
1798 | } | |
1799 | ||
3b319885 | 1800 | return free_and_replace(s->fdname, p); |
8dd4c05b LP |
1801 | } |
1802 | ||
b02cb41c LP |
1803 | int config_parse_service_sockets( |
1804 | const char *unit, | |
1805 | const char *filename, | |
1806 | unsigned line, | |
1807 | const char *section, | |
1808 | unsigned section_line, | |
1809 | const char *lvalue, | |
1810 | int ltype, | |
1811 | const char *rvalue, | |
1812 | void *data, | |
1813 | void *userdata) { | |
f976f3f6 LP |
1814 | |
1815 | Service *s = data; | |
7b2313f5 | 1816 | const char *p; |
b02cb41c | 1817 | int r; |
f976f3f6 LP |
1818 | |
1819 | assert(filename); | |
1820 | assert(lvalue); | |
1821 | assert(rvalue); | |
1822 | assert(data); | |
1823 | ||
7b2313f5 | 1824 | p = rvalue; |
9ed794a3 | 1825 | for (;;) { |
6a0f3175 | 1826 | _cleanup_free_ char *word = NULL, *k = NULL; |
f976f3f6 | 1827 | |
7b2313f5 SS |
1828 | r = extract_first_word(&p, &word, NULL, 0); |
1829 | if (r == 0) | |
1830 | break; | |
1831 | if (r == -ENOMEM) | |
74051b9b | 1832 | return log_oom(); |
7b2313f5 SS |
1833 | if (r < 0) { |
1834 | log_syntax(unit, LOG_ERR, filename, line, r, "Trailing garbage in sockets, ignoring: %s", rvalue); | |
1835 | break; | |
1836 | } | |
f976f3f6 | 1837 | |
7b2313f5 | 1838 | r = unit_name_printf(UNIT(s), word, &k); |
b02cb41c | 1839 | if (r < 0) { |
063c4b1a | 1840 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %m", word); |
b02cb41c LP |
1841 | continue; |
1842 | } | |
57020a3a | 1843 | |
b02cb41c | 1844 | if (!endswith(k, ".socket")) { |
12ca818f | 1845 | log_syntax(unit, LOG_ERR, filename, line, 0, "Unit must be of type socket, ignoring: %s", k); |
f976f3f6 LP |
1846 | continue; |
1847 | } | |
1848 | ||
5a724170 | 1849 | r = unit_add_two_dependencies_by_name(UNIT(s), UNIT_WANTS, UNIT_AFTER, k, true, UNIT_DEPENDENCY_FILE); |
57020a3a | 1850 | if (r < 0) |
b02cb41c | 1851 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to add dependency on %s, ignoring: %m", k); |
f976f3f6 | 1852 | |
35d8c19a | 1853 | r = unit_add_dependency_by_name(UNIT(s), UNIT_TRIGGERED_BY, k, true, UNIT_DEPENDENCY_FILE); |
57020a3a | 1854 | if (r < 0) |
b02cb41c | 1855 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to add dependency on %s, ignoring: %m", k); |
f976f3f6 LP |
1856 | } |
1857 | ||
1858 | return 0; | |
1859 | } | |
1860 | ||
b02cb41c LP |
1861 | int config_parse_bus_name( |
1862 | const char *unit, | |
1863 | const char *filename, | |
1864 | unsigned line, | |
1865 | const char *section, | |
1866 | unsigned section_line, | |
1867 | const char *lvalue, | |
1868 | int ltype, | |
1869 | const char *rvalue, | |
1870 | void *data, | |
1871 | void *userdata) { | |
1872 | ||
1873 | _cleanup_free_ char *k = NULL; | |
47538b76 | 1874 | const Unit *u = userdata; |
b02cb41c LP |
1875 | int r; |
1876 | ||
1877 | assert(filename); | |
1878 | assert(lvalue); | |
1879 | assert(rvalue); | |
1880 | assert(u); | |
1881 | ||
1882 | r = unit_full_printf(u, rvalue, &k); | |
1883 | if (r < 0) { | |
063c4b1a | 1884 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue); |
b02cb41c LP |
1885 | return 0; |
1886 | } | |
1887 | ||
1888 | if (!service_name_is_valid(k)) { | |
063c4b1a | 1889 | log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid bus name, ignoring: %s", k); |
b02cb41c LP |
1890 | return 0; |
1891 | } | |
1892 | ||
1893 | return config_parse_string(unit, filename, line, section, section_line, lvalue, ltype, k, data, userdata); | |
1894 | } | |
1895 | ||
aad41f08 LP |
1896 | int config_parse_service_timeout( |
1897 | const char *unit, | |
1898 | const char *filename, | |
1899 | unsigned line, | |
1900 | const char *section, | |
1901 | unsigned section_line, | |
1902 | const char *lvalue, | |
1903 | int ltype, | |
1904 | const char *rvalue, | |
1905 | void *data, | |
1906 | void *userdata) { | |
98709151 LN |
1907 | |
1908 | Service *s = userdata; | |
aad41f08 | 1909 | usec_t usec; |
98709151 LN |
1910 | int r; |
1911 | ||
1912 | assert(filename); | |
1913 | assert(lvalue); | |
1914 | assert(rvalue); | |
1915 | assert(s); | |
1916 | ||
6c58305a | 1917 | /* This is called for two cases: TimeoutSec= and TimeoutStartSec=. */ |
98709151 | 1918 | |
fb27be3f YW |
1919 | /* Traditionally, these options accepted 0 to disable the timeouts. However, a timeout of 0 suggests it happens |
1920 | * immediately, hence fix this to become USEC_INFINITY instead. This is in-line with how we internally handle | |
1921 | * all other timeouts. */ | |
1922 | r = parse_sec_fix_0(rvalue, &usec); | |
aad41f08 LP |
1923 | if (r < 0) { |
1924 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse %s= parameter, ignoring: %s", lvalue, rvalue); | |
1925 | return 0; | |
1926 | } | |
d568a335 | 1927 | |
6c58305a YW |
1928 | s->start_timeout_defined = true; |
1929 | s->timeout_start_usec = usec; | |
36c16a7c | 1930 | |
6c58305a | 1931 | if (streq(lvalue, "TimeoutSec")) |
aad41f08 | 1932 | s->timeout_stop_usec = usec; |
36c16a7c | 1933 | |
d568a335 | 1934 | return 0; |
98709151 LN |
1935 | } |
1936 | ||
dc653bf4 JK |
1937 | int config_parse_service_timeout_abort( |
1938 | const char *unit, | |
1939 | const char *filename, | |
1940 | unsigned line, | |
1941 | const char *section, | |
1942 | unsigned section_line, | |
1943 | const char *lvalue, | |
1944 | int ltype, | |
1945 | const char *rvalue, | |
1946 | void *data, | |
1947 | void *userdata) { | |
1948 | ||
1949 | Service *s = userdata; | |
1950 | int r; | |
1951 | ||
1952 | assert(filename); | |
1953 | assert(lvalue); | |
1954 | assert(rvalue); | |
1955 | assert(s); | |
1956 | ||
1957 | rvalue += strspn(rvalue, WHITESPACE); | |
1958 | if (isempty(rvalue)) { | |
1959 | s->timeout_abort_set = false; | |
1960 | return 0; | |
1961 | } | |
1962 | ||
1963 | r = parse_sec(rvalue, &s->timeout_abort_usec); | |
1964 | if (r < 0) { | |
1965 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse TimeoutAbortSec= setting, ignoring: %s", rvalue); | |
1966 | return 0; | |
1967 | } | |
1968 | ||
1969 | s->timeout_abort_set = true; | |
1970 | return 0; | |
1971 | } | |
1972 | ||
89beff89 LP |
1973 | int config_parse_sec_fix_0( |
1974 | const char *unit, | |
1975 | const char *filename, | |
1976 | unsigned line, | |
1977 | const char *section, | |
1978 | unsigned section_line, | |
1979 | const char *lvalue, | |
1980 | int ltype, | |
1981 | const char *rvalue, | |
1982 | void *data, | |
1983 | void *userdata) { | |
1984 | ||
1985 | usec_t *usec = data; | |
1986 | int r; | |
1987 | ||
1988 | assert(filename); | |
1989 | assert(lvalue); | |
1990 | assert(rvalue); | |
1991 | assert(usec); | |
1992 | ||
1993 | /* This is pretty much like config_parse_sec(), except that this treats a time of 0 as infinity, for | |
1994 | * compatibility with older versions of systemd where 0 instead of infinity was used as indicator to turn off a | |
1995 | * timeout. */ | |
1996 | ||
0004f698 | 1997 | r = parse_sec_fix_0(rvalue, usec); |
89beff89 LP |
1998 | if (r < 0) { |
1999 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse %s= parameter, ignoring: %s", lvalue, rvalue); | |
2000 | return 0; | |
2001 | } | |
2002 | ||
89beff89 LP |
2003 | return 0; |
2004 | } | |
2005 | ||
ae480f0b | 2006 | int config_parse_user_group_compat( |
66dccd8d LP |
2007 | const char *unit, |
2008 | const char *filename, | |
2009 | unsigned line, | |
2010 | const char *section, | |
2011 | unsigned section_line, | |
2012 | const char *lvalue, | |
2013 | int ltype, | |
2014 | const char *rvalue, | |
2015 | void *data, | |
2016 | void *userdata) { | |
2017 | ||
063c4b1a YW |
2018 | _cleanup_free_ char *k = NULL; |
2019 | char **user = data; | |
47538b76 | 2020 | const Unit *u = userdata; |
66dccd8d LP |
2021 | int r; |
2022 | ||
2023 | assert(filename); | |
2024 | assert(lvalue); | |
2025 | assert(rvalue); | |
2026 | assert(u); | |
2027 | ||
063c4b1a YW |
2028 | if (isempty(rvalue)) { |
2029 | *user = mfree(*user); | |
2030 | return 0; | |
2031 | } | |
66dccd8d | 2032 | |
063c4b1a YW |
2033 | r = unit_full_printf(u, rvalue, &k); |
2034 | if (r < 0) { | |
2035 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in %s: %m", rvalue); | |
2036 | return -ENOEXEC; | |
66dccd8d LP |
2037 | } |
2038 | ||
ae480f0b | 2039 | if (!valid_user_group_name_or_id_compat(k)) { |
063c4b1a YW |
2040 | log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid user/group name or numeric ID: %s", k); |
2041 | return -ENOEXEC; | |
2042 | } | |
66dccd8d | 2043 | |
063c4b1a | 2044 | return free_and_replace(*user, k); |
66dccd8d LP |
2045 | } |
2046 | ||
ae480f0b | 2047 | int config_parse_user_group_strv_compat( |
66dccd8d LP |
2048 | const char *unit, |
2049 | const char *filename, | |
2050 | unsigned line, | |
2051 | const char *section, | |
2052 | unsigned section_line, | |
2053 | const char *lvalue, | |
2054 | int ltype, | |
2055 | const char *rvalue, | |
2056 | void *data, | |
2057 | void *userdata) { | |
2058 | ||
2059 | char ***users = data; | |
47538b76 | 2060 | const Unit *u = userdata; |
063c4b1a | 2061 | const char *p = rvalue; |
66dccd8d LP |
2062 | int r; |
2063 | ||
2064 | assert(filename); | |
2065 | assert(lvalue); | |
2066 | assert(rvalue); | |
2067 | assert(u); | |
2068 | ||
2069 | if (isempty(rvalue)) { | |
9f2d41a6 | 2070 | *users = strv_free(*users); |
66dccd8d LP |
2071 | return 0; |
2072 | } | |
2073 | ||
66dccd8d LP |
2074 | for (;;) { |
2075 | _cleanup_free_ char *word = NULL, *k = NULL; | |
2076 | ||
9a82ab95 | 2077 | r = extract_first_word(&p, &word, NULL, 0); |
66dccd8d LP |
2078 | if (r == 0) |
2079 | break; | |
2080 | if (r == -ENOMEM) | |
2081 | return log_oom(); | |
2082 | if (r < 0) { | |
bb28e684 ZJS |
2083 | log_syntax(unit, LOG_ERR, filename, line, r, "Invalid syntax: %s", rvalue); |
2084 | return -ENOEXEC; | |
66dccd8d LP |
2085 | } |
2086 | ||
2087 | r = unit_full_printf(u, word, &k); | |
2088 | if (r < 0) { | |
bb28e684 ZJS |
2089 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in %s: %m", word); |
2090 | return -ENOEXEC; | |
66dccd8d LP |
2091 | } |
2092 | ||
ae480f0b | 2093 | if (!valid_user_group_name_or_id_compat(k)) { |
bb28e684 ZJS |
2094 | log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid user/group name or numeric ID: %s", k); |
2095 | return -ENOEXEC; | |
66dccd8d LP |
2096 | } |
2097 | ||
2098 | r = strv_push(users, k); | |
2099 | if (r < 0) | |
2100 | return log_oom(); | |
2101 | ||
2102 | k = NULL; | |
2103 | } | |
2104 | ||
2105 | return 0; | |
2106 | } | |
2107 | ||
5f5d8eab LP |
2108 | int config_parse_working_directory( |
2109 | const char *unit, | |
2110 | const char *filename, | |
2111 | unsigned line, | |
2112 | const char *section, | |
2113 | unsigned section_line, | |
2114 | const char *lvalue, | |
2115 | int ltype, | |
2116 | const char *rvalue, | |
2117 | void *data, | |
2118 | void *userdata) { | |
2119 | ||
2120 | ExecContext *c = data; | |
47538b76 | 2121 | const Unit *u = userdata; |
5f5d8eab LP |
2122 | bool missing_ok; |
2123 | int r; | |
2124 | ||
2125 | assert(filename); | |
2126 | assert(lvalue); | |
2127 | assert(rvalue); | |
2128 | assert(c); | |
2129 | assert(u); | |
2130 | ||
862fcffd YW |
2131 | if (isempty(rvalue)) { |
2132 | c->working_directory_home = false; | |
2133 | c->working_directory = mfree(c->working_directory); | |
2134 | return 0; | |
2135 | } | |
2136 | ||
5f5d8eab LP |
2137 | if (rvalue[0] == '-') { |
2138 | missing_ok = true; | |
2139 | rvalue++; | |
2140 | } else | |
2141 | missing_ok = false; | |
2142 | ||
2143 | if (streq(rvalue, "~")) { | |
2144 | c->working_directory_home = true; | |
2145 | c->working_directory = mfree(c->working_directory); | |
2146 | } else { | |
2147 | _cleanup_free_ char *k = NULL; | |
2148 | ||
2149 | r = unit_full_printf(u, rvalue, &k); | |
2150 | if (r < 0) { | |
bb28e684 ZJS |
2151 | log_syntax(unit, LOG_ERR, filename, line, r, |
2152 | "Failed to resolve unit specifiers in working directory path '%s'%s: %m", | |
2153 | rvalue, missing_ok ? ", ignoring" : ""); | |
2154 | return missing_ok ? 0 : -ENOEXEC; | |
5f5d8eab LP |
2155 | } |
2156 | ||
2f4d31c1 YW |
2157 | r = path_simplify_and_warn(k, PATH_CHECK_ABSOLUTE | (missing_ok ? 0 : PATH_CHECK_FATAL), unit, filename, line, lvalue); |
2158 | if (r < 0) | |
bb28e684 | 2159 | return missing_ok ? 0 : -ENOEXEC; |
5f5d8eab | 2160 | |
5f5d8eab | 2161 | c->working_directory_home = false; |
bb28e684 | 2162 | free_and_replace(c->working_directory, k); |
5f5d8eab LP |
2163 | } |
2164 | ||
2165 | c->working_directory_missing_ok = missing_ok; | |
2166 | return 0; | |
2167 | } | |
2168 | ||
e8e581bf ZJS |
2169 | int config_parse_unit_env_file(const char *unit, |
2170 | const char *filename, | |
2171 | unsigned line, | |
2172 | const char *section, | |
71a61510 | 2173 | unsigned section_line, |
e8e581bf ZJS |
2174 | const char *lvalue, |
2175 | int ltype, | |
2176 | const char *rvalue, | |
2177 | void *data, | |
2178 | void *userdata) { | |
ddb26e18 | 2179 | |
853b8397 | 2180 | char ***env = data; |
47538b76 | 2181 | const Unit *u = userdata; |
19f6d710 | 2182 | _cleanup_free_ char *n = NULL; |
853b8397 | 2183 | int r; |
ddb26e18 LP |
2184 | |
2185 | assert(filename); | |
2186 | assert(lvalue); | |
2187 | assert(rvalue); | |
2188 | assert(data); | |
2189 | ||
74051b9b LP |
2190 | if (isempty(rvalue)) { |
2191 | /* Empty assignment frees the list */ | |
6796073e | 2192 | *env = strv_free(*env); |
74051b9b LP |
2193 | return 0; |
2194 | } | |
2195 | ||
19f6d710 | 2196 | r = unit_full_printf(u, rvalue, &n); |
12ca818f | 2197 | if (r < 0) { |
063c4b1a | 2198 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue); |
12ca818f LP |
2199 | return 0; |
2200 | } | |
8fef7659 | 2201 | |
2f4d31c1 YW |
2202 | r = path_simplify_and_warn(n[0] == '-' ? n + 1 : n, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue); |
2203 | if (r < 0) | |
afe4bfe2 | 2204 | return 0; |
afe4bfe2 | 2205 | |
2f4d31c1 | 2206 | r = strv_push(env, n); |
853b8397 LP |
2207 | if (r < 0) |
2208 | return log_oom(); | |
2209 | ||
2f4d31c1 YW |
2210 | n = NULL; |
2211 | ||
853b8397 LP |
2212 | return 0; |
2213 | } | |
2214 | ||
f7f3f5c3 LP |
2215 | int config_parse_environ( |
2216 | const char *unit, | |
2217 | const char *filename, | |
2218 | unsigned line, | |
2219 | const char *section, | |
2220 | unsigned section_line, | |
2221 | const char *lvalue, | |
2222 | int ltype, | |
2223 | const char *rvalue, | |
2224 | void *data, | |
2225 | void *userdata) { | |
853b8397 | 2226 | |
47538b76 | 2227 | const Unit *u = userdata; |
035fe294 ZJS |
2228 | char ***env = data; |
2229 | const char *p; | |
19f6d710 | 2230 | int r; |
853b8397 LP |
2231 | |
2232 | assert(filename); | |
2233 | assert(lvalue); | |
2234 | assert(rvalue); | |
97d0e5f8 | 2235 | assert(data); |
853b8397 LP |
2236 | |
2237 | if (isempty(rvalue)) { | |
2238 | /* Empty assignment resets the list */ | |
6796073e | 2239 | *env = strv_free(*env); |
853b8397 LP |
2240 | return 0; |
2241 | } | |
2242 | ||
035fe294 ZJS |
2243 | for (p = rvalue;; ) { |
2244 | _cleanup_free_ char *word = NULL, *k = NULL; | |
035fe294 | 2245 | |
4ec85141 | 2246 | r = extract_first_word(&p, &word, NULL, EXTRACT_CUNESCAPE|EXTRACT_UNQUOTE); |
035fe294 ZJS |
2247 | if (r == 0) |
2248 | return 0; | |
2249 | if (r == -ENOMEM) | |
2250 | return log_oom(); | |
12ca818f | 2251 | if (r < 0) { |
035fe294 ZJS |
2252 | log_syntax(unit, LOG_WARNING, filename, line, r, |
2253 | "Invalid syntax, ignoring: %s", rvalue); | |
12ca818f LP |
2254 | return 0; |
2255 | } | |
97d0e5f8 | 2256 | |
035fe294 ZJS |
2257 | if (u) { |
2258 | r = unit_full_printf(u, word, &k); | |
2259 | if (r < 0) { | |
2260 | log_syntax(unit, LOG_ERR, filename, line, r, | |
063c4b1a | 2261 | "Failed to resolve unit specifiers in %s, ignoring: %m", word); |
035fe294 ZJS |
2262 | continue; |
2263 | } | |
ae2a15bc LP |
2264 | } else |
2265 | k = TAKE_PTR(word); | |
853b8397 | 2266 | |
035fe294 ZJS |
2267 | if (!env_assignment_is_valid(k)) { |
2268 | log_syntax(unit, LOG_ERR, filename, line, 0, | |
2269 | "Invalid environment assignment, ignoring: %s", k); | |
853b8397 LP |
2270 | continue; |
2271 | } | |
2272 | ||
54ac3494 ZJS |
2273 | r = strv_env_replace(env, k); |
2274 | if (r < 0) | |
853b8397 | 2275 | return log_oom(); |
f7f3f5c3 | 2276 | |
54ac3494 | 2277 | k = NULL; |
853b8397 | 2278 | } |
ddb26e18 LP |
2279 | } |
2280 | ||
00819cc1 LP |
2281 | int config_parse_pass_environ( |
2282 | const char *unit, | |
2283 | const char *filename, | |
2284 | unsigned line, | |
2285 | const char *section, | |
2286 | unsigned section_line, | |
2287 | const char *lvalue, | |
2288 | int ltype, | |
2289 | const char *rvalue, | |
2290 | void *data, | |
2291 | void *userdata) { | |
b4c14404 | 2292 | |
b4c14404 FB |
2293 | _cleanup_strv_free_ char **n = NULL; |
2294 | size_t nlen = 0, nbufsize = 0; | |
41de9cc2 | 2295 | char*** passenv = data; |
063c4b1a | 2296 | const char *p = rvalue; |
47538b76 | 2297 | const Unit *u = userdata; |
b4c14404 FB |
2298 | int r; |
2299 | ||
2300 | assert(filename); | |
2301 | assert(lvalue); | |
2302 | assert(rvalue); | |
2303 | assert(data); | |
2304 | ||
2305 | if (isempty(rvalue)) { | |
2306 | /* Empty assignment resets the list */ | |
2307 | *passenv = strv_free(*passenv); | |
2308 | return 0; | |
2309 | } | |
2310 | ||
2311 | for (;;) { | |
41de9cc2 | 2312 | _cleanup_free_ char *word = NULL, *k = NULL; |
b4c14404 | 2313 | |
4ec85141 | 2314 | r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE); |
b4c14404 FB |
2315 | if (r == 0) |
2316 | break; | |
2317 | if (r == -ENOMEM) | |
2318 | return log_oom(); | |
2319 | if (r < 0) { | |
2320 | log_syntax(unit, LOG_ERR, filename, line, r, | |
063c4b1a | 2321 | "Trailing garbage in %s, ignoring: %s", lvalue, rvalue); |
b4c14404 FB |
2322 | break; |
2323 | } | |
2324 | ||
41de9cc2 LP |
2325 | if (u) { |
2326 | r = unit_full_printf(u, word, &k); | |
2327 | if (r < 0) { | |
2328 | log_syntax(unit, LOG_ERR, filename, line, r, | |
063c4b1a | 2329 | "Failed to resolve specifiers in %s, ignoring: %m", word); |
41de9cc2 LP |
2330 | continue; |
2331 | } | |
ae2a15bc LP |
2332 | } else |
2333 | k = TAKE_PTR(word); | |
41de9cc2 LP |
2334 | |
2335 | if (!env_name_is_valid(k)) { | |
2336 | log_syntax(unit, LOG_ERR, filename, line, 0, | |
2337 | "Invalid environment name for %s, ignoring: %s", lvalue, k); | |
b4c14404 FB |
2338 | continue; |
2339 | } | |
2340 | ||
2341 | if (!GREEDY_REALLOC(n, nbufsize, nlen + 2)) | |
2342 | return log_oom(); | |
41de9cc2 | 2343 | |
1cc6c93a | 2344 | n[nlen++] = TAKE_PTR(k); |
b4c14404 | 2345 | n[nlen] = NULL; |
b4c14404 FB |
2346 | } |
2347 | ||
2348 | if (n) { | |
2349 | r = strv_extend_strv(passenv, n, true); | |
2350 | if (r < 0) | |
2351 | return r; | |
2352 | } | |
2353 | ||
2354 | return 0; | |
2355 | } | |
2356 | ||
00819cc1 LP |
2357 | int config_parse_unset_environ( |
2358 | const char *unit, | |
2359 | const char *filename, | |
2360 | unsigned line, | |
2361 | const char *section, | |
2362 | unsigned section_line, | |
2363 | const char *lvalue, | |
2364 | int ltype, | |
2365 | const char *rvalue, | |
2366 | void *data, | |
2367 | void *userdata) { | |
2368 | ||
2369 | _cleanup_strv_free_ char **n = NULL; | |
00819cc1 LP |
2370 | size_t nlen = 0, nbufsize = 0; |
2371 | char*** unsetenv = data; | |
063c4b1a | 2372 | const char *p = rvalue; |
47538b76 | 2373 | const Unit *u = userdata; |
00819cc1 LP |
2374 | int r; |
2375 | ||
2376 | assert(filename); | |
2377 | assert(lvalue); | |
2378 | assert(rvalue); | |
2379 | assert(data); | |
2380 | ||
2381 | if (isempty(rvalue)) { | |
2382 | /* Empty assignment resets the list */ | |
2383 | *unsetenv = strv_free(*unsetenv); | |
2384 | return 0; | |
2385 | } | |
2386 | ||
2387 | for (;;) { | |
2388 | _cleanup_free_ char *word = NULL, *k = NULL; | |
2389 | ||
4ec85141 | 2390 | r = extract_first_word(&p, &word, NULL, EXTRACT_CUNESCAPE|EXTRACT_UNQUOTE); |
00819cc1 LP |
2391 | if (r == 0) |
2392 | break; | |
2393 | if (r == -ENOMEM) | |
2394 | return log_oom(); | |
2395 | if (r < 0) { | |
2396 | log_syntax(unit, LOG_ERR, filename, line, r, | |
063c4b1a | 2397 | "Trailing garbage in %s, ignoring: %s", lvalue, rvalue); |
00819cc1 LP |
2398 | break; |
2399 | } | |
2400 | ||
2401 | if (u) { | |
2402 | r = unit_full_printf(u, word, &k); | |
2403 | if (r < 0) { | |
2404 | log_syntax(unit, LOG_ERR, filename, line, r, | |
063c4b1a | 2405 | "Failed to resolve unit specifiers in %s, ignoring: %m", word); |
00819cc1 LP |
2406 | continue; |
2407 | } | |
ae2a15bc LP |
2408 | } else |
2409 | k = TAKE_PTR(word); | |
00819cc1 LP |
2410 | |
2411 | if (!env_assignment_is_valid(k) && !env_name_is_valid(k)) { | |
2412 | log_syntax(unit, LOG_ERR, filename, line, 0, | |
2413 | "Invalid environment name or assignment %s, ignoring: %s", lvalue, k); | |
2414 | continue; | |
2415 | } | |
2416 | ||
2417 | if (!GREEDY_REALLOC(n, nbufsize, nlen + 2)) | |
2418 | return log_oom(); | |
2419 | ||
1cc6c93a | 2420 | n[nlen++] = TAKE_PTR(k); |
00819cc1 | 2421 | n[nlen] = NULL; |
00819cc1 LP |
2422 | } |
2423 | ||
2424 | if (n) { | |
2425 | r = strv_extend_strv(unsetenv, n, true); | |
2426 | if (r < 0) | |
2427 | return r; | |
2428 | } | |
2429 | ||
2430 | return 0; | |
2431 | } | |
2432 | ||
d3070fbd LP |
2433 | int config_parse_log_extra_fields( |
2434 | const char *unit, | |
2435 | const char *filename, | |
2436 | unsigned line, | |
2437 | const char *section, | |
2438 | unsigned section_line, | |
2439 | const char *lvalue, | |
2440 | int ltype, | |
2441 | const char *rvalue, | |
2442 | void *data, | |
2443 | void *userdata) { | |
2444 | ||
2445 | ExecContext *c = data; | |
47538b76 | 2446 | const Unit *u = userdata; |
063c4b1a | 2447 | const char *p = rvalue; |
d3070fbd LP |
2448 | int r; |
2449 | ||
2450 | assert(filename); | |
2451 | assert(lvalue); | |
2452 | assert(rvalue); | |
2453 | assert(c); | |
2454 | ||
2455 | if (isempty(rvalue)) { | |
2456 | exec_context_free_log_extra_fields(c); | |
2457 | return 0; | |
2458 | } | |
2459 | ||
063c4b1a | 2460 | for (;;) { |
d3070fbd LP |
2461 | _cleanup_free_ char *word = NULL, *k = NULL; |
2462 | struct iovec *t; | |
2463 | const char *eq; | |
2464 | ||
4ec85141 | 2465 | r = extract_first_word(&p, &word, NULL, EXTRACT_CUNESCAPE|EXTRACT_UNQUOTE); |
d3070fbd | 2466 | if (r == 0) |
063c4b1a | 2467 | return 0; |
d3070fbd LP |
2468 | if (r == -ENOMEM) |
2469 | return log_oom(); | |
2470 | if (r < 0) { | |
2471 | log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid syntax, ignoring: %s", rvalue); | |
2472 | return 0; | |
2473 | } | |
2474 | ||
2475 | r = unit_full_printf(u, word, &k); | |
2476 | if (r < 0) { | |
063c4b1a | 2477 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in %s, ignoring: %m", word); |
d3070fbd LP |
2478 | continue; |
2479 | } | |
2480 | ||
2481 | eq = strchr(k, '='); | |
2482 | if (!eq) { | |
063c4b1a | 2483 | log_syntax(unit, LOG_ERR, filename, line, 0, "Log field lacks '=' character, ignoring: %s", k); |
d3070fbd LP |
2484 | continue; |
2485 | } | |
2486 | ||
2487 | if (!journal_field_valid(k, eq-k, false)) { | |
063c4b1a | 2488 | log_syntax(unit, LOG_ERR, filename, line, 0, "Log field name is invalid, ignoring: %s", k); |
d3070fbd LP |
2489 | continue; |
2490 | } | |
2491 | ||
aa484f35 | 2492 | t = reallocarray(c->log_extra_fields, c->n_log_extra_fields+1, sizeof(struct iovec)); |
d3070fbd LP |
2493 | if (!t) |
2494 | return log_oom(); | |
2495 | ||
2496 | c->log_extra_fields = t; | |
2497 | c->log_extra_fields[c->n_log_extra_fields++] = IOVEC_MAKE_STRING(k); | |
2498 | ||
2499 | k = NULL; | |
2500 | } | |
d3070fbd LP |
2501 | } |
2502 | ||
59fccdc5 LP |
2503 | int config_parse_unit_condition_path( |
2504 | const char *unit, | |
2505 | const char *filename, | |
2506 | unsigned line, | |
2507 | const char *section, | |
2508 | unsigned section_line, | |
2509 | const char *lvalue, | |
2510 | int ltype, | |
2511 | const char *rvalue, | |
2512 | void *data, | |
2513 | void *userdata) { | |
52661efd | 2514 | |
2fbe635a | 2515 | _cleanup_free_ char *p = NULL; |
59fccdc5 LP |
2516 | Condition **list = data, *c; |
2517 | ConditionType t = ltype; | |
2518 | bool trigger, negate; | |
47538b76 | 2519 | const Unit *u = userdata; |
19f6d710 | 2520 | int r; |
52661efd LP |
2521 | |
2522 | assert(filename); | |
2523 | assert(lvalue); | |
2524 | assert(rvalue); | |
2525 | assert(data); | |
2526 | ||
74051b9b LP |
2527 | if (isempty(rvalue)) { |
2528 | /* Empty assignment resets the list */ | |
447021aa | 2529 | *list = condition_free_list(*list); |
74051b9b LP |
2530 | return 0; |
2531 | } | |
2532 | ||
ab7f148f LP |
2533 | trigger = rvalue[0] == '|'; |
2534 | if (trigger) | |
267632f0 LP |
2535 | rvalue++; |
2536 | ||
ab7f148f LP |
2537 | negate = rvalue[0] == '!'; |
2538 | if (negate) | |
52661efd LP |
2539 | rvalue++; |
2540 | ||
19f6d710 | 2541 | r = unit_full_printf(u, rvalue, &p); |
59fccdc5 | 2542 | if (r < 0) { |
063c4b1a | 2543 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue); |
59fccdc5 | 2544 | return 0; |
19f6d710 | 2545 | } |
095b2d7a | 2546 | |
2f4d31c1 YW |
2547 | r = path_simplify_and_warn(p, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue); |
2548 | if (r < 0) | |
52661efd | 2549 | return 0; |
52661efd | 2550 | |
59fccdc5 | 2551 | c = condition_new(t, p, trigger, negate); |
ab7f148f | 2552 | if (!c) |
74051b9b | 2553 | return log_oom(); |
52661efd | 2554 | |
59fccdc5 | 2555 | LIST_PREPEND(conditions, *list, c); |
52661efd LP |
2556 | return 0; |
2557 | } | |
2558 | ||
59fccdc5 LP |
2559 | int config_parse_unit_condition_string( |
2560 | const char *unit, | |
2561 | const char *filename, | |
2562 | unsigned line, | |
2563 | const char *section, | |
2564 | unsigned section_line, | |
2565 | const char *lvalue, | |
2566 | int ltype, | |
2567 | const char *rvalue, | |
2568 | void *data, | |
2569 | void *userdata) { | |
039655a4 | 2570 | |
2fbe635a | 2571 | _cleanup_free_ char *s = NULL; |
59fccdc5 LP |
2572 | Condition **list = data, *c; |
2573 | ConditionType t = ltype; | |
2574 | bool trigger, negate; | |
47538b76 | 2575 | const Unit *u = userdata; |
19f6d710 | 2576 | int r; |
039655a4 LP |
2577 | |
2578 | assert(filename); | |
2579 | assert(lvalue); | |
2580 | assert(rvalue); | |
2581 | assert(data); | |
2582 | ||
74051b9b LP |
2583 | if (isempty(rvalue)) { |
2584 | /* Empty assignment resets the list */ | |
447021aa | 2585 | *list = condition_free_list(*list); |
74051b9b LP |
2586 | return 0; |
2587 | } | |
2588 | ||
9266f31e | 2589 | trigger = *rvalue == '|'; |
c0d6e764 | 2590 | if (trigger) |
9266f31e | 2591 | rvalue += 1 + strspn(rvalue + 1, WHITESPACE); |
267632f0 | 2592 | |
9266f31e | 2593 | negate = *rvalue == '!'; |
c0d6e764 | 2594 | if (negate) |
9266f31e | 2595 | rvalue += 1 + strspn(rvalue + 1, WHITESPACE); |
039655a4 | 2596 | |
19f6d710 | 2597 | r = unit_full_printf(u, rvalue, &s); |
59fccdc5 | 2598 | if (r < 0) { |
cae90de3 ZJS |
2599 | log_syntax(unit, LOG_ERR, filename, line, r, |
2600 | "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue); | |
59fccdc5 | 2601 | return 0; |
19f6d710 | 2602 | } |
095b2d7a | 2603 | |
59fccdc5 | 2604 | c = condition_new(t, s, trigger, negate); |
c0d6e764 LP |
2605 | if (!c) |
2606 | return log_oom(); | |
039655a4 | 2607 | |
59fccdc5 | 2608 | LIST_PREPEND(conditions, *list, c); |
039655a4 LP |
2609 | return 0; |
2610 | } | |
2611 | ||
59fccdc5 LP |
2612 | int config_parse_unit_condition_null( |
2613 | const char *unit, | |
2614 | const char *filename, | |
2615 | unsigned line, | |
2616 | const char *section, | |
2617 | unsigned section_line, | |
2618 | const char *lvalue, | |
2619 | int ltype, | |
2620 | const char *rvalue, | |
2621 | void *data, | |
2622 | void *userdata) { | |
d257ddef | 2623 | |
59fccdc5 | 2624 | Condition **list = data, *c; |
267632f0 | 2625 | bool trigger, negate; |
d257ddef LP |
2626 | int b; |
2627 | ||
2628 | assert(filename); | |
2629 | assert(lvalue); | |
2630 | assert(rvalue); | |
2631 | assert(data); | |
2632 | ||
55dadc5c LP |
2633 | log_syntax(unit, LOG_WARNING, filename, line, 0, "%s= is deprecated, please do not use.", lvalue); |
2634 | ||
74051b9b LP |
2635 | if (isempty(rvalue)) { |
2636 | /* Empty assignment resets the list */ | |
447021aa | 2637 | *list = condition_free_list(*list); |
74051b9b LP |
2638 | return 0; |
2639 | } | |
2640 | ||
2641 | trigger = rvalue[0] == '|'; | |
2642 | if (trigger) | |
267632f0 LP |
2643 | rvalue++; |
2644 | ||
74051b9b LP |
2645 | negate = rvalue[0] == '!'; |
2646 | if (negate) | |
d257ddef LP |
2647 | rvalue++; |
2648 | ||
74051b9b LP |
2649 | b = parse_boolean(rvalue); |
2650 | if (b < 0) { | |
12ca818f | 2651 | log_syntax(unit, LOG_ERR, filename, line, b, "Failed to parse boolean value in condition, ignoring: %s", rvalue); |
d257ddef LP |
2652 | return 0; |
2653 | } | |
2654 | ||
2655 | if (!b) | |
2656 | negate = !negate; | |
2657 | ||
74051b9b LP |
2658 | c = condition_new(CONDITION_NULL, NULL, trigger, negate); |
2659 | if (!c) | |
2660 | return log_oom(); | |
d257ddef | 2661 | |
59fccdc5 | 2662 | LIST_PREPEND(conditions, *list, c); |
d257ddef LP |
2663 | return 0; |
2664 | } | |
2665 | ||
a57f7e2c LP |
2666 | int config_parse_unit_requires_mounts_for( |
2667 | const char *unit, | |
2668 | const char *filename, | |
2669 | unsigned line, | |
2670 | const char *section, | |
71a61510 | 2671 | unsigned section_line, |
a57f7e2c LP |
2672 | const char *lvalue, |
2673 | int ltype, | |
2674 | const char *rvalue, | |
2675 | void *data, | |
2676 | void *userdata) { | |
7c8fa05c | 2677 | |
063c4b1a | 2678 | const char *p = rvalue; |
7c8fa05c | 2679 | Unit *u = userdata; |
035fe294 | 2680 | int r; |
7c8fa05c LP |
2681 | |
2682 | assert(filename); | |
2683 | assert(lvalue); | |
2684 | assert(rvalue); | |
2685 | assert(data); | |
2686 | ||
063c4b1a | 2687 | for (;;) { |
744bb5b1 | 2688 | _cleanup_free_ char *word = NULL, *resolved = NULL; |
a57f7e2c | 2689 | |
4ec85141 | 2690 | r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE); |
035fe294 ZJS |
2691 | if (r == 0) |
2692 | return 0; | |
2693 | if (r == -ENOMEM) | |
a57f7e2c | 2694 | return log_oom(); |
035fe294 ZJS |
2695 | if (r < 0) { |
2696 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
2697 | "Invalid syntax, ignoring: %s", rvalue); | |
2698 | return 0; | |
2699 | } | |
7c8fa05c | 2700 | |
744bb5b1 LP |
2701 | r = unit_full_printf(u, word, &resolved); |
2702 | if (r < 0) { | |
063c4b1a | 2703 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %m", word); |
744bb5b1 LP |
2704 | continue; |
2705 | } | |
2706 | ||
2f4d31c1 YW |
2707 | r = path_simplify_and_warn(resolved, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue); |
2708 | if (r < 0) | |
2709 | continue; | |
2710 | ||
eef85c4a | 2711 | r = unit_require_mounts_for(u, resolved, UNIT_DEPENDENCY_FILE); |
a57f7e2c | 2712 | if (r < 0) { |
063c4b1a | 2713 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to add required mount '%s', ignoring: %m", resolved); |
a57f7e2c LP |
2714 | continue; |
2715 | } | |
2716 | } | |
7c8fa05c | 2717 | } |
9e372868 | 2718 | |
e8e581bf ZJS |
2719 | int config_parse_documentation(const char *unit, |
2720 | const char *filename, | |
2721 | unsigned line, | |
2722 | const char *section, | |
71a61510 | 2723 | unsigned section_line, |
e8e581bf ZJS |
2724 | const char *lvalue, |
2725 | int ltype, | |
2726 | const char *rvalue, | |
2727 | void *data, | |
2728 | void *userdata) { | |
49dbfa7b LP |
2729 | |
2730 | Unit *u = userdata; | |
2731 | int r; | |
2732 | char **a, **b; | |
2733 | ||
2734 | assert(filename); | |
2735 | assert(lvalue); | |
2736 | assert(rvalue); | |
2737 | assert(u); | |
2738 | ||
74051b9b LP |
2739 | if (isempty(rvalue)) { |
2740 | /* Empty assignment resets the list */ | |
6796073e | 2741 | u->documentation = strv_free(u->documentation); |
74051b9b LP |
2742 | return 0; |
2743 | } | |
2744 | ||
71a61510 | 2745 | r = config_parse_unit_strv_printf(unit, filename, line, section, section_line, lvalue, ltype, |
e8e581bf | 2746 | rvalue, data, userdata); |
49dbfa7b LP |
2747 | if (r < 0) |
2748 | return r; | |
2749 | ||
2750 | for (a = b = u->documentation; a && *a; a++) { | |
2751 | ||
a2e03378 | 2752 | if (documentation_url_is_valid(*a)) |
49dbfa7b LP |
2753 | *(b++) = *a; |
2754 | else { | |
12ca818f | 2755 | log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid URL, ignoring: %s", *a); |
49dbfa7b LP |
2756 | free(*a); |
2757 | } | |
2758 | } | |
f6d2d421 ZJS |
2759 | if (b) |
2760 | *b = NULL; | |
49dbfa7b LP |
2761 | |
2762 | return r; | |
2763 | } | |
2764 | ||
349cc4a5 | 2765 | #if HAVE_SECCOMP |
17df7223 LP |
2766 | int config_parse_syscall_filter( |
2767 | const char *unit, | |
2768 | const char *filename, | |
2769 | unsigned line, | |
2770 | const char *section, | |
2771 | unsigned section_line, | |
2772 | const char *lvalue, | |
2773 | int ltype, | |
2774 | const char *rvalue, | |
2775 | void *data, | |
2776 | void *userdata) { | |
2777 | ||
8351ceae | 2778 | ExecContext *c = data; |
47538b76 | 2779 | const Unit *u = userdata; |
b5fb3789 | 2780 | bool invert = false; |
8130926d | 2781 | const char *p; |
17df7223 | 2782 | int r; |
8351ceae LP |
2783 | |
2784 | assert(filename); | |
2785 | assert(lvalue); | |
2786 | assert(rvalue); | |
2787 | assert(u); | |
2788 | ||
74051b9b LP |
2789 | if (isempty(rvalue)) { |
2790 | /* Empty assignment resets the list */ | |
8cfa775f | 2791 | c->syscall_filter = hashmap_free(c->syscall_filter); |
17df7223 | 2792 | c->syscall_whitelist = false; |
74051b9b LP |
2793 | return 0; |
2794 | } | |
2795 | ||
8351ceae LP |
2796 | if (rvalue[0] == '~') { |
2797 | invert = true; | |
2798 | rvalue++; | |
2799 | } | |
2800 | ||
17df7223 | 2801 | if (!c->syscall_filter) { |
8cfa775f | 2802 | c->syscall_filter = hashmap_new(NULL); |
17df7223 LP |
2803 | if (!c->syscall_filter) |
2804 | return log_oom(); | |
2805 | ||
c0467cf3 | 2806 | if (invert) |
17df7223 LP |
2807 | /* Allow everything but the ones listed */ |
2808 | c->syscall_whitelist = false; | |
c0467cf3 | 2809 | else { |
17df7223 LP |
2810 | /* Allow nothing but the ones listed */ |
2811 | c->syscall_whitelist = true; | |
8351ceae | 2812 | |
17df7223 | 2813 | /* Accept default syscalls if we are on a whitelist */ |
2f6b9110 LP |
2814 | r = seccomp_parse_syscall_filter( |
2815 | "@default", -1, c->syscall_filter, | |
58f6ab44 ZJS |
2816 | SECCOMP_PARSE_PERMISSIVE|SECCOMP_PARSE_WHITELIST, |
2817 | unit, | |
2818 | NULL, 0); | |
201c1cc2 TM |
2819 | if (r < 0) |
2820 | return r; | |
c0467cf3 | 2821 | } |
8351ceae LP |
2822 | } |
2823 | ||
8130926d LP |
2824 | p = rvalue; |
2825 | for (;;) { | |
8cfa775f YW |
2826 | _cleanup_free_ char *word = NULL, *name = NULL; |
2827 | int num; | |
8351ceae | 2828 | |
8130926d LP |
2829 | r = extract_first_word(&p, &word, NULL, 0); |
2830 | if (r == 0) | |
063c4b1a | 2831 | return 0; |
8130926d | 2832 | if (r == -ENOMEM) |
74051b9b | 2833 | return log_oom(); |
8130926d LP |
2834 | if (r < 0) { |
2835 | log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid syntax, ignoring: %s", rvalue); | |
063c4b1a | 2836 | return 0; |
8130926d | 2837 | } |
8351ceae | 2838 | |
8cfa775f YW |
2839 | r = parse_syscall_and_errno(word, &name, &num); |
2840 | if (r < 0) { | |
2841 | log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse syscall:errno, ignoring: %s", word); | |
2842 | continue; | |
2843 | } | |
2844 | ||
58f6ab44 | 2845 | r = seccomp_parse_syscall_filter( |
acd142af LP |
2846 | name, num, c->syscall_filter, |
2847 | SECCOMP_PARSE_LOG|SECCOMP_PARSE_PERMISSIVE| | |
2848 | (invert ? SECCOMP_PARSE_INVERT : 0)| | |
2849 | (c->syscall_whitelist ? SECCOMP_PARSE_WHITELIST : 0), | |
2850 | unit, filename, line); | |
201c1cc2 TM |
2851 | if (r < 0) |
2852 | return r; | |
c0467cf3 | 2853 | } |
17df7223 LP |
2854 | } |
2855 | ||
57183d11 LP |
2856 | int config_parse_syscall_archs( |
2857 | const char *unit, | |
2858 | const char *filename, | |
2859 | unsigned line, | |
2860 | const char *section, | |
2861 | unsigned section_line, | |
2862 | const char *lvalue, | |
2863 | int ltype, | |
2864 | const char *rvalue, | |
2865 | void *data, | |
2866 | void *userdata) { | |
2867 | ||
063c4b1a | 2868 | const char *p = rvalue; |
d3b1c508 | 2869 | Set **archs = data; |
57183d11 LP |
2870 | int r; |
2871 | ||
2872 | if (isempty(rvalue)) { | |
525d3cc7 | 2873 | *archs = set_free(*archs); |
57183d11 LP |
2874 | return 0; |
2875 | } | |
2876 | ||
d5099efc | 2877 | r = set_ensure_allocated(archs, NULL); |
57183d11 LP |
2878 | if (r < 0) |
2879 | return log_oom(); | |
2880 | ||
063c4b1a | 2881 | for (;;) { |
035fe294 | 2882 | _cleanup_free_ char *word = NULL; |
57183d11 LP |
2883 | uint32_t a; |
2884 | ||
4ec85141 | 2885 | r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE); |
035fe294 ZJS |
2886 | if (r == 0) |
2887 | return 0; | |
2888 | if (r == -ENOMEM) | |
57183d11 | 2889 | return log_oom(); |
035fe294 ZJS |
2890 | if (r < 0) { |
2891 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
2892 | "Invalid syntax, ignoring: %s", rvalue); | |
2893 | return 0; | |
2894 | } | |
57183d11 | 2895 | |
035fe294 | 2896 | r = seccomp_arch_from_string(word, &a); |
57183d11 | 2897 | if (r < 0) { |
035fe294 ZJS |
2898 | log_syntax(unit, LOG_ERR, filename, line, r, |
2899 | "Failed to parse system call architecture \"%s\", ignoring: %m", word); | |
57183d11 LP |
2900 | continue; |
2901 | } | |
2902 | ||
d3b1c508 | 2903 | r = set_put(*archs, UINT32_TO_PTR(a + 1)); |
57183d11 LP |
2904 | if (r < 0) |
2905 | return log_oom(); | |
2906 | } | |
57183d11 LP |
2907 | } |
2908 | ||
17df7223 LP |
2909 | int config_parse_syscall_errno( |
2910 | const char *unit, | |
2911 | const char *filename, | |
2912 | unsigned line, | |
2913 | const char *section, | |
2914 | unsigned section_line, | |
2915 | const char *lvalue, | |
2916 | int ltype, | |
2917 | const char *rvalue, | |
2918 | void *data, | |
2919 | void *userdata) { | |
2920 | ||
2921 | ExecContext *c = data; | |
2922 | int e; | |
2923 | ||
2924 | assert(filename); | |
2925 | assert(lvalue); | |
2926 | assert(rvalue); | |
2927 | ||
2928 | if (isempty(rvalue)) { | |
2929 | /* Empty assignment resets to KILL */ | |
2930 | c->syscall_errno = 0; | |
2931 | return 0; | |
8351ceae LP |
2932 | } |
2933 | ||
3df90f24 YW |
2934 | e = parse_errno(rvalue); |
2935 | if (e <= 0) { | |
12ca818f | 2936 | log_syntax(unit, LOG_ERR, filename, line, 0, "Failed to parse error number, ignoring: %s", rvalue); |
17df7223 LP |
2937 | return 0; |
2938 | } | |
8351ceae | 2939 | |
17df7223 | 2940 | c->syscall_errno = e; |
8351ceae LP |
2941 | return 0; |
2942 | } | |
4298d0b5 LP |
2943 | |
2944 | int config_parse_address_families( | |
2945 | const char *unit, | |
2946 | const char *filename, | |
2947 | unsigned line, | |
2948 | const char *section, | |
2949 | unsigned section_line, | |
2950 | const char *lvalue, | |
2951 | int ltype, | |
2952 | const char *rvalue, | |
2953 | void *data, | |
2954 | void *userdata) { | |
2955 | ||
2956 | ExecContext *c = data; | |
4298d0b5 | 2957 | bool invert = false; |
035fe294 | 2958 | const char *p; |
4298d0b5 LP |
2959 | int r; |
2960 | ||
2961 | assert(filename); | |
2962 | assert(lvalue); | |
2963 | assert(rvalue); | |
4298d0b5 LP |
2964 | |
2965 | if (isempty(rvalue)) { | |
2966 | /* Empty assignment resets the list */ | |
525d3cc7 | 2967 | c->address_families = set_free(c->address_families); |
4298d0b5 LP |
2968 | c->address_families_whitelist = false; |
2969 | return 0; | |
2970 | } | |
2971 | ||
2972 | if (rvalue[0] == '~') { | |
2973 | invert = true; | |
2974 | rvalue++; | |
2975 | } | |
2976 | ||
2977 | if (!c->address_families) { | |
d5099efc | 2978 | c->address_families = set_new(NULL); |
4298d0b5 LP |
2979 | if (!c->address_families) |
2980 | return log_oom(); | |
2981 | ||
2982 | c->address_families_whitelist = !invert; | |
2983 | } | |
2984 | ||
035fe294 ZJS |
2985 | for (p = rvalue;;) { |
2986 | _cleanup_free_ char *word = NULL; | |
4298d0b5 LP |
2987 | int af; |
2988 | ||
4ec85141 | 2989 | r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE); |
035fe294 ZJS |
2990 | if (r == 0) |
2991 | return 0; | |
2992 | if (r == -ENOMEM) | |
4298d0b5 | 2993 | return log_oom(); |
035fe294 ZJS |
2994 | if (r < 0) { |
2995 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
2996 | "Invalid syntax, ignoring: %s", rvalue); | |
2997 | return 0; | |
2998 | } | |
4298d0b5 | 2999 | |
035fe294 | 3000 | af = af_from_name(word); |
acf4d158 YW |
3001 | if (af < 0) { |
3002 | log_syntax(unit, LOG_ERR, filename, line, af, | |
063c4b1a | 3003 | "Failed to parse address family, ignoring: %s", word); |
4298d0b5 LP |
3004 | continue; |
3005 | } | |
3006 | ||
3007 | /* If we previously wanted to forbid an address family and now | |
035fe294 | 3008 | * we want to allow it, then just remove it from the list. |
4298d0b5 LP |
3009 | */ |
3010 | if (!invert == c->address_families_whitelist) { | |
3011 | r = set_put(c->address_families, INT_TO_PTR(af)); | |
4298d0b5 LP |
3012 | if (r < 0) |
3013 | return log_oom(); | |
3014 | } else | |
3015 | set_remove(c->address_families, INT_TO_PTR(af)); | |
3016 | } | |
4298d0b5 | 3017 | } |
add00535 LP |
3018 | |
3019 | int config_parse_restrict_namespaces( | |
3020 | const char *unit, | |
3021 | const char *filename, | |
3022 | unsigned line, | |
3023 | const char *section, | |
3024 | unsigned section_line, | |
3025 | const char *lvalue, | |
3026 | int ltype, | |
3027 | const char *rvalue, | |
3028 | void *data, | |
3029 | void *userdata) { | |
3030 | ||
3031 | ExecContext *c = data; | |
aa9d574d | 3032 | unsigned long flags; |
add00535 LP |
3033 | bool invert = false; |
3034 | int r; | |
3035 | ||
3036 | if (isempty(rvalue)) { | |
3037 | /* Reset to the default. */ | |
aa9d574d YW |
3038 | c->restrict_namespaces = NAMESPACE_FLAGS_INITIAL; |
3039 | return 0; | |
3040 | } | |
3041 | ||
3042 | /* Boolean parameter ignores the previous settings */ | |
3043 | r = parse_boolean(rvalue); | |
3044 | if (r > 0) { | |
3045 | c->restrict_namespaces = 0; | |
3046 | return 0; | |
3047 | } else if (r == 0) { | |
add00535 LP |
3048 | c->restrict_namespaces = NAMESPACE_FLAGS_ALL; |
3049 | return 0; | |
3050 | } | |
3051 | ||
3052 | if (rvalue[0] == '~') { | |
3053 | invert = true; | |
3054 | rvalue++; | |
3055 | } | |
3056 | ||
aa9d574d YW |
3057 | /* Not a boolean argument, in this case it's a list of namespace types. */ |
3058 | r = namespace_flags_from_string(rvalue, &flags); | |
3059 | if (r < 0) { | |
3060 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse namespace type string, ignoring: %s", rvalue); | |
3061 | return 0; | |
add00535 LP |
3062 | } |
3063 | ||
aa9d574d YW |
3064 | if (c->restrict_namespaces == NAMESPACE_FLAGS_INITIAL) |
3065 | /* Initial assignment. Just set the value. */ | |
3066 | c->restrict_namespaces = invert ? (~flags) & NAMESPACE_FLAGS_ALL : flags; | |
3067 | else | |
3068 | /* Merge the value with the previous one. */ | |
3069 | SET_FLAG(c->restrict_namespaces, flags, !invert); | |
add00535 LP |
3070 | |
3071 | return 0; | |
3072 | } | |
c0467cf3 | 3073 | #endif |
8351ceae | 3074 | |
a016b922 LP |
3075 | int config_parse_unit_slice( |
3076 | const char *unit, | |
3077 | const char *filename, | |
3078 | unsigned line, | |
3079 | const char *section, | |
71a61510 | 3080 | unsigned section_line, |
a016b922 LP |
3081 | const char *lvalue, |
3082 | int ltype, | |
3083 | const char *rvalue, | |
3084 | void *data, | |
3085 | void *userdata) { | |
3086 | ||
063c4b1a | 3087 | _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; |
a016b922 | 3088 | _cleanup_free_ char *k = NULL; |
d79200e2 | 3089 | Unit *u = userdata, *slice = NULL; |
a016b922 LP |
3090 | int r; |
3091 | ||
3092 | assert(filename); | |
3093 | assert(lvalue); | |
3094 | assert(rvalue); | |
3095 | assert(u); | |
3096 | ||
19f6d710 | 3097 | r = unit_name_printf(u, rvalue, &k); |
d79200e2 | 3098 | if (r < 0) { |
063c4b1a | 3099 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue); |
d79200e2 | 3100 | return 0; |
19f6d710 | 3101 | } |
a016b922 | 3102 | |
063c4b1a | 3103 | r = manager_load_unit(u->manager, k, NULL, &error, &slice); |
a016b922 | 3104 | if (r < 0) { |
063c4b1a | 3105 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to load slice unit %s, ignoring: %s", k, bus_error_message(&error, r)); |
a016b922 LP |
3106 | return 0; |
3107 | } | |
3108 | ||
d79200e2 LP |
3109 | r = unit_set_slice(u, slice); |
3110 | if (r < 0) { | |
063c4b1a | 3111 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to assign slice %s to unit %s, ignoring: %m", slice->id, u->id); |
a016b922 LP |
3112 | return 0; |
3113 | } | |
3114 | ||
a016b922 LP |
3115 | return 0; |
3116 | } | |
3117 | ||
b2f8b02e LP |
3118 | int config_parse_cpu_quota( |
3119 | const char *unit, | |
3120 | const char *filename, | |
3121 | unsigned line, | |
3122 | const char *section, | |
3123 | unsigned section_line, | |
3124 | const char *lvalue, | |
3125 | int ltype, | |
3126 | const char *rvalue, | |
3127 | void *data, | |
3128 | void *userdata) { | |
3129 | ||
3130 | CGroupContext *c = data; | |
9184ca48 | 3131 | int r; |
b2f8b02e LP |
3132 | |
3133 | assert(filename); | |
3134 | assert(lvalue); | |
3135 | assert(rvalue); | |
3136 | ||
3137 | if (isempty(rvalue)) { | |
3a43da28 | 3138 | c->cpu_quota_per_sec_usec = USEC_INFINITY; |
b2f8b02e LP |
3139 | return 0; |
3140 | } | |
3141 | ||
f806dfd3 | 3142 | r = parse_permille_unbounded(rvalue); |
9184ca48 | 3143 | if (r <= 0) { |
063c4b1a | 3144 | log_syntax(unit, LOG_ERR, filename, line, r, "Invalid CPU quota '%s', ignoring.", rvalue); |
9a054909 | 3145 | return 0; |
b2f8b02e LP |
3146 | } |
3147 | ||
f806dfd3 | 3148 | c->cpu_quota_per_sec_usec = ((usec_t) r * USEC_PER_SEC) / 1000U; |
b2f8b02e LP |
3149 | return 0; |
3150 | } | |
3151 | ||
047f5d63 PH |
3152 | int config_parse_cpuset_cpus( |
3153 | const char *unit, | |
3154 | const char *filename, | |
3155 | unsigned line, | |
3156 | const char *section, | |
3157 | unsigned section_line, | |
3158 | const char *lvalue, | |
3159 | int ltype, | |
3160 | const char *rvalue, | |
3161 | void *data, | |
3162 | void *userdata) { | |
3163 | ||
3164 | CGroupContext *c = data; | |
3165 | ||
3166 | (void) parse_cpu_set_extend(rvalue, &c->cpuset_cpus, true, unit, filename, line, lvalue); | |
3167 | ||
3168 | return 0; | |
3169 | } | |
3170 | ||
3171 | int config_parse_cpuset_mems( | |
3172 | const char *unit, | |
3173 | const char *filename, | |
3174 | unsigned line, | |
3175 | const char *section, | |
3176 | unsigned section_line, | |
3177 | const char *lvalue, | |
3178 | int ltype, | |
3179 | const char *rvalue, | |
3180 | void *data, | |
3181 | void *userdata) { | |
3182 | ||
3183 | CGroupContext *c = data; | |
3184 | ||
3185 | (void) parse_cpu_set_extend(rvalue, &c->cpuset_mems, true, unit, filename, line, lvalue); | |
3186 | ||
3187 | return 0; | |
3188 | } | |
3189 | ||
4ad49000 LP |
3190 | int config_parse_memory_limit( |
3191 | const char *unit, | |
3192 | const char *filename, | |
3193 | unsigned line, | |
3194 | const char *section, | |
71a61510 | 3195 | unsigned section_line, |
4ad49000 LP |
3196 | const char *lvalue, |
3197 | int ltype, | |
3198 | const char *rvalue, | |
3199 | void *data, | |
3200 | void *userdata) { | |
3201 | ||
3202 | CGroupContext *c = data; | |
da4d897e | 3203 | uint64_t bytes = CGROUP_LIMIT_MAX; |
4ad49000 LP |
3204 | int r; |
3205 | ||
e57c9ce1 | 3206 | if (!isempty(rvalue) && !streq(rvalue, "infinity")) { |
875ae566 | 3207 | |
f806dfd3 | 3208 | r = parse_permille(rvalue); |
875ae566 LP |
3209 | if (r < 0) { |
3210 | r = parse_size(rvalue, 1024, &bytes); | |
3211 | if (r < 0) { | |
063c4b1a | 3212 | log_syntax(unit, LOG_ERR, filename, line, r, "Invalid memory limit '%s', ignoring: %m", rvalue); |
875ae566 LP |
3213 | return 0; |
3214 | } | |
3215 | } else | |
f806dfd3 | 3216 | bytes = physical_memory_scale(r, 1000U); |
875ae566 | 3217 | |
906bdbf5 | 3218 | if (bytes >= UINT64_MAX || |
22bf131b | 3219 | (bytes <= 0 && !STR_IN_SET(lvalue, "MemorySwapMax", "MemoryLow", "MemoryMin", "DefaultMemoryLow", "DefaultMemoryMin"))) { |
063c4b1a | 3220 | log_syntax(unit, LOG_ERR, filename, line, 0, "Memory limit '%s' out of range, ignoring.", rvalue); |
da4d897e TH |
3221 | return 0; |
3222 | } | |
4ad49000 LP |
3223 | } |
3224 | ||
c52db42b CD |
3225 | if (streq(lvalue, "DefaultMemoryLow")) { |
3226 | c->default_memory_low_set = true; | |
3227 | if (isempty(rvalue)) | |
3228 | c->default_memory_low = CGROUP_LIMIT_MIN; | |
3229 | else | |
3230 | c->default_memory_low = bytes; | |
7ad5439e CD |
3231 | } else if (streq(lvalue, "DefaultMemoryMin")) { |
3232 | c->default_memory_min_set = true; | |
3233 | if (isempty(rvalue)) | |
3234 | c->default_memory_min = CGROUP_LIMIT_MIN; | |
3235 | else | |
3236 | c->default_memory_min = bytes; | |
3237 | } else if (streq(lvalue, "MemoryMin")) { | |
48422635 | 3238 | c->memory_min = bytes; |
7ad5439e CD |
3239 | c->memory_min_set = true; |
3240 | } else if (streq(lvalue, "MemoryLow")) { | |
da4d897e | 3241 | c->memory_low = bytes; |
c52db42b CD |
3242 | c->memory_low_set = true; |
3243 | } else if (streq(lvalue, "MemoryHigh")) | |
da4d897e TH |
3244 | c->memory_high = bytes; |
3245 | else if (streq(lvalue, "MemoryMax")) | |
3246 | c->memory_max = bytes; | |
96e131ea WC |
3247 | else if (streq(lvalue, "MemorySwapMax")) |
3248 | c->memory_swap_max = bytes; | |
3249 | else if (streq(lvalue, "MemoryLimit")) | |
da4d897e | 3250 | c->memory_limit = bytes; |
96e131ea WC |
3251 | else |
3252 | return -EINVAL; | |
4ad49000 | 3253 | |
4ad49000 LP |
3254 | return 0; |
3255 | } | |
3256 | ||
03a7b521 LP |
3257 | int config_parse_tasks_max( |
3258 | const char *unit, | |
3259 | const char *filename, | |
3260 | unsigned line, | |
3261 | const char *section, | |
3262 | unsigned section_line, | |
3263 | const char *lvalue, | |
3264 | int ltype, | |
3265 | const char *rvalue, | |
3266 | void *data, | |
3267 | void *userdata) { | |
3268 | ||
f5058264 | 3269 | uint64_t *tasks_max = data, v; |
47538b76 | 3270 | const Unit *u = userdata; |
03a7b521 LP |
3271 | int r; |
3272 | ||
f5058264 | 3273 | if (isempty(rvalue)) { |
958b8c7b | 3274 | *tasks_max = u ? u->manager->default_tasks_max : UINT64_MAX; |
f5058264 TH |
3275 | return 0; |
3276 | } | |
3277 | ||
3278 | if (streq(rvalue, "infinity")) { | |
3279 | *tasks_max = CGROUP_LIMIT_MAX; | |
03a7b521 LP |
3280 | return 0; |
3281 | } | |
3282 | ||
f806dfd3 | 3283 | r = parse_permille(rvalue); |
83f8e808 | 3284 | if (r < 0) { |
f5058264 | 3285 | r = safe_atou64(rvalue, &v); |
83f8e808 | 3286 | if (r < 0) { |
063c4b1a | 3287 | log_syntax(unit, LOG_ERR, filename, line, r, "Invalid maximum tasks value '%s', ignoring: %m", rvalue); |
83f8e808 LP |
3288 | return 0; |
3289 | } | |
3290 | } else | |
f806dfd3 | 3291 | v = system_tasks_max_scale(r, 1000U); |
83f8e808 | 3292 | |
f5058264 | 3293 | if (v <= 0 || v >= UINT64_MAX) { |
063c4b1a | 3294 | log_syntax(unit, LOG_ERR, filename, line, 0, "Maximum tasks value '%s' out of range, ignoring.", rvalue); |
03a7b521 LP |
3295 | return 0; |
3296 | } | |
3297 | ||
f5058264 | 3298 | *tasks_max = v; |
03a7b521 LP |
3299 | return 0; |
3300 | } | |
3301 | ||
02638280 LP |
3302 | int config_parse_delegate( |
3303 | const char *unit, | |
3304 | const char *filename, | |
3305 | unsigned line, | |
3306 | const char *section, | |
3307 | unsigned section_line, | |
3308 | const char *lvalue, | |
3309 | int ltype, | |
3310 | const char *rvalue, | |
3311 | void *data, | |
3312 | void *userdata) { | |
3313 | ||
3314 | CGroupContext *c = data; | |
ecae73d7 | 3315 | UnitType t; |
02638280 LP |
3316 | int r; |
3317 | ||
ecae73d7 ZJS |
3318 | t = unit_name_to_type(unit); |
3319 | assert(t != _UNIT_TYPE_INVALID); | |
3320 | ||
3321 | if (!unit_vtable[t]->can_delegate) { | |
3322 | log_syntax(unit, LOG_ERR, filename, line, 0, "Delegate= setting not supported for this unit type, ignoring."); | |
3323 | return 0; | |
3324 | } | |
3325 | ||
02638280 LP |
3326 | /* We either accept a boolean value, which may be used to turn on delegation for all controllers, or turn it |
3327 | * off for all. Or it takes a list of controller names, in which case we add the specified controllers to the | |
3328 | * mask to delegate. */ | |
3329 | ||
1bdfc7b9 | 3330 | if (isempty(rvalue)) { |
d48013f8 YW |
3331 | /* An empty string resets controllers and set Delegate=yes. */ |
3332 | c->delegate = true; | |
1bdfc7b9 YW |
3333 | c->delegate_controllers = 0; |
3334 | return 0; | |
3335 | } | |
3336 | ||
02638280 LP |
3337 | r = parse_boolean(rvalue); |
3338 | if (r < 0) { | |
3339 | const char *p = rvalue; | |
3340 | CGroupMask mask = 0; | |
3341 | ||
3342 | for (;;) { | |
3343 | _cleanup_free_ char *word = NULL; | |
3344 | CGroupController cc; | |
3345 | ||
4ec85141 | 3346 | r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE); |
02638280 LP |
3347 | if (r == 0) |
3348 | break; | |
3349 | if (r == -ENOMEM) | |
3350 | return log_oom(); | |
3351 | if (r < 0) { | |
3352 | log_syntax(unit, LOG_ERR, filename, line, r, "Invalid syntax, ignoring: %s", rvalue); | |
ff1b8455 | 3353 | return 0; |
02638280 LP |
3354 | } |
3355 | ||
3356 | cc = cgroup_controller_from_string(word); | |
3357 | if (cc < 0) { | |
063c4b1a | 3358 | log_syntax(unit, LOG_ERR, filename, line, r, "Invalid controller name '%s', ignoring", word); |
02638280 LP |
3359 | continue; |
3360 | } | |
3361 | ||
3362 | mask |= CGROUP_CONTROLLER_TO_MASK(cc); | |
3363 | } | |
3364 | ||
3365 | c->delegate = true; | |
3366 | c->delegate_controllers |= mask; | |
3367 | ||
3368 | } else if (r > 0) { | |
3369 | c->delegate = true; | |
3370 | c->delegate_controllers = _CGROUP_MASK_ALL; | |
3371 | } else { | |
3372 | c->delegate = false; | |
3373 | c->delegate_controllers = 0; | |
3374 | } | |
3375 | ||
3376 | return 0; | |
3377 | } | |
3378 | ||
4ad49000 LP |
3379 | int config_parse_device_allow( |
3380 | const char *unit, | |
3381 | const char *filename, | |
3382 | unsigned line, | |
3383 | const char *section, | |
71a61510 | 3384 | unsigned section_line, |
4ad49000 LP |
3385 | const char *lvalue, |
3386 | int ltype, | |
3387 | const char *rvalue, | |
3388 | void *data, | |
3389 | void *userdata) { | |
3390 | ||
c9f620bf | 3391 | _cleanup_free_ char *path = NULL, *resolved = NULL; |
4ad49000 | 3392 | CGroupContext *c = data; |
c9f620bf | 3393 | const char *p = rvalue; |
1116e14c | 3394 | int r; |
4ad49000 LP |
3395 | |
3396 | if (isempty(rvalue)) { | |
3397 | while (c->device_allow) | |
3398 | cgroup_context_free_device_allow(c, c->device_allow); | |
3399 | ||
3400 | return 0; | |
3401 | } | |
3402 | ||
4ec85141 | 3403 | r = extract_first_word(&p, &path, NULL, EXTRACT_UNQUOTE); |
c9f620bf YW |
3404 | if (r == -ENOMEM) |
3405 | return log_oom(); | |
508f63b4 | 3406 | if (r < 0) { |
1116e14c | 3407 | log_syntax(unit, LOG_WARNING, filename, line, r, |
c9f620bf YW |
3408 | "Invalid syntax, ignoring: %s", rvalue); |
3409 | return 0; | |
3410 | } | |
3411 | if (r == 0) { | |
3412 | log_syntax(unit, LOG_WARNING, filename, line, 0, | |
3413 | "Failed to extract device path and rights from '%s', ignoring.", rvalue); | |
20d52ab6 | 3414 | return 0; |
1116e14c NBS |
3415 | } |
3416 | ||
c9f620bf YW |
3417 | r = unit_full_printf(userdata, path, &resolved); |
3418 | if (r < 0) { | |
3419 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
3420 | "Failed to resolve unit specifiers in '%s', ignoring: %m", path); | |
4ad49000 LP |
3421 | return 0; |
3422 | } | |
3423 | ||
49fe5c09 | 3424 | if (!STARTSWITH_SET(resolved, "block-", "char-")) { |
2f4d31c1 | 3425 | |
57e84e75 LP |
3426 | r = path_simplify_and_warn(resolved, 0, unit, filename, line, lvalue); |
3427 | if (r < 0) | |
3428 | return 0; | |
3429 | ||
3430 | if (!valid_device_node_path(resolved)) { | |
3431 | log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid device node path '%s', ignoring.", resolved); | |
3432 | return 0; | |
3433 | } | |
c9f620bf | 3434 | } |
4ad49000 | 3435 | |
c9f620bf YW |
3436 | if (!isempty(p) && !in_charset(p, "rwm")) { |
3437 | log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid device rights '%s', ignoring.", p); | |
4ad49000 LP |
3438 | return 0; |
3439 | } | |
3440 | ||
fd870bac | 3441 | return cgroup_add_device_allow(c, resolved, p); |
4ad49000 LP |
3442 | } |
3443 | ||
13c31542 TH |
3444 | int config_parse_io_device_weight( |
3445 | const char *unit, | |
3446 | const char *filename, | |
3447 | unsigned line, | |
3448 | const char *section, | |
3449 | unsigned section_line, | |
3450 | const char *lvalue, | |
3451 | int ltype, | |
3452 | const char *rvalue, | |
3453 | void *data, | |
3454 | void *userdata) { | |
3455 | ||
c9f620bf | 3456 | _cleanup_free_ char *path = NULL, *resolved = NULL; |
13c31542 TH |
3457 | CGroupIODeviceWeight *w; |
3458 | CGroupContext *c = data; | |
c9f620bf | 3459 | const char *p = rvalue; |
13c31542 | 3460 | uint64_t u; |
13c31542 TH |
3461 | int r; |
3462 | ||
3463 | assert(filename); | |
3464 | assert(lvalue); | |
3465 | assert(rvalue); | |
3466 | ||
3467 | if (isempty(rvalue)) { | |
3468 | while (c->io_device_weights) | |
3469 | cgroup_context_free_io_device_weight(c, c->io_device_weights); | |
3470 | ||
3471 | return 0; | |
3472 | } | |
3473 | ||
4ec85141 | 3474 | r = extract_first_word(&p, &path, NULL, EXTRACT_UNQUOTE); |
c9f620bf YW |
3475 | if (r == -ENOMEM) |
3476 | return log_oom(); | |
3477 | if (r < 0) { | |
3478 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
3479 | "Invalid syntax, ignoring: %s", rvalue); | |
3480 | return 0; | |
3481 | } | |
3482 | if (r == 0 || isempty(p)) { | |
3483 | log_syntax(unit, LOG_WARNING, filename, line, 0, | |
3484 | "Failed to extract device path and weight from '%s', ignoring.", rvalue); | |
13c31542 TH |
3485 | return 0; |
3486 | } | |
3487 | ||
c9f620bf YW |
3488 | r = unit_full_printf(userdata, path, &resolved); |
3489 | if (r < 0) { | |
3490 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
3491 | "Failed to resolve unit specifiers in '%s', ignoring: %m", path); | |
3492 | return 0; | |
3493 | } | |
13c31542 | 3494 | |
2f4d31c1 YW |
3495 | r = path_simplify_and_warn(resolved, 0, unit, filename, line, lvalue); |
3496 | if (r < 0) | |
3497 | return 0; | |
3498 | ||
c9f620bf | 3499 | r = cg_weight_parse(p, &u); |
13c31542 | 3500 | if (r < 0) { |
c9f620bf | 3501 | log_syntax(unit, LOG_ERR, filename, line, r, "IO weight '%s' invalid, ignoring: %m", p); |
13c31542 TH |
3502 | return 0; |
3503 | } | |
3504 | ||
3505 | assert(u != CGROUP_WEIGHT_INVALID); | |
3506 | ||
3507 | w = new0(CGroupIODeviceWeight, 1); | |
3508 | if (!w) | |
3509 | return log_oom(); | |
3510 | ||
c9f620bf | 3511 | w->path = TAKE_PTR(resolved); |
13c31542 TH |
3512 | w->weight = u; |
3513 | ||
3514 | LIST_PREPEND(device_weights, c->io_device_weights, w); | |
3515 | return 0; | |
3516 | } | |
3517 | ||
6ae4283c TH |
3518 | int config_parse_io_device_latency( |
3519 | const char *unit, | |
3520 | const char *filename, | |
3521 | unsigned line, | |
3522 | const char *section, | |
3523 | unsigned section_line, | |
3524 | const char *lvalue, | |
3525 | int ltype, | |
3526 | const char *rvalue, | |
3527 | void *data, | |
3528 | void *userdata) { | |
3529 | ||
3530 | _cleanup_free_ char *path = NULL, *resolved = NULL; | |
3531 | CGroupIODeviceLatency *l; | |
3532 | CGroupContext *c = data; | |
3533 | const char *p = rvalue; | |
3534 | usec_t usec; | |
3535 | int r; | |
3536 | ||
3537 | assert(filename); | |
3538 | assert(lvalue); | |
3539 | assert(rvalue); | |
3540 | ||
3541 | if (isempty(rvalue)) { | |
3542 | while (c->io_device_latencies) | |
3543 | cgroup_context_free_io_device_latency(c, c->io_device_latencies); | |
3544 | ||
3545 | return 0; | |
3546 | } | |
3547 | ||
4ec85141 | 3548 | r = extract_first_word(&p, &path, NULL, EXTRACT_UNQUOTE); |
6ae4283c TH |
3549 | if (r == -ENOMEM) |
3550 | return log_oom(); | |
3551 | if (r < 0) { | |
3552 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
3553 | "Invalid syntax, ignoring: %s", rvalue); | |
3554 | return 0; | |
3555 | } | |
3556 | if (r == 0 || isempty(p)) { | |
3557 | log_syntax(unit, LOG_WARNING, filename, line, 0, | |
3558 | "Failed to extract device path and latency from '%s', ignoring.", rvalue); | |
3559 | return 0; | |
3560 | } | |
3561 | ||
3562 | r = unit_full_printf(userdata, path, &resolved); | |
3563 | if (r < 0) { | |
3564 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
3565 | "Failed to resolve unit specifiers in '%s', ignoring: %m", path); | |
3566 | return 0; | |
3567 | } | |
3568 | ||
3569 | r = path_simplify_and_warn(resolved, 0, unit, filename, line, lvalue); | |
3570 | if (r < 0) | |
3571 | return 0; | |
3572 | ||
3573 | if (parse_sec(p, &usec) < 0) { | |
3574 | log_syntax(unit, LOG_ERR, filename, line, 0, "Failed to parse timer value, ignoring: %s", p); | |
3575 | return 0; | |
3576 | } | |
3577 | ||
3578 | l = new0(CGroupIODeviceLatency, 1); | |
3579 | if (!l) | |
3580 | return log_oom(); | |
3581 | ||
3582 | l->path = TAKE_PTR(resolved); | |
3583 | l->target_usec = usec; | |
3584 | ||
3585 | LIST_PREPEND(device_latencies, c->io_device_latencies, l); | |
3586 | return 0; | |
3587 | } | |
3588 | ||
13c31542 TH |
3589 | int config_parse_io_limit( |
3590 | const char *unit, | |
3591 | const char *filename, | |
3592 | unsigned line, | |
3593 | const char *section, | |
3594 | unsigned section_line, | |
3595 | const char *lvalue, | |
3596 | int ltype, | |
3597 | const char *rvalue, | |
3598 | void *data, | |
3599 | void *userdata) { | |
3600 | ||
c9f620bf | 3601 | _cleanup_free_ char *path = NULL, *resolved = NULL; |
13c31542 TH |
3602 | CGroupIODeviceLimit *l = NULL, *t; |
3603 | CGroupContext *c = data; | |
9be57249 | 3604 | CGroupIOLimitType type; |
c9f620bf | 3605 | const char *p = rvalue; |
13c31542 | 3606 | uint64_t num; |
13c31542 TH |
3607 | int r; |
3608 | ||
3609 | assert(filename); | |
3610 | assert(lvalue); | |
3611 | assert(rvalue); | |
3612 | ||
9be57249 TH |
3613 | type = cgroup_io_limit_type_from_string(lvalue); |
3614 | assert(type >= 0); | |
13c31542 TH |
3615 | |
3616 | if (isempty(rvalue)) { | |
3617 | LIST_FOREACH(device_limits, l, c->io_device_limits) | |
9be57249 | 3618 | l->limits[type] = cgroup_io_limit_defaults[type]; |
13c31542 TH |
3619 | return 0; |
3620 | } | |
3621 | ||
4ec85141 | 3622 | r = extract_first_word(&p, &path, NULL, EXTRACT_UNQUOTE); |
c9f620bf YW |
3623 | if (r == -ENOMEM) |
3624 | return log_oom(); | |
3625 | if (r < 0) { | |
3626 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
3627 | "Invalid syntax, ignoring: %s", rvalue); | |
3628 | return 0; | |
3629 | } | |
3630 | if (r == 0 || isempty(p)) { | |
3631 | log_syntax(unit, LOG_WARNING, filename, line, 0, | |
3632 | "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue); | |
13c31542 TH |
3633 | return 0; |
3634 | } | |
3635 | ||
c9f620bf YW |
3636 | r = unit_full_printf(userdata, path, &resolved); |
3637 | if (r < 0) { | |
3638 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
3639 | "Failed to resolve unit specifiers in '%s', ignoring: %m", path); | |
3640 | return 0; | |
3641 | } | |
13c31542 | 3642 | |
2f4d31c1 YW |
3643 | r = path_simplify_and_warn(resolved, 0, unit, filename, line, lvalue); |
3644 | if (r < 0) | |
3645 | return 0; | |
3646 | ||
9d5e9b4a | 3647 | if (streq("infinity", p)) |
13c31542 | 3648 | num = CGROUP_LIMIT_MAX; |
9d5e9b4a | 3649 | else { |
c9f620bf | 3650 | r = parse_size(p, 1000, &num); |
13c31542 | 3651 | if (r < 0 || num <= 0) { |
c9f620bf | 3652 | log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid IO limit '%s', ignoring.", p); |
13c31542 TH |
3653 | return 0; |
3654 | } | |
3655 | } | |
3656 | ||
3657 | LIST_FOREACH(device_limits, t, c->io_device_limits) { | |
c9f620bf | 3658 | if (path_equal(resolved, t->path)) { |
13c31542 TH |
3659 | l = t; |
3660 | break; | |
3661 | } | |
3662 | } | |
3663 | ||
3664 | if (!l) { | |
9be57249 TH |
3665 | CGroupIOLimitType ttype; |
3666 | ||
13c31542 TH |
3667 | l = new0(CGroupIODeviceLimit, 1); |
3668 | if (!l) | |
3669 | return log_oom(); | |
3670 | ||
c9f620bf | 3671 | l->path = TAKE_PTR(resolved); |
9be57249 TH |
3672 | for (ttype = 0; ttype < _CGROUP_IO_LIMIT_TYPE_MAX; ttype++) |
3673 | l->limits[ttype] = cgroup_io_limit_defaults[ttype]; | |
13c31542 TH |
3674 | |
3675 | LIST_PREPEND(device_limits, c->io_device_limits, l); | |
3676 | } | |
3677 | ||
9be57249 | 3678 | l->limits[type] = num; |
13c31542 TH |
3679 | |
3680 | return 0; | |
3681 | } | |
3682 | ||
8e7076ca LP |
3683 | int config_parse_blockio_device_weight( |
3684 | const char *unit, | |
3685 | const char *filename, | |
3686 | unsigned line, | |
3687 | const char *section, | |
71a61510 | 3688 | unsigned section_line, |
8e7076ca LP |
3689 | const char *lvalue, |
3690 | int ltype, | |
3691 | const char *rvalue, | |
3692 | void *data, | |
3693 | void *userdata) { | |
3694 | ||
c9f620bf | 3695 | _cleanup_free_ char *path = NULL, *resolved = NULL; |
8e7076ca | 3696 | CGroupBlockIODeviceWeight *w; |
4ad49000 | 3697 | CGroupContext *c = data; |
c9f620bf | 3698 | const char *p = rvalue; |
d53d9474 | 3699 | uint64_t u; |
4ad49000 LP |
3700 | int r; |
3701 | ||
3702 | assert(filename); | |
3703 | assert(lvalue); | |
3704 | assert(rvalue); | |
3705 | ||
3706 | if (isempty(rvalue)) { | |
4ad49000 LP |
3707 | while (c->blockio_device_weights) |
3708 | cgroup_context_free_blockio_device_weight(c, c->blockio_device_weights); | |
3709 | ||
3710 | return 0; | |
3711 | } | |
3712 | ||
4ec85141 | 3713 | r = extract_first_word(&p, &path, NULL, EXTRACT_UNQUOTE); |
c9f620bf YW |
3714 | if (r == -ENOMEM) |
3715 | return log_oom(); | |
3716 | if (r < 0) { | |
3717 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
3718 | "Invalid syntax, ignoring: %s", rvalue); | |
3719 | return 0; | |
3720 | } | |
3721 | if (r == 0 || isempty(p)) { | |
3722 | log_syntax(unit, LOG_WARNING, filename, line, 0, | |
3723 | "Failed to extract device node and weight from '%s', ignoring.", rvalue); | |
8e7076ca LP |
3724 | return 0; |
3725 | } | |
4ad49000 | 3726 | |
c9f620bf YW |
3727 | r = unit_full_printf(userdata, path, &resolved); |
3728 | if (r < 0) { | |
3729 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
3730 | "Failed to resolve unit specifiers in '%s', ignoring: %m", path); | |
3731 | return 0; | |
3732 | } | |
4ad49000 | 3733 | |
2f4d31c1 YW |
3734 | r = path_simplify_and_warn(resolved, 0, unit, filename, line, lvalue); |
3735 | if (r < 0) | |
3736 | return 0; | |
3737 | ||
c9f620bf | 3738 | r = cg_blkio_weight_parse(p, &u); |
d53d9474 | 3739 | if (r < 0) { |
c9f620bf | 3740 | log_syntax(unit, LOG_ERR, filename, line, r, "Invalid block IO weight '%s', ignoring: %m", p); |
4ad49000 LP |
3741 | return 0; |
3742 | } | |
3743 | ||
d53d9474 LP |
3744 | assert(u != CGROUP_BLKIO_WEIGHT_INVALID); |
3745 | ||
8e7076ca LP |
3746 | w = new0(CGroupBlockIODeviceWeight, 1); |
3747 | if (!w) | |
3748 | return log_oom(); | |
4ad49000 | 3749 | |
c9f620bf | 3750 | w->path = TAKE_PTR(resolved); |
d53d9474 | 3751 | w->weight = u; |
4ad49000 | 3752 | |
71fda00f | 3753 | LIST_PREPEND(device_weights, c->blockio_device_weights, w); |
4ad49000 LP |
3754 | return 0; |
3755 | } | |
3756 | ||
3757 | int config_parse_blockio_bandwidth( | |
3758 | const char *unit, | |
3759 | const char *filename, | |
3760 | unsigned line, | |
3761 | const char *section, | |
71a61510 | 3762 | unsigned section_line, |
4ad49000 LP |
3763 | const char *lvalue, |
3764 | int ltype, | |
3765 | const char *rvalue, | |
3766 | void *data, | |
3767 | void *userdata) { | |
3768 | ||
c9f620bf | 3769 | _cleanup_free_ char *path = NULL, *resolved = NULL; |
979d0311 | 3770 | CGroupBlockIODeviceBandwidth *b = NULL, *t; |
4ad49000 | 3771 | CGroupContext *c = data; |
c9f620bf | 3772 | const char *p = rvalue; |
59f448cf | 3773 | uint64_t bytes; |
47c0980d | 3774 | bool read; |
4ad49000 LP |
3775 | int r; |
3776 | ||
3777 | assert(filename); | |
3778 | assert(lvalue); | |
3779 | assert(rvalue); | |
3780 | ||
47c0980d G |
3781 | read = streq("BlockIOReadBandwidth", lvalue); |
3782 | ||
4ad49000 | 3783 | if (isempty(rvalue)) { |
979d0311 TH |
3784 | LIST_FOREACH(device_bandwidths, b, c->blockio_device_bandwidths) { |
3785 | b->rbps = CGROUP_LIMIT_MAX; | |
3786 | b->wbps = CGROUP_LIMIT_MAX; | |
3787 | } | |
4ad49000 LP |
3788 | return 0; |
3789 | } | |
3790 | ||
4ec85141 | 3791 | r = extract_first_word(&p, &path, NULL, EXTRACT_UNQUOTE); |
c9f620bf YW |
3792 | if (r == -ENOMEM) |
3793 | return log_oom(); | |
3794 | if (r < 0) { | |
3795 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
3796 | "Invalid syntax, ignoring: %s", rvalue); | |
3797 | return 0; | |
3798 | } | |
3799 | if (r == 0 || isempty(p)) { | |
3800 | log_syntax(unit, LOG_WARNING, filename, line, 0, | |
3801 | "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue); | |
4ad49000 LP |
3802 | return 0; |
3803 | } | |
3804 | ||
c9f620bf YW |
3805 | r = unit_full_printf(userdata, path, &resolved); |
3806 | if (r < 0) { | |
3807 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
3808 | "Failed to resolve unit specifiers in '%s', ignoring: %m", path); | |
3809 | return 0; | |
3810 | } | |
4ad49000 | 3811 | |
2f4d31c1 YW |
3812 | r = path_simplify_and_warn(resolved, 0, unit, filename, line, lvalue); |
3813 | if (r < 0) | |
3814 | return 0; | |
3815 | ||
c9f620bf | 3816 | r = parse_size(p, 1000, &bytes); |
4ad49000 | 3817 | if (r < 0 || bytes <= 0) { |
c9f620bf | 3818 | log_syntax(unit, LOG_ERR, filename, line, r, "Invalid Block IO Bandwidth '%s', ignoring.", p); |
4ad49000 LP |
3819 | return 0; |
3820 | } | |
3821 | ||
979d0311 | 3822 | LIST_FOREACH(device_bandwidths, t, c->blockio_device_bandwidths) { |
c9f620bf | 3823 | if (path_equal(resolved, t->path)) { |
979d0311 TH |
3824 | b = t; |
3825 | break; | |
3826 | } | |
3827 | } | |
4ad49000 | 3828 | |
979d0311 TH |
3829 | if (!t) { |
3830 | b = new0(CGroupBlockIODeviceBandwidth, 1); | |
3831 | if (!b) | |
3832 | return log_oom(); | |
3833 | ||
c9f620bf | 3834 | b->path = TAKE_PTR(resolved); |
979d0311 TH |
3835 | b->rbps = CGROUP_LIMIT_MAX; |
3836 | b->wbps = CGROUP_LIMIT_MAX; | |
3837 | ||
3838 | LIST_PREPEND(device_bandwidths, c->blockio_device_bandwidths, b); | |
3839 | } | |
4ad49000 | 3840 | |
979d0311 TH |
3841 | if (read) |
3842 | b->rbps = bytes; | |
3843 | else | |
3844 | b->wbps = bytes; | |
4ad49000 LP |
3845 | |
3846 | return 0; | |
3847 | } | |
3848 | ||
d420282b LP |
3849 | int config_parse_job_mode_isolate( |
3850 | const char *unit, | |
3851 | const char *filename, | |
3852 | unsigned line, | |
3853 | const char *section, | |
3854 | unsigned section_line, | |
3855 | const char *lvalue, | |
3856 | int ltype, | |
3857 | const char *rvalue, | |
3858 | void *data, | |
3859 | void *userdata) { | |
3860 | ||
3861 | JobMode *m = data; | |
3862 | int r; | |
3863 | ||
3864 | assert(filename); | |
3865 | assert(lvalue); | |
3866 | assert(rvalue); | |
3867 | ||
3868 | r = parse_boolean(rvalue); | |
3869 | if (r < 0) { | |
12ca818f | 3870 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse boolean, ignoring: %s", rvalue); |
d420282b LP |
3871 | return 0; |
3872 | } | |
3873 | ||
8ab39347 YW |
3874 | log_notice("%s is deprecated. Please use OnFailureJobMode= instead", lvalue); |
3875 | ||
d420282b LP |
3876 | *m = r ? JOB_ISOLATE : JOB_REPLACE; |
3877 | return 0; | |
3878 | } | |
3879 | ||
3536f49e | 3880 | int config_parse_exec_directories( |
e66cf1a3 LP |
3881 | const char *unit, |
3882 | const char *filename, | |
3883 | unsigned line, | |
3884 | const char *section, | |
3885 | unsigned section_line, | |
3886 | const char *lvalue, | |
3887 | int ltype, | |
3888 | const char *rvalue, | |
3889 | void *data, | |
3890 | void *userdata) { | |
3891 | ||
a2a5291b | 3892 | char***rt = data; |
47538b76 | 3893 | const Unit *u = userdata; |
035fe294 | 3894 | const char *p; |
e66cf1a3 LP |
3895 | int r; |
3896 | ||
3897 | assert(filename); | |
3898 | assert(lvalue); | |
3899 | assert(rvalue); | |
3900 | assert(data); | |
3901 | ||
3902 | if (isempty(rvalue)) { | |
3903 | /* Empty assignment resets the list */ | |
6796073e | 3904 | *rt = strv_free(*rt); |
e66cf1a3 LP |
3905 | return 0; |
3906 | } | |
3907 | ||
035fe294 ZJS |
3908 | for (p = rvalue;;) { |
3909 | _cleanup_free_ char *word = NULL, *k = NULL; | |
e66cf1a3 | 3910 | |
4ec85141 | 3911 | r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE); |
035fe294 | 3912 | if (r == -ENOMEM) |
e66cf1a3 | 3913 | return log_oom(); |
035fe294 ZJS |
3914 | if (r < 0) { |
3915 | log_syntax(unit, LOG_WARNING, filename, line, r, | |
3916 | "Invalid syntax, ignoring: %s", rvalue); | |
3917 | return 0; | |
3918 | } | |
091e9efe LP |
3919 | if (r == 0) |
3920 | return 0; | |
e66cf1a3 | 3921 | |
18913df9 | 3922 | r = unit_full_printf(u, word, &k); |
9b5864d9 | 3923 | if (r < 0) { |
035fe294 | 3924 | log_syntax(unit, LOG_ERR, filename, line, r, |
063c4b1a | 3925 | "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word); |
9b5864d9 MG |
3926 | continue; |
3927 | } | |
3928 | ||
2f4d31c1 YW |
3929 | r = path_simplify_and_warn(k, PATH_CHECK_RELATIVE, unit, filename, line, lvalue); |
3930 | if (r < 0) | |
e8865688 | 3931 | continue; |
e8865688 LP |
3932 | |
3933 | if (path_startswith(k, "private")) { | |
3934 | log_syntax(unit, LOG_ERR, filename, line, 0, | |
4605de11 | 3935 | "%s= path can't be 'private', ignoring assignment: %s", lvalue, word); |
e66cf1a3 LP |
3936 | continue; |
3937 | } | |
3938 | ||
035fe294 | 3939 | r = strv_push(rt, k); |
e66cf1a3 LP |
3940 | if (r < 0) |
3941 | return log_oom(); | |
035fe294 | 3942 | k = NULL; |
e66cf1a3 | 3943 | } |
e66cf1a3 LP |
3944 | } |
3945 | ||
3af00fb8 LP |
3946 | int config_parse_set_status( |
3947 | const char *unit, | |
3948 | const char *filename, | |
3949 | unsigned line, | |
3950 | const char *section, | |
3951 | unsigned section_line, | |
3952 | const char *lvalue, | |
3953 | int ltype, | |
3954 | const char *rvalue, | |
3955 | void *data, | |
3956 | void *userdata) { | |
3957 | ||
3af00fb8 | 3958 | size_t l; |
a2a5291b | 3959 | const char *word, *state; |
3af00fb8 LP |
3960 | int r; |
3961 | ExitStatusSet *status_set = data; | |
3962 | ||
3963 | assert(filename); | |
3964 | assert(lvalue); | |
3965 | assert(rvalue); | |
3966 | assert(data); | |
3967 | ||
3e2d435b | 3968 | /* Empty assignment resets the list */ |
3af00fb8 | 3969 | if (isempty(rvalue)) { |
3e2d435b | 3970 | exit_status_set_free(status_set); |
3af00fb8 LP |
3971 | return 0; |
3972 | } | |
3973 | ||
a2a5291b | 3974 | FOREACH_WORD(word, l, rvalue, state) { |
3af00fb8 | 3975 | _cleanup_free_ char *temp; |
23d5dd16 | 3976 | Bitmap *bitmap; |
3af00fb8 | 3977 | |
a2a5291b | 3978 | temp = strndup(word, l); |
3af00fb8 LP |
3979 | if (!temp) |
3980 | return log_oom(); | |
3981 | ||
2e2ed880 ZJS |
3982 | /* We need to call exit_status_from_string() first, because we want |
3983 | * to parse numbers as exit statuses, not signals. */ | |
3af00fb8 | 3984 | |
2e2ed880 ZJS |
3985 | r = exit_status_from_string(temp); |
3986 | if (r >= 0) { | |
3987 | assert(r >= 0 && r < 256); | |
3988 | bitmap = &status_set->status; | |
3af00fb8 | 3989 | } else { |
2e2ed880 ZJS |
3990 | r = signal_from_string(temp); |
3991 | ||
3992 | if (r <= 0) { | |
3993 | log_syntax(unit, LOG_ERR, filename, line, 0, | |
3994 | "Failed to parse value, ignoring: %s", word); | |
1e2fd62d | 3995 | continue; |
3af00fb8 | 3996 | } |
2e2ed880 | 3997 | bitmap = &status_set->signal; |
3af00fb8 | 3998 | } |
1e2fd62d | 3999 | |
2e2ed880 | 4000 | r = bitmap_set(bitmap, r); |
063c4b1a | 4001 | if (r < 0) |
2e2ed880 | 4002 | return log_error_errno(r, "Failed to set signal or status %s: %m", word); |
3af00fb8 | 4003 | } |
b2fadec6 | 4004 | if (!isempty(state)) |
12ca818f | 4005 | log_syntax(unit, LOG_ERR, filename, line, 0, "Trailing garbage, ignoring."); |
3af00fb8 LP |
4006 | |
4007 | return 0; | |
4008 | } | |
4009 | ||
94828d2d LP |
4010 | int config_parse_namespace_path_strv( |
4011 | const char *unit, | |
4012 | const char *filename, | |
4013 | unsigned line, | |
4014 | const char *section, | |
4015 | unsigned section_line, | |
4016 | const char *lvalue, | |
4017 | int ltype, | |
4018 | const char *rvalue, | |
4019 | void *data, | |
4020 | void *userdata) { | |
4021 | ||
47538b76 | 4022 | const Unit *u = userdata; |
a2a5291b | 4023 | char*** sv = data; |
063c4b1a | 4024 | const char *p = rvalue; |
94828d2d LP |
4025 | int r; |
4026 | ||
4027 | assert(filename); | |
4028 | assert(lvalue); | |
4029 | assert(rvalue); | |
4030 | assert(data); | |
4031 | ||
4032 | if (isempty(rvalue)) { | |
4033 | /* Empty assignment resets the list */ | |
6796073e | 4034 | *sv = strv_free(*sv); |
94828d2d LP |
4035 | return 0; |
4036 | } | |
4037 | ||
727f76d7 | 4038 | for (;;) { |
7b07e993 | 4039 | _cleanup_free_ char *word = NULL, *resolved = NULL, *joined = NULL; |
20b7a007 LP |
4040 | const char *w; |
4041 | bool ignore_enoent = false, shall_prefix = false; | |
94828d2d | 4042 | |
4ec85141 | 4043 | r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE); |
0293a7a8 EV |
4044 | if (r == 0) |
4045 | break; | |
4046 | if (r == -ENOMEM) | |
4047 | return log_oom(); | |
727f76d7 | 4048 | if (r < 0) { |
7b07e993 | 4049 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to extract first word, ignoring: %s", rvalue); |
727f76d7 EV |
4050 | return 0; |
4051 | } | |
94828d2d | 4052 | |
20b7a007 LP |
4053 | w = word; |
4054 | if (startswith(w, "-")) { | |
4055 | ignore_enoent = true; | |
4056 | w++; | |
4057 | } | |
4058 | if (startswith(w, "+")) { | |
4059 | shall_prefix = true; | |
4060 | w++; | |
4061 | } | |
7b07e993 | 4062 | |
20b7a007 | 4063 | r = unit_full_printf(u, w, &resolved); |
7b07e993 | 4064 | if (r < 0) { |
063c4b1a | 4065 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in %s: %m", w); |
94828d2d LP |
4066 | continue; |
4067 | } | |
4068 | ||
2f4d31c1 YW |
4069 | r = path_simplify_and_warn(resolved, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue); |
4070 | if (r < 0) | |
7b07e993 | 4071 | continue; |
94828d2d | 4072 | |
20b7a007 LP |
4073 | joined = strjoin(ignore_enoent ? "-" : "", |
4074 | shall_prefix ? "+" : "", | |
4075 | resolved); | |
7b07e993 LP |
4076 | |
4077 | r = strv_push(sv, joined); | |
94828d2d LP |
4078 | if (r < 0) |
4079 | return log_oom(); | |
4080 | ||
7b07e993 | 4081 | joined = NULL; |
94828d2d LP |
4082 | } |
4083 | ||
4084 | return 0; | |
4085 | } | |
4086 | ||
2abd4e38 YW |
4087 | int config_parse_temporary_filesystems( |
4088 | const char *unit, | |
4089 | const char *filename, | |
4090 | unsigned line, | |
4091 | const char *section, | |
4092 | unsigned section_line, | |
4093 | const char *lvalue, | |
4094 | int ltype, | |
4095 | const char *rvalue, | |
4096 | void *data, | |
4097 | void *userdata) { | |
4098 | ||
47538b76 | 4099 | const Unit *u = userdata; |
2abd4e38 | 4100 | ExecContext *c = data; |
063c4b1a | 4101 | const char *p = rvalue; |
2abd4e38 YW |
4102 | int r; |
4103 | ||
4104 | assert(filename); | |
4105 | assert(lvalue); | |
4106 | assert(rvalue); | |
4107 | assert(data); | |
4108 | ||
4109 | if (isempty(rvalue)) { | |
4110 | /* Empty assignment resets the list */ | |
4111 | temporary_filesystem_free_many(c->temporary_filesystems, c->n_temporary_filesystems); | |
4112 | c->temporary_filesystems = NULL; | |
4113 | c->n_temporary_filesystems = 0; | |
4114 | return 0; | |
4115 | } | |
4116 | ||
2abd4e38 YW |
4117 | for (;;) { |
4118 | _cleanup_free_ char *word = NULL, *path = NULL, *resolved = NULL; | |
4119 | const char *w; | |
4120 | ||
4ec85141 | 4121 | r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE); |
2abd4e38 | 4122 | if (r == 0) |
063c4b1a | 4123 | return 0; |
2abd4e38 YW |
4124 | if (r == -ENOMEM) |
4125 | return log_oom(); | |
4126 | if (r < 0) { | |
4127 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to extract first word, ignoring: %s", rvalue); | |
4128 | return 0; | |
4129 | } | |
4130 | ||
4131 | w = word; | |
4132 | r = extract_first_word(&w, &path, ":", EXTRACT_DONT_COALESCE_SEPARATORS); | |
063c4b1a YW |
4133 | if (r == -ENOMEM) |
4134 | return log_oom(); | |
4135 | if (r < 0) { | |
4136 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to extract first word, ignoring: %s", word); | |
4137 | continue; | |
4138 | } | |
4139 | if (r == 0) { | |
4140 | log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid syntax, ignoring: %s", word); | |
4141 | continue; | |
4142 | } | |
2abd4e38 YW |
4143 | |
4144 | r = unit_full_printf(u, path, &resolved); | |
4145 | if (r < 0) { | |
063c4b1a | 4146 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in %s, ignoring: %m", path); |
2abd4e38 YW |
4147 | continue; |
4148 | } | |
4149 | ||
2f4d31c1 YW |
4150 | r = path_simplify_and_warn(resolved, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue); |
4151 | if (r < 0) | |
2abd4e38 | 4152 | continue; |
2abd4e38 | 4153 | |
a26fec24 | 4154 | r = temporary_filesystem_add(&c->temporary_filesystems, &c->n_temporary_filesystems, resolved, w); |
6302d1ea | 4155 | if (r < 0) |
2abd4e38 | 4156 | return log_oom(); |
2abd4e38 | 4157 | } |
2abd4e38 YW |
4158 | } |
4159 | ||
d2d6c096 LP |
4160 | int config_parse_bind_paths( |
4161 | const char *unit, | |
4162 | const char *filename, | |
4163 | unsigned line, | |
4164 | const char *section, | |
4165 | unsigned section_line, | |
4166 | const char *lvalue, | |
4167 | int ltype, | |
4168 | const char *rvalue, | |
4169 | void *data, | |
4170 | void *userdata) { | |
4171 | ||
4172 | ExecContext *c = data; | |
47538b76 | 4173 | const Unit *u = userdata; |
d2d6c096 LP |
4174 | const char *p; |
4175 | int r; | |
4176 | ||
4177 | assert(filename); | |
4178 | assert(lvalue); | |
4179 | assert(rvalue); | |
4180 | assert(data); | |
4181 | ||
4182 | if (isempty(rvalue)) { | |
4183 | /* Empty assignment resets the list */ | |
4184 | bind_mount_free_many(c->bind_mounts, c->n_bind_mounts); | |
4185 | c->bind_mounts = NULL; | |
4186 | c->n_bind_mounts = 0; | |
4187 | return 0; | |
4188 | } | |
4189 | ||
4190 | p = rvalue; | |
4191 | for (;;) { | |
4192 | _cleanup_free_ char *source = NULL, *destination = NULL; | |
42d43f21 | 4193 | _cleanup_free_ char *sresolved = NULL, *dresolved = NULL; |
d2d6c096 LP |
4194 | char *s = NULL, *d = NULL; |
4195 | bool rbind = true, ignore_enoent = false; | |
4196 | ||
4ec85141 | 4197 | r = extract_first_word(&p, &source, ":" WHITESPACE, EXTRACT_UNQUOTE|EXTRACT_DONT_COALESCE_SEPARATORS); |
d2d6c096 LP |
4198 | if (r == 0) |
4199 | break; | |
4200 | if (r == -ENOMEM) | |
4201 | return log_oom(); | |
4202 | if (r < 0) { | |
2f4d31c1 | 4203 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse %s, ignoring: %s", lvalue, rvalue); |
d2d6c096 LP |
4204 | return 0; |
4205 | } | |
4206 | ||
42d43f21 DC |
4207 | r = unit_full_printf(u, source, &sresolved); |
4208 | if (r < 0) { | |
4209 | log_syntax(unit, LOG_ERR, filename, line, r, | |
063c4b1a | 4210 | "Failed to resolved unit specifiers in \"%s\", ignoring: %m", source); |
2f4d31c1 | 4211 | continue; |
42d43f21 DC |
4212 | } |
4213 | ||
4214 | s = sresolved; | |
d2d6c096 LP |
4215 | if (s[0] == '-') { |
4216 | ignore_enoent = true; | |
4217 | s++; | |
4218 | } | |
4219 | ||
2f4d31c1 YW |
4220 | r = path_simplify_and_warn(s, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue); |
4221 | if (r < 0) | |
4222 | continue; | |
d2d6c096 LP |
4223 | |
4224 | /* Optionally, the destination is specified. */ | |
4225 | if (p && p[-1] == ':') { | |
4ec85141 | 4226 | r = extract_first_word(&p, &destination, ":" WHITESPACE, EXTRACT_UNQUOTE|EXTRACT_DONT_COALESCE_SEPARATORS); |
d2d6c096 LP |
4227 | if (r == -ENOMEM) |
4228 | return log_oom(); | |
4229 | if (r < 0) { | |
2f4d31c1 | 4230 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse %s, ignoring: %s", lvalue, rvalue); |
d2d6c096 LP |
4231 | return 0; |
4232 | } | |
4233 | if (r == 0) { | |
2f4d31c1 YW |
4234 | log_syntax(unit, LOG_ERR, filename, line, 0, "Missing argument after ':', ignoring: %s", s); |
4235 | continue; | |
d2d6c096 LP |
4236 | } |
4237 | ||
42d43f21 DC |
4238 | r = unit_full_printf(u, destination, &dresolved); |
4239 | if (r < 0) { | |
4240 | log_syntax(unit, LOG_ERR, filename, line, r, | |
4241 | "Failed to resolved specifiers in \"%s\", ignoring: %m", destination); | |
2f4d31c1 | 4242 | continue; |
42d43f21 DC |
4243 | } |
4244 | ||
2f4d31c1 YW |
4245 | r = path_simplify_and_warn(dresolved, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue); |
4246 | if (r < 0) | |
4247 | continue; | |
d2d6c096 | 4248 | |
2f4d31c1 | 4249 | d = dresolved; |
d2d6c096 LP |
4250 | |
4251 | /* Optionally, there's also a short option string specified */ | |
4252 | if (p && p[-1] == ':') { | |
4253 | _cleanup_free_ char *options = NULL; | |
4254 | ||
4ec85141 | 4255 | r = extract_first_word(&p, &options, NULL, EXTRACT_UNQUOTE); |
d2d6c096 LP |
4256 | if (r == -ENOMEM) |
4257 | return log_oom(); | |
4258 | if (r < 0) { | |
4259 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse %s: %s", lvalue, rvalue); | |
4260 | return 0; | |
4261 | } | |
4262 | ||
4263 | if (isempty(options) || streq(options, "rbind")) | |
4264 | rbind = true; | |
4265 | else if (streq(options, "norbind")) | |
4266 | rbind = false; | |
4267 | else { | |
4268 | log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid option string, ignoring setting: %s", options); | |
2f4d31c1 | 4269 | continue; |
d2d6c096 LP |
4270 | } |
4271 | } | |
4272 | } else | |
4273 | d = s; | |
4274 | ||
4275 | r = bind_mount_add(&c->bind_mounts, &c->n_bind_mounts, | |
4276 | &(BindMount) { | |
4277 | .source = s, | |
4278 | .destination = d, | |
4279 | .read_only = !!strstr(lvalue, "ReadOnly"), | |
4280 | .recursive = rbind, | |
4281 | .ignore_enoent = ignore_enoent, | |
4282 | }); | |
4283 | if (r < 0) | |
4284 | return log_oom(); | |
4285 | } | |
4286 | ||
4287 | return 0; | |
4288 | } | |
4289 | ||
eae51da3 LP |
4290 | int config_parse_job_timeout_sec( |
4291 | const char* unit, | |
4292 | const char *filename, | |
4293 | unsigned line, | |
4294 | const char *section, | |
4295 | unsigned section_line, | |
4296 | const char *lvalue, | |
4297 | int ltype, | |
4298 | const char *rvalue, | |
4299 | void *data, | |
4300 | void *userdata) { | |
4301 | ||
4302 | Unit *u = data; | |
4303 | usec_t usec; | |
4304 | int r; | |
4305 | ||
4306 | assert(filename); | |
4307 | assert(lvalue); | |
4308 | assert(rvalue); | |
4309 | assert(u); | |
4310 | ||
4311 | r = parse_sec_fix_0(rvalue, &usec); | |
4312 | if (r < 0) { | |
4313 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse JobTimeoutSec= parameter, ignoring: %s", rvalue); | |
4314 | return 0; | |
4315 | } | |
4316 | ||
4317 | /* If the user explicitly changed JobTimeoutSec= also change JobRunningTimeoutSec=, for compatibility with old | |
c05f3c8f | 4318 | * versions. If JobRunningTimeoutSec= was explicitly set, avoid this however as whatever the user picked should |
eae51da3 LP |
4319 | * count. */ |
4320 | ||
4321 | if (!u->job_running_timeout_set) | |
4322 | u->job_running_timeout = usec; | |
4323 | ||
4324 | u->job_timeout = usec; | |
4325 | ||
4326 | return 0; | |
4327 | } | |
4328 | ||
4329 | int config_parse_job_running_timeout_sec( | |
4330 | const char* unit, | |
4331 | const char *filename, | |
4332 | unsigned line, | |
4333 | const char *section, | |
4334 | unsigned section_line, | |
4335 | const char *lvalue, | |
4336 | int ltype, | |
4337 | const char *rvalue, | |
4338 | void *data, | |
4339 | void *userdata) { | |
4340 | ||
4341 | Unit *u = data; | |
4342 | usec_t usec; | |
4343 | int r; | |
4344 | ||
4345 | assert(filename); | |
4346 | assert(lvalue); | |
4347 | assert(rvalue); | |
4348 | assert(u); | |
4349 | ||
4350 | r = parse_sec_fix_0(rvalue, &usec); | |
4351 | if (r < 0) { | |
4352 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse JobRunningTimeoutSec= parameter, ignoring: %s", rvalue); | |
4353 | return 0; | |
4354 | } | |
4355 | ||
4356 | u->job_running_timeout = usec; | |
4357 | u->job_running_timeout_set = true; | |
4358 | ||
4359 | return 0; | |
4360 | } | |
4361 | ||
54fcb619 ZJS |
4362 | int config_parse_emergency_action( |
4363 | const char* unit, | |
4364 | const char *filename, | |
4365 | unsigned line, | |
4366 | const char *section, | |
4367 | unsigned section_line, | |
4368 | const char *lvalue, | |
4369 | int ltype, | |
4370 | const char *rvalue, | |
4371 | void *data, | |
4372 | void *userdata) { | |
4373 | ||
4374 | Manager *m = NULL; | |
4375 | EmergencyAction *x = data; | |
4376 | int r; | |
4377 | ||
4378 | assert(filename); | |
4379 | assert(lvalue); | |
4380 | assert(rvalue); | |
4381 | assert(data); | |
4382 | ||
4383 | if (unit) | |
4384 | m = ((Unit*) userdata)->manager; | |
4385 | else | |
4386 | m = data; | |
4387 | ||
4388 | r = parse_emergency_action(rvalue, MANAGER_IS_SYSTEM(m), x); | |
4389 | if (r < 0) { | |
469f76f1 ZJS |
4390 | if (r == -EOPNOTSUPP && MANAGER_IS_USER(m)) { |
4391 | /* Compat mode: remove for systemd 241. */ | |
4392 | ||
4393 | log_syntax(unit, LOG_INFO, filename, line, r, | |
4394 | "%s= in user mode specified as \"%s\", using \"exit-force\" instead.", | |
4395 | lvalue, rvalue); | |
4396 | *x = EMERGENCY_ACTION_EXIT_FORCE; | |
4397 | return 0; | |
4398 | } | |
4399 | ||
54fcb619 ZJS |
4400 | if (r == -EOPNOTSUPP) |
4401 | log_syntax(unit, LOG_ERR, filename, line, r, | |
4402 | "%s= specified as %s mode action, ignoring: %s", | |
4403 | lvalue, MANAGER_IS_SYSTEM(m) ? "user" : "system", rvalue); | |
4404 | else | |
4405 | log_syntax(unit, LOG_ERR, filename, line, r, | |
4406 | "Failed to parse %s=, ignoring: %s", lvalue, rvalue); | |
4407 | return 0; | |
4408 | } | |
4409 | ||
4410 | return 0; | |
4411 | } | |
4412 | ||
a9353a5c LP |
4413 | int config_parse_pid_file( |
4414 | const char *unit, | |
4415 | const char *filename, | |
4416 | unsigned line, | |
4417 | const char *section, | |
4418 | unsigned section_line, | |
4419 | const char *lvalue, | |
4420 | int ltype, | |
4421 | const char *rvalue, | |
4422 | void *data, | |
4423 | void *userdata) { | |
4424 | ||
4425 | _cleanup_free_ char *k = NULL, *n = NULL; | |
47538b76 | 4426 | const Unit *u = userdata; |
a9353a5c | 4427 | char **s = data; |
a9353a5c LP |
4428 | int r; |
4429 | ||
4430 | assert(filename); | |
4431 | assert(lvalue); | |
4432 | assert(rvalue); | |
4433 | assert(u); | |
4434 | ||
b8055c05 YW |
4435 | if (isempty(rvalue)) { |
4436 | /* An empty assignment removes already set value. */ | |
4437 | *s = mfree(*s); | |
4438 | return 0; | |
4439 | } | |
4440 | ||
a9353a5c LP |
4441 | r = unit_full_printf(u, rvalue, &k); |
4442 | if (r < 0) { | |
4443 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue); | |
4444 | return 0; | |
4445 | } | |
4446 | ||
4447 | /* If this is a relative path make it absolute by prefixing the /run */ | |
4448 | n = path_make_absolute(k, u->manager->prefix[EXEC_DIRECTORY_RUNTIME]); | |
4449 | if (!n) | |
4450 | return log_oom(); | |
4451 | ||
4452 | /* Check that the result is a sensible path */ | |
4453 | r = path_simplify_and_warn(n, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue); | |
4454 | if (r < 0) | |
4455 | return r; | |
4456 | ||
4a66b5c9 LP |
4457 | r = patch_var_run(unit, filename, line, lvalue, &n); |
4458 | if (r < 0) | |
4459 | return r; | |
a9353a5c | 4460 | |
4a66b5c9 | 4461 | free_and_replace(*s, n); |
a9353a5c LP |
4462 | return 0; |
4463 | } | |
4464 | ||
7af67e9a LP |
4465 | int config_parse_exit_status( |
4466 | const char *unit, | |
4467 | const char *filename, | |
4468 | unsigned line, | |
4469 | const char *section, | |
4470 | unsigned section_line, | |
4471 | const char *lvalue, | |
4472 | int ltype, | |
4473 | const char *rvalue, | |
4474 | void *data, | |
4475 | void *userdata) { | |
4476 | ||
4477 | int *exit_status = data, r; | |
4478 | uint8_t u; | |
4479 | ||
4480 | assert(filename); | |
4481 | assert(lvalue); | |
4482 | assert(rvalue); | |
4483 | assert(exit_status); | |
4484 | ||
4485 | if (isempty(rvalue)) { | |
4486 | *exit_status = -1; | |
4487 | return 0; | |
4488 | } | |
4489 | ||
4490 | r = safe_atou8(rvalue, &u); | |
4491 | if (r < 0) { | |
4492 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse exit status '%s', ignoring: %m", rvalue); | |
4493 | return 0; | |
4494 | } | |
4495 | ||
4496 | *exit_status = u; | |
4497 | return 0; | |
4498 | } | |
4499 | ||
c72703e2 CD |
4500 | int config_parse_disable_controllers( |
4501 | const char *unit, | |
4502 | const char *filename, | |
4503 | unsigned line, | |
4504 | const char *section, | |
4505 | unsigned section_line, | |
4506 | const char *lvalue, | |
4507 | int ltype, | |
4508 | const char *rvalue, | |
4509 | void *data, | |
4510 | void *userdata) { | |
4511 | ||
4512 | int r; | |
4513 | CGroupContext *c = data; | |
4514 | CGroupMask disabled_mask; | |
4515 | ||
4516 | /* 1. If empty, make all controllers eligible for use again. | |
4517 | * 2. If non-empty, merge all listed controllers, space separated. */ | |
4518 | ||
4519 | if (isempty(rvalue)) { | |
4520 | c->disable_controllers = 0; | |
4521 | return 0; | |
4522 | } | |
4523 | ||
4524 | r = cg_mask_from_string(rvalue, &disabled_mask); | |
4525 | if (r < 0 || disabled_mask <= 0) { | |
4526 | log_syntax(unit, LOG_ERR, filename, line, r, "Invalid cgroup string: %s, ignoring", rvalue); | |
4527 | return 0; | |
4528 | } | |
4529 | ||
4530 | c->disable_controllers |= disabled_mask; | |
4531 | ||
4532 | return 0; | |
4533 | } | |
4534 | ||
fab34748 KL |
4535 | int config_parse_ip_filter_bpf_progs( |
4536 | const char *unit, | |
4537 | const char *filename, | |
4538 | unsigned line, | |
4539 | const char *section, | |
4540 | unsigned section_line, | |
4541 | const char *lvalue, | |
4542 | int ltype, | |
4543 | const char *rvalue, | |
4544 | void *data, | |
4545 | void *userdata) { | |
4546 | ||
4547 | _cleanup_free_ char *resolved = NULL; | |
47538b76 | 4548 | const Unit *u = userdata; |
fab34748 KL |
4549 | char ***paths = data; |
4550 | int r; | |
4551 | ||
4552 | assert(filename); | |
4553 | assert(lvalue); | |
4554 | assert(rvalue); | |
4555 | assert(paths); | |
4556 | ||
4557 | if (isempty(rvalue)) { | |
4558 | *paths = strv_free(*paths); | |
4559 | return 0; | |
4560 | } | |
4561 | ||
4562 | r = unit_full_printf(u, rvalue, &resolved); | |
4563 | if (r < 0) { | |
4564 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue); | |
4565 | return 0; | |
4566 | } | |
4567 | ||
4568 | r = path_simplify_and_warn(resolved, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue); | |
4569 | if (r < 0) | |
4570 | return 0; | |
4571 | ||
4572 | if (strv_contains(*paths, resolved)) | |
4573 | return 0; | |
4574 | ||
4575 | r = strv_extend(paths, resolved); | |
4576 | if (r < 0) | |
4577 | return log_oom(); | |
4578 | ||
4579 | r = bpf_firewall_supported(); | |
4580 | if (r < 0) | |
4581 | return r; | |
4582 | if (r != BPF_FIREWALL_SUPPORTED_WITH_MULTI) { | |
4583 | static bool warned = false; | |
4584 | ||
4585 | log_full(warned ? LOG_DEBUG : LOG_WARNING, | |
4586 | "File %s:%u configures an IP firewall with BPF programs (%s=%s), but the local system does not support BPF/cgroup based firewalling with multiple filters.\n" | |
4587 | "Starting this unit will fail! (This warning is only shown for the first loaded unit using IP firewalling.)", filename, line, lvalue, rvalue); | |
4588 | ||
4589 | warned = true; | |
4590 | } | |
4591 | ||
4592 | return 0; | |
4593 | } | |
4594 | ||
23a177ef LP |
4595 | static int merge_by_names(Unit **u, Set *names, const char *id) { |
4596 | char *k; | |
4597 | int r; | |
4598 | ||
4599 | assert(u); | |
4600 | assert(*u); | |
23a177ef | 4601 | |
e8630e69 | 4602 | /* Let's try to add in all names that are aliases of this unit */ |
23a177ef | 4603 | while ((k = set_steal_first(names))) { |
e8630e69 | 4604 | _cleanup_free_ _unused_ char *free_k = k; |
23a177ef | 4605 | |
e8630e69 | 4606 | /* First try to merge in the other name into our unit */ |
9946996c LP |
4607 | r = unit_merge_by_name(*u, k); |
4608 | if (r < 0) { | |
23a177ef LP |
4609 | Unit *other; |
4610 | ||
e8630e69 ZJS |
4611 | /* Hmm, we couldn't merge the other unit into ours? Then let's try it the other way |
4612 | * round. */ | |
036643a2 | 4613 | |
e8630e69 ZJS |
4614 | other = manager_get_unit((*u)->manager, k); |
4615 | if (!other) | |
4616 | return r; /* return previous failure */ | |
036643a2 | 4617 | |
e8630e69 ZJS |
4618 | r = unit_merge(other, *u); |
4619 | if (r < 0) | |
a837f088 | 4620 | return r; |
fe51822e | 4621 | |
e8630e69 ZJS |
4622 | *u = other; |
4623 | return merge_by_names(u, names, NULL); | |
036643a2 | 4624 | } |
034c6ed7 | 4625 | |
e8630e69 ZJS |
4626 | if (streq_ptr(id, k)) |
4627 | unit_choose_id(*u, id); | |
1b64d026 LP |
4628 | } |
4629 | ||
e48614c4 | 4630 | return 0; |
0301abf4 LP |
4631 | } |
4632 | ||
e537352b | 4633 | int unit_load_fragment(Unit *u) { |
e8630e69 ZJS |
4634 | const char *fragment; |
4635 | _cleanup_set_free_free_ Set *names = NULL; | |
5a1c1b53 | 4636 | struct stat st; |
23a177ef | 4637 | int r; |
0301abf4 LP |
4638 | |
4639 | assert(u); | |
ac155bb8 MS |
4640 | assert(u->load_state == UNIT_STUB); |
4641 | assert(u->id); | |
23a177ef | 4642 | |
3f5e8115 LP |
4643 | if (u->transient) { |
4644 | u->load_state = UNIT_LOADED; | |
4645 | return 0; | |
4646 | } | |
4647 | ||
91e0ee5f ZJS |
4648 | /* Possibly rebuild the fragment map to catch new units */ |
4649 | r = unit_file_build_name_map(&u->manager->lookup_paths, | |
4650 | &u->manager->unit_cache_mtime, | |
4651 | &u->manager->unit_id_map, | |
4652 | &u->manager->unit_name_map, | |
4653 | &u->manager->unit_path_cache); | |
9946996c | 4654 | if (r < 0) |
91e0ee5f ZJS |
4655 | log_error_errno(r, "Failed to rebuild name map: %m"); |
4656 | ||
e8630e69 ZJS |
4657 | r = unit_file_find_fragment(u->manager->unit_id_map, |
4658 | u->manager->unit_name_map, | |
4659 | u->id, | |
4660 | &fragment, | |
4661 | &names); | |
4662 | if (r < 0 && r != -ENOENT) | |
294d81f1 LP |
4663 | return r; |
4664 | ||
e8630e69 ZJS |
4665 | if (fragment) { |
4666 | /* Open the file, check if this is a mask, otherwise read. */ | |
4667 | _cleanup_fclose_ FILE *f = NULL; | |
0301abf4 | 4668 | |
e8630e69 ZJS |
4669 | /* Try to open the file name. A symlink is OK, for example for linked files or masks. We |
4670 | * expect that all symlinks within the lookup paths have been already resolved, but we don't | |
4671 | * verify this here. */ | |
4672 | f = fopen(fragment, "re"); | |
4673 | if (!f) | |
4674 | return log_unit_notice_errno(u, errno, "Failed to open %s: %m", fragment); | |
6ccb1b44 | 4675 | |
e8630e69 ZJS |
4676 | if (fstat(fileno(f), &st) < 0) |
4677 | return -errno; | |
294d81f1 | 4678 | |
e8630e69 | 4679 | r = free_and_strdup(&u->fragment_path, fragment); |
7410616c LP |
4680 | if (r < 0) |
4681 | return r; | |
294d81f1 | 4682 | |
e8630e69 ZJS |
4683 | if (null_or_empty(&st)) { |
4684 | u->load_state = UNIT_MASKED; | |
4685 | u->fragment_mtime = 0; | |
4686 | } else { | |
4687 | u->load_state = UNIT_LOADED; | |
4688 | u->fragment_mtime = timespec_load(&st.st_mtim); | |
4689 | ||
4690 | /* Now, parse the file contents */ | |
4691 | r = config_parse(u->id, fragment, f, | |
4692 | UNIT_VTABLE(u)->sections, | |
4693 | config_item_perf_lookup, load_fragment_gperf_lookup, | |
4694 | CONFIG_PARSE_ALLOW_INCLUDE, u); | |
bb28e684 | 4695 | if (r == -ENOEXEC) |
e8630e69 ZJS |
4696 | log_unit_notice_errno(u, r, "Unit configuration has fatal error, unit will not be started."); |
4697 | if (r < 0) | |
4698 | return r; | |
bb28e684 | 4699 | } |
e8630e69 | 4700 | } |
890f434c | 4701 | |
5a1c1b53 FB |
4702 | if (u->source_path) { |
4703 | if (stat(u->source_path, &st) >= 0) | |
4704 | u->source_mtime = timespec_load(&st.st_mtim); | |
4705 | else | |
4706 | u->source_mtime = 0; | |
4707 | } | |
4708 | ||
e8630e69 ZJS |
4709 | /* We do the merge dance here because for some unit types, the unit might have aliases which are not |
4710 | * declared in the file system. In particular, this is true (and frequent) for device and swap units. | |
4711 | */ | |
4712 | Unit *merged; | |
4713 | const char *id = u->id; | |
4714 | _cleanup_free_ char *free_id = NULL; | |
294d81f1 | 4715 | |
e8630e69 ZJS |
4716 | if (fragment) { |
4717 | id = basename(fragment); | |
4718 | if (unit_name_is_valid(id, UNIT_NAME_TEMPLATE)) { | |
4719 | assert(u->instance); /* If we're not trying to use a template for non-instanced unit, | |
4720 | * this must be set. */ | |
890f434c | 4721 | |
e8630e69 ZJS |
4722 | r = unit_name_replace_instance(id, u->instance, &free_id); |
4723 | if (r < 0) | |
4724 | return log_debug_errno(r, "Failed to build id (%s + %s): %m", id, u->instance); | |
4725 | id = free_id; | |
abc08d4d | 4726 | } |
071830ff LP |
4727 | } |
4728 | ||
e8630e69 ZJS |
4729 | merged = u; |
4730 | r = merge_by_names(&merged, names, id); | |
4731 | if (r < 0) | |
4732 | return r; | |
4733 | ||
4734 | if (merged != u) | |
4735 | u->load_state = UNIT_MERGED; | |
4736 | ||
23a177ef | 4737 | return 0; |
3efd4195 | 4738 | } |
e537352b LP |
4739 | |
4740 | void unit_dump_config_items(FILE *f) { | |
f975e971 LP |
4741 | static const struct { |
4742 | const ConfigParserCallback callback; | |
4743 | const char *rvalue; | |
4744 | } table[] = { | |
17df7223 | 4745 | { config_parse_warn_compat, "NOTSUPPORTED" }, |
f975e971 LP |
4746 | { config_parse_int, "INTEGER" }, |
4747 | { config_parse_unsigned, "UNSIGNED" }, | |
5556b5fe | 4748 | { config_parse_iec_size, "SIZE" }, |
59f448cf | 4749 | { config_parse_iec_uint64, "SIZE" }, |
5556b5fe | 4750 | { config_parse_si_size, "SIZE" }, |
f975e971 LP |
4751 | { config_parse_bool, "BOOLEAN" }, |
4752 | { config_parse_string, "STRING" }, | |
4753 | { config_parse_path, "PATH" }, | |
4754 | { config_parse_unit_path_printf, "PATH" }, | |
4755 | { config_parse_strv, "STRING [...]" }, | |
4756 | { config_parse_exec_nice, "NICE" }, | |
4757 | { config_parse_exec_oom_score_adjust, "OOMSCOREADJUST" }, | |
4758 | { config_parse_exec_io_class, "IOCLASS" }, | |
4759 | { config_parse_exec_io_priority, "IOPRIORITY" }, | |
4760 | { config_parse_exec_cpu_sched_policy, "CPUSCHEDPOLICY" }, | |
4761 | { config_parse_exec_cpu_sched_prio, "CPUSCHEDPRIO" }, | |
4762 | { config_parse_exec_cpu_affinity, "CPUAFFINITY" }, | |
4763 | { config_parse_mode, "MODE" }, | |
4764 | { config_parse_unit_env_file, "FILE" }, | |
52c239d7 LB |
4765 | { config_parse_exec_output, "OUTPUT" }, |
4766 | { config_parse_exec_input, "INPUT" }, | |
ca37242e LP |
4767 | { config_parse_log_facility, "FACILITY" }, |
4768 | { config_parse_log_level, "LEVEL" }, | |
f975e971 | 4769 | { config_parse_exec_secure_bits, "SECUREBITS" }, |
a103496c | 4770 | { config_parse_capability_set, "BOUNDINGSET" }, |
4f424df7 | 4771 | { config_parse_rlimit, "LIMIT" }, |
f975e971 | 4772 | { config_parse_unit_deps, "UNIT [...]" }, |
f975e971 LP |
4773 | { config_parse_exec, "PATH [ARGUMENT [...]]" }, |
4774 | { config_parse_service_type, "SERVICETYPE" }, | |
4775 | { config_parse_service_restart, "SERVICERESTART" }, | |
f975e971 | 4776 | { config_parse_kill_mode, "KILLMODE" }, |
f757855e | 4777 | { config_parse_signal, "SIGNAL" }, |
f975e971 LP |
4778 | { config_parse_socket_listen, "SOCKET [...]" }, |
4779 | { config_parse_socket_bind, "SOCKETBIND" }, | |
4780 | { config_parse_socket_bindtodevice, "NETWORKINTERFACE" }, | |
7f602784 | 4781 | { config_parse_sec, "SECONDS" }, |
d88a251b | 4782 | { config_parse_nsec, "NANOSECONDS" }, |
94828d2d | 4783 | { config_parse_namespace_path_strv, "PATH [...]" }, |
d2d6c096 | 4784 | { config_parse_bind_paths, "PATH[:PATH[:OPTIONS]] [...]" }, |
7c8fa05c | 4785 | { config_parse_unit_requires_mounts_for, "PATH [...]" }, |
f975e971 LP |
4786 | { config_parse_exec_mount_flags, "MOUNTFLAG [...]" }, |
4787 | { config_parse_unit_string_printf, "STRING" }, | |
3ecaa09b | 4788 | { config_parse_trigger_unit, "UNIT" }, |
f975e971 | 4789 | { config_parse_timer, "TIMER" }, |
f975e971 | 4790 | { config_parse_path_spec, "PATH" }, |
f975e971 LP |
4791 | { config_parse_notify_access, "ACCESS" }, |
4792 | { config_parse_ip_tos, "TOS" }, | |
4793 | { config_parse_unit_condition_path, "CONDITION" }, | |
4794 | { config_parse_unit_condition_string, "CONDITION" }, | |
4795 | { config_parse_unit_condition_null, "CONDITION" }, | |
a016b922 | 4796 | { config_parse_unit_slice, "SLICE" }, |
7f0386f6 LP |
4797 | { config_parse_documentation, "URL" }, |
4798 | { config_parse_service_timeout, "SECONDS" }, | |
87a47f99 | 4799 | { config_parse_emergency_action, "ACTION" }, |
7f0386f6 LP |
4800 | { config_parse_set_status, "STATUS" }, |
4801 | { config_parse_service_sockets, "SOCKETS" }, | |
7f0386f6 | 4802 | { config_parse_environ, "ENVIRON" }, |
349cc4a5 | 4803 | #if HAVE_SECCOMP |
17df7223 | 4804 | { config_parse_syscall_filter, "SYSCALLS" }, |
6a6751fe | 4805 | { config_parse_syscall_archs, "ARCHS" }, |
17df7223 | 4806 | { config_parse_syscall_errno, "ERRNO" }, |
4298d0b5 | 4807 | { config_parse_address_families, "FAMILIES" }, |
add00535 | 4808 | { config_parse_restrict_namespaces, "NAMESPACES" }, |
c0467cf3 | 4809 | #endif |
7f0386f6 | 4810 | { config_parse_cpu_shares, "SHARES" }, |
984faf29 | 4811 | { config_parse_cg_weight, "WEIGHT" }, |
7f0386f6 LP |
4812 | { config_parse_memory_limit, "LIMIT" }, |
4813 | { config_parse_device_allow, "DEVICE" }, | |
4814 | { config_parse_device_policy, "POLICY" }, | |
13c31542 | 4815 | { config_parse_io_limit, "LIMIT" }, |
13c31542 | 4816 | { config_parse_io_device_weight, "DEVICEWEIGHT" }, |
6ae4283c | 4817 | { config_parse_io_device_latency, "DEVICELATENCY" }, |
7f0386f6 LP |
4818 | { config_parse_blockio_bandwidth, "BANDWIDTH" }, |
4819 | { config_parse_blockio_weight, "WEIGHT" }, | |
4820 | { config_parse_blockio_device_weight, "DEVICEWEIGHT" }, | |
4821 | { config_parse_long, "LONG" }, | |
4822 | { config_parse_socket_service, "SERVICE" }, | |
349cc4a5 | 4823 | #if HAVE_SELINUX |
6a6751fe LP |
4824 | { config_parse_exec_selinux_context, "LABEL" }, |
4825 | #endif | |
4826 | { config_parse_job_mode, "MODE" }, | |
4827 | { config_parse_job_mode_isolate, "BOOLEAN" }, | |
4298d0b5 | 4828 | { config_parse_personality, "PERSONALITY" }, |
f975e971 LP |
4829 | }; |
4830 | ||
4831 | const char *prev = NULL; | |
4832 | const char *i; | |
4833 | ||
4834 | assert(f); | |
e537352b | 4835 | |
f975e971 LP |
4836 | NULSTR_FOREACH(i, load_fragment_gperf_nulstr) { |
4837 | const char *rvalue = "OTHER", *lvalue; | |
313b7856 | 4838 | const ConfigPerfItem *p; |
f975e971 LP |
4839 | size_t prefix_len; |
4840 | const char *dot; | |
313b7856 | 4841 | unsigned j; |
f975e971 LP |
4842 | |
4843 | assert_se(p = load_fragment_gperf_lookup(i, strlen(i))); | |
4844 | ||
313b7856 LP |
4845 | /* Hide legacy settings */ |
4846 | if (p->parse == config_parse_warn_compat && | |
4847 | p->ltype == DISABLED_LEGACY) | |
4848 | continue; | |
4849 | ||
4850 | for (j = 0; j < ELEMENTSOF(table); j++) | |
4851 | if (p->parse == table[j].callback) { | |
4852 | rvalue = table[j].rvalue; | |
4853 | break; | |
4854 | } | |
4855 | ||
f975e971 LP |
4856 | dot = strchr(i, '.'); |
4857 | lvalue = dot ? dot + 1 : i; | |
4858 | prefix_len = dot-i; | |
4859 | ||
4860 | if (dot) | |
641906e9 | 4861 | if (!prev || !strneq(prev, i, prefix_len+1)) { |
f975e971 LP |
4862 | if (prev) |
4863 | fputc('\n', f); | |
4864 | ||
4865 | fprintf(f, "[%.*s]\n", (int) prefix_len, i); | |
4866 | } | |
4867 | ||
f975e971 LP |
4868 | fprintf(f, "%s=%s\n", lvalue, rvalue); |
4869 | prev = i; | |
4870 | } | |
e537352b | 4871 | } |
a07a7324 FS |
4872 | |
4873 | int config_parse_cpu_affinity2( | |
4874 | const char *unit, | |
4875 | const char *filename, | |
4876 | unsigned line, | |
4877 | const char *section, | |
4878 | unsigned section_line, | |
4879 | const char *lvalue, | |
4880 | int ltype, | |
4881 | const char *rvalue, | |
4882 | void *data, | |
4883 | void *userdata) { | |
4884 | ||
4885 | CPUSet *affinity = data; | |
4886 | ||
4887 | assert(affinity); | |
4888 | ||
4889 | (void) parse_cpu_set_extend(rvalue, affinity, true, unit, filename, line, lvalue); | |
4890 | ||
4891 | return 0; | |
4892 | } | |
4893 | ||
4894 | int config_parse_show_status( | |
4895 | const char* unit, | |
4896 | const char *filename, | |
4897 | unsigned line, | |
4898 | const char *section, | |
4899 | unsigned section_line, | |
4900 | const char *lvalue, | |
4901 | int ltype, | |
4902 | const char *rvalue, | |
4903 | void *data, | |
4904 | void *userdata) { | |
4905 | ||
4906 | int k; | |
4907 | ShowStatus *b = data; | |
4908 | ||
4909 | assert(filename); | |
4910 | assert(lvalue); | |
4911 | assert(rvalue); | |
4912 | assert(data); | |
4913 | ||
4914 | k = parse_show_status(rvalue, b); | |
4915 | if (k < 0) { | |
4916 | log_syntax(unit, LOG_ERR, filename, line, k, "Failed to parse show status setting, ignoring: %s", rvalue); | |
4917 | return 0; | |
4918 | } | |
4919 | ||
4920 | return 0; | |
4921 | } | |
4922 | ||
4923 | int config_parse_output_restricted( | |
4924 | const char* unit, | |
4925 | const char *filename, | |
4926 | unsigned line, | |
4927 | const char *section, | |
4928 | unsigned section_line, | |
4929 | const char *lvalue, | |
4930 | int ltype, | |
4931 | const char *rvalue, | |
4932 | void *data, | |
4933 | void *userdata) { | |
4934 | ||
4935 | ExecOutput t, *eo = data; | |
4936 | ||
4937 | assert(filename); | |
4938 | assert(lvalue); | |
4939 | assert(rvalue); | |
4940 | assert(data); | |
4941 | ||
4942 | t = exec_output_from_string(rvalue); | |
4943 | if (t < 0) { | |
4944 | log_syntax(unit, LOG_ERR, filename, line, 0, "Failed to parse output type, ignoring: %s", rvalue); | |
4945 | return 0; | |
4946 | } | |
4947 | ||
4948 | if (IN_SET(t, EXEC_OUTPUT_SOCKET, EXEC_OUTPUT_NAMED_FD, EXEC_OUTPUT_FILE, EXEC_OUTPUT_FILE_APPEND)) { | |
4949 | log_syntax(unit, LOG_ERR, filename, line, 0, "Standard output types socket, fd:, file:, append: are not supported as defaults, ignoring: %s", rvalue); | |
4950 | return 0; | |
4951 | } | |
4952 | ||
4953 | *eo = t; | |
4954 | return 0; | |
4955 | } | |
4956 | ||
4957 | int config_parse_crash_chvt( | |
4958 | const char* unit, | |
4959 | const char *filename, | |
4960 | unsigned line, | |
4961 | const char *section, | |
4962 | unsigned section_line, | |
4963 | const char *lvalue, | |
4964 | int ltype, | |
4965 | const char *rvalue, | |
4966 | void *data, | |
4967 | void *userdata) { | |
4968 | ||
4969 | int r; | |
4970 | ||
4971 | assert(filename); | |
4972 | assert(lvalue); | |
4973 | assert(rvalue); | |
4974 | assert(data); | |
4975 | ||
4976 | r = parse_crash_chvt(rvalue, data); | |
4977 | if (r < 0) { | |
4978 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse CrashChangeVT= setting, ignoring: %s", rvalue); | |
4979 | return 0; | |
4980 | } | |
4981 | ||
4982 | return 0; | |
4983 | } | |
4984 | ||
4985 | int config_parse_timeout_abort( | |
4986 | const char* unit, | |
4987 | const char *filename, | |
4988 | unsigned line, | |
4989 | const char *section, | |
4990 | unsigned section_line, | |
4991 | const char *lvalue, | |
4992 | int ltype, | |
4993 | const char *rvalue, | |
4994 | void *data, | |
4995 | void *userdata) { | |
4996 | ||
4997 | usec_t *timeout_usec = data; | |
4998 | int r; | |
4999 | ||
5000 | assert(filename); | |
5001 | assert(lvalue); | |
5002 | assert(rvalue); | |
5003 | assert(timeout_usec); | |
5004 | ||
5005 | rvalue += strspn(rvalue, WHITESPACE); | |
5006 | if (isempty(rvalue)) { | |
5007 | *timeout_usec = false; | |
5008 | return 0; | |
5009 | } | |
5010 | ||
5011 | r = parse_sec(rvalue, timeout_usec); | |
5012 | if (r < 0) { | |
5013 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse DefaultTimeoutAbortSec= setting, ignoring: %s", rvalue); | |
5014 | return 0; | |
5015 | } | |
5016 | ||
5017 | *timeout_usec = true; | |
5018 | return 0; | |
5019 | } |