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