1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
3 Copyright © 2012 Holger Hans Peter Freyther
11 #include <sys/resource.h>
13 #include "sd-messages.h"
16 #include "all-units.h"
17 #include "alloc-util.h"
18 #include "bpf-firewall.h"
20 #include "bpf-program.h"
21 #include "bpf-socket-bind.h"
22 #include "bus-error.h"
23 #include "bus-internal.h"
26 #include "capability-util.h"
27 #include "cgroup-setup.h"
28 #include "conf-parser.h"
29 #include "core-varlink.h"
30 #include "cpu-set-util.h"
31 #include "creds-util.h"
33 #include "errno-list.h"
35 #include "exec-credential.h"
39 #include "firewall-util.h"
41 #include "hexdecoct.h"
42 #include "iovec-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"
49 #include "missing_ioprio.h"
50 #include "mountpoint-util.h"
51 #include "nulstr-util.h"
52 #include "open-file.h"
53 #include "parse-helpers.h"
54 #include "parse-util.h"
55 #include "path-util.h"
56 #include "pcre2-util.h"
57 #include "percent-util.h"
58 #include "process-util.h"
59 #include "seccomp-util.h"
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"
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"
76 static int parse_socket_protocol(const char *s
) {
79 r
= parse_ip_protocol(s
);
82 if (!IN_SET(r
, IPPROTO_UDPLITE
, IPPROTO_SCTP
))
83 return -EPROTONOSUPPORT
;
88 int parse_crash_chvt(const char *value
, int *data
) {
91 if (safe_atoi(value
, data
) >= 0)
94 b
= parse_boolean(value
);
99 *data
= 0; /* switch to where kmsg goes */
101 *data
= -1; /* turn off switching */
106 int parse_confirm_spawn(const char *value
, char **console
) {
110 r
= value
? parse_boolean(value
) : 1;
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 */
118 else /* on with only a tty file name, not a fully qualified path */
119 s
= path_join("/dev/", value
);
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_exec_preserve_mode
, exec_preserve_mode
, ExecPreserveMode
, "Failed to parse resource 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_restart_mode
, service_restart_mode
, ServiceRestartMode
, "Failed to parse service restart mode");
144 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_timeout_failure_mode
, service_timeout_failure_mode
, ServiceTimeoutFailureMode
, "Failed to parse timeout failure mode");
145 DEFINE_CONFIG_PARSE_ENUM(config_parse_socket_bind
, socket_address_bind_ipv6_only_or_bool
, SocketAddressBindIPv6Only
, "Failed to parse bind IPv6 only value");
146 DEFINE_CONFIG_PARSE_ENUM(config_parse_oom_policy
, oom_policy
, OOMPolicy
, "Failed to parse OOM policy");
147 DEFINE_CONFIG_PARSE_ENUM(config_parse_managed_oom_preference
, managed_oom_preference
, ManagedOOMPreference
, "Failed to parse ManagedOOMPreference=");
148 DEFINE_CONFIG_PARSE_ENUM(config_parse_memory_pressure_watch
, cgroup_pressure_watch
, CGroupPressureWatch
, "Failed to parse memory pressure watch setting");
149 DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_ip_tos
, ip_tos
, int, -1, "Failed to parse IP TOS value");
150 DEFINE_CONFIG_PARSE_PTR(config_parse_blockio_weight
, cg_blkio_weight_parse
, uint64_t, "Invalid block IO weight");
151 DEFINE_CONFIG_PARSE_PTR(config_parse_cg_weight
, cg_weight_parse
, uint64_t, "Invalid weight");
152 DEFINE_CONFIG_PARSE_PTR(config_parse_cg_cpu_weight
, cg_cpu_weight_parse
, uint64_t, "Invalid CPU weight");
153 static DEFINE_CONFIG_PARSE_PTR(config_parse_cpu_shares_internal
, cg_cpu_shares_parse
, uint64_t, "Invalid CPU shares");
154 DEFINE_CONFIG_PARSE_PTR(config_parse_exec_mount_propagation_flag
, mount_propagation_flag_from_string
, unsigned long, "Failed to parse mount propagation flag");
155 DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_numa_policy
, mpol
, int, -1, "Invalid NUMA policy type");
156 DEFINE_CONFIG_PARSE_ENUM(config_parse_status_unit_format
, status_unit_format
, StatusUnitFormat
, "Failed to parse status unit format");
157 DEFINE_CONFIG_PARSE_ENUM_FULL(config_parse_socket_timestamping
, socket_timestamping_from_string_harder
, SocketTimestamping
, "Failed to parse timestamping precision");
159 int config_parse_cpu_shares(
161 const char *filename
,
164 unsigned section_line
,
176 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
177 "Unit uses %s=; please use CPUWeight= instead. Support for %s= will be removed soon.",
180 return config_parse_cpu_shares_internal(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
);
183 bool contains_instance_specifier_superset(const char *s
) {
185 bool percent
= false;
199 /* If the string is just the instance specifier, it's not a superset of the instance. */
200 if (memcmp_nn(p
, q
- p
, "%i", strlen("%i")) == 0)
203 /* %i, %n and %N all expand to the instance or a superset of it. */
208 if (IN_SET(*p
, 'n', 'N', 'i'))
216 /* `name` is the rendered version of `format` via `unit_printf` or similar functions. */
217 int unit_is_likely_recursive_template_dependency(Unit
*u
, const char *name
, const char *format
) {
218 const char *fragment_path
;
224 /* If a template unit has a direct dependency on itself that includes the unit instance as part of
225 * the template instance via a unit specifier (%i, %n or %N), this will almost certainly lead to
226 * infinite recursion as systemd will keep instantiating new instances of the template unit.
227 * https://github.com/systemd/systemd/issues/17602 shows a good example of how this can happen in
228 * practice. To guard against this, we check for templates that depend on themselves and have the
229 * instantiated unit instance included as part of the template instance of the dependency via a
232 * For example, if systemd-notify@.service depends on systemd-notify@%n.service, this will result in
233 * infinite recursion.
236 if (!unit_name_is_valid(name
, UNIT_NAME_INSTANCE
))
239 if (!unit_name_prefix_equal(u
->id
, name
))
242 if (u
->type
!= unit_name_to_type(name
))
245 r
= unit_file_find_fragment(u
->manager
->unit_id_map
, u
->manager
->unit_name_map
, name
, &fragment_path
, NULL
);
249 /* Fragment paths should also be equal as a custom fragment for a specific template instance
250 * wouldn't necessarily lead to infinite recursion. */
251 if (!path_equal_ptr(u
->fragment_path
, fragment_path
))
254 if (!contains_instance_specifier_superset(format
))
260 int config_parse_unit_deps(
262 const char *filename
,
265 unsigned section_line
,
272 UnitDependency d
= ltype
;
279 for (const char *p
= rvalue
;;) {
280 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
283 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_RETAIN_ESCAPE
);
289 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
293 r
= unit_name_printf(u
, word
, &k
);
295 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
299 r
= unit_is_likely_recursive_template_dependency(u
, k
, word
);
301 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to determine if '%s' is a recursive dependency, ignoring: %m", k
);
305 log_syntax(unit
, LOG_DEBUG
, filename
, line
, 0,
306 "Dropping dependency %s=%s that likely leads to infinite recursion.",
307 unit_dependency_to_string(d
), word
);
311 r
= unit_add_dependency_by_name(u
, d
, k
, true, UNIT_DEPENDENCY_FILE
);
313 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
317 int config_parse_obsolete_unit_deps(
319 const char *filename
,
322 unsigned section_line
,
329 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
330 "Unit dependency type %s= is obsolete, replacing by %s=, please update your unit file", lvalue
, unit_dependency_to_string(ltype
));
332 return config_parse_unit_deps(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
);
335 int config_parse_unit_string_printf(
337 const char *filename
,
340 unsigned section_line
,
347 _cleanup_free_
char *k
= NULL
;
348 const Unit
*u
= ASSERT_PTR(userdata
);
355 r
= unit_full_printf(u
, rvalue
, &k
);
357 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
361 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
364 int config_parse_unit_strv_printf(
366 const char *filename
,
369 unsigned section_line
,
376 const Unit
*u
= ASSERT_PTR(userdata
);
377 _cleanup_free_
char *k
= NULL
;
384 r
= unit_full_printf(u
, rvalue
, &k
);
386 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
390 return config_parse_strv(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
393 int config_parse_unit_path_printf(
395 const char *filename
,
398 unsigned section_line
,
405 _cleanup_free_
char *k
= NULL
;
406 const Unit
*u
= ASSERT_PTR(userdata
);
414 r
= unit_path_printf(u
, rvalue
, &k
);
416 log_syntax(unit
, fatal
? LOG_ERR
: LOG_WARNING
, filename
, line
, r
,
417 "Failed to resolve unit specifiers in '%s'%s: %m",
418 rvalue
, fatal
? "" : ", ignoring");
419 return fatal
? -ENOEXEC
: 0;
422 return config_parse_path(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
425 int config_parse_colon_separated_paths(
427 const char *filename
,
430 unsigned section_line
,
436 char ***sv
= ASSERT_PTR(data
);
437 const Unit
*u
= userdata
;
444 if (isempty(rvalue
)) {
445 /* Empty assignment resets the list */
446 *sv
= strv_free(*sv
);
450 for (const char *p
= rvalue
;;) {
451 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
453 r
= extract_first_word(&p
, &word
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
457 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
463 r
= unit_path_printf(u
, word
, &k
);
465 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
466 "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
470 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
474 r
= strv_consume(sv
, TAKE_PTR(k
));
482 int config_parse_unit_path_strv_printf(
484 const char *filename
,
487 unsigned section_line
,
495 const Unit
*u
= ASSERT_PTR(userdata
);
502 if (isempty(rvalue
)) {
507 for (const char *p
= rvalue
;;) {
508 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
510 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
516 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
517 "Invalid syntax, ignoring: %s", rvalue
);
521 r
= unit_path_printf(u
, word
, &k
);
523 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
524 "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
528 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
532 r
= strv_consume(x
, TAKE_PTR(k
));
538 static int patch_var_run(
540 const char *filename
,
548 e
= path_startswith(*path
, "/var/run/");
552 z
= path_join("/run/", e
);
556 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
557 "%s= references a path below legacy directory /var/run/, updating %s → %s; "
558 "please update the unit file accordingly.", lvalue
, *path
, z
);
560 free_and_replace(*path
, z
);
565 int config_parse_socket_listen(
567 const char *filename
,
570 unsigned section_line
,
577 _cleanup_free_ SocketPort
*p
= NULL
;
589 if (isempty(rvalue
)) {
590 /* An empty assignment removes all ports */
591 socket_free_ports(s
);
595 p
= new0(SocketPort
, 1);
599 if (ltype
!= SOCKET_SOCKET
) {
600 _cleanup_free_
char *k
= NULL
;
602 r
= unit_path_printf(UNIT(s
), rvalue
, &k
);
604 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
608 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
612 if (ltype
== SOCKET_FIFO
) {
613 r
= patch_var_run(unit
, filename
, line
, lvalue
, &k
);
618 free_and_replace(p
->path
, k
);
621 } else if (streq(lvalue
, "ListenNetlink")) {
622 _cleanup_free_
char *k
= NULL
;
624 r
= unit_path_printf(UNIT(s
), rvalue
, &k
);
626 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
630 r
= socket_address_parse_netlink(&p
->address
, k
);
632 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse address value in '%s', ignoring: %m", k
);
636 p
->type
= SOCKET_SOCKET
;
639 _cleanup_free_
char *k
= NULL
;
641 r
= unit_path_printf(UNIT(s
), rvalue
, &k
);
643 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
647 if (k
[0] == '/') { /* Only for AF_UNIX file system sockets… */
648 r
= patch_var_run(unit
, filename
, line
, lvalue
, &k
);
653 r
= socket_address_parse_and_warn(&p
->address
, k
);
655 if (r
!= -EAFNOSUPPORT
)
656 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse address value in '%s', ignoring: %m", k
);
660 if (streq(lvalue
, "ListenStream"))
661 p
->address
.type
= SOCK_STREAM
;
662 else if (streq(lvalue
, "ListenDatagram"))
663 p
->address
.type
= SOCK_DGRAM
;
665 assert(streq(lvalue
, "ListenSequentialPacket"));
666 p
->address
.type
= SOCK_SEQPACKET
;
669 if (socket_address_family(&p
->address
) != AF_UNIX
&& p
->address
.type
== SOCK_SEQPACKET
) {
670 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Address family not supported, ignoring: %s", rvalue
);
674 p
->type
= SOCKET_SOCKET
;
678 p
->auxiliary_fds
= NULL
;
679 p
->n_auxiliary_fds
= 0;
682 tail
= LIST_FIND_TAIL(port
, s
->ports
);
683 LIST_INSERT_AFTER(port
, s
->ports
, tail
, p
);
690 int config_parse_exec_nice(
692 const char *filename
,
695 unsigned section_line
,
702 ExecContext
*c
= ASSERT_PTR(data
);
709 if (isempty(rvalue
)) {
714 r
= parse_nice(rvalue
, &priority
);
717 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Nice priority out of range, ignoring: %s", rvalue
);
719 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse nice priority '%s', ignoring: %m", rvalue
);
729 int config_parse_exec_oom_score_adjust(
731 const char *filename
,
734 unsigned section_line
,
741 ExecContext
*c
= ASSERT_PTR(data
);
748 if (isempty(rvalue
)) {
749 c
->oom_score_adjust_set
= false;
753 r
= parse_oom_score_adjust(rvalue
, &oa
);
756 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "OOM score adjust value out of range, ignoring: %s", rvalue
);
758 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse the OOM score adjust value '%s', ignoring: %m", rvalue
);
762 c
->oom_score_adjust
= oa
;
763 c
->oom_score_adjust_set
= true;
768 int config_parse_exec_coredump_filter(
770 const char *filename
,
773 unsigned section_line
,
780 ExecContext
*c
= ASSERT_PTR(data
);
787 if (isempty(rvalue
)) {
788 c
->coredump_filter
= 0;
789 c
->coredump_filter_set
= false;
794 r
= coredump_filter_mask_from_string(rvalue
, &f
);
796 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
797 "Failed to parse the CoredumpFilter=%s, ignoring: %m", rvalue
);
801 c
->coredump_filter
|= f
;
802 c
->coredump_filter_set
= true;
806 int config_parse_kill_mode(
808 const char *filename
,
811 unsigned section_line
,
818 KillMode
*k
= data
, m
;
825 if (isempty(rvalue
)) {
826 *k
= KILL_CONTROL_GROUP
;
830 m
= kill_mode_from_string(rvalue
);
832 log_syntax(unit
, LOG_WARNING
, filename
, line
, m
,
833 "Failed to parse kill mode specification, ignoring: %s", rvalue
);
838 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
839 "Unit uses KillMode=none. "
840 "This is unsafe, as it disables systemd's process lifecycle management for the service. "
841 "Please update the service to use a safer KillMode=, such as 'mixed' or 'control-group'. "
842 "Support for KillMode=none is deprecated and will eventually be removed.");
848 int config_parse_exec(
850 const char *filename
,
853 unsigned section_line
,
860 ExecCommand
**e
= ASSERT_PTR(data
);
861 const Unit
*u
= userdata
;
872 if (isempty(rvalue
)) {
873 /* An empty assignment resets the list */
874 *e
= exec_command_free_list(*e
);
880 _cleanup_free_
char *path
= NULL
, *firstword
= NULL
;
881 ExecCommandFlags flags
= 0;
882 bool ignore
= false, separate_argv0
= false;
883 _cleanup_free_ ExecCommand
*nce
= NULL
;
884 _cleanup_strv_free_
char **n
= NULL
;
890 r
= extract_first_word_and_warn(&p
, &firstword
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
894 /* A lone ";" is a separator. Let's make sure we don't treat it as an executable name. */
895 if (streq(firstword
, ";")) {
902 /* We accept an absolute path as first argument. If it's prefixed with - and the path doesn't
903 * exist, we ignore it instead of erroring out; if it's prefixed with @, we allow overriding of
904 * argv[0]; if it's prefixed with :, we will not do environment variable substitution;
905 * if it's prefixed with +, it will be run with full privileges and no sandboxing; if
906 * it's prefixed with '!' we apply sandboxing, but do not change user/group credentials; if
907 * it's prefixed with '!!', then we apply user/group credentials if the kernel supports ambient
908 * capabilities -- if it doesn't we don't apply the credentials themselves, but do apply most
909 * other sandboxing, with some special exceptions for changing UID.
911 * The idea is that '!!' may be used to write services that can take benefit of systemd's
912 * UID/GID dropping if the kernel supports ambient creds, but provide an automatic fallback to
913 * privilege dropping within the daemon if the kernel does not offer that. */
915 if (*f
== '-' && !(flags
& EXEC_COMMAND_IGNORE_FAILURE
)) {
916 flags
|= EXEC_COMMAND_IGNORE_FAILURE
;
918 } else if (*f
== '@' && !separate_argv0
)
919 separate_argv0
= true;
920 else if (*f
== ':' && !(flags
& EXEC_COMMAND_NO_ENV_EXPAND
))
921 flags
|= EXEC_COMMAND_NO_ENV_EXPAND
;
922 else if (*f
== '+' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
923 flags
|= EXEC_COMMAND_FULLY_PRIVILEGED
;
924 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
925 flags
|= EXEC_COMMAND_NO_SETUID
;
926 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_AMBIENT_MAGIC
))) {
927 flags
&= ~EXEC_COMMAND_NO_SETUID
;
928 flags
|= EXEC_COMMAND_AMBIENT_MAGIC
;
934 r
= unit_path_printf(u
, f
, &path
);
936 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
937 "Failed to resolve unit specifiers in '%s'%s: %m",
938 f
, ignore
? ", ignoring" : "");
939 return ignore
? 0 : -ENOEXEC
;
943 /* First word is either "-" or "@" with no command. */
944 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
945 "Empty path in command line%s: '%s'",
946 ignore
? ", ignoring" : "", rvalue
);
947 return ignore
? 0 : -ENOEXEC
;
949 if (!string_is_safe(path
)) {
950 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
951 "Executable name contains special characters%s: %s",
952 ignore
? ", ignoring" : "", path
);
953 return ignore
? 0 : -ENOEXEC
;
955 if (endswith(path
, "/")) {
956 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
957 "Executable path specifies a directory%s: %s",
958 ignore
? ", ignoring" : "", path
);
959 return ignore
? 0 : -ENOEXEC
;
962 if (!(path_is_absolute(path
) ? path_is_valid(path
) : filename_is_valid(path
))) {
963 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
964 "Neither a valid executable name nor an absolute path%s: %s",
965 ignore
? ", ignoring" : "", path
);
966 return ignore
? 0 : -ENOEXEC
;
969 if (!separate_argv0
) {
972 if (!GREEDY_REALLOC0(n
, nlen
+ 2))
984 while (!isempty(p
)) {
985 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
987 /* Check explicitly for an unquoted semicolon as
988 * command separator token. */
989 if (p
[0] == ';' && (!p
[1] || strchr(WHITESPACE
, p
[1]))) {
991 p
+= strspn(p
, WHITESPACE
);
996 /* Check for \; explicitly, to not confuse it with \\; or "\;" or "\\;" etc.
997 * extract_first_word() would return the same for all of those. */
998 if (p
[0] == '\\' && p
[1] == ';' && (!p
[2] || strchr(WHITESPACE
, p
[2]))) {
1002 p
+= strspn(p
, WHITESPACE
);
1004 if (!GREEDY_REALLOC0(n
, nlen
+ 2))
1015 r
= extract_first_word_and_warn(&p
, &word
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
1019 return ignore
? 0 : -ENOEXEC
;
1021 r
= unit_full_printf(u
, word
, &resolved
);
1023 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
1024 "Failed to resolve unit specifiers in %s%s: %m",
1025 word
, ignore
? ", ignoring" : "");
1026 return ignore
? 0 : -ENOEXEC
;
1029 if (!GREEDY_REALLOC(n
, nlen
+ 2))
1032 n
[nlen
++] = TAKE_PTR(resolved
);
1037 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
1038 "Empty executable name or zeroeth argument%s: %s",
1039 ignore
? ", ignoring" : "", rvalue
);
1040 return ignore
? 0 : -ENOEXEC
;
1043 nce
= new0(ExecCommand
, 1);
1047 nce
->argv
= TAKE_PTR(n
);
1048 nce
->path
= TAKE_PTR(path
);
1051 exec_command_append_list(e
, nce
);
1053 /* Do not _cleanup_free_ these. */
1057 } while (semicolon
);
1062 int config_parse_socket_bindtodevice(
1064 const char *filename
,
1066 const char *section
,
1067 unsigned section_line
,
1074 Socket
*s
= ASSERT_PTR(data
);
1080 if (isempty(rvalue
) || streq(rvalue
, "*")) {
1081 s
->bind_to_device
= mfree(s
->bind_to_device
);
1085 if (!ifname_valid(rvalue
)) {
1086 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid interface name, ignoring: %s", rvalue
);
1090 return free_and_strdup_warn(&s
->bind_to_device
, rvalue
);
1093 int config_parse_exec_input(
1095 const char *filename
,
1097 const char *section
,
1098 unsigned section_line
,
1105 ExecContext
*c
= ASSERT_PTR(data
);
1106 const Unit
*u
= userdata
;
1115 n
= startswith(rvalue
, "fd:");
1117 _cleanup_free_
char *resolved
= NULL
;
1119 r
= unit_fd_printf(u
, n
, &resolved
);
1121 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", n
);
1125 if (isempty(resolved
))
1126 resolved
= mfree(resolved
);
1127 else if (!fdname_is_valid(resolved
)) {
1128 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", resolved
);
1132 free_and_replace(c
->stdio_fdname
[STDIN_FILENO
], resolved
);
1134 ei
= EXEC_INPUT_NAMED_FD
;
1136 } else if ((n
= startswith(rvalue
, "file:"))) {
1137 _cleanup_free_
char *resolved
= NULL
;
1139 r
= unit_path_printf(u
, n
, &resolved
);
1141 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", n
);
1145 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1149 free_and_replace(c
->stdio_file
[STDIN_FILENO
], resolved
);
1151 ei
= EXEC_INPUT_FILE
;
1154 ei
= exec_input_from_string(rvalue
);
1156 log_syntax(unit
, LOG_WARNING
, filename
, line
, ei
, "Failed to parse input specifier, ignoring: %s", rvalue
);
1165 int config_parse_exec_input_text(
1167 const char *filename
,
1169 const char *section
,
1170 unsigned section_line
,
1177 _cleanup_free_
char *unescaped
= NULL
, *resolved
= NULL
;
1178 ExecContext
*c
= ASSERT_PTR(data
);
1179 const Unit
*u
= userdata
;
1186 if (isempty(rvalue
)) {
1187 /* Reset if the empty string is assigned */
1188 c
->stdin_data
= mfree(c
->stdin_data
);
1189 c
->stdin_data_size
= 0;
1193 ssize_t l
= cunescape(rvalue
, 0, &unescaped
);
1195 log_syntax(unit
, LOG_WARNING
, filename
, line
, l
,
1196 "Failed to decode C escaped text '%s', ignoring: %m", rvalue
);
1200 r
= unit_full_printf_full(u
, unescaped
, EXEC_STDIN_DATA_MAX
, &resolved
);
1202 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1203 "Failed to resolve unit specifiers in '%s', ignoring: %m", unescaped
);
1207 size_t sz
= strlen(resolved
);
1208 if (c
->stdin_data_size
+ sz
+ 1 < c
->stdin_data_size
|| /* check for overflow */
1209 c
->stdin_data_size
+ sz
+ 1 > EXEC_STDIN_DATA_MAX
) {
1210 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
1211 "Standard input data too large (%zu), maximum of %zu permitted, ignoring.",
1212 c
->stdin_data_size
+ sz
, (size_t) EXEC_STDIN_DATA_MAX
);
1216 void *p
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
+ 1);
1220 *((char*) mempcpy((char*) p
+ c
->stdin_data_size
, resolved
, sz
)) = '\n';
1223 c
->stdin_data_size
+= sz
+ 1;
1228 int config_parse_exec_input_data(
1230 const char *filename
,
1232 const char *section
,
1233 unsigned section_line
,
1240 _cleanup_free_
void *p
= NULL
;
1241 ExecContext
*c
= ASSERT_PTR(data
);
1250 if (isempty(rvalue
)) {
1251 /* Reset if the empty string is assigned */
1252 c
->stdin_data
= mfree(c
->stdin_data
);
1253 c
->stdin_data_size
= 0;
1257 r
= unbase64mem(rvalue
, SIZE_MAX
, &p
, &sz
);
1259 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1260 "Failed to decode base64 data, ignoring: %s", rvalue
);
1266 if (c
->stdin_data_size
+ sz
< c
->stdin_data_size
|| /* check for overflow */
1267 c
->stdin_data_size
+ sz
> EXEC_STDIN_DATA_MAX
) {
1268 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
1269 "Standard input data too large (%zu), maximum of %zu permitted, ignoring.",
1270 c
->stdin_data_size
+ sz
, (size_t) EXEC_STDIN_DATA_MAX
);
1274 q
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
);
1278 memcpy((uint8_t*) q
+ c
->stdin_data_size
, p
, sz
);
1281 c
->stdin_data_size
+= sz
;
1286 int config_parse_exec_output(
1288 const char *filename
,
1290 const char *section
,
1291 unsigned section_line
,
1298 _cleanup_free_
char *resolved
= NULL
;
1300 ExecContext
*c
= ASSERT_PTR(data
);
1301 const Unit
*u
= userdata
;
1302 bool obsolete
= false;
1311 n
= startswith(rvalue
, "fd:");
1313 r
= unit_fd_printf(u
, n
, &resolved
);
1315 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", n
);
1319 if (isempty(resolved
))
1320 resolved
= mfree(resolved
);
1321 else if (!fdname_is_valid(resolved
)) {
1322 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", resolved
);
1326 eo
= EXEC_OUTPUT_NAMED_FD
;
1328 } else if (streq(rvalue
, "syslog")) {
1329 eo
= EXEC_OUTPUT_JOURNAL
;
1332 } else if (streq(rvalue
, "syslog+console")) {
1333 eo
= EXEC_OUTPUT_JOURNAL_AND_CONSOLE
;
1336 } else if ((n
= startswith(rvalue
, "file:"))) {
1338 r
= unit_path_printf(u
, n
, &resolved
);
1340 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", n
);
1344 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1348 eo
= EXEC_OUTPUT_FILE
;
1350 } else if ((n
= startswith(rvalue
, "append:"))) {
1352 r
= unit_path_printf(u
, n
, &resolved
);
1354 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", n
);
1358 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1362 eo
= EXEC_OUTPUT_FILE_APPEND
;
1364 } else if ((n
= startswith(rvalue
, "truncate:"))) {
1366 r
= unit_path_printf(u
, n
, &resolved
);
1368 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", n
);
1372 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1376 eo
= EXEC_OUTPUT_FILE_TRUNCATE
;
1378 eo
= exec_output_from_string(rvalue
);
1380 log_syntax(unit
, LOG_WARNING
, filename
, line
, eo
, "Failed to parse output specifier, ignoring: %s", rvalue
);
1386 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
1387 "Standard output type %s is obsolete, automatically updating to %s. Please update your unit file, and consider removing the setting altogether.",
1388 rvalue
, exec_output_to_string(eo
));
1390 if (streq(lvalue
, "StandardOutput")) {
1391 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1392 free_and_replace(c
->stdio_fdname
[STDOUT_FILENO
], resolved
);
1394 free_and_replace(c
->stdio_file
[STDOUT_FILENO
], resolved
);
1399 assert(streq(lvalue
, "StandardError"));
1401 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1402 free_and_replace(c
->stdio_fdname
[STDERR_FILENO
], resolved
);
1404 free_and_replace(c
->stdio_file
[STDERR_FILENO
], resolved
);
1412 int config_parse_exec_io_class(const char *unit
,
1413 const char *filename
,
1415 const char *section
,
1416 unsigned section_line
,
1423 ExecContext
*c
= ASSERT_PTR(data
);
1430 if (isempty(rvalue
)) {
1431 c
->ioprio_set
= false;
1432 c
->ioprio
= IOPRIO_DEFAULT_CLASS_AND_PRIO
;
1436 x
= ioprio_class_from_string(rvalue
);
1438 log_syntax(unit
, LOG_WARNING
, filename
, line
, x
, "Failed to parse IO scheduling class, ignoring: %s", rvalue
);
1442 c
->ioprio
= ioprio_normalize(ioprio_prio_value(x
, ioprio_prio_data(c
->ioprio
)));
1443 c
->ioprio_set
= true;
1448 int config_parse_exec_io_priority(const char *unit
,
1449 const char *filename
,
1451 const char *section
,
1452 unsigned section_line
,
1459 ExecContext
*c
= ASSERT_PTR(data
);
1466 if (isempty(rvalue
)) {
1467 c
->ioprio_set
= false;
1468 c
->ioprio
= IOPRIO_DEFAULT_CLASS_AND_PRIO
;
1472 r
= ioprio_parse_priority(rvalue
, &i
);
1474 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse IO priority, ignoring: %s", rvalue
);
1478 c
->ioprio
= ioprio_normalize(ioprio_prio_value(ioprio_prio_class(c
->ioprio
), i
));
1479 c
->ioprio_set
= true;
1484 int config_parse_exec_cpu_sched_policy(const char *unit
,
1485 const char *filename
,
1487 const char *section
,
1488 unsigned section_line
,
1495 ExecContext
*c
= ASSERT_PTR(data
);
1502 if (isempty(rvalue
)) {
1503 c
->cpu_sched_set
= false;
1504 c
->cpu_sched_policy
= SCHED_OTHER
;
1505 c
->cpu_sched_priority
= 0;
1509 x
= sched_policy_from_string(rvalue
);
1511 log_syntax(unit
, LOG_WARNING
, filename
, line
, x
, "Failed to parse CPU scheduling policy, ignoring: %s", rvalue
);
1515 c
->cpu_sched_policy
= x
;
1516 /* Moving to or from real-time policy? We need to adjust the priority */
1517 c
->cpu_sched_priority
= CLAMP(c
->cpu_sched_priority
, sched_get_priority_min(x
), sched_get_priority_max(x
));
1518 c
->cpu_sched_set
= true;
1523 int config_parse_exec_mount_apivfs(const char *unit
,
1524 const char *filename
,
1526 const char *section
,
1527 unsigned section_line
,
1534 ExecContext
*c
= ASSERT_PTR(data
);
1541 if (isempty(rvalue
)) {
1542 c
->mount_apivfs_set
= false;
1543 c
->mount_apivfs
= false;
1547 k
= parse_boolean(rvalue
);
1549 log_syntax(unit
, LOG_WARNING
, filename
, line
, k
,
1550 "Failed to parse boolean value, ignoring: %s",
1555 c
->mount_apivfs_set
= true;
1556 c
->mount_apivfs
= k
;
1560 int config_parse_numa_mask(const char *unit
,
1561 const char *filename
,
1563 const char *section
,
1564 unsigned section_line
,
1571 NUMAPolicy
*p
= ASSERT_PTR(data
);
1577 if (streq(rvalue
, "all")) {
1578 r
= numa_mask_add_all(&p
->nodes
);
1580 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1581 "Failed to create NUMA mask representing \"all\" NUMA nodes, ignoring: %m");
1583 r
= parse_cpu_set_extend(rvalue
, &p
->nodes
, true, unit
, filename
, line
, lvalue
);
1585 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse NUMA node mask, ignoring: %s", rvalue
);
1591 int config_parse_exec_cpu_sched_prio(const char *unit
,
1592 const char *filename
,
1594 const char *section
,
1595 unsigned section_line
,
1602 ExecContext
*c
= ASSERT_PTR(data
);
1609 r
= safe_atoi(rvalue
, &i
);
1611 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse CPU scheduling priority, ignoring: %s", rvalue
);
1615 /* On Linux RR/FIFO range from 1 to 99 and OTHER/BATCH may only be 0. Policy might be set later so
1616 * we do not check the precise range, but only the generic outer bounds. */
1617 if (i
< 0 || i
> 99) {
1618 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "CPU scheduling priority is out of range, ignoring: %s", rvalue
);
1622 c
->cpu_sched_priority
= i
;
1623 c
->cpu_sched_set
= true;
1628 int config_parse_root_image_options(
1630 const char *filename
,
1632 const char *section
,
1633 unsigned section_line
,
1640 _cleanup_(mount_options_free_allp
) MountOptions
*options
= NULL
;
1641 _cleanup_strv_free_
char **l
= NULL
;
1642 ExecContext
*c
= ASSERT_PTR(data
);
1643 const Unit
*u
= userdata
;
1650 if (isempty(rvalue
)) {
1651 c
->root_image_options
= mount_options_free_all(c
->root_image_options
);
1655 r
= strv_split_colon_pairs(&l
, rvalue
);
1659 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
1663 STRV_FOREACH_PAIR(first
, second
, l
) {
1664 MountOptions
*o
= NULL
;
1665 _cleanup_free_
char *mount_options_resolved
= NULL
;
1666 const char *mount_options
= NULL
, *partition
= "root";
1667 PartitionDesignator partition_designator
;
1669 /* Format is either 'root:foo' or 'foo' (root is implied) */
1670 if (!isempty(*second
)) {
1672 mount_options
= *second
;
1674 mount_options
= *first
;
1676 partition_designator
= partition_designator_from_string(partition
);
1677 if (partition_designator
< 0) {
1678 log_syntax(unit
, LOG_WARNING
, filename
, line
, partition_designator
,
1679 "Invalid partition name %s, ignoring", partition
);
1682 r
= unit_full_printf(u
, mount_options
, &mount_options_resolved
);
1684 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", mount_options
);
1688 o
= new(MountOptions
, 1);
1691 *o
= (MountOptions
) {
1692 .partition_designator
= partition_designator
,
1693 .options
= TAKE_PTR(mount_options_resolved
),
1695 LIST_APPEND(mount_options
, options
, TAKE_PTR(o
));
1699 LIST_JOIN(mount_options
, c
->root_image_options
, options
);
1701 /* empty spaces/separators only */
1702 c
->root_image_options
= mount_options_free_all(c
->root_image_options
);
1707 int config_parse_exec_root_hash(
1709 const char *filename
,
1711 const char *section
,
1712 unsigned section_line
,
1719 _cleanup_free_
void *roothash_decoded
= NULL
;
1720 ExecContext
*c
= ASSERT_PTR(data
);
1721 size_t roothash_decoded_size
= 0;
1728 if (isempty(rvalue
)) {
1729 /* Reset if the empty string is assigned */
1730 c
->root_hash_path
= mfree(c
->root_hash_path
);
1731 c
->root_hash
= mfree(c
->root_hash
);
1732 c
->root_hash_size
= 0;
1736 if (path_is_absolute(rvalue
)) {
1737 /* We have the path to a roothash to load and decode, eg: RootHash=/foo/bar.roothash */
1738 _cleanup_free_
char *p
= NULL
;
1744 free_and_replace(c
->root_hash_path
, p
);
1745 c
->root_hash
= mfree(c
->root_hash
);
1746 c
->root_hash_size
= 0;
1750 /* We have a roothash to decode, eg: RootHash=012345789abcdef */
1751 r
= unhexmem(rvalue
, strlen(rvalue
), &roothash_decoded
, &roothash_decoded_size
);
1753 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to decode RootHash=, ignoring: %s", rvalue
);
1756 if (roothash_decoded_size
< sizeof(sd_id128_t
)) {
1757 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "RootHash= is too short, ignoring: %s", rvalue
);
1761 free_and_replace(c
->root_hash
, roothash_decoded
);
1762 c
->root_hash_size
= roothash_decoded_size
;
1763 c
->root_hash_path
= mfree(c
->root_hash_path
);
1768 int config_parse_exec_root_hash_sig(
1770 const char *filename
,
1772 const char *section
,
1773 unsigned section_line
,
1780 _cleanup_free_
void *roothash_sig_decoded
= NULL
;
1782 ExecContext
*c
= ASSERT_PTR(data
);
1783 size_t roothash_sig_decoded_size
= 0;
1790 if (isempty(rvalue
)) {
1791 /* Reset if the empty string is assigned */
1792 c
->root_hash_sig_path
= mfree(c
->root_hash_sig_path
);
1793 c
->root_hash_sig
= mfree(c
->root_hash_sig
);
1794 c
->root_hash_sig_size
= 0;
1798 if (path_is_absolute(rvalue
)) {
1799 /* We have the path to a roothash signature to load and decode, eg: RootHashSignature=/foo/bar.roothash.p7s */
1800 _cleanup_free_
char *p
= NULL
;
1806 free_and_replace(c
->root_hash_sig_path
, p
);
1807 c
->root_hash_sig
= mfree(c
->root_hash_sig
);
1808 c
->root_hash_sig_size
= 0;
1812 if (!(value
= startswith(rvalue
, "base64:"))) {
1813 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
1814 "Failed to decode RootHashSignature=, not a path but doesn't start with 'base64:', ignoring: %s", rvalue
);
1818 /* We have a roothash signature to decode, eg: RootHashSignature=base64:012345789abcdef */
1819 r
= unbase64mem(value
, strlen(value
), &roothash_sig_decoded
, &roothash_sig_decoded_size
);
1821 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to decode RootHashSignature=, ignoring: %s", rvalue
);
1825 free_and_replace(c
->root_hash_sig
, roothash_sig_decoded
);
1826 c
->root_hash_sig_size
= roothash_sig_decoded_size
;
1827 c
->root_hash_sig_path
= mfree(c
->root_hash_sig_path
);
1832 int config_parse_exec_cpu_affinity(
1834 const char *filename
,
1836 const char *section
,
1837 unsigned section_line
,
1844 ExecContext
*c
= ASSERT_PTR(data
);
1845 const Unit
*u
= userdata
;
1846 _cleanup_free_
char *k
= NULL
;
1853 if (streq(rvalue
, "numa")) {
1854 c
->cpu_affinity_from_numa
= true;
1855 cpu_set_reset(&c
->cpu_set
);
1860 r
= unit_full_printf(u
, rvalue
, &k
);
1862 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1863 "Failed to resolve unit specifiers in '%s', ignoring: %m",
1868 r
= parse_cpu_set_extend(k
, &c
->cpu_set
, true, unit
, filename
, line
, lvalue
);
1870 c
->cpu_affinity_from_numa
= false;
1875 int config_parse_capability_set(
1877 const char *filename
,
1879 const char *section
,
1880 unsigned section_line
,
1887 uint64_t *capability_set
= ASSERT_PTR(data
);
1888 uint64_t sum
= 0, initial
, def
;
1889 bool invert
= false;
1896 if (rvalue
[0] == '~') {
1901 if (streq(lvalue
, "CapabilityBoundingSet")) {
1902 initial
= CAP_MASK_ALL
; /* initialized to all bits on */
1903 def
= CAP_MASK_UNSET
; /* not set */
1905 def
= initial
= 0; /* All bits off */
1907 r
= capability_set_from_string(rvalue
, &sum
);
1909 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= specifier '%s', ignoring: %m", lvalue
, rvalue
);
1913 if (sum
== 0 || *capability_set
== def
)
1914 /* "", "~" or uninitialized data -> replace */
1915 *capability_set
= invert
? ~sum
: sum
;
1917 /* previous data -> merge */
1919 *capability_set
&= ~sum
;
1921 *capability_set
|= sum
;
1927 int config_parse_exec_selinux_context(
1929 const char *filename
,
1931 const char *section
,
1932 unsigned section_line
,
1939 ExecContext
*c
= ASSERT_PTR(data
);
1940 const Unit
*u
= userdata
;
1949 if (isempty(rvalue
)) {
1950 c
->selinux_context
= mfree(c
->selinux_context
);
1951 c
->selinux_context_ignore
= false;
1955 if (rvalue
[0] == '-') {
1961 r
= unit_full_printf(u
, rvalue
, &k
);
1963 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
1964 "Failed to resolve unit specifiers in '%s'%s: %m",
1965 rvalue
, ignore
? ", ignoring" : "");
1966 return ignore
? 0 : -ENOEXEC
;
1969 free_and_replace(c
->selinux_context
, k
);
1970 c
->selinux_context_ignore
= ignore
;
1975 int config_parse_exec_apparmor_profile(
1977 const char *filename
,
1979 const char *section
,
1980 unsigned section_line
,
1987 ExecContext
*c
= ASSERT_PTR(data
);
1988 const Unit
*u
= userdata
;
1997 if (isempty(rvalue
)) {
1998 c
->apparmor_profile
= mfree(c
->apparmor_profile
);
1999 c
->apparmor_profile_ignore
= false;
2003 if (rvalue
[0] == '-') {
2009 r
= unit_full_printf(u
, rvalue
, &k
);
2011 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
2012 "Failed to resolve unit specifiers in '%s'%s: %m",
2013 rvalue
, ignore
? ", ignoring" : "");
2014 return ignore
? 0 : -ENOEXEC
;
2017 free_and_replace(c
->apparmor_profile
, k
);
2018 c
->apparmor_profile_ignore
= ignore
;
2023 int config_parse_exec_smack_process_label(
2025 const char *filename
,
2027 const char *section
,
2028 unsigned section_line
,
2035 ExecContext
*c
= ASSERT_PTR(data
);
2036 const Unit
*u
= userdata
;
2045 if (isempty(rvalue
)) {
2046 c
->smack_process_label
= mfree(c
->smack_process_label
);
2047 c
->smack_process_label_ignore
= false;
2051 if (rvalue
[0] == '-') {
2057 r
= unit_full_printf(u
, rvalue
, &k
);
2059 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
2060 "Failed to resolve unit specifiers in '%s'%s: %m",
2061 rvalue
, ignore
? ", ignoring" : "");
2062 return ignore
? 0 : -ENOEXEC
;
2065 free_and_replace(c
->smack_process_label
, k
);
2066 c
->smack_process_label_ignore
= ignore
;
2071 int config_parse_timer(
2073 const char *filename
,
2075 const char *section
,
2076 unsigned section_line
,
2083 _cleanup_(calendar_spec_freep
) CalendarSpec
*c
= NULL
;
2084 _cleanup_free_
char *k
= NULL
;
2085 const Unit
*u
= userdata
;
2086 Timer
*t
= ASSERT_PTR(data
);
2095 if (isempty(rvalue
)) {
2096 /* Empty assignment resets list */
2097 timer_free_values(t
);
2101 r
= unit_full_printf(u
, rvalue
, &k
);
2103 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2107 if (ltype
== TIMER_CALENDAR
) {
2108 r
= calendar_spec_from_string(k
, &c
);
2110 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse calendar specification, ignoring: %s", k
);
2114 r
= parse_sec(k
, &usec
);
2116 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse timer value, ignoring: %s", k
);
2121 v
= new(TimerValue
, 1);
2128 .calendar_spec
= TAKE_PTR(c
),
2131 LIST_PREPEND(value
, t
->values
, v
);
2136 int config_parse_trigger_unit(
2138 const char *filename
,
2140 const char *section
,
2141 unsigned section_line
,
2148 _cleanup_free_
char *p
= NULL
;
2149 Unit
*u
= ASSERT_PTR(data
);
2157 if (UNIT_TRIGGER(u
)) {
2158 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Multiple units to trigger specified, ignoring: %s", rvalue
);
2162 r
= unit_name_printf(u
, rvalue
, &p
);
2164 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2168 type
= unit_name_to_type(p
);
2170 log_syntax(unit
, LOG_WARNING
, filename
, line
, type
, "Unit type not valid, ignoring: %s", rvalue
);
2173 if (unit_has_name(u
, p
)) {
2174 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Units cannot trigger themselves, ignoring: %s", rvalue
);
2178 r
= unit_add_two_dependencies_by_name(u
, UNIT_BEFORE
, UNIT_TRIGGERS
, p
, true, UNIT_DEPENDENCY_FILE
);
2180 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add trigger on %s, ignoring: %m", p
);
2187 int config_parse_path_spec(const char *unit
,
2188 const char *filename
,
2190 const char *section
,
2191 unsigned section_line
,
2198 Path
*p
= ASSERT_PTR(data
);
2201 _cleanup_free_
char *k
= NULL
;
2208 if (isempty(rvalue
)) {
2209 /* Empty assignment clears list */
2214 b
= path_type_from_string(lvalue
);
2216 log_syntax(unit
, LOG_WARNING
, filename
, line
, b
, "Failed to parse path type, ignoring: %s", lvalue
);
2220 r
= unit_path_printf(UNIT(p
), rvalue
, &k
);
2222 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2226 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2230 s
= new0(PathSpec
, 1);
2235 s
->path
= TAKE_PTR(k
);
2237 s
->inotify_fd
= -EBADF
;
2239 LIST_PREPEND(spec
, p
->specs
, s
);
2244 int config_parse_socket_service(
2246 const char *filename
,
2248 const char *section
,
2249 unsigned section_line
,
2256 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
2257 _cleanup_free_
char *p
= NULL
;
2258 Socket
*s
= ASSERT_PTR(data
);
2266 r
= unit_name_printf(UNIT(s
), rvalue
, &p
);
2268 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2272 if (!endswith(p
, ".service")) {
2273 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Unit must be of type service, ignoring: %s", rvalue
);
2277 r
= manager_load_unit(UNIT(s
)->manager
, p
, NULL
, &error
, &x
);
2279 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to load unit %s, ignoring: %s", rvalue
, bus_error_message(&error
, r
));
2283 unit_ref_set(&s
->service
, UNIT(s
), x
);
2288 int config_parse_fdname(
2290 const char *filename
,
2292 const char *section
,
2293 unsigned section_line
,
2300 _cleanup_free_
char *p
= NULL
;
2301 Socket
*s
= ASSERT_PTR(data
);
2308 if (isempty(rvalue
)) {
2309 s
->fdname
= mfree(s
->fdname
);
2313 r
= unit_fd_printf(UNIT(s
), rvalue
, &p
);
2315 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2319 if (!fdname_is_valid(p
)) {
2320 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", p
);
2324 return free_and_replace(s
->fdname
, p
);
2327 int config_parse_service_sockets(
2329 const char *filename
,
2331 const char *section
,
2332 unsigned section_line
,
2339 Service
*s
= ASSERT_PTR(data
);
2346 for (const char *p
= rvalue
;;) {
2347 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2349 r
= extract_first_word(&p
, &word
, NULL
, 0);
2353 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Trailing garbage in sockets, ignoring: %s", rvalue
);
2359 r
= unit_name_printf(UNIT(s
), word
, &k
);
2361 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
2365 if (!endswith(k
, ".socket")) {
2366 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Unit must be of type socket, ignoring: %s", k
);
2370 r
= unit_add_two_dependencies_by_name(UNIT(s
), UNIT_WANTS
, UNIT_AFTER
, k
, true, UNIT_DEPENDENCY_FILE
);
2372 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
2374 r
= unit_add_dependency_by_name(UNIT(s
), UNIT_TRIGGERED_BY
, k
, true, UNIT_DEPENDENCY_FILE
);
2376 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
2380 int config_parse_bus_name(
2382 const char *filename
,
2384 const char *section
,
2385 unsigned section_line
,
2392 _cleanup_free_
char *k
= NULL
;
2393 const Unit
*u
= ASSERT_PTR(userdata
);
2400 r
= unit_full_printf_full(u
, rvalue
, SD_BUS_MAXIMUM_NAME_LENGTH
, &k
);
2402 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2406 if (!sd_bus_service_name_is_valid(k
)) {
2407 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid bus name, ignoring: %s", k
);
2411 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
2414 int config_parse_service_timeout(
2416 const char *filename
,
2418 const char *section
,
2419 unsigned section_line
,
2426 Service
*s
= ASSERT_PTR(userdata
);
2434 /* This is called for two cases: TimeoutSec= and TimeoutStartSec=. */
2436 /* Traditionally, these options accepted 0 to disable the timeouts. However, a timeout of 0 suggests it happens
2437 * immediately, hence fix this to become USEC_INFINITY instead. This is in-line with how we internally handle
2438 * all other timeouts. */
2439 r
= parse_sec_fix_0(rvalue
, &usec
);
2441 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
2445 s
->start_timeout_defined
= true;
2446 s
->timeout_start_usec
= usec
;
2448 if (streq(lvalue
, "TimeoutSec"))
2449 s
->timeout_stop_usec
= usec
;
2454 int config_parse_timeout_abort(
2456 const char *filename
,
2458 const char *section
,
2459 unsigned section_line
,
2466 usec_t
*ret
= ASSERT_PTR(data
);
2473 /* Note: apart from setting the arg, this returns an extra bit of information in the return value. */
2475 if (isempty(rvalue
)) {
2477 return 0; /* "not set" */
2480 r
= parse_sec(rvalue
, ret
);
2482 return log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= setting, ignoring: %s", lvalue
, rvalue
);
2484 return 1; /* "set" */
2487 int config_parse_service_timeout_abort(
2489 const char *filename
,
2491 const char *section
,
2492 unsigned section_line
,
2499 Service
*s
= ASSERT_PTR(userdata
);
2502 r
= config_parse_timeout_abort(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
,
2503 &s
->timeout_abort_usec
, s
);
2505 s
->timeout_abort_set
= r
;
2509 int config_parse_user_group_compat(
2511 const char *filename
,
2513 const char *section
,
2514 unsigned section_line
,
2521 _cleanup_free_
char *k
= NULL
;
2523 const Unit
*u
= ASSERT_PTR(userdata
);
2530 if (isempty(rvalue
)) {
2531 *user
= mfree(*user
);
2535 r
= unit_full_printf(u
, rvalue
, &k
);
2537 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", rvalue
);
2541 if (!valid_user_group_name(k
, VALID_USER_ALLOW_NUMERIC
|VALID_USER_RELAX
|VALID_USER_WARN
)) {
2542 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2546 if (strstr(lvalue
, "User") && streq(k
, NOBODY_USER_NAME
))
2547 log_struct(LOG_NOTICE
,
2548 "MESSAGE=%s:%u: Special user %s configured, this is not safe!", filename
, line
, k
,
2550 "MESSAGE_ID=" SD_MESSAGE_NOBODY_USER_UNSUITABLE_STR
,
2551 "OFFENDING_USER=%s", k
,
2552 "CONFIG_FILE=%s", filename
,
2553 "CONFIG_LINE=%u", line
);
2555 return free_and_replace(*user
, k
);
2558 int config_parse_user_group_strv_compat(
2560 const char *filename
,
2562 const char *section
,
2563 unsigned section_line
,
2570 char ***users
= data
;
2571 const Unit
*u
= ASSERT_PTR(userdata
);
2578 if (isempty(rvalue
)) {
2579 *users
= strv_free(*users
);
2583 for (const char *p
= rvalue
;;) {
2584 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2586 r
= extract_first_word(&p
, &word
, NULL
, 0);
2590 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax: %s", rvalue
);
2596 r
= unit_full_printf(u
, word
, &k
);
2598 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", word
);
2602 if (!valid_user_group_name(k
, VALID_USER_ALLOW_NUMERIC
|VALID_USER_RELAX
|VALID_USER_WARN
)) {
2603 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2607 r
= strv_push(users
, k
);
2615 int config_parse_working_directory(
2617 const char *filename
,
2619 const char *section
,
2620 unsigned section_line
,
2627 ExecContext
*c
= ASSERT_PTR(data
);
2628 const Unit
*u
= ASSERT_PTR(userdata
);
2636 if (isempty(rvalue
)) {
2637 c
->working_directory_home
= false;
2638 c
->working_directory
= mfree(c
->working_directory
);
2642 if (rvalue
[0] == '-') {
2648 if (streq(rvalue
, "~")) {
2649 c
->working_directory_home
= true;
2650 c
->working_directory
= mfree(c
->working_directory
);
2652 _cleanup_free_
char *k
= NULL
;
2654 r
= unit_path_printf(u
, rvalue
, &k
);
2656 log_syntax(unit
, missing_ok
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
2657 "Failed to resolve unit specifiers in working directory path '%s'%s: %m",
2658 rvalue
, missing_ok
? ", ignoring" : "");
2659 return missing_ok
? 0 : -ENOEXEC
;
2662 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
| (missing_ok
? 0 : PATH_CHECK_FATAL
), unit
, filename
, line
, lvalue
);
2664 return missing_ok
? 0 : -ENOEXEC
;
2666 c
->working_directory_home
= false;
2667 free_and_replace(c
->working_directory
, k
);
2670 c
->working_directory_missing_ok
= missing_ok
;
2674 int config_parse_unit_env_file(const char *unit
,
2675 const char *filename
,
2677 const char *section
,
2678 unsigned section_line
,
2685 char ***env
= ASSERT_PTR(data
);
2686 const Unit
*u
= userdata
;
2687 _cleanup_free_
char *n
= NULL
;
2694 if (isempty(rvalue
)) {
2695 /* Empty assignment frees the list */
2696 *env
= strv_free(*env
);
2700 r
= unit_full_printf_full(u
, rvalue
, PATH_MAX
, &n
);
2702 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2706 r
= path_simplify_and_warn(n
[0] == '-' ? n
+ 1 : n
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2710 r
= strv_push(env
, n
);
2719 int config_parse_environ(
2721 const char *filename
,
2723 const char *section
,
2724 unsigned section_line
,
2731 const Unit
*u
= userdata
;
2732 char ***env
= ASSERT_PTR(data
);
2739 if (isempty(rvalue
)) {
2740 /* Empty assignment resets the list */
2741 *env
= strv_free(*env
);
2745 /* If 'u' is set, we operate on the regular unit specifier table. Otherwise we use a manager-specific
2746 * specifier table (in which case ltype must contain the runtime scope). */
2747 const Specifier
*table
= u
? NULL
: (const Specifier
[]) {
2748 COMMON_SYSTEM_SPECIFIERS
,
2749 COMMON_TMP_SPECIFIERS
,
2750 COMMON_CREDS_SPECIFIERS(ltype
),
2751 { 'h', specifier_user_home
, NULL
},
2752 { 's', specifier_user_shell
, NULL
},
2755 for (const char *p
= rvalue
;; ) {
2756 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
2758 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2762 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2763 "Invalid syntax, ignoring: %s", rvalue
);
2770 r
= specifier_printf(word
, sc_arg_max(), table
, NULL
, NULL
, &resolved
);
2772 r
= unit_env_printf(u
, word
, &resolved
);
2774 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2775 "Failed to resolve specifiers in %s, ignoring: %m", word
);
2779 if (!env_assignment_is_valid(resolved
)) {
2780 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
2781 "Invalid environment assignment, ignoring: %s", resolved
);
2785 r
= strv_env_replace_consume(env
, TAKE_PTR(resolved
));
2787 return log_error_errno(r
, "Failed to update environment: %m");
2791 int config_parse_pass_environ(
2793 const char *filename
,
2795 const char *section
,
2796 unsigned section_line
,
2803 _cleanup_strv_free_
char **n
= NULL
;
2804 const Unit
*u
= userdata
;
2805 char*** passenv
= ASSERT_PTR(data
);
2813 if (isempty(rvalue
)) {
2814 /* Empty assignment resets the list */
2815 *passenv
= strv_free(*passenv
);
2819 for (const char *p
= rvalue
;;) {
2820 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2822 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
2826 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2827 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2834 r
= unit_env_printf(u
, word
, &k
);
2836 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2837 "Failed to resolve specifiers in %s, ignoring: %m", word
);
2843 if (!env_name_is_valid(k
)) {
2844 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
2845 "Invalid environment name for %s, ignoring: %s", lvalue
, k
);
2849 if (!GREEDY_REALLOC(n
, nlen
+ 2))
2852 n
[nlen
++] = TAKE_PTR(k
);
2857 r
= strv_extend_strv(passenv
, n
, true);
2865 int config_parse_unset_environ(
2867 const char *filename
,
2869 const char *section
,
2870 unsigned section_line
,
2877 _cleanup_strv_free_
char **n
= NULL
;
2878 char*** unsetenv
= ASSERT_PTR(data
);
2879 const Unit
*u
= userdata
;
2887 if (isempty(rvalue
)) {
2888 /* Empty assignment resets the list */
2889 *unsetenv
= strv_free(*unsetenv
);
2893 for (const char *p
= rvalue
;;) {
2894 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2896 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2900 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2901 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2908 r
= unit_env_printf(u
, word
, &k
);
2910 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2911 "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2917 if (!env_assignment_is_valid(k
) && !env_name_is_valid(k
)) {
2918 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
2919 "Invalid environment name or assignment %s, ignoring: %s", lvalue
, k
);
2923 if (!GREEDY_REALLOC(n
, nlen
+ 2))
2926 n
[nlen
++] = TAKE_PTR(k
);
2931 r
= strv_extend_strv(unsetenv
, n
, true);
2939 int config_parse_log_extra_fields(
2941 const char *filename
,
2943 const char *section
,
2944 unsigned section_line
,
2951 ExecContext
*c
= ASSERT_PTR(data
);
2952 const Unit
*u
= userdata
;
2959 if (isempty(rvalue
)) {
2960 exec_context_free_log_extra_fields(c
);
2964 for (const char *p
= rvalue
;;) {
2965 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2969 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2973 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
2979 r
= unit_full_printf(u
, word
, &k
);
2981 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2985 eq
= strchr(k
, '=');
2987 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Log field lacks '=' character, ignoring: %s", k
);
2991 if (!journal_field_valid(k
, eq
-k
, false)) {
2992 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Log field name is invalid, ignoring: %s", k
);
2996 t
= reallocarray(c
->log_extra_fields
, c
->n_log_extra_fields
+1, sizeof(struct iovec
));
3000 c
->log_extra_fields
= t
;
3001 c
->log_extra_fields
[c
->n_log_extra_fields
++] = IOVEC_MAKE_STRING(k
);
3007 int config_parse_log_namespace(
3009 const char *filename
,
3011 const char *section
,
3012 unsigned section_line
,
3019 _cleanup_free_
char *k
= NULL
;
3020 ExecContext
*c
= ASSERT_PTR(data
);
3021 const Unit
*u
= userdata
;
3028 if (isempty(rvalue
)) {
3029 c
->log_namespace
= mfree(c
->log_namespace
);
3033 r
= unit_full_printf_full(u
, rvalue
, NAME_MAX
, &k
);
3035 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
3039 if (!log_namespace_name_valid(k
)) {
3040 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Specified log namespace name is not valid, ignoring: %s", k
);
3044 free_and_replace(c
->log_namespace
, k
);
3048 int config_parse_unit_condition_path(
3050 const char *filename
,
3052 const char *section
,
3053 unsigned section_line
,
3060 _cleanup_free_
char *p
= NULL
;
3061 Condition
**list
= ASSERT_PTR(data
), *c
;
3062 ConditionType t
= ltype
;
3063 bool trigger
, negate
;
3064 const Unit
*u
= userdata
;
3071 if (isempty(rvalue
)) {
3072 /* Empty assignment resets the list */
3073 *list
= condition_free_list(*list
);
3077 trigger
= rvalue
[0] == '|';
3081 negate
= rvalue
[0] == '!';
3085 r
= unit_path_printf(u
, rvalue
, &p
);
3087 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
3091 r
= path_simplify_and_warn(p
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
3095 c
= condition_new(t
, p
, trigger
, negate
);
3099 LIST_PREPEND(conditions
, *list
, c
);
3103 int config_parse_unit_condition_string(
3105 const char *filename
,
3107 const char *section
,
3108 unsigned section_line
,
3115 _cleanup_free_
char *s
= NULL
;
3116 Condition
**list
= ASSERT_PTR(data
), *c
;
3117 ConditionType t
= ltype
;
3118 bool trigger
, negate
;
3119 const Unit
*u
= userdata
;
3126 if (isempty(rvalue
)) {
3127 /* Empty assignment resets the list */
3128 *list
= condition_free_list(*list
);
3132 trigger
= *rvalue
== '|';
3134 rvalue
+= 1 + strspn(rvalue
+ 1, WHITESPACE
);
3136 negate
= *rvalue
== '!';
3138 rvalue
+= 1 + strspn(rvalue
+ 1, WHITESPACE
);
3140 r
= unit_full_printf(u
, rvalue
, &s
);
3142 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3143 "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
3147 c
= condition_new(t
, s
, trigger
, negate
);
3151 LIST_PREPEND(conditions
, *list
, c
);
3155 int config_parse_unit_requires_mounts_for(
3157 const char *filename
,
3159 const char *section
,
3160 unsigned section_line
,
3175 for (const char *p
= rvalue
;;) {
3176 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
3178 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3182 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3183 "Invalid syntax, ignoring: %s", rvalue
);
3189 r
= unit_path_printf(u
, word
, &resolved
);
3191 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
3195 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
3199 r
= unit_require_mounts_for(u
, resolved
, UNIT_DEPENDENCY_FILE
);
3201 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add required mount '%s', ignoring: %m", resolved
);
3207 int config_parse_documentation(
3209 const char *filename
,
3211 const char *section
,
3212 unsigned section_line
,
3219 Unit
*u
= ASSERT_PTR(userdata
);
3227 if (isempty(rvalue
)) {
3228 /* Empty assignment resets the list */
3229 u
->documentation
= strv_free(u
->documentation
);
3233 r
= config_parse_unit_strv_printf(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
,
3234 rvalue
, data
, userdata
);
3238 for (a
= b
= u
->documentation
; a
&& *a
; a
++) {
3240 if (documentation_url_is_valid(*a
))
3243 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid URL, ignoring: %s", *a
);
3254 int config_parse_syscall_filter(
3256 const char *filename
,
3258 const char *section
,
3259 unsigned section_line
,
3266 ExecContext
*c
= data
;
3267 _unused_
const Unit
*u
= ASSERT_PTR(userdata
);
3268 bool invert
= false;
3275 if (isempty(rvalue
)) {
3276 /* Empty assignment resets the list */
3277 c
->syscall_filter
= hashmap_free(c
->syscall_filter
);
3278 c
->syscall_allow_list
= false;
3282 if (rvalue
[0] == '~') {
3287 if (!c
->syscall_filter
) {
3288 c
->syscall_filter
= hashmap_new(NULL
);
3289 if (!c
->syscall_filter
)
3293 /* Allow everything but the ones listed */
3294 c
->syscall_allow_list
= false;
3296 /* Allow nothing but the ones listed */
3297 c
->syscall_allow_list
= true;
3299 /* Accept default syscalls if we are on an allow_list */
3300 r
= seccomp_parse_syscall_filter(
3301 "@default", -1, c
->syscall_filter
,
3302 SECCOMP_PARSE_PERMISSIVE
|SECCOMP_PARSE_ALLOW_LIST
,
3310 for (const char *p
= rvalue
;;) {
3311 _cleanup_free_
char *word
= NULL
, *name
= NULL
;
3314 r
= extract_first_word(&p
, &word
, NULL
, 0);
3318 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3319 "Invalid syntax, ignoring: %s", rvalue
);
3325 r
= parse_syscall_and_errno(word
, &name
, &num
);
3327 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3328 "Failed to parse syscall:errno, ignoring: %s", word
);
3331 if (!invert
&& num
>= 0) {
3332 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3333 "Allow-listed system calls cannot take error number, ignoring: %s", word
);
3337 r
= seccomp_parse_syscall_filter(
3338 name
, num
, c
->syscall_filter
,
3339 SECCOMP_PARSE_LOG
|SECCOMP_PARSE_PERMISSIVE
|
3340 (invert
? SECCOMP_PARSE_INVERT
: 0)|
3341 (c
->syscall_allow_list
? SECCOMP_PARSE_ALLOW_LIST
: 0),
3342 unit
, filename
, line
);
3348 int config_parse_syscall_log(
3350 const char *filename
,
3352 const char *section
,
3353 unsigned section_line
,
3360 ExecContext
*c
= data
;
3361 _unused_
const Unit
*u
= ASSERT_PTR(userdata
);
3362 bool invert
= false;
3370 if (isempty(rvalue
)) {
3371 /* Empty assignment resets the list */
3372 c
->syscall_log
= hashmap_free(c
->syscall_log
);
3373 c
->syscall_log_allow_list
= false;
3377 if (rvalue
[0] == '~') {
3382 if (!c
->syscall_log
) {
3383 c
->syscall_log
= hashmap_new(NULL
);
3384 if (!c
->syscall_log
)
3388 /* Log everything but the ones listed */
3389 c
->syscall_log_allow_list
= false;
3391 /* Log nothing but the ones listed */
3392 c
->syscall_log_allow_list
= true;
3397 _cleanup_free_
char *word
= NULL
;
3399 r
= extract_first_word(&p
, &word
, NULL
, 0);
3403 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3409 r
= seccomp_parse_syscall_filter(
3410 word
, -1, c
->syscall_log
,
3411 SECCOMP_PARSE_LOG
|SECCOMP_PARSE_PERMISSIVE
|
3412 (invert
? SECCOMP_PARSE_INVERT
: 0)|
3413 (c
->syscall_log_allow_list
? SECCOMP_PARSE_ALLOW_LIST
: 0),
3414 unit
, filename
, line
);
3420 int config_parse_syscall_archs(
3422 const char *filename
,
3424 const char *section
,
3425 unsigned section_line
,
3435 if (isempty(rvalue
)) {
3436 *archs
= set_free(*archs
);
3440 for (const char *p
= rvalue
;;) {
3441 _cleanup_free_
char *word
= NULL
;
3444 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3448 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3449 "Invalid syntax, ignoring: %s", rvalue
);
3455 r
= seccomp_arch_from_string(word
, &a
);
3457 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3458 "Failed to parse system call architecture \"%s\", ignoring: %m", word
);
3462 r
= set_ensure_put(archs
, NULL
, UINT32_TO_PTR(a
+ 1));
3468 int config_parse_syscall_errno(
3470 const char *filename
,
3472 const char *section
,
3473 unsigned section_line
,
3480 ExecContext
*c
= data
;
3487 if (isempty(rvalue
) || streq(rvalue
, "kill")) {
3488 /* Empty assignment resets to KILL */
3489 c
->syscall_errno
= SECCOMP_ERROR_NUMBER_KILL
;
3493 e
= parse_errno(rvalue
);
3495 log_syntax(unit
, LOG_WARNING
, filename
, line
, e
, "Failed to parse error number, ignoring: %s", rvalue
);
3499 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid error number, ignoring: %s", rvalue
);
3503 c
->syscall_errno
= e
;
3507 int config_parse_address_families(
3509 const char *filename
,
3511 const char *section
,
3512 unsigned section_line
,
3519 ExecContext
*c
= data
;
3520 bool invert
= false;
3527 if (isempty(rvalue
)) {
3528 /* Empty assignment resets the list */
3529 c
->address_families
= set_free(c
->address_families
);
3530 c
->address_families_allow_list
= false;
3534 if (streq(rvalue
, "none")) {
3535 /* Forbid all address families. */
3536 c
->address_families
= set_free(c
->address_families
);
3537 c
->address_families_allow_list
= true;
3541 if (rvalue
[0] == '~') {
3546 if (!c
->address_families
) {
3547 c
->address_families
= set_new(NULL
);
3548 if (!c
->address_families
)
3551 c
->address_families_allow_list
= !invert
;
3554 for (const char *p
= rvalue
;;) {
3555 _cleanup_free_
char *word
= NULL
;
3558 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3562 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3563 "Invalid syntax, ignoring: %s", rvalue
);
3569 af
= af_from_name(word
);
3571 log_syntax(unit
, LOG_WARNING
, filename
, line
, af
,
3572 "Failed to parse address family, ignoring: %s", word
);
3576 /* If we previously wanted to forbid an address family and now
3577 * we want to allow it, then just remove it from the list.
3579 if (!invert
== c
->address_families_allow_list
) {
3580 r
= set_put(c
->address_families
, INT_TO_PTR(af
));
3584 set_remove(c
->address_families
, INT_TO_PTR(af
));
3588 int config_parse_restrict_namespaces(
3590 const char *filename
,
3592 const char *section
,
3593 unsigned section_line
,
3600 ExecContext
*c
= data
;
3601 unsigned long flags
;
3602 bool invert
= false;
3605 if (isempty(rvalue
)) {
3606 /* Reset to the default. */
3607 c
->restrict_namespaces
= NAMESPACE_FLAGS_INITIAL
;
3611 /* Boolean parameter ignores the previous settings */
3612 r
= parse_boolean(rvalue
);
3614 c
->restrict_namespaces
= 0;
3616 } else if (r
== 0) {
3617 c
->restrict_namespaces
= NAMESPACE_FLAGS_ALL
;
3621 if (rvalue
[0] == '~') {
3626 /* Not a boolean argument, in this case it's a list of namespace types. */
3627 r
= namespace_flags_from_string(rvalue
, &flags
);
3629 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse namespace type string, ignoring: %s", rvalue
);
3633 if (c
->restrict_namespaces
== NAMESPACE_FLAGS_INITIAL
)
3634 /* Initial assignment. Just set the value. */
3635 c
->restrict_namespaces
= invert
? (~flags
) & NAMESPACE_FLAGS_ALL
: flags
;
3637 /* Merge the value with the previous one. */
3638 SET_FLAG(c
->restrict_namespaces
, flags
, !invert
);
3644 int config_parse_restrict_filesystems(
3646 const char *filename
,
3648 const char *section
,
3649 unsigned section_line
,
3655 ExecContext
*c
= ASSERT_PTR(data
);
3656 bool invert
= false;
3663 if (isempty(rvalue
)) {
3664 /* Empty assignment resets the list */
3665 c
->restrict_filesystems
= set_free_free(c
->restrict_filesystems
);
3666 c
->restrict_filesystems_allow_list
= false;
3670 if (rvalue
[0] == '~') {
3675 if (!c
->restrict_filesystems
) {
3677 /* Allow everything but the ones listed */
3678 c
->restrict_filesystems_allow_list
= false;
3680 /* Allow nothing but the ones listed */
3681 c
->restrict_filesystems_allow_list
= true;
3684 for (const char *p
= rvalue
;;) {
3685 _cleanup_free_
char *word
= NULL
;
3687 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3693 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3694 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
3698 r
= lsm_bpf_parse_filesystem(
3700 &c
->restrict_filesystems
,
3701 FILESYSTEM_PARSE_LOG
|
3702 (invert
? FILESYSTEM_PARSE_INVERT
: 0)|
3703 (c
->restrict_filesystems_allow_list
? FILESYSTEM_PARSE_ALLOW_LIST
: 0),
3704 unit
, filename
, line
);
3713 int config_parse_unit_slice(
3715 const char *filename
,
3717 const char *section
,
3718 unsigned section_line
,
3725 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
3726 _cleanup_free_
char *k
= NULL
;
3727 Unit
*u
= userdata
, *slice
;
3735 r
= unit_name_printf(u
, rvalue
, &k
);
3737 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
3741 r
= manager_load_unit(u
->manager
, k
, NULL
, &error
, &slice
);
3743 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to load slice unit %s, ignoring: %s", k
, bus_error_message(&error
, r
));
3747 r
= unit_set_slice(u
, slice
);
3749 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to assign slice %s to unit %s, ignoring: %m", slice
->id
, u
->id
);
3756 int config_parse_cpu_quota(
3758 const char *filename
,
3760 const char *section
,
3761 unsigned section_line
,
3768 CGroupContext
*c
= data
;
3775 if (isempty(rvalue
)) {
3776 c
->cpu_quota_per_sec_usec
= USEC_INFINITY
;
3780 r
= parse_permyriad_unbounded(rvalue
);
3782 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid CPU quota '%s', ignoring.", rvalue
);
3786 c
->cpu_quota_per_sec_usec
= ((usec_t
) r
* USEC_PER_SEC
) / 10000U;
3790 int config_parse_allowed_cpuset(
3792 const char *filename
,
3794 const char *section
,
3795 unsigned section_line
,
3804 (void) parse_cpu_set_extend(rvalue
, c
, true, unit
, filename
, line
, lvalue
);
3808 int config_parse_memory_limit(
3810 const char *filename
,
3812 const char *section
,
3813 unsigned section_line
,
3820 CGroupContext
*c
= data
;
3821 uint64_t bytes
= CGROUP_LIMIT_MAX
;
3824 if (isempty(rvalue
) && STR_IN_SET(lvalue
, "DefaultMemoryLow",
3829 bytes
= CGROUP_LIMIT_MIN
;
3830 else if (!isempty(rvalue
) && !streq(rvalue
, "infinity")) {
3832 r
= parse_permyriad(rvalue
);
3834 r
= parse_size(rvalue
, 1024, &bytes
);
3836 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid memory limit '%s', ignoring: %m", rvalue
);
3840 bytes
= physical_memory_scale(r
, 10000U);
3842 if (bytes
>= UINT64_MAX
||
3843 (bytes
<= 0 && !STR_IN_SET(lvalue
,
3845 "StartupMemorySwapMax",
3847 "StartupMemoryZSwapMax",
3852 "DefaultstartupMemoryLow",
3853 "DefaultMemoryMin"))) {
3854 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Memory limit '%s' out of range, ignoring.", rvalue
);
3859 if (streq(lvalue
, "DefaultMemoryLow")) {
3860 c
->default_memory_low
= bytes
;
3861 c
->default_memory_low_set
= true;
3862 } else if (streq(lvalue
, "DefaultStartupMemoryLow")) {
3863 c
->default_startup_memory_low
= bytes
;
3864 c
->default_startup_memory_low_set
= true;
3865 } else if (streq(lvalue
, "DefaultMemoryMin")) {
3866 c
->default_memory_min
= bytes
;
3867 c
->default_memory_min_set
= true;
3868 } else if (streq(lvalue
, "MemoryMin")) {
3869 c
->memory_min
= bytes
;
3870 c
->memory_min_set
= true;
3871 } else if (streq(lvalue
, "MemoryLow")) {
3872 c
->memory_low
= bytes
;
3873 c
->memory_low_set
= true;
3874 } else if (streq(lvalue
, "StartupMemoryLow")) {
3875 c
->startup_memory_low
= bytes
;
3876 c
->startup_memory_low_set
= true;
3877 } else if (streq(lvalue
, "MemoryHigh"))
3878 c
->memory_high
= bytes
;
3879 else if (streq(lvalue
, "StartupMemoryHigh")) {
3880 c
->startup_memory_high
= bytes
;
3881 c
->startup_memory_high_set
= true;
3882 } else if (streq(lvalue
, "MemoryMax"))
3883 c
->memory_max
= bytes
;
3884 else if (streq(lvalue
, "StartupMemoryMax")) {
3885 c
->startup_memory_max
= bytes
;
3886 c
->startup_memory_max_set
= true;
3887 } else if (streq(lvalue
, "MemorySwapMax"))
3888 c
->memory_swap_max
= bytes
;
3889 else if (streq(lvalue
, "StartupMemorySwapMax")) {
3890 c
->startup_memory_swap_max
= bytes
;
3891 c
->startup_memory_swap_max_set
= true;
3892 } else if (streq(lvalue
, "MemoryZSwapMax"))
3893 c
->memory_zswap_max
= bytes
;
3894 else if (streq(lvalue
, "StartupMemoryZSwapMax")) {
3895 c
->startup_memory_zswap_max
= bytes
;
3896 c
->startup_memory_zswap_max_set
= true;
3897 } else if (streq(lvalue
, "MemoryLimit")) {
3898 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3899 "Unit uses MemoryLimit=; please use MemoryMax= instead. Support for MemoryLimit= will be removed soon.");
3900 c
->memory_limit
= bytes
;
3907 int config_parse_tasks_max(
3909 const char *filename
,
3911 const char *section
,
3912 unsigned section_line
,
3919 const Unit
*u
= userdata
;
3920 CGroupTasksMax
*tasks_max
= data
;
3924 if (isempty(rvalue
)) {
3925 *tasks_max
= u
? u
->manager
->defaults
.tasks_max
: CGROUP_TASKS_MAX_UNSET
;
3929 if (streq(rvalue
, "infinity")) {
3930 *tasks_max
= CGROUP_TASKS_MAX_UNSET
;
3934 r
= parse_permyriad(rvalue
);
3936 *tasks_max
= (CGroupTasksMax
) { r
, 10000U }; /* r‱ */
3938 r
= safe_atou64(rvalue
, &v
);
3940 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid maximum tasks value '%s', ignoring: %m", rvalue
);
3944 if (v
<= 0 || v
>= UINT64_MAX
) {
3945 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Maximum tasks value '%s' out of range, ignoring.", rvalue
);
3949 *tasks_max
= (CGroupTasksMax
) { v
};
3955 int config_parse_delegate(
3957 const char *filename
,
3959 const char *section
,
3960 unsigned section_line
,
3967 CGroupContext
*c
= data
;
3971 t
= unit_name_to_type(unit
);
3972 assert(t
!= _UNIT_TYPE_INVALID
);
3974 if (!unit_vtable
[t
]->can_delegate
) {
3975 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Delegate= setting not supported for this unit type, ignoring.");
3979 /* We either accept a boolean value, which may be used to turn on delegation for all controllers, or
3980 * turn it off for all. Or it takes a list of controller names, in which case we add the specified
3981 * controllers to the mask to delegate. Delegate= enables delegation without any controllers. */
3983 if (isempty(rvalue
)) {
3984 /* An empty string resets controllers and sets Delegate=yes. */
3986 c
->delegate_controllers
= 0;
3990 r
= parse_boolean(rvalue
);
3992 CGroupMask mask
= 0;
3994 for (const char *p
= rvalue
;;) {
3995 _cleanup_free_
char *word
= NULL
;
3996 CGroupController cc
;
3998 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
4002 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
4008 cc
= cgroup_controller_from_string(word
);
4010 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid controller name '%s', ignoring", word
);
4014 mask
|= CGROUP_CONTROLLER_TO_MASK(cc
);
4018 c
->delegate_controllers
|= mask
;
4022 c
->delegate_controllers
= _CGROUP_MASK_ALL
;
4024 c
->delegate
= false;
4025 c
->delegate_controllers
= 0;
4031 int config_parse_delegate_subgroup(
4033 const char *filename
,
4035 const char *section
,
4036 unsigned section_line
,
4043 CGroupContext
*c
= ASSERT_PTR(data
);
4046 t
= unit_name_to_type(unit
);
4049 if (!unit_vtable
[t
]->can_delegate
) {
4050 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "DelegateSubgroup= setting not supported for this unit type, ignoring.");
4054 if (isempty(rvalue
)) {
4055 c
->delegate_subgroup
= mfree(c
->delegate_subgroup
);
4059 if (cg_needs_escape(rvalue
)) { /* Insist that specified names don't need escaping */
4060 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid control group name, ignoring: %s", rvalue
);
4064 return free_and_strdup_warn(&c
->delegate_subgroup
, rvalue
);
4067 int config_parse_managed_oom_mode(
4069 const char *filename
,
4071 const char *section
,
4072 unsigned section_line
,
4079 ManagedOOMMode
*mode
= data
, m
;
4082 t
= unit_name_to_type(unit
);
4083 assert(t
!= _UNIT_TYPE_INVALID
);
4085 if (!unit_vtable
[t
]->can_set_managed_oom
)
4086 return log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "%s= is not supported for this unit type, ignoring.", lvalue
);
4088 if (isempty(rvalue
)) {
4089 *mode
= MANAGED_OOM_AUTO
;
4093 m
= managed_oom_mode_from_string(rvalue
);
4095 log_syntax(unit
, LOG_WARNING
, filename
, line
, m
, "Invalid syntax, ignoring: %s", rvalue
);
4103 int config_parse_managed_oom_mem_pressure_limit(
4105 const char *filename
,
4107 const char *section
,
4108 unsigned section_line
,
4115 uint32_t *limit
= data
;
4119 t
= unit_name_to_type(unit
);
4120 assert(t
!= _UNIT_TYPE_INVALID
);
4122 if (!unit_vtable
[t
]->can_set_managed_oom
)
4123 return log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "%s= is not supported for this unit type, ignoring.", lvalue
);
4125 if (isempty(rvalue
)) {
4130 r
= parse_permyriad(rvalue
);
4132 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse memory pressure limit value, ignoring: %s", rvalue
);
4136 /* Normalize to 2^32-1 == 100% */
4137 *limit
= UINT32_SCALE_FROM_PERMYRIAD(r
);
4141 int config_parse_device_allow(
4143 const char *filename
,
4145 const char *section
,
4146 unsigned section_line
,
4153 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4154 CGroupDevicePermissions permissions
;
4155 CGroupContext
*c
= data
;
4156 const char *p
= rvalue
;
4159 if (isempty(rvalue
)) {
4160 while (c
->device_allow
)
4161 cgroup_context_free_device_allow(c
, c
->device_allow
);
4166 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4170 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4171 "Failed to extract device path and rights from '%s', ignoring.", rvalue
);
4175 r
= unit_path_printf(userdata
, path
, &resolved
);
4177 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4178 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4182 if (!STARTSWITH_SET(resolved
, "block-", "char-")) {
4184 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4188 if (!valid_device_node_path(resolved
)) {
4189 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid device node path '%s', ignoring.", resolved
);
4194 permissions
= isempty(p
) ? 0 : cgroup_device_permissions_from_string(p
);
4195 if (permissions
< 0) {
4196 log_syntax(unit
, LOG_WARNING
, filename
, line
, permissions
, "Invalid device rights '%s', ignoring.", p
);
4200 return cgroup_context_add_device_allow(c
, resolved
, permissions
);
4203 int config_parse_io_device_weight(
4205 const char *filename
,
4207 const char *section
,
4208 unsigned section_line
,
4215 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4216 CGroupIODeviceWeight
*w
;
4217 CGroupContext
*c
= data
;
4218 const char *p
= ASSERT_PTR(rvalue
);
4225 if (isempty(rvalue
)) {
4226 while (c
->io_device_weights
)
4227 cgroup_context_free_io_device_weight(c
, c
->io_device_weights
);
4232 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4236 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4237 "Failed to extract device path and weight from '%s', ignoring.", rvalue
);
4240 if (r
== 0 || isempty(p
)) {
4241 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4242 "Invalid device path or weight specified in '%s', ignoring.", rvalue
);
4246 r
= unit_path_printf(userdata
, path
, &resolved
);
4248 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4249 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4253 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4257 r
= cg_weight_parse(p
, &u
);
4259 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "IO weight '%s' invalid, ignoring: %m", p
);
4263 assert(u
!= CGROUP_WEIGHT_INVALID
);
4265 w
= new0(CGroupIODeviceWeight
, 1);
4269 w
->path
= TAKE_PTR(resolved
);
4272 LIST_PREPEND(device_weights
, c
->io_device_weights
, w
);
4276 int config_parse_io_device_latency(
4278 const char *filename
,
4280 const char *section
,
4281 unsigned section_line
,
4288 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4289 CGroupIODeviceLatency
*l
;
4290 CGroupContext
*c
= data
;
4291 const char *p
= ASSERT_PTR(rvalue
);
4298 if (isempty(rvalue
)) {
4299 while (c
->io_device_latencies
)
4300 cgroup_context_free_io_device_latency(c
, c
->io_device_latencies
);
4305 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4309 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4310 "Failed to extract device path and latency from '%s', ignoring.", rvalue
);
4313 if (r
== 0 || isempty(p
)) {
4314 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4315 "Invalid device path or latency specified in '%s', ignoring.", rvalue
);
4319 r
= unit_path_printf(userdata
, path
, &resolved
);
4321 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4322 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4326 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4330 r
= parse_sec(p
, &usec
);
4332 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse timer value, ignoring: %s", p
);
4336 l
= new0(CGroupIODeviceLatency
, 1);
4340 l
->path
= TAKE_PTR(resolved
);
4341 l
->target_usec
= usec
;
4343 LIST_PREPEND(device_latencies
, c
->io_device_latencies
, l
);
4347 int config_parse_io_limit(
4349 const char *filename
,
4351 const char *section
,
4352 unsigned section_line
,
4359 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4360 CGroupIODeviceLimit
*l
= NULL
;
4361 CGroupContext
*c
= data
;
4362 CGroupIOLimitType type
;
4363 const char *p
= ASSERT_PTR(rvalue
);
4370 type
= cgroup_io_limit_type_from_string(lvalue
);
4373 if (isempty(rvalue
)) {
4374 LIST_FOREACH(device_limits
, t
, c
->io_device_limits
)
4375 t
->limits
[type
] = cgroup_io_limit_defaults
[type
];
4379 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4383 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4384 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
4387 if (r
== 0 || isempty(p
)) {
4388 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4389 "Invalid device node or bandwidth specified in '%s', ignoring.", rvalue
);
4393 r
= unit_path_printf(userdata
, path
, &resolved
);
4395 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4396 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4400 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4404 if (streq("infinity", p
))
4405 num
= CGROUP_LIMIT_MAX
;
4407 r
= parse_size(p
, 1000, &num
);
4408 if (r
< 0 || num
<= 0) {
4409 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid IO limit '%s', ignoring.", p
);
4414 LIST_FOREACH(device_limits
, t
, c
->io_device_limits
)
4415 if (path_equal(resolved
, t
->path
)) {
4421 l
= new0(CGroupIODeviceLimit
, 1);
4425 l
->path
= TAKE_PTR(resolved
);
4426 for (CGroupIOLimitType i
= 0; i
< _CGROUP_IO_LIMIT_TYPE_MAX
; i
++)
4427 l
->limits
[i
] = cgroup_io_limit_defaults
[i
];
4429 LIST_PREPEND(device_limits
, c
->io_device_limits
, l
);
4432 l
->limits
[type
] = num
;
4437 int config_parse_blockio_device_weight(
4439 const char *filename
,
4441 const char *section
,
4442 unsigned section_line
,
4449 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4450 CGroupBlockIODeviceWeight
*w
;
4451 CGroupContext
*c
= data
;
4452 const char *p
= ASSERT_PTR(rvalue
);
4459 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4460 "Unit uses %s=; please use IO*= settings instead. Support for %s= will be removed soon.",
4463 if (isempty(rvalue
)) {
4464 while (c
->blockio_device_weights
)
4465 cgroup_context_free_blockio_device_weight(c
, c
->blockio_device_weights
);
4470 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4474 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4475 "Failed to extract device node and weight from '%s', ignoring.", rvalue
);
4478 if (r
== 0 || isempty(p
)) {
4479 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4480 "Invalid device node or weight specified in '%s', ignoring.", rvalue
);
4484 r
= unit_path_printf(userdata
, path
, &resolved
);
4486 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4487 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4491 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4495 r
= cg_blkio_weight_parse(p
, &u
);
4497 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid block IO weight '%s', ignoring: %m", p
);
4501 assert(u
!= CGROUP_BLKIO_WEIGHT_INVALID
);
4503 w
= new0(CGroupBlockIODeviceWeight
, 1);
4507 w
->path
= TAKE_PTR(resolved
);
4510 LIST_PREPEND(device_weights
, c
->blockio_device_weights
, w
);
4514 int config_parse_blockio_bandwidth(
4516 const char *filename
,
4518 const char *section
,
4519 unsigned section_line
,
4526 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4527 CGroupBlockIODeviceBandwidth
*b
= NULL
;
4528 CGroupContext
*c
= data
;
4529 const char *p
= ASSERT_PTR(rvalue
);
4537 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4538 "Unit uses %s=; please use IO*= settings instead. Support for %s= will be removed soon.",
4541 read
= streq("BlockIOReadBandwidth", lvalue
);
4543 if (isempty(rvalue
)) {
4544 LIST_FOREACH(device_bandwidths
, t
, c
->blockio_device_bandwidths
) {
4545 t
->rbps
= CGROUP_LIMIT_MAX
;
4546 t
->wbps
= CGROUP_LIMIT_MAX
;
4551 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4555 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4556 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
4559 if (r
== 0 || isempty(p
)) {
4560 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4561 "Invalid device node or bandwidth specified in '%s', ignoring.", rvalue
);
4565 r
= unit_path_printf(userdata
, path
, &resolved
);
4567 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4568 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4572 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4576 r
= parse_size(p
, 1000, &bytes
);
4577 if (r
< 0 || bytes
<= 0) {
4578 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid Block IO Bandwidth '%s', ignoring.", p
);
4582 LIST_FOREACH(device_bandwidths
, t
, c
->blockio_device_bandwidths
)
4583 if (path_equal(resolved
, t
->path
)) {
4589 b
= new0(CGroupBlockIODeviceBandwidth
, 1);
4593 b
->path
= TAKE_PTR(resolved
);
4594 b
->rbps
= CGROUP_LIMIT_MAX
;
4595 b
->wbps
= CGROUP_LIMIT_MAX
;
4597 LIST_PREPEND(device_bandwidths
, c
->blockio_device_bandwidths
, b
);
4608 int config_parse_job_mode_isolate(
4610 const char *filename
,
4612 const char *section
,
4613 unsigned section_line
,
4627 r
= parse_boolean(rvalue
);
4629 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse boolean, ignoring: %s", rvalue
);
4633 log_notice("%s is deprecated. Please use OnFailureJobMode= instead", lvalue
);
4635 *m
= r
? JOB_ISOLATE
: JOB_REPLACE
;
4639 int config_parse_exec_directories(
4641 const char *filename
,
4643 const char *section
,
4644 unsigned section_line
,
4651 ExecDirectory
*ed
= ASSERT_PTR(data
);
4652 const Unit
*u
= userdata
;
4659 if (isempty(rvalue
)) {
4660 /* Empty assignment resets the list */
4661 exec_directory_done(ed
);
4665 for (const char *p
= rvalue
;;) {
4666 _cleanup_free_
char *tuple
= NULL
;
4668 r
= extract_first_word(&p
, &tuple
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_RETAIN_ESCAPE
);
4672 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4673 "Invalid syntax %s=%s, ignoring: %m", lvalue
, rvalue
);
4679 _cleanup_free_
char *src
= NULL
, *dest
= NULL
;
4680 const char *q
= tuple
;
4681 r
= extract_many_words(&q
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
, &src
, &dest
, NULL
);
4685 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4686 "Invalid syntax in %s=, ignoring: %s", lvalue
, tuple
);
4690 _cleanup_free_
char *sresolved
= NULL
;
4691 r
= unit_path_printf(u
, src
, &sresolved
);
4693 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4694 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", src
);
4698 r
= path_simplify_and_warn(sresolved
, PATH_CHECK_RELATIVE
, unit
, filename
, line
, lvalue
);
4702 if (path_startswith(sresolved
, "private")) {
4703 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4704 "%s= path can't be 'private', ignoring assignment: %s", lvalue
, tuple
);
4708 /* For State and Runtime directories we support an optional destination parameter, which
4709 * will be used to create a symlink to the source. */
4710 _cleanup_free_
char *dresolved
= NULL
;
4711 if (!isempty(dest
)) {
4712 if (streq(lvalue
, "ConfigurationDirectory")) {
4713 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4714 "Destination parameter is not supported for ConfigurationDirectory, ignoring: %s", tuple
);
4718 r
= unit_path_printf(u
, dest
, &dresolved
);
4720 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4721 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", dest
);
4725 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_RELATIVE
, unit
, filename
, line
, lvalue
);
4730 r
= exec_directory_add(ed
, sresolved
, dresolved
);
4736 int config_parse_set_credential(
4738 const char *filename
,
4740 const char *section
,
4741 unsigned section_line
,
4748 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
4749 _cleanup_free_
void *d
= NULL
;
4750 ExecContext
*context
= ASSERT_PTR(data
);
4751 ExecSetCredential
*old
;
4753 bool encrypted
= ltype
;
4754 const char *p
= ASSERT_PTR(rvalue
);
4761 if (isempty(rvalue
)) {
4762 /* Empty assignment resets the list */
4763 context
->set_credentials
= hashmap_free(context
->set_credentials
);
4767 r
= extract_first_word(&p
, &word
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4771 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract credential name, ignoring: %s", rvalue
);
4774 if (r
== 0 || isempty(p
)) {
4775 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid syntax, ignoring: %s", rvalue
);
4779 r
= unit_cred_printf(u
, word
, &k
);
4781 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
4784 if (!credential_name_valid(k
)) {
4785 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Credential name \"%s\" not valid, ignoring.", k
);
4790 r
= unbase64mem_full(p
, SIZE_MAX
, true, &d
, &size
);
4792 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Encrypted credential data not valid Base64 data, ignoring.");
4799 /* We support escape codes here, so that users can insert trailing \n if they like */
4800 l
= cunescape(p
, UNESCAPE_ACCEPT_NUL
, &unescaped
);
4802 log_syntax(unit
, LOG_WARNING
, filename
, line
, l
, "Can't unescape \"%s\", ignoring: %m", p
);
4810 old
= hashmap_get(context
->set_credentials
, k
);
4812 free_and_replace(old
->data
, d
);
4814 old
->encrypted
= encrypted
;
4816 _cleanup_(exec_set_credential_freep
) ExecSetCredential
*sc
= NULL
;
4818 sc
= new(ExecSetCredential
, 1);
4822 *sc
= (ExecSetCredential
) {
4824 .data
= TAKE_PTR(d
),
4826 .encrypted
= encrypted
,
4829 r
= hashmap_ensure_put(&context
->set_credentials
, &exec_set_credential_hash_ops
, sc
->id
, sc
);
4833 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4834 "Duplicated credential value '%s', ignoring assignment: %s", sc
->id
, rvalue
);
4844 int hashmap_put_credential(Hashmap
**h
, const char *id
, const char *path
, bool encrypted
) {
4845 ExecLoadCredential
*old
;
4852 old
= hashmap_get(*h
, id
);
4854 r
= free_and_strdup(&old
->path
, path
);
4858 old
->encrypted
= encrypted
;
4860 _cleanup_(exec_load_credential_freep
) ExecLoadCredential
*lc
= NULL
;
4862 lc
= new(ExecLoadCredential
, 1);
4866 *lc
= (ExecLoadCredential
) {
4868 .path
= strdup(path
),
4869 .encrypted
= encrypted
,
4871 if (!lc
->id
|| !lc
->path
)
4874 r
= hashmap_ensure_put(h
, &exec_load_credential_hash_ops
, lc
->id
, lc
);
4884 int config_parse_load_credential(
4886 const char *filename
,
4888 const char *section
,
4889 unsigned section_line
,
4896 _cleanup_free_
char *word
= NULL
, *k
= NULL
, *q
= NULL
;
4897 ExecContext
*context
= ASSERT_PTR(data
);
4898 bool encrypted
= ltype
;
4907 if (isempty(rvalue
)) {
4908 /* Empty assignment resets the list */
4909 context
->load_credentials
= hashmap_free(context
->load_credentials
);
4914 r
= extract_first_word(&p
, &word
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4918 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
4922 r
= unit_cred_printf(u
, word
, &k
);
4924 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
4927 if (!credential_name_valid(k
)) {
4928 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Credential name \"%s\" not valid, ignoring.", k
);
4933 /* If only one field is specified take it as shortcut for inheriting a credential named
4934 * the same way from our parent */
4939 r
= unit_path_printf(u
, p
, &q
);
4941 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", p
);
4944 if (path_is_absolute(q
) ? !path_is_normalized(q
) : !credential_name_valid(q
)) {
4945 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Credential source \"%s\" not valid, ignoring.", q
);
4950 r
= hashmap_put_credential(&context
->load_credentials
, k
, q
, encrypted
);
4952 return log_error_errno(r
, "Failed to store load credential '%s': %m", rvalue
);
4957 int config_parse_import_credential(
4959 const char *filename
,
4961 const char *section
,
4962 unsigned section_line
,
4969 _cleanup_free_
char *s
= NULL
;
4970 Set
** import_credentials
= ASSERT_PTR(data
);
4978 if (isempty(rvalue
)) {
4979 /* Empty assignment resets the list */
4980 *import_credentials
= set_free_free(*import_credentials
);
4984 r
= unit_cred_printf(u
, rvalue
, &s
);
4986 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", s
);
4989 if (!credential_glob_valid(s
)) {
4990 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Credential name or glob \"%s\" not valid, ignoring.", s
);
4994 r
= set_put_strdup(import_credentials
, s
);
4996 return log_error_errno(r
, "Failed to store credential name '%s': %m", rvalue
);
5001 int config_parse_set_status(
5003 const char *filename
,
5005 const char *section
,
5006 unsigned section_line
,
5013 ExitStatusSet
*status_set
= ASSERT_PTR(data
);
5020 /* Empty assignment resets the list */
5021 if (isempty(rvalue
)) {
5022 exit_status_set_free(status_set
);
5026 for (const char *p
= rvalue
;;) {
5027 _cleanup_free_
char *word
= NULL
;
5030 r
= extract_first_word(&p
, &word
, NULL
, 0);
5034 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5035 "Failed to parse %s=%s, ignoring: %m", lvalue
, rvalue
);
5041 /* We need to call exit_status_from_string() first, because we want
5042 * to parse numbers as exit statuses, not signals. */
5044 r
= exit_status_from_string(word
);
5046 assert(r
>= 0 && r
< 256);
5047 bitmap
= &status_set
->status
;
5049 r
= signal_from_string(word
);
5051 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5052 "Failed to parse value, ignoring: %s", word
);
5055 bitmap
= &status_set
->signal
;
5058 r
= bitmap_set(bitmap
, r
);
5060 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5061 "Failed to set signal or status %s, ignoring: %m", word
);
5065 int config_parse_namespace_path_strv(
5067 const char *filename
,
5069 const char *section
,
5070 unsigned section_line
,
5077 const Unit
*u
= userdata
;
5078 char*** sv
= ASSERT_PTR(data
);
5085 if (isempty(rvalue
)) {
5086 /* Empty assignment resets the list */
5087 *sv
= strv_free(*sv
);
5091 for (const char *p
= rvalue
;;) {
5092 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
, *joined
= NULL
;
5094 bool ignore_enoent
= false, shall_prefix
= false;
5096 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
5100 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
5107 if (startswith(w
, "-")) {
5108 ignore_enoent
= true;
5111 if (startswith(w
, "+")) {
5112 shall_prefix
= true;
5116 r
= unit_path_printf(u
, w
, &resolved
);
5118 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", w
);
5122 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5126 joined
= strjoin(ignore_enoent
? "-" : "",
5127 shall_prefix
? "+" : "",
5130 r
= strv_push(sv
, joined
);
5140 int config_parse_temporary_filesystems(
5142 const char *filename
,
5144 const char *section
,
5145 unsigned section_line
,
5152 const Unit
*u
= userdata
;
5153 ExecContext
*c
= ASSERT_PTR(data
);
5160 if (isempty(rvalue
)) {
5161 /* Empty assignment resets the list */
5162 temporary_filesystem_free_many(c
->temporary_filesystems
, c
->n_temporary_filesystems
);
5163 c
->temporary_filesystems
= NULL
;
5164 c
->n_temporary_filesystems
= 0;
5168 for (const char *p
= rvalue
;;) {
5169 _cleanup_free_
char *word
= NULL
, *path
= NULL
, *resolved
= NULL
;
5172 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
5176 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
5183 r
= extract_first_word(&w
, &path
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
5187 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", word
);
5191 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid syntax, ignoring: %s", word
);
5195 r
= unit_path_printf(u
, path
, &resolved
);
5197 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", path
);
5201 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5205 r
= temporary_filesystem_add(&c
->temporary_filesystems
, &c
->n_temporary_filesystems
, resolved
, w
);
5211 int config_parse_bind_paths(
5213 const char *filename
,
5215 const char *section
,
5216 unsigned section_line
,
5223 ExecContext
*c
= ASSERT_PTR(data
);
5224 const Unit
*u
= userdata
;
5231 if (isempty(rvalue
)) {
5232 /* Empty assignment resets the list */
5233 bind_mount_free_many(c
->bind_mounts
, c
->n_bind_mounts
);
5234 c
->bind_mounts
= NULL
;
5235 c
->n_bind_mounts
= 0;
5239 for (const char *p
= rvalue
;;) {
5240 _cleanup_free_
char *source
= NULL
, *destination
= NULL
;
5241 _cleanup_free_
char *sresolved
= NULL
, *dresolved
= NULL
;
5242 char *s
= NULL
, *d
= NULL
;
5243 bool rbind
= true, ignore_enoent
= false;
5245 r
= extract_first_word(&p
, &source
, ":" WHITESPACE
, EXTRACT_UNQUOTE
|EXTRACT_DONT_COALESCE_SEPARATORS
);
5249 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
5255 r
= unit_full_printf_full(u
, source
, PATH_MAX
, &sresolved
);
5257 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5258 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", source
);
5264 ignore_enoent
= true;
5268 r
= path_simplify_and_warn(s
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5272 /* Optionally, the destination is specified. */
5273 if (p
&& p
[-1] == ':') {
5274 r
= extract_first_word(&p
, &destination
, ":" WHITESPACE
, EXTRACT_UNQUOTE
|EXTRACT_DONT_COALESCE_SEPARATORS
);
5278 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
5282 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Missing argument after ':', ignoring: %s", s
);
5286 r
= unit_path_printf(u
, destination
, &dresolved
);
5288 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5289 "Failed to resolve specifiers in \"%s\", ignoring: %m", destination
);
5293 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5299 /* Optionally, there's also a short option string specified */
5300 if (p
&& p
[-1] == ':') {
5301 _cleanup_free_
char *options
= NULL
;
5303 r
= extract_first_word(&p
, &options
, NULL
, EXTRACT_UNQUOTE
);
5307 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s=, ignoring: %s", lvalue
, rvalue
);
5311 if (isempty(options
) || streq(options
, "rbind"))
5313 else if (streq(options
, "norbind"))
5316 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid option string, ignoring setting: %s", options
);
5323 r
= bind_mount_add(&c
->bind_mounts
, &c
->n_bind_mounts
,
5327 .read_only
= !!strstr(lvalue
, "ReadOnly"),
5329 .ignore_enoent
= ignore_enoent
,
5338 int config_parse_mount_images(
5340 const char *filename
,
5342 const char *section
,
5343 unsigned section_line
,
5350 ExecContext
*c
= ASSERT_PTR(data
);
5351 const Unit
*u
= userdata
;
5358 if (isempty(rvalue
)) {
5359 /* Empty assignment resets the list */
5360 c
->mount_images
= mount_image_free_many(c
->mount_images
, &c
->n_mount_images
);
5364 for (const char *p
= rvalue
;;) {
5365 _cleanup_(mount_options_free_allp
) MountOptions
*options
= NULL
;
5366 _cleanup_free_
char *first
= NULL
, *second
= NULL
, *tuple
= NULL
;
5367 _cleanup_free_
char *sresolved
= NULL
, *dresolved
= NULL
;
5368 const char *q
= NULL
;
5370 bool permissive
= false;
5372 r
= extract_first_word(&p
, &tuple
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_RETAIN_ESCAPE
);
5376 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5377 "Invalid syntax %s=%s, ignoring: %m", lvalue
, rvalue
);
5384 r
= extract_many_words(&q
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
, &first
, &second
, NULL
);
5388 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5389 "Invalid syntax in %s=, ignoring: %s", lvalue
, tuple
);
5401 r
= unit_path_printf(u
, s
, &sresolved
);
5403 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5404 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", s
);
5408 r
= path_simplify_and_warn(sresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5412 if (isempty(second
)) {
5413 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Missing destination in %s, ignoring: %s", lvalue
, rvalue
);
5417 r
= unit_path_printf(u
, second
, &dresolved
);
5419 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5420 "Failed to resolve specifiers in \"%s\", ignoring: %m", second
);
5424 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5429 _cleanup_free_
char *partition
= NULL
, *mount_options
= NULL
, *mount_options_resolved
= NULL
;
5430 MountOptions
*o
= NULL
;
5431 PartitionDesignator partition_designator
;
5433 r
= extract_many_words(&q
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
, &partition
, &mount_options
, NULL
);
5437 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", q
);
5442 /* Single set of options, applying to the root partition/single filesystem */
5444 r
= unit_full_printf(u
, partition
, &mount_options_resolved
);
5446 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", first
);
5450 o
= new(MountOptions
, 1);
5453 *o
= (MountOptions
) {
5454 .partition_designator
= PARTITION_ROOT
,
5455 .options
= TAKE_PTR(mount_options_resolved
),
5457 LIST_APPEND(mount_options
, options
, o
);
5462 partition_designator
= partition_designator_from_string(partition
);
5463 if (partition_designator
< 0) {
5464 log_syntax(unit
, LOG_WARNING
, filename
, line
, partition_designator
,
5465 "Invalid partition name %s, ignoring", partition
);
5468 r
= unit_full_printf(u
, mount_options
, &mount_options_resolved
);
5470 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", mount_options
);
5474 o
= new(MountOptions
, 1);
5477 *o
= (MountOptions
) {
5478 .partition_designator
= partition_designator
,
5479 .options
= TAKE_PTR(mount_options_resolved
),
5481 LIST_APPEND(mount_options
, options
, o
);
5484 r
= mount_image_add(&c
->mount_images
, &c
->n_mount_images
,
5486 .source
= sresolved
,
5487 .destination
= dresolved
,
5488 .mount_options
= options
,
5489 .ignore_enoent
= permissive
,
5490 .type
= MOUNT_IMAGE_DISCRETE
,
5497 int config_parse_extension_images(
5499 const char *filename
,
5501 const char *section
,
5502 unsigned section_line
,
5509 ExecContext
*c
= ASSERT_PTR(data
);
5510 const Unit
*u
= userdata
;
5517 if (isempty(rvalue
)) {
5518 /* Empty assignment resets the list */
5519 c
->extension_images
= mount_image_free_many(c
->extension_images
, &c
->n_extension_images
);
5523 for (const char *p
= rvalue
;;) {
5524 _cleanup_free_
char *source
= NULL
, *tuple
= NULL
, *sresolved
= NULL
;
5525 _cleanup_(mount_options_free_allp
) MountOptions
*options
= NULL
;
5526 bool permissive
= false;
5527 const char *q
= NULL
;
5530 r
= extract_first_word(&p
, &tuple
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_RETAIN_ESCAPE
);
5534 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5535 "Invalid syntax %s=%s, ignoring: %m", lvalue
, rvalue
);
5542 r
= extract_first_word(&q
, &source
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
);
5546 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5547 "Invalid syntax in %s=, ignoring: %s", lvalue
, tuple
);
5559 r
= unit_path_printf(u
, s
, &sresolved
);
5561 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5562 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", s
);
5566 r
= path_simplify_and_warn(sresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5571 _cleanup_free_
char *partition
= NULL
, *mount_options
= NULL
, *mount_options_resolved
= NULL
;
5572 MountOptions
*o
= NULL
;
5573 PartitionDesignator partition_designator
;
5575 r
= extract_many_words(&q
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
, &partition
, &mount_options
, NULL
);
5579 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", q
);
5584 /* Single set of options, applying to the root partition/single filesystem */
5586 r
= unit_full_printf(u
, partition
, &mount_options_resolved
);
5588 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", partition
);
5592 o
= new(MountOptions
, 1);
5595 *o
= (MountOptions
) {
5596 .partition_designator
= PARTITION_ROOT
,
5597 .options
= TAKE_PTR(mount_options_resolved
),
5599 LIST_APPEND(mount_options
, options
, o
);
5604 partition_designator
= partition_designator_from_string(partition
);
5605 if (partition_designator
< 0) {
5606 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid partition name %s, ignoring", partition
);
5609 r
= unit_full_printf(u
, mount_options
, &mount_options_resolved
);
5611 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", mount_options
);
5615 o
= new(MountOptions
, 1);
5618 *o
= (MountOptions
) {
5619 .partition_designator
= partition_designator
,
5620 .options
= TAKE_PTR(mount_options_resolved
),
5622 LIST_APPEND(mount_options
, options
, o
);
5625 r
= mount_image_add(&c
->extension_images
, &c
->n_extension_images
,
5627 .source
= sresolved
,
5628 .mount_options
= options
,
5629 .ignore_enoent
= permissive
,
5630 .type
= MOUNT_IMAGE_EXTENSION
,
5637 int config_parse_job_timeout_sec(
5639 const char *filename
,
5641 const char *section
,
5642 unsigned section_line
,
5649 Unit
*u
= ASSERT_PTR(data
);
5657 r
= parse_sec_fix_0(rvalue
, &usec
);
5659 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse JobTimeoutSec= parameter, ignoring: %s", rvalue
);
5663 /* If the user explicitly changed JobTimeoutSec= also change JobRunningTimeoutSec=, for compatibility with old
5664 * versions. If JobRunningTimeoutSec= was explicitly set, avoid this however as whatever the user picked should
5667 if (!u
->job_running_timeout_set
)
5668 u
->job_running_timeout
= usec
;
5670 u
->job_timeout
= usec
;
5675 int config_parse_job_running_timeout_sec(
5677 const char *filename
,
5679 const char *section
,
5680 unsigned section_line
,
5687 Unit
*u
= ASSERT_PTR(data
);
5695 r
= parse_sec_fix_0(rvalue
, &usec
);
5697 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse JobRunningTimeoutSec= parameter, ignoring: %s", rvalue
);
5701 u
->job_running_timeout
= usec
;
5702 u
->job_running_timeout_set
= true;
5707 int config_parse_emergency_action(
5709 const char *filename
,
5711 const char *section
,
5712 unsigned section_line
,
5719 EmergencyAction
*x
= ASSERT_PTR(data
);
5720 RuntimeScope runtime_scope
;
5727 /* If we have a unit determine the scope based on it */
5729 runtime_scope
= ((Unit
*) ASSERT_PTR(userdata
))->manager
->runtime_scope
;
5731 runtime_scope
= ltype
; /* otherwise, assume the scope is passed in via ltype */
5733 r
= parse_emergency_action(rvalue
, runtime_scope
, x
);
5735 if (r
== -EOPNOTSUPP
)
5736 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5737 "%s= specified as %s mode action, ignoring: %s",
5738 lvalue
, runtime_scope_to_string(runtime_scope
), rvalue
);
5740 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5741 "Failed to parse %s=, ignoring: %s", lvalue
, rvalue
);
5748 int config_parse_pid_file(
5750 const char *filename
,
5752 const char *section
,
5753 unsigned section_line
,
5760 _cleanup_free_
char *k
= NULL
, *n
= NULL
;
5761 const Unit
*u
= ASSERT_PTR(userdata
);
5769 if (isempty(rvalue
)) {
5770 /* An empty assignment removes already set value. */
5775 r
= unit_path_printf(u
, rvalue
, &k
);
5777 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
5781 /* If this is a relative path make it absolute by prefixing the /run */
5782 n
= path_make_absolute(k
, u
->manager
->prefix
[EXEC_DIRECTORY_RUNTIME
]);
5786 /* Check that the result is a sensible path */
5787 r
= path_simplify_and_warn(n
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5791 r
= patch_var_run(unit
, filename
, line
, lvalue
, &n
);
5795 free_and_replace(*s
, n
);
5799 int config_parse_exit_status(
5801 const char *filename
,
5803 const char *section
,
5804 unsigned section_line
,
5811 int *exit_status
= data
, r
;
5817 assert(exit_status
);
5819 if (isempty(rvalue
)) {
5824 r
= safe_atou8(rvalue
, &u
);
5826 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse exit status '%s', ignoring: %m", rvalue
);
5834 int config_parse_disable_controllers(
5836 const char *filename
,
5838 const char *section
,
5839 unsigned section_line
,
5847 CGroupContext
*c
= data
;
5848 CGroupMask disabled_mask
;
5850 /* 1. If empty, make all controllers eligible for use again.
5851 * 2. If non-empty, merge all listed controllers, space separated. */
5853 if (isempty(rvalue
)) {
5854 c
->disable_controllers
= 0;
5858 r
= cg_mask_from_string(rvalue
, &disabled_mask
);
5859 if (r
< 0 || disabled_mask
<= 0) {
5860 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid cgroup string: %s, ignoring", rvalue
);
5864 c
->disable_controllers
|= disabled_mask
;
5869 int config_parse_ip_filter_bpf_progs(
5871 const char *filename
,
5873 const char *section
,
5874 unsigned section_line
,
5881 _cleanup_free_
char *resolved
= NULL
;
5882 const Unit
*u
= userdata
;
5883 char ***paths
= ASSERT_PTR(data
);
5890 if (isempty(rvalue
)) {
5891 *paths
= strv_free(*paths
);
5895 r
= unit_path_printf(u
, rvalue
, &resolved
);
5897 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
5901 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5905 if (strv_contains(*paths
, resolved
))
5908 r
= strv_extend(paths
, resolved
);
5912 r
= bpf_firewall_supported();
5915 if (r
!= BPF_FIREWALL_SUPPORTED_WITH_MULTI
) {
5916 static bool warned
= false;
5918 log_full(warned
? LOG_DEBUG
: LOG_WARNING
,
5919 "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"
5920 "Starting this unit will fail! (This warning is only shown for the first loaded unit using IP firewalling.)", filename
, line
, lvalue
, rvalue
);
5928 int config_parse_bpf_foreign_program(
5930 const char *filename
,
5932 const char *section
,
5933 unsigned section_line
,
5939 _cleanup_free_
char *resolved
= NULL
, *word
= NULL
;
5940 CGroupContext
*c
= data
;
5941 const char *p
= ASSERT_PTR(rvalue
);
5948 if (isempty(rvalue
)) {
5949 while (c
->bpf_foreign_programs
)
5950 cgroup_context_remove_bpf_foreign_program(c
, c
->bpf_foreign_programs
);
5955 r
= extract_first_word(&p
, &word
, ":", 0);
5959 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse foreign BPF program, ignoring: %s", rvalue
);
5962 if (r
== 0 || isempty(p
)) {
5963 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid syntax in %s=, ignoring: %s", lvalue
, rvalue
);
5967 attach_type
= bpf_cgroup_attach_type_from_string(word
);
5968 if (attach_type
< 0) {
5969 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Unknown BPF attach type=%s, ignoring: %s", word
, rvalue
);
5973 r
= unit_path_printf(u
, p
, &resolved
);
5975 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %s", p
, rvalue
);
5979 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5983 r
= cgroup_context_add_bpf_foreign_program(c
, attach_type
, resolved
);
5985 return log_error_errno(r
, "Failed to add foreign BPF program to cgroup context: %m");
5990 int config_parse_cgroup_socket_bind(
5992 const char *filename
,
5994 const char *section
,
5995 unsigned section_line
,
6001 _cleanup_free_ CGroupSocketBindItem
*item
= NULL
;
6002 CGroupSocketBindItem
**head
= data
;
6003 uint16_t nr_ports
, port_min
;
6004 int af
, ip_protocol
, r
;
6006 if (isempty(rvalue
)) {
6007 cgroup_context_remove_socket_bind(head
);
6011 r
= parse_socket_bind_item(rvalue
, &af
, &ip_protocol
, &nr_ports
, &port_min
);
6015 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
6016 "Unable to parse %s= assignment, ignoring: %s", lvalue
, rvalue
);
6020 item
= new(CGroupSocketBindItem
, 1);
6023 *item
= (CGroupSocketBindItem
) {
6024 .address_family
= af
,
6025 .ip_protocol
= ip_protocol
,
6026 .nr_ports
= nr_ports
,
6027 .port_min
= port_min
,
6030 LIST_PREPEND(socket_bind_items
, *head
, TAKE_PTR(item
));
6035 int config_parse_restrict_network_interfaces(
6037 const char *filename
,
6039 const char *section
,
6040 unsigned section_line
,
6046 CGroupContext
*c
= ASSERT_PTR(data
);
6047 bool is_allow_rule
= true;
6054 if (isempty(rvalue
)) {
6055 /* Empty assignment resets the list */
6056 c
->restrict_network_interfaces
= set_free_free(c
->restrict_network_interfaces
);
6060 if (rvalue
[0] == '~') {
6061 is_allow_rule
= false;
6065 if (set_isempty(c
->restrict_network_interfaces
))
6066 /* Only initialize this when creating the set */
6067 c
->restrict_network_interfaces_is_allow_list
= is_allow_rule
;
6069 for (const char *p
= rvalue
;;) {
6070 _cleanup_free_
char *word
= NULL
;
6072 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
6078 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
6079 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
6083 if (!ifname_valid(word
)) {
6084 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid interface name, ignoring: %s", word
);
6088 if (c
->restrict_network_interfaces_is_allow_list
!= is_allow_rule
)
6089 free(set_remove(c
->restrict_network_interfaces
, word
));
6091 r
= set_put_strdup(&c
->restrict_network_interfaces
, word
);
6100 static int merge_by_names(Unit
*u
, Set
*names
, const char *id
) {
6106 /* Let's try to add in all names that are aliases of this unit */
6107 while ((k
= set_steal_first(names
))) {
6108 _cleanup_free_ _unused_
char *free_k
= k
;
6110 /* First try to merge in the other name into our unit */
6111 r
= unit_merge_by_name(u
, k
);
6115 /* Hmm, we couldn't merge the other unit into ours? Then let's try it the other way
6118 other
= manager_get_unit(u
->manager
, k
);
6120 return r
; /* return previous failure */
6122 r
= unit_merge(other
, u
);
6126 return merge_by_names(other
, names
, NULL
);
6129 if (streq_ptr(id
, k
))
6130 unit_choose_id(u
, id
);
6136 int unit_load_fragment(Unit
*u
) {
6137 const char *fragment
;
6138 _cleanup_set_free_free_ Set
*names
= NULL
;
6142 assert(u
->load_state
== UNIT_STUB
);
6146 u
->access_selinux_context
= mfree(u
->access_selinux_context
);
6147 u
->load_state
= UNIT_LOADED
;
6151 /* Possibly rebuild the fragment map to catch new units */
6152 r
= unit_file_build_name_map(&u
->manager
->lookup_paths
,
6153 &u
->manager
->unit_cache_timestamp_hash
,
6154 &u
->manager
->unit_id_map
,
6155 &u
->manager
->unit_name_map
,
6156 &u
->manager
->unit_path_cache
);
6158 return log_error_errno(r
, "Failed to rebuild name map: %m");
6160 r
= unit_file_find_fragment(u
->manager
->unit_id_map
,
6161 u
->manager
->unit_name_map
,
6165 if (r
< 0 && r
!= -ENOENT
)
6169 /* Open the file, check if this is a mask, otherwise read. */
6170 _cleanup_fclose_
FILE *f
= NULL
;
6173 /* Try to open the file name. A symlink is OK, for example for linked files or masks. We
6174 * expect that all symlinks within the lookup paths have been already resolved, but we don't
6175 * verify this here. */
6176 f
= fopen(fragment
, "re");
6178 return log_unit_notice_errno(u
, errno
, "Failed to open %s: %m", fragment
);
6180 if (fstat(fileno(f
), &st
) < 0)
6183 r
= free_and_strdup(&u
->fragment_path
, fragment
);
6187 if (null_or_empty(&st
)) {
6188 /* Unit file is masked */
6190 u
->load_state
= u
->perpetual
? UNIT_LOADED
: UNIT_MASKED
; /* don't allow perpetual units to ever be masked */
6191 u
->fragment_mtime
= 0;
6192 u
->access_selinux_context
= mfree(u
->access_selinux_context
);
6195 if (mac_selinux_use()) {
6196 _cleanup_freecon_
char *selcon
= NULL
;
6198 /* Cache the SELinux context of the unit file here. We'll make use of when checking access permissions to loaded units */
6199 r
= fgetfilecon_raw(fileno(f
), &selcon
);
6201 log_unit_warning_errno(u
, r
, "Failed to read SELinux context of '%s', ignoring: %m", fragment
);
6203 r
= free_and_strdup(&u
->access_selinux_context
, selcon
);
6208 u
->access_selinux_context
= mfree(u
->access_selinux_context
);
6210 u
->load_state
= UNIT_LOADED
;
6211 u
->fragment_mtime
= timespec_load(&st
.st_mtim
);
6213 /* Now, parse the file contents */
6214 r
= config_parse(u
->id
, fragment
, f
,
6215 UNIT_VTABLE(u
)->sections
,
6216 config_item_perf_lookup
, load_fragment_gperf_lookup
,
6221 log_unit_notice_errno(u
, r
, "Unit configuration has fatal error, unit will not be started.");
6227 /* Call merge_by_names with the name derived from the fragment path as the preferred name.
6229 * We do the merge dance here because for some unit types, the unit might have aliases which are not
6230 * declared in the file system. In particular, this is true (and frequent) for device and swap units.
6232 const char *id
= u
->id
;
6233 _cleanup_free_
char *filename
= NULL
, *free_id
= NULL
;
6236 r
= path_extract_filename(fragment
, &filename
);
6238 return log_debug_errno(r
, "Failed to extract filename from fragment '%s': %m", fragment
);
6241 if (unit_name_is_valid(id
, UNIT_NAME_TEMPLATE
)) {
6242 assert(u
->instance
); /* If we're not trying to use a template for non-instanced unit,
6243 * this must be set. */
6245 r
= unit_name_replace_instance(id
, u
->instance
, &free_id
);
6247 return log_debug_errno(r
, "Failed to build id (%s + %s): %m", id
, u
->instance
);
6252 return merge_by_names(u
, names
, id
);
6255 void unit_dump_config_items(FILE *f
) {
6256 static const struct {
6257 const ConfigParserCallback callback
;
6260 { config_parse_warn_compat
, "NOTSUPPORTED" },
6261 { config_parse_int
, "INTEGER" },
6262 { config_parse_unsigned
, "UNSIGNED" },
6263 { config_parse_iec_size
, "SIZE" },
6264 { config_parse_iec_uint64
, "SIZE" },
6265 { config_parse_si_uint64
, "SIZE" },
6266 { config_parse_bool
, "BOOLEAN" },
6267 { config_parse_string
, "STRING" },
6268 { config_parse_path
, "PATH" },
6269 { config_parse_unit_path_printf
, "PATH" },
6270 { config_parse_colon_separated_paths
, "PATH" },
6271 { config_parse_strv
, "STRING [...]" },
6272 { config_parse_exec_nice
, "NICE" },
6273 { config_parse_exec_oom_score_adjust
, "OOMSCOREADJUST" },
6274 { config_parse_exec_io_class
, "IOCLASS" },
6275 { config_parse_exec_io_priority
, "IOPRIORITY" },
6276 { config_parse_exec_cpu_sched_policy
, "CPUSCHEDPOLICY" },
6277 { config_parse_exec_cpu_sched_prio
, "CPUSCHEDPRIO" },
6278 { config_parse_exec_cpu_affinity
, "CPUAFFINITY" },
6279 { config_parse_mode
, "MODE" },
6280 { config_parse_unit_env_file
, "FILE" },
6281 { config_parse_exec_output
, "OUTPUT" },
6282 { config_parse_exec_input
, "INPUT" },
6283 { config_parse_log_facility
, "FACILITY" },
6284 { config_parse_log_level
, "LEVEL" },
6285 { config_parse_exec_secure_bits
, "SECUREBITS" },
6286 { config_parse_capability_set
, "BOUNDINGSET" },
6287 { config_parse_rlimit
, "LIMIT" },
6288 { config_parse_unit_deps
, "UNIT [...]" },
6289 { config_parse_exec
, "PATH [ARGUMENT [...]]" },
6290 { config_parse_service_type
, "SERVICETYPE" },
6291 { config_parse_service_exit_type
, "SERVICEEXITTYPE" },
6292 { config_parse_service_restart
, "SERVICERESTART" },
6293 { config_parse_service_restart_mode
, "SERVICERESTARTMODE" },
6294 { config_parse_service_timeout_failure_mode
, "TIMEOUTMODE" },
6295 { config_parse_kill_mode
, "KILLMODE" },
6296 { config_parse_signal
, "SIGNAL" },
6297 { config_parse_socket_listen
, "SOCKET [...]" },
6298 { config_parse_socket_bind
, "SOCKETBIND" },
6299 { config_parse_socket_bindtodevice
, "NETWORKINTERFACE" },
6300 { config_parse_sec
, "SECONDS" },
6301 { config_parse_nsec
, "NANOSECONDS" },
6302 { config_parse_namespace_path_strv
, "PATH [...]" },
6303 { config_parse_bind_paths
, "PATH[:PATH[:OPTIONS]] [...]" },
6304 { config_parse_unit_requires_mounts_for
,
6306 { config_parse_exec_mount_propagation_flag
,
6308 { config_parse_unit_string_printf
, "STRING" },
6309 { config_parse_trigger_unit
, "UNIT" },
6310 { config_parse_timer
, "TIMER" },
6311 { config_parse_path_spec
, "PATH" },
6312 { config_parse_notify_access
, "ACCESS" },
6313 { config_parse_ip_tos
, "TOS" },
6314 { config_parse_unit_condition_path
, "CONDITION" },
6315 { config_parse_unit_condition_string
, "CONDITION" },
6316 { config_parse_unit_slice
, "SLICE" },
6317 { config_parse_documentation
, "URL" },
6318 { config_parse_service_timeout
, "SECONDS" },
6319 { config_parse_emergency_action
, "ACTION" },
6320 { config_parse_set_status
, "STATUS" },
6321 { config_parse_service_sockets
, "SOCKETS" },
6322 { config_parse_environ
, "ENVIRON" },
6324 { config_parse_syscall_filter
, "SYSCALLS" },
6325 { config_parse_syscall_archs
, "ARCHS" },
6326 { config_parse_syscall_errno
, "ERRNO" },
6327 { config_parse_syscall_log
, "SYSCALLS" },
6328 { config_parse_address_families
, "FAMILIES" },
6329 { config_parse_restrict_namespaces
, "NAMESPACES" },
6331 { config_parse_restrict_filesystems
, "FILESYSTEMS" },
6332 { config_parse_cpu_shares
, "SHARES" },
6333 { config_parse_cg_weight
, "WEIGHT" },
6334 { config_parse_cg_cpu_weight
, "CPUWEIGHT" },
6335 { config_parse_memory_limit
, "LIMIT" },
6336 { config_parse_device_allow
, "DEVICE" },
6337 { config_parse_device_policy
, "POLICY" },
6338 { config_parse_io_limit
, "LIMIT" },
6339 { config_parse_io_device_weight
, "DEVICEWEIGHT" },
6340 { config_parse_io_device_latency
, "DEVICELATENCY" },
6341 { config_parse_blockio_bandwidth
, "BANDWIDTH" },
6342 { config_parse_blockio_weight
, "WEIGHT" },
6343 { config_parse_blockio_device_weight
, "DEVICEWEIGHT" },
6344 { config_parse_long
, "LONG" },
6345 { config_parse_socket_service
, "SERVICE" },
6347 { config_parse_exec_selinux_context
, "LABEL" },
6349 { config_parse_job_mode
, "MODE" },
6350 { config_parse_job_mode_isolate
, "BOOLEAN" },
6351 { config_parse_personality
, "PERSONALITY" },
6352 { config_parse_log_filter_patterns
, "REGEX" },
6355 const char *prev
= NULL
;
6359 NULSTR_FOREACH(i
, load_fragment_gperf_nulstr
) {
6360 const char *rvalue
= "OTHER", *lvalue
;
6361 const ConfigPerfItem
*p
;
6364 assert_se(p
= load_fragment_gperf_lookup(i
, strlen(i
)));
6366 /* Hide legacy settings */
6367 if (p
->parse
== config_parse_warn_compat
&&
6368 p
->ltype
== DISABLED_LEGACY
)
6371 for (size_t j
= 0; j
< ELEMENTSOF(table
); j
++)
6372 if (p
->parse
== table
[j
].callback
) {
6373 rvalue
= table
[j
].rvalue
;
6377 dot
= strchr(i
, '.');
6378 lvalue
= dot
? dot
+ 1 : i
;
6381 size_t prefix_len
= dot
- i
;
6383 if (!prev
|| !strneq(prev
, i
, prefix_len
+1)) {
6387 fprintf(f
, "[%.*s]\n", (int) prefix_len
, i
);
6391 fprintf(f
, "%s=%s\n", lvalue
, rvalue
);
6396 int config_parse_cpu_affinity2(
6398 const char *filename
,
6400 const char *section
,
6401 unsigned section_line
,
6408 CPUSet
*affinity
= ASSERT_PTR(data
);
6410 (void) parse_cpu_set_extend(rvalue
, affinity
, true, unit
, filename
, line
, lvalue
);
6415 int config_parse_show_status(
6417 const char *filename
,
6419 const char *section
,
6420 unsigned section_line
,
6428 ShowStatus
*b
= ASSERT_PTR(data
);
6434 k
= parse_show_status(rvalue
, b
);
6436 log_syntax(unit
, LOG_WARNING
, filename
, line
, k
, "Failed to parse show status setting, ignoring: %s", rvalue
);
6441 int config_parse_output_restricted(
6443 const char *filename
,
6445 const char *section
,
6446 unsigned section_line
,
6453 ExecOutput t
, *eo
= ASSERT_PTR(data
);
6454 bool obsolete
= false;
6460 if (streq(rvalue
, "syslog")) {
6461 t
= EXEC_OUTPUT_JOURNAL
;
6463 } else if (streq(rvalue
, "syslog+console")) {
6464 t
= EXEC_OUTPUT_JOURNAL_AND_CONSOLE
;
6467 t
= exec_output_from_string(rvalue
);
6469 log_syntax(unit
, LOG_WARNING
, filename
, line
, t
, "Failed to parse output type, ignoring: %s", rvalue
);
6473 if (IN_SET(t
, EXEC_OUTPUT_SOCKET
, EXEC_OUTPUT_NAMED_FD
, EXEC_OUTPUT_FILE
, EXEC_OUTPUT_FILE_APPEND
, EXEC_OUTPUT_FILE_TRUNCATE
)) {
6474 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Standard output types socket, fd:, file:, append:, truncate: are not supported as defaults, ignoring: %s", rvalue
);
6480 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
6481 "Standard output type %s is obsolete, automatically updating to %s. Please update your configuration.",
6482 rvalue
, exec_output_to_string(t
));
6488 int config_parse_crash_chvt(
6490 const char *filename
,
6492 const char *section
,
6493 unsigned section_line
,
6507 r
= parse_crash_chvt(rvalue
, data
);
6509 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse CrashChangeVT= setting, ignoring: %s", rvalue
);
6514 int config_parse_swap_priority(
6516 const char *filename
,
6518 const char *section
,
6519 unsigned section_line
,
6526 Swap
*s
= ASSERT_PTR(userdata
);
6534 if (isempty(rvalue
)) {
6535 s
->parameters_fragment
.priority
= -1;
6536 s
->parameters_fragment
.priority_set
= false;
6540 r
= safe_atoi(rvalue
, &priority
);
6542 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid swap priority '%s', ignoring.", rvalue
);
6546 if (priority
< -1) {
6547 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
);
6551 if (priority
> 32767) {
6552 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Swap priority out of range, ignoring: %s", rvalue
);
6556 s
->parameters_fragment
.priority
= priority
;
6557 s
->parameters_fragment
.priority_set
= true;
6561 int config_parse_watchdog_sec(
6563 const char *filename
,
6565 const char *section
,
6566 unsigned section_line
,
6573 usec_t
*usec
= data
;
6579 /* This is called for {Runtime,Reboot,KExec}WatchdogSec= where "default" maps to
6580 * USEC_INFINITY internally. */
6582 if (streq(rvalue
, "default"))
6583 *usec
= USEC_INFINITY
;
6584 else if (streq(rvalue
, "off"))
6587 return config_parse_sec(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
);
6592 int config_parse_tty_size(
6594 const char *filename
,
6596 const char *section
,
6597 unsigned section_line
,
6604 unsigned *sz
= data
;
6610 if (isempty(rvalue
)) {
6615 return config_parse_unsigned(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
);
6618 int config_parse_log_filter_patterns(
6620 const char *filename
,
6622 const char *section
,
6623 unsigned section_line
,
6630 ExecContext
*c
= ASSERT_PTR(data
);
6631 const char *pattern
= ASSERT_PTR(rvalue
);
6632 bool is_allowlist
= true;
6638 if (isempty(pattern
)) {
6639 /* Empty assignment resets the lists. */
6640 c
->log_filter_allowed_patterns
= set_free_free(c
->log_filter_allowed_patterns
);
6641 c
->log_filter_denied_patterns
= set_free_free(c
->log_filter_denied_patterns
);
6645 if (pattern
[0] == '~') {
6646 is_allowlist
= false;
6648 if (isempty(pattern
))
6649 /* LogFilterPatterns=~ is not considered a valid pattern. */
6650 return log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
6651 "Regex pattern invalid, ignoring: %s=%s", lvalue
, rvalue
);
6654 if (pattern_compile_and_log(pattern
, 0, NULL
) < 0)
6657 r
= set_put_strdup(is_allowlist
? &c
->log_filter_allowed_patterns
: &c
->log_filter_denied_patterns
,
6660 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
6661 "Failed to store log filtering pattern, ignoring: %s=%s", lvalue
, rvalue
);
6668 int config_parse_open_file(
6670 const char *filename
,
6672 const char *section
,
6673 unsigned section_line
,
6680 _cleanup_(open_file_freep
) OpenFile
*of
= NULL
;
6681 OpenFile
**head
= ASSERT_PTR(data
);
6688 if (isempty(rvalue
)) {
6689 open_file_free_many(head
);
6693 r
= open_file_parse(rvalue
, &of
);
6695 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse OpenFile= setting, ignoring: %s", rvalue
);
6699 LIST_APPEND(open_files
, *head
, TAKE_PTR(of
));
6704 int config_parse_cgroup_nft_set(
6706 const char *filename
,
6708 const char *section
,
6709 unsigned section_line
,
6716 CGroupContext
*c
= ASSERT_PTR(data
);
6717 Unit
*u
= ASSERT_PTR(userdata
);
6719 return config_parse_nft_set(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, &c
->nft_set_context
, u
);