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
);
162 DEFINE_CONFIG_PARSE_ENUM(config_parse_socket_defer_trigger
, socket_defer_trigger
, SocketDeferTrigger
);
164 bool contains_instance_specifier_superset(const char *s
) {
166 bool percent
= false;
180 /* If the string is just the instance specifier, it's not a superset of the instance. */
181 if (memcmp_nn(p
, q
- p
, "%i", strlen("%i")) == 0)
184 /* %i, %n and %N all expand to the instance or a superset of it. */
189 if (IN_SET(*p
, 'n', 'N', 'i'))
197 /* `name` is the rendered version of `format` via `unit_printf` or similar functions. */
198 int unit_is_likely_recursive_template_dependency(Unit
*u
, const char *name
, const char *format
) {
199 const char *fragment_path
;
205 /* If a template unit has a direct dependency on itself that includes the unit instance as part of
206 * the template instance via a unit specifier (%i, %n or %N), this will almost certainly lead to
207 * infinite recursion as systemd will keep instantiating new instances of the template unit.
208 * https://github.com/systemd/systemd/issues/17602 shows a good example of how this can happen in
209 * practice. To guard against this, we check for templates that depend on themselves and have the
210 * instantiated unit instance included as part of the template instance of the dependency via a
213 * For example, if systemd-notify@.service depends on systemd-notify@%n.service, this will result in
214 * infinite recursion.
217 if (!unit_name_is_valid(name
, UNIT_NAME_INSTANCE
))
220 if (!unit_name_prefix_equal(u
->id
, name
))
223 if (u
->type
!= unit_name_to_type(name
))
226 r
= unit_file_find_fragment(u
->manager
->unit_id_map
, u
->manager
->unit_name_map
, name
, &fragment_path
, NULL
);
230 /* Fragment paths should also be equal as a custom fragment for a specific template instance
231 * wouldn't necessarily lead to infinite recursion. */
232 if (!path_equal(u
->fragment_path
, fragment_path
))
235 if (!contains_instance_specifier_superset(format
))
241 int config_parse_unit_deps(
243 const char *filename
,
246 unsigned section_line
,
253 UnitDependency d
= ltype
;
260 for (const char *p
= rvalue
;;) {
261 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
264 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_RETAIN_ESCAPE
);
270 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
274 r
= unit_name_printf(u
, word
, &k
);
276 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
280 r
= unit_is_likely_recursive_template_dependency(u
, k
, word
);
282 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to determine if '%s' is a recursive dependency, ignoring: %m", k
);
286 log_syntax(unit
, LOG_DEBUG
, filename
, line
, 0,
287 "Dropping dependency %s=%s that likely leads to infinite recursion.",
288 unit_dependency_to_string(d
), word
);
292 r
= unit_add_dependency_by_name(u
, d
, k
, true, UNIT_DEPENDENCY_FILE
);
294 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
298 int config_parse_obsolete_unit_deps(
300 const char *filename
,
303 unsigned section_line
,
310 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
311 "Unit dependency type %s= is obsolete, replacing by %s=, please update your unit file", lvalue
, unit_dependency_to_string(ltype
));
313 return config_parse_unit_deps(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
);
316 int config_parse_unit_string_printf(
318 const char *filename
,
321 unsigned section_line
,
328 _cleanup_free_
char *k
= NULL
;
329 const Unit
*u
= ASSERT_PTR(userdata
);
336 r
= unit_full_printf(u
, rvalue
, &k
);
338 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
342 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
345 int config_parse_reboot_parameter(
347 const char *filename
,
350 unsigned section_line
,
357 _cleanup_free_
char *k
= NULL
;
358 const Unit
*u
= ASSERT_PTR(userdata
);
365 r
= unit_full_printf(u
, rvalue
, &k
);
367 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
371 if (!reboot_parameter_is_valid(k
)) {
372 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid reboot parameter '%s', ignoring.", k
);
376 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
379 int config_parse_unit_strv_printf(
381 const char *filename
,
384 unsigned section_line
,
391 const Unit
*u
= ASSERT_PTR(userdata
);
392 _cleanup_free_
char *k
= NULL
;
399 r
= unit_full_printf(u
, rvalue
, &k
);
401 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
405 return config_parse_strv(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
408 int config_parse_unit_path_printf(
410 const char *filename
,
413 unsigned section_line
,
420 _cleanup_free_
char *k
= NULL
;
421 const Unit
*u
= ASSERT_PTR(userdata
);
429 r
= unit_path_printf(u
, rvalue
, &k
);
431 log_syntax(unit
, fatal
? LOG_ERR
: LOG_WARNING
, filename
, line
, r
,
432 "Failed to resolve unit specifiers in '%s'%s: %m",
433 rvalue
, fatal
? "" : ", ignoring");
434 return fatal
? -ENOEXEC
: 0;
437 return config_parse_path(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
440 int config_parse_colon_separated_paths(
442 const char *filename
,
445 unsigned section_line
,
452 char ***sv
= ASSERT_PTR(data
);
453 const Unit
*u
= ASSERT_PTR(userdata
);
460 if (isempty(rvalue
)) {
461 /* Empty assignment resets the list */
462 *sv
= strv_free(*sv
);
466 for (const char *p
= rvalue
;;) {
467 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
469 r
= extract_first_word(&p
, &word
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
473 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
479 r
= unit_path_printf(u
, word
, &k
);
481 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
482 "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
486 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
490 r
= strv_consume(sv
, TAKE_PTR(k
));
498 int config_parse_unit_path_strv_printf(
500 const char *filename
,
503 unsigned section_line
,
511 const Unit
*u
= ASSERT_PTR(userdata
);
518 if (isempty(rvalue
)) {
523 for (const char *p
= rvalue
;;) {
524 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
526 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
532 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
533 "Invalid syntax, ignoring: %s", rvalue
);
537 r
= unit_path_printf(u
, word
, &k
);
539 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
540 "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
544 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
548 r
= strv_consume(x
, TAKE_PTR(k
));
554 static int patch_var_run(
556 const char *filename
,
564 e
= path_startswith(*path
, "/var/run/");
568 z
= path_join("/run/", e
);
572 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
573 "%s= references a path below legacy directory /var/run/, updating %s → %s; "
574 "please update the unit file accordingly.", lvalue
, *path
, z
);
576 free_and_replace(*path
, z
);
581 int config_parse_socket_listen(
583 const char *filename
,
586 unsigned section_line
,
593 Socket
*s
= ASSERT_PTR(SOCKET(data
));
594 _cleanup_free_ SocketPort
*p
= NULL
;
601 if (isempty(rvalue
)) {
602 /* An empty assignment removes all ports */
603 socket_free_ports(s
);
607 p
= new(SocketPort
, 1);
616 if (ltype
!= SOCKET_SOCKET
) {
617 _cleanup_free_
char *k
= NULL
;
619 r
= unit_path_printf(UNIT(s
), rvalue
, &k
);
621 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
625 PathSimplifyWarnFlags flags
= PATH_CHECK_ABSOLUTE
;
626 if (ltype
!= SOCKET_SPECIAL
)
627 flags
|= PATH_CHECK_NON_API_VFS
;
629 r
= path_simplify_and_warn(k
, flags
, unit
, filename
, line
, lvalue
);
633 if (ltype
== SOCKET_FIFO
) {
634 r
= patch_var_run(unit
, filename
, line
, lvalue
, &k
);
639 free_and_replace(p
->path
, k
);
642 } else if (streq(lvalue
, "ListenNetlink")) {
643 _cleanup_free_
char *k
= NULL
;
645 r
= unit_path_printf(UNIT(s
), rvalue
, &k
);
647 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
651 r
= socket_address_parse_netlink(&p
->address
, k
);
653 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse address value in '%s', ignoring: %m", k
);
657 p
->type
= SOCKET_SOCKET
;
660 _cleanup_free_
char *k
= NULL
;
662 r
= unit_path_printf(UNIT(s
), rvalue
, &k
);
664 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
668 if (path_is_absolute(k
)) { /* Only for AF_UNIX file system sockets… */
669 r
= patch_var_run(unit
, filename
, line
, lvalue
, &k
);
674 r
= socket_address_parse_and_warn(&p
->address
, k
);
676 if (r
!= -EAFNOSUPPORT
)
677 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse address value in '%s', ignoring: %m", k
);
681 if (streq(lvalue
, "ListenStream"))
682 p
->address
.type
= SOCK_STREAM
;
683 else if (streq(lvalue
, "ListenDatagram"))
684 p
->address
.type
= SOCK_DGRAM
;
686 assert(streq(lvalue
, "ListenSequentialPacket"));
687 p
->address
.type
= SOCK_SEQPACKET
;
690 if (socket_address_family(&p
->address
) != AF_UNIX
&& p
->address
.type
== SOCK_SEQPACKET
) {
691 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Address family not supported, ignoring: %s", rvalue
);
695 p
->type
= SOCKET_SOCKET
;
698 LIST_APPEND(port
, s
->ports
, TAKE_PTR(p
));
702 int config_parse_exec_nice(
704 const char *filename
,
707 unsigned section_line
,
714 ExecContext
*c
= ASSERT_PTR(data
);
721 if (isempty(rvalue
)) {
726 r
= parse_nice(rvalue
, &priority
);
729 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Nice priority out of range, ignoring: %s", rvalue
);
731 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse nice priority '%s', ignoring: %m", rvalue
);
741 int config_parse_exec_oom_score_adjust(
743 const char *filename
,
746 unsigned section_line
,
753 ExecContext
*c
= ASSERT_PTR(data
);
760 if (isempty(rvalue
)) {
761 c
->oom_score_adjust_set
= false;
765 r
= parse_oom_score_adjust(rvalue
, &oa
);
768 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "OOM score adjust value out of range, ignoring: %s", rvalue
);
770 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse the OOM score adjust value '%s', ignoring: %m", rvalue
);
774 c
->oom_score_adjust
= oa
;
775 c
->oom_score_adjust_set
= true;
780 int config_parse_exec_coredump_filter(
782 const char *filename
,
785 unsigned section_line
,
792 ExecContext
*c
= ASSERT_PTR(data
);
799 if (isempty(rvalue
)) {
800 c
->coredump_filter
= 0;
801 c
->coredump_filter_set
= false;
806 r
= coredump_filter_mask_from_string(rvalue
, &f
);
808 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
809 "Failed to parse the CoredumpFilter=%s, ignoring: %m", rvalue
);
813 c
->coredump_filter
|= f
;
814 c
->coredump_filter_set
= true;
818 int config_parse_kill_mode(
820 const char *filename
,
823 unsigned section_line
,
830 KillMode
*k
= data
, m
;
837 if (isempty(rvalue
)) {
838 *k
= KILL_CONTROL_GROUP
;
842 m
= kill_mode_from_string(rvalue
);
844 log_syntax(unit
, LOG_WARNING
, filename
, line
, m
,
845 "Failed to parse kill mode specification, ignoring: %s", rvalue
);
850 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
851 "Unit uses KillMode=none. "
852 "This is unsafe, as it disables systemd's process lifecycle management for the service. "
853 "Please update the service to use a safer KillMode=, such as 'mixed' or 'control-group'. "
854 "Support for KillMode=none is deprecated and will eventually be removed.");
860 int config_parse_exec(
862 const char *filename
,
865 unsigned section_line
,
872 ExecCommand
**e
= ASSERT_PTR(data
);
873 const Unit
*u
= ASSERT_PTR(userdata
);
882 if (isempty(rvalue
)) {
883 /* An empty assignment resets the list */
884 *e
= exec_command_free_list(*e
);
888 const char *p
= rvalue
;
892 _cleanup_free_
char *firstword
= NULL
;
896 r
= extract_first_word_and_warn(&p
, &firstword
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
900 /* A lone ";" is a separator. Let's make sure we don't treat it as an executable name.
902 * SOFT DEPRECATION: We support multiple command lines in one ExecStart= line for
903 * compatibility with older versions, but we no longer document this exists, it's deprecated
904 * in a soft way. New unit files, should not use this feature. */
905 if (streq(firstword
, ";")) {
910 const char *f
= firstword
;
911 bool ignore
, separate_argv0
= false, ambient_hack
= false;
912 ExecCommandFlags flags
= 0;
915 /* We accept an absolute path as first argument. Valid prefixes and their effect:
917 * "-": Ignore if the path doesn't exist
918 * "@": Allow overriding argv[0] (supplied as a separate argument)
919 * "|": Prefix the cmdline with target user's shell (when combined with "@" invoke
920 * login shell semantics)
921 * ":": Disable environment variable substitution
922 * "+": Run with full privileges and no sandboxing
923 * "!": Apply sandboxing except for user/group credentials
926 if (*f
== '-' && !FLAGS_SET(flags
, EXEC_COMMAND_IGNORE_FAILURE
))
927 flags
|= EXEC_COMMAND_IGNORE_FAILURE
;
928 else if (*f
== '@' && !separate_argv0
)
929 separate_argv0
= true;
930 else if (*f
== ':' && !FLAGS_SET(flags
, EXEC_COMMAND_NO_ENV_EXPAND
))
931 flags
|= EXEC_COMMAND_NO_ENV_EXPAND
;
932 else if (*f
== '|' && !FLAGS_SET(flags
, EXEC_COMMAND_VIA_SHELL
))
933 flags
|= EXEC_COMMAND_VIA_SHELL
;
934 else if (*f
== '+' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
)) && !ambient_hack
)
935 flags
|= EXEC_COMMAND_FULLY_PRIVILEGED
;
936 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
)) && !ambient_hack
)
937 flags
|= EXEC_COMMAND_NO_SETUID
;
938 else if (*f
== '!' && !FLAGS_SET(flags
, EXEC_COMMAND_FULLY_PRIVILEGED
) && !ambient_hack
) {
939 /* Compatibility with the old !! ambient caps hack (removed in v258). Since
940 * we don't support that anymore and !! was a noop on non-supporting systems,
941 * we'll just turn off the EXEC_COMMAND_NO_SETUID flag again and be done with
943 flags
&= ~EXEC_COMMAND_NO_SETUID
;
946 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
947 "The !! modifier for %s= lines is no longer supported and is now ignored. "
948 "Please update your unit files and remove the modifier.", lvalue
);
953 ignore
= FLAGS_SET(flags
, EXEC_COMMAND_IGNORE_FAILURE
);
955 _cleanup_strv_free_
char **args
= NULL
;
956 _cleanup_free_
char *path
= NULL
;
958 if (FLAGS_SET(flags
, EXEC_COMMAND_VIA_SHELL
)) {
959 /* Use _PATH_BSHELL as placeholder since we can't do NSS lookups in pid1. This would
960 * be exported to various dbus properties and is used to determine SELinux label -
961 * which isn't accurate, but is a best-effort thing to assume all shells have more
962 * or less the same label. */
963 path
= strdup(_PATH_BSHELL
);
967 if (strv_extend_many(&args
, separate_argv0
? "-sh" : "sh", empty_to_null(f
)) < 0)
970 r
= unit_path_printf(u
, f
, &path
);
972 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
973 "Failed to resolve unit specifiers in '%s'%s: %m",
974 f
, ignore
? ", ignoring" : "");
975 return ignore
? 0 : -ENOEXEC
;
979 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
980 "Empty path in command line%s: %s",
981 ignore
? ", ignoring" : "", rvalue
);
982 return ignore
? 0 : -ENOEXEC
;
984 if (!string_is_safe(path
)) {
985 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
986 "Executable path contains special characters%s: %s",
987 ignore
? ", ignoring" : "", path
);
988 return ignore
? 0 : -ENOEXEC
;
990 if (path_implies_directory(path
)) {
991 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
992 "Executable path specifies a directory%s: %s",
993 ignore
? ", ignoring" : "", path
);
994 return ignore
? 0 : -ENOEXEC
;
997 if (!filename_or_absolute_path_is_valid(path
)) {
998 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
999 "Neither a valid executable name nor an absolute path%s: %s",
1000 ignore
? ", ignoring" : "", path
);
1001 return ignore
? 0 : -ENOEXEC
;
1004 if (!separate_argv0
)
1005 if (strv_extend(&args
, path
) < 0)
1009 while (!isempty(p
)) {
1010 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
1012 /* Check explicitly for an unquoted semicolon as command separator token. */
1013 if (p
[0] == ';' && (!p
[1] || strchr(WHITESPACE
, p
[1]))) {
1015 p
= skip_leading_chars(p
, /* bad = */ NULL
);
1020 /* Check for \; explicitly, to not confuse it with \\; or "\;" or "\\;" etc.
1021 * extract_first_word() would return the same for all of those. */
1022 if (p
[0] == '\\' && p
[1] == ';' && (!p
[2] || strchr(WHITESPACE
, p
[2]))) {
1024 p
= skip_leading_chars(p
, /* bad = */ NULL
);
1026 if (strv_extend(&args
, ";") < 0)
1032 r
= extract_first_word_and_warn(&p
, &word
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
1034 return ignore
? 0 : -ENOEXEC
;
1038 r
= unit_full_printf(u
, word
, &resolved
);
1040 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
1041 "Failed to resolve unit specifiers in '%s'%s: %m",
1042 word
, ignore
? ", ignoring" : "");
1043 return ignore
? 0 : -ENOEXEC
;
1046 if (strv_consume(&args
, TAKE_PTR(resolved
)) < 0)
1050 if (strv_isempty(args
)) {
1051 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
1052 "Empty executable name or zeroeth argument%s: %s",
1053 ignore
? ", ignoring" : "", rvalue
);
1054 return ignore
? 0 : -ENOEXEC
;
1057 ExecCommand
*nec
= new(ExecCommand
, 1);
1061 *nec
= (ExecCommand
) {
1062 .path
= path_simplify(TAKE_PTR(path
)),
1063 .argv
= TAKE_PTR(args
),
1067 exec_command_append_list(e
, nec
);
1070 } while (semicolon
);
1075 int config_parse_socket_bindtodevice(
1077 const char *filename
,
1079 const char *section
,
1080 unsigned section_line
,
1087 _cleanup_free_
char *p
= NULL
;
1088 Socket
*s
= ASSERT_PTR(data
);
1095 if (isempty(rvalue
) || streq(rvalue
, "*")) {
1096 s
->bind_to_device
= mfree(s
->bind_to_device
);
1100 r
= unit_full_printf(UNIT(s
), rvalue
, &p
);
1102 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
1106 if (!ifname_valid(p
)) {
1107 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid interface name, ignoring: %s", p
);
1111 return free_and_replace(s
->bind_to_device
, p
);
1114 int config_parse_exec_input(
1116 const char *filename
,
1118 const char *section
,
1119 unsigned section_line
,
1126 ExecContext
*c
= ASSERT_PTR(data
);
1127 const Unit
*u
= userdata
;
1136 n
= startswith(rvalue
, "fd:");
1138 _cleanup_free_
char *resolved
= NULL
;
1140 r
= unit_fd_printf(u
, n
, &resolved
);
1142 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", n
);
1146 if (isempty(resolved
))
1147 resolved
= mfree(resolved
);
1148 else if (!fdname_is_valid(resolved
)) {
1149 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", resolved
);
1153 free_and_replace(c
->stdio_fdname
[STDIN_FILENO
], resolved
);
1155 ei
= EXEC_INPUT_NAMED_FD
;
1157 } else if ((n
= startswith(rvalue
, "file:"))) {
1158 _cleanup_free_
char *resolved
= NULL
;
1160 r
= unit_path_printf(u
, n
, &resolved
);
1162 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", n
);
1166 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1170 free_and_replace(c
->stdio_file
[STDIN_FILENO
], resolved
);
1172 ei
= EXEC_INPUT_FILE
;
1175 ei
= exec_input_from_string(rvalue
);
1177 log_syntax(unit
, LOG_WARNING
, filename
, line
, ei
, "Failed to parse input specifier, ignoring: %s", rvalue
);
1186 int config_parse_exec_input_text(
1188 const char *filename
,
1190 const char *section
,
1191 unsigned section_line
,
1198 _cleanup_free_
char *unescaped
= NULL
, *resolved
= NULL
;
1199 ExecContext
*c
= ASSERT_PTR(data
);
1200 const Unit
*u
= userdata
;
1207 if (isempty(rvalue
)) {
1208 /* Reset if the empty string is assigned */
1209 c
->stdin_data
= mfree(c
->stdin_data
);
1210 c
->stdin_data_size
= 0;
1214 ssize_t l
= cunescape(rvalue
, 0, &unescaped
);
1216 log_syntax(unit
, LOG_WARNING
, filename
, line
, l
,
1217 "Failed to decode C escaped text '%s', ignoring: %m", rvalue
);
1221 r
= unit_full_printf_full(u
, unescaped
, EXEC_STDIN_DATA_MAX
, &resolved
);
1223 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1224 "Failed to resolve unit specifiers in '%s', ignoring: %m", unescaped
);
1228 size_t sz
= strlen(resolved
);
1229 if (c
->stdin_data_size
+ sz
+ 1 < c
->stdin_data_size
|| /* check for overflow */
1230 c
->stdin_data_size
+ sz
+ 1 > EXEC_STDIN_DATA_MAX
) {
1231 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
1232 "Standard input data too large (%zu), maximum of %zu permitted, ignoring.",
1233 c
->stdin_data_size
+ sz
, (size_t) EXEC_STDIN_DATA_MAX
);
1237 void *p
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
+ 1);
1241 *((char*) mempcpy((char*) p
+ c
->stdin_data_size
, resolved
, sz
)) = '\n';
1244 c
->stdin_data_size
+= sz
+ 1;
1249 int config_parse_exec_input_data(
1251 const char *filename
,
1253 const char *section
,
1254 unsigned section_line
,
1261 _cleanup_free_
void *p
= NULL
;
1262 ExecContext
*c
= ASSERT_PTR(data
);
1271 if (isempty(rvalue
)) {
1272 /* Reset if the empty string is assigned */
1273 c
->stdin_data
= mfree(c
->stdin_data
);
1274 c
->stdin_data_size
= 0;
1278 r
= unbase64mem(rvalue
, &p
, &sz
);
1280 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1281 "Failed to decode base64 data, ignoring: %s", rvalue
);
1287 if (c
->stdin_data_size
+ sz
< c
->stdin_data_size
|| /* check for overflow */
1288 c
->stdin_data_size
+ sz
> EXEC_STDIN_DATA_MAX
) {
1289 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
1290 "Standard input data too large (%zu), maximum of %zu permitted, ignoring.",
1291 c
->stdin_data_size
+ sz
, (size_t) EXEC_STDIN_DATA_MAX
);
1295 q
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
);
1299 memcpy((uint8_t*) q
+ c
->stdin_data_size
, p
, sz
);
1302 c
->stdin_data_size
+= sz
;
1307 int config_parse_exec_output(
1309 const char *filename
,
1311 const char *section
,
1312 unsigned section_line
,
1319 _cleanup_free_
char *resolved
= NULL
;
1321 ExecContext
*c
= ASSERT_PTR(data
);
1322 const Unit
*u
= userdata
;
1323 bool obsolete
= false;
1332 n
= startswith(rvalue
, "fd:");
1334 r
= unit_fd_printf(u
, n
, &resolved
);
1336 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", n
);
1340 if (isempty(resolved
))
1341 resolved
= mfree(resolved
);
1342 else if (!fdname_is_valid(resolved
)) {
1343 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", resolved
);
1347 eo
= EXEC_OUTPUT_NAMED_FD
;
1349 } else if (streq(rvalue
, "syslog")) {
1350 eo
= EXEC_OUTPUT_JOURNAL
;
1353 } else if (streq(rvalue
, "syslog+console")) {
1354 eo
= EXEC_OUTPUT_JOURNAL_AND_CONSOLE
;
1357 } else if ((n
= startswith(rvalue
, "file:"))) {
1359 r
= unit_path_printf(u
, n
, &resolved
);
1361 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", n
);
1365 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1369 eo
= EXEC_OUTPUT_FILE
;
1371 } else if ((n
= startswith(rvalue
, "append:"))) {
1373 r
= unit_path_printf(u
, n
, &resolved
);
1375 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", n
);
1379 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1383 eo
= EXEC_OUTPUT_FILE_APPEND
;
1385 } else if ((n
= startswith(rvalue
, "truncate:"))) {
1387 r
= unit_path_printf(u
, n
, &resolved
);
1389 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", n
);
1393 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1397 eo
= EXEC_OUTPUT_FILE_TRUNCATE
;
1399 eo
= exec_output_from_string(rvalue
);
1401 log_syntax(unit
, LOG_WARNING
, filename
, line
, eo
, "Failed to parse output specifier, ignoring: %s", rvalue
);
1407 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
1408 "Standard output type %s is obsolete, automatically updating to %s. Please update your unit file, and consider removing the setting altogether.",
1409 rvalue
, exec_output_to_string(eo
));
1411 if (streq(lvalue
, "StandardOutput")) {
1412 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1413 free_and_replace(c
->stdio_fdname
[STDOUT_FILENO
], resolved
);
1415 free_and_replace(c
->stdio_file
[STDOUT_FILENO
], resolved
);
1420 assert(streq(lvalue
, "StandardError"));
1422 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1423 free_and_replace(c
->stdio_fdname
[STDERR_FILENO
], resolved
);
1425 free_and_replace(c
->stdio_file
[STDERR_FILENO
], resolved
);
1433 int config_parse_exec_io_class(
1435 const char *filename
,
1437 const char *section
,
1438 unsigned section_line
,
1445 ExecContext
*c
= ASSERT_PTR(data
);
1452 if (isempty(rvalue
)) {
1453 c
->ioprio_is_set
= false;
1454 c
->ioprio
= IOPRIO_DEFAULT_CLASS_AND_PRIO
;
1458 x
= ioprio_class_from_string(rvalue
);
1460 log_syntax(unit
, LOG_WARNING
, filename
, line
, x
, "Failed to parse IO scheduling class, ignoring: %s", rvalue
);
1464 c
->ioprio
= ioprio_normalize(ioprio_prio_value(x
, ioprio_prio_data(c
->ioprio
)));
1465 c
->ioprio_is_set
= true;
1470 int config_parse_exec_io_priority(
1472 const char *filename
,
1474 const char *section
,
1475 unsigned section_line
,
1482 ExecContext
*c
= ASSERT_PTR(data
);
1489 if (isempty(rvalue
)) {
1490 c
->ioprio_is_set
= false;
1491 c
->ioprio
= IOPRIO_DEFAULT_CLASS_AND_PRIO
;
1495 r
= ioprio_parse_priority(rvalue
, &i
);
1497 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse IO priority, ignoring: %s", rvalue
);
1501 c
->ioprio
= ioprio_normalize(ioprio_prio_value(ioprio_prio_class(c
->ioprio
), i
));
1502 c
->ioprio_is_set
= true;
1507 int config_parse_exec_cpu_sched_policy(
1509 const char *filename
,
1511 const char *section
,
1512 unsigned section_line
,
1519 ExecContext
*c
= ASSERT_PTR(data
);
1526 if (isempty(rvalue
)) {
1527 c
->cpu_sched_set
= false;
1528 c
->cpu_sched_policy
= SCHED_OTHER
;
1529 c
->cpu_sched_priority
= 0;
1533 x
= sched_policy_from_string(rvalue
);
1535 log_syntax(unit
, LOG_WARNING
, filename
, line
, x
, "Failed to parse CPU scheduling policy, ignoring: %s", rvalue
);
1539 c
->cpu_sched_policy
= x
;
1540 /* Moving to or from real-time policy? We need to adjust the priority */
1541 c
->cpu_sched_priority
= CLAMP(c
->cpu_sched_priority
, sched_get_priority_min(x
), sched_get_priority_max(x
));
1542 c
->cpu_sched_set
= true;
1547 int config_parse_numa_mask(
1549 const char *filename
,
1551 const char *section
,
1552 unsigned section_line
,
1559 CPUSet
*cpu_set
= ASSERT_PTR(data
);
1566 if (streq(rvalue
, "all")) {
1567 _cleanup_(cpu_set_done
) CPUSet c
= {};
1569 r
= numa_mask_add_all(&c
);
1571 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1572 "Failed to create NUMA mask representing \"all\" NUMA nodes, ignoring: %m");
1574 cpu_set_done(cpu_set
);
1575 *cpu_set
= TAKE_STRUCT(c
);
1579 /* When parsing system.conf or user.conf, rather than unit files, userdata is NULL. */
1581 config_parse_unit_cpu_set(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
) :
1582 config_parse_cpu_set(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
);
1585 int config_parse_exec_cpu_sched_prio(
1587 const char *filename
,
1589 const char *section
,
1590 unsigned section_line
,
1597 ExecContext
*c
= ASSERT_PTR(data
);
1604 r
= safe_atoi(rvalue
, &i
);
1606 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse CPU scheduling priority, ignoring: %s", rvalue
);
1610 /* On Linux RR/FIFO range from 1 to 99 and OTHER/BATCH may only be 0. Policy might be set later so
1611 * we do not check the precise range, but only the generic outer bounds. */
1612 if (i
< 0 || i
> 99) {
1613 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "CPU scheduling priority is out of range, ignoring: %s", rvalue
);
1617 c
->cpu_sched_priority
= i
;
1618 c
->cpu_sched_set
= true;
1623 int config_parse_root_image_options(
1625 const char *filename
,
1627 const char *section
,
1628 unsigned section_line
,
1635 _cleanup_(mount_options_free_allp
) MountOptions
*options
= NULL
;
1636 _cleanup_strv_free_
char **l
= NULL
;
1637 ExecContext
*c
= ASSERT_PTR(data
);
1638 const Unit
*u
= userdata
;
1645 if (isempty(rvalue
)) {
1646 c
->root_image_options
= mount_options_free_all(c
->root_image_options
);
1650 r
= strv_split_colon_pairs(&l
, rvalue
);
1654 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
1658 STRV_FOREACH_PAIR(first
, second
, l
) {
1659 MountOptions
*o
= NULL
;
1660 _cleanup_free_
char *mount_options_resolved
= NULL
;
1661 const char *mount_options
= NULL
, *partition
= "root";
1662 PartitionDesignator partition_designator
;
1664 /* Format is either 'root:foo' or 'foo' (root is implied) */
1665 if (!isempty(*second
)) {
1667 mount_options
= *second
;
1669 mount_options
= *first
;
1671 partition_designator
= partition_designator_from_string(partition
);
1672 if (partition_designator
< 0) {
1673 log_syntax(unit
, LOG_WARNING
, filename
, line
, partition_designator
,
1674 "Invalid partition name %s, ignoring", partition
);
1677 r
= unit_full_printf(u
, mount_options
, &mount_options_resolved
);
1679 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", mount_options
);
1683 o
= new(MountOptions
, 1);
1686 *o
= (MountOptions
) {
1687 .partition_designator
= partition_designator
,
1688 .options
= TAKE_PTR(mount_options_resolved
),
1690 LIST_APPEND(mount_options
, options
, TAKE_PTR(o
));
1694 LIST_JOIN(mount_options
, c
->root_image_options
, options
);
1696 /* empty spaces/separators only */
1697 c
->root_image_options
= mount_options_free_all(c
->root_image_options
);
1702 int config_parse_exec_root_hash(
1704 const char *filename
,
1706 const char *section
,
1707 unsigned section_line
,
1714 _cleanup_free_
void *roothash_decoded
= NULL
;
1715 ExecContext
*c
= ASSERT_PTR(data
);
1716 size_t roothash_decoded_size
= 0;
1723 if (isempty(rvalue
)) {
1724 /* Reset if the empty string is assigned */
1725 c
->root_hash_path
= mfree(c
->root_hash_path
);
1726 c
->root_hash
= mfree(c
->root_hash
);
1727 c
->root_hash_size
= 0;
1731 if (path_is_absolute(rvalue
)) {
1732 /* We have the path to a roothash to load and decode, eg: RootHash=/foo/bar.roothash */
1733 _cleanup_free_
char *p
= NULL
;
1739 free_and_replace(c
->root_hash_path
, p
);
1740 c
->root_hash
= mfree(c
->root_hash
);
1741 c
->root_hash_size
= 0;
1745 /* We have a roothash to decode, eg: RootHash=012345789abcdef */
1746 r
= unhexmem(rvalue
, &roothash_decoded
, &roothash_decoded_size
);
1748 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to decode RootHash=, ignoring: %s", rvalue
);
1751 if (roothash_decoded_size
< sizeof(sd_id128_t
)) {
1752 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "RootHash= is too short, ignoring: %s", rvalue
);
1756 free_and_replace(c
->root_hash
, roothash_decoded
);
1757 c
->root_hash_size
= roothash_decoded_size
;
1758 c
->root_hash_path
= mfree(c
->root_hash_path
);
1763 int config_parse_exec_root_hash_sig(
1765 const char *filename
,
1767 const char *section
,
1768 unsigned section_line
,
1775 _cleanup_free_
void *roothash_sig_decoded
= NULL
;
1777 ExecContext
*c
= ASSERT_PTR(data
);
1778 size_t roothash_sig_decoded_size
= 0;
1785 if (isempty(rvalue
)) {
1786 /* Reset if the empty string is assigned */
1787 c
->root_hash_sig_path
= mfree(c
->root_hash_sig_path
);
1788 c
->root_hash_sig
= mfree(c
->root_hash_sig
);
1789 c
->root_hash_sig_size
= 0;
1793 if (path_is_absolute(rvalue
)) {
1794 /* We have the path to a roothash signature to load and decode, eg: RootHashSignature=/foo/bar.roothash.p7s */
1795 _cleanup_free_
char *p
= NULL
;
1801 free_and_replace(c
->root_hash_sig_path
, p
);
1802 c
->root_hash_sig
= mfree(c
->root_hash_sig
);
1803 c
->root_hash_sig_size
= 0;
1807 if (!(value
= startswith(rvalue
, "base64:"))) {
1808 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
1809 "Failed to decode RootHashSignature=, not a path but doesn't start with 'base64:', ignoring: %s", rvalue
);
1813 /* We have a roothash signature to decode, eg: RootHashSignature=base64:012345789abcdef */
1814 r
= unbase64mem(value
, &roothash_sig_decoded
, &roothash_sig_decoded_size
);
1816 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to decode RootHashSignature=, ignoring: %s", rvalue
);
1820 free_and_replace(c
->root_hash_sig
, roothash_sig_decoded
);
1821 c
->root_hash_sig_size
= roothash_sig_decoded_size
;
1822 c
->root_hash_sig_path
= mfree(c
->root_hash_sig_path
);
1827 int config_parse_exec_cpu_affinity(
1829 const char *filename
,
1831 const char *section
,
1832 unsigned section_line
,
1839 ExecContext
*c
= ASSERT_PTR(data
);
1846 if (streq(rvalue
, "numa")) {
1847 c
->cpu_affinity_from_numa
= true;
1848 cpu_set_done(&c
->cpu_set
);
1852 r
= config_parse_unit_cpu_set(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, &c
->cpu_set
, userdata
);
1854 c
->cpu_affinity_from_numa
= false;
1859 int config_parse_capability_set(
1861 const char *filename
,
1863 const char *section
,
1864 unsigned section_line
,
1871 uint64_t *capability_set
= ASSERT_PTR(data
);
1872 uint64_t sum
= 0, initial
, def
;
1873 bool invert
= false;
1880 if (rvalue
[0] == '~') {
1885 if (streq(lvalue
, "CapabilityBoundingSet")) {
1886 initial
= CAP_MASK_ALL
; /* initialized to all bits on */
1887 def
= CAP_MASK_UNSET
; /* not set */
1889 def
= initial
= 0; /* All bits off */
1891 r
= capability_set_from_string(rvalue
, &sum
);
1893 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= specifier '%s', ignoring: %m", lvalue
, rvalue
);
1897 if (sum
== 0 || *capability_set
== def
)
1898 /* "", "~" or uninitialized data -> replace */
1899 *capability_set
= invert
? ~sum
: sum
;
1901 /* previous data -> merge */
1903 *capability_set
&= ~sum
;
1905 *capability_set
|= sum
;
1911 int config_parse_exec_selinux_context(
1913 const char *filename
,
1915 const char *section
,
1916 unsigned section_line
,
1923 ExecContext
*c
= ASSERT_PTR(data
);
1924 const Unit
*u
= userdata
;
1933 if (isempty(rvalue
)) {
1934 c
->selinux_context
= mfree(c
->selinux_context
);
1935 c
->selinux_context_ignore
= false;
1939 if (rvalue
[0] == '-') {
1945 r
= unit_full_printf(u
, rvalue
, &k
);
1947 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
1948 "Failed to resolve unit specifiers in '%s'%s: %m",
1949 rvalue
, ignore
? ", ignoring" : "");
1950 return ignore
? 0 : -ENOEXEC
;
1953 free_and_replace(c
->selinux_context
, k
);
1954 c
->selinux_context_ignore
= ignore
;
1959 int config_parse_exec_apparmor_profile(
1961 const char *filename
,
1963 const char *section
,
1964 unsigned section_line
,
1971 ExecContext
*c
= ASSERT_PTR(data
);
1972 const Unit
*u
= userdata
;
1981 if (isempty(rvalue
)) {
1982 c
->apparmor_profile
= mfree(c
->apparmor_profile
);
1983 c
->apparmor_profile_ignore
= false;
1987 if (rvalue
[0] == '-') {
1993 r
= unit_full_printf(u
, rvalue
, &k
);
1995 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
1996 "Failed to resolve unit specifiers in '%s'%s: %m",
1997 rvalue
, ignore
? ", ignoring" : "");
1998 return ignore
? 0 : -ENOEXEC
;
2001 free_and_replace(c
->apparmor_profile
, k
);
2002 c
->apparmor_profile_ignore
= ignore
;
2007 int config_parse_exec_smack_process_label(
2009 const char *filename
,
2011 const char *section
,
2012 unsigned section_line
,
2019 ExecContext
*c
= ASSERT_PTR(data
);
2020 const Unit
*u
= userdata
;
2029 if (isempty(rvalue
)) {
2030 c
->smack_process_label
= mfree(c
->smack_process_label
);
2031 c
->smack_process_label_ignore
= false;
2035 if (rvalue
[0] == '-') {
2041 r
= unit_full_printf(u
, rvalue
, &k
);
2043 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
2044 "Failed to resolve unit specifiers in '%s'%s: %m",
2045 rvalue
, ignore
? ", ignoring" : "");
2046 return ignore
? 0 : -ENOEXEC
;
2049 free_and_replace(c
->smack_process_label
, k
);
2050 c
->smack_process_label_ignore
= ignore
;
2055 int config_parse_timer(
2057 const char *filename
,
2059 const char *section
,
2060 unsigned section_line
,
2067 _cleanup_(calendar_spec_freep
) CalendarSpec
*c
= NULL
;
2068 _cleanup_free_
char *k
= NULL
;
2069 const Unit
*u
= userdata
;
2070 Timer
*t
= ASSERT_PTR(data
);
2079 if (isempty(rvalue
)) {
2080 /* Empty assignment resets list */
2081 timer_free_values(t
);
2085 r
= unit_full_printf(u
, rvalue
, &k
);
2087 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2091 if (ltype
== TIMER_CALENDAR
) {
2092 r
= calendar_spec_from_string(k
, &c
);
2094 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse calendar specification, ignoring: %s", k
);
2098 r
= parse_sec(k
, &usec
);
2100 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse timer value, ignoring: %s", k
);
2105 v
= new(TimerValue
, 1);
2112 .calendar_spec
= TAKE_PTR(c
),
2115 LIST_PREPEND(value
, t
->values
, v
);
2120 int config_parse_trigger_unit(
2122 const char *filename
,
2124 const char *section
,
2125 unsigned section_line
,
2132 _cleanup_free_
char *p
= NULL
;
2133 Unit
*u
= ASSERT_PTR(data
);
2141 if (UNIT_TRIGGER(u
)) {
2142 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Multiple units to trigger specified, ignoring: %s", rvalue
);
2146 r
= unit_name_printf(u
, rvalue
, &p
);
2148 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2152 type
= unit_name_to_type(p
);
2154 log_syntax(unit
, LOG_WARNING
, filename
, line
, type
, "Unit type not valid, ignoring: %s", rvalue
);
2157 if (unit_has_name(u
, p
)) {
2158 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Units cannot trigger themselves, ignoring: %s", rvalue
);
2162 r
= unit_add_two_dependencies_by_name(u
, UNIT_BEFORE
, UNIT_TRIGGERS
, p
, true, UNIT_DEPENDENCY_FILE
);
2164 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add trigger on %s, ignoring: %m", p
);
2171 int config_parse_path_spec(
2173 const char *filename
,
2175 const char *section
,
2176 unsigned section_line
,
2183 Path
*p
= ASSERT_PTR(data
);
2186 _cleanup_free_
char *k
= NULL
;
2193 if (isempty(rvalue
)) {
2194 /* Empty assignment clears list */
2199 b
= path_type_from_string(lvalue
);
2201 log_syntax(unit
, LOG_WARNING
, filename
, line
, b
, "Failed to parse path type, ignoring: %s", lvalue
);
2205 r
= unit_path_printf(UNIT(p
), rvalue
, &k
);
2207 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2211 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2215 s
= new0(PathSpec
, 1);
2220 s
->path
= TAKE_PTR(k
);
2222 s
->inotify_fd
= -EBADF
;
2224 LIST_PREPEND(spec
, p
->specs
, s
);
2229 int config_parse_socket_service(
2231 const char *filename
,
2233 const char *section
,
2234 unsigned section_line
,
2241 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
2242 _cleanup_free_
char *p
= NULL
;
2243 Socket
*s
= ASSERT_PTR(data
);
2251 r
= unit_name_printf(UNIT(s
), rvalue
, &p
);
2253 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2257 if (!endswith(p
, ".service")) {
2258 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Unit must be of type service, ignoring: %s", rvalue
);
2262 r
= manager_load_unit(UNIT(s
)->manager
, p
, NULL
, &error
, &x
);
2264 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to load unit %s, ignoring: %s", rvalue
, bus_error_message(&error
, r
));
2268 unit_ref_set(&s
->service
, UNIT(s
), x
);
2273 int config_parse_fdname(
2275 const char *filename
,
2277 const char *section
,
2278 unsigned section_line
,
2285 _cleanup_free_
char *p
= NULL
;
2286 Socket
*s
= ASSERT_PTR(data
);
2293 if (isempty(rvalue
)) {
2294 s
->fdname
= mfree(s
->fdname
);
2298 r
= unit_fd_printf(UNIT(s
), rvalue
, &p
);
2300 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2304 if (!fdname_is_valid(p
)) {
2305 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", p
);
2309 return free_and_replace(s
->fdname
, p
);
2312 int config_parse_service_sockets(
2314 const char *filename
,
2316 const char *section
,
2317 unsigned section_line
,
2324 Service
*s
= ASSERT_PTR(data
);
2331 for (const char *p
= rvalue
;;) {
2332 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2334 r
= extract_first_word(&p
, &word
, NULL
, 0);
2338 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Trailing garbage in sockets, ignoring: %s", rvalue
);
2344 r
= unit_name_printf(UNIT(s
), word
, &k
);
2346 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
2350 if (!endswith(k
, ".socket")) {
2351 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Unit must be of type socket, ignoring: %s", k
);
2355 r
= unit_add_two_dependencies_by_name(UNIT(s
), UNIT_WANTS
, UNIT_AFTER
, k
, true, UNIT_DEPENDENCY_FILE
);
2357 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
2359 r
= unit_add_dependency_by_name(UNIT(s
), UNIT_TRIGGERED_BY
, k
, true, UNIT_DEPENDENCY_FILE
);
2361 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
2365 int config_parse_bus_name(
2367 const char *filename
,
2369 const char *section
,
2370 unsigned section_line
,
2377 _cleanup_free_
char *k
= NULL
;
2378 const Unit
*u
= ASSERT_PTR(userdata
);
2385 r
= unit_full_printf_full(u
, rvalue
, SD_BUS_MAXIMUM_NAME_LENGTH
, &k
);
2387 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2391 if (!sd_bus_service_name_is_valid(k
)) {
2392 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid bus name, ignoring: %s", k
);
2396 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
2399 int config_parse_service_timeout(
2401 const char *filename
,
2403 const char *section
,
2404 unsigned section_line
,
2411 Service
*s
= ASSERT_PTR(userdata
);
2419 /* This is called for two cases: TimeoutSec= and TimeoutStartSec=. */
2421 /* Traditionally, these options accepted 0 to disable the timeouts. However, a timeout of 0 suggests it happens
2422 * immediately, hence fix this to become USEC_INFINITY instead. This is in-line with how we internally handle
2423 * all other timeouts. */
2424 r
= parse_sec_fix_0(rvalue
, &usec
);
2426 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
2430 s
->start_timeout_defined
= true;
2431 s
->timeout_start_usec
= usec
;
2433 if (streq(lvalue
, "TimeoutSec"))
2434 s
->timeout_stop_usec
= usec
;
2439 int config_parse_timeout_abort(
2441 const char *filename
,
2443 const char *section
,
2444 unsigned section_line
,
2451 usec_t
*ret
= ASSERT_PTR(data
);
2458 /* Note: apart from setting the arg, this returns an extra bit of information in the return value. */
2460 if (isempty(rvalue
)) {
2462 return 0; /* "not set" */
2465 r
= parse_sec(rvalue
, ret
);
2467 return log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= setting, ignoring: %s", lvalue
, rvalue
);
2469 return 1; /* "set" */
2472 int config_parse_service_timeout_abort(
2474 const char *filename
,
2476 const char *section
,
2477 unsigned section_line
,
2484 Service
*s
= ASSERT_PTR(userdata
);
2487 r
= config_parse_timeout_abort(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
,
2488 &s
->timeout_abort_usec
, s
);
2490 s
->timeout_abort_set
= r
;
2494 int config_parse_user_group_compat(
2496 const char *filename
,
2498 const char *section
,
2499 unsigned section_line
,
2506 _cleanup_free_
char *k
= NULL
;
2508 const Unit
*u
= ASSERT_PTR(userdata
);
2515 if (isempty(rvalue
)) {
2516 *user
= mfree(*user
);
2520 r
= unit_full_printf(u
, rvalue
, &k
);
2522 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", rvalue
);
2526 if (!valid_user_group_name(k
, VALID_USER_ALLOW_NUMERIC
|VALID_USER_RELAX
|VALID_USER_WARN
)) {
2527 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2531 if (strstr(lvalue
, "User") && streq(k
, NOBODY_USER_NAME
))
2532 log_struct(LOG_NOTICE
,
2533 LOG_MESSAGE("%s:%u: Special user %s configured, this is not safe!", filename
, line
, k
),
2534 LOG_MESSAGE_ID(SD_MESSAGE_NOBODY_USER_UNSUITABLE_STR
),
2535 LOG_ITEM("UNIT=%s", unit
),
2536 LOG_ITEM("OFFENDING_USER=%s", k
),
2537 LOG_ITEM("CONFIG_FILE=%s", filename
),
2538 LOG_ITEM("CONFIG_LINE=%u", line
));
2540 return free_and_replace(*user
, k
);
2543 int config_parse_user_group_strv_compat(
2545 const char *filename
,
2547 const char *section
,
2548 unsigned section_line
,
2555 char ***users
= data
;
2556 const Unit
*u
= ASSERT_PTR(userdata
);
2563 if (isempty(rvalue
)) {
2564 *users
= strv_free(*users
);
2568 for (const char *p
= rvalue
;;) {
2569 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2571 r
= extract_first_word(&p
, &word
, NULL
, 0);
2575 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax: %s", rvalue
);
2581 r
= unit_full_printf(u
, word
, &k
);
2583 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", word
);
2587 if (!valid_user_group_name(k
, VALID_USER_ALLOW_NUMERIC
|VALID_USER_RELAX
|VALID_USER_WARN
)) {
2588 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2592 r
= strv_push(users
, k
);
2600 int config_parse_working_directory(
2602 const char *filename
,
2604 const char *section
,
2605 unsigned section_line
,
2612 ExecContext
*c
= ASSERT_PTR(data
);
2613 const Unit
*u
= ASSERT_PTR(userdata
);
2621 if (isempty(rvalue
)) {
2622 c
->working_directory_missing_ok
= false;
2623 c
->working_directory_home
= false;
2624 c
->working_directory
= mfree(c
->working_directory
);
2628 if (rvalue
[0] == '-') {
2634 if (streq(rvalue
, "~")) {
2635 c
->working_directory_home
= true;
2636 c
->working_directory
= mfree(c
->working_directory
);
2638 _cleanup_free_
char *k
= NULL
;
2640 r
= unit_path_printf(u
, rvalue
, &k
);
2642 log_syntax(unit
, missing_ok
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
2643 "Failed to resolve unit specifiers in working directory path '%s'%s: %m",
2644 rvalue
, missing_ok
? ", ignoring" : "");
2645 return missing_ok
? 0 : -ENOEXEC
;
2648 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
|(missing_ok
? 0 : PATH_CHECK_FATAL
),
2649 unit
, filename
, line
, lvalue
);
2651 return missing_ok
? 0 : -ENOEXEC
;
2653 c
->working_directory_home
= false;
2654 free_and_replace(c
->working_directory
, k
);
2657 c
->working_directory_missing_ok
= missing_ok
;
2661 int config_parse_unit_env_file(
2663 const char *filename
,
2665 const char *section
,
2666 unsigned section_line
,
2673 char ***env
= ASSERT_PTR(data
);
2674 const Unit
*u
= userdata
;
2675 _cleanup_free_
char *n
= NULL
;
2682 if (isempty(rvalue
)) {
2683 /* Empty assignment frees the list */
2684 *env
= strv_free(*env
);
2688 r
= unit_path_printf(u
, rvalue
, &n
);
2690 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2694 r
= path_simplify_and_warn(n
[0] == '-' ? n
+ 1 : n
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2698 r
= strv_push(env
, n
);
2707 int config_parse_environ(
2709 const char *filename
,
2711 const char *section
,
2712 unsigned section_line
,
2719 const Unit
*u
= userdata
;
2720 char ***env
= ASSERT_PTR(data
);
2727 if (isempty(rvalue
)) {
2728 /* Empty assignment resets the list */
2729 *env
= strv_free(*env
);
2733 /* If 'u' is set, we operate on the regular unit specifier table. Otherwise we use a manager-specific
2734 * specifier table (in which case ltype must contain the runtime scope). */
2735 const Specifier
*table
= u
? NULL
: (const Specifier
[]) {
2736 COMMON_SYSTEM_SPECIFIERS
,
2737 COMMON_TMP_SPECIFIERS
,
2738 COMMON_CREDS_SPECIFIERS(ltype
),
2739 { 'h', specifier_user_home
, NULL
},
2740 { 's', specifier_user_shell
, NULL
},
2744 for (const char *p
= rvalue
;; ) {
2745 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
2747 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2751 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2752 "Invalid syntax, ignoring: %s", rvalue
);
2759 r
= specifier_printf(word
, sc_arg_max(), table
, NULL
, NULL
, &resolved
);
2761 r
= unit_env_printf(u
, word
, &resolved
);
2763 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2764 "Failed to resolve specifiers in %s, ignoring: %m", word
);
2768 if (!env_assignment_is_valid(resolved
)) {
2769 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
2770 "Invalid environment assignment, ignoring: %s", resolved
);
2774 r
= strv_env_replace_consume(env
, TAKE_PTR(resolved
));
2776 return log_error_errno(r
, "Failed to update environment: %m");
2780 int config_parse_pass_environ(
2782 const char *filename
,
2784 const char *section
,
2785 unsigned section_line
,
2792 char ***passenv
= ASSERT_PTR(data
);
2793 const Unit
*u
= userdata
;
2800 if (isempty(rvalue
)) {
2801 /* Empty assignment resets the list */
2802 *passenv
= strv_free(*passenv
);
2806 _cleanup_strv_free_
char **n
= NULL
;
2808 for (const char *p
= rvalue
;;) {
2809 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2811 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
2815 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2816 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2823 r
= unit_env_printf(u
, word
, &k
);
2825 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2826 "Failed to resolve specifiers in %s, ignoring: %m", word
);
2832 if (!env_name_is_valid(k
)) {
2833 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
2834 "Invalid environment name for %s, ignoring: %s", lvalue
, k
);
2838 if (strv_consume(&n
, TAKE_PTR(k
)) < 0)
2842 r
= strv_extend_strv_consume(passenv
, TAKE_PTR(n
), /* filter_duplicates = */ true);
2849 int config_parse_unset_environ(
2851 const char *filename
,
2853 const char *section
,
2854 unsigned section_line
,
2861 char ***unsetenv
= ASSERT_PTR(data
);
2862 const Unit
*u
= userdata
;
2869 if (isempty(rvalue
)) {
2870 /* Empty assignment resets the list */
2871 *unsetenv
= strv_free(*unsetenv
);
2875 _cleanup_strv_free_
char **n
= NULL
;
2877 for (const char *p
= rvalue
;;) {
2878 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2880 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2884 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2885 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2892 r
= unit_env_printf(u
, word
, &k
);
2894 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2895 "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2901 if (!env_assignment_is_valid(k
) && !env_name_is_valid(k
)) {
2902 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
2903 "Invalid environment name or assignment %s, ignoring: %s", lvalue
, k
);
2907 if (strv_consume(&n
, TAKE_PTR(k
)) < 0)
2911 r
= strv_extend_strv_consume(unsetenv
, TAKE_PTR(n
), /* filter_duplicates = */ true);
2918 int config_parse_log_extra_fields(
2920 const char *filename
,
2922 const char *section
,
2923 unsigned section_line
,
2930 ExecContext
*c
= ASSERT_PTR(data
);
2931 const Unit
*u
= userdata
;
2938 if (isempty(rvalue
)) {
2939 exec_context_free_log_extra_fields(c
);
2943 for (const char *p
= rvalue
;;) {
2944 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2947 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2951 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
2957 r
= unit_full_printf(u
, word
, &k
);
2959 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2963 eq
= strchr(k
, '=');
2965 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Log field lacks '=' character, ignoring: %s", k
);
2969 if (!journal_field_valid(k
, eq
-k
, false)) {
2970 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Log field name is invalid, ignoring: %s", k
);
2974 if (!GREEDY_REALLOC(c
->log_extra_fields
, c
->n_log_extra_fields
+ 1))
2977 c
->log_extra_fields
[c
->n_log_extra_fields
++] = IOVEC_MAKE_STRING(k
);
2982 int config_parse_log_namespace(
2984 const char *filename
,
2986 const char *section
,
2987 unsigned section_line
,
2994 _cleanup_free_
char *k
= NULL
;
2995 ExecContext
*c
= ASSERT_PTR(data
);
2996 const Unit
*u
= userdata
;
3003 if (isempty(rvalue
)) {
3004 c
->log_namespace
= mfree(c
->log_namespace
);
3008 r
= unit_full_printf_full(u
, rvalue
, NAME_MAX
, &k
);
3010 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
3014 if (!log_namespace_name_valid(k
)) {
3015 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Specified log namespace name is not valid, ignoring: %s", k
);
3019 free_and_replace(c
->log_namespace
, k
);
3023 int config_parse_unit_condition_path(
3025 const char *filename
,
3027 const char *section
,
3028 unsigned section_line
,
3035 _cleanup_free_
char *p
= NULL
;
3036 Condition
**list
= ASSERT_PTR(data
), *c
;
3037 ConditionType t
= ltype
;
3038 bool trigger
, negate
;
3039 const Unit
*u
= userdata
;
3046 if (isempty(rvalue
)) {
3047 /* Empty assignment resets the list */
3048 *list
= condition_free_list(*list
);
3052 trigger
= rvalue
[0] == '|';
3056 negate
= rvalue
[0] == '!';
3060 r
= unit_path_printf(u
, rvalue
, &p
);
3062 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
3066 r
= path_simplify_and_warn(p
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
3070 c
= condition_new(t
, p
, trigger
, negate
);
3074 LIST_PREPEND(conditions
, *list
, c
);
3078 int config_parse_unit_condition_string(
3080 const char *filename
,
3082 const char *section
,
3083 unsigned section_line
,
3090 _cleanup_free_
char *s
= NULL
;
3091 Condition
**list
= ASSERT_PTR(data
), *c
;
3092 ConditionType t
= ltype
;
3093 bool trigger
, negate
;
3094 const Unit
*u
= userdata
;
3101 if (isempty(rvalue
)) {
3102 /* Empty assignment resets the list */
3103 *list
= condition_free_list(*list
);
3107 trigger
= *rvalue
== '|';
3109 rvalue
+= 1 + strspn(rvalue
+ 1, WHITESPACE
);
3111 negate
= *rvalue
== '!';
3113 rvalue
+= 1 + strspn(rvalue
+ 1, WHITESPACE
);
3115 r
= unit_full_printf(u
, rvalue
, &s
);
3117 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3118 "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
3122 c
= condition_new(t
, s
, trigger
, negate
);
3126 LIST_PREPEND(conditions
, *list
, c
);
3130 int config_parse_unit_mounts_for(
3132 const char *filename
,
3134 const char *section
,
3135 unsigned section_line
,
3149 assert(STR_IN_SET(lvalue
, "RequiresMountsFor", "WantsMountsFor"));
3151 for (const char *p
= rvalue
;;) {
3152 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
3154 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3158 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3159 "Invalid syntax, ignoring: %s", rvalue
);
3165 r
= unit_path_printf(u
, word
, &resolved
);
3167 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
3171 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
3175 r
= unit_add_mounts_for(u
, resolved
, UNIT_DEPENDENCY_FILE
, unit_mount_dependency_type_from_string(lvalue
));
3177 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add requested mount '%s', ignoring: %m", resolved
);
3183 int config_parse_documentation(
3185 const char *filename
,
3187 const char *section
,
3188 unsigned section_line
,
3195 Unit
*u
= ASSERT_PTR(userdata
);
3203 if (isempty(rvalue
)) {
3204 /* Empty assignment resets the list */
3205 u
->documentation
= strv_free(u
->documentation
);
3209 r
= config_parse_unit_strv_printf(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
,
3210 rvalue
, data
, userdata
);
3214 for (a
= b
= u
->documentation
; a
&& *a
; a
++) {
3216 if (documentation_url_is_valid(*a
))
3219 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid URL, ignoring: %s", *a
);
3230 int config_parse_syscall_filter(
3232 const char *filename
,
3234 const char *section
,
3235 unsigned section_line
,
3242 ExecContext
*c
= data
;
3243 _unused_
const Unit
*u
= ASSERT_PTR(userdata
);
3244 bool invert
= false;
3251 if (isempty(rvalue
)) {
3252 /* Empty assignment resets the list */
3253 c
->syscall_filter
= hashmap_free(c
->syscall_filter
);
3254 c
->syscall_allow_list
= false;
3258 if (rvalue
[0] == '~') {
3263 if (!c
->syscall_filter
) {
3264 c
->syscall_filter
= hashmap_new(NULL
);
3265 if (!c
->syscall_filter
)
3269 /* Allow everything but the ones listed */
3270 c
->syscall_allow_list
= false;
3272 /* Allow nothing but the ones listed */
3273 c
->syscall_allow_list
= true;
3275 /* Accept default syscalls if we are on an allow_list */
3276 r
= seccomp_parse_syscall_filter(
3277 "@default", -1, c
->syscall_filter
,
3278 SECCOMP_PARSE_PERMISSIVE
|SECCOMP_PARSE_ALLOW_LIST
,
3286 for (const char *p
= rvalue
;;) {
3287 _cleanup_free_
char *word
= NULL
, *name
= NULL
;
3290 r
= extract_first_word(&p
, &word
, NULL
, 0);
3294 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3295 "Invalid syntax, ignoring: %s", rvalue
);
3301 r
= parse_syscall_and_errno(word
, &name
, &num
);
3303 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3304 "Failed to parse syscall:errno, ignoring: %s", word
);
3307 if (!invert
&& num
>= 0) {
3308 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3309 "Allow-listed system calls cannot take error number, ignoring: %s", word
);
3313 r
= seccomp_parse_syscall_filter(
3314 name
, num
, c
->syscall_filter
,
3315 SECCOMP_PARSE_LOG
|SECCOMP_PARSE_PERMISSIVE
|
3316 (invert
? SECCOMP_PARSE_INVERT
: 0)|
3317 (c
->syscall_allow_list
? SECCOMP_PARSE_ALLOW_LIST
: 0),
3318 unit
, filename
, line
);
3324 int config_parse_syscall_log(
3326 const char *filename
,
3328 const char *section
,
3329 unsigned section_line
,
3336 ExecContext
*c
= data
;
3337 _unused_
const Unit
*u
= ASSERT_PTR(userdata
);
3338 bool invert
= false;
3346 if (isempty(rvalue
)) {
3347 /* Empty assignment resets the list */
3348 c
->syscall_log
= hashmap_free(c
->syscall_log
);
3349 c
->syscall_log_allow_list
= false;
3353 if (rvalue
[0] == '~') {
3358 if (!c
->syscall_log
) {
3359 c
->syscall_log
= hashmap_new(NULL
);
3360 if (!c
->syscall_log
)
3364 /* Log everything but the ones listed */
3365 c
->syscall_log_allow_list
= false;
3367 /* Log nothing but the ones listed */
3368 c
->syscall_log_allow_list
= true;
3373 _cleanup_free_
char *word
= NULL
;
3375 r
= extract_first_word(&p
, &word
, NULL
, 0);
3379 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3385 r
= seccomp_parse_syscall_filter(
3386 word
, -1, c
->syscall_log
,
3387 SECCOMP_PARSE_LOG
|SECCOMP_PARSE_PERMISSIVE
|
3388 (invert
? SECCOMP_PARSE_INVERT
: 0)|
3389 (c
->syscall_log_allow_list
? SECCOMP_PARSE_ALLOW_LIST
: 0),
3390 unit
, filename
, line
);
3396 int config_parse_syscall_archs(
3398 const char *filename
,
3400 const char *section
,
3401 unsigned section_line
,
3411 if (isempty(rvalue
)) {
3412 *archs
= set_free(*archs
);
3416 for (const char *p
= rvalue
;;) {
3417 _cleanup_free_
char *word
= NULL
;
3420 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3424 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3425 "Invalid syntax, ignoring: %s", rvalue
);
3431 r
= seccomp_arch_from_string(word
, &a
);
3433 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3434 "Failed to parse system call architecture \"%s\", ignoring: %m", word
);
3438 r
= set_ensure_put(archs
, NULL
, UINT32_TO_PTR(a
+ 1));
3444 int config_parse_syscall_errno(
3446 const char *filename
,
3448 const char *section
,
3449 unsigned section_line
,
3456 ExecContext
*c
= data
;
3463 if (isempty(rvalue
) || streq(rvalue
, "kill")) {
3464 /* Empty assignment resets to KILL */
3465 c
->syscall_errno
= SECCOMP_ERROR_NUMBER_KILL
;
3469 e
= parse_errno(rvalue
);
3471 log_syntax(unit
, LOG_WARNING
, filename
, line
, e
, "Failed to parse error number, ignoring: %s", rvalue
);
3475 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid error number, ignoring: %s", rvalue
);
3479 c
->syscall_errno
= e
;
3483 int config_parse_address_families(
3485 const char *filename
,
3487 const char *section
,
3488 unsigned section_line
,
3495 ExecContext
*c
= data
;
3496 bool invert
= false;
3503 if (isempty(rvalue
)) {
3504 /* Empty assignment resets the list */
3505 c
->address_families
= set_free(c
->address_families
);
3506 c
->address_families_allow_list
= false;
3510 if (streq(rvalue
, "none")) {
3511 /* Forbid all address families. */
3512 c
->address_families
= set_free(c
->address_families
);
3513 c
->address_families_allow_list
= true;
3517 if (rvalue
[0] == '~') {
3522 if (!c
->address_families
) {
3523 c
->address_families
= set_new(NULL
);
3524 if (!c
->address_families
)
3527 c
->address_families_allow_list
= !invert
;
3530 for (const char *p
= rvalue
;;) {
3531 _cleanup_free_
char *word
= NULL
;
3534 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3538 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3539 "Invalid syntax, ignoring: %s", rvalue
);
3545 af
= af_from_name(word
);
3547 log_syntax(unit
, LOG_WARNING
, filename
, line
, af
,
3548 "Failed to parse address family, ignoring: %s", word
);
3552 /* If we previously wanted to forbid an address family and now
3553 * we want to allow it, then just remove it from the list.
3555 if (!invert
== c
->address_families_allow_list
) {
3556 r
= set_put(c
->address_families
, INT_TO_PTR(af
));
3560 set_remove(c
->address_families
, INT_TO_PTR(af
));
3565 int config_parse_namespace_flags(
3567 const char *filename
,
3569 const char *section
,
3570 unsigned section_line
,
3577 unsigned long *flags
= data
;
3578 unsigned long all
= UPDATE_FLAG(NAMESPACE_FLAGS_ALL
, CLONE_NEWUSER
, !streq(lvalue
, "DelegateNamespaces"));
3580 bool invert
= false;
3583 if (isempty(rvalue
)) {
3584 /* Reset to the default. */
3585 *flags
= NAMESPACE_FLAGS_INITIAL
;
3589 /* Boolean parameter ignores the previous settings */
3590 r
= parse_boolean(rvalue
);
3592 /* RestrictNamespaces= value gets stored into a field with reverse semantics (the namespaces
3593 * which are retained), so RestrictNamespaces=true means we retain no access to any
3594 * namespaces and vice-versa. */
3595 *flags
= streq(lvalue
, "RestrictNamespaces") ? 0 : all
;
3597 } else if (r
== 0) {
3598 *flags
= streq(lvalue
, "RestrictNamespaces") ? all
: 0;
3602 if (rvalue
[0] == '~') {
3607 /* Not a boolean argument, in this case it's a list of namespace types. */
3608 r
= namespace_flags_from_string(rvalue
, &f
);
3610 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse namespace type string, ignoring: %s", rvalue
);
3614 if (*flags
== NAMESPACE_FLAGS_INITIAL
)
3615 /* Initial assignment. Just set the value. */
3616 f
= invert
? (~f
) & all
: f
;
3618 /* Merge the value with the previous one. */
3619 f
= UPDATE_FLAG(*flags
, f
, !invert
);
3621 if (FLAGS_SET(f
, CLONE_NEWUSER
) && streq(lvalue
, "DelegateNamespaces")) {
3622 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "The user namespace cannot be delegated with DelegateNamespaces=, ignoring: %s", rvalue
);
3631 int config_parse_restrict_filesystems(
3633 const char *filename
,
3635 const char *section
,
3636 unsigned section_line
,
3642 ExecContext
*c
= ASSERT_PTR(data
);
3643 bool invert
= false;
3650 if (isempty(rvalue
)) {
3651 /* Empty assignment resets the list */
3652 c
->restrict_filesystems
= set_free(c
->restrict_filesystems
);
3653 c
->restrict_filesystems_allow_list
= false;
3657 if (rvalue
[0] == '~') {
3662 if (!c
->restrict_filesystems
) {
3664 /* Allow everything but the ones listed */
3665 c
->restrict_filesystems_allow_list
= false;
3667 /* Allow nothing but the ones listed */
3668 c
->restrict_filesystems_allow_list
= true;
3671 for (const char *p
= rvalue
;;) {
3672 _cleanup_free_
char *word
= NULL
;
3674 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3680 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3681 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
3685 r
= bpf_restrict_fs_parse_filesystem(
3687 &c
->restrict_filesystems
,
3688 FILESYSTEM_PARSE_LOG
|
3689 (invert
? FILESYSTEM_PARSE_INVERT
: 0)|
3690 (c
->restrict_filesystems_allow_list
? FILESYSTEM_PARSE_ALLOW_LIST
: 0),
3691 unit
, filename
, line
);
3700 int config_parse_unit_slice(
3702 const char *filename
,
3704 const char *section
,
3705 unsigned section_line
,
3712 Unit
*u
= ASSERT_PTR(userdata
), *slice
;
3713 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
3714 _cleanup_free_
char *k
= NULL
;
3721 r
= unit_name_printf(u
, rvalue
, &k
);
3723 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
3727 r
= manager_load_unit(u
->manager
, k
, NULL
, &error
, &slice
);
3729 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to load slice unit %s, ignoring: %s", k
, bus_error_message(&error
, r
));
3733 r
= unit_set_slice(u
, slice
);
3735 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to assign slice %s to unit %s, ignoring: %m", slice
->id
, u
->id
);
3742 int config_parse_cpu_quota(
3744 const char *filename
,
3746 const char *section
,
3747 unsigned section_line
,
3754 CGroupContext
*c
= data
;
3761 if (isempty(rvalue
)) {
3762 c
->cpu_quota_per_sec_usec
= USEC_INFINITY
;
3766 r
= parse_permyriad_unbounded(rvalue
);
3768 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid CPU quota '%s', ignoring.", rvalue
);
3772 c
->cpu_quota_per_sec_usec
= ((usec_t
) r
* USEC_PER_SEC
) / 10000U;
3776 int config_parse_unit_cpu_set(
3778 const char *filename
,
3780 const char *section
,
3781 unsigned section_line
,
3788 const Unit
*u
= ASSERT_PTR(userdata
);
3789 _cleanup_free_
char *k
= NULL
;
3796 r
= unit_full_printf(u
, rvalue
, &k
);
3798 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3799 "Failed to resolve unit specifiers in '%s', ignoring: %m",
3804 return config_parse_cpu_set(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
3807 int config_parse_memory_limit(
3809 const char *filename
,
3811 const char *section
,
3812 unsigned section_line
,
3819 CGroupContext
*c
= data
;
3820 uint64_t bytes
= CGROUP_LIMIT_MAX
;
3823 if (isempty(rvalue
) && STR_IN_SET(lvalue
, "DefaultMemoryLow",
3828 bytes
= CGROUP_LIMIT_MIN
;
3829 else if (!isempty(rvalue
) && !streq(rvalue
, "infinity")) {
3831 r
= parse_permyriad(rvalue
);
3833 r
= parse_size(rvalue
, 1024, &bytes
);
3835 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid memory limit '%s', ignoring: %m", rvalue
);
3839 bytes
= physical_memory_scale(r
, 10000U);
3841 if (bytes
>= UINT64_MAX
||
3842 (bytes
<= 0 && !STR_IN_SET(lvalue
,
3844 "StartupMemorySwapMax",
3846 "StartupMemoryZSwapMax",
3851 "DefaultstartupMemoryLow",
3852 "DefaultMemoryMin"))) {
3853 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Memory limit '%s' out of range, ignoring.", rvalue
);
3858 if (streq(lvalue
, "DefaultMemoryLow")) {
3859 c
->default_memory_low
= bytes
;
3860 c
->default_memory_low_set
= true;
3861 } else if (streq(lvalue
, "DefaultStartupMemoryLow")) {
3862 c
->default_startup_memory_low
= bytes
;
3863 c
->default_startup_memory_low_set
= true;
3864 } else if (streq(lvalue
, "DefaultMemoryMin")) {
3865 c
->default_memory_min
= bytes
;
3866 c
->default_memory_min_set
= true;
3867 } else if (streq(lvalue
, "MemoryMin")) {
3868 c
->memory_min
= bytes
;
3869 c
->memory_min_set
= true;
3870 } else if (streq(lvalue
, "MemoryLow")) {
3871 c
->memory_low
= bytes
;
3872 c
->memory_low_set
= true;
3873 } else if (streq(lvalue
, "StartupMemoryLow")) {
3874 c
->startup_memory_low
= bytes
;
3875 c
->startup_memory_low_set
= true;
3876 } else if (streq(lvalue
, "MemoryHigh"))
3877 c
->memory_high
= bytes
;
3878 else if (streq(lvalue
, "StartupMemoryHigh")) {
3879 c
->startup_memory_high
= bytes
;
3880 c
->startup_memory_high_set
= true;
3881 } else if (streq(lvalue
, "MemoryMax"))
3882 c
->memory_max
= bytes
;
3883 else if (streq(lvalue
, "StartupMemoryMax")) {
3884 c
->startup_memory_max
= bytes
;
3885 c
->startup_memory_max_set
= true;
3886 } else if (streq(lvalue
, "MemorySwapMax"))
3887 c
->memory_swap_max
= bytes
;
3888 else if (streq(lvalue
, "StartupMemorySwapMax")) {
3889 c
->startup_memory_swap_max
= bytes
;
3890 c
->startup_memory_swap_max_set
= true;
3891 } else if (streq(lvalue
, "MemoryZSwapMax"))
3892 c
->memory_zswap_max
= bytes
;
3893 else if (streq(lvalue
, "StartupMemoryZSwapMax")) {
3894 c
->startup_memory_zswap_max
= bytes
;
3895 c
->startup_memory_zswap_max_set
= true;
3902 int config_parse_tasks_max(
3904 const char *filename
,
3906 const char *section
,
3907 unsigned section_line
,
3914 CGroupTasksMax
*tasks_max
= ASSERT_PTR(data
);
3915 const Unit
*u
= userdata
;
3919 if (isempty(rvalue
)) {
3920 *tasks_max
= u
? u
->manager
->defaults
.tasks_max
: CGROUP_TASKS_MAX_UNSET
;
3924 if (streq(rvalue
, "infinity")) {
3925 *tasks_max
= CGROUP_TASKS_MAX_UNSET
;
3929 r
= parse_permyriad(rvalue
);
3931 *tasks_max
= (CGroupTasksMax
) { r
, 10000U }; /* r‱ */
3933 r
= safe_atou64(rvalue
, &v
);
3935 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid maximum tasks value '%s', ignoring: %m", rvalue
);
3939 if (v
<= 0 || v
>= UINT64_MAX
) {
3940 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Maximum tasks value '%s' out of range, ignoring.", rvalue
);
3944 *tasks_max
= (CGroupTasksMax
) { v
};
3950 int config_parse_delegate(
3952 const char *filename
,
3954 const char *section
,
3955 unsigned section_line
,
3962 CGroupContext
*c
= data
;
3966 t
= unit_name_to_type(unit
);
3967 assert(t
!= _UNIT_TYPE_INVALID
);
3969 if (!unit_vtable
[t
]->can_delegate
) {
3970 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Delegate= setting not supported for this unit type, ignoring.");
3974 /* We either accept a boolean value, which may be used to turn on delegation for all controllers, or
3975 * turn it off for all. Or it takes a list of controller names, in which case we add the specified
3976 * controllers to the mask to delegate. Delegate= enables delegation without any controllers. */
3978 if (isempty(rvalue
)) {
3979 /* An empty string resets controllers and sets Delegate=yes. */
3981 c
->delegate_controllers
= 0;
3985 r
= parse_boolean(rvalue
);
3987 CGroupMask mask
= 0;
3989 for (const char *p
= rvalue
;;) {
3990 _cleanup_free_
char *word
= NULL
;
3991 CGroupController cc
;
3993 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3997 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
4003 cc
= cgroup_controller_from_string(word
);
4005 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid controller name '%s', ignoring", word
);
4009 mask
|= CGROUP_CONTROLLER_TO_MASK(cc
);
4013 c
->delegate_controllers
|= mask
;
4017 c
->delegate_controllers
= CGROUP_MASK_DELEGATE
;
4019 c
->delegate
= false;
4020 c
->delegate_controllers
= 0;
4026 int config_parse_delegate_subgroup(
4028 const char *filename
,
4030 const char *section
,
4031 unsigned section_line
,
4038 CGroupContext
*c
= ASSERT_PTR(data
);
4041 t
= unit_name_to_type(unit
);
4044 if (!unit_vtable
[t
]->can_delegate
) {
4045 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "DelegateSubgroup= setting not supported for this unit type, ignoring.");
4049 if (isempty(rvalue
)) {
4050 c
->delegate_subgroup
= mfree(c
->delegate_subgroup
);
4054 if (cg_needs_escape(rvalue
)) { /* Insist that specified names don't need escaping */
4055 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid control group name, ignoring: %s", rvalue
);
4059 return free_and_strdup_warn(&c
->delegate_subgroup
, rvalue
);
4062 int config_parse_managed_oom_mode(
4064 const char *filename
,
4066 const char *section
,
4067 unsigned section_line
,
4074 ManagedOOMMode
*mode
= data
, m
;
4077 t
= unit_name_to_type(unit
);
4078 assert(t
!= _UNIT_TYPE_INVALID
);
4080 if (!unit_vtable
[t
]->can_set_managed_oom
)
4081 return log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "%s= is not supported for this unit type, ignoring.", lvalue
);
4083 if (isempty(rvalue
)) {
4084 *mode
= MANAGED_OOM_AUTO
;
4088 m
= managed_oom_mode_from_string(rvalue
);
4090 log_syntax(unit
, LOG_WARNING
, filename
, line
, m
, "Invalid syntax, ignoring: %s", rvalue
);
4098 int config_parse_managed_oom_mem_pressure_limit(
4100 const char *filename
,
4102 const char *section
,
4103 unsigned section_line
,
4110 uint32_t *limit
= data
;
4114 t
= unit_name_to_type(unit
);
4115 assert(t
!= _UNIT_TYPE_INVALID
);
4117 if (!unit_vtable
[t
]->can_set_managed_oom
)
4118 return log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "%s= is not supported for this unit type, ignoring.", lvalue
);
4120 if (isempty(rvalue
)) {
4125 r
= parse_permyriad(rvalue
);
4127 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse memory pressure limit value, ignoring: %s", rvalue
);
4131 /* Normalize to 2^32-1 == 100% */
4132 *limit
= UINT32_SCALE_FROM_PERMYRIAD(r
);
4136 int config_parse_managed_oom_mem_pressure_duration_sec(
4138 const char *filename
,
4140 const char *section
,
4141 unsigned section_line
,
4148 usec_t usec
, *duration
= ASSERT_PTR(data
);
4152 t
= unit_name_to_type(unit
);
4153 assert(t
!= _UNIT_TYPE_INVALID
);
4155 if (!unit_vtable
[t
]->can_set_managed_oom
)
4156 return log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "%s= is not supported for this unit type, ignoring.", lvalue
);
4158 if (isempty(rvalue
)) {
4159 *duration
= USEC_INFINITY
;
4163 r
= parse_sec(rvalue
, &usec
);
4165 return log_syntax_parse_error(unit
, filename
, line
, r
, lvalue
, rvalue
);
4167 if (usec
< 1 * USEC_PER_SEC
|| usec
== USEC_INFINITY
)
4168 return log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "%s= must be at least 1s and less than infinity, ignoring: %s", lvalue
, rvalue
);
4174 int config_parse_device_allow(
4176 const char *filename
,
4178 const char *section
,
4179 unsigned section_line
,
4186 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4187 CGroupDevicePermissions permissions
;
4188 CGroupContext
*c
= data
;
4189 const char *p
= rvalue
;
4192 if (isempty(rvalue
)) {
4193 while (c
->device_allow
)
4194 cgroup_context_free_device_allow(c
, c
->device_allow
);
4199 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4203 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4204 "Failed to extract device path and rights from '%s', ignoring.", rvalue
);
4208 r
= unit_path_printf(userdata
, path
, &resolved
);
4210 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4211 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4215 if (!STARTSWITH_SET(resolved
, "block-", "char-")) {
4217 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4221 if (!valid_device_node_path(resolved
)) {
4222 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid device node path '%s', ignoring.", resolved
);
4227 permissions
= isempty(p
) ? 0 : cgroup_device_permissions_from_string(p
);
4228 if (permissions
< 0) {
4229 log_syntax(unit
, LOG_WARNING
, filename
, line
, permissions
, "Invalid device rights '%s', ignoring.", p
);
4233 return cgroup_context_add_device_allow(c
, resolved
, permissions
);
4236 int config_parse_io_device_weight(
4238 const char *filename
,
4240 const char *section
,
4241 unsigned section_line
,
4248 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4249 CGroupIODeviceWeight
*w
;
4250 CGroupContext
*c
= data
;
4251 const char *p
= ASSERT_PTR(rvalue
);
4258 if (isempty(rvalue
)) {
4259 while (c
->io_device_weights
)
4260 cgroup_context_free_io_device_weight(c
, c
->io_device_weights
);
4265 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4269 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4270 "Failed to extract device path and weight from '%s', ignoring.", rvalue
);
4273 if (r
== 0 || isempty(p
)) {
4274 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4275 "Invalid device path or weight specified in '%s', ignoring.", rvalue
);
4279 r
= unit_path_printf(userdata
, path
, &resolved
);
4281 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4282 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4286 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4290 r
= cg_weight_parse(p
, &u
);
4292 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "IO weight '%s' invalid, ignoring: %m", p
);
4296 assert(u
!= CGROUP_WEIGHT_INVALID
);
4298 w
= new0(CGroupIODeviceWeight
, 1);
4302 w
->path
= TAKE_PTR(resolved
);
4305 LIST_APPEND(device_weights
, c
->io_device_weights
, w
);
4309 int config_parse_io_device_latency(
4311 const char *filename
,
4313 const char *section
,
4314 unsigned section_line
,
4321 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4322 CGroupIODeviceLatency
*l
;
4323 CGroupContext
*c
= data
;
4324 const char *p
= ASSERT_PTR(rvalue
);
4331 if (isempty(rvalue
)) {
4332 while (c
->io_device_latencies
)
4333 cgroup_context_free_io_device_latency(c
, c
->io_device_latencies
);
4338 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4342 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4343 "Failed to extract device path and latency from '%s', ignoring.", rvalue
);
4346 if (r
== 0 || isempty(p
)) {
4347 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4348 "Invalid device path or latency specified in '%s', ignoring.", rvalue
);
4352 r
= unit_path_printf(userdata
, path
, &resolved
);
4354 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4355 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4359 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4363 r
= parse_sec(p
, &usec
);
4365 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse timer value, ignoring: %s", p
);
4369 l
= new0(CGroupIODeviceLatency
, 1);
4373 l
->path
= TAKE_PTR(resolved
);
4374 l
->target_usec
= usec
;
4376 LIST_APPEND(device_latencies
, c
->io_device_latencies
, l
);
4380 int config_parse_io_limit(
4382 const char *filename
,
4384 const char *section
,
4385 unsigned section_line
,
4392 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4393 CGroupIODeviceLimit
*l
= NULL
;
4394 CGroupContext
*c
= data
;
4395 CGroupIOLimitType type
;
4396 const char *p
= ASSERT_PTR(rvalue
);
4403 type
= cgroup_io_limit_type_from_string(lvalue
);
4406 if (isempty(rvalue
)) {
4407 LIST_FOREACH(device_limits
, t
, c
->io_device_limits
)
4408 t
->limits
[type
] = cgroup_io_limit_defaults
[type
];
4412 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4416 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4417 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
4420 if (r
== 0 || isempty(p
)) {
4421 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4422 "Invalid device node or bandwidth specified in '%s', ignoring.", rvalue
);
4426 r
= unit_path_printf(userdata
, path
, &resolved
);
4428 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4429 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4433 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4437 if (streq("infinity", p
))
4438 num
= CGROUP_LIMIT_MAX
;
4440 r
= parse_size(p
, 1000, &num
);
4441 if (r
< 0 || num
<= 0) {
4442 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid IO limit '%s', ignoring.", p
);
4447 LIST_FOREACH(device_limits
, t
, c
->io_device_limits
)
4448 if (path_equal(resolved
, t
->path
)) {
4454 l
= new0(CGroupIODeviceLimit
, 1);
4458 l
->path
= TAKE_PTR(resolved
);
4459 for (CGroupIOLimitType i
= 0; i
< _CGROUP_IO_LIMIT_TYPE_MAX
; i
++)
4460 l
->limits
[i
] = cgroup_io_limit_defaults
[i
];
4462 LIST_APPEND(device_limits
, c
->io_device_limits
, l
);
4465 l
->limits
[type
] = num
;
4470 int config_parse_job_mode_isolate(
4472 const char *filename
,
4474 const char *section
,
4475 unsigned section_line
,
4489 r
= parse_boolean(rvalue
);
4491 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse boolean, ignoring: %s", rvalue
);
4495 log_notice("%s is deprecated. Please use OnFailureJobMode= instead", lvalue
);
4497 *m
= r
? JOB_ISOLATE
: JOB_REPLACE
;
4501 int config_parse_exec_directories(
4503 const char *filename
,
4505 const char *section
,
4506 unsigned section_line
,
4513 ExecDirectory
*ed
= ASSERT_PTR(data
);
4514 const Unit
*u
= userdata
;
4521 if (isempty(rvalue
)) {
4522 /* Empty assignment resets the list */
4523 exec_directory_done(ed
);
4527 for (const char *p
= rvalue
;;) {
4528 _cleanup_free_
char *tuple
= NULL
;
4530 r
= extract_first_word(&p
, &tuple
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_RETAIN_ESCAPE
);
4534 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4535 "Invalid syntax %s=%s, ignoring: %m", lvalue
, rvalue
);
4541 _cleanup_free_
char *src
= NULL
, *dest
= NULL
, *flags
= NULL
;
4542 const char *q
= tuple
;
4543 r
= extract_many_words(&q
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
|EXTRACT_DONT_COALESCE_SEPARATORS
, &src
, &dest
, &flags
);
4547 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4548 "Invalid syntax in %s=, ignoring: %s", lvalue
, tuple
);
4552 _cleanup_free_
char *sresolved
= NULL
;
4553 r
= unit_path_printf(u
, src
, &sresolved
);
4555 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4556 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", src
);
4560 r
= path_simplify_and_warn(sresolved
, PATH_CHECK_RELATIVE
, unit
, filename
, line
, lvalue
);
4564 if (path_startswith(sresolved
, "private")) {
4565 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4566 "%s= path can't be 'private', ignoring assignment: %s", lvalue
, tuple
);
4570 if (!isempty(dest
) && streq(lvalue
, "ConfigurationDirectory")) {
4571 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4572 "Additional parameter is not supported for ConfigurationDirectory, ignoring: %s", tuple
);
4576 /* For State and Runtime directories we support an optional destination parameter, which
4577 * will be used to create a symlink to the source. */
4578 _cleanup_free_
char *dresolved
= NULL
;
4579 if (!isempty(dest
)) {
4580 r
= unit_path_printf(u
, dest
, &dresolved
);
4582 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4583 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", dest
);
4587 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_RELATIVE
, unit
, filename
, line
, lvalue
);
4592 ExecDirectoryFlags exec_directory_flags
= exec_directory_flags_from_string(flags
);
4593 if (exec_directory_flags
< 0 || (exec_directory_flags
& ~_EXEC_DIRECTORY_FLAGS_PUBLIC
) != 0) {
4594 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4595 "Invalid flags for %s=, ignoring: %s", lvalue
, flags
);
4599 r
= exec_directory_add(ed
, sresolved
, dresolved
, exec_directory_flags
);
4605 int config_parse_set_credential(
4607 const char *filename
,
4609 const char *section
,
4610 unsigned section_line
,
4617 ExecContext
*context
= ASSERT_PTR(data
);
4618 const Unit
*u
= ASSERT_PTR(userdata
);
4625 if (isempty(rvalue
)) {
4626 /* Empty assignment resets the list */
4627 context
->set_credentials
= hashmap_free(context
->set_credentials
);
4631 _cleanup_free_
char *word
= NULL
, *id
= NULL
;
4632 const char *p
= rvalue
;
4633 bool encrypted
= ltype
;
4635 r
= extract_first_word(&p
, &word
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4639 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract credential name, ignoring: %s", rvalue
);
4642 if (r
== 0 || isempty(p
)) {
4643 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid syntax, ignoring: %s", rvalue
);
4647 r
= unit_cred_printf(u
, word
, &id
);
4649 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
4652 if (!credential_name_valid(id
)) {
4653 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Credential name \"%s\" not valid, ignoring.", id
);
4657 _cleanup_free_
void *d
= NULL
;
4661 r
= unbase64mem_full(p
, SIZE_MAX
, /* secure = */ true, &d
, &size
);
4665 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Encrypted credential data not valid Base64 data, ignoring: %m");
4671 /* We support escape codes here, so that users can insert trailing \n if they like */
4672 l
= cunescape(p
, UNESCAPE_ACCEPT_NUL
, (char**) &d
);
4676 log_syntax(unit
, LOG_WARNING
, filename
, line
, l
, "Can't unescape \"%s\", ignoring: %m", p
);
4683 r
= exec_context_put_set_credential(context
, id
, TAKE_PTR(d
), size
, encrypted
);
4685 return log_error_errno(r
, "Failed to store set credential '%s': %m", rvalue
);
4690 int config_parse_load_credential(
4692 const char *filename
,
4694 const char *section
,
4695 unsigned section_line
,
4702 ExecContext
*context
= ASSERT_PTR(data
);
4703 const Unit
*u
= ASSERT_PTR(userdata
);
4710 if (isempty(rvalue
)) {
4711 /* Empty assignment resets the list */
4712 context
->load_credentials
= hashmap_free(context
->load_credentials
);
4716 _cleanup_free_
char *word
= NULL
, *id
= NULL
, *path
= NULL
;
4717 const char *p
= rvalue
;
4718 bool encrypted
= ltype
;
4720 r
= extract_first_word(&p
, &word
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4724 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
4728 r
= unit_cred_printf(u
, word
, &id
);
4730 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
4733 if (!credential_name_valid(id
)) {
4734 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Credential name \"%s\" not valid, ignoring.", id
);
4739 /* If only one field is specified take it as shortcut for inheriting a credential named
4740 * the same way from our parent */
4745 r
= unit_path_printf(u
, p
, &path
);
4747 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", p
);
4750 if (path_is_absolute(path
) ? !path_is_normalized(path
) : !credential_name_valid(path
)) {
4751 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Credential source \"%s\" not valid, ignoring.", path
);
4756 r
= exec_context_put_load_credential(context
, id
, path
, encrypted
);
4758 return log_error_errno(r
, "Failed to store load credential '%s': %m", rvalue
);
4763 int config_parse_import_credential(
4765 const char *filename
,
4767 const char *section
,
4768 unsigned section_line
,
4775 ExecContext
*context
= ASSERT_PTR(data
);
4783 if (isempty(rvalue
)) {
4784 /* Empty assignment resets the list */
4785 context
->import_credentials
= ordered_set_free(context
->import_credentials
);
4789 const char *p
= rvalue
;
4790 _cleanup_free_
char *word
= NULL
, *glob
= NULL
;
4792 r
= extract_first_word(&p
, &word
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4796 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
4800 r
= unit_cred_printf(u
, word
, &glob
);
4802 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
4806 if (!credential_glob_valid(glob
)) {
4807 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Credential name or glob \"%s\" not valid, ignoring.", glob
);
4811 if (!isempty(p
) && !credential_name_valid(p
)) {
4812 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Credential name \"%s\" not valid, ignoring.", p
);
4816 r
= exec_context_put_import_credential(context
, glob
, p
);
4818 return log_error_errno(r
, "Failed to store import credential '%s': %m", rvalue
);
4823 int config_parse_set_status(
4825 const char *filename
,
4827 const char *section
,
4828 unsigned section_line
,
4835 ExitStatusSet
*status_set
= ASSERT_PTR(data
);
4842 /* Empty assignment resets the list */
4843 if (isempty(rvalue
)) {
4844 exit_status_set_free(status_set
);
4848 for (const char *p
= rvalue
;;) {
4849 _cleanup_free_
char *word
= NULL
;
4852 r
= extract_first_word(&p
, &word
, NULL
, 0);
4856 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4857 "Failed to parse %s=%s, ignoring: %m", lvalue
, rvalue
);
4863 /* We need to call exit_status_from_string() first, because we want
4864 * to parse numbers as exit statuses, not signals. */
4866 r
= exit_status_from_string(word
);
4868 assert(r
>= 0 && r
< 256);
4869 bitmap
= &status_set
->status
;
4871 r
= signal_from_string(word
);
4873 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4874 "Failed to parse value, ignoring: %s", word
);
4877 bitmap
= &status_set
->signal
;
4880 r
= bitmap_set(bitmap
, r
);
4882 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4883 "Failed to set signal or status %s, ignoring: %m", word
);
4887 int config_parse_namespace_path_strv(
4889 const char *filename
,
4891 const char *section
,
4892 unsigned section_line
,
4899 const Unit
*u
= userdata
;
4900 char*** sv
= ASSERT_PTR(data
);
4907 if (isempty(rvalue
)) {
4908 /* Empty assignment resets the list */
4909 *sv
= strv_free(*sv
);
4913 for (const char *p
= rvalue
;;) {
4914 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
, *joined
= NULL
;
4916 bool ignore_enoent
= false, shall_prefix
= false;
4918 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
4922 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
4929 if (startswith(w
, "-")) {
4930 ignore_enoent
= true;
4933 if (startswith(w
, "+")) {
4934 shall_prefix
= true;
4938 r
= unit_path_printf(u
, w
, &resolved
);
4940 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", w
);
4944 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4948 joined
= strjoin(ignore_enoent
? "-" : "",
4949 shall_prefix
? "+" : "",
4952 r
= strv_push(sv
, joined
);
4962 int config_parse_temporary_filesystems(
4964 const char *filename
,
4966 const char *section
,
4967 unsigned section_line
,
4974 const Unit
*u
= userdata
;
4975 ExecContext
*c
= ASSERT_PTR(data
);
4982 if (isempty(rvalue
)) {
4983 /* Empty assignment resets the list */
4984 temporary_filesystem_free_many(c
->temporary_filesystems
, c
->n_temporary_filesystems
);
4985 c
->temporary_filesystems
= NULL
;
4986 c
->n_temporary_filesystems
= 0;
4990 for (const char *p
= rvalue
;;) {
4991 _cleanup_free_
char *word
= NULL
, *path
= NULL
, *resolved
= NULL
;
4994 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
4998 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
5005 r
= extract_first_word(&w
, &path
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
5009 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", word
);
5013 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid syntax, ignoring: %s", word
);
5017 r
= unit_path_printf(u
, path
, &resolved
);
5019 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", path
);
5023 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5027 r
= temporary_filesystem_add(&c
->temporary_filesystems
, &c
->n_temporary_filesystems
, resolved
, w
);
5033 int config_parse_bind_paths(
5035 const char *filename
,
5037 const char *section
,
5038 unsigned section_line
,
5045 ExecContext
*c
= ASSERT_PTR(data
);
5046 const Unit
*u
= ASSERT_PTR(userdata
);
5053 if (isempty(rvalue
)) {
5054 /* Empty assignment resets the list */
5055 bind_mount_free_many(c
->bind_mounts
, c
->n_bind_mounts
);
5056 c
->bind_mounts
= NULL
;
5057 c
->n_bind_mounts
= 0;
5061 for (const char *p
= rvalue
;;) {
5062 _cleanup_free_
char *source
= NULL
, *destination
= NULL
;
5063 _cleanup_free_
char *sresolved
= NULL
, *dresolved
= NULL
;
5064 char *s
= NULL
, *d
= NULL
;
5065 bool rbind
= true, ignore_enoent
= false;
5067 r
= extract_first_word(&p
, &source
, ":" WHITESPACE
, EXTRACT_UNQUOTE
|EXTRACT_DONT_COALESCE_SEPARATORS
);
5071 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
5077 r
= unit_path_printf(u
, source
, &sresolved
);
5079 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5080 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", source
);
5086 ignore_enoent
= true;
5090 r
= path_simplify_and_warn(s
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5094 /* Optionally, the destination is specified. */
5095 if (p
&& p
[-1] == ':') {
5096 r
= extract_first_word(&p
, &destination
, ":" WHITESPACE
, EXTRACT_UNQUOTE
|EXTRACT_DONT_COALESCE_SEPARATORS
);
5100 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
5104 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Missing argument after ':', ignoring: %s", s
);
5108 r
= unit_path_printf(u
, destination
, &dresolved
);
5110 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5111 "Failed to resolve specifiers in \"%s\", ignoring: %m", destination
);
5115 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5121 /* Optionally, there's also a short option string specified */
5122 if (p
&& p
[-1] == ':') {
5123 _cleanup_free_
char *options
= NULL
;
5125 r
= extract_first_word(&p
, &options
, NULL
, EXTRACT_UNQUOTE
);
5129 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s=, ignoring: %s", lvalue
, rvalue
);
5133 if (isempty(options
) || streq(options
, "rbind"))
5135 else if (streq(options
, "norbind"))
5138 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid option string, ignoring setting: %s", options
);
5145 r
= bind_mount_add(&c
->bind_mounts
, &c
->n_bind_mounts
,
5149 .read_only
= !!strstr(lvalue
, "ReadOnly"),
5151 .ignore_enoent
= ignore_enoent
,
5160 int config_parse_mount_images(
5162 const char *filename
,
5164 const char *section
,
5165 unsigned section_line
,
5172 ExecContext
*c
= ASSERT_PTR(data
);
5173 const Unit
*u
= userdata
;
5180 if (isempty(rvalue
)) {
5181 /* Empty assignment resets the list */
5182 c
->mount_images
= mount_image_free_many(c
->mount_images
, &c
->n_mount_images
);
5186 for (const char *p
= rvalue
;;) {
5187 _cleanup_(mount_options_free_allp
) MountOptions
*options
= NULL
;
5188 _cleanup_free_
char *first
= NULL
, *second
= NULL
, *tuple
= NULL
;
5189 _cleanup_free_
char *sresolved
= NULL
, *dresolved
= NULL
;
5190 const char *q
= NULL
;
5192 bool permissive
= false;
5194 r
= extract_first_word(&p
, &tuple
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_RETAIN_ESCAPE
);
5198 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5199 "Invalid syntax %s=%s, ignoring: %m", lvalue
, rvalue
);
5206 r
= extract_many_words(&q
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
, &first
, &second
);
5210 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5211 "Invalid syntax in %s=, ignoring: %s", lvalue
, tuple
);
5223 r
= unit_path_printf(u
, s
, &sresolved
);
5225 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5226 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", s
);
5230 r
= path_simplify_and_warn(sresolved
, PATH_CHECK_ABSOLUTE
|PATH_CHECK_NON_API_VFS_DEV_OK
, unit
, filename
, line
, lvalue
);
5234 if (isempty(second
)) {
5235 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Missing destination in %s, ignoring: %s", lvalue
, rvalue
);
5239 r
= unit_path_printf(u
, second
, &dresolved
);
5241 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5242 "Failed to resolve specifiers in \"%s\", ignoring: %m", second
);
5246 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_ABSOLUTE
|PATH_CHECK_NON_API_VFS_DEV_OK
, unit
, filename
, line
, lvalue
);
5251 _cleanup_free_
char *partition
= NULL
, *mount_options
= NULL
, *mount_options_resolved
= NULL
;
5252 MountOptions
*o
= NULL
;
5253 PartitionDesignator partition_designator
;
5255 r
= extract_many_words(&q
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
, &partition
, &mount_options
);
5259 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", q
);
5264 /* Single set of options, applying to the root partition/single filesystem */
5266 r
= unit_full_printf(u
, partition
, &mount_options_resolved
);
5268 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", first
);
5272 o
= new(MountOptions
, 1);
5275 *o
= (MountOptions
) {
5276 .partition_designator
= PARTITION_ROOT
,
5277 .options
= TAKE_PTR(mount_options_resolved
),
5279 LIST_APPEND(mount_options
, options
, o
);
5284 partition_designator
= partition_designator_from_string(partition
);
5285 if (partition_designator
< 0) {
5286 log_syntax(unit
, LOG_WARNING
, filename
, line
, partition_designator
,
5287 "Invalid partition name %s, ignoring", partition
);
5290 r
= unit_full_printf(u
, mount_options
, &mount_options_resolved
);
5292 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", mount_options
);
5296 o
= new(MountOptions
, 1);
5299 *o
= (MountOptions
) {
5300 .partition_designator
= partition_designator
,
5301 .options
= TAKE_PTR(mount_options_resolved
),
5303 LIST_APPEND(mount_options
, options
, o
);
5306 r
= mount_image_add(&c
->mount_images
, &c
->n_mount_images
,
5308 .source
= sresolved
,
5309 .destination
= dresolved
,
5310 .mount_options
= options
,
5311 .ignore_enoent
= permissive
,
5312 .type
= MOUNT_IMAGE_DISCRETE
,
5319 int config_parse_extension_images(
5321 const char *filename
,
5323 const char *section
,
5324 unsigned section_line
,
5331 ExecContext
*c
= ASSERT_PTR(data
);
5332 const Unit
*u
= userdata
;
5339 if (isempty(rvalue
)) {
5340 /* Empty assignment resets the list */
5341 c
->extension_images
= mount_image_free_many(c
->extension_images
, &c
->n_extension_images
);
5345 for (const char *p
= rvalue
;;) {
5346 _cleanup_free_
char *source
= NULL
, *tuple
= NULL
, *sresolved
= NULL
;
5347 _cleanup_(mount_options_free_allp
) MountOptions
*options
= NULL
;
5348 bool permissive
= false;
5349 const char *q
= NULL
;
5352 r
= extract_first_word(&p
, &tuple
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_RETAIN_ESCAPE
);
5356 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5357 "Invalid syntax %s=%s, ignoring: %m", lvalue
, rvalue
);
5364 r
= extract_first_word(&q
, &source
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
);
5368 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5369 "Invalid syntax in %s=, ignoring: %s", lvalue
, tuple
);
5381 r
= unit_path_printf(u
, s
, &sresolved
);
5383 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5384 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", s
);
5388 r
= path_simplify_and_warn(sresolved
, PATH_CHECK_ABSOLUTE
|PATH_CHECK_NON_API_VFS
, unit
, filename
, line
, lvalue
);
5393 _cleanup_free_
char *partition
= NULL
, *mount_options
= NULL
, *mount_options_resolved
= NULL
;
5394 MountOptions
*o
= NULL
;
5395 PartitionDesignator partition_designator
;
5397 r
= extract_many_words(&q
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
, &partition
, &mount_options
);
5401 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", q
);
5406 /* Single set of options, applying to the root partition/single filesystem */
5408 r
= unit_full_printf(u
, partition
, &mount_options_resolved
);
5410 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", partition
);
5414 o
= new(MountOptions
, 1);
5417 *o
= (MountOptions
) {
5418 .partition_designator
= PARTITION_ROOT
,
5419 .options
= TAKE_PTR(mount_options_resolved
),
5421 LIST_APPEND(mount_options
, options
, o
);
5426 partition_designator
= partition_designator_from_string(partition
);
5427 if (partition_designator
< 0) {
5428 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid partition name %s, ignoring", partition
);
5431 r
= unit_full_printf(u
, mount_options
, &mount_options_resolved
);
5433 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", mount_options
);
5437 o
= new(MountOptions
, 1);
5440 *o
= (MountOptions
) {
5441 .partition_designator
= partition_designator
,
5442 .options
= TAKE_PTR(mount_options_resolved
),
5444 LIST_APPEND(mount_options
, options
, o
);
5447 r
= mount_image_add(&c
->extension_images
, &c
->n_extension_images
,
5449 .source
= sresolved
,
5450 .mount_options
= options
,
5451 .ignore_enoent
= permissive
,
5452 .type
= MOUNT_IMAGE_EXTENSION
,
5459 int config_parse_job_timeout_sec(
5461 const char *filename
,
5463 const char *section
,
5464 unsigned section_line
,
5471 Unit
*u
= ASSERT_PTR(data
);
5479 r
= parse_sec_fix_0(rvalue
, &usec
);
5481 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse JobTimeoutSec= parameter, ignoring: %s", rvalue
);
5485 /* If the user explicitly changed JobTimeoutSec= also change JobRunningTimeoutSec=, for compatibility with old
5486 * versions. If JobRunningTimeoutSec= was explicitly set, avoid this however as whatever the user picked should
5489 if (!u
->job_running_timeout_set
)
5490 u
->job_running_timeout
= usec
;
5492 u
->job_timeout
= usec
;
5497 int config_parse_job_running_timeout_sec(
5499 const char *filename
,
5501 const char *section
,
5502 unsigned section_line
,
5509 Unit
*u
= ASSERT_PTR(data
);
5517 r
= parse_sec_fix_0(rvalue
, &usec
);
5519 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse JobRunningTimeoutSec= parameter, ignoring: %s", rvalue
);
5523 u
->job_running_timeout
= usec
;
5524 u
->job_running_timeout_set
= true;
5529 int config_parse_emergency_action(
5531 const char *filename
,
5533 const char *section
,
5534 unsigned section_line
,
5541 EmergencyAction
*x
= ASSERT_PTR(data
);
5542 RuntimeScope runtime_scope
;
5549 /* If we have a unit determine the scope based on it */
5551 runtime_scope
= ((Unit
*) ASSERT_PTR(userdata
))->manager
->runtime_scope
;
5553 runtime_scope
= ltype
; /* otherwise, assume the scope is passed in via ltype */
5555 r
= parse_emergency_action(rvalue
, runtime_scope
, x
);
5557 if (r
== -EOPNOTSUPP
)
5558 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5559 "%s= specified as %s mode action, ignoring: %s",
5560 lvalue
, runtime_scope_to_string(runtime_scope
), rvalue
);
5562 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5563 "Failed to parse %s=, ignoring: %s", lvalue
, rvalue
);
5570 int config_parse_pid_file(
5572 const char *filename
,
5574 const char *section
,
5575 unsigned section_line
,
5582 _cleanup_free_
char *k
= NULL
, *n
= NULL
;
5583 const Unit
*u
= ASSERT_PTR(userdata
);
5591 if (isempty(rvalue
)) {
5592 /* An empty assignment removes already set value. */
5597 r
= unit_path_printf(u
, rvalue
, &k
);
5599 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
5603 /* If this is a relative path make it absolute by prefixing the /run */
5604 n
= path_make_absolute(k
, u
->manager
->prefix
[EXEC_DIRECTORY_RUNTIME
]);
5608 /* Check that the result is a sensible path */
5609 r
= path_simplify_and_warn(n
, PATH_CHECK_ABSOLUTE
|PATH_CHECK_NON_API_VFS
, unit
, filename
, line
, lvalue
);
5613 r
= patch_var_run(unit
, filename
, line
, lvalue
, &n
);
5617 free_and_replace(*s
, n
);
5621 int config_parse_exit_status(
5623 const char *filename
,
5625 const char *section
,
5626 unsigned section_line
,
5633 int *exit_status
= data
, r
;
5639 assert(exit_status
);
5641 if (isempty(rvalue
)) {
5646 r
= safe_atou8(rvalue
, &u
);
5648 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse exit status '%s', ignoring: %m", rvalue
);
5656 int config_parse_disable_controllers(
5658 const char *filename
,
5660 const char *section
,
5661 unsigned section_line
,
5669 CGroupContext
*c
= data
;
5670 CGroupMask disabled_mask
;
5672 /* 1. If empty, make all controllers eligible for use again.
5673 * 2. If non-empty, merge all listed controllers, space separated. */
5675 if (isempty(rvalue
)) {
5676 c
->disable_controllers
= 0;
5680 r
= cg_mask_from_string(rvalue
, &disabled_mask
);
5681 if (r
< 0 || disabled_mask
<= 0) {
5682 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid cgroup string: %s, ignoring", rvalue
);
5686 c
->disable_controllers
|= disabled_mask
;
5691 int config_parse_ip_filter_bpf_progs(
5693 const char *filename
,
5695 const char *section
,
5696 unsigned section_line
,
5703 _cleanup_free_
char *resolved
= NULL
;
5704 const Unit
*u
= userdata
;
5705 char ***paths
= ASSERT_PTR(data
);
5712 if (isempty(rvalue
)) {
5713 *paths
= strv_free(*paths
);
5717 r
= unit_path_printf(u
, rvalue
, &resolved
);
5719 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
5723 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5727 if (strv_contains(*paths
, resolved
))
5730 r
= strv_extend(paths
, resolved
);
5734 if (bpf_program_supported() <= 0) {
5735 static bool warned
= false;
5737 log_syntax(unit
, warned
? LOG_DEBUG
: LOG_WARNING
, filename
, line
, 0,
5738 "Configures an IP firewall with BPF programs (%s=%s), but the local system does not support BPF/cgroup based firewalling with multiple filters. "
5739 "Starting this unit will fail! (This warning is only shown for the first loaded unit using IP firewalling.)", lvalue
, rvalue
);
5747 int config_parse_bpf_foreign_program(
5749 const char *filename
,
5751 const char *section
,
5752 unsigned section_line
,
5758 _cleanup_free_
char *resolved
= NULL
, *word
= NULL
;
5759 CGroupContext
*c
= data
;
5760 const char *p
= ASSERT_PTR(rvalue
);
5767 if (isempty(rvalue
)) {
5768 while (c
->bpf_foreign_programs
)
5769 cgroup_context_remove_bpf_foreign_program(c
, c
->bpf_foreign_programs
);
5774 r
= extract_first_word(&p
, &word
, ":", 0);
5778 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse foreign BPF program, ignoring: %s", rvalue
);
5781 if (r
== 0 || isempty(p
)) {
5782 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid syntax in %s=, ignoring: %s", lvalue
, rvalue
);
5786 attach_type
= bpf_cgroup_attach_type_from_string(word
);
5787 if (attach_type
< 0) {
5788 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Unknown BPF attach type=%s, ignoring: %s", word
, rvalue
);
5792 r
= unit_path_printf(u
, p
, &resolved
);
5794 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %s", p
, rvalue
);
5798 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5802 r
= cgroup_context_add_bpf_foreign_program(c
, attach_type
, resolved
);
5804 return log_error_errno(r
, "Failed to add foreign BPF program to cgroup context: %m");
5809 int config_parse_cgroup_socket_bind(
5811 const char *filename
,
5813 const char *section
,
5814 unsigned section_line
,
5820 _cleanup_free_ CGroupSocketBindItem
*item
= NULL
;
5821 CGroupSocketBindItem
**head
= data
;
5822 uint16_t nr_ports
, port_min
;
5823 int af
, ip_protocol
, r
;
5825 if (isempty(rvalue
)) {
5826 cgroup_context_remove_socket_bind(head
);
5830 r
= parse_socket_bind_item(rvalue
, &af
, &ip_protocol
, &nr_ports
, &port_min
);
5834 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5835 "Unable to parse %s= assignment, ignoring: %s", lvalue
, rvalue
);
5839 item
= new(CGroupSocketBindItem
, 1);
5842 *item
= (CGroupSocketBindItem
) {
5843 .address_family
= af
,
5844 .ip_protocol
= ip_protocol
,
5845 .nr_ports
= nr_ports
,
5846 .port_min
= port_min
,
5849 LIST_PREPEND(socket_bind_items
, *head
, TAKE_PTR(item
));
5854 int config_parse_restrict_network_interfaces(
5856 const char *filename
,
5858 const char *section
,
5859 unsigned section_line
,
5865 CGroupContext
*c
= ASSERT_PTR(data
);
5866 bool is_allow_rule
= true;
5873 if (isempty(rvalue
)) {
5874 /* Empty assignment resets the list */
5875 c
->restrict_network_interfaces
= set_free(c
->restrict_network_interfaces
);
5879 if (rvalue
[0] == '~') {
5880 is_allow_rule
= false;
5884 if (set_isempty(c
->restrict_network_interfaces
))
5885 /* Only initialize this when creating the set */
5886 c
->restrict_network_interfaces_is_allow_list
= is_allow_rule
;
5888 for (const char *p
= rvalue
;;) {
5889 _cleanup_free_
char *word
= NULL
;
5891 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
5897 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5898 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
5902 if (!ifname_valid_full(word
, IFNAME_VALID_ALTERNATIVE
)) {
5903 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid interface name, ignoring: %s", word
);
5907 if (c
->restrict_network_interfaces_is_allow_list
!= is_allow_rule
)
5908 free(set_remove(c
->restrict_network_interfaces
, word
));
5910 r
= set_put_strdup(&c
->restrict_network_interfaces
, word
);
5919 int config_parse_mount_node(
5921 const char *filename
,
5923 const char *section
,
5924 unsigned section_line
,
5931 const Unit
*u
= ASSERT_PTR(userdata
);
5932 _cleanup_free_
char *resolved
= NULL
, *path
= NULL
;
5939 r
= unit_full_printf(u
, rvalue
, &resolved
);
5941 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
5945 path
= fstab_node_to_udev_node(resolved
);
5949 /* The source passed is not necessarily something we understand, and we pass it as-is to mount/swapon,
5950 * so path_is_valid is not used. But let's check for basic sanity, i.e. if the source is longer than
5951 * PATH_MAX, you're likely doing something wrong. */
5952 if (strlen(path
) >= PATH_MAX
) {
5953 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Resolved mount path '%s' too long, ignoring.", path
);
5957 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, path
, data
, userdata
);
5960 int config_parse_concurrency_max(
5962 const char *filename
,
5964 const char *section
,
5965 unsigned section_line
,
5972 unsigned *concurrency_max
= ASSERT_PTR(data
);
5974 if (isempty(rvalue
) || streq(rvalue
, "infinity")) {
5975 *concurrency_max
= UINT_MAX
;
5979 return config_parse_unsigned(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
);
5982 static int merge_by_names(Unit
*u
, Set
*names
, const char *id
) {
5988 /* Let's try to add in all names that are aliases of this unit */
5989 while ((k
= set_steal_first(names
))) {
5990 _cleanup_free_ _unused_
char *free_k
= k
;
5992 /* First try to merge in the other name into our unit */
5993 r
= unit_merge_by_name(u
, k
);
5997 /* Hmm, we couldn't merge the other unit into ours? Then let's try it the other way
6000 other
= manager_get_unit(u
->manager
, k
);
6002 return r
; /* return previous failure */
6004 r
= unit_merge(other
, u
);
6008 return merge_by_names(other
, names
, NULL
);
6011 if (streq_ptr(id
, k
))
6012 unit_choose_id(u
, id
);
6018 int unit_load_fragment(Unit
*u
) {
6022 assert(u
->load_state
== UNIT_STUB
);
6026 u
->access_selinux_context
= mfree(u
->access_selinux_context
);
6027 u
->load_state
= UNIT_LOADED
;
6031 /* Possibly rebuild the fragment map to catch new units */
6032 r
= unit_file_build_name_map(&u
->manager
->lookup_paths
,
6033 &u
->manager
->unit_cache_timestamp_hash
,
6034 &u
->manager
->unit_id_map
,
6035 &u
->manager
->unit_name_map
,
6036 &u
->manager
->unit_path_cache
);
6038 return log_error_errno(r
, "Failed to rebuild name map: %m");
6040 const char *fragment
;
6041 _cleanup_set_free_ Set
*names
= NULL
;
6042 r
= unit_file_find_fragment(u
->manager
->unit_id_map
,
6043 u
->manager
->unit_name_map
,
6047 if (r
< 0 && r
!= -ENOENT
)
6051 /* Open the file, check if this is a mask, otherwise read. */
6052 _cleanup_fclose_
FILE *f
= NULL
;
6055 /* Try to open the file name. A symlink is OK, for example for linked files or masks. We
6056 * expect that all symlinks within the lookup paths have been already resolved, but we don't
6057 * verify this here. */
6058 f
= fopen(fragment
, "re");
6060 return log_unit_notice_errno(u
, errno
, "Failed to open %s: %m", fragment
);
6062 if (fstat(fileno(f
), &st
) < 0)
6065 r
= free_and_strdup(&u
->fragment_path
, fragment
);
6069 if (null_or_empty(&st
)) {
6070 /* Unit file is masked */
6072 u
->load_state
= u
->perpetual
? UNIT_LOADED
: UNIT_MASKED
; /* don't allow perpetual units to ever be masked */
6073 u
->fragment_mtime
= 0;
6074 u
->access_selinux_context
= mfree(u
->access_selinux_context
);
6077 if (mac_selinux_use()) {
6078 _cleanup_freecon_
char *selcon
= NULL
;
6080 /* Cache the SELinux context of the unit file here. We'll make use of when checking access permissions to loaded units */
6081 r
= fgetfilecon_raw(fileno(f
), &selcon
);
6083 log_unit_warning_errno(u
, r
, "Failed to read SELinux context of '%s', ignoring: %m", fragment
);
6085 r
= free_and_strdup(&u
->access_selinux_context
, selcon
);
6090 u
->access_selinux_context
= mfree(u
->access_selinux_context
);
6092 u
->load_state
= UNIT_LOADED
;
6093 u
->fragment_mtime
= timespec_load(&st
.st_mtim
);
6095 /* Now, parse the file contents */
6096 r
= config_parse(u
->id
, fragment
, f
,
6097 UNIT_VTABLE(u
)->sections
,
6098 config_item_perf_lookup
, load_fragment_gperf_lookup
,
6103 log_unit_notice_errno(u
, r
, "Unit configuration has fatal error, unit will not be started.");
6109 /* Call merge_by_names with the name derived from the fragment path as the preferred name.
6111 * We do the merge dance here because for some unit types, the unit might have aliases which are not
6112 * declared in the file system. In particular, this is true (and frequent) for device and swap units.
6114 const char *id
= u
->id
;
6115 _cleanup_free_
char *filename
= NULL
, *free_id
= NULL
;
6118 r
= path_extract_filename(fragment
, &filename
);
6120 return log_debug_errno(r
, "Failed to extract filename from fragment '%s': %m", fragment
);
6123 if (unit_name_is_valid(id
, UNIT_NAME_TEMPLATE
)) {
6124 assert(u
->instance
); /* If we're not trying to use a template for non-instanced unit,
6125 * this must be set. */
6127 r
= unit_name_replace_instance(id
, u
->instance
, &free_id
);
6129 return log_debug_errno(r
, "Failed to build id (%s + %s): %m", id
, u
->instance
);
6134 return merge_by_names(u
, names
, id
);
6137 void unit_dump_config_items(FILE *f
) {
6138 static const struct {
6139 const ConfigParserCallback callback
;
6142 { config_parse_warn_compat
, "NOTSUPPORTED" },
6143 { config_parse_int
, "INTEGER" },
6144 { config_parse_unsigned
, "UNSIGNED" },
6145 { config_parse_iec_size
, "SIZE" },
6146 { config_parse_iec_uint64
, "SIZE" },
6147 { config_parse_si_uint64
, "SIZE" },
6148 { config_parse_bool
, "BOOLEAN" },
6149 { config_parse_string
, "STRING" },
6150 { config_parse_path
, "PATH" },
6151 { config_parse_unit_path_printf
, "PATH" },
6152 { config_parse_colon_separated_paths
, "PATH" },
6153 { config_parse_strv
, "STRING [...]" },
6154 { config_parse_exec_nice
, "NICE" },
6155 { config_parse_exec_oom_score_adjust
, "OOMSCOREADJUST" },
6156 { config_parse_exec_io_class
, "IOCLASS" },
6157 { config_parse_exec_io_priority
, "IOPRIORITY" },
6158 { config_parse_exec_cpu_sched_policy
, "CPUSCHEDPOLICY" },
6159 { config_parse_exec_cpu_sched_prio
, "CPUSCHEDPRIO" },
6160 { config_parse_exec_cpu_affinity
, "CPUAFFINITY" },
6161 { config_parse_mode
, "MODE" },
6162 { config_parse_unit_env_file
, "FILE" },
6163 { config_parse_exec_output
, "OUTPUT" },
6164 { config_parse_exec_input
, "INPUT" },
6165 { config_parse_log_facility
, "FACILITY" },
6166 { config_parse_log_level
, "LEVEL" },
6167 { config_parse_exec_secure_bits
, "SECUREBITS" },
6168 { config_parse_capability_set
, "BOUNDINGSET" },
6169 { config_parse_rlimit
, "LIMIT" },
6170 { config_parse_unit_deps
, "UNIT [...]" },
6171 { config_parse_exec
, "PATH [ARGUMENT [...]]" },
6172 { config_parse_service_type
, "SERVICETYPE" },
6173 { config_parse_service_exit_type
, "SERVICEEXITTYPE" },
6174 { config_parse_service_restart
, "SERVICERESTART" },
6175 { config_parse_service_restart_mode
, "SERVICERESTARTMODE" },
6176 { config_parse_service_timeout_failure_mode
, "TIMEOUTMODE" },
6177 { config_parse_kill_mode
, "KILLMODE" },
6178 { config_parse_signal
, "SIGNAL" },
6179 { config_parse_socket_listen
, "SOCKET [...]" },
6180 { config_parse_socket_bind
, "SOCKETBIND" },
6181 { config_parse_socket_bindtodevice
, "NETWORKINTERFACE" },
6182 { config_parse_sec
, "SECONDS" },
6183 { config_parse_nsec
, "NANOSECONDS" },
6184 { config_parse_namespace_path_strv
, "PATH [...]" },
6185 { config_parse_bind_paths
, "PATH[:PATH[:OPTIONS]] [...]" },
6186 { config_parse_unit_mounts_for
, "PATH [...]" },
6187 { config_parse_exec_mount_propagation_flag
,
6189 { config_parse_unit_string_printf
, "STRING" },
6190 { config_parse_trigger_unit
, "UNIT" },
6191 { config_parse_timer
, "TIMER" },
6192 { config_parse_path_spec
, "PATH" },
6193 { config_parse_notify_access
, "ACCESS" },
6194 { config_parse_ip_tos
, "TOS" },
6195 { config_parse_unit_condition_path
, "CONDITION" },
6196 { config_parse_unit_condition_string
, "CONDITION" },
6197 { config_parse_unit_slice
, "SLICE" },
6198 { config_parse_documentation
, "URL" },
6199 { config_parse_service_timeout
, "SECONDS" },
6200 { config_parse_emergency_action
, "ACTION" },
6201 { config_parse_set_status
, "STATUS" },
6202 { config_parse_service_sockets
, "SOCKETS" },
6203 { config_parse_environ
, "ENVIRON" },
6205 { config_parse_syscall_filter
, "SYSCALLS" },
6206 { config_parse_syscall_archs
, "ARCHS" },
6207 { config_parse_syscall_errno
, "ERRNO" },
6208 { config_parse_syscall_log
, "SYSCALLS" },
6209 { config_parse_address_families
, "FAMILIES" },
6211 { config_parse_namespace_flags
, "NAMESPACES" },
6212 { config_parse_restrict_filesystems
, "FILESYSTEMS" },
6213 { config_parse_cg_weight
, "WEIGHT" },
6214 { config_parse_cg_cpu_weight
, "CPUWEIGHT" },
6215 { config_parse_memory_limit
, "LIMIT" },
6216 { config_parse_device_allow
, "DEVICE" },
6217 { config_parse_device_policy
, "POLICY" },
6218 { config_parse_io_limit
, "LIMIT" },
6219 { config_parse_io_device_weight
, "DEVICEWEIGHT" },
6220 { config_parse_io_device_latency
, "DEVICELATENCY" },
6221 { config_parse_long
, "LONG" },
6222 { config_parse_socket_service
, "SERVICE" },
6224 { config_parse_exec_selinux_context
, "LABEL" },
6226 { config_parse_job_mode
, "MODE" },
6227 { config_parse_job_mode_isolate
, "BOOLEAN" },
6228 { config_parse_personality
, "PERSONALITY" },
6229 { config_parse_log_filter_patterns
, "REGEX" },
6230 { config_parse_mount_node
, "NODE" },
6233 const char *prev
= NULL
;
6237 NULSTR_FOREACH(i
, load_fragment_gperf_nulstr
) {
6238 const char *rvalue
= "OTHER", *lvalue
;
6239 const ConfigPerfItem
*p
;
6242 assert_se(p
= load_fragment_gperf_lookup(i
, strlen(i
)));
6244 /* Hide legacy settings */
6245 if (p
->parse
== config_parse_warn_compat
&&
6246 p
->ltype
== DISABLED_LEGACY
)
6249 FOREACH_ELEMENT(j
, table
)
6250 if (p
->parse
== j
->callback
) {
6255 dot
= strchr(i
, '.');
6256 lvalue
= dot
? dot
+ 1 : i
;
6259 size_t prefix_len
= dot
- i
;
6261 if (!prev
|| !strneq(prev
, i
, prefix_len
+1)) {
6265 fprintf(f
, "[%.*s]\n", (int) prefix_len
, i
);
6269 fprintf(f
, "%s=%s\n", lvalue
, rvalue
);
6274 int config_parse_show_status(
6276 const char *filename
,
6278 const char *section
,
6279 unsigned section_line
,
6287 ShowStatus
*b
= ASSERT_PTR(data
);
6293 k
= parse_show_status(rvalue
, b
);
6295 log_syntax(unit
, LOG_WARNING
, filename
, line
, k
, "Failed to parse show status setting, ignoring: %s", rvalue
);
6300 int config_parse_output_restricted(
6302 const char *filename
,
6304 const char *section
,
6305 unsigned section_line
,
6312 ExecOutput t
, *eo
= ASSERT_PTR(data
);
6313 bool obsolete
= false;
6319 if (streq(rvalue
, "syslog")) {
6320 t
= EXEC_OUTPUT_JOURNAL
;
6322 } else if (streq(rvalue
, "syslog+console")) {
6323 t
= EXEC_OUTPUT_JOURNAL_AND_CONSOLE
;
6326 t
= exec_output_from_string(rvalue
);
6328 log_syntax(unit
, LOG_WARNING
, filename
, line
, t
, "Failed to parse output type, ignoring: %s", rvalue
);
6332 if (IN_SET(t
, EXEC_OUTPUT_SOCKET
, EXEC_OUTPUT_NAMED_FD
, EXEC_OUTPUT_FILE
, EXEC_OUTPUT_FILE_APPEND
, EXEC_OUTPUT_FILE_TRUNCATE
)) {
6333 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Standard output types socket, fd:, file:, append:, truncate: are not supported as defaults, ignoring: %s", rvalue
);
6339 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
6340 "Standard output type %s is obsolete, automatically updating to %s. Please update your configuration.",
6341 rvalue
, exec_output_to_string(t
));
6347 int config_parse_crash_chvt(
6349 const char *filename
,
6351 const char *section
,
6352 unsigned section_line
,
6366 r
= parse_crash_chvt(rvalue
, data
);
6368 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse CrashChangeVT= setting, ignoring: %s", rvalue
);
6373 int config_parse_swap_priority(
6375 const char *filename
,
6377 const char *section
,
6378 unsigned section_line
,
6385 Swap
*s
= ASSERT_PTR(userdata
);
6393 if (isempty(rvalue
)) {
6394 s
->parameters_fragment
.priority
= -1;
6395 s
->parameters_fragment
.priority_set
= false;
6399 r
= safe_atoi(rvalue
, &priority
);
6401 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid swap priority '%s', ignoring.", rvalue
);
6405 if (priority
< -1) {
6406 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
);
6410 if (priority
> 32767) {
6411 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Swap priority out of range, ignoring: %s", rvalue
);
6415 s
->parameters_fragment
.priority
= priority
;
6416 s
->parameters_fragment
.priority_set
= true;
6420 int config_parse_watchdog_sec(
6422 const char *filename
,
6424 const char *section
,
6425 unsigned section_line
,
6432 usec_t
*usec
= data
;
6438 /* This is called for {Runtime,Reboot,KExec}WatchdogSec= where "default" maps to
6439 * USEC_INFINITY internally. */
6441 if (streq(rvalue
, "default"))
6442 *usec
= USEC_INFINITY
;
6443 else if (streq(rvalue
, "off"))
6446 return config_parse_sec(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
);
6451 int config_parse_tty_size(
6453 const char *filename
,
6455 const char *section
,
6456 unsigned section_line
,
6463 unsigned *sz
= data
;
6469 if (isempty(rvalue
)) {
6474 return config_parse_unsigned(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
);
6477 int config_parse_log_filter_patterns(
6479 const char *filename
,
6481 const char *section
,
6482 unsigned section_line
,
6489 ExecContext
*c
= ASSERT_PTR(data
);
6490 const char *pattern
= ASSERT_PTR(rvalue
);
6491 bool is_allowlist
= true;
6497 if (isempty(pattern
)) {
6498 /* Empty assignment resets the lists. */
6499 c
->log_filter_allowed_patterns
= set_free(c
->log_filter_allowed_patterns
);
6500 c
->log_filter_denied_patterns
= set_free(c
->log_filter_denied_patterns
);
6504 if (pattern
[0] == '~') {
6505 is_allowlist
= false;
6507 if (isempty(pattern
))
6508 /* LogFilterPatterns=~ is not considered a valid pattern. */
6509 return log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
6510 "Regex pattern invalid, ignoring: %s=%s", lvalue
, rvalue
);
6513 if (pattern_compile_and_log(pattern
, 0, NULL
) < 0)
6516 r
= set_put_strdup(is_allowlist
? &c
->log_filter_allowed_patterns
: &c
->log_filter_denied_patterns
,
6519 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
6520 "Failed to store log filtering pattern, ignoring: %s=%s", lvalue
, rvalue
);
6527 int config_parse_open_file(
6529 const char *filename
,
6531 const char *section
,
6532 unsigned section_line
,
6539 _cleanup_(open_file_freep
) OpenFile
*of
= NULL
;
6540 OpenFile
**head
= ASSERT_PTR(data
);
6547 if (isempty(rvalue
)) {
6548 open_file_free_many(head
);
6552 r
= open_file_parse(rvalue
, &of
);
6554 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse OpenFile= setting, ignoring: %s", rvalue
);
6558 LIST_APPEND(open_files
, *head
, TAKE_PTR(of
));
6563 int config_parse_cgroup_nft_set(
6565 const char *filename
,
6567 const char *section
,
6568 unsigned section_line
,
6575 CGroupContext
*c
= ASSERT_PTR(data
);
6576 Unit
*u
= ASSERT_PTR(userdata
);
6578 return config_parse_nft_set(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, &c
->nft_set_context
, u
);
6581 int config_parse_protect_hostname(
6583 const char *filename
,
6585 const char *section
,
6586 unsigned section_line
,
6593 ExecContext
*c
= ASSERT_PTR(data
);
6594 Unit
*u
= ASSERT_PTR(userdata
);
6595 _cleanup_free_
char *h
= NULL
, *p
= NULL
;
6598 if (isempty(rvalue
)) {
6599 c
->protect_hostname
= PROTECT_HOSTNAME_NO
;
6600 c
->private_hostname
= mfree(c
->private_hostname
);
6604 const char *colon
= strchr(rvalue
, ':');
6606 r
= unit_full_printf_full(u
, colon
+ 1, HOST_NAME_MAX
, &h
);
6608 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
6609 "Failed to resolve unit specifiers in '%s', ignoring: %m", colon
+ 1);
6613 if (!hostname_is_valid(h
, /* flags = */ 0))
6614 return log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
6615 "Invalid hostname is specified to %s=, ignoring: %s", lvalue
, h
);
6617 p
= strndup(rvalue
, colon
- rvalue
);
6622 ProtectHostname t
= protect_hostname_from_string(p
?: rvalue
);
6623 if (t
< 0 || (t
== PROTECT_HOSTNAME_NO
&& h
))
6624 return log_syntax_parse_error(unit
, filename
, line
, 0, lvalue
, rvalue
);
6626 c
->protect_hostname
= t
;
6627 free_and_replace(c
->private_hostname
, h
);