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
);
4214 if (r
<= 0 || isempty(p
)) {
4215 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4216 "Failed to extract device path and weight from '%s', ignoring.", rvalue
);
4220 r
= unit_path_printf(userdata
, path
, &resolved
);
4222 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4223 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4227 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4231 r
= cg_weight_parse(p
, &u
);
4233 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "IO weight '%s' invalid, ignoring: %m", p
);
4237 assert(u
!= CGROUP_WEIGHT_INVALID
);
4239 w
= new0(CGroupIODeviceWeight
, 1);
4243 w
->path
= TAKE_PTR(resolved
);
4246 LIST_PREPEND(device_weights
, c
->io_device_weights
, w
);
4250 int config_parse_io_device_latency(
4252 const char *filename
,
4254 const char *section
,
4255 unsigned section_line
,
4262 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4263 CGroupIODeviceLatency
*l
;
4264 CGroupContext
*c
= data
;
4265 const char *p
= rvalue
;
4273 if (isempty(rvalue
)) {
4274 while (c
->io_device_latencies
)
4275 cgroup_context_free_io_device_latency(c
, c
->io_device_latencies
);
4280 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4283 if (r
<= 0 || isempty(p
)) {
4284 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4285 "Failed to extract device path and latency from '%s', ignoring.", rvalue
);
4289 r
= unit_path_printf(userdata
, path
, &resolved
);
4291 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4292 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4296 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4300 r
= parse_sec(p
, &usec
);
4302 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse timer value, ignoring: %s", p
);
4306 l
= new0(CGroupIODeviceLatency
, 1);
4310 l
->path
= TAKE_PTR(resolved
);
4311 l
->target_usec
= usec
;
4313 LIST_PREPEND(device_latencies
, c
->io_device_latencies
, l
);
4317 int config_parse_io_limit(
4319 const char *filename
,
4321 const char *section
,
4322 unsigned section_line
,
4329 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4330 CGroupIODeviceLimit
*l
= NULL
;
4331 CGroupContext
*c
= data
;
4332 CGroupIOLimitType type
;
4333 const char *p
= rvalue
;
4341 type
= cgroup_io_limit_type_from_string(lvalue
);
4344 if (isempty(rvalue
)) {
4345 LIST_FOREACH(device_limits
, t
, c
->io_device_limits
)
4346 t
->limits
[type
] = cgroup_io_limit_defaults
[type
];
4350 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4353 if (r
<= 0 || isempty(p
)) {
4354 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4355 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
4359 r
= unit_path_printf(userdata
, path
, &resolved
);
4361 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4362 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4366 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4370 if (streq("infinity", p
))
4371 num
= CGROUP_LIMIT_MAX
;
4373 r
= parse_size(p
, 1000, &num
);
4374 if (r
< 0 || num
<= 0) {
4375 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid IO limit '%s', ignoring.", p
);
4380 LIST_FOREACH(device_limits
, t
, c
->io_device_limits
)
4381 if (path_equal(resolved
, t
->path
)) {
4387 CGroupIOLimitType ttype
;
4389 l
= new0(CGroupIODeviceLimit
, 1);
4393 l
->path
= TAKE_PTR(resolved
);
4394 for (ttype
= 0; ttype
< _CGROUP_IO_LIMIT_TYPE_MAX
; ttype
++)
4395 l
->limits
[ttype
] = cgroup_io_limit_defaults
[ttype
];
4397 LIST_PREPEND(device_limits
, c
->io_device_limits
, l
);
4400 l
->limits
[type
] = num
;
4405 int config_parse_blockio_device_weight(
4407 const char *filename
,
4409 const char *section
,
4410 unsigned section_line
,
4417 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4418 CGroupBlockIODeviceWeight
*w
;
4419 CGroupContext
*c
= data
;
4420 const char *p
= rvalue
;
4428 if (isempty(rvalue
)) {
4429 while (c
->blockio_device_weights
)
4430 cgroup_context_free_blockio_device_weight(c
, c
->blockio_device_weights
);
4435 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4438 if (r
<= 0 || isempty(p
)) {
4439 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4440 "Failed to extract device node and weight from '%s', ignoring.", rvalue
);
4444 r
= unit_path_printf(userdata
, path
, &resolved
);
4446 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4447 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4451 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4455 r
= cg_blkio_weight_parse(p
, &u
);
4457 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid block IO weight '%s', ignoring: %m", p
);
4461 assert(u
!= CGROUP_BLKIO_WEIGHT_INVALID
);
4463 w
= new0(CGroupBlockIODeviceWeight
, 1);
4467 w
->path
= TAKE_PTR(resolved
);
4470 LIST_PREPEND(device_weights
, c
->blockio_device_weights
, w
);
4474 int config_parse_blockio_bandwidth(
4476 const char *filename
,
4478 const char *section
,
4479 unsigned section_line
,
4486 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4487 CGroupBlockIODeviceBandwidth
*b
= NULL
;
4488 CGroupContext
*c
= data
;
4489 const char *p
= rvalue
;
4498 read
= streq("BlockIOReadBandwidth", lvalue
);
4500 if (isempty(rvalue
)) {
4501 LIST_FOREACH(device_bandwidths
, t
, c
->blockio_device_bandwidths
) {
4502 t
->rbps
= CGROUP_LIMIT_MAX
;
4503 t
->wbps
= CGROUP_LIMIT_MAX
;
4508 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4511 if (r
<= 0 || isempty(p
)) {
4512 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4513 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
4517 r
= unit_path_printf(userdata
, path
, &resolved
);
4519 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4520 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4524 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4528 r
= parse_size(p
, 1000, &bytes
);
4529 if (r
< 0 || bytes
<= 0) {
4530 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid Block IO Bandwidth '%s', ignoring.", p
);
4534 LIST_FOREACH(device_bandwidths
, t
, c
->blockio_device_bandwidths
)
4535 if (path_equal(resolved
, t
->path
)) {
4541 b
= new0(CGroupBlockIODeviceBandwidth
, 1);
4545 b
->path
= TAKE_PTR(resolved
);
4546 b
->rbps
= CGROUP_LIMIT_MAX
;
4547 b
->wbps
= CGROUP_LIMIT_MAX
;
4549 LIST_PREPEND(device_bandwidths
, c
->blockio_device_bandwidths
, b
);
4560 int config_parse_job_mode_isolate(
4562 const char *filename
,
4564 const char *section
,
4565 unsigned section_line
,
4579 r
= parse_boolean(rvalue
);
4581 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse boolean, ignoring: %s", rvalue
);
4585 log_notice("%s is deprecated. Please use OnFailureJobMode= instead", lvalue
);
4587 *m
= r
? JOB_ISOLATE
: JOB_REPLACE
;
4591 int config_parse_exec_directories(
4593 const char *filename
,
4595 const char *section
,
4596 unsigned section_line
,
4603 ExecDirectory
*ed
= data
;
4604 const Unit
*u
= userdata
;
4612 if (isempty(rvalue
)) {
4613 /* Empty assignment resets the list */
4614 exec_directory_done(ed
);
4618 for (const char *p
= rvalue
;;) {
4619 _cleanup_free_
char *tuple
= NULL
;
4621 r
= extract_first_word(&p
, &tuple
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_RETAIN_ESCAPE
);
4625 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4626 "Invalid syntax %s=%s, ignoring: %m", lvalue
, rvalue
);
4632 _cleanup_free_
char *src
= NULL
, *dest
= NULL
;
4633 const char *q
= tuple
;
4634 r
= extract_many_words(&q
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
, &src
, &dest
, NULL
);
4638 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
?: SYNTHETIC_ERRNO(EINVAL
),
4639 "Invalid syntax in %s=, ignoring: %s", lvalue
, tuple
);
4643 _cleanup_free_
char *sresolved
= NULL
;
4644 r
= unit_path_printf(u
, src
, &sresolved
);
4646 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4647 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", src
);
4651 r
= path_simplify_and_warn(sresolved
, PATH_CHECK_RELATIVE
, unit
, filename
, line
, lvalue
);
4655 if (path_startswith(sresolved
, "private")) {
4656 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4657 "%s= path can't be 'private', ignoring assignment: %s", lvalue
, tuple
);
4661 /* For State and Runtime directories we support an optional destination parameter, which
4662 * will be used to create a symlink to the source. */
4663 _cleanup_strv_free_
char **symlinks
= NULL
;
4664 if (!isempty(dest
)) {
4665 _cleanup_free_
char *dresolved
= NULL
;
4667 if (streq(lvalue
, "ConfigurationDirectory")) {
4668 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4669 "Destination parameter is not supported for ConfigurationDirectory, ignoring: %s", tuple
);
4673 r
= unit_path_printf(u
, dest
, &dresolved
);
4675 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4676 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", dest
);
4680 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_RELATIVE
, unit
, filename
, line
, lvalue
);
4684 r
= strv_consume(&symlinks
, TAKE_PTR(dresolved
));
4689 r
= exec_directory_add(&ed
->items
, &ed
->n_items
, sresolved
, symlinks
);
4695 int config_parse_set_credential(
4697 const char *filename
,
4699 const char *section
,
4700 unsigned section_line
,
4707 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
4708 _cleanup_free_
void *d
= NULL
;
4709 ExecContext
*context
= data
;
4710 ExecSetCredential
*old
;
4712 bool encrypted
= ltype
;
4713 const char *p
= rvalue
;
4722 if (isempty(rvalue
)) {
4723 /* Empty assignment resets the list */
4724 context
->set_credentials
= hashmap_free(context
->set_credentials
);
4728 r
= extract_first_word(&p
, &word
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4732 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
4736 r
= unit_cred_printf(u
, word
, &k
);
4738 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
4741 if (!credential_name_valid(k
)) {
4742 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Credential name \"%s\" not valid, ignoring.", k
);
4747 r
= unbase64mem_full(p
, SIZE_MAX
, true, &d
, &size
);
4749 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Encrypted credential data not valid Base64 data, ignoring.");
4756 /* We support escape codes here, so that users can insert trailing \n if they like */
4757 l
= cunescape(p
, UNESCAPE_ACCEPT_NUL
, &unescaped
);
4759 log_syntax(unit
, LOG_WARNING
, filename
, line
, l
, "Can't unescape \"%s\", ignoring: %m", p
);
4767 old
= hashmap_get(context
->set_credentials
, k
);
4769 free_and_replace(old
->data
, d
);
4771 old
->encrypted
= encrypted
;
4773 _cleanup_(exec_set_credential_freep
) ExecSetCredential
*sc
= NULL
;
4775 sc
= new(ExecSetCredential
, 1);
4779 *sc
= (ExecSetCredential
) {
4781 .data
= TAKE_PTR(d
),
4783 .encrypted
= encrypted
,
4786 r
= hashmap_ensure_put(&context
->set_credentials
, &exec_set_credential_hash_ops
, sc
->id
, sc
);
4790 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4791 "Duplicated credential value '%s', ignoring assignment: %s", sc
->id
, rvalue
);
4801 int config_parse_load_credential(
4803 const char *filename
,
4805 const char *section
,
4806 unsigned section_line
,
4813 _cleanup_free_
char *word
= NULL
, *k
= NULL
, *q
= NULL
;
4814 ExecContext
*context
= data
;
4815 ExecLoadCredential
*old
;
4816 bool encrypted
= ltype
;
4826 if (isempty(rvalue
)) {
4827 /* Empty assignment resets the list */
4828 context
->load_credentials
= hashmap_free(context
->load_credentials
);
4833 r
= extract_first_word(&p
, &word
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4837 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
4841 r
= unit_cred_printf(u
, word
, &k
);
4843 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
4846 if (!credential_name_valid(k
)) {
4847 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Credential name \"%s\" not valid, ignoring.", k
);
4852 /* If only one field is specified take it as shortcut for inheriting a credential named
4853 * the same way from our parent */
4858 r
= unit_path_printf(u
, p
, &q
);
4860 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", p
);
4863 if (path_is_absolute(q
) ? !path_is_normalized(q
) : !credential_name_valid(q
)) {
4864 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Credential source \"%s\" not valid, ignoring.", q
);
4869 old
= hashmap_get(context
->load_credentials
, k
);
4871 free_and_replace(old
->path
, q
);
4872 old
->encrypted
= encrypted
;
4874 _cleanup_(exec_load_credential_freep
) ExecLoadCredential
*lc
= NULL
;
4876 lc
= new(ExecLoadCredential
, 1);
4880 *lc
= (ExecLoadCredential
) {
4882 .path
= TAKE_PTR(q
),
4883 .encrypted
= encrypted
,
4886 r
= hashmap_ensure_put(&context
->load_credentials
, &exec_load_credential_hash_ops
, lc
->id
, lc
);
4890 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4891 "Duplicated credential value '%s', ignoring assignment: %s", lc
->id
, rvalue
);
4901 int config_parse_set_status(
4903 const char *filename
,
4905 const char *section
,
4906 unsigned section_line
,
4913 ExitStatusSet
*status_set
= data
;
4921 /* Empty assignment resets the list */
4922 if (isempty(rvalue
)) {
4923 exit_status_set_free(status_set
);
4927 for (const char *p
= rvalue
;;) {
4928 _cleanup_free_
char *word
= NULL
;
4931 r
= extract_first_word(&p
, &word
, NULL
, 0);
4935 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4936 "Failed to parse %s=%s, ignoring: %m", lvalue
, rvalue
);
4942 /* We need to call exit_status_from_string() first, because we want
4943 * to parse numbers as exit statuses, not signals. */
4945 r
= exit_status_from_string(word
);
4947 assert(r
>= 0 && r
< 256);
4948 bitmap
= &status_set
->status
;
4950 r
= signal_from_string(word
);
4952 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4953 "Failed to parse value, ignoring: %s", word
);
4956 bitmap
= &status_set
->signal
;
4959 r
= bitmap_set(bitmap
, r
);
4961 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4962 "Failed to set signal or status %s, ignoring: %m", word
);
4966 int config_parse_namespace_path_strv(
4968 const char *filename
,
4970 const char *section
,
4971 unsigned section_line
,
4978 const Unit
*u
= userdata
;
4987 if (isempty(rvalue
)) {
4988 /* Empty assignment resets the list */
4989 *sv
= strv_free(*sv
);
4993 for (const char *p
= rvalue
;;) {
4994 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
, *joined
= NULL
;
4996 bool ignore_enoent
= false, shall_prefix
= false;
4998 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
5002 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
5009 if (startswith(w
, "-")) {
5010 ignore_enoent
= true;
5013 if (startswith(w
, "+")) {
5014 shall_prefix
= true;
5018 r
= unit_path_printf(u
, w
, &resolved
);
5020 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", w
);
5024 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5028 joined
= strjoin(ignore_enoent
? "-" : "",
5029 shall_prefix
? "+" : "",
5032 r
= strv_push(sv
, joined
);
5042 int config_parse_temporary_filesystems(
5044 const char *filename
,
5046 const char *section
,
5047 unsigned section_line
,
5054 const Unit
*u
= userdata
;
5055 ExecContext
*c
= data
;
5063 if (isempty(rvalue
)) {
5064 /* Empty assignment resets the list */
5065 temporary_filesystem_free_many(c
->temporary_filesystems
, c
->n_temporary_filesystems
);
5066 c
->temporary_filesystems
= NULL
;
5067 c
->n_temporary_filesystems
= 0;
5071 for (const char *p
= rvalue
;;) {
5072 _cleanup_free_
char *word
= NULL
, *path
= NULL
, *resolved
= NULL
;
5075 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
5079 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
5086 r
= extract_first_word(&w
, &path
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
5090 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", word
);
5094 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid syntax, ignoring: %s", word
);
5098 r
= unit_path_printf(u
, path
, &resolved
);
5100 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", path
);
5104 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5108 r
= temporary_filesystem_add(&c
->temporary_filesystems
, &c
->n_temporary_filesystems
, resolved
, w
);
5114 int config_parse_bind_paths(
5116 const char *filename
,
5118 const char *section
,
5119 unsigned section_line
,
5126 ExecContext
*c
= data
;
5127 const Unit
*u
= userdata
;
5135 if (isempty(rvalue
)) {
5136 /* Empty assignment resets the list */
5137 bind_mount_free_many(c
->bind_mounts
, c
->n_bind_mounts
);
5138 c
->bind_mounts
= NULL
;
5139 c
->n_bind_mounts
= 0;
5143 for (const char *p
= rvalue
;;) {
5144 _cleanup_free_
char *source
= NULL
, *destination
= NULL
;
5145 _cleanup_free_
char *sresolved
= NULL
, *dresolved
= NULL
;
5146 char *s
= NULL
, *d
= NULL
;
5147 bool rbind
= true, ignore_enoent
= false;
5149 r
= extract_first_word(&p
, &source
, ":" WHITESPACE
, EXTRACT_UNQUOTE
|EXTRACT_DONT_COALESCE_SEPARATORS
);
5153 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
5159 r
= unit_full_printf_full(u
, source
, PATH_MAX
, &sresolved
);
5161 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5162 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", source
);
5168 ignore_enoent
= true;
5172 r
= path_simplify_and_warn(s
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5176 /* Optionally, the destination is specified. */
5177 if (p
&& p
[-1] == ':') {
5178 r
= extract_first_word(&p
, &destination
, ":" WHITESPACE
, EXTRACT_UNQUOTE
|EXTRACT_DONT_COALESCE_SEPARATORS
);
5182 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
5186 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Missing argument after ':', ignoring: %s", s
);
5190 r
= unit_path_printf(u
, destination
, &dresolved
);
5192 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5193 "Failed to resolve specifiers in \"%s\", ignoring: %m", destination
);
5197 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5203 /* Optionally, there's also a short option string specified */
5204 if (p
&& p
[-1] == ':') {
5205 _cleanup_free_
char *options
= NULL
;
5207 r
= extract_first_word(&p
, &options
, NULL
, EXTRACT_UNQUOTE
);
5211 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s: %s", lvalue
, rvalue
);
5215 if (isempty(options
) || streq(options
, "rbind"))
5217 else if (streq(options
, "norbind"))
5220 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid option string, ignoring setting: %s", options
);
5227 r
= bind_mount_add(&c
->bind_mounts
, &c
->n_bind_mounts
,
5231 .read_only
= !!strstr(lvalue
, "ReadOnly"),
5233 .ignore_enoent
= ignore_enoent
,
5242 int config_parse_mount_images(
5244 const char *filename
,
5246 const char *section
,
5247 unsigned section_line
,
5254 ExecContext
*c
= data
;
5255 const Unit
*u
= userdata
;
5263 if (isempty(rvalue
)) {
5264 /* Empty assignment resets the list */
5265 c
->mount_images
= mount_image_free_many(c
->mount_images
, &c
->n_mount_images
);
5269 for (const char *p
= rvalue
;;) {
5270 _cleanup_(mount_options_free_allp
) MountOptions
*options
= NULL
;
5271 _cleanup_free_
char *first
= NULL
, *second
= NULL
, *tuple
= NULL
;
5272 _cleanup_free_
char *sresolved
= NULL
, *dresolved
= NULL
;
5273 const char *q
= NULL
;
5275 bool permissive
= false;
5277 r
= extract_first_word(&p
, &tuple
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_RETAIN_ESCAPE
);
5281 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5282 "Invalid syntax %s=%s, ignoring: %m", lvalue
, rvalue
);
5289 r
= extract_many_words(&q
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
, &first
, &second
, NULL
);
5293 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5294 "Invalid syntax in %s=, ignoring: %s", lvalue
, tuple
);
5306 r
= unit_path_printf(u
, s
, &sresolved
);
5308 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5309 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", s
);
5313 r
= path_simplify_and_warn(sresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5317 if (isempty(second
)) {
5318 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Missing destination in %s, ignoring: %s", lvalue
, rvalue
);
5322 r
= unit_path_printf(u
, second
, &dresolved
);
5324 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5325 "Failed to resolve specifiers in \"%s\", ignoring: %m", second
);
5329 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5334 _cleanup_free_
char *partition
= NULL
, *mount_options
= NULL
, *mount_options_resolved
= NULL
;
5335 MountOptions
*o
= NULL
;
5336 PartitionDesignator partition_designator
;
5338 r
= extract_many_words(&q
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
, &partition
, &mount_options
, NULL
);
5342 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", q
);
5347 /* Single set of options, applying to the root partition/single filesystem */
5349 r
= unit_full_printf(u
, partition
, &mount_options_resolved
);
5351 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", first
);
5355 o
= new(MountOptions
, 1);
5358 *o
= (MountOptions
) {
5359 .partition_designator
= PARTITION_ROOT
,
5360 .options
= TAKE_PTR(mount_options_resolved
),
5362 LIST_APPEND(mount_options
, options
, o
);
5367 partition_designator
= partition_designator_from_string(partition
);
5368 if (partition_designator
< 0) {
5369 log_syntax(unit
, LOG_WARNING
, filename
, line
, partition_designator
,
5370 "Invalid partition name %s, ignoring", partition
);
5373 r
= unit_full_printf(u
, mount_options
, &mount_options_resolved
);
5375 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", mount_options
);
5379 o
= new(MountOptions
, 1);
5382 *o
= (MountOptions
) {
5383 .partition_designator
= partition_designator
,
5384 .options
= TAKE_PTR(mount_options_resolved
),
5386 LIST_APPEND(mount_options
, options
, o
);
5389 r
= mount_image_add(&c
->mount_images
, &c
->n_mount_images
,
5391 .source
= sresolved
,
5392 .destination
= dresolved
,
5393 .mount_options
= options
,
5394 .ignore_enoent
= permissive
,
5395 .type
= MOUNT_IMAGE_DISCRETE
,
5402 int config_parse_extension_images(
5404 const char *filename
,
5406 const char *section
,
5407 unsigned section_line
,
5414 ExecContext
*c
= data
;
5415 const Unit
*u
= userdata
;
5423 if (isempty(rvalue
)) {
5424 /* Empty assignment resets the list */
5425 c
->extension_images
= mount_image_free_many(c
->extension_images
, &c
->n_extension_images
);
5429 for (const char *p
= rvalue
;;) {
5430 _cleanup_free_
char *source
= NULL
, *tuple
= NULL
, *sresolved
= NULL
;
5431 _cleanup_(mount_options_free_allp
) MountOptions
*options
= NULL
;
5432 bool permissive
= false;
5433 const char *q
= NULL
;
5436 r
= extract_first_word(&p
, &tuple
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_RETAIN_ESCAPE
);
5440 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5441 "Invalid syntax %s=%s, ignoring: %m", lvalue
, rvalue
);
5448 r
= extract_first_word(&q
, &source
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
);
5452 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5453 "Invalid syntax in %s=, ignoring: %s", lvalue
, tuple
);
5465 r
= unit_path_printf(u
, s
, &sresolved
);
5467 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5468 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", s
);
5472 r
= path_simplify_and_warn(sresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5477 _cleanup_free_
char *partition
= NULL
, *mount_options
= NULL
, *mount_options_resolved
= NULL
;
5478 MountOptions
*o
= NULL
;
5479 PartitionDesignator partition_designator
;
5481 r
= extract_many_words(&q
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
, &partition
, &mount_options
, NULL
);
5485 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", q
);
5490 /* Single set of options, applying to the root partition/single filesystem */
5492 r
= unit_full_printf(u
, partition
, &mount_options_resolved
);
5494 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", partition
);
5498 o
= new(MountOptions
, 1);
5501 *o
= (MountOptions
) {
5502 .partition_designator
= PARTITION_ROOT
,
5503 .options
= TAKE_PTR(mount_options_resolved
),
5505 LIST_APPEND(mount_options
, options
, o
);
5510 partition_designator
= partition_designator_from_string(partition
);
5511 if (partition_designator
< 0) {
5512 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid partition name %s, ignoring", partition
);
5515 r
= unit_full_printf(u
, mount_options
, &mount_options_resolved
);
5517 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", mount_options
);
5521 o
= new(MountOptions
, 1);
5524 *o
= (MountOptions
) {
5525 .partition_designator
= partition_designator
,
5526 .options
= TAKE_PTR(mount_options_resolved
),
5528 LIST_APPEND(mount_options
, options
, o
);
5531 r
= mount_image_add(&c
->extension_images
, &c
->n_extension_images
,
5533 .source
= sresolved
,
5534 .mount_options
= options
,
5535 .ignore_enoent
= permissive
,
5536 .type
= MOUNT_IMAGE_EXTENSION
,
5543 int config_parse_job_timeout_sec(
5545 const char *filename
,
5547 const char *section
,
5548 unsigned section_line
,
5564 r
= parse_sec_fix_0(rvalue
, &usec
);
5566 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse JobTimeoutSec= parameter, ignoring: %s", rvalue
);
5570 /* If the user explicitly changed JobTimeoutSec= also change JobRunningTimeoutSec=, for compatibility with old
5571 * versions. If JobRunningTimeoutSec= was explicitly set, avoid this however as whatever the user picked should
5574 if (!u
->job_running_timeout_set
)
5575 u
->job_running_timeout
= usec
;
5577 u
->job_timeout
= usec
;
5582 int config_parse_job_running_timeout_sec(
5584 const char *filename
,
5586 const char *section
,
5587 unsigned section_line
,
5603 r
= parse_sec_fix_0(rvalue
, &usec
);
5605 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse JobRunningTimeoutSec= parameter, ignoring: %s", rvalue
);
5609 u
->job_running_timeout
= usec
;
5610 u
->job_running_timeout_set
= true;
5615 int config_parse_emergency_action(
5617 const char *filename
,
5619 const char *section
,
5620 unsigned section_line
,
5628 EmergencyAction
*x
= data
;
5637 m
= ((Unit
*) userdata
)->manager
;
5641 r
= parse_emergency_action(rvalue
, MANAGER_IS_SYSTEM(m
), x
);
5643 if (r
== -EOPNOTSUPP
&& MANAGER_IS_USER(m
)) {
5644 /* Compat mode: remove for systemd 241. */
5646 log_syntax(unit
, LOG_INFO
, filename
, line
, r
,
5647 "%s= in user mode specified as \"%s\", using \"exit-force\" instead.",
5649 *x
= EMERGENCY_ACTION_EXIT_FORCE
;
5653 if (r
== -EOPNOTSUPP
)
5654 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5655 "%s= specified as %s mode action, ignoring: %s",
5656 lvalue
, MANAGER_IS_SYSTEM(m
) ? "user" : "system", rvalue
);
5658 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5659 "Failed to parse %s=, ignoring: %s", lvalue
, rvalue
);
5666 int config_parse_pid_file(
5668 const char *filename
,
5670 const char *section
,
5671 unsigned section_line
,
5678 _cleanup_free_
char *k
= NULL
, *n
= NULL
;
5679 const Unit
*u
= userdata
;
5688 if (isempty(rvalue
)) {
5689 /* An empty assignment removes already set value. */
5694 r
= unit_path_printf(u
, rvalue
, &k
);
5696 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
5700 /* If this is a relative path make it absolute by prefixing the /run */
5701 n
= path_make_absolute(k
, u
->manager
->prefix
[EXEC_DIRECTORY_RUNTIME
]);
5705 /* Check that the result is a sensible path */
5706 r
= path_simplify_and_warn(n
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5710 r
= patch_var_run(unit
, filename
, line
, lvalue
, &n
);
5714 free_and_replace(*s
, n
);
5718 int config_parse_exit_status(
5720 const char *filename
,
5722 const char *section
,
5723 unsigned section_line
,
5730 int *exit_status
= data
, r
;
5736 assert(exit_status
);
5738 if (isempty(rvalue
)) {
5743 r
= safe_atou8(rvalue
, &u
);
5745 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse exit status '%s', ignoring: %m", rvalue
);
5753 int config_parse_disable_controllers(
5755 const char *filename
,
5757 const char *section
,
5758 unsigned section_line
,
5766 CGroupContext
*c
= data
;
5767 CGroupMask disabled_mask
;
5769 /* 1. If empty, make all controllers eligible for use again.
5770 * 2. If non-empty, merge all listed controllers, space separated. */
5772 if (isempty(rvalue
)) {
5773 c
->disable_controllers
= 0;
5777 r
= cg_mask_from_string(rvalue
, &disabled_mask
);
5778 if (r
< 0 || disabled_mask
<= 0) {
5779 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid cgroup string: %s, ignoring", rvalue
);
5783 c
->disable_controllers
|= disabled_mask
;
5788 int config_parse_ip_filter_bpf_progs(
5790 const char *filename
,
5792 const char *section
,
5793 unsigned section_line
,
5800 _cleanup_free_
char *resolved
= NULL
;
5801 const Unit
*u
= userdata
;
5802 char ***paths
= data
;
5810 if (isempty(rvalue
)) {
5811 *paths
= strv_free(*paths
);
5815 r
= unit_path_printf(u
, rvalue
, &resolved
);
5817 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
5821 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5825 if (strv_contains(*paths
, resolved
))
5828 r
= strv_extend(paths
, resolved
);
5832 r
= bpf_firewall_supported();
5835 if (r
!= BPF_FIREWALL_SUPPORTED_WITH_MULTI
) {
5836 static bool warned
= false;
5838 log_full(warned
? LOG_DEBUG
: LOG_WARNING
,
5839 "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"
5840 "Starting this unit will fail! (This warning is only shown for the first loaded unit using IP firewalling.)", filename
, line
, lvalue
, rvalue
);
5848 int config_parse_bpf_foreign_program(
5850 const char *filename
,
5852 const char *section
,
5853 unsigned section_line
,
5859 _cleanup_free_
char *resolved
= NULL
, *word
= NULL
;
5860 CGroupContext
*c
= data
;
5868 if (isempty(rvalue
)) {
5869 while (c
->bpf_foreign_programs
)
5870 cgroup_context_remove_bpf_foreign_program(c
, c
->bpf_foreign_programs
);
5875 r
= extract_first_word(&rvalue
, &word
, ":", 0);
5878 if (r
<= 0 || isempty(rvalue
)) {
5879 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse foreign BPF program, ignoring: %s", rvalue
);
5883 attach_type
= bpf_cgroup_attach_type_from_string(word
);
5884 if (attach_type
< 0) {
5885 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Unknown BPF attach type=%s, ignoring: %s", word
, rvalue
);
5889 r
= unit_path_printf(u
, rvalue
, &resolved
);
5891 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
5895 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5899 r
= cgroup_add_bpf_foreign_program(c
, attach_type
, resolved
);
5901 return log_error_errno(r
, "Failed to add foreign BPF program to cgroup context: %m");
5906 int config_parse_cgroup_socket_bind(
5908 const char *filename
,
5910 const char *section
,
5911 unsigned section_line
,
5917 _cleanup_free_ CGroupSocketBindItem
*item
= NULL
;
5918 CGroupSocketBindItem
**head
= data
;
5919 uint16_t nr_ports
, port_min
;
5920 int af
, ip_protocol
, r
;
5922 if (isempty(rvalue
)) {
5923 cgroup_context_remove_socket_bind(head
);
5927 r
= parse_socket_bind_item(rvalue
, &af
, &ip_protocol
, &nr_ports
, &port_min
);
5931 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5932 "Unable to parse %s= assignment, ignoring: %s", lvalue
, rvalue
);
5936 item
= new(CGroupSocketBindItem
, 1);
5939 *item
= (CGroupSocketBindItem
) {
5940 .address_family
= af
,
5941 .ip_protocol
= ip_protocol
,
5942 .nr_ports
= nr_ports
,
5943 .port_min
= port_min
,
5946 LIST_PREPEND(socket_bind_items
, *head
, TAKE_PTR(item
));
5951 int config_parse_restrict_network_interfaces(
5953 const char *filename
,
5955 const char *section
,
5956 unsigned section_line
,
5962 CGroupContext
*c
= data
;
5963 bool is_allow_rule
= true;
5971 if (isempty(rvalue
)) {
5972 /* Empty assignment resets the list */
5973 c
->restrict_network_interfaces
= set_free(c
->restrict_network_interfaces
);
5977 if (rvalue
[0] == '~') {
5978 is_allow_rule
= false;
5982 if (set_isempty(c
->restrict_network_interfaces
))
5983 /* Only initialize this when creating the set */
5984 c
->restrict_network_interfaces_is_allow_list
= is_allow_rule
;
5986 for (const char *p
= rvalue
;;) {
5987 _cleanup_free_
char *word
= NULL
;
5989 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
5995 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5996 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
6000 if (!ifname_valid(word
)) {
6001 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid interface name, ignoring: %s", word
);
6005 if (c
->restrict_network_interfaces_is_allow_list
!= is_allow_rule
)
6006 free(set_remove(c
->restrict_network_interfaces
, word
));
6008 r
= set_put_strdup(&c
->restrict_network_interfaces
, word
);
6017 static int merge_by_names(Unit
**u
, Set
*names
, const char *id
) {
6024 /* Let's try to add in all names that are aliases of this unit */
6025 while ((k
= set_steal_first(names
))) {
6026 _cleanup_free_ _unused_
char *free_k
= k
;
6028 /* First try to merge in the other name into our unit */
6029 r
= unit_merge_by_name(*u
, k
);
6033 /* Hmm, we couldn't merge the other unit into ours? Then let's try it the other way
6036 other
= manager_get_unit((*u
)->manager
, k
);
6038 return r
; /* return previous failure */
6040 r
= unit_merge(other
, *u
);
6045 return merge_by_names(u
, names
, NULL
);
6048 if (streq_ptr(id
, k
))
6049 unit_choose_id(*u
, id
);
6055 int unit_load_fragment(Unit
*u
) {
6056 const char *fragment
;
6057 _cleanup_set_free_free_ Set
*names
= NULL
;
6061 assert(u
->load_state
== UNIT_STUB
);
6065 u
->load_state
= UNIT_LOADED
;
6069 /* Possibly rebuild the fragment map to catch new units */
6070 r
= unit_file_build_name_map(&u
->manager
->lookup_paths
,
6071 &u
->manager
->unit_cache_timestamp_hash
,
6072 &u
->manager
->unit_id_map
,
6073 &u
->manager
->unit_name_map
,
6074 &u
->manager
->unit_path_cache
);
6076 return log_error_errno(r
, "Failed to rebuild name map: %m");
6078 r
= unit_file_find_fragment(u
->manager
->unit_id_map
,
6079 u
->manager
->unit_name_map
,
6083 if (r
< 0 && r
!= -ENOENT
)
6087 /* Open the file, check if this is a mask, otherwise read. */
6088 _cleanup_fclose_
FILE *f
= NULL
;
6091 /* Try to open the file name. A symlink is OK, for example for linked files or masks. We
6092 * expect that all symlinks within the lookup paths have been already resolved, but we don't
6093 * verify this here. */
6094 f
= fopen(fragment
, "re");
6096 return log_unit_notice_errno(u
, errno
, "Failed to open %s: %m", fragment
);
6098 if (fstat(fileno(f
), &st
) < 0)
6101 r
= free_and_strdup(&u
->fragment_path
, fragment
);
6105 if (null_or_empty(&st
)) {
6106 /* Unit file is masked */
6108 u
->load_state
= u
->perpetual
? UNIT_LOADED
: UNIT_MASKED
; /* don't allow perpetual units to ever be masked */
6109 u
->fragment_mtime
= 0;
6111 u
->load_state
= UNIT_LOADED
;
6112 u
->fragment_mtime
= timespec_load(&st
.st_mtim
);
6114 /* Now, parse the file contents */
6115 r
= config_parse(u
->id
, fragment
, f
,
6116 UNIT_VTABLE(u
)->sections
,
6117 config_item_perf_lookup
, load_fragment_gperf_lookup
,
6122 log_unit_notice_errno(u
, r
, "Unit configuration has fatal error, unit will not be started.");
6128 /* Call merge_by_names with the name derived from the fragment path as the preferred name.
6130 * We do the merge dance here because for some unit types, the unit might have aliases which are not
6131 * declared in the file system. In particular, this is true (and frequent) for device and swap units.
6133 const char *id
= u
->id
;
6134 _cleanup_free_
char *free_id
= NULL
;
6137 id
= basename(fragment
);
6138 if (unit_name_is_valid(id
, UNIT_NAME_TEMPLATE
)) {
6139 assert(u
->instance
); /* If we're not trying to use a template for non-instanced unit,
6140 * this must be set. */
6142 r
= unit_name_replace_instance(id
, u
->instance
, &free_id
);
6144 return log_debug_errno(r
, "Failed to build id (%s + %s): %m", id
, u
->instance
);
6150 r
= merge_by_names(&merged
, names
, id
);
6155 u
->load_state
= UNIT_MERGED
;
6160 void unit_dump_config_items(FILE *f
) {
6161 static const struct {
6162 const ConfigParserCallback callback
;
6165 { config_parse_warn_compat
, "NOTSUPPORTED" },
6166 { config_parse_int
, "INTEGER" },
6167 { config_parse_unsigned
, "UNSIGNED" },
6168 { config_parse_iec_size
, "SIZE" },
6169 { config_parse_iec_uint64
, "SIZE" },
6170 { config_parse_si_uint64
, "SIZE" },
6171 { config_parse_bool
, "BOOLEAN" },
6172 { config_parse_string
, "STRING" },
6173 { config_parse_path
, "PATH" },
6174 { config_parse_unit_path_printf
, "PATH" },
6175 { config_parse_colon_separated_paths
, "PATH" },
6176 { config_parse_strv
, "STRING [...]" },
6177 { config_parse_exec_nice
, "NICE" },
6178 { config_parse_exec_oom_score_adjust
, "OOMSCOREADJUST" },
6179 { config_parse_exec_io_class
, "IOCLASS" },
6180 { config_parse_exec_io_priority
, "IOPRIORITY" },
6181 { config_parse_exec_cpu_sched_policy
, "CPUSCHEDPOLICY" },
6182 { config_parse_exec_cpu_sched_prio
, "CPUSCHEDPRIO" },
6183 { config_parse_exec_cpu_affinity
, "CPUAFFINITY" },
6184 { config_parse_mode
, "MODE" },
6185 { config_parse_unit_env_file
, "FILE" },
6186 { config_parse_exec_output
, "OUTPUT" },
6187 { config_parse_exec_input
, "INPUT" },
6188 { config_parse_log_facility
, "FACILITY" },
6189 { config_parse_log_level
, "LEVEL" },
6190 { config_parse_exec_secure_bits
, "SECUREBITS" },
6191 { config_parse_capability_set
, "BOUNDINGSET" },
6192 { config_parse_rlimit
, "LIMIT" },
6193 { config_parse_unit_deps
, "UNIT [...]" },
6194 { config_parse_exec
, "PATH [ARGUMENT [...]]" },
6195 { config_parse_service_type
, "SERVICETYPE" },
6196 { config_parse_service_exit_type
, "SERVICEEXITTYPE" },
6197 { config_parse_service_restart
, "SERVICERESTART" },
6198 { config_parse_service_timeout_failure_mode
, "TIMEOUTMODE" },
6199 { config_parse_kill_mode
, "KILLMODE" },
6200 { config_parse_signal
, "SIGNAL" },
6201 { config_parse_socket_listen
, "SOCKET [...]" },
6202 { config_parse_socket_bind
, "SOCKETBIND" },
6203 { config_parse_socket_bindtodevice
, "NETWORKINTERFACE" },
6204 { config_parse_sec
, "SECONDS" },
6205 { config_parse_nsec
, "NANOSECONDS" },
6206 { config_parse_namespace_path_strv
, "PATH [...]" },
6207 { config_parse_bind_paths
, "PATH[:PATH[:OPTIONS]] [...]" },
6208 { config_parse_unit_requires_mounts_for
, "PATH [...]" },
6209 { config_parse_exec_mount_flags
, "MOUNTFLAG [...]" },
6210 { config_parse_unit_string_printf
, "STRING" },
6211 { config_parse_trigger_unit
, "UNIT" },
6212 { config_parse_timer
, "TIMER" },
6213 { config_parse_path_spec
, "PATH" },
6214 { config_parse_notify_access
, "ACCESS" },
6215 { config_parse_ip_tos
, "TOS" },
6216 { config_parse_unit_condition_path
, "CONDITION" },
6217 { config_parse_unit_condition_string
, "CONDITION" },
6218 { config_parse_unit_slice
, "SLICE" },
6219 { config_parse_documentation
, "URL" },
6220 { config_parse_service_timeout
, "SECONDS" },
6221 { config_parse_emergency_action
, "ACTION" },
6222 { config_parse_set_status
, "STATUS" },
6223 { config_parse_service_sockets
, "SOCKETS" },
6224 { config_parse_environ
, "ENVIRON" },
6226 { config_parse_syscall_filter
, "SYSCALLS" },
6227 { config_parse_syscall_archs
, "ARCHS" },
6228 { config_parse_syscall_errno
, "ERRNO" },
6229 { config_parse_syscall_log
, "SYSCALLS" },
6230 { config_parse_address_families
, "FAMILIES" },
6231 { config_parse_restrict_namespaces
, "NAMESPACES" },
6233 { config_parse_restrict_filesystems
, "FILESYSTEMS" },
6234 { config_parse_cpu_shares
, "SHARES" },
6235 { config_parse_cg_weight
, "WEIGHT" },
6236 { config_parse_memory_limit
, "LIMIT" },
6237 { config_parse_device_allow
, "DEVICE" },
6238 { config_parse_device_policy
, "POLICY" },
6239 { config_parse_io_limit
, "LIMIT" },
6240 { config_parse_io_device_weight
, "DEVICEWEIGHT" },
6241 { config_parse_io_device_latency
, "DEVICELATENCY" },
6242 { config_parse_blockio_bandwidth
, "BANDWIDTH" },
6243 { config_parse_blockio_weight
, "WEIGHT" },
6244 { config_parse_blockio_device_weight
, "DEVICEWEIGHT" },
6245 { config_parse_long
, "LONG" },
6246 { config_parse_socket_service
, "SERVICE" },
6248 { config_parse_exec_selinux_context
, "LABEL" },
6250 { config_parse_job_mode
, "MODE" },
6251 { config_parse_job_mode_isolate
, "BOOLEAN" },
6252 { config_parse_personality
, "PERSONALITY" },
6255 const char *prev
= NULL
;
6260 NULSTR_FOREACH(i
, load_fragment_gperf_nulstr
) {
6261 const char *rvalue
= "OTHER", *lvalue
;
6262 const ConfigPerfItem
*p
;
6265 assert_se(p
= load_fragment_gperf_lookup(i
, strlen(i
)));
6267 /* Hide legacy settings */
6268 if (p
->parse
== config_parse_warn_compat
&&
6269 p
->ltype
== DISABLED_LEGACY
)
6272 for (size_t j
= 0; j
< ELEMENTSOF(table
); j
++)
6273 if (p
->parse
== table
[j
].callback
) {
6274 rvalue
= table
[j
].rvalue
;
6278 dot
= strchr(i
, '.');
6279 lvalue
= dot
? dot
+ 1 : i
;
6282 size_t prefix_len
= dot
- i
;
6284 if (!prev
|| !strneq(prev
, i
, prefix_len
+1)) {
6288 fprintf(f
, "[%.*s]\n", (int) prefix_len
, i
);
6292 fprintf(f
, "%s=%s\n", lvalue
, rvalue
);
6297 int config_parse_cpu_affinity2(
6299 const char *filename
,
6301 const char *section
,
6302 unsigned section_line
,
6309 CPUSet
*affinity
= data
;
6313 (void) parse_cpu_set_extend(rvalue
, affinity
, true, unit
, filename
, line
, lvalue
);
6318 int config_parse_show_status(
6320 const char *filename
,
6322 const char *section
,
6323 unsigned section_line
,
6331 ShowStatus
*b
= data
;
6338 k
= parse_show_status(rvalue
, b
);
6340 log_syntax(unit
, LOG_WARNING
, filename
, line
, k
, "Failed to parse show status setting, ignoring: %s", rvalue
);
6345 int config_parse_output_restricted(
6347 const char *filename
,
6349 const char *section
,
6350 unsigned section_line
,
6357 ExecOutput t
, *eo
= data
;
6358 bool obsolete
= false;
6365 if (streq(rvalue
, "syslog")) {
6366 t
= EXEC_OUTPUT_JOURNAL
;
6368 } else if (streq(rvalue
, "syslog+console")) {
6369 t
= EXEC_OUTPUT_JOURNAL_AND_CONSOLE
;
6372 t
= exec_output_from_string(rvalue
);
6374 log_syntax(unit
, LOG_WARNING
, filename
, line
, t
, "Failed to parse output type, ignoring: %s", rvalue
);
6378 if (IN_SET(t
, EXEC_OUTPUT_SOCKET
, EXEC_OUTPUT_NAMED_FD
, EXEC_OUTPUT_FILE
, EXEC_OUTPUT_FILE_APPEND
, EXEC_OUTPUT_FILE_TRUNCATE
)) {
6379 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Standard output types socket, fd:, file:, append:, truncate: are not supported as defaults, ignoring: %s", rvalue
);
6385 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
6386 "Standard output type %s is obsolete, automatically updating to %s. Please update your configuration.",
6387 rvalue
, exec_output_to_string(t
));
6393 int config_parse_crash_chvt(
6395 const char *filename
,
6397 const char *section
,
6398 unsigned section_line
,
6412 r
= parse_crash_chvt(rvalue
, data
);
6414 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse CrashChangeVT= setting, ignoring: %s", rvalue
);
6419 int config_parse_swap_priority(
6421 const char *filename
,
6423 const char *section
,
6424 unsigned section_line
,
6440 if (isempty(rvalue
)) {
6441 s
->parameters_fragment
.priority
= -1;
6442 s
->parameters_fragment
.priority_set
= false;
6446 r
= safe_atoi(rvalue
, &priority
);
6448 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid swap priority '%s', ignoring.", rvalue
);
6452 if (priority
< -1) {
6453 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
);
6457 if (priority
> 32767) {
6458 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Swap priority out of range, ignoring: %s", rvalue
);
6462 s
->parameters_fragment
.priority
= priority
;
6463 s
->parameters_fragment
.priority_set
= true;
6467 int config_parse_watchdog_sec(
6469 const char *filename
,
6471 const char *section
,
6472 unsigned section_line
,
6479 usec_t
*usec
= data
;
6485 /* This is called for {Runtime,Reboot,KExec}WatchdogSec= where "default" maps to
6486 * USEC_INFINITY internally. */
6488 if (streq(rvalue
, "default"))
6489 *usec
= USEC_INFINITY
;
6490 else if (streq(rvalue
, "off"))
6493 return config_parse_sec(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
);
6498 int config_parse_tty_size(
6500 const char *filename
,
6502 const char *section
,
6503 unsigned section_line
,
6510 unsigned *sz
= data
;
6516 if (isempty(rvalue
)) {
6521 return config_parse_unsigned(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
);