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 "percent-util.h"
56 #include "process-util.h"
58 #include "seccomp-util.h"
60 #include "securebits-util.h"
61 #include "selinux-util.h"
62 #include "signal-util.h"
63 #include "socket-netlink.h"
64 #include "specifier.h"
65 #include "stat-util.h"
66 #include "string-util.h"
68 #include "syslog-util.h"
69 #include "time-util.h"
70 #include "unit-name.h"
71 #include "unit-printf.h"
72 #include "user-util.h"
76 static int parse_socket_protocol(const char *s
) {
79 r
= parse_ip_protocol(s
);
82 if (!IN_SET(r
, IPPROTO_UDPLITE
, IPPROTO_SCTP
))
83 return -EPROTONOSUPPORT
;
88 int parse_crash_chvt(const char *value
, int *data
) {
91 if (safe_atoi(value
, data
) >= 0)
94 b
= parse_boolean(value
);
99 *data
= 0; /* switch to where kmsg goes */
101 *data
= -1; /* turn off switching */
106 int parse_confirm_spawn(const char *value
, char **console
) {
110 r
= value
? parse_boolean(value
) : 1;
114 } else if (r
> 0) /* on with default tty */
115 s
= strdup("/dev/console");
116 else if (is_path(value
)) /* on with fully qualified path */
118 else /* on with only a tty file name, not a fully qualified path */
119 s
= path_join("/dev/", value
);
127 DEFINE_CONFIG_PARSE(config_parse_socket_protocol
, parse_socket_protocol
, "Failed to parse socket protocol");
128 DEFINE_CONFIG_PARSE(config_parse_exec_secure_bits
, secure_bits_from_string
, "Failed to parse secure bits");
129 DEFINE_CONFIG_PARSE_ENUM(config_parse_collect_mode
, collect_mode
, CollectMode
, "Failed to parse garbage collection mode");
130 DEFINE_CONFIG_PARSE_ENUM(config_parse_device_policy
, cgroup_device_policy
, CGroupDevicePolicy
, "Failed to parse device policy");
131 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_keyring_mode
, exec_keyring_mode
, ExecKeyringMode
, "Failed to parse keyring mode");
132 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_proc
, protect_proc
, ProtectProc
, "Failed to parse /proc/ protection mode");
133 DEFINE_CONFIG_PARSE_ENUM(config_parse_proc_subset
, proc_subset
, ProcSubset
, "Failed to parse /proc/ subset mode");
134 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_utmp_mode
, exec_utmp_mode
, ExecUtmpMode
, "Failed to parse utmp mode");
135 DEFINE_CONFIG_PARSE_ENUM(config_parse_job_mode
, job_mode
, JobMode
, "Failed to parse job mode");
136 DEFINE_CONFIG_PARSE_ENUM(config_parse_notify_access
, notify_access
, NotifyAccess
, "Failed to parse notify access specifier");
137 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_home
, protect_home
, ProtectHome
, "Failed to parse protect home value");
138 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_system
, protect_system
, ProtectSystem
, "Failed to parse protect system value");
139 DEFINE_CONFIG_PARSE_ENUM(config_parse_runtime_preserve_mode
, exec_preserve_mode
, ExecPreserveMode
, "Failed to parse runtime directory preserve mode");
140 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_type
, service_type
, ServiceType
, "Failed to parse service type");
141 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_exit_type
, service_exit_type
, ServiceExitType
, "Failed to parse service exit type");
142 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart
, service_restart
, ServiceRestart
, "Failed to parse service restart specifier");
143 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_timeout_failure_mode
, service_timeout_failure_mode
, ServiceTimeoutFailureMode
, "Failed to parse timeout failure mode");
144 DEFINE_CONFIG_PARSE_ENUM(config_parse_socket_bind
, socket_address_bind_ipv6_only_or_bool
, SocketAddressBindIPv6Only
, "Failed to parse bind IPv6 only value");
145 DEFINE_CONFIG_PARSE_ENUM(config_parse_oom_policy
, oom_policy
, OOMPolicy
, "Failed to parse OOM policy");
146 DEFINE_CONFIG_PARSE_ENUM(config_parse_managed_oom_preference
, managed_oom_preference
, ManagedOOMPreference
, "Failed to parse ManagedOOMPreference=");
147 DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_ip_tos
, ip_tos
, int, -1, "Failed to parse IP TOS value");
148 DEFINE_CONFIG_PARSE_PTR(config_parse_blockio_weight
, cg_blkio_weight_parse
, uint64_t, "Invalid block IO weight");
149 DEFINE_CONFIG_PARSE_PTR(config_parse_cg_weight
, cg_weight_parse
, uint64_t, "Invalid weight");
150 DEFINE_CONFIG_PARSE_PTR(config_parse_cg_cpu_weight
, cg_cpu_weight_parse
, uint64_t, "Invalid CPU weight");
151 static DEFINE_CONFIG_PARSE_PTR(config_parse_cpu_shares_internal
, cg_cpu_shares_parse
, uint64_t, "Invalid CPU shares");
152 DEFINE_CONFIG_PARSE_PTR(config_parse_exec_mount_flags
, mount_propagation_flags_from_string
, unsigned long, "Failed to parse mount flag");
153 DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_numa_policy
, mpol
, int, -1, "Invalid NUMA policy type");
154 DEFINE_CONFIG_PARSE_ENUM(config_parse_status_unit_format
, status_unit_format
, StatusUnitFormat
, "Failed to parse status unit format");
155 DEFINE_CONFIG_PARSE_ENUM_FULL(config_parse_socket_timestamping
, socket_timestamping_from_string_harder
, SocketTimestamping
, "Failed to parse timestamping precision");
157 int config_parse_cpu_shares(
159 const char *filename
,
162 unsigned section_line
,
174 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
175 "Unit uses %s=; please use CPUWeight= instead. Support for %s= will be removed soon.",
178 return config_parse_cpu_shares_internal(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
);
181 bool contains_instance_specifier_superset(const char *s
) {
183 bool percent
= false;
197 /* If the string is just the instance specifier, it's not a superset of the instance. */
198 if (memcmp_nn(p
, q
- p
, "%i", strlen("%i")) == 0)
201 /* %i, %n and %N all expand to the instance or a superset of it. */
206 if (IN_SET(*p
, 'n', 'N', 'i'))
215 /* `name` is the rendered version of `format` via `unit_printf` or similar functions. */
216 int unit_is_likely_recursive_template_dependency(Unit
*u
, const char *name
, const char *format
) {
217 const char *fragment_path
;
223 /* If a template unit has a direct dependency on itself that includes the unit instance as part of
224 * the template instance via a unit specifier (%i, %n or %N), this will almost certainly lead to
225 * infinite recursion as systemd will keep instantiating new instances of the template unit.
226 * https://github.com/systemd/systemd/issues/17602 shows a good example of how this can happen in
227 * practice. To guard against this, we check for templates that depend on themselves and have the
228 * instantiated unit instance included as part of the template instance of the dependency via a
231 * For example, if systemd-notify@.service depends on systemd-notify@%n.service, this will result in
232 * infinite recursion.
235 if (!unit_name_is_valid(name
, UNIT_NAME_INSTANCE
))
238 if (!unit_name_prefix_equal(u
->id
, name
))
241 if (u
->type
!= unit_name_to_type(name
))
244 r
= unit_file_find_fragment(u
->manager
->unit_id_map
, u
->manager
->unit_name_map
, name
, &fragment_path
, NULL
);
248 /* Fragment paths should also be equal as a custom fragment for a specific template instance
249 * wouldn't necessarily lead to infinite recursion. */
250 if (!path_equal_ptr(u
->fragment_path
, fragment_path
))
253 if (!contains_instance_specifier_superset(format
))
259 int config_parse_unit_deps(
261 const char *filename
,
264 unsigned section_line
,
271 UnitDependency d
= ltype
;
278 for (const char *p
= rvalue
;;) {
279 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
282 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_RETAIN_ESCAPE
);
288 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
292 r
= unit_name_printf(u
, word
, &k
);
294 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
298 r
= unit_is_likely_recursive_template_dependency(u
, k
, word
);
300 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to determine if '%s' is a recursive dependency, ignoring: %m", k
);
304 log_syntax(unit
, LOG_DEBUG
, filename
, line
, 0,
305 "Dropping dependency %s=%s that likely leads to infinite recursion.",
306 unit_dependency_to_string(d
), word
);
310 r
= unit_add_dependency_by_name(u
, d
, k
, true, UNIT_DEPENDENCY_FILE
);
312 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
316 int config_parse_obsolete_unit_deps(
318 const char *filename
,
321 unsigned section_line
,
328 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
329 "Unit dependency type %s= is obsolete, replacing by %s=, please update your unit file", lvalue
, unit_dependency_to_string(ltype
));
331 return config_parse_unit_deps(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
);
334 int config_parse_unit_string_printf(
336 const char *filename
,
339 unsigned section_line
,
346 _cleanup_free_
char *k
= NULL
;
347 const Unit
*u
= ASSERT_PTR(userdata
);
354 r
= unit_full_printf(u
, rvalue
, &k
);
356 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
360 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
363 int config_parse_unit_strv_printf(
365 const char *filename
,
368 unsigned section_line
,
375 const Unit
*u
= ASSERT_PTR(userdata
);
376 _cleanup_free_
char *k
= NULL
;
383 r
= unit_full_printf(u
, rvalue
, &k
);
385 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
389 return config_parse_strv(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
392 int config_parse_unit_path_printf(
394 const char *filename
,
397 unsigned section_line
,
404 _cleanup_free_
char *k
= NULL
;
405 const Unit
*u
= ASSERT_PTR(userdata
);
413 r
= unit_path_printf(u
, rvalue
, &k
);
415 log_syntax(unit
, fatal
? LOG_ERR
: LOG_WARNING
, filename
, line
, r
,
416 "Failed to resolve unit specifiers in '%s'%s: %m",
417 rvalue
, fatal
? "" : ", ignoring");
418 return fatal
? -ENOEXEC
: 0;
421 return config_parse_path(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
424 int config_parse_colon_separated_paths(
426 const char *filename
,
429 unsigned section_line
,
435 char ***sv
= ASSERT_PTR(data
);
436 const Unit
*u
= userdata
;
443 if (isempty(rvalue
)) {
444 /* Empty assignment resets the list */
445 *sv
= strv_free(*sv
);
449 for (const char *p
= rvalue
;;) {
450 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
452 r
= extract_first_word(&p
, &word
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
456 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
462 r
= unit_path_printf(u
, word
, &k
);
464 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
465 "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
469 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
473 r
= strv_consume(sv
, TAKE_PTR(k
));
481 int config_parse_unit_path_strv_printf(
483 const char *filename
,
486 unsigned section_line
,
494 const Unit
*u
= ASSERT_PTR(userdata
);
501 if (isempty(rvalue
)) {
506 for (const char *p
= rvalue
;;) {
507 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
509 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
515 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
516 "Invalid syntax, ignoring: %s", rvalue
);
520 r
= unit_path_printf(u
, word
, &k
);
522 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
523 "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
527 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
531 r
= strv_consume(x
, TAKE_PTR(k
));
537 static int patch_var_run(
539 const char *filename
,
547 e
= path_startswith(*path
, "/var/run/");
551 z
= path_join("/run/", e
);
555 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
556 "%s= references a path below legacy directory /var/run/, updating %s → %s; "
557 "please update the unit file accordingly.", lvalue
, *path
, z
);
559 free_and_replace(*path
, z
);
564 int config_parse_socket_listen(
566 const char *filename
,
569 unsigned section_line
,
576 _cleanup_free_ SocketPort
*p
= NULL
;
588 if (isempty(rvalue
)) {
589 /* An empty assignment removes all ports */
590 socket_free_ports(s
);
594 p
= new0(SocketPort
, 1);
598 if (ltype
!= SOCKET_SOCKET
) {
599 _cleanup_free_
char *k
= NULL
;
601 r
= unit_path_printf(UNIT(s
), rvalue
, &k
);
603 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
607 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
611 if (ltype
== SOCKET_FIFO
) {
612 r
= patch_var_run(unit
, filename
, line
, lvalue
, &k
);
617 free_and_replace(p
->path
, k
);
620 } else if (streq(lvalue
, "ListenNetlink")) {
621 _cleanup_free_
char *k
= NULL
;
623 r
= unit_path_printf(UNIT(s
), rvalue
, &k
);
625 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
629 r
= socket_address_parse_netlink(&p
->address
, k
);
631 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse address value in '%s', ignoring: %m", k
);
635 p
->type
= SOCKET_SOCKET
;
638 _cleanup_free_
char *k
= NULL
;
640 r
= unit_path_printf(UNIT(s
), rvalue
, &k
);
642 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
646 if (k
[0] == '/') { /* Only for AF_UNIX file system sockets… */
647 r
= patch_var_run(unit
, filename
, line
, lvalue
, &k
);
652 r
= socket_address_parse_and_warn(&p
->address
, k
);
654 if (r
!= -EAFNOSUPPORT
)
655 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse address value in '%s', ignoring: %m", k
);
659 if (streq(lvalue
, "ListenStream"))
660 p
->address
.type
= SOCK_STREAM
;
661 else if (streq(lvalue
, "ListenDatagram"))
662 p
->address
.type
= SOCK_DGRAM
;
664 assert(streq(lvalue
, "ListenSequentialPacket"));
665 p
->address
.type
= SOCK_SEQPACKET
;
668 if (socket_address_family(&p
->address
) != AF_UNIX
&& p
->address
.type
== SOCK_SEQPACKET
) {
669 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Address family not supported, ignoring: %s", rvalue
);
673 p
->type
= SOCKET_SOCKET
;
677 p
->auxiliary_fds
= NULL
;
678 p
->n_auxiliary_fds
= 0;
681 LIST_FIND_TAIL(port
, s
->ports
, tail
);
682 LIST_INSERT_AFTER(port
, s
->ports
, tail
, p
);
689 int config_parse_exec_nice(
691 const char *filename
,
694 unsigned section_line
,
701 ExecContext
*c
= ASSERT_PTR(data
);
708 if (isempty(rvalue
)) {
713 r
= parse_nice(rvalue
, &priority
);
716 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Nice priority out of range, ignoring: %s", rvalue
);
718 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse nice priority '%s', ignoring: %m", rvalue
);
728 int config_parse_exec_oom_score_adjust(
730 const char *filename
,
733 unsigned section_line
,
740 ExecContext
*c
= ASSERT_PTR(data
);
747 if (isempty(rvalue
)) {
748 c
->oom_score_adjust_set
= false;
752 r
= parse_oom_score_adjust(rvalue
, &oa
);
755 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "OOM score adjust value out of range, ignoring: %s", rvalue
);
757 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse the OOM score adjust value '%s', ignoring: %m", rvalue
);
761 c
->oom_score_adjust
= oa
;
762 c
->oom_score_adjust_set
= true;
767 int config_parse_exec_coredump_filter(
769 const char *filename
,
772 unsigned section_line
,
779 ExecContext
*c
= ASSERT_PTR(data
);
786 if (isempty(rvalue
)) {
787 c
->coredump_filter
= 0;
788 c
->coredump_filter_set
= false;
793 r
= coredump_filter_mask_from_string(rvalue
, &f
);
795 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
796 "Failed to parse the CoredumpFilter=%s, ignoring: %m", rvalue
);
800 c
->coredump_filter
|= f
;
801 c
->oom_score_adjust_set
= true;
805 int config_parse_kill_mode(
807 const char *filename
,
810 unsigned section_line
,
817 KillMode
*k
= data
, m
;
824 if (isempty(rvalue
)) {
825 *k
= KILL_CONTROL_GROUP
;
829 m
= kill_mode_from_string(rvalue
);
831 log_syntax(unit
, LOG_WARNING
, filename
, line
, m
,
832 "Failed to parse kill mode specification, ignoring: %s", rvalue
);
837 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
838 "Unit uses KillMode=none. "
839 "This is unsafe, as it disables systemd's process lifecycle management for the service. "
840 "Please update the service to use a safer KillMode=, such as 'mixed' or 'control-group'. "
841 "Support for KillMode=none is deprecated and will eventually be removed.");
847 int config_parse_exec(
849 const char *filename
,
852 unsigned section_line
,
859 ExecCommand
**e
= ASSERT_PTR(data
);
860 const Unit
*u
= userdata
;
871 if (isempty(rvalue
)) {
872 /* An empty assignment resets the list */
873 *e
= exec_command_free_list(*e
);
879 _cleanup_free_
char *path
= NULL
, *firstword
= NULL
;
880 ExecCommandFlags flags
= 0;
881 bool ignore
= false, separate_argv0
= false;
882 _cleanup_free_ ExecCommand
*nce
= NULL
;
883 _cleanup_strv_free_
char **n
= NULL
;
889 r
= extract_first_word_and_warn(&p
, &firstword
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
893 /* A lone ";" is a separator. Let's make sure we don't treat it as an executable name. */
894 if (streq(firstword
, ";")) {
901 /* We accept an absolute path as first argument. If it's prefixed with - and the path doesn't
902 * exist, we ignore it instead of erroring out; if it's prefixed with @, we allow overriding of
903 * argv[0]; if it's prefixed with :, we will not do environment variable substitution;
904 * if it's prefixed with +, it will be run with full privileges and no sandboxing; if
905 * it's prefixed with '!' we apply sandboxing, but do not change user/group credentials; if
906 * it's prefixed with '!!', then we apply user/group credentials if the kernel supports ambient
907 * capabilities -- if it doesn't we don't apply the credentials themselves, but do apply most
908 * other sandboxing, with some special exceptions for changing UID.
910 * The idea is that '!!' may be used to write services that can take benefit of systemd's
911 * UID/GID dropping if the kernel supports ambient creds, but provide an automatic fallback to
912 * privilege dropping within the daemon if the kernel does not offer that. */
914 if (*f
== '-' && !(flags
& EXEC_COMMAND_IGNORE_FAILURE
)) {
915 flags
|= EXEC_COMMAND_IGNORE_FAILURE
;
917 } else if (*f
== '@' && !separate_argv0
)
918 separate_argv0
= true;
919 else if (*f
== ':' && !(flags
& EXEC_COMMAND_NO_ENV_EXPAND
))
920 flags
|= EXEC_COMMAND_NO_ENV_EXPAND
;
921 else if (*f
== '+' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
922 flags
|= EXEC_COMMAND_FULLY_PRIVILEGED
;
923 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
924 flags
|= EXEC_COMMAND_NO_SETUID
;
925 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_AMBIENT_MAGIC
))) {
926 flags
&= ~EXEC_COMMAND_NO_SETUID
;
927 flags
|= EXEC_COMMAND_AMBIENT_MAGIC
;
933 r
= unit_path_printf(u
, f
, &path
);
935 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
936 "Failed to resolve unit specifiers in '%s'%s: %m",
937 f
, ignore
? ", ignoring" : "");
938 return ignore
? 0 : -ENOEXEC
;
942 /* First word is either "-" or "@" with no command. */
943 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
944 "Empty path in command line%s: '%s'",
945 ignore
? ", ignoring" : "", rvalue
);
946 return ignore
? 0 : -ENOEXEC
;
948 if (!string_is_safe(path
)) {
949 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
950 "Executable name contains special characters%s: %s",
951 ignore
? ", ignoring" : "", path
);
952 return ignore
? 0 : -ENOEXEC
;
954 if (endswith(path
, "/")) {
955 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
956 "Executable path specifies a directory%s: %s",
957 ignore
? ", ignoring" : "", path
);
958 return ignore
? 0 : -ENOEXEC
;
961 if (!(path_is_absolute(path
) ? path_is_valid(path
) : filename_is_valid(path
))) {
962 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
963 "Neither a valid executable name nor an absolute path%s: %s",
964 ignore
? ", ignoring" : "", path
);
965 return ignore
? 0 : -ENOEXEC
;
968 if (!separate_argv0
) {
971 if (!GREEDY_REALLOC0(n
, nlen
+ 2))
983 while (!isempty(p
)) {
984 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
986 /* Check explicitly for an unquoted semicolon as
987 * command separator token. */
988 if (p
[0] == ';' && (!p
[1] || strchr(WHITESPACE
, p
[1]))) {
990 p
+= strspn(p
, WHITESPACE
);
995 /* Check for \; explicitly, to not confuse it with \\; or "\;" or "\\;" etc.
996 * extract_first_word() would return the same for all of those. */
997 if (p
[0] == '\\' && p
[1] == ';' && (!p
[2] || strchr(WHITESPACE
, p
[2]))) {
1001 p
+= strspn(p
, WHITESPACE
);
1003 if (!GREEDY_REALLOC0(n
, nlen
+ 2))
1014 r
= extract_first_word_and_warn(&p
, &word
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
1018 return ignore
? 0 : -ENOEXEC
;
1020 r
= unit_full_printf(u
, word
, &resolved
);
1022 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
1023 "Failed to resolve unit specifiers in %s%s: %m",
1024 word
, ignore
? ", ignoring" : "");
1025 return ignore
? 0 : -ENOEXEC
;
1028 if (!GREEDY_REALLOC(n
, nlen
+ 2))
1031 n
[nlen
++] = TAKE_PTR(resolved
);
1036 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
1037 "Empty executable name or zeroeth argument%s: %s",
1038 ignore
? ", ignoring" : "", rvalue
);
1039 return ignore
? 0 : -ENOEXEC
;
1042 nce
= new0(ExecCommand
, 1);
1046 nce
->argv
= TAKE_PTR(n
);
1047 nce
->path
= TAKE_PTR(path
);
1050 exec_command_append_list(e
, nce
);
1052 /* Do not _cleanup_free_ these. */
1056 } while (semicolon
);
1061 int config_parse_socket_bindtodevice(
1063 const char *filename
,
1065 const char *section
,
1066 unsigned section_line
,
1073 Socket
*s
= ASSERT_PTR(data
);
1079 if (isempty(rvalue
) || streq(rvalue
, "*")) {
1080 s
->bind_to_device
= mfree(s
->bind_to_device
);
1084 if (!ifname_valid(rvalue
)) {
1085 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid interface name, ignoring: %s", rvalue
);
1089 return free_and_strdup_warn(&s
->bind_to_device
, rvalue
);
1092 int config_parse_exec_input(
1094 const char *filename
,
1096 const char *section
,
1097 unsigned section_line
,
1104 ExecContext
*c
= ASSERT_PTR(data
);
1105 const Unit
*u
= userdata
;
1114 n
= startswith(rvalue
, "fd:");
1116 _cleanup_free_
char *resolved
= NULL
;
1118 r
= unit_fd_printf(u
, n
, &resolved
);
1120 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", n
);
1124 if (isempty(resolved
))
1125 resolved
= mfree(resolved
);
1126 else if (!fdname_is_valid(resolved
)) {
1127 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", resolved
);
1131 free_and_replace(c
->stdio_fdname
[STDIN_FILENO
], resolved
);
1133 ei
= EXEC_INPUT_NAMED_FD
;
1135 } else if ((n
= startswith(rvalue
, "file:"))) {
1136 _cleanup_free_
char *resolved
= NULL
;
1138 r
= unit_path_printf(u
, n
, &resolved
);
1140 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", n
);
1144 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1148 free_and_replace(c
->stdio_file
[STDIN_FILENO
], resolved
);
1150 ei
= EXEC_INPUT_FILE
;
1153 ei
= exec_input_from_string(rvalue
);
1155 log_syntax(unit
, LOG_WARNING
, filename
, line
, ei
, "Failed to parse input specifier, ignoring: %s", rvalue
);
1164 int config_parse_exec_input_text(
1166 const char *filename
,
1168 const char *section
,
1169 unsigned section_line
,
1176 _cleanup_free_
char *unescaped
= NULL
, *resolved
= NULL
;
1177 ExecContext
*c
= ASSERT_PTR(data
);
1178 const Unit
*u
= userdata
;
1185 if (isempty(rvalue
)) {
1186 /* Reset if the empty string is assigned */
1187 c
->stdin_data
= mfree(c
->stdin_data
);
1188 c
->stdin_data_size
= 0;
1192 ssize_t l
= cunescape(rvalue
, 0, &unescaped
);
1194 log_syntax(unit
, LOG_WARNING
, filename
, line
, l
,
1195 "Failed to decode C escaped text '%s', ignoring: %m", rvalue
);
1199 r
= unit_full_printf_full(u
, unescaped
, EXEC_STDIN_DATA_MAX
, &resolved
);
1201 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1202 "Failed to resolve unit specifiers in '%s', ignoring: %m", unescaped
);
1206 size_t sz
= strlen(resolved
);
1207 if (c
->stdin_data_size
+ sz
+ 1 < c
->stdin_data_size
|| /* check for overflow */
1208 c
->stdin_data_size
+ sz
+ 1 > EXEC_STDIN_DATA_MAX
) {
1209 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
1210 "Standard input data too large (%zu), maximum of %zu permitted, ignoring.",
1211 c
->stdin_data_size
+ sz
, (size_t) EXEC_STDIN_DATA_MAX
);
1215 void *p
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
+ 1);
1219 *((char*) mempcpy((char*) p
+ c
->stdin_data_size
, resolved
, sz
)) = '\n';
1222 c
->stdin_data_size
+= sz
+ 1;
1227 int config_parse_exec_input_data(
1229 const char *filename
,
1231 const char *section
,
1232 unsigned section_line
,
1239 _cleanup_free_
void *p
= NULL
;
1240 ExecContext
*c
= ASSERT_PTR(data
);
1249 if (isempty(rvalue
)) {
1250 /* Reset if the empty string is assigned */
1251 c
->stdin_data
= mfree(c
->stdin_data
);
1252 c
->stdin_data_size
= 0;
1256 r
= unbase64mem(rvalue
, SIZE_MAX
, &p
, &sz
);
1258 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1259 "Failed to decode base64 data, ignoring: %s", rvalue
);
1265 if (c
->stdin_data_size
+ sz
< c
->stdin_data_size
|| /* check for overflow */
1266 c
->stdin_data_size
+ sz
> EXEC_STDIN_DATA_MAX
) {
1267 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
1268 "Standard input data too large (%zu), maximum of %zu permitted, ignoring.",
1269 c
->stdin_data_size
+ sz
, (size_t) EXEC_STDIN_DATA_MAX
);
1273 q
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
);
1277 memcpy((uint8_t*) q
+ c
->stdin_data_size
, p
, sz
);
1280 c
->stdin_data_size
+= sz
;
1285 int config_parse_exec_output(
1287 const char *filename
,
1289 const char *section
,
1290 unsigned section_line
,
1297 _cleanup_free_
char *resolved
= NULL
;
1299 ExecContext
*c
= ASSERT_PTR(data
);
1300 const Unit
*u
= userdata
;
1301 bool obsolete
= false;
1310 n
= startswith(rvalue
, "fd:");
1312 r
= unit_fd_printf(u
, n
, &resolved
);
1314 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", n
);
1318 if (isempty(resolved
))
1319 resolved
= mfree(resolved
);
1320 else if (!fdname_is_valid(resolved
)) {
1321 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", resolved
);
1325 eo
= EXEC_OUTPUT_NAMED_FD
;
1327 } else if (streq(rvalue
, "syslog")) {
1328 eo
= EXEC_OUTPUT_JOURNAL
;
1331 } else if (streq(rvalue
, "syslog+console")) {
1332 eo
= EXEC_OUTPUT_JOURNAL_AND_CONSOLE
;
1335 } else if ((n
= startswith(rvalue
, "file:"))) {
1337 r
= unit_path_printf(u
, n
, &resolved
);
1339 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", n
);
1343 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1347 eo
= EXEC_OUTPUT_FILE
;
1349 } else if ((n
= startswith(rvalue
, "append:"))) {
1351 r
= unit_path_printf(u
, n
, &resolved
);
1353 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", n
);
1357 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1361 eo
= EXEC_OUTPUT_FILE_APPEND
;
1363 } else if ((n
= startswith(rvalue
, "truncate:"))) {
1365 r
= unit_path_printf(u
, n
, &resolved
);
1367 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", n
);
1371 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1375 eo
= EXEC_OUTPUT_FILE_TRUNCATE
;
1377 eo
= exec_output_from_string(rvalue
);
1379 log_syntax(unit
, LOG_WARNING
, filename
, line
, eo
, "Failed to parse output specifier, ignoring: %s", rvalue
);
1385 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
1386 "Standard output type %s is obsolete, automatically updating to %s. Please update your unit file, and consider removing the setting altogether.",
1387 rvalue
, exec_output_to_string(eo
));
1389 if (streq(lvalue
, "StandardOutput")) {
1390 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1391 free_and_replace(c
->stdio_fdname
[STDOUT_FILENO
], resolved
);
1393 free_and_replace(c
->stdio_file
[STDOUT_FILENO
], resolved
);
1398 assert(streq(lvalue
, "StandardError"));
1400 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1401 free_and_replace(c
->stdio_fdname
[STDERR_FILENO
], resolved
);
1403 free_and_replace(c
->stdio_file
[STDERR_FILENO
], resolved
);
1411 int config_parse_exec_io_class(const char *unit
,
1412 const char *filename
,
1414 const char *section
,
1415 unsigned section_line
,
1422 ExecContext
*c
= ASSERT_PTR(data
);
1429 if (isempty(rvalue
)) {
1430 c
->ioprio_set
= false;
1431 c
->ioprio
= IOPRIO_DEFAULT_CLASS_AND_PRIO
;
1435 x
= ioprio_class_from_string(rvalue
);
1437 log_syntax(unit
, LOG_WARNING
, filename
, line
, x
, "Failed to parse IO scheduling class, ignoring: %s", rvalue
);
1441 c
->ioprio
= ioprio_normalize(ioprio_prio_value(x
, ioprio_prio_data(c
->ioprio
)));
1442 c
->ioprio_set
= true;
1447 int config_parse_exec_io_priority(const char *unit
,
1448 const char *filename
,
1450 const char *section
,
1451 unsigned section_line
,
1458 ExecContext
*c
= ASSERT_PTR(data
);
1465 if (isempty(rvalue
)) {
1466 c
->ioprio_set
= false;
1467 c
->ioprio
= IOPRIO_DEFAULT_CLASS_AND_PRIO
;
1471 r
= ioprio_parse_priority(rvalue
, &i
);
1473 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse IO priority, ignoring: %s", rvalue
);
1477 c
->ioprio
= ioprio_normalize(ioprio_prio_value(ioprio_prio_class(c
->ioprio
), i
));
1478 c
->ioprio_set
= true;
1483 int config_parse_exec_cpu_sched_policy(const char *unit
,
1484 const char *filename
,
1486 const char *section
,
1487 unsigned section_line
,
1494 ExecContext
*c
= ASSERT_PTR(data
);
1501 if (isempty(rvalue
)) {
1502 c
->cpu_sched_set
= false;
1503 c
->cpu_sched_policy
= SCHED_OTHER
;
1504 c
->cpu_sched_priority
= 0;
1508 x
= sched_policy_from_string(rvalue
);
1510 log_syntax(unit
, LOG_WARNING
, filename
, line
, x
, "Failed to parse CPU scheduling policy, ignoring: %s", rvalue
);
1514 c
->cpu_sched_policy
= x
;
1515 /* Moving to or from real-time policy? We need to adjust the priority */
1516 c
->cpu_sched_priority
= CLAMP(c
->cpu_sched_priority
, sched_get_priority_min(x
), sched_get_priority_max(x
));
1517 c
->cpu_sched_set
= true;
1522 int config_parse_exec_mount_apivfs(const char *unit
,
1523 const char *filename
,
1525 const char *section
,
1526 unsigned section_line
,
1533 ExecContext
*c
= ASSERT_PTR(data
);
1540 if (isempty(rvalue
)) {
1541 c
->mount_apivfs_set
= false;
1542 c
->mount_apivfs
= false;
1546 k
= parse_boolean(rvalue
);
1548 log_syntax(unit
, LOG_WARNING
, filename
, line
, k
,
1549 "Failed to parse boolean value, ignoring: %s",
1554 c
->mount_apivfs_set
= true;
1555 c
->mount_apivfs
= k
;
1559 int config_parse_numa_mask(const char *unit
,
1560 const char *filename
,
1562 const char *section
,
1563 unsigned section_line
,
1570 NUMAPolicy
*p
= ASSERT_PTR(data
);
1576 if (streq(rvalue
, "all")) {
1577 r
= numa_mask_add_all(&p
->nodes
);
1579 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1580 "Failed to create NUMA mask representing \"all\" NUMA nodes, ignoring: %m");
1582 r
= parse_cpu_set_extend(rvalue
, &p
->nodes
, true, unit
, filename
, line
, lvalue
);
1584 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse NUMA node mask, ignoring: %s", rvalue
);
1590 int config_parse_exec_cpu_sched_prio(const char *unit
,
1591 const char *filename
,
1593 const char *section
,
1594 unsigned section_line
,
1601 ExecContext
*c
= ASSERT_PTR(data
);
1608 r
= safe_atoi(rvalue
, &i
);
1610 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse CPU scheduling priority, ignoring: %s", rvalue
);
1614 /* On Linux RR/FIFO range from 1 to 99 and OTHER/BATCH may only be 0. Policy might be set later so
1615 * we do not check the precise range, but only the generic outer bounds. */
1616 if (i
< 0 || i
> 99) {
1617 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "CPU scheduling priority is out of range, ignoring: %s", rvalue
);
1621 c
->cpu_sched_priority
= i
;
1622 c
->cpu_sched_set
= true;
1627 int config_parse_root_image_options(
1629 const char *filename
,
1631 const char *section
,
1632 unsigned section_line
,
1639 _cleanup_(mount_options_free_allp
) MountOptions
*options
= NULL
;
1640 _cleanup_strv_free_
char **l
= NULL
;
1641 ExecContext
*c
= ASSERT_PTR(data
);
1642 const Unit
*u
= userdata
;
1649 if (isempty(rvalue
)) {
1650 c
->root_image_options
= mount_options_free_all(c
->root_image_options
);
1654 r
= strv_split_colon_pairs(&l
, rvalue
);
1658 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
1662 STRV_FOREACH_PAIR(first
, second
, l
) {
1663 MountOptions
*o
= NULL
;
1664 _cleanup_free_
char *mount_options_resolved
= NULL
;
1665 const char *mount_options
= NULL
, *partition
= "root";
1666 PartitionDesignator partition_designator
;
1668 /* Format is either 'root:foo' or 'foo' (root is implied) */
1669 if (!isempty(*second
)) {
1671 mount_options
= *second
;
1673 mount_options
= *first
;
1675 partition_designator
= partition_designator_from_string(partition
);
1676 if (partition_designator
< 0) {
1677 log_syntax(unit
, LOG_WARNING
, filename
, line
, partition_designator
,
1678 "Invalid partition name %s, ignoring", partition
);
1681 r
= unit_full_printf(u
, mount_options
, &mount_options_resolved
);
1683 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", mount_options
);
1687 o
= new(MountOptions
, 1);
1690 *o
= (MountOptions
) {
1691 .partition_designator
= partition_designator
,
1692 .options
= TAKE_PTR(mount_options_resolved
),
1694 LIST_APPEND(mount_options
, options
, TAKE_PTR(o
));
1698 LIST_JOIN(mount_options
, c
->root_image_options
, options
);
1700 /* empty spaces/separators only */
1701 c
->root_image_options
= mount_options_free_all(c
->root_image_options
);
1706 int config_parse_exec_root_hash(
1708 const char *filename
,
1710 const char *section
,
1711 unsigned section_line
,
1718 _cleanup_free_
void *roothash_decoded
= NULL
;
1719 ExecContext
*c
= ASSERT_PTR(data
);
1720 size_t roothash_decoded_size
= 0;
1727 if (isempty(rvalue
)) {
1728 /* Reset if the empty string is assigned */
1729 c
->root_hash_path
= mfree(c
->root_hash_path
);
1730 c
->root_hash
= mfree(c
->root_hash
);
1731 c
->root_hash_size
= 0;
1735 if (path_is_absolute(rvalue
)) {
1736 /* We have the path to a roothash to load and decode, eg: RootHash=/foo/bar.roothash */
1737 _cleanup_free_
char *p
= NULL
;
1743 free_and_replace(c
->root_hash_path
, p
);
1744 c
->root_hash
= mfree(c
->root_hash
);
1745 c
->root_hash_size
= 0;
1749 /* We have a roothash to decode, eg: RootHash=012345789abcdef */
1750 r
= unhexmem(rvalue
, strlen(rvalue
), &roothash_decoded
, &roothash_decoded_size
);
1752 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to decode RootHash=, ignoring: %s", rvalue
);
1755 if (roothash_decoded_size
< sizeof(sd_id128_t
)) {
1756 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "RootHash= is too short, ignoring: %s", rvalue
);
1760 free_and_replace(c
->root_hash
, roothash_decoded
);
1761 c
->root_hash_size
= roothash_decoded_size
;
1762 c
->root_hash_path
= mfree(c
->root_hash_path
);
1767 int config_parse_exec_root_hash_sig(
1769 const char *filename
,
1771 const char *section
,
1772 unsigned section_line
,
1779 _cleanup_free_
void *roothash_sig_decoded
= NULL
;
1781 ExecContext
*c
= ASSERT_PTR(data
);
1782 size_t roothash_sig_decoded_size
= 0;
1789 if (isempty(rvalue
)) {
1790 /* Reset if the empty string is assigned */
1791 c
->root_hash_sig_path
= mfree(c
->root_hash_sig_path
);
1792 c
->root_hash_sig
= mfree(c
->root_hash_sig
);
1793 c
->root_hash_sig_size
= 0;
1797 if (path_is_absolute(rvalue
)) {
1798 /* We have the path to a roothash signature to load and decode, eg: RootHashSignature=/foo/bar.roothash.p7s */
1799 _cleanup_free_
char *p
= NULL
;
1805 free_and_replace(c
->root_hash_sig_path
, p
);
1806 c
->root_hash_sig
= mfree(c
->root_hash_sig
);
1807 c
->root_hash_sig_size
= 0;
1811 if (!(value
= startswith(rvalue
, "base64:"))) {
1812 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
1813 "Failed to decode RootHashSignature=, not a path but doesn't start with 'base64:', ignoring: %s", rvalue
);
1817 /* We have a roothash signature to decode, eg: RootHashSignature=base64:012345789abcdef */
1818 r
= unbase64mem(value
, strlen(value
), &roothash_sig_decoded
, &roothash_sig_decoded_size
);
1820 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to decode RootHashSignature=, ignoring: %s", rvalue
);
1824 free_and_replace(c
->root_hash_sig
, roothash_sig_decoded
);
1825 c
->root_hash_sig_size
= roothash_sig_decoded_size
;
1826 c
->root_hash_sig_path
= mfree(c
->root_hash_sig_path
);
1831 int config_parse_exec_cpu_affinity(
1833 const char *filename
,
1835 const char *section
,
1836 unsigned section_line
,
1843 ExecContext
*c
= ASSERT_PTR(data
);
1844 const Unit
*u
= userdata
;
1845 _cleanup_free_
char *k
= NULL
;
1852 if (streq(rvalue
, "numa")) {
1853 c
->cpu_affinity_from_numa
= true;
1854 cpu_set_reset(&c
->cpu_set
);
1859 r
= unit_full_printf(u
, rvalue
, &k
);
1861 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1862 "Failed to resolve unit specifiers in '%s', ignoring: %m",
1867 r
= parse_cpu_set_extend(k
, &c
->cpu_set
, true, unit
, filename
, line
, lvalue
);
1869 c
->cpu_affinity_from_numa
= false;
1874 int config_parse_capability_set(
1876 const char *filename
,
1878 const char *section
,
1879 unsigned section_line
,
1886 uint64_t *capability_set
= ASSERT_PTR(data
);
1887 uint64_t sum
= 0, initial
= 0;
1888 bool invert
= false;
1895 if (rvalue
[0] == '~') {
1900 if (streq(lvalue
, "CapabilityBoundingSet"))
1901 initial
= CAP_ALL
; /* initialized to all bits on */
1902 /* else "AmbientCapabilities" initialized to all bits off */
1904 r
= capability_set_from_string(rvalue
, &sum
);
1906 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= specifier '%s', ignoring: %m", lvalue
, rvalue
);
1910 if (sum
== 0 || *capability_set
== initial
)
1911 /* "", "~" or uninitialized data -> replace */
1912 *capability_set
= invert
? ~sum
: sum
;
1914 /* previous data -> merge */
1916 *capability_set
&= ~sum
;
1918 *capability_set
|= sum
;
1924 int config_parse_exec_selinux_context(
1926 const char *filename
,
1928 const char *section
,
1929 unsigned section_line
,
1936 ExecContext
*c
= ASSERT_PTR(data
);
1937 const Unit
*u
= userdata
;
1946 if (isempty(rvalue
)) {
1947 c
->selinux_context
= mfree(c
->selinux_context
);
1948 c
->selinux_context_ignore
= false;
1952 if (rvalue
[0] == '-') {
1958 r
= unit_full_printf(u
, rvalue
, &k
);
1960 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
1961 "Failed to resolve unit specifiers in '%s'%s: %m",
1962 rvalue
, ignore
? ", ignoring" : "");
1963 return ignore
? 0 : -ENOEXEC
;
1966 free_and_replace(c
->selinux_context
, k
);
1967 c
->selinux_context_ignore
= ignore
;
1972 int config_parse_exec_apparmor_profile(
1974 const char *filename
,
1976 const char *section
,
1977 unsigned section_line
,
1984 ExecContext
*c
= ASSERT_PTR(data
);
1985 const Unit
*u
= userdata
;
1994 if (isempty(rvalue
)) {
1995 c
->apparmor_profile
= mfree(c
->apparmor_profile
);
1996 c
->apparmor_profile_ignore
= false;
2000 if (rvalue
[0] == '-') {
2006 r
= unit_full_printf(u
, rvalue
, &k
);
2008 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
2009 "Failed to resolve unit specifiers in '%s'%s: %m",
2010 rvalue
, ignore
? ", ignoring" : "");
2011 return ignore
? 0 : -ENOEXEC
;
2014 free_and_replace(c
->apparmor_profile
, k
);
2015 c
->apparmor_profile_ignore
= ignore
;
2020 int config_parse_exec_smack_process_label(
2022 const char *filename
,
2024 const char *section
,
2025 unsigned section_line
,
2032 ExecContext
*c
= ASSERT_PTR(data
);
2033 const Unit
*u
= userdata
;
2042 if (isempty(rvalue
)) {
2043 c
->smack_process_label
= mfree(c
->smack_process_label
);
2044 c
->smack_process_label_ignore
= false;
2048 if (rvalue
[0] == '-') {
2054 r
= unit_full_printf(u
, rvalue
, &k
);
2056 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
2057 "Failed to resolve unit specifiers in '%s'%s: %m",
2058 rvalue
, ignore
? ", ignoring" : "");
2059 return ignore
? 0 : -ENOEXEC
;
2062 free_and_replace(c
->smack_process_label
, k
);
2063 c
->smack_process_label_ignore
= ignore
;
2068 int config_parse_timer(
2070 const char *filename
,
2072 const char *section
,
2073 unsigned section_line
,
2080 _cleanup_(calendar_spec_freep
) CalendarSpec
*c
= NULL
;
2081 _cleanup_free_
char *k
= NULL
;
2082 const Unit
*u
= userdata
;
2083 Timer
*t
= ASSERT_PTR(data
);
2092 if (isempty(rvalue
)) {
2093 /* Empty assignment resets list */
2094 timer_free_values(t
);
2098 r
= unit_full_printf(u
, rvalue
, &k
);
2100 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2104 if (ltype
== TIMER_CALENDAR
) {
2105 r
= calendar_spec_from_string(k
, &c
);
2107 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse calendar specification, ignoring: %s", k
);
2111 r
= parse_sec(k
, &usec
);
2113 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse timer value, ignoring: %s", k
);
2118 v
= new(TimerValue
, 1);
2125 .calendar_spec
= TAKE_PTR(c
),
2128 LIST_PREPEND(value
, t
->values
, v
);
2133 int config_parse_trigger_unit(
2135 const char *filename
,
2137 const char *section
,
2138 unsigned section_line
,
2145 _cleanup_free_
char *p
= NULL
;
2146 Unit
*u
= ASSERT_PTR(data
);
2154 if (UNIT_TRIGGER(u
)) {
2155 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Multiple units to trigger specified, ignoring: %s", rvalue
);
2159 r
= unit_name_printf(u
, rvalue
, &p
);
2161 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2165 type
= unit_name_to_type(p
);
2167 log_syntax(unit
, LOG_WARNING
, filename
, line
, type
, "Unit type not valid, ignoring: %s", rvalue
);
2170 if (unit_has_name(u
, p
)) {
2171 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Units cannot trigger themselves, ignoring: %s", rvalue
);
2175 r
= unit_add_two_dependencies_by_name(u
, UNIT_BEFORE
, UNIT_TRIGGERS
, p
, true, UNIT_DEPENDENCY_FILE
);
2177 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add trigger on %s, ignoring: %m", p
);
2184 int config_parse_path_spec(const char *unit
,
2185 const char *filename
,
2187 const char *section
,
2188 unsigned section_line
,
2195 Path
*p
= ASSERT_PTR(data
);
2198 _cleanup_free_
char *k
= NULL
;
2205 if (isempty(rvalue
)) {
2206 /* Empty assignment clears list */
2211 b
= path_type_from_string(lvalue
);
2213 log_syntax(unit
, LOG_WARNING
, filename
, line
, b
, "Failed to parse path type, ignoring: %s", lvalue
);
2217 r
= unit_path_printf(UNIT(p
), rvalue
, &k
);
2219 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2223 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2227 s
= new0(PathSpec
, 1);
2232 s
->path
= TAKE_PTR(k
);
2236 LIST_PREPEND(spec
, p
->specs
, s
);
2241 int config_parse_socket_service(
2243 const char *filename
,
2245 const char *section
,
2246 unsigned section_line
,
2253 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
2254 _cleanup_free_
char *p
= NULL
;
2255 Socket
*s
= ASSERT_PTR(data
);
2263 r
= unit_name_printf(UNIT(s
), rvalue
, &p
);
2265 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2269 if (!endswith(p
, ".service")) {
2270 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Unit must be of type service, ignoring: %s", rvalue
);
2274 r
= manager_load_unit(UNIT(s
)->manager
, p
, NULL
, &error
, &x
);
2276 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to load unit %s, ignoring: %s", rvalue
, bus_error_message(&error
, r
));
2280 unit_ref_set(&s
->service
, UNIT(s
), x
);
2285 int config_parse_fdname(
2287 const char *filename
,
2289 const char *section
,
2290 unsigned section_line
,
2297 _cleanup_free_
char *p
= NULL
;
2298 Socket
*s
= ASSERT_PTR(data
);
2305 if (isempty(rvalue
)) {
2306 s
->fdname
= mfree(s
->fdname
);
2310 r
= unit_fd_printf(UNIT(s
), rvalue
, &p
);
2312 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2316 if (!fdname_is_valid(p
)) {
2317 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", p
);
2321 return free_and_replace(s
->fdname
, p
);
2324 int config_parse_service_sockets(
2326 const char *filename
,
2328 const char *section
,
2329 unsigned section_line
,
2336 Service
*s
= ASSERT_PTR(data
);
2343 for (const char *p
= rvalue
;;) {
2344 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2346 r
= extract_first_word(&p
, &word
, NULL
, 0);
2350 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Trailing garbage in sockets, ignoring: %s", rvalue
);
2356 r
= unit_name_printf(UNIT(s
), word
, &k
);
2358 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
2362 if (!endswith(k
, ".socket")) {
2363 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Unit must be of type socket, ignoring: %s", k
);
2367 r
= unit_add_two_dependencies_by_name(UNIT(s
), UNIT_WANTS
, UNIT_AFTER
, k
, true, UNIT_DEPENDENCY_FILE
);
2369 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
2371 r
= unit_add_dependency_by_name(UNIT(s
), UNIT_TRIGGERED_BY
, k
, true, UNIT_DEPENDENCY_FILE
);
2373 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
2377 int config_parse_bus_name(
2379 const char *filename
,
2381 const char *section
,
2382 unsigned section_line
,
2389 _cleanup_free_
char *k
= NULL
;
2390 const Unit
*u
= ASSERT_PTR(userdata
);
2397 r
= unit_full_printf_full(u
, rvalue
, SD_BUS_MAXIMUM_NAME_LENGTH
, &k
);
2399 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2403 if (!sd_bus_service_name_is_valid(k
)) {
2404 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid bus name, ignoring: %s", k
);
2408 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
2411 int config_parse_service_timeout(
2413 const char *filename
,
2415 const char *section
,
2416 unsigned section_line
,
2423 Service
*s
= ASSERT_PTR(userdata
);
2431 /* This is called for two cases: TimeoutSec= and TimeoutStartSec=. */
2433 /* Traditionally, these options accepted 0 to disable the timeouts. However, a timeout of 0 suggests it happens
2434 * immediately, hence fix this to become USEC_INFINITY instead. This is in-line with how we internally handle
2435 * all other timeouts. */
2436 r
= parse_sec_fix_0(rvalue
, &usec
);
2438 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
2442 s
->start_timeout_defined
= true;
2443 s
->timeout_start_usec
= usec
;
2445 if (streq(lvalue
, "TimeoutSec"))
2446 s
->timeout_stop_usec
= usec
;
2451 int config_parse_timeout_abort(
2453 const char *filename
,
2455 const char *section
,
2456 unsigned section_line
,
2463 usec_t
*ret
= ASSERT_PTR(data
);
2470 /* Note: apart from setting the arg, this returns an extra bit of information in the return value. */
2472 if (isempty(rvalue
)) {
2474 return 0; /* "not set" */
2477 r
= parse_sec(rvalue
, ret
);
2479 return log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= setting, ignoring: %s", lvalue
, rvalue
);
2481 return 1; /* "set" */
2484 int config_parse_service_timeout_abort(
2486 const char *filename
,
2488 const char *section
,
2489 unsigned section_line
,
2496 Service
*s
= ASSERT_PTR(userdata
);
2499 r
= config_parse_timeout_abort(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
,
2500 &s
->timeout_abort_usec
, s
);
2502 s
->timeout_abort_set
= r
;
2506 int config_parse_user_group_compat(
2508 const char *filename
,
2510 const char *section
,
2511 unsigned section_line
,
2518 _cleanup_free_
char *k
= NULL
;
2520 const Unit
*u
= ASSERT_PTR(userdata
);
2527 if (isempty(rvalue
)) {
2528 *user
= mfree(*user
);
2532 r
= unit_full_printf(u
, rvalue
, &k
);
2534 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", rvalue
);
2538 if (!valid_user_group_name(k
, VALID_USER_ALLOW_NUMERIC
|VALID_USER_RELAX
|VALID_USER_WARN
)) {
2539 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2543 if (strstr(lvalue
, "User") && streq(k
, NOBODY_USER_NAME
))
2544 log_struct(LOG_NOTICE
,
2545 "MESSAGE=%s:%u: Special user %s configured, this is not safe!", filename
, line
, k
,
2547 "MESSAGE_ID=" SD_MESSAGE_NOBODY_USER_UNSUITABLE_STR
,
2548 "OFFENDING_USER=%s", k
,
2549 "CONFIG_FILE=%s", filename
,
2550 "CONFIG_LINE=%u", line
);
2552 return free_and_replace(*user
, k
);
2555 int config_parse_user_group_strv_compat(
2557 const char *filename
,
2559 const char *section
,
2560 unsigned section_line
,
2567 char ***users
= data
;
2568 const Unit
*u
= ASSERT_PTR(userdata
);
2575 if (isempty(rvalue
)) {
2576 *users
= strv_free(*users
);
2580 for (const char *p
= rvalue
;;) {
2581 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2583 r
= extract_first_word(&p
, &word
, NULL
, 0);
2587 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax: %s", rvalue
);
2593 r
= unit_full_printf(u
, word
, &k
);
2595 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", word
);
2599 if (!valid_user_group_name(k
, VALID_USER_ALLOW_NUMERIC
|VALID_USER_RELAX
|VALID_USER_WARN
)) {
2600 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2604 r
= strv_push(users
, k
);
2612 int config_parse_working_directory(
2614 const char *filename
,
2616 const char *section
,
2617 unsigned section_line
,
2624 ExecContext
*c
= ASSERT_PTR(data
);
2625 const Unit
*u
= ASSERT_PTR(userdata
);
2633 if (isempty(rvalue
)) {
2634 c
->working_directory_home
= false;
2635 c
->working_directory
= mfree(c
->working_directory
);
2639 if (rvalue
[0] == '-') {
2645 if (streq(rvalue
, "~")) {
2646 c
->working_directory_home
= true;
2647 c
->working_directory
= mfree(c
->working_directory
);
2649 _cleanup_free_
char *k
= NULL
;
2651 r
= unit_path_printf(u
, rvalue
, &k
);
2653 log_syntax(unit
, missing_ok
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
2654 "Failed to resolve unit specifiers in working directory path '%s'%s: %m",
2655 rvalue
, missing_ok
? ", ignoring" : "");
2656 return missing_ok
? 0 : -ENOEXEC
;
2659 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
| (missing_ok
? 0 : PATH_CHECK_FATAL
), unit
, filename
, line
, lvalue
);
2661 return missing_ok
? 0 : -ENOEXEC
;
2663 c
->working_directory_home
= false;
2664 free_and_replace(c
->working_directory
, k
);
2667 c
->working_directory_missing_ok
= missing_ok
;
2671 int config_parse_unit_env_file(const char *unit
,
2672 const char *filename
,
2674 const char *section
,
2675 unsigned section_line
,
2682 char ***env
= ASSERT_PTR(data
);
2683 const Unit
*u
= userdata
;
2684 _cleanup_free_
char *n
= NULL
;
2691 if (isempty(rvalue
)) {
2692 /* Empty assignment frees the list */
2693 *env
= strv_free(*env
);
2697 r
= unit_full_printf_full(u
, rvalue
, PATH_MAX
, &n
);
2699 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2703 r
= path_simplify_and_warn(n
[0] == '-' ? n
+ 1 : n
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2707 r
= strv_push(env
, n
);
2716 int config_parse_environ(
2718 const char *filename
,
2720 const char *section
,
2721 unsigned section_line
,
2728 const Unit
*u
= userdata
;
2729 char ***env
= ASSERT_PTR(data
);
2736 if (isempty(rvalue
)) {
2737 /* Empty assignment resets the list */
2738 *env
= strv_free(*env
);
2742 for (const char *p
= rvalue
;; ) {
2743 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
2745 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2749 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2750 "Invalid syntax, ignoring: %s", rvalue
);
2757 r
= unit_env_printf(u
, word
, &resolved
);
2759 r
= specifier_printf(word
, sc_arg_max(), system_and_tmp_specifier_table
, NULL
, NULL
, &resolved
);
2761 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2762 "Failed to resolve specifiers in %s, ignoring: %m", word
);
2766 if (!env_assignment_is_valid(resolved
)) {
2767 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
2768 "Invalid environment assignment, ignoring: %s", resolved
);
2772 r
= strv_env_replace_consume(env
, TAKE_PTR(resolved
));
2774 return log_error_errno(r
, "Failed to update environment: %m");
2778 int config_parse_pass_environ(
2780 const char *filename
,
2782 const char *section
,
2783 unsigned section_line
,
2790 _cleanup_strv_free_
char **n
= NULL
;
2791 const Unit
*u
= userdata
;
2792 char*** passenv
= ASSERT_PTR(data
);
2800 if (isempty(rvalue
)) {
2801 /* Empty assignment resets the list */
2802 *passenv
= strv_free(*passenv
);
2806 for (const char *p
= rvalue
;;) {
2807 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2809 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
2813 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2814 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2821 r
= unit_env_printf(u
, word
, &k
);
2823 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2824 "Failed to resolve specifiers in %s, ignoring: %m", word
);
2830 if (!env_name_is_valid(k
)) {
2831 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
2832 "Invalid environment name for %s, ignoring: %s", lvalue
, k
);
2836 if (!GREEDY_REALLOC(n
, nlen
+ 2))
2839 n
[nlen
++] = TAKE_PTR(k
);
2844 r
= strv_extend_strv(passenv
, n
, true);
2852 int config_parse_unset_environ(
2854 const char *filename
,
2856 const char *section
,
2857 unsigned section_line
,
2864 _cleanup_strv_free_
char **n
= NULL
;
2865 char*** unsetenv
= ASSERT_PTR(data
);
2866 const Unit
*u
= userdata
;
2874 if (isempty(rvalue
)) {
2875 /* Empty assignment resets the list */
2876 *unsetenv
= strv_free(*unsetenv
);
2880 for (const char *p
= rvalue
;;) {
2881 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2883 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2887 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2888 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2895 r
= unit_env_printf(u
, word
, &k
);
2897 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2898 "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2904 if (!env_assignment_is_valid(k
) && !env_name_is_valid(k
)) {
2905 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
2906 "Invalid environment name or assignment %s, ignoring: %s", lvalue
, k
);
2910 if (!GREEDY_REALLOC(n
, nlen
+ 2))
2913 n
[nlen
++] = TAKE_PTR(k
);
2918 r
= strv_extend_strv(unsetenv
, n
, true);
2926 int config_parse_log_extra_fields(
2928 const char *filename
,
2930 const char *section
,
2931 unsigned section_line
,
2938 ExecContext
*c
= ASSERT_PTR(data
);
2939 const Unit
*u
= userdata
;
2946 if (isempty(rvalue
)) {
2947 exec_context_free_log_extra_fields(c
);
2951 for (const char *p
= rvalue
;;) {
2952 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2956 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2960 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
2966 r
= unit_full_printf(u
, word
, &k
);
2968 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2972 eq
= strchr(k
, '=');
2974 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Log field lacks '=' character, ignoring: %s", k
);
2978 if (!journal_field_valid(k
, eq
-k
, false)) {
2979 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Log field name is invalid, ignoring: %s", k
);
2983 t
= reallocarray(c
->log_extra_fields
, c
->n_log_extra_fields
+1, sizeof(struct iovec
));
2987 c
->log_extra_fields
= t
;
2988 c
->log_extra_fields
[c
->n_log_extra_fields
++] = IOVEC_MAKE_STRING(k
);
2994 int config_parse_log_namespace(
2996 const char *filename
,
2998 const char *section
,
2999 unsigned section_line
,
3006 _cleanup_free_
char *k
= NULL
;
3007 ExecContext
*c
= ASSERT_PTR(data
);
3008 const Unit
*u
= userdata
;
3015 if (isempty(rvalue
)) {
3016 c
->log_namespace
= mfree(c
->log_namespace
);
3020 r
= unit_full_printf_full(u
, rvalue
, NAME_MAX
, &k
);
3022 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
3026 if (!log_namespace_name_valid(k
)) {
3027 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Specified log namespace name is not valid, ignoring: %s", k
);
3031 free_and_replace(c
->log_namespace
, k
);
3035 int config_parse_unit_condition_path(
3037 const char *filename
,
3039 const char *section
,
3040 unsigned section_line
,
3047 _cleanup_free_
char *p
= NULL
;
3048 Condition
**list
= ASSERT_PTR(data
), *c
;
3049 ConditionType t
= ltype
;
3050 bool trigger
, negate
;
3051 const Unit
*u
= userdata
;
3058 if (isempty(rvalue
)) {
3059 /* Empty assignment resets the list */
3060 *list
= condition_free_list(*list
);
3064 trigger
= rvalue
[0] == '|';
3068 negate
= rvalue
[0] == '!';
3072 r
= unit_path_printf(u
, rvalue
, &p
);
3074 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
3078 r
= path_simplify_and_warn(p
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
3082 c
= condition_new(t
, p
, trigger
, negate
);
3086 LIST_PREPEND(conditions
, *list
, c
);
3090 int config_parse_unit_condition_string(
3092 const char *filename
,
3094 const char *section
,
3095 unsigned section_line
,
3102 _cleanup_free_
char *s
= NULL
;
3103 Condition
**list
= ASSERT_PTR(data
), *c
;
3104 ConditionType t
= ltype
;
3105 bool trigger
, negate
;
3106 const Unit
*u
= userdata
;
3113 if (isempty(rvalue
)) {
3114 /* Empty assignment resets the list */
3115 *list
= condition_free_list(*list
);
3119 trigger
= *rvalue
== '|';
3121 rvalue
+= 1 + strspn(rvalue
+ 1, WHITESPACE
);
3123 negate
= *rvalue
== '!';
3125 rvalue
+= 1 + strspn(rvalue
+ 1, WHITESPACE
);
3127 r
= unit_full_printf(u
, rvalue
, &s
);
3129 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3130 "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
3134 c
= condition_new(t
, s
, trigger
, negate
);
3138 LIST_PREPEND(conditions
, *list
, c
);
3142 int config_parse_unit_requires_mounts_for(
3144 const char *filename
,
3146 const char *section
,
3147 unsigned section_line
,
3162 for (const char *p
= rvalue
;;) {
3163 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
3165 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3169 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3170 "Invalid syntax, ignoring: %s", rvalue
);
3176 r
= unit_path_printf(u
, word
, &resolved
);
3178 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
3182 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
3186 r
= unit_require_mounts_for(u
, resolved
, UNIT_DEPENDENCY_FILE
);
3188 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add required mount '%s', ignoring: %m", resolved
);
3194 int config_parse_documentation(
3196 const char *filename
,
3198 const char *section
,
3199 unsigned section_line
,
3206 Unit
*u
= ASSERT_PTR(userdata
);
3214 if (isempty(rvalue
)) {
3215 /* Empty assignment resets the list */
3216 u
->documentation
= strv_free(u
->documentation
);
3220 r
= config_parse_unit_strv_printf(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
,
3221 rvalue
, data
, userdata
);
3225 for (a
= b
= u
->documentation
; a
&& *a
; a
++) {
3227 if (documentation_url_is_valid(*a
))
3230 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid URL, ignoring: %s", *a
);
3241 int config_parse_syscall_filter(
3243 const char *filename
,
3245 const char *section
,
3246 unsigned section_line
,
3253 ExecContext
*c
= data
;
3254 _unused_
const Unit
*u
= ASSERT_PTR(userdata
);
3255 bool invert
= false;
3262 if (isempty(rvalue
)) {
3263 /* Empty assignment resets the list */
3264 c
->syscall_filter
= hashmap_free(c
->syscall_filter
);
3265 c
->syscall_allow_list
= false;
3269 if (rvalue
[0] == '~') {
3274 if (!c
->syscall_filter
) {
3275 c
->syscall_filter
= hashmap_new(NULL
);
3276 if (!c
->syscall_filter
)
3280 /* Allow everything but the ones listed */
3281 c
->syscall_allow_list
= false;
3283 /* Allow nothing but the ones listed */
3284 c
->syscall_allow_list
= true;
3286 /* Accept default syscalls if we are on an allow_list */
3287 r
= seccomp_parse_syscall_filter(
3288 "@default", -1, c
->syscall_filter
,
3289 SECCOMP_PARSE_PERMISSIVE
|SECCOMP_PARSE_ALLOW_LIST
,
3297 for (const char *p
= rvalue
;;) {
3298 _cleanup_free_
char *word
= NULL
, *name
= NULL
;
3301 r
= extract_first_word(&p
, &word
, NULL
, 0);
3305 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3306 "Invalid syntax, ignoring: %s", rvalue
);
3312 r
= parse_syscall_and_errno(word
, &name
, &num
);
3314 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3315 "Failed to parse syscall:errno, ignoring: %s", word
);
3318 if (!invert
&& num
>= 0) {
3319 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3320 "Allow-listed system calls cannot take error number, ignoring: %s", word
);
3324 r
= seccomp_parse_syscall_filter(
3325 name
, num
, c
->syscall_filter
,
3326 SECCOMP_PARSE_LOG
|SECCOMP_PARSE_PERMISSIVE
|
3327 (invert
? SECCOMP_PARSE_INVERT
: 0)|
3328 (c
->syscall_allow_list
? SECCOMP_PARSE_ALLOW_LIST
: 0),
3329 unit
, filename
, line
);
3335 int config_parse_syscall_log(
3337 const char *filename
,
3339 const char *section
,
3340 unsigned section_line
,
3347 ExecContext
*c
= data
;
3348 _unused_
const Unit
*u
= ASSERT_PTR(userdata
);
3349 bool invert
= false;
3357 if (isempty(rvalue
)) {
3358 /* Empty assignment resets the list */
3359 c
->syscall_log
= hashmap_free(c
->syscall_log
);
3360 c
->syscall_log_allow_list
= false;
3364 if (rvalue
[0] == '~') {
3369 if (!c
->syscall_log
) {
3370 c
->syscall_log
= hashmap_new(NULL
);
3371 if (!c
->syscall_log
)
3375 /* Log everything but the ones listed */
3376 c
->syscall_log_allow_list
= false;
3378 /* Log nothing but the ones listed */
3379 c
->syscall_log_allow_list
= true;
3384 _cleanup_free_
char *word
= NULL
;
3386 r
= extract_first_word(&p
, &word
, NULL
, 0);
3390 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3396 r
= seccomp_parse_syscall_filter(
3397 word
, -1, c
->syscall_log
,
3398 SECCOMP_PARSE_LOG
|SECCOMP_PARSE_PERMISSIVE
|
3399 (invert
? SECCOMP_PARSE_INVERT
: 0)|
3400 (c
->syscall_log_allow_list
? SECCOMP_PARSE_ALLOW_LIST
: 0),
3401 unit
, filename
, line
);
3407 int config_parse_syscall_archs(
3409 const char *filename
,
3411 const char *section
,
3412 unsigned section_line
,
3422 if (isempty(rvalue
)) {
3423 *archs
= set_free(*archs
);
3427 for (const char *p
= rvalue
;;) {
3428 _cleanup_free_
char *word
= NULL
;
3431 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3435 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3436 "Invalid syntax, ignoring: %s", rvalue
);
3442 r
= seccomp_arch_from_string(word
, &a
);
3444 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3445 "Failed to parse system call architecture \"%s\", ignoring: %m", word
);
3449 r
= set_ensure_put(archs
, NULL
, UINT32_TO_PTR(a
+ 1));
3455 int config_parse_syscall_errno(
3457 const char *filename
,
3459 const char *section
,
3460 unsigned section_line
,
3467 ExecContext
*c
= data
;
3474 if (isempty(rvalue
) || streq(rvalue
, "kill")) {
3475 /* Empty assignment resets to KILL */
3476 c
->syscall_errno
= SECCOMP_ERROR_NUMBER_KILL
;
3480 e
= parse_errno(rvalue
);
3482 log_syntax(unit
, LOG_WARNING
, filename
, line
, e
, "Failed to parse error number, ignoring: %s", rvalue
);
3486 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid error number, ignoring: %s", rvalue
);
3490 c
->syscall_errno
= e
;
3494 int config_parse_address_families(
3496 const char *filename
,
3498 const char *section
,
3499 unsigned section_line
,
3506 ExecContext
*c
= data
;
3507 bool invert
= false;
3514 if (isempty(rvalue
)) {
3515 /* Empty assignment resets the list */
3516 c
->address_families
= set_free(c
->address_families
);
3517 c
->address_families_allow_list
= false;
3521 if (streq(rvalue
, "none")) {
3522 /* Forbid all address families. */
3523 c
->address_families
= set_free(c
->address_families
);
3524 c
->address_families_allow_list
= true;
3528 if (rvalue
[0] == '~') {
3533 if (!c
->address_families
) {
3534 c
->address_families
= set_new(NULL
);
3535 if (!c
->address_families
)
3538 c
->address_families_allow_list
= !invert
;
3541 for (const char *p
= rvalue
;;) {
3542 _cleanup_free_
char *word
= NULL
;
3545 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3549 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3550 "Invalid syntax, ignoring: %s", rvalue
);
3556 af
= af_from_name(word
);
3558 log_syntax(unit
, LOG_WARNING
, filename
, line
, af
,
3559 "Failed to parse address family, ignoring: %s", word
);
3563 /* If we previously wanted to forbid an address family and now
3564 * we want to allow it, then just remove it from the list.
3566 if (!invert
== c
->address_families_allow_list
) {
3567 r
= set_put(c
->address_families
, INT_TO_PTR(af
));
3571 set_remove(c
->address_families
, INT_TO_PTR(af
));
3575 int config_parse_restrict_namespaces(
3577 const char *filename
,
3579 const char *section
,
3580 unsigned section_line
,
3587 ExecContext
*c
= data
;
3588 unsigned long flags
;
3589 bool invert
= false;
3592 if (isempty(rvalue
)) {
3593 /* Reset to the default. */
3594 c
->restrict_namespaces
= NAMESPACE_FLAGS_INITIAL
;
3598 /* Boolean parameter ignores the previous settings */
3599 r
= parse_boolean(rvalue
);
3601 c
->restrict_namespaces
= 0;
3603 } else if (r
== 0) {
3604 c
->restrict_namespaces
= NAMESPACE_FLAGS_ALL
;
3608 if (rvalue
[0] == '~') {
3613 /* Not a boolean argument, in this case it's a list of namespace types. */
3614 r
= namespace_flags_from_string(rvalue
, &flags
);
3616 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse namespace type string, ignoring: %s", rvalue
);
3620 if (c
->restrict_namespaces
== NAMESPACE_FLAGS_INITIAL
)
3621 /* Initial assignment. Just set the value. */
3622 c
->restrict_namespaces
= invert
? (~flags
) & NAMESPACE_FLAGS_ALL
: flags
;
3624 /* Merge the value with the previous one. */
3625 SET_FLAG(c
->restrict_namespaces
, flags
, !invert
);
3631 int config_parse_restrict_filesystems(
3633 const char *filename
,
3635 const char *section
,
3636 unsigned section_line
,
3642 ExecContext
*c
= ASSERT_PTR(data
);
3643 bool invert
= false;
3650 if (isempty(rvalue
)) {
3651 /* Empty assignment resets the list */
3652 c
->restrict_filesystems
= set_free(c
->restrict_filesystems
);
3653 c
->restrict_filesystems_allow_list
= false;
3657 if (rvalue
[0] == '~') {
3662 if (!c
->restrict_filesystems
) {
3664 /* Allow everything but the ones listed */
3665 c
->restrict_filesystems_allow_list
= false;
3667 /* Allow nothing but the ones listed */
3668 c
->restrict_filesystems_allow_list
= true;
3671 for (const char *p
= rvalue
;;) {
3672 _cleanup_free_
char *word
= NULL
;
3674 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3680 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3681 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
3685 r
= lsm_bpf_parse_filesystem(
3687 &c
->restrict_filesystems
,
3688 FILESYSTEM_PARSE_LOG
|
3689 (invert
? FILESYSTEM_PARSE_INVERT
: 0)|
3690 (c
->restrict_filesystems_allow_list
? FILESYSTEM_PARSE_ALLOW_LIST
: 0),
3691 unit
, filename
, line
);
3700 int config_parse_unit_slice(
3702 const char *filename
,
3704 const char *section
,
3705 unsigned section_line
,
3712 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
3713 _cleanup_free_
char *k
= NULL
;
3714 Unit
*u
= userdata
, *slice
;
3722 r
= unit_name_printf(u
, rvalue
, &k
);
3724 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
3728 r
= manager_load_unit(u
->manager
, k
, NULL
, &error
, &slice
);
3730 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to load slice unit %s, ignoring: %s", k
, bus_error_message(&error
, r
));
3734 r
= unit_set_slice(u
, slice
);
3736 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to assign slice %s to unit %s, ignoring: %m", slice
->id
, u
->id
);
3743 int config_parse_cpu_quota(
3745 const char *filename
,
3747 const char *section
,
3748 unsigned section_line
,
3755 CGroupContext
*c
= data
;
3762 if (isempty(rvalue
)) {
3763 c
->cpu_quota_per_sec_usec
= USEC_INFINITY
;
3767 r
= parse_permyriad_unbounded(rvalue
);
3769 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid CPU quota '%s', ignoring.", rvalue
);
3773 c
->cpu_quota_per_sec_usec
= ((usec_t
) r
* USEC_PER_SEC
) / 10000U;
3777 int config_parse_allowed_cpuset(
3779 const char *filename
,
3781 const char *section
,
3782 unsigned section_line
,
3791 (void) parse_cpu_set_extend(rvalue
, c
, true, unit
, filename
, line
, lvalue
);
3795 int config_parse_memory_limit(
3797 const char *filename
,
3799 const char *section
,
3800 unsigned section_line
,
3807 CGroupContext
*c
= data
;
3808 uint64_t bytes
= CGROUP_LIMIT_MAX
;
3811 if (isempty(rvalue
) && STR_IN_SET(lvalue
, "DefaultMemoryLow",
3815 bytes
= CGROUP_LIMIT_MIN
;
3816 else if (!isempty(rvalue
) && !streq(rvalue
, "infinity")) {
3818 r
= parse_permyriad(rvalue
);
3820 r
= parse_size(rvalue
, 1024, &bytes
);
3822 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid memory limit '%s', ignoring: %m", rvalue
);
3826 bytes
= physical_memory_scale(r
, 10000U);
3828 if (bytes
>= UINT64_MAX
||
3829 (bytes
<= 0 && !STR_IN_SET(lvalue
, "MemorySwapMax", "MemoryZSwapMax", "MemoryLow", "MemoryMin", "DefaultMemoryLow", "DefaultMemoryMin"))) {
3830 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Memory limit '%s' out of range, ignoring.", rvalue
);
3835 if (streq(lvalue
, "DefaultMemoryLow")) {
3836 c
->default_memory_low
= bytes
;
3837 c
->default_memory_low_set
= true;
3838 } else if (streq(lvalue
, "DefaultMemoryMin")) {
3839 c
->default_memory_min
= bytes
;
3840 c
->default_memory_min_set
= true;
3841 } else if (streq(lvalue
, "MemoryMin")) {
3842 c
->memory_min
= bytes
;
3843 c
->memory_min_set
= true;
3844 } else if (streq(lvalue
, "MemoryLow")) {
3845 c
->memory_low
= bytes
;
3846 c
->memory_low_set
= true;
3847 } else if (streq(lvalue
, "MemoryHigh"))
3848 c
->memory_high
= bytes
;
3849 else if (streq(lvalue
, "MemoryMax"))
3850 c
->memory_max
= bytes
;
3851 else if (streq(lvalue
, "MemorySwapMax"))
3852 c
->memory_swap_max
= bytes
;
3853 else if (streq(lvalue
, "MemoryZSwapMax"))
3854 c
->memory_zswap_max
= bytes
;
3855 else if (streq(lvalue
, "MemoryLimit")) {
3856 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3857 "Unit uses MemoryLimit=; please use MemoryMax= instead. Support for MemoryLimit= will be removed soon.");
3858 c
->memory_limit
= bytes
;
3865 int config_parse_tasks_max(
3867 const char *filename
,
3869 const char *section
,
3870 unsigned section_line
,
3877 const Unit
*u
= userdata
;
3878 TasksMax
*tasks_max
= data
;
3882 if (isempty(rvalue
)) {
3883 *tasks_max
= u
? u
->manager
->default_tasks_max
: TASKS_MAX_UNSET
;
3887 if (streq(rvalue
, "infinity")) {
3888 *tasks_max
= TASKS_MAX_UNSET
;
3892 r
= parse_permyriad(rvalue
);
3894 *tasks_max
= (TasksMax
) { r
, 10000U }; /* r‱ */
3896 r
= safe_atou64(rvalue
, &v
);
3898 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid maximum tasks value '%s', ignoring: %m", rvalue
);
3902 if (v
<= 0 || v
>= UINT64_MAX
) {
3903 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Maximum tasks value '%s' out of range, ignoring.", rvalue
);
3907 *tasks_max
= (TasksMax
) { v
};
3913 int config_parse_delegate(
3915 const char *filename
,
3917 const char *section
,
3918 unsigned section_line
,
3925 CGroupContext
*c
= data
;
3929 t
= unit_name_to_type(unit
);
3930 assert(t
!= _UNIT_TYPE_INVALID
);
3932 if (!unit_vtable
[t
]->can_delegate
) {
3933 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Delegate= setting not supported for this unit type, ignoring.");
3937 /* We either accept a boolean value, which may be used to turn on delegation for all controllers, or turn it
3938 * off for all. Or it takes a list of controller names, in which case we add the specified controllers to the
3939 * mask to delegate. */
3941 if (isempty(rvalue
)) {
3942 /* An empty string resets controllers and set Delegate=yes. */
3944 c
->delegate_controllers
= 0;
3948 r
= parse_boolean(rvalue
);
3950 CGroupMask mask
= 0;
3952 for (const char *p
= rvalue
;;) {
3953 _cleanup_free_
char *word
= NULL
;
3954 CGroupController cc
;
3956 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3960 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3966 cc
= cgroup_controller_from_string(word
);
3968 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid controller name '%s', ignoring", word
);
3972 mask
|= CGROUP_CONTROLLER_TO_MASK(cc
);
3976 c
->delegate_controllers
|= mask
;
3980 c
->delegate_controllers
= _CGROUP_MASK_ALL
;
3982 c
->delegate
= false;
3983 c
->delegate_controllers
= 0;
3989 int config_parse_managed_oom_mode(
3991 const char *filename
,
3993 const char *section
,
3994 unsigned section_line
,
4001 ManagedOOMMode
*mode
= data
, m
;
4004 t
= unit_name_to_type(unit
);
4005 assert(t
!= _UNIT_TYPE_INVALID
);
4007 if (!unit_vtable
[t
]->can_set_managed_oom
)
4008 return log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "%s= is not supported for this unit type, ignoring.", lvalue
);
4010 if (isempty(rvalue
)) {
4011 *mode
= MANAGED_OOM_AUTO
;
4015 m
= managed_oom_mode_from_string(rvalue
);
4017 log_syntax(unit
, LOG_WARNING
, filename
, line
, m
, "Invalid syntax, ignoring: %s", rvalue
);
4025 int config_parse_managed_oom_mem_pressure_limit(
4027 const char *filename
,
4029 const char *section
,
4030 unsigned section_line
,
4037 uint32_t *limit
= data
;
4041 t
= unit_name_to_type(unit
);
4042 assert(t
!= _UNIT_TYPE_INVALID
);
4044 if (!unit_vtable
[t
]->can_set_managed_oom
)
4045 return log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "%s= is not supported for this unit type, ignoring.", lvalue
);
4047 if (isempty(rvalue
)) {
4052 r
= parse_permyriad(rvalue
);
4054 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse memory pressure limit value, ignoring: %s", rvalue
);
4058 /* Normalize to 2^32-1 == 100% */
4059 *limit
= UINT32_SCALE_FROM_PERMYRIAD(r
);
4063 int config_parse_device_allow(
4065 const char *filename
,
4067 const char *section
,
4068 unsigned section_line
,
4075 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4076 CGroupContext
*c
= data
;
4077 const char *p
= rvalue
;
4080 if (isempty(rvalue
)) {
4081 while (c
->device_allow
)
4082 cgroup_context_free_device_allow(c
, c
->device_allow
);
4087 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4091 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4092 "Failed to extract device path and rights from '%s', ignoring.", rvalue
);
4096 r
= unit_path_printf(userdata
, path
, &resolved
);
4098 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4099 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4103 if (!STARTSWITH_SET(resolved
, "block-", "char-")) {
4105 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4109 if (!valid_device_node_path(resolved
)) {
4110 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid device node path '%s', ignoring.", resolved
);
4115 if (!isempty(p
) && !in_charset(p
, "rwm")) {
4116 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid device rights '%s', ignoring.", p
);
4120 return cgroup_add_device_allow(c
, resolved
, p
);
4123 int config_parse_io_device_weight(
4125 const char *filename
,
4127 const char *section
,
4128 unsigned section_line
,
4135 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4136 CGroupIODeviceWeight
*w
;
4137 CGroupContext
*c
= data
;
4138 const char *p
= ASSERT_PTR(rvalue
);
4145 if (isempty(rvalue
)) {
4146 while (c
->io_device_weights
)
4147 cgroup_context_free_io_device_weight(c
, c
->io_device_weights
);
4152 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4156 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4157 "Failed to extract device path and weight from '%s', ignoring.", rvalue
);
4160 if (r
== 0 || isempty(p
)) {
4161 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4162 "Invalid device path or weight specified in '%s', ignoring.", rvalue
);
4166 r
= unit_path_printf(userdata
, path
, &resolved
);
4168 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4169 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4173 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4177 r
= cg_weight_parse(p
, &u
);
4179 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "IO weight '%s' invalid, ignoring: %m", p
);
4183 assert(u
!= CGROUP_WEIGHT_INVALID
);
4185 w
= new0(CGroupIODeviceWeight
, 1);
4189 w
->path
= TAKE_PTR(resolved
);
4192 LIST_PREPEND(device_weights
, c
->io_device_weights
, w
);
4196 int config_parse_io_device_latency(
4198 const char *filename
,
4200 const char *section
,
4201 unsigned section_line
,
4208 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4209 CGroupIODeviceLatency
*l
;
4210 CGroupContext
*c
= data
;
4211 const char *p
= ASSERT_PTR(rvalue
);
4218 if (isempty(rvalue
)) {
4219 while (c
->io_device_latencies
)
4220 cgroup_context_free_io_device_latency(c
, c
->io_device_latencies
);
4225 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4229 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4230 "Failed to extract device path and latency from '%s', ignoring.", rvalue
);
4233 if (r
== 0 || isempty(p
)) {
4234 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4235 "Invalid device path or latency specified in '%s', ignoring.", rvalue
);
4239 r
= unit_path_printf(userdata
, path
, &resolved
);
4241 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4242 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4246 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4250 r
= parse_sec(p
, &usec
);
4252 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse timer value, ignoring: %s", p
);
4256 l
= new0(CGroupIODeviceLatency
, 1);
4260 l
->path
= TAKE_PTR(resolved
);
4261 l
->target_usec
= usec
;
4263 LIST_PREPEND(device_latencies
, c
->io_device_latencies
, l
);
4267 int config_parse_io_limit(
4269 const char *filename
,
4271 const char *section
,
4272 unsigned section_line
,
4279 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4280 CGroupIODeviceLimit
*l
= NULL
;
4281 CGroupContext
*c
= data
;
4282 CGroupIOLimitType type
;
4283 const char *p
= ASSERT_PTR(rvalue
);
4290 type
= cgroup_io_limit_type_from_string(lvalue
);
4293 if (isempty(rvalue
)) {
4294 LIST_FOREACH(device_limits
, t
, c
->io_device_limits
)
4295 t
->limits
[type
] = cgroup_io_limit_defaults
[type
];
4299 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4303 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4304 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
4307 if (r
== 0 || isempty(p
)) {
4308 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4309 "Invalid device node or bandwidth specified in '%s', ignoring.", rvalue
);
4313 r
= unit_path_printf(userdata
, path
, &resolved
);
4315 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4316 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4320 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4324 if (streq("infinity", p
))
4325 num
= CGROUP_LIMIT_MAX
;
4327 r
= parse_size(p
, 1000, &num
);
4328 if (r
< 0 || num
<= 0) {
4329 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid IO limit '%s', ignoring.", p
);
4334 LIST_FOREACH(device_limits
, t
, c
->io_device_limits
)
4335 if (path_equal(resolved
, t
->path
)) {
4341 CGroupIOLimitType ttype
;
4343 l
= new0(CGroupIODeviceLimit
, 1);
4347 l
->path
= TAKE_PTR(resolved
);
4348 for (ttype
= 0; ttype
< _CGROUP_IO_LIMIT_TYPE_MAX
; ttype
++)
4349 l
->limits
[ttype
] = cgroup_io_limit_defaults
[ttype
];
4351 LIST_PREPEND(device_limits
, c
->io_device_limits
, l
);
4354 l
->limits
[type
] = num
;
4359 int config_parse_blockio_device_weight(
4361 const char *filename
,
4363 const char *section
,
4364 unsigned section_line
,
4371 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4372 CGroupBlockIODeviceWeight
*w
;
4373 CGroupContext
*c
= data
;
4374 const char *p
= ASSERT_PTR(rvalue
);
4381 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4382 "Unit uses %s=; please use IO*= settings instead. Support for %s= will be removed soon.",
4385 if (isempty(rvalue
)) {
4386 while (c
->blockio_device_weights
)
4387 cgroup_context_free_blockio_device_weight(c
, c
->blockio_device_weights
);
4392 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4396 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4397 "Failed to extract device node and weight from '%s', ignoring.", rvalue
);
4400 if (r
== 0 || isempty(p
)) {
4401 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4402 "Invalid device node or weight specified in '%s', ignoring.", rvalue
);
4406 r
= unit_path_printf(userdata
, path
, &resolved
);
4408 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4409 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4413 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4417 r
= cg_blkio_weight_parse(p
, &u
);
4419 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid block IO weight '%s', ignoring: %m", p
);
4423 assert(u
!= CGROUP_BLKIO_WEIGHT_INVALID
);
4425 w
= new0(CGroupBlockIODeviceWeight
, 1);
4429 w
->path
= TAKE_PTR(resolved
);
4432 LIST_PREPEND(device_weights
, c
->blockio_device_weights
, w
);
4436 int config_parse_blockio_bandwidth(
4438 const char *filename
,
4440 const char *section
,
4441 unsigned section_line
,
4448 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4449 CGroupBlockIODeviceBandwidth
*b
= NULL
;
4450 CGroupContext
*c
= data
;
4451 const char *p
= ASSERT_PTR(rvalue
);
4459 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4460 "Unit uses %s=; please use IO*= settings instead. Support for %s= will be removed soon.",
4463 read
= streq("BlockIOReadBandwidth", lvalue
);
4465 if (isempty(rvalue
)) {
4466 LIST_FOREACH(device_bandwidths
, t
, c
->blockio_device_bandwidths
) {
4467 t
->rbps
= CGROUP_LIMIT_MAX
;
4468 t
->wbps
= CGROUP_LIMIT_MAX
;
4473 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4477 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4478 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
4481 if (r
== 0 || isempty(p
)) {
4482 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4483 "Invalid device node or bandwidth specified in '%s', ignoring.", rvalue
);
4487 r
= unit_path_printf(userdata
, path
, &resolved
);
4489 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4490 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4494 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4498 r
= parse_size(p
, 1000, &bytes
);
4499 if (r
< 0 || bytes
<= 0) {
4500 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid Block IO Bandwidth '%s', ignoring.", p
);
4504 LIST_FOREACH(device_bandwidths
, t
, c
->blockio_device_bandwidths
)
4505 if (path_equal(resolved
, t
->path
)) {
4511 b
= new0(CGroupBlockIODeviceBandwidth
, 1);
4515 b
->path
= TAKE_PTR(resolved
);
4516 b
->rbps
= CGROUP_LIMIT_MAX
;
4517 b
->wbps
= CGROUP_LIMIT_MAX
;
4519 LIST_PREPEND(device_bandwidths
, c
->blockio_device_bandwidths
, b
);
4530 int config_parse_job_mode_isolate(
4532 const char *filename
,
4534 const char *section
,
4535 unsigned section_line
,
4549 r
= parse_boolean(rvalue
);
4551 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse boolean, ignoring: %s", rvalue
);
4555 log_notice("%s is deprecated. Please use OnFailureJobMode= instead", lvalue
);
4557 *m
= r
? JOB_ISOLATE
: JOB_REPLACE
;
4561 int config_parse_exec_directories(
4563 const char *filename
,
4565 const char *section
,
4566 unsigned section_line
,
4573 ExecDirectory
*ed
= ASSERT_PTR(data
);
4574 const Unit
*u
= userdata
;
4581 if (isempty(rvalue
)) {
4582 /* Empty assignment resets the list */
4583 exec_directory_done(ed
);
4587 for (const char *p
= rvalue
;;) {
4588 _cleanup_free_
char *tuple
= NULL
;
4590 r
= extract_first_word(&p
, &tuple
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_RETAIN_ESCAPE
);
4594 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4595 "Invalid syntax %s=%s, ignoring: %m", lvalue
, rvalue
);
4601 _cleanup_free_
char *src
= NULL
, *dest
= NULL
;
4602 const char *q
= tuple
;
4603 r
= extract_many_words(&q
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
, &src
, &dest
, NULL
);
4607 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
?: SYNTHETIC_ERRNO(EINVAL
),
4608 "Invalid syntax in %s=, ignoring: %s", lvalue
, tuple
);
4612 _cleanup_free_
char *sresolved
= NULL
;
4613 r
= unit_path_printf(u
, src
, &sresolved
);
4615 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4616 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", src
);
4620 r
= path_simplify_and_warn(sresolved
, PATH_CHECK_RELATIVE
, unit
, filename
, line
, lvalue
);
4624 if (path_startswith(sresolved
, "private")) {
4625 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4626 "%s= path can't be 'private', ignoring assignment: %s", lvalue
, tuple
);
4630 /* For State and Runtime directories we support an optional destination parameter, which
4631 * will be used to create a symlink to the source. */
4632 _cleanup_free_
char *dresolved
= NULL
;
4633 if (!isempty(dest
)) {
4634 if (streq(lvalue
, "ConfigurationDirectory")) {
4635 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4636 "Destination parameter is not supported for ConfigurationDirectory, ignoring: %s", tuple
);
4640 r
= unit_path_printf(u
, dest
, &dresolved
);
4642 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4643 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", dest
);
4647 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_RELATIVE
, unit
, filename
, line
, lvalue
);
4652 r
= exec_directory_add(ed
, sresolved
, dresolved
);
4658 int config_parse_set_credential(
4660 const char *filename
,
4662 const char *section
,
4663 unsigned section_line
,
4670 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
4671 _cleanup_free_
void *d
= NULL
;
4672 ExecContext
*context
= ASSERT_PTR(data
);
4673 ExecSetCredential
*old
;
4675 bool encrypted
= ltype
;
4676 const char *p
= ASSERT_PTR(rvalue
);
4683 if (isempty(rvalue
)) {
4684 /* Empty assignment resets the list */
4685 context
->set_credentials
= hashmap_free(context
->set_credentials
);
4689 r
= extract_first_word(&p
, &word
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4693 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract credential name, ignoring: %s", rvalue
);
4696 if (r
== 0 || isempty(p
)) {
4697 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid syntax, ignoring: %s", rvalue
);
4701 r
= unit_cred_printf(u
, word
, &k
);
4703 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
4706 if (!credential_name_valid(k
)) {
4707 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Credential name \"%s\" not valid, ignoring.", k
);
4712 r
= unbase64mem_full(p
, SIZE_MAX
, true, &d
, &size
);
4714 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Encrypted credential data not valid Base64 data, ignoring.");
4721 /* We support escape codes here, so that users can insert trailing \n if they like */
4722 l
= cunescape(p
, UNESCAPE_ACCEPT_NUL
, &unescaped
);
4724 log_syntax(unit
, LOG_WARNING
, filename
, line
, l
, "Can't unescape \"%s\", ignoring: %m", p
);
4732 old
= hashmap_get(context
->set_credentials
, k
);
4734 free_and_replace(old
->data
, d
);
4736 old
->encrypted
= encrypted
;
4738 _cleanup_(exec_set_credential_freep
) ExecSetCredential
*sc
= NULL
;
4740 sc
= new(ExecSetCredential
, 1);
4744 *sc
= (ExecSetCredential
) {
4746 .data
= TAKE_PTR(d
),
4748 .encrypted
= encrypted
,
4751 r
= hashmap_ensure_put(&context
->set_credentials
, &exec_set_credential_hash_ops
, sc
->id
, sc
);
4755 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4756 "Duplicated credential value '%s', ignoring assignment: %s", sc
->id
, rvalue
);
4766 int config_parse_load_credential(
4768 const char *filename
,
4770 const char *section
,
4771 unsigned section_line
,
4778 _cleanup_free_
char *word
= NULL
, *k
= NULL
, *q
= NULL
;
4779 ExecContext
*context
= ASSERT_PTR(data
);
4780 ExecLoadCredential
*old
;
4781 bool encrypted
= ltype
;
4790 if (isempty(rvalue
)) {
4791 /* Empty assignment resets the list */
4792 context
->load_credentials
= hashmap_free(context
->load_credentials
);
4797 r
= extract_first_word(&p
, &word
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4801 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
4805 r
= unit_cred_printf(u
, word
, &k
);
4807 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
4810 if (!credential_name_valid(k
)) {
4811 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Credential name \"%s\" not valid, ignoring.", k
);
4816 /* If only one field is specified take it as shortcut for inheriting a credential named
4817 * the same way from our parent */
4822 r
= unit_path_printf(u
, p
, &q
);
4824 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", p
);
4827 if (path_is_absolute(q
) ? !path_is_normalized(q
) : !credential_name_valid(q
)) {
4828 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Credential source \"%s\" not valid, ignoring.", q
);
4833 old
= hashmap_get(context
->load_credentials
, k
);
4835 free_and_replace(old
->path
, q
);
4836 old
->encrypted
= encrypted
;
4838 _cleanup_(exec_load_credential_freep
) ExecLoadCredential
*lc
= NULL
;
4840 lc
= new(ExecLoadCredential
, 1);
4844 *lc
= (ExecLoadCredential
) {
4846 .path
= TAKE_PTR(q
),
4847 .encrypted
= encrypted
,
4850 r
= hashmap_ensure_put(&context
->load_credentials
, &exec_load_credential_hash_ops
, lc
->id
, lc
);
4854 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4855 "Duplicated credential value '%s', ignoring assignment: %s", lc
->id
, rvalue
);
4865 int config_parse_set_status(
4867 const char *filename
,
4869 const char *section
,
4870 unsigned section_line
,
4877 ExitStatusSet
*status_set
= ASSERT_PTR(data
);
4884 /* Empty assignment resets the list */
4885 if (isempty(rvalue
)) {
4886 exit_status_set_free(status_set
);
4890 for (const char *p
= rvalue
;;) {
4891 _cleanup_free_
char *word
= NULL
;
4894 r
= extract_first_word(&p
, &word
, NULL
, 0);
4898 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4899 "Failed to parse %s=%s, ignoring: %m", lvalue
, rvalue
);
4905 /* We need to call exit_status_from_string() first, because we want
4906 * to parse numbers as exit statuses, not signals. */
4908 r
= exit_status_from_string(word
);
4910 assert(r
>= 0 && r
< 256);
4911 bitmap
= &status_set
->status
;
4913 r
= signal_from_string(word
);
4915 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4916 "Failed to parse value, ignoring: %s", word
);
4919 bitmap
= &status_set
->signal
;
4922 r
= bitmap_set(bitmap
, r
);
4924 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4925 "Failed to set signal or status %s, ignoring: %m", word
);
4929 int config_parse_namespace_path_strv(
4931 const char *filename
,
4933 const char *section
,
4934 unsigned section_line
,
4941 const Unit
*u
= userdata
;
4942 char*** sv
= ASSERT_PTR(data
);
4949 if (isempty(rvalue
)) {
4950 /* Empty assignment resets the list */
4951 *sv
= strv_free(*sv
);
4955 for (const char *p
= rvalue
;;) {
4956 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
, *joined
= NULL
;
4958 bool ignore_enoent
= false, shall_prefix
= false;
4960 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
4964 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
4971 if (startswith(w
, "-")) {
4972 ignore_enoent
= true;
4975 if (startswith(w
, "+")) {
4976 shall_prefix
= true;
4980 r
= unit_path_printf(u
, w
, &resolved
);
4982 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", w
);
4986 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4990 joined
= strjoin(ignore_enoent
? "-" : "",
4991 shall_prefix
? "+" : "",
4994 r
= strv_push(sv
, joined
);
5004 int config_parse_temporary_filesystems(
5006 const char *filename
,
5008 const char *section
,
5009 unsigned section_line
,
5016 const Unit
*u
= userdata
;
5017 ExecContext
*c
= ASSERT_PTR(data
);
5024 if (isempty(rvalue
)) {
5025 /* Empty assignment resets the list */
5026 temporary_filesystem_free_many(c
->temporary_filesystems
, c
->n_temporary_filesystems
);
5027 c
->temporary_filesystems
= NULL
;
5028 c
->n_temporary_filesystems
= 0;
5032 for (const char *p
= rvalue
;;) {
5033 _cleanup_free_
char *word
= NULL
, *path
= NULL
, *resolved
= NULL
;
5036 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
5040 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
5047 r
= extract_first_word(&w
, &path
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
5051 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", word
);
5055 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid syntax, ignoring: %s", word
);
5059 r
= unit_path_printf(u
, path
, &resolved
);
5061 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", path
);
5065 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5069 r
= temporary_filesystem_add(&c
->temporary_filesystems
, &c
->n_temporary_filesystems
, resolved
, w
);
5075 int config_parse_bind_paths(
5077 const char *filename
,
5079 const char *section
,
5080 unsigned section_line
,
5087 ExecContext
*c
= ASSERT_PTR(data
);
5088 const Unit
*u
= userdata
;
5095 if (isempty(rvalue
)) {
5096 /* Empty assignment resets the list */
5097 bind_mount_free_many(c
->bind_mounts
, c
->n_bind_mounts
);
5098 c
->bind_mounts
= NULL
;
5099 c
->n_bind_mounts
= 0;
5103 for (const char *p
= rvalue
;;) {
5104 _cleanup_free_
char *source
= NULL
, *destination
= NULL
;
5105 _cleanup_free_
char *sresolved
= NULL
, *dresolved
= NULL
;
5106 char *s
= NULL
, *d
= NULL
;
5107 bool rbind
= true, ignore_enoent
= false;
5109 r
= extract_first_word(&p
, &source
, ":" WHITESPACE
, EXTRACT_UNQUOTE
|EXTRACT_DONT_COALESCE_SEPARATORS
);
5113 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
5119 r
= unit_full_printf_full(u
, source
, PATH_MAX
, &sresolved
);
5121 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5122 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", source
);
5128 ignore_enoent
= true;
5132 r
= path_simplify_and_warn(s
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5136 /* Optionally, the destination is specified. */
5137 if (p
&& p
[-1] == ':') {
5138 r
= extract_first_word(&p
, &destination
, ":" WHITESPACE
, EXTRACT_UNQUOTE
|EXTRACT_DONT_COALESCE_SEPARATORS
);
5142 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
5146 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Missing argument after ':', ignoring: %s", s
);
5150 r
= unit_path_printf(u
, destination
, &dresolved
);
5152 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5153 "Failed to resolve specifiers in \"%s\", ignoring: %m", destination
);
5157 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5163 /* Optionally, there's also a short option string specified */
5164 if (p
&& p
[-1] == ':') {
5165 _cleanup_free_
char *options
= NULL
;
5167 r
= extract_first_word(&p
, &options
, NULL
, EXTRACT_UNQUOTE
);
5171 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s=, ignoring: %s", lvalue
, rvalue
);
5175 if (isempty(options
) || streq(options
, "rbind"))
5177 else if (streq(options
, "norbind"))
5180 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid option string, ignoring setting: %s", options
);
5187 r
= bind_mount_add(&c
->bind_mounts
, &c
->n_bind_mounts
,
5191 .read_only
= !!strstr(lvalue
, "ReadOnly"),
5193 .ignore_enoent
= ignore_enoent
,
5202 int config_parse_mount_images(
5204 const char *filename
,
5206 const char *section
,
5207 unsigned section_line
,
5214 ExecContext
*c
= ASSERT_PTR(data
);
5215 const Unit
*u
= userdata
;
5222 if (isempty(rvalue
)) {
5223 /* Empty assignment resets the list */
5224 c
->mount_images
= mount_image_free_many(c
->mount_images
, &c
->n_mount_images
);
5228 for (const char *p
= rvalue
;;) {
5229 _cleanup_(mount_options_free_allp
) MountOptions
*options
= NULL
;
5230 _cleanup_free_
char *first
= NULL
, *second
= NULL
, *tuple
= NULL
;
5231 _cleanup_free_
char *sresolved
= NULL
, *dresolved
= NULL
;
5232 const char *q
= NULL
;
5234 bool permissive
= false;
5236 r
= extract_first_word(&p
, &tuple
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_RETAIN_ESCAPE
);
5240 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5241 "Invalid syntax %s=%s, ignoring: %m", lvalue
, rvalue
);
5248 r
= extract_many_words(&q
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
, &first
, &second
, NULL
);
5252 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5253 "Invalid syntax in %s=, ignoring: %s", lvalue
, tuple
);
5265 r
= unit_path_printf(u
, s
, &sresolved
);
5267 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5268 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", s
);
5272 r
= path_simplify_and_warn(sresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5276 if (isempty(second
)) {
5277 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Missing destination in %s, ignoring: %s", lvalue
, rvalue
);
5281 r
= unit_path_printf(u
, second
, &dresolved
);
5283 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5284 "Failed to resolve specifiers in \"%s\", ignoring: %m", second
);
5288 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5293 _cleanup_free_
char *partition
= NULL
, *mount_options
= NULL
, *mount_options_resolved
= NULL
;
5294 MountOptions
*o
= NULL
;
5295 PartitionDesignator partition_designator
;
5297 r
= extract_many_words(&q
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
, &partition
, &mount_options
, NULL
);
5301 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", q
);
5306 /* Single set of options, applying to the root partition/single filesystem */
5308 r
= unit_full_printf(u
, partition
, &mount_options_resolved
);
5310 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", first
);
5314 o
= new(MountOptions
, 1);
5317 *o
= (MountOptions
) {
5318 .partition_designator
= PARTITION_ROOT
,
5319 .options
= TAKE_PTR(mount_options_resolved
),
5321 LIST_APPEND(mount_options
, options
, o
);
5326 partition_designator
= partition_designator_from_string(partition
);
5327 if (partition_designator
< 0) {
5328 log_syntax(unit
, LOG_WARNING
, filename
, line
, partition_designator
,
5329 "Invalid partition name %s, ignoring", partition
);
5332 r
= unit_full_printf(u
, mount_options
, &mount_options_resolved
);
5334 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", mount_options
);
5338 o
= new(MountOptions
, 1);
5341 *o
= (MountOptions
) {
5342 .partition_designator
= partition_designator
,
5343 .options
= TAKE_PTR(mount_options_resolved
),
5345 LIST_APPEND(mount_options
, options
, o
);
5348 r
= mount_image_add(&c
->mount_images
, &c
->n_mount_images
,
5350 .source
= sresolved
,
5351 .destination
= dresolved
,
5352 .mount_options
= options
,
5353 .ignore_enoent
= permissive
,
5354 .type
= MOUNT_IMAGE_DISCRETE
,
5361 int config_parse_extension_images(
5363 const char *filename
,
5365 const char *section
,
5366 unsigned section_line
,
5373 ExecContext
*c
= ASSERT_PTR(data
);
5374 const Unit
*u
= userdata
;
5381 if (isempty(rvalue
)) {
5382 /* Empty assignment resets the list */
5383 c
->extension_images
= mount_image_free_many(c
->extension_images
, &c
->n_extension_images
);
5387 for (const char *p
= rvalue
;;) {
5388 _cleanup_free_
char *source
= NULL
, *tuple
= NULL
, *sresolved
= NULL
;
5389 _cleanup_(mount_options_free_allp
) MountOptions
*options
= NULL
;
5390 bool permissive
= false;
5391 const char *q
= NULL
;
5394 r
= extract_first_word(&p
, &tuple
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_RETAIN_ESCAPE
);
5398 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5399 "Invalid syntax %s=%s, ignoring: %m", lvalue
, rvalue
);
5406 r
= extract_first_word(&q
, &source
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
);
5410 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5411 "Invalid syntax in %s=, ignoring: %s", lvalue
, tuple
);
5423 r
= unit_path_printf(u
, s
, &sresolved
);
5425 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5426 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", s
);
5430 r
= path_simplify_and_warn(sresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5435 _cleanup_free_
char *partition
= NULL
, *mount_options
= NULL
, *mount_options_resolved
= NULL
;
5436 MountOptions
*o
= NULL
;
5437 PartitionDesignator partition_designator
;
5439 r
= extract_many_words(&q
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
, &partition
, &mount_options
, NULL
);
5443 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", q
);
5448 /* Single set of options, applying to the root partition/single filesystem */
5450 r
= unit_full_printf(u
, partition
, &mount_options_resolved
);
5452 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", partition
);
5456 o
= new(MountOptions
, 1);
5459 *o
= (MountOptions
) {
5460 .partition_designator
= PARTITION_ROOT
,
5461 .options
= TAKE_PTR(mount_options_resolved
),
5463 LIST_APPEND(mount_options
, options
, o
);
5468 partition_designator
= partition_designator_from_string(partition
);
5469 if (partition_designator
< 0) {
5470 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid partition name %s, ignoring", partition
);
5473 r
= unit_full_printf(u
, mount_options
, &mount_options_resolved
);
5475 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", mount_options
);
5479 o
= new(MountOptions
, 1);
5482 *o
= (MountOptions
) {
5483 .partition_designator
= partition_designator
,
5484 .options
= TAKE_PTR(mount_options_resolved
),
5486 LIST_APPEND(mount_options
, options
, o
);
5489 r
= mount_image_add(&c
->extension_images
, &c
->n_extension_images
,
5491 .source
= sresolved
,
5492 .mount_options
= options
,
5493 .ignore_enoent
= permissive
,
5494 .type
= MOUNT_IMAGE_EXTENSION
,
5501 int config_parse_job_timeout_sec(
5503 const char *filename
,
5505 const char *section
,
5506 unsigned section_line
,
5513 Unit
*u
= ASSERT_PTR(data
);
5521 r
= parse_sec_fix_0(rvalue
, &usec
);
5523 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse JobTimeoutSec= parameter, ignoring: %s", rvalue
);
5527 /* If the user explicitly changed JobTimeoutSec= also change JobRunningTimeoutSec=, for compatibility with old
5528 * versions. If JobRunningTimeoutSec= was explicitly set, avoid this however as whatever the user picked should
5531 if (!u
->job_running_timeout_set
)
5532 u
->job_running_timeout
= usec
;
5534 u
->job_timeout
= usec
;
5539 int config_parse_job_running_timeout_sec(
5541 const char *filename
,
5543 const char *section
,
5544 unsigned section_line
,
5551 Unit
*u
= ASSERT_PTR(data
);
5559 r
= parse_sec_fix_0(rvalue
, &usec
);
5561 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse JobRunningTimeoutSec= parameter, ignoring: %s", rvalue
);
5565 u
->job_running_timeout
= usec
;
5566 u
->job_running_timeout_set
= true;
5571 int config_parse_emergency_action(
5573 const char *filename
,
5575 const char *section
,
5576 unsigned section_line
,
5584 EmergencyAction
*x
= ASSERT_PTR(data
);
5592 m
= ((Unit
*) userdata
)->manager
;
5596 r
= parse_emergency_action(rvalue
, MANAGER_IS_SYSTEM(m
), x
);
5598 if (r
== -EOPNOTSUPP
&& MANAGER_IS_USER(m
)) {
5599 /* Compat mode: remove for systemd 241. */
5601 log_syntax(unit
, LOG_INFO
, filename
, line
, r
,
5602 "%s= in user mode specified as \"%s\", using \"exit-force\" instead.",
5604 *x
= EMERGENCY_ACTION_EXIT_FORCE
;
5608 if (r
== -EOPNOTSUPP
)
5609 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5610 "%s= specified as %s mode action, ignoring: %s",
5611 lvalue
, MANAGER_IS_SYSTEM(m
) ? "user" : "system", rvalue
);
5613 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5614 "Failed to parse %s=, ignoring: %s", lvalue
, rvalue
);
5621 int config_parse_pid_file(
5623 const char *filename
,
5625 const char *section
,
5626 unsigned section_line
,
5633 _cleanup_free_
char *k
= NULL
, *n
= NULL
;
5634 const Unit
*u
= ASSERT_PTR(userdata
);
5642 if (isempty(rvalue
)) {
5643 /* An empty assignment removes already set value. */
5648 r
= unit_path_printf(u
, rvalue
, &k
);
5650 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
5654 /* If this is a relative path make it absolute by prefixing the /run */
5655 n
= path_make_absolute(k
, u
->manager
->prefix
[EXEC_DIRECTORY_RUNTIME
]);
5659 /* Check that the result is a sensible path */
5660 r
= path_simplify_and_warn(n
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5664 r
= patch_var_run(unit
, filename
, line
, lvalue
, &n
);
5668 free_and_replace(*s
, n
);
5672 int config_parse_exit_status(
5674 const char *filename
,
5676 const char *section
,
5677 unsigned section_line
,
5684 int *exit_status
= data
, r
;
5690 assert(exit_status
);
5692 if (isempty(rvalue
)) {
5697 r
= safe_atou8(rvalue
, &u
);
5699 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse exit status '%s', ignoring: %m", rvalue
);
5707 int config_parse_disable_controllers(
5709 const char *filename
,
5711 const char *section
,
5712 unsigned section_line
,
5720 CGroupContext
*c
= data
;
5721 CGroupMask disabled_mask
;
5723 /* 1. If empty, make all controllers eligible for use again.
5724 * 2. If non-empty, merge all listed controllers, space separated. */
5726 if (isempty(rvalue
)) {
5727 c
->disable_controllers
= 0;
5731 r
= cg_mask_from_string(rvalue
, &disabled_mask
);
5732 if (r
< 0 || disabled_mask
<= 0) {
5733 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid cgroup string: %s, ignoring", rvalue
);
5737 c
->disable_controllers
|= disabled_mask
;
5742 int config_parse_ip_filter_bpf_progs(
5744 const char *filename
,
5746 const char *section
,
5747 unsigned section_line
,
5754 _cleanup_free_
char *resolved
= NULL
;
5755 const Unit
*u
= userdata
;
5756 char ***paths
= ASSERT_PTR(data
);
5763 if (isempty(rvalue
)) {
5764 *paths
= strv_free(*paths
);
5768 r
= unit_path_printf(u
, rvalue
, &resolved
);
5770 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
5774 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5778 if (strv_contains(*paths
, resolved
))
5781 r
= strv_extend(paths
, resolved
);
5785 r
= bpf_firewall_supported();
5788 if (r
!= BPF_FIREWALL_SUPPORTED_WITH_MULTI
) {
5789 static bool warned
= false;
5791 log_full(warned
? LOG_DEBUG
: LOG_WARNING
,
5792 "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"
5793 "Starting this unit will fail! (This warning is only shown for the first loaded unit using IP firewalling.)", filename
, line
, lvalue
, rvalue
);
5801 int config_parse_bpf_foreign_program(
5803 const char *filename
,
5805 const char *section
,
5806 unsigned section_line
,
5812 _cleanup_free_
char *resolved
= NULL
, *word
= NULL
;
5813 CGroupContext
*c
= data
;
5814 const char *p
= ASSERT_PTR(rvalue
);
5821 if (isempty(rvalue
)) {
5822 while (c
->bpf_foreign_programs
)
5823 cgroup_context_remove_bpf_foreign_program(c
, c
->bpf_foreign_programs
);
5828 r
= extract_first_word(&p
, &word
, ":", 0);
5832 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse foreign BPF program, ignoring: %s", rvalue
);
5835 if (r
== 0 || isempty(p
)) {
5836 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid syntax in %s=, ignoring: %s", lvalue
, rvalue
);
5840 attach_type
= bpf_cgroup_attach_type_from_string(word
);
5841 if (attach_type
< 0) {
5842 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Unknown BPF attach type=%s, ignoring: %s", word
, rvalue
);
5846 r
= unit_path_printf(u
, p
, &resolved
);
5848 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %s", p
, rvalue
);
5852 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5856 r
= cgroup_add_bpf_foreign_program(c
, attach_type
, resolved
);
5858 return log_error_errno(r
, "Failed to add foreign BPF program to cgroup context: %m");
5863 int config_parse_cgroup_socket_bind(
5865 const char *filename
,
5867 const char *section
,
5868 unsigned section_line
,
5874 _cleanup_free_ CGroupSocketBindItem
*item
= NULL
;
5875 CGroupSocketBindItem
**head
= data
;
5876 uint16_t nr_ports
, port_min
;
5877 int af
, ip_protocol
, r
;
5879 if (isempty(rvalue
)) {
5880 cgroup_context_remove_socket_bind(head
);
5884 r
= parse_socket_bind_item(rvalue
, &af
, &ip_protocol
, &nr_ports
, &port_min
);
5888 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5889 "Unable to parse %s= assignment, ignoring: %s", lvalue
, rvalue
);
5893 item
= new(CGroupSocketBindItem
, 1);
5896 *item
= (CGroupSocketBindItem
) {
5897 .address_family
= af
,
5898 .ip_protocol
= ip_protocol
,
5899 .nr_ports
= nr_ports
,
5900 .port_min
= port_min
,
5903 LIST_PREPEND(socket_bind_items
, *head
, TAKE_PTR(item
));
5908 int config_parse_restrict_network_interfaces(
5910 const char *filename
,
5912 const char *section
,
5913 unsigned section_line
,
5919 CGroupContext
*c
= ASSERT_PTR(data
);
5920 bool is_allow_rule
= true;
5927 if (isempty(rvalue
)) {
5928 /* Empty assignment resets the list */
5929 c
->restrict_network_interfaces
= set_free(c
->restrict_network_interfaces
);
5933 if (rvalue
[0] == '~') {
5934 is_allow_rule
= false;
5938 if (set_isempty(c
->restrict_network_interfaces
))
5939 /* Only initialize this when creating the set */
5940 c
->restrict_network_interfaces_is_allow_list
= is_allow_rule
;
5942 for (const char *p
= rvalue
;;) {
5943 _cleanup_free_
char *word
= NULL
;
5945 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
5951 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5952 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
5956 if (!ifname_valid(word
)) {
5957 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid interface name, ignoring: %s", word
);
5961 if (c
->restrict_network_interfaces_is_allow_list
!= is_allow_rule
)
5962 free(set_remove(c
->restrict_network_interfaces
, word
));
5964 r
= set_put_strdup(&c
->restrict_network_interfaces
, word
);
5973 static int merge_by_names(Unit
**u
, Set
*names
, const char *id
) {
5980 /* Let's try to add in all names that are aliases of this unit */
5981 while ((k
= set_steal_first(names
))) {
5982 _cleanup_free_ _unused_
char *free_k
= k
;
5984 /* First try to merge in the other name into our unit */
5985 r
= unit_merge_by_name(*u
, k
);
5989 /* Hmm, we couldn't merge the other unit into ours? Then let's try it the other way
5992 other
= manager_get_unit((*u
)->manager
, k
);
5994 return r
; /* return previous failure */
5996 r
= unit_merge(other
, *u
);
6001 return merge_by_names(u
, names
, NULL
);
6004 if (streq_ptr(id
, k
))
6005 unit_choose_id(*u
, id
);
6011 int unit_load_fragment(Unit
*u
) {
6012 const char *fragment
;
6013 _cleanup_set_free_free_ Set
*names
= NULL
;
6017 assert(u
->load_state
== UNIT_STUB
);
6021 u
->access_selinux_context
= mfree(u
->access_selinux_context
);
6022 u
->load_state
= UNIT_LOADED
;
6026 /* Possibly rebuild the fragment map to catch new units */
6027 r
= unit_file_build_name_map(&u
->manager
->lookup_paths
,
6028 &u
->manager
->unit_cache_timestamp_hash
,
6029 &u
->manager
->unit_id_map
,
6030 &u
->manager
->unit_name_map
,
6031 &u
->manager
->unit_path_cache
);
6033 return log_error_errno(r
, "Failed to rebuild name map: %m");
6035 r
= unit_file_find_fragment(u
->manager
->unit_id_map
,
6036 u
->manager
->unit_name_map
,
6040 if (r
< 0 && r
!= -ENOENT
)
6044 /* Open the file, check if this is a mask, otherwise read. */
6045 _cleanup_fclose_
FILE *f
= NULL
;
6048 /* Try to open the file name. A symlink is OK, for example for linked files or masks. We
6049 * expect that all symlinks within the lookup paths have been already resolved, but we don't
6050 * verify this here. */
6051 f
= fopen(fragment
, "re");
6053 return log_unit_notice_errno(u
, errno
, "Failed to open %s: %m", fragment
);
6055 if (fstat(fileno(f
), &st
) < 0)
6058 r
= free_and_strdup(&u
->fragment_path
, fragment
);
6062 if (null_or_empty(&st
)) {
6063 /* Unit file is masked */
6065 u
->load_state
= u
->perpetual
? UNIT_LOADED
: UNIT_MASKED
; /* don't allow perpetual units to ever be masked */
6066 u
->fragment_mtime
= 0;
6067 u
->access_selinux_context
= mfree(u
->access_selinux_context
);
6070 if (mac_selinux_use()) {
6071 _cleanup_freecon_
char *selcon
= NULL
;
6073 /* Cache the SELinux context of the unit file here. We'll make use of when checking access permissions to loaded units */
6074 r
= fgetfilecon_raw(fileno(f
), &selcon
);
6076 log_unit_warning_errno(u
, r
, "Failed to read SELinux context of '%s', ignoring: %m", fragment
);
6078 r
= free_and_strdup(&u
->access_selinux_context
, selcon
);
6083 u
->access_selinux_context
= mfree(u
->access_selinux_context
);
6085 u
->load_state
= UNIT_LOADED
;
6086 u
->fragment_mtime
= timespec_load(&st
.st_mtim
);
6088 /* Now, parse the file contents */
6089 r
= config_parse(u
->id
, fragment
, f
,
6090 UNIT_VTABLE(u
)->sections
,
6091 config_item_perf_lookup
, load_fragment_gperf_lookup
,
6096 log_unit_notice_errno(u
, r
, "Unit configuration has fatal error, unit will not be started.");
6102 /* Call merge_by_names with the name derived from the fragment path as the preferred name.
6104 * We do the merge dance here because for some unit types, the unit might have aliases which are not
6105 * declared in the file system. In particular, this is true (and frequent) for device and swap units.
6107 const char *id
= u
->id
;
6108 _cleanup_free_
char *free_id
= NULL
;
6111 id
= basename(fragment
);
6112 if (unit_name_is_valid(id
, UNIT_NAME_TEMPLATE
)) {
6113 assert(u
->instance
); /* If we're not trying to use a template for non-instanced unit,
6114 * this must be set. */
6116 r
= unit_name_replace_instance(id
, u
->instance
, &free_id
);
6118 return log_debug_errno(r
, "Failed to build id (%s + %s): %m", id
, u
->instance
);
6124 r
= merge_by_names(&merged
, names
, id
);
6129 u
->load_state
= UNIT_MERGED
;
6134 void unit_dump_config_items(FILE *f
) {
6135 static const struct {
6136 const ConfigParserCallback callback
;
6139 { config_parse_warn_compat
, "NOTSUPPORTED" },
6140 { config_parse_int
, "INTEGER" },
6141 { config_parse_unsigned
, "UNSIGNED" },
6142 { config_parse_iec_size
, "SIZE" },
6143 { config_parse_iec_uint64
, "SIZE" },
6144 { config_parse_si_uint64
, "SIZE" },
6145 { config_parse_bool
, "BOOLEAN" },
6146 { config_parse_string
, "STRING" },
6147 { config_parse_path
, "PATH" },
6148 { config_parse_unit_path_printf
, "PATH" },
6149 { config_parse_colon_separated_paths
, "PATH" },
6150 { config_parse_strv
, "STRING [...]" },
6151 { config_parse_exec_nice
, "NICE" },
6152 { config_parse_exec_oom_score_adjust
, "OOMSCOREADJUST" },
6153 { config_parse_exec_io_class
, "IOCLASS" },
6154 { config_parse_exec_io_priority
, "IOPRIORITY" },
6155 { config_parse_exec_cpu_sched_policy
, "CPUSCHEDPOLICY" },
6156 { config_parse_exec_cpu_sched_prio
, "CPUSCHEDPRIO" },
6157 { config_parse_exec_cpu_affinity
, "CPUAFFINITY" },
6158 { config_parse_mode
, "MODE" },
6159 { config_parse_unit_env_file
, "FILE" },
6160 { config_parse_exec_output
, "OUTPUT" },
6161 { config_parse_exec_input
, "INPUT" },
6162 { config_parse_log_facility
, "FACILITY" },
6163 { config_parse_log_level
, "LEVEL" },
6164 { config_parse_exec_secure_bits
, "SECUREBITS" },
6165 { config_parse_capability_set
, "BOUNDINGSET" },
6166 { config_parse_rlimit
, "LIMIT" },
6167 { config_parse_unit_deps
, "UNIT [...]" },
6168 { config_parse_exec
, "PATH [ARGUMENT [...]]" },
6169 { config_parse_service_type
, "SERVICETYPE" },
6170 { config_parse_service_exit_type
, "SERVICEEXITTYPE" },
6171 { config_parse_service_restart
, "SERVICERESTART" },
6172 { config_parse_service_timeout_failure_mode
, "TIMEOUTMODE" },
6173 { config_parse_kill_mode
, "KILLMODE" },
6174 { config_parse_signal
, "SIGNAL" },
6175 { config_parse_socket_listen
, "SOCKET [...]" },
6176 { config_parse_socket_bind
, "SOCKETBIND" },
6177 { config_parse_socket_bindtodevice
, "NETWORKINTERFACE" },
6178 { config_parse_sec
, "SECONDS" },
6179 { config_parse_nsec
, "NANOSECONDS" },
6180 { config_parse_namespace_path_strv
, "PATH [...]" },
6181 { config_parse_bind_paths
, "PATH[:PATH[:OPTIONS]] [...]" },
6182 { config_parse_unit_requires_mounts_for
, "PATH [...]" },
6183 { config_parse_exec_mount_flags
, "MOUNTFLAG [...]" },
6184 { config_parse_unit_string_printf
, "STRING" },
6185 { config_parse_trigger_unit
, "UNIT" },
6186 { config_parse_timer
, "TIMER" },
6187 { config_parse_path_spec
, "PATH" },
6188 { config_parse_notify_access
, "ACCESS" },
6189 { config_parse_ip_tos
, "TOS" },
6190 { config_parse_unit_condition_path
, "CONDITION" },
6191 { config_parse_unit_condition_string
, "CONDITION" },
6192 { config_parse_unit_slice
, "SLICE" },
6193 { config_parse_documentation
, "URL" },
6194 { config_parse_service_timeout
, "SECONDS" },
6195 { config_parse_emergency_action
, "ACTION" },
6196 { config_parse_set_status
, "STATUS" },
6197 { config_parse_service_sockets
, "SOCKETS" },
6198 { config_parse_environ
, "ENVIRON" },
6200 { config_parse_syscall_filter
, "SYSCALLS" },
6201 { config_parse_syscall_archs
, "ARCHS" },
6202 { config_parse_syscall_errno
, "ERRNO" },
6203 { config_parse_syscall_log
, "SYSCALLS" },
6204 { config_parse_address_families
, "FAMILIES" },
6205 { config_parse_restrict_namespaces
, "NAMESPACES" },
6207 { config_parse_restrict_filesystems
, "FILESYSTEMS" },
6208 { config_parse_cpu_shares
, "SHARES" },
6209 { config_parse_cg_weight
, "WEIGHT" },
6210 { config_parse_cg_cpu_weight
, "CPUWEIGHT" },
6211 { config_parse_memory_limit
, "LIMIT" },
6212 { config_parse_device_allow
, "DEVICE" },
6213 { config_parse_device_policy
, "POLICY" },
6214 { config_parse_io_limit
, "LIMIT" },
6215 { config_parse_io_device_weight
, "DEVICEWEIGHT" },
6216 { config_parse_io_device_latency
, "DEVICELATENCY" },
6217 { config_parse_blockio_bandwidth
, "BANDWIDTH" },
6218 { config_parse_blockio_weight
, "WEIGHT" },
6219 { config_parse_blockio_device_weight
, "DEVICEWEIGHT" },
6220 { config_parse_long
, "LONG" },
6221 { config_parse_socket_service
, "SERVICE" },
6223 { config_parse_exec_selinux_context
, "LABEL" },
6225 { config_parse_job_mode
, "MODE" },
6226 { config_parse_job_mode_isolate
, "BOOLEAN" },
6227 { config_parse_personality
, "PERSONALITY" },
6230 const char *prev
= NULL
;
6234 NULSTR_FOREACH(i
, load_fragment_gperf_nulstr
) {
6235 const char *rvalue
= "OTHER", *lvalue
;
6236 const ConfigPerfItem
*p
;
6239 assert_se(p
= load_fragment_gperf_lookup(i
, strlen(i
)));
6241 /* Hide legacy settings */
6242 if (p
->parse
== config_parse_warn_compat
&&
6243 p
->ltype
== DISABLED_LEGACY
)
6246 for (size_t j
= 0; j
< ELEMENTSOF(table
); j
++)
6247 if (p
->parse
== table
[j
].callback
) {
6248 rvalue
= table
[j
].rvalue
;
6252 dot
= strchr(i
, '.');
6253 lvalue
= dot
? dot
+ 1 : i
;
6256 size_t prefix_len
= dot
- i
;
6258 if (!prev
|| !strneq(prev
, i
, prefix_len
+1)) {
6262 fprintf(f
, "[%.*s]\n", (int) prefix_len
, i
);
6266 fprintf(f
, "%s=%s\n", lvalue
, rvalue
);
6271 int config_parse_cpu_affinity2(
6273 const char *filename
,
6275 const char *section
,
6276 unsigned section_line
,
6283 CPUSet
*affinity
= ASSERT_PTR(data
);
6285 (void) parse_cpu_set_extend(rvalue
, affinity
, true, unit
, filename
, line
, lvalue
);
6290 int config_parse_show_status(
6292 const char *filename
,
6294 const char *section
,
6295 unsigned section_line
,
6303 ShowStatus
*b
= ASSERT_PTR(data
);
6309 k
= parse_show_status(rvalue
, b
);
6311 log_syntax(unit
, LOG_WARNING
, filename
, line
, k
, "Failed to parse show status setting, ignoring: %s", rvalue
);
6316 int config_parse_output_restricted(
6318 const char *filename
,
6320 const char *section
,
6321 unsigned section_line
,
6328 ExecOutput t
, *eo
= ASSERT_PTR(data
);
6329 bool obsolete
= false;
6335 if (streq(rvalue
, "syslog")) {
6336 t
= EXEC_OUTPUT_JOURNAL
;
6338 } else if (streq(rvalue
, "syslog+console")) {
6339 t
= EXEC_OUTPUT_JOURNAL_AND_CONSOLE
;
6342 t
= exec_output_from_string(rvalue
);
6344 log_syntax(unit
, LOG_WARNING
, filename
, line
, t
, "Failed to parse output type, ignoring: %s", rvalue
);
6348 if (IN_SET(t
, EXEC_OUTPUT_SOCKET
, EXEC_OUTPUT_NAMED_FD
, EXEC_OUTPUT_FILE
, EXEC_OUTPUT_FILE_APPEND
, EXEC_OUTPUT_FILE_TRUNCATE
)) {
6349 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Standard output types socket, fd:, file:, append:, truncate: are not supported as defaults, ignoring: %s", rvalue
);
6355 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
6356 "Standard output type %s is obsolete, automatically updating to %s. Please update your configuration.",
6357 rvalue
, exec_output_to_string(t
));
6363 int config_parse_crash_chvt(
6365 const char *filename
,
6367 const char *section
,
6368 unsigned section_line
,
6382 r
= parse_crash_chvt(rvalue
, data
);
6384 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse CrashChangeVT= setting, ignoring: %s", rvalue
);
6389 int config_parse_swap_priority(
6391 const char *filename
,
6393 const char *section
,
6394 unsigned section_line
,
6401 Swap
*s
= ASSERT_PTR(userdata
);
6409 if (isempty(rvalue
)) {
6410 s
->parameters_fragment
.priority
= -1;
6411 s
->parameters_fragment
.priority_set
= false;
6415 r
= safe_atoi(rvalue
, &priority
);
6417 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid swap priority '%s', ignoring.", rvalue
);
6421 if (priority
< -1) {
6422 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
);
6426 if (priority
> 32767) {
6427 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Swap priority out of range, ignoring: %s", rvalue
);
6431 s
->parameters_fragment
.priority
= priority
;
6432 s
->parameters_fragment
.priority_set
= true;
6436 int config_parse_watchdog_sec(
6438 const char *filename
,
6440 const char *section
,
6441 unsigned section_line
,
6448 usec_t
*usec
= data
;
6454 /* This is called for {Runtime,Reboot,KExec}WatchdogSec= where "default" maps to
6455 * USEC_INFINITY internally. */
6457 if (streq(rvalue
, "default"))
6458 *usec
= USEC_INFINITY
;
6459 else if (streq(rvalue
, "off"))
6462 return config_parse_sec(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
);
6467 int config_parse_tty_size(
6469 const char *filename
,
6471 const char *section
,
6472 unsigned section_line
,
6479 unsigned *sz
= data
;
6485 if (isempty(rvalue
)) {
6490 return config_parse_unsigned(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
);