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