1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
3 Copyright © 2012 Holger Hans Peter Freyther
11 #include "sd-messages.h"
14 #include "all-units.h"
15 #include "alloc-util.h"
16 #include "bpf-program.h"
17 #include "bpf-restrict-fs.h"
18 #include "bus-error.h"
19 #include "calendarspec.h"
21 #include "capability-util.h"
22 #include "cgroup-setup.h"
23 #include "condition.h"
24 #include "conf-parser.h"
25 #include "coredump-util.h"
26 #include "cpu-set-util.h"
27 #include "creds-util.h"
28 #include "dissect-image.h"
31 #include "exec-credential.h"
33 #include "extract-word.h"
35 #include "firewall-util.h"
36 #include "fstab-util.h"
38 #include "hexdecoct.h"
39 #include "hostname-util.h"
40 #include "ioprio-util.h"
41 #include "iovec-util.h"
42 #include "ip-protocol-list.h"
43 #include "journal-file.h"
44 #include "limits-util.h"
45 #include "load-fragment.h"
48 #include "mountpoint-util.h"
50 #include "nulstr-util.h"
51 #include "open-file.h"
52 #include "ordered-set.h"
53 #include "parse-helpers.h"
54 #include "parse-util.h"
55 #include "path-util.h"
56 #include "pcre2-util.h"
57 #include "percent-util.h"
58 #include "process-util.h"
59 #include "reboot-util.h"
60 #include "seccomp-util.h"
61 #include "securebits-util.h"
62 #include "selinux-util.h"
64 #include "show-status.h"
65 #include "signal-util.h"
66 #include "socket-netlink.h"
67 #include "specifier.h"
68 #include "stat-util.h"
69 #include "string-util.h"
71 #include "syslog-util.h"
72 #include "time-util.h"
73 #include "unit-name.h"
74 #include "unit-printf.h"
75 #include "user-util.h"
78 static int parse_socket_protocol(const char *s
) {
81 r
= parse_ip_protocol(s
);
84 if (!IN_SET(r
, IPPROTO_UDPLITE
, IPPROTO_SCTP
, IPPROTO_MPTCP
))
85 return -EPROTONOSUPPORT
;
90 int parse_crash_chvt(const char *value
, int *data
) {
93 if (safe_atoi(value
, data
) >= 0)
96 b
= parse_boolean(value
);
101 *data
= 0; /* switch to where kmsg goes */
103 *data
= -1; /* turn off switching */
108 int parse_confirm_spawn(const char *value
, char **console
) {
112 r
= value
? parse_boolean(value
) : 1;
116 } else if (r
> 0) /* on with default tty */
117 s
= strdup("/dev/console");
118 else if (is_path(value
)) /* on with fully qualified path */
120 else /* on with only a tty file name, not a fully qualified path */
121 s
= path_join("/dev/", value
);
129 DEFINE_CONFIG_PARSE(config_parse_socket_protocol
, parse_socket_protocol
);
130 DEFINE_CONFIG_PARSE(config_parse_exec_secure_bits
, secure_bits_from_string
);
131 DEFINE_CONFIG_PARSE_ENUM(config_parse_collect_mode
, collect_mode
, CollectMode
);
132 DEFINE_CONFIG_PARSE_ENUM(config_parse_device_policy
, cgroup_device_policy
, CGroupDevicePolicy
);
133 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_keyring_mode
, exec_keyring_mode
, ExecKeyringMode
);
134 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_proc
, protect_proc
, ProtectProc
);
135 DEFINE_CONFIG_PARSE_ENUM(config_parse_proc_subset
, proc_subset
, ProcSubset
);
136 DEFINE_CONFIG_PARSE_ENUM(config_parse_private_tmp
, private_tmp
, PrivateTmp
);
137 DEFINE_CONFIG_PARSE_ENUM(config_parse_private_users
, private_users
, PrivateUsers
);
138 DEFINE_CONFIG_PARSE_ENUM(config_parse_private_pids
, private_pids
, PrivatePIDs
);
139 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_control_groups
, protect_control_groups
, ProtectControlGroups
);
140 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_utmp_mode
, exec_utmp_mode
, ExecUtmpMode
);
141 DEFINE_CONFIG_PARSE_ENUM(config_parse_job_mode
, job_mode
, JobMode
);
142 DEFINE_CONFIG_PARSE_ENUM(config_parse_notify_access
, notify_access
, NotifyAccess
);
143 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_home
, protect_home
, ProtectHome
);
144 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_system
, protect_system
, ProtectSystem
);
145 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_preserve_mode
, exec_preserve_mode
, ExecPreserveMode
);
146 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_type
, service_type
, ServiceType
);
147 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_exit_type
, service_exit_type
, ServiceExitType
);
148 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart
, service_restart
, ServiceRestart
);
149 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart_mode
, service_restart_mode
, ServiceRestartMode
);
150 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_timeout_failure_mode
, service_timeout_failure_mode
, ServiceTimeoutFailureMode
);
151 DEFINE_CONFIG_PARSE_ENUM(config_parse_socket_bind
, socket_address_bind_ipv6_only_or_bool
, SocketAddressBindIPv6Only
);
152 DEFINE_CONFIG_PARSE_ENUM(config_parse_oom_policy
, oom_policy
, OOMPolicy
);
153 DEFINE_CONFIG_PARSE_ENUM(config_parse_managed_oom_preference
, managed_oom_preference
, ManagedOOMPreference
);
154 DEFINE_CONFIG_PARSE_ENUM(config_parse_memory_pressure_watch
, cgroup_pressure_watch
, CGroupPressureWatch
);
155 DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_ip_tos
, ip_tos
, int, -1);
156 DEFINE_CONFIG_PARSE_PTR(config_parse_cg_weight
, cg_weight_parse
, uint64_t);
157 DEFINE_CONFIG_PARSE_PTR(config_parse_cg_cpu_weight
, cg_cpu_weight_parse
, uint64_t);
158 DEFINE_CONFIG_PARSE_PTR(config_parse_exec_mount_propagation_flag
, mount_propagation_flag_from_string
, unsigned long);
159 DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_numa_policy
, mpol
, int, -1);
160 DEFINE_CONFIG_PARSE_ENUM(config_parse_status_unit_format
, status_unit_format
, StatusUnitFormat
);
161 DEFINE_CONFIG_PARSE_ENUM_FULL(config_parse_socket_timestamping
, socket_timestamping_from_string_harder
, SocketTimestamping
);
163 bool contains_instance_specifier_superset(const char *s
) {
165 bool percent
= false;
179 /* If the string is just the instance specifier, it's not a superset of the instance. */
180 if (memcmp_nn(p
, q
- p
, "%i", strlen("%i")) == 0)
183 /* %i, %n and %N all expand to the instance or a superset of it. */
188 if (IN_SET(*p
, 'n', 'N', 'i'))
196 /* `name` is the rendered version of `format` via `unit_printf` or similar functions. */
197 int unit_is_likely_recursive_template_dependency(Unit
*u
, const char *name
, const char *format
) {
198 const char *fragment_path
;
204 /* If a template unit has a direct dependency on itself that includes the unit instance as part of
205 * the template instance via a unit specifier (%i, %n or %N), this will almost certainly lead to
206 * infinite recursion as systemd will keep instantiating new instances of the template unit.
207 * https://github.com/systemd/systemd/issues/17602 shows a good example of how this can happen in
208 * practice. To guard against this, we check for templates that depend on themselves and have the
209 * instantiated unit instance included as part of the template instance of the dependency via a
212 * For example, if systemd-notify@.service depends on systemd-notify@%n.service, this will result in
213 * infinite recursion.
216 if (!unit_name_is_valid(name
, UNIT_NAME_INSTANCE
))
219 if (!unit_name_prefix_equal(u
->id
, name
))
222 if (u
->type
!= unit_name_to_type(name
))
225 r
= unit_file_find_fragment(u
->manager
->unit_id_map
, u
->manager
->unit_name_map
, name
, &fragment_path
, NULL
);
229 /* Fragment paths should also be equal as a custom fragment for a specific template instance
230 * wouldn't necessarily lead to infinite recursion. */
231 if (!path_equal(u
->fragment_path
, fragment_path
))
234 if (!contains_instance_specifier_superset(format
))
240 int config_parse_unit_deps(
242 const char *filename
,
245 unsigned section_line
,
252 UnitDependency d
= ltype
;
259 for (const char *p
= rvalue
;;) {
260 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
263 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_RETAIN_ESCAPE
);
269 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
273 r
= unit_name_printf(u
, word
, &k
);
275 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
279 r
= unit_is_likely_recursive_template_dependency(u
, k
, word
);
281 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to determine if '%s' is a recursive dependency, ignoring: %m", k
);
285 log_syntax(unit
, LOG_DEBUG
, filename
, line
, 0,
286 "Dropping dependency %s=%s that likely leads to infinite recursion.",
287 unit_dependency_to_string(d
), word
);
291 r
= unit_add_dependency_by_name(u
, d
, k
, true, UNIT_DEPENDENCY_FILE
);
293 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
297 int config_parse_obsolete_unit_deps(
299 const char *filename
,
302 unsigned section_line
,
309 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
310 "Unit dependency type %s= is obsolete, replacing by %s=, please update your unit file", lvalue
, unit_dependency_to_string(ltype
));
312 return config_parse_unit_deps(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
);
315 int config_parse_unit_string_printf(
317 const char *filename
,
320 unsigned section_line
,
327 _cleanup_free_
char *k
= NULL
;
328 const Unit
*u
= ASSERT_PTR(userdata
);
335 r
= unit_full_printf(u
, rvalue
, &k
);
337 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
341 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
344 int config_parse_reboot_parameter(
346 const char *filename
,
349 unsigned section_line
,
356 _cleanup_free_
char *k
= NULL
;
357 const Unit
*u
= ASSERT_PTR(userdata
);
364 r
= unit_full_printf(u
, rvalue
, &k
);
366 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
370 if (!reboot_parameter_is_valid(k
)) {
371 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid reboot parameter '%s', ignoring.", k
);
375 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
378 int config_parse_unit_strv_printf(
380 const char *filename
,
383 unsigned section_line
,
390 const Unit
*u
= ASSERT_PTR(userdata
);
391 _cleanup_free_
char *k
= NULL
;
398 r
= unit_full_printf(u
, rvalue
, &k
);
400 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
404 return config_parse_strv(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
407 int config_parse_unit_path_printf(
409 const char *filename
,
412 unsigned section_line
,
419 _cleanup_free_
char *k
= NULL
;
420 const Unit
*u
= ASSERT_PTR(userdata
);
428 r
= unit_path_printf(u
, rvalue
, &k
);
430 log_syntax(unit
, fatal
? LOG_ERR
: LOG_WARNING
, filename
, line
, r
,
431 "Failed to resolve unit specifiers in '%s'%s: %m",
432 rvalue
, fatal
? "" : ", ignoring");
433 return fatal
? -ENOEXEC
: 0;
436 return config_parse_path(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
439 int config_parse_colon_separated_paths(
441 const char *filename
,
444 unsigned section_line
,
451 char ***sv
= ASSERT_PTR(data
);
452 const Unit
*u
= ASSERT_PTR(userdata
);
459 if (isempty(rvalue
)) {
460 /* Empty assignment resets the list */
461 *sv
= strv_free(*sv
);
465 for (const char *p
= rvalue
;;) {
466 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
468 r
= extract_first_word(&p
, &word
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
472 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
478 r
= unit_path_printf(u
, word
, &k
);
480 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
481 "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
485 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
489 r
= strv_consume(sv
, TAKE_PTR(k
));
497 int config_parse_unit_path_strv_printf(
499 const char *filename
,
502 unsigned section_line
,
510 const Unit
*u
= ASSERT_PTR(userdata
);
517 if (isempty(rvalue
)) {
522 for (const char *p
= rvalue
;;) {
523 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
525 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
531 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
532 "Invalid syntax, ignoring: %s", rvalue
);
536 r
= unit_path_printf(u
, word
, &k
);
538 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
539 "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
543 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
547 r
= strv_consume(x
, TAKE_PTR(k
));
553 static int patch_var_run(
555 const char *filename
,
563 e
= path_startswith(*path
, "/var/run/");
567 z
= path_join("/run/", e
);
571 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
572 "%s= references a path below legacy directory /var/run/, updating %s → %s; "
573 "please update the unit file accordingly.", lvalue
, *path
, z
);
575 free_and_replace(*path
, z
);
580 int config_parse_socket_listen(
582 const char *filename
,
585 unsigned section_line
,
592 Socket
*s
= ASSERT_PTR(SOCKET(data
));
593 _cleanup_free_ SocketPort
*p
= NULL
;
600 if (isempty(rvalue
)) {
601 /* An empty assignment removes all ports */
602 socket_free_ports(s
);
606 p
= new(SocketPort
, 1);
615 if (ltype
!= SOCKET_SOCKET
) {
616 _cleanup_free_
char *k
= NULL
;
618 r
= unit_path_printf(UNIT(s
), rvalue
, &k
);
620 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
624 PathSimplifyWarnFlags flags
= PATH_CHECK_ABSOLUTE
;
625 if (ltype
!= SOCKET_SPECIAL
)
626 flags
|= PATH_CHECK_NON_API_VFS
;
628 r
= path_simplify_and_warn(k
, flags
, unit
, filename
, line
, lvalue
);
632 if (ltype
== SOCKET_FIFO
) {
633 r
= patch_var_run(unit
, filename
, line
, lvalue
, &k
);
638 free_and_replace(p
->path
, k
);
641 } else if (streq(lvalue
, "ListenNetlink")) {
642 _cleanup_free_
char *k
= NULL
;
644 r
= unit_path_printf(UNIT(s
), rvalue
, &k
);
646 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
650 r
= socket_address_parse_netlink(&p
->address
, k
);
652 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse address value in '%s', ignoring: %m", k
);
656 p
->type
= SOCKET_SOCKET
;
659 _cleanup_free_
char *k
= NULL
;
661 r
= unit_path_printf(UNIT(s
), rvalue
, &k
);
663 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
667 if (path_is_absolute(k
)) { /* Only for AF_UNIX file system sockets… */
668 r
= patch_var_run(unit
, filename
, line
, lvalue
, &k
);
673 r
= socket_address_parse_and_warn(&p
->address
, k
);
675 if (r
!= -EAFNOSUPPORT
)
676 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse address value in '%s', ignoring: %m", k
);
680 if (streq(lvalue
, "ListenStream"))
681 p
->address
.type
= SOCK_STREAM
;
682 else if (streq(lvalue
, "ListenDatagram"))
683 p
->address
.type
= SOCK_DGRAM
;
685 assert(streq(lvalue
, "ListenSequentialPacket"));
686 p
->address
.type
= SOCK_SEQPACKET
;
689 if (socket_address_family(&p
->address
) != AF_UNIX
&& p
->address
.type
== SOCK_SEQPACKET
) {
690 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Address family not supported, ignoring: %s", rvalue
);
694 p
->type
= SOCKET_SOCKET
;
697 LIST_APPEND(port
, s
->ports
, TAKE_PTR(p
));
701 int config_parse_exec_nice(
703 const char *filename
,
706 unsigned section_line
,
713 ExecContext
*c
= ASSERT_PTR(data
);
720 if (isempty(rvalue
)) {
725 r
= parse_nice(rvalue
, &priority
);
728 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Nice priority out of range, ignoring: %s", rvalue
);
730 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse nice priority '%s', ignoring: %m", rvalue
);
740 int config_parse_exec_oom_score_adjust(
742 const char *filename
,
745 unsigned section_line
,
752 ExecContext
*c
= ASSERT_PTR(data
);
759 if (isempty(rvalue
)) {
760 c
->oom_score_adjust_set
= false;
764 r
= parse_oom_score_adjust(rvalue
, &oa
);
767 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "OOM score adjust value out of range, ignoring: %s", rvalue
);
769 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse the OOM score adjust value '%s', ignoring: %m", rvalue
);
773 c
->oom_score_adjust
= oa
;
774 c
->oom_score_adjust_set
= true;
779 int config_parse_exec_coredump_filter(
781 const char *filename
,
784 unsigned section_line
,
791 ExecContext
*c
= ASSERT_PTR(data
);
798 if (isempty(rvalue
)) {
799 c
->coredump_filter
= 0;
800 c
->coredump_filter_set
= false;
805 r
= coredump_filter_mask_from_string(rvalue
, &f
);
807 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
808 "Failed to parse the CoredumpFilter=%s, ignoring: %m", rvalue
);
812 c
->coredump_filter
|= f
;
813 c
->coredump_filter_set
= true;
817 int config_parse_kill_mode(
819 const char *filename
,
822 unsigned section_line
,
829 KillMode
*k
= data
, m
;
836 if (isempty(rvalue
)) {
837 *k
= KILL_CONTROL_GROUP
;
841 m
= kill_mode_from_string(rvalue
);
843 log_syntax(unit
, LOG_WARNING
, filename
, line
, m
,
844 "Failed to parse kill mode specification, ignoring: %s", rvalue
);
849 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
850 "Unit uses KillMode=none. "
851 "This is unsafe, as it disables systemd's process lifecycle management for the service. "
852 "Please update the service to use a safer KillMode=, such as 'mixed' or 'control-group'. "
853 "Support for KillMode=none is deprecated and will eventually be removed.");
859 int config_parse_exec(
861 const char *filename
,
864 unsigned section_line
,
871 ExecCommand
**e
= ASSERT_PTR(data
);
872 const Unit
*u
= ASSERT_PTR(userdata
);
881 if (isempty(rvalue
)) {
882 /* An empty assignment resets the list */
883 *e
= exec_command_free_list(*e
);
887 const char *p
= rvalue
;
891 _cleanup_free_
char *firstword
= NULL
;
895 r
= extract_first_word_and_warn(&p
, &firstword
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
899 /* A lone ";" is a separator. Let's make sure we don't treat it as an executable name.
901 * SOFT DEPRECATION: We support multiple command lines in one ExecStart= line for
902 * compatibility with older versions, but we no longer document this exists, it's deprecated
903 * in a soft way. New unit files, should not use this feature. */
904 if (streq(firstword
, ";")) {
909 const char *f
= firstword
;
910 bool ignore
, separate_argv0
= false, ambient_hack
= false;
911 ExecCommandFlags flags
= 0;
914 /* We accept an absolute path as first argument. Valid prefixes and their effect:
916 * "-": Ignore if the path doesn't exist
917 * "@": Allow overriding argv[0] (supplied as a separate argument)
918 * "|": Prefix the cmdline with target user's shell (when combined with "@" invoke
919 * login shell semantics)
920 * ":": Disable environment variable substitution
921 * "+": Run with full privileges and no sandboxing
922 * "!": Apply sandboxing except for user/group credentials
925 if (*f
== '-' && !FLAGS_SET(flags
, EXEC_COMMAND_IGNORE_FAILURE
))
926 flags
|= EXEC_COMMAND_IGNORE_FAILURE
;
927 else if (*f
== '@' && !separate_argv0
)
928 separate_argv0
= true;
929 else if (*f
== ':' && !FLAGS_SET(flags
, EXEC_COMMAND_NO_ENV_EXPAND
))
930 flags
|= EXEC_COMMAND_NO_ENV_EXPAND
;
931 else if (*f
== '|' && !FLAGS_SET(flags
, EXEC_COMMAND_VIA_SHELL
))
932 flags
|= EXEC_COMMAND_VIA_SHELL
;
933 else if (*f
== '+' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
)) && !ambient_hack
)
934 flags
|= EXEC_COMMAND_FULLY_PRIVILEGED
;
935 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
)) && !ambient_hack
)
936 flags
|= EXEC_COMMAND_NO_SETUID
;
937 else if (*f
== '!' && !FLAGS_SET(flags
, EXEC_COMMAND_FULLY_PRIVILEGED
) && !ambient_hack
) {
938 /* Compatibility with the old !! ambient caps hack (removed in v258). Since
939 * we don't support that anymore and !! was a noop on non-supporting systems,
940 * we'll just turn off the EXEC_COMMAND_NO_SETUID flag again and be done with
942 flags
&= ~EXEC_COMMAND_NO_SETUID
;
945 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
946 "The !! modifier for %s= lines is no longer supported and is now ignored. "
947 "Please update your unit files and remove the modifier.", lvalue
);
952 ignore
= FLAGS_SET(flags
, EXEC_COMMAND_IGNORE_FAILURE
);
954 _cleanup_strv_free_
char **args
= NULL
;
955 _cleanup_free_
char *path
= NULL
;
957 if (FLAGS_SET(flags
, EXEC_COMMAND_VIA_SHELL
)) {
958 /* Use _PATH_BSHELL as placeholder since we can't do NSS lookups in pid1. This would
959 * be exported to various dbus properties and is used to determine SELinux label -
960 * which isn't accurate, but is a best-effort thing to assume all shells have more
961 * or less the same label. */
962 path
= strdup(_PATH_BSHELL
);
966 if (strv_extend_many(&args
, separate_argv0
? "-sh" : "sh", empty_to_null(f
)) < 0)
969 r
= unit_path_printf(u
, f
, &path
);
971 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
972 "Failed to resolve unit specifiers in '%s'%s: %m",
973 f
, ignore
? ", ignoring" : "");
974 return ignore
? 0 : -ENOEXEC
;
978 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
979 "Empty path in command line%s: %s",
980 ignore
? ", ignoring" : "", rvalue
);
981 return ignore
? 0 : -ENOEXEC
;
983 if (!string_is_safe(path
)) {
984 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
985 "Executable path contains special characters%s: %s",
986 ignore
? ", ignoring" : "", path
);
987 return ignore
? 0 : -ENOEXEC
;
989 if (path_implies_directory(path
)) {
990 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
991 "Executable path specifies a directory%s: %s",
992 ignore
? ", ignoring" : "", path
);
993 return ignore
? 0 : -ENOEXEC
;
996 if (!filename_or_absolute_path_is_valid(path
)) {
997 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
998 "Neither a valid executable name nor an absolute path%s: %s",
999 ignore
? ", ignoring" : "", path
);
1000 return ignore
? 0 : -ENOEXEC
;
1003 if (!separate_argv0
)
1004 if (strv_extend(&args
, path
) < 0)
1008 while (!isempty(p
)) {
1009 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
1011 /* Check explicitly for an unquoted semicolon as command separator token. */
1012 if (p
[0] == ';' && (!p
[1] || strchr(WHITESPACE
, p
[1]))) {
1014 p
= skip_leading_chars(p
, /* bad = */ NULL
);
1019 /* Check for \; explicitly, to not confuse it with \\; or "\;" or "\\;" etc.
1020 * extract_first_word() would return the same for all of those. */
1021 if (p
[0] == '\\' && p
[1] == ';' && (!p
[2] || strchr(WHITESPACE
, p
[2]))) {
1023 p
= skip_leading_chars(p
, /* bad = */ NULL
);
1025 if (strv_extend(&args
, ";") < 0)
1031 r
= extract_first_word_and_warn(&p
, &word
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
1033 return ignore
? 0 : -ENOEXEC
;
1037 r
= unit_full_printf(u
, word
, &resolved
);
1039 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
1040 "Failed to resolve unit specifiers in '%s'%s: %m",
1041 word
, ignore
? ", ignoring" : "");
1042 return ignore
? 0 : -ENOEXEC
;
1045 if (strv_consume(&args
, TAKE_PTR(resolved
)) < 0)
1049 if (strv_isempty(args
)) {
1050 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
1051 "Empty executable name or zeroeth argument%s: %s",
1052 ignore
? ", ignoring" : "", rvalue
);
1053 return ignore
? 0 : -ENOEXEC
;
1056 ExecCommand
*nec
= new(ExecCommand
, 1);
1060 *nec
= (ExecCommand
) {
1061 .path
= path_simplify(TAKE_PTR(path
)),
1062 .argv
= TAKE_PTR(args
),
1066 exec_command_append_list(e
, nec
);
1069 } while (semicolon
);
1074 int config_parse_socket_bindtodevice(
1076 const char *filename
,
1078 const char *section
,
1079 unsigned section_line
,
1086 _cleanup_free_
char *p
= NULL
;
1087 Socket
*s
= ASSERT_PTR(data
);
1094 if (isempty(rvalue
) || streq(rvalue
, "*")) {
1095 s
->bind_to_device
= mfree(s
->bind_to_device
);
1099 r
= unit_full_printf(UNIT(s
), rvalue
, &p
);
1101 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
1105 if (!ifname_valid(p
)) {
1106 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid interface name, ignoring: %s", p
);
1110 return free_and_replace(s
->bind_to_device
, p
);
1113 int config_parse_exec_input(
1115 const char *filename
,
1117 const char *section
,
1118 unsigned section_line
,
1125 ExecContext
*c
= ASSERT_PTR(data
);
1126 const Unit
*u
= userdata
;
1135 n
= startswith(rvalue
, "fd:");
1137 _cleanup_free_
char *resolved
= NULL
;
1139 r
= unit_fd_printf(u
, n
, &resolved
);
1141 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", n
);
1145 if (isempty(resolved
))
1146 resolved
= mfree(resolved
);
1147 else if (!fdname_is_valid(resolved
)) {
1148 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", resolved
);
1152 free_and_replace(c
->stdio_fdname
[STDIN_FILENO
], resolved
);
1154 ei
= EXEC_INPUT_NAMED_FD
;
1156 } else if ((n
= startswith(rvalue
, "file:"))) {
1157 _cleanup_free_
char *resolved
= NULL
;
1159 r
= unit_path_printf(u
, n
, &resolved
);
1161 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", n
);
1165 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1169 free_and_replace(c
->stdio_file
[STDIN_FILENO
], resolved
);
1171 ei
= EXEC_INPUT_FILE
;
1174 ei
= exec_input_from_string(rvalue
);
1176 log_syntax(unit
, LOG_WARNING
, filename
, line
, ei
, "Failed to parse input specifier, ignoring: %s", rvalue
);
1185 int config_parse_exec_input_text(
1187 const char *filename
,
1189 const char *section
,
1190 unsigned section_line
,
1197 _cleanup_free_
char *unescaped
= NULL
, *resolved
= NULL
;
1198 ExecContext
*c
= ASSERT_PTR(data
);
1199 const Unit
*u
= userdata
;
1206 if (isempty(rvalue
)) {
1207 /* Reset if the empty string is assigned */
1208 c
->stdin_data
= mfree(c
->stdin_data
);
1209 c
->stdin_data_size
= 0;
1213 ssize_t l
= cunescape(rvalue
, 0, &unescaped
);
1215 log_syntax(unit
, LOG_WARNING
, filename
, line
, l
,
1216 "Failed to decode C escaped text '%s', ignoring: %m", rvalue
);
1220 r
= unit_full_printf_full(u
, unescaped
, EXEC_STDIN_DATA_MAX
, &resolved
);
1222 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1223 "Failed to resolve unit specifiers in '%s', ignoring: %m", unescaped
);
1227 size_t sz
= strlen(resolved
);
1228 if (c
->stdin_data_size
+ sz
+ 1 < c
->stdin_data_size
|| /* check for overflow */
1229 c
->stdin_data_size
+ sz
+ 1 > EXEC_STDIN_DATA_MAX
) {
1230 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
1231 "Standard input data too large (%zu), maximum of %zu permitted, ignoring.",
1232 c
->stdin_data_size
+ sz
, (size_t) EXEC_STDIN_DATA_MAX
);
1236 void *p
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
+ 1);
1240 *((char*) mempcpy((char*) p
+ c
->stdin_data_size
, resolved
, sz
)) = '\n';
1243 c
->stdin_data_size
+= sz
+ 1;
1248 int config_parse_exec_input_data(
1250 const char *filename
,
1252 const char *section
,
1253 unsigned section_line
,
1260 _cleanup_free_
void *p
= NULL
;
1261 ExecContext
*c
= ASSERT_PTR(data
);
1270 if (isempty(rvalue
)) {
1271 /* Reset if the empty string is assigned */
1272 c
->stdin_data
= mfree(c
->stdin_data
);
1273 c
->stdin_data_size
= 0;
1277 r
= unbase64mem(rvalue
, &p
, &sz
);
1279 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1280 "Failed to decode base64 data, ignoring: %s", rvalue
);
1286 if (c
->stdin_data_size
+ sz
< c
->stdin_data_size
|| /* check for overflow */
1287 c
->stdin_data_size
+ sz
> EXEC_STDIN_DATA_MAX
) {
1288 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
1289 "Standard input data too large (%zu), maximum of %zu permitted, ignoring.",
1290 c
->stdin_data_size
+ sz
, (size_t) EXEC_STDIN_DATA_MAX
);
1294 q
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
);
1298 memcpy((uint8_t*) q
+ c
->stdin_data_size
, p
, sz
);
1301 c
->stdin_data_size
+= sz
;
1306 int config_parse_exec_output(
1308 const char *filename
,
1310 const char *section
,
1311 unsigned section_line
,
1318 _cleanup_free_
char *resolved
= NULL
;
1320 ExecContext
*c
= ASSERT_PTR(data
);
1321 const Unit
*u
= userdata
;
1322 bool obsolete
= false;
1331 n
= startswith(rvalue
, "fd:");
1333 r
= unit_fd_printf(u
, n
, &resolved
);
1335 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", n
);
1339 if (isempty(resolved
))
1340 resolved
= mfree(resolved
);
1341 else if (!fdname_is_valid(resolved
)) {
1342 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", resolved
);
1346 eo
= EXEC_OUTPUT_NAMED_FD
;
1348 } else if (streq(rvalue
, "syslog")) {
1349 eo
= EXEC_OUTPUT_JOURNAL
;
1352 } else if (streq(rvalue
, "syslog+console")) {
1353 eo
= EXEC_OUTPUT_JOURNAL_AND_CONSOLE
;
1356 } else if ((n
= startswith(rvalue
, "file:"))) {
1358 r
= unit_path_printf(u
, n
, &resolved
);
1360 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", n
);
1364 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1368 eo
= EXEC_OUTPUT_FILE
;
1370 } else if ((n
= startswith(rvalue
, "append:"))) {
1372 r
= unit_path_printf(u
, n
, &resolved
);
1374 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", n
);
1378 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1382 eo
= EXEC_OUTPUT_FILE_APPEND
;
1384 } else if ((n
= startswith(rvalue
, "truncate:"))) {
1386 r
= unit_path_printf(u
, n
, &resolved
);
1388 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", n
);
1392 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1396 eo
= EXEC_OUTPUT_FILE_TRUNCATE
;
1398 eo
= exec_output_from_string(rvalue
);
1400 log_syntax(unit
, LOG_WARNING
, filename
, line
, eo
, "Failed to parse output specifier, ignoring: %s", rvalue
);
1406 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
1407 "Standard output type %s is obsolete, automatically updating to %s. Please update your unit file, and consider removing the setting altogether.",
1408 rvalue
, exec_output_to_string(eo
));
1410 if (streq(lvalue
, "StandardOutput")) {
1411 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1412 free_and_replace(c
->stdio_fdname
[STDOUT_FILENO
], resolved
);
1414 free_and_replace(c
->stdio_file
[STDOUT_FILENO
], resolved
);
1419 assert(streq(lvalue
, "StandardError"));
1421 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1422 free_and_replace(c
->stdio_fdname
[STDERR_FILENO
], resolved
);
1424 free_and_replace(c
->stdio_file
[STDERR_FILENO
], resolved
);
1432 int config_parse_exec_io_class(
1434 const char *filename
,
1436 const char *section
,
1437 unsigned section_line
,
1444 ExecContext
*c
= ASSERT_PTR(data
);
1451 if (isempty(rvalue
)) {
1452 c
->ioprio_set
= false;
1453 c
->ioprio
= IOPRIO_DEFAULT_CLASS_AND_PRIO
;
1457 x
= ioprio_class_from_string(rvalue
);
1459 log_syntax(unit
, LOG_WARNING
, filename
, line
, x
, "Failed to parse IO scheduling class, ignoring: %s", rvalue
);
1463 c
->ioprio
= ioprio_normalize(ioprio_prio_value(x
, ioprio_prio_data(c
->ioprio
)));
1464 c
->ioprio_set
= true;
1469 int config_parse_exec_io_priority(
1471 const char *filename
,
1473 const char *section
,
1474 unsigned section_line
,
1481 ExecContext
*c
= ASSERT_PTR(data
);
1488 if (isempty(rvalue
)) {
1489 c
->ioprio_set
= false;
1490 c
->ioprio
= IOPRIO_DEFAULT_CLASS_AND_PRIO
;
1494 r
= ioprio_parse_priority(rvalue
, &i
);
1496 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse IO priority, ignoring: %s", rvalue
);
1500 c
->ioprio
= ioprio_normalize(ioprio_prio_value(ioprio_prio_class(c
->ioprio
), i
));
1501 c
->ioprio_set
= true;
1506 int config_parse_exec_cpu_sched_policy(
1508 const char *filename
,
1510 const char *section
,
1511 unsigned section_line
,
1518 ExecContext
*c
= ASSERT_PTR(data
);
1525 if (isempty(rvalue
)) {
1526 c
->cpu_sched_set
= false;
1527 c
->cpu_sched_policy
= SCHED_OTHER
;
1528 c
->cpu_sched_priority
= 0;
1532 x
= sched_policy_from_string(rvalue
);
1534 log_syntax(unit
, LOG_WARNING
, filename
, line
, x
, "Failed to parse CPU scheduling policy, ignoring: %s", rvalue
);
1538 c
->cpu_sched_policy
= x
;
1539 /* Moving to or from real-time policy? We need to adjust the priority */
1540 c
->cpu_sched_priority
= CLAMP(c
->cpu_sched_priority
, sched_get_priority_min(x
), sched_get_priority_max(x
));
1541 c
->cpu_sched_set
= true;
1546 int config_parse_numa_mask(
1548 const char *filename
,
1550 const char *section
,
1551 unsigned section_line
,
1558 CPUSet
*cpu_set
= ASSERT_PTR(data
);
1565 if (streq(rvalue
, "all")) {
1566 _cleanup_(cpu_set_done
) CPUSet c
= {};
1568 r
= numa_mask_add_all(&c
);
1570 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1571 "Failed to create NUMA mask representing \"all\" NUMA nodes, ignoring: %m");
1573 cpu_set_done(cpu_set
);
1574 *cpu_set
= TAKE_STRUCT(c
);
1578 /* When parsing system.conf or user.conf, rather than unit files, userdata is NULL. */
1580 config_parse_unit_cpu_set(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
) :
1581 config_parse_cpu_set(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
);
1584 int config_parse_exec_cpu_sched_prio(
1586 const char *filename
,
1588 const char *section
,
1589 unsigned section_line
,
1596 ExecContext
*c
= ASSERT_PTR(data
);
1603 r
= safe_atoi(rvalue
, &i
);
1605 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse CPU scheduling priority, ignoring: %s", rvalue
);
1609 /* On Linux RR/FIFO range from 1 to 99 and OTHER/BATCH may only be 0. Policy might be set later so
1610 * we do not check the precise range, but only the generic outer bounds. */
1611 if (i
< 0 || i
> 99) {
1612 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "CPU scheduling priority is out of range, ignoring: %s", rvalue
);
1616 c
->cpu_sched_priority
= i
;
1617 c
->cpu_sched_set
= true;
1622 int config_parse_root_image_options(
1624 const char *filename
,
1626 const char *section
,
1627 unsigned section_line
,
1634 _cleanup_(mount_options_free_allp
) MountOptions
*options
= NULL
;
1635 _cleanup_strv_free_
char **l
= NULL
;
1636 ExecContext
*c
= ASSERT_PTR(data
);
1637 const Unit
*u
= userdata
;
1644 if (isempty(rvalue
)) {
1645 c
->root_image_options
= mount_options_free_all(c
->root_image_options
);
1649 r
= strv_split_colon_pairs(&l
, rvalue
);
1653 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
1657 STRV_FOREACH_PAIR(first
, second
, l
) {
1658 MountOptions
*o
= NULL
;
1659 _cleanup_free_
char *mount_options_resolved
= NULL
;
1660 const char *mount_options
= NULL
, *partition
= "root";
1661 PartitionDesignator partition_designator
;
1663 /* Format is either 'root:foo' or 'foo' (root is implied) */
1664 if (!isempty(*second
)) {
1666 mount_options
= *second
;
1668 mount_options
= *first
;
1670 partition_designator
= partition_designator_from_string(partition
);
1671 if (partition_designator
< 0) {
1672 log_syntax(unit
, LOG_WARNING
, filename
, line
, partition_designator
,
1673 "Invalid partition name %s, ignoring", partition
);
1676 r
= unit_full_printf(u
, mount_options
, &mount_options_resolved
);
1678 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", mount_options
);
1682 o
= new(MountOptions
, 1);
1685 *o
= (MountOptions
) {
1686 .partition_designator
= partition_designator
,
1687 .options
= TAKE_PTR(mount_options_resolved
),
1689 LIST_APPEND(mount_options
, options
, TAKE_PTR(o
));
1693 LIST_JOIN(mount_options
, c
->root_image_options
, options
);
1695 /* empty spaces/separators only */
1696 c
->root_image_options
= mount_options_free_all(c
->root_image_options
);
1701 int config_parse_exec_root_hash(
1703 const char *filename
,
1705 const char *section
,
1706 unsigned section_line
,
1713 _cleanup_free_
void *roothash_decoded
= NULL
;
1714 ExecContext
*c
= ASSERT_PTR(data
);
1715 size_t roothash_decoded_size
= 0;
1722 if (isempty(rvalue
)) {
1723 /* Reset if the empty string is assigned */
1724 c
->root_hash_path
= mfree(c
->root_hash_path
);
1725 c
->root_hash
= mfree(c
->root_hash
);
1726 c
->root_hash_size
= 0;
1730 if (path_is_absolute(rvalue
)) {
1731 /* We have the path to a roothash to load and decode, eg: RootHash=/foo/bar.roothash */
1732 _cleanup_free_
char *p
= NULL
;
1738 free_and_replace(c
->root_hash_path
, p
);
1739 c
->root_hash
= mfree(c
->root_hash
);
1740 c
->root_hash_size
= 0;
1744 /* We have a roothash to decode, eg: RootHash=012345789abcdef */
1745 r
= unhexmem(rvalue
, &roothash_decoded
, &roothash_decoded_size
);
1747 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to decode RootHash=, ignoring: %s", rvalue
);
1750 if (roothash_decoded_size
< sizeof(sd_id128_t
)) {
1751 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "RootHash= is too short, ignoring: %s", rvalue
);
1755 free_and_replace(c
->root_hash
, roothash_decoded
);
1756 c
->root_hash_size
= roothash_decoded_size
;
1757 c
->root_hash_path
= mfree(c
->root_hash_path
);
1762 int config_parse_exec_root_hash_sig(
1764 const char *filename
,
1766 const char *section
,
1767 unsigned section_line
,
1774 _cleanup_free_
void *roothash_sig_decoded
= NULL
;
1776 ExecContext
*c
= ASSERT_PTR(data
);
1777 size_t roothash_sig_decoded_size
= 0;
1784 if (isempty(rvalue
)) {
1785 /* Reset if the empty string is assigned */
1786 c
->root_hash_sig_path
= mfree(c
->root_hash_sig_path
);
1787 c
->root_hash_sig
= mfree(c
->root_hash_sig
);
1788 c
->root_hash_sig_size
= 0;
1792 if (path_is_absolute(rvalue
)) {
1793 /* We have the path to a roothash signature to load and decode, eg: RootHashSignature=/foo/bar.roothash.p7s */
1794 _cleanup_free_
char *p
= NULL
;
1800 free_and_replace(c
->root_hash_sig_path
, p
);
1801 c
->root_hash_sig
= mfree(c
->root_hash_sig
);
1802 c
->root_hash_sig_size
= 0;
1806 if (!(value
= startswith(rvalue
, "base64:"))) {
1807 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
1808 "Failed to decode RootHashSignature=, not a path but doesn't start with 'base64:', ignoring: %s", rvalue
);
1812 /* We have a roothash signature to decode, eg: RootHashSignature=base64:012345789abcdef */
1813 r
= unbase64mem(value
, &roothash_sig_decoded
, &roothash_sig_decoded_size
);
1815 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to decode RootHashSignature=, ignoring: %s", rvalue
);
1819 free_and_replace(c
->root_hash_sig
, roothash_sig_decoded
);
1820 c
->root_hash_sig_size
= roothash_sig_decoded_size
;
1821 c
->root_hash_sig_path
= mfree(c
->root_hash_sig_path
);
1826 int config_parse_exec_cpu_affinity(
1828 const char *filename
,
1830 const char *section
,
1831 unsigned section_line
,
1838 ExecContext
*c
= ASSERT_PTR(data
);
1845 if (streq(rvalue
, "numa")) {
1846 c
->cpu_affinity_from_numa
= true;
1847 cpu_set_done(&c
->cpu_set
);
1851 r
= config_parse_unit_cpu_set(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, &c
->cpu_set
, userdata
);
1853 c
->cpu_affinity_from_numa
= false;
1858 int config_parse_capability_set(
1860 const char *filename
,
1862 const char *section
,
1863 unsigned section_line
,
1870 uint64_t *capability_set
= ASSERT_PTR(data
);
1871 uint64_t sum
= 0, initial
, def
;
1872 bool invert
= false;
1879 if (rvalue
[0] == '~') {
1884 if (streq(lvalue
, "CapabilityBoundingSet")) {
1885 initial
= CAP_MASK_ALL
; /* initialized to all bits on */
1886 def
= CAP_MASK_UNSET
; /* not set */
1888 def
= initial
= 0; /* All bits off */
1890 r
= capability_set_from_string(rvalue
, &sum
);
1892 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= specifier '%s', ignoring: %m", lvalue
, rvalue
);
1896 if (sum
== 0 || *capability_set
== def
)
1897 /* "", "~" or uninitialized data -> replace */
1898 *capability_set
= invert
? ~sum
: sum
;
1900 /* previous data -> merge */
1902 *capability_set
&= ~sum
;
1904 *capability_set
|= sum
;
1910 int config_parse_exec_selinux_context(
1912 const char *filename
,
1914 const char *section
,
1915 unsigned section_line
,
1922 ExecContext
*c
= ASSERT_PTR(data
);
1923 const Unit
*u
= userdata
;
1932 if (isempty(rvalue
)) {
1933 c
->selinux_context
= mfree(c
->selinux_context
);
1934 c
->selinux_context_ignore
= false;
1938 if (rvalue
[0] == '-') {
1944 r
= unit_full_printf(u
, rvalue
, &k
);
1946 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
1947 "Failed to resolve unit specifiers in '%s'%s: %m",
1948 rvalue
, ignore
? ", ignoring" : "");
1949 return ignore
? 0 : -ENOEXEC
;
1952 free_and_replace(c
->selinux_context
, k
);
1953 c
->selinux_context_ignore
= ignore
;
1958 int config_parse_exec_apparmor_profile(
1960 const char *filename
,
1962 const char *section
,
1963 unsigned section_line
,
1970 ExecContext
*c
= ASSERT_PTR(data
);
1971 const Unit
*u
= userdata
;
1980 if (isempty(rvalue
)) {
1981 c
->apparmor_profile
= mfree(c
->apparmor_profile
);
1982 c
->apparmor_profile_ignore
= false;
1986 if (rvalue
[0] == '-') {
1992 r
= unit_full_printf(u
, rvalue
, &k
);
1994 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
1995 "Failed to resolve unit specifiers in '%s'%s: %m",
1996 rvalue
, ignore
? ", ignoring" : "");
1997 return ignore
? 0 : -ENOEXEC
;
2000 free_and_replace(c
->apparmor_profile
, k
);
2001 c
->apparmor_profile_ignore
= ignore
;
2006 int config_parse_exec_smack_process_label(
2008 const char *filename
,
2010 const char *section
,
2011 unsigned section_line
,
2018 ExecContext
*c
= ASSERT_PTR(data
);
2019 const Unit
*u
= userdata
;
2028 if (isempty(rvalue
)) {
2029 c
->smack_process_label
= mfree(c
->smack_process_label
);
2030 c
->smack_process_label_ignore
= false;
2034 if (rvalue
[0] == '-') {
2040 r
= unit_full_printf(u
, rvalue
, &k
);
2042 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
2043 "Failed to resolve unit specifiers in '%s'%s: %m",
2044 rvalue
, ignore
? ", ignoring" : "");
2045 return ignore
? 0 : -ENOEXEC
;
2048 free_and_replace(c
->smack_process_label
, k
);
2049 c
->smack_process_label_ignore
= ignore
;
2054 int config_parse_timer(
2056 const char *filename
,
2058 const char *section
,
2059 unsigned section_line
,
2066 _cleanup_(calendar_spec_freep
) CalendarSpec
*c
= NULL
;
2067 _cleanup_free_
char *k
= NULL
;
2068 const Unit
*u
= userdata
;
2069 Timer
*t
= ASSERT_PTR(data
);
2078 if (isempty(rvalue
)) {
2079 /* Empty assignment resets list */
2080 timer_free_values(t
);
2084 r
= unit_full_printf(u
, rvalue
, &k
);
2086 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2090 if (ltype
== TIMER_CALENDAR
) {
2091 r
= calendar_spec_from_string(k
, &c
);
2093 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse calendar specification, ignoring: %s", k
);
2097 r
= parse_sec(k
, &usec
);
2099 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse timer value, ignoring: %s", k
);
2104 v
= new(TimerValue
, 1);
2111 .calendar_spec
= TAKE_PTR(c
),
2114 LIST_PREPEND(value
, t
->values
, v
);
2119 int config_parse_trigger_unit(
2121 const char *filename
,
2123 const char *section
,
2124 unsigned section_line
,
2131 _cleanup_free_
char *p
= NULL
;
2132 Unit
*u
= ASSERT_PTR(data
);
2140 if (UNIT_TRIGGER(u
)) {
2141 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Multiple units to trigger specified, ignoring: %s", rvalue
);
2145 r
= unit_name_printf(u
, rvalue
, &p
);
2147 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2151 type
= unit_name_to_type(p
);
2153 log_syntax(unit
, LOG_WARNING
, filename
, line
, type
, "Unit type not valid, ignoring: %s", rvalue
);
2156 if (unit_has_name(u
, p
)) {
2157 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Units cannot trigger themselves, ignoring: %s", rvalue
);
2161 r
= unit_add_two_dependencies_by_name(u
, UNIT_BEFORE
, UNIT_TRIGGERS
, p
, true, UNIT_DEPENDENCY_FILE
);
2163 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add trigger on %s, ignoring: %m", p
);
2170 int config_parse_path_spec(
2172 const char *filename
,
2174 const char *section
,
2175 unsigned section_line
,
2182 Path
*p
= ASSERT_PTR(data
);
2185 _cleanup_free_
char *k
= NULL
;
2192 if (isempty(rvalue
)) {
2193 /* Empty assignment clears list */
2198 b
= path_type_from_string(lvalue
);
2200 log_syntax(unit
, LOG_WARNING
, filename
, line
, b
, "Failed to parse path type, ignoring: %s", lvalue
);
2204 r
= unit_path_printf(UNIT(p
), rvalue
, &k
);
2206 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2210 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2214 s
= new0(PathSpec
, 1);
2219 s
->path
= TAKE_PTR(k
);
2221 s
->inotify_fd
= -EBADF
;
2223 LIST_PREPEND(spec
, p
->specs
, s
);
2228 int config_parse_socket_service(
2230 const char *filename
,
2232 const char *section
,
2233 unsigned section_line
,
2240 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
2241 _cleanup_free_
char *p
= NULL
;
2242 Socket
*s
= ASSERT_PTR(data
);
2250 r
= unit_name_printf(UNIT(s
), rvalue
, &p
);
2252 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2256 if (!endswith(p
, ".service")) {
2257 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Unit must be of type service, ignoring: %s", rvalue
);
2261 r
= manager_load_unit(UNIT(s
)->manager
, p
, NULL
, &error
, &x
);
2263 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to load unit %s, ignoring: %s", rvalue
, bus_error_message(&error
, r
));
2267 unit_ref_set(&s
->service
, UNIT(s
), x
);
2272 int config_parse_fdname(
2274 const char *filename
,
2276 const char *section
,
2277 unsigned section_line
,
2284 _cleanup_free_
char *p
= NULL
;
2285 Socket
*s
= ASSERT_PTR(data
);
2292 if (isempty(rvalue
)) {
2293 s
->fdname
= mfree(s
->fdname
);
2297 r
= unit_fd_printf(UNIT(s
), rvalue
, &p
);
2299 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2303 if (!fdname_is_valid(p
)) {
2304 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", p
);
2308 return free_and_replace(s
->fdname
, p
);
2311 int config_parse_service_sockets(
2313 const char *filename
,
2315 const char *section
,
2316 unsigned section_line
,
2323 Service
*s
= ASSERT_PTR(data
);
2330 for (const char *p
= rvalue
;;) {
2331 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2333 r
= extract_first_word(&p
, &word
, NULL
, 0);
2337 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Trailing garbage in sockets, ignoring: %s", rvalue
);
2343 r
= unit_name_printf(UNIT(s
), word
, &k
);
2345 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
2349 if (!endswith(k
, ".socket")) {
2350 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Unit must be of type socket, ignoring: %s", k
);
2354 r
= unit_add_two_dependencies_by_name(UNIT(s
), UNIT_WANTS
, UNIT_AFTER
, k
, true, UNIT_DEPENDENCY_FILE
);
2356 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
2358 r
= unit_add_dependency_by_name(UNIT(s
), UNIT_TRIGGERED_BY
, k
, true, UNIT_DEPENDENCY_FILE
);
2360 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
2364 int config_parse_bus_name(
2366 const char *filename
,
2368 const char *section
,
2369 unsigned section_line
,
2376 _cleanup_free_
char *k
= NULL
;
2377 const Unit
*u
= ASSERT_PTR(userdata
);
2384 r
= unit_full_printf_full(u
, rvalue
, SD_BUS_MAXIMUM_NAME_LENGTH
, &k
);
2386 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2390 if (!sd_bus_service_name_is_valid(k
)) {
2391 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid bus name, ignoring: %s", k
);
2395 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
2398 int config_parse_service_timeout(
2400 const char *filename
,
2402 const char *section
,
2403 unsigned section_line
,
2410 Service
*s
= ASSERT_PTR(userdata
);
2418 /* This is called for two cases: TimeoutSec= and TimeoutStartSec=. */
2420 /* Traditionally, these options accepted 0 to disable the timeouts. However, a timeout of 0 suggests it happens
2421 * immediately, hence fix this to become USEC_INFINITY instead. This is in-line with how we internally handle
2422 * all other timeouts. */
2423 r
= parse_sec_fix_0(rvalue
, &usec
);
2425 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
2429 s
->start_timeout_defined
= true;
2430 s
->timeout_start_usec
= usec
;
2432 if (streq(lvalue
, "TimeoutSec"))
2433 s
->timeout_stop_usec
= usec
;
2438 int config_parse_timeout_abort(
2440 const char *filename
,
2442 const char *section
,
2443 unsigned section_line
,
2450 usec_t
*ret
= ASSERT_PTR(data
);
2457 /* Note: apart from setting the arg, this returns an extra bit of information in the return value. */
2459 if (isempty(rvalue
)) {
2461 return 0; /* "not set" */
2464 r
= parse_sec(rvalue
, ret
);
2466 return log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= setting, ignoring: %s", lvalue
, rvalue
);
2468 return 1; /* "set" */
2471 int config_parse_service_timeout_abort(
2473 const char *filename
,
2475 const char *section
,
2476 unsigned section_line
,
2483 Service
*s
= ASSERT_PTR(userdata
);
2486 r
= config_parse_timeout_abort(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
,
2487 &s
->timeout_abort_usec
, s
);
2489 s
->timeout_abort_set
= r
;
2493 int config_parse_user_group_compat(
2495 const char *filename
,
2497 const char *section
,
2498 unsigned section_line
,
2505 _cleanup_free_
char *k
= NULL
;
2507 const Unit
*u
= ASSERT_PTR(userdata
);
2514 if (isempty(rvalue
)) {
2515 *user
= mfree(*user
);
2519 r
= unit_full_printf(u
, rvalue
, &k
);
2521 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", rvalue
);
2525 if (!valid_user_group_name(k
, VALID_USER_ALLOW_NUMERIC
|VALID_USER_RELAX
|VALID_USER_WARN
)) {
2526 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2530 if (strstr(lvalue
, "User") && streq(k
, NOBODY_USER_NAME
))
2531 log_struct(LOG_NOTICE
,
2532 LOG_MESSAGE("%s:%u: Special user %s configured, this is not safe!", filename
, line
, k
),
2533 LOG_MESSAGE_ID(SD_MESSAGE_NOBODY_USER_UNSUITABLE_STR
),
2534 LOG_ITEM("UNIT=%s", unit
),
2535 LOG_ITEM("OFFENDING_USER=%s", k
),
2536 LOG_ITEM("CONFIG_FILE=%s", filename
),
2537 LOG_ITEM("CONFIG_LINE=%u", line
));
2539 return free_and_replace(*user
, k
);
2542 int config_parse_user_group_strv_compat(
2544 const char *filename
,
2546 const char *section
,
2547 unsigned section_line
,
2554 char ***users
= data
;
2555 const Unit
*u
= ASSERT_PTR(userdata
);
2562 if (isempty(rvalue
)) {
2563 *users
= strv_free(*users
);
2567 for (const char *p
= rvalue
;;) {
2568 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2570 r
= extract_first_word(&p
, &word
, NULL
, 0);
2574 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax: %s", rvalue
);
2580 r
= unit_full_printf(u
, word
, &k
);
2582 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", word
);
2586 if (!valid_user_group_name(k
, VALID_USER_ALLOW_NUMERIC
|VALID_USER_RELAX
|VALID_USER_WARN
)) {
2587 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2591 r
= strv_push(users
, k
);
2599 int config_parse_working_directory(
2601 const char *filename
,
2603 const char *section
,
2604 unsigned section_line
,
2611 ExecContext
*c
= ASSERT_PTR(data
);
2612 const Unit
*u
= ASSERT_PTR(userdata
);
2620 if (isempty(rvalue
)) {
2621 c
->working_directory_missing_ok
= false;
2622 c
->working_directory_home
= false;
2623 c
->working_directory
= mfree(c
->working_directory
);
2627 if (rvalue
[0] == '-') {
2633 if (streq(rvalue
, "~")) {
2634 c
->working_directory_home
= true;
2635 c
->working_directory
= mfree(c
->working_directory
);
2637 _cleanup_free_
char *k
= NULL
;
2639 r
= unit_path_printf(u
, rvalue
, &k
);
2641 log_syntax(unit
, missing_ok
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
2642 "Failed to resolve unit specifiers in working directory path '%s'%s: %m",
2643 rvalue
, missing_ok
? ", ignoring" : "");
2644 return missing_ok
? 0 : -ENOEXEC
;
2647 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
|(missing_ok
? 0 : PATH_CHECK_FATAL
),
2648 unit
, filename
, line
, lvalue
);
2650 return missing_ok
? 0 : -ENOEXEC
;
2652 c
->working_directory_home
= false;
2653 free_and_replace(c
->working_directory
, k
);
2656 c
->working_directory_missing_ok
= missing_ok
;
2660 int config_parse_unit_env_file(
2662 const char *filename
,
2664 const char *section
,
2665 unsigned section_line
,
2672 char ***env
= ASSERT_PTR(data
);
2673 const Unit
*u
= userdata
;
2674 _cleanup_free_
char *n
= NULL
;
2681 if (isempty(rvalue
)) {
2682 /* Empty assignment frees the list */
2683 *env
= strv_free(*env
);
2687 r
= unit_path_printf(u
, rvalue
, &n
);
2689 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2693 r
= path_simplify_and_warn(n
[0] == '-' ? n
+ 1 : n
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2697 r
= strv_push(env
, n
);
2706 int config_parse_environ(
2708 const char *filename
,
2710 const char *section
,
2711 unsigned section_line
,
2718 const Unit
*u
= userdata
;
2719 char ***env
= ASSERT_PTR(data
);
2726 if (isempty(rvalue
)) {
2727 /* Empty assignment resets the list */
2728 *env
= strv_free(*env
);
2732 /* If 'u' is set, we operate on the regular unit specifier table. Otherwise we use a manager-specific
2733 * specifier table (in which case ltype must contain the runtime scope). */
2734 const Specifier
*table
= u
? NULL
: (const Specifier
[]) {
2735 COMMON_SYSTEM_SPECIFIERS
,
2736 COMMON_TMP_SPECIFIERS
,
2737 COMMON_CREDS_SPECIFIERS(ltype
),
2738 { 'h', specifier_user_home
, NULL
},
2739 { 's', specifier_user_shell
, NULL
},
2743 for (const char *p
= rvalue
;; ) {
2744 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
2746 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2750 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2751 "Invalid syntax, ignoring: %s", rvalue
);
2758 r
= specifier_printf(word
, sc_arg_max(), table
, NULL
, NULL
, &resolved
);
2760 r
= unit_env_printf(u
, word
, &resolved
);
2762 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2763 "Failed to resolve specifiers in %s, ignoring: %m", word
);
2767 if (!env_assignment_is_valid(resolved
)) {
2768 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
2769 "Invalid environment assignment, ignoring: %s", resolved
);
2773 r
= strv_env_replace_consume(env
, TAKE_PTR(resolved
));
2775 return log_error_errno(r
, "Failed to update environment: %m");
2779 int config_parse_pass_environ(
2781 const char *filename
,
2783 const char *section
,
2784 unsigned section_line
,
2791 char ***passenv
= ASSERT_PTR(data
);
2792 const Unit
*u
= userdata
;
2799 if (isempty(rvalue
)) {
2800 /* Empty assignment resets the list */
2801 *passenv
= strv_free(*passenv
);
2805 _cleanup_strv_free_
char **n
= NULL
;
2807 for (const char *p
= rvalue
;;) {
2808 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2810 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
2814 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2815 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2822 r
= unit_env_printf(u
, word
, &k
);
2824 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2825 "Failed to resolve specifiers in %s, ignoring: %m", word
);
2831 if (!env_name_is_valid(k
)) {
2832 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
2833 "Invalid environment name for %s, ignoring: %s", lvalue
, k
);
2837 if (strv_consume(&n
, TAKE_PTR(k
)) < 0)
2841 r
= strv_extend_strv_consume(passenv
, TAKE_PTR(n
), /* filter_duplicates = */ true);
2848 int config_parse_unset_environ(
2850 const char *filename
,
2852 const char *section
,
2853 unsigned section_line
,
2860 char ***unsetenv
= ASSERT_PTR(data
);
2861 const Unit
*u
= userdata
;
2868 if (isempty(rvalue
)) {
2869 /* Empty assignment resets the list */
2870 *unsetenv
= strv_free(*unsetenv
);
2874 _cleanup_strv_free_
char **n
= NULL
;
2876 for (const char *p
= rvalue
;;) {
2877 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2879 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2883 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2884 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2891 r
= unit_env_printf(u
, word
, &k
);
2893 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2894 "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2900 if (!env_assignment_is_valid(k
) && !env_name_is_valid(k
)) {
2901 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
2902 "Invalid environment name or assignment %s, ignoring: %s", lvalue
, k
);
2906 if (strv_consume(&n
, TAKE_PTR(k
)) < 0)
2910 r
= strv_extend_strv_consume(unsetenv
, TAKE_PTR(n
), /* filter_duplicates = */ true);
2917 int config_parse_log_extra_fields(
2919 const char *filename
,
2921 const char *section
,
2922 unsigned section_line
,
2929 ExecContext
*c
= ASSERT_PTR(data
);
2930 const Unit
*u
= userdata
;
2937 if (isempty(rvalue
)) {
2938 exec_context_free_log_extra_fields(c
);
2942 for (const char *p
= rvalue
;;) {
2943 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2946 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2950 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
2956 r
= unit_full_printf(u
, word
, &k
);
2958 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2962 eq
= strchr(k
, '=');
2964 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Log field lacks '=' character, ignoring: %s", k
);
2968 if (!journal_field_valid(k
, eq
-k
, false)) {
2969 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Log field name is invalid, ignoring: %s", k
);
2973 if (!GREEDY_REALLOC(c
->log_extra_fields
, c
->n_log_extra_fields
+ 1))
2976 c
->log_extra_fields
[c
->n_log_extra_fields
++] = IOVEC_MAKE_STRING(k
);
2981 int config_parse_log_namespace(
2983 const char *filename
,
2985 const char *section
,
2986 unsigned section_line
,
2993 _cleanup_free_
char *k
= NULL
;
2994 ExecContext
*c
= ASSERT_PTR(data
);
2995 const Unit
*u
= userdata
;
3002 if (isempty(rvalue
)) {
3003 c
->log_namespace
= mfree(c
->log_namespace
);
3007 r
= unit_full_printf_full(u
, rvalue
, NAME_MAX
, &k
);
3009 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
3013 if (!log_namespace_name_valid(k
)) {
3014 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Specified log namespace name is not valid, ignoring: %s", k
);
3018 free_and_replace(c
->log_namespace
, k
);
3022 int config_parse_unit_condition_path(
3024 const char *filename
,
3026 const char *section
,
3027 unsigned section_line
,
3034 _cleanup_free_
char *p
= NULL
;
3035 Condition
**list
= ASSERT_PTR(data
), *c
;
3036 ConditionType t
= ltype
;
3037 bool trigger
, negate
;
3038 const Unit
*u
= userdata
;
3045 if (isempty(rvalue
)) {
3046 /* Empty assignment resets the list */
3047 *list
= condition_free_list(*list
);
3051 trigger
= rvalue
[0] == '|';
3055 negate
= rvalue
[0] == '!';
3059 r
= unit_path_printf(u
, rvalue
, &p
);
3061 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
3065 r
= path_simplify_and_warn(p
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
3069 c
= condition_new(t
, p
, trigger
, negate
);
3073 LIST_PREPEND(conditions
, *list
, c
);
3077 int config_parse_unit_condition_string(
3079 const char *filename
,
3081 const char *section
,
3082 unsigned section_line
,
3089 _cleanup_free_
char *s
= NULL
;
3090 Condition
**list
= ASSERT_PTR(data
), *c
;
3091 ConditionType t
= ltype
;
3092 bool trigger
, negate
;
3093 const Unit
*u
= userdata
;
3100 if (isempty(rvalue
)) {
3101 /* Empty assignment resets the list */
3102 *list
= condition_free_list(*list
);
3106 trigger
= *rvalue
== '|';
3108 rvalue
+= 1 + strspn(rvalue
+ 1, WHITESPACE
);
3110 negate
= *rvalue
== '!';
3112 rvalue
+= 1 + strspn(rvalue
+ 1, WHITESPACE
);
3114 r
= unit_full_printf(u
, rvalue
, &s
);
3116 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3117 "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
3121 c
= condition_new(t
, s
, trigger
, negate
);
3125 LIST_PREPEND(conditions
, *list
, c
);
3129 int config_parse_unit_mounts_for(
3131 const char *filename
,
3133 const char *section
,
3134 unsigned section_line
,
3148 assert(STR_IN_SET(lvalue
, "RequiresMountsFor", "WantsMountsFor"));
3150 for (const char *p
= rvalue
;;) {
3151 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
3153 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3157 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3158 "Invalid syntax, ignoring: %s", rvalue
);
3164 r
= unit_path_printf(u
, word
, &resolved
);
3166 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
3170 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
3174 r
= unit_add_mounts_for(u
, resolved
, UNIT_DEPENDENCY_FILE
, unit_mount_dependency_type_from_string(lvalue
));
3176 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add requested mount '%s', ignoring: %m", resolved
);
3182 int config_parse_documentation(
3184 const char *filename
,
3186 const char *section
,
3187 unsigned section_line
,
3194 Unit
*u
= ASSERT_PTR(userdata
);
3202 if (isempty(rvalue
)) {
3203 /* Empty assignment resets the list */
3204 u
->documentation
= strv_free(u
->documentation
);
3208 r
= config_parse_unit_strv_printf(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
,
3209 rvalue
, data
, userdata
);
3213 for (a
= b
= u
->documentation
; a
&& *a
; a
++) {
3215 if (documentation_url_is_valid(*a
))
3218 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid URL, ignoring: %s", *a
);
3229 int config_parse_syscall_filter(
3231 const char *filename
,
3233 const char *section
,
3234 unsigned section_line
,
3241 ExecContext
*c
= data
;
3242 _unused_
const Unit
*u
= ASSERT_PTR(userdata
);
3243 bool invert
= false;
3250 if (isempty(rvalue
)) {
3251 /* Empty assignment resets the list */
3252 c
->syscall_filter
= hashmap_free(c
->syscall_filter
);
3253 c
->syscall_allow_list
= false;
3257 if (rvalue
[0] == '~') {
3262 if (!c
->syscall_filter
) {
3263 c
->syscall_filter
= hashmap_new(NULL
);
3264 if (!c
->syscall_filter
)
3268 /* Allow everything but the ones listed */
3269 c
->syscall_allow_list
= false;
3271 /* Allow nothing but the ones listed */
3272 c
->syscall_allow_list
= true;
3274 /* Accept default syscalls if we are on an allow_list */
3275 r
= seccomp_parse_syscall_filter(
3276 "@default", -1, c
->syscall_filter
,
3277 SECCOMP_PARSE_PERMISSIVE
|SECCOMP_PARSE_ALLOW_LIST
,
3285 for (const char *p
= rvalue
;;) {
3286 _cleanup_free_
char *word
= NULL
, *name
= NULL
;
3289 r
= extract_first_word(&p
, &word
, NULL
, 0);
3293 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3294 "Invalid syntax, ignoring: %s", rvalue
);
3300 r
= parse_syscall_and_errno(word
, &name
, &num
);
3302 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3303 "Failed to parse syscall:errno, ignoring: %s", word
);
3306 if (!invert
&& num
>= 0) {
3307 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3308 "Allow-listed system calls cannot take error number, ignoring: %s", word
);
3312 r
= seccomp_parse_syscall_filter(
3313 name
, num
, c
->syscall_filter
,
3314 SECCOMP_PARSE_LOG
|SECCOMP_PARSE_PERMISSIVE
|
3315 (invert
? SECCOMP_PARSE_INVERT
: 0)|
3316 (c
->syscall_allow_list
? SECCOMP_PARSE_ALLOW_LIST
: 0),
3317 unit
, filename
, line
);
3323 int config_parse_syscall_log(
3325 const char *filename
,
3327 const char *section
,
3328 unsigned section_line
,
3335 ExecContext
*c
= data
;
3336 _unused_
const Unit
*u
= ASSERT_PTR(userdata
);
3337 bool invert
= false;
3345 if (isempty(rvalue
)) {
3346 /* Empty assignment resets the list */
3347 c
->syscall_log
= hashmap_free(c
->syscall_log
);
3348 c
->syscall_log_allow_list
= false;
3352 if (rvalue
[0] == '~') {
3357 if (!c
->syscall_log
) {
3358 c
->syscall_log
= hashmap_new(NULL
);
3359 if (!c
->syscall_log
)
3363 /* Log everything but the ones listed */
3364 c
->syscall_log_allow_list
= false;
3366 /* Log nothing but the ones listed */
3367 c
->syscall_log_allow_list
= true;
3372 _cleanup_free_
char *word
= NULL
;
3374 r
= extract_first_word(&p
, &word
, NULL
, 0);
3378 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3384 r
= seccomp_parse_syscall_filter(
3385 word
, -1, c
->syscall_log
,
3386 SECCOMP_PARSE_LOG
|SECCOMP_PARSE_PERMISSIVE
|
3387 (invert
? SECCOMP_PARSE_INVERT
: 0)|
3388 (c
->syscall_log_allow_list
? SECCOMP_PARSE_ALLOW_LIST
: 0),
3389 unit
, filename
, line
);
3395 int config_parse_syscall_archs(
3397 const char *filename
,
3399 const char *section
,
3400 unsigned section_line
,
3410 if (isempty(rvalue
)) {
3411 *archs
= set_free(*archs
);
3415 for (const char *p
= rvalue
;;) {
3416 _cleanup_free_
char *word
= NULL
;
3419 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3423 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3424 "Invalid syntax, ignoring: %s", rvalue
);
3430 r
= seccomp_arch_from_string(word
, &a
);
3432 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3433 "Failed to parse system call architecture \"%s\", ignoring: %m", word
);
3437 r
= set_ensure_put(archs
, NULL
, UINT32_TO_PTR(a
+ 1));
3443 int config_parse_syscall_errno(
3445 const char *filename
,
3447 const char *section
,
3448 unsigned section_line
,
3455 ExecContext
*c
= data
;
3462 if (isempty(rvalue
) || streq(rvalue
, "kill")) {
3463 /* Empty assignment resets to KILL */
3464 c
->syscall_errno
= SECCOMP_ERROR_NUMBER_KILL
;
3468 e
= parse_errno(rvalue
);
3470 log_syntax(unit
, LOG_WARNING
, filename
, line
, e
, "Failed to parse error number, ignoring: %s", rvalue
);
3474 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid error number, ignoring: %s", rvalue
);
3478 c
->syscall_errno
= e
;
3482 int config_parse_address_families(
3484 const char *filename
,
3486 const char *section
,
3487 unsigned section_line
,
3494 ExecContext
*c
= data
;
3495 bool invert
= false;
3502 if (isempty(rvalue
)) {
3503 /* Empty assignment resets the list */
3504 c
->address_families
= set_free(c
->address_families
);
3505 c
->address_families_allow_list
= false;
3509 if (streq(rvalue
, "none")) {
3510 /* Forbid all address families. */
3511 c
->address_families
= set_free(c
->address_families
);
3512 c
->address_families_allow_list
= true;
3516 if (rvalue
[0] == '~') {
3521 if (!c
->address_families
) {
3522 c
->address_families
= set_new(NULL
);
3523 if (!c
->address_families
)
3526 c
->address_families_allow_list
= !invert
;
3529 for (const char *p
= rvalue
;;) {
3530 _cleanup_free_
char *word
= NULL
;
3533 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3537 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3538 "Invalid syntax, ignoring: %s", rvalue
);
3544 af
= af_from_name(word
);
3546 log_syntax(unit
, LOG_WARNING
, filename
, line
, af
,
3547 "Failed to parse address family, ignoring: %s", word
);
3551 /* If we previously wanted to forbid an address family and now
3552 * we want to allow it, then just remove it from the list.
3554 if (!invert
== c
->address_families_allow_list
) {
3555 r
= set_put(c
->address_families
, INT_TO_PTR(af
));
3559 set_remove(c
->address_families
, INT_TO_PTR(af
));
3564 int config_parse_namespace_flags(
3566 const char *filename
,
3568 const char *section
,
3569 unsigned section_line
,
3576 unsigned long *flags
= data
;
3577 unsigned long all
= UPDATE_FLAG(NAMESPACE_FLAGS_ALL
, CLONE_NEWUSER
, !streq(lvalue
, "DelegateNamespaces"));
3579 bool invert
= false;
3582 if (isempty(rvalue
)) {
3583 /* Reset to the default. */
3584 *flags
= NAMESPACE_FLAGS_INITIAL
;
3588 /* Boolean parameter ignores the previous settings */
3589 r
= parse_boolean(rvalue
);
3591 /* RestrictNamespaces= value gets stored into a field with reverse semantics (the namespaces
3592 * which are retained), so RestrictNamespaces=true means we retain no access to any
3593 * namespaces and vice-versa. */
3594 *flags
= streq(lvalue
, "RestrictNamespaces") ? 0 : all
;
3596 } else if (r
== 0) {
3597 *flags
= streq(lvalue
, "RestrictNamespaces") ? all
: 0;
3601 if (rvalue
[0] == '~') {
3606 /* Not a boolean argument, in this case it's a list of namespace types. */
3607 r
= namespace_flags_from_string(rvalue
, &f
);
3609 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse namespace type string, ignoring: %s", rvalue
);
3613 if (*flags
== NAMESPACE_FLAGS_INITIAL
)
3614 /* Initial assignment. Just set the value. */
3615 f
= invert
? (~f
) & all
: f
;
3617 /* Merge the value with the previous one. */
3618 f
= UPDATE_FLAG(*flags
, f
, !invert
);
3620 if (FLAGS_SET(f
, CLONE_NEWUSER
) && streq(lvalue
, "DelegateNamespaces")) {
3621 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "The user namespace cannot be delegated with DelegateNamespaces=, ignoring: %s", rvalue
);
3630 int config_parse_restrict_filesystems(
3632 const char *filename
,
3634 const char *section
,
3635 unsigned section_line
,
3641 ExecContext
*c
= ASSERT_PTR(data
);
3642 bool invert
= false;
3649 if (isempty(rvalue
)) {
3650 /* Empty assignment resets the list */
3651 c
->restrict_filesystems
= set_free(c
->restrict_filesystems
);
3652 c
->restrict_filesystems_allow_list
= false;
3656 if (rvalue
[0] == '~') {
3661 if (!c
->restrict_filesystems
) {
3663 /* Allow everything but the ones listed */
3664 c
->restrict_filesystems_allow_list
= false;
3666 /* Allow nothing but the ones listed */
3667 c
->restrict_filesystems_allow_list
= true;
3670 for (const char *p
= rvalue
;;) {
3671 _cleanup_free_
char *word
= NULL
;
3673 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3679 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3680 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
3684 r
= bpf_restrict_fs_parse_filesystem(
3686 &c
->restrict_filesystems
,
3687 FILESYSTEM_PARSE_LOG
|
3688 (invert
? FILESYSTEM_PARSE_INVERT
: 0)|
3689 (c
->restrict_filesystems_allow_list
? FILESYSTEM_PARSE_ALLOW_LIST
: 0),
3690 unit
, filename
, line
);
3699 int config_parse_unit_slice(
3701 const char *filename
,
3703 const char *section
,
3704 unsigned section_line
,
3711 Unit
*u
= ASSERT_PTR(userdata
), *slice
;
3712 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
3713 _cleanup_free_
char *k
= NULL
;
3720 r
= unit_name_printf(u
, rvalue
, &k
);
3722 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
3726 r
= manager_load_unit(u
->manager
, k
, NULL
, &error
, &slice
);
3728 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to load slice unit %s, ignoring: %s", k
, bus_error_message(&error
, r
));
3732 r
= unit_set_slice(u
, slice
);
3734 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to assign slice %s to unit %s, ignoring: %m", slice
->id
, u
->id
);
3741 int config_parse_cpu_quota(
3743 const char *filename
,
3745 const char *section
,
3746 unsigned section_line
,
3753 CGroupContext
*c
= data
;
3760 if (isempty(rvalue
)) {
3761 c
->cpu_quota_per_sec_usec
= USEC_INFINITY
;
3765 r
= parse_permyriad_unbounded(rvalue
);
3767 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid CPU quota '%s', ignoring.", rvalue
);
3771 c
->cpu_quota_per_sec_usec
= ((usec_t
) r
* USEC_PER_SEC
) / 10000U;
3775 int config_parse_unit_cpu_set(
3777 const char *filename
,
3779 const char *section
,
3780 unsigned section_line
,
3787 const Unit
*u
= ASSERT_PTR(userdata
);
3788 _cleanup_free_
char *k
= NULL
;
3795 r
= unit_full_printf(u
, rvalue
, &k
);
3797 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3798 "Failed to resolve unit specifiers in '%s', ignoring: %m",
3803 return config_parse_cpu_set(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
3806 int config_parse_memory_limit(
3808 const char *filename
,
3810 const char *section
,
3811 unsigned section_line
,
3818 CGroupContext
*c
= data
;
3819 uint64_t bytes
= CGROUP_LIMIT_MAX
;
3822 if (isempty(rvalue
) && STR_IN_SET(lvalue
, "DefaultMemoryLow",
3827 bytes
= CGROUP_LIMIT_MIN
;
3828 else if (!isempty(rvalue
) && !streq(rvalue
, "infinity")) {
3830 r
= parse_permyriad(rvalue
);
3832 r
= parse_size(rvalue
, 1024, &bytes
);
3834 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid memory limit '%s', ignoring: %m", rvalue
);
3838 bytes
= physical_memory_scale(r
, 10000U);
3840 if (bytes
>= UINT64_MAX
||
3841 (bytes
<= 0 && !STR_IN_SET(lvalue
,
3843 "StartupMemorySwapMax",
3845 "StartupMemoryZSwapMax",
3850 "DefaultstartupMemoryLow",
3851 "DefaultMemoryMin"))) {
3852 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Memory limit '%s' out of range, ignoring.", rvalue
);
3857 if (streq(lvalue
, "DefaultMemoryLow")) {
3858 c
->default_memory_low
= bytes
;
3859 c
->default_memory_low_set
= true;
3860 } else if (streq(lvalue
, "DefaultStartupMemoryLow")) {
3861 c
->default_startup_memory_low
= bytes
;
3862 c
->default_startup_memory_low_set
= true;
3863 } else if (streq(lvalue
, "DefaultMemoryMin")) {
3864 c
->default_memory_min
= bytes
;
3865 c
->default_memory_min_set
= true;
3866 } else if (streq(lvalue
, "MemoryMin")) {
3867 c
->memory_min
= bytes
;
3868 c
->memory_min_set
= true;
3869 } else if (streq(lvalue
, "MemoryLow")) {
3870 c
->memory_low
= bytes
;
3871 c
->memory_low_set
= true;
3872 } else if (streq(lvalue
, "StartupMemoryLow")) {
3873 c
->startup_memory_low
= bytes
;
3874 c
->startup_memory_low_set
= true;
3875 } else if (streq(lvalue
, "MemoryHigh"))
3876 c
->memory_high
= bytes
;
3877 else if (streq(lvalue
, "StartupMemoryHigh")) {
3878 c
->startup_memory_high
= bytes
;
3879 c
->startup_memory_high_set
= true;
3880 } else if (streq(lvalue
, "MemoryMax"))
3881 c
->memory_max
= bytes
;
3882 else if (streq(lvalue
, "StartupMemoryMax")) {
3883 c
->startup_memory_max
= bytes
;
3884 c
->startup_memory_max_set
= true;
3885 } else if (streq(lvalue
, "MemorySwapMax"))
3886 c
->memory_swap_max
= bytes
;
3887 else if (streq(lvalue
, "StartupMemorySwapMax")) {
3888 c
->startup_memory_swap_max
= bytes
;
3889 c
->startup_memory_swap_max_set
= true;
3890 } else if (streq(lvalue
, "MemoryZSwapMax"))
3891 c
->memory_zswap_max
= bytes
;
3892 else if (streq(lvalue
, "StartupMemoryZSwapMax")) {
3893 c
->startup_memory_zswap_max
= bytes
;
3894 c
->startup_memory_zswap_max_set
= true;
3901 int config_parse_tasks_max(
3903 const char *filename
,
3905 const char *section
,
3906 unsigned section_line
,
3913 CGroupTasksMax
*tasks_max
= ASSERT_PTR(data
);
3914 const Unit
*u
= userdata
;
3918 if (isempty(rvalue
)) {
3919 *tasks_max
= u
? u
->manager
->defaults
.tasks_max
: CGROUP_TASKS_MAX_UNSET
;
3923 if (streq(rvalue
, "infinity")) {
3924 *tasks_max
= CGROUP_TASKS_MAX_UNSET
;
3928 r
= parse_permyriad(rvalue
);
3930 *tasks_max
= (CGroupTasksMax
) { r
, 10000U }; /* r‱ */
3932 r
= safe_atou64(rvalue
, &v
);
3934 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid maximum tasks value '%s', ignoring: %m", rvalue
);
3938 if (v
<= 0 || v
>= UINT64_MAX
) {
3939 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Maximum tasks value '%s' out of range, ignoring.", rvalue
);
3943 *tasks_max
= (CGroupTasksMax
) { v
};
3949 int config_parse_delegate(
3951 const char *filename
,
3953 const char *section
,
3954 unsigned section_line
,
3961 CGroupContext
*c
= data
;
3965 t
= unit_name_to_type(unit
);
3966 assert(t
!= _UNIT_TYPE_INVALID
);
3968 if (!unit_vtable
[t
]->can_delegate
) {
3969 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Delegate= setting not supported for this unit type, ignoring.");
3973 /* We either accept a boolean value, which may be used to turn on delegation for all controllers, or
3974 * turn it off for all. Or it takes a list of controller names, in which case we add the specified
3975 * controllers to the mask to delegate. Delegate= enables delegation without any controllers. */
3977 if (isempty(rvalue
)) {
3978 /* An empty string resets controllers and sets Delegate=yes. */
3980 c
->delegate_controllers
= 0;
3984 r
= parse_boolean(rvalue
);
3986 CGroupMask mask
= 0;
3988 for (const char *p
= rvalue
;;) {
3989 _cleanup_free_
char *word
= NULL
;
3990 CGroupController cc
;
3992 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3996 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
4002 cc
= cgroup_controller_from_string(word
);
4004 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid controller name '%s', ignoring", word
);
4008 mask
|= CGROUP_CONTROLLER_TO_MASK(cc
);
4012 c
->delegate_controllers
|= mask
;
4016 c
->delegate_controllers
= CGROUP_MASK_DELEGATE
;
4018 c
->delegate
= false;
4019 c
->delegate_controllers
= 0;
4025 int config_parse_delegate_subgroup(
4027 const char *filename
,
4029 const char *section
,
4030 unsigned section_line
,
4037 CGroupContext
*c
= ASSERT_PTR(data
);
4040 t
= unit_name_to_type(unit
);
4043 if (!unit_vtable
[t
]->can_delegate
) {
4044 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "DelegateSubgroup= setting not supported for this unit type, ignoring.");
4048 if (isempty(rvalue
)) {
4049 c
->delegate_subgroup
= mfree(c
->delegate_subgroup
);
4053 if (cg_needs_escape(rvalue
)) { /* Insist that specified names don't need escaping */
4054 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid control group name, ignoring: %s", rvalue
);
4058 return free_and_strdup_warn(&c
->delegate_subgroup
, rvalue
);
4061 int config_parse_managed_oom_mode(
4063 const char *filename
,
4065 const char *section
,
4066 unsigned section_line
,
4073 ManagedOOMMode
*mode
= data
, m
;
4076 t
= unit_name_to_type(unit
);
4077 assert(t
!= _UNIT_TYPE_INVALID
);
4079 if (!unit_vtable
[t
]->can_set_managed_oom
)
4080 return log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "%s= is not supported for this unit type, ignoring.", lvalue
);
4082 if (isempty(rvalue
)) {
4083 *mode
= MANAGED_OOM_AUTO
;
4087 m
= managed_oom_mode_from_string(rvalue
);
4089 log_syntax(unit
, LOG_WARNING
, filename
, line
, m
, "Invalid syntax, ignoring: %s", rvalue
);
4097 int config_parse_managed_oom_mem_pressure_limit(
4099 const char *filename
,
4101 const char *section
,
4102 unsigned section_line
,
4109 uint32_t *limit
= data
;
4113 t
= unit_name_to_type(unit
);
4114 assert(t
!= _UNIT_TYPE_INVALID
);
4116 if (!unit_vtable
[t
]->can_set_managed_oom
)
4117 return log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "%s= is not supported for this unit type, ignoring.", lvalue
);
4119 if (isempty(rvalue
)) {
4124 r
= parse_permyriad(rvalue
);
4126 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse memory pressure limit value, ignoring: %s", rvalue
);
4130 /* Normalize to 2^32-1 == 100% */
4131 *limit
= UINT32_SCALE_FROM_PERMYRIAD(r
);
4135 int config_parse_managed_oom_mem_pressure_duration_sec(
4137 const char *filename
,
4139 const char *section
,
4140 unsigned section_line
,
4147 usec_t usec
, *duration
= ASSERT_PTR(data
);
4151 t
= unit_name_to_type(unit
);
4152 assert(t
!= _UNIT_TYPE_INVALID
);
4154 if (!unit_vtable
[t
]->can_set_managed_oom
)
4155 return log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "%s= is not supported for this unit type, ignoring.", lvalue
);
4157 if (isempty(rvalue
)) {
4158 *duration
= USEC_INFINITY
;
4162 r
= parse_sec(rvalue
, &usec
);
4164 return log_syntax_parse_error(unit
, filename
, line
, r
, lvalue
, rvalue
);
4166 if (usec
< 1 * USEC_PER_SEC
|| usec
== USEC_INFINITY
)
4167 return log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "%s= must be at least 1s and less than infinity, ignoring: %s", lvalue
, rvalue
);
4173 int config_parse_device_allow(
4175 const char *filename
,
4177 const char *section
,
4178 unsigned section_line
,
4185 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4186 CGroupDevicePermissions permissions
;
4187 CGroupContext
*c
= data
;
4188 const char *p
= rvalue
;
4191 if (isempty(rvalue
)) {
4192 while (c
->device_allow
)
4193 cgroup_context_free_device_allow(c
, c
->device_allow
);
4198 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4202 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4203 "Failed to extract device path and rights from '%s', ignoring.", rvalue
);
4207 r
= unit_path_printf(userdata
, path
, &resolved
);
4209 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4210 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4214 if (!STARTSWITH_SET(resolved
, "block-", "char-")) {
4216 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4220 if (!valid_device_node_path(resolved
)) {
4221 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid device node path '%s', ignoring.", resolved
);
4226 permissions
= isempty(p
) ? 0 : cgroup_device_permissions_from_string(p
);
4227 if (permissions
< 0) {
4228 log_syntax(unit
, LOG_WARNING
, filename
, line
, permissions
, "Invalid device rights '%s', ignoring.", p
);
4232 return cgroup_context_add_device_allow(c
, resolved
, permissions
);
4235 int config_parse_io_device_weight(
4237 const char *filename
,
4239 const char *section
,
4240 unsigned section_line
,
4247 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4248 CGroupIODeviceWeight
*w
;
4249 CGroupContext
*c
= data
;
4250 const char *p
= ASSERT_PTR(rvalue
);
4257 if (isempty(rvalue
)) {
4258 while (c
->io_device_weights
)
4259 cgroup_context_free_io_device_weight(c
, c
->io_device_weights
);
4264 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4268 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4269 "Failed to extract device path and weight from '%s', ignoring.", rvalue
);
4272 if (r
== 0 || isempty(p
)) {
4273 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4274 "Invalid device path or weight specified in '%s', ignoring.", rvalue
);
4278 r
= unit_path_printf(userdata
, path
, &resolved
);
4280 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4281 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4285 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4289 r
= cg_weight_parse(p
, &u
);
4291 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "IO weight '%s' invalid, ignoring: %m", p
);
4295 assert(u
!= CGROUP_WEIGHT_INVALID
);
4297 w
= new0(CGroupIODeviceWeight
, 1);
4301 w
->path
= TAKE_PTR(resolved
);
4304 LIST_APPEND(device_weights
, c
->io_device_weights
, w
);
4308 int config_parse_io_device_latency(
4310 const char *filename
,
4312 const char *section
,
4313 unsigned section_line
,
4320 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4321 CGroupIODeviceLatency
*l
;
4322 CGroupContext
*c
= data
;
4323 const char *p
= ASSERT_PTR(rvalue
);
4330 if (isempty(rvalue
)) {
4331 while (c
->io_device_latencies
)
4332 cgroup_context_free_io_device_latency(c
, c
->io_device_latencies
);
4337 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4341 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4342 "Failed to extract device path and latency from '%s', ignoring.", rvalue
);
4345 if (r
== 0 || isempty(p
)) {
4346 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4347 "Invalid device path or latency specified in '%s', ignoring.", rvalue
);
4351 r
= unit_path_printf(userdata
, path
, &resolved
);
4353 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4354 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4358 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4362 r
= parse_sec(p
, &usec
);
4364 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse timer value, ignoring: %s", p
);
4368 l
= new0(CGroupIODeviceLatency
, 1);
4372 l
->path
= TAKE_PTR(resolved
);
4373 l
->target_usec
= usec
;
4375 LIST_APPEND(device_latencies
, c
->io_device_latencies
, l
);
4379 int config_parse_io_limit(
4381 const char *filename
,
4383 const char *section
,
4384 unsigned section_line
,
4391 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4392 CGroupIODeviceLimit
*l
= NULL
;
4393 CGroupContext
*c
= data
;
4394 CGroupIOLimitType type
;
4395 const char *p
= ASSERT_PTR(rvalue
);
4402 type
= cgroup_io_limit_type_from_string(lvalue
);
4405 if (isempty(rvalue
)) {
4406 LIST_FOREACH(device_limits
, t
, c
->io_device_limits
)
4407 t
->limits
[type
] = cgroup_io_limit_defaults
[type
];
4411 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4415 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4416 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
4419 if (r
== 0 || isempty(p
)) {
4420 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4421 "Invalid device node or bandwidth specified in '%s', ignoring.", rvalue
);
4425 r
= unit_path_printf(userdata
, path
, &resolved
);
4427 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4428 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4432 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4436 if (streq("infinity", p
))
4437 num
= CGROUP_LIMIT_MAX
;
4439 r
= parse_size(p
, 1000, &num
);
4440 if (r
< 0 || num
<= 0) {
4441 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid IO limit '%s', ignoring.", p
);
4446 LIST_FOREACH(device_limits
, t
, c
->io_device_limits
)
4447 if (path_equal(resolved
, t
->path
)) {
4453 l
= new0(CGroupIODeviceLimit
, 1);
4457 l
->path
= TAKE_PTR(resolved
);
4458 for (CGroupIOLimitType i
= 0; i
< _CGROUP_IO_LIMIT_TYPE_MAX
; i
++)
4459 l
->limits
[i
] = cgroup_io_limit_defaults
[i
];
4461 LIST_APPEND(device_limits
, c
->io_device_limits
, l
);
4464 l
->limits
[type
] = num
;
4469 int config_parse_job_mode_isolate(
4471 const char *filename
,
4473 const char *section
,
4474 unsigned section_line
,
4488 r
= parse_boolean(rvalue
);
4490 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse boolean, ignoring: %s", rvalue
);
4494 log_notice("%s is deprecated. Please use OnFailureJobMode= instead", lvalue
);
4496 *m
= r
? JOB_ISOLATE
: JOB_REPLACE
;
4500 int config_parse_exec_directories(
4502 const char *filename
,
4504 const char *section
,
4505 unsigned section_line
,
4512 ExecDirectory
*ed
= ASSERT_PTR(data
);
4513 const Unit
*u
= userdata
;
4520 if (isempty(rvalue
)) {
4521 /* Empty assignment resets the list */
4522 exec_directory_done(ed
);
4526 for (const char *p
= rvalue
;;) {
4527 _cleanup_free_
char *tuple
= NULL
;
4529 r
= extract_first_word(&p
, &tuple
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_RETAIN_ESCAPE
);
4533 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4534 "Invalid syntax %s=%s, ignoring: %m", lvalue
, rvalue
);
4540 _cleanup_free_
char *src
= NULL
, *dest
= NULL
, *flags
= NULL
;
4541 const char *q
= tuple
;
4542 r
= extract_many_words(&q
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
|EXTRACT_DONT_COALESCE_SEPARATORS
, &src
, &dest
, &flags
);
4546 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4547 "Invalid syntax in %s=, ignoring: %s", lvalue
, tuple
);
4551 _cleanup_free_
char *sresolved
= NULL
;
4552 r
= unit_path_printf(u
, src
, &sresolved
);
4554 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4555 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", src
);
4559 r
= path_simplify_and_warn(sresolved
, PATH_CHECK_RELATIVE
, unit
, filename
, line
, lvalue
);
4563 if (path_startswith(sresolved
, "private")) {
4564 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4565 "%s= path can't be 'private', ignoring assignment: %s", lvalue
, tuple
);
4569 if (!isempty(dest
) && streq(lvalue
, "ConfigurationDirectory")) {
4570 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4571 "Additional parameter is not supported for ConfigurationDirectory, ignoring: %s", tuple
);
4575 /* For State and Runtime directories we support an optional destination parameter, which
4576 * will be used to create a symlink to the source. */
4577 _cleanup_free_
char *dresolved
= NULL
;
4578 if (!isempty(dest
)) {
4579 r
= unit_path_printf(u
, dest
, &dresolved
);
4581 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4582 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", dest
);
4586 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_RELATIVE
, unit
, filename
, line
, lvalue
);
4591 ExecDirectoryFlags exec_directory_flags
= exec_directory_flags_from_string(flags
);
4592 if (exec_directory_flags
< 0 || (exec_directory_flags
& ~_EXEC_DIRECTORY_FLAGS_PUBLIC
) != 0) {
4593 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4594 "Invalid flags for %s=, ignoring: %s", lvalue
, flags
);
4598 r
= exec_directory_add(ed
, sresolved
, dresolved
, exec_directory_flags
);
4604 int config_parse_set_credential(
4606 const char *filename
,
4608 const char *section
,
4609 unsigned section_line
,
4616 ExecContext
*context
= ASSERT_PTR(data
);
4617 const Unit
*u
= ASSERT_PTR(userdata
);
4624 if (isempty(rvalue
)) {
4625 /* Empty assignment resets the list */
4626 context
->set_credentials
= hashmap_free(context
->set_credentials
);
4630 _cleanup_free_
char *word
= NULL
, *id
= NULL
;
4631 const char *p
= rvalue
;
4632 bool encrypted
= ltype
;
4634 r
= extract_first_word(&p
, &word
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4638 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract credential name, ignoring: %s", rvalue
);
4641 if (r
== 0 || isempty(p
)) {
4642 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid syntax, ignoring: %s", rvalue
);
4646 r
= unit_cred_printf(u
, word
, &id
);
4648 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
4651 if (!credential_name_valid(id
)) {
4652 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Credential name \"%s\" not valid, ignoring.", id
);
4656 _cleanup_free_
void *d
= NULL
;
4660 r
= unbase64mem_full(p
, SIZE_MAX
, /* secure = */ true, &d
, &size
);
4664 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Encrypted credential data not valid Base64 data, ignoring: %m");
4670 /* We support escape codes here, so that users can insert trailing \n if they like */
4671 l
= cunescape(p
, UNESCAPE_ACCEPT_NUL
, (char**) &d
);
4675 log_syntax(unit
, LOG_WARNING
, filename
, line
, l
, "Can't unescape \"%s\", ignoring: %m", p
);
4682 r
= exec_context_put_set_credential(context
, id
, TAKE_PTR(d
), size
, encrypted
);
4684 return log_error_errno(r
, "Failed to store set credential '%s': %m", rvalue
);
4689 int config_parse_load_credential(
4691 const char *filename
,
4693 const char *section
,
4694 unsigned section_line
,
4701 ExecContext
*context
= ASSERT_PTR(data
);
4702 const Unit
*u
= ASSERT_PTR(userdata
);
4709 if (isempty(rvalue
)) {
4710 /* Empty assignment resets the list */
4711 context
->load_credentials
= hashmap_free(context
->load_credentials
);
4715 _cleanup_free_
char *word
= NULL
, *id
= NULL
, *path
= NULL
;
4716 const char *p
= rvalue
;
4717 bool encrypted
= ltype
;
4719 r
= extract_first_word(&p
, &word
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4723 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
4727 r
= unit_cred_printf(u
, word
, &id
);
4729 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
4732 if (!credential_name_valid(id
)) {
4733 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Credential name \"%s\" not valid, ignoring.", id
);
4738 /* If only one field is specified take it as shortcut for inheriting a credential named
4739 * the same way from our parent */
4744 r
= unit_path_printf(u
, p
, &path
);
4746 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", p
);
4749 if (path_is_absolute(path
) ? !path_is_normalized(path
) : !credential_name_valid(path
)) {
4750 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Credential source \"%s\" not valid, ignoring.", path
);
4755 r
= exec_context_put_load_credential(context
, id
, path
, encrypted
);
4757 return log_error_errno(r
, "Failed to store load credential '%s': %m", rvalue
);
4762 int config_parse_import_credential(
4764 const char *filename
,
4766 const char *section
,
4767 unsigned section_line
,
4774 ExecContext
*context
= ASSERT_PTR(data
);
4782 if (isempty(rvalue
)) {
4783 /* Empty assignment resets the list */
4784 context
->import_credentials
= ordered_set_free(context
->import_credentials
);
4788 const char *p
= rvalue
;
4789 _cleanup_free_
char *word
= NULL
, *glob
= NULL
;
4791 r
= extract_first_word(&p
, &word
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4795 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
4799 r
= unit_cred_printf(u
, word
, &glob
);
4801 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
4805 if (!credential_glob_valid(glob
)) {
4806 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Credential name or glob \"%s\" not valid, ignoring.", glob
);
4810 if (!isempty(p
) && !credential_name_valid(p
)) {
4811 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Credential name \"%s\" not valid, ignoring.", p
);
4815 r
= exec_context_put_import_credential(context
, glob
, p
);
4817 return log_error_errno(r
, "Failed to store import credential '%s': %m", rvalue
);
4822 int config_parse_set_status(
4824 const char *filename
,
4826 const char *section
,
4827 unsigned section_line
,
4834 ExitStatusSet
*status_set
= ASSERT_PTR(data
);
4841 /* Empty assignment resets the list */
4842 if (isempty(rvalue
)) {
4843 exit_status_set_free(status_set
);
4847 for (const char *p
= rvalue
;;) {
4848 _cleanup_free_
char *word
= NULL
;
4851 r
= extract_first_word(&p
, &word
, NULL
, 0);
4855 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4856 "Failed to parse %s=%s, ignoring: %m", lvalue
, rvalue
);
4862 /* We need to call exit_status_from_string() first, because we want
4863 * to parse numbers as exit statuses, not signals. */
4865 r
= exit_status_from_string(word
);
4867 assert(r
>= 0 && r
< 256);
4868 bitmap
= &status_set
->status
;
4870 r
= signal_from_string(word
);
4872 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4873 "Failed to parse value, ignoring: %s", word
);
4876 bitmap
= &status_set
->signal
;
4879 r
= bitmap_set(bitmap
, r
);
4881 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4882 "Failed to set signal or status %s, ignoring: %m", word
);
4886 int config_parse_namespace_path_strv(
4888 const char *filename
,
4890 const char *section
,
4891 unsigned section_line
,
4898 const Unit
*u
= userdata
;
4899 char*** sv
= ASSERT_PTR(data
);
4906 if (isempty(rvalue
)) {
4907 /* Empty assignment resets the list */
4908 *sv
= strv_free(*sv
);
4912 for (const char *p
= rvalue
;;) {
4913 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
, *joined
= NULL
;
4915 bool ignore_enoent
= false, shall_prefix
= false;
4917 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
4921 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
4928 if (startswith(w
, "-")) {
4929 ignore_enoent
= true;
4932 if (startswith(w
, "+")) {
4933 shall_prefix
= true;
4937 r
= unit_path_printf(u
, w
, &resolved
);
4939 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", w
);
4943 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4947 joined
= strjoin(ignore_enoent
? "-" : "",
4948 shall_prefix
? "+" : "",
4951 r
= strv_push(sv
, joined
);
4961 int config_parse_temporary_filesystems(
4963 const char *filename
,
4965 const char *section
,
4966 unsigned section_line
,
4973 const Unit
*u
= userdata
;
4974 ExecContext
*c
= ASSERT_PTR(data
);
4981 if (isempty(rvalue
)) {
4982 /* Empty assignment resets the list */
4983 temporary_filesystem_free_many(c
->temporary_filesystems
, c
->n_temporary_filesystems
);
4984 c
->temporary_filesystems
= NULL
;
4985 c
->n_temporary_filesystems
= 0;
4989 for (const char *p
= rvalue
;;) {
4990 _cleanup_free_
char *word
= NULL
, *path
= NULL
, *resolved
= NULL
;
4993 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
4997 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
5004 r
= extract_first_word(&w
, &path
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
5008 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", word
);
5012 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid syntax, ignoring: %s", word
);
5016 r
= unit_path_printf(u
, path
, &resolved
);
5018 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", path
);
5022 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5026 r
= temporary_filesystem_add(&c
->temporary_filesystems
, &c
->n_temporary_filesystems
, resolved
, w
);
5032 int config_parse_bind_paths(
5034 const char *filename
,
5036 const char *section
,
5037 unsigned section_line
,
5044 ExecContext
*c
= ASSERT_PTR(data
);
5045 const Unit
*u
= ASSERT_PTR(userdata
);
5052 if (isempty(rvalue
)) {
5053 /* Empty assignment resets the list */
5054 bind_mount_free_many(c
->bind_mounts
, c
->n_bind_mounts
);
5055 c
->bind_mounts
= NULL
;
5056 c
->n_bind_mounts
= 0;
5060 for (const char *p
= rvalue
;;) {
5061 _cleanup_free_
char *source
= NULL
, *destination
= NULL
;
5062 _cleanup_free_
char *sresolved
= NULL
, *dresolved
= NULL
;
5063 char *s
= NULL
, *d
= NULL
;
5064 bool rbind
= true, ignore_enoent
= false;
5066 r
= extract_first_word(&p
, &source
, ":" WHITESPACE
, EXTRACT_UNQUOTE
|EXTRACT_DONT_COALESCE_SEPARATORS
);
5070 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
5076 r
= unit_path_printf(u
, source
, &sresolved
);
5078 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5079 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", source
);
5085 ignore_enoent
= true;
5089 r
= path_simplify_and_warn(s
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5093 /* Optionally, the destination is specified. */
5094 if (p
&& p
[-1] == ':') {
5095 r
= extract_first_word(&p
, &destination
, ":" WHITESPACE
, EXTRACT_UNQUOTE
|EXTRACT_DONT_COALESCE_SEPARATORS
);
5099 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
5103 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Missing argument after ':', ignoring: %s", s
);
5107 r
= unit_path_printf(u
, destination
, &dresolved
);
5109 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5110 "Failed to resolve specifiers in \"%s\", ignoring: %m", destination
);
5114 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5120 /* Optionally, there's also a short option string specified */
5121 if (p
&& p
[-1] == ':') {
5122 _cleanup_free_
char *options
= NULL
;
5124 r
= extract_first_word(&p
, &options
, NULL
, EXTRACT_UNQUOTE
);
5128 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s=, ignoring: %s", lvalue
, rvalue
);
5132 if (isempty(options
) || streq(options
, "rbind"))
5134 else if (streq(options
, "norbind"))
5137 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid option string, ignoring setting: %s", options
);
5144 r
= bind_mount_add(&c
->bind_mounts
, &c
->n_bind_mounts
,
5148 .read_only
= !!strstr(lvalue
, "ReadOnly"),
5150 .ignore_enoent
= ignore_enoent
,
5159 int config_parse_mount_images(
5161 const char *filename
,
5163 const char *section
,
5164 unsigned section_line
,
5171 ExecContext
*c
= ASSERT_PTR(data
);
5172 const Unit
*u
= userdata
;
5179 if (isempty(rvalue
)) {
5180 /* Empty assignment resets the list */
5181 c
->mount_images
= mount_image_free_many(c
->mount_images
, &c
->n_mount_images
);
5185 for (const char *p
= rvalue
;;) {
5186 _cleanup_(mount_options_free_allp
) MountOptions
*options
= NULL
;
5187 _cleanup_free_
char *first
= NULL
, *second
= NULL
, *tuple
= NULL
;
5188 _cleanup_free_
char *sresolved
= NULL
, *dresolved
= NULL
;
5189 const char *q
= NULL
;
5191 bool permissive
= false;
5193 r
= extract_first_word(&p
, &tuple
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_RETAIN_ESCAPE
);
5197 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5198 "Invalid syntax %s=%s, ignoring: %m", lvalue
, rvalue
);
5205 r
= extract_many_words(&q
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
, &first
, &second
);
5209 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5210 "Invalid syntax in %s=, ignoring: %s", lvalue
, tuple
);
5222 r
= unit_path_printf(u
, s
, &sresolved
);
5224 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5225 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", s
);
5229 r
= path_simplify_and_warn(sresolved
, PATH_CHECK_ABSOLUTE
|PATH_CHECK_NON_API_VFS_DEV_OK
, unit
, filename
, line
, lvalue
);
5233 if (isempty(second
)) {
5234 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Missing destination in %s, ignoring: %s", lvalue
, rvalue
);
5238 r
= unit_path_printf(u
, second
, &dresolved
);
5240 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5241 "Failed to resolve specifiers in \"%s\", ignoring: %m", second
);
5245 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_ABSOLUTE
|PATH_CHECK_NON_API_VFS_DEV_OK
, unit
, filename
, line
, lvalue
);
5250 _cleanup_free_
char *partition
= NULL
, *mount_options
= NULL
, *mount_options_resolved
= NULL
;
5251 MountOptions
*o
= NULL
;
5252 PartitionDesignator partition_designator
;
5254 r
= extract_many_words(&q
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
, &partition
, &mount_options
);
5258 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", q
);
5263 /* Single set of options, applying to the root partition/single filesystem */
5265 r
= unit_full_printf(u
, partition
, &mount_options_resolved
);
5267 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", first
);
5271 o
= new(MountOptions
, 1);
5274 *o
= (MountOptions
) {
5275 .partition_designator
= PARTITION_ROOT
,
5276 .options
= TAKE_PTR(mount_options_resolved
),
5278 LIST_APPEND(mount_options
, options
, o
);
5283 partition_designator
= partition_designator_from_string(partition
);
5284 if (partition_designator
< 0) {
5285 log_syntax(unit
, LOG_WARNING
, filename
, line
, partition_designator
,
5286 "Invalid partition name %s, ignoring", partition
);
5289 r
= unit_full_printf(u
, mount_options
, &mount_options_resolved
);
5291 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", mount_options
);
5295 o
= new(MountOptions
, 1);
5298 *o
= (MountOptions
) {
5299 .partition_designator
= partition_designator
,
5300 .options
= TAKE_PTR(mount_options_resolved
),
5302 LIST_APPEND(mount_options
, options
, o
);
5305 r
= mount_image_add(&c
->mount_images
, &c
->n_mount_images
,
5307 .source
= sresolved
,
5308 .destination
= dresolved
,
5309 .mount_options
= options
,
5310 .ignore_enoent
= permissive
,
5311 .type
= MOUNT_IMAGE_DISCRETE
,
5318 int config_parse_extension_images(
5320 const char *filename
,
5322 const char *section
,
5323 unsigned section_line
,
5330 ExecContext
*c
= ASSERT_PTR(data
);
5331 const Unit
*u
= userdata
;
5338 if (isempty(rvalue
)) {
5339 /* Empty assignment resets the list */
5340 c
->extension_images
= mount_image_free_many(c
->extension_images
, &c
->n_extension_images
);
5344 for (const char *p
= rvalue
;;) {
5345 _cleanup_free_
char *source
= NULL
, *tuple
= NULL
, *sresolved
= NULL
;
5346 _cleanup_(mount_options_free_allp
) MountOptions
*options
= NULL
;
5347 bool permissive
= false;
5348 const char *q
= NULL
;
5351 r
= extract_first_word(&p
, &tuple
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_RETAIN_ESCAPE
);
5355 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5356 "Invalid syntax %s=%s, ignoring: %m", lvalue
, rvalue
);
5363 r
= extract_first_word(&q
, &source
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
);
5367 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5368 "Invalid syntax in %s=, ignoring: %s", lvalue
, tuple
);
5380 r
= unit_path_printf(u
, s
, &sresolved
);
5382 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5383 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", s
);
5387 r
= path_simplify_and_warn(sresolved
, PATH_CHECK_ABSOLUTE
|PATH_CHECK_NON_API_VFS
, unit
, filename
, line
, lvalue
);
5392 _cleanup_free_
char *partition
= NULL
, *mount_options
= NULL
, *mount_options_resolved
= NULL
;
5393 MountOptions
*o
= NULL
;
5394 PartitionDesignator partition_designator
;
5396 r
= extract_many_words(&q
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
, &partition
, &mount_options
);
5400 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", q
);
5405 /* Single set of options, applying to the root partition/single filesystem */
5407 r
= unit_full_printf(u
, partition
, &mount_options_resolved
);
5409 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", partition
);
5413 o
= new(MountOptions
, 1);
5416 *o
= (MountOptions
) {
5417 .partition_designator
= PARTITION_ROOT
,
5418 .options
= TAKE_PTR(mount_options_resolved
),
5420 LIST_APPEND(mount_options
, options
, o
);
5425 partition_designator
= partition_designator_from_string(partition
);
5426 if (partition_designator
< 0) {
5427 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid partition name %s, ignoring", partition
);
5430 r
= unit_full_printf(u
, mount_options
, &mount_options_resolved
);
5432 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", mount_options
);
5436 o
= new(MountOptions
, 1);
5439 *o
= (MountOptions
) {
5440 .partition_designator
= partition_designator
,
5441 .options
= TAKE_PTR(mount_options_resolved
),
5443 LIST_APPEND(mount_options
, options
, o
);
5446 r
= mount_image_add(&c
->extension_images
, &c
->n_extension_images
,
5448 .source
= sresolved
,
5449 .mount_options
= options
,
5450 .ignore_enoent
= permissive
,
5451 .type
= MOUNT_IMAGE_EXTENSION
,
5458 int config_parse_job_timeout_sec(
5460 const char *filename
,
5462 const char *section
,
5463 unsigned section_line
,
5470 Unit
*u
= ASSERT_PTR(data
);
5478 r
= parse_sec_fix_0(rvalue
, &usec
);
5480 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse JobTimeoutSec= parameter, ignoring: %s", rvalue
);
5484 /* If the user explicitly changed JobTimeoutSec= also change JobRunningTimeoutSec=, for compatibility with old
5485 * versions. If JobRunningTimeoutSec= was explicitly set, avoid this however as whatever the user picked should
5488 if (!u
->job_running_timeout_set
)
5489 u
->job_running_timeout
= usec
;
5491 u
->job_timeout
= usec
;
5496 int config_parse_job_running_timeout_sec(
5498 const char *filename
,
5500 const char *section
,
5501 unsigned section_line
,
5508 Unit
*u
= ASSERT_PTR(data
);
5516 r
= parse_sec_fix_0(rvalue
, &usec
);
5518 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse JobRunningTimeoutSec= parameter, ignoring: %s", rvalue
);
5522 u
->job_running_timeout
= usec
;
5523 u
->job_running_timeout_set
= true;
5528 int config_parse_emergency_action(
5530 const char *filename
,
5532 const char *section
,
5533 unsigned section_line
,
5540 EmergencyAction
*x
= ASSERT_PTR(data
);
5541 RuntimeScope runtime_scope
;
5548 /* If we have a unit determine the scope based on it */
5550 runtime_scope
= ((Unit
*) ASSERT_PTR(userdata
))->manager
->runtime_scope
;
5552 runtime_scope
= ltype
; /* otherwise, assume the scope is passed in via ltype */
5554 r
= parse_emergency_action(rvalue
, runtime_scope
, x
);
5556 if (r
== -EOPNOTSUPP
)
5557 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5558 "%s= specified as %s mode action, ignoring: %s",
5559 lvalue
, runtime_scope_to_string(runtime_scope
), rvalue
);
5561 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5562 "Failed to parse %s=, ignoring: %s", lvalue
, rvalue
);
5569 int config_parse_pid_file(
5571 const char *filename
,
5573 const char *section
,
5574 unsigned section_line
,
5581 _cleanup_free_
char *k
= NULL
, *n
= NULL
;
5582 const Unit
*u
= ASSERT_PTR(userdata
);
5590 if (isempty(rvalue
)) {
5591 /* An empty assignment removes already set value. */
5596 r
= unit_path_printf(u
, rvalue
, &k
);
5598 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
5602 /* If this is a relative path make it absolute by prefixing the /run */
5603 n
= path_make_absolute(k
, u
->manager
->prefix
[EXEC_DIRECTORY_RUNTIME
]);
5607 /* Check that the result is a sensible path */
5608 r
= path_simplify_and_warn(n
, PATH_CHECK_ABSOLUTE
|PATH_CHECK_NON_API_VFS
, unit
, filename
, line
, lvalue
);
5612 r
= patch_var_run(unit
, filename
, line
, lvalue
, &n
);
5616 free_and_replace(*s
, n
);
5620 int config_parse_exit_status(
5622 const char *filename
,
5624 const char *section
,
5625 unsigned section_line
,
5632 int *exit_status
= data
, r
;
5638 assert(exit_status
);
5640 if (isempty(rvalue
)) {
5645 r
= safe_atou8(rvalue
, &u
);
5647 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse exit status '%s', ignoring: %m", rvalue
);
5655 int config_parse_disable_controllers(
5657 const char *filename
,
5659 const char *section
,
5660 unsigned section_line
,
5668 CGroupContext
*c
= data
;
5669 CGroupMask disabled_mask
;
5671 /* 1. If empty, make all controllers eligible for use again.
5672 * 2. If non-empty, merge all listed controllers, space separated. */
5674 if (isempty(rvalue
)) {
5675 c
->disable_controllers
= 0;
5679 r
= cg_mask_from_string(rvalue
, &disabled_mask
);
5680 if (r
< 0 || disabled_mask
<= 0) {
5681 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid cgroup string: %s, ignoring", rvalue
);
5685 c
->disable_controllers
|= disabled_mask
;
5690 int config_parse_ip_filter_bpf_progs(
5692 const char *filename
,
5694 const char *section
,
5695 unsigned section_line
,
5702 _cleanup_free_
char *resolved
= NULL
;
5703 const Unit
*u
= userdata
;
5704 char ***paths
= ASSERT_PTR(data
);
5711 if (isempty(rvalue
)) {
5712 *paths
= strv_free(*paths
);
5716 r
= unit_path_printf(u
, rvalue
, &resolved
);
5718 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
5722 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5726 if (strv_contains(*paths
, resolved
))
5729 r
= strv_extend(paths
, resolved
);
5733 if (bpf_program_supported() <= 0) {
5734 static bool warned
= false;
5736 log_syntax(unit
, warned
? LOG_DEBUG
: LOG_WARNING
, filename
, line
, 0,
5737 "Configures an IP firewall with BPF programs (%s=%s), but the local system does not support BPF/cgroup based firewalling with multiple filters. "
5738 "Starting this unit will fail! (This warning is only shown for the first loaded unit using IP firewalling.)", lvalue
, rvalue
);
5746 int config_parse_bpf_foreign_program(
5748 const char *filename
,
5750 const char *section
,
5751 unsigned section_line
,
5757 _cleanup_free_
char *resolved
= NULL
, *word
= NULL
;
5758 CGroupContext
*c
= data
;
5759 const char *p
= ASSERT_PTR(rvalue
);
5766 if (isempty(rvalue
)) {
5767 while (c
->bpf_foreign_programs
)
5768 cgroup_context_remove_bpf_foreign_program(c
, c
->bpf_foreign_programs
);
5773 r
= extract_first_word(&p
, &word
, ":", 0);
5777 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse foreign BPF program, ignoring: %s", rvalue
);
5780 if (r
== 0 || isempty(p
)) {
5781 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid syntax in %s=, ignoring: %s", lvalue
, rvalue
);
5785 attach_type
= bpf_cgroup_attach_type_from_string(word
);
5786 if (attach_type
< 0) {
5787 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Unknown BPF attach type=%s, ignoring: %s", word
, rvalue
);
5791 r
= unit_path_printf(u
, p
, &resolved
);
5793 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %s", p
, rvalue
);
5797 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5801 r
= cgroup_context_add_bpf_foreign_program(c
, attach_type
, resolved
);
5803 return log_error_errno(r
, "Failed to add foreign BPF program to cgroup context: %m");
5808 int config_parse_cgroup_socket_bind(
5810 const char *filename
,
5812 const char *section
,
5813 unsigned section_line
,
5819 _cleanup_free_ CGroupSocketBindItem
*item
= NULL
;
5820 CGroupSocketBindItem
**head
= data
;
5821 uint16_t nr_ports
, port_min
;
5822 int af
, ip_protocol
, r
;
5824 if (isempty(rvalue
)) {
5825 cgroup_context_remove_socket_bind(head
);
5829 r
= parse_socket_bind_item(rvalue
, &af
, &ip_protocol
, &nr_ports
, &port_min
);
5833 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5834 "Unable to parse %s= assignment, ignoring: %s", lvalue
, rvalue
);
5838 item
= new(CGroupSocketBindItem
, 1);
5841 *item
= (CGroupSocketBindItem
) {
5842 .address_family
= af
,
5843 .ip_protocol
= ip_protocol
,
5844 .nr_ports
= nr_ports
,
5845 .port_min
= port_min
,
5848 LIST_PREPEND(socket_bind_items
, *head
, TAKE_PTR(item
));
5853 int config_parse_restrict_network_interfaces(
5855 const char *filename
,
5857 const char *section
,
5858 unsigned section_line
,
5864 CGroupContext
*c
= ASSERT_PTR(data
);
5865 bool is_allow_rule
= true;
5872 if (isempty(rvalue
)) {
5873 /* Empty assignment resets the list */
5874 c
->restrict_network_interfaces
= set_free(c
->restrict_network_interfaces
);
5878 if (rvalue
[0] == '~') {
5879 is_allow_rule
= false;
5883 if (set_isempty(c
->restrict_network_interfaces
))
5884 /* Only initialize this when creating the set */
5885 c
->restrict_network_interfaces_is_allow_list
= is_allow_rule
;
5887 for (const char *p
= rvalue
;;) {
5888 _cleanup_free_
char *word
= NULL
;
5890 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
5896 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5897 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
5901 if (!ifname_valid_full(word
, IFNAME_VALID_ALTERNATIVE
)) {
5902 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid interface name, ignoring: %s", word
);
5906 if (c
->restrict_network_interfaces_is_allow_list
!= is_allow_rule
)
5907 free(set_remove(c
->restrict_network_interfaces
, word
));
5909 r
= set_put_strdup(&c
->restrict_network_interfaces
, word
);
5918 int config_parse_mount_node(
5920 const char *filename
,
5922 const char *section
,
5923 unsigned section_line
,
5930 const Unit
*u
= ASSERT_PTR(userdata
);
5931 _cleanup_free_
char *resolved
= NULL
, *path
= NULL
;
5938 r
= unit_full_printf(u
, rvalue
, &resolved
);
5940 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
5944 path
= fstab_node_to_udev_node(resolved
);
5948 /* The source passed is not necessarily something we understand, and we pass it as-is to mount/swapon,
5949 * so path_is_valid is not used. But let's check for basic sanity, i.e. if the source is longer than
5950 * PATH_MAX, you're likely doing something wrong. */
5951 if (strlen(path
) >= PATH_MAX
) {
5952 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Resolved mount path '%s' too long, ignoring.", path
);
5956 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, path
, data
, userdata
);
5959 int config_parse_concurrency_max(
5961 const char *filename
,
5963 const char *section
,
5964 unsigned section_line
,
5971 unsigned *concurrency_max
= ASSERT_PTR(data
);
5973 if (isempty(rvalue
) || streq(rvalue
, "infinity")) {
5974 *concurrency_max
= UINT_MAX
;
5978 return config_parse_unsigned(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
);
5981 static int merge_by_names(Unit
*u
, Set
*names
, const char *id
) {
5987 /* Let's try to add in all names that are aliases of this unit */
5988 while ((k
= set_steal_first(names
))) {
5989 _cleanup_free_ _unused_
char *free_k
= k
;
5991 /* First try to merge in the other name into our unit */
5992 r
= unit_merge_by_name(u
, k
);
5996 /* Hmm, we couldn't merge the other unit into ours? Then let's try it the other way
5999 other
= manager_get_unit(u
->manager
, k
);
6001 return r
; /* return previous failure */
6003 r
= unit_merge(other
, u
);
6007 return merge_by_names(other
, names
, NULL
);
6010 if (streq_ptr(id
, k
))
6011 unit_choose_id(u
, id
);
6017 int unit_load_fragment(Unit
*u
) {
6021 assert(u
->load_state
== UNIT_STUB
);
6025 u
->access_selinux_context
= mfree(u
->access_selinux_context
);
6026 u
->load_state
= UNIT_LOADED
;
6030 /* Possibly rebuild the fragment map to catch new units */
6031 r
= unit_file_build_name_map(&u
->manager
->lookup_paths
,
6032 &u
->manager
->unit_cache_timestamp_hash
,
6033 &u
->manager
->unit_id_map
,
6034 &u
->manager
->unit_name_map
,
6035 &u
->manager
->unit_path_cache
);
6037 return log_error_errno(r
, "Failed to rebuild name map: %m");
6039 const char *fragment
;
6040 _cleanup_set_free_ Set
*names
= NULL
;
6041 r
= unit_file_find_fragment(u
->manager
->unit_id_map
,
6042 u
->manager
->unit_name_map
,
6046 if (r
< 0 && r
!= -ENOENT
)
6050 /* Open the file, check if this is a mask, otherwise read. */
6051 _cleanup_fclose_
FILE *f
= NULL
;
6054 /* Try to open the file name. A symlink is OK, for example for linked files or masks. We
6055 * expect that all symlinks within the lookup paths have been already resolved, but we don't
6056 * verify this here. */
6057 f
= fopen(fragment
, "re");
6059 return log_unit_notice_errno(u
, errno
, "Failed to open %s: %m", fragment
);
6061 if (fstat(fileno(f
), &st
) < 0)
6064 r
= free_and_strdup(&u
->fragment_path
, fragment
);
6068 if (null_or_empty(&st
)) {
6069 /* Unit file is masked */
6071 u
->load_state
= u
->perpetual
? UNIT_LOADED
: UNIT_MASKED
; /* don't allow perpetual units to ever be masked */
6072 u
->fragment_mtime
= 0;
6073 u
->access_selinux_context
= mfree(u
->access_selinux_context
);
6076 if (mac_selinux_use()) {
6077 _cleanup_freecon_
char *selcon
= NULL
;
6079 /* Cache the SELinux context of the unit file here. We'll make use of when checking access permissions to loaded units */
6080 r
= fgetfilecon_raw(fileno(f
), &selcon
);
6082 log_unit_warning_errno(u
, r
, "Failed to read SELinux context of '%s', ignoring: %m", fragment
);
6084 r
= free_and_strdup(&u
->access_selinux_context
, selcon
);
6089 u
->access_selinux_context
= mfree(u
->access_selinux_context
);
6091 u
->load_state
= UNIT_LOADED
;
6092 u
->fragment_mtime
= timespec_load(&st
.st_mtim
);
6094 /* Now, parse the file contents */
6095 r
= config_parse(u
->id
, fragment
, f
,
6096 UNIT_VTABLE(u
)->sections
,
6097 config_item_perf_lookup
, load_fragment_gperf_lookup
,
6102 log_unit_notice_errno(u
, r
, "Unit configuration has fatal error, unit will not be started.");
6108 /* Call merge_by_names with the name derived from the fragment path as the preferred name.
6110 * We do the merge dance here because for some unit types, the unit might have aliases which are not
6111 * declared in the file system. In particular, this is true (and frequent) for device and swap units.
6113 const char *id
= u
->id
;
6114 _cleanup_free_
char *filename
= NULL
, *free_id
= NULL
;
6117 r
= path_extract_filename(fragment
, &filename
);
6119 return log_debug_errno(r
, "Failed to extract filename from fragment '%s': %m", fragment
);
6122 if (unit_name_is_valid(id
, UNIT_NAME_TEMPLATE
)) {
6123 assert(u
->instance
); /* If we're not trying to use a template for non-instanced unit,
6124 * this must be set. */
6126 r
= unit_name_replace_instance(id
, u
->instance
, &free_id
);
6128 return log_debug_errno(r
, "Failed to build id (%s + %s): %m", id
, u
->instance
);
6133 return merge_by_names(u
, names
, id
);
6136 void unit_dump_config_items(FILE *f
) {
6137 static const struct {
6138 const ConfigParserCallback callback
;
6141 { config_parse_warn_compat
, "NOTSUPPORTED" },
6142 { config_parse_int
, "INTEGER" },
6143 { config_parse_unsigned
, "UNSIGNED" },
6144 { config_parse_iec_size
, "SIZE" },
6145 { config_parse_iec_uint64
, "SIZE" },
6146 { config_parse_si_uint64
, "SIZE" },
6147 { config_parse_bool
, "BOOLEAN" },
6148 { config_parse_string
, "STRING" },
6149 { config_parse_path
, "PATH" },
6150 { config_parse_unit_path_printf
, "PATH" },
6151 { config_parse_colon_separated_paths
, "PATH" },
6152 { config_parse_strv
, "STRING [...]" },
6153 { config_parse_exec_nice
, "NICE" },
6154 { config_parse_exec_oom_score_adjust
, "OOMSCOREADJUST" },
6155 { config_parse_exec_io_class
, "IOCLASS" },
6156 { config_parse_exec_io_priority
, "IOPRIORITY" },
6157 { config_parse_exec_cpu_sched_policy
, "CPUSCHEDPOLICY" },
6158 { config_parse_exec_cpu_sched_prio
, "CPUSCHEDPRIO" },
6159 { config_parse_exec_cpu_affinity
, "CPUAFFINITY" },
6160 { config_parse_mode
, "MODE" },
6161 { config_parse_unit_env_file
, "FILE" },
6162 { config_parse_exec_output
, "OUTPUT" },
6163 { config_parse_exec_input
, "INPUT" },
6164 { config_parse_log_facility
, "FACILITY" },
6165 { config_parse_log_level
, "LEVEL" },
6166 { config_parse_exec_secure_bits
, "SECUREBITS" },
6167 { config_parse_capability_set
, "BOUNDINGSET" },
6168 { config_parse_rlimit
, "LIMIT" },
6169 { config_parse_unit_deps
, "UNIT [...]" },
6170 { config_parse_exec
, "PATH [ARGUMENT [...]]" },
6171 { config_parse_service_type
, "SERVICETYPE" },
6172 { config_parse_service_exit_type
, "SERVICEEXITTYPE" },
6173 { config_parse_service_restart
, "SERVICERESTART" },
6174 { config_parse_service_restart_mode
, "SERVICERESTARTMODE" },
6175 { config_parse_service_timeout_failure_mode
, "TIMEOUTMODE" },
6176 { config_parse_kill_mode
, "KILLMODE" },
6177 { config_parse_signal
, "SIGNAL" },
6178 { config_parse_socket_listen
, "SOCKET [...]" },
6179 { config_parse_socket_bind
, "SOCKETBIND" },
6180 { config_parse_socket_bindtodevice
, "NETWORKINTERFACE" },
6181 { config_parse_sec
, "SECONDS" },
6182 { config_parse_nsec
, "NANOSECONDS" },
6183 { config_parse_namespace_path_strv
, "PATH [...]" },
6184 { config_parse_bind_paths
, "PATH[:PATH[:OPTIONS]] [...]" },
6185 { config_parse_unit_mounts_for
, "PATH [...]" },
6186 { config_parse_exec_mount_propagation_flag
,
6188 { config_parse_unit_string_printf
, "STRING" },
6189 { config_parse_trigger_unit
, "UNIT" },
6190 { config_parse_timer
, "TIMER" },
6191 { config_parse_path_spec
, "PATH" },
6192 { config_parse_notify_access
, "ACCESS" },
6193 { config_parse_ip_tos
, "TOS" },
6194 { config_parse_unit_condition_path
, "CONDITION" },
6195 { config_parse_unit_condition_string
, "CONDITION" },
6196 { config_parse_unit_slice
, "SLICE" },
6197 { config_parse_documentation
, "URL" },
6198 { config_parse_service_timeout
, "SECONDS" },
6199 { config_parse_emergency_action
, "ACTION" },
6200 { config_parse_set_status
, "STATUS" },
6201 { config_parse_service_sockets
, "SOCKETS" },
6202 { config_parse_environ
, "ENVIRON" },
6204 { config_parse_syscall_filter
, "SYSCALLS" },
6205 { config_parse_syscall_archs
, "ARCHS" },
6206 { config_parse_syscall_errno
, "ERRNO" },
6207 { config_parse_syscall_log
, "SYSCALLS" },
6208 { config_parse_address_families
, "FAMILIES" },
6210 { config_parse_namespace_flags
, "NAMESPACES" },
6211 { config_parse_restrict_filesystems
, "FILESYSTEMS" },
6212 { config_parse_cg_weight
, "WEIGHT" },
6213 { config_parse_cg_cpu_weight
, "CPUWEIGHT" },
6214 { config_parse_memory_limit
, "LIMIT" },
6215 { config_parse_device_allow
, "DEVICE" },
6216 { config_parse_device_policy
, "POLICY" },
6217 { config_parse_io_limit
, "LIMIT" },
6218 { config_parse_io_device_weight
, "DEVICEWEIGHT" },
6219 { config_parse_io_device_latency
, "DEVICELATENCY" },
6220 { config_parse_long
, "LONG" },
6221 { config_parse_socket_service
, "SERVICE" },
6223 { config_parse_exec_selinux_context
, "LABEL" },
6225 { config_parse_job_mode
, "MODE" },
6226 { config_parse_job_mode_isolate
, "BOOLEAN" },
6227 { config_parse_personality
, "PERSONALITY" },
6228 { config_parse_log_filter_patterns
, "REGEX" },
6229 { config_parse_mount_node
, "NODE" },
6232 const char *prev
= NULL
;
6236 NULSTR_FOREACH(i
, load_fragment_gperf_nulstr
) {
6237 const char *rvalue
= "OTHER", *lvalue
;
6238 const ConfigPerfItem
*p
;
6241 assert_se(p
= load_fragment_gperf_lookup(i
, strlen(i
)));
6243 /* Hide legacy settings */
6244 if (p
->parse
== config_parse_warn_compat
&&
6245 p
->ltype
== DISABLED_LEGACY
)
6248 FOREACH_ELEMENT(j
, table
)
6249 if (p
->parse
== j
->callback
) {
6254 dot
= strchr(i
, '.');
6255 lvalue
= dot
? dot
+ 1 : i
;
6258 size_t prefix_len
= dot
- i
;
6260 if (!prev
|| !strneq(prev
, i
, prefix_len
+1)) {
6264 fprintf(f
, "[%.*s]\n", (int) prefix_len
, i
);
6268 fprintf(f
, "%s=%s\n", lvalue
, rvalue
);
6273 int config_parse_show_status(
6275 const char *filename
,
6277 const char *section
,
6278 unsigned section_line
,
6286 ShowStatus
*b
= ASSERT_PTR(data
);
6292 k
= parse_show_status(rvalue
, b
);
6294 log_syntax(unit
, LOG_WARNING
, filename
, line
, k
, "Failed to parse show status setting, ignoring: %s", rvalue
);
6299 int config_parse_output_restricted(
6301 const char *filename
,
6303 const char *section
,
6304 unsigned section_line
,
6311 ExecOutput t
, *eo
= ASSERT_PTR(data
);
6312 bool obsolete
= false;
6318 if (streq(rvalue
, "syslog")) {
6319 t
= EXEC_OUTPUT_JOURNAL
;
6321 } else if (streq(rvalue
, "syslog+console")) {
6322 t
= EXEC_OUTPUT_JOURNAL_AND_CONSOLE
;
6325 t
= exec_output_from_string(rvalue
);
6327 log_syntax(unit
, LOG_WARNING
, filename
, line
, t
, "Failed to parse output type, ignoring: %s", rvalue
);
6331 if (IN_SET(t
, EXEC_OUTPUT_SOCKET
, EXEC_OUTPUT_NAMED_FD
, EXEC_OUTPUT_FILE
, EXEC_OUTPUT_FILE_APPEND
, EXEC_OUTPUT_FILE_TRUNCATE
)) {
6332 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Standard output types socket, fd:, file:, append:, truncate: are not supported as defaults, ignoring: %s", rvalue
);
6338 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
6339 "Standard output type %s is obsolete, automatically updating to %s. Please update your configuration.",
6340 rvalue
, exec_output_to_string(t
));
6346 int config_parse_crash_chvt(
6348 const char *filename
,
6350 const char *section
,
6351 unsigned section_line
,
6365 r
= parse_crash_chvt(rvalue
, data
);
6367 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse CrashChangeVT= setting, ignoring: %s", rvalue
);
6372 int config_parse_swap_priority(
6374 const char *filename
,
6376 const char *section
,
6377 unsigned section_line
,
6384 Swap
*s
= ASSERT_PTR(userdata
);
6392 if (isempty(rvalue
)) {
6393 s
->parameters_fragment
.priority
= -1;
6394 s
->parameters_fragment
.priority_set
= false;
6398 r
= safe_atoi(rvalue
, &priority
);
6400 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid swap priority '%s', ignoring.", rvalue
);
6404 if (priority
< -1) {
6405 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
);
6409 if (priority
> 32767) {
6410 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Swap priority out of range, ignoring: %s", rvalue
);
6414 s
->parameters_fragment
.priority
= priority
;
6415 s
->parameters_fragment
.priority_set
= true;
6419 int config_parse_watchdog_sec(
6421 const char *filename
,
6423 const char *section
,
6424 unsigned section_line
,
6431 usec_t
*usec
= data
;
6437 /* This is called for {Runtime,Reboot,KExec}WatchdogSec= where "default" maps to
6438 * USEC_INFINITY internally. */
6440 if (streq(rvalue
, "default"))
6441 *usec
= USEC_INFINITY
;
6442 else if (streq(rvalue
, "off"))
6445 return config_parse_sec(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
);
6450 int config_parse_tty_size(
6452 const char *filename
,
6454 const char *section
,
6455 unsigned section_line
,
6462 unsigned *sz
= data
;
6468 if (isempty(rvalue
)) {
6473 return config_parse_unsigned(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
);
6476 int config_parse_log_filter_patterns(
6478 const char *filename
,
6480 const char *section
,
6481 unsigned section_line
,
6488 ExecContext
*c
= ASSERT_PTR(data
);
6489 const char *pattern
= ASSERT_PTR(rvalue
);
6490 bool is_allowlist
= true;
6496 if (isempty(pattern
)) {
6497 /* Empty assignment resets the lists. */
6498 c
->log_filter_allowed_patterns
= set_free(c
->log_filter_allowed_patterns
);
6499 c
->log_filter_denied_patterns
= set_free(c
->log_filter_denied_patterns
);
6503 if (pattern
[0] == '~') {
6504 is_allowlist
= false;
6506 if (isempty(pattern
))
6507 /* LogFilterPatterns=~ is not considered a valid pattern. */
6508 return log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
6509 "Regex pattern invalid, ignoring: %s=%s", lvalue
, rvalue
);
6512 if (pattern_compile_and_log(pattern
, 0, NULL
) < 0)
6515 r
= set_put_strdup(is_allowlist
? &c
->log_filter_allowed_patterns
: &c
->log_filter_denied_patterns
,
6518 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
6519 "Failed to store log filtering pattern, ignoring: %s=%s", lvalue
, rvalue
);
6526 int config_parse_open_file(
6528 const char *filename
,
6530 const char *section
,
6531 unsigned section_line
,
6538 _cleanup_(open_file_freep
) OpenFile
*of
= NULL
;
6539 OpenFile
**head
= ASSERT_PTR(data
);
6546 if (isempty(rvalue
)) {
6547 open_file_free_many(head
);
6551 r
= open_file_parse(rvalue
, &of
);
6553 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse OpenFile= setting, ignoring: %s", rvalue
);
6557 LIST_APPEND(open_files
, *head
, TAKE_PTR(of
));
6562 int config_parse_cgroup_nft_set(
6564 const char *filename
,
6566 const char *section
,
6567 unsigned section_line
,
6574 CGroupContext
*c
= ASSERT_PTR(data
);
6575 Unit
*u
= ASSERT_PTR(userdata
);
6577 return config_parse_nft_set(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, &c
->nft_set_context
, u
);
6580 int config_parse_protect_hostname(
6582 const char *filename
,
6584 const char *section
,
6585 unsigned section_line
,
6592 ExecContext
*c
= ASSERT_PTR(data
);
6593 Unit
*u
= ASSERT_PTR(userdata
);
6594 _cleanup_free_
char *h
= NULL
, *p
= NULL
;
6597 if (isempty(rvalue
)) {
6598 c
->protect_hostname
= PROTECT_HOSTNAME_NO
;
6599 c
->private_hostname
= mfree(c
->private_hostname
);
6603 const char *colon
= strchr(rvalue
, ':');
6605 r
= unit_full_printf_full(u
, colon
+ 1, HOST_NAME_MAX
, &h
);
6607 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
6608 "Failed to resolve unit specifiers in '%s', ignoring: %m", colon
+ 1);
6612 if (!hostname_is_valid(h
, /* flags = */ 0))
6613 return log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
6614 "Invalid hostname is specified to %s=, ignoring: %s", lvalue
, h
);
6616 p
= strndup(rvalue
, colon
- rvalue
);
6621 ProtectHostname t
= protect_hostname_from_string(p
?: rvalue
);
6622 if (t
< 0 || (t
== PROTECT_HOSTNAME_NO
&& h
))
6623 return log_syntax_parse_error(unit
, filename
, line
, 0, lvalue
, rvalue
);
6625 c
->protect_hostname
= t
;
6626 free_and_replace(c
->private_hostname
, h
);