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