1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
3 Copyright © 2012 Holger Hans Peter Freyther
14 #include <sys/resource.h>
16 #include "sd-messages.h"
19 #include "all-units.h"
20 #include "alloc-util.h"
21 #include "bpf-firewall.h"
23 #include "bpf-program.h"
24 #include "bpf-socket-bind.h"
25 #include "bus-error.h"
26 #include "bus-internal.h"
29 #include "capability-util.h"
30 #include "cgroup-setup.h"
31 #include "conf-parser.h"
32 #include "core-varlink.h"
33 #include "cpu-set-util.h"
34 #include "creds-util.h"
36 #include "errno-list.h"
41 #include "hexdecoct.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 "parse-helpers.h"
53 #include "parse-util.h"
54 #include "path-util.h"
55 #include "pcre2-util.h"
56 #include "percent-util.h"
57 #include "process-util.h"
59 #include "seccomp-util.h"
61 #include "securebits-util.h"
62 #include "selinux-util.h"
63 #include "signal-util.h"
64 #include "socket-netlink.h"
65 #include "specifier.h"
66 #include "stat-util.h"
67 #include "string-util.h"
69 #include "syslog-util.h"
70 #include "time-util.h"
71 #include "unit-name.h"
72 #include "unit-printf.h"
73 #include "user-util.h"
77 static int parse_socket_protocol(const char *s
) {
80 r
= parse_ip_protocol(s
);
83 if (!IN_SET(r
, IPPROTO_UDPLITE
, IPPROTO_SCTP
))
84 return -EPROTONOSUPPORT
;
89 int parse_crash_chvt(const char *value
, int *data
) {
92 if (safe_atoi(value
, data
) >= 0)
95 b
= parse_boolean(value
);
100 *data
= 0; /* switch to where kmsg goes */
102 *data
= -1; /* turn off switching */
107 int parse_confirm_spawn(const char *value
, char **console
) {
111 r
= value
? parse_boolean(value
) : 1;
115 } else if (r
> 0) /* on with default tty */
116 s
= strdup("/dev/console");
117 else if (is_path(value
)) /* on with fully qualified path */
119 else /* on with only a tty file name, not a fully qualified path */
120 s
= path_join("/dev/", value
);
128 DEFINE_CONFIG_PARSE(config_parse_socket_protocol
, parse_socket_protocol
, "Failed to parse socket protocol");
129 DEFINE_CONFIG_PARSE(config_parse_exec_secure_bits
, secure_bits_from_string
, "Failed to parse secure bits");
130 DEFINE_CONFIG_PARSE_ENUM(config_parse_collect_mode
, collect_mode
, CollectMode
, "Failed to parse garbage collection mode");
131 DEFINE_CONFIG_PARSE_ENUM(config_parse_device_policy
, cgroup_device_policy
, CGroupDevicePolicy
, "Failed to parse device policy");
132 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_keyring_mode
, exec_keyring_mode
, ExecKeyringMode
, "Failed to parse keyring mode");
133 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_proc
, protect_proc
, ProtectProc
, "Failed to parse /proc/ protection mode");
134 DEFINE_CONFIG_PARSE_ENUM(config_parse_proc_subset
, proc_subset
, ProcSubset
, "Failed to parse /proc/ subset mode");
135 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_utmp_mode
, exec_utmp_mode
, ExecUtmpMode
, "Failed to parse utmp mode");
136 DEFINE_CONFIG_PARSE_ENUM(config_parse_job_mode
, job_mode
, JobMode
, "Failed to parse job mode");
137 DEFINE_CONFIG_PARSE_ENUM(config_parse_notify_access
, notify_access
, NotifyAccess
, "Failed to parse notify access specifier");
138 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_home
, protect_home
, ProtectHome
, "Failed to parse protect home value");
139 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_system
, protect_system
, ProtectSystem
, "Failed to parse protect system value");
140 DEFINE_CONFIG_PARSE_ENUM(config_parse_runtime_preserve_mode
, exec_preserve_mode
, ExecPreserveMode
, "Failed to parse runtime directory preserve mode");
141 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_type
, service_type
, ServiceType
, "Failed to parse service type");
142 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_exit_type
, service_exit_type
, ServiceExitType
, "Failed to parse service exit type");
143 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart
, service_restart
, ServiceRestart
, "Failed to parse service restart specifier");
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_WITH_DEFAULT(config_parse_ip_tos
, ip_tos
, int, -1, "Failed to parse IP TOS value");
149 DEFINE_CONFIG_PARSE_PTR(config_parse_blockio_weight
, cg_blkio_weight_parse
, uint64_t, "Invalid block IO weight");
150 DEFINE_CONFIG_PARSE_PTR(config_parse_cg_weight
, cg_weight_parse
, uint64_t, "Invalid weight");
151 DEFINE_CONFIG_PARSE_PTR(config_parse_cg_cpu_weight
, cg_cpu_weight_parse
, uint64_t, "Invalid CPU weight");
152 static DEFINE_CONFIG_PARSE_PTR(config_parse_cpu_shares_internal
, cg_cpu_shares_parse
, uint64_t, "Invalid CPU shares");
153 DEFINE_CONFIG_PARSE_PTR(config_parse_exec_mount_flags
, mount_propagation_flag_from_string
, unsigned long, "Failed to parse mount flag");
154 DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_numa_policy
, mpol
, int, -1, "Invalid NUMA policy type");
155 DEFINE_CONFIG_PARSE_ENUM(config_parse_status_unit_format
, status_unit_format
, StatusUnitFormat
, "Failed to parse status unit format");
156 DEFINE_CONFIG_PARSE_ENUM_FULL(config_parse_socket_timestamping
, socket_timestamping_from_string_harder
, SocketTimestamping
, "Failed to parse timestamping precision");
158 int config_parse_cpu_shares(
160 const char *filename
,
163 unsigned section_line
,
175 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
176 "Unit uses %s=; please use CPUWeight= instead. Support for %s= will be removed soon.",
179 return config_parse_cpu_shares_internal(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
);
182 bool contains_instance_specifier_superset(const char *s
) {
184 bool percent
= false;
198 /* If the string is just the instance specifier, it's not a superset of the instance. */
199 if (memcmp_nn(p
, q
- p
, "%i", strlen("%i")) == 0)
202 /* %i, %n and %N all expand to the instance or a superset of it. */
207 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 LIST_FIND_TAIL(port
, s
->ports
, tail
);
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
->oom_score_adjust_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
= 0;
1889 bool invert
= false;
1896 if (rvalue
[0] == '~') {
1901 if (streq(lvalue
, "CapabilityBoundingSet"))
1902 initial
= CAP_ALL
; /* initialized to all bits on */
1903 /* else "AmbientCapabilities" initialized to all bits off */
1905 r
= capability_set_from_string(rvalue
, &sum
);
1907 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= specifier '%s', ignoring: %m", lvalue
, rvalue
);
1911 if (sum
== 0 || *capability_set
== initial
)
1912 /* "", "~" or uninitialized data -> replace */
1913 *capability_set
= invert
? ~sum
: sum
;
1915 /* previous data -> merge */
1917 *capability_set
&= ~sum
;
1919 *capability_set
|= sum
;
1925 int config_parse_exec_selinux_context(
1927 const char *filename
,
1929 const char *section
,
1930 unsigned section_line
,
1937 ExecContext
*c
= ASSERT_PTR(data
);
1938 const Unit
*u
= userdata
;
1947 if (isempty(rvalue
)) {
1948 c
->selinux_context
= mfree(c
->selinux_context
);
1949 c
->selinux_context_ignore
= false;
1953 if (rvalue
[0] == '-') {
1959 r
= unit_full_printf(u
, rvalue
, &k
);
1961 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
1962 "Failed to resolve unit specifiers in '%s'%s: %m",
1963 rvalue
, ignore
? ", ignoring" : "");
1964 return ignore
? 0 : -ENOEXEC
;
1967 free_and_replace(c
->selinux_context
, k
);
1968 c
->selinux_context_ignore
= ignore
;
1973 int config_parse_exec_apparmor_profile(
1975 const char *filename
,
1977 const char *section
,
1978 unsigned section_line
,
1985 ExecContext
*c
= ASSERT_PTR(data
);
1986 const Unit
*u
= userdata
;
1995 if (isempty(rvalue
)) {
1996 c
->apparmor_profile
= mfree(c
->apparmor_profile
);
1997 c
->apparmor_profile_ignore
= false;
2001 if (rvalue
[0] == '-') {
2007 r
= unit_full_printf(u
, rvalue
, &k
);
2009 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
2010 "Failed to resolve unit specifiers in '%s'%s: %m",
2011 rvalue
, ignore
? ", ignoring" : "");
2012 return ignore
? 0 : -ENOEXEC
;
2015 free_and_replace(c
->apparmor_profile
, k
);
2016 c
->apparmor_profile_ignore
= ignore
;
2021 int config_parse_exec_smack_process_label(
2023 const char *filename
,
2025 const char *section
,
2026 unsigned section_line
,
2033 ExecContext
*c
= ASSERT_PTR(data
);
2034 const Unit
*u
= userdata
;
2043 if (isempty(rvalue
)) {
2044 c
->smack_process_label
= mfree(c
->smack_process_label
);
2045 c
->smack_process_label_ignore
= false;
2049 if (rvalue
[0] == '-') {
2055 r
= unit_full_printf(u
, rvalue
, &k
);
2057 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
2058 "Failed to resolve unit specifiers in '%s'%s: %m",
2059 rvalue
, ignore
? ", ignoring" : "");
2060 return ignore
? 0 : -ENOEXEC
;
2063 free_and_replace(c
->smack_process_label
, k
);
2064 c
->smack_process_label_ignore
= ignore
;
2069 int config_parse_timer(
2071 const char *filename
,
2073 const char *section
,
2074 unsigned section_line
,
2081 _cleanup_(calendar_spec_freep
) CalendarSpec
*c
= NULL
;
2082 _cleanup_free_
char *k
= NULL
;
2083 const Unit
*u
= userdata
;
2084 Timer
*t
= ASSERT_PTR(data
);
2093 if (isempty(rvalue
)) {
2094 /* Empty assignment resets list */
2095 timer_free_values(t
);
2099 r
= unit_full_printf(u
, rvalue
, &k
);
2101 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2105 if (ltype
== TIMER_CALENDAR
) {
2106 r
= calendar_spec_from_string(k
, &c
);
2108 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse calendar specification, ignoring: %s", k
);
2112 r
= parse_sec(k
, &usec
);
2114 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse timer value, ignoring: %s", k
);
2119 v
= new(TimerValue
, 1);
2126 .calendar_spec
= TAKE_PTR(c
),
2129 LIST_PREPEND(value
, t
->values
, v
);
2134 int config_parse_trigger_unit(
2136 const char *filename
,
2138 const char *section
,
2139 unsigned section_line
,
2146 _cleanup_free_
char *p
= NULL
;
2147 Unit
*u
= ASSERT_PTR(data
);
2155 if (UNIT_TRIGGER(u
)) {
2156 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Multiple units to trigger specified, ignoring: %s", rvalue
);
2160 r
= unit_name_printf(u
, rvalue
, &p
);
2162 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2166 type
= unit_name_to_type(p
);
2168 log_syntax(unit
, LOG_WARNING
, filename
, line
, type
, "Unit type not valid, ignoring: %s", rvalue
);
2171 if (unit_has_name(u
, p
)) {
2172 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Units cannot trigger themselves, ignoring: %s", rvalue
);
2176 r
= unit_add_two_dependencies_by_name(u
, UNIT_BEFORE
, UNIT_TRIGGERS
, p
, true, UNIT_DEPENDENCY_FILE
);
2178 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add trigger on %s, ignoring: %m", p
);
2185 int config_parse_path_spec(const char *unit
,
2186 const char *filename
,
2188 const char *section
,
2189 unsigned section_line
,
2196 Path
*p
= ASSERT_PTR(data
);
2199 _cleanup_free_
char *k
= NULL
;
2206 if (isempty(rvalue
)) {
2207 /* Empty assignment clears list */
2212 b
= path_type_from_string(lvalue
);
2214 log_syntax(unit
, LOG_WARNING
, filename
, line
, b
, "Failed to parse path type, ignoring: %s", lvalue
);
2218 r
= unit_path_printf(UNIT(p
), rvalue
, &k
);
2220 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2224 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2228 s
= new0(PathSpec
, 1);
2233 s
->path
= TAKE_PTR(k
);
2235 s
->inotify_fd
= -EBADF
;
2237 LIST_PREPEND(spec
, p
->specs
, s
);
2242 int config_parse_socket_service(
2244 const char *filename
,
2246 const char *section
,
2247 unsigned section_line
,
2254 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
2255 _cleanup_free_
char *p
= NULL
;
2256 Socket
*s
= ASSERT_PTR(data
);
2264 r
= unit_name_printf(UNIT(s
), rvalue
, &p
);
2266 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2270 if (!endswith(p
, ".service")) {
2271 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Unit must be of type service, ignoring: %s", rvalue
);
2275 r
= manager_load_unit(UNIT(s
)->manager
, p
, NULL
, &error
, &x
);
2277 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to load unit %s, ignoring: %s", rvalue
, bus_error_message(&error
, r
));
2281 unit_ref_set(&s
->service
, UNIT(s
), x
);
2286 int config_parse_fdname(
2288 const char *filename
,
2290 const char *section
,
2291 unsigned section_line
,
2298 _cleanup_free_
char *p
= NULL
;
2299 Socket
*s
= ASSERT_PTR(data
);
2306 if (isempty(rvalue
)) {
2307 s
->fdname
= mfree(s
->fdname
);
2311 r
= unit_fd_printf(UNIT(s
), rvalue
, &p
);
2313 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2317 if (!fdname_is_valid(p
)) {
2318 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", p
);
2322 return free_and_replace(s
->fdname
, p
);
2325 int config_parse_service_sockets(
2327 const char *filename
,
2329 const char *section
,
2330 unsigned section_line
,
2337 Service
*s
= ASSERT_PTR(data
);
2344 for (const char *p
= rvalue
;;) {
2345 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2347 r
= extract_first_word(&p
, &word
, NULL
, 0);
2351 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Trailing garbage in sockets, ignoring: %s", rvalue
);
2357 r
= unit_name_printf(UNIT(s
), word
, &k
);
2359 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
2363 if (!endswith(k
, ".socket")) {
2364 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Unit must be of type socket, ignoring: %s", k
);
2368 r
= unit_add_two_dependencies_by_name(UNIT(s
), UNIT_WANTS
, UNIT_AFTER
, k
, true, UNIT_DEPENDENCY_FILE
);
2370 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
2372 r
= unit_add_dependency_by_name(UNIT(s
), UNIT_TRIGGERED_BY
, k
, true, UNIT_DEPENDENCY_FILE
);
2374 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
2378 int config_parse_bus_name(
2380 const char *filename
,
2382 const char *section
,
2383 unsigned section_line
,
2390 _cleanup_free_
char *k
= NULL
;
2391 const Unit
*u
= ASSERT_PTR(userdata
);
2398 r
= unit_full_printf_full(u
, rvalue
, SD_BUS_MAXIMUM_NAME_LENGTH
, &k
);
2400 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2404 if (!sd_bus_service_name_is_valid(k
)) {
2405 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid bus name, ignoring: %s", k
);
2409 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
2412 int config_parse_service_timeout(
2414 const char *filename
,
2416 const char *section
,
2417 unsigned section_line
,
2424 Service
*s
= ASSERT_PTR(userdata
);
2432 /* This is called for two cases: TimeoutSec= and TimeoutStartSec=. */
2434 /* Traditionally, these options accepted 0 to disable the timeouts. However, a timeout of 0 suggests it happens
2435 * immediately, hence fix this to become USEC_INFINITY instead. This is in-line with how we internally handle
2436 * all other timeouts. */
2437 r
= parse_sec_fix_0(rvalue
, &usec
);
2439 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
2443 s
->start_timeout_defined
= true;
2444 s
->timeout_start_usec
= usec
;
2446 if (streq(lvalue
, "TimeoutSec"))
2447 s
->timeout_stop_usec
= usec
;
2452 int config_parse_timeout_abort(
2454 const char *filename
,
2456 const char *section
,
2457 unsigned section_line
,
2464 usec_t
*ret
= ASSERT_PTR(data
);
2471 /* Note: apart from setting the arg, this returns an extra bit of information in the return value. */
2473 if (isempty(rvalue
)) {
2475 return 0; /* "not set" */
2478 r
= parse_sec(rvalue
, ret
);
2480 return log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= setting, ignoring: %s", lvalue
, rvalue
);
2482 return 1; /* "set" */
2485 int config_parse_service_timeout_abort(
2487 const char *filename
,
2489 const char *section
,
2490 unsigned section_line
,
2497 Service
*s
= ASSERT_PTR(userdata
);
2500 r
= config_parse_timeout_abort(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
,
2501 &s
->timeout_abort_usec
, s
);
2503 s
->timeout_abort_set
= r
;
2507 int config_parse_user_group_compat(
2509 const char *filename
,
2511 const char *section
,
2512 unsigned section_line
,
2519 _cleanup_free_
char *k
= NULL
;
2521 const Unit
*u
= ASSERT_PTR(userdata
);
2528 if (isempty(rvalue
)) {
2529 *user
= mfree(*user
);
2533 r
= unit_full_printf(u
, rvalue
, &k
);
2535 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", rvalue
);
2539 if (!valid_user_group_name(k
, VALID_USER_ALLOW_NUMERIC
|VALID_USER_RELAX
|VALID_USER_WARN
)) {
2540 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2544 if (strstr(lvalue
, "User") && streq(k
, NOBODY_USER_NAME
))
2545 log_struct(LOG_NOTICE
,
2546 "MESSAGE=%s:%u: Special user %s configured, this is not safe!", filename
, line
, k
,
2548 "MESSAGE_ID=" SD_MESSAGE_NOBODY_USER_UNSUITABLE_STR
,
2549 "OFFENDING_USER=%s", k
,
2550 "CONFIG_FILE=%s", filename
,
2551 "CONFIG_LINE=%u", line
);
2553 return free_and_replace(*user
, k
);
2556 int config_parse_user_group_strv_compat(
2558 const char *filename
,
2560 const char *section
,
2561 unsigned section_line
,
2568 char ***users
= data
;
2569 const Unit
*u
= ASSERT_PTR(userdata
);
2576 if (isempty(rvalue
)) {
2577 *users
= strv_free(*users
);
2581 for (const char *p
= rvalue
;;) {
2582 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2584 r
= extract_first_word(&p
, &word
, NULL
, 0);
2588 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax: %s", rvalue
);
2594 r
= unit_full_printf(u
, word
, &k
);
2596 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", word
);
2600 if (!valid_user_group_name(k
, VALID_USER_ALLOW_NUMERIC
|VALID_USER_RELAX
|VALID_USER_WARN
)) {
2601 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2605 r
= strv_push(users
, k
);
2613 int config_parse_working_directory(
2615 const char *filename
,
2617 const char *section
,
2618 unsigned section_line
,
2625 ExecContext
*c
= ASSERT_PTR(data
);
2626 const Unit
*u
= ASSERT_PTR(userdata
);
2634 if (isempty(rvalue
)) {
2635 c
->working_directory_home
= false;
2636 c
->working_directory
= mfree(c
->working_directory
);
2640 if (rvalue
[0] == '-') {
2646 if (streq(rvalue
, "~")) {
2647 c
->working_directory_home
= true;
2648 c
->working_directory
= mfree(c
->working_directory
);
2650 _cleanup_free_
char *k
= NULL
;
2652 r
= unit_path_printf(u
, rvalue
, &k
);
2654 log_syntax(unit
, missing_ok
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
2655 "Failed to resolve unit specifiers in working directory path '%s'%s: %m",
2656 rvalue
, missing_ok
? ", ignoring" : "");
2657 return missing_ok
? 0 : -ENOEXEC
;
2660 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
| (missing_ok
? 0 : PATH_CHECK_FATAL
), unit
, filename
, line
, lvalue
);
2662 return missing_ok
? 0 : -ENOEXEC
;
2664 c
->working_directory_home
= false;
2665 free_and_replace(c
->working_directory
, k
);
2668 c
->working_directory_missing_ok
= missing_ok
;
2672 int config_parse_unit_env_file(const char *unit
,
2673 const char *filename
,
2675 const char *section
,
2676 unsigned section_line
,
2683 char ***env
= ASSERT_PTR(data
);
2684 const Unit
*u
= userdata
;
2685 _cleanup_free_
char *n
= NULL
;
2692 if (isempty(rvalue
)) {
2693 /* Empty assignment frees the list */
2694 *env
= strv_free(*env
);
2698 r
= unit_full_printf_full(u
, rvalue
, PATH_MAX
, &n
);
2700 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2704 r
= path_simplify_and_warn(n
[0] == '-' ? n
+ 1 : n
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2708 r
= strv_push(env
, n
);
2717 int config_parse_environ(
2719 const char *filename
,
2721 const char *section
,
2722 unsigned section_line
,
2729 const Unit
*u
= userdata
;
2730 char ***env
= ASSERT_PTR(data
);
2737 if (isempty(rvalue
)) {
2738 /* Empty assignment resets the list */
2739 *env
= strv_free(*env
);
2743 for (const char *p
= rvalue
;; ) {
2744 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
2746 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2750 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2751 "Invalid syntax, ignoring: %s", rvalue
);
2758 r
= unit_env_printf(u
, word
, &resolved
);
2760 r
= specifier_printf(word
, sc_arg_max(), system_and_tmp_specifier_table
, NULL
, NULL
, &resolved
);
2762 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2763 "Failed to resolve specifiers in %s, ignoring: %m", word
);
2767 if (!env_assignment_is_valid(resolved
)) {
2768 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
2769 "Invalid environment assignment, ignoring: %s", resolved
);
2773 r
= strv_env_replace_consume(env
, TAKE_PTR(resolved
));
2775 return log_error_errno(r
, "Failed to update environment: %m");
2779 int config_parse_pass_environ(
2781 const char *filename
,
2783 const char *section
,
2784 unsigned section_line
,
2791 _cleanup_strv_free_
char **n
= NULL
;
2792 const Unit
*u
= userdata
;
2793 char*** passenv
= ASSERT_PTR(data
);
2801 if (isempty(rvalue
)) {
2802 /* Empty assignment resets the list */
2803 *passenv
= strv_free(*passenv
);
2807 for (const char *p
= rvalue
;;) {
2808 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2810 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
2814 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2815 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2822 r
= unit_env_printf(u
, word
, &k
);
2824 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2825 "Failed to resolve specifiers in %s, ignoring: %m", word
);
2831 if (!env_name_is_valid(k
)) {
2832 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
2833 "Invalid environment name for %s, ignoring: %s", lvalue
, k
);
2837 if (!GREEDY_REALLOC(n
, nlen
+ 2))
2840 n
[nlen
++] = TAKE_PTR(k
);
2845 r
= strv_extend_strv(passenv
, n
, true);
2853 int config_parse_unset_environ(
2855 const char *filename
,
2857 const char *section
,
2858 unsigned section_line
,
2865 _cleanup_strv_free_
char **n
= NULL
;
2866 char*** unsetenv
= ASSERT_PTR(data
);
2867 const Unit
*u
= userdata
;
2875 if (isempty(rvalue
)) {
2876 /* Empty assignment resets the list */
2877 *unsetenv
= strv_free(*unsetenv
);
2881 for (const char *p
= rvalue
;;) {
2882 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2884 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2888 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2889 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2896 r
= unit_env_printf(u
, word
, &k
);
2898 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2899 "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2905 if (!env_assignment_is_valid(k
) && !env_name_is_valid(k
)) {
2906 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
2907 "Invalid environment name or assignment %s, ignoring: %s", lvalue
, k
);
2911 if (!GREEDY_REALLOC(n
, nlen
+ 2))
2914 n
[nlen
++] = TAKE_PTR(k
);
2919 r
= strv_extend_strv(unsetenv
, n
, true);
2927 int config_parse_log_extra_fields(
2929 const char *filename
,
2931 const char *section
,
2932 unsigned section_line
,
2939 ExecContext
*c
= ASSERT_PTR(data
);
2940 const Unit
*u
= userdata
;
2947 if (isempty(rvalue
)) {
2948 exec_context_free_log_extra_fields(c
);
2952 for (const char *p
= rvalue
;;) {
2953 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2957 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2961 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
2967 r
= unit_full_printf(u
, word
, &k
);
2969 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2973 eq
= strchr(k
, '=');
2975 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Log field lacks '=' character, ignoring: %s", k
);
2979 if (!journal_field_valid(k
, eq
-k
, false)) {
2980 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Log field name is invalid, ignoring: %s", k
);
2984 t
= reallocarray(c
->log_extra_fields
, c
->n_log_extra_fields
+1, sizeof(struct iovec
));
2988 c
->log_extra_fields
= t
;
2989 c
->log_extra_fields
[c
->n_log_extra_fields
++] = IOVEC_MAKE_STRING(k
);
2995 int config_parse_log_namespace(
2997 const char *filename
,
2999 const char *section
,
3000 unsigned section_line
,
3007 _cleanup_free_
char *k
= NULL
;
3008 ExecContext
*c
= ASSERT_PTR(data
);
3009 const Unit
*u
= userdata
;
3016 if (isempty(rvalue
)) {
3017 c
->log_namespace
= mfree(c
->log_namespace
);
3021 r
= unit_full_printf_full(u
, rvalue
, NAME_MAX
, &k
);
3023 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
3027 if (!log_namespace_name_valid(k
)) {
3028 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Specified log namespace name is not valid, ignoring: %s", k
);
3032 free_and_replace(c
->log_namespace
, k
);
3036 int config_parse_unit_condition_path(
3038 const char *filename
,
3040 const char *section
,
3041 unsigned section_line
,
3048 _cleanup_free_
char *p
= NULL
;
3049 Condition
**list
= ASSERT_PTR(data
), *c
;
3050 ConditionType t
= ltype
;
3051 bool trigger
, negate
;
3052 const Unit
*u
= userdata
;
3059 if (isempty(rvalue
)) {
3060 /* Empty assignment resets the list */
3061 *list
= condition_free_list(*list
);
3065 trigger
= rvalue
[0] == '|';
3069 negate
= rvalue
[0] == '!';
3073 r
= unit_path_printf(u
, rvalue
, &p
);
3075 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
3079 r
= path_simplify_and_warn(p
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
3083 c
= condition_new(t
, p
, trigger
, negate
);
3087 LIST_PREPEND(conditions
, *list
, c
);
3091 int config_parse_unit_condition_string(
3093 const char *filename
,
3095 const char *section
,
3096 unsigned section_line
,
3103 _cleanup_free_
char *s
= NULL
;
3104 Condition
**list
= ASSERT_PTR(data
), *c
;
3105 ConditionType t
= ltype
;
3106 bool trigger
, negate
;
3107 const Unit
*u
= userdata
;
3114 if (isempty(rvalue
)) {
3115 /* Empty assignment resets the list */
3116 *list
= condition_free_list(*list
);
3120 trigger
= *rvalue
== '|';
3122 rvalue
+= 1 + strspn(rvalue
+ 1, WHITESPACE
);
3124 negate
= *rvalue
== '!';
3126 rvalue
+= 1 + strspn(rvalue
+ 1, WHITESPACE
);
3128 r
= unit_full_printf(u
, rvalue
, &s
);
3130 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3131 "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
3135 c
= condition_new(t
, s
, trigger
, negate
);
3139 LIST_PREPEND(conditions
, *list
, c
);
3143 int config_parse_unit_requires_mounts_for(
3145 const char *filename
,
3147 const char *section
,
3148 unsigned section_line
,
3163 for (const char *p
= rvalue
;;) {
3164 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
3166 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3170 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3171 "Invalid syntax, ignoring: %s", rvalue
);
3177 r
= unit_path_printf(u
, word
, &resolved
);
3179 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
3183 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
3187 r
= unit_require_mounts_for(u
, resolved
, UNIT_DEPENDENCY_FILE
);
3189 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add required mount '%s', ignoring: %m", resolved
);
3195 int config_parse_documentation(
3197 const char *filename
,
3199 const char *section
,
3200 unsigned section_line
,
3207 Unit
*u
= ASSERT_PTR(userdata
);
3215 if (isempty(rvalue
)) {
3216 /* Empty assignment resets the list */
3217 u
->documentation
= strv_free(u
->documentation
);
3221 r
= config_parse_unit_strv_printf(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
,
3222 rvalue
, data
, userdata
);
3226 for (a
= b
= u
->documentation
; a
&& *a
; a
++) {
3228 if (documentation_url_is_valid(*a
))
3231 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid URL, ignoring: %s", *a
);
3242 int config_parse_syscall_filter(
3244 const char *filename
,
3246 const char *section
,
3247 unsigned section_line
,
3254 ExecContext
*c
= data
;
3255 _unused_
const Unit
*u
= ASSERT_PTR(userdata
);
3256 bool invert
= false;
3263 if (isempty(rvalue
)) {
3264 /* Empty assignment resets the list */
3265 c
->syscall_filter
= hashmap_free(c
->syscall_filter
);
3266 c
->syscall_allow_list
= false;
3270 if (rvalue
[0] == '~') {
3275 if (!c
->syscall_filter
) {
3276 c
->syscall_filter
= hashmap_new(NULL
);
3277 if (!c
->syscall_filter
)
3281 /* Allow everything but the ones listed */
3282 c
->syscall_allow_list
= false;
3284 /* Allow nothing but the ones listed */
3285 c
->syscall_allow_list
= true;
3287 /* Accept default syscalls if we are on an allow_list */
3288 r
= seccomp_parse_syscall_filter(
3289 "@default", -1, c
->syscall_filter
,
3290 SECCOMP_PARSE_PERMISSIVE
|SECCOMP_PARSE_ALLOW_LIST
,
3298 for (const char *p
= rvalue
;;) {
3299 _cleanup_free_
char *word
= NULL
, *name
= NULL
;
3302 r
= extract_first_word(&p
, &word
, NULL
, 0);
3306 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3307 "Invalid syntax, ignoring: %s", rvalue
);
3313 r
= parse_syscall_and_errno(word
, &name
, &num
);
3315 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3316 "Failed to parse syscall:errno, ignoring: %s", word
);
3319 if (!invert
&& num
>= 0) {
3320 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3321 "Allow-listed system calls cannot take error number, ignoring: %s", word
);
3325 r
= seccomp_parse_syscall_filter(
3326 name
, num
, c
->syscall_filter
,
3327 SECCOMP_PARSE_LOG
|SECCOMP_PARSE_PERMISSIVE
|
3328 (invert
? SECCOMP_PARSE_INVERT
: 0)|
3329 (c
->syscall_allow_list
? SECCOMP_PARSE_ALLOW_LIST
: 0),
3330 unit
, filename
, line
);
3336 int config_parse_syscall_log(
3338 const char *filename
,
3340 const char *section
,
3341 unsigned section_line
,
3348 ExecContext
*c
= data
;
3349 _unused_
const Unit
*u
= ASSERT_PTR(userdata
);
3350 bool invert
= false;
3358 if (isempty(rvalue
)) {
3359 /* Empty assignment resets the list */
3360 c
->syscall_log
= hashmap_free(c
->syscall_log
);
3361 c
->syscall_log_allow_list
= false;
3365 if (rvalue
[0] == '~') {
3370 if (!c
->syscall_log
) {
3371 c
->syscall_log
= hashmap_new(NULL
);
3372 if (!c
->syscall_log
)
3376 /* Log everything but the ones listed */
3377 c
->syscall_log_allow_list
= false;
3379 /* Log nothing but the ones listed */
3380 c
->syscall_log_allow_list
= true;
3385 _cleanup_free_
char *word
= NULL
;
3387 r
= extract_first_word(&p
, &word
, NULL
, 0);
3391 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3397 r
= seccomp_parse_syscall_filter(
3398 word
, -1, c
->syscall_log
,
3399 SECCOMP_PARSE_LOG
|SECCOMP_PARSE_PERMISSIVE
|
3400 (invert
? SECCOMP_PARSE_INVERT
: 0)|
3401 (c
->syscall_log_allow_list
? SECCOMP_PARSE_ALLOW_LIST
: 0),
3402 unit
, filename
, line
);
3408 int config_parse_syscall_archs(
3410 const char *filename
,
3412 const char *section
,
3413 unsigned section_line
,
3423 if (isempty(rvalue
)) {
3424 *archs
= set_free(*archs
);
3428 for (const char *p
= rvalue
;;) {
3429 _cleanup_free_
char *word
= NULL
;
3432 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3436 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3437 "Invalid syntax, ignoring: %s", rvalue
);
3443 r
= seccomp_arch_from_string(word
, &a
);
3445 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3446 "Failed to parse system call architecture \"%s\", ignoring: %m", word
);
3450 r
= set_ensure_put(archs
, NULL
, UINT32_TO_PTR(a
+ 1));
3456 int config_parse_syscall_errno(
3458 const char *filename
,
3460 const char *section
,
3461 unsigned section_line
,
3468 ExecContext
*c
= data
;
3475 if (isempty(rvalue
) || streq(rvalue
, "kill")) {
3476 /* Empty assignment resets to KILL */
3477 c
->syscall_errno
= SECCOMP_ERROR_NUMBER_KILL
;
3481 e
= parse_errno(rvalue
);
3483 log_syntax(unit
, LOG_WARNING
, filename
, line
, e
, "Failed to parse error number, ignoring: %s", rvalue
);
3487 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid error number, ignoring: %s", rvalue
);
3491 c
->syscall_errno
= e
;
3495 int config_parse_address_families(
3497 const char *filename
,
3499 const char *section
,
3500 unsigned section_line
,
3507 ExecContext
*c
= data
;
3508 bool invert
= false;
3515 if (isempty(rvalue
)) {
3516 /* Empty assignment resets the list */
3517 c
->address_families
= set_free(c
->address_families
);
3518 c
->address_families_allow_list
= false;
3522 if (streq(rvalue
, "none")) {
3523 /* Forbid all address families. */
3524 c
->address_families
= set_free(c
->address_families
);
3525 c
->address_families_allow_list
= true;
3529 if (rvalue
[0] == '~') {
3534 if (!c
->address_families
) {
3535 c
->address_families
= set_new(NULL
);
3536 if (!c
->address_families
)
3539 c
->address_families_allow_list
= !invert
;
3542 for (const char *p
= rvalue
;;) {
3543 _cleanup_free_
char *word
= NULL
;
3546 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3550 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3551 "Invalid syntax, ignoring: %s", rvalue
);
3557 af
= af_from_name(word
);
3559 log_syntax(unit
, LOG_WARNING
, filename
, line
, af
,
3560 "Failed to parse address family, ignoring: %s", word
);
3564 /* If we previously wanted to forbid an address family and now
3565 * we want to allow it, then just remove it from the list.
3567 if (!invert
== c
->address_families_allow_list
) {
3568 r
= set_put(c
->address_families
, INT_TO_PTR(af
));
3572 set_remove(c
->address_families
, INT_TO_PTR(af
));
3576 int config_parse_restrict_namespaces(
3578 const char *filename
,
3580 const char *section
,
3581 unsigned section_line
,
3588 ExecContext
*c
= data
;
3589 unsigned long flags
;
3590 bool invert
= false;
3593 if (isempty(rvalue
)) {
3594 /* Reset to the default. */
3595 c
->restrict_namespaces
= NAMESPACE_FLAGS_INITIAL
;
3599 /* Boolean parameter ignores the previous settings */
3600 r
= parse_boolean(rvalue
);
3602 c
->restrict_namespaces
= 0;
3604 } else if (r
== 0) {
3605 c
->restrict_namespaces
= NAMESPACE_FLAGS_ALL
;
3609 if (rvalue
[0] == '~') {
3614 /* Not a boolean argument, in this case it's a list of namespace types. */
3615 r
= namespace_flags_from_string(rvalue
, &flags
);
3617 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse namespace type string, ignoring: %s", rvalue
);
3621 if (c
->restrict_namespaces
== NAMESPACE_FLAGS_INITIAL
)
3622 /* Initial assignment. Just set the value. */
3623 c
->restrict_namespaces
= invert
? (~flags
) & NAMESPACE_FLAGS_ALL
: flags
;
3625 /* Merge the value with the previous one. */
3626 SET_FLAG(c
->restrict_namespaces
, flags
, !invert
);
3632 int config_parse_restrict_filesystems(
3634 const char *filename
,
3636 const char *section
,
3637 unsigned section_line
,
3643 ExecContext
*c
= ASSERT_PTR(data
);
3644 bool invert
= false;
3651 if (isempty(rvalue
)) {
3652 /* Empty assignment resets the list */
3653 c
->restrict_filesystems
= set_free(c
->restrict_filesystems
);
3654 c
->restrict_filesystems_allow_list
= false;
3658 if (rvalue
[0] == '~') {
3663 if (!c
->restrict_filesystems
) {
3665 /* Allow everything but the ones listed */
3666 c
->restrict_filesystems_allow_list
= false;
3668 /* Allow nothing but the ones listed */
3669 c
->restrict_filesystems_allow_list
= true;
3672 for (const char *p
= rvalue
;;) {
3673 _cleanup_free_
char *word
= NULL
;
3675 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3681 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3682 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
3686 r
= lsm_bpf_parse_filesystem(
3688 &c
->restrict_filesystems
,
3689 FILESYSTEM_PARSE_LOG
|
3690 (invert
? FILESYSTEM_PARSE_INVERT
: 0)|
3691 (c
->restrict_filesystems_allow_list
? FILESYSTEM_PARSE_ALLOW_LIST
: 0),
3692 unit
, filename
, line
);
3701 int config_parse_unit_slice(
3703 const char *filename
,
3705 const char *section
,
3706 unsigned section_line
,
3713 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
3714 _cleanup_free_
char *k
= NULL
;
3715 Unit
*u
= userdata
, *slice
;
3723 r
= unit_name_printf(u
, rvalue
, &k
);
3725 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
3729 r
= manager_load_unit(u
->manager
, k
, NULL
, &error
, &slice
);
3731 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to load slice unit %s, ignoring: %s", k
, bus_error_message(&error
, r
));
3735 r
= unit_set_slice(u
, slice
);
3737 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to assign slice %s to unit %s, ignoring: %m", slice
->id
, u
->id
);
3744 int config_parse_cpu_quota(
3746 const char *filename
,
3748 const char *section
,
3749 unsigned section_line
,
3756 CGroupContext
*c
= data
;
3763 if (isempty(rvalue
)) {
3764 c
->cpu_quota_per_sec_usec
= USEC_INFINITY
;
3768 r
= parse_permyriad_unbounded(rvalue
);
3770 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid CPU quota '%s', ignoring.", rvalue
);
3774 c
->cpu_quota_per_sec_usec
= ((usec_t
) r
* USEC_PER_SEC
) / 10000U;
3778 int config_parse_allowed_cpuset(
3780 const char *filename
,
3782 const char *section
,
3783 unsigned section_line
,
3792 (void) parse_cpu_set_extend(rvalue
, c
, true, unit
, filename
, line
, lvalue
);
3796 int config_parse_memory_limit(
3798 const char *filename
,
3800 const char *section
,
3801 unsigned section_line
,
3808 CGroupContext
*c
= data
;
3809 uint64_t bytes
= CGROUP_LIMIT_MAX
;
3812 if (isempty(rvalue
) && STR_IN_SET(lvalue
, "DefaultMemoryLow",
3816 bytes
= CGROUP_LIMIT_MIN
;
3817 else if (!isempty(rvalue
) && !streq(rvalue
, "infinity")) {
3819 r
= parse_permyriad(rvalue
);
3821 r
= parse_size(rvalue
, 1024, &bytes
);
3823 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid memory limit '%s', ignoring: %m", rvalue
);
3827 bytes
= physical_memory_scale(r
, 10000U);
3829 if (bytes
>= UINT64_MAX
||
3830 (bytes
<= 0 && !STR_IN_SET(lvalue
, "MemorySwapMax", "MemoryZSwapMax", "MemoryLow", "MemoryMin", "DefaultMemoryLow", "DefaultMemoryMin"))) {
3831 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Memory limit '%s' out of range, ignoring.", rvalue
);
3836 if (streq(lvalue
, "DefaultMemoryLow")) {
3837 c
->default_memory_low
= bytes
;
3838 c
->default_memory_low_set
= true;
3839 } else if (streq(lvalue
, "DefaultMemoryMin")) {
3840 c
->default_memory_min
= bytes
;
3841 c
->default_memory_min_set
= true;
3842 } else if (streq(lvalue
, "MemoryMin")) {
3843 c
->memory_min
= bytes
;
3844 c
->memory_min_set
= true;
3845 } else if (streq(lvalue
, "MemoryLow")) {
3846 c
->memory_low
= bytes
;
3847 c
->memory_low_set
= true;
3848 } else if (streq(lvalue
, "MemoryHigh"))
3849 c
->memory_high
= bytes
;
3850 else if (streq(lvalue
, "MemoryMax"))
3851 c
->memory_max
= bytes
;
3852 else if (streq(lvalue
, "MemorySwapMax"))
3853 c
->memory_swap_max
= bytes
;
3854 else if (streq(lvalue
, "MemoryZSwapMax"))
3855 c
->memory_zswap_max
= bytes
;
3856 else if (streq(lvalue
, "MemoryLimit")) {
3857 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3858 "Unit uses MemoryLimit=; please use MemoryMax= instead. Support for MemoryLimit= will be removed soon.");
3859 c
->memory_limit
= bytes
;
3866 int config_parse_tasks_max(
3868 const char *filename
,
3870 const char *section
,
3871 unsigned section_line
,
3878 const Unit
*u
= userdata
;
3879 TasksMax
*tasks_max
= data
;
3883 if (isempty(rvalue
)) {
3884 *tasks_max
= u
? u
->manager
->default_tasks_max
: TASKS_MAX_UNSET
;
3888 if (streq(rvalue
, "infinity")) {
3889 *tasks_max
= TASKS_MAX_UNSET
;
3893 r
= parse_permyriad(rvalue
);
3895 *tasks_max
= (TasksMax
) { r
, 10000U }; /* r‱ */
3897 r
= safe_atou64(rvalue
, &v
);
3899 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid maximum tasks value '%s', ignoring: %m", rvalue
);
3903 if (v
<= 0 || v
>= UINT64_MAX
) {
3904 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Maximum tasks value '%s' out of range, ignoring.", rvalue
);
3908 *tasks_max
= (TasksMax
) { v
};
3914 int config_parse_delegate(
3916 const char *filename
,
3918 const char *section
,
3919 unsigned section_line
,
3926 CGroupContext
*c
= data
;
3930 t
= unit_name_to_type(unit
);
3931 assert(t
!= _UNIT_TYPE_INVALID
);
3933 if (!unit_vtable
[t
]->can_delegate
) {
3934 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Delegate= setting not supported for this unit type, ignoring.");
3938 /* We either accept a boolean value, which may be used to turn on delegation for all controllers, or turn it
3939 * off for all. Or it takes a list of controller names, in which case we add the specified controllers to the
3940 * mask to delegate. */
3942 if (isempty(rvalue
)) {
3943 /* An empty string resets controllers and set Delegate=yes. */
3945 c
->delegate_controllers
= 0;
3949 r
= parse_boolean(rvalue
);
3951 CGroupMask mask
= 0;
3953 for (const char *p
= rvalue
;;) {
3954 _cleanup_free_
char *word
= NULL
;
3955 CGroupController cc
;
3957 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3961 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3967 cc
= cgroup_controller_from_string(word
);
3969 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid controller name '%s', ignoring", word
);
3973 mask
|= CGROUP_CONTROLLER_TO_MASK(cc
);
3977 c
->delegate_controllers
|= mask
;
3981 c
->delegate_controllers
= _CGROUP_MASK_ALL
;
3983 c
->delegate
= false;
3984 c
->delegate_controllers
= 0;
3990 int config_parse_managed_oom_mode(
3992 const char *filename
,
3994 const char *section
,
3995 unsigned section_line
,
4002 ManagedOOMMode
*mode
= data
, m
;
4005 t
= unit_name_to_type(unit
);
4006 assert(t
!= _UNIT_TYPE_INVALID
);
4008 if (!unit_vtable
[t
]->can_set_managed_oom
)
4009 return log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "%s= is not supported for this unit type, ignoring.", lvalue
);
4011 if (isempty(rvalue
)) {
4012 *mode
= MANAGED_OOM_AUTO
;
4016 m
= managed_oom_mode_from_string(rvalue
);
4018 log_syntax(unit
, LOG_WARNING
, filename
, line
, m
, "Invalid syntax, ignoring: %s", rvalue
);
4026 int config_parse_managed_oom_mem_pressure_limit(
4028 const char *filename
,
4030 const char *section
,
4031 unsigned section_line
,
4038 uint32_t *limit
= data
;
4042 t
= unit_name_to_type(unit
);
4043 assert(t
!= _UNIT_TYPE_INVALID
);
4045 if (!unit_vtable
[t
]->can_set_managed_oom
)
4046 return log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "%s= is not supported for this unit type, ignoring.", lvalue
);
4048 if (isempty(rvalue
)) {
4053 r
= parse_permyriad(rvalue
);
4055 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse memory pressure limit value, ignoring: %s", rvalue
);
4059 /* Normalize to 2^32-1 == 100% */
4060 *limit
= UINT32_SCALE_FROM_PERMYRIAD(r
);
4064 int config_parse_device_allow(
4066 const char *filename
,
4068 const char *section
,
4069 unsigned section_line
,
4076 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4077 CGroupContext
*c
= data
;
4078 const char *p
= rvalue
;
4081 if (isempty(rvalue
)) {
4082 while (c
->device_allow
)
4083 cgroup_context_free_device_allow(c
, c
->device_allow
);
4088 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4092 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4093 "Failed to extract device path and rights from '%s', ignoring.", rvalue
);
4097 r
= unit_path_printf(userdata
, path
, &resolved
);
4099 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4100 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4104 if (!STARTSWITH_SET(resolved
, "block-", "char-")) {
4106 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4110 if (!valid_device_node_path(resolved
)) {
4111 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid device node path '%s', ignoring.", resolved
);
4116 if (!isempty(p
) && !in_charset(p
, "rwm")) {
4117 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid device rights '%s', ignoring.", p
);
4121 return cgroup_add_device_allow(c
, resolved
, p
);
4124 int config_parse_io_device_weight(
4126 const char *filename
,
4128 const char *section
,
4129 unsigned section_line
,
4136 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4137 CGroupIODeviceWeight
*w
;
4138 CGroupContext
*c
= data
;
4139 const char *p
= ASSERT_PTR(rvalue
);
4146 if (isempty(rvalue
)) {
4147 while (c
->io_device_weights
)
4148 cgroup_context_free_io_device_weight(c
, c
->io_device_weights
);
4153 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4157 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4158 "Failed to extract device path and weight from '%s', ignoring.", rvalue
);
4161 if (r
== 0 || isempty(p
)) {
4162 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4163 "Invalid device path or weight specified in '%s', ignoring.", rvalue
);
4167 r
= unit_path_printf(userdata
, path
, &resolved
);
4169 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4170 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4174 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4178 r
= cg_weight_parse(p
, &u
);
4180 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "IO weight '%s' invalid, ignoring: %m", p
);
4184 assert(u
!= CGROUP_WEIGHT_INVALID
);
4186 w
= new0(CGroupIODeviceWeight
, 1);
4190 w
->path
= TAKE_PTR(resolved
);
4193 LIST_PREPEND(device_weights
, c
->io_device_weights
, w
);
4197 int config_parse_io_device_latency(
4199 const char *filename
,
4201 const char *section
,
4202 unsigned section_line
,
4209 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4210 CGroupIODeviceLatency
*l
;
4211 CGroupContext
*c
= data
;
4212 const char *p
= ASSERT_PTR(rvalue
);
4219 if (isempty(rvalue
)) {
4220 while (c
->io_device_latencies
)
4221 cgroup_context_free_io_device_latency(c
, c
->io_device_latencies
);
4226 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4230 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4231 "Failed to extract device path and latency from '%s', ignoring.", rvalue
);
4234 if (r
== 0 || isempty(p
)) {
4235 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4236 "Invalid device path or latency specified in '%s', ignoring.", rvalue
);
4240 r
= unit_path_printf(userdata
, path
, &resolved
);
4242 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4243 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4247 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4251 r
= parse_sec(p
, &usec
);
4253 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse timer value, ignoring: %s", p
);
4257 l
= new0(CGroupIODeviceLatency
, 1);
4261 l
->path
= TAKE_PTR(resolved
);
4262 l
->target_usec
= usec
;
4264 LIST_PREPEND(device_latencies
, c
->io_device_latencies
, l
);
4268 int config_parse_io_limit(
4270 const char *filename
,
4272 const char *section
,
4273 unsigned section_line
,
4280 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4281 CGroupIODeviceLimit
*l
= NULL
;
4282 CGroupContext
*c
= data
;
4283 CGroupIOLimitType type
;
4284 const char *p
= ASSERT_PTR(rvalue
);
4291 type
= cgroup_io_limit_type_from_string(lvalue
);
4294 if (isempty(rvalue
)) {
4295 LIST_FOREACH(device_limits
, t
, c
->io_device_limits
)
4296 t
->limits
[type
] = cgroup_io_limit_defaults
[type
];
4300 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4304 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4305 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
4308 if (r
== 0 || isempty(p
)) {
4309 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4310 "Invalid device node or bandwidth specified in '%s', ignoring.", rvalue
);
4314 r
= unit_path_printf(userdata
, path
, &resolved
);
4316 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4317 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4321 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4325 if (streq("infinity", p
))
4326 num
= CGROUP_LIMIT_MAX
;
4328 r
= parse_size(p
, 1000, &num
);
4329 if (r
< 0 || num
<= 0) {
4330 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid IO limit '%s', ignoring.", p
);
4335 LIST_FOREACH(device_limits
, t
, c
->io_device_limits
)
4336 if (path_equal(resolved
, t
->path
)) {
4342 CGroupIOLimitType ttype
;
4344 l
= new0(CGroupIODeviceLimit
, 1);
4348 l
->path
= TAKE_PTR(resolved
);
4349 for (ttype
= 0; ttype
< _CGROUP_IO_LIMIT_TYPE_MAX
; ttype
++)
4350 l
->limits
[ttype
] = cgroup_io_limit_defaults
[ttype
];
4352 LIST_PREPEND(device_limits
, c
->io_device_limits
, l
);
4355 l
->limits
[type
] = num
;
4360 int config_parse_blockio_device_weight(
4362 const char *filename
,
4364 const char *section
,
4365 unsigned section_line
,
4372 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4373 CGroupBlockIODeviceWeight
*w
;
4374 CGroupContext
*c
= data
;
4375 const char *p
= ASSERT_PTR(rvalue
);
4382 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4383 "Unit uses %s=; please use IO*= settings instead. Support for %s= will be removed soon.",
4386 if (isempty(rvalue
)) {
4387 while (c
->blockio_device_weights
)
4388 cgroup_context_free_blockio_device_weight(c
, c
->blockio_device_weights
);
4393 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4397 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4398 "Failed to extract device node and weight from '%s', ignoring.", rvalue
);
4401 if (r
== 0 || isempty(p
)) {
4402 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4403 "Invalid device node or weight specified in '%s', ignoring.", rvalue
);
4407 r
= unit_path_printf(userdata
, path
, &resolved
);
4409 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4410 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4414 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4418 r
= cg_blkio_weight_parse(p
, &u
);
4420 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid block IO weight '%s', ignoring: %m", p
);
4424 assert(u
!= CGROUP_BLKIO_WEIGHT_INVALID
);
4426 w
= new0(CGroupBlockIODeviceWeight
, 1);
4430 w
->path
= TAKE_PTR(resolved
);
4433 LIST_PREPEND(device_weights
, c
->blockio_device_weights
, w
);
4437 int config_parse_blockio_bandwidth(
4439 const char *filename
,
4441 const char *section
,
4442 unsigned section_line
,
4449 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4450 CGroupBlockIODeviceBandwidth
*b
= NULL
;
4451 CGroupContext
*c
= data
;
4452 const char *p
= ASSERT_PTR(rvalue
);
4460 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4461 "Unit uses %s=; please use IO*= settings instead. Support for %s= will be removed soon.",
4464 read
= streq("BlockIOReadBandwidth", lvalue
);
4466 if (isempty(rvalue
)) {
4467 LIST_FOREACH(device_bandwidths
, t
, c
->blockio_device_bandwidths
) {
4468 t
->rbps
= CGROUP_LIMIT_MAX
;
4469 t
->wbps
= CGROUP_LIMIT_MAX
;
4474 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4478 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4479 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
4482 if (r
== 0 || isempty(p
)) {
4483 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4484 "Invalid device node or bandwidth specified in '%s', ignoring.", rvalue
);
4488 r
= unit_path_printf(userdata
, path
, &resolved
);
4490 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4491 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4495 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4499 r
= parse_size(p
, 1000, &bytes
);
4500 if (r
< 0 || bytes
<= 0) {
4501 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid Block IO Bandwidth '%s', ignoring.", p
);
4505 LIST_FOREACH(device_bandwidths
, t
, c
->blockio_device_bandwidths
)
4506 if (path_equal(resolved
, t
->path
)) {
4512 b
= new0(CGroupBlockIODeviceBandwidth
, 1);
4516 b
->path
= TAKE_PTR(resolved
);
4517 b
->rbps
= CGROUP_LIMIT_MAX
;
4518 b
->wbps
= CGROUP_LIMIT_MAX
;
4520 LIST_PREPEND(device_bandwidths
, c
->blockio_device_bandwidths
, b
);
4531 int config_parse_job_mode_isolate(
4533 const char *filename
,
4535 const char *section
,
4536 unsigned section_line
,
4550 r
= parse_boolean(rvalue
);
4552 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse boolean, ignoring: %s", rvalue
);
4556 log_notice("%s is deprecated. Please use OnFailureJobMode= instead", lvalue
);
4558 *m
= r
? JOB_ISOLATE
: JOB_REPLACE
;
4562 int config_parse_exec_directories(
4564 const char *filename
,
4566 const char *section
,
4567 unsigned section_line
,
4574 ExecDirectory
*ed
= ASSERT_PTR(data
);
4575 const Unit
*u
= userdata
;
4582 if (isempty(rvalue
)) {
4583 /* Empty assignment resets the list */
4584 exec_directory_done(ed
);
4588 for (const char *p
= rvalue
;;) {
4589 _cleanup_free_
char *tuple
= NULL
;
4591 r
= extract_first_word(&p
, &tuple
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_RETAIN_ESCAPE
);
4595 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4596 "Invalid syntax %s=%s, ignoring: %m", lvalue
, rvalue
);
4602 _cleanup_free_
char *src
= NULL
, *dest
= NULL
;
4603 const char *q
= tuple
;
4604 r
= extract_many_words(&q
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
, &src
, &dest
, NULL
);
4608 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
?: SYNTHETIC_ERRNO(EINVAL
),
4609 "Invalid syntax in %s=, ignoring: %s", lvalue
, tuple
);
4613 _cleanup_free_
char *sresolved
= NULL
;
4614 r
= unit_path_printf(u
, src
, &sresolved
);
4616 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4617 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", src
);
4621 r
= path_simplify_and_warn(sresolved
, PATH_CHECK_RELATIVE
, unit
, filename
, line
, lvalue
);
4625 if (path_startswith(sresolved
, "private")) {
4626 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4627 "%s= path can't be 'private', ignoring assignment: %s", lvalue
, tuple
);
4631 /* For State and Runtime directories we support an optional destination parameter, which
4632 * will be used to create a symlink to the source. */
4633 _cleanup_free_
char *dresolved
= NULL
;
4634 if (!isempty(dest
)) {
4635 if (streq(lvalue
, "ConfigurationDirectory")) {
4636 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4637 "Destination parameter is not supported for ConfigurationDirectory, ignoring: %s", tuple
);
4641 r
= unit_path_printf(u
, dest
, &dresolved
);
4643 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4644 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", dest
);
4648 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_RELATIVE
, unit
, filename
, line
, lvalue
);
4653 r
= exec_directory_add(ed
, sresolved
, dresolved
);
4659 int config_parse_set_credential(
4661 const char *filename
,
4663 const char *section
,
4664 unsigned section_line
,
4671 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
4672 _cleanup_free_
void *d
= NULL
;
4673 ExecContext
*context
= ASSERT_PTR(data
);
4674 ExecSetCredential
*old
;
4676 bool encrypted
= ltype
;
4677 const char *p
= ASSERT_PTR(rvalue
);
4684 if (isempty(rvalue
)) {
4685 /* Empty assignment resets the list */
4686 context
->set_credentials
= hashmap_free(context
->set_credentials
);
4690 r
= extract_first_word(&p
, &word
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4694 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract credential name, ignoring: %s", rvalue
);
4697 if (r
== 0 || isempty(p
)) {
4698 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid syntax, ignoring: %s", rvalue
);
4702 r
= unit_cred_printf(u
, word
, &k
);
4704 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
4707 if (!credential_name_valid(k
)) {
4708 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Credential name \"%s\" not valid, ignoring.", k
);
4713 r
= unbase64mem_full(p
, SIZE_MAX
, true, &d
, &size
);
4715 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Encrypted credential data not valid Base64 data, ignoring.");
4722 /* We support escape codes here, so that users can insert trailing \n if they like */
4723 l
= cunescape(p
, UNESCAPE_ACCEPT_NUL
, &unescaped
);
4725 log_syntax(unit
, LOG_WARNING
, filename
, line
, l
, "Can't unescape \"%s\", ignoring: %m", p
);
4733 old
= hashmap_get(context
->set_credentials
, k
);
4735 free_and_replace(old
->data
, d
);
4737 old
->encrypted
= encrypted
;
4739 _cleanup_(exec_set_credential_freep
) ExecSetCredential
*sc
= NULL
;
4741 sc
= new(ExecSetCredential
, 1);
4745 *sc
= (ExecSetCredential
) {
4747 .data
= TAKE_PTR(d
),
4749 .encrypted
= encrypted
,
4752 r
= hashmap_ensure_put(&context
->set_credentials
, &exec_set_credential_hash_ops
, sc
->id
, sc
);
4756 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4757 "Duplicated credential value '%s', ignoring assignment: %s", sc
->id
, rvalue
);
4767 int config_parse_load_credential(
4769 const char *filename
,
4771 const char *section
,
4772 unsigned section_line
,
4779 _cleanup_free_
char *word
= NULL
, *k
= NULL
, *q
= NULL
;
4780 ExecContext
*context
= ASSERT_PTR(data
);
4781 ExecLoadCredential
*old
;
4782 bool encrypted
= ltype
;
4791 if (isempty(rvalue
)) {
4792 /* Empty assignment resets the list */
4793 context
->load_credentials
= hashmap_free(context
->load_credentials
);
4798 r
= extract_first_word(&p
, &word
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4802 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
4806 r
= unit_cred_printf(u
, word
, &k
);
4808 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
4811 if (!credential_name_valid(k
)) {
4812 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Credential name \"%s\" not valid, ignoring.", k
);
4817 /* If only one field is specified take it as shortcut for inheriting a credential named
4818 * the same way from our parent */
4823 r
= unit_path_printf(u
, p
, &q
);
4825 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", p
);
4828 if (path_is_absolute(q
) ? !path_is_normalized(q
) : !credential_name_valid(q
)) {
4829 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Credential source \"%s\" not valid, ignoring.", q
);
4834 old
= hashmap_get(context
->load_credentials
, k
);
4836 free_and_replace(old
->path
, q
);
4837 old
->encrypted
= encrypted
;
4839 _cleanup_(exec_load_credential_freep
) ExecLoadCredential
*lc
= NULL
;
4841 lc
= new(ExecLoadCredential
, 1);
4845 *lc
= (ExecLoadCredential
) {
4847 .path
= TAKE_PTR(q
),
4848 .encrypted
= encrypted
,
4851 r
= hashmap_ensure_put(&context
->load_credentials
, &exec_load_credential_hash_ops
, lc
->id
, lc
);
4855 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4856 "Duplicated credential value '%s', ignoring assignment: %s", lc
->id
, rvalue
);
4866 int config_parse_set_status(
4868 const char *filename
,
4870 const char *section
,
4871 unsigned section_line
,
4878 ExitStatusSet
*status_set
= ASSERT_PTR(data
);
4885 /* Empty assignment resets the list */
4886 if (isempty(rvalue
)) {
4887 exit_status_set_free(status_set
);
4891 for (const char *p
= rvalue
;;) {
4892 _cleanup_free_
char *word
= NULL
;
4895 r
= extract_first_word(&p
, &word
, NULL
, 0);
4899 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4900 "Failed to parse %s=%s, ignoring: %m", lvalue
, rvalue
);
4906 /* We need to call exit_status_from_string() first, because we want
4907 * to parse numbers as exit statuses, not signals. */
4909 r
= exit_status_from_string(word
);
4911 assert(r
>= 0 && r
< 256);
4912 bitmap
= &status_set
->status
;
4914 r
= signal_from_string(word
);
4916 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4917 "Failed to parse value, ignoring: %s", word
);
4920 bitmap
= &status_set
->signal
;
4923 r
= bitmap_set(bitmap
, r
);
4925 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4926 "Failed to set signal or status %s, ignoring: %m", word
);
4930 int config_parse_namespace_path_strv(
4932 const char *filename
,
4934 const char *section
,
4935 unsigned section_line
,
4942 const Unit
*u
= userdata
;
4943 char*** sv
= ASSERT_PTR(data
);
4950 if (isempty(rvalue
)) {
4951 /* Empty assignment resets the list */
4952 *sv
= strv_free(*sv
);
4956 for (const char *p
= rvalue
;;) {
4957 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
, *joined
= NULL
;
4959 bool ignore_enoent
= false, shall_prefix
= false;
4961 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
4965 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
4972 if (startswith(w
, "-")) {
4973 ignore_enoent
= true;
4976 if (startswith(w
, "+")) {
4977 shall_prefix
= true;
4981 r
= unit_path_printf(u
, w
, &resolved
);
4983 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", w
);
4987 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4991 joined
= strjoin(ignore_enoent
? "-" : "",
4992 shall_prefix
? "+" : "",
4995 r
= strv_push(sv
, joined
);
5005 int config_parse_temporary_filesystems(
5007 const char *filename
,
5009 const char *section
,
5010 unsigned section_line
,
5017 const Unit
*u
= userdata
;
5018 ExecContext
*c
= ASSERT_PTR(data
);
5025 if (isempty(rvalue
)) {
5026 /* Empty assignment resets the list */
5027 temporary_filesystem_free_many(c
->temporary_filesystems
, c
->n_temporary_filesystems
);
5028 c
->temporary_filesystems
= NULL
;
5029 c
->n_temporary_filesystems
= 0;
5033 for (const char *p
= rvalue
;;) {
5034 _cleanup_free_
char *word
= NULL
, *path
= NULL
, *resolved
= NULL
;
5037 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
5041 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
5048 r
= extract_first_word(&w
, &path
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
5052 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", word
);
5056 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid syntax, ignoring: %s", word
);
5060 r
= unit_path_printf(u
, path
, &resolved
);
5062 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", path
);
5066 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5070 r
= temporary_filesystem_add(&c
->temporary_filesystems
, &c
->n_temporary_filesystems
, resolved
, w
);
5076 int config_parse_bind_paths(
5078 const char *filename
,
5080 const char *section
,
5081 unsigned section_line
,
5088 ExecContext
*c
= ASSERT_PTR(data
);
5089 const Unit
*u
= userdata
;
5096 if (isempty(rvalue
)) {
5097 /* Empty assignment resets the list */
5098 bind_mount_free_many(c
->bind_mounts
, c
->n_bind_mounts
);
5099 c
->bind_mounts
= NULL
;
5100 c
->n_bind_mounts
= 0;
5104 for (const char *p
= rvalue
;;) {
5105 _cleanup_free_
char *source
= NULL
, *destination
= NULL
;
5106 _cleanup_free_
char *sresolved
= NULL
, *dresolved
= NULL
;
5107 char *s
= NULL
, *d
= NULL
;
5108 bool rbind
= true, ignore_enoent
= false;
5110 r
= extract_first_word(&p
, &source
, ":" WHITESPACE
, EXTRACT_UNQUOTE
|EXTRACT_DONT_COALESCE_SEPARATORS
);
5114 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
5120 r
= unit_full_printf_full(u
, source
, PATH_MAX
, &sresolved
);
5122 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5123 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", source
);
5129 ignore_enoent
= true;
5133 r
= path_simplify_and_warn(s
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5137 /* Optionally, the destination is specified. */
5138 if (p
&& p
[-1] == ':') {
5139 r
= extract_first_word(&p
, &destination
, ":" WHITESPACE
, EXTRACT_UNQUOTE
|EXTRACT_DONT_COALESCE_SEPARATORS
);
5143 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
5147 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Missing argument after ':', ignoring: %s", s
);
5151 r
= unit_path_printf(u
, destination
, &dresolved
);
5153 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5154 "Failed to resolve specifiers in \"%s\", ignoring: %m", destination
);
5158 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5164 /* Optionally, there's also a short option string specified */
5165 if (p
&& p
[-1] == ':') {
5166 _cleanup_free_
char *options
= NULL
;
5168 r
= extract_first_word(&p
, &options
, NULL
, EXTRACT_UNQUOTE
);
5172 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s=, ignoring: %s", lvalue
, rvalue
);
5176 if (isempty(options
) || streq(options
, "rbind"))
5178 else if (streq(options
, "norbind"))
5181 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid option string, ignoring setting: %s", options
);
5188 r
= bind_mount_add(&c
->bind_mounts
, &c
->n_bind_mounts
,
5192 .read_only
= !!strstr(lvalue
, "ReadOnly"),
5194 .ignore_enoent
= ignore_enoent
,
5203 int config_parse_mount_images(
5205 const char *filename
,
5207 const char *section
,
5208 unsigned section_line
,
5215 ExecContext
*c
= ASSERT_PTR(data
);
5216 const Unit
*u
= userdata
;
5223 if (isempty(rvalue
)) {
5224 /* Empty assignment resets the list */
5225 c
->mount_images
= mount_image_free_many(c
->mount_images
, &c
->n_mount_images
);
5229 for (const char *p
= rvalue
;;) {
5230 _cleanup_(mount_options_free_allp
) MountOptions
*options
= NULL
;
5231 _cleanup_free_
char *first
= NULL
, *second
= NULL
, *tuple
= NULL
;
5232 _cleanup_free_
char *sresolved
= NULL
, *dresolved
= NULL
;
5233 const char *q
= NULL
;
5235 bool permissive
= false;
5237 r
= extract_first_word(&p
, &tuple
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_RETAIN_ESCAPE
);
5241 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5242 "Invalid syntax %s=%s, ignoring: %m", lvalue
, rvalue
);
5249 r
= extract_many_words(&q
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
, &first
, &second
, NULL
);
5253 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5254 "Invalid syntax in %s=, ignoring: %s", lvalue
, tuple
);
5266 r
= unit_path_printf(u
, s
, &sresolved
);
5268 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5269 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", s
);
5273 r
= path_simplify_and_warn(sresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5277 if (isempty(second
)) {
5278 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Missing destination in %s, ignoring: %s", lvalue
, rvalue
);
5282 r
= unit_path_printf(u
, second
, &dresolved
);
5284 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5285 "Failed to resolve specifiers in \"%s\", ignoring: %m", second
);
5289 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5294 _cleanup_free_
char *partition
= NULL
, *mount_options
= NULL
, *mount_options_resolved
= NULL
;
5295 MountOptions
*o
= NULL
;
5296 PartitionDesignator partition_designator
;
5298 r
= extract_many_words(&q
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
, &partition
, &mount_options
, NULL
);
5302 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", q
);
5307 /* Single set of options, applying to the root partition/single filesystem */
5309 r
= unit_full_printf(u
, partition
, &mount_options_resolved
);
5311 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", first
);
5315 o
= new(MountOptions
, 1);
5318 *o
= (MountOptions
) {
5319 .partition_designator
= PARTITION_ROOT
,
5320 .options
= TAKE_PTR(mount_options_resolved
),
5322 LIST_APPEND(mount_options
, options
, o
);
5327 partition_designator
= partition_designator_from_string(partition
);
5328 if (partition_designator
< 0) {
5329 log_syntax(unit
, LOG_WARNING
, filename
, line
, partition_designator
,
5330 "Invalid partition name %s, ignoring", partition
);
5333 r
= unit_full_printf(u
, mount_options
, &mount_options_resolved
);
5335 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", mount_options
);
5339 o
= new(MountOptions
, 1);
5342 *o
= (MountOptions
) {
5343 .partition_designator
= partition_designator
,
5344 .options
= TAKE_PTR(mount_options_resolved
),
5346 LIST_APPEND(mount_options
, options
, o
);
5349 r
= mount_image_add(&c
->mount_images
, &c
->n_mount_images
,
5351 .source
= sresolved
,
5352 .destination
= dresolved
,
5353 .mount_options
= options
,
5354 .ignore_enoent
= permissive
,
5355 .type
= MOUNT_IMAGE_DISCRETE
,
5362 int config_parse_extension_images(
5364 const char *filename
,
5366 const char *section
,
5367 unsigned section_line
,
5374 ExecContext
*c
= ASSERT_PTR(data
);
5375 const Unit
*u
= userdata
;
5382 if (isempty(rvalue
)) {
5383 /* Empty assignment resets the list */
5384 c
->extension_images
= mount_image_free_many(c
->extension_images
, &c
->n_extension_images
);
5388 for (const char *p
= rvalue
;;) {
5389 _cleanup_free_
char *source
= NULL
, *tuple
= NULL
, *sresolved
= NULL
;
5390 _cleanup_(mount_options_free_allp
) MountOptions
*options
= NULL
;
5391 bool permissive
= false;
5392 const char *q
= NULL
;
5395 r
= extract_first_word(&p
, &tuple
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_RETAIN_ESCAPE
);
5399 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5400 "Invalid syntax %s=%s, ignoring: %m", lvalue
, rvalue
);
5407 r
= extract_first_word(&q
, &source
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
);
5411 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5412 "Invalid syntax in %s=, ignoring: %s", lvalue
, tuple
);
5424 r
= unit_path_printf(u
, s
, &sresolved
);
5426 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5427 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", s
);
5431 r
= path_simplify_and_warn(sresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5436 _cleanup_free_
char *partition
= NULL
, *mount_options
= NULL
, *mount_options_resolved
= NULL
;
5437 MountOptions
*o
= NULL
;
5438 PartitionDesignator partition_designator
;
5440 r
= extract_many_words(&q
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
, &partition
, &mount_options
, NULL
);
5444 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", q
);
5449 /* Single set of options, applying to the root partition/single filesystem */
5451 r
= unit_full_printf(u
, partition
, &mount_options_resolved
);
5453 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", partition
);
5457 o
= new(MountOptions
, 1);
5460 *o
= (MountOptions
) {
5461 .partition_designator
= PARTITION_ROOT
,
5462 .options
= TAKE_PTR(mount_options_resolved
),
5464 LIST_APPEND(mount_options
, options
, o
);
5469 partition_designator
= partition_designator_from_string(partition
);
5470 if (partition_designator
< 0) {
5471 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid partition name %s, ignoring", partition
);
5474 r
= unit_full_printf(u
, mount_options
, &mount_options_resolved
);
5476 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", mount_options
);
5480 o
= new(MountOptions
, 1);
5483 *o
= (MountOptions
) {
5484 .partition_designator
= partition_designator
,
5485 .options
= TAKE_PTR(mount_options_resolved
),
5487 LIST_APPEND(mount_options
, options
, o
);
5490 r
= mount_image_add(&c
->extension_images
, &c
->n_extension_images
,
5492 .source
= sresolved
,
5493 .mount_options
= options
,
5494 .ignore_enoent
= permissive
,
5495 .type
= MOUNT_IMAGE_EXTENSION
,
5502 int config_parse_job_timeout_sec(
5504 const char *filename
,
5506 const char *section
,
5507 unsigned section_line
,
5514 Unit
*u
= ASSERT_PTR(data
);
5522 r
= parse_sec_fix_0(rvalue
, &usec
);
5524 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse JobTimeoutSec= parameter, ignoring: %s", rvalue
);
5528 /* If the user explicitly changed JobTimeoutSec= also change JobRunningTimeoutSec=, for compatibility with old
5529 * versions. If JobRunningTimeoutSec= was explicitly set, avoid this however as whatever the user picked should
5532 if (!u
->job_running_timeout_set
)
5533 u
->job_running_timeout
= usec
;
5535 u
->job_timeout
= usec
;
5540 int config_parse_job_running_timeout_sec(
5542 const char *filename
,
5544 const char *section
,
5545 unsigned section_line
,
5552 Unit
*u
= ASSERT_PTR(data
);
5560 r
= parse_sec_fix_0(rvalue
, &usec
);
5562 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse JobRunningTimeoutSec= parameter, ignoring: %s", rvalue
);
5566 u
->job_running_timeout
= usec
;
5567 u
->job_running_timeout_set
= true;
5572 int config_parse_emergency_action(
5574 const char *filename
,
5576 const char *section
,
5577 unsigned section_line
,
5585 EmergencyAction
*x
= ASSERT_PTR(data
);
5593 m
= ((Unit
*) userdata
)->manager
;
5597 r
= parse_emergency_action(rvalue
, MANAGER_IS_SYSTEM(m
), x
);
5599 if (r
== -EOPNOTSUPP
&& MANAGER_IS_USER(m
)) {
5600 /* Compat mode: remove for systemd 241. */
5602 log_syntax(unit
, LOG_INFO
, filename
, line
, r
,
5603 "%s= in user mode specified as \"%s\", using \"exit-force\" instead.",
5605 *x
= EMERGENCY_ACTION_EXIT_FORCE
;
5609 if (r
== -EOPNOTSUPP
)
5610 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5611 "%s= specified as %s mode action, ignoring: %s",
5612 lvalue
, MANAGER_IS_SYSTEM(m
) ? "user" : "system", rvalue
);
5614 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5615 "Failed to parse %s=, ignoring: %s", lvalue
, rvalue
);
5622 int config_parse_pid_file(
5624 const char *filename
,
5626 const char *section
,
5627 unsigned section_line
,
5634 _cleanup_free_
char *k
= NULL
, *n
= NULL
;
5635 const Unit
*u
= ASSERT_PTR(userdata
);
5643 if (isempty(rvalue
)) {
5644 /* An empty assignment removes already set value. */
5649 r
= unit_path_printf(u
, rvalue
, &k
);
5651 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
5655 /* If this is a relative path make it absolute by prefixing the /run */
5656 n
= path_make_absolute(k
, u
->manager
->prefix
[EXEC_DIRECTORY_RUNTIME
]);
5660 /* Check that the result is a sensible path */
5661 r
= path_simplify_and_warn(n
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5665 r
= patch_var_run(unit
, filename
, line
, lvalue
, &n
);
5669 free_and_replace(*s
, n
);
5673 int config_parse_exit_status(
5675 const char *filename
,
5677 const char *section
,
5678 unsigned section_line
,
5685 int *exit_status
= data
, r
;
5691 assert(exit_status
);
5693 if (isempty(rvalue
)) {
5698 r
= safe_atou8(rvalue
, &u
);
5700 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse exit status '%s', ignoring: %m", rvalue
);
5708 int config_parse_disable_controllers(
5710 const char *filename
,
5712 const char *section
,
5713 unsigned section_line
,
5721 CGroupContext
*c
= data
;
5722 CGroupMask disabled_mask
;
5724 /* 1. If empty, make all controllers eligible for use again.
5725 * 2. If non-empty, merge all listed controllers, space separated. */
5727 if (isempty(rvalue
)) {
5728 c
->disable_controllers
= 0;
5732 r
= cg_mask_from_string(rvalue
, &disabled_mask
);
5733 if (r
< 0 || disabled_mask
<= 0) {
5734 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid cgroup string: %s, ignoring", rvalue
);
5738 c
->disable_controllers
|= disabled_mask
;
5743 int config_parse_ip_filter_bpf_progs(
5745 const char *filename
,
5747 const char *section
,
5748 unsigned section_line
,
5755 _cleanup_free_
char *resolved
= NULL
;
5756 const Unit
*u
= userdata
;
5757 char ***paths
= ASSERT_PTR(data
);
5764 if (isempty(rvalue
)) {
5765 *paths
= strv_free(*paths
);
5769 r
= unit_path_printf(u
, rvalue
, &resolved
);
5771 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
5775 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5779 if (strv_contains(*paths
, resolved
))
5782 r
= strv_extend(paths
, resolved
);
5786 r
= bpf_firewall_supported();
5789 if (r
!= BPF_FIREWALL_SUPPORTED_WITH_MULTI
) {
5790 static bool warned
= false;
5792 log_full(warned
? LOG_DEBUG
: LOG_WARNING
,
5793 "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"
5794 "Starting this unit will fail! (This warning is only shown for the first loaded unit using IP firewalling.)", filename
, line
, lvalue
, rvalue
);
5802 int config_parse_bpf_foreign_program(
5804 const char *filename
,
5806 const char *section
,
5807 unsigned section_line
,
5813 _cleanup_free_
char *resolved
= NULL
, *word
= NULL
;
5814 CGroupContext
*c
= data
;
5815 const char *p
= ASSERT_PTR(rvalue
);
5822 if (isempty(rvalue
)) {
5823 while (c
->bpf_foreign_programs
)
5824 cgroup_context_remove_bpf_foreign_program(c
, c
->bpf_foreign_programs
);
5829 r
= extract_first_word(&p
, &word
, ":", 0);
5833 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse foreign BPF program, ignoring: %s", rvalue
);
5836 if (r
== 0 || isempty(p
)) {
5837 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid syntax in %s=, ignoring: %s", lvalue
, rvalue
);
5841 attach_type
= bpf_cgroup_attach_type_from_string(word
);
5842 if (attach_type
< 0) {
5843 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Unknown BPF attach type=%s, ignoring: %s", word
, rvalue
);
5847 r
= unit_path_printf(u
, p
, &resolved
);
5849 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %s", p
, rvalue
);
5853 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5857 r
= cgroup_add_bpf_foreign_program(c
, attach_type
, resolved
);
5859 return log_error_errno(r
, "Failed to add foreign BPF program to cgroup context: %m");
5864 int config_parse_cgroup_socket_bind(
5866 const char *filename
,
5868 const char *section
,
5869 unsigned section_line
,
5875 _cleanup_free_ CGroupSocketBindItem
*item
= NULL
;
5876 CGroupSocketBindItem
**head
= data
;
5877 uint16_t nr_ports
, port_min
;
5878 int af
, ip_protocol
, r
;
5880 if (isempty(rvalue
)) {
5881 cgroup_context_remove_socket_bind(head
);
5885 r
= parse_socket_bind_item(rvalue
, &af
, &ip_protocol
, &nr_ports
, &port_min
);
5889 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5890 "Unable to parse %s= assignment, ignoring: %s", lvalue
, rvalue
);
5894 item
= new(CGroupSocketBindItem
, 1);
5897 *item
= (CGroupSocketBindItem
) {
5898 .address_family
= af
,
5899 .ip_protocol
= ip_protocol
,
5900 .nr_ports
= nr_ports
,
5901 .port_min
= port_min
,
5904 LIST_PREPEND(socket_bind_items
, *head
, TAKE_PTR(item
));
5909 int config_parse_restrict_network_interfaces(
5911 const char *filename
,
5913 const char *section
,
5914 unsigned section_line
,
5920 CGroupContext
*c
= ASSERT_PTR(data
);
5921 bool is_allow_rule
= true;
5928 if (isempty(rvalue
)) {
5929 /* Empty assignment resets the list */
5930 c
->restrict_network_interfaces
= set_free(c
->restrict_network_interfaces
);
5934 if (rvalue
[0] == '~') {
5935 is_allow_rule
= false;
5939 if (set_isempty(c
->restrict_network_interfaces
))
5940 /* Only initialize this when creating the set */
5941 c
->restrict_network_interfaces_is_allow_list
= is_allow_rule
;
5943 for (const char *p
= rvalue
;;) {
5944 _cleanup_free_
char *word
= NULL
;
5946 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
5952 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5953 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
5957 if (!ifname_valid(word
)) {
5958 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid interface name, ignoring: %s", word
);
5962 if (c
->restrict_network_interfaces_is_allow_list
!= is_allow_rule
)
5963 free(set_remove(c
->restrict_network_interfaces
, word
));
5965 r
= set_put_strdup(&c
->restrict_network_interfaces
, word
);
5974 static int merge_by_names(Unit
**u
, Set
*names
, const char *id
) {
5981 /* Let's try to add in all names that are aliases of this unit */
5982 while ((k
= set_steal_first(names
))) {
5983 _cleanup_free_ _unused_
char *free_k
= k
;
5985 /* First try to merge in the other name into our unit */
5986 r
= unit_merge_by_name(*u
, k
);
5990 /* Hmm, we couldn't merge the other unit into ours? Then let's try it the other way
5993 other
= manager_get_unit((*u
)->manager
, k
);
5995 return r
; /* return previous failure */
5997 r
= unit_merge(other
, *u
);
6002 return merge_by_names(u
, names
, NULL
);
6005 if (streq_ptr(id
, k
))
6006 unit_choose_id(*u
, id
);
6012 int unit_load_fragment(Unit
*u
) {
6013 const char *fragment
;
6014 _cleanup_set_free_free_ Set
*names
= NULL
;
6018 assert(u
->load_state
== UNIT_STUB
);
6022 u
->access_selinux_context
= mfree(u
->access_selinux_context
);
6023 u
->load_state
= UNIT_LOADED
;
6027 /* Possibly rebuild the fragment map to catch new units */
6028 r
= unit_file_build_name_map(&u
->manager
->lookup_paths
,
6029 &u
->manager
->unit_cache_timestamp_hash
,
6030 &u
->manager
->unit_id_map
,
6031 &u
->manager
->unit_name_map
,
6032 &u
->manager
->unit_path_cache
);
6034 return log_error_errno(r
, "Failed to rebuild name map: %m");
6036 r
= unit_file_find_fragment(u
->manager
->unit_id_map
,
6037 u
->manager
->unit_name_map
,
6041 if (r
< 0 && r
!= -ENOENT
)
6045 /* Open the file, check if this is a mask, otherwise read. */
6046 _cleanup_fclose_
FILE *f
= NULL
;
6049 /* Try to open the file name. A symlink is OK, for example for linked files or masks. We
6050 * expect that all symlinks within the lookup paths have been already resolved, but we don't
6051 * verify this here. */
6052 f
= fopen(fragment
, "re");
6054 return log_unit_notice_errno(u
, errno
, "Failed to open %s: %m", fragment
);
6056 if (fstat(fileno(f
), &st
) < 0)
6059 r
= free_and_strdup(&u
->fragment_path
, fragment
);
6063 if (null_or_empty(&st
)) {
6064 /* Unit file is masked */
6066 u
->load_state
= u
->perpetual
? UNIT_LOADED
: UNIT_MASKED
; /* don't allow perpetual units to ever be masked */
6067 u
->fragment_mtime
= 0;
6068 u
->access_selinux_context
= mfree(u
->access_selinux_context
);
6071 if (mac_selinux_use()) {
6072 _cleanup_freecon_
char *selcon
= NULL
;
6074 /* Cache the SELinux context of the unit file here. We'll make use of when checking access permissions to loaded units */
6075 r
= fgetfilecon_raw(fileno(f
), &selcon
);
6077 log_unit_warning_errno(u
, r
, "Failed to read SELinux context of '%s', ignoring: %m", fragment
);
6079 r
= free_and_strdup(&u
->access_selinux_context
, selcon
);
6084 u
->access_selinux_context
= mfree(u
->access_selinux_context
);
6086 u
->load_state
= UNIT_LOADED
;
6087 u
->fragment_mtime
= timespec_load(&st
.st_mtim
);
6089 /* Now, parse the file contents */
6090 r
= config_parse(u
->id
, fragment
, f
,
6091 UNIT_VTABLE(u
)->sections
,
6092 config_item_perf_lookup
, load_fragment_gperf_lookup
,
6097 log_unit_notice_errno(u
, r
, "Unit configuration has fatal error, unit will not be started.");
6103 /* Call merge_by_names with the name derived from the fragment path as the preferred name.
6105 * We do the merge dance here because for some unit types, the unit might have aliases which are not
6106 * declared in the file system. In particular, this is true (and frequent) for device and swap units.
6108 const char *id
= u
->id
;
6109 _cleanup_free_
char *free_id
= NULL
;
6112 id
= basename(fragment
);
6113 if (unit_name_is_valid(id
, UNIT_NAME_TEMPLATE
)) {
6114 assert(u
->instance
); /* If we're not trying to use a template for non-instanced unit,
6115 * this must be set. */
6117 r
= unit_name_replace_instance(id
, u
->instance
, &free_id
);
6119 return log_debug_errno(r
, "Failed to build id (%s + %s): %m", id
, u
->instance
);
6125 r
= merge_by_names(&merged
, names
, id
);
6130 u
->load_state
= UNIT_MERGED
;
6135 void unit_dump_config_items(FILE *f
) {
6136 static const struct {
6137 const ConfigParserCallback callback
;
6140 { config_parse_warn_compat
, "NOTSUPPORTED" },
6141 { config_parse_int
, "INTEGER" },
6142 { config_parse_unsigned
, "UNSIGNED" },
6143 { config_parse_iec_size
, "SIZE" },
6144 { config_parse_iec_uint64
, "SIZE" },
6145 { config_parse_si_uint64
, "SIZE" },
6146 { config_parse_bool
, "BOOLEAN" },
6147 { config_parse_string
, "STRING" },
6148 { config_parse_path
, "PATH" },
6149 { config_parse_unit_path_printf
, "PATH" },
6150 { config_parse_colon_separated_paths
, "PATH" },
6151 { config_parse_strv
, "STRING [...]" },
6152 { config_parse_exec_nice
, "NICE" },
6153 { config_parse_exec_oom_score_adjust
, "OOMSCOREADJUST" },
6154 { config_parse_exec_io_class
, "IOCLASS" },
6155 { config_parse_exec_io_priority
, "IOPRIORITY" },
6156 { config_parse_exec_cpu_sched_policy
, "CPUSCHEDPOLICY" },
6157 { config_parse_exec_cpu_sched_prio
, "CPUSCHEDPRIO" },
6158 { config_parse_exec_cpu_affinity
, "CPUAFFINITY" },
6159 { config_parse_mode
, "MODE" },
6160 { config_parse_unit_env_file
, "FILE" },
6161 { config_parse_exec_output
, "OUTPUT" },
6162 { config_parse_exec_input
, "INPUT" },
6163 { config_parse_log_facility
, "FACILITY" },
6164 { config_parse_log_level
, "LEVEL" },
6165 { config_parse_exec_secure_bits
, "SECUREBITS" },
6166 { config_parse_capability_set
, "BOUNDINGSET" },
6167 { config_parse_rlimit
, "LIMIT" },
6168 { config_parse_unit_deps
, "UNIT [...]" },
6169 { config_parse_exec
, "PATH [ARGUMENT [...]]" },
6170 { config_parse_service_type
, "SERVICETYPE" },
6171 { config_parse_service_exit_type
, "SERVICEEXITTYPE" },
6172 { config_parse_service_restart
, "SERVICERESTART" },
6173 { config_parse_service_timeout_failure_mode
, "TIMEOUTMODE" },
6174 { config_parse_kill_mode
, "KILLMODE" },
6175 { config_parse_signal
, "SIGNAL" },
6176 { config_parse_socket_listen
, "SOCKET [...]" },
6177 { config_parse_socket_bind
, "SOCKETBIND" },
6178 { config_parse_socket_bindtodevice
, "NETWORKINTERFACE" },
6179 { config_parse_sec
, "SECONDS" },
6180 { config_parse_nsec
, "NANOSECONDS" },
6181 { config_parse_namespace_path_strv
, "PATH [...]" },
6182 { config_parse_bind_paths
, "PATH[:PATH[:OPTIONS]] [...]" },
6183 { config_parse_unit_requires_mounts_for
, "PATH [...]" },
6184 { config_parse_exec_mount_flags
, "MOUNTFLAG [...]" },
6185 { config_parse_unit_string_printf
, "STRING" },
6186 { config_parse_trigger_unit
, "UNIT" },
6187 { config_parse_timer
, "TIMER" },
6188 { config_parse_path_spec
, "PATH" },
6189 { config_parse_notify_access
, "ACCESS" },
6190 { config_parse_ip_tos
, "TOS" },
6191 { config_parse_unit_condition_path
, "CONDITION" },
6192 { config_parse_unit_condition_string
, "CONDITION" },
6193 { config_parse_unit_slice
, "SLICE" },
6194 { config_parse_documentation
, "URL" },
6195 { config_parse_service_timeout
, "SECONDS" },
6196 { config_parse_emergency_action
, "ACTION" },
6197 { config_parse_set_status
, "STATUS" },
6198 { config_parse_service_sockets
, "SOCKETS" },
6199 { config_parse_environ
, "ENVIRON" },
6201 { config_parse_syscall_filter
, "SYSCALLS" },
6202 { config_parse_syscall_archs
, "ARCHS" },
6203 { config_parse_syscall_errno
, "ERRNO" },
6204 { config_parse_syscall_log
, "SYSCALLS" },
6205 { config_parse_address_families
, "FAMILIES" },
6206 { config_parse_restrict_namespaces
, "NAMESPACES" },
6208 { config_parse_restrict_filesystems
, "FILESYSTEMS" },
6209 { config_parse_cpu_shares
, "SHARES" },
6210 { config_parse_cg_weight
, "WEIGHT" },
6211 { config_parse_cg_cpu_weight
, "CPUWEIGHT" },
6212 { config_parse_memory_limit
, "LIMIT" },
6213 { config_parse_device_allow
, "DEVICE" },
6214 { config_parse_device_policy
, "POLICY" },
6215 { config_parse_io_limit
, "LIMIT" },
6216 { config_parse_io_device_weight
, "DEVICEWEIGHT" },
6217 { config_parse_io_device_latency
, "DEVICELATENCY" },
6218 { config_parse_blockio_bandwidth
, "BANDWIDTH" },
6219 { config_parse_blockio_weight
, "WEIGHT" },
6220 { config_parse_blockio_device_weight
, "DEVICEWEIGHT" },
6221 { config_parse_long
, "LONG" },
6222 { config_parse_socket_service
, "SERVICE" },
6224 { config_parse_exec_selinux_context
, "LABEL" },
6226 { config_parse_job_mode
, "MODE" },
6227 { config_parse_job_mode_isolate
, "BOOLEAN" },
6228 { config_parse_personality
, "PERSONALITY" },
6229 { config_parse_log_filter_patterns
, "REGEX" },
6232 const char *prev
= NULL
;
6236 NULSTR_FOREACH(i
, load_fragment_gperf_nulstr
) {
6237 const char *rvalue
= "OTHER", *lvalue
;
6238 const ConfigPerfItem
*p
;
6241 assert_se(p
= load_fragment_gperf_lookup(i
, strlen(i
)));
6243 /* Hide legacy settings */
6244 if (p
->parse
== config_parse_warn_compat
&&
6245 p
->ltype
== DISABLED_LEGACY
)
6248 for (size_t j
= 0; j
< ELEMENTSOF(table
); j
++)
6249 if (p
->parse
== table
[j
].callback
) {
6250 rvalue
= table
[j
].rvalue
;
6254 dot
= strchr(i
, '.');
6255 lvalue
= dot
? dot
+ 1 : i
;
6258 size_t prefix_len
= dot
- i
;
6260 if (!prev
|| !strneq(prev
, i
, prefix_len
+1)) {
6264 fprintf(f
, "[%.*s]\n", (int) prefix_len
, i
);
6268 fprintf(f
, "%s=%s\n", lvalue
, rvalue
);
6273 int config_parse_cpu_affinity2(
6275 const char *filename
,
6277 const char *section
,
6278 unsigned section_line
,
6285 CPUSet
*affinity
= ASSERT_PTR(data
);
6287 (void) parse_cpu_set_extend(rvalue
, affinity
, true, unit
, filename
, line
, lvalue
);
6292 int config_parse_show_status(
6294 const char *filename
,
6296 const char *section
,
6297 unsigned section_line
,
6305 ShowStatus
*b
= ASSERT_PTR(data
);
6311 k
= parse_show_status(rvalue
, b
);
6313 log_syntax(unit
, LOG_WARNING
, filename
, line
, k
, "Failed to parse show status setting, ignoring: %s", rvalue
);
6318 int config_parse_output_restricted(
6320 const char *filename
,
6322 const char *section
,
6323 unsigned section_line
,
6330 ExecOutput t
, *eo
= ASSERT_PTR(data
);
6331 bool obsolete
= false;
6337 if (streq(rvalue
, "syslog")) {
6338 t
= EXEC_OUTPUT_JOURNAL
;
6340 } else if (streq(rvalue
, "syslog+console")) {
6341 t
= EXEC_OUTPUT_JOURNAL_AND_CONSOLE
;
6344 t
= exec_output_from_string(rvalue
);
6346 log_syntax(unit
, LOG_WARNING
, filename
, line
, t
, "Failed to parse output type, ignoring: %s", rvalue
);
6350 if (IN_SET(t
, EXEC_OUTPUT_SOCKET
, EXEC_OUTPUT_NAMED_FD
, EXEC_OUTPUT_FILE
, EXEC_OUTPUT_FILE_APPEND
, EXEC_OUTPUT_FILE_TRUNCATE
)) {
6351 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Standard output types socket, fd:, file:, append:, truncate: are not supported as defaults, ignoring: %s", rvalue
);
6357 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
6358 "Standard output type %s is obsolete, automatically updating to %s. Please update your configuration.",
6359 rvalue
, exec_output_to_string(t
));
6365 int config_parse_crash_chvt(
6367 const char *filename
,
6369 const char *section
,
6370 unsigned section_line
,
6384 r
= parse_crash_chvt(rvalue
, data
);
6386 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse CrashChangeVT= setting, ignoring: %s", rvalue
);
6391 int config_parse_swap_priority(
6393 const char *filename
,
6395 const char *section
,
6396 unsigned section_line
,
6403 Swap
*s
= ASSERT_PTR(userdata
);
6411 if (isempty(rvalue
)) {
6412 s
->parameters_fragment
.priority
= -1;
6413 s
->parameters_fragment
.priority_set
= false;
6417 r
= safe_atoi(rvalue
, &priority
);
6419 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid swap priority '%s', ignoring.", rvalue
);
6423 if (priority
< -1) {
6424 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
);
6428 if (priority
> 32767) {
6429 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Swap priority out of range, ignoring: %s", rvalue
);
6433 s
->parameters_fragment
.priority
= priority
;
6434 s
->parameters_fragment
.priority_set
= true;
6438 int config_parse_watchdog_sec(
6440 const char *filename
,
6442 const char *section
,
6443 unsigned section_line
,
6450 usec_t
*usec
= data
;
6456 /* This is called for {Runtime,Reboot,KExec}WatchdogSec= where "default" maps to
6457 * USEC_INFINITY internally. */
6459 if (streq(rvalue
, "default"))
6460 *usec
= USEC_INFINITY
;
6461 else if (streq(rvalue
, "off"))
6464 return config_parse_sec(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
);
6469 int config_parse_tty_size(
6471 const char *filename
,
6473 const char *section
,
6474 unsigned section_line
,
6481 unsigned *sz
= data
;
6487 if (isempty(rvalue
)) {
6492 return config_parse_unsigned(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
);
6495 int config_parse_log_filter_patterns(
6497 const char *filename
,
6499 const char *section
,
6500 unsigned section_line
,
6507 ExecContext
*c
= ASSERT_PTR(data
);
6508 _cleanup_(pattern_freep
) pcre2_code
*compiled_pattern
= NULL
;
6509 const char *pattern
= ASSERT_PTR(rvalue
);
6510 bool is_allowlist
= true;
6516 if (isempty(pattern
)) {
6517 /* Empty assignment resets the lists. */
6518 c
->log_filter_allowed_patterns
= set_free(c
->log_filter_allowed_patterns
);
6519 c
->log_filter_denied_patterns
= set_free(c
->log_filter_denied_patterns
);
6523 if (pattern
[0] == '~') {
6524 is_allowlist
= false;
6526 if (isempty(pattern
))
6527 /* LogFilterPatterns=~ is not considered a valid pattern. */
6528 return log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
6529 "Regex pattern invalid, ignoring: %s=%s", lvalue
, rvalue
);
6532 if (pattern_compile_and_log(pattern
, 0, &compiled_pattern
) < 0)
6535 r
= set_put_strdup(is_allowlist
? &c
->log_filter_allowed_patterns
: &c
->log_filter_denied_patterns
,
6538 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
6539 "Failed to store log filtering pattern, ignoring: %s=%s", lvalue
, rvalue
);