]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/core/load-fragment.c
pid1: generate warnings if old obsolete cgroupsv1 settings are used
[thirdparty/systemd.git] / src / core / load-fragment.c
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 /***
3 Copyright © 2012 Holger Hans Peter Freyther
4 ***/
5
6 #include <errno.h>
7 #include <fcntl.h>
8 #include <linux/fs.h>
9 #include <linux/oom.h>
10 #if HAVE_SECCOMP
11 #include <seccomp.h>
12 #endif
13 #include <sched.h>
14 #include <sys/resource.h>
15
16 #include "sd-messages.h"
17
18 #include "af-list.h"
19 #include "all-units.h"
20 #include "alloc-util.h"
21 #include "bpf-firewall.h"
22 #include "bpf-lsm.h"
23 #include "bpf-program.h"
24 #include "bpf-socket-bind.h"
25 #include "bus-error.h"
26 #include "bus-internal.h"
27 #include "bus-util.h"
28 #include "cap-list.h"
29 #include "capability-util.h"
30 #include "cgroup-setup.h"
31 #include "conf-parser.h"
32 #include "core-varlink.h"
33 #include "cpu-set-util.h"
34 #include "creds-util.h"
35 #include "env-util.h"
36 #include "errno-list.h"
37 #include "escape.h"
38 #include "fd-util.h"
39 #include "fileio.h"
40 #include "fs-util.h"
41 #include "hexdecoct.h"
42 #include "io-util.h"
43 #include "ioprio-util.h"
44 #include "ip-protocol-list.h"
45 #include "journal-file.h"
46 #include "limits-util.h"
47 #include "load-fragment.h"
48 #include "log.h"
49 #include "missing_ioprio.h"
50 #include "mountpoint-util.h"
51 #include "nulstr-util.h"
52 #include "parse-helpers.h"
53 #include "parse-util.h"
54 #include "path-util.h"
55 #include "percent-util.h"
56 #include "process-util.h"
57 #if HAVE_SECCOMP
58 #include "seccomp-util.h"
59 #endif
60 #include "securebits-util.h"
61 #include "selinux-util.h"
62 #include "signal-util.h"
63 #include "socket-netlink.h"
64 #include "specifier.h"
65 #include "stat-util.h"
66 #include "string-util.h"
67 #include "strv.h"
68 #include "syslog-util.h"
69 #include "time-util.h"
70 #include "unit-name.h"
71 #include "unit-printf.h"
72 #include "user-util.h"
73 #include "utf8.h"
74 #include "web-util.h"
75
76 static int parse_socket_protocol(const char *s) {
77 int r;
78
79 r = parse_ip_protocol(s);
80 if (r < 0)
81 return r;
82 if (!IN_SET(r, IPPROTO_UDPLITE, IPPROTO_SCTP))
83 return -EPROTONOSUPPORT;
84
85 return r;
86 }
87
88 int parse_crash_chvt(const char *value, int *data) {
89 int b;
90
91 if (safe_atoi(value, data) >= 0)
92 return 0;
93
94 b = parse_boolean(value);
95 if (b < 0)
96 return b;
97
98 if (b > 0)
99 *data = 0; /* switch to where kmsg goes */
100 else
101 *data = -1; /* turn off switching */
102
103 return 0;
104 }
105
106 int parse_confirm_spawn(const char *value, char **console) {
107 char *s;
108 int r;
109
110 r = value ? parse_boolean(value) : 1;
111 if (r == 0) {
112 *console = NULL;
113 return 0;
114 } else if (r > 0) /* on with default tty */
115 s = strdup("/dev/console");
116 else if (is_path(value)) /* on with fully qualified path */
117 s = strdup(value);
118 else /* on with only a tty file name, not a fully qualified path */
119 s = path_join("/dev/", value);
120 if (!s)
121 return -ENOMEM;
122
123 *console = s;
124 return 0;
125 }
126
127 DEFINE_CONFIG_PARSE(config_parse_socket_protocol, parse_socket_protocol, "Failed to parse socket protocol");
128 DEFINE_CONFIG_PARSE(config_parse_exec_secure_bits, secure_bits_from_string, "Failed to parse secure bits");
129 DEFINE_CONFIG_PARSE_ENUM(config_parse_collect_mode, collect_mode, CollectMode, "Failed to parse garbage collection mode");
130 DEFINE_CONFIG_PARSE_ENUM(config_parse_device_policy, cgroup_device_policy, CGroupDevicePolicy, "Failed to parse device policy");
131 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_keyring_mode, exec_keyring_mode, ExecKeyringMode, "Failed to parse keyring mode");
132 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_proc, protect_proc, ProtectProc, "Failed to parse /proc/ protection mode");
133 DEFINE_CONFIG_PARSE_ENUM(config_parse_proc_subset, proc_subset, ProcSubset, "Failed to parse /proc/ subset mode");
134 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_utmp_mode, exec_utmp_mode, ExecUtmpMode, "Failed to parse utmp mode");
135 DEFINE_CONFIG_PARSE_ENUM(config_parse_job_mode, job_mode, JobMode, "Failed to parse job mode");
136 DEFINE_CONFIG_PARSE_ENUM(config_parse_notify_access, notify_access, NotifyAccess, "Failed to parse notify access specifier");
137 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_home, protect_home, ProtectHome, "Failed to parse protect home value");
138 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_system, protect_system, ProtectSystem, "Failed to parse protect system value");
139 DEFINE_CONFIG_PARSE_ENUM(config_parse_runtime_preserve_mode, exec_preserve_mode, ExecPreserveMode, "Failed to parse runtime directory preserve mode");
140 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_type, service_type, ServiceType, "Failed to parse service type");
141 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_exit_type, service_exit_type, ServiceExitType, "Failed to parse service exit type");
142 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart, service_restart, ServiceRestart, "Failed to parse service restart specifier");
143 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_timeout_failure_mode, service_timeout_failure_mode, ServiceTimeoutFailureMode, "Failed to parse timeout failure mode");
144 DEFINE_CONFIG_PARSE_ENUM(config_parse_socket_bind, socket_address_bind_ipv6_only_or_bool, SocketAddressBindIPv6Only, "Failed to parse bind IPv6 only value");
145 DEFINE_CONFIG_PARSE_ENUM(config_parse_oom_policy, oom_policy, OOMPolicy, "Failed to parse OOM policy");
146 DEFINE_CONFIG_PARSE_ENUM(config_parse_managed_oom_preference, managed_oom_preference, ManagedOOMPreference, "Failed to parse ManagedOOMPreference=");
147 DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_ip_tos, ip_tos, int, -1, "Failed to parse IP TOS value");
148 DEFINE_CONFIG_PARSE_PTR(config_parse_blockio_weight, cg_blkio_weight_parse, uint64_t, "Invalid block IO weight");
149 DEFINE_CONFIG_PARSE_PTR(config_parse_cg_weight, cg_weight_parse, uint64_t, "Invalid weight");
150 DEFINE_CONFIG_PARSE_PTR(config_parse_cg_cpu_weight, cg_cpu_weight_parse, uint64_t, "Invalid CPU weight");
151 static DEFINE_CONFIG_PARSE_PTR(config_parse_cpu_shares_internal, cg_cpu_shares_parse, uint64_t, "Invalid CPU shares");
152 DEFINE_CONFIG_PARSE_PTR(config_parse_exec_mount_flags, mount_propagation_flags_from_string, unsigned long, "Failed to parse mount flag");
153 DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_numa_policy, mpol, int, -1, "Invalid NUMA policy type");
154 DEFINE_CONFIG_PARSE_ENUM(config_parse_status_unit_format, status_unit_format, StatusUnitFormat, "Failed to parse status unit format");
155 DEFINE_CONFIG_PARSE_ENUM_FULL(config_parse_socket_timestamping, socket_timestamping_from_string_harder, SocketTimestamping, "Failed to parse timestamping precision");
156
157 int config_parse_cpu_shares(
158 const char *unit,
159 const char *filename,
160 unsigned line,
161 const char *section,
162 unsigned section_line,
163 const char *lvalue,
164 int ltype,
165 const char *rvalue,
166 void *data,
167 void *userdata) {
168
169 assert(filename);
170 assert(lvalue);
171 assert(rvalue);
172
173
174 log_syntax(unit, LOG_WARNING, filename, line, 0,
175 "Unit uses %s=; please use CPUWeight= instead. Support for %s= will be removed soon.",
176 lvalue, lvalue);
177
178 return config_parse_cpu_shares_internal(unit, filename, line, section, section_line, lvalue, ltype, rvalue, data, userdata);
179 }
180
181 bool contains_instance_specifier_superset(const char *s) {
182 const char *p, *q;
183 bool percent = false;
184
185 assert(s);
186
187 p = strchr(s, '@');
188 if (!p)
189 return false;
190
191 p++; /* Skip '@' */
192
193 q = strrchr(p, '.');
194 if (!q)
195 q = p + strlen(p);
196
197 /* If the string is just the instance specifier, it's not a superset of the instance. */
198 if (memcmp_nn(p, q - p, "%i", strlen("%i")) == 0)
199 return false;
200
201 /* %i, %n and %N all expand to the instance or a superset of it. */
202 for (; p < q; p++) {
203 if (*p == '%')
204 percent = !percent;
205 else if (percent) {
206 if (IN_SET(*p, 'n', 'N', 'i'))
207 return true;
208 percent = false;
209 }
210 }
211
212 return false;
213 }
214
215 /* `name` is the rendered version of `format` via `unit_printf` or similar functions. */
216 int unit_is_likely_recursive_template_dependency(Unit *u, const char *name, const char *format) {
217 const char *fragment_path;
218 int r;
219
220 assert(u);
221 assert(name);
222
223 /* If a template unit has a direct dependency on itself that includes the unit instance as part of
224 * the template instance via a unit specifier (%i, %n or %N), this will almost certainly lead to
225 * infinite recursion as systemd will keep instantiating new instances of the template unit.
226 * https://github.com/systemd/systemd/issues/17602 shows a good example of how this can happen in
227 * practice. To guard against this, we check for templates that depend on themselves and have the
228 * instantiated unit instance included as part of the template instance of the dependency via a
229 * specifier.
230 *
231 * For example, if systemd-notify@.service depends on systemd-notify@%n.service, this will result in
232 * infinite recursion.
233 */
234
235 if (!unit_name_is_valid(name, UNIT_NAME_INSTANCE))
236 return false;
237
238 if (!unit_name_prefix_equal(u->id, name))
239 return false;
240
241 if (u->type != unit_name_to_type(name))
242 return false;
243
244 r = unit_file_find_fragment(u->manager->unit_id_map, u->manager->unit_name_map, name, &fragment_path, NULL);
245 if (r < 0)
246 return r;
247
248 /* Fragment paths should also be equal as a custom fragment for a specific template instance
249 * wouldn't necessarily lead to infinite recursion. */
250 if (!path_equal_ptr(u->fragment_path, fragment_path))
251 return false;
252
253 if (!contains_instance_specifier_superset(format))
254 return false;
255
256 return true;
257 }
258
259 int config_parse_unit_deps(
260 const char *unit,
261 const char *filename,
262 unsigned line,
263 const char *section,
264 unsigned section_line,
265 const char *lvalue,
266 int ltype,
267 const char *rvalue,
268 void *data,
269 void *userdata) {
270
271 UnitDependency d = ltype;
272 Unit *u = userdata;
273
274 assert(filename);
275 assert(lvalue);
276 assert(rvalue);
277
278 for (const char *p = rvalue;;) {
279 _cleanup_free_ char *word = NULL, *k = NULL;
280 int r;
281
282 r = extract_first_word(&p, &word, NULL, EXTRACT_RETAIN_ESCAPE);
283 if (r == 0)
284 return 0;
285 if (r == -ENOMEM)
286 return log_oom();
287 if (r < 0) {
288 log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid syntax, ignoring: %s", rvalue);
289 return 0;
290 }
291
292 r = unit_name_printf(u, word, &k);
293 if (r < 0) {
294 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %m", word);
295 continue;
296 }
297
298 r = unit_is_likely_recursive_template_dependency(u, k, word);
299 if (r < 0) {
300 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to determine if '%s' is a recursive dependency, ignoring: %m", k);
301 continue;
302 }
303 if (r > 0) {
304 log_syntax(unit, LOG_DEBUG, filename, line, 0,
305 "Dropping dependency %s=%s that likely leads to infinite recursion.",
306 unit_dependency_to_string(d), word);
307 continue;
308 }
309
310 r = unit_add_dependency_by_name(u, d, k, true, UNIT_DEPENDENCY_FILE);
311 if (r < 0)
312 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to add dependency on %s, ignoring: %m", k);
313 }
314 }
315
316 int config_parse_obsolete_unit_deps(
317 const char *unit,
318 const char *filename,
319 unsigned line,
320 const char *section,
321 unsigned section_line,
322 const char *lvalue,
323 int ltype,
324 const char *rvalue,
325 void *data,
326 void *userdata) {
327
328 log_syntax(unit, LOG_WARNING, filename, line, 0,
329 "Unit dependency type %s= is obsolete, replacing by %s=, please update your unit file", lvalue, unit_dependency_to_string(ltype));
330
331 return config_parse_unit_deps(unit, filename, line, section, section_line, lvalue, ltype, rvalue, data, userdata);
332 }
333
334 int config_parse_unit_string_printf(
335 const char *unit,
336 const char *filename,
337 unsigned line,
338 const char *section,
339 unsigned section_line,
340 const char *lvalue,
341 int ltype,
342 const char *rvalue,
343 void *data,
344 void *userdata) {
345
346 _cleanup_free_ char *k = NULL;
347 const Unit *u = userdata;
348 int r;
349
350 assert(filename);
351 assert(lvalue);
352 assert(rvalue);
353 assert(u);
354
355 r = unit_full_printf(u, rvalue, &k);
356 if (r < 0) {
357 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue);
358 return 0;
359 }
360
361 return config_parse_string(unit, filename, line, section, section_line, lvalue, ltype, k, data, userdata);
362 }
363
364 int config_parse_unit_strv_printf(
365 const char *unit,
366 const char *filename,
367 unsigned line,
368 const char *section,
369 unsigned section_line,
370 const char *lvalue,
371 int ltype,
372 const char *rvalue,
373 void *data,
374 void *userdata) {
375
376 const Unit *u = userdata;
377 _cleanup_free_ char *k = NULL;
378 int r;
379
380 assert(filename);
381 assert(lvalue);
382 assert(rvalue);
383 assert(u);
384
385 r = unit_full_printf(u, rvalue, &k);
386 if (r < 0) {
387 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue);
388 return 0;
389 }
390
391 return config_parse_strv(unit, filename, line, section, section_line, lvalue, ltype, k, data, userdata);
392 }
393
394 int config_parse_unit_path_printf(
395 const char *unit,
396 const char *filename,
397 unsigned line,
398 const char *section,
399 unsigned section_line,
400 const char *lvalue,
401 int ltype,
402 const char *rvalue,
403 void *data,
404 void *userdata) {
405
406 _cleanup_free_ char *k = NULL;
407 const Unit *u = userdata;
408 int r;
409 bool fatal = ltype;
410
411 assert(filename);
412 assert(lvalue);
413 assert(rvalue);
414 assert(u);
415
416 r = unit_path_printf(u, rvalue, &k);
417 if (r < 0) {
418 log_syntax(unit, fatal ? LOG_ERR : LOG_WARNING, filename, line, r,
419 "Failed to resolve unit specifiers in '%s'%s: %m",
420 rvalue, fatal ? "" : ", ignoring");
421 return fatal ? -ENOEXEC : 0;
422 }
423
424 return config_parse_path(unit, filename, line, section, section_line, lvalue, ltype, k, data, userdata);
425 }
426
427 int config_parse_colon_separated_paths(
428 const char *unit,
429 const char *filename,
430 unsigned line,
431 const char *section,
432 unsigned section_line,
433 const char *lvalue,
434 int ltype,
435 const char *rvalue,
436 void *data,
437 void *userdata) {
438 char ***sv = data;
439 const Unit *u = userdata;
440 int r;
441
442 assert(filename);
443 assert(lvalue);
444 assert(rvalue);
445 assert(data);
446
447 if (isempty(rvalue)) {
448 /* Empty assignment resets the list */
449 *sv = strv_free(*sv);
450 return 0;
451 }
452
453 for (const char *p = rvalue;;) {
454 _cleanup_free_ char *word = NULL, *k = NULL;
455
456 r = extract_first_word(&p, &word, ":", EXTRACT_DONT_COALESCE_SEPARATORS);
457 if (r == -ENOMEM)
458 return log_oom();
459 if (r < 0) {
460 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to extract first word, ignoring: %s", rvalue);
461 return 0;
462 }
463 if (r == 0)
464 break;
465
466 r = unit_path_printf(u, word, &k);
467 if (r < 0) {
468 log_syntax(unit, LOG_WARNING, filename, line, r,
469 "Failed to resolve unit specifiers in '%s', ignoring: %m", word);
470 return 0;
471 }
472
473 r = path_simplify_and_warn(k, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue);
474 if (r < 0)
475 return 0;
476
477 r = strv_consume(sv, TAKE_PTR(k));
478 if (r < 0)
479 return log_oom();
480 }
481
482 return 0;
483 }
484
485 int config_parse_unit_path_strv_printf(
486 const char *unit,
487 const char *filename,
488 unsigned line,
489 const char *section,
490 unsigned section_line,
491 const char *lvalue,
492 int ltype,
493 const char *rvalue,
494 void *data,
495 void *userdata) {
496
497 char ***x = data;
498 const Unit *u = userdata;
499 int r;
500
501 assert(filename);
502 assert(lvalue);
503 assert(rvalue);
504 assert(u);
505
506 if (isempty(rvalue)) {
507 *x = strv_free(*x);
508 return 0;
509 }
510
511 for (const char *p = rvalue;;) {
512 _cleanup_free_ char *word = NULL, *k = NULL;
513
514 r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE);
515 if (r == 0)
516 return 0;
517 if (r == -ENOMEM)
518 return log_oom();
519 if (r < 0) {
520 log_syntax(unit, LOG_WARNING, filename, line, r,
521 "Invalid syntax, ignoring: %s", rvalue);
522 return 0;
523 }
524
525 r = unit_path_printf(u, word, &k);
526 if (r < 0) {
527 log_syntax(unit, LOG_WARNING, filename, line, r,
528 "Failed to resolve unit specifiers in '%s', ignoring: %m", word);
529 return 0;
530 }
531
532 r = path_simplify_and_warn(k, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue);
533 if (r < 0)
534 return 0;
535
536 r = strv_consume(x, TAKE_PTR(k));
537 if (r < 0)
538 return log_oom();
539 }
540 }
541
542 static int patch_var_run(
543 const char *unit,
544 const char *filename,
545 unsigned line,
546 const char *lvalue,
547 char **path) {
548
549 const char *e;
550 char *z;
551
552 e = path_startswith(*path, "/var/run/");
553 if (!e)
554 return 0;
555
556 z = path_join("/run/", e);
557 if (!z)
558 return log_oom();
559
560 log_syntax(unit, LOG_NOTICE, filename, line, 0,
561 "%s= references a path below legacy directory /var/run/, updating %s → %s; "
562 "please update the unit file accordingly.", lvalue, *path, z);
563
564 free_and_replace(*path, z);
565
566 return 1;
567 }
568
569 int config_parse_socket_listen(
570 const char *unit,
571 const char *filename,
572 unsigned line,
573 const char *section,
574 unsigned section_line,
575 const char *lvalue,
576 int ltype,
577 const char *rvalue,
578 void *data,
579 void *userdata) {
580
581 _cleanup_free_ SocketPort *p = NULL;
582 SocketPort *tail;
583 Socket *s;
584 int r;
585
586 assert(filename);
587 assert(lvalue);
588 assert(rvalue);
589 assert(data);
590
591 s = SOCKET(data);
592
593 if (isempty(rvalue)) {
594 /* An empty assignment removes all ports */
595 socket_free_ports(s);
596 return 0;
597 }
598
599 p = new0(SocketPort, 1);
600 if (!p)
601 return log_oom();
602
603 if (ltype != SOCKET_SOCKET) {
604 _cleanup_free_ char *k = NULL;
605
606 r = unit_path_printf(UNIT(s), rvalue, &k);
607 if (r < 0) {
608 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue);
609 return 0;
610 }
611
612 r = path_simplify_and_warn(k, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue);
613 if (r < 0)
614 return 0;
615
616 if (ltype == SOCKET_FIFO) {
617 r = patch_var_run(unit, filename, line, lvalue, &k);
618 if (r < 0)
619 return r;
620 }
621
622 free_and_replace(p->path, k);
623 p->type = ltype;
624
625 } else if (streq(lvalue, "ListenNetlink")) {
626 _cleanup_free_ char *k = NULL;
627
628 r = unit_path_printf(UNIT(s), rvalue, &k);
629 if (r < 0) {
630 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue);
631 return 0;
632 }
633
634 r = socket_address_parse_netlink(&p->address, k);
635 if (r < 0) {
636 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse address value in '%s', ignoring: %m", k);
637 return 0;
638 }
639
640 p->type = SOCKET_SOCKET;
641
642 } else {
643 _cleanup_free_ char *k = NULL;
644
645 r = unit_path_printf(UNIT(s), rvalue, &k);
646 if (r < 0) {
647 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue);
648 return 0;
649 }
650
651 if (k[0] == '/') { /* Only for AF_UNIX file system sockets… */
652 r = patch_var_run(unit, filename, line, lvalue, &k);
653 if (r < 0)
654 return r;
655 }
656
657 r = socket_address_parse_and_warn(&p->address, k);
658 if (r < 0) {
659 if (r != -EAFNOSUPPORT)
660 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse address value in '%s', ignoring: %m", k);
661 return 0;
662 }
663
664 if (streq(lvalue, "ListenStream"))
665 p->address.type = SOCK_STREAM;
666 else if (streq(lvalue, "ListenDatagram"))
667 p->address.type = SOCK_DGRAM;
668 else {
669 assert(streq(lvalue, "ListenSequentialPacket"));
670 p->address.type = SOCK_SEQPACKET;
671 }
672
673 if (socket_address_family(&p->address) != AF_UNIX && p->address.type == SOCK_SEQPACKET) {
674 log_syntax(unit, LOG_WARNING, filename, line, 0, "Address family not supported, ignoring: %s", rvalue);
675 return 0;
676 }
677
678 p->type = SOCKET_SOCKET;
679 }
680
681 p->fd = -1;
682 p->auxiliary_fds = NULL;
683 p->n_auxiliary_fds = 0;
684 p->socket = s;
685
686 LIST_FIND_TAIL(port, s->ports, tail);
687 LIST_INSERT_AFTER(port, s->ports, tail, p);
688
689 p = NULL;
690
691 return 0;
692 }
693
694 int config_parse_exec_nice(
695 const char *unit,
696 const char *filename,
697 unsigned line,
698 const char *section,
699 unsigned section_line,
700 const char *lvalue,
701 int ltype,
702 const char *rvalue,
703 void *data,
704 void *userdata) {
705
706 ExecContext *c = data;
707 int priority, r;
708
709 assert(filename);
710 assert(lvalue);
711 assert(rvalue);
712 assert(data);
713
714 if (isempty(rvalue)) {
715 c->nice_set = false;
716 return 0;
717 }
718
719 r = parse_nice(rvalue, &priority);
720 if (r < 0) {
721 if (r == -ERANGE)
722 log_syntax(unit, LOG_WARNING, filename, line, r, "Nice priority out of range, ignoring: %s", rvalue);
723 else
724 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse nice priority '%s', ignoring: %m", rvalue);
725 return 0;
726 }
727
728 c->nice = priority;
729 c->nice_set = true;
730
731 return 0;
732 }
733
734 int config_parse_exec_oom_score_adjust(
735 const char* unit,
736 const char *filename,
737 unsigned line,
738 const char *section,
739 unsigned section_line,
740 const char *lvalue,
741 int ltype,
742 const char *rvalue,
743 void *data,
744 void *userdata) {
745
746 ExecContext *c = data;
747 int oa, r;
748
749 assert(filename);
750 assert(lvalue);
751 assert(rvalue);
752 assert(data);
753
754 if (isempty(rvalue)) {
755 c->oom_score_adjust_set = false;
756 return 0;
757 }
758
759 r = parse_oom_score_adjust(rvalue, &oa);
760 if (r < 0) {
761 if (r == -ERANGE)
762 log_syntax(unit, LOG_WARNING, filename, line, r, "OOM score adjust value out of range, ignoring: %s", rvalue);
763 else
764 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse the OOM score adjust value '%s', ignoring: %m", rvalue);
765 return 0;
766 }
767
768 c->oom_score_adjust = oa;
769 c->oom_score_adjust_set = true;
770
771 return 0;
772 }
773
774 int config_parse_exec_coredump_filter(
775 const char* unit,
776 const char *filename,
777 unsigned line,
778 const char *section,
779 unsigned section_line,
780 const char *lvalue,
781 int ltype,
782 const char *rvalue,
783 void *data,
784 void *userdata) {
785
786 ExecContext *c = data;
787 int r;
788
789 assert(filename);
790 assert(lvalue);
791 assert(rvalue);
792 assert(data);
793
794 if (isempty(rvalue)) {
795 c->coredump_filter = 0;
796 c->coredump_filter_set = false;
797 return 0;
798 }
799
800 uint64_t f;
801 r = coredump_filter_mask_from_string(rvalue, &f);
802 if (r < 0) {
803 log_syntax(unit, LOG_WARNING, filename, line, r,
804 "Failed to parse the CoredumpFilter=%s, ignoring: %m", rvalue);
805 return 0;
806 }
807
808 c->coredump_filter |= f;
809 c->oom_score_adjust_set = true;
810 return 0;
811 }
812
813 int config_parse_kill_mode(
814 const char* unit,
815 const char *filename,
816 unsigned line,
817 const char *section,
818 unsigned section_line,
819 const char *lvalue,
820 int ltype,
821 const char *rvalue,
822 void *data,
823 void *userdata) {
824
825 KillMode *k = data, m;
826
827 assert(filename);
828 assert(lvalue);
829 assert(rvalue);
830 assert(data);
831
832 if (isempty(rvalue)) {
833 *k = KILL_CONTROL_GROUP;
834 return 0;
835 }
836
837 m = kill_mode_from_string(rvalue);
838 if (m < 0) {
839 log_syntax(unit, LOG_WARNING, filename, line, m,
840 "Failed to parse kill mode specification, ignoring: %s", rvalue);
841 return 0;
842 }
843
844 if (m == KILL_NONE)
845 log_syntax(unit, LOG_WARNING, filename, line, 0,
846 "Unit configured to use KillMode=none. "
847 "This is unsafe, as it disables systemd's process lifecycle management for the service. "
848 "Please update your service to use a safer KillMode=, such as 'mixed' or 'control-group'. "
849 "Support for KillMode=none is deprecated and will eventually be removed.");
850
851 *k = m;
852 return 0;
853 }
854
855 int config_parse_exec(
856 const char *unit,
857 const char *filename,
858 unsigned line,
859 const char *section,
860 unsigned section_line,
861 const char *lvalue,
862 int ltype,
863 const char *rvalue,
864 void *data,
865 void *userdata) {
866
867 ExecCommand **e = data;
868 const Unit *u = userdata;
869 const char *p;
870 bool semicolon;
871 int r;
872
873 assert(filename);
874 assert(lvalue);
875 assert(rvalue);
876 assert(e);
877
878 e += ltype;
879
880 if (isempty(rvalue)) {
881 /* An empty assignment resets the list */
882 *e = exec_command_free_list(*e);
883 return 0;
884 }
885
886 p = rvalue;
887 do {
888 _cleanup_free_ char *path = NULL, *firstword = NULL;
889 ExecCommandFlags flags = 0;
890 bool ignore = false, separate_argv0 = false;
891 _cleanup_free_ ExecCommand *nce = NULL;
892 _cleanup_strv_free_ char **n = NULL;
893 size_t nlen = 0;
894 const char *f;
895
896 semicolon = false;
897
898 r = extract_first_word_and_warn(&p, &firstword, NULL, EXTRACT_UNQUOTE|EXTRACT_CUNESCAPE, unit, filename, line, rvalue);
899 if (r <= 0)
900 return 0;
901
902 /* A lone ";" is a separator. Let's make sure we don't treat it as an executable name. */
903 if (streq(firstword, ";")) {
904 semicolon = true;
905 continue;
906 }
907
908 f = firstword;
909 for (;;) {
910 /* We accept an absolute path as first argument. If it's prefixed with - and the path doesn't
911 * exist, we ignore it instead of erroring out; if it's prefixed with @, we allow overriding of
912 * argv[0]; if it's prefixed with :, we will not do environment variable substitution;
913 * if it's prefixed with +, it will be run with full privileges and no sandboxing; if
914 * it's prefixed with '!' we apply sandboxing, but do not change user/group credentials; if
915 * it's prefixed with '!!', then we apply user/group credentials if the kernel supports ambient
916 * capabilities -- if it doesn't we don't apply the credentials themselves, but do apply most
917 * other sandboxing, with some special exceptions for changing UID.
918 *
919 * The idea is that '!!' may be used to write services that can take benefit of systemd's
920 * UID/GID dropping if the kernel supports ambient creds, but provide an automatic fallback to
921 * privilege dropping within the daemon if the kernel does not offer that. */
922
923 if (*f == '-' && !(flags & EXEC_COMMAND_IGNORE_FAILURE)) {
924 flags |= EXEC_COMMAND_IGNORE_FAILURE;
925 ignore = true;
926 } else if (*f == '@' && !separate_argv0)
927 separate_argv0 = true;
928 else if (*f == ':' && !(flags & EXEC_COMMAND_NO_ENV_EXPAND))
929 flags |= EXEC_COMMAND_NO_ENV_EXPAND;
930 else if (*f == '+' && !(flags & (EXEC_COMMAND_FULLY_PRIVILEGED|EXEC_COMMAND_NO_SETUID|EXEC_COMMAND_AMBIENT_MAGIC)))
931 flags |= EXEC_COMMAND_FULLY_PRIVILEGED;
932 else if (*f == '!' && !(flags & (EXEC_COMMAND_FULLY_PRIVILEGED|EXEC_COMMAND_NO_SETUID|EXEC_COMMAND_AMBIENT_MAGIC)))
933 flags |= EXEC_COMMAND_NO_SETUID;
934 else if (*f == '!' && !(flags & (EXEC_COMMAND_FULLY_PRIVILEGED|EXEC_COMMAND_AMBIENT_MAGIC))) {
935 flags &= ~EXEC_COMMAND_NO_SETUID;
936 flags |= EXEC_COMMAND_AMBIENT_MAGIC;
937 } else
938 break;
939 f++;
940 }
941
942 r = unit_path_printf(u, f, &path);
943 if (r < 0) {
944 log_syntax(unit, ignore ? LOG_WARNING : LOG_ERR, filename, line, r,
945 "Failed to resolve unit specifiers in '%s'%s: %m",
946 f, ignore ? ", ignoring" : "");
947 return ignore ? 0 : -ENOEXEC;
948 }
949
950 if (isempty(path)) {
951 /* First word is either "-" or "@" with no command. */
952 log_syntax(unit, ignore ? LOG_WARNING : LOG_ERR, filename, line, 0,
953 "Empty path in command line%s: '%s'",
954 ignore ? ", ignoring" : "", rvalue);
955 return ignore ? 0 : -ENOEXEC;
956 }
957 if (!string_is_safe(path)) {
958 log_syntax(unit, ignore ? LOG_WARNING : LOG_ERR, filename, line, 0,
959 "Executable name contains special characters%s: %s",
960 ignore ? ", ignoring" : "", path);
961 return ignore ? 0 : -ENOEXEC;
962 }
963 if (endswith(path, "/")) {
964 log_syntax(unit, ignore ? LOG_WARNING : LOG_ERR, filename, line, 0,
965 "Executable path specifies a directory%s: %s",
966 ignore ? ", ignoring" : "", path);
967 return ignore ? 0 : -ENOEXEC;
968 }
969
970 if (!(path_is_absolute(path) ? path_is_valid(path) : filename_is_valid(path))) {
971 log_syntax(unit, ignore ? LOG_WARNING : LOG_ERR, filename, line, 0,
972 "Neither a valid executable name nor an absolute path%s: %s",
973 ignore ? ", ignoring" : "", path);
974 return ignore ? 0 : -ENOEXEC;
975 }
976
977 if (!separate_argv0) {
978 char *w = NULL;
979
980 if (!GREEDY_REALLOC0(n, nlen + 2))
981 return log_oom();
982
983 w = strdup(path);
984 if (!w)
985 return log_oom();
986 n[nlen++] = w;
987 n[nlen] = NULL;
988 }
989
990 path_simplify(path);
991
992 while (!isempty(p)) {
993 _cleanup_free_ char *word = NULL, *resolved = NULL;
994
995 /* Check explicitly for an unquoted semicolon as
996 * command separator token. */
997 if (p[0] == ';' && (!p[1] || strchr(WHITESPACE, p[1]))) {
998 p++;
999 p += strspn(p, WHITESPACE);
1000 semicolon = true;
1001 break;
1002 }
1003
1004 /* Check for \; explicitly, to not confuse it with \\; or "\;" or "\\;" etc.
1005 * extract_first_word() would return the same for all of those. */
1006 if (p[0] == '\\' && p[1] == ';' && (!p[2] || strchr(WHITESPACE, p[2]))) {
1007 char *w;
1008
1009 p += 2;
1010 p += strspn(p, WHITESPACE);
1011
1012 if (!GREEDY_REALLOC0(n, nlen + 2))
1013 return log_oom();
1014
1015 w = strdup(";");
1016 if (!w)
1017 return log_oom();
1018 n[nlen++] = w;
1019 n[nlen] = NULL;
1020 continue;
1021 }
1022
1023 r = extract_first_word_and_warn(&p, &word, NULL, EXTRACT_UNQUOTE|EXTRACT_CUNESCAPE, unit, filename, line, rvalue);
1024 if (r == 0)
1025 break;
1026 if (r < 0)
1027 return ignore ? 0 : -ENOEXEC;
1028
1029 r = unit_full_printf(u, word, &resolved);
1030 if (r < 0) {
1031 log_syntax(unit, ignore ? LOG_WARNING : LOG_ERR, filename, line, r,
1032 "Failed to resolve unit specifiers in %s%s: %m",
1033 word, ignore ? ", ignoring" : "");
1034 return ignore ? 0 : -ENOEXEC;
1035 }
1036
1037 if (!GREEDY_REALLOC(n, nlen + 2))
1038 return log_oom();
1039
1040 n[nlen++] = TAKE_PTR(resolved);
1041 n[nlen] = NULL;
1042 }
1043
1044 if (!n || !n[0]) {
1045 log_syntax(unit, ignore ? LOG_WARNING : LOG_ERR, filename, line, 0,
1046 "Empty executable name or zeroeth argument%s: %s",
1047 ignore ? ", ignoring" : "", rvalue);
1048 return ignore ? 0 : -ENOEXEC;
1049 }
1050
1051 nce = new0(ExecCommand, 1);
1052 if (!nce)
1053 return log_oom();
1054
1055 nce->argv = TAKE_PTR(n);
1056 nce->path = TAKE_PTR(path);
1057 nce->flags = flags;
1058
1059 exec_command_append_list(e, nce);
1060
1061 /* Do not _cleanup_free_ these. */
1062 nce = NULL;
1063
1064 rvalue = p;
1065 } while (semicolon);
1066
1067 return 0;
1068 }
1069
1070 int config_parse_socket_bindtodevice(
1071 const char* unit,
1072 const char *filename,
1073 unsigned line,
1074 const char *section,
1075 unsigned section_line,
1076 const char *lvalue,
1077 int ltype,
1078 const char *rvalue,
1079 void *data,
1080 void *userdata) {
1081
1082 Socket *s = data;
1083
1084 assert(filename);
1085 assert(lvalue);
1086 assert(rvalue);
1087 assert(data);
1088
1089 if (isempty(rvalue) || streq(rvalue, "*")) {
1090 s->bind_to_device = mfree(s->bind_to_device);
1091 return 0;
1092 }
1093
1094 if (!ifname_valid(rvalue)) {
1095 log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid interface name, ignoring: %s", rvalue);
1096 return 0;
1097 }
1098
1099 return free_and_strdup_warn(&s->bind_to_device, rvalue);
1100 }
1101
1102 int config_parse_exec_input(
1103 const char *unit,
1104 const char *filename,
1105 unsigned line,
1106 const char *section,
1107 unsigned section_line,
1108 const char *lvalue,
1109 int ltype,
1110 const char *rvalue,
1111 void *data,
1112 void *userdata) {
1113
1114 ExecContext *c = data;
1115 const Unit *u = userdata;
1116 const char *n;
1117 ExecInput ei;
1118 int r;
1119
1120 assert(data);
1121 assert(filename);
1122 assert(line);
1123 assert(rvalue);
1124
1125 n = startswith(rvalue, "fd:");
1126 if (n) {
1127 _cleanup_free_ char *resolved = NULL;
1128
1129 r = unit_fd_printf(u, n, &resolved);
1130 if (r < 0) {
1131 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %m", n);
1132 return 0;
1133 }
1134
1135 if (isempty(resolved))
1136 resolved = mfree(resolved);
1137 else if (!fdname_is_valid(resolved)) {
1138 log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid file descriptor name, ignoring: %s", resolved);
1139 return 0;
1140 }
1141
1142 free_and_replace(c->stdio_fdname[STDIN_FILENO], resolved);
1143
1144 ei = EXEC_INPUT_NAMED_FD;
1145
1146 } else if ((n = startswith(rvalue, "file:"))) {
1147 _cleanup_free_ char *resolved = NULL;
1148
1149 r = unit_path_printf(u, n, &resolved);
1150 if (r < 0) {
1151 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %m", n);
1152 return 0;
1153 }
1154
1155 r = path_simplify_and_warn(resolved, PATH_CHECK_ABSOLUTE | PATH_CHECK_FATAL, unit, filename, line, lvalue);
1156 if (r < 0)
1157 return 0;
1158
1159 free_and_replace(c->stdio_file[STDIN_FILENO], resolved);
1160
1161 ei = EXEC_INPUT_FILE;
1162
1163 } else {
1164 ei = exec_input_from_string(rvalue);
1165 if (ei < 0) {
1166 log_syntax(unit, LOG_WARNING, filename, line, ei, "Failed to parse input specifier, ignoring: %s", rvalue);
1167 return 0;
1168 }
1169 }
1170
1171 c->std_input = ei;
1172 return 0;
1173 }
1174
1175 int config_parse_exec_input_text(
1176 const char *unit,
1177 const char *filename,
1178 unsigned line,
1179 const char *section,
1180 unsigned section_line,
1181 const char *lvalue,
1182 int ltype,
1183 const char *rvalue,
1184 void *data,
1185 void *userdata) {
1186
1187 _cleanup_free_ char *unescaped = NULL, *resolved = NULL;
1188 ExecContext *c = data;
1189 const Unit *u = userdata;
1190 int r;
1191
1192 assert(data);
1193 assert(filename);
1194 assert(line);
1195 assert(rvalue);
1196
1197 if (isempty(rvalue)) {
1198 /* Reset if the empty string is assigned */
1199 c->stdin_data = mfree(c->stdin_data);
1200 c->stdin_data_size = 0;
1201 return 0;
1202 }
1203
1204 ssize_t l = cunescape(rvalue, 0, &unescaped);
1205 if (l < 0) {
1206 log_syntax(unit, LOG_WARNING, filename, line, l,
1207 "Failed to decode C escaped text '%s', ignoring: %m", rvalue);
1208 return 0;
1209 }
1210
1211 r = unit_full_printf_full(u, unescaped, EXEC_STDIN_DATA_MAX, &resolved);
1212 if (r < 0) {
1213 log_syntax(unit, LOG_WARNING, filename, line, r,
1214 "Failed to resolve unit specifiers in '%s', ignoring: %m", unescaped);
1215 return 0;
1216 }
1217
1218 size_t sz = strlen(resolved);
1219 if (c->stdin_data_size + sz + 1 < c->stdin_data_size || /* check for overflow */
1220 c->stdin_data_size + sz + 1 > EXEC_STDIN_DATA_MAX) {
1221 log_syntax(unit, LOG_WARNING, filename, line, 0,
1222 "Standard input data too large (%zu), maximum of %zu permitted, ignoring.",
1223 c->stdin_data_size + sz, (size_t) EXEC_STDIN_DATA_MAX);
1224 return 0;
1225 }
1226
1227 void *p = realloc(c->stdin_data, c->stdin_data_size + sz + 1);
1228 if (!p)
1229 return log_oom();
1230
1231 *((char*) mempcpy((char*) p + c->stdin_data_size, resolved, sz)) = '\n';
1232
1233 c->stdin_data = p;
1234 c->stdin_data_size += sz + 1;
1235
1236 return 0;
1237 }
1238
1239 int config_parse_exec_input_data(
1240 const char *unit,
1241 const char *filename,
1242 unsigned line,
1243 const char *section,
1244 unsigned section_line,
1245 const char *lvalue,
1246 int ltype,
1247 const char *rvalue,
1248 void *data,
1249 void *userdata) {
1250
1251 _cleanup_free_ void *p = NULL;
1252 ExecContext *c = data;
1253 size_t sz;
1254 void *q;
1255 int r;
1256
1257 assert(data);
1258 assert(filename);
1259 assert(line);
1260 assert(rvalue);
1261
1262 if (isempty(rvalue)) {
1263 /* Reset if the empty string is assigned */
1264 c->stdin_data = mfree(c->stdin_data);
1265 c->stdin_data_size = 0;
1266 return 0;
1267 }
1268
1269 r = unbase64mem(rvalue, SIZE_MAX, &p, &sz);
1270 if (r < 0) {
1271 log_syntax(unit, LOG_WARNING, filename, line, r,
1272 "Failed to decode base64 data, ignoring: %s", rvalue);
1273 return 0;
1274 }
1275
1276 assert(sz > 0);
1277
1278 if (c->stdin_data_size + sz < c->stdin_data_size || /* check for overflow */
1279 c->stdin_data_size + sz > EXEC_STDIN_DATA_MAX) {
1280 log_syntax(unit, LOG_WARNING, filename, line, 0,
1281 "Standard input data too large (%zu), maximum of %zu permitted, ignoring.",
1282 c->stdin_data_size + sz, (size_t) EXEC_STDIN_DATA_MAX);
1283 return 0;
1284 }
1285
1286 q = realloc(c->stdin_data, c->stdin_data_size + sz);
1287 if (!q)
1288 return log_oom();
1289
1290 memcpy((uint8_t*) q + c->stdin_data_size, p, sz);
1291
1292 c->stdin_data = q;
1293 c->stdin_data_size += sz;
1294
1295 return 0;
1296 }
1297
1298 int config_parse_exec_output(
1299 const char *unit,
1300 const char *filename,
1301 unsigned line,
1302 const char *section,
1303 unsigned section_line,
1304 const char *lvalue,
1305 int ltype,
1306 const char *rvalue,
1307 void *data,
1308 void *userdata) {
1309
1310 _cleanup_free_ char *resolved = NULL;
1311 const char *n;
1312 ExecContext *c = data;
1313 const Unit *u = userdata;
1314 bool obsolete = false;
1315 ExecOutput eo;
1316 int r;
1317
1318 assert(data);
1319 assert(filename);
1320 assert(line);
1321 assert(lvalue);
1322 assert(rvalue);
1323
1324 n = startswith(rvalue, "fd:");
1325 if (n) {
1326 r = unit_fd_printf(u, n, &resolved);
1327 if (r < 0) {
1328 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in %s: %m", n);
1329 return 0;
1330 }
1331
1332 if (isempty(resolved))
1333 resolved = mfree(resolved);
1334 else if (!fdname_is_valid(resolved)) {
1335 log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid file descriptor name, ignoring: %s", resolved);
1336 return 0;
1337 }
1338
1339 eo = EXEC_OUTPUT_NAMED_FD;
1340
1341 } else if (streq(rvalue, "syslog")) {
1342 eo = EXEC_OUTPUT_JOURNAL;
1343 obsolete = true;
1344
1345 } else if (streq(rvalue, "syslog+console")) {
1346 eo = EXEC_OUTPUT_JOURNAL_AND_CONSOLE;
1347 obsolete = true;
1348
1349 } else if ((n = startswith(rvalue, "file:"))) {
1350
1351 r = unit_path_printf(u, n, &resolved);
1352 if (r < 0) {
1353 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in %s, ignoring: %m", n);
1354 return 0;
1355 }
1356
1357 r = path_simplify_and_warn(resolved, PATH_CHECK_ABSOLUTE | PATH_CHECK_FATAL, unit, filename, line, lvalue);
1358 if (r < 0)
1359 return 0;
1360
1361 eo = EXEC_OUTPUT_FILE;
1362
1363 } else if ((n = startswith(rvalue, "append:"))) {
1364
1365 r = unit_path_printf(u, n, &resolved);
1366 if (r < 0) {
1367 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in %s, ignoring: %m", n);
1368 return 0;
1369 }
1370
1371 r = path_simplify_and_warn(resolved, PATH_CHECK_ABSOLUTE | PATH_CHECK_FATAL, unit, filename, line, lvalue);
1372 if (r < 0)
1373 return 0;
1374
1375 eo = EXEC_OUTPUT_FILE_APPEND;
1376
1377 } else if ((n = startswith(rvalue, "truncate:"))) {
1378
1379 r = unit_path_printf(u, n, &resolved);
1380 if (r < 0) {
1381 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in %s, ignoring: %m", n);
1382 return 0;
1383 }
1384
1385 r = path_simplify_and_warn(resolved, PATH_CHECK_ABSOLUTE | PATH_CHECK_FATAL, unit, filename, line, lvalue);
1386 if (r < 0)
1387 return 0;
1388
1389 eo = EXEC_OUTPUT_FILE_TRUNCATE;
1390 } else {
1391 eo = exec_output_from_string(rvalue);
1392 if (eo < 0) {
1393 log_syntax(unit, LOG_WARNING, filename, line, eo, "Failed to parse output specifier, ignoring: %s", rvalue);
1394 return 0;
1395 }
1396 }
1397
1398 if (obsolete)
1399 log_syntax(unit, LOG_NOTICE, filename, line, 0,
1400 "Standard output type %s is obsolete, automatically updating to %s. Please update your unit file, and consider removing the setting altogether.",
1401 rvalue, exec_output_to_string(eo));
1402
1403 if (streq(lvalue, "StandardOutput")) {
1404 if (eo == EXEC_OUTPUT_NAMED_FD)
1405 free_and_replace(c->stdio_fdname[STDOUT_FILENO], resolved);
1406 else
1407 free_and_replace(c->stdio_file[STDOUT_FILENO], resolved);
1408
1409 c->std_output = eo;
1410
1411 } else {
1412 assert(streq(lvalue, "StandardError"));
1413
1414 if (eo == EXEC_OUTPUT_NAMED_FD)
1415 free_and_replace(c->stdio_fdname[STDERR_FILENO], resolved);
1416 else
1417 free_and_replace(c->stdio_file[STDERR_FILENO], resolved);
1418
1419 c->std_error = eo;
1420 }
1421
1422 return 0;
1423 }
1424
1425 int config_parse_exec_io_class(const char *unit,
1426 const char *filename,
1427 unsigned line,
1428 const char *section,
1429 unsigned section_line,
1430 const char *lvalue,
1431 int ltype,
1432 const char *rvalue,
1433 void *data,
1434 void *userdata) {
1435
1436 ExecContext *c = data;
1437 int x;
1438
1439 assert(filename);
1440 assert(lvalue);
1441 assert(rvalue);
1442 assert(data);
1443
1444 if (isempty(rvalue)) {
1445 c->ioprio_set = false;
1446 c->ioprio = IOPRIO_DEFAULT_CLASS_AND_PRIO;
1447 return 0;
1448 }
1449
1450 x = ioprio_class_from_string(rvalue);
1451 if (x < 0) {
1452 log_syntax(unit, LOG_WARNING, filename, line, x, "Failed to parse IO scheduling class, ignoring: %s", rvalue);
1453 return 0;
1454 }
1455
1456 c->ioprio = ioprio_normalize(ioprio_prio_value(x, ioprio_prio_data(c->ioprio)));
1457 c->ioprio_set = true;
1458
1459 return 0;
1460 }
1461
1462 int config_parse_exec_io_priority(const char *unit,
1463 const char *filename,
1464 unsigned line,
1465 const char *section,
1466 unsigned section_line,
1467 const char *lvalue,
1468 int ltype,
1469 const char *rvalue,
1470 void *data,
1471 void *userdata) {
1472
1473 ExecContext *c = data;
1474 int i, r;
1475
1476 assert(filename);
1477 assert(lvalue);
1478 assert(rvalue);
1479 assert(data);
1480
1481 if (isempty(rvalue)) {
1482 c->ioprio_set = false;
1483 c->ioprio = IOPRIO_DEFAULT_CLASS_AND_PRIO;
1484 return 0;
1485 }
1486
1487 r = ioprio_parse_priority(rvalue, &i);
1488 if (r < 0) {
1489 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse IO priority, ignoring: %s", rvalue);
1490 return 0;
1491 }
1492
1493 c->ioprio = ioprio_normalize(ioprio_prio_value(ioprio_prio_class(c->ioprio), i));
1494 c->ioprio_set = true;
1495
1496 return 0;
1497 }
1498
1499 int config_parse_exec_cpu_sched_policy(const char *unit,
1500 const char *filename,
1501 unsigned line,
1502 const char *section,
1503 unsigned section_line,
1504 const char *lvalue,
1505 int ltype,
1506 const char *rvalue,
1507 void *data,
1508 void *userdata) {
1509
1510 ExecContext *c = data;
1511 int x;
1512
1513 assert(filename);
1514 assert(lvalue);
1515 assert(rvalue);
1516 assert(data);
1517
1518 if (isempty(rvalue)) {
1519 c->cpu_sched_set = false;
1520 c->cpu_sched_policy = SCHED_OTHER;
1521 c->cpu_sched_priority = 0;
1522 return 0;
1523 }
1524
1525 x = sched_policy_from_string(rvalue);
1526 if (x < 0) {
1527 log_syntax(unit, LOG_WARNING, filename, line, x, "Failed to parse CPU scheduling policy, ignoring: %s", rvalue);
1528 return 0;
1529 }
1530
1531 c->cpu_sched_policy = x;
1532 /* Moving to or from real-time policy? We need to adjust the priority */
1533 c->cpu_sched_priority = CLAMP(c->cpu_sched_priority, sched_get_priority_min(x), sched_get_priority_max(x));
1534 c->cpu_sched_set = true;
1535
1536 return 0;
1537 }
1538
1539 int config_parse_exec_mount_apivfs(const char *unit,
1540 const char *filename,
1541 unsigned line,
1542 const char *section,
1543 unsigned section_line,
1544 const char *lvalue,
1545 int ltype,
1546 const char *rvalue,
1547 void *data,
1548 void *userdata) {
1549
1550 ExecContext *c = data;
1551 int k;
1552
1553 assert(filename);
1554 assert(lvalue);
1555 assert(rvalue);
1556 assert(data);
1557
1558 if (isempty(rvalue)) {
1559 c->mount_apivfs_set = false;
1560 c->mount_apivfs = false;
1561 return 0;
1562 }
1563
1564 k = parse_boolean(rvalue);
1565 if (k < 0) {
1566 log_syntax(unit, LOG_WARNING, filename, line, k,
1567 "Failed to parse boolean value, ignoring: %s",
1568 rvalue);
1569 return 0;
1570 }
1571
1572 c->mount_apivfs_set = true;
1573 c->mount_apivfs = k;
1574 return 0;
1575 }
1576
1577 int config_parse_numa_mask(const char *unit,
1578 const char *filename,
1579 unsigned line,
1580 const char *section,
1581 unsigned section_line,
1582 const char *lvalue,
1583 int ltype,
1584 const char *rvalue,
1585 void *data,
1586 void *userdata) {
1587 int r;
1588 NUMAPolicy *p = data;
1589
1590 assert(filename);
1591 assert(lvalue);
1592 assert(rvalue);
1593 assert(data);
1594
1595 if (streq(rvalue, "all")) {
1596 r = numa_mask_add_all(&p->nodes);
1597 if (r < 0)
1598 log_syntax(unit, LOG_WARNING, filename, line, r,
1599 "Failed to create NUMA mask representing \"all\" NUMA nodes, ignoring: %m");
1600 } else {
1601 r = parse_cpu_set_extend(rvalue, &p->nodes, true, unit, filename, line, lvalue);
1602 if (r < 0)
1603 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse NUMA node mask, ignoring: %s", rvalue);
1604 }
1605
1606 return 0;
1607 }
1608
1609 int config_parse_exec_cpu_sched_prio(const char *unit,
1610 const char *filename,
1611 unsigned line,
1612 const char *section,
1613 unsigned section_line,
1614 const char *lvalue,
1615 int ltype,
1616 const char *rvalue,
1617 void *data,
1618 void *userdata) {
1619
1620 ExecContext *c = data;
1621 int i, min, max, r;
1622
1623 assert(filename);
1624 assert(lvalue);
1625 assert(rvalue);
1626 assert(data);
1627
1628 r = safe_atoi(rvalue, &i);
1629 if (r < 0) {
1630 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse CPU scheduling priority, ignoring: %s", rvalue);
1631 return 0;
1632 }
1633
1634 /* On Linux RR/FIFO range from 1 to 99 and OTHER/BATCH may only be 0 */
1635 min = sched_get_priority_min(c->cpu_sched_policy);
1636 max = sched_get_priority_max(c->cpu_sched_policy);
1637
1638 if (i < min || i > max) {
1639 log_syntax(unit, LOG_WARNING, filename, line, 0, "CPU scheduling priority is out of range, ignoring: %s", rvalue);
1640 return 0;
1641 }
1642
1643 c->cpu_sched_priority = i;
1644 c->cpu_sched_set = true;
1645
1646 return 0;
1647 }
1648
1649 int config_parse_root_image_options(
1650 const char *unit,
1651 const char *filename,
1652 unsigned line,
1653 const char *section,
1654 unsigned section_line,
1655 const char *lvalue,
1656 int ltype,
1657 const char *rvalue,
1658 void *data,
1659 void *userdata) {
1660
1661 _cleanup_(mount_options_free_allp) MountOptions *options = NULL;
1662 _cleanup_strv_free_ char **l = NULL;
1663 ExecContext *c = data;
1664 const Unit *u = userdata;
1665 int r;
1666
1667 assert(filename);
1668 assert(lvalue);
1669 assert(rvalue);
1670 assert(data);
1671
1672 if (isempty(rvalue)) {
1673 c->root_image_options = mount_options_free_all(c->root_image_options);
1674 return 0;
1675 }
1676
1677 r = strv_split_colon_pairs(&l, rvalue);
1678 if (r == -ENOMEM)
1679 return log_oom();
1680 if (r < 0) {
1681 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse %s, ignoring: %s", lvalue, rvalue);
1682 return 0;
1683 }
1684
1685 STRV_FOREACH_PAIR(first, second, l) {
1686 MountOptions *o = NULL;
1687 _cleanup_free_ char *mount_options_resolved = NULL;
1688 const char *mount_options = NULL, *partition = "root";
1689 PartitionDesignator partition_designator;
1690
1691 /* Format is either 'root:foo' or 'foo' (root is implied) */
1692 if (!isempty(*second)) {
1693 partition = *first;
1694 mount_options = *second;
1695 } else
1696 mount_options = *first;
1697
1698 partition_designator = partition_designator_from_string(partition);
1699 if (partition_designator < 0) {
1700 log_syntax(unit, LOG_WARNING, filename, line, partition_designator,
1701 "Invalid partition name %s, ignoring", partition);
1702 continue;
1703 }
1704 r = unit_full_printf(u, mount_options, &mount_options_resolved);
1705 if (r < 0) {
1706 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in %s, ignoring: %m", mount_options);
1707 continue;
1708 }
1709
1710 o = new(MountOptions, 1);
1711 if (!o)
1712 return log_oom();
1713 *o = (MountOptions) {
1714 .partition_designator = partition_designator,
1715 .options = TAKE_PTR(mount_options_resolved),
1716 };
1717 LIST_APPEND(mount_options, options, TAKE_PTR(o));
1718 }
1719
1720 if (options)
1721 LIST_JOIN(mount_options, c->root_image_options, options);
1722 else
1723 /* empty spaces/separators only */
1724 c->root_image_options = mount_options_free_all(c->root_image_options);
1725
1726 return 0;
1727 }
1728
1729 int config_parse_exec_root_hash(
1730 const char *unit,
1731 const char *filename,
1732 unsigned line,
1733 const char *section,
1734 unsigned section_line,
1735 const char *lvalue,
1736 int ltype,
1737 const char *rvalue,
1738 void *data,
1739 void *userdata) {
1740
1741 _cleanup_free_ void *roothash_decoded = NULL;
1742 ExecContext *c = data;
1743 size_t roothash_decoded_size = 0;
1744 int r;
1745
1746 assert(data);
1747 assert(filename);
1748 assert(line);
1749 assert(rvalue);
1750
1751 if (isempty(rvalue)) {
1752 /* Reset if the empty string is assigned */
1753 c->root_hash_path = mfree(c->root_hash_path);
1754 c->root_hash = mfree(c->root_hash);
1755 c->root_hash_size = 0;
1756 return 0;
1757 }
1758
1759 if (path_is_absolute(rvalue)) {
1760 /* We have the path to a roothash to load and decode, eg: RootHash=/foo/bar.roothash */
1761 _cleanup_free_ char *p = NULL;
1762
1763 p = strdup(rvalue);
1764 if (!p)
1765 return -ENOMEM;
1766
1767 free_and_replace(c->root_hash_path, p);
1768 c->root_hash = mfree(c->root_hash);
1769 c->root_hash_size = 0;
1770 return 0;
1771 }
1772
1773 /* We have a roothash to decode, eg: RootHash=012345789abcdef */
1774 r = unhexmem(rvalue, strlen(rvalue), &roothash_decoded, &roothash_decoded_size);
1775 if (r < 0) {
1776 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to decode RootHash=, ignoring: %s", rvalue);
1777 return 0;
1778 }
1779 if (roothash_decoded_size < sizeof(sd_id128_t)) {
1780 log_syntax(unit, LOG_WARNING, filename, line, 0, "RootHash= is too short, ignoring: %s", rvalue);
1781 return 0;
1782 }
1783
1784 free_and_replace(c->root_hash, roothash_decoded);
1785 c->root_hash_size = roothash_decoded_size;
1786 c->root_hash_path = mfree(c->root_hash_path);
1787
1788 return 0;
1789 }
1790
1791 int config_parse_exec_root_hash_sig(
1792 const char *unit,
1793 const char *filename,
1794 unsigned line,
1795 const char *section,
1796 unsigned section_line,
1797 const char *lvalue,
1798 int ltype,
1799 const char *rvalue,
1800 void *data,
1801 void *userdata) {
1802
1803 _cleanup_free_ void *roothash_sig_decoded = NULL;
1804 char *value;
1805 ExecContext *c = data;
1806 size_t roothash_sig_decoded_size = 0;
1807 int r;
1808
1809 assert(data);
1810 assert(filename);
1811 assert(line);
1812 assert(rvalue);
1813
1814 if (isempty(rvalue)) {
1815 /* Reset if the empty string is assigned */
1816 c->root_hash_sig_path = mfree(c->root_hash_sig_path);
1817 c->root_hash_sig = mfree(c->root_hash_sig);
1818 c->root_hash_sig_size = 0;
1819 return 0;
1820 }
1821
1822 if (path_is_absolute(rvalue)) {
1823 /* We have the path to a roothash signature to load and decode, eg: RootHashSignature=/foo/bar.roothash.p7s */
1824 _cleanup_free_ char *p = NULL;
1825
1826 p = strdup(rvalue);
1827 if (!p)
1828 return log_oom();
1829
1830 free_and_replace(c->root_hash_sig_path, p);
1831 c->root_hash_sig = mfree(c->root_hash_sig);
1832 c->root_hash_sig_size = 0;
1833 return 0;
1834 }
1835
1836 if (!(value = startswith(rvalue, "base64:"))) {
1837 log_syntax(unit, LOG_WARNING, filename, line, 0,
1838 "Failed to decode RootHashSignature=, not a path but doesn't start with 'base64:', ignoring: %s", rvalue);
1839 return 0;
1840 }
1841
1842 /* We have a roothash signature to decode, eg: RootHashSignature=base64:012345789abcdef */
1843 r = unbase64mem(value, strlen(value), &roothash_sig_decoded, &roothash_sig_decoded_size);
1844 if (r < 0) {
1845 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to decode RootHashSignature=, ignoring: %s", rvalue);
1846 return 0;
1847 }
1848
1849 free_and_replace(c->root_hash_sig, roothash_sig_decoded);
1850 c->root_hash_sig_size = roothash_sig_decoded_size;
1851 c->root_hash_sig_path = mfree(c->root_hash_sig_path);
1852
1853 return 0;
1854 }
1855
1856 int config_parse_exec_cpu_affinity(
1857 const char *unit,
1858 const char *filename,
1859 unsigned line,
1860 const char *section,
1861 unsigned section_line,
1862 const char *lvalue,
1863 int ltype,
1864 const char *rvalue,
1865 void *data,
1866 void *userdata) {
1867
1868 ExecContext *c = data;
1869 const Unit *u = userdata;
1870 _cleanup_free_ char *k = NULL;
1871 int r;
1872
1873 assert(filename);
1874 assert(lvalue);
1875 assert(rvalue);
1876 assert(data);
1877
1878 if (streq(rvalue, "numa")) {
1879 c->cpu_affinity_from_numa = true;
1880 cpu_set_reset(&c->cpu_set);
1881
1882 return 0;
1883 }
1884
1885 r = unit_full_printf(u, rvalue, &k);
1886 if (r < 0) {
1887 log_syntax(unit, LOG_WARNING, filename, line, r,
1888 "Failed to resolve unit specifiers in '%s', ignoring: %m",
1889 rvalue);
1890 return 0;
1891 }
1892
1893 r = parse_cpu_set_extend(k, &c->cpu_set, true, unit, filename, line, lvalue);
1894 if (r >= 0)
1895 c->cpu_affinity_from_numa = false;
1896
1897 return 0;
1898 }
1899
1900 int config_parse_capability_set(
1901 const char *unit,
1902 const char *filename,
1903 unsigned line,
1904 const char *section,
1905 unsigned section_line,
1906 const char *lvalue,
1907 int ltype,
1908 const char *rvalue,
1909 void *data,
1910 void *userdata) {
1911
1912 uint64_t *capability_set = data;
1913 uint64_t sum = 0, initial = 0;
1914 bool invert = false;
1915 int r;
1916
1917 assert(filename);
1918 assert(lvalue);
1919 assert(rvalue);
1920 assert(data);
1921
1922 if (rvalue[0] == '~') {
1923 invert = true;
1924 rvalue++;
1925 }
1926
1927 if (streq(lvalue, "CapabilityBoundingSet"))
1928 initial = CAP_ALL; /* initialized to all bits on */
1929 /* else "AmbientCapabilities" initialized to all bits off */
1930
1931 r = capability_set_from_string(rvalue, &sum);
1932 if (r < 0) {
1933 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse %s= specifier '%s', ignoring: %m", lvalue, rvalue);
1934 return 0;
1935 }
1936
1937 if (sum == 0 || *capability_set == initial)
1938 /* "", "~" or uninitialized data -> replace */
1939 *capability_set = invert ? ~sum : sum;
1940 else {
1941 /* previous data -> merge */
1942 if (invert)
1943 *capability_set &= ~sum;
1944 else
1945 *capability_set |= sum;
1946 }
1947
1948 return 0;
1949 }
1950
1951 int config_parse_exec_selinux_context(
1952 const char *unit,
1953 const char *filename,
1954 unsigned line,
1955 const char *section,
1956 unsigned section_line,
1957 const char *lvalue,
1958 int ltype,
1959 const char *rvalue,
1960 void *data,
1961 void *userdata) {
1962
1963 ExecContext *c = data;
1964 const Unit *u = userdata;
1965 bool ignore;
1966 char *k;
1967 int r;
1968
1969 assert(filename);
1970 assert(lvalue);
1971 assert(rvalue);
1972 assert(data);
1973
1974 if (isempty(rvalue)) {
1975 c->selinux_context = mfree(c->selinux_context);
1976 c->selinux_context_ignore = false;
1977 return 0;
1978 }
1979
1980 if (rvalue[0] == '-') {
1981 ignore = true;
1982 rvalue++;
1983 } else
1984 ignore = false;
1985
1986 r = unit_full_printf(u, rvalue, &k);
1987 if (r < 0) {
1988 log_syntax(unit, ignore ? LOG_WARNING : LOG_ERR, filename, line, r,
1989 "Failed to resolve unit specifiers in '%s'%s: %m",
1990 rvalue, ignore ? ", ignoring" : "");
1991 return ignore ? 0 : -ENOEXEC;
1992 }
1993
1994 free_and_replace(c->selinux_context, k);
1995 c->selinux_context_ignore = ignore;
1996
1997 return 0;
1998 }
1999
2000 int config_parse_exec_apparmor_profile(
2001 const char *unit,
2002 const char *filename,
2003 unsigned line,
2004 const char *section,
2005 unsigned section_line,
2006 const char *lvalue,
2007 int ltype,
2008 const char *rvalue,
2009 void *data,
2010 void *userdata) {
2011
2012 ExecContext *c = data;
2013 const Unit *u = userdata;
2014 bool ignore;
2015 char *k;
2016 int r;
2017
2018 assert(filename);
2019 assert(lvalue);
2020 assert(rvalue);
2021 assert(data);
2022
2023 if (isempty(rvalue)) {
2024 c->apparmor_profile = mfree(c->apparmor_profile);
2025 c->apparmor_profile_ignore = false;
2026 return 0;
2027 }
2028
2029 if (rvalue[0] == '-') {
2030 ignore = true;
2031 rvalue++;
2032 } else
2033 ignore = false;
2034
2035 r = unit_full_printf(u, rvalue, &k);
2036 if (r < 0) {
2037 log_syntax(unit, ignore ? LOG_WARNING : LOG_ERR, filename, line, r,
2038 "Failed to resolve unit specifiers in '%s'%s: %m",
2039 rvalue, ignore ? ", ignoring" : "");
2040 return ignore ? 0 : -ENOEXEC;
2041 }
2042
2043 free_and_replace(c->apparmor_profile, k);
2044 c->apparmor_profile_ignore = ignore;
2045
2046 return 0;
2047 }
2048
2049 int config_parse_exec_smack_process_label(
2050 const char *unit,
2051 const char *filename,
2052 unsigned line,
2053 const char *section,
2054 unsigned section_line,
2055 const char *lvalue,
2056 int ltype,
2057 const char *rvalue,
2058 void *data,
2059 void *userdata) {
2060
2061 ExecContext *c = data;
2062 const Unit *u = userdata;
2063 bool ignore;
2064 char *k;
2065 int r;
2066
2067 assert(filename);
2068 assert(lvalue);
2069 assert(rvalue);
2070 assert(data);
2071
2072 if (isempty(rvalue)) {
2073 c->smack_process_label = mfree(c->smack_process_label);
2074 c->smack_process_label_ignore = false;
2075 return 0;
2076 }
2077
2078 if (rvalue[0] == '-') {
2079 ignore = true;
2080 rvalue++;
2081 } else
2082 ignore = false;
2083
2084 r = unit_full_printf(u, rvalue, &k);
2085 if (r < 0) {
2086 log_syntax(unit, ignore ? LOG_WARNING : LOG_ERR, filename, line, r,
2087 "Failed to resolve unit specifiers in '%s'%s: %m",
2088 rvalue, ignore ? ", ignoring" : "");
2089 return ignore ? 0 : -ENOEXEC;
2090 }
2091
2092 free_and_replace(c->smack_process_label, k);
2093 c->smack_process_label_ignore = ignore;
2094
2095 return 0;
2096 }
2097
2098 int config_parse_timer(
2099 const char *unit,
2100 const char *filename,
2101 unsigned line,
2102 const char *section,
2103 unsigned section_line,
2104 const char *lvalue,
2105 int ltype,
2106 const char *rvalue,
2107 void *data,
2108 void *userdata) {
2109
2110 _cleanup_(calendar_spec_freep) CalendarSpec *c = NULL;
2111 _cleanup_free_ char *k = NULL;
2112 const Unit *u = userdata;
2113 Timer *t = data;
2114 usec_t usec = 0;
2115 TimerValue *v;
2116 int r;
2117
2118 assert(filename);
2119 assert(lvalue);
2120 assert(rvalue);
2121 assert(data);
2122
2123 if (isempty(rvalue)) {
2124 /* Empty assignment resets list */
2125 timer_free_values(t);
2126 return 0;
2127 }
2128
2129 r = unit_full_printf(u, rvalue, &k);
2130 if (r < 0) {
2131 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue);
2132 return 0;
2133 }
2134
2135 if (ltype == TIMER_CALENDAR) {
2136 r = calendar_spec_from_string(k, &c);
2137 if (r < 0) {
2138 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse calendar specification, ignoring: %s", k);
2139 return 0;
2140 }
2141 } else {
2142 r = parse_sec(k, &usec);
2143 if (r < 0) {
2144 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse timer value, ignoring: %s", k);
2145 return 0;
2146 }
2147 }
2148
2149 v = new(TimerValue, 1);
2150 if (!v)
2151 return log_oom();
2152
2153 *v = (TimerValue) {
2154 .base = ltype,
2155 .value = usec,
2156 .calendar_spec = TAKE_PTR(c),
2157 };
2158
2159 LIST_PREPEND(value, t->values, v);
2160
2161 return 0;
2162 }
2163
2164 int config_parse_trigger_unit(
2165 const char *unit,
2166 const char *filename,
2167 unsigned line,
2168 const char *section,
2169 unsigned section_line,
2170 const char *lvalue,
2171 int ltype,
2172 const char *rvalue,
2173 void *data,
2174 void *userdata) {
2175
2176 _cleanup_free_ char *p = NULL;
2177 Unit *u = data;
2178 UnitType type;
2179 int r;
2180
2181 assert(filename);
2182 assert(lvalue);
2183 assert(rvalue);
2184 assert(data);
2185
2186 if (UNIT_TRIGGER(u)) {
2187 log_syntax(unit, LOG_WARNING, filename, line, 0, "Multiple units to trigger specified, ignoring: %s", rvalue);
2188 return 0;
2189 }
2190
2191 r = unit_name_printf(u, rvalue, &p);
2192 if (r < 0) {
2193 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue);
2194 return 0;
2195 }
2196
2197 type = unit_name_to_type(p);
2198 if (type < 0) {
2199 log_syntax(unit, LOG_WARNING, filename, line, type, "Unit type not valid, ignoring: %s", rvalue);
2200 return 0;
2201 }
2202 if (unit_has_name(u, p)) {
2203 log_syntax(unit, LOG_WARNING, filename, line, 0, "Units cannot trigger themselves, ignoring: %s", rvalue);
2204 return 0;
2205 }
2206
2207 r = unit_add_two_dependencies_by_name(u, UNIT_BEFORE, UNIT_TRIGGERS, p, true, UNIT_DEPENDENCY_FILE);
2208 if (r < 0) {
2209 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to add trigger on %s, ignoring: %m", p);
2210 return 0;
2211 }
2212
2213 return 0;
2214 }
2215
2216 int config_parse_path_spec(const char *unit,
2217 const char *filename,
2218 unsigned line,
2219 const char *section,
2220 unsigned section_line,
2221 const char *lvalue,
2222 int ltype,
2223 const char *rvalue,
2224 void *data,
2225 void *userdata) {
2226
2227 Path *p = data;
2228 PathSpec *s;
2229 PathType b;
2230 _cleanup_free_ char *k = NULL;
2231 int r;
2232
2233 assert(filename);
2234 assert(lvalue);
2235 assert(rvalue);
2236 assert(data);
2237
2238 if (isempty(rvalue)) {
2239 /* Empty assignment clears list */
2240 path_free_specs(p);
2241 return 0;
2242 }
2243
2244 b = path_type_from_string(lvalue);
2245 if (b < 0) {
2246 log_syntax(unit, LOG_WARNING, filename, line, b, "Failed to parse path type, ignoring: %s", lvalue);
2247 return 0;
2248 }
2249
2250 r = unit_path_printf(UNIT(p), rvalue, &k);
2251 if (r < 0) {
2252 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue);
2253 return 0;
2254 }
2255
2256 r = path_simplify_and_warn(k, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue);
2257 if (r < 0)
2258 return 0;
2259
2260 s = new0(PathSpec, 1);
2261 if (!s)
2262 return log_oom();
2263
2264 s->unit = UNIT(p);
2265 s->path = TAKE_PTR(k);
2266 s->type = b;
2267 s->inotify_fd = -1;
2268
2269 LIST_PREPEND(spec, p->specs, s);
2270
2271 return 0;
2272 }
2273
2274 int config_parse_socket_service(
2275 const char *unit,
2276 const char *filename,
2277 unsigned line,
2278 const char *section,
2279 unsigned section_line,
2280 const char *lvalue,
2281 int ltype,
2282 const char *rvalue,
2283 void *data,
2284 void *userdata) {
2285
2286 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
2287 _cleanup_free_ char *p = NULL;
2288 Socket *s = data;
2289 Unit *x;
2290 int r;
2291
2292 assert(filename);
2293 assert(lvalue);
2294 assert(rvalue);
2295 assert(data);
2296
2297 r = unit_name_printf(UNIT(s), rvalue, &p);
2298 if (r < 0) {
2299 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue);
2300 return 0;
2301 }
2302
2303 if (!endswith(p, ".service")) {
2304 log_syntax(unit, LOG_WARNING, filename, line, 0, "Unit must be of type service, ignoring: %s", rvalue);
2305 return 0;
2306 }
2307
2308 r = manager_load_unit(UNIT(s)->manager, p, NULL, &error, &x);
2309 if (r < 0) {
2310 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to load unit %s, ignoring: %s", rvalue, bus_error_message(&error, r));
2311 return 0;
2312 }
2313
2314 unit_ref_set(&s->service, UNIT(s), x);
2315
2316 return 0;
2317 }
2318
2319 int config_parse_fdname(
2320 const char *unit,
2321 const char *filename,
2322 unsigned line,
2323 const char *section,
2324 unsigned section_line,
2325 const char *lvalue,
2326 int ltype,
2327 const char *rvalue,
2328 void *data,
2329 void *userdata) {
2330
2331 _cleanup_free_ char *p = NULL;
2332 Socket *s = data;
2333 int r;
2334
2335 assert(filename);
2336 assert(lvalue);
2337 assert(rvalue);
2338 assert(data);
2339
2340 if (isempty(rvalue)) {
2341 s->fdname = mfree(s->fdname);
2342 return 0;
2343 }
2344
2345 r = unit_fd_printf(UNIT(s), rvalue, &p);
2346 if (r < 0) {
2347 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue);
2348 return 0;
2349 }
2350
2351 if (!fdname_is_valid(p)) {
2352 log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid file descriptor name, ignoring: %s", p);
2353 return 0;
2354 }
2355
2356 return free_and_replace(s->fdname, p);
2357 }
2358
2359 int config_parse_service_sockets(
2360 const char *unit,
2361 const char *filename,
2362 unsigned line,
2363 const char *section,
2364 unsigned section_line,
2365 const char *lvalue,
2366 int ltype,
2367 const char *rvalue,
2368 void *data,
2369 void *userdata) {
2370
2371 Service *s = data;
2372 int r;
2373
2374 assert(filename);
2375 assert(lvalue);
2376 assert(rvalue);
2377 assert(data);
2378
2379 for (const char *p = rvalue;;) {
2380 _cleanup_free_ char *word = NULL, *k = NULL;
2381
2382 r = extract_first_word(&p, &word, NULL, 0);
2383 if (r == -ENOMEM)
2384 return log_oom();
2385 if (r < 0) {
2386 log_syntax(unit, LOG_WARNING, filename, line, r, "Trailing garbage in sockets, ignoring: %s", rvalue);
2387 return 0;
2388 }
2389 if (r == 0)
2390 return 0;
2391
2392 r = unit_name_printf(UNIT(s), word, &k);
2393 if (r < 0) {
2394 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %m", word);
2395 continue;
2396 }
2397
2398 if (!endswith(k, ".socket")) {
2399 log_syntax(unit, LOG_WARNING, filename, line, 0, "Unit must be of type socket, ignoring: %s", k);
2400 continue;
2401 }
2402
2403 r = unit_add_two_dependencies_by_name(UNIT(s), UNIT_WANTS, UNIT_AFTER, k, true, UNIT_DEPENDENCY_FILE);
2404 if (r < 0)
2405 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to add dependency on %s, ignoring: %m", k);
2406
2407 r = unit_add_dependency_by_name(UNIT(s), UNIT_TRIGGERED_BY, k, true, UNIT_DEPENDENCY_FILE);
2408 if (r < 0)
2409 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to add dependency on %s, ignoring: %m", k);
2410 }
2411 }
2412
2413 int config_parse_bus_name(
2414 const char *unit,
2415 const char *filename,
2416 unsigned line,
2417 const char *section,
2418 unsigned section_line,
2419 const char *lvalue,
2420 int ltype,
2421 const char *rvalue,
2422 void *data,
2423 void *userdata) {
2424
2425 _cleanup_free_ char *k = NULL;
2426 const Unit *u = userdata;
2427 int r;
2428
2429 assert(filename);
2430 assert(lvalue);
2431 assert(rvalue);
2432 assert(u);
2433
2434 r = unit_full_printf_full(u, rvalue, SD_BUS_MAXIMUM_NAME_LENGTH, &k);
2435 if (r < 0) {
2436 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue);
2437 return 0;
2438 }
2439
2440 if (!sd_bus_service_name_is_valid(k)) {
2441 log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid bus name, ignoring: %s", k);
2442 return 0;
2443 }
2444
2445 return config_parse_string(unit, filename, line, section, section_line, lvalue, ltype, k, data, userdata);
2446 }
2447
2448 int config_parse_service_timeout(
2449 const char *unit,
2450 const char *filename,
2451 unsigned line,
2452 const char *section,
2453 unsigned section_line,
2454 const char *lvalue,
2455 int ltype,
2456 const char *rvalue,
2457 void *data,
2458 void *userdata) {
2459
2460 Service *s = userdata;
2461 usec_t usec;
2462 int r;
2463
2464 assert(filename);
2465 assert(lvalue);
2466 assert(rvalue);
2467 assert(s);
2468
2469 /* This is called for two cases: TimeoutSec= and TimeoutStartSec=. */
2470
2471 /* Traditionally, these options accepted 0 to disable the timeouts. However, a timeout of 0 suggests it happens
2472 * immediately, hence fix this to become USEC_INFINITY instead. This is in-line with how we internally handle
2473 * all other timeouts. */
2474 r = parse_sec_fix_0(rvalue, &usec);
2475 if (r < 0) {
2476 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse %s= parameter, ignoring: %s", lvalue, rvalue);
2477 return 0;
2478 }
2479
2480 s->start_timeout_defined = true;
2481 s->timeout_start_usec = usec;
2482
2483 if (streq(lvalue, "TimeoutSec"))
2484 s->timeout_stop_usec = usec;
2485
2486 return 0;
2487 }
2488
2489 int config_parse_timeout_abort(
2490 const char *unit,
2491 const char *filename,
2492 unsigned line,
2493 const char *section,
2494 unsigned section_line,
2495 const char *lvalue,
2496 int ltype,
2497 const char *rvalue,
2498 void *data,
2499 void *userdata) {
2500
2501 usec_t *ret = data;
2502 int r;
2503
2504 assert(filename);
2505 assert(lvalue);
2506 assert(rvalue);
2507 assert(ret);
2508
2509 /* Note: apart from setting the arg, this returns an extra bit of information in the return value. */
2510
2511 if (isempty(rvalue)) {
2512 *ret = 0;
2513 return 0; /* "not set" */
2514 }
2515
2516 r = parse_sec(rvalue, ret);
2517 if (r < 0)
2518 return log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse %s= setting, ignoring: %s", lvalue, rvalue);
2519
2520 return 1; /* "set" */
2521 }
2522
2523 int config_parse_service_timeout_abort(
2524 const char *unit,
2525 const char *filename,
2526 unsigned line,
2527 const char *section,
2528 unsigned section_line,
2529 const char *lvalue,
2530 int ltype,
2531 const char *rvalue,
2532 void *data,
2533 void *userdata) {
2534
2535 Service *s = userdata;
2536 int r;
2537
2538 assert(s);
2539
2540 r = config_parse_timeout_abort(unit, filename, line, section, section_line, lvalue, ltype, rvalue,
2541 &s->timeout_abort_usec, s);
2542 if (r >= 0)
2543 s->timeout_abort_set = r;
2544 return 0;
2545 }
2546
2547 int config_parse_sec_fix_0(
2548 const char *unit,
2549 const char *filename,
2550 unsigned line,
2551 const char *section,
2552 unsigned section_line,
2553 const char *lvalue,
2554 int ltype,
2555 const char *rvalue,
2556 void *data,
2557 void *userdata) {
2558
2559 usec_t *usec = data;
2560 int r;
2561
2562 assert(filename);
2563 assert(lvalue);
2564 assert(rvalue);
2565 assert(usec);
2566
2567 /* This is pretty much like config_parse_sec(), except that this treats a time of 0 as infinity, for
2568 * compatibility with older versions of systemd where 0 instead of infinity was used as indicator to turn off a
2569 * timeout. */
2570
2571 r = parse_sec_fix_0(rvalue, usec);
2572 if (r < 0)
2573 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse %s= parameter, ignoring: %s", lvalue, rvalue);
2574
2575 return 0;
2576 }
2577
2578 int config_parse_user_group_compat(
2579 const char *unit,
2580 const char *filename,
2581 unsigned line,
2582 const char *section,
2583 unsigned section_line,
2584 const char *lvalue,
2585 int ltype,
2586 const char *rvalue,
2587 void *data,
2588 void *userdata) {
2589
2590 _cleanup_free_ char *k = NULL;
2591 char **user = data;
2592 const Unit *u = userdata;
2593 int r;
2594
2595 assert(filename);
2596 assert(lvalue);
2597 assert(rvalue);
2598 assert(u);
2599
2600 if (isempty(rvalue)) {
2601 *user = mfree(*user);
2602 return 0;
2603 }
2604
2605 r = unit_full_printf(u, rvalue, &k);
2606 if (r < 0) {
2607 log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in %s: %m", rvalue);
2608 return -ENOEXEC;
2609 }
2610
2611 if (!valid_user_group_name(k, VALID_USER_ALLOW_NUMERIC|VALID_USER_RELAX|VALID_USER_WARN)) {
2612 log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid user/group name or numeric ID: %s", k);
2613 return -ENOEXEC;
2614 }
2615
2616 if (strstr(lvalue, "User") && streq(k, NOBODY_USER_NAME))
2617 log_struct(LOG_NOTICE,
2618 "MESSAGE=%s:%u: Special user %s configured, this is not safe!", filename, line, k,
2619 "UNIT=%s", unit,
2620 "MESSAGE_ID=" SD_MESSAGE_NOBODY_USER_UNSUITABLE_STR,
2621 "OFFENDING_USER=%s", k,
2622 "CONFIG_FILE=%s", filename,
2623 "CONFIG_LINE=%u", line);
2624
2625 return free_and_replace(*user, k);
2626 }
2627
2628 int config_parse_user_group_strv_compat(
2629 const char *unit,
2630 const char *filename,
2631 unsigned line,
2632 const char *section,
2633 unsigned section_line,
2634 const char *lvalue,
2635 int ltype,
2636 const char *rvalue,
2637 void *data,
2638 void *userdata) {
2639
2640 char ***users = data;
2641 const Unit *u = userdata;
2642 int r;
2643
2644 assert(filename);
2645 assert(lvalue);
2646 assert(rvalue);
2647 assert(u);
2648
2649 if (isempty(rvalue)) {
2650 *users = strv_free(*users);
2651 return 0;
2652 }
2653
2654 for (const char *p = rvalue;;) {
2655 _cleanup_free_ char *word = NULL, *k = NULL;
2656
2657 r = extract_first_word(&p, &word, NULL, 0);
2658 if (r == -ENOMEM)
2659 return log_oom();
2660 if (r < 0) {
2661 log_syntax(unit, LOG_ERR, filename, line, r, "Invalid syntax: %s", rvalue);
2662 return -ENOEXEC;
2663 }
2664 if (r == 0)
2665 return 0;
2666
2667 r = unit_full_printf(u, word, &k);
2668 if (r < 0) {
2669 log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers in %s: %m", word);
2670 return -ENOEXEC;
2671 }
2672
2673 if (!valid_user_group_name(k, VALID_USER_ALLOW_NUMERIC|VALID_USER_RELAX|VALID_USER_WARN)) {
2674 log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid user/group name or numeric ID: %s", k);
2675 return -ENOEXEC;
2676 }
2677
2678 r = strv_push(users, k);
2679 if (r < 0)
2680 return log_oom();
2681
2682 k = NULL;
2683 }
2684 }
2685
2686 int config_parse_working_directory(
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) {
2697
2698 ExecContext *c = data;
2699 const Unit *u = userdata;
2700 bool missing_ok;
2701 int r;
2702
2703 assert(filename);
2704 assert(lvalue);
2705 assert(rvalue);
2706 assert(c);
2707 assert(u);
2708
2709 if (isempty(rvalue)) {
2710 c->working_directory_home = false;
2711 c->working_directory = mfree(c->working_directory);
2712 return 0;
2713 }
2714
2715 if (rvalue[0] == '-') {
2716 missing_ok = true;
2717 rvalue++;
2718 } else
2719 missing_ok = false;
2720
2721 if (streq(rvalue, "~")) {
2722 c->working_directory_home = true;
2723 c->working_directory = mfree(c->working_directory);
2724 } else {
2725 _cleanup_free_ char *k = NULL;
2726
2727 r = unit_path_printf(u, rvalue, &k);
2728 if (r < 0) {
2729 log_syntax(unit, missing_ok ? LOG_WARNING : LOG_ERR, filename, line, r,
2730 "Failed to resolve unit specifiers in working directory path '%s'%s: %m",
2731 rvalue, missing_ok ? ", ignoring" : "");
2732 return missing_ok ? 0 : -ENOEXEC;
2733 }
2734
2735 r = path_simplify_and_warn(k, PATH_CHECK_ABSOLUTE | (missing_ok ? 0 : PATH_CHECK_FATAL), unit, filename, line, lvalue);
2736 if (r < 0)
2737 return missing_ok ? 0 : -ENOEXEC;
2738
2739 c->working_directory_home = false;
2740 free_and_replace(c->working_directory, k);
2741 }
2742
2743 c->working_directory_missing_ok = missing_ok;
2744 return 0;
2745 }
2746
2747 int config_parse_unit_env_file(const char *unit,
2748 const char *filename,
2749 unsigned line,
2750 const char *section,
2751 unsigned section_line,
2752 const char *lvalue,
2753 int ltype,
2754 const char *rvalue,
2755 void *data,
2756 void *userdata) {
2757
2758 char ***env = data;
2759 const Unit *u = userdata;
2760 _cleanup_free_ char *n = NULL;
2761 int r;
2762
2763 assert(filename);
2764 assert(lvalue);
2765 assert(rvalue);
2766 assert(data);
2767
2768 if (isempty(rvalue)) {
2769 /* Empty assignment frees the list */
2770 *env = strv_free(*env);
2771 return 0;
2772 }
2773
2774 r = unit_full_printf_full(u, rvalue, PATH_MAX, &n);
2775 if (r < 0) {
2776 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue);
2777 return 0;
2778 }
2779
2780 r = path_simplify_and_warn(n[0] == '-' ? n + 1 : n, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue);
2781 if (r < 0)
2782 return 0;
2783
2784 r = strv_push(env, n);
2785 if (r < 0)
2786 return log_oom();
2787
2788 n = NULL;
2789
2790 return 0;
2791 }
2792
2793 int config_parse_environ(
2794 const char *unit,
2795 const char *filename,
2796 unsigned line,
2797 const char *section,
2798 unsigned section_line,
2799 const char *lvalue,
2800 int ltype,
2801 const char *rvalue,
2802 void *data,
2803 void *userdata) {
2804
2805 const Unit *u = userdata;
2806 char ***env = data;
2807 int r;
2808
2809 assert(filename);
2810 assert(lvalue);
2811 assert(rvalue);
2812 assert(data);
2813
2814 if (isempty(rvalue)) {
2815 /* Empty assignment resets the list */
2816 *env = strv_free(*env);
2817 return 0;
2818 }
2819
2820 for (const char *p = rvalue;; ) {
2821 _cleanup_free_ char *word = NULL, *resolved = NULL;
2822
2823 r = extract_first_word(&p, &word, NULL, EXTRACT_CUNESCAPE|EXTRACT_UNQUOTE);
2824 if (r == -ENOMEM)
2825 return log_oom();
2826 if (r < 0) {
2827 log_syntax(unit, LOG_WARNING, filename, line, r,
2828 "Invalid syntax, ignoring: %s", rvalue);
2829 return 0;
2830 }
2831 if (r == 0)
2832 return 0;
2833
2834 if (u)
2835 r = unit_env_printf(u, word, &resolved);
2836 else
2837 r = specifier_printf(word, sc_arg_max(), system_and_tmp_specifier_table, NULL, NULL, &resolved);
2838 if (r < 0) {
2839 log_syntax(unit, LOG_WARNING, filename, line, r,
2840 "Failed to resolve specifiers in %s, ignoring: %m", word);
2841 continue;
2842 }
2843
2844 if (!env_assignment_is_valid(resolved)) {
2845 log_syntax(unit, LOG_WARNING, filename, line, 0,
2846 "Invalid environment assignment, ignoring: %s", resolved);
2847 continue;
2848 }
2849
2850 r = strv_env_replace_consume(env, TAKE_PTR(resolved));
2851 if (r < 0)
2852 return log_error_errno(r, "Failed to update environment: %m");
2853 }
2854 }
2855
2856 int config_parse_pass_environ(
2857 const char *unit,
2858 const char *filename,
2859 unsigned line,
2860 const char *section,
2861 unsigned section_line,
2862 const char *lvalue,
2863 int ltype,
2864 const char *rvalue,
2865 void *data,
2866 void *userdata) {
2867
2868 _cleanup_strv_free_ char **n = NULL;
2869 const Unit *u = userdata;
2870 char*** passenv = data;
2871 size_t nlen = 0;
2872 int r;
2873
2874 assert(filename);
2875 assert(lvalue);
2876 assert(rvalue);
2877 assert(data);
2878
2879 if (isempty(rvalue)) {
2880 /* Empty assignment resets the list */
2881 *passenv = strv_free(*passenv);
2882 return 0;
2883 }
2884
2885 for (const char *p = rvalue;;) {
2886 _cleanup_free_ char *word = NULL, *k = NULL;
2887
2888 r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE);
2889 if (r == -ENOMEM)
2890 return log_oom();
2891 if (r < 0) {
2892 log_syntax(unit, LOG_WARNING, filename, line, r,
2893 "Trailing garbage in %s, ignoring: %s", lvalue, rvalue);
2894 break;
2895 }
2896 if (r == 0)
2897 break;
2898
2899 if (u) {
2900 r = unit_env_printf(u, word, &k);
2901 if (r < 0) {
2902 log_syntax(unit, LOG_WARNING, filename, line, r,
2903 "Failed to resolve specifiers in %s, ignoring: %m", word);
2904 continue;
2905 }
2906 } else
2907 k = TAKE_PTR(word);
2908
2909 if (!env_name_is_valid(k)) {
2910 log_syntax(unit, LOG_WARNING, filename, line, 0,
2911 "Invalid environment name for %s, ignoring: %s", lvalue, k);
2912 continue;
2913 }
2914
2915 if (!GREEDY_REALLOC(n, nlen + 2))
2916 return log_oom();
2917
2918 n[nlen++] = TAKE_PTR(k);
2919 n[nlen] = NULL;
2920 }
2921
2922 if (n) {
2923 r = strv_extend_strv(passenv, n, true);
2924 if (r < 0)
2925 return log_oom();
2926 }
2927
2928 return 0;
2929 }
2930
2931 int config_parse_unset_environ(
2932 const char *unit,
2933 const char *filename,
2934 unsigned line,
2935 const char *section,
2936 unsigned section_line,
2937 const char *lvalue,
2938 int ltype,
2939 const char *rvalue,
2940 void *data,
2941 void *userdata) {
2942
2943 _cleanup_strv_free_ char **n = NULL;
2944 char*** unsetenv = data;
2945 const Unit *u = userdata;
2946 size_t nlen = 0;
2947 int r;
2948
2949 assert(filename);
2950 assert(lvalue);
2951 assert(rvalue);
2952 assert(data);
2953
2954 if (isempty(rvalue)) {
2955 /* Empty assignment resets the list */
2956 *unsetenv = strv_free(*unsetenv);
2957 return 0;
2958 }
2959
2960 for (const char *p = rvalue;;) {
2961 _cleanup_free_ char *word = NULL, *k = NULL;
2962
2963 r = extract_first_word(&p, &word, NULL, EXTRACT_CUNESCAPE|EXTRACT_UNQUOTE);
2964 if (r == -ENOMEM)
2965 return log_oom();
2966 if (r < 0) {
2967 log_syntax(unit, LOG_WARNING, filename, line, r,
2968 "Trailing garbage in %s, ignoring: %s", lvalue, rvalue);
2969 break;
2970 }
2971 if (r == 0)
2972 break;
2973
2974 if (u) {
2975 r = unit_env_printf(u, word, &k);
2976 if (r < 0) {
2977 log_syntax(unit, LOG_WARNING, filename, line, r,
2978 "Failed to resolve unit specifiers in %s, ignoring: %m", word);
2979 continue;
2980 }
2981 } else
2982 k = TAKE_PTR(word);
2983
2984 if (!env_assignment_is_valid(k) && !env_name_is_valid(k)) {
2985 log_syntax(unit, LOG_WARNING, filename, line, 0,
2986 "Invalid environment name or assignment %s, ignoring: %s", lvalue, k);
2987 continue;
2988 }
2989
2990 if (!GREEDY_REALLOC(n, nlen + 2))
2991 return log_oom();
2992
2993 n[nlen++] = TAKE_PTR(k);
2994 n[nlen] = NULL;
2995 }
2996
2997 if (n) {
2998 r = strv_extend_strv(unsetenv, n, true);
2999 if (r < 0)
3000 return log_oom();
3001 }
3002
3003 return 0;
3004 }
3005
3006 int config_parse_log_extra_fields(
3007 const char *unit,
3008 const char *filename,
3009 unsigned line,
3010 const char *section,
3011 unsigned section_line,
3012 const char *lvalue,
3013 int ltype,
3014 const char *rvalue,
3015 void *data,
3016 void *userdata) {
3017
3018 ExecContext *c = data;
3019 const Unit *u = userdata;
3020 int r;
3021
3022 assert(filename);
3023 assert(lvalue);
3024 assert(rvalue);
3025 assert(c);
3026
3027 if (isempty(rvalue)) {
3028 exec_context_free_log_extra_fields(c);
3029 return 0;
3030 }
3031
3032 for (const char *p = rvalue;;) {
3033 _cleanup_free_ char *word = NULL, *k = NULL;
3034 struct iovec *t;
3035 const char *eq;
3036
3037 r = extract_first_word(&p, &word, NULL, EXTRACT_CUNESCAPE|EXTRACT_UNQUOTE);
3038 if (r == -ENOMEM)
3039 return log_oom();
3040 if (r < 0) {
3041 log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid syntax, ignoring: %s", rvalue);
3042 return 0;
3043 }
3044 if (r == 0)
3045 return 0;
3046
3047 r = unit_full_printf(u, word, &k);
3048 if (r < 0) {
3049 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in %s, ignoring: %m", word);
3050 continue;
3051 }
3052
3053 eq = strchr(k, '=');
3054 if (!eq) {
3055 log_syntax(unit, LOG_WARNING, filename, line, 0, "Log field lacks '=' character, ignoring: %s", k);
3056 continue;
3057 }
3058
3059 if (!journal_field_valid(k, eq-k, false)) {
3060 log_syntax(unit, LOG_WARNING, filename, line, 0, "Log field name is invalid, ignoring: %s", k);
3061 continue;
3062 }
3063
3064 t = reallocarray(c->log_extra_fields, c->n_log_extra_fields+1, sizeof(struct iovec));
3065 if (!t)
3066 return log_oom();
3067
3068 c->log_extra_fields = t;
3069 c->log_extra_fields[c->n_log_extra_fields++] = IOVEC_MAKE_STRING(k);
3070
3071 k = NULL;
3072 }
3073 }
3074
3075 int config_parse_log_namespace(
3076 const char *unit,
3077 const char *filename,
3078 unsigned line,
3079 const char *section,
3080 unsigned section_line,
3081 const char *lvalue,
3082 int ltype,
3083 const char *rvalue,
3084 void *data,
3085 void *userdata) {
3086
3087 _cleanup_free_ char *k = NULL;
3088 ExecContext *c = data;
3089 const Unit *u = userdata;
3090 int r;
3091
3092 assert(filename);
3093 assert(lvalue);
3094 assert(rvalue);
3095 assert(c);
3096
3097 if (isempty(rvalue)) {
3098 c->log_namespace = mfree(c->log_namespace);
3099 return 0;
3100 }
3101
3102 r = unit_full_printf_full(u, rvalue, NAME_MAX, &k);
3103 if (r < 0) {
3104 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue);
3105 return 0;
3106 }
3107
3108 if (!log_namespace_name_valid(k)) {
3109 log_syntax(unit, LOG_WARNING, filename, line, 0, "Specified log namespace name is not valid, ignoring: %s", k);
3110 return 0;
3111 }
3112
3113 free_and_replace(c->log_namespace, k);
3114 return 0;
3115 }
3116
3117 int config_parse_unit_condition_path(
3118 const char *unit,
3119 const char *filename,
3120 unsigned line,
3121 const char *section,
3122 unsigned section_line,
3123 const char *lvalue,
3124 int ltype,
3125 const char *rvalue,
3126 void *data,
3127 void *userdata) {
3128
3129 _cleanup_free_ char *p = NULL;
3130 Condition **list = data, *c;
3131 ConditionType t = ltype;
3132 bool trigger, negate;
3133 const Unit *u = userdata;
3134 int r;
3135
3136 assert(filename);
3137 assert(lvalue);
3138 assert(rvalue);
3139 assert(data);
3140
3141 if (isempty(rvalue)) {
3142 /* Empty assignment resets the list */
3143 *list = condition_free_list(*list);
3144 return 0;
3145 }
3146
3147 trigger = rvalue[0] == '|';
3148 if (trigger)
3149 rvalue++;
3150
3151 negate = rvalue[0] == '!';
3152 if (negate)
3153 rvalue++;
3154
3155 r = unit_path_printf(u, rvalue, &p);
3156 if (r < 0) {
3157 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue);
3158 return 0;
3159 }
3160
3161 r = path_simplify_and_warn(p, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue);
3162 if (r < 0)
3163 return 0;
3164
3165 c = condition_new(t, p, trigger, negate);
3166 if (!c)
3167 return log_oom();
3168
3169 LIST_PREPEND(conditions, *list, c);
3170 return 0;
3171 }
3172
3173 int config_parse_unit_condition_string(
3174 const char *unit,
3175 const char *filename,
3176 unsigned line,
3177 const char *section,
3178 unsigned section_line,
3179 const char *lvalue,
3180 int ltype,
3181 const char *rvalue,
3182 void *data,
3183 void *userdata) {
3184
3185 _cleanup_free_ char *s = NULL;
3186 Condition **list = data, *c;
3187 ConditionType t = ltype;
3188 bool trigger, negate;
3189 const Unit *u = userdata;
3190 int r;
3191
3192 assert(filename);
3193 assert(lvalue);
3194 assert(rvalue);
3195 assert(data);
3196
3197 if (isempty(rvalue)) {
3198 /* Empty assignment resets the list */
3199 *list = condition_free_list(*list);
3200 return 0;
3201 }
3202
3203 trigger = *rvalue == '|';
3204 if (trigger)
3205 rvalue += 1 + strspn(rvalue + 1, WHITESPACE);
3206
3207 negate = *rvalue == '!';
3208 if (negate)
3209 rvalue += 1 + strspn(rvalue + 1, WHITESPACE);
3210
3211 r = unit_full_printf(u, rvalue, &s);
3212 if (r < 0) {
3213 log_syntax(unit, LOG_WARNING, filename, line, r,
3214 "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue);
3215 return 0;
3216 }
3217
3218 c = condition_new(t, s, trigger, negate);
3219 if (!c)
3220 return log_oom();
3221
3222 LIST_PREPEND(conditions, *list, c);
3223 return 0;
3224 }
3225
3226 int config_parse_unit_requires_mounts_for(
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 Unit *u = userdata;
3239 int r;
3240
3241 assert(filename);
3242 assert(lvalue);
3243 assert(rvalue);
3244 assert(data);
3245
3246 for (const char *p = rvalue;;) {
3247 _cleanup_free_ char *word = NULL, *resolved = NULL;
3248
3249 r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE);
3250 if (r == -ENOMEM)
3251 return log_oom();
3252 if (r < 0) {
3253 log_syntax(unit, LOG_WARNING, filename, line, r,
3254 "Invalid syntax, ignoring: %s", rvalue);
3255 return 0;
3256 }
3257 if (r == 0)
3258 return 0;
3259
3260 r = unit_path_printf(u, word, &resolved);
3261 if (r < 0) {
3262 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %m", word);
3263 continue;
3264 }
3265
3266 r = path_simplify_and_warn(resolved, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue);
3267 if (r < 0)
3268 continue;
3269
3270 r = unit_require_mounts_for(u, resolved, UNIT_DEPENDENCY_FILE);
3271 if (r < 0) {
3272 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to add required mount '%s', ignoring: %m", resolved);
3273 continue;
3274 }
3275 }
3276 }
3277
3278 int config_parse_documentation(
3279 const char *unit,
3280 const char *filename,
3281 unsigned line,
3282 const char *section,
3283 unsigned section_line,
3284 const char *lvalue,
3285 int ltype,
3286 const char *rvalue,
3287 void *data,
3288 void *userdata) {
3289
3290 Unit *u = userdata;
3291 int r;
3292 char **a, **b;
3293
3294 assert(filename);
3295 assert(lvalue);
3296 assert(rvalue);
3297 assert(u);
3298
3299 if (isempty(rvalue)) {
3300 /* Empty assignment resets the list */
3301 u->documentation = strv_free(u->documentation);
3302 return 0;
3303 }
3304
3305 r = config_parse_unit_strv_printf(unit, filename, line, section, section_line, lvalue, ltype,
3306 rvalue, data, userdata);
3307 if (r < 0)
3308 return r;
3309
3310 for (a = b = u->documentation; a && *a; a++) {
3311
3312 if (documentation_url_is_valid(*a))
3313 *(b++) = *a;
3314 else {
3315 log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid URL, ignoring: %s", *a);
3316 free(*a);
3317 }
3318 }
3319 if (b)
3320 *b = NULL;
3321
3322 return 0;
3323 }
3324
3325 #if HAVE_SECCOMP
3326 int config_parse_syscall_filter(
3327 const char *unit,
3328 const char *filename,
3329 unsigned line,
3330 const char *section,
3331 unsigned section_line,
3332 const char *lvalue,
3333 int ltype,
3334 const char *rvalue,
3335 void *data,
3336 void *userdata) {
3337
3338 ExecContext *c = data;
3339 _unused_ const Unit *u = userdata;
3340 bool invert = false;
3341 int r;
3342
3343 assert(filename);
3344 assert(lvalue);
3345 assert(rvalue);
3346 assert(u);
3347
3348 if (isempty(rvalue)) {
3349 /* Empty assignment resets the list */
3350 c->syscall_filter = hashmap_free(c->syscall_filter);
3351 c->syscall_allow_list = false;
3352 return 0;
3353 }
3354
3355 if (rvalue[0] == '~') {
3356 invert = true;
3357 rvalue++;
3358 }
3359
3360 if (!c->syscall_filter) {
3361 c->syscall_filter = hashmap_new(NULL);
3362 if (!c->syscall_filter)
3363 return log_oom();
3364
3365 if (invert)
3366 /* Allow everything but the ones listed */
3367 c->syscall_allow_list = false;
3368 else {
3369 /* Allow nothing but the ones listed */
3370 c->syscall_allow_list = true;
3371
3372 /* Accept default syscalls if we are on an allow_list */
3373 r = seccomp_parse_syscall_filter(
3374 "@default", -1, c->syscall_filter,
3375 SECCOMP_PARSE_PERMISSIVE|SECCOMP_PARSE_ALLOW_LIST,
3376 unit,
3377 NULL, 0);
3378 if (r < 0)
3379 return r;
3380 }
3381 }
3382
3383 for (const char *p = rvalue;;) {
3384 _cleanup_free_ char *word = NULL, *name = NULL;
3385 int num;
3386
3387 r = extract_first_word(&p, &word, NULL, 0);
3388 if (r == -ENOMEM)
3389 return log_oom();
3390 if (r < 0) {
3391 log_syntax(unit, LOG_WARNING, filename, line, r,
3392 "Invalid syntax, ignoring: %s", rvalue);
3393 return 0;
3394 }
3395 if (r == 0)
3396 return 0;
3397
3398 r = parse_syscall_and_errno(word, &name, &num);
3399 if (r < 0) {
3400 log_syntax(unit, LOG_WARNING, filename, line, r,
3401 "Failed to parse syscall:errno, ignoring: %s", word);
3402 continue;
3403 }
3404 if (!invert && num >= 0) {
3405 log_syntax(unit, LOG_WARNING, filename, line, 0,
3406 "Allow-listed system calls cannot take error number, ignoring: %s", word);
3407 continue;
3408 }
3409
3410 r = seccomp_parse_syscall_filter(
3411 name, num, c->syscall_filter,
3412 SECCOMP_PARSE_LOG|SECCOMP_PARSE_PERMISSIVE|
3413 (invert ? SECCOMP_PARSE_INVERT : 0)|
3414 (c->syscall_allow_list ? SECCOMP_PARSE_ALLOW_LIST : 0),
3415 unit, filename, line);
3416 if (r < 0)
3417 return r;
3418 }
3419 }
3420
3421 int config_parse_syscall_log(
3422 const char *unit,
3423 const char *filename,
3424 unsigned line,
3425 const char *section,
3426 unsigned section_line,
3427 const char *lvalue,
3428 int ltype,
3429 const char *rvalue,
3430 void *data,
3431 void *userdata) {
3432
3433 ExecContext *c = data;
3434 _unused_ const Unit *u = userdata;
3435 bool invert = false;
3436 const char *p;
3437 int r;
3438
3439 assert(filename);
3440 assert(lvalue);
3441 assert(rvalue);
3442 assert(u);
3443
3444 if (isempty(rvalue)) {
3445 /* Empty assignment resets the list */
3446 c->syscall_log = hashmap_free(c->syscall_log);
3447 c->syscall_log_allow_list = false;
3448 return 0;
3449 }
3450
3451 if (rvalue[0] == '~') {
3452 invert = true;
3453 rvalue++;
3454 }
3455
3456 if (!c->syscall_log) {
3457 c->syscall_log = hashmap_new(NULL);
3458 if (!c->syscall_log)
3459 return log_oom();
3460
3461 if (invert)
3462 /* Log everything but the ones listed */
3463 c->syscall_log_allow_list = false;
3464 else
3465 /* Log nothing but the ones listed */
3466 c->syscall_log_allow_list = true;
3467 }
3468
3469 p = rvalue;
3470 for (;;) {
3471 _cleanup_free_ char *word = NULL;
3472
3473 r = extract_first_word(&p, &word, NULL, 0);
3474 if (r == -ENOMEM)
3475 return log_oom();
3476 if (r < 0) {
3477 log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid syntax, ignoring: %s", rvalue);
3478 return 0;
3479 }
3480 if (r == 0)
3481 return 0;
3482
3483 r = seccomp_parse_syscall_filter(
3484 word, -1, c->syscall_log,
3485 SECCOMP_PARSE_LOG|SECCOMP_PARSE_PERMISSIVE|
3486 (invert ? SECCOMP_PARSE_INVERT : 0)|
3487 (c->syscall_log_allow_list ? SECCOMP_PARSE_ALLOW_LIST : 0),
3488 unit, filename, line);
3489 if (r < 0)
3490 return r;
3491 }
3492 }
3493
3494 int config_parse_syscall_archs(
3495 const char *unit,
3496 const char *filename,
3497 unsigned line,
3498 const char *section,
3499 unsigned section_line,
3500 const char *lvalue,
3501 int ltype,
3502 const char *rvalue,
3503 void *data,
3504 void *userdata) {
3505
3506 Set **archs = data;
3507 int r;
3508
3509 if (isempty(rvalue)) {
3510 *archs = set_free(*archs);
3511 return 0;
3512 }
3513
3514 for (const char *p = rvalue;;) {
3515 _cleanup_free_ char *word = NULL;
3516 uint32_t a;
3517
3518 r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE);
3519 if (r == -ENOMEM)
3520 return log_oom();
3521 if (r < 0) {
3522 log_syntax(unit, LOG_WARNING, filename, line, r,
3523 "Invalid syntax, ignoring: %s", rvalue);
3524 return 0;
3525 }
3526 if (r == 0)
3527 return 0;
3528
3529 r = seccomp_arch_from_string(word, &a);
3530 if (r < 0) {
3531 log_syntax(unit, LOG_WARNING, filename, line, r,
3532 "Failed to parse system call architecture \"%s\", ignoring: %m", word);
3533 continue;
3534 }
3535
3536 r = set_ensure_put(archs, NULL, UINT32_TO_PTR(a + 1));
3537 if (r < 0)
3538 return log_oom();
3539 }
3540 }
3541
3542 int config_parse_syscall_errno(
3543 const char *unit,
3544 const char *filename,
3545 unsigned line,
3546 const char *section,
3547 unsigned section_line,
3548 const char *lvalue,
3549 int ltype,
3550 const char *rvalue,
3551 void *data,
3552 void *userdata) {
3553
3554 ExecContext *c = data;
3555 int e;
3556
3557 assert(filename);
3558 assert(lvalue);
3559 assert(rvalue);
3560
3561 if (isempty(rvalue) || streq(rvalue, "kill")) {
3562 /* Empty assignment resets to KILL */
3563 c->syscall_errno = SECCOMP_ERROR_NUMBER_KILL;
3564 return 0;
3565 }
3566
3567 e = parse_errno(rvalue);
3568 if (e < 0) {
3569 log_syntax(unit, LOG_WARNING, filename, line, e, "Failed to parse error number, ignoring: %s", rvalue);
3570 return 0;
3571 }
3572 if (e == 0) {
3573 log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid error number, ignoring: %s", rvalue);
3574 return 0;
3575 }
3576
3577 c->syscall_errno = e;
3578 return 0;
3579 }
3580
3581 int config_parse_address_families(
3582 const char *unit,
3583 const char *filename,
3584 unsigned line,
3585 const char *section,
3586 unsigned section_line,
3587 const char *lvalue,
3588 int ltype,
3589 const char *rvalue,
3590 void *data,
3591 void *userdata) {
3592
3593 ExecContext *c = data;
3594 bool invert = false;
3595 int r;
3596
3597 assert(filename);
3598 assert(lvalue);
3599 assert(rvalue);
3600
3601 if (isempty(rvalue)) {
3602 /* Empty assignment resets the list */
3603 c->address_families = set_free(c->address_families);
3604 c->address_families_allow_list = false;
3605 return 0;
3606 }
3607
3608 if (streq(rvalue, "none")) {
3609 /* Forbid all address families. */
3610 c->address_families = set_free(c->address_families);
3611 c->address_families_allow_list = true;
3612 return 0;
3613 }
3614
3615 if (rvalue[0] == '~') {
3616 invert = true;
3617 rvalue++;
3618 }
3619
3620 if (!c->address_families) {
3621 c->address_families = set_new(NULL);
3622 if (!c->address_families)
3623 return log_oom();
3624
3625 c->address_families_allow_list = !invert;
3626 }
3627
3628 for (const char *p = rvalue;;) {
3629 _cleanup_free_ char *word = NULL;
3630 int af;
3631
3632 r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE);
3633 if (r == -ENOMEM)
3634 return log_oom();
3635 if (r < 0) {
3636 log_syntax(unit, LOG_WARNING, filename, line, r,
3637 "Invalid syntax, ignoring: %s", rvalue);
3638 return 0;
3639 }
3640 if (r == 0)
3641 return 0;
3642
3643 af = af_from_name(word);
3644 if (af < 0) {
3645 log_syntax(unit, LOG_WARNING, filename, line, af,
3646 "Failed to parse address family, ignoring: %s", word);
3647 continue;
3648 }
3649
3650 /* If we previously wanted to forbid an address family and now
3651 * we want to allow it, then just remove it from the list.
3652 */
3653 if (!invert == c->address_families_allow_list) {
3654 r = set_put(c->address_families, INT_TO_PTR(af));
3655 if (r < 0)
3656 return log_oom();
3657 } else
3658 set_remove(c->address_families, INT_TO_PTR(af));
3659 }
3660 }
3661
3662 int config_parse_restrict_namespaces(
3663 const char *unit,
3664 const char *filename,
3665 unsigned line,
3666 const char *section,
3667 unsigned section_line,
3668 const char *lvalue,
3669 int ltype,
3670 const char *rvalue,
3671 void *data,
3672 void *userdata) {
3673
3674 ExecContext *c = data;
3675 unsigned long flags;
3676 bool invert = false;
3677 int r;
3678
3679 if (isempty(rvalue)) {
3680 /* Reset to the default. */
3681 c->restrict_namespaces = NAMESPACE_FLAGS_INITIAL;
3682 return 0;
3683 }
3684
3685 /* Boolean parameter ignores the previous settings */
3686 r = parse_boolean(rvalue);
3687 if (r > 0) {
3688 c->restrict_namespaces = 0;
3689 return 0;
3690 } else if (r == 0) {
3691 c->restrict_namespaces = NAMESPACE_FLAGS_ALL;
3692 return 0;
3693 }
3694
3695 if (rvalue[0] == '~') {
3696 invert = true;
3697 rvalue++;
3698 }
3699
3700 /* Not a boolean argument, in this case it's a list of namespace types. */
3701 r = namespace_flags_from_string(rvalue, &flags);
3702 if (r < 0) {
3703 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse namespace type string, ignoring: %s", rvalue);
3704 return 0;
3705 }
3706
3707 if (c->restrict_namespaces == NAMESPACE_FLAGS_INITIAL)
3708 /* Initial assignment. Just set the value. */
3709 c->restrict_namespaces = invert ? (~flags) & NAMESPACE_FLAGS_ALL : flags;
3710 else
3711 /* Merge the value with the previous one. */
3712 SET_FLAG(c->restrict_namespaces, flags, !invert);
3713
3714 return 0;
3715 }
3716 #endif
3717
3718 int config_parse_restrict_filesystems(
3719 const char *unit,
3720 const char *filename,
3721 unsigned line,
3722 const char *section,
3723 unsigned section_line,
3724 const char *lvalue,
3725 int ltype,
3726 const char *rvalue,
3727 void *data,
3728 void *userdata) {
3729 ExecContext *c = data;
3730 bool invert = false;
3731 int r;
3732
3733 assert(filename);
3734 assert(lvalue);
3735 assert(rvalue);
3736 assert(data);
3737
3738 if (isempty(rvalue)) {
3739 /* Empty assignment resets the list */
3740 c->restrict_filesystems = set_free(c->restrict_filesystems);
3741 c->restrict_filesystems_allow_list = false;
3742 return 0;
3743 }
3744
3745 if (rvalue[0] == '~') {
3746 invert = true;
3747 rvalue++;
3748 }
3749
3750 if (!c->restrict_filesystems) {
3751 if (invert)
3752 /* Allow everything but the ones listed */
3753 c->restrict_filesystems_allow_list = false;
3754 else
3755 /* Allow nothing but the ones listed */
3756 c->restrict_filesystems_allow_list = true;
3757 }
3758
3759 for (const char *p = rvalue;;) {
3760 _cleanup_free_ char *word = NULL;
3761
3762 r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE);
3763 if (r == 0)
3764 break;
3765 if (r == -ENOMEM)
3766 return log_oom();
3767 if (r < 0) {
3768 log_syntax(unit, LOG_WARNING, filename, line, r,
3769 "Trailing garbage in %s, ignoring: %s", lvalue, rvalue);
3770 break;
3771 }
3772
3773 r = lsm_bpf_parse_filesystem(
3774 word,
3775 &c->restrict_filesystems,
3776 FILESYSTEM_PARSE_LOG|
3777 (invert ? FILESYSTEM_PARSE_INVERT : 0)|
3778 (c->restrict_filesystems_allow_list ? FILESYSTEM_PARSE_ALLOW_LIST : 0),
3779 unit, filename, line);
3780
3781 if (r < 0)
3782 return r;
3783 }
3784
3785 return 0;
3786 }
3787
3788 int config_parse_unit_slice(
3789 const char *unit,
3790 const char *filename,
3791 unsigned line,
3792 const char *section,
3793 unsigned section_line,
3794 const char *lvalue,
3795 int ltype,
3796 const char *rvalue,
3797 void *data,
3798 void *userdata) {
3799
3800 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
3801 _cleanup_free_ char *k = NULL;
3802 Unit *u = userdata, *slice;
3803 int r;
3804
3805 assert(filename);
3806 assert(lvalue);
3807 assert(rvalue);
3808 assert(u);
3809
3810 r = unit_name_printf(u, rvalue, &k);
3811 if (r < 0) {
3812 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue);
3813 return 0;
3814 }
3815
3816 r = manager_load_unit(u->manager, k, NULL, &error, &slice);
3817 if (r < 0) {
3818 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to load slice unit %s, ignoring: %s", k, bus_error_message(&error, r));
3819 return 0;
3820 }
3821
3822 r = unit_set_slice(u, slice);
3823 if (r < 0) {
3824 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to assign slice %s to unit %s, ignoring: %m", slice->id, u->id);
3825 return 0;
3826 }
3827
3828 return 0;
3829 }
3830
3831 int config_parse_cpu_quota(
3832 const char *unit,
3833 const char *filename,
3834 unsigned line,
3835 const char *section,
3836 unsigned section_line,
3837 const char *lvalue,
3838 int ltype,
3839 const char *rvalue,
3840 void *data,
3841 void *userdata) {
3842
3843 CGroupContext *c = data;
3844 int r;
3845
3846 assert(filename);
3847 assert(lvalue);
3848 assert(rvalue);
3849
3850 if (isempty(rvalue)) {
3851 c->cpu_quota_per_sec_usec = USEC_INFINITY;
3852 return 0;
3853 }
3854
3855 r = parse_permyriad_unbounded(rvalue);
3856 if (r <= 0) {
3857 log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid CPU quota '%s', ignoring.", rvalue);
3858 return 0;
3859 }
3860
3861 c->cpu_quota_per_sec_usec = ((usec_t) r * USEC_PER_SEC) / 10000U;
3862 return 0;
3863 }
3864
3865 int config_parse_allowed_cpuset(
3866 const char *unit,
3867 const char *filename,
3868 unsigned line,
3869 const char *section,
3870 unsigned section_line,
3871 const char *lvalue,
3872 int ltype,
3873 const char *rvalue,
3874 void *data,
3875 void *userdata) {
3876
3877 CPUSet *c = data;
3878
3879 (void) parse_cpu_set_extend(rvalue, c, true, unit, filename, line, lvalue);
3880 return 0;
3881 }
3882
3883 int config_parse_memory_limit(
3884 const char *unit,
3885 const char *filename,
3886 unsigned line,
3887 const char *section,
3888 unsigned section_line,
3889 const char *lvalue,
3890 int ltype,
3891 const char *rvalue,
3892 void *data,
3893 void *userdata) {
3894
3895 CGroupContext *c = data;
3896 uint64_t bytes = CGROUP_LIMIT_MAX;
3897 int r;
3898
3899 if (isempty(rvalue) && STR_IN_SET(lvalue, "DefaultMemoryLow",
3900 "DefaultMemoryMin",
3901 "MemoryLow",
3902 "MemoryMin"))
3903 bytes = CGROUP_LIMIT_MIN;
3904 else if (!isempty(rvalue) && !streq(rvalue, "infinity")) {
3905
3906 r = parse_permyriad(rvalue);
3907 if (r < 0) {
3908 r = parse_size(rvalue, 1024, &bytes);
3909 if (r < 0) {
3910 log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid memory limit '%s', ignoring: %m", rvalue);
3911 return 0;
3912 }
3913 } else
3914 bytes = physical_memory_scale(r, 10000U);
3915
3916 if (bytes >= UINT64_MAX ||
3917 (bytes <= 0 && !STR_IN_SET(lvalue, "MemorySwapMax", "MemoryLow", "MemoryMin", "DefaultMemoryLow", "DefaultMemoryMin"))) {
3918 log_syntax(unit, LOG_WARNING, filename, line, 0, "Memory limit '%s' out of range, ignoring.", rvalue);
3919 return 0;
3920 }
3921 }
3922
3923 if (streq(lvalue, "DefaultMemoryLow")) {
3924 c->default_memory_low = bytes;
3925 c->default_memory_low_set = true;
3926 } else if (streq(lvalue, "DefaultMemoryMin")) {
3927 c->default_memory_min = bytes;
3928 c->default_memory_min_set = true;
3929 } else if (streq(lvalue, "MemoryMin")) {
3930 c->memory_min = bytes;
3931 c->memory_min_set = true;
3932 } else if (streq(lvalue, "MemoryLow")) {
3933 c->memory_low = bytes;
3934 c->memory_low_set = true;
3935 } else if (streq(lvalue, "MemoryHigh"))
3936 c->memory_high = bytes;
3937 else if (streq(lvalue, "MemoryMax"))
3938 c->memory_max = bytes;
3939 else if (streq(lvalue, "MemorySwapMax"))
3940 c->memory_swap_max = bytes;
3941 else if (streq(lvalue, "MemoryLimit")) {
3942 log_syntax(unit, LOG_WARNING, filename, line, 0,
3943 "Unit uses MemoryLimit=; please use MemoryMax= instead. Support for MemoryLimit= will be removed soon.");
3944 c->memory_limit = bytes;
3945 } else
3946 return -EINVAL;
3947
3948 return 0;
3949 }
3950
3951 int config_parse_tasks_max(
3952 const char *unit,
3953 const char *filename,
3954 unsigned line,
3955 const char *section,
3956 unsigned section_line,
3957 const char *lvalue,
3958 int ltype,
3959 const char *rvalue,
3960 void *data,
3961 void *userdata) {
3962
3963 const Unit *u = userdata;
3964 TasksMax *tasks_max = data;
3965 uint64_t v;
3966 int r;
3967
3968 if (isempty(rvalue)) {
3969 *tasks_max = u ? u->manager->default_tasks_max : TASKS_MAX_UNSET;
3970 return 0;
3971 }
3972
3973 if (streq(rvalue, "infinity")) {
3974 *tasks_max = TASKS_MAX_UNSET;
3975 return 0;
3976 }
3977
3978 r = parse_permyriad(rvalue);
3979 if (r >= 0)
3980 *tasks_max = (TasksMax) { r, 10000U }; /* r‱ */
3981 else {
3982 r = safe_atou64(rvalue, &v);
3983 if (r < 0) {
3984 log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid maximum tasks value '%s', ignoring: %m", rvalue);
3985 return 0;
3986 }
3987
3988 if (v <= 0 || v >= UINT64_MAX) {
3989 log_syntax(unit, LOG_WARNING, filename, line, 0, "Maximum tasks value '%s' out of range, ignoring.", rvalue);
3990 return 0;
3991 }
3992
3993 *tasks_max = (TasksMax) { v };
3994 }
3995
3996 return 0;
3997 }
3998
3999 int config_parse_delegate(
4000 const char *unit,
4001 const char *filename,
4002 unsigned line,
4003 const char *section,
4004 unsigned section_line,
4005 const char *lvalue,
4006 int ltype,
4007 const char *rvalue,
4008 void *data,
4009 void *userdata) {
4010
4011 CGroupContext *c = data;
4012 UnitType t;
4013 int r;
4014
4015 t = unit_name_to_type(unit);
4016 assert(t != _UNIT_TYPE_INVALID);
4017
4018 if (!unit_vtable[t]->can_delegate) {
4019 log_syntax(unit, LOG_WARNING, filename, line, 0, "Delegate= setting not supported for this unit type, ignoring.");
4020 return 0;
4021 }
4022
4023 /* We either accept a boolean value, which may be used to turn on delegation for all controllers, or turn it
4024 * off for all. Or it takes a list of controller names, in which case we add the specified controllers to the
4025 * mask to delegate. */
4026
4027 if (isempty(rvalue)) {
4028 /* An empty string resets controllers and set Delegate=yes. */
4029 c->delegate = true;
4030 c->delegate_controllers = 0;
4031 return 0;
4032 }
4033
4034 r = parse_boolean(rvalue);
4035 if (r < 0) {
4036 CGroupMask mask = 0;
4037
4038 for (const char *p = rvalue;;) {
4039 _cleanup_free_ char *word = NULL;
4040 CGroupController cc;
4041
4042 r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE);
4043 if (r == -ENOMEM)
4044 return log_oom();
4045 if (r < 0) {
4046 log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid syntax, ignoring: %s", rvalue);
4047 return 0;
4048 }
4049 if (r == 0)
4050 break;
4051
4052 cc = cgroup_controller_from_string(word);
4053 if (cc < 0) {
4054 log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid controller name '%s', ignoring", word);
4055 continue;
4056 }
4057
4058 mask |= CGROUP_CONTROLLER_TO_MASK(cc);
4059 }
4060
4061 c->delegate = true;
4062 c->delegate_controllers |= mask;
4063
4064 } else if (r > 0) {
4065 c->delegate = true;
4066 c->delegate_controllers = _CGROUP_MASK_ALL;
4067 } else {
4068 c->delegate = false;
4069 c->delegate_controllers = 0;
4070 }
4071
4072 return 0;
4073 }
4074
4075 int config_parse_managed_oom_mode(
4076 const char *unit,
4077 const char *filename,
4078 unsigned line,
4079 const char *section,
4080 unsigned section_line,
4081 const char *lvalue,
4082 int ltype,
4083 const char *rvalue,
4084 void *data,
4085 void *userdata) {
4086
4087 ManagedOOMMode *mode = data, m;
4088 UnitType t;
4089
4090 t = unit_name_to_type(unit);
4091 assert(t != _UNIT_TYPE_INVALID);
4092
4093 if (!unit_vtable[t]->can_set_managed_oom)
4094 return log_syntax(unit, LOG_WARNING, filename, line, 0, "%s= is not supported for this unit type, ignoring.", lvalue);
4095
4096 if (isempty(rvalue)) {
4097 *mode = MANAGED_OOM_AUTO;
4098 return 0;
4099 }
4100
4101 m = managed_oom_mode_from_string(rvalue);
4102 if (m < 0) {
4103 log_syntax(unit, LOG_WARNING, filename, line, m, "Invalid syntax, ignoring: %s", rvalue);
4104 return 0;
4105 }
4106
4107 *mode = m;
4108 return 0;
4109 }
4110
4111 int config_parse_managed_oom_mem_pressure_limit(
4112 const char *unit,
4113 const char *filename,
4114 unsigned line,
4115 const char *section,
4116 unsigned section_line,
4117 const char *lvalue,
4118 int ltype,
4119 const char *rvalue,
4120 void *data,
4121 void *userdata) {
4122
4123 uint32_t *limit = data;
4124 UnitType t;
4125 int r;
4126
4127 t = unit_name_to_type(unit);
4128 assert(t != _UNIT_TYPE_INVALID);
4129
4130 if (!unit_vtable[t]->can_set_managed_oom)
4131 return log_syntax(unit, LOG_WARNING, filename, line, 0, "%s= is not supported for this unit type, ignoring.", lvalue);
4132
4133 if (isempty(rvalue)) {
4134 *limit = 0;
4135 return 0;
4136 }
4137
4138 r = parse_permyriad(rvalue);
4139 if (r < 0) {
4140 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse memory pressure limit value, ignoring: %s", rvalue);
4141 return 0;
4142 }
4143
4144 /* Normalize to 2^32-1 == 100% */
4145 *limit = UINT32_SCALE_FROM_PERMYRIAD(r);
4146 return 0;
4147 }
4148
4149 int config_parse_device_allow(
4150 const char *unit,
4151 const char *filename,
4152 unsigned line,
4153 const char *section,
4154 unsigned section_line,
4155 const char *lvalue,
4156 int ltype,
4157 const char *rvalue,
4158 void *data,
4159 void *userdata) {
4160
4161 _cleanup_free_ char *path = NULL, *resolved = NULL;
4162 CGroupContext *c = data;
4163 const char *p = rvalue;
4164 int r;
4165
4166 if (isempty(rvalue)) {
4167 while (c->device_allow)
4168 cgroup_context_free_device_allow(c, c->device_allow);
4169
4170 return 0;
4171 }
4172
4173 r = extract_first_word(&p, &path, NULL, EXTRACT_UNQUOTE);
4174 if (r == -ENOMEM)
4175 return log_oom();
4176 if (r <= 0) {
4177 log_syntax(unit, LOG_WARNING, filename, line, r,
4178 "Failed to extract device path and rights from '%s', ignoring.", rvalue);
4179 return 0;
4180 }
4181
4182 r = unit_path_printf(userdata, path, &resolved);
4183 if (r < 0) {
4184 log_syntax(unit, LOG_WARNING, filename, line, r,
4185 "Failed to resolve unit specifiers in '%s', ignoring: %m", path);
4186 return 0;
4187 }
4188
4189 if (!STARTSWITH_SET(resolved, "block-", "char-")) {
4190
4191 r = path_simplify_and_warn(resolved, 0, unit, filename, line, lvalue);
4192 if (r < 0)
4193 return 0;
4194
4195 if (!valid_device_node_path(resolved)) {
4196 log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid device node path '%s', ignoring.", resolved);
4197 return 0;
4198 }
4199 }
4200
4201 if (!isempty(p) && !in_charset(p, "rwm")) {
4202 log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid device rights '%s', ignoring.", p);
4203 return 0;
4204 }
4205
4206 return cgroup_add_device_allow(c, resolved, p);
4207 }
4208
4209 int config_parse_io_device_weight(
4210 const char *unit,
4211 const char *filename,
4212 unsigned line,
4213 const char *section,
4214 unsigned section_line,
4215 const char *lvalue,
4216 int ltype,
4217 const char *rvalue,
4218 void *data,
4219 void *userdata) {
4220
4221 _cleanup_free_ char *path = NULL, *resolved = NULL;
4222 CGroupIODeviceWeight *w;
4223 CGroupContext *c = data;
4224 const char *p = rvalue;
4225 uint64_t u;
4226 int r;
4227
4228 assert(filename);
4229 assert(lvalue);
4230 assert(rvalue);
4231
4232 if (isempty(rvalue)) {
4233 while (c->io_device_weights)
4234 cgroup_context_free_io_device_weight(c, c->io_device_weights);
4235
4236 return 0;
4237 }
4238
4239 r = extract_first_word(&p, &path, NULL, EXTRACT_UNQUOTE);
4240 if (r == -ENOMEM)
4241 return log_oom();
4242 if (r < 0) {
4243 log_syntax(unit, LOG_WARNING, filename, line, r,
4244 "Failed to extract device path and weight from '%s', ignoring.", rvalue);
4245 return 0;
4246 }
4247 if (r == 0 || isempty(p)) {
4248 log_syntax(unit, LOG_WARNING, filename, line, 0,
4249 "Invalid device path or weight specified in '%s', ignoring.", rvalue);
4250 return 0;
4251 }
4252
4253 r = unit_path_printf(userdata, path, &resolved);
4254 if (r < 0) {
4255 log_syntax(unit, LOG_WARNING, filename, line, r,
4256 "Failed to resolve unit specifiers in '%s', ignoring: %m", path);
4257 return 0;
4258 }
4259
4260 r = path_simplify_and_warn(resolved, 0, unit, filename, line, lvalue);
4261 if (r < 0)
4262 return 0;
4263
4264 r = cg_weight_parse(p, &u);
4265 if (r < 0) {
4266 log_syntax(unit, LOG_WARNING, filename, line, r, "IO weight '%s' invalid, ignoring: %m", p);
4267 return 0;
4268 }
4269
4270 assert(u != CGROUP_WEIGHT_INVALID);
4271
4272 w = new0(CGroupIODeviceWeight, 1);
4273 if (!w)
4274 return log_oom();
4275
4276 w->path = TAKE_PTR(resolved);
4277 w->weight = u;
4278
4279 LIST_PREPEND(device_weights, c->io_device_weights, w);
4280 return 0;
4281 }
4282
4283 int config_parse_io_device_latency(
4284 const char *unit,
4285 const char *filename,
4286 unsigned line,
4287 const char *section,
4288 unsigned section_line,
4289 const char *lvalue,
4290 int ltype,
4291 const char *rvalue,
4292 void *data,
4293 void *userdata) {
4294
4295 _cleanup_free_ char *path = NULL, *resolved = NULL;
4296 CGroupIODeviceLatency *l;
4297 CGroupContext *c = data;
4298 const char *p = rvalue;
4299 usec_t usec;
4300 int r;
4301
4302 assert(filename);
4303 assert(lvalue);
4304 assert(rvalue);
4305
4306 if (isempty(rvalue)) {
4307 while (c->io_device_latencies)
4308 cgroup_context_free_io_device_latency(c, c->io_device_latencies);
4309
4310 return 0;
4311 }
4312
4313 r = extract_first_word(&p, &path, NULL, EXTRACT_UNQUOTE);
4314 if (r == -ENOMEM)
4315 return log_oom();
4316 if (r < 0) {
4317 log_syntax(unit, LOG_WARNING, filename, line, r,
4318 "Failed to extract device path and latency from '%s', ignoring.", rvalue);
4319 return 0;
4320 }
4321 if (r == 0 || isempty(p)) {
4322 log_syntax(unit, LOG_WARNING, filename, line, 0,
4323 "Invalid device path or latency specified in '%s', ignoring.", rvalue);
4324 return 0;
4325 }
4326
4327 r = unit_path_printf(userdata, path, &resolved);
4328 if (r < 0) {
4329 log_syntax(unit, LOG_WARNING, filename, line, r,
4330 "Failed to resolve unit specifiers in '%s', ignoring: %m", path);
4331 return 0;
4332 }
4333
4334 r = path_simplify_and_warn(resolved, 0, unit, filename, line, lvalue);
4335 if (r < 0)
4336 return 0;
4337
4338 r = parse_sec(p, &usec);
4339 if (r < 0) {
4340 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse timer value, ignoring: %s", p);
4341 return 0;
4342 }
4343
4344 l = new0(CGroupIODeviceLatency, 1);
4345 if (!l)
4346 return log_oom();
4347
4348 l->path = TAKE_PTR(resolved);
4349 l->target_usec = usec;
4350
4351 LIST_PREPEND(device_latencies, c->io_device_latencies, l);
4352 return 0;
4353 }
4354
4355 int config_parse_io_limit(
4356 const char *unit,
4357 const char *filename,
4358 unsigned line,
4359 const char *section,
4360 unsigned section_line,
4361 const char *lvalue,
4362 int ltype,
4363 const char *rvalue,
4364 void *data,
4365 void *userdata) {
4366
4367 _cleanup_free_ char *path = NULL, *resolved = NULL;
4368 CGroupIODeviceLimit *l = NULL;
4369 CGroupContext *c = data;
4370 CGroupIOLimitType type;
4371 const char *p = rvalue;
4372 uint64_t num;
4373 int r;
4374
4375 assert(filename);
4376 assert(lvalue);
4377 assert(rvalue);
4378
4379 type = cgroup_io_limit_type_from_string(lvalue);
4380 assert(type >= 0);
4381
4382 if (isempty(rvalue)) {
4383 LIST_FOREACH(device_limits, t, c->io_device_limits)
4384 t->limits[type] = cgroup_io_limit_defaults[type];
4385 return 0;
4386 }
4387
4388 r = extract_first_word(&p, &path, NULL, EXTRACT_UNQUOTE);
4389 if (r == -ENOMEM)
4390 return log_oom();
4391 if (r < 0) {
4392 log_syntax(unit, LOG_WARNING, filename, line, r,
4393 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue);
4394 return 0;
4395 }
4396 if (r == 0 || isempty(p)) {
4397 log_syntax(unit, LOG_WARNING, filename, line, 0,
4398 "Invalid device node or bandwidth specified in '%s', ignoring.", rvalue);
4399 return 0;
4400 }
4401
4402 r = unit_path_printf(userdata, path, &resolved);
4403 if (r < 0) {
4404 log_syntax(unit, LOG_WARNING, filename, line, r,
4405 "Failed to resolve unit specifiers in '%s', ignoring: %m", path);
4406 return 0;
4407 }
4408
4409 r = path_simplify_and_warn(resolved, 0, unit, filename, line, lvalue);
4410 if (r < 0)
4411 return 0;
4412
4413 if (streq("infinity", p))
4414 num = CGROUP_LIMIT_MAX;
4415 else {
4416 r = parse_size(p, 1000, &num);
4417 if (r < 0 || num <= 0) {
4418 log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid IO limit '%s', ignoring.", p);
4419 return 0;
4420 }
4421 }
4422
4423 LIST_FOREACH(device_limits, t, c->io_device_limits)
4424 if (path_equal(resolved, t->path)) {
4425 l = t;
4426 break;
4427 }
4428
4429 if (!l) {
4430 CGroupIOLimitType ttype;
4431
4432 l = new0(CGroupIODeviceLimit, 1);
4433 if (!l)
4434 return log_oom();
4435
4436 l->path = TAKE_PTR(resolved);
4437 for (ttype = 0; ttype < _CGROUP_IO_LIMIT_TYPE_MAX; ttype++)
4438 l->limits[ttype] = cgroup_io_limit_defaults[ttype];
4439
4440 LIST_PREPEND(device_limits, c->io_device_limits, l);
4441 }
4442
4443 l->limits[type] = num;
4444
4445 return 0;
4446 }
4447
4448 int config_parse_blockio_device_weight(
4449 const char *unit,
4450 const char *filename,
4451 unsigned line,
4452 const char *section,
4453 unsigned section_line,
4454 const char *lvalue,
4455 int ltype,
4456 const char *rvalue,
4457 void *data,
4458 void *userdata) {
4459
4460 _cleanup_free_ char *path = NULL, *resolved = NULL;
4461 CGroupBlockIODeviceWeight *w;
4462 CGroupContext *c = data;
4463 const char *p = rvalue;
4464 uint64_t u;
4465 int r;
4466
4467 assert(filename);
4468 assert(lvalue);
4469 assert(rvalue);
4470
4471 log_syntax(unit, LOG_WARNING, filename, line, 0,
4472 "Unit uses %s=; please use IO*= settings instead. Support for %s= will be removed soon.",
4473 lvalue, lvalue);
4474
4475 if (isempty(rvalue)) {
4476 while (c->blockio_device_weights)
4477 cgroup_context_free_blockio_device_weight(c, c->blockio_device_weights);
4478
4479 return 0;
4480 }
4481
4482 r = extract_first_word(&p, &path, NULL, EXTRACT_UNQUOTE);
4483 if (r == -ENOMEM)
4484 return log_oom();
4485 if (r < 0) {
4486 log_syntax(unit, LOG_WARNING, filename, line, r,
4487 "Failed to extract device node and weight from '%s', ignoring.", rvalue);
4488 return 0;
4489 }
4490 if (r == 0 || isempty(p)) {
4491 log_syntax(unit, LOG_WARNING, filename, line, 0,
4492 "Invalid device node or weight specified in '%s', ignoring.", rvalue);
4493 return 0;
4494 }
4495
4496 r = unit_path_printf(userdata, path, &resolved);
4497 if (r < 0) {
4498 log_syntax(unit, LOG_WARNING, filename, line, r,
4499 "Failed to resolve unit specifiers in '%s', ignoring: %m", path);
4500 return 0;
4501 }
4502
4503 r = path_simplify_and_warn(resolved, 0, unit, filename, line, lvalue);
4504 if (r < 0)
4505 return 0;
4506
4507 r = cg_blkio_weight_parse(p, &u);
4508 if (r < 0) {
4509 log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid block IO weight '%s', ignoring: %m", p);
4510 return 0;
4511 }
4512
4513 assert(u != CGROUP_BLKIO_WEIGHT_INVALID);
4514
4515 w = new0(CGroupBlockIODeviceWeight, 1);
4516 if (!w)
4517 return log_oom();
4518
4519 w->path = TAKE_PTR(resolved);
4520 w->weight = u;
4521
4522 LIST_PREPEND(device_weights, c->blockio_device_weights, w);
4523 return 0;
4524 }
4525
4526 int config_parse_blockio_bandwidth(
4527 const char *unit,
4528 const char *filename,
4529 unsigned line,
4530 const char *section,
4531 unsigned section_line,
4532 const char *lvalue,
4533 int ltype,
4534 const char *rvalue,
4535 void *data,
4536 void *userdata) {
4537
4538 _cleanup_free_ char *path = NULL, *resolved = NULL;
4539 CGroupBlockIODeviceBandwidth *b = NULL;
4540 CGroupContext *c = data;
4541 const char *p = rvalue;
4542 uint64_t bytes;
4543 bool read;
4544 int r;
4545
4546 assert(filename);
4547 assert(lvalue);
4548 assert(rvalue);
4549
4550 log_syntax(unit, LOG_WARNING, filename, line, 0,
4551 "Unit uses %s=; please use IO*= settings instead. Support for %s= will be removed soon.",
4552 lvalue, lvalue);
4553
4554 read = streq("BlockIOReadBandwidth", lvalue);
4555
4556 if (isempty(rvalue)) {
4557 LIST_FOREACH(device_bandwidths, t, c->blockio_device_bandwidths) {
4558 t->rbps = CGROUP_LIMIT_MAX;
4559 t->wbps = CGROUP_LIMIT_MAX;
4560 }
4561 return 0;
4562 }
4563
4564 r = extract_first_word(&p, &path, NULL, EXTRACT_UNQUOTE);
4565 if (r == -ENOMEM)
4566 return log_oom();
4567 if (r < 0) {
4568 log_syntax(unit, LOG_WARNING, filename, line, r,
4569 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue);
4570 return 0;
4571 }
4572 if (r == 0 || isempty(p)) {
4573 log_syntax(unit, LOG_WARNING, filename, line, 0,
4574 "Invalid device node or bandwidth specified in '%s', ignoring.", rvalue);
4575 return 0;
4576 }
4577
4578 r = unit_path_printf(userdata, path, &resolved);
4579 if (r < 0) {
4580 log_syntax(unit, LOG_WARNING, filename, line, r,
4581 "Failed to resolve unit specifiers in '%s', ignoring: %m", path);
4582 return 0;
4583 }
4584
4585 r = path_simplify_and_warn(resolved, 0, unit, filename, line, lvalue);
4586 if (r < 0)
4587 return 0;
4588
4589 r = parse_size(p, 1000, &bytes);
4590 if (r < 0 || bytes <= 0) {
4591 log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid Block IO Bandwidth '%s', ignoring.", p);
4592 return 0;
4593 }
4594
4595 LIST_FOREACH(device_bandwidths, t, c->blockio_device_bandwidths)
4596 if (path_equal(resolved, t->path)) {
4597 b = t;
4598 break;
4599 }
4600
4601 if (!b) {
4602 b = new0(CGroupBlockIODeviceBandwidth, 1);
4603 if (!b)
4604 return log_oom();
4605
4606 b->path = TAKE_PTR(resolved);
4607 b->rbps = CGROUP_LIMIT_MAX;
4608 b->wbps = CGROUP_LIMIT_MAX;
4609
4610 LIST_PREPEND(device_bandwidths, c->blockio_device_bandwidths, b);
4611 }
4612
4613 if (read)
4614 b->rbps = bytes;
4615 else
4616 b->wbps = bytes;
4617
4618 return 0;
4619 }
4620
4621 int config_parse_job_mode_isolate(
4622 const char *unit,
4623 const char *filename,
4624 unsigned line,
4625 const char *section,
4626 unsigned section_line,
4627 const char *lvalue,
4628 int ltype,
4629 const char *rvalue,
4630 void *data,
4631 void *userdata) {
4632
4633 JobMode *m = data;
4634 int r;
4635
4636 assert(filename);
4637 assert(lvalue);
4638 assert(rvalue);
4639
4640 r = parse_boolean(rvalue);
4641 if (r < 0) {
4642 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse boolean, ignoring: %s", rvalue);
4643 return 0;
4644 }
4645
4646 log_notice("%s is deprecated. Please use OnFailureJobMode= instead", lvalue);
4647
4648 *m = r ? JOB_ISOLATE : JOB_REPLACE;
4649 return 0;
4650 }
4651
4652 int config_parse_exec_directories(
4653 const char *unit,
4654 const char *filename,
4655 unsigned line,
4656 const char *section,
4657 unsigned section_line,
4658 const char *lvalue,
4659 int ltype,
4660 const char *rvalue,
4661 void *data,
4662 void *userdata) {
4663
4664 ExecDirectory *ed = data;
4665 const Unit *u = userdata;
4666 int r;
4667
4668 assert(filename);
4669 assert(lvalue);
4670 assert(rvalue);
4671 assert(data);
4672
4673 if (isempty(rvalue)) {
4674 /* Empty assignment resets the list */
4675 exec_directory_done(ed);
4676 return 0;
4677 }
4678
4679 for (const char *p = rvalue;;) {
4680 _cleanup_free_ char *tuple = NULL;
4681
4682 r = extract_first_word(&p, &tuple, NULL, EXTRACT_UNQUOTE|EXTRACT_RETAIN_ESCAPE);
4683 if (r == -ENOMEM)
4684 return log_oom();
4685 if (r < 0) {
4686 log_syntax(unit, LOG_WARNING, filename, line, r,
4687 "Invalid syntax %s=%s, ignoring: %m", lvalue, rvalue);
4688 return 0;
4689 }
4690 if (r == 0)
4691 return 0;
4692
4693 _cleanup_free_ char *src = NULL, *dest = NULL;
4694 const char *q = tuple;
4695 r = extract_many_words(&q, ":", EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS, &src, &dest, NULL);
4696 if (r == -ENOMEM)
4697 return log_oom();
4698 if (r <= 0) {
4699 log_syntax(unit, LOG_WARNING, filename, line, r ?: SYNTHETIC_ERRNO(EINVAL),
4700 "Invalid syntax in %s=, ignoring: %s", lvalue, tuple);
4701 return 0;
4702 }
4703
4704 _cleanup_free_ char *sresolved = NULL;
4705 r = unit_path_printf(u, src, &sresolved);
4706 if (r < 0) {
4707 log_syntax(unit, LOG_WARNING, filename, line, r,
4708 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", src);
4709 continue;
4710 }
4711
4712 r = path_simplify_and_warn(sresolved, PATH_CHECK_RELATIVE, unit, filename, line, lvalue);
4713 if (r < 0)
4714 continue;
4715
4716 if (path_startswith(sresolved, "private")) {
4717 log_syntax(unit, LOG_WARNING, filename, line, 0,
4718 "%s= path can't be 'private', ignoring assignment: %s", lvalue, tuple);
4719 continue;
4720 }
4721
4722 /* For State and Runtime directories we support an optional destination parameter, which
4723 * will be used to create a symlink to the source. */
4724 _cleanup_strv_free_ char **symlinks = NULL;
4725 if (!isempty(dest)) {
4726 _cleanup_free_ char *dresolved = NULL;
4727
4728 if (streq(lvalue, "ConfigurationDirectory")) {
4729 log_syntax(unit, LOG_WARNING, filename, line, 0,
4730 "Destination parameter is not supported for ConfigurationDirectory, ignoring: %s", tuple);
4731 continue;
4732 }
4733
4734 r = unit_path_printf(u, dest, &dresolved);
4735 if (r < 0) {
4736 log_syntax(unit, LOG_WARNING, filename, line, r,
4737 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", dest);
4738 continue;
4739 }
4740
4741 r = path_simplify_and_warn(dresolved, PATH_CHECK_RELATIVE, unit, filename, line, lvalue);
4742 if (r < 0)
4743 continue;
4744
4745 r = strv_consume(&symlinks, TAKE_PTR(dresolved));
4746 if (r < 0)
4747 return log_oom();
4748 }
4749
4750 r = exec_directory_add(&ed->items, &ed->n_items, sresolved, symlinks);
4751 if (r < 0)
4752 return log_oom();
4753 }
4754 }
4755
4756 int config_parse_set_credential(
4757 const char *unit,
4758 const char *filename,
4759 unsigned line,
4760 const char *section,
4761 unsigned section_line,
4762 const char *lvalue,
4763 int ltype,
4764 const char *rvalue,
4765 void *data,
4766 void *userdata) {
4767
4768 _cleanup_free_ char *word = NULL, *k = NULL;
4769 _cleanup_free_ void *d = NULL;
4770 ExecContext *context = data;
4771 ExecSetCredential *old;
4772 Unit *u = userdata;
4773 bool encrypted = ltype;
4774 const char *p = rvalue;
4775 size_t size;
4776 int r;
4777
4778 assert(filename);
4779 assert(lvalue);
4780 assert(rvalue);
4781 assert(context);
4782
4783 if (isempty(rvalue)) {
4784 /* Empty assignment resets the list */
4785 context->set_credentials = hashmap_free(context->set_credentials);
4786 return 0;
4787 }
4788
4789 r = extract_first_word(&p, &word, ":", EXTRACT_DONT_COALESCE_SEPARATORS);
4790 if (r == -ENOMEM)
4791 return log_oom();
4792 if (r < 0) {
4793 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to extract credential name, ignoring: %s", rvalue);
4794 return 0;
4795 }
4796 if (r == 0 || isempty(p)) {
4797 log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid syntax, ignoring: %s", rvalue);
4798 return 0;
4799 }
4800
4801 r = unit_cred_printf(u, word, &k);
4802 if (r < 0) {
4803 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word);
4804 return 0;
4805 }
4806 if (!credential_name_valid(k)) {
4807 log_syntax(unit, LOG_WARNING, filename, line, 0, "Credential name \"%s\" not valid, ignoring.", k);
4808 return 0;
4809 }
4810
4811 if (encrypted) {
4812 r = unbase64mem_full(p, SIZE_MAX, true, &d, &size);
4813 if (r < 0) {
4814 log_syntax(unit, LOG_WARNING, filename, line, r, "Encrypted credential data not valid Base64 data, ignoring.");
4815 return 0;
4816 }
4817 } else {
4818 char *unescaped;
4819 ssize_t l;
4820
4821 /* We support escape codes here, so that users can insert trailing \n if they like */
4822 l = cunescape(p, UNESCAPE_ACCEPT_NUL, &unescaped);
4823 if (l < 0) {
4824 log_syntax(unit, LOG_WARNING, filename, line, l, "Can't unescape \"%s\", ignoring: %m", p);
4825 return 0;
4826 }
4827
4828 d = unescaped;
4829 size = l;
4830 }
4831
4832 old = hashmap_get(context->set_credentials, k);
4833 if (old) {
4834 free_and_replace(old->data, d);
4835 old->size = size;
4836 old->encrypted = encrypted;
4837 } else {
4838 _cleanup_(exec_set_credential_freep) ExecSetCredential *sc = NULL;
4839
4840 sc = new(ExecSetCredential, 1);
4841 if (!sc)
4842 return log_oom();
4843
4844 *sc = (ExecSetCredential) {
4845 .id = TAKE_PTR(k),
4846 .data = TAKE_PTR(d),
4847 .size = size,
4848 .encrypted = encrypted,
4849 };
4850
4851 r = hashmap_ensure_put(&context->set_credentials, &exec_set_credential_hash_ops, sc->id, sc);
4852 if (r == -ENOMEM)
4853 return log_oom();
4854 if (r < 0) {
4855 log_syntax(unit, LOG_WARNING, filename, line, r,
4856 "Duplicated credential value '%s', ignoring assignment: %s", sc->id, rvalue);
4857 return 0;
4858 }
4859
4860 TAKE_PTR(sc);
4861 }
4862
4863 return 0;
4864 }
4865
4866 int config_parse_load_credential(
4867 const char *unit,
4868 const char *filename,
4869 unsigned line,
4870 const char *section,
4871 unsigned section_line,
4872 const char *lvalue,
4873 int ltype,
4874 const char *rvalue,
4875 void *data,
4876 void *userdata) {
4877
4878 _cleanup_free_ char *word = NULL, *k = NULL, *q = NULL;
4879 ExecContext *context = data;
4880 ExecLoadCredential *old;
4881 bool encrypted = ltype;
4882 Unit *u = userdata;
4883 const char *p;
4884 int r;
4885
4886 assert(filename);
4887 assert(lvalue);
4888 assert(rvalue);
4889 assert(context);
4890
4891 if (isempty(rvalue)) {
4892 /* Empty assignment resets the list */
4893 context->load_credentials = hashmap_free(context->load_credentials);
4894 return 0;
4895 }
4896
4897 p = rvalue;
4898 r = extract_first_word(&p, &word, ":", EXTRACT_DONT_COALESCE_SEPARATORS);
4899 if (r == -ENOMEM)
4900 return log_oom();
4901 if (r <= 0) {
4902 log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid syntax, ignoring: %s", rvalue);
4903 return 0;
4904 }
4905
4906 r = unit_cred_printf(u, word, &k);
4907 if (r < 0) {
4908 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word);
4909 return 0;
4910 }
4911 if (!credential_name_valid(k)) {
4912 log_syntax(unit, LOG_WARNING, filename, line, 0, "Credential name \"%s\" not valid, ignoring.", k);
4913 return 0;
4914 }
4915
4916 if (isempty(p)) {
4917 /* If only one field is specified take it as shortcut for inheriting a credential named
4918 * the same way from our parent */
4919 q = strdup(k);
4920 if (!q)
4921 return log_oom();
4922 } else {
4923 r = unit_path_printf(u, p, &q);
4924 if (r < 0) {
4925 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", p);
4926 return 0;
4927 }
4928 if (path_is_absolute(q) ? !path_is_normalized(q) : !credential_name_valid(q)) {
4929 log_syntax(unit, LOG_WARNING, filename, line, 0, "Credential source \"%s\" not valid, ignoring.", q);
4930 return 0;
4931 }
4932 }
4933
4934 old = hashmap_get(context->load_credentials, k);
4935 if (old) {
4936 free_and_replace(old->path, q);
4937 old->encrypted = encrypted;
4938 } else {
4939 _cleanup_(exec_load_credential_freep) ExecLoadCredential *lc = NULL;
4940
4941 lc = new(ExecLoadCredential, 1);
4942 if (!lc)
4943 return log_oom();
4944
4945 *lc = (ExecLoadCredential) {
4946 .id = TAKE_PTR(k),
4947 .path = TAKE_PTR(q),
4948 .encrypted = encrypted,
4949 };
4950
4951 r = hashmap_ensure_put(&context->load_credentials, &exec_load_credential_hash_ops, lc->id, lc);
4952 if (r == -ENOMEM)
4953 return log_oom();
4954 if (r < 0) {
4955 log_syntax(unit, LOG_WARNING, filename, line, r,
4956 "Duplicated credential value '%s', ignoring assignment: %s", lc->id, rvalue);
4957 return 0;
4958 }
4959
4960 TAKE_PTR(lc);
4961 }
4962
4963 return 0;
4964 }
4965
4966 int config_parse_set_status(
4967 const char *unit,
4968 const char *filename,
4969 unsigned line,
4970 const char *section,
4971 unsigned section_line,
4972 const char *lvalue,
4973 int ltype,
4974 const char *rvalue,
4975 void *data,
4976 void *userdata) {
4977
4978 ExitStatusSet *status_set = data;
4979 int r;
4980
4981 assert(filename);
4982 assert(lvalue);
4983 assert(rvalue);
4984 assert(status_set);
4985
4986 /* Empty assignment resets the list */
4987 if (isempty(rvalue)) {
4988 exit_status_set_free(status_set);
4989 return 0;
4990 }
4991
4992 for (const char *p = rvalue;;) {
4993 _cleanup_free_ char *word = NULL;
4994 Bitmap *bitmap;
4995
4996 r = extract_first_word(&p, &word, NULL, 0);
4997 if (r == -ENOMEM)
4998 return log_oom();
4999 if (r < 0) {
5000 log_syntax(unit, LOG_WARNING, filename, line, r,
5001 "Failed to parse %s=%s, ignoring: %m", lvalue, rvalue);
5002 return 0;
5003 }
5004 if (r == 0)
5005 return 0;
5006
5007 /* We need to call exit_status_from_string() first, because we want
5008 * to parse numbers as exit statuses, not signals. */
5009
5010 r = exit_status_from_string(word);
5011 if (r >= 0) {
5012 assert(r >= 0 && r < 256);
5013 bitmap = &status_set->status;
5014 } else {
5015 r = signal_from_string(word);
5016 if (r < 0) {
5017 log_syntax(unit, LOG_WARNING, filename, line, r,
5018 "Failed to parse value, ignoring: %s", word);
5019 continue;
5020 }
5021 bitmap = &status_set->signal;
5022 }
5023
5024 r = bitmap_set(bitmap, r);
5025 if (r < 0)
5026 log_syntax(unit, LOG_WARNING, filename, line, r,
5027 "Failed to set signal or status %s, ignoring: %m", word);
5028 }
5029 }
5030
5031 int config_parse_namespace_path_strv(
5032 const char *unit,
5033 const char *filename,
5034 unsigned line,
5035 const char *section,
5036 unsigned section_line,
5037 const char *lvalue,
5038 int ltype,
5039 const char *rvalue,
5040 void *data,
5041 void *userdata) {
5042
5043 const Unit *u = userdata;
5044 char*** sv = data;
5045 int r;
5046
5047 assert(filename);
5048 assert(lvalue);
5049 assert(rvalue);
5050 assert(data);
5051
5052 if (isempty(rvalue)) {
5053 /* Empty assignment resets the list */
5054 *sv = strv_free(*sv);
5055 return 0;
5056 }
5057
5058 for (const char *p = rvalue;;) {
5059 _cleanup_free_ char *word = NULL, *resolved = NULL, *joined = NULL;
5060 const char *w;
5061 bool ignore_enoent = false, shall_prefix = false;
5062
5063 r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE);
5064 if (r == -ENOMEM)
5065 return log_oom();
5066 if (r < 0) {
5067 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to extract first word, ignoring: %s", rvalue);
5068 return 0;
5069 }
5070 if (r == 0)
5071 break;
5072
5073 w = word;
5074 if (startswith(w, "-")) {
5075 ignore_enoent = true;
5076 w++;
5077 }
5078 if (startswith(w, "+")) {
5079 shall_prefix = true;
5080 w++;
5081 }
5082
5083 r = unit_path_printf(u, w, &resolved);
5084 if (r < 0) {
5085 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in %s: %m", w);
5086 continue;
5087 }
5088
5089 r = path_simplify_and_warn(resolved, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue);
5090 if (r < 0)
5091 continue;
5092
5093 joined = strjoin(ignore_enoent ? "-" : "",
5094 shall_prefix ? "+" : "",
5095 resolved);
5096
5097 r = strv_push(sv, joined);
5098 if (r < 0)
5099 return log_oom();
5100
5101 joined = NULL;
5102 }
5103
5104 return 0;
5105 }
5106
5107 int config_parse_temporary_filesystems(
5108 const char *unit,
5109 const char *filename,
5110 unsigned line,
5111 const char *section,
5112 unsigned section_line,
5113 const char *lvalue,
5114 int ltype,
5115 const char *rvalue,
5116 void *data,
5117 void *userdata) {
5118
5119 const Unit *u = userdata;
5120 ExecContext *c = data;
5121 int r;
5122
5123 assert(filename);
5124 assert(lvalue);
5125 assert(rvalue);
5126 assert(data);
5127
5128 if (isempty(rvalue)) {
5129 /* Empty assignment resets the list */
5130 temporary_filesystem_free_many(c->temporary_filesystems, c->n_temporary_filesystems);
5131 c->temporary_filesystems = NULL;
5132 c->n_temporary_filesystems = 0;
5133 return 0;
5134 }
5135
5136 for (const char *p = rvalue;;) {
5137 _cleanup_free_ char *word = NULL, *path = NULL, *resolved = NULL;
5138 const char *w;
5139
5140 r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE);
5141 if (r == -ENOMEM)
5142 return log_oom();
5143 if (r < 0) {
5144 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to extract first word, ignoring: %s", rvalue);
5145 return 0;
5146 }
5147 if (r == 0)
5148 return 0;
5149
5150 w = word;
5151 r = extract_first_word(&w, &path, ":", EXTRACT_DONT_COALESCE_SEPARATORS);
5152 if (r == -ENOMEM)
5153 return log_oom();
5154 if (r < 0) {
5155 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to extract first word, ignoring: %s", word);
5156 continue;
5157 }
5158 if (r == 0) {
5159 log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid syntax, ignoring: %s", word);
5160 continue;
5161 }
5162
5163 r = unit_path_printf(u, path, &resolved);
5164 if (r < 0) {
5165 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in %s, ignoring: %m", path);
5166 continue;
5167 }
5168
5169 r = path_simplify_and_warn(resolved, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue);
5170 if (r < 0)
5171 continue;
5172
5173 r = temporary_filesystem_add(&c->temporary_filesystems, &c->n_temporary_filesystems, resolved, w);
5174 if (r < 0)
5175 return log_oom();
5176 }
5177 }
5178
5179 int config_parse_bind_paths(
5180 const char *unit,
5181 const char *filename,
5182 unsigned line,
5183 const char *section,
5184 unsigned section_line,
5185 const char *lvalue,
5186 int ltype,
5187 const char *rvalue,
5188 void *data,
5189 void *userdata) {
5190
5191 ExecContext *c = data;
5192 const Unit *u = userdata;
5193 int r;
5194
5195 assert(filename);
5196 assert(lvalue);
5197 assert(rvalue);
5198 assert(data);
5199
5200 if (isempty(rvalue)) {
5201 /* Empty assignment resets the list */
5202 bind_mount_free_many(c->bind_mounts, c->n_bind_mounts);
5203 c->bind_mounts = NULL;
5204 c->n_bind_mounts = 0;
5205 return 0;
5206 }
5207
5208 for (const char *p = rvalue;;) {
5209 _cleanup_free_ char *source = NULL, *destination = NULL;
5210 _cleanup_free_ char *sresolved = NULL, *dresolved = NULL;
5211 char *s = NULL, *d = NULL;
5212 bool rbind = true, ignore_enoent = false;
5213
5214 r = extract_first_word(&p, &source, ":" WHITESPACE, EXTRACT_UNQUOTE|EXTRACT_DONT_COALESCE_SEPARATORS);
5215 if (r == -ENOMEM)
5216 return log_oom();
5217 if (r < 0) {
5218 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse %s, ignoring: %s", lvalue, rvalue);
5219 return 0;
5220 }
5221 if (r == 0)
5222 break;
5223
5224 r = unit_full_printf_full(u, source, PATH_MAX, &sresolved);
5225 if (r < 0) {
5226 log_syntax(unit, LOG_WARNING, filename, line, r,
5227 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", source);
5228 continue;
5229 }
5230
5231 s = sresolved;
5232 if (s[0] == '-') {
5233 ignore_enoent = true;
5234 s++;
5235 }
5236
5237 r = path_simplify_and_warn(s, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue);
5238 if (r < 0)
5239 continue;
5240
5241 /* Optionally, the destination is specified. */
5242 if (p && p[-1] == ':') {
5243 r = extract_first_word(&p, &destination, ":" WHITESPACE, EXTRACT_UNQUOTE|EXTRACT_DONT_COALESCE_SEPARATORS);
5244 if (r == -ENOMEM)
5245 return log_oom();
5246 if (r < 0) {
5247 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse %s, ignoring: %s", lvalue, rvalue);
5248 return 0;
5249 }
5250 if (r == 0) {
5251 log_syntax(unit, LOG_WARNING, filename, line, 0, "Missing argument after ':', ignoring: %s", s);
5252 continue;
5253 }
5254
5255 r = unit_path_printf(u, destination, &dresolved);
5256 if (r < 0) {
5257 log_syntax(unit, LOG_WARNING, filename, line, r,
5258 "Failed to resolve specifiers in \"%s\", ignoring: %m", destination);
5259 continue;
5260 }
5261
5262 r = path_simplify_and_warn(dresolved, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue);
5263 if (r < 0)
5264 continue;
5265
5266 d = dresolved;
5267
5268 /* Optionally, there's also a short option string specified */
5269 if (p && p[-1] == ':') {
5270 _cleanup_free_ char *options = NULL;
5271
5272 r = extract_first_word(&p, &options, NULL, EXTRACT_UNQUOTE);
5273 if (r == -ENOMEM)
5274 return log_oom();
5275 if (r < 0) {
5276 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse %s=, ignoring: %s", lvalue, rvalue);
5277 return 0;
5278 }
5279
5280 if (isempty(options) || streq(options, "rbind"))
5281 rbind = true;
5282 else if (streq(options, "norbind"))
5283 rbind = false;
5284 else {
5285 log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid option string, ignoring setting: %s", options);
5286 continue;
5287 }
5288 }
5289 } else
5290 d = s;
5291
5292 r = bind_mount_add(&c->bind_mounts, &c->n_bind_mounts,
5293 &(BindMount) {
5294 .source = s,
5295 .destination = d,
5296 .read_only = !!strstr(lvalue, "ReadOnly"),
5297 .recursive = rbind,
5298 .ignore_enoent = ignore_enoent,
5299 });
5300 if (r < 0)
5301 return log_oom();
5302 }
5303
5304 return 0;
5305 }
5306
5307 int config_parse_mount_images(
5308 const char *unit,
5309 const char *filename,
5310 unsigned line,
5311 const char *section,
5312 unsigned section_line,
5313 const char *lvalue,
5314 int ltype,
5315 const char *rvalue,
5316 void *data,
5317 void *userdata) {
5318
5319 ExecContext *c = data;
5320 const Unit *u = userdata;
5321 int r;
5322
5323 assert(filename);
5324 assert(lvalue);
5325 assert(rvalue);
5326 assert(data);
5327
5328 if (isempty(rvalue)) {
5329 /* Empty assignment resets the list */
5330 c->mount_images = mount_image_free_many(c->mount_images, &c->n_mount_images);
5331 return 0;
5332 }
5333
5334 for (const char *p = rvalue;;) {
5335 _cleanup_(mount_options_free_allp) MountOptions *options = NULL;
5336 _cleanup_free_ char *first = NULL, *second = NULL, *tuple = NULL;
5337 _cleanup_free_ char *sresolved = NULL, *dresolved = NULL;
5338 const char *q = NULL;
5339 char *s = NULL;
5340 bool permissive = false;
5341
5342 r = extract_first_word(&p, &tuple, NULL, EXTRACT_UNQUOTE|EXTRACT_RETAIN_ESCAPE);
5343 if (r == -ENOMEM)
5344 return log_oom();
5345 if (r < 0) {
5346 log_syntax(unit, LOG_WARNING, filename, line, r,
5347 "Invalid syntax %s=%s, ignoring: %m", lvalue, rvalue);
5348 return 0;
5349 }
5350 if (r == 0)
5351 return 0;
5352
5353 q = tuple;
5354 r = extract_many_words(&q, ":", EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS, &first, &second, NULL);
5355 if (r == -ENOMEM)
5356 return log_oom();
5357 if (r < 0) {
5358 log_syntax(unit, LOG_WARNING, filename, line, r,
5359 "Invalid syntax in %s=, ignoring: %s", lvalue, tuple);
5360 return 0;
5361 }
5362 if (r == 0)
5363 continue;
5364
5365 s = first;
5366 if (s[0] == '-') {
5367 permissive = true;
5368 s++;
5369 }
5370
5371 r = unit_path_printf(u, s, &sresolved);
5372 if (r < 0) {
5373 log_syntax(unit, LOG_WARNING, filename, line, r,
5374 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", s);
5375 continue;
5376 }
5377
5378 r = path_simplify_and_warn(sresolved, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue);
5379 if (r < 0)
5380 continue;
5381
5382 if (isempty(second)) {
5383 log_syntax(unit, LOG_WARNING, filename, line, 0, "Missing destination in %s, ignoring: %s", lvalue, rvalue);
5384 continue;
5385 }
5386
5387 r = unit_path_printf(u, second, &dresolved);
5388 if (r < 0) {
5389 log_syntax(unit, LOG_WARNING, filename, line, r,
5390 "Failed to resolve specifiers in \"%s\", ignoring: %m", second);
5391 continue;
5392 }
5393
5394 r = path_simplify_and_warn(dresolved, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue);
5395 if (r < 0)
5396 continue;
5397
5398 for (;;) {
5399 _cleanup_free_ char *partition = NULL, *mount_options = NULL, *mount_options_resolved = NULL;
5400 MountOptions *o = NULL;
5401 PartitionDesignator partition_designator;
5402
5403 r = extract_many_words(&q, ":", EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS, &partition, &mount_options, NULL);
5404 if (r == -ENOMEM)
5405 return log_oom();
5406 if (r < 0) {
5407 log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid syntax, ignoring: %s", q);
5408 return 0;
5409 }
5410 if (r == 0)
5411 break;
5412 /* Single set of options, applying to the root partition/single filesystem */
5413 if (r == 1) {
5414 r = unit_full_printf(u, partition, &mount_options_resolved);
5415 if (r < 0) {
5416 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in %s, ignoring: %m", first);
5417 continue;
5418 }
5419
5420 o = new(MountOptions, 1);
5421 if (!o)
5422 return log_oom();
5423 *o = (MountOptions) {
5424 .partition_designator = PARTITION_ROOT,
5425 .options = TAKE_PTR(mount_options_resolved),
5426 };
5427 LIST_APPEND(mount_options, options, o);
5428
5429 break;
5430 }
5431
5432 partition_designator = partition_designator_from_string(partition);
5433 if (partition_designator < 0) {
5434 log_syntax(unit, LOG_WARNING, filename, line, partition_designator,
5435 "Invalid partition name %s, ignoring", partition);
5436 continue;
5437 }
5438 r = unit_full_printf(u, mount_options, &mount_options_resolved);
5439 if (r < 0) {
5440 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in %s, ignoring: %m", mount_options);
5441 continue;
5442 }
5443
5444 o = new(MountOptions, 1);
5445 if (!o)
5446 return log_oom();
5447 *o = (MountOptions) {
5448 .partition_designator = partition_designator,
5449 .options = TAKE_PTR(mount_options_resolved),
5450 };
5451 LIST_APPEND(mount_options, options, o);
5452 }
5453
5454 r = mount_image_add(&c->mount_images, &c->n_mount_images,
5455 &(MountImage) {
5456 .source = sresolved,
5457 .destination = dresolved,
5458 .mount_options = options,
5459 .ignore_enoent = permissive,
5460 .type = MOUNT_IMAGE_DISCRETE,
5461 });
5462 if (r < 0)
5463 return log_oom();
5464 }
5465 }
5466
5467 int config_parse_extension_images(
5468 const char *unit,
5469 const char *filename,
5470 unsigned line,
5471 const char *section,
5472 unsigned section_line,
5473 const char *lvalue,
5474 int ltype,
5475 const char *rvalue,
5476 void *data,
5477 void *userdata) {
5478
5479 ExecContext *c = data;
5480 const Unit *u = userdata;
5481 int r;
5482
5483 assert(filename);
5484 assert(lvalue);
5485 assert(rvalue);
5486 assert(data);
5487
5488 if (isempty(rvalue)) {
5489 /* Empty assignment resets the list */
5490 c->extension_images = mount_image_free_many(c->extension_images, &c->n_extension_images);
5491 return 0;
5492 }
5493
5494 for (const char *p = rvalue;;) {
5495 _cleanup_free_ char *source = NULL, *tuple = NULL, *sresolved = NULL;
5496 _cleanup_(mount_options_free_allp) MountOptions *options = NULL;
5497 bool permissive = false;
5498 const char *q = NULL;
5499 char *s = NULL;
5500
5501 r = extract_first_word(&p, &tuple, NULL, EXTRACT_UNQUOTE|EXTRACT_RETAIN_ESCAPE);
5502 if (r == -ENOMEM)
5503 return log_oom();
5504 if (r < 0) {
5505 log_syntax(unit, LOG_WARNING, filename, line, r,
5506 "Invalid syntax %s=%s, ignoring: %m", lvalue, rvalue);
5507 return 0;
5508 }
5509 if (r == 0)
5510 return 0;
5511
5512 q = tuple;
5513 r = extract_first_word(&q, &source, ":", EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS);
5514 if (r == -ENOMEM)
5515 return log_oom();
5516 if (r < 0) {
5517 log_syntax(unit, LOG_WARNING, filename, line, r,
5518 "Invalid syntax in %s=, ignoring: %s", lvalue, tuple);
5519 return 0;
5520 }
5521 if (r == 0)
5522 continue;
5523
5524 s = source;
5525 if (s[0] == '-') {
5526 permissive = true;
5527 s++;
5528 }
5529
5530 r = unit_path_printf(u, s, &sresolved);
5531 if (r < 0) {
5532 log_syntax(unit, LOG_WARNING, filename, line, r,
5533 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", s);
5534 continue;
5535 }
5536
5537 r = path_simplify_and_warn(sresolved, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue);
5538 if (r < 0)
5539 continue;
5540
5541 for (;;) {
5542 _cleanup_free_ char *partition = NULL, *mount_options = NULL, *mount_options_resolved = NULL;
5543 MountOptions *o = NULL;
5544 PartitionDesignator partition_designator;
5545
5546 r = extract_many_words(&q, ":", EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS, &partition, &mount_options, NULL);
5547 if (r == -ENOMEM)
5548 return log_oom();
5549 if (r < 0) {
5550 log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid syntax, ignoring: %s", q);
5551 return 0;
5552 }
5553 if (r == 0)
5554 break;
5555 /* Single set of options, applying to the root partition/single filesystem */
5556 if (r == 1) {
5557 r = unit_full_printf(u, partition, &mount_options_resolved);
5558 if (r < 0) {
5559 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in %s, ignoring: %m", partition);
5560 continue;
5561 }
5562
5563 o = new(MountOptions, 1);
5564 if (!o)
5565 return log_oom();
5566 *o = (MountOptions) {
5567 .partition_designator = PARTITION_ROOT,
5568 .options = TAKE_PTR(mount_options_resolved),
5569 };
5570 LIST_APPEND(mount_options, options, o);
5571
5572 break;
5573 }
5574
5575 partition_designator = partition_designator_from_string(partition);
5576 if (partition_designator < 0) {
5577 log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid partition name %s, ignoring", partition);
5578 continue;
5579 }
5580 r = unit_full_printf(u, mount_options, &mount_options_resolved);
5581 if (r < 0) {
5582 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in %s, ignoring: %m", mount_options);
5583 continue;
5584 }
5585
5586 o = new(MountOptions, 1);
5587 if (!o)
5588 return log_oom();
5589 *o = (MountOptions) {
5590 .partition_designator = partition_designator,
5591 .options = TAKE_PTR(mount_options_resolved),
5592 };
5593 LIST_APPEND(mount_options, options, o);
5594 }
5595
5596 r = mount_image_add(&c->extension_images, &c->n_extension_images,
5597 &(MountImage) {
5598 .source = sresolved,
5599 .mount_options = options,
5600 .ignore_enoent = permissive,
5601 .type = MOUNT_IMAGE_EXTENSION,
5602 });
5603 if (r < 0)
5604 return log_oom();
5605 }
5606 }
5607
5608 int config_parse_job_timeout_sec(
5609 const char* unit,
5610 const char *filename,
5611 unsigned line,
5612 const char *section,
5613 unsigned section_line,
5614 const char *lvalue,
5615 int ltype,
5616 const char *rvalue,
5617 void *data,
5618 void *userdata) {
5619
5620 Unit *u = data;
5621 usec_t usec;
5622 int r;
5623
5624 assert(filename);
5625 assert(lvalue);
5626 assert(rvalue);
5627 assert(u);
5628
5629 r = parse_sec_fix_0(rvalue, &usec);
5630 if (r < 0) {
5631 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse JobTimeoutSec= parameter, ignoring: %s", rvalue);
5632 return 0;
5633 }
5634
5635 /* If the user explicitly changed JobTimeoutSec= also change JobRunningTimeoutSec=, for compatibility with old
5636 * versions. If JobRunningTimeoutSec= was explicitly set, avoid this however as whatever the user picked should
5637 * count. */
5638
5639 if (!u->job_running_timeout_set)
5640 u->job_running_timeout = usec;
5641
5642 u->job_timeout = usec;
5643
5644 return 0;
5645 }
5646
5647 int config_parse_job_running_timeout_sec(
5648 const char* unit,
5649 const char *filename,
5650 unsigned line,
5651 const char *section,
5652 unsigned section_line,
5653 const char *lvalue,
5654 int ltype,
5655 const char *rvalue,
5656 void *data,
5657 void *userdata) {
5658
5659 Unit *u = data;
5660 usec_t usec;
5661 int r;
5662
5663 assert(filename);
5664 assert(lvalue);
5665 assert(rvalue);
5666 assert(u);
5667
5668 r = parse_sec_fix_0(rvalue, &usec);
5669 if (r < 0) {
5670 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse JobRunningTimeoutSec= parameter, ignoring: %s", rvalue);
5671 return 0;
5672 }
5673
5674 u->job_running_timeout = usec;
5675 u->job_running_timeout_set = true;
5676
5677 return 0;
5678 }
5679
5680 int config_parse_emergency_action(
5681 const char* unit,
5682 const char *filename,
5683 unsigned line,
5684 const char *section,
5685 unsigned section_line,
5686 const char *lvalue,
5687 int ltype,
5688 const char *rvalue,
5689 void *data,
5690 void *userdata) {
5691
5692 Manager *m = NULL;
5693 EmergencyAction *x = data;
5694 int r;
5695
5696 assert(filename);
5697 assert(lvalue);
5698 assert(rvalue);
5699 assert(data);
5700
5701 if (unit)
5702 m = ((Unit*) userdata)->manager;
5703 else
5704 m = data;
5705
5706 r = parse_emergency_action(rvalue, MANAGER_IS_SYSTEM(m), x);
5707 if (r < 0) {
5708 if (r == -EOPNOTSUPP && MANAGER_IS_USER(m)) {
5709 /* Compat mode: remove for systemd 241. */
5710
5711 log_syntax(unit, LOG_INFO, filename, line, r,
5712 "%s= in user mode specified as \"%s\", using \"exit-force\" instead.",
5713 lvalue, rvalue);
5714 *x = EMERGENCY_ACTION_EXIT_FORCE;
5715 return 0;
5716 }
5717
5718 if (r == -EOPNOTSUPP)
5719 log_syntax(unit, LOG_WARNING, filename, line, r,
5720 "%s= specified as %s mode action, ignoring: %s",
5721 lvalue, MANAGER_IS_SYSTEM(m) ? "user" : "system", rvalue);
5722 else
5723 log_syntax(unit, LOG_WARNING, filename, line, r,
5724 "Failed to parse %s=, ignoring: %s", lvalue, rvalue);
5725 return 0;
5726 }
5727
5728 return 0;
5729 }
5730
5731 int config_parse_pid_file(
5732 const char *unit,
5733 const char *filename,
5734 unsigned line,
5735 const char *section,
5736 unsigned section_line,
5737 const char *lvalue,
5738 int ltype,
5739 const char *rvalue,
5740 void *data,
5741 void *userdata) {
5742
5743 _cleanup_free_ char *k = NULL, *n = NULL;
5744 const Unit *u = userdata;
5745 char **s = data;
5746 int r;
5747
5748 assert(filename);
5749 assert(lvalue);
5750 assert(rvalue);
5751 assert(u);
5752
5753 if (isempty(rvalue)) {
5754 /* An empty assignment removes already set value. */
5755 *s = mfree(*s);
5756 return 0;
5757 }
5758
5759 r = unit_path_printf(u, rvalue, &k);
5760 if (r < 0) {
5761 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue);
5762 return 0;
5763 }
5764
5765 /* If this is a relative path make it absolute by prefixing the /run */
5766 n = path_make_absolute(k, u->manager->prefix[EXEC_DIRECTORY_RUNTIME]);
5767 if (!n)
5768 return log_oom();
5769
5770 /* Check that the result is a sensible path */
5771 r = path_simplify_and_warn(n, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue);
5772 if (r < 0)
5773 return r;
5774
5775 r = patch_var_run(unit, filename, line, lvalue, &n);
5776 if (r < 0)
5777 return r;
5778
5779 free_and_replace(*s, n);
5780 return 0;
5781 }
5782
5783 int config_parse_exit_status(
5784 const char *unit,
5785 const char *filename,
5786 unsigned line,
5787 const char *section,
5788 unsigned section_line,
5789 const char *lvalue,
5790 int ltype,
5791 const char *rvalue,
5792 void *data,
5793 void *userdata) {
5794
5795 int *exit_status = data, r;
5796 uint8_t u;
5797
5798 assert(filename);
5799 assert(lvalue);
5800 assert(rvalue);
5801 assert(exit_status);
5802
5803 if (isempty(rvalue)) {
5804 *exit_status = -1;
5805 return 0;
5806 }
5807
5808 r = safe_atou8(rvalue, &u);
5809 if (r < 0) {
5810 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse exit status '%s', ignoring: %m", rvalue);
5811 return 0;
5812 }
5813
5814 *exit_status = u;
5815 return 0;
5816 }
5817
5818 int config_parse_disable_controllers(
5819 const char *unit,
5820 const char *filename,
5821 unsigned line,
5822 const char *section,
5823 unsigned section_line,
5824 const char *lvalue,
5825 int ltype,
5826 const char *rvalue,
5827 void *data,
5828 void *userdata) {
5829
5830 int r;
5831 CGroupContext *c = data;
5832 CGroupMask disabled_mask;
5833
5834 /* 1. If empty, make all controllers eligible for use again.
5835 * 2. If non-empty, merge all listed controllers, space separated. */
5836
5837 if (isempty(rvalue)) {
5838 c->disable_controllers = 0;
5839 return 0;
5840 }
5841
5842 r = cg_mask_from_string(rvalue, &disabled_mask);
5843 if (r < 0 || disabled_mask <= 0) {
5844 log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid cgroup string: %s, ignoring", rvalue);
5845 return 0;
5846 }
5847
5848 c->disable_controllers |= disabled_mask;
5849
5850 return 0;
5851 }
5852
5853 int config_parse_ip_filter_bpf_progs(
5854 const char *unit,
5855 const char *filename,
5856 unsigned line,
5857 const char *section,
5858 unsigned section_line,
5859 const char *lvalue,
5860 int ltype,
5861 const char *rvalue,
5862 void *data,
5863 void *userdata) {
5864
5865 _cleanup_free_ char *resolved = NULL;
5866 const Unit *u = userdata;
5867 char ***paths = data;
5868 int r;
5869
5870 assert(filename);
5871 assert(lvalue);
5872 assert(rvalue);
5873 assert(paths);
5874
5875 if (isempty(rvalue)) {
5876 *paths = strv_free(*paths);
5877 return 0;
5878 }
5879
5880 r = unit_path_printf(u, rvalue, &resolved);
5881 if (r < 0) {
5882 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue);
5883 return 0;
5884 }
5885
5886 r = path_simplify_and_warn(resolved, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue);
5887 if (r < 0)
5888 return 0;
5889
5890 if (strv_contains(*paths, resolved))
5891 return 0;
5892
5893 r = strv_extend(paths, resolved);
5894 if (r < 0)
5895 return log_oom();
5896
5897 r = bpf_firewall_supported();
5898 if (r < 0)
5899 return r;
5900 if (r != BPF_FIREWALL_SUPPORTED_WITH_MULTI) {
5901 static bool warned = false;
5902
5903 log_full(warned ? LOG_DEBUG : LOG_WARNING,
5904 "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"
5905 "Starting this unit will fail! (This warning is only shown for the first loaded unit using IP firewalling.)", filename, line, lvalue, rvalue);
5906
5907 warned = true;
5908 }
5909
5910 return 0;
5911 }
5912
5913 int config_parse_bpf_foreign_program(
5914 const char *unit,
5915 const char *filename,
5916 unsigned line,
5917 const char *section,
5918 unsigned section_line,
5919 const char *lvalue,
5920 int ltype,
5921 const char *rvalue,
5922 void *data,
5923 void *userdata) {
5924 _cleanup_free_ char *resolved = NULL, *word = NULL;
5925 CGroupContext *c = data;
5926 const char *p = rvalue;
5927 Unit *u = userdata;
5928 int attach_type, r;
5929
5930 assert(filename);
5931 assert(lvalue);
5932 assert(rvalue);
5933
5934 if (isempty(rvalue)) {
5935 while (c->bpf_foreign_programs)
5936 cgroup_context_remove_bpf_foreign_program(c, c->bpf_foreign_programs);
5937
5938 return 0;
5939 }
5940
5941 r = extract_first_word(&p, &word, ":", 0);
5942 if (r == -ENOMEM)
5943 return log_oom();
5944 if (r < 0) {
5945 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse foreign BPF program, ignoring: %s", rvalue);
5946 return 0;
5947 }
5948 if (r == 0 || isempty(p)) {
5949 log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid syntax in %s=, ignoring: %s", lvalue, rvalue);
5950 return 0;
5951 }
5952
5953 attach_type = bpf_cgroup_attach_type_from_string(word);
5954 if (attach_type < 0) {
5955 log_syntax(unit, LOG_WARNING, filename, line, 0, "Unknown BPF attach type=%s, ignoring: %s", word, rvalue);
5956 return 0;
5957 }
5958
5959 r = unit_path_printf(u, p, &resolved);
5960 if (r < 0) {
5961 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %s", p, rvalue);
5962 return 0;
5963 }
5964
5965 r = path_simplify_and_warn(resolved, PATH_CHECK_ABSOLUTE, unit, filename, line, lvalue);
5966 if (r < 0)
5967 return 0;
5968
5969 r = cgroup_add_bpf_foreign_program(c, attach_type, resolved);
5970 if (r < 0)
5971 return log_error_errno(r, "Failed to add foreign BPF program to cgroup context: %m");
5972
5973 return 0;
5974 }
5975
5976 int config_parse_cgroup_socket_bind(
5977 const char *unit,
5978 const char *filename,
5979 unsigned line,
5980 const char *section,
5981 unsigned section_line,
5982 const char *lvalue,
5983 int ltype,
5984 const char *rvalue,
5985 void *data,
5986 void *userdata) {
5987 _cleanup_free_ CGroupSocketBindItem *item = NULL;
5988 CGroupSocketBindItem **head = data;
5989 uint16_t nr_ports, port_min;
5990 int af, ip_protocol, r;
5991
5992 if (isempty(rvalue)) {
5993 cgroup_context_remove_socket_bind(head);
5994 return 0;
5995 }
5996
5997 r = parse_socket_bind_item(rvalue, &af, &ip_protocol, &nr_ports, &port_min);
5998 if (r == -ENOMEM)
5999 return log_oom();
6000 if (r < 0) {
6001 log_syntax(unit, LOG_WARNING, filename, line, r,
6002 "Unable to parse %s= assignment, ignoring: %s", lvalue, rvalue);
6003 return 0;
6004 }
6005
6006 item = new(CGroupSocketBindItem, 1);
6007 if (!item)
6008 return log_oom();
6009 *item = (CGroupSocketBindItem) {
6010 .address_family = af,
6011 .ip_protocol = ip_protocol,
6012 .nr_ports = nr_ports,
6013 .port_min = port_min,
6014 };
6015
6016 LIST_PREPEND(socket_bind_items, *head, TAKE_PTR(item));
6017
6018 return 0;
6019 }
6020
6021 int config_parse_restrict_network_interfaces(
6022 const char *unit,
6023 const char *filename,
6024 unsigned line,
6025 const char *section,
6026 unsigned section_line,
6027 const char *lvalue,
6028 int ltype,
6029 const char *rvalue,
6030 void *data,
6031 void *userdata) {
6032 CGroupContext *c = data;
6033 bool is_allow_rule = true;
6034 int r;
6035
6036 assert(filename);
6037 assert(lvalue);
6038 assert(rvalue);
6039 assert(data);
6040
6041 if (isempty(rvalue)) {
6042 /* Empty assignment resets the list */
6043 c->restrict_network_interfaces = set_free(c->restrict_network_interfaces);
6044 return 0;
6045 }
6046
6047 if (rvalue[0] == '~') {
6048 is_allow_rule = false;
6049 rvalue++;
6050 }
6051
6052 if (set_isempty(c->restrict_network_interfaces))
6053 /* Only initialize this when creating the set */
6054 c->restrict_network_interfaces_is_allow_list = is_allow_rule;
6055
6056 for (const char *p = rvalue;;) {
6057 _cleanup_free_ char *word = NULL;
6058
6059 r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE);
6060 if (r == 0)
6061 break;
6062 if (r == -ENOMEM)
6063 return log_oom();
6064 if (r < 0) {
6065 log_syntax(unit, LOG_WARNING, filename, line, r,
6066 "Trailing garbage in %s, ignoring: %s", lvalue, rvalue);
6067 break;
6068 }
6069
6070 if (!ifname_valid(word)) {
6071 log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid interface name, ignoring: %s", word);
6072 continue;
6073 }
6074
6075 if (c->restrict_network_interfaces_is_allow_list != is_allow_rule)
6076 free(set_remove(c->restrict_network_interfaces, word));
6077 else {
6078 r = set_put_strdup(&c->restrict_network_interfaces, word);
6079 if (r < 0)
6080 return log_oom();
6081 }
6082 }
6083
6084 return 0;
6085 }
6086
6087 static int merge_by_names(Unit **u, Set *names, const char *id) {
6088 char *k;
6089 int r;
6090
6091 assert(u);
6092 assert(*u);
6093
6094 /* Let's try to add in all names that are aliases of this unit */
6095 while ((k = set_steal_first(names))) {
6096 _cleanup_free_ _unused_ char *free_k = k;
6097
6098 /* First try to merge in the other name into our unit */
6099 r = unit_merge_by_name(*u, k);
6100 if (r < 0) {
6101 Unit *other;
6102
6103 /* Hmm, we couldn't merge the other unit into ours? Then let's try it the other way
6104 * round. */
6105
6106 other = manager_get_unit((*u)->manager, k);
6107 if (!other)
6108 return r; /* return previous failure */
6109
6110 r = unit_merge(other, *u);
6111 if (r < 0)
6112 return r;
6113
6114 *u = other;
6115 return merge_by_names(u, names, NULL);
6116 }
6117
6118 if (streq_ptr(id, k))
6119 unit_choose_id(*u, id);
6120 }
6121
6122 return 0;
6123 }
6124
6125 int unit_load_fragment(Unit *u) {
6126 const char *fragment;
6127 _cleanup_set_free_free_ Set *names = NULL;
6128 int r;
6129
6130 assert(u);
6131 assert(u->load_state == UNIT_STUB);
6132 assert(u->id);
6133
6134 if (u->transient) {
6135 u->access_selinux_context = mfree(u->access_selinux_context);
6136 u->load_state = UNIT_LOADED;
6137 return 0;
6138 }
6139
6140 /* Possibly rebuild the fragment map to catch new units */
6141 r = unit_file_build_name_map(&u->manager->lookup_paths,
6142 &u->manager->unit_cache_timestamp_hash,
6143 &u->manager->unit_id_map,
6144 &u->manager->unit_name_map,
6145 &u->manager->unit_path_cache);
6146 if (r < 0)
6147 return log_error_errno(r, "Failed to rebuild name map: %m");
6148
6149 r = unit_file_find_fragment(u->manager->unit_id_map,
6150 u->manager->unit_name_map,
6151 u->id,
6152 &fragment,
6153 &names);
6154 if (r < 0 && r != -ENOENT)
6155 return r;
6156
6157 if (fragment) {
6158 /* Open the file, check if this is a mask, otherwise read. */
6159 _cleanup_fclose_ FILE *f = NULL;
6160 struct stat st;
6161
6162 /* Try to open the file name. A symlink is OK, for example for linked files or masks. We
6163 * expect that all symlinks within the lookup paths have been already resolved, but we don't
6164 * verify this here. */
6165 f = fopen(fragment, "re");
6166 if (!f)
6167 return log_unit_notice_errno(u, errno, "Failed to open %s: %m", fragment);
6168
6169 if (fstat(fileno(f), &st) < 0)
6170 return -errno;
6171
6172 r = free_and_strdup(&u->fragment_path, fragment);
6173 if (r < 0)
6174 return r;
6175
6176 if (null_or_empty(&st)) {
6177 /* Unit file is masked */
6178
6179 u->load_state = u->perpetual ? UNIT_LOADED : UNIT_MASKED; /* don't allow perpetual units to ever be masked */
6180 u->fragment_mtime = 0;
6181 u->access_selinux_context = mfree(u->access_selinux_context);
6182 } else {
6183 #if HAVE_SELINUX
6184 if (mac_selinux_use()) {
6185 _cleanup_freecon_ char *selcon = NULL;
6186
6187 /* Cache the SELinux context of the unit file here. We'll make use of when checking access permissions to loaded units */
6188 r = fgetfilecon_raw(fileno(f), &selcon);
6189 if (r < 0)
6190 log_unit_warning_errno(u, r, "Failed to read SELinux context of '%s', ignoring: %m", fragment);
6191
6192 r = free_and_strdup(&u->access_selinux_context, selcon);
6193 if (r < 0)
6194 return r;
6195 } else
6196 #endif
6197 u->access_selinux_context = mfree(u->access_selinux_context);
6198
6199 u->load_state = UNIT_LOADED;
6200 u->fragment_mtime = timespec_load(&st.st_mtim);
6201
6202 /* Now, parse the file contents */
6203 r = config_parse(u->id, fragment, f,
6204 UNIT_VTABLE(u)->sections,
6205 config_item_perf_lookup, load_fragment_gperf_lookup,
6206 0,
6207 u,
6208 NULL);
6209 if (r == -ENOEXEC)
6210 log_unit_notice_errno(u, r, "Unit configuration has fatal error, unit will not be started.");
6211 if (r < 0)
6212 return r;
6213 }
6214 }
6215
6216 /* Call merge_by_names with the name derived from the fragment path as the preferred name.
6217 *
6218 * We do the merge dance here because for some unit types, the unit might have aliases which are not
6219 * declared in the file system. In particular, this is true (and frequent) for device and swap units.
6220 */
6221 const char *id = u->id;
6222 _cleanup_free_ char *free_id = NULL;
6223
6224 if (fragment) {
6225 id = basename(fragment);
6226 if (unit_name_is_valid(id, UNIT_NAME_TEMPLATE)) {
6227 assert(u->instance); /* If we're not trying to use a template for non-instanced unit,
6228 * this must be set. */
6229
6230 r = unit_name_replace_instance(id, u->instance, &free_id);
6231 if (r < 0)
6232 return log_debug_errno(r, "Failed to build id (%s + %s): %m", id, u->instance);
6233 id = free_id;
6234 }
6235 }
6236
6237 Unit *merged = u;
6238 r = merge_by_names(&merged, names, id);
6239 if (r < 0)
6240 return r;
6241
6242 if (merged != u)
6243 u->load_state = UNIT_MERGED;
6244
6245 return 0;
6246 }
6247
6248 void unit_dump_config_items(FILE *f) {
6249 static const struct {
6250 const ConfigParserCallback callback;
6251 const char *rvalue;
6252 } table[] = {
6253 { config_parse_warn_compat, "NOTSUPPORTED" },
6254 { config_parse_int, "INTEGER" },
6255 { config_parse_unsigned, "UNSIGNED" },
6256 { config_parse_iec_size, "SIZE" },
6257 { config_parse_iec_uint64, "SIZE" },
6258 { config_parse_si_uint64, "SIZE" },
6259 { config_parse_bool, "BOOLEAN" },
6260 { config_parse_string, "STRING" },
6261 { config_parse_path, "PATH" },
6262 { config_parse_unit_path_printf, "PATH" },
6263 { config_parse_colon_separated_paths, "PATH" },
6264 { config_parse_strv, "STRING [...]" },
6265 { config_parse_exec_nice, "NICE" },
6266 { config_parse_exec_oom_score_adjust, "OOMSCOREADJUST" },
6267 { config_parse_exec_io_class, "IOCLASS" },
6268 { config_parse_exec_io_priority, "IOPRIORITY" },
6269 { config_parse_exec_cpu_sched_policy, "CPUSCHEDPOLICY" },
6270 { config_parse_exec_cpu_sched_prio, "CPUSCHEDPRIO" },
6271 { config_parse_exec_cpu_affinity, "CPUAFFINITY" },
6272 { config_parse_mode, "MODE" },
6273 { config_parse_unit_env_file, "FILE" },
6274 { config_parse_exec_output, "OUTPUT" },
6275 { config_parse_exec_input, "INPUT" },
6276 { config_parse_log_facility, "FACILITY" },
6277 { config_parse_log_level, "LEVEL" },
6278 { config_parse_exec_secure_bits, "SECUREBITS" },
6279 { config_parse_capability_set, "BOUNDINGSET" },
6280 { config_parse_rlimit, "LIMIT" },
6281 { config_parse_unit_deps, "UNIT [...]" },
6282 { config_parse_exec, "PATH [ARGUMENT [...]]" },
6283 { config_parse_service_type, "SERVICETYPE" },
6284 { config_parse_service_exit_type, "SERVICEEXITTYPE" },
6285 { config_parse_service_restart, "SERVICERESTART" },
6286 { config_parse_service_timeout_failure_mode, "TIMEOUTMODE" },
6287 { config_parse_kill_mode, "KILLMODE" },
6288 { config_parse_signal, "SIGNAL" },
6289 { config_parse_socket_listen, "SOCKET [...]" },
6290 { config_parse_socket_bind, "SOCKETBIND" },
6291 { config_parse_socket_bindtodevice, "NETWORKINTERFACE" },
6292 { config_parse_sec, "SECONDS" },
6293 { config_parse_nsec, "NANOSECONDS" },
6294 { config_parse_namespace_path_strv, "PATH [...]" },
6295 { config_parse_bind_paths, "PATH[:PATH[:OPTIONS]] [...]" },
6296 { config_parse_unit_requires_mounts_for, "PATH [...]" },
6297 { config_parse_exec_mount_flags, "MOUNTFLAG [...]" },
6298 { config_parse_unit_string_printf, "STRING" },
6299 { config_parse_trigger_unit, "UNIT" },
6300 { config_parse_timer, "TIMER" },
6301 { config_parse_path_spec, "PATH" },
6302 { config_parse_notify_access, "ACCESS" },
6303 { config_parse_ip_tos, "TOS" },
6304 { config_parse_unit_condition_path, "CONDITION" },
6305 { config_parse_unit_condition_string, "CONDITION" },
6306 { config_parse_unit_slice, "SLICE" },
6307 { config_parse_documentation, "URL" },
6308 { config_parse_service_timeout, "SECONDS" },
6309 { config_parse_emergency_action, "ACTION" },
6310 { config_parse_set_status, "STATUS" },
6311 { config_parse_service_sockets, "SOCKETS" },
6312 { config_parse_environ, "ENVIRON" },
6313 #if HAVE_SECCOMP
6314 { config_parse_syscall_filter, "SYSCALLS" },
6315 { config_parse_syscall_archs, "ARCHS" },
6316 { config_parse_syscall_errno, "ERRNO" },
6317 { config_parse_syscall_log, "SYSCALLS" },
6318 { config_parse_address_families, "FAMILIES" },
6319 { config_parse_restrict_namespaces, "NAMESPACES" },
6320 #endif
6321 { config_parse_restrict_filesystems, "FILESYSTEMS" },
6322 { config_parse_cpu_shares, "SHARES" },
6323 { config_parse_cg_weight, "WEIGHT" },
6324 { config_parse_cg_cpu_weight, "CPUWEIGHT" },
6325 { config_parse_memory_limit, "LIMIT" },
6326 { config_parse_device_allow, "DEVICE" },
6327 { config_parse_device_policy, "POLICY" },
6328 { config_parse_io_limit, "LIMIT" },
6329 { config_parse_io_device_weight, "DEVICEWEIGHT" },
6330 { config_parse_io_device_latency, "DEVICELATENCY" },
6331 { config_parse_blockio_bandwidth, "BANDWIDTH" },
6332 { config_parse_blockio_weight, "WEIGHT" },
6333 { config_parse_blockio_device_weight, "DEVICEWEIGHT" },
6334 { config_parse_long, "LONG" },
6335 { config_parse_socket_service, "SERVICE" },
6336 #if HAVE_SELINUX
6337 { config_parse_exec_selinux_context, "LABEL" },
6338 #endif
6339 { config_parse_job_mode, "MODE" },
6340 { config_parse_job_mode_isolate, "BOOLEAN" },
6341 { config_parse_personality, "PERSONALITY" },
6342 };
6343
6344 const char *prev = NULL;
6345 const char *i;
6346
6347 assert(f);
6348
6349 NULSTR_FOREACH(i, load_fragment_gperf_nulstr) {
6350 const char *rvalue = "OTHER", *lvalue;
6351 const ConfigPerfItem *p;
6352 const char *dot;
6353
6354 assert_se(p = load_fragment_gperf_lookup(i, strlen(i)));
6355
6356 /* Hide legacy settings */
6357 if (p->parse == config_parse_warn_compat &&
6358 p->ltype == DISABLED_LEGACY)
6359 continue;
6360
6361 for (size_t j = 0; j < ELEMENTSOF(table); j++)
6362 if (p->parse == table[j].callback) {
6363 rvalue = table[j].rvalue;
6364 break;
6365 }
6366
6367 dot = strchr(i, '.');
6368 lvalue = dot ? dot + 1 : i;
6369
6370 if (dot) {
6371 size_t prefix_len = dot - i;
6372
6373 if (!prev || !strneq(prev, i, prefix_len+1)) {
6374 if (prev)
6375 fputc('\n', f);
6376
6377 fprintf(f, "[%.*s]\n", (int) prefix_len, i);
6378 }
6379 }
6380
6381 fprintf(f, "%s=%s\n", lvalue, rvalue);
6382 prev = i;
6383 }
6384 }
6385
6386 int config_parse_cpu_affinity2(
6387 const char *unit,
6388 const char *filename,
6389 unsigned line,
6390 const char *section,
6391 unsigned section_line,
6392 const char *lvalue,
6393 int ltype,
6394 const char *rvalue,
6395 void *data,
6396 void *userdata) {
6397
6398 CPUSet *affinity = data;
6399
6400 assert(affinity);
6401
6402 (void) parse_cpu_set_extend(rvalue, affinity, true, unit, filename, line, lvalue);
6403
6404 return 0;
6405 }
6406
6407 int config_parse_show_status(
6408 const char* unit,
6409 const char *filename,
6410 unsigned line,
6411 const char *section,
6412 unsigned section_line,
6413 const char *lvalue,
6414 int ltype,
6415 const char *rvalue,
6416 void *data,
6417 void *userdata) {
6418
6419 int k;
6420 ShowStatus *b = data;
6421
6422 assert(filename);
6423 assert(lvalue);
6424 assert(rvalue);
6425 assert(data);
6426
6427 k = parse_show_status(rvalue, b);
6428 if (k < 0)
6429 log_syntax(unit, LOG_WARNING, filename, line, k, "Failed to parse show status setting, ignoring: %s", rvalue);
6430
6431 return 0;
6432 }
6433
6434 int config_parse_output_restricted(
6435 const char* unit,
6436 const char *filename,
6437 unsigned line,
6438 const char *section,
6439 unsigned section_line,
6440 const char *lvalue,
6441 int ltype,
6442 const char *rvalue,
6443 void *data,
6444 void *userdata) {
6445
6446 ExecOutput t, *eo = data;
6447 bool obsolete = false;
6448
6449 assert(filename);
6450 assert(lvalue);
6451 assert(rvalue);
6452 assert(data);
6453
6454 if (streq(rvalue, "syslog")) {
6455 t = EXEC_OUTPUT_JOURNAL;
6456 obsolete = true;
6457 } else if (streq(rvalue, "syslog+console")) {
6458 t = EXEC_OUTPUT_JOURNAL_AND_CONSOLE;
6459 obsolete = true;
6460 } else {
6461 t = exec_output_from_string(rvalue);
6462 if (t < 0) {
6463 log_syntax(unit, LOG_WARNING, filename, line, t, "Failed to parse output type, ignoring: %s", rvalue);
6464 return 0;
6465 }
6466
6467 if (IN_SET(t, EXEC_OUTPUT_SOCKET, EXEC_OUTPUT_NAMED_FD, EXEC_OUTPUT_FILE, EXEC_OUTPUT_FILE_APPEND, EXEC_OUTPUT_FILE_TRUNCATE)) {
6468 log_syntax(unit, LOG_WARNING, filename, line, 0, "Standard output types socket, fd:, file:, append:, truncate: are not supported as defaults, ignoring: %s", rvalue);
6469 return 0;
6470 }
6471 }
6472
6473 if (obsolete)
6474 log_syntax(unit, LOG_NOTICE, filename, line, 0,
6475 "Standard output type %s is obsolete, automatically updating to %s. Please update your configuration.",
6476 rvalue, exec_output_to_string(t));
6477
6478 *eo = t;
6479 return 0;
6480 }
6481
6482 int config_parse_crash_chvt(
6483 const char* unit,
6484 const char *filename,
6485 unsigned line,
6486 const char *section,
6487 unsigned section_line,
6488 const char *lvalue,
6489 int ltype,
6490 const char *rvalue,
6491 void *data,
6492 void *userdata) {
6493
6494 int r;
6495
6496 assert(filename);
6497 assert(lvalue);
6498 assert(rvalue);
6499 assert(data);
6500
6501 r = parse_crash_chvt(rvalue, data);
6502 if (r < 0)
6503 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse CrashChangeVT= setting, ignoring: %s", rvalue);
6504
6505 return 0;
6506 }
6507
6508 int config_parse_swap_priority(
6509 const char *unit,
6510 const char *filename,
6511 unsigned line,
6512 const char *section,
6513 unsigned section_line,
6514 const char *lvalue,
6515 int ltype,
6516 const char *rvalue,
6517 void *data,
6518 void *userdata) {
6519
6520 Swap *s = userdata;
6521 int r, priority;
6522
6523 assert(s);
6524 assert(filename);
6525 assert(lvalue);
6526 assert(rvalue);
6527 assert(data);
6528
6529 if (isempty(rvalue)) {
6530 s->parameters_fragment.priority = -1;
6531 s->parameters_fragment.priority_set = false;
6532 return 0;
6533 }
6534
6535 r = safe_atoi(rvalue, &priority);
6536 if (r < 0) {
6537 log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid swap priority '%s', ignoring.", rvalue);
6538 return 0;
6539 }
6540
6541 if (priority < -1) {
6542 log_syntax(unit, LOG_WARNING, filename, line, 0, "Sorry, swap priorities smaller than -1 may only be assigned by the kernel itself, ignoring: %s", rvalue);
6543 return 0;
6544 }
6545
6546 if (priority > 32767) {
6547 log_syntax(unit, LOG_WARNING, filename, line, 0, "Swap priority out of range, ignoring: %s", rvalue);
6548 return 0;
6549 }
6550
6551 s->parameters_fragment.priority = priority;
6552 s->parameters_fragment.priority_set = true;
6553 return 0;
6554 }
6555
6556 int config_parse_watchdog_sec(
6557 const char *unit,
6558 const char *filename,
6559 unsigned line,
6560 const char *section,
6561 unsigned section_line,
6562 const char *lvalue,
6563 int ltype,
6564 const char *rvalue,
6565 void *data,
6566 void *userdata) {
6567
6568 usec_t *usec = data;
6569
6570 assert(filename);
6571 assert(lvalue);
6572 assert(rvalue);
6573
6574 /* This is called for {Runtime,Reboot,KExec}WatchdogSec= where "default" maps to
6575 * USEC_INFINITY internally. */
6576
6577 if (streq(rvalue, "default"))
6578 *usec = USEC_INFINITY;
6579 else if (streq(rvalue, "off"))
6580 *usec = 0;
6581 else
6582 return config_parse_sec(unit, filename, line, section, section_line, lvalue, ltype, rvalue, data, userdata);
6583
6584 return 0;
6585 }
6586
6587 int config_parse_tty_size(
6588 const char *unit,
6589 const char *filename,
6590 unsigned line,
6591 const char *section,
6592 unsigned section_line,
6593 const char *lvalue,
6594 int ltype,
6595 const char *rvalue,
6596 void *data,
6597 void *userdata) {
6598
6599 unsigned *sz = data;
6600
6601 assert(filename);
6602 assert(lvalue);
6603 assert(rvalue);
6604
6605 if (isempty(rvalue)) {
6606 *sz = UINT_MAX;
6607 return 0;
6608 }
6609
6610 return config_parse_unsigned(unit, filename, line, section, section_line, lvalue, ltype, rvalue, data, userdata);
6611 }