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
= userdata
;
355 r
= unit_full_printf(u
, rvalue
, &k
);
357 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
361 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
364 int config_parse_unit_strv_printf(
366 const char *filename
,
369 unsigned section_line
,
376 const Unit
*u
= userdata
;
377 _cleanup_free_
char *k
= NULL
;
385 r
= unit_full_printf(u
, rvalue
, &k
);
387 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
391 return config_parse_strv(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
394 int config_parse_unit_path_printf(
396 const char *filename
,
399 unsigned section_line
,
406 _cleanup_free_
char *k
= NULL
;
407 const Unit
*u
= userdata
;
416 r
= unit_path_printf(u
, rvalue
, &k
);
418 log_syntax(unit
, fatal
? LOG_ERR
: LOG_WARNING
, filename
, line
, r
,
419 "Failed to resolve unit specifiers in '%s'%s: %m",
420 rvalue
, fatal
? "" : ", ignoring");
421 return fatal
? -ENOEXEC
: 0;
424 return config_parse_path(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
427 int config_parse_colon_separated_paths(
429 const char *filename
,
432 unsigned section_line
,
439 const Unit
*u
= userdata
;
447 if (isempty(rvalue
)) {
448 /* Empty assignment resets the list */
449 *sv
= strv_free(*sv
);
453 for (const char *p
= rvalue
;;) {
454 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
456 r
= extract_first_word(&p
, &word
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
460 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
466 r
= unit_path_printf(u
, word
, &k
);
468 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
469 "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
473 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
477 r
= strv_consume(sv
, TAKE_PTR(k
));
485 int config_parse_unit_path_strv_printf(
487 const char *filename
,
490 unsigned section_line
,
498 const Unit
*u
= userdata
;
506 if (isempty(rvalue
)) {
511 for (const char *p
= rvalue
;;) {
512 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
514 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
520 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
521 "Invalid syntax, ignoring: %s", rvalue
);
525 r
= unit_path_printf(u
, word
, &k
);
527 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
528 "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
532 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
536 r
= strv_consume(x
, TAKE_PTR(k
));
542 static int patch_var_run(
544 const char *filename
,
552 e
= path_startswith(*path
, "/var/run/");
556 z
= path_join("/run/", e
);
560 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
561 "%s= references a path below legacy directory /var/run/, updating %s → %s; "
562 "please update the unit file accordingly.", lvalue
, *path
, z
);
564 free_and_replace(*path
, z
);
569 int config_parse_socket_listen(
571 const char *filename
,
574 unsigned section_line
,
581 _cleanup_free_ SocketPort
*p
= NULL
;
593 if (isempty(rvalue
)) {
594 /* An empty assignment removes all ports */
595 socket_free_ports(s
);
599 p
= new0(SocketPort
, 1);
603 if (ltype
!= SOCKET_SOCKET
) {
604 _cleanup_free_
char *k
= NULL
;
606 r
= unit_path_printf(UNIT(s
), rvalue
, &k
);
608 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
612 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
616 if (ltype
== SOCKET_FIFO
) {
617 r
= patch_var_run(unit
, filename
, line
, lvalue
, &k
);
622 free_and_replace(p
->path
, k
);
625 } else if (streq(lvalue
, "ListenNetlink")) {
626 _cleanup_free_
char *k
= NULL
;
628 r
= unit_path_printf(UNIT(s
), rvalue
, &k
);
630 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
634 r
= socket_address_parse_netlink(&p
->address
, k
);
636 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse address value in '%s', ignoring: %m", k
);
640 p
->type
= SOCKET_SOCKET
;
643 _cleanup_free_
char *k
= NULL
;
645 r
= unit_path_printf(UNIT(s
), rvalue
, &k
);
647 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
651 if (k
[0] == '/') { /* Only for AF_UNIX file system sockets… */
652 r
= patch_var_run(unit
, filename
, line
, lvalue
, &k
);
657 r
= socket_address_parse_and_warn(&p
->address
, k
);
659 if (r
!= -EAFNOSUPPORT
)
660 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse address value in '%s', ignoring: %m", k
);
664 if (streq(lvalue
, "ListenStream"))
665 p
->address
.type
= SOCK_STREAM
;
666 else if (streq(lvalue
, "ListenDatagram"))
667 p
->address
.type
= SOCK_DGRAM
;
669 assert(streq(lvalue
, "ListenSequentialPacket"));
670 p
->address
.type
= SOCK_SEQPACKET
;
673 if (socket_address_family(&p
->address
) != AF_UNIX
&& p
->address
.type
== SOCK_SEQPACKET
) {
674 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Address family not supported, ignoring: %s", rvalue
);
678 p
->type
= SOCKET_SOCKET
;
682 p
->auxiliary_fds
= NULL
;
683 p
->n_auxiliary_fds
= 0;
686 LIST_FIND_TAIL(port
, s
->ports
, tail
);
687 LIST_INSERT_AFTER(port
, s
->ports
, tail
, p
);
694 int config_parse_exec_nice(
696 const char *filename
,
699 unsigned section_line
,
706 ExecContext
*c
= data
;
714 if (isempty(rvalue
)) {
719 r
= parse_nice(rvalue
, &priority
);
722 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Nice priority out of range, ignoring: %s", rvalue
);
724 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse nice priority '%s', ignoring: %m", rvalue
);
734 int config_parse_exec_oom_score_adjust(
736 const char *filename
,
739 unsigned section_line
,
746 ExecContext
*c
= data
;
754 if (isempty(rvalue
)) {
755 c
->oom_score_adjust_set
= false;
759 r
= parse_oom_score_adjust(rvalue
, &oa
);
762 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "OOM score adjust value out of range, ignoring: %s", rvalue
);
764 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse the OOM score adjust value '%s', ignoring: %m", rvalue
);
768 c
->oom_score_adjust
= oa
;
769 c
->oom_score_adjust_set
= true;
774 int config_parse_exec_coredump_filter(
776 const char *filename
,
779 unsigned section_line
,
786 ExecContext
*c
= data
;
794 if (isempty(rvalue
)) {
795 c
->coredump_filter
= 0;
796 c
->coredump_filter_set
= false;
801 r
= coredump_filter_mask_from_string(rvalue
, &f
);
803 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
804 "Failed to parse the CoredumpFilter=%s, ignoring: %m", rvalue
);
808 c
->coredump_filter
|= f
;
809 c
->oom_score_adjust_set
= true;
813 int config_parse_kill_mode(
815 const char *filename
,
818 unsigned section_line
,
825 KillMode
*k
= data
, m
;
832 if (isempty(rvalue
)) {
833 *k
= KILL_CONTROL_GROUP
;
837 m
= kill_mode_from_string(rvalue
);
839 log_syntax(unit
, LOG_WARNING
, filename
, line
, m
,
840 "Failed to parse kill mode specification, ignoring: %s", rvalue
);
845 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
846 "Unit uses KillMode=none. "
847 "This is unsafe, as it disables systemd's process lifecycle management for the service. "
848 "Please update the service to use a safer KillMode=, such as 'mixed' or 'control-group'. "
849 "Support for KillMode=none is deprecated and will eventually be removed.");
855 int config_parse_exec(
857 const char *filename
,
860 unsigned section_line
,
867 ExecCommand
**e
= data
;
868 const Unit
*u
= userdata
;
880 if (isempty(rvalue
)) {
881 /* An empty assignment resets the list */
882 *e
= exec_command_free_list(*e
);
888 _cleanup_free_
char *path
= NULL
, *firstword
= NULL
;
889 ExecCommandFlags flags
= 0;
890 bool ignore
= false, separate_argv0
= false;
891 _cleanup_free_ ExecCommand
*nce
= NULL
;
892 _cleanup_strv_free_
char **n
= NULL
;
898 r
= extract_first_word_and_warn(&p
, &firstword
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
902 /* A lone ";" is a separator. Let's make sure we don't treat it as an executable name. */
903 if (streq(firstword
, ";")) {
910 /* We accept an absolute path as first argument. If it's prefixed with - and the path doesn't
911 * exist, we ignore it instead of erroring out; if it's prefixed with @, we allow overriding of
912 * argv[0]; if it's prefixed with :, we will not do environment variable substitution;
913 * if it's prefixed with +, it will be run with full privileges and no sandboxing; if
914 * it's prefixed with '!' we apply sandboxing, but do not change user/group credentials; if
915 * it's prefixed with '!!', then we apply user/group credentials if the kernel supports ambient
916 * capabilities -- if it doesn't we don't apply the credentials themselves, but do apply most
917 * other sandboxing, with some special exceptions for changing UID.
919 * The idea is that '!!' may be used to write services that can take benefit of systemd's
920 * UID/GID dropping if the kernel supports ambient creds, but provide an automatic fallback to
921 * privilege dropping within the daemon if the kernel does not offer that. */
923 if (*f
== '-' && !(flags
& EXEC_COMMAND_IGNORE_FAILURE
)) {
924 flags
|= EXEC_COMMAND_IGNORE_FAILURE
;
926 } else if (*f
== '@' && !separate_argv0
)
927 separate_argv0
= true;
928 else if (*f
== ':' && !(flags
& EXEC_COMMAND_NO_ENV_EXPAND
))
929 flags
|= EXEC_COMMAND_NO_ENV_EXPAND
;
930 else if (*f
== '+' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
931 flags
|= EXEC_COMMAND_FULLY_PRIVILEGED
;
932 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
933 flags
|= EXEC_COMMAND_NO_SETUID
;
934 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_AMBIENT_MAGIC
))) {
935 flags
&= ~EXEC_COMMAND_NO_SETUID
;
936 flags
|= EXEC_COMMAND_AMBIENT_MAGIC
;
942 r
= unit_path_printf(u
, f
, &path
);
944 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
945 "Failed to resolve unit specifiers in '%s'%s: %m",
946 f
, ignore
? ", ignoring" : "");
947 return ignore
? 0 : -ENOEXEC
;
951 /* First word is either "-" or "@" with no command. */
952 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
953 "Empty path in command line%s: '%s'",
954 ignore
? ", ignoring" : "", rvalue
);
955 return ignore
? 0 : -ENOEXEC
;
957 if (!string_is_safe(path
)) {
958 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
959 "Executable name contains special characters%s: %s",
960 ignore
? ", ignoring" : "", path
);
961 return ignore
? 0 : -ENOEXEC
;
963 if (endswith(path
, "/")) {
964 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
965 "Executable path specifies a directory%s: %s",
966 ignore
? ", ignoring" : "", path
);
967 return ignore
? 0 : -ENOEXEC
;
970 if (!(path_is_absolute(path
) ? path_is_valid(path
) : filename_is_valid(path
))) {
971 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
972 "Neither a valid executable name nor an absolute path%s: %s",
973 ignore
? ", ignoring" : "", path
);
974 return ignore
? 0 : -ENOEXEC
;
977 if (!separate_argv0
) {
980 if (!GREEDY_REALLOC0(n
, nlen
+ 2))
992 while (!isempty(p
)) {
993 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
995 /* Check explicitly for an unquoted semicolon as
996 * command separator token. */
997 if (p
[0] == ';' && (!p
[1] || strchr(WHITESPACE
, p
[1]))) {
999 p
+= strspn(p
, WHITESPACE
);
1004 /* Check for \; explicitly, to not confuse it with \\; or "\;" or "\\;" etc.
1005 * extract_first_word() would return the same for all of those. */
1006 if (p
[0] == '\\' && p
[1] == ';' && (!p
[2] || strchr(WHITESPACE
, p
[2]))) {
1010 p
+= strspn(p
, WHITESPACE
);
1012 if (!GREEDY_REALLOC0(n
, nlen
+ 2))
1023 r
= extract_first_word_and_warn(&p
, &word
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
1027 return ignore
? 0 : -ENOEXEC
;
1029 r
= unit_full_printf(u
, word
, &resolved
);
1031 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
1032 "Failed to resolve unit specifiers in %s%s: %m",
1033 word
, ignore
? ", ignoring" : "");
1034 return ignore
? 0 : -ENOEXEC
;
1037 if (!GREEDY_REALLOC(n
, nlen
+ 2))
1040 n
[nlen
++] = TAKE_PTR(resolved
);
1045 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
1046 "Empty executable name or zeroeth argument%s: %s",
1047 ignore
? ", ignoring" : "", rvalue
);
1048 return ignore
? 0 : -ENOEXEC
;
1051 nce
= new0(ExecCommand
, 1);
1055 nce
->argv
= TAKE_PTR(n
);
1056 nce
->path
= TAKE_PTR(path
);
1059 exec_command_append_list(e
, nce
);
1061 /* Do not _cleanup_free_ these. */
1065 } while (semicolon
);
1070 int config_parse_socket_bindtodevice(
1072 const char *filename
,
1074 const char *section
,
1075 unsigned section_line
,
1089 if (isempty(rvalue
) || streq(rvalue
, "*")) {
1090 s
->bind_to_device
= mfree(s
->bind_to_device
);
1094 if (!ifname_valid(rvalue
)) {
1095 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid interface name, ignoring: %s", rvalue
);
1099 return free_and_strdup_warn(&s
->bind_to_device
, rvalue
);
1102 int config_parse_exec_input(
1104 const char *filename
,
1106 const char *section
,
1107 unsigned section_line
,
1114 ExecContext
*c
= data
;
1115 const Unit
*u
= userdata
;
1125 n
= startswith(rvalue
, "fd:");
1127 _cleanup_free_
char *resolved
= NULL
;
1129 r
= unit_fd_printf(u
, n
, &resolved
);
1131 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", n
);
1135 if (isempty(resolved
))
1136 resolved
= mfree(resolved
);
1137 else if (!fdname_is_valid(resolved
)) {
1138 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", resolved
);
1142 free_and_replace(c
->stdio_fdname
[STDIN_FILENO
], resolved
);
1144 ei
= EXEC_INPUT_NAMED_FD
;
1146 } else if ((n
= startswith(rvalue
, "file:"))) {
1147 _cleanup_free_
char *resolved
= NULL
;
1149 r
= unit_path_printf(u
, n
, &resolved
);
1151 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", n
);
1155 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1159 free_and_replace(c
->stdio_file
[STDIN_FILENO
], resolved
);
1161 ei
= EXEC_INPUT_FILE
;
1164 ei
= exec_input_from_string(rvalue
);
1166 log_syntax(unit
, LOG_WARNING
, filename
, line
, ei
, "Failed to parse input specifier, ignoring: %s", rvalue
);
1175 int config_parse_exec_input_text(
1177 const char *filename
,
1179 const char *section
,
1180 unsigned section_line
,
1187 _cleanup_free_
char *unescaped
= NULL
, *resolved
= NULL
;
1188 ExecContext
*c
= data
;
1189 const Unit
*u
= userdata
;
1197 if (isempty(rvalue
)) {
1198 /* Reset if the empty string is assigned */
1199 c
->stdin_data
= mfree(c
->stdin_data
);
1200 c
->stdin_data_size
= 0;
1204 ssize_t l
= cunescape(rvalue
, 0, &unescaped
);
1206 log_syntax(unit
, LOG_WARNING
, filename
, line
, l
,
1207 "Failed to decode C escaped text '%s', ignoring: %m", rvalue
);
1211 r
= unit_full_printf_full(u
, unescaped
, EXEC_STDIN_DATA_MAX
, &resolved
);
1213 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1214 "Failed to resolve unit specifiers in '%s', ignoring: %m", unescaped
);
1218 size_t sz
= strlen(resolved
);
1219 if (c
->stdin_data_size
+ sz
+ 1 < c
->stdin_data_size
|| /* check for overflow */
1220 c
->stdin_data_size
+ sz
+ 1 > EXEC_STDIN_DATA_MAX
) {
1221 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
1222 "Standard input data too large (%zu), maximum of %zu permitted, ignoring.",
1223 c
->stdin_data_size
+ sz
, (size_t) EXEC_STDIN_DATA_MAX
);
1227 void *p
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
+ 1);
1231 *((char*) mempcpy((char*) p
+ c
->stdin_data_size
, resolved
, sz
)) = '\n';
1234 c
->stdin_data_size
+= sz
+ 1;
1239 int config_parse_exec_input_data(
1241 const char *filename
,
1243 const char *section
,
1244 unsigned section_line
,
1251 _cleanup_free_
void *p
= NULL
;
1252 ExecContext
*c
= data
;
1262 if (isempty(rvalue
)) {
1263 /* Reset if the empty string is assigned */
1264 c
->stdin_data
= mfree(c
->stdin_data
);
1265 c
->stdin_data_size
= 0;
1269 r
= unbase64mem(rvalue
, SIZE_MAX
, &p
, &sz
);
1271 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1272 "Failed to decode base64 data, ignoring: %s", rvalue
);
1278 if (c
->stdin_data_size
+ sz
< c
->stdin_data_size
|| /* check for overflow */
1279 c
->stdin_data_size
+ sz
> EXEC_STDIN_DATA_MAX
) {
1280 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
1281 "Standard input data too large (%zu), maximum of %zu permitted, ignoring.",
1282 c
->stdin_data_size
+ sz
, (size_t) EXEC_STDIN_DATA_MAX
);
1286 q
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
);
1290 memcpy((uint8_t*) q
+ c
->stdin_data_size
, p
, sz
);
1293 c
->stdin_data_size
+= sz
;
1298 int config_parse_exec_output(
1300 const char *filename
,
1302 const char *section
,
1303 unsigned section_line
,
1310 _cleanup_free_
char *resolved
= NULL
;
1312 ExecContext
*c
= data
;
1313 const Unit
*u
= userdata
;
1314 bool obsolete
= false;
1324 n
= startswith(rvalue
, "fd:");
1326 r
= unit_fd_printf(u
, n
, &resolved
);
1328 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", n
);
1332 if (isempty(resolved
))
1333 resolved
= mfree(resolved
);
1334 else if (!fdname_is_valid(resolved
)) {
1335 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", resolved
);
1339 eo
= EXEC_OUTPUT_NAMED_FD
;
1341 } else if (streq(rvalue
, "syslog")) {
1342 eo
= EXEC_OUTPUT_JOURNAL
;
1345 } else if (streq(rvalue
, "syslog+console")) {
1346 eo
= EXEC_OUTPUT_JOURNAL_AND_CONSOLE
;
1349 } else if ((n
= startswith(rvalue
, "file:"))) {
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
;
1363 } else if ((n
= startswith(rvalue
, "append:"))) {
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_APPEND
;
1377 } else if ((n
= startswith(rvalue
, "truncate:"))) {
1379 r
= unit_path_printf(u
, n
, &resolved
);
1381 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", n
);
1385 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1389 eo
= EXEC_OUTPUT_FILE_TRUNCATE
;
1391 eo
= exec_output_from_string(rvalue
);
1393 log_syntax(unit
, LOG_WARNING
, filename
, line
, eo
, "Failed to parse output specifier, ignoring: %s", rvalue
);
1399 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
1400 "Standard output type %s is obsolete, automatically updating to %s. Please update your unit file, and consider removing the setting altogether.",
1401 rvalue
, exec_output_to_string(eo
));
1403 if (streq(lvalue
, "StandardOutput")) {
1404 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1405 free_and_replace(c
->stdio_fdname
[STDOUT_FILENO
], resolved
);
1407 free_and_replace(c
->stdio_file
[STDOUT_FILENO
], resolved
);
1412 assert(streq(lvalue
, "StandardError"));
1414 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1415 free_and_replace(c
->stdio_fdname
[STDERR_FILENO
], resolved
);
1417 free_and_replace(c
->stdio_file
[STDERR_FILENO
], resolved
);
1425 int config_parse_exec_io_class(const char *unit
,
1426 const char *filename
,
1428 const char *section
,
1429 unsigned section_line
,
1436 ExecContext
*c
= data
;
1444 if (isempty(rvalue
)) {
1445 c
->ioprio_set
= false;
1446 c
->ioprio
= IOPRIO_DEFAULT_CLASS_AND_PRIO
;
1450 x
= ioprio_class_from_string(rvalue
);
1452 log_syntax(unit
, LOG_WARNING
, filename
, line
, x
, "Failed to parse IO scheduling class, ignoring: %s", rvalue
);
1456 c
->ioprio
= ioprio_normalize(ioprio_prio_value(x
, ioprio_prio_data(c
->ioprio
)));
1457 c
->ioprio_set
= true;
1462 int config_parse_exec_io_priority(const char *unit
,
1463 const char *filename
,
1465 const char *section
,
1466 unsigned section_line
,
1473 ExecContext
*c
= data
;
1481 if (isempty(rvalue
)) {
1482 c
->ioprio_set
= false;
1483 c
->ioprio
= IOPRIO_DEFAULT_CLASS_AND_PRIO
;
1487 r
= ioprio_parse_priority(rvalue
, &i
);
1489 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse IO priority, ignoring: %s", rvalue
);
1493 c
->ioprio
= ioprio_normalize(ioprio_prio_value(ioprio_prio_class(c
->ioprio
), i
));
1494 c
->ioprio_set
= true;
1499 int config_parse_exec_cpu_sched_policy(const char *unit
,
1500 const char *filename
,
1502 const char *section
,
1503 unsigned section_line
,
1510 ExecContext
*c
= data
;
1518 if (isempty(rvalue
)) {
1519 c
->cpu_sched_set
= false;
1520 c
->cpu_sched_policy
= SCHED_OTHER
;
1521 c
->cpu_sched_priority
= 0;
1525 x
= sched_policy_from_string(rvalue
);
1527 log_syntax(unit
, LOG_WARNING
, filename
, line
, x
, "Failed to parse CPU scheduling policy, ignoring: %s", rvalue
);
1531 c
->cpu_sched_policy
= x
;
1532 /* Moving to or from real-time policy? We need to adjust the priority */
1533 c
->cpu_sched_priority
= CLAMP(c
->cpu_sched_priority
, sched_get_priority_min(x
), sched_get_priority_max(x
));
1534 c
->cpu_sched_set
= true;
1539 int config_parse_exec_mount_apivfs(const char *unit
,
1540 const char *filename
,
1542 const char *section
,
1543 unsigned section_line
,
1550 ExecContext
*c
= data
;
1558 if (isempty(rvalue
)) {
1559 c
->mount_apivfs_set
= false;
1560 c
->mount_apivfs
= false;
1564 k
= parse_boolean(rvalue
);
1566 log_syntax(unit
, LOG_WARNING
, filename
, line
, k
,
1567 "Failed to parse boolean value, ignoring: %s",
1572 c
->mount_apivfs_set
= true;
1573 c
->mount_apivfs
= k
;
1577 int config_parse_numa_mask(const char *unit
,
1578 const char *filename
,
1580 const char *section
,
1581 unsigned section_line
,
1588 NUMAPolicy
*p
= data
;
1595 if (streq(rvalue
, "all")) {
1596 r
= numa_mask_add_all(&p
->nodes
);
1598 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1599 "Failed to create NUMA mask representing \"all\" NUMA nodes, ignoring: %m");
1601 r
= parse_cpu_set_extend(rvalue
, &p
->nodes
, true, unit
, filename
, line
, lvalue
);
1603 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse NUMA node mask, ignoring: %s", rvalue
);
1609 int config_parse_exec_cpu_sched_prio(const char *unit
,
1610 const char *filename
,
1612 const char *section
,
1613 unsigned section_line
,
1620 ExecContext
*c
= data
;
1628 r
= safe_atoi(rvalue
, &i
);
1630 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse CPU scheduling priority, ignoring: %s", rvalue
);
1634 /* On Linux RR/FIFO range from 1 to 99 and OTHER/BATCH may only be 0 */
1635 min
= sched_get_priority_min(c
->cpu_sched_policy
);
1636 max
= sched_get_priority_max(c
->cpu_sched_policy
);
1638 if (i
< min
|| i
> max
) {
1639 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "CPU scheduling priority is out of range, ignoring: %s", rvalue
);
1643 c
->cpu_sched_priority
= i
;
1644 c
->cpu_sched_set
= true;
1649 int config_parse_root_image_options(
1651 const char *filename
,
1653 const char *section
,
1654 unsigned section_line
,
1661 _cleanup_(mount_options_free_allp
) MountOptions
*options
= NULL
;
1662 _cleanup_strv_free_
char **l
= NULL
;
1663 ExecContext
*c
= data
;
1664 const Unit
*u
= userdata
;
1672 if (isempty(rvalue
)) {
1673 c
->root_image_options
= mount_options_free_all(c
->root_image_options
);
1677 r
= strv_split_colon_pairs(&l
, rvalue
);
1681 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
1685 STRV_FOREACH_PAIR(first
, second
, l
) {
1686 MountOptions
*o
= NULL
;
1687 _cleanup_free_
char *mount_options_resolved
= NULL
;
1688 const char *mount_options
= NULL
, *partition
= "root";
1689 PartitionDesignator partition_designator
;
1691 /* Format is either 'root:foo' or 'foo' (root is implied) */
1692 if (!isempty(*second
)) {
1694 mount_options
= *second
;
1696 mount_options
= *first
;
1698 partition_designator
= partition_designator_from_string(partition
);
1699 if (partition_designator
< 0) {
1700 log_syntax(unit
, LOG_WARNING
, filename
, line
, partition_designator
,
1701 "Invalid partition name %s, ignoring", partition
);
1704 r
= unit_full_printf(u
, mount_options
, &mount_options_resolved
);
1706 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", mount_options
);
1710 o
= new(MountOptions
, 1);
1713 *o
= (MountOptions
) {
1714 .partition_designator
= partition_designator
,
1715 .options
= TAKE_PTR(mount_options_resolved
),
1717 LIST_APPEND(mount_options
, options
, TAKE_PTR(o
));
1721 LIST_JOIN(mount_options
, c
->root_image_options
, options
);
1723 /* empty spaces/separators only */
1724 c
->root_image_options
= mount_options_free_all(c
->root_image_options
);
1729 int config_parse_exec_root_hash(
1731 const char *filename
,
1733 const char *section
,
1734 unsigned section_line
,
1741 _cleanup_free_
void *roothash_decoded
= NULL
;
1742 ExecContext
*c
= data
;
1743 size_t roothash_decoded_size
= 0;
1751 if (isempty(rvalue
)) {
1752 /* Reset if the empty string is assigned */
1753 c
->root_hash_path
= mfree(c
->root_hash_path
);
1754 c
->root_hash
= mfree(c
->root_hash
);
1755 c
->root_hash_size
= 0;
1759 if (path_is_absolute(rvalue
)) {
1760 /* We have the path to a roothash to load and decode, eg: RootHash=/foo/bar.roothash */
1761 _cleanup_free_
char *p
= NULL
;
1767 free_and_replace(c
->root_hash_path
, p
);
1768 c
->root_hash
= mfree(c
->root_hash
);
1769 c
->root_hash_size
= 0;
1773 /* We have a roothash to decode, eg: RootHash=012345789abcdef */
1774 r
= unhexmem(rvalue
, strlen(rvalue
), &roothash_decoded
, &roothash_decoded_size
);
1776 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to decode RootHash=, ignoring: %s", rvalue
);
1779 if (roothash_decoded_size
< sizeof(sd_id128_t
)) {
1780 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "RootHash= is too short, ignoring: %s", rvalue
);
1784 free_and_replace(c
->root_hash
, roothash_decoded
);
1785 c
->root_hash_size
= roothash_decoded_size
;
1786 c
->root_hash_path
= mfree(c
->root_hash_path
);
1791 int config_parse_exec_root_hash_sig(
1793 const char *filename
,
1795 const char *section
,
1796 unsigned section_line
,
1803 _cleanup_free_
void *roothash_sig_decoded
= NULL
;
1805 ExecContext
*c
= data
;
1806 size_t roothash_sig_decoded_size
= 0;
1814 if (isempty(rvalue
)) {
1815 /* Reset if the empty string is assigned */
1816 c
->root_hash_sig_path
= mfree(c
->root_hash_sig_path
);
1817 c
->root_hash_sig
= mfree(c
->root_hash_sig
);
1818 c
->root_hash_sig_size
= 0;
1822 if (path_is_absolute(rvalue
)) {
1823 /* We have the path to a roothash signature to load and decode, eg: RootHashSignature=/foo/bar.roothash.p7s */
1824 _cleanup_free_
char *p
= NULL
;
1830 free_and_replace(c
->root_hash_sig_path
, p
);
1831 c
->root_hash_sig
= mfree(c
->root_hash_sig
);
1832 c
->root_hash_sig_size
= 0;
1836 if (!(value
= startswith(rvalue
, "base64:"))) {
1837 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
1838 "Failed to decode RootHashSignature=, not a path but doesn't start with 'base64:', ignoring: %s", rvalue
);
1842 /* We have a roothash signature to decode, eg: RootHashSignature=base64:012345789abcdef */
1843 r
= unbase64mem(value
, strlen(value
), &roothash_sig_decoded
, &roothash_sig_decoded_size
);
1845 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to decode RootHashSignature=, ignoring: %s", rvalue
);
1849 free_and_replace(c
->root_hash_sig
, roothash_sig_decoded
);
1850 c
->root_hash_sig_size
= roothash_sig_decoded_size
;
1851 c
->root_hash_sig_path
= mfree(c
->root_hash_sig_path
);
1856 int config_parse_exec_cpu_affinity(
1858 const char *filename
,
1860 const char *section
,
1861 unsigned section_line
,
1868 ExecContext
*c
= data
;
1869 const Unit
*u
= userdata
;
1870 _cleanup_free_
char *k
= NULL
;
1878 if (streq(rvalue
, "numa")) {
1879 c
->cpu_affinity_from_numa
= true;
1880 cpu_set_reset(&c
->cpu_set
);
1885 r
= unit_full_printf(u
, rvalue
, &k
);
1887 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1888 "Failed to resolve unit specifiers in '%s', ignoring: %m",
1893 r
= parse_cpu_set_extend(k
, &c
->cpu_set
, true, unit
, filename
, line
, lvalue
);
1895 c
->cpu_affinity_from_numa
= false;
1900 int config_parse_capability_set(
1902 const char *filename
,
1904 const char *section
,
1905 unsigned section_line
,
1912 uint64_t *capability_set
= data
;
1913 uint64_t sum
= 0, initial
= 0;
1914 bool invert
= false;
1922 if (rvalue
[0] == '~') {
1927 if (streq(lvalue
, "CapabilityBoundingSet"))
1928 initial
= CAP_ALL
; /* initialized to all bits on */
1929 /* else "AmbientCapabilities" initialized to all bits off */
1931 r
= capability_set_from_string(rvalue
, &sum
);
1933 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= specifier '%s', ignoring: %m", lvalue
, rvalue
);
1937 if (sum
== 0 || *capability_set
== initial
)
1938 /* "", "~" or uninitialized data -> replace */
1939 *capability_set
= invert
? ~sum
: sum
;
1941 /* previous data -> merge */
1943 *capability_set
&= ~sum
;
1945 *capability_set
|= sum
;
1951 int config_parse_exec_selinux_context(
1953 const char *filename
,
1955 const char *section
,
1956 unsigned section_line
,
1963 ExecContext
*c
= data
;
1964 const Unit
*u
= userdata
;
1974 if (isempty(rvalue
)) {
1975 c
->selinux_context
= mfree(c
->selinux_context
);
1976 c
->selinux_context_ignore
= false;
1980 if (rvalue
[0] == '-') {
1986 r
= unit_full_printf(u
, rvalue
, &k
);
1988 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
1989 "Failed to resolve unit specifiers in '%s'%s: %m",
1990 rvalue
, ignore
? ", ignoring" : "");
1991 return ignore
? 0 : -ENOEXEC
;
1994 free_and_replace(c
->selinux_context
, k
);
1995 c
->selinux_context_ignore
= ignore
;
2000 int config_parse_exec_apparmor_profile(
2002 const char *filename
,
2004 const char *section
,
2005 unsigned section_line
,
2012 ExecContext
*c
= data
;
2013 const Unit
*u
= userdata
;
2023 if (isempty(rvalue
)) {
2024 c
->apparmor_profile
= mfree(c
->apparmor_profile
);
2025 c
->apparmor_profile_ignore
= false;
2029 if (rvalue
[0] == '-') {
2035 r
= unit_full_printf(u
, rvalue
, &k
);
2037 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
2038 "Failed to resolve unit specifiers in '%s'%s: %m",
2039 rvalue
, ignore
? ", ignoring" : "");
2040 return ignore
? 0 : -ENOEXEC
;
2043 free_and_replace(c
->apparmor_profile
, k
);
2044 c
->apparmor_profile_ignore
= ignore
;
2049 int config_parse_exec_smack_process_label(
2051 const char *filename
,
2053 const char *section
,
2054 unsigned section_line
,
2061 ExecContext
*c
= data
;
2062 const Unit
*u
= userdata
;
2072 if (isempty(rvalue
)) {
2073 c
->smack_process_label
= mfree(c
->smack_process_label
);
2074 c
->smack_process_label_ignore
= false;
2078 if (rvalue
[0] == '-') {
2084 r
= unit_full_printf(u
, rvalue
, &k
);
2086 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
2087 "Failed to resolve unit specifiers in '%s'%s: %m",
2088 rvalue
, ignore
? ", ignoring" : "");
2089 return ignore
? 0 : -ENOEXEC
;
2092 free_and_replace(c
->smack_process_label
, k
);
2093 c
->smack_process_label_ignore
= ignore
;
2098 int config_parse_timer(
2100 const char *filename
,
2102 const char *section
,
2103 unsigned section_line
,
2110 _cleanup_(calendar_spec_freep
) CalendarSpec
*c
= NULL
;
2111 _cleanup_free_
char *k
= NULL
;
2112 const Unit
*u
= userdata
;
2123 if (isempty(rvalue
)) {
2124 /* Empty assignment resets list */
2125 timer_free_values(t
);
2129 r
= unit_full_printf(u
, rvalue
, &k
);
2131 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2135 if (ltype
== TIMER_CALENDAR
) {
2136 r
= calendar_spec_from_string(k
, &c
);
2138 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse calendar specification, ignoring: %s", k
);
2142 r
= parse_sec(k
, &usec
);
2144 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse timer value, ignoring: %s", k
);
2149 v
= new(TimerValue
, 1);
2156 .calendar_spec
= TAKE_PTR(c
),
2159 LIST_PREPEND(value
, t
->values
, v
);
2164 int config_parse_trigger_unit(
2166 const char *filename
,
2168 const char *section
,
2169 unsigned section_line
,
2176 _cleanup_free_
char *p
= NULL
;
2186 if (UNIT_TRIGGER(u
)) {
2187 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Multiple units to trigger specified, ignoring: %s", rvalue
);
2191 r
= unit_name_printf(u
, rvalue
, &p
);
2193 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2197 type
= unit_name_to_type(p
);
2199 log_syntax(unit
, LOG_WARNING
, filename
, line
, type
, "Unit type not valid, ignoring: %s", rvalue
);
2202 if (unit_has_name(u
, p
)) {
2203 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Units cannot trigger themselves, ignoring: %s", rvalue
);
2207 r
= unit_add_two_dependencies_by_name(u
, UNIT_BEFORE
, UNIT_TRIGGERS
, p
, true, UNIT_DEPENDENCY_FILE
);
2209 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add trigger on %s, ignoring: %m", p
);
2216 int config_parse_path_spec(const char *unit
,
2217 const char *filename
,
2219 const char *section
,
2220 unsigned section_line
,
2230 _cleanup_free_
char *k
= NULL
;
2238 if (isempty(rvalue
)) {
2239 /* Empty assignment clears list */
2244 b
= path_type_from_string(lvalue
);
2246 log_syntax(unit
, LOG_WARNING
, filename
, line
, b
, "Failed to parse path type, ignoring: %s", lvalue
);
2250 r
= unit_path_printf(UNIT(p
), rvalue
, &k
);
2252 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2256 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2260 s
= new0(PathSpec
, 1);
2265 s
->path
= TAKE_PTR(k
);
2269 LIST_PREPEND(spec
, p
->specs
, s
);
2274 int config_parse_socket_service(
2276 const char *filename
,
2278 const char *section
,
2279 unsigned section_line
,
2286 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
2287 _cleanup_free_
char *p
= NULL
;
2297 r
= unit_name_printf(UNIT(s
), rvalue
, &p
);
2299 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2303 if (!endswith(p
, ".service")) {
2304 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Unit must be of type service, ignoring: %s", rvalue
);
2308 r
= manager_load_unit(UNIT(s
)->manager
, p
, NULL
, &error
, &x
);
2310 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to load unit %s, ignoring: %s", rvalue
, bus_error_message(&error
, r
));
2314 unit_ref_set(&s
->service
, UNIT(s
), x
);
2319 int config_parse_fdname(
2321 const char *filename
,
2323 const char *section
,
2324 unsigned section_line
,
2331 _cleanup_free_
char *p
= NULL
;
2340 if (isempty(rvalue
)) {
2341 s
->fdname
= mfree(s
->fdname
);
2345 r
= unit_fd_printf(UNIT(s
), rvalue
, &p
);
2347 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2351 if (!fdname_is_valid(p
)) {
2352 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", p
);
2356 return free_and_replace(s
->fdname
, p
);
2359 int config_parse_service_sockets(
2361 const char *filename
,
2363 const char *section
,
2364 unsigned section_line
,
2379 for (const char *p
= rvalue
;;) {
2380 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2382 r
= extract_first_word(&p
, &word
, NULL
, 0);
2386 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Trailing garbage in sockets, ignoring: %s", rvalue
);
2392 r
= unit_name_printf(UNIT(s
), word
, &k
);
2394 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
2398 if (!endswith(k
, ".socket")) {
2399 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Unit must be of type socket, ignoring: %s", k
);
2403 r
= unit_add_two_dependencies_by_name(UNIT(s
), UNIT_WANTS
, UNIT_AFTER
, k
, true, UNIT_DEPENDENCY_FILE
);
2405 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
2407 r
= unit_add_dependency_by_name(UNIT(s
), UNIT_TRIGGERED_BY
, k
, true, UNIT_DEPENDENCY_FILE
);
2409 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
2413 int config_parse_bus_name(
2415 const char *filename
,
2417 const char *section
,
2418 unsigned section_line
,
2425 _cleanup_free_
char *k
= NULL
;
2426 const Unit
*u
= userdata
;
2434 r
= unit_full_printf_full(u
, rvalue
, SD_BUS_MAXIMUM_NAME_LENGTH
, &k
);
2436 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2440 if (!sd_bus_service_name_is_valid(k
)) {
2441 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid bus name, ignoring: %s", k
);
2445 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
2448 int config_parse_service_timeout(
2450 const char *filename
,
2452 const char *section
,
2453 unsigned section_line
,
2460 Service
*s
= userdata
;
2469 /* This is called for two cases: TimeoutSec= and TimeoutStartSec=. */
2471 /* Traditionally, these options accepted 0 to disable the timeouts. However, a timeout of 0 suggests it happens
2472 * immediately, hence fix this to become USEC_INFINITY instead. This is in-line with how we internally handle
2473 * all other timeouts. */
2474 r
= parse_sec_fix_0(rvalue
, &usec
);
2476 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
2480 s
->start_timeout_defined
= true;
2481 s
->timeout_start_usec
= usec
;
2483 if (streq(lvalue
, "TimeoutSec"))
2484 s
->timeout_stop_usec
= usec
;
2489 int config_parse_timeout_abort(
2491 const char *filename
,
2493 const char *section
,
2494 unsigned section_line
,
2509 /* Note: apart from setting the arg, this returns an extra bit of information in the return value. */
2511 if (isempty(rvalue
)) {
2513 return 0; /* "not set" */
2516 r
= parse_sec(rvalue
, ret
);
2518 return log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= setting, ignoring: %s", lvalue
, rvalue
);
2520 return 1; /* "set" */
2523 int config_parse_service_timeout_abort(
2525 const char *filename
,
2527 const char *section
,
2528 unsigned section_line
,
2535 Service
*s
= userdata
;
2540 r
= config_parse_timeout_abort(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
,
2541 &s
->timeout_abort_usec
, s
);
2543 s
->timeout_abort_set
= r
;
2547 int config_parse_sec_fix_0(
2549 const char *filename
,
2551 const char *section
,
2552 unsigned section_line
,
2559 usec_t
*usec
= data
;
2567 /* This is pretty much like config_parse_sec(), except that this treats a time of 0 as infinity, for
2568 * compatibility with older versions of systemd where 0 instead of infinity was used as indicator to turn off a
2571 r
= parse_sec_fix_0(rvalue
, usec
);
2573 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
2578 int config_parse_user_group_compat(
2580 const char *filename
,
2582 const char *section
,
2583 unsigned section_line
,
2590 _cleanup_free_
char *k
= NULL
;
2592 const Unit
*u
= userdata
;
2600 if (isempty(rvalue
)) {
2601 *user
= mfree(*user
);
2605 r
= unit_full_printf(u
, rvalue
, &k
);
2607 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", rvalue
);
2611 if (!valid_user_group_name(k
, VALID_USER_ALLOW_NUMERIC
|VALID_USER_RELAX
|VALID_USER_WARN
)) {
2612 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2616 if (strstr(lvalue
, "User") && streq(k
, NOBODY_USER_NAME
))
2617 log_struct(LOG_NOTICE
,
2618 "MESSAGE=%s:%u: Special user %s configured, this is not safe!", filename
, line
, k
,
2620 "MESSAGE_ID=" SD_MESSAGE_NOBODY_USER_UNSUITABLE_STR
,
2621 "OFFENDING_USER=%s", k
,
2622 "CONFIG_FILE=%s", filename
,
2623 "CONFIG_LINE=%u", line
);
2625 return free_and_replace(*user
, k
);
2628 int config_parse_user_group_strv_compat(
2630 const char *filename
,
2632 const char *section
,
2633 unsigned section_line
,
2640 char ***users
= data
;
2641 const Unit
*u
= userdata
;
2649 if (isempty(rvalue
)) {
2650 *users
= strv_free(*users
);
2654 for (const char *p
= rvalue
;;) {
2655 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2657 r
= extract_first_word(&p
, &word
, NULL
, 0);
2661 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax: %s", rvalue
);
2667 r
= unit_full_printf(u
, word
, &k
);
2669 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", word
);
2673 if (!valid_user_group_name(k
, VALID_USER_ALLOW_NUMERIC
|VALID_USER_RELAX
|VALID_USER_WARN
)) {
2674 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2678 r
= strv_push(users
, k
);
2686 int config_parse_working_directory(
2688 const char *filename
,
2690 const char *section
,
2691 unsigned section_line
,
2698 ExecContext
*c
= data
;
2699 const Unit
*u
= userdata
;
2709 if (isempty(rvalue
)) {
2710 c
->working_directory_home
= false;
2711 c
->working_directory
= mfree(c
->working_directory
);
2715 if (rvalue
[0] == '-') {
2721 if (streq(rvalue
, "~")) {
2722 c
->working_directory_home
= true;
2723 c
->working_directory
= mfree(c
->working_directory
);
2725 _cleanup_free_
char *k
= NULL
;
2727 r
= unit_path_printf(u
, rvalue
, &k
);
2729 log_syntax(unit
, missing_ok
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
2730 "Failed to resolve unit specifiers in working directory path '%s'%s: %m",
2731 rvalue
, missing_ok
? ", ignoring" : "");
2732 return missing_ok
? 0 : -ENOEXEC
;
2735 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
| (missing_ok
? 0 : PATH_CHECK_FATAL
), unit
, filename
, line
, lvalue
);
2737 return missing_ok
? 0 : -ENOEXEC
;
2739 c
->working_directory_home
= false;
2740 free_and_replace(c
->working_directory
, k
);
2743 c
->working_directory_missing_ok
= missing_ok
;
2747 int config_parse_unit_env_file(const char *unit
,
2748 const char *filename
,
2750 const char *section
,
2751 unsigned section_line
,
2759 const Unit
*u
= userdata
;
2760 _cleanup_free_
char *n
= NULL
;
2768 if (isempty(rvalue
)) {
2769 /* Empty assignment frees the list */
2770 *env
= strv_free(*env
);
2774 r
= unit_full_printf_full(u
, rvalue
, PATH_MAX
, &n
);
2776 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2780 r
= path_simplify_and_warn(n
[0] == '-' ? n
+ 1 : n
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2784 r
= strv_push(env
, n
);
2793 int config_parse_environ(
2795 const char *filename
,
2797 const char *section
,
2798 unsigned section_line
,
2805 const Unit
*u
= userdata
;
2814 if (isempty(rvalue
)) {
2815 /* Empty assignment resets the list */
2816 *env
= strv_free(*env
);
2820 for (const char *p
= rvalue
;; ) {
2821 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
2823 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2827 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2828 "Invalid syntax, ignoring: %s", rvalue
);
2835 r
= unit_env_printf(u
, word
, &resolved
);
2837 r
= specifier_printf(word
, sc_arg_max(), system_and_tmp_specifier_table
, NULL
, NULL
, &resolved
);
2839 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2840 "Failed to resolve specifiers in %s, ignoring: %m", word
);
2844 if (!env_assignment_is_valid(resolved
)) {
2845 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
2846 "Invalid environment assignment, ignoring: %s", resolved
);
2850 r
= strv_env_replace_consume(env
, TAKE_PTR(resolved
));
2852 return log_error_errno(r
, "Failed to update environment: %m");
2856 int config_parse_pass_environ(
2858 const char *filename
,
2860 const char *section
,
2861 unsigned section_line
,
2868 _cleanup_strv_free_
char **n
= NULL
;
2869 const Unit
*u
= userdata
;
2870 char*** passenv
= data
;
2879 if (isempty(rvalue
)) {
2880 /* Empty assignment resets the list */
2881 *passenv
= strv_free(*passenv
);
2885 for (const char *p
= rvalue
;;) {
2886 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2888 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
2892 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2893 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2900 r
= unit_env_printf(u
, word
, &k
);
2902 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2903 "Failed to resolve specifiers in %s, ignoring: %m", word
);
2909 if (!env_name_is_valid(k
)) {
2910 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
2911 "Invalid environment name for %s, ignoring: %s", lvalue
, k
);
2915 if (!GREEDY_REALLOC(n
, nlen
+ 2))
2918 n
[nlen
++] = TAKE_PTR(k
);
2923 r
= strv_extend_strv(passenv
, n
, true);
2931 int config_parse_unset_environ(
2933 const char *filename
,
2935 const char *section
,
2936 unsigned section_line
,
2943 _cleanup_strv_free_
char **n
= NULL
;
2944 char*** unsetenv
= data
;
2945 const Unit
*u
= userdata
;
2954 if (isempty(rvalue
)) {
2955 /* Empty assignment resets the list */
2956 *unsetenv
= strv_free(*unsetenv
);
2960 for (const char *p
= rvalue
;;) {
2961 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2963 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2967 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2968 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2975 r
= unit_env_printf(u
, word
, &k
);
2977 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2978 "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2984 if (!env_assignment_is_valid(k
) && !env_name_is_valid(k
)) {
2985 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
2986 "Invalid environment name or assignment %s, ignoring: %s", lvalue
, k
);
2990 if (!GREEDY_REALLOC(n
, nlen
+ 2))
2993 n
[nlen
++] = TAKE_PTR(k
);
2998 r
= strv_extend_strv(unsetenv
, n
, true);
3006 int config_parse_log_extra_fields(
3008 const char *filename
,
3010 const char *section
,
3011 unsigned section_line
,
3018 ExecContext
*c
= data
;
3019 const Unit
*u
= userdata
;
3027 if (isempty(rvalue
)) {
3028 exec_context_free_log_extra_fields(c
);
3032 for (const char *p
= rvalue
;;) {
3033 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
3037 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
3041 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3047 r
= unit_full_printf(u
, word
, &k
);
3049 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
3053 eq
= strchr(k
, '=');
3055 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Log field lacks '=' character, ignoring: %s", k
);
3059 if (!journal_field_valid(k
, eq
-k
, false)) {
3060 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Log field name is invalid, ignoring: %s", k
);
3064 t
= reallocarray(c
->log_extra_fields
, c
->n_log_extra_fields
+1, sizeof(struct iovec
));
3068 c
->log_extra_fields
= t
;
3069 c
->log_extra_fields
[c
->n_log_extra_fields
++] = IOVEC_MAKE_STRING(k
);
3075 int config_parse_log_namespace(
3077 const char *filename
,
3079 const char *section
,
3080 unsigned section_line
,
3087 _cleanup_free_
char *k
= NULL
;
3088 ExecContext
*c
= data
;
3089 const Unit
*u
= userdata
;
3097 if (isempty(rvalue
)) {
3098 c
->log_namespace
= mfree(c
->log_namespace
);
3102 r
= unit_full_printf_full(u
, rvalue
, NAME_MAX
, &k
);
3104 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
3108 if (!log_namespace_name_valid(k
)) {
3109 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Specified log namespace name is not valid, ignoring: %s", k
);
3113 free_and_replace(c
->log_namespace
, k
);
3117 int config_parse_unit_condition_path(
3119 const char *filename
,
3121 const char *section
,
3122 unsigned section_line
,
3129 _cleanup_free_
char *p
= NULL
;
3130 Condition
**list
= data
, *c
;
3131 ConditionType t
= ltype
;
3132 bool trigger
, negate
;
3133 const Unit
*u
= userdata
;
3141 if (isempty(rvalue
)) {
3142 /* Empty assignment resets the list */
3143 *list
= condition_free_list(*list
);
3147 trigger
= rvalue
[0] == '|';
3151 negate
= rvalue
[0] == '!';
3155 r
= unit_path_printf(u
, rvalue
, &p
);
3157 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
3161 r
= path_simplify_and_warn(p
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
3165 c
= condition_new(t
, p
, trigger
, negate
);
3169 LIST_PREPEND(conditions
, *list
, c
);
3173 int config_parse_unit_condition_string(
3175 const char *filename
,
3177 const char *section
,
3178 unsigned section_line
,
3185 _cleanup_free_
char *s
= NULL
;
3186 Condition
**list
= data
, *c
;
3187 ConditionType t
= ltype
;
3188 bool trigger
, negate
;
3189 const Unit
*u
= userdata
;
3197 if (isempty(rvalue
)) {
3198 /* Empty assignment resets the list */
3199 *list
= condition_free_list(*list
);
3203 trigger
= *rvalue
== '|';
3205 rvalue
+= 1 + strspn(rvalue
+ 1, WHITESPACE
);
3207 negate
= *rvalue
== '!';
3209 rvalue
+= 1 + strspn(rvalue
+ 1, WHITESPACE
);
3211 r
= unit_full_printf(u
, rvalue
, &s
);
3213 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3214 "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
3218 c
= condition_new(t
, s
, trigger
, negate
);
3222 LIST_PREPEND(conditions
, *list
, c
);
3226 int config_parse_unit_requires_mounts_for(
3228 const char *filename
,
3230 const char *section
,
3231 unsigned section_line
,
3246 for (const char *p
= rvalue
;;) {
3247 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
3249 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3253 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3254 "Invalid syntax, ignoring: %s", rvalue
);
3260 r
= unit_path_printf(u
, word
, &resolved
);
3262 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
3266 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
3270 r
= unit_require_mounts_for(u
, resolved
, UNIT_DEPENDENCY_FILE
);
3272 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add required mount '%s', ignoring: %m", resolved
);
3278 int config_parse_documentation(
3280 const char *filename
,
3282 const char *section
,
3283 unsigned section_line
,
3299 if (isempty(rvalue
)) {
3300 /* Empty assignment resets the list */
3301 u
->documentation
= strv_free(u
->documentation
);
3305 r
= config_parse_unit_strv_printf(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
,
3306 rvalue
, data
, userdata
);
3310 for (a
= b
= u
->documentation
; a
&& *a
; a
++) {
3312 if (documentation_url_is_valid(*a
))
3315 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid URL, ignoring: %s", *a
);
3326 int config_parse_syscall_filter(
3328 const char *filename
,
3330 const char *section
,
3331 unsigned section_line
,
3338 ExecContext
*c
= data
;
3339 _unused_
const Unit
*u
= userdata
;
3340 bool invert
= false;
3348 if (isempty(rvalue
)) {
3349 /* Empty assignment resets the list */
3350 c
->syscall_filter
= hashmap_free(c
->syscall_filter
);
3351 c
->syscall_allow_list
= false;
3355 if (rvalue
[0] == '~') {
3360 if (!c
->syscall_filter
) {
3361 c
->syscall_filter
= hashmap_new(NULL
);
3362 if (!c
->syscall_filter
)
3366 /* Allow everything but the ones listed */
3367 c
->syscall_allow_list
= false;
3369 /* Allow nothing but the ones listed */
3370 c
->syscall_allow_list
= true;
3372 /* Accept default syscalls if we are on an allow_list */
3373 r
= seccomp_parse_syscall_filter(
3374 "@default", -1, c
->syscall_filter
,
3375 SECCOMP_PARSE_PERMISSIVE
|SECCOMP_PARSE_ALLOW_LIST
,
3383 for (const char *p
= rvalue
;;) {
3384 _cleanup_free_
char *word
= NULL
, *name
= NULL
;
3387 r
= extract_first_word(&p
, &word
, NULL
, 0);
3391 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3392 "Invalid syntax, ignoring: %s", rvalue
);
3398 r
= parse_syscall_and_errno(word
, &name
, &num
);
3400 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3401 "Failed to parse syscall:errno, ignoring: %s", word
);
3404 if (!invert
&& num
>= 0) {
3405 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3406 "Allow-listed system calls cannot take error number, ignoring: %s", word
);
3410 r
= seccomp_parse_syscall_filter(
3411 name
, num
, c
->syscall_filter
,
3412 SECCOMP_PARSE_LOG
|SECCOMP_PARSE_PERMISSIVE
|
3413 (invert
? SECCOMP_PARSE_INVERT
: 0)|
3414 (c
->syscall_allow_list
? SECCOMP_PARSE_ALLOW_LIST
: 0),
3415 unit
, filename
, line
);
3421 int config_parse_syscall_log(
3423 const char *filename
,
3425 const char *section
,
3426 unsigned section_line
,
3433 ExecContext
*c
= data
;
3434 _unused_
const Unit
*u
= userdata
;
3435 bool invert
= false;
3444 if (isempty(rvalue
)) {
3445 /* Empty assignment resets the list */
3446 c
->syscall_log
= hashmap_free(c
->syscall_log
);
3447 c
->syscall_log_allow_list
= false;
3451 if (rvalue
[0] == '~') {
3456 if (!c
->syscall_log
) {
3457 c
->syscall_log
= hashmap_new(NULL
);
3458 if (!c
->syscall_log
)
3462 /* Log everything but the ones listed */
3463 c
->syscall_log_allow_list
= false;
3465 /* Log nothing but the ones listed */
3466 c
->syscall_log_allow_list
= true;
3471 _cleanup_free_
char *word
= NULL
;
3473 r
= extract_first_word(&p
, &word
, NULL
, 0);
3477 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3483 r
= seccomp_parse_syscall_filter(
3484 word
, -1, c
->syscall_log
,
3485 SECCOMP_PARSE_LOG
|SECCOMP_PARSE_PERMISSIVE
|
3486 (invert
? SECCOMP_PARSE_INVERT
: 0)|
3487 (c
->syscall_log_allow_list
? SECCOMP_PARSE_ALLOW_LIST
: 0),
3488 unit
, filename
, line
);
3494 int config_parse_syscall_archs(
3496 const char *filename
,
3498 const char *section
,
3499 unsigned section_line
,
3509 if (isempty(rvalue
)) {
3510 *archs
= set_free(*archs
);
3514 for (const char *p
= rvalue
;;) {
3515 _cleanup_free_
char *word
= NULL
;
3518 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3522 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3523 "Invalid syntax, ignoring: %s", rvalue
);
3529 r
= seccomp_arch_from_string(word
, &a
);
3531 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3532 "Failed to parse system call architecture \"%s\", ignoring: %m", word
);
3536 r
= set_ensure_put(archs
, NULL
, UINT32_TO_PTR(a
+ 1));
3542 int config_parse_syscall_errno(
3544 const char *filename
,
3546 const char *section
,
3547 unsigned section_line
,
3554 ExecContext
*c
= data
;
3561 if (isempty(rvalue
) || streq(rvalue
, "kill")) {
3562 /* Empty assignment resets to KILL */
3563 c
->syscall_errno
= SECCOMP_ERROR_NUMBER_KILL
;
3567 e
= parse_errno(rvalue
);
3569 log_syntax(unit
, LOG_WARNING
, filename
, line
, e
, "Failed to parse error number, ignoring: %s", rvalue
);
3573 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid error number, ignoring: %s", rvalue
);
3577 c
->syscall_errno
= e
;
3581 int config_parse_address_families(
3583 const char *filename
,
3585 const char *section
,
3586 unsigned section_line
,
3593 ExecContext
*c
= data
;
3594 bool invert
= false;
3601 if (isempty(rvalue
)) {
3602 /* Empty assignment resets the list */
3603 c
->address_families
= set_free(c
->address_families
);
3604 c
->address_families_allow_list
= false;
3608 if (streq(rvalue
, "none")) {
3609 /* Forbid all address families. */
3610 c
->address_families
= set_free(c
->address_families
);
3611 c
->address_families_allow_list
= true;
3615 if (rvalue
[0] == '~') {
3620 if (!c
->address_families
) {
3621 c
->address_families
= set_new(NULL
);
3622 if (!c
->address_families
)
3625 c
->address_families_allow_list
= !invert
;
3628 for (const char *p
= rvalue
;;) {
3629 _cleanup_free_
char *word
= NULL
;
3632 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3636 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3637 "Invalid syntax, ignoring: %s", rvalue
);
3643 af
= af_from_name(word
);
3645 log_syntax(unit
, LOG_WARNING
, filename
, line
, af
,
3646 "Failed to parse address family, ignoring: %s", word
);
3650 /* If we previously wanted to forbid an address family and now
3651 * we want to allow it, then just remove it from the list.
3653 if (!invert
== c
->address_families_allow_list
) {
3654 r
= set_put(c
->address_families
, INT_TO_PTR(af
));
3658 set_remove(c
->address_families
, INT_TO_PTR(af
));
3662 int config_parse_restrict_namespaces(
3664 const char *filename
,
3666 const char *section
,
3667 unsigned section_line
,
3674 ExecContext
*c
= data
;
3675 unsigned long flags
;
3676 bool invert
= false;
3679 if (isempty(rvalue
)) {
3680 /* Reset to the default. */
3681 c
->restrict_namespaces
= NAMESPACE_FLAGS_INITIAL
;
3685 /* Boolean parameter ignores the previous settings */
3686 r
= parse_boolean(rvalue
);
3688 c
->restrict_namespaces
= 0;
3690 } else if (r
== 0) {
3691 c
->restrict_namespaces
= NAMESPACE_FLAGS_ALL
;
3695 if (rvalue
[0] == '~') {
3700 /* Not a boolean argument, in this case it's a list of namespace types. */
3701 r
= namespace_flags_from_string(rvalue
, &flags
);
3703 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse namespace type string, ignoring: %s", rvalue
);
3707 if (c
->restrict_namespaces
== NAMESPACE_FLAGS_INITIAL
)
3708 /* Initial assignment. Just set the value. */
3709 c
->restrict_namespaces
= invert
? (~flags
) & NAMESPACE_FLAGS_ALL
: flags
;
3711 /* Merge the value with the previous one. */
3712 SET_FLAG(c
->restrict_namespaces
, flags
, !invert
);
3718 int config_parse_restrict_filesystems(
3720 const char *filename
,
3722 const char *section
,
3723 unsigned section_line
,
3729 ExecContext
*c
= data
;
3730 bool invert
= false;
3738 if (isempty(rvalue
)) {
3739 /* Empty assignment resets the list */
3740 c
->restrict_filesystems
= set_free(c
->restrict_filesystems
);
3741 c
->restrict_filesystems_allow_list
= false;
3745 if (rvalue
[0] == '~') {
3750 if (!c
->restrict_filesystems
) {
3752 /* Allow everything but the ones listed */
3753 c
->restrict_filesystems_allow_list
= false;
3755 /* Allow nothing but the ones listed */
3756 c
->restrict_filesystems_allow_list
= true;
3759 for (const char *p
= rvalue
;;) {
3760 _cleanup_free_
char *word
= NULL
;
3762 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3768 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3769 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
3773 r
= lsm_bpf_parse_filesystem(
3775 &c
->restrict_filesystems
,
3776 FILESYSTEM_PARSE_LOG
|
3777 (invert
? FILESYSTEM_PARSE_INVERT
: 0)|
3778 (c
->restrict_filesystems_allow_list
? FILESYSTEM_PARSE_ALLOW_LIST
: 0),
3779 unit
, filename
, line
);
3788 int config_parse_unit_slice(
3790 const char *filename
,
3792 const char *section
,
3793 unsigned section_line
,
3800 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
3801 _cleanup_free_
char *k
= NULL
;
3802 Unit
*u
= userdata
, *slice
;
3810 r
= unit_name_printf(u
, rvalue
, &k
);
3812 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
3816 r
= manager_load_unit(u
->manager
, k
, NULL
, &error
, &slice
);
3818 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to load slice unit %s, ignoring: %s", k
, bus_error_message(&error
, r
));
3822 r
= unit_set_slice(u
, slice
);
3824 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to assign slice %s to unit %s, ignoring: %m", slice
->id
, u
->id
);
3831 int config_parse_cpu_quota(
3833 const char *filename
,
3835 const char *section
,
3836 unsigned section_line
,
3843 CGroupContext
*c
= data
;
3850 if (isempty(rvalue
)) {
3851 c
->cpu_quota_per_sec_usec
= USEC_INFINITY
;
3855 r
= parse_permyriad_unbounded(rvalue
);
3857 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid CPU quota '%s', ignoring.", rvalue
);
3861 c
->cpu_quota_per_sec_usec
= ((usec_t
) r
* USEC_PER_SEC
) / 10000U;
3865 int config_parse_allowed_cpuset(
3867 const char *filename
,
3869 const char *section
,
3870 unsigned section_line
,
3879 (void) parse_cpu_set_extend(rvalue
, c
, true, unit
, filename
, line
, lvalue
);
3883 int config_parse_memory_limit(
3885 const char *filename
,
3887 const char *section
,
3888 unsigned section_line
,
3895 CGroupContext
*c
= data
;
3896 uint64_t bytes
= CGROUP_LIMIT_MAX
;
3899 if (isempty(rvalue
) && STR_IN_SET(lvalue
, "DefaultMemoryLow",
3903 bytes
= CGROUP_LIMIT_MIN
;
3904 else if (!isempty(rvalue
) && !streq(rvalue
, "infinity")) {
3906 r
= parse_permyriad(rvalue
);
3908 r
= parse_size(rvalue
, 1024, &bytes
);
3910 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid memory limit '%s', ignoring: %m", rvalue
);
3914 bytes
= physical_memory_scale(r
, 10000U);
3916 if (bytes
>= UINT64_MAX
||
3917 (bytes
<= 0 && !STR_IN_SET(lvalue
, "MemorySwapMax", "MemoryLow", "MemoryMin", "DefaultMemoryLow", "DefaultMemoryMin"))) {
3918 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Memory limit '%s' out of range, ignoring.", rvalue
);
3923 if (streq(lvalue
, "DefaultMemoryLow")) {
3924 c
->default_memory_low
= bytes
;
3925 c
->default_memory_low_set
= true;
3926 } else if (streq(lvalue
, "DefaultMemoryMin")) {
3927 c
->default_memory_min
= bytes
;
3928 c
->default_memory_min_set
= true;
3929 } else if (streq(lvalue
, "MemoryMin")) {
3930 c
->memory_min
= bytes
;
3931 c
->memory_min_set
= true;
3932 } else if (streq(lvalue
, "MemoryLow")) {
3933 c
->memory_low
= bytes
;
3934 c
->memory_low_set
= true;
3935 } else if (streq(lvalue
, "MemoryHigh"))
3936 c
->memory_high
= bytes
;
3937 else if (streq(lvalue
, "MemoryMax"))
3938 c
->memory_max
= bytes
;
3939 else if (streq(lvalue
, "MemorySwapMax"))
3940 c
->memory_swap_max
= bytes
;
3941 else if (streq(lvalue
, "MemoryLimit")) {
3942 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3943 "Unit uses MemoryLimit=; please use MemoryMax= instead. Support for MemoryLimit= will be removed soon.");
3944 c
->memory_limit
= bytes
;
3951 int config_parse_tasks_max(
3953 const char *filename
,
3955 const char *section
,
3956 unsigned section_line
,
3963 const Unit
*u
= userdata
;
3964 TasksMax
*tasks_max
= data
;
3968 if (isempty(rvalue
)) {
3969 *tasks_max
= u
? u
->manager
->default_tasks_max
: TASKS_MAX_UNSET
;
3973 if (streq(rvalue
, "infinity")) {
3974 *tasks_max
= TASKS_MAX_UNSET
;
3978 r
= parse_permyriad(rvalue
);
3980 *tasks_max
= (TasksMax
) { r
, 10000U }; /* r‱ */
3982 r
= safe_atou64(rvalue
, &v
);
3984 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid maximum tasks value '%s', ignoring: %m", rvalue
);
3988 if (v
<= 0 || v
>= UINT64_MAX
) {
3989 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Maximum tasks value '%s' out of range, ignoring.", rvalue
);
3993 *tasks_max
= (TasksMax
) { v
};
3999 int config_parse_delegate(
4001 const char *filename
,
4003 const char *section
,
4004 unsigned section_line
,
4011 CGroupContext
*c
= data
;
4015 t
= unit_name_to_type(unit
);
4016 assert(t
!= _UNIT_TYPE_INVALID
);
4018 if (!unit_vtable
[t
]->can_delegate
) {
4019 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Delegate= setting not supported for this unit type, ignoring.");
4023 /* We either accept a boolean value, which may be used to turn on delegation for all controllers, or turn it
4024 * off for all. Or it takes a list of controller names, in which case we add the specified controllers to the
4025 * mask to delegate. */
4027 if (isempty(rvalue
)) {
4028 /* An empty string resets controllers and set Delegate=yes. */
4030 c
->delegate_controllers
= 0;
4034 r
= parse_boolean(rvalue
);
4036 CGroupMask mask
= 0;
4038 for (const char *p
= rvalue
;;) {
4039 _cleanup_free_
char *word
= NULL
;
4040 CGroupController cc
;
4042 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
4046 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
4052 cc
= cgroup_controller_from_string(word
);
4054 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid controller name '%s', ignoring", word
);
4058 mask
|= CGROUP_CONTROLLER_TO_MASK(cc
);
4062 c
->delegate_controllers
|= mask
;
4066 c
->delegate_controllers
= _CGROUP_MASK_ALL
;
4068 c
->delegate
= false;
4069 c
->delegate_controllers
= 0;
4075 int config_parse_managed_oom_mode(
4077 const char *filename
,
4079 const char *section
,
4080 unsigned section_line
,
4087 ManagedOOMMode
*mode
= data
, m
;
4090 t
= unit_name_to_type(unit
);
4091 assert(t
!= _UNIT_TYPE_INVALID
);
4093 if (!unit_vtable
[t
]->can_set_managed_oom
)
4094 return log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "%s= is not supported for this unit type, ignoring.", lvalue
);
4096 if (isempty(rvalue
)) {
4097 *mode
= MANAGED_OOM_AUTO
;
4101 m
= managed_oom_mode_from_string(rvalue
);
4103 log_syntax(unit
, LOG_WARNING
, filename
, line
, m
, "Invalid syntax, ignoring: %s", rvalue
);
4111 int config_parse_managed_oom_mem_pressure_limit(
4113 const char *filename
,
4115 const char *section
,
4116 unsigned section_line
,
4123 uint32_t *limit
= data
;
4127 t
= unit_name_to_type(unit
);
4128 assert(t
!= _UNIT_TYPE_INVALID
);
4130 if (!unit_vtable
[t
]->can_set_managed_oom
)
4131 return log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "%s= is not supported for this unit type, ignoring.", lvalue
);
4133 if (isempty(rvalue
)) {
4138 r
= parse_permyriad(rvalue
);
4140 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse memory pressure limit value, ignoring: %s", rvalue
);
4144 /* Normalize to 2^32-1 == 100% */
4145 *limit
= UINT32_SCALE_FROM_PERMYRIAD(r
);
4149 int config_parse_device_allow(
4151 const char *filename
,
4153 const char *section
,
4154 unsigned section_line
,
4161 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4162 CGroupContext
*c
= data
;
4163 const char *p
= rvalue
;
4166 if (isempty(rvalue
)) {
4167 while (c
->device_allow
)
4168 cgroup_context_free_device_allow(c
, c
->device_allow
);
4173 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4177 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4178 "Failed to extract device path and rights from '%s', ignoring.", rvalue
);
4182 r
= unit_path_printf(userdata
, path
, &resolved
);
4184 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4185 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4189 if (!STARTSWITH_SET(resolved
, "block-", "char-")) {
4191 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4195 if (!valid_device_node_path(resolved
)) {
4196 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid device node path '%s', ignoring.", resolved
);
4201 if (!isempty(p
) && !in_charset(p
, "rwm")) {
4202 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid device rights '%s', ignoring.", p
);
4206 return cgroup_add_device_allow(c
, resolved
, p
);
4209 int config_parse_io_device_weight(
4211 const char *filename
,
4213 const char *section
,
4214 unsigned section_line
,
4221 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4222 CGroupIODeviceWeight
*w
;
4223 CGroupContext
*c
= data
;
4224 const char *p
= rvalue
;
4232 if (isempty(rvalue
)) {
4233 while (c
->io_device_weights
)
4234 cgroup_context_free_io_device_weight(c
, c
->io_device_weights
);
4239 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4243 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4244 "Failed to extract device path and weight from '%s', ignoring.", rvalue
);
4247 if (r
== 0 || isempty(p
)) {
4248 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4249 "Invalid device path or weight specified in '%s', ignoring.", rvalue
);
4253 r
= unit_path_printf(userdata
, path
, &resolved
);
4255 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4256 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4260 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4264 r
= cg_weight_parse(p
, &u
);
4266 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "IO weight '%s' invalid, ignoring: %m", p
);
4270 assert(u
!= CGROUP_WEIGHT_INVALID
);
4272 w
= new0(CGroupIODeviceWeight
, 1);
4276 w
->path
= TAKE_PTR(resolved
);
4279 LIST_PREPEND(device_weights
, c
->io_device_weights
, w
);
4283 int config_parse_io_device_latency(
4285 const char *filename
,
4287 const char *section
,
4288 unsigned section_line
,
4295 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4296 CGroupIODeviceLatency
*l
;
4297 CGroupContext
*c
= data
;
4298 const char *p
= rvalue
;
4306 if (isempty(rvalue
)) {
4307 while (c
->io_device_latencies
)
4308 cgroup_context_free_io_device_latency(c
, c
->io_device_latencies
);
4313 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4317 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4318 "Failed to extract device path and latency from '%s', ignoring.", rvalue
);
4321 if (r
== 0 || isempty(p
)) {
4322 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4323 "Invalid device path or latency specified in '%s', ignoring.", rvalue
);
4327 r
= unit_path_printf(userdata
, path
, &resolved
);
4329 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4330 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4334 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4338 r
= parse_sec(p
, &usec
);
4340 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse timer value, ignoring: %s", p
);
4344 l
= new0(CGroupIODeviceLatency
, 1);
4348 l
->path
= TAKE_PTR(resolved
);
4349 l
->target_usec
= usec
;
4351 LIST_PREPEND(device_latencies
, c
->io_device_latencies
, l
);
4355 int config_parse_io_limit(
4357 const char *filename
,
4359 const char *section
,
4360 unsigned section_line
,
4367 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4368 CGroupIODeviceLimit
*l
= NULL
;
4369 CGroupContext
*c
= data
;
4370 CGroupIOLimitType type
;
4371 const char *p
= rvalue
;
4379 type
= cgroup_io_limit_type_from_string(lvalue
);
4382 if (isempty(rvalue
)) {
4383 LIST_FOREACH(device_limits
, t
, c
->io_device_limits
)
4384 t
->limits
[type
] = cgroup_io_limit_defaults
[type
];
4388 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4392 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4393 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
4396 if (r
== 0 || isempty(p
)) {
4397 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4398 "Invalid device node or bandwidth specified in '%s', ignoring.", rvalue
);
4402 r
= unit_path_printf(userdata
, path
, &resolved
);
4404 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4405 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4409 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4413 if (streq("infinity", p
))
4414 num
= CGROUP_LIMIT_MAX
;
4416 r
= parse_size(p
, 1000, &num
);
4417 if (r
< 0 || num
<= 0) {
4418 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid IO limit '%s', ignoring.", p
);
4423 LIST_FOREACH(device_limits
, t
, c
->io_device_limits
)
4424 if (path_equal(resolved
, t
->path
)) {
4430 CGroupIOLimitType ttype
;
4432 l
= new0(CGroupIODeviceLimit
, 1);
4436 l
->path
= TAKE_PTR(resolved
);
4437 for (ttype
= 0; ttype
< _CGROUP_IO_LIMIT_TYPE_MAX
; ttype
++)
4438 l
->limits
[ttype
] = cgroup_io_limit_defaults
[ttype
];
4440 LIST_PREPEND(device_limits
, c
->io_device_limits
, l
);
4443 l
->limits
[type
] = num
;
4448 int config_parse_blockio_device_weight(
4450 const char *filename
,
4452 const char *section
,
4453 unsigned section_line
,
4460 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4461 CGroupBlockIODeviceWeight
*w
;
4462 CGroupContext
*c
= data
;
4463 const char *p
= rvalue
;
4471 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4472 "Unit uses %s=; please use IO*= settings instead. Support for %s= will be removed soon.",
4475 if (isempty(rvalue
)) {
4476 while (c
->blockio_device_weights
)
4477 cgroup_context_free_blockio_device_weight(c
, c
->blockio_device_weights
);
4482 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4486 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4487 "Failed to extract device node and weight from '%s', ignoring.", rvalue
);
4490 if (r
== 0 || isempty(p
)) {
4491 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4492 "Invalid device node or weight specified in '%s', ignoring.", rvalue
);
4496 r
= unit_path_printf(userdata
, path
, &resolved
);
4498 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4499 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4503 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4507 r
= cg_blkio_weight_parse(p
, &u
);
4509 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid block IO weight '%s', ignoring: %m", p
);
4513 assert(u
!= CGROUP_BLKIO_WEIGHT_INVALID
);
4515 w
= new0(CGroupBlockIODeviceWeight
, 1);
4519 w
->path
= TAKE_PTR(resolved
);
4522 LIST_PREPEND(device_weights
, c
->blockio_device_weights
, w
);
4526 int config_parse_blockio_bandwidth(
4528 const char *filename
,
4530 const char *section
,
4531 unsigned section_line
,
4538 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4539 CGroupBlockIODeviceBandwidth
*b
= NULL
;
4540 CGroupContext
*c
= data
;
4541 const char *p
= rvalue
;
4550 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4551 "Unit uses %s=; please use IO*= settings instead. Support for %s= will be removed soon.",
4554 read
= streq("BlockIOReadBandwidth", lvalue
);
4556 if (isempty(rvalue
)) {
4557 LIST_FOREACH(device_bandwidths
, t
, c
->blockio_device_bandwidths
) {
4558 t
->rbps
= CGROUP_LIMIT_MAX
;
4559 t
->wbps
= CGROUP_LIMIT_MAX
;
4564 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4568 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4569 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
4572 if (r
== 0 || isempty(p
)) {
4573 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4574 "Invalid device node or bandwidth specified in '%s', ignoring.", rvalue
);
4578 r
= unit_path_printf(userdata
, path
, &resolved
);
4580 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4581 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4585 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4589 r
= parse_size(p
, 1000, &bytes
);
4590 if (r
< 0 || bytes
<= 0) {
4591 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid Block IO Bandwidth '%s', ignoring.", p
);
4595 LIST_FOREACH(device_bandwidths
, t
, c
->blockio_device_bandwidths
)
4596 if (path_equal(resolved
, t
->path
)) {
4602 b
= new0(CGroupBlockIODeviceBandwidth
, 1);
4606 b
->path
= TAKE_PTR(resolved
);
4607 b
->rbps
= CGROUP_LIMIT_MAX
;
4608 b
->wbps
= CGROUP_LIMIT_MAX
;
4610 LIST_PREPEND(device_bandwidths
, c
->blockio_device_bandwidths
, b
);
4621 int config_parse_job_mode_isolate(
4623 const char *filename
,
4625 const char *section
,
4626 unsigned section_line
,
4640 r
= parse_boolean(rvalue
);
4642 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse boolean, ignoring: %s", rvalue
);
4646 log_notice("%s is deprecated. Please use OnFailureJobMode= instead", lvalue
);
4648 *m
= r
? JOB_ISOLATE
: JOB_REPLACE
;
4652 int config_parse_exec_directories(
4654 const char *filename
,
4656 const char *section
,
4657 unsigned section_line
,
4664 ExecDirectory
*ed
= data
;
4665 const Unit
*u
= userdata
;
4673 if (isempty(rvalue
)) {
4674 /* Empty assignment resets the list */
4675 exec_directory_done(ed
);
4679 for (const char *p
= rvalue
;;) {
4680 _cleanup_free_
char *tuple
= NULL
;
4682 r
= extract_first_word(&p
, &tuple
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_RETAIN_ESCAPE
);
4686 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4687 "Invalid syntax %s=%s, ignoring: %m", lvalue
, rvalue
);
4693 _cleanup_free_
char *src
= NULL
, *dest
= NULL
;
4694 const char *q
= tuple
;
4695 r
= extract_many_words(&q
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
, &src
, &dest
, NULL
);
4699 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
?: SYNTHETIC_ERRNO(EINVAL
),
4700 "Invalid syntax in %s=, ignoring: %s", lvalue
, tuple
);
4704 _cleanup_free_
char *sresolved
= NULL
;
4705 r
= unit_path_printf(u
, src
, &sresolved
);
4707 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4708 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", src
);
4712 r
= path_simplify_and_warn(sresolved
, PATH_CHECK_RELATIVE
, unit
, filename
, line
, lvalue
);
4716 if (path_startswith(sresolved
, "private")) {
4717 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4718 "%s= path can't be 'private', ignoring assignment: %s", lvalue
, tuple
);
4722 /* For State and Runtime directories we support an optional destination parameter, which
4723 * will be used to create a symlink to the source. */
4724 _cleanup_strv_free_
char **symlinks
= NULL
;
4725 if (!isempty(dest
)) {
4726 _cleanup_free_
char *dresolved
= NULL
;
4728 if (streq(lvalue
, "ConfigurationDirectory")) {
4729 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4730 "Destination parameter is not supported for ConfigurationDirectory, ignoring: %s", tuple
);
4734 r
= unit_path_printf(u
, dest
, &dresolved
);
4736 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4737 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", dest
);
4741 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_RELATIVE
, unit
, filename
, line
, lvalue
);
4745 r
= strv_consume(&symlinks
, TAKE_PTR(dresolved
));
4750 r
= exec_directory_add(&ed
->items
, &ed
->n_items
, sresolved
, symlinks
);
4756 int config_parse_set_credential(
4758 const char *filename
,
4760 const char *section
,
4761 unsigned section_line
,
4768 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
4769 _cleanup_free_
void *d
= NULL
;
4770 ExecContext
*context
= data
;
4771 ExecSetCredential
*old
;
4773 bool encrypted
= ltype
;
4774 const char *p
= rvalue
;
4783 if (isempty(rvalue
)) {
4784 /* Empty assignment resets the list */
4785 context
->set_credentials
= hashmap_free(context
->set_credentials
);
4789 r
= extract_first_word(&p
, &word
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4793 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract credential name, ignoring: %s", rvalue
);
4796 if (r
== 0 || isempty(p
)) {
4797 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid syntax, ignoring: %s", rvalue
);
4801 r
= unit_cred_printf(u
, word
, &k
);
4803 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
4806 if (!credential_name_valid(k
)) {
4807 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Credential name \"%s\" not valid, ignoring.", k
);
4812 r
= unbase64mem_full(p
, SIZE_MAX
, true, &d
, &size
);
4814 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Encrypted credential data not valid Base64 data, ignoring.");
4821 /* We support escape codes here, so that users can insert trailing \n if they like */
4822 l
= cunescape(p
, UNESCAPE_ACCEPT_NUL
, &unescaped
);
4824 log_syntax(unit
, LOG_WARNING
, filename
, line
, l
, "Can't unescape \"%s\", ignoring: %m", p
);
4832 old
= hashmap_get(context
->set_credentials
, k
);
4834 free_and_replace(old
->data
, d
);
4836 old
->encrypted
= encrypted
;
4838 _cleanup_(exec_set_credential_freep
) ExecSetCredential
*sc
= NULL
;
4840 sc
= new(ExecSetCredential
, 1);
4844 *sc
= (ExecSetCredential
) {
4846 .data
= TAKE_PTR(d
),
4848 .encrypted
= encrypted
,
4851 r
= hashmap_ensure_put(&context
->set_credentials
, &exec_set_credential_hash_ops
, sc
->id
, sc
);
4855 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4856 "Duplicated credential value '%s', ignoring assignment: %s", sc
->id
, rvalue
);
4866 int config_parse_load_credential(
4868 const char *filename
,
4870 const char *section
,
4871 unsigned section_line
,
4878 _cleanup_free_
char *word
= NULL
, *k
= NULL
, *q
= NULL
;
4879 ExecContext
*context
= data
;
4880 ExecLoadCredential
*old
;
4881 bool encrypted
= ltype
;
4891 if (isempty(rvalue
)) {
4892 /* Empty assignment resets the list */
4893 context
->load_credentials
= hashmap_free(context
->load_credentials
);
4898 r
= extract_first_word(&p
, &word
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4902 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
4906 r
= unit_cred_printf(u
, word
, &k
);
4908 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
4911 if (!credential_name_valid(k
)) {
4912 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Credential name \"%s\" not valid, ignoring.", k
);
4917 /* If only one field is specified take it as shortcut for inheriting a credential named
4918 * the same way from our parent */
4923 r
= unit_path_printf(u
, p
, &q
);
4925 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", p
);
4928 if (path_is_absolute(q
) ? !path_is_normalized(q
) : !credential_name_valid(q
)) {
4929 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Credential source \"%s\" not valid, ignoring.", q
);
4934 old
= hashmap_get(context
->load_credentials
, k
);
4936 free_and_replace(old
->path
, q
);
4937 old
->encrypted
= encrypted
;
4939 _cleanup_(exec_load_credential_freep
) ExecLoadCredential
*lc
= NULL
;
4941 lc
= new(ExecLoadCredential
, 1);
4945 *lc
= (ExecLoadCredential
) {
4947 .path
= TAKE_PTR(q
),
4948 .encrypted
= encrypted
,
4951 r
= hashmap_ensure_put(&context
->load_credentials
, &exec_load_credential_hash_ops
, lc
->id
, lc
);
4955 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4956 "Duplicated credential value '%s', ignoring assignment: %s", lc
->id
, rvalue
);
4966 int config_parse_set_status(
4968 const char *filename
,
4970 const char *section
,
4971 unsigned section_line
,
4978 ExitStatusSet
*status_set
= data
;
4986 /* Empty assignment resets the list */
4987 if (isempty(rvalue
)) {
4988 exit_status_set_free(status_set
);
4992 for (const char *p
= rvalue
;;) {
4993 _cleanup_free_
char *word
= NULL
;
4996 r
= extract_first_word(&p
, &word
, NULL
, 0);
5000 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5001 "Failed to parse %s=%s, ignoring: %m", lvalue
, rvalue
);
5007 /* We need to call exit_status_from_string() first, because we want
5008 * to parse numbers as exit statuses, not signals. */
5010 r
= exit_status_from_string(word
);
5012 assert(r
>= 0 && r
< 256);
5013 bitmap
= &status_set
->status
;
5015 r
= signal_from_string(word
);
5017 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5018 "Failed to parse value, ignoring: %s", word
);
5021 bitmap
= &status_set
->signal
;
5024 r
= bitmap_set(bitmap
, r
);
5026 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5027 "Failed to set signal or status %s, ignoring: %m", word
);
5031 int config_parse_namespace_path_strv(
5033 const char *filename
,
5035 const char *section
,
5036 unsigned section_line
,
5043 const Unit
*u
= userdata
;
5052 if (isempty(rvalue
)) {
5053 /* Empty assignment resets the list */
5054 *sv
= strv_free(*sv
);
5058 for (const char *p
= rvalue
;;) {
5059 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
, *joined
= NULL
;
5061 bool ignore_enoent
= false, shall_prefix
= false;
5063 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
5067 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
5074 if (startswith(w
, "-")) {
5075 ignore_enoent
= true;
5078 if (startswith(w
, "+")) {
5079 shall_prefix
= true;
5083 r
= unit_path_printf(u
, w
, &resolved
);
5085 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", w
);
5089 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5093 joined
= strjoin(ignore_enoent
? "-" : "",
5094 shall_prefix
? "+" : "",
5097 r
= strv_push(sv
, joined
);
5107 int config_parse_temporary_filesystems(
5109 const char *filename
,
5111 const char *section
,
5112 unsigned section_line
,
5119 const Unit
*u
= userdata
;
5120 ExecContext
*c
= data
;
5128 if (isempty(rvalue
)) {
5129 /* Empty assignment resets the list */
5130 temporary_filesystem_free_many(c
->temporary_filesystems
, c
->n_temporary_filesystems
);
5131 c
->temporary_filesystems
= NULL
;
5132 c
->n_temporary_filesystems
= 0;
5136 for (const char *p
= rvalue
;;) {
5137 _cleanup_free_
char *word
= NULL
, *path
= NULL
, *resolved
= NULL
;
5140 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
5144 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
5151 r
= extract_first_word(&w
, &path
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
5155 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", word
);
5159 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid syntax, ignoring: %s", word
);
5163 r
= unit_path_printf(u
, path
, &resolved
);
5165 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", path
);
5169 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5173 r
= temporary_filesystem_add(&c
->temporary_filesystems
, &c
->n_temporary_filesystems
, resolved
, w
);
5179 int config_parse_bind_paths(
5181 const char *filename
,
5183 const char *section
,
5184 unsigned section_line
,
5191 ExecContext
*c
= data
;
5192 const Unit
*u
= userdata
;
5200 if (isempty(rvalue
)) {
5201 /* Empty assignment resets the list */
5202 bind_mount_free_many(c
->bind_mounts
, c
->n_bind_mounts
);
5203 c
->bind_mounts
= NULL
;
5204 c
->n_bind_mounts
= 0;
5208 for (const char *p
= rvalue
;;) {
5209 _cleanup_free_
char *source
= NULL
, *destination
= NULL
;
5210 _cleanup_free_
char *sresolved
= NULL
, *dresolved
= NULL
;
5211 char *s
= NULL
, *d
= NULL
;
5212 bool rbind
= true, ignore_enoent
= false;
5214 r
= extract_first_word(&p
, &source
, ":" WHITESPACE
, EXTRACT_UNQUOTE
|EXTRACT_DONT_COALESCE_SEPARATORS
);
5218 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
5224 r
= unit_full_printf_full(u
, source
, PATH_MAX
, &sresolved
);
5226 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5227 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", source
);
5233 ignore_enoent
= true;
5237 r
= path_simplify_and_warn(s
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5241 /* Optionally, the destination is specified. */
5242 if (p
&& p
[-1] == ':') {
5243 r
= extract_first_word(&p
, &destination
, ":" WHITESPACE
, EXTRACT_UNQUOTE
|EXTRACT_DONT_COALESCE_SEPARATORS
);
5247 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
5251 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Missing argument after ':', ignoring: %s", s
);
5255 r
= unit_path_printf(u
, destination
, &dresolved
);
5257 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5258 "Failed to resolve specifiers in \"%s\", ignoring: %m", destination
);
5262 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5268 /* Optionally, there's also a short option string specified */
5269 if (p
&& p
[-1] == ':') {
5270 _cleanup_free_
char *options
= NULL
;
5272 r
= extract_first_word(&p
, &options
, NULL
, EXTRACT_UNQUOTE
);
5276 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s=, ignoring: %s", lvalue
, rvalue
);
5280 if (isempty(options
) || streq(options
, "rbind"))
5282 else if (streq(options
, "norbind"))
5285 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid option string, ignoring setting: %s", options
);
5292 r
= bind_mount_add(&c
->bind_mounts
, &c
->n_bind_mounts
,
5296 .read_only
= !!strstr(lvalue
, "ReadOnly"),
5298 .ignore_enoent
= ignore_enoent
,
5307 int config_parse_mount_images(
5309 const char *filename
,
5311 const char *section
,
5312 unsigned section_line
,
5319 ExecContext
*c
= data
;
5320 const Unit
*u
= userdata
;
5328 if (isempty(rvalue
)) {
5329 /* Empty assignment resets the list */
5330 c
->mount_images
= mount_image_free_many(c
->mount_images
, &c
->n_mount_images
);
5334 for (const char *p
= rvalue
;;) {
5335 _cleanup_(mount_options_free_allp
) MountOptions
*options
= NULL
;
5336 _cleanup_free_
char *first
= NULL
, *second
= NULL
, *tuple
= NULL
;
5337 _cleanup_free_
char *sresolved
= NULL
, *dresolved
= NULL
;
5338 const char *q
= NULL
;
5340 bool permissive
= false;
5342 r
= extract_first_word(&p
, &tuple
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_RETAIN_ESCAPE
);
5346 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5347 "Invalid syntax %s=%s, ignoring: %m", lvalue
, rvalue
);
5354 r
= extract_many_words(&q
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
, &first
, &second
, NULL
);
5358 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5359 "Invalid syntax in %s=, ignoring: %s", lvalue
, tuple
);
5371 r
= unit_path_printf(u
, s
, &sresolved
);
5373 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5374 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", s
);
5378 r
= path_simplify_and_warn(sresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5382 if (isempty(second
)) {
5383 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Missing destination in %s, ignoring: %s", lvalue
, rvalue
);
5387 r
= unit_path_printf(u
, second
, &dresolved
);
5389 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5390 "Failed to resolve specifiers in \"%s\", ignoring: %m", second
);
5394 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5399 _cleanup_free_
char *partition
= NULL
, *mount_options
= NULL
, *mount_options_resolved
= NULL
;
5400 MountOptions
*o
= NULL
;
5401 PartitionDesignator partition_designator
;
5403 r
= extract_many_words(&q
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
, &partition
, &mount_options
, NULL
);
5407 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", q
);
5412 /* Single set of options, applying to the root partition/single filesystem */
5414 r
= unit_full_printf(u
, partition
, &mount_options_resolved
);
5416 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", first
);
5420 o
= new(MountOptions
, 1);
5423 *o
= (MountOptions
) {
5424 .partition_designator
= PARTITION_ROOT
,
5425 .options
= TAKE_PTR(mount_options_resolved
),
5427 LIST_APPEND(mount_options
, options
, o
);
5432 partition_designator
= partition_designator_from_string(partition
);
5433 if (partition_designator
< 0) {
5434 log_syntax(unit
, LOG_WARNING
, filename
, line
, partition_designator
,
5435 "Invalid partition name %s, ignoring", partition
);
5438 r
= unit_full_printf(u
, mount_options
, &mount_options_resolved
);
5440 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", mount_options
);
5444 o
= new(MountOptions
, 1);
5447 *o
= (MountOptions
) {
5448 .partition_designator
= partition_designator
,
5449 .options
= TAKE_PTR(mount_options_resolved
),
5451 LIST_APPEND(mount_options
, options
, o
);
5454 r
= mount_image_add(&c
->mount_images
, &c
->n_mount_images
,
5456 .source
= sresolved
,
5457 .destination
= dresolved
,
5458 .mount_options
= options
,
5459 .ignore_enoent
= permissive
,
5460 .type
= MOUNT_IMAGE_DISCRETE
,
5467 int config_parse_extension_images(
5469 const char *filename
,
5471 const char *section
,
5472 unsigned section_line
,
5479 ExecContext
*c
= data
;
5480 const Unit
*u
= userdata
;
5488 if (isempty(rvalue
)) {
5489 /* Empty assignment resets the list */
5490 c
->extension_images
= mount_image_free_many(c
->extension_images
, &c
->n_extension_images
);
5494 for (const char *p
= rvalue
;;) {
5495 _cleanup_free_
char *source
= NULL
, *tuple
= NULL
, *sresolved
= NULL
;
5496 _cleanup_(mount_options_free_allp
) MountOptions
*options
= NULL
;
5497 bool permissive
= false;
5498 const char *q
= NULL
;
5501 r
= extract_first_word(&p
, &tuple
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_RETAIN_ESCAPE
);
5505 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5506 "Invalid syntax %s=%s, ignoring: %m", lvalue
, rvalue
);
5513 r
= extract_first_word(&q
, &source
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
);
5517 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5518 "Invalid syntax in %s=, ignoring: %s", lvalue
, tuple
);
5530 r
= unit_path_printf(u
, s
, &sresolved
);
5532 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5533 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", s
);
5537 r
= path_simplify_and_warn(sresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5542 _cleanup_free_
char *partition
= NULL
, *mount_options
= NULL
, *mount_options_resolved
= NULL
;
5543 MountOptions
*o
= NULL
;
5544 PartitionDesignator partition_designator
;
5546 r
= extract_many_words(&q
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
, &partition
, &mount_options
, NULL
);
5550 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", q
);
5555 /* Single set of options, applying to the root partition/single filesystem */
5557 r
= unit_full_printf(u
, partition
, &mount_options_resolved
);
5559 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", partition
);
5563 o
= new(MountOptions
, 1);
5566 *o
= (MountOptions
) {
5567 .partition_designator
= PARTITION_ROOT
,
5568 .options
= TAKE_PTR(mount_options_resolved
),
5570 LIST_APPEND(mount_options
, options
, o
);
5575 partition_designator
= partition_designator_from_string(partition
);
5576 if (partition_designator
< 0) {
5577 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid partition name %s, ignoring", partition
);
5580 r
= unit_full_printf(u
, mount_options
, &mount_options_resolved
);
5582 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", mount_options
);
5586 o
= new(MountOptions
, 1);
5589 *o
= (MountOptions
) {
5590 .partition_designator
= partition_designator
,
5591 .options
= TAKE_PTR(mount_options_resolved
),
5593 LIST_APPEND(mount_options
, options
, o
);
5596 r
= mount_image_add(&c
->extension_images
, &c
->n_extension_images
,
5598 .source
= sresolved
,
5599 .mount_options
= options
,
5600 .ignore_enoent
= permissive
,
5601 .type
= MOUNT_IMAGE_EXTENSION
,
5608 int config_parse_job_timeout_sec(
5610 const char *filename
,
5612 const char *section
,
5613 unsigned section_line
,
5629 r
= parse_sec_fix_0(rvalue
, &usec
);
5631 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse JobTimeoutSec= parameter, ignoring: %s", rvalue
);
5635 /* If the user explicitly changed JobTimeoutSec= also change JobRunningTimeoutSec=, for compatibility with old
5636 * versions. If JobRunningTimeoutSec= was explicitly set, avoid this however as whatever the user picked should
5639 if (!u
->job_running_timeout_set
)
5640 u
->job_running_timeout
= usec
;
5642 u
->job_timeout
= usec
;
5647 int config_parse_job_running_timeout_sec(
5649 const char *filename
,
5651 const char *section
,
5652 unsigned section_line
,
5668 r
= parse_sec_fix_0(rvalue
, &usec
);
5670 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse JobRunningTimeoutSec= parameter, ignoring: %s", rvalue
);
5674 u
->job_running_timeout
= usec
;
5675 u
->job_running_timeout_set
= true;
5680 int config_parse_emergency_action(
5682 const char *filename
,
5684 const char *section
,
5685 unsigned section_line
,
5693 EmergencyAction
*x
= data
;
5702 m
= ((Unit
*) userdata
)->manager
;
5706 r
= parse_emergency_action(rvalue
, MANAGER_IS_SYSTEM(m
), x
);
5708 if (r
== -EOPNOTSUPP
&& MANAGER_IS_USER(m
)) {
5709 /* Compat mode: remove for systemd 241. */
5711 log_syntax(unit
, LOG_INFO
, filename
, line
, r
,
5712 "%s= in user mode specified as \"%s\", using \"exit-force\" instead.",
5714 *x
= EMERGENCY_ACTION_EXIT_FORCE
;
5718 if (r
== -EOPNOTSUPP
)
5719 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5720 "%s= specified as %s mode action, ignoring: %s",
5721 lvalue
, MANAGER_IS_SYSTEM(m
) ? "user" : "system", rvalue
);
5723 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5724 "Failed to parse %s=, ignoring: %s", lvalue
, rvalue
);
5731 int config_parse_pid_file(
5733 const char *filename
,
5735 const char *section
,
5736 unsigned section_line
,
5743 _cleanup_free_
char *k
= NULL
, *n
= NULL
;
5744 const Unit
*u
= userdata
;
5753 if (isempty(rvalue
)) {
5754 /* An empty assignment removes already set value. */
5759 r
= unit_path_printf(u
, rvalue
, &k
);
5761 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
5765 /* If this is a relative path make it absolute by prefixing the /run */
5766 n
= path_make_absolute(k
, u
->manager
->prefix
[EXEC_DIRECTORY_RUNTIME
]);
5770 /* Check that the result is a sensible path */
5771 r
= path_simplify_and_warn(n
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5775 r
= patch_var_run(unit
, filename
, line
, lvalue
, &n
);
5779 free_and_replace(*s
, n
);
5783 int config_parse_exit_status(
5785 const char *filename
,
5787 const char *section
,
5788 unsigned section_line
,
5795 int *exit_status
= data
, r
;
5801 assert(exit_status
);
5803 if (isempty(rvalue
)) {
5808 r
= safe_atou8(rvalue
, &u
);
5810 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse exit status '%s', ignoring: %m", rvalue
);
5818 int config_parse_disable_controllers(
5820 const char *filename
,
5822 const char *section
,
5823 unsigned section_line
,
5831 CGroupContext
*c
= data
;
5832 CGroupMask disabled_mask
;
5834 /* 1. If empty, make all controllers eligible for use again.
5835 * 2. If non-empty, merge all listed controllers, space separated. */
5837 if (isempty(rvalue
)) {
5838 c
->disable_controllers
= 0;
5842 r
= cg_mask_from_string(rvalue
, &disabled_mask
);
5843 if (r
< 0 || disabled_mask
<= 0) {
5844 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid cgroup string: %s, ignoring", rvalue
);
5848 c
->disable_controllers
|= disabled_mask
;
5853 int config_parse_ip_filter_bpf_progs(
5855 const char *filename
,
5857 const char *section
,
5858 unsigned section_line
,
5865 _cleanup_free_
char *resolved
= NULL
;
5866 const Unit
*u
= userdata
;
5867 char ***paths
= data
;
5875 if (isempty(rvalue
)) {
5876 *paths
= strv_free(*paths
);
5880 r
= unit_path_printf(u
, rvalue
, &resolved
);
5882 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
5886 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5890 if (strv_contains(*paths
, resolved
))
5893 r
= strv_extend(paths
, resolved
);
5897 r
= bpf_firewall_supported();
5900 if (r
!= BPF_FIREWALL_SUPPORTED_WITH_MULTI
) {
5901 static bool warned
= false;
5903 log_full(warned
? LOG_DEBUG
: LOG_WARNING
,
5904 "File %s:%u configures an IP firewall with BPF programs (%s=%s), but the local system does not support BPF/cgroup based firewalling with multiple filters.\n"
5905 "Starting this unit will fail! (This warning is only shown for the first loaded unit using IP firewalling.)", filename
, line
, lvalue
, rvalue
);
5913 int config_parse_bpf_foreign_program(
5915 const char *filename
,
5917 const char *section
,
5918 unsigned section_line
,
5924 _cleanup_free_
char *resolved
= NULL
, *word
= NULL
;
5925 CGroupContext
*c
= data
;
5926 const char *p
= rvalue
;
5934 if (isempty(rvalue
)) {
5935 while (c
->bpf_foreign_programs
)
5936 cgroup_context_remove_bpf_foreign_program(c
, c
->bpf_foreign_programs
);
5941 r
= extract_first_word(&p
, &word
, ":", 0);
5945 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse foreign BPF program, ignoring: %s", rvalue
);
5948 if (r
== 0 || isempty(p
)) {
5949 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid syntax in %s=, ignoring: %s", lvalue
, rvalue
);
5953 attach_type
= bpf_cgroup_attach_type_from_string(word
);
5954 if (attach_type
< 0) {
5955 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Unknown BPF attach type=%s, ignoring: %s", word
, rvalue
);
5959 r
= unit_path_printf(u
, p
, &resolved
);
5961 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %s", p
, rvalue
);
5965 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5969 r
= cgroup_add_bpf_foreign_program(c
, attach_type
, resolved
);
5971 return log_error_errno(r
, "Failed to add foreign BPF program to cgroup context: %m");
5976 int config_parse_cgroup_socket_bind(
5978 const char *filename
,
5980 const char *section
,
5981 unsigned section_line
,
5987 _cleanup_free_ CGroupSocketBindItem
*item
= NULL
;
5988 CGroupSocketBindItem
**head
= data
;
5989 uint16_t nr_ports
, port_min
;
5990 int af
, ip_protocol
, r
;
5992 if (isempty(rvalue
)) {
5993 cgroup_context_remove_socket_bind(head
);
5997 r
= parse_socket_bind_item(rvalue
, &af
, &ip_protocol
, &nr_ports
, &port_min
);
6001 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
6002 "Unable to parse %s= assignment, ignoring: %s", lvalue
, rvalue
);
6006 item
= new(CGroupSocketBindItem
, 1);
6009 *item
= (CGroupSocketBindItem
) {
6010 .address_family
= af
,
6011 .ip_protocol
= ip_protocol
,
6012 .nr_ports
= nr_ports
,
6013 .port_min
= port_min
,
6016 LIST_PREPEND(socket_bind_items
, *head
, TAKE_PTR(item
));
6021 int config_parse_restrict_network_interfaces(
6023 const char *filename
,
6025 const char *section
,
6026 unsigned section_line
,
6032 CGroupContext
*c
= data
;
6033 bool is_allow_rule
= true;
6041 if (isempty(rvalue
)) {
6042 /* Empty assignment resets the list */
6043 c
->restrict_network_interfaces
= set_free(c
->restrict_network_interfaces
);
6047 if (rvalue
[0] == '~') {
6048 is_allow_rule
= false;
6052 if (set_isempty(c
->restrict_network_interfaces
))
6053 /* Only initialize this when creating the set */
6054 c
->restrict_network_interfaces_is_allow_list
= is_allow_rule
;
6056 for (const char *p
= rvalue
;;) {
6057 _cleanup_free_
char *word
= NULL
;
6059 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
6065 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
6066 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
6070 if (!ifname_valid(word
)) {
6071 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid interface name, ignoring: %s", word
);
6075 if (c
->restrict_network_interfaces_is_allow_list
!= is_allow_rule
)
6076 free(set_remove(c
->restrict_network_interfaces
, word
));
6078 r
= set_put_strdup(&c
->restrict_network_interfaces
, word
);
6087 static int merge_by_names(Unit
**u
, Set
*names
, const char *id
) {
6094 /* Let's try to add in all names that are aliases of this unit */
6095 while ((k
= set_steal_first(names
))) {
6096 _cleanup_free_ _unused_
char *free_k
= k
;
6098 /* First try to merge in the other name into our unit */
6099 r
= unit_merge_by_name(*u
, k
);
6103 /* Hmm, we couldn't merge the other unit into ours? Then let's try it the other way
6106 other
= manager_get_unit((*u
)->manager
, k
);
6108 return r
; /* return previous failure */
6110 r
= unit_merge(other
, *u
);
6115 return merge_by_names(u
, names
, NULL
);
6118 if (streq_ptr(id
, k
))
6119 unit_choose_id(*u
, id
);
6125 int unit_load_fragment(Unit
*u
) {
6126 const char *fragment
;
6127 _cleanup_set_free_free_ Set
*names
= NULL
;
6131 assert(u
->load_state
== UNIT_STUB
);
6135 u
->access_selinux_context
= mfree(u
->access_selinux_context
);
6136 u
->load_state
= UNIT_LOADED
;
6140 /* Possibly rebuild the fragment map to catch new units */
6141 r
= unit_file_build_name_map(&u
->manager
->lookup_paths
,
6142 &u
->manager
->unit_cache_timestamp_hash
,
6143 &u
->manager
->unit_id_map
,
6144 &u
->manager
->unit_name_map
,
6145 &u
->manager
->unit_path_cache
);
6147 return log_error_errno(r
, "Failed to rebuild name map: %m");
6149 r
= unit_file_find_fragment(u
->manager
->unit_id_map
,
6150 u
->manager
->unit_name_map
,
6154 if (r
< 0 && r
!= -ENOENT
)
6158 /* Open the file, check if this is a mask, otherwise read. */
6159 _cleanup_fclose_
FILE *f
= NULL
;
6162 /* Try to open the file name. A symlink is OK, for example for linked files or masks. We
6163 * expect that all symlinks within the lookup paths have been already resolved, but we don't
6164 * verify this here. */
6165 f
= fopen(fragment
, "re");
6167 return log_unit_notice_errno(u
, errno
, "Failed to open %s: %m", fragment
);
6169 if (fstat(fileno(f
), &st
) < 0)
6172 r
= free_and_strdup(&u
->fragment_path
, fragment
);
6176 if (null_or_empty(&st
)) {
6177 /* Unit file is masked */
6179 u
->load_state
= u
->perpetual
? UNIT_LOADED
: UNIT_MASKED
; /* don't allow perpetual units to ever be masked */
6180 u
->fragment_mtime
= 0;
6181 u
->access_selinux_context
= mfree(u
->access_selinux_context
);
6184 if (mac_selinux_use()) {
6185 _cleanup_freecon_
char *selcon
= NULL
;
6187 /* Cache the SELinux context of the unit file here. We'll make use of when checking access permissions to loaded units */
6188 r
= fgetfilecon_raw(fileno(f
), &selcon
);
6190 log_unit_warning_errno(u
, r
, "Failed to read SELinux context of '%s', ignoring: %m", fragment
);
6192 r
= free_and_strdup(&u
->access_selinux_context
, selcon
);
6197 u
->access_selinux_context
= mfree(u
->access_selinux_context
);
6199 u
->load_state
= UNIT_LOADED
;
6200 u
->fragment_mtime
= timespec_load(&st
.st_mtim
);
6202 /* Now, parse the file contents */
6203 r
= config_parse(u
->id
, fragment
, f
,
6204 UNIT_VTABLE(u
)->sections
,
6205 config_item_perf_lookup
, load_fragment_gperf_lookup
,
6210 log_unit_notice_errno(u
, r
, "Unit configuration has fatal error, unit will not be started.");
6216 /* Call merge_by_names with the name derived from the fragment path as the preferred name.
6218 * We do the merge dance here because for some unit types, the unit might have aliases which are not
6219 * declared in the file system. In particular, this is true (and frequent) for device and swap units.
6221 const char *id
= u
->id
;
6222 _cleanup_free_
char *free_id
= NULL
;
6225 id
= basename(fragment
);
6226 if (unit_name_is_valid(id
, UNIT_NAME_TEMPLATE
)) {
6227 assert(u
->instance
); /* If we're not trying to use a template for non-instanced unit,
6228 * this must be set. */
6230 r
= unit_name_replace_instance(id
, u
->instance
, &free_id
);
6232 return log_debug_errno(r
, "Failed to build id (%s + %s): %m", id
, u
->instance
);
6238 r
= merge_by_names(&merged
, names
, id
);
6243 u
->load_state
= UNIT_MERGED
;
6248 void unit_dump_config_items(FILE *f
) {
6249 static const struct {
6250 const ConfigParserCallback callback
;
6253 { config_parse_warn_compat
, "NOTSUPPORTED" },
6254 { config_parse_int
, "INTEGER" },
6255 { config_parse_unsigned
, "UNSIGNED" },
6256 { config_parse_iec_size
, "SIZE" },
6257 { config_parse_iec_uint64
, "SIZE" },
6258 { config_parse_si_uint64
, "SIZE" },
6259 { config_parse_bool
, "BOOLEAN" },
6260 { config_parse_string
, "STRING" },
6261 { config_parse_path
, "PATH" },
6262 { config_parse_unit_path_printf
, "PATH" },
6263 { config_parse_colon_separated_paths
, "PATH" },
6264 { config_parse_strv
, "STRING [...]" },
6265 { config_parse_exec_nice
, "NICE" },
6266 { config_parse_exec_oom_score_adjust
, "OOMSCOREADJUST" },
6267 { config_parse_exec_io_class
, "IOCLASS" },
6268 { config_parse_exec_io_priority
, "IOPRIORITY" },
6269 { config_parse_exec_cpu_sched_policy
, "CPUSCHEDPOLICY" },
6270 { config_parse_exec_cpu_sched_prio
, "CPUSCHEDPRIO" },
6271 { config_parse_exec_cpu_affinity
, "CPUAFFINITY" },
6272 { config_parse_mode
, "MODE" },
6273 { config_parse_unit_env_file
, "FILE" },
6274 { config_parse_exec_output
, "OUTPUT" },
6275 { config_parse_exec_input
, "INPUT" },
6276 { config_parse_log_facility
, "FACILITY" },
6277 { config_parse_log_level
, "LEVEL" },
6278 { config_parse_exec_secure_bits
, "SECUREBITS" },
6279 { config_parse_capability_set
, "BOUNDINGSET" },
6280 { config_parse_rlimit
, "LIMIT" },
6281 { config_parse_unit_deps
, "UNIT [...]" },
6282 { config_parse_exec
, "PATH [ARGUMENT [...]]" },
6283 { config_parse_service_type
, "SERVICETYPE" },
6284 { config_parse_service_exit_type
, "SERVICEEXITTYPE" },
6285 { config_parse_service_restart
, "SERVICERESTART" },
6286 { config_parse_service_timeout_failure_mode
, "TIMEOUTMODE" },
6287 { config_parse_kill_mode
, "KILLMODE" },
6288 { config_parse_signal
, "SIGNAL" },
6289 { config_parse_socket_listen
, "SOCKET [...]" },
6290 { config_parse_socket_bind
, "SOCKETBIND" },
6291 { config_parse_socket_bindtodevice
, "NETWORKINTERFACE" },
6292 { config_parse_sec
, "SECONDS" },
6293 { config_parse_nsec
, "NANOSECONDS" },
6294 { config_parse_namespace_path_strv
, "PATH [...]" },
6295 { config_parse_bind_paths
, "PATH[:PATH[:OPTIONS]] [...]" },
6296 { config_parse_unit_requires_mounts_for
, "PATH [...]" },
6297 { config_parse_exec_mount_flags
, "MOUNTFLAG [...]" },
6298 { config_parse_unit_string_printf
, "STRING" },
6299 { config_parse_trigger_unit
, "UNIT" },
6300 { config_parse_timer
, "TIMER" },
6301 { config_parse_path_spec
, "PATH" },
6302 { config_parse_notify_access
, "ACCESS" },
6303 { config_parse_ip_tos
, "TOS" },
6304 { config_parse_unit_condition_path
, "CONDITION" },
6305 { config_parse_unit_condition_string
, "CONDITION" },
6306 { config_parse_unit_slice
, "SLICE" },
6307 { config_parse_documentation
, "URL" },
6308 { config_parse_service_timeout
, "SECONDS" },
6309 { config_parse_emergency_action
, "ACTION" },
6310 { config_parse_set_status
, "STATUS" },
6311 { config_parse_service_sockets
, "SOCKETS" },
6312 { config_parse_environ
, "ENVIRON" },
6314 { config_parse_syscall_filter
, "SYSCALLS" },
6315 { config_parse_syscall_archs
, "ARCHS" },
6316 { config_parse_syscall_errno
, "ERRNO" },
6317 { config_parse_syscall_log
, "SYSCALLS" },
6318 { config_parse_address_families
, "FAMILIES" },
6319 { config_parse_restrict_namespaces
, "NAMESPACES" },
6321 { config_parse_restrict_filesystems
, "FILESYSTEMS" },
6322 { config_parse_cpu_shares
, "SHARES" },
6323 { config_parse_cg_weight
, "WEIGHT" },
6324 { config_parse_cg_cpu_weight
, "CPUWEIGHT" },
6325 { config_parse_memory_limit
, "LIMIT" },
6326 { config_parse_device_allow
, "DEVICE" },
6327 { config_parse_device_policy
, "POLICY" },
6328 { config_parse_io_limit
, "LIMIT" },
6329 { config_parse_io_device_weight
, "DEVICEWEIGHT" },
6330 { config_parse_io_device_latency
, "DEVICELATENCY" },
6331 { config_parse_blockio_bandwidth
, "BANDWIDTH" },
6332 { config_parse_blockio_weight
, "WEIGHT" },
6333 { config_parse_blockio_device_weight
, "DEVICEWEIGHT" },
6334 { config_parse_long
, "LONG" },
6335 { config_parse_socket_service
, "SERVICE" },
6337 { config_parse_exec_selinux_context
, "LABEL" },
6339 { config_parse_job_mode
, "MODE" },
6340 { config_parse_job_mode_isolate
, "BOOLEAN" },
6341 { config_parse_personality
, "PERSONALITY" },
6344 const char *prev
= NULL
;
6349 NULSTR_FOREACH(i
, load_fragment_gperf_nulstr
) {
6350 const char *rvalue
= "OTHER", *lvalue
;
6351 const ConfigPerfItem
*p
;
6354 assert_se(p
= load_fragment_gperf_lookup(i
, strlen(i
)));
6356 /* Hide legacy settings */
6357 if (p
->parse
== config_parse_warn_compat
&&
6358 p
->ltype
== DISABLED_LEGACY
)
6361 for (size_t j
= 0; j
< ELEMENTSOF(table
); j
++)
6362 if (p
->parse
== table
[j
].callback
) {
6363 rvalue
= table
[j
].rvalue
;
6367 dot
= strchr(i
, '.');
6368 lvalue
= dot
? dot
+ 1 : i
;
6371 size_t prefix_len
= dot
- i
;
6373 if (!prev
|| !strneq(prev
, i
, prefix_len
+1)) {
6377 fprintf(f
, "[%.*s]\n", (int) prefix_len
, i
);
6381 fprintf(f
, "%s=%s\n", lvalue
, rvalue
);
6386 int config_parse_cpu_affinity2(
6388 const char *filename
,
6390 const char *section
,
6391 unsigned section_line
,
6398 CPUSet
*affinity
= data
;
6402 (void) parse_cpu_set_extend(rvalue
, affinity
, true, unit
, filename
, line
, lvalue
);
6407 int config_parse_show_status(
6409 const char *filename
,
6411 const char *section
,
6412 unsigned section_line
,
6420 ShowStatus
*b
= data
;
6427 k
= parse_show_status(rvalue
, b
);
6429 log_syntax(unit
, LOG_WARNING
, filename
, line
, k
, "Failed to parse show status setting, ignoring: %s", rvalue
);
6434 int config_parse_output_restricted(
6436 const char *filename
,
6438 const char *section
,
6439 unsigned section_line
,
6446 ExecOutput t
, *eo
= data
;
6447 bool obsolete
= false;
6454 if (streq(rvalue
, "syslog")) {
6455 t
= EXEC_OUTPUT_JOURNAL
;
6457 } else if (streq(rvalue
, "syslog+console")) {
6458 t
= EXEC_OUTPUT_JOURNAL_AND_CONSOLE
;
6461 t
= exec_output_from_string(rvalue
);
6463 log_syntax(unit
, LOG_WARNING
, filename
, line
, t
, "Failed to parse output type, ignoring: %s", rvalue
);
6467 if (IN_SET(t
, EXEC_OUTPUT_SOCKET
, EXEC_OUTPUT_NAMED_FD
, EXEC_OUTPUT_FILE
, EXEC_OUTPUT_FILE_APPEND
, EXEC_OUTPUT_FILE_TRUNCATE
)) {
6468 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Standard output types socket, fd:, file:, append:, truncate: are not supported as defaults, ignoring: %s", rvalue
);
6474 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
6475 "Standard output type %s is obsolete, automatically updating to %s. Please update your configuration.",
6476 rvalue
, exec_output_to_string(t
));
6482 int config_parse_crash_chvt(
6484 const char *filename
,
6486 const char *section
,
6487 unsigned section_line
,
6501 r
= parse_crash_chvt(rvalue
, data
);
6503 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse CrashChangeVT= setting, ignoring: %s", rvalue
);
6508 int config_parse_swap_priority(
6510 const char *filename
,
6512 const char *section
,
6513 unsigned section_line
,
6529 if (isempty(rvalue
)) {
6530 s
->parameters_fragment
.priority
= -1;
6531 s
->parameters_fragment
.priority_set
= false;
6535 r
= safe_atoi(rvalue
, &priority
);
6537 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid swap priority '%s', ignoring.", rvalue
);
6541 if (priority
< -1) {
6542 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Sorry, swap priorities smaller than -1 may only be assigned by the kernel itself, ignoring: %s", rvalue
);
6546 if (priority
> 32767) {
6547 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Swap priority out of range, ignoring: %s", rvalue
);
6551 s
->parameters_fragment
.priority
= priority
;
6552 s
->parameters_fragment
.priority_set
= true;
6556 int config_parse_watchdog_sec(
6558 const char *filename
,
6560 const char *section
,
6561 unsigned section_line
,
6568 usec_t
*usec
= data
;
6574 /* This is called for {Runtime,Reboot,KExec}WatchdogSec= where "default" maps to
6575 * USEC_INFINITY internally. */
6577 if (streq(rvalue
, "default"))
6578 *usec
= USEC_INFINITY
;
6579 else if (streq(rvalue
, "off"))
6582 return config_parse_sec(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
);
6587 int config_parse_tty_size(
6589 const char *filename
,
6591 const char *section
,
6592 unsigned section_line
,
6599 unsigned *sz
= data
;
6605 if (isempty(rvalue
)) {
6610 return config_parse_unsigned(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
);