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 "signal-util.h"
62 #include "socket-netlink.h"
63 #include "specifier.h"
64 #include "stat-util.h"
65 #include "string-util.h"
67 #include "syslog-util.h"
68 #include "time-util.h"
69 #include "unit-name.h"
70 #include "unit-printf.h"
71 #include "user-util.h"
75 static int parse_socket_protocol(const char *s
) {
78 r
= parse_ip_protocol(s
);
81 if (!IN_SET(r
, IPPROTO_UDPLITE
, IPPROTO_SCTP
))
82 return -EPROTONOSUPPORT
;
87 int parse_crash_chvt(const char *value
, int *data
) {
90 if (safe_atoi(value
, data
) >= 0)
93 b
= parse_boolean(value
);
98 *data
= 0; /* switch to where kmsg goes */
100 *data
= -1; /* turn off switching */
105 int parse_confirm_spawn(const char *value
, char **console
) {
109 r
= value
? parse_boolean(value
) : 1;
113 } else if (r
> 0) /* on with default tty */
114 s
= strdup("/dev/console");
115 else if (is_path(value
)) /* on with fully qualified path */
117 else /* on with only a tty file name, not a fully qualified path */
118 s
= path_join("/dev/", value
);
126 DEFINE_CONFIG_PARSE(config_parse_socket_protocol
, parse_socket_protocol
, "Failed to parse socket protocol");
127 DEFINE_CONFIG_PARSE(config_parse_exec_secure_bits
, secure_bits_from_string
, "Failed to parse secure bits");
128 DEFINE_CONFIG_PARSE_ENUM(config_parse_collect_mode
, collect_mode
, CollectMode
, "Failed to parse garbage collection mode");
129 DEFINE_CONFIG_PARSE_ENUM(config_parse_device_policy
, cgroup_device_policy
, CGroupDevicePolicy
, "Failed to parse device policy");
130 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_keyring_mode
, exec_keyring_mode
, ExecKeyringMode
, "Failed to parse keyring mode");
131 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_proc
, protect_proc
, ProtectProc
, "Failed to parse /proc/ protection mode");
132 DEFINE_CONFIG_PARSE_ENUM(config_parse_proc_subset
, proc_subset
, ProcSubset
, "Failed to parse /proc/ subset mode");
133 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_utmp_mode
, exec_utmp_mode
, ExecUtmpMode
, "Failed to parse utmp mode");
134 DEFINE_CONFIG_PARSE_ENUM(config_parse_job_mode
, job_mode
, JobMode
, "Failed to parse job mode");
135 DEFINE_CONFIG_PARSE_ENUM(config_parse_notify_access
, notify_access
, NotifyAccess
, "Failed to parse notify access specifier");
136 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_home
, protect_home
, ProtectHome
, "Failed to parse protect home value");
137 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_system
, protect_system
, ProtectSystem
, "Failed to parse protect system value");
138 DEFINE_CONFIG_PARSE_ENUM(config_parse_runtime_preserve_mode
, exec_preserve_mode
, ExecPreserveMode
, "Failed to parse runtime directory preserve mode");
139 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_type
, service_type
, ServiceType
, "Failed to parse service type");
140 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_exit_type
, service_exit_type
, ServiceExitType
, "Failed to parse service exit type");
141 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart
, service_restart
, ServiceRestart
, "Failed to parse service restart specifier");
142 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_timeout_failure_mode
, service_timeout_failure_mode
, ServiceTimeoutFailureMode
, "Failed to parse timeout failure mode");
143 DEFINE_CONFIG_PARSE_ENUM(config_parse_socket_bind
, socket_address_bind_ipv6_only_or_bool
, SocketAddressBindIPv6Only
, "Failed to parse bind IPv6 only value");
144 DEFINE_CONFIG_PARSE_ENUM(config_parse_oom_policy
, oom_policy
, OOMPolicy
, "Failed to parse OOM policy");
145 DEFINE_CONFIG_PARSE_ENUM(config_parse_managed_oom_preference
, managed_oom_preference
, ManagedOOMPreference
, "Failed to parse ManagedOOMPreference=");
146 DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_ip_tos
, ip_tos
, int, -1, "Failed to parse IP TOS value");
147 DEFINE_CONFIG_PARSE_PTR(config_parse_blockio_weight
, cg_blkio_weight_parse
, uint64_t, "Invalid block IO weight");
148 DEFINE_CONFIG_PARSE_PTR(config_parse_cg_weight
, cg_weight_parse
, uint64_t, "Invalid weight");
149 DEFINE_CONFIG_PARSE_PTR(config_parse_cpu_shares
, cg_cpu_shares_parse
, uint64_t, "Invalid CPU shares");
150 DEFINE_CONFIG_PARSE_PTR(config_parse_exec_mount_flags
, mount_propagation_flags_from_string
, unsigned long, "Failed to parse mount flag");
151 DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_numa_policy
, mpol
, int, -1, "Invalid NUMA policy type");
152 DEFINE_CONFIG_PARSE_ENUM(config_parse_status_unit_format
, status_unit_format
, StatusUnitFormat
, "Failed to parse status unit format");
153 DEFINE_CONFIG_PARSE_ENUM_FULL(config_parse_socket_timestamping
, socket_timestamping_from_string_harder
, SocketTimestamping
, "Failed to parse timestamping precision");
155 bool contains_instance_specifier_superset(const char *s
) {
157 bool percent
= false;
171 /* If the string is just the instance specifier, it's not a superset of the instance. */
172 if (memcmp_nn(p
, q
- p
, "%i", strlen("%i")) == 0)
175 /* %i, %n and %N all expand to the instance or a superset of it. */
180 if (IN_SET(*p
, 'n', 'N', 'i'))
189 /* `name` is the rendered version of `format` via `unit_printf` or similar functions. */
190 int unit_is_likely_recursive_template_dependency(Unit
*u
, const char *name
, const char *format
) {
191 const char *fragment_path
;
197 /* If a template unit has a direct dependency on itself that includes the unit instance as part of
198 * the template instance via a unit specifier (%i, %n or %N), this will almost certainly lead to
199 * infinite recursion as systemd will keep instantiating new instances of the template unit.
200 * https://github.com/systemd/systemd/issues/17602 shows a good example of how this can happen in
201 * practice. To guard against this, we check for templates that depend on themselves and have the
202 * instantiated unit instance included as part of the template instance of the dependency via a
205 * For example, if systemd-notify@.service depends on systemd-notify@%n.service, this will result in
206 * infinite recursion.
209 if (!unit_name_is_valid(name
, UNIT_NAME_INSTANCE
))
212 if (!unit_name_prefix_equal(u
->id
, name
))
215 if (u
->type
!= unit_name_to_type(name
))
218 r
= unit_file_find_fragment(u
->manager
->unit_id_map
, u
->manager
->unit_name_map
, name
, &fragment_path
, NULL
);
222 /* Fragment paths should also be equal as a custom fragment for a specific template instance
223 * wouldn't necessarily lead to infinite recursion. */
224 if (!path_equal_ptr(u
->fragment_path
, fragment_path
))
227 if (!contains_instance_specifier_superset(format
))
233 int config_parse_unit_deps(
235 const char *filename
,
238 unsigned section_line
,
245 UnitDependency d
= ltype
;
252 for (const char *p
= rvalue
;;) {
253 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
256 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_RETAIN_ESCAPE
);
262 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
266 r
= unit_name_printf(u
, word
, &k
);
268 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
272 r
= unit_is_likely_recursive_template_dependency(u
, k
, word
);
274 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to determine if '%s' is a recursive dependency, ignoring: %m", k
);
278 log_syntax(unit
, LOG_DEBUG
, filename
, line
, 0,
279 "Dropping dependency %s=%s that likely leads to infinite recursion.",
280 unit_dependency_to_string(d
), word
);
284 r
= unit_add_dependency_by_name(u
, d
, k
, true, UNIT_DEPENDENCY_FILE
);
286 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
290 int config_parse_obsolete_unit_deps(
292 const char *filename
,
295 unsigned section_line
,
302 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
303 "Unit dependency type %s= is obsolete, replacing by %s=, please update your unit file", lvalue
, unit_dependency_to_string(ltype
));
305 return config_parse_unit_deps(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
);
308 int config_parse_unit_string_printf(
310 const char *filename
,
313 unsigned section_line
,
320 _cleanup_free_
char *k
= NULL
;
321 const Unit
*u
= userdata
;
329 r
= unit_full_printf(u
, rvalue
, &k
);
331 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
335 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
338 int config_parse_unit_strv_printf(
340 const char *filename
,
343 unsigned section_line
,
350 const Unit
*u
= userdata
;
351 _cleanup_free_
char *k
= NULL
;
359 r
= unit_full_printf(u
, rvalue
, &k
);
361 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
365 return config_parse_strv(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
368 int config_parse_unit_path_printf(
370 const char *filename
,
373 unsigned section_line
,
380 _cleanup_free_
char *k
= NULL
;
381 const Unit
*u
= userdata
;
390 r
= unit_path_printf(u
, rvalue
, &k
);
392 log_syntax(unit
, fatal
? LOG_ERR
: LOG_WARNING
, filename
, line
, r
,
393 "Failed to resolve unit specifiers in '%s'%s: %m",
394 rvalue
, fatal
? "" : ", ignoring");
395 return fatal
? -ENOEXEC
: 0;
398 return config_parse_path(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
401 int config_parse_colon_separated_paths(
403 const char *filename
,
406 unsigned section_line
,
413 const Unit
*u
= userdata
;
421 if (isempty(rvalue
)) {
422 /* Empty assignment resets the list */
423 *sv
= strv_free(*sv
);
427 for (const char *p
= rvalue
;;) {
428 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
430 r
= extract_first_word(&p
, &word
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
434 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
440 r
= unit_path_printf(u
, word
, &k
);
442 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
443 "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
447 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
451 r
= strv_consume(sv
, TAKE_PTR(k
));
459 int config_parse_unit_path_strv_printf(
461 const char *filename
,
464 unsigned section_line
,
472 const Unit
*u
= userdata
;
480 if (isempty(rvalue
)) {
485 for (const char *p
= rvalue
;;) {
486 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
488 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
494 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
495 "Invalid syntax, ignoring: %s", rvalue
);
499 r
= unit_path_printf(u
, word
, &k
);
501 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
502 "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
506 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
510 r
= strv_consume(x
, TAKE_PTR(k
));
516 static int patch_var_run(
518 const char *filename
,
526 e
= path_startswith(*path
, "/var/run/");
530 z
= path_join("/run/", e
);
534 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
535 "%s= references a path below legacy directory /var/run/, updating %s → %s; "
536 "please update the unit file accordingly.", lvalue
, *path
, z
);
538 free_and_replace(*path
, z
);
543 int config_parse_socket_listen(
545 const char *filename
,
548 unsigned section_line
,
555 _cleanup_free_ SocketPort
*p
= NULL
;
567 if (isempty(rvalue
)) {
568 /* An empty assignment removes all ports */
569 socket_free_ports(s
);
573 p
= new0(SocketPort
, 1);
577 if (ltype
!= SOCKET_SOCKET
) {
578 _cleanup_free_
char *k
= NULL
;
580 r
= unit_path_printf(UNIT(s
), rvalue
, &k
);
582 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
586 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
590 if (ltype
== SOCKET_FIFO
) {
591 r
= patch_var_run(unit
, filename
, line
, lvalue
, &k
);
596 free_and_replace(p
->path
, k
);
599 } else if (streq(lvalue
, "ListenNetlink")) {
600 _cleanup_free_
char *k
= NULL
;
602 r
= unit_path_printf(UNIT(s
), rvalue
, &k
);
604 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
608 r
= socket_address_parse_netlink(&p
->address
, k
);
610 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse address value in '%s', ignoring: %m", k
);
614 p
->type
= SOCKET_SOCKET
;
617 _cleanup_free_
char *k
= NULL
;
619 r
= unit_path_printf(UNIT(s
), rvalue
, &k
);
621 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
625 if (k
[0] == '/') { /* Only for AF_UNIX file system sockets… */
626 r
= patch_var_run(unit
, filename
, line
, lvalue
, &k
);
631 r
= socket_address_parse_and_warn(&p
->address
, k
);
633 if (r
!= -EAFNOSUPPORT
)
634 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse address value in '%s', ignoring: %m", k
);
638 if (streq(lvalue
, "ListenStream"))
639 p
->address
.type
= SOCK_STREAM
;
640 else if (streq(lvalue
, "ListenDatagram"))
641 p
->address
.type
= SOCK_DGRAM
;
643 assert(streq(lvalue
, "ListenSequentialPacket"));
644 p
->address
.type
= SOCK_SEQPACKET
;
647 if (socket_address_family(&p
->address
) != AF_UNIX
&& p
->address
.type
== SOCK_SEQPACKET
) {
648 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Address family not supported, ignoring: %s", rvalue
);
652 p
->type
= SOCKET_SOCKET
;
656 p
->auxiliary_fds
= NULL
;
657 p
->n_auxiliary_fds
= 0;
660 LIST_FIND_TAIL(port
, s
->ports
, tail
);
661 LIST_INSERT_AFTER(port
, s
->ports
, tail
, p
);
668 int config_parse_exec_nice(
670 const char *filename
,
673 unsigned section_line
,
680 ExecContext
*c
= data
;
688 if (isempty(rvalue
)) {
693 r
= parse_nice(rvalue
, &priority
);
696 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Nice priority out of range, ignoring: %s", rvalue
);
698 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse nice priority '%s', ignoring: %m", rvalue
);
708 int config_parse_exec_oom_score_adjust(
710 const char *filename
,
713 unsigned section_line
,
720 ExecContext
*c
= data
;
728 if (isempty(rvalue
)) {
729 c
->oom_score_adjust_set
= false;
733 r
= parse_oom_score_adjust(rvalue
, &oa
);
736 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "OOM score adjust value out of range, ignoring: %s", rvalue
);
738 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse the OOM score adjust value '%s', ignoring: %m", rvalue
);
742 c
->oom_score_adjust
= oa
;
743 c
->oom_score_adjust_set
= true;
748 int config_parse_exec_coredump_filter(
750 const char *filename
,
753 unsigned section_line
,
760 ExecContext
*c
= data
;
768 if (isempty(rvalue
)) {
769 c
->coredump_filter
= 0;
770 c
->coredump_filter_set
= false;
775 r
= coredump_filter_mask_from_string(rvalue
, &f
);
777 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
778 "Failed to parse the CoredumpFilter=%s, ignoring: %m", rvalue
);
782 c
->coredump_filter
|= f
;
783 c
->oom_score_adjust_set
= true;
787 int config_parse_kill_mode(
789 const char *filename
,
792 unsigned section_line
,
799 KillMode
*k
= data
, m
;
806 if (isempty(rvalue
)) {
807 *k
= KILL_CONTROL_GROUP
;
811 m
= kill_mode_from_string(rvalue
);
813 log_syntax(unit
, LOG_WARNING
, filename
, line
, m
,
814 "Failed to parse kill mode specification, ignoring: %s", rvalue
);
819 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
820 "Unit configured to use KillMode=none. "
821 "This is unsafe, as it disables systemd's process lifecycle management for the service. "
822 "Please update your service to use a safer KillMode=, such as 'mixed' or 'control-group'. "
823 "Support for KillMode=none is deprecated and will eventually be removed.");
829 int config_parse_exec(
831 const char *filename
,
834 unsigned section_line
,
841 ExecCommand
**e
= data
;
842 const Unit
*u
= userdata
;
854 if (isempty(rvalue
)) {
855 /* An empty assignment resets the list */
856 *e
= exec_command_free_list(*e
);
862 _cleanup_free_
char *path
= NULL
, *firstword
= NULL
;
863 ExecCommandFlags flags
= 0;
864 bool ignore
= false, separate_argv0
= false;
865 _cleanup_free_ ExecCommand
*nce
= NULL
;
866 _cleanup_strv_free_
char **n
= NULL
;
872 r
= extract_first_word_and_warn(&p
, &firstword
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
876 /* A lone ";" is a separator. Let's make sure we don't treat it as an executable name. */
877 if (streq(firstword
, ";")) {
884 /* We accept an absolute path as first argument. If it's prefixed with - and the path doesn't
885 * exist, we ignore it instead of erroring out; if it's prefixed with @, we allow overriding of
886 * argv[0]; if it's prefixed with :, we will not do environment variable substitution;
887 * if it's prefixed with +, it will be run with full privileges and no sandboxing; if
888 * it's prefixed with '!' we apply sandboxing, but do not change user/group credentials; if
889 * it's prefixed with '!!', then we apply user/group credentials if the kernel supports ambient
890 * capabilities -- if it doesn't we don't apply the credentials themselves, but do apply most
891 * other sandboxing, with some special exceptions for changing UID.
893 * The idea is that '!!' may be used to write services that can take benefit of systemd's
894 * UID/GID dropping if the kernel supports ambient creds, but provide an automatic fallback to
895 * privilege dropping within the daemon if the kernel does not offer that. */
897 if (*f
== '-' && !(flags
& EXEC_COMMAND_IGNORE_FAILURE
)) {
898 flags
|= EXEC_COMMAND_IGNORE_FAILURE
;
900 } else if (*f
== '@' && !separate_argv0
)
901 separate_argv0
= true;
902 else if (*f
== ':' && !(flags
& EXEC_COMMAND_NO_ENV_EXPAND
))
903 flags
|= EXEC_COMMAND_NO_ENV_EXPAND
;
904 else if (*f
== '+' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
905 flags
|= EXEC_COMMAND_FULLY_PRIVILEGED
;
906 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
907 flags
|= EXEC_COMMAND_NO_SETUID
;
908 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_AMBIENT_MAGIC
))) {
909 flags
&= ~EXEC_COMMAND_NO_SETUID
;
910 flags
|= EXEC_COMMAND_AMBIENT_MAGIC
;
916 r
= unit_path_printf(u
, f
, &path
);
918 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
919 "Failed to resolve unit specifiers in '%s'%s: %m",
920 f
, ignore
? ", ignoring" : "");
921 return ignore
? 0 : -ENOEXEC
;
925 /* First word is either "-" or "@" with no command. */
926 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
927 "Empty path in command line%s: '%s'",
928 ignore
? ", ignoring" : "", rvalue
);
929 return ignore
? 0 : -ENOEXEC
;
931 if (!string_is_safe(path
)) {
932 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
933 "Executable name contains special characters%s: %s",
934 ignore
? ", ignoring" : "", path
);
935 return ignore
? 0 : -ENOEXEC
;
937 if (endswith(path
, "/")) {
938 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
939 "Executable path specifies a directory%s: %s",
940 ignore
? ", ignoring" : "", path
);
941 return ignore
? 0 : -ENOEXEC
;
944 if (!(path_is_absolute(path
) ? path_is_valid(path
) : filename_is_valid(path
))) {
945 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
946 "Neither a valid executable name nor an absolute path%s: %s",
947 ignore
? ", ignoring" : "", path
);
948 return ignore
? 0 : -ENOEXEC
;
951 if (!separate_argv0
) {
954 if (!GREEDY_REALLOC0(n
, nlen
+ 2))
966 while (!isempty(p
)) {
967 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
969 /* Check explicitly for an unquoted semicolon as
970 * command separator token. */
971 if (p
[0] == ';' && (!p
[1] || strchr(WHITESPACE
, p
[1]))) {
973 p
+= strspn(p
, WHITESPACE
);
978 /* Check for \; explicitly, to not confuse it with \\; or "\;" or "\\;" etc.
979 * extract_first_word() would return the same for all of those. */
980 if (p
[0] == '\\' && p
[1] == ';' && (!p
[2] || strchr(WHITESPACE
, p
[2]))) {
984 p
+= strspn(p
, WHITESPACE
);
986 if (!GREEDY_REALLOC0(n
, nlen
+ 2))
997 r
= extract_first_word_and_warn(&p
, &word
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
1001 return ignore
? 0 : -ENOEXEC
;
1003 r
= unit_full_printf(u
, word
, &resolved
);
1005 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
1006 "Failed to resolve unit specifiers in %s%s: %m",
1007 word
, ignore
? ", ignoring" : "");
1008 return ignore
? 0 : -ENOEXEC
;
1011 if (!GREEDY_REALLOC(n
, nlen
+ 2))
1014 n
[nlen
++] = TAKE_PTR(resolved
);
1019 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
1020 "Empty executable name or zeroeth argument%s: %s",
1021 ignore
? ", ignoring" : "", rvalue
);
1022 return ignore
? 0 : -ENOEXEC
;
1025 nce
= new0(ExecCommand
, 1);
1029 nce
->argv
= TAKE_PTR(n
);
1030 nce
->path
= TAKE_PTR(path
);
1033 exec_command_append_list(e
, nce
);
1035 /* Do not _cleanup_free_ these. */
1039 } while (semicolon
);
1044 int config_parse_socket_bindtodevice(
1046 const char *filename
,
1048 const char *section
,
1049 unsigned section_line
,
1063 if (isempty(rvalue
) || streq(rvalue
, "*")) {
1064 s
->bind_to_device
= mfree(s
->bind_to_device
);
1068 if (!ifname_valid(rvalue
)) {
1069 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid interface name, ignoring: %s", rvalue
);
1073 return free_and_strdup_warn(&s
->bind_to_device
, rvalue
);
1076 int config_parse_exec_input(
1078 const char *filename
,
1080 const char *section
,
1081 unsigned section_line
,
1088 ExecContext
*c
= data
;
1089 const Unit
*u
= userdata
;
1099 n
= startswith(rvalue
, "fd:");
1101 _cleanup_free_
char *resolved
= NULL
;
1103 r
= unit_fd_printf(u
, n
, &resolved
);
1105 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", n
);
1109 if (isempty(resolved
))
1110 resolved
= mfree(resolved
);
1111 else if (!fdname_is_valid(resolved
)) {
1112 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", resolved
);
1116 free_and_replace(c
->stdio_fdname
[STDIN_FILENO
], resolved
);
1118 ei
= EXEC_INPUT_NAMED_FD
;
1120 } else if ((n
= startswith(rvalue
, "file:"))) {
1121 _cleanup_free_
char *resolved
= NULL
;
1123 r
= unit_path_printf(u
, n
, &resolved
);
1125 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", n
);
1129 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1133 free_and_replace(c
->stdio_file
[STDIN_FILENO
], resolved
);
1135 ei
= EXEC_INPUT_FILE
;
1138 ei
= exec_input_from_string(rvalue
);
1140 log_syntax(unit
, LOG_WARNING
, filename
, line
, ei
, "Failed to parse input specifier, ignoring: %s", rvalue
);
1149 int config_parse_exec_input_text(
1151 const char *filename
,
1153 const char *section
,
1154 unsigned section_line
,
1161 _cleanup_free_
char *unescaped
= NULL
, *resolved
= NULL
;
1162 ExecContext
*c
= data
;
1163 const Unit
*u
= userdata
;
1171 if (isempty(rvalue
)) {
1172 /* Reset if the empty string is assigned */
1173 c
->stdin_data
= mfree(c
->stdin_data
);
1174 c
->stdin_data_size
= 0;
1178 ssize_t l
= cunescape(rvalue
, 0, &unescaped
);
1180 log_syntax(unit
, LOG_WARNING
, filename
, line
, l
,
1181 "Failed to decode C escaped text '%s', ignoring: %m", rvalue
);
1185 r
= unit_full_printf_full(u
, unescaped
, EXEC_STDIN_DATA_MAX
, &resolved
);
1187 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1188 "Failed to resolve unit specifiers in '%s', ignoring: %m", unescaped
);
1192 size_t sz
= strlen(resolved
);
1193 if (c
->stdin_data_size
+ sz
+ 1 < c
->stdin_data_size
|| /* check for overflow */
1194 c
->stdin_data_size
+ sz
+ 1 > EXEC_STDIN_DATA_MAX
) {
1195 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
1196 "Standard input data too large (%zu), maximum of %zu permitted, ignoring.",
1197 c
->stdin_data_size
+ sz
, (size_t) EXEC_STDIN_DATA_MAX
);
1201 void *p
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
+ 1);
1205 *((char*) mempcpy((char*) p
+ c
->stdin_data_size
, resolved
, sz
)) = '\n';
1208 c
->stdin_data_size
+= sz
+ 1;
1213 int config_parse_exec_input_data(
1215 const char *filename
,
1217 const char *section
,
1218 unsigned section_line
,
1225 _cleanup_free_
void *p
= NULL
;
1226 ExecContext
*c
= data
;
1236 if (isempty(rvalue
)) {
1237 /* Reset if the empty string is assigned */
1238 c
->stdin_data
= mfree(c
->stdin_data
);
1239 c
->stdin_data_size
= 0;
1243 r
= unbase64mem(rvalue
, SIZE_MAX
, &p
, &sz
);
1245 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1246 "Failed to decode base64 data, ignoring: %s", rvalue
);
1252 if (c
->stdin_data_size
+ sz
< c
->stdin_data_size
|| /* check for overflow */
1253 c
->stdin_data_size
+ sz
> EXEC_STDIN_DATA_MAX
) {
1254 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
1255 "Standard input data too large (%zu), maximum of %zu permitted, ignoring.",
1256 c
->stdin_data_size
+ sz
, (size_t) EXEC_STDIN_DATA_MAX
);
1260 q
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
);
1264 memcpy((uint8_t*) q
+ c
->stdin_data_size
, p
, sz
);
1267 c
->stdin_data_size
+= sz
;
1272 int config_parse_exec_output(
1274 const char *filename
,
1276 const char *section
,
1277 unsigned section_line
,
1284 _cleanup_free_
char *resolved
= NULL
;
1286 ExecContext
*c
= data
;
1287 const Unit
*u
= userdata
;
1288 bool obsolete
= false;
1298 n
= startswith(rvalue
, "fd:");
1300 r
= unit_fd_printf(u
, n
, &resolved
);
1302 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", n
);
1306 if (isempty(resolved
))
1307 resolved
= mfree(resolved
);
1308 else if (!fdname_is_valid(resolved
)) {
1309 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", resolved
);
1313 eo
= EXEC_OUTPUT_NAMED_FD
;
1315 } else if (streq(rvalue
, "syslog")) {
1316 eo
= EXEC_OUTPUT_JOURNAL
;
1319 } else if (streq(rvalue
, "syslog+console")) {
1320 eo
= EXEC_OUTPUT_JOURNAL_AND_CONSOLE
;
1323 } else if ((n
= startswith(rvalue
, "file:"))) {
1325 r
= unit_path_printf(u
, n
, &resolved
);
1327 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", n
);
1331 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1335 eo
= EXEC_OUTPUT_FILE
;
1337 } else if ((n
= startswith(rvalue
, "append:"))) {
1339 r
= unit_path_printf(u
, n
, &resolved
);
1341 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", n
);
1345 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1349 eo
= EXEC_OUTPUT_FILE_APPEND
;
1351 } else if ((n
= startswith(rvalue
, "truncate:"))) {
1353 r
= unit_path_printf(u
, n
, &resolved
);
1355 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", n
);
1359 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1363 eo
= EXEC_OUTPUT_FILE_TRUNCATE
;
1365 eo
= exec_output_from_string(rvalue
);
1367 log_syntax(unit
, LOG_WARNING
, filename
, line
, eo
, "Failed to parse output specifier, ignoring: %s", rvalue
);
1373 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
1374 "Standard output type %s is obsolete, automatically updating to %s. Please update your unit file, and consider removing the setting altogether.",
1375 rvalue
, exec_output_to_string(eo
));
1377 if (streq(lvalue
, "StandardOutput")) {
1378 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1379 free_and_replace(c
->stdio_fdname
[STDOUT_FILENO
], resolved
);
1381 free_and_replace(c
->stdio_file
[STDOUT_FILENO
], resolved
);
1386 assert(streq(lvalue
, "StandardError"));
1388 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1389 free_and_replace(c
->stdio_fdname
[STDERR_FILENO
], resolved
);
1391 free_and_replace(c
->stdio_file
[STDERR_FILENO
], resolved
);
1399 int config_parse_exec_io_class(const char *unit
,
1400 const char *filename
,
1402 const char *section
,
1403 unsigned section_line
,
1410 ExecContext
*c
= data
;
1418 if (isempty(rvalue
)) {
1419 c
->ioprio_set
= false;
1420 c
->ioprio
= IOPRIO_DEFAULT_CLASS_AND_PRIO
;
1424 x
= ioprio_class_from_string(rvalue
);
1426 log_syntax(unit
, LOG_WARNING
, filename
, line
, x
, "Failed to parse IO scheduling class, ignoring: %s", rvalue
);
1430 c
->ioprio
= ioprio_normalize(ioprio_prio_value(x
, ioprio_prio_data(c
->ioprio
)));
1431 c
->ioprio_set
= true;
1436 int config_parse_exec_io_priority(const char *unit
,
1437 const char *filename
,
1439 const char *section
,
1440 unsigned section_line
,
1447 ExecContext
*c
= data
;
1455 if (isempty(rvalue
)) {
1456 c
->ioprio_set
= false;
1457 c
->ioprio
= IOPRIO_DEFAULT_CLASS_AND_PRIO
;
1461 r
= ioprio_parse_priority(rvalue
, &i
);
1463 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse IO priority, ignoring: %s", rvalue
);
1467 c
->ioprio
= ioprio_normalize(ioprio_prio_value(ioprio_prio_class(c
->ioprio
), i
));
1468 c
->ioprio_set
= true;
1473 int config_parse_exec_cpu_sched_policy(const char *unit
,
1474 const char *filename
,
1476 const char *section
,
1477 unsigned section_line
,
1484 ExecContext
*c
= data
;
1492 if (isempty(rvalue
)) {
1493 c
->cpu_sched_set
= false;
1494 c
->cpu_sched_policy
= SCHED_OTHER
;
1495 c
->cpu_sched_priority
= 0;
1499 x
= sched_policy_from_string(rvalue
);
1501 log_syntax(unit
, LOG_WARNING
, filename
, line
, x
, "Failed to parse CPU scheduling policy, ignoring: %s", rvalue
);
1505 c
->cpu_sched_policy
= x
;
1506 /* Moving to or from real-time policy? We need to adjust the priority */
1507 c
->cpu_sched_priority
= CLAMP(c
->cpu_sched_priority
, sched_get_priority_min(x
), sched_get_priority_max(x
));
1508 c
->cpu_sched_set
= true;
1513 int config_parse_exec_mount_apivfs(const char *unit
,
1514 const char *filename
,
1516 const char *section
,
1517 unsigned section_line
,
1524 ExecContext
*c
= data
;
1532 if (isempty(rvalue
)) {
1533 c
->mount_apivfs_set
= false;
1534 c
->mount_apivfs
= false;
1538 k
= parse_boolean(rvalue
);
1540 log_syntax(unit
, LOG_WARNING
, filename
, line
, k
,
1541 "Failed to parse boolean value, ignoring: %s",
1546 c
->mount_apivfs_set
= true;
1547 c
->mount_apivfs
= k
;
1551 int config_parse_numa_mask(const char *unit
,
1552 const char *filename
,
1554 const char *section
,
1555 unsigned section_line
,
1562 NUMAPolicy
*p
= data
;
1569 if (streq(rvalue
, "all")) {
1570 r
= numa_mask_add_all(&p
->nodes
);
1572 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1573 "Failed to create NUMA mask representing \"all\" NUMA nodes, ignoring: %m");
1575 r
= parse_cpu_set_extend(rvalue
, &p
->nodes
, true, unit
, filename
, line
, lvalue
);
1577 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse NUMA node mask, ignoring: %s", rvalue
);
1583 int config_parse_exec_cpu_sched_prio(const char *unit
,
1584 const char *filename
,
1586 const char *section
,
1587 unsigned section_line
,
1594 ExecContext
*c
= data
;
1602 r
= safe_atoi(rvalue
, &i
);
1604 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse CPU scheduling priority, ignoring: %s", rvalue
);
1608 /* On Linux RR/FIFO range from 1 to 99 and OTHER/BATCH may only be 0 */
1609 min
= sched_get_priority_min(c
->cpu_sched_policy
);
1610 max
= sched_get_priority_max(c
->cpu_sched_policy
);
1612 if (i
< min
|| i
> max
) {
1613 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "CPU scheduling priority is out of range, ignoring: %s", rvalue
);
1617 c
->cpu_sched_priority
= i
;
1618 c
->cpu_sched_set
= true;
1623 int config_parse_root_image_options(
1625 const char *filename
,
1627 const char *section
,
1628 unsigned section_line
,
1635 _cleanup_(mount_options_free_allp
) MountOptions
*options
= NULL
;
1636 _cleanup_strv_free_
char **l
= NULL
;
1637 ExecContext
*c
= data
;
1638 const Unit
*u
= userdata
;
1646 if (isempty(rvalue
)) {
1647 c
->root_image_options
= mount_options_free_all(c
->root_image_options
);
1651 r
= strv_split_colon_pairs(&l
, rvalue
);
1655 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
1659 STRV_FOREACH_PAIR(first
, second
, l
) {
1660 MountOptions
*o
= NULL
;
1661 _cleanup_free_
char *mount_options_resolved
= NULL
;
1662 const char *mount_options
= NULL
, *partition
= "root";
1663 PartitionDesignator partition_designator
;
1665 /* Format is either 'root:foo' or 'foo' (root is implied) */
1666 if (!isempty(*second
)) {
1668 mount_options
= *second
;
1670 mount_options
= *first
;
1672 partition_designator
= partition_designator_from_string(partition
);
1673 if (partition_designator
< 0) {
1674 log_syntax(unit
, LOG_WARNING
, filename
, line
, partition_designator
,
1675 "Invalid partition name %s, ignoring", partition
);
1678 r
= unit_full_printf(u
, mount_options
, &mount_options_resolved
);
1680 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", mount_options
);
1684 o
= new(MountOptions
, 1);
1687 *o
= (MountOptions
) {
1688 .partition_designator
= partition_designator
,
1689 .options
= TAKE_PTR(mount_options_resolved
),
1691 LIST_APPEND(mount_options
, options
, TAKE_PTR(o
));
1695 LIST_JOIN(mount_options
, c
->root_image_options
, options
);
1697 /* empty spaces/separators only */
1698 c
->root_image_options
= mount_options_free_all(c
->root_image_options
);
1703 int config_parse_exec_root_hash(
1705 const char *filename
,
1707 const char *section
,
1708 unsigned section_line
,
1715 _cleanup_free_
void *roothash_decoded
= NULL
;
1716 ExecContext
*c
= data
;
1717 size_t roothash_decoded_size
= 0;
1725 if (isempty(rvalue
)) {
1726 /* Reset if the empty string is assigned */
1727 c
->root_hash_path
= mfree(c
->root_hash_path
);
1728 c
->root_hash
= mfree(c
->root_hash
);
1729 c
->root_hash_size
= 0;
1733 if (path_is_absolute(rvalue
)) {
1734 /* We have the path to a roothash to load and decode, eg: RootHash=/foo/bar.roothash */
1735 _cleanup_free_
char *p
= NULL
;
1741 free_and_replace(c
->root_hash_path
, p
);
1742 c
->root_hash
= mfree(c
->root_hash
);
1743 c
->root_hash_size
= 0;
1747 /* We have a roothash to decode, eg: RootHash=012345789abcdef */
1748 r
= unhexmem(rvalue
, strlen(rvalue
), &roothash_decoded
, &roothash_decoded_size
);
1750 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to decode RootHash=, ignoring: %s", rvalue
);
1753 if (roothash_decoded_size
< sizeof(sd_id128_t
)) {
1754 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "RootHash= is too short, ignoring: %s", rvalue
);
1758 free_and_replace(c
->root_hash
, roothash_decoded
);
1759 c
->root_hash_size
= roothash_decoded_size
;
1760 c
->root_hash_path
= mfree(c
->root_hash_path
);
1765 int config_parse_exec_root_hash_sig(
1767 const char *filename
,
1769 const char *section
,
1770 unsigned section_line
,
1777 _cleanup_free_
void *roothash_sig_decoded
= NULL
;
1779 ExecContext
*c
= data
;
1780 size_t roothash_sig_decoded_size
= 0;
1788 if (isempty(rvalue
)) {
1789 /* Reset if the empty string is assigned */
1790 c
->root_hash_sig_path
= mfree(c
->root_hash_sig_path
);
1791 c
->root_hash_sig
= mfree(c
->root_hash_sig
);
1792 c
->root_hash_sig_size
= 0;
1796 if (path_is_absolute(rvalue
)) {
1797 /* We have the path to a roothash signature to load and decode, eg: RootHashSignature=/foo/bar.roothash.p7s */
1798 _cleanup_free_
char *p
= NULL
;
1804 free_and_replace(c
->root_hash_sig_path
, p
);
1805 c
->root_hash_sig
= mfree(c
->root_hash_sig
);
1806 c
->root_hash_sig_size
= 0;
1810 if (!(value
= startswith(rvalue
, "base64:"))) {
1811 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
1812 "Failed to decode RootHashSignature=, not a path but doesn't start with 'base64:', ignoring: %s", rvalue
);
1816 /* We have a roothash signature to decode, eg: RootHashSignature=base64:012345789abcdef */
1817 r
= unbase64mem(value
, strlen(value
), &roothash_sig_decoded
, &roothash_sig_decoded_size
);
1819 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to decode RootHashSignature=, ignoring: %s", rvalue
);
1823 free_and_replace(c
->root_hash_sig
, roothash_sig_decoded
);
1824 c
->root_hash_sig_size
= roothash_sig_decoded_size
;
1825 c
->root_hash_sig_path
= mfree(c
->root_hash_sig_path
);
1830 int config_parse_exec_cpu_affinity(
1832 const char *filename
,
1834 const char *section
,
1835 unsigned section_line
,
1842 ExecContext
*c
= data
;
1843 const Unit
*u
= userdata
;
1844 _cleanup_free_
char *k
= NULL
;
1852 if (streq(rvalue
, "numa")) {
1853 c
->cpu_affinity_from_numa
= true;
1854 cpu_set_reset(&c
->cpu_set
);
1859 r
= unit_full_printf(u
, rvalue
, &k
);
1861 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1862 "Failed to resolve unit specifiers in '%s', ignoring: %m",
1867 r
= parse_cpu_set_extend(k
, &c
->cpu_set
, true, unit
, filename
, line
, lvalue
);
1869 c
->cpu_affinity_from_numa
= false;
1874 int config_parse_capability_set(
1876 const char *filename
,
1878 const char *section
,
1879 unsigned section_line
,
1886 uint64_t *capability_set
= data
;
1887 uint64_t sum
= 0, initial
= 0;
1888 bool invert
= false;
1896 if (rvalue
[0] == '~') {
1901 if (streq(lvalue
, "CapabilityBoundingSet"))
1902 initial
= CAP_ALL
; /* initialized to all bits on */
1903 /* else "AmbientCapabilities" initialized to all bits off */
1905 r
= capability_set_from_string(rvalue
, &sum
);
1907 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= specifier '%s', ignoring: %m", lvalue
, rvalue
);
1911 if (sum
== 0 || *capability_set
== initial
)
1912 /* "", "~" or uninitialized data -> replace */
1913 *capability_set
= invert
? ~sum
: sum
;
1915 /* previous data -> merge */
1917 *capability_set
&= ~sum
;
1919 *capability_set
|= sum
;
1925 int config_parse_exec_selinux_context(
1927 const char *filename
,
1929 const char *section
,
1930 unsigned section_line
,
1937 ExecContext
*c
= data
;
1938 const Unit
*u
= userdata
;
1948 if (isempty(rvalue
)) {
1949 c
->selinux_context
= mfree(c
->selinux_context
);
1950 c
->selinux_context_ignore
= false;
1954 if (rvalue
[0] == '-') {
1960 r
= unit_full_printf(u
, rvalue
, &k
);
1962 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
1963 "Failed to resolve unit specifiers in '%s'%s: %m",
1964 rvalue
, ignore
? ", ignoring" : "");
1965 return ignore
? 0 : -ENOEXEC
;
1968 free_and_replace(c
->selinux_context
, k
);
1969 c
->selinux_context_ignore
= ignore
;
1974 int config_parse_exec_apparmor_profile(
1976 const char *filename
,
1978 const char *section
,
1979 unsigned section_line
,
1986 ExecContext
*c
= data
;
1987 const Unit
*u
= userdata
;
1997 if (isempty(rvalue
)) {
1998 c
->apparmor_profile
= mfree(c
->apparmor_profile
);
1999 c
->apparmor_profile_ignore
= false;
2003 if (rvalue
[0] == '-') {
2009 r
= unit_full_printf(u
, rvalue
, &k
);
2011 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
2012 "Failed to resolve unit specifiers in '%s'%s: %m",
2013 rvalue
, ignore
? ", ignoring" : "");
2014 return ignore
? 0 : -ENOEXEC
;
2017 free_and_replace(c
->apparmor_profile
, k
);
2018 c
->apparmor_profile_ignore
= ignore
;
2023 int config_parse_exec_smack_process_label(
2025 const char *filename
,
2027 const char *section
,
2028 unsigned section_line
,
2035 ExecContext
*c
= data
;
2036 const Unit
*u
= userdata
;
2046 if (isempty(rvalue
)) {
2047 c
->smack_process_label
= mfree(c
->smack_process_label
);
2048 c
->smack_process_label_ignore
= false;
2052 if (rvalue
[0] == '-') {
2058 r
= unit_full_printf(u
, rvalue
, &k
);
2060 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
2061 "Failed to resolve unit specifiers in '%s'%s: %m",
2062 rvalue
, ignore
? ", ignoring" : "");
2063 return ignore
? 0 : -ENOEXEC
;
2066 free_and_replace(c
->smack_process_label
, k
);
2067 c
->smack_process_label_ignore
= ignore
;
2072 int config_parse_timer(
2074 const char *filename
,
2076 const char *section
,
2077 unsigned section_line
,
2084 _cleanup_(calendar_spec_freep
) CalendarSpec
*c
= NULL
;
2085 _cleanup_free_
char *k
= NULL
;
2086 const Unit
*u
= userdata
;
2097 if (isempty(rvalue
)) {
2098 /* Empty assignment resets list */
2099 timer_free_values(t
);
2103 r
= unit_full_printf(u
, rvalue
, &k
);
2105 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2109 if (ltype
== TIMER_CALENDAR
) {
2110 r
= calendar_spec_from_string(k
, &c
);
2112 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse calendar specification, ignoring: %s", k
);
2116 r
= parse_sec(k
, &usec
);
2118 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse timer value, ignoring: %s", k
);
2123 v
= new(TimerValue
, 1);
2130 .calendar_spec
= TAKE_PTR(c
),
2133 LIST_PREPEND(value
, t
->values
, v
);
2138 int config_parse_trigger_unit(
2140 const char *filename
,
2142 const char *section
,
2143 unsigned section_line
,
2150 _cleanup_free_
char *p
= NULL
;
2160 if (UNIT_TRIGGER(u
)) {
2161 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Multiple units to trigger specified, ignoring: %s", rvalue
);
2165 r
= unit_name_printf(u
, rvalue
, &p
);
2167 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2171 type
= unit_name_to_type(p
);
2173 log_syntax(unit
, LOG_WARNING
, filename
, line
, type
, "Unit type not valid, ignoring: %s", rvalue
);
2176 if (unit_has_name(u
, p
)) {
2177 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Units cannot trigger themselves, ignoring: %s", rvalue
);
2181 r
= unit_add_two_dependencies_by_name(u
, UNIT_BEFORE
, UNIT_TRIGGERS
, p
, true, UNIT_DEPENDENCY_FILE
);
2183 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add trigger on %s, ignoring: %m", p
);
2190 int config_parse_path_spec(const char *unit
,
2191 const char *filename
,
2193 const char *section
,
2194 unsigned section_line
,
2204 _cleanup_free_
char *k
= NULL
;
2212 if (isempty(rvalue
)) {
2213 /* Empty assignment clears list */
2218 b
= path_type_from_string(lvalue
);
2220 log_syntax(unit
, LOG_WARNING
, filename
, line
, b
, "Failed to parse path type, ignoring: %s", lvalue
);
2224 r
= unit_path_printf(UNIT(p
), rvalue
, &k
);
2226 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2230 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2234 s
= new0(PathSpec
, 1);
2239 s
->path
= TAKE_PTR(k
);
2243 LIST_PREPEND(spec
, p
->specs
, s
);
2248 int config_parse_socket_service(
2250 const char *filename
,
2252 const char *section
,
2253 unsigned section_line
,
2260 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
2261 _cleanup_free_
char *p
= NULL
;
2271 r
= unit_name_printf(UNIT(s
), rvalue
, &p
);
2273 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2277 if (!endswith(p
, ".service")) {
2278 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Unit must be of type service, ignoring: %s", rvalue
);
2282 r
= manager_load_unit(UNIT(s
)->manager
, p
, NULL
, &error
, &x
);
2284 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to load unit %s, ignoring: %s", rvalue
, bus_error_message(&error
, r
));
2288 unit_ref_set(&s
->service
, UNIT(s
), x
);
2293 int config_parse_fdname(
2295 const char *filename
,
2297 const char *section
,
2298 unsigned section_line
,
2305 _cleanup_free_
char *p
= NULL
;
2314 if (isempty(rvalue
)) {
2315 s
->fdname
= mfree(s
->fdname
);
2319 r
= unit_fd_printf(UNIT(s
), rvalue
, &p
);
2321 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2325 if (!fdname_is_valid(p
)) {
2326 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", p
);
2330 return free_and_replace(s
->fdname
, p
);
2333 int config_parse_service_sockets(
2335 const char *filename
,
2337 const char *section
,
2338 unsigned section_line
,
2353 for (const char *p
= rvalue
;;) {
2354 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2356 r
= extract_first_word(&p
, &word
, NULL
, 0);
2360 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Trailing garbage in sockets, ignoring: %s", rvalue
);
2366 r
= unit_name_printf(UNIT(s
), word
, &k
);
2368 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
2372 if (!endswith(k
, ".socket")) {
2373 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Unit must be of type socket, ignoring: %s", k
);
2377 r
= unit_add_two_dependencies_by_name(UNIT(s
), UNIT_WANTS
, UNIT_AFTER
, k
, true, UNIT_DEPENDENCY_FILE
);
2379 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
2381 r
= unit_add_dependency_by_name(UNIT(s
), UNIT_TRIGGERED_BY
, k
, true, UNIT_DEPENDENCY_FILE
);
2383 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
2387 int config_parse_bus_name(
2389 const char *filename
,
2391 const char *section
,
2392 unsigned section_line
,
2399 _cleanup_free_
char *k
= NULL
;
2400 const Unit
*u
= userdata
;
2408 r
= unit_full_printf_full(u
, rvalue
, SD_BUS_MAXIMUM_NAME_LENGTH
, &k
);
2410 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2414 if (!sd_bus_service_name_is_valid(k
)) {
2415 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid bus name, ignoring: %s", k
);
2419 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
2422 int config_parse_service_timeout(
2424 const char *filename
,
2426 const char *section
,
2427 unsigned section_line
,
2434 Service
*s
= userdata
;
2443 /* This is called for two cases: TimeoutSec= and TimeoutStartSec=. */
2445 /* Traditionally, these options accepted 0 to disable the timeouts. However, a timeout of 0 suggests it happens
2446 * immediately, hence fix this to become USEC_INFINITY instead. This is in-line with how we internally handle
2447 * all other timeouts. */
2448 r
= parse_sec_fix_0(rvalue
, &usec
);
2450 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
2454 s
->start_timeout_defined
= true;
2455 s
->timeout_start_usec
= usec
;
2457 if (streq(lvalue
, "TimeoutSec"))
2458 s
->timeout_stop_usec
= usec
;
2463 int config_parse_timeout_abort(
2465 const char *filename
,
2467 const char *section
,
2468 unsigned section_line
,
2483 /* Note: apart from setting the arg, this returns an extra bit of information in the return value. */
2485 if (isempty(rvalue
)) {
2487 return 0; /* "not set" */
2490 r
= parse_sec(rvalue
, ret
);
2492 return log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= setting, ignoring: %s", lvalue
, rvalue
);
2494 return 1; /* "set" */
2497 int config_parse_service_timeout_abort(
2499 const char *filename
,
2501 const char *section
,
2502 unsigned section_line
,
2509 Service
*s
= userdata
;
2514 r
= config_parse_timeout_abort(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
,
2515 &s
->timeout_abort_usec
, s
);
2517 s
->timeout_abort_set
= r
;
2521 int config_parse_sec_fix_0(
2523 const char *filename
,
2525 const char *section
,
2526 unsigned section_line
,
2533 usec_t
*usec
= data
;
2541 /* This is pretty much like config_parse_sec(), except that this treats a time of 0 as infinity, for
2542 * compatibility with older versions of systemd where 0 instead of infinity was used as indicator to turn off a
2545 r
= parse_sec_fix_0(rvalue
, usec
);
2547 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
2552 int config_parse_user_group_compat(
2554 const char *filename
,
2556 const char *section
,
2557 unsigned section_line
,
2564 _cleanup_free_
char *k
= NULL
;
2566 const Unit
*u
= userdata
;
2574 if (isempty(rvalue
)) {
2575 *user
= mfree(*user
);
2579 r
= unit_full_printf(u
, rvalue
, &k
);
2581 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", rvalue
);
2585 if (!valid_user_group_name(k
, VALID_USER_ALLOW_NUMERIC
|VALID_USER_RELAX
|VALID_USER_WARN
)) {
2586 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2590 if (strstr(lvalue
, "User") && streq(k
, NOBODY_USER_NAME
))
2591 log_struct(LOG_NOTICE
,
2592 "MESSAGE=%s:%u: Special user %s configured, this is not safe!", filename
, line
, k
,
2594 "MESSAGE_ID=" SD_MESSAGE_NOBODY_USER_UNSUITABLE_STR
,
2595 "OFFENDING_USER=%s", k
,
2596 "CONFIG_FILE=%s", filename
,
2597 "CONFIG_LINE=%u", line
);
2599 return free_and_replace(*user
, k
);
2602 int config_parse_user_group_strv_compat(
2604 const char *filename
,
2606 const char *section
,
2607 unsigned section_line
,
2614 char ***users
= data
;
2615 const Unit
*u
= userdata
;
2623 if (isempty(rvalue
)) {
2624 *users
= strv_free(*users
);
2628 for (const char *p
= rvalue
;;) {
2629 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2631 r
= extract_first_word(&p
, &word
, NULL
, 0);
2635 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax: %s", rvalue
);
2641 r
= unit_full_printf(u
, word
, &k
);
2643 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", word
);
2647 if (!valid_user_group_name(k
, VALID_USER_ALLOW_NUMERIC
|VALID_USER_RELAX
|VALID_USER_WARN
)) {
2648 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2652 r
= strv_push(users
, k
);
2660 int config_parse_working_directory(
2662 const char *filename
,
2664 const char *section
,
2665 unsigned section_line
,
2672 ExecContext
*c
= data
;
2673 const Unit
*u
= userdata
;
2683 if (isempty(rvalue
)) {
2684 c
->working_directory_home
= false;
2685 c
->working_directory
= mfree(c
->working_directory
);
2689 if (rvalue
[0] == '-') {
2695 if (streq(rvalue
, "~")) {
2696 c
->working_directory_home
= true;
2697 c
->working_directory
= mfree(c
->working_directory
);
2699 _cleanup_free_
char *k
= NULL
;
2701 r
= unit_path_printf(u
, rvalue
, &k
);
2703 log_syntax(unit
, missing_ok
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
2704 "Failed to resolve unit specifiers in working directory path '%s'%s: %m",
2705 rvalue
, missing_ok
? ", ignoring" : "");
2706 return missing_ok
? 0 : -ENOEXEC
;
2709 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
| (missing_ok
? 0 : PATH_CHECK_FATAL
), unit
, filename
, line
, lvalue
);
2711 return missing_ok
? 0 : -ENOEXEC
;
2713 c
->working_directory_home
= false;
2714 free_and_replace(c
->working_directory
, k
);
2717 c
->working_directory_missing_ok
= missing_ok
;
2721 int config_parse_unit_env_file(const char *unit
,
2722 const char *filename
,
2724 const char *section
,
2725 unsigned section_line
,
2733 const Unit
*u
= userdata
;
2734 _cleanup_free_
char *n
= NULL
;
2742 if (isempty(rvalue
)) {
2743 /* Empty assignment frees the list */
2744 *env
= strv_free(*env
);
2748 r
= unit_full_printf_full(u
, rvalue
, PATH_MAX
, &n
);
2750 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2754 r
= path_simplify_and_warn(n
[0] == '-' ? n
+ 1 : n
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2758 r
= strv_push(env
, n
);
2767 int config_parse_environ(
2769 const char *filename
,
2771 const char *section
,
2772 unsigned section_line
,
2779 const Unit
*u
= userdata
;
2788 if (isempty(rvalue
)) {
2789 /* Empty assignment resets the list */
2790 *env
= strv_free(*env
);
2794 for (const char *p
= rvalue
;; ) {
2795 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
2797 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2801 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2802 "Invalid syntax, ignoring: %s", rvalue
);
2809 r
= unit_env_printf(u
, word
, &resolved
);
2811 r
= specifier_printf(word
, sc_arg_max(), system_and_tmp_specifier_table
, NULL
, NULL
, &resolved
);
2813 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2814 "Failed to resolve specifiers in %s, ignoring: %m", word
);
2818 if (!env_assignment_is_valid(resolved
)) {
2819 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
2820 "Invalid environment assignment, ignoring: %s", resolved
);
2824 r
= strv_env_replace_consume(env
, TAKE_PTR(resolved
));
2826 return log_error_errno(r
, "Failed to update environment: %m");
2830 int config_parse_pass_environ(
2832 const char *filename
,
2834 const char *section
,
2835 unsigned section_line
,
2842 _cleanup_strv_free_
char **n
= NULL
;
2843 const Unit
*u
= userdata
;
2844 char*** passenv
= data
;
2853 if (isempty(rvalue
)) {
2854 /* Empty assignment resets the list */
2855 *passenv
= strv_free(*passenv
);
2859 for (const char *p
= rvalue
;;) {
2860 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2862 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
2866 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2867 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2874 r
= unit_env_printf(u
, word
, &k
);
2876 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2877 "Failed to resolve specifiers in %s, ignoring: %m", word
);
2883 if (!env_name_is_valid(k
)) {
2884 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
2885 "Invalid environment name for %s, ignoring: %s", lvalue
, k
);
2889 if (!GREEDY_REALLOC(n
, nlen
+ 2))
2892 n
[nlen
++] = TAKE_PTR(k
);
2897 r
= strv_extend_strv(passenv
, n
, true);
2905 int config_parse_unset_environ(
2907 const char *filename
,
2909 const char *section
,
2910 unsigned section_line
,
2917 _cleanup_strv_free_
char **n
= NULL
;
2918 char*** unsetenv
= data
;
2919 const Unit
*u
= userdata
;
2928 if (isempty(rvalue
)) {
2929 /* Empty assignment resets the list */
2930 *unsetenv
= strv_free(*unsetenv
);
2934 for (const char *p
= rvalue
;;) {
2935 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2937 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2941 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2942 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2949 r
= unit_env_printf(u
, word
, &k
);
2951 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2952 "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2958 if (!env_assignment_is_valid(k
) && !env_name_is_valid(k
)) {
2959 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
2960 "Invalid environment name or assignment %s, ignoring: %s", lvalue
, k
);
2964 if (!GREEDY_REALLOC(n
, nlen
+ 2))
2967 n
[nlen
++] = TAKE_PTR(k
);
2972 r
= strv_extend_strv(unsetenv
, n
, true);
2980 int config_parse_log_extra_fields(
2982 const char *filename
,
2984 const char *section
,
2985 unsigned section_line
,
2992 ExecContext
*c
= data
;
2993 const Unit
*u
= userdata
;
3001 if (isempty(rvalue
)) {
3002 exec_context_free_log_extra_fields(c
);
3006 for (const char *p
= rvalue
;;) {
3007 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
3011 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
3015 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3021 r
= unit_full_printf(u
, word
, &k
);
3023 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
3027 eq
= strchr(k
, '=');
3029 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Log field lacks '=' character, ignoring: %s", k
);
3033 if (!journal_field_valid(k
, eq
-k
, false)) {
3034 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Log field name is invalid, ignoring: %s", k
);
3038 t
= reallocarray(c
->log_extra_fields
, c
->n_log_extra_fields
+1, sizeof(struct iovec
));
3042 c
->log_extra_fields
= t
;
3043 c
->log_extra_fields
[c
->n_log_extra_fields
++] = IOVEC_MAKE_STRING(k
);
3049 int config_parse_log_namespace(
3051 const char *filename
,
3053 const char *section
,
3054 unsigned section_line
,
3061 _cleanup_free_
char *k
= NULL
;
3062 ExecContext
*c
= data
;
3063 const Unit
*u
= userdata
;
3071 if (isempty(rvalue
)) {
3072 c
->log_namespace
= mfree(c
->log_namespace
);
3076 r
= unit_full_printf_full(u
, rvalue
, NAME_MAX
, &k
);
3078 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
3082 if (!log_namespace_name_valid(k
)) {
3083 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Specified log namespace name is not valid, ignoring: %s", k
);
3087 free_and_replace(c
->log_namespace
, k
);
3091 int config_parse_unit_condition_path(
3093 const char *filename
,
3095 const char *section
,
3096 unsigned section_line
,
3103 _cleanup_free_
char *p
= NULL
;
3104 Condition
**list
= data
, *c
;
3105 ConditionType t
= ltype
;
3106 bool trigger
, negate
;
3107 const Unit
*u
= userdata
;
3115 if (isempty(rvalue
)) {
3116 /* Empty assignment resets the list */
3117 *list
= condition_free_list(*list
);
3121 trigger
= rvalue
[0] == '|';
3125 negate
= rvalue
[0] == '!';
3129 r
= unit_path_printf(u
, rvalue
, &p
);
3131 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
3135 r
= path_simplify_and_warn(p
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
3139 c
= condition_new(t
, p
, trigger
, negate
);
3143 LIST_PREPEND(conditions
, *list
, c
);
3147 int config_parse_unit_condition_string(
3149 const char *filename
,
3151 const char *section
,
3152 unsigned section_line
,
3159 _cleanup_free_
char *s
= NULL
;
3160 Condition
**list
= data
, *c
;
3161 ConditionType t
= ltype
;
3162 bool trigger
, negate
;
3163 const Unit
*u
= userdata
;
3171 if (isempty(rvalue
)) {
3172 /* Empty assignment resets the list */
3173 *list
= condition_free_list(*list
);
3177 trigger
= *rvalue
== '|';
3179 rvalue
+= 1 + strspn(rvalue
+ 1, WHITESPACE
);
3181 negate
= *rvalue
== '!';
3183 rvalue
+= 1 + strspn(rvalue
+ 1, WHITESPACE
);
3185 r
= unit_full_printf(u
, rvalue
, &s
);
3187 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3188 "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
3192 c
= condition_new(t
, s
, trigger
, negate
);
3196 LIST_PREPEND(conditions
, *list
, c
);
3200 int config_parse_unit_requires_mounts_for(
3202 const char *filename
,
3204 const char *section
,
3205 unsigned section_line
,
3220 for (const char *p
= rvalue
;;) {
3221 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
3223 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3227 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3228 "Invalid syntax, ignoring: %s", rvalue
);
3234 r
= unit_path_printf(u
, word
, &resolved
);
3236 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
3240 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
3244 r
= unit_require_mounts_for(u
, resolved
, UNIT_DEPENDENCY_FILE
);
3246 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add required mount '%s', ignoring: %m", resolved
);
3252 int config_parse_documentation(
3254 const char *filename
,
3256 const char *section
,
3257 unsigned section_line
,
3273 if (isempty(rvalue
)) {
3274 /* Empty assignment resets the list */
3275 u
->documentation
= strv_free(u
->documentation
);
3279 r
= config_parse_unit_strv_printf(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
,
3280 rvalue
, data
, userdata
);
3284 for (a
= b
= u
->documentation
; a
&& *a
; a
++) {
3286 if (documentation_url_is_valid(*a
))
3289 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid URL, ignoring: %s", *a
);
3300 int config_parse_syscall_filter(
3302 const char *filename
,
3304 const char *section
,
3305 unsigned section_line
,
3312 ExecContext
*c
= data
;
3313 _unused_
const Unit
*u
= userdata
;
3314 bool invert
= false;
3322 if (isempty(rvalue
)) {
3323 /* Empty assignment resets the list */
3324 c
->syscall_filter
= hashmap_free(c
->syscall_filter
);
3325 c
->syscall_allow_list
= false;
3329 if (rvalue
[0] == '~') {
3334 if (!c
->syscall_filter
) {
3335 c
->syscall_filter
= hashmap_new(NULL
);
3336 if (!c
->syscall_filter
)
3340 /* Allow everything but the ones listed */
3341 c
->syscall_allow_list
= false;
3343 /* Allow nothing but the ones listed */
3344 c
->syscall_allow_list
= true;
3346 /* Accept default syscalls if we are on an allow_list */
3347 r
= seccomp_parse_syscall_filter(
3348 "@default", -1, c
->syscall_filter
,
3349 SECCOMP_PARSE_PERMISSIVE
|SECCOMP_PARSE_ALLOW_LIST
,
3357 for (const char *p
= rvalue
;;) {
3358 _cleanup_free_
char *word
= NULL
, *name
= NULL
;
3361 r
= extract_first_word(&p
, &word
, NULL
, 0);
3365 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3366 "Invalid syntax, ignoring: %s", rvalue
);
3372 r
= parse_syscall_and_errno(word
, &name
, &num
);
3374 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3375 "Failed to parse syscall:errno, ignoring: %s", word
);
3378 if (!invert
&& num
>= 0) {
3379 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3380 "Allow-listed system calls cannot take error number, ignoring: %s", word
);
3384 r
= seccomp_parse_syscall_filter(
3385 name
, num
, c
->syscall_filter
,
3386 SECCOMP_PARSE_LOG
|SECCOMP_PARSE_PERMISSIVE
|
3387 (invert
? SECCOMP_PARSE_INVERT
: 0)|
3388 (c
->syscall_allow_list
? SECCOMP_PARSE_ALLOW_LIST
: 0),
3389 unit
, filename
, line
);
3395 int config_parse_syscall_log(
3397 const char *filename
,
3399 const char *section
,
3400 unsigned section_line
,
3407 ExecContext
*c
= data
;
3408 _unused_
const Unit
*u
= userdata
;
3409 bool invert
= false;
3418 if (isempty(rvalue
)) {
3419 /* Empty assignment resets the list */
3420 c
->syscall_log
= hashmap_free(c
->syscall_log
);
3421 c
->syscall_log_allow_list
= false;
3425 if (rvalue
[0] == '~') {
3430 if (!c
->syscall_log
) {
3431 c
->syscall_log
= hashmap_new(NULL
);
3432 if (!c
->syscall_log
)
3436 /* Log everything but the ones listed */
3437 c
->syscall_log_allow_list
= false;
3439 /* Log nothing but the ones listed */
3440 c
->syscall_log_allow_list
= true;
3445 _cleanup_free_
char *word
= NULL
;
3447 r
= extract_first_word(&p
, &word
, NULL
, 0);
3451 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3457 r
= seccomp_parse_syscall_filter(
3458 word
, -1, c
->syscall_log
,
3459 SECCOMP_PARSE_LOG
|SECCOMP_PARSE_PERMISSIVE
|
3460 (invert
? SECCOMP_PARSE_INVERT
: 0)|
3461 (c
->syscall_log_allow_list
? SECCOMP_PARSE_ALLOW_LIST
: 0),
3462 unit
, filename
, line
);
3468 int config_parse_syscall_archs(
3470 const char *filename
,
3472 const char *section
,
3473 unsigned section_line
,
3483 if (isempty(rvalue
)) {
3484 *archs
= set_free(*archs
);
3488 for (const char *p
= rvalue
;;) {
3489 _cleanup_free_
char *word
= NULL
;
3492 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3496 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3497 "Invalid syntax, ignoring: %s", rvalue
);
3503 r
= seccomp_arch_from_string(word
, &a
);
3505 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3506 "Failed to parse system call architecture \"%s\", ignoring: %m", word
);
3510 r
= set_ensure_put(archs
, NULL
, UINT32_TO_PTR(a
+ 1));
3516 int config_parse_syscall_errno(
3518 const char *filename
,
3520 const char *section
,
3521 unsigned section_line
,
3528 ExecContext
*c
= data
;
3535 if (isempty(rvalue
) || streq(rvalue
, "kill")) {
3536 /* Empty assignment resets to KILL */
3537 c
->syscall_errno
= SECCOMP_ERROR_NUMBER_KILL
;
3541 e
= parse_errno(rvalue
);
3543 log_syntax(unit
, LOG_WARNING
, filename
, line
, e
, "Failed to parse error number, ignoring: %s", rvalue
);
3547 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid error number, ignoring: %s", rvalue
);
3551 c
->syscall_errno
= e
;
3555 int config_parse_address_families(
3557 const char *filename
,
3559 const char *section
,
3560 unsigned section_line
,
3567 ExecContext
*c
= data
;
3568 bool invert
= false;
3575 if (isempty(rvalue
)) {
3576 /* Empty assignment resets the list */
3577 c
->address_families
= set_free(c
->address_families
);
3578 c
->address_families_allow_list
= false;
3582 if (streq(rvalue
, "none")) {
3583 /* Forbid all address families. */
3584 c
->address_families
= set_free(c
->address_families
);
3585 c
->address_families_allow_list
= true;
3589 if (rvalue
[0] == '~') {
3594 if (!c
->address_families
) {
3595 c
->address_families
= set_new(NULL
);
3596 if (!c
->address_families
)
3599 c
->address_families_allow_list
= !invert
;
3602 for (const char *p
= rvalue
;;) {
3603 _cleanup_free_
char *word
= NULL
;
3606 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3610 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3611 "Invalid syntax, ignoring: %s", rvalue
);
3617 af
= af_from_name(word
);
3619 log_syntax(unit
, LOG_WARNING
, filename
, line
, af
,
3620 "Failed to parse address family, ignoring: %s", word
);
3624 /* If we previously wanted to forbid an address family and now
3625 * we want to allow it, then just remove it from the list.
3627 if (!invert
== c
->address_families_allow_list
) {
3628 r
= set_put(c
->address_families
, INT_TO_PTR(af
));
3632 set_remove(c
->address_families
, INT_TO_PTR(af
));
3636 int config_parse_restrict_namespaces(
3638 const char *filename
,
3640 const char *section
,
3641 unsigned section_line
,
3648 ExecContext
*c
= data
;
3649 unsigned long flags
;
3650 bool invert
= false;
3653 if (isempty(rvalue
)) {
3654 /* Reset to the default. */
3655 c
->restrict_namespaces
= NAMESPACE_FLAGS_INITIAL
;
3659 /* Boolean parameter ignores the previous settings */
3660 r
= parse_boolean(rvalue
);
3662 c
->restrict_namespaces
= 0;
3664 } else if (r
== 0) {
3665 c
->restrict_namespaces
= NAMESPACE_FLAGS_ALL
;
3669 if (rvalue
[0] == '~') {
3674 /* Not a boolean argument, in this case it's a list of namespace types. */
3675 r
= namespace_flags_from_string(rvalue
, &flags
);
3677 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse namespace type string, ignoring: %s", rvalue
);
3681 if (c
->restrict_namespaces
== NAMESPACE_FLAGS_INITIAL
)
3682 /* Initial assignment. Just set the value. */
3683 c
->restrict_namespaces
= invert
? (~flags
) & NAMESPACE_FLAGS_ALL
: flags
;
3685 /* Merge the value with the previous one. */
3686 SET_FLAG(c
->restrict_namespaces
, flags
, !invert
);
3692 int config_parse_restrict_filesystems(
3694 const char *filename
,
3696 const char *section
,
3697 unsigned section_line
,
3703 ExecContext
*c
= data
;
3704 bool invert
= false;
3712 if (isempty(rvalue
)) {
3713 /* Empty assignment resets the list */
3714 c
->restrict_filesystems
= set_free(c
->restrict_filesystems
);
3715 c
->restrict_filesystems_allow_list
= false;
3719 if (rvalue
[0] == '~') {
3724 if (!c
->restrict_filesystems
) {
3726 /* Allow everything but the ones listed */
3727 c
->restrict_filesystems_allow_list
= false;
3729 /* Allow nothing but the ones listed */
3730 c
->restrict_filesystems_allow_list
= true;
3733 for (const char *p
= rvalue
;;) {
3734 _cleanup_free_
char *word
= NULL
;
3736 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3742 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3743 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
3747 r
= lsm_bpf_parse_filesystem(
3749 &c
->restrict_filesystems
,
3750 FILESYSTEM_PARSE_LOG
|
3751 (invert
? FILESYSTEM_PARSE_INVERT
: 0)|
3752 (c
->restrict_filesystems_allow_list
? FILESYSTEM_PARSE_ALLOW_LIST
: 0),
3753 unit
, filename
, line
);
3762 int config_parse_unit_slice(
3764 const char *filename
,
3766 const char *section
,
3767 unsigned section_line
,
3774 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
3775 _cleanup_free_
char *k
= NULL
;
3776 Unit
*u
= userdata
, *slice
;
3784 r
= unit_name_printf(u
, rvalue
, &k
);
3786 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
3790 r
= manager_load_unit(u
->manager
, k
, NULL
, &error
, &slice
);
3792 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to load slice unit %s, ignoring: %s", k
, bus_error_message(&error
, r
));
3796 r
= unit_set_slice(u
, slice
);
3798 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to assign slice %s to unit %s, ignoring: %m", slice
->id
, u
->id
);
3805 int config_parse_cpu_quota(
3807 const char *filename
,
3809 const char *section
,
3810 unsigned section_line
,
3817 CGroupContext
*c
= data
;
3824 if (isempty(rvalue
)) {
3825 c
->cpu_quota_per_sec_usec
= USEC_INFINITY
;
3829 r
= parse_permyriad_unbounded(rvalue
);
3831 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid CPU quota '%s', ignoring.", rvalue
);
3835 c
->cpu_quota_per_sec_usec
= ((usec_t
) r
* USEC_PER_SEC
) / 10000U;
3839 int config_parse_allowed_cpuset(
3841 const char *filename
,
3843 const char *section
,
3844 unsigned section_line
,
3853 (void) parse_cpu_set_extend(rvalue
, c
, true, unit
, filename
, line
, lvalue
);
3857 int config_parse_memory_limit(
3859 const char *filename
,
3861 const char *section
,
3862 unsigned section_line
,
3869 CGroupContext
*c
= data
;
3870 uint64_t bytes
= CGROUP_LIMIT_MAX
;
3873 if (isempty(rvalue
) && STR_IN_SET(lvalue
, "DefaultMemoryLow",
3877 bytes
= CGROUP_LIMIT_MIN
;
3878 else if (!isempty(rvalue
) && !streq(rvalue
, "infinity")) {
3880 r
= parse_permyriad(rvalue
);
3882 r
= parse_size(rvalue
, 1024, &bytes
);
3884 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid memory limit '%s', ignoring: %m", rvalue
);
3888 bytes
= physical_memory_scale(r
, 10000U);
3890 if (bytes
>= UINT64_MAX
||
3891 (bytes
<= 0 && !STR_IN_SET(lvalue
, "MemorySwapMax", "MemoryLow", "MemoryMin", "DefaultMemoryLow", "DefaultMemoryMin"))) {
3892 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Memory limit '%s' out of range, ignoring.", rvalue
);
3897 if (streq(lvalue
, "DefaultMemoryLow")) {
3898 c
->default_memory_low
= bytes
;
3899 c
->default_memory_low_set
= true;
3900 } else if (streq(lvalue
, "DefaultMemoryMin")) {
3901 c
->default_memory_min
= bytes
;
3902 c
->default_memory_min_set
= true;
3903 } else if (streq(lvalue
, "MemoryMin")) {
3904 c
->memory_min
= bytes
;
3905 c
->memory_min_set
= true;
3906 } else if (streq(lvalue
, "MemoryLow")) {
3907 c
->memory_low
= bytes
;
3908 c
->memory_low_set
= true;
3909 } else if (streq(lvalue
, "MemoryHigh"))
3910 c
->memory_high
= bytes
;
3911 else if (streq(lvalue
, "MemoryMax"))
3912 c
->memory_max
= bytes
;
3913 else if (streq(lvalue
, "MemorySwapMax"))
3914 c
->memory_swap_max
= bytes
;
3915 else if (streq(lvalue
, "MemoryLimit"))
3916 c
->memory_limit
= bytes
;
3923 int config_parse_tasks_max(
3925 const char *filename
,
3927 const char *section
,
3928 unsigned section_line
,
3935 const Unit
*u
= userdata
;
3936 TasksMax
*tasks_max
= data
;
3940 if (isempty(rvalue
)) {
3941 *tasks_max
= u
? u
->manager
->default_tasks_max
: TASKS_MAX_UNSET
;
3945 if (streq(rvalue
, "infinity")) {
3946 *tasks_max
= TASKS_MAX_UNSET
;
3950 r
= parse_permyriad(rvalue
);
3952 *tasks_max
= (TasksMax
) { r
, 10000U }; /* r‱ */
3954 r
= safe_atou64(rvalue
, &v
);
3956 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid maximum tasks value '%s', ignoring: %m", rvalue
);
3960 if (v
<= 0 || v
>= UINT64_MAX
) {
3961 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Maximum tasks value '%s' out of range, ignoring.", rvalue
);
3965 *tasks_max
= (TasksMax
) { v
};
3971 int config_parse_delegate(
3973 const char *filename
,
3975 const char *section
,
3976 unsigned section_line
,
3983 CGroupContext
*c
= data
;
3987 t
= unit_name_to_type(unit
);
3988 assert(t
!= _UNIT_TYPE_INVALID
);
3990 if (!unit_vtable
[t
]->can_delegate
) {
3991 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Delegate= setting not supported for this unit type, ignoring.");
3995 /* We either accept a boolean value, which may be used to turn on delegation for all controllers, or turn it
3996 * off for all. Or it takes a list of controller names, in which case we add the specified controllers to the
3997 * mask to delegate. */
3999 if (isempty(rvalue
)) {
4000 /* An empty string resets controllers and set Delegate=yes. */
4002 c
->delegate_controllers
= 0;
4006 r
= parse_boolean(rvalue
);
4008 CGroupMask mask
= 0;
4010 for (const char *p
= rvalue
;;) {
4011 _cleanup_free_
char *word
= NULL
;
4012 CGroupController cc
;
4014 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
4018 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
4024 cc
= cgroup_controller_from_string(word
);
4026 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid controller name '%s', ignoring", word
);
4030 mask
|= CGROUP_CONTROLLER_TO_MASK(cc
);
4034 c
->delegate_controllers
|= mask
;
4038 c
->delegate_controllers
= _CGROUP_MASK_ALL
;
4040 c
->delegate
= false;
4041 c
->delegate_controllers
= 0;
4047 int config_parse_managed_oom_mode(
4049 const char *filename
,
4051 const char *section
,
4052 unsigned section_line
,
4059 ManagedOOMMode
*mode
= data
, m
;
4062 t
= unit_name_to_type(unit
);
4063 assert(t
!= _UNIT_TYPE_INVALID
);
4065 if (!unit_vtable
[t
]->can_set_managed_oom
)
4066 return log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "%s= is not supported for this unit type, ignoring.", lvalue
);
4068 if (isempty(rvalue
)) {
4069 *mode
= MANAGED_OOM_AUTO
;
4073 m
= managed_oom_mode_from_string(rvalue
);
4075 log_syntax(unit
, LOG_WARNING
, filename
, line
, m
, "Invalid syntax, ignoring: %s", rvalue
);
4083 int config_parse_managed_oom_mem_pressure_limit(
4085 const char *filename
,
4087 const char *section
,
4088 unsigned section_line
,
4095 uint32_t *limit
= data
;
4099 t
= unit_name_to_type(unit
);
4100 assert(t
!= _UNIT_TYPE_INVALID
);
4102 if (!unit_vtable
[t
]->can_set_managed_oom
)
4103 return log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "%s= is not supported for this unit type, ignoring.", lvalue
);
4105 if (isempty(rvalue
)) {
4110 r
= parse_permyriad(rvalue
);
4112 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse memory pressure limit value, ignoring: %s", rvalue
);
4116 /* Normalize to 2^32-1 == 100% */
4117 *limit
= UINT32_SCALE_FROM_PERMYRIAD(r
);
4121 int config_parse_device_allow(
4123 const char *filename
,
4125 const char *section
,
4126 unsigned section_line
,
4133 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4134 CGroupContext
*c
= data
;
4135 const char *p
= rvalue
;
4138 if (isempty(rvalue
)) {
4139 while (c
->device_allow
)
4140 cgroup_context_free_device_allow(c
, c
->device_allow
);
4145 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4149 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4150 "Failed to extract device path and rights from '%s', ignoring.", rvalue
);
4154 r
= unit_path_printf(userdata
, path
, &resolved
);
4156 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4157 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4161 if (!STARTSWITH_SET(resolved
, "block-", "char-")) {
4163 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4167 if (!valid_device_node_path(resolved
)) {
4168 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid device node path '%s', ignoring.", resolved
);
4173 if (!isempty(p
) && !in_charset(p
, "rwm")) {
4174 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid device rights '%s', ignoring.", p
);
4178 return cgroup_add_device_allow(c
, resolved
, p
);
4181 int config_parse_io_device_weight(
4183 const char *filename
,
4185 const char *section
,
4186 unsigned section_line
,
4193 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4194 CGroupIODeviceWeight
*w
;
4195 CGroupContext
*c
= data
;
4196 const char *p
= rvalue
;
4204 if (isempty(rvalue
)) {
4205 while (c
->io_device_weights
)
4206 cgroup_context_free_io_device_weight(c
, c
->io_device_weights
);
4211 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4215 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4216 "Failed to extract device path and weight from '%s', ignoring.", rvalue
);
4219 if (r
== 0 || isempty(p
)) {
4220 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4221 "Invalid device path or weight specified in '%s', ignoring.", rvalue
);
4225 r
= unit_path_printf(userdata
, path
, &resolved
);
4227 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4228 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4232 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4236 r
= cg_weight_parse(p
, &u
);
4238 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "IO weight '%s' invalid, ignoring: %m", p
);
4242 assert(u
!= CGROUP_WEIGHT_INVALID
);
4244 w
= new0(CGroupIODeviceWeight
, 1);
4248 w
->path
= TAKE_PTR(resolved
);
4251 LIST_PREPEND(device_weights
, c
->io_device_weights
, w
);
4255 int config_parse_io_device_latency(
4257 const char *filename
,
4259 const char *section
,
4260 unsigned section_line
,
4267 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4268 CGroupIODeviceLatency
*l
;
4269 CGroupContext
*c
= data
;
4270 const char *p
= rvalue
;
4278 if (isempty(rvalue
)) {
4279 while (c
->io_device_latencies
)
4280 cgroup_context_free_io_device_latency(c
, c
->io_device_latencies
);
4285 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4289 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4290 "Failed to extract device path and latency from '%s', ignoring.", rvalue
);
4293 if (r
== 0 || isempty(p
)) {
4294 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4295 "Invalid device path or latency specified in '%s', ignoring.", rvalue
);
4299 r
= unit_path_printf(userdata
, path
, &resolved
);
4301 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4302 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4306 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4310 r
= parse_sec(p
, &usec
);
4312 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse timer value, ignoring: %s", p
);
4316 l
= new0(CGroupIODeviceLatency
, 1);
4320 l
->path
= TAKE_PTR(resolved
);
4321 l
->target_usec
= usec
;
4323 LIST_PREPEND(device_latencies
, c
->io_device_latencies
, l
);
4327 int config_parse_io_limit(
4329 const char *filename
,
4331 const char *section
,
4332 unsigned section_line
,
4339 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4340 CGroupIODeviceLimit
*l
= NULL
;
4341 CGroupContext
*c
= data
;
4342 CGroupIOLimitType type
;
4343 const char *p
= rvalue
;
4351 type
= cgroup_io_limit_type_from_string(lvalue
);
4354 if (isempty(rvalue
)) {
4355 LIST_FOREACH(device_limits
, t
, c
->io_device_limits
)
4356 t
->limits
[type
] = cgroup_io_limit_defaults
[type
];
4360 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4364 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4365 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
4368 if (r
== 0 || isempty(p
)) {
4369 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4370 "Invalid device node or bandwidth specified in '%s', ignoring.", rvalue
);
4374 r
= unit_path_printf(userdata
, path
, &resolved
);
4376 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4377 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4381 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4385 if (streq("infinity", p
))
4386 num
= CGROUP_LIMIT_MAX
;
4388 r
= parse_size(p
, 1000, &num
);
4389 if (r
< 0 || num
<= 0) {
4390 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid IO limit '%s', ignoring.", p
);
4395 LIST_FOREACH(device_limits
, t
, c
->io_device_limits
)
4396 if (path_equal(resolved
, t
->path
)) {
4402 CGroupIOLimitType ttype
;
4404 l
= new0(CGroupIODeviceLimit
, 1);
4408 l
->path
= TAKE_PTR(resolved
);
4409 for (ttype
= 0; ttype
< _CGROUP_IO_LIMIT_TYPE_MAX
; ttype
++)
4410 l
->limits
[ttype
] = cgroup_io_limit_defaults
[ttype
];
4412 LIST_PREPEND(device_limits
, c
->io_device_limits
, l
);
4415 l
->limits
[type
] = num
;
4420 int config_parse_blockio_device_weight(
4422 const char *filename
,
4424 const char *section
,
4425 unsigned section_line
,
4432 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4433 CGroupBlockIODeviceWeight
*w
;
4434 CGroupContext
*c
= data
;
4435 const char *p
= rvalue
;
4443 if (isempty(rvalue
)) {
4444 while (c
->blockio_device_weights
)
4445 cgroup_context_free_blockio_device_weight(c
, c
->blockio_device_weights
);
4450 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4454 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4455 "Failed to extract device node and weight from '%s', ignoring.", rvalue
);
4458 if (r
== 0 || isempty(p
)) {
4459 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4460 "Invalid device node or weight specified in '%s', ignoring.", rvalue
);
4464 r
= unit_path_printf(userdata
, path
, &resolved
);
4466 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4467 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4471 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4475 r
= cg_blkio_weight_parse(p
, &u
);
4477 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid block IO weight '%s', ignoring: %m", p
);
4481 assert(u
!= CGROUP_BLKIO_WEIGHT_INVALID
);
4483 w
= new0(CGroupBlockIODeviceWeight
, 1);
4487 w
->path
= TAKE_PTR(resolved
);
4490 LIST_PREPEND(device_weights
, c
->blockio_device_weights
, w
);
4494 int config_parse_blockio_bandwidth(
4496 const char *filename
,
4498 const char *section
,
4499 unsigned section_line
,
4506 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4507 CGroupBlockIODeviceBandwidth
*b
= NULL
;
4508 CGroupContext
*c
= data
;
4509 const char *p
= rvalue
;
4518 read
= streq("BlockIOReadBandwidth", lvalue
);
4520 if (isempty(rvalue
)) {
4521 LIST_FOREACH(device_bandwidths
, t
, c
->blockio_device_bandwidths
) {
4522 t
->rbps
= CGROUP_LIMIT_MAX
;
4523 t
->wbps
= CGROUP_LIMIT_MAX
;
4528 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4532 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4533 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
4536 if (r
== 0 || isempty(p
)) {
4537 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4538 "Invalid device node or bandwidth specified in '%s', ignoring.", rvalue
);
4542 r
= unit_path_printf(userdata
, path
, &resolved
);
4544 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4545 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4549 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4553 r
= parse_size(p
, 1000, &bytes
);
4554 if (r
< 0 || bytes
<= 0) {
4555 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid Block IO Bandwidth '%s', ignoring.", p
);
4559 LIST_FOREACH(device_bandwidths
, t
, c
->blockio_device_bandwidths
)
4560 if (path_equal(resolved
, t
->path
)) {
4566 b
= new0(CGroupBlockIODeviceBandwidth
, 1);
4570 b
->path
= TAKE_PTR(resolved
);
4571 b
->rbps
= CGROUP_LIMIT_MAX
;
4572 b
->wbps
= CGROUP_LIMIT_MAX
;
4574 LIST_PREPEND(device_bandwidths
, c
->blockio_device_bandwidths
, b
);
4585 int config_parse_job_mode_isolate(
4587 const char *filename
,
4589 const char *section
,
4590 unsigned section_line
,
4604 r
= parse_boolean(rvalue
);
4606 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse boolean, ignoring: %s", rvalue
);
4610 log_notice("%s is deprecated. Please use OnFailureJobMode= instead", lvalue
);
4612 *m
= r
? JOB_ISOLATE
: JOB_REPLACE
;
4616 int config_parse_exec_directories(
4618 const char *filename
,
4620 const char *section
,
4621 unsigned section_line
,
4628 ExecDirectory
*ed
= data
;
4629 const Unit
*u
= userdata
;
4637 if (isempty(rvalue
)) {
4638 /* Empty assignment resets the list */
4639 exec_directory_done(ed
);
4643 for (const char *p
= rvalue
;;) {
4644 _cleanup_free_
char *tuple
= NULL
;
4646 r
= extract_first_word(&p
, &tuple
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_RETAIN_ESCAPE
);
4650 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4651 "Invalid syntax %s=%s, ignoring: %m", lvalue
, rvalue
);
4657 _cleanup_free_
char *src
= NULL
, *dest
= NULL
;
4658 const char *q
= tuple
;
4659 r
= extract_many_words(&q
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
, &src
, &dest
, NULL
);
4663 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
?: SYNTHETIC_ERRNO(EINVAL
),
4664 "Invalid syntax in %s=, ignoring: %s", lvalue
, tuple
);
4668 _cleanup_free_
char *sresolved
= NULL
;
4669 r
= unit_path_printf(u
, src
, &sresolved
);
4671 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4672 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", src
);
4676 r
= path_simplify_and_warn(sresolved
, PATH_CHECK_RELATIVE
, unit
, filename
, line
, lvalue
);
4680 if (path_startswith(sresolved
, "private")) {
4681 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4682 "%s= path can't be 'private', ignoring assignment: %s", lvalue
, tuple
);
4686 /* For State and Runtime directories we support an optional destination parameter, which
4687 * will be used to create a symlink to the source. */
4688 _cleanup_strv_free_
char **symlinks
= NULL
;
4689 if (!isempty(dest
)) {
4690 _cleanup_free_
char *dresolved
= NULL
;
4692 if (streq(lvalue
, "ConfigurationDirectory")) {
4693 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4694 "Destination parameter is not supported for ConfigurationDirectory, ignoring: %s", tuple
);
4698 r
= unit_path_printf(u
, dest
, &dresolved
);
4700 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4701 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", dest
);
4705 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_RELATIVE
, unit
, filename
, line
, lvalue
);
4709 r
= strv_consume(&symlinks
, TAKE_PTR(dresolved
));
4714 r
= exec_directory_add(&ed
->items
, &ed
->n_items
, sresolved
, symlinks
);
4720 int config_parse_set_credential(
4722 const char *filename
,
4724 const char *section
,
4725 unsigned section_line
,
4732 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
4733 _cleanup_free_
void *d
= NULL
;
4734 ExecContext
*context
= data
;
4735 ExecSetCredential
*old
;
4737 bool encrypted
= ltype
;
4738 const char *p
= rvalue
;
4747 if (isempty(rvalue
)) {
4748 /* Empty assignment resets the list */
4749 context
->set_credentials
= hashmap_free(context
->set_credentials
);
4753 r
= extract_first_word(&p
, &word
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4757 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract credential name, ignoring: %s", rvalue
);
4760 if (r
== 0 || isempty(p
)) {
4761 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid syntax, ignoring: %s", rvalue
);
4765 r
= unit_cred_printf(u
, word
, &k
);
4767 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
4770 if (!credential_name_valid(k
)) {
4771 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Credential name \"%s\" not valid, ignoring.", k
);
4776 r
= unbase64mem_full(p
, SIZE_MAX
, true, &d
, &size
);
4778 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Encrypted credential data not valid Base64 data, ignoring.");
4785 /* We support escape codes here, so that users can insert trailing \n if they like */
4786 l
= cunescape(p
, UNESCAPE_ACCEPT_NUL
, &unescaped
);
4788 log_syntax(unit
, LOG_WARNING
, filename
, line
, l
, "Can't unescape \"%s\", ignoring: %m", p
);
4796 old
= hashmap_get(context
->set_credentials
, k
);
4798 free_and_replace(old
->data
, d
);
4800 old
->encrypted
= encrypted
;
4802 _cleanup_(exec_set_credential_freep
) ExecSetCredential
*sc
= NULL
;
4804 sc
= new(ExecSetCredential
, 1);
4808 *sc
= (ExecSetCredential
) {
4810 .data
= TAKE_PTR(d
),
4812 .encrypted
= encrypted
,
4815 r
= hashmap_ensure_put(&context
->set_credentials
, &exec_set_credential_hash_ops
, sc
->id
, sc
);
4819 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4820 "Duplicated credential value '%s', ignoring assignment: %s", sc
->id
, rvalue
);
4830 int config_parse_load_credential(
4832 const char *filename
,
4834 const char *section
,
4835 unsigned section_line
,
4842 _cleanup_free_
char *word
= NULL
, *k
= NULL
, *q
= NULL
;
4843 ExecContext
*context
= data
;
4844 ExecLoadCredential
*old
;
4845 bool encrypted
= ltype
;
4855 if (isempty(rvalue
)) {
4856 /* Empty assignment resets the list */
4857 context
->load_credentials
= hashmap_free(context
->load_credentials
);
4862 r
= extract_first_word(&p
, &word
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4866 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
4870 r
= unit_cred_printf(u
, word
, &k
);
4872 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
4875 if (!credential_name_valid(k
)) {
4876 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Credential name \"%s\" not valid, ignoring.", k
);
4881 /* If only one field is specified take it as shortcut for inheriting a credential named
4882 * the same way from our parent */
4887 r
= unit_path_printf(u
, p
, &q
);
4889 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", p
);
4892 if (path_is_absolute(q
) ? !path_is_normalized(q
) : !credential_name_valid(q
)) {
4893 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Credential source \"%s\" not valid, ignoring.", q
);
4898 old
= hashmap_get(context
->load_credentials
, k
);
4900 free_and_replace(old
->path
, q
);
4901 old
->encrypted
= encrypted
;
4903 _cleanup_(exec_load_credential_freep
) ExecLoadCredential
*lc
= NULL
;
4905 lc
= new(ExecLoadCredential
, 1);
4909 *lc
= (ExecLoadCredential
) {
4911 .path
= TAKE_PTR(q
),
4912 .encrypted
= encrypted
,
4915 r
= hashmap_ensure_put(&context
->load_credentials
, &exec_load_credential_hash_ops
, lc
->id
, lc
);
4919 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4920 "Duplicated credential value '%s', ignoring assignment: %s", lc
->id
, rvalue
);
4930 int config_parse_set_status(
4932 const char *filename
,
4934 const char *section
,
4935 unsigned section_line
,
4942 ExitStatusSet
*status_set
= data
;
4950 /* Empty assignment resets the list */
4951 if (isempty(rvalue
)) {
4952 exit_status_set_free(status_set
);
4956 for (const char *p
= rvalue
;;) {
4957 _cleanup_free_
char *word
= NULL
;
4960 r
= extract_first_word(&p
, &word
, NULL
, 0);
4964 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4965 "Failed to parse %s=%s, ignoring: %m", lvalue
, rvalue
);
4971 /* We need to call exit_status_from_string() first, because we want
4972 * to parse numbers as exit statuses, not signals. */
4974 r
= exit_status_from_string(word
);
4976 assert(r
>= 0 && r
< 256);
4977 bitmap
= &status_set
->status
;
4979 r
= signal_from_string(word
);
4981 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4982 "Failed to parse value, ignoring: %s", word
);
4985 bitmap
= &status_set
->signal
;
4988 r
= bitmap_set(bitmap
, r
);
4990 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4991 "Failed to set signal or status %s, ignoring: %m", word
);
4995 int config_parse_namespace_path_strv(
4997 const char *filename
,
4999 const char *section
,
5000 unsigned section_line
,
5007 const Unit
*u
= userdata
;
5016 if (isempty(rvalue
)) {
5017 /* Empty assignment resets the list */
5018 *sv
= strv_free(*sv
);
5022 for (const char *p
= rvalue
;;) {
5023 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
, *joined
= NULL
;
5025 bool ignore_enoent
= false, shall_prefix
= false;
5027 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
5031 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
5038 if (startswith(w
, "-")) {
5039 ignore_enoent
= true;
5042 if (startswith(w
, "+")) {
5043 shall_prefix
= true;
5047 r
= unit_path_printf(u
, w
, &resolved
);
5049 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", w
);
5053 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5057 joined
= strjoin(ignore_enoent
? "-" : "",
5058 shall_prefix
? "+" : "",
5061 r
= strv_push(sv
, joined
);
5071 int config_parse_temporary_filesystems(
5073 const char *filename
,
5075 const char *section
,
5076 unsigned section_line
,
5083 const Unit
*u
= userdata
;
5084 ExecContext
*c
= data
;
5092 if (isempty(rvalue
)) {
5093 /* Empty assignment resets the list */
5094 temporary_filesystem_free_many(c
->temporary_filesystems
, c
->n_temporary_filesystems
);
5095 c
->temporary_filesystems
= NULL
;
5096 c
->n_temporary_filesystems
= 0;
5100 for (const char *p
= rvalue
;;) {
5101 _cleanup_free_
char *word
= NULL
, *path
= NULL
, *resolved
= NULL
;
5104 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
5108 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
5115 r
= extract_first_word(&w
, &path
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
5119 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", word
);
5123 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid syntax, ignoring: %s", word
);
5127 r
= unit_path_printf(u
, path
, &resolved
);
5129 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", path
);
5133 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5137 r
= temporary_filesystem_add(&c
->temporary_filesystems
, &c
->n_temporary_filesystems
, resolved
, w
);
5143 int config_parse_bind_paths(
5145 const char *filename
,
5147 const char *section
,
5148 unsigned section_line
,
5155 ExecContext
*c
= data
;
5156 const Unit
*u
= userdata
;
5164 if (isempty(rvalue
)) {
5165 /* Empty assignment resets the list */
5166 bind_mount_free_many(c
->bind_mounts
, c
->n_bind_mounts
);
5167 c
->bind_mounts
= NULL
;
5168 c
->n_bind_mounts
= 0;
5172 for (const char *p
= rvalue
;;) {
5173 _cleanup_free_
char *source
= NULL
, *destination
= NULL
;
5174 _cleanup_free_
char *sresolved
= NULL
, *dresolved
= NULL
;
5175 char *s
= NULL
, *d
= NULL
;
5176 bool rbind
= true, ignore_enoent
= false;
5178 r
= extract_first_word(&p
, &source
, ":" WHITESPACE
, EXTRACT_UNQUOTE
|EXTRACT_DONT_COALESCE_SEPARATORS
);
5182 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
5188 r
= unit_full_printf_full(u
, source
, PATH_MAX
, &sresolved
);
5190 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5191 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", source
);
5197 ignore_enoent
= true;
5201 r
= path_simplify_and_warn(s
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5205 /* Optionally, the destination is specified. */
5206 if (p
&& p
[-1] == ':') {
5207 r
= extract_first_word(&p
, &destination
, ":" WHITESPACE
, EXTRACT_UNQUOTE
|EXTRACT_DONT_COALESCE_SEPARATORS
);
5211 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
5215 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Missing argument after ':', ignoring: %s", s
);
5219 r
= unit_path_printf(u
, destination
, &dresolved
);
5221 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5222 "Failed to resolve specifiers in \"%s\", ignoring: %m", destination
);
5226 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5232 /* Optionally, there's also a short option string specified */
5233 if (p
&& p
[-1] == ':') {
5234 _cleanup_free_
char *options
= NULL
;
5236 r
= extract_first_word(&p
, &options
, NULL
, EXTRACT_UNQUOTE
);
5240 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s=, ignoring: %s", lvalue
, rvalue
);
5244 if (isempty(options
) || streq(options
, "rbind"))
5246 else if (streq(options
, "norbind"))
5249 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid option string, ignoring setting: %s", options
);
5256 r
= bind_mount_add(&c
->bind_mounts
, &c
->n_bind_mounts
,
5260 .read_only
= !!strstr(lvalue
, "ReadOnly"),
5262 .ignore_enoent
= ignore_enoent
,
5271 int config_parse_mount_images(
5273 const char *filename
,
5275 const char *section
,
5276 unsigned section_line
,
5283 ExecContext
*c
= data
;
5284 const Unit
*u
= userdata
;
5292 if (isempty(rvalue
)) {
5293 /* Empty assignment resets the list */
5294 c
->mount_images
= mount_image_free_many(c
->mount_images
, &c
->n_mount_images
);
5298 for (const char *p
= rvalue
;;) {
5299 _cleanup_(mount_options_free_allp
) MountOptions
*options
= NULL
;
5300 _cleanup_free_
char *first
= NULL
, *second
= NULL
, *tuple
= NULL
;
5301 _cleanup_free_
char *sresolved
= NULL
, *dresolved
= NULL
;
5302 const char *q
= NULL
;
5304 bool permissive
= false;
5306 r
= extract_first_word(&p
, &tuple
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_RETAIN_ESCAPE
);
5310 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5311 "Invalid syntax %s=%s, ignoring: %m", lvalue
, rvalue
);
5318 r
= extract_many_words(&q
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
, &first
, &second
, NULL
);
5322 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5323 "Invalid syntax in %s=, ignoring: %s", lvalue
, tuple
);
5335 r
= unit_path_printf(u
, s
, &sresolved
);
5337 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5338 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", s
);
5342 r
= path_simplify_and_warn(sresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5346 if (isempty(second
)) {
5347 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Missing destination in %s, ignoring: %s", lvalue
, rvalue
);
5351 r
= unit_path_printf(u
, second
, &dresolved
);
5353 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5354 "Failed to resolve specifiers in \"%s\", ignoring: %m", second
);
5358 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5363 _cleanup_free_
char *partition
= NULL
, *mount_options
= NULL
, *mount_options_resolved
= NULL
;
5364 MountOptions
*o
= NULL
;
5365 PartitionDesignator partition_designator
;
5367 r
= extract_many_words(&q
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
, &partition
, &mount_options
, NULL
);
5371 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", q
);
5376 /* Single set of options, applying to the root partition/single filesystem */
5378 r
= unit_full_printf(u
, partition
, &mount_options_resolved
);
5380 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", first
);
5384 o
= new(MountOptions
, 1);
5387 *o
= (MountOptions
) {
5388 .partition_designator
= PARTITION_ROOT
,
5389 .options
= TAKE_PTR(mount_options_resolved
),
5391 LIST_APPEND(mount_options
, options
, o
);
5396 partition_designator
= partition_designator_from_string(partition
);
5397 if (partition_designator
< 0) {
5398 log_syntax(unit
, LOG_WARNING
, filename
, line
, partition_designator
,
5399 "Invalid partition name %s, ignoring", partition
);
5402 r
= unit_full_printf(u
, mount_options
, &mount_options_resolved
);
5404 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", mount_options
);
5408 o
= new(MountOptions
, 1);
5411 *o
= (MountOptions
) {
5412 .partition_designator
= partition_designator
,
5413 .options
= TAKE_PTR(mount_options_resolved
),
5415 LIST_APPEND(mount_options
, options
, o
);
5418 r
= mount_image_add(&c
->mount_images
, &c
->n_mount_images
,
5420 .source
= sresolved
,
5421 .destination
= dresolved
,
5422 .mount_options
= options
,
5423 .ignore_enoent
= permissive
,
5424 .type
= MOUNT_IMAGE_DISCRETE
,
5431 int config_parse_extension_images(
5433 const char *filename
,
5435 const char *section
,
5436 unsigned section_line
,
5443 ExecContext
*c
= data
;
5444 const Unit
*u
= userdata
;
5452 if (isempty(rvalue
)) {
5453 /* Empty assignment resets the list */
5454 c
->extension_images
= mount_image_free_many(c
->extension_images
, &c
->n_extension_images
);
5458 for (const char *p
= rvalue
;;) {
5459 _cleanup_free_
char *source
= NULL
, *tuple
= NULL
, *sresolved
= NULL
;
5460 _cleanup_(mount_options_free_allp
) MountOptions
*options
= NULL
;
5461 bool permissive
= false;
5462 const char *q
= NULL
;
5465 r
= extract_first_word(&p
, &tuple
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_RETAIN_ESCAPE
);
5469 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5470 "Invalid syntax %s=%s, ignoring: %m", lvalue
, rvalue
);
5477 r
= extract_first_word(&q
, &source
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
);
5481 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5482 "Invalid syntax in %s=, ignoring: %s", lvalue
, tuple
);
5494 r
= unit_path_printf(u
, s
, &sresolved
);
5496 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5497 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", s
);
5501 r
= path_simplify_and_warn(sresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5506 _cleanup_free_
char *partition
= NULL
, *mount_options
= NULL
, *mount_options_resolved
= NULL
;
5507 MountOptions
*o
= NULL
;
5508 PartitionDesignator partition_designator
;
5510 r
= extract_many_words(&q
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
, &partition
, &mount_options
, NULL
);
5514 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", q
);
5519 /* Single set of options, applying to the root partition/single filesystem */
5521 r
= unit_full_printf(u
, partition
, &mount_options_resolved
);
5523 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", partition
);
5527 o
= new(MountOptions
, 1);
5530 *o
= (MountOptions
) {
5531 .partition_designator
= PARTITION_ROOT
,
5532 .options
= TAKE_PTR(mount_options_resolved
),
5534 LIST_APPEND(mount_options
, options
, o
);
5539 partition_designator
= partition_designator_from_string(partition
);
5540 if (partition_designator
< 0) {
5541 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid partition name %s, ignoring", partition
);
5544 r
= unit_full_printf(u
, mount_options
, &mount_options_resolved
);
5546 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", mount_options
);
5550 o
= new(MountOptions
, 1);
5553 *o
= (MountOptions
) {
5554 .partition_designator
= partition_designator
,
5555 .options
= TAKE_PTR(mount_options_resolved
),
5557 LIST_APPEND(mount_options
, options
, o
);
5560 r
= mount_image_add(&c
->extension_images
, &c
->n_extension_images
,
5562 .source
= sresolved
,
5563 .mount_options
= options
,
5564 .ignore_enoent
= permissive
,
5565 .type
= MOUNT_IMAGE_EXTENSION
,
5572 int config_parse_job_timeout_sec(
5574 const char *filename
,
5576 const char *section
,
5577 unsigned section_line
,
5593 r
= parse_sec_fix_0(rvalue
, &usec
);
5595 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse JobTimeoutSec= parameter, ignoring: %s", rvalue
);
5599 /* If the user explicitly changed JobTimeoutSec= also change JobRunningTimeoutSec=, for compatibility with old
5600 * versions. If JobRunningTimeoutSec= was explicitly set, avoid this however as whatever the user picked should
5603 if (!u
->job_running_timeout_set
)
5604 u
->job_running_timeout
= usec
;
5606 u
->job_timeout
= usec
;
5611 int config_parse_job_running_timeout_sec(
5613 const char *filename
,
5615 const char *section
,
5616 unsigned section_line
,
5632 r
= parse_sec_fix_0(rvalue
, &usec
);
5634 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse JobRunningTimeoutSec= parameter, ignoring: %s", rvalue
);
5638 u
->job_running_timeout
= usec
;
5639 u
->job_running_timeout_set
= true;
5644 int config_parse_emergency_action(
5646 const char *filename
,
5648 const char *section
,
5649 unsigned section_line
,
5657 EmergencyAction
*x
= data
;
5666 m
= ((Unit
*) userdata
)->manager
;
5670 r
= parse_emergency_action(rvalue
, MANAGER_IS_SYSTEM(m
), x
);
5672 if (r
== -EOPNOTSUPP
&& MANAGER_IS_USER(m
)) {
5673 /* Compat mode: remove for systemd 241. */
5675 log_syntax(unit
, LOG_INFO
, filename
, line
, r
,
5676 "%s= in user mode specified as \"%s\", using \"exit-force\" instead.",
5678 *x
= EMERGENCY_ACTION_EXIT_FORCE
;
5682 if (r
== -EOPNOTSUPP
)
5683 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5684 "%s= specified as %s mode action, ignoring: %s",
5685 lvalue
, MANAGER_IS_SYSTEM(m
) ? "user" : "system", rvalue
);
5687 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5688 "Failed to parse %s=, ignoring: %s", lvalue
, rvalue
);
5695 int config_parse_pid_file(
5697 const char *filename
,
5699 const char *section
,
5700 unsigned section_line
,
5707 _cleanup_free_
char *k
= NULL
, *n
= NULL
;
5708 const Unit
*u
= userdata
;
5717 if (isempty(rvalue
)) {
5718 /* An empty assignment removes already set value. */
5723 r
= unit_path_printf(u
, rvalue
, &k
);
5725 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
5729 /* If this is a relative path make it absolute by prefixing the /run */
5730 n
= path_make_absolute(k
, u
->manager
->prefix
[EXEC_DIRECTORY_RUNTIME
]);
5734 /* Check that the result is a sensible path */
5735 r
= path_simplify_and_warn(n
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5739 r
= patch_var_run(unit
, filename
, line
, lvalue
, &n
);
5743 free_and_replace(*s
, n
);
5747 int config_parse_exit_status(
5749 const char *filename
,
5751 const char *section
,
5752 unsigned section_line
,
5759 int *exit_status
= data
, r
;
5765 assert(exit_status
);
5767 if (isempty(rvalue
)) {
5772 r
= safe_atou8(rvalue
, &u
);
5774 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse exit status '%s', ignoring: %m", rvalue
);
5782 int config_parse_disable_controllers(
5784 const char *filename
,
5786 const char *section
,
5787 unsigned section_line
,
5795 CGroupContext
*c
= data
;
5796 CGroupMask disabled_mask
;
5798 /* 1. If empty, make all controllers eligible for use again.
5799 * 2. If non-empty, merge all listed controllers, space separated. */
5801 if (isempty(rvalue
)) {
5802 c
->disable_controllers
= 0;
5806 r
= cg_mask_from_string(rvalue
, &disabled_mask
);
5807 if (r
< 0 || disabled_mask
<= 0) {
5808 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid cgroup string: %s, ignoring", rvalue
);
5812 c
->disable_controllers
|= disabled_mask
;
5817 int config_parse_ip_filter_bpf_progs(
5819 const char *filename
,
5821 const char *section
,
5822 unsigned section_line
,
5829 _cleanup_free_
char *resolved
= NULL
;
5830 const Unit
*u
= userdata
;
5831 char ***paths
= data
;
5839 if (isempty(rvalue
)) {
5840 *paths
= strv_free(*paths
);
5844 r
= unit_path_printf(u
, rvalue
, &resolved
);
5846 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
5850 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5854 if (strv_contains(*paths
, resolved
))
5857 r
= strv_extend(paths
, resolved
);
5861 r
= bpf_firewall_supported();
5864 if (r
!= BPF_FIREWALL_SUPPORTED_WITH_MULTI
) {
5865 static bool warned
= false;
5867 log_full(warned
? LOG_DEBUG
: LOG_WARNING
,
5868 "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"
5869 "Starting this unit will fail! (This warning is only shown for the first loaded unit using IP firewalling.)", filename
, line
, lvalue
, rvalue
);
5877 int config_parse_bpf_foreign_program(
5879 const char *filename
,
5881 const char *section
,
5882 unsigned section_line
,
5888 _cleanup_free_
char *resolved
= NULL
, *word
= NULL
;
5889 CGroupContext
*c
= data
;
5890 const char *p
= rvalue
;
5898 if (isempty(rvalue
)) {
5899 while (c
->bpf_foreign_programs
)
5900 cgroup_context_remove_bpf_foreign_program(c
, c
->bpf_foreign_programs
);
5905 r
= extract_first_word(&p
, &word
, ":", 0);
5909 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse foreign BPF program, ignoring: %s", rvalue
);
5912 if (r
== 0 || isempty(p
)) {
5913 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid syntax in %s=, ignoring: %s", lvalue
, rvalue
);
5917 attach_type
= bpf_cgroup_attach_type_from_string(word
);
5918 if (attach_type
< 0) {
5919 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Unknown BPF attach type=%s, ignoring: %s", word
, rvalue
);
5923 r
= unit_path_printf(u
, p
, &resolved
);
5925 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %s", p
, rvalue
);
5929 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5933 r
= cgroup_add_bpf_foreign_program(c
, attach_type
, resolved
);
5935 return log_error_errno(r
, "Failed to add foreign BPF program to cgroup context: %m");
5940 int config_parse_cgroup_socket_bind(
5942 const char *filename
,
5944 const char *section
,
5945 unsigned section_line
,
5951 _cleanup_free_ CGroupSocketBindItem
*item
= NULL
;
5952 CGroupSocketBindItem
**head
= data
;
5953 uint16_t nr_ports
, port_min
;
5954 int af
, ip_protocol
, r
;
5956 if (isempty(rvalue
)) {
5957 cgroup_context_remove_socket_bind(head
);
5961 r
= parse_socket_bind_item(rvalue
, &af
, &ip_protocol
, &nr_ports
, &port_min
);
5965 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5966 "Unable to parse %s= assignment, ignoring: %s", lvalue
, rvalue
);
5970 item
= new(CGroupSocketBindItem
, 1);
5973 *item
= (CGroupSocketBindItem
) {
5974 .address_family
= af
,
5975 .ip_protocol
= ip_protocol
,
5976 .nr_ports
= nr_ports
,
5977 .port_min
= port_min
,
5980 LIST_PREPEND(socket_bind_items
, *head
, TAKE_PTR(item
));
5985 int config_parse_restrict_network_interfaces(
5987 const char *filename
,
5989 const char *section
,
5990 unsigned section_line
,
5996 CGroupContext
*c
= data
;
5997 bool is_allow_rule
= true;
6005 if (isempty(rvalue
)) {
6006 /* Empty assignment resets the list */
6007 c
->restrict_network_interfaces
= set_free(c
->restrict_network_interfaces
);
6011 if (rvalue
[0] == '~') {
6012 is_allow_rule
= false;
6016 if (set_isempty(c
->restrict_network_interfaces
))
6017 /* Only initialize this when creating the set */
6018 c
->restrict_network_interfaces_is_allow_list
= is_allow_rule
;
6020 for (const char *p
= rvalue
;;) {
6021 _cleanup_free_
char *word
= NULL
;
6023 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
6029 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
6030 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
6034 if (!ifname_valid(word
)) {
6035 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid interface name, ignoring: %s", word
);
6039 if (c
->restrict_network_interfaces_is_allow_list
!= is_allow_rule
)
6040 free(set_remove(c
->restrict_network_interfaces
, word
));
6042 r
= set_put_strdup(&c
->restrict_network_interfaces
, word
);
6051 static int merge_by_names(Unit
**u
, Set
*names
, const char *id
) {
6058 /* Let's try to add in all names that are aliases of this unit */
6059 while ((k
= set_steal_first(names
))) {
6060 _cleanup_free_ _unused_
char *free_k
= k
;
6062 /* First try to merge in the other name into our unit */
6063 r
= unit_merge_by_name(*u
, k
);
6067 /* Hmm, we couldn't merge the other unit into ours? Then let's try it the other way
6070 other
= manager_get_unit((*u
)->manager
, k
);
6072 return r
; /* return previous failure */
6074 r
= unit_merge(other
, *u
);
6079 return merge_by_names(u
, names
, NULL
);
6082 if (streq_ptr(id
, k
))
6083 unit_choose_id(*u
, id
);
6089 int unit_load_fragment(Unit
*u
) {
6090 const char *fragment
;
6091 _cleanup_set_free_free_ Set
*names
= NULL
;
6095 assert(u
->load_state
== UNIT_STUB
);
6099 u
->load_state
= UNIT_LOADED
;
6103 /* Possibly rebuild the fragment map to catch new units */
6104 r
= unit_file_build_name_map(&u
->manager
->lookup_paths
,
6105 &u
->manager
->unit_cache_timestamp_hash
,
6106 &u
->manager
->unit_id_map
,
6107 &u
->manager
->unit_name_map
,
6108 &u
->manager
->unit_path_cache
);
6110 return log_error_errno(r
, "Failed to rebuild name map: %m");
6112 r
= unit_file_find_fragment(u
->manager
->unit_id_map
,
6113 u
->manager
->unit_name_map
,
6117 if (r
< 0 && r
!= -ENOENT
)
6121 /* Open the file, check if this is a mask, otherwise read. */
6122 _cleanup_fclose_
FILE *f
= NULL
;
6125 /* Try to open the file name. A symlink is OK, for example for linked files or masks. We
6126 * expect that all symlinks within the lookup paths have been already resolved, but we don't
6127 * verify this here. */
6128 f
= fopen(fragment
, "re");
6130 return log_unit_notice_errno(u
, errno
, "Failed to open %s: %m", fragment
);
6132 if (fstat(fileno(f
), &st
) < 0)
6135 r
= free_and_strdup(&u
->fragment_path
, fragment
);
6139 if (null_or_empty(&st
)) {
6140 /* Unit file is masked */
6142 u
->load_state
= u
->perpetual
? UNIT_LOADED
: UNIT_MASKED
; /* don't allow perpetual units to ever be masked */
6143 u
->fragment_mtime
= 0;
6145 u
->load_state
= UNIT_LOADED
;
6146 u
->fragment_mtime
= timespec_load(&st
.st_mtim
);
6148 /* Now, parse the file contents */
6149 r
= config_parse(u
->id
, fragment
, f
,
6150 UNIT_VTABLE(u
)->sections
,
6151 config_item_perf_lookup
, load_fragment_gperf_lookup
,
6156 log_unit_notice_errno(u
, r
, "Unit configuration has fatal error, unit will not be started.");
6162 /* Call merge_by_names with the name derived from the fragment path as the preferred name.
6164 * We do the merge dance here because for some unit types, the unit might have aliases which are not
6165 * declared in the file system. In particular, this is true (and frequent) for device and swap units.
6167 const char *id
= u
->id
;
6168 _cleanup_free_
char *free_id
= NULL
;
6171 id
= basename(fragment
);
6172 if (unit_name_is_valid(id
, UNIT_NAME_TEMPLATE
)) {
6173 assert(u
->instance
); /* If we're not trying to use a template for non-instanced unit,
6174 * this must be set. */
6176 r
= unit_name_replace_instance(id
, u
->instance
, &free_id
);
6178 return log_debug_errno(r
, "Failed to build id (%s + %s): %m", id
, u
->instance
);
6184 r
= merge_by_names(&merged
, names
, id
);
6189 u
->load_state
= UNIT_MERGED
;
6194 void unit_dump_config_items(FILE *f
) {
6195 static const struct {
6196 const ConfigParserCallback callback
;
6199 { config_parse_warn_compat
, "NOTSUPPORTED" },
6200 { config_parse_int
, "INTEGER" },
6201 { config_parse_unsigned
, "UNSIGNED" },
6202 { config_parse_iec_size
, "SIZE" },
6203 { config_parse_iec_uint64
, "SIZE" },
6204 { config_parse_si_uint64
, "SIZE" },
6205 { config_parse_bool
, "BOOLEAN" },
6206 { config_parse_string
, "STRING" },
6207 { config_parse_path
, "PATH" },
6208 { config_parse_unit_path_printf
, "PATH" },
6209 { config_parse_colon_separated_paths
, "PATH" },
6210 { config_parse_strv
, "STRING [...]" },
6211 { config_parse_exec_nice
, "NICE" },
6212 { config_parse_exec_oom_score_adjust
, "OOMSCOREADJUST" },
6213 { config_parse_exec_io_class
, "IOCLASS" },
6214 { config_parse_exec_io_priority
, "IOPRIORITY" },
6215 { config_parse_exec_cpu_sched_policy
, "CPUSCHEDPOLICY" },
6216 { config_parse_exec_cpu_sched_prio
, "CPUSCHEDPRIO" },
6217 { config_parse_exec_cpu_affinity
, "CPUAFFINITY" },
6218 { config_parse_mode
, "MODE" },
6219 { config_parse_unit_env_file
, "FILE" },
6220 { config_parse_exec_output
, "OUTPUT" },
6221 { config_parse_exec_input
, "INPUT" },
6222 { config_parse_log_facility
, "FACILITY" },
6223 { config_parse_log_level
, "LEVEL" },
6224 { config_parse_exec_secure_bits
, "SECUREBITS" },
6225 { config_parse_capability_set
, "BOUNDINGSET" },
6226 { config_parse_rlimit
, "LIMIT" },
6227 { config_parse_unit_deps
, "UNIT [...]" },
6228 { config_parse_exec
, "PATH [ARGUMENT [...]]" },
6229 { config_parse_service_type
, "SERVICETYPE" },
6230 { config_parse_service_exit_type
, "SERVICEEXITTYPE" },
6231 { config_parse_service_restart
, "SERVICERESTART" },
6232 { config_parse_service_timeout_failure_mode
, "TIMEOUTMODE" },
6233 { config_parse_kill_mode
, "KILLMODE" },
6234 { config_parse_signal
, "SIGNAL" },
6235 { config_parse_socket_listen
, "SOCKET [...]" },
6236 { config_parse_socket_bind
, "SOCKETBIND" },
6237 { config_parse_socket_bindtodevice
, "NETWORKINTERFACE" },
6238 { config_parse_sec
, "SECONDS" },
6239 { config_parse_nsec
, "NANOSECONDS" },
6240 { config_parse_namespace_path_strv
, "PATH [...]" },
6241 { config_parse_bind_paths
, "PATH[:PATH[:OPTIONS]] [...]" },
6242 { config_parse_unit_requires_mounts_for
, "PATH [...]" },
6243 { config_parse_exec_mount_flags
, "MOUNTFLAG [...]" },
6244 { config_parse_unit_string_printf
, "STRING" },
6245 { config_parse_trigger_unit
, "UNIT" },
6246 { config_parse_timer
, "TIMER" },
6247 { config_parse_path_spec
, "PATH" },
6248 { config_parse_notify_access
, "ACCESS" },
6249 { config_parse_ip_tos
, "TOS" },
6250 { config_parse_unit_condition_path
, "CONDITION" },
6251 { config_parse_unit_condition_string
, "CONDITION" },
6252 { config_parse_unit_slice
, "SLICE" },
6253 { config_parse_documentation
, "URL" },
6254 { config_parse_service_timeout
, "SECONDS" },
6255 { config_parse_emergency_action
, "ACTION" },
6256 { config_parse_set_status
, "STATUS" },
6257 { config_parse_service_sockets
, "SOCKETS" },
6258 { config_parse_environ
, "ENVIRON" },
6260 { config_parse_syscall_filter
, "SYSCALLS" },
6261 { config_parse_syscall_archs
, "ARCHS" },
6262 { config_parse_syscall_errno
, "ERRNO" },
6263 { config_parse_syscall_log
, "SYSCALLS" },
6264 { config_parse_address_families
, "FAMILIES" },
6265 { config_parse_restrict_namespaces
, "NAMESPACES" },
6267 { config_parse_restrict_filesystems
, "FILESYSTEMS" },
6268 { config_parse_cpu_shares
, "SHARES" },
6269 { config_parse_cg_weight
, "WEIGHT" },
6270 { config_parse_memory_limit
, "LIMIT" },
6271 { config_parse_device_allow
, "DEVICE" },
6272 { config_parse_device_policy
, "POLICY" },
6273 { config_parse_io_limit
, "LIMIT" },
6274 { config_parse_io_device_weight
, "DEVICEWEIGHT" },
6275 { config_parse_io_device_latency
, "DEVICELATENCY" },
6276 { config_parse_blockio_bandwidth
, "BANDWIDTH" },
6277 { config_parse_blockio_weight
, "WEIGHT" },
6278 { config_parse_blockio_device_weight
, "DEVICEWEIGHT" },
6279 { config_parse_long
, "LONG" },
6280 { config_parse_socket_service
, "SERVICE" },
6282 { config_parse_exec_selinux_context
, "LABEL" },
6284 { config_parse_job_mode
, "MODE" },
6285 { config_parse_job_mode_isolate
, "BOOLEAN" },
6286 { config_parse_personality
, "PERSONALITY" },
6289 const char *prev
= NULL
;
6294 NULSTR_FOREACH(i
, load_fragment_gperf_nulstr
) {
6295 const char *rvalue
= "OTHER", *lvalue
;
6296 const ConfigPerfItem
*p
;
6299 assert_se(p
= load_fragment_gperf_lookup(i
, strlen(i
)));
6301 /* Hide legacy settings */
6302 if (p
->parse
== config_parse_warn_compat
&&
6303 p
->ltype
== DISABLED_LEGACY
)
6306 for (size_t j
= 0; j
< ELEMENTSOF(table
); j
++)
6307 if (p
->parse
== table
[j
].callback
) {
6308 rvalue
= table
[j
].rvalue
;
6312 dot
= strchr(i
, '.');
6313 lvalue
= dot
? dot
+ 1 : i
;
6316 size_t prefix_len
= dot
- i
;
6318 if (!prev
|| !strneq(prev
, i
, prefix_len
+1)) {
6322 fprintf(f
, "[%.*s]\n", (int) prefix_len
, i
);
6326 fprintf(f
, "%s=%s\n", lvalue
, rvalue
);
6331 int config_parse_cpu_affinity2(
6333 const char *filename
,
6335 const char *section
,
6336 unsigned section_line
,
6343 CPUSet
*affinity
= data
;
6347 (void) parse_cpu_set_extend(rvalue
, affinity
, true, unit
, filename
, line
, lvalue
);
6352 int config_parse_show_status(
6354 const char *filename
,
6356 const char *section
,
6357 unsigned section_line
,
6365 ShowStatus
*b
= data
;
6372 k
= parse_show_status(rvalue
, b
);
6374 log_syntax(unit
, LOG_WARNING
, filename
, line
, k
, "Failed to parse show status setting, ignoring: %s", rvalue
);
6379 int config_parse_output_restricted(
6381 const char *filename
,
6383 const char *section
,
6384 unsigned section_line
,
6391 ExecOutput t
, *eo
= data
;
6392 bool obsolete
= false;
6399 if (streq(rvalue
, "syslog")) {
6400 t
= EXEC_OUTPUT_JOURNAL
;
6402 } else if (streq(rvalue
, "syslog+console")) {
6403 t
= EXEC_OUTPUT_JOURNAL_AND_CONSOLE
;
6406 t
= exec_output_from_string(rvalue
);
6408 log_syntax(unit
, LOG_WARNING
, filename
, line
, t
, "Failed to parse output type, ignoring: %s", rvalue
);
6412 if (IN_SET(t
, EXEC_OUTPUT_SOCKET
, EXEC_OUTPUT_NAMED_FD
, EXEC_OUTPUT_FILE
, EXEC_OUTPUT_FILE_APPEND
, EXEC_OUTPUT_FILE_TRUNCATE
)) {
6413 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Standard output types socket, fd:, file:, append:, truncate: are not supported as defaults, ignoring: %s", rvalue
);
6419 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
6420 "Standard output type %s is obsolete, automatically updating to %s. Please update your configuration.",
6421 rvalue
, exec_output_to_string(t
));
6427 int config_parse_crash_chvt(
6429 const char *filename
,
6431 const char *section
,
6432 unsigned section_line
,
6446 r
= parse_crash_chvt(rvalue
, data
);
6448 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse CrashChangeVT= setting, ignoring: %s", rvalue
);
6453 int config_parse_swap_priority(
6455 const char *filename
,
6457 const char *section
,
6458 unsigned section_line
,
6474 if (isempty(rvalue
)) {
6475 s
->parameters_fragment
.priority
= -1;
6476 s
->parameters_fragment
.priority_set
= false;
6480 r
= safe_atoi(rvalue
, &priority
);
6482 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid swap priority '%s', ignoring.", rvalue
);
6486 if (priority
< -1) {
6487 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
);
6491 if (priority
> 32767) {
6492 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Swap priority out of range, ignoring: %s", rvalue
);
6496 s
->parameters_fragment
.priority
= priority
;
6497 s
->parameters_fragment
.priority_set
= true;
6501 int config_parse_watchdog_sec(
6503 const char *filename
,
6505 const char *section
,
6506 unsigned section_line
,
6513 usec_t
*usec
= data
;
6519 /* This is called for {Runtime,Reboot,KExec}WatchdogSec= where "default" maps to
6520 * USEC_INFINITY internally. */
6522 if (streq(rvalue
, "default"))
6523 *usec
= USEC_INFINITY
;
6524 else if (streq(rvalue
, "off"))
6527 return config_parse_sec(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
);
6532 int config_parse_tty_size(
6534 const char *filename
,
6536 const char *section
,
6537 unsigned section_line
,
6544 unsigned *sz
= data
;
6550 if (isempty(rvalue
)) {
6555 return config_parse_unsigned(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
);