1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
3 Copyright © 2012 Holger Hans Peter Freyther
11 #include <sys/resource.h>
13 #include "sd-messages.h"
16 #include "all-units.h"
17 #include "alloc-util.h"
18 #include "bpf-firewall.h"
19 #include "bpf-program.h"
20 #include "bpf-restrict-fs.h"
21 #include "bpf-socket-bind.h"
22 #include "bus-error.h"
23 #include "bus-internal.h"
26 #include "capability-util.h"
27 #include "cgroup-setup.h"
28 #include "conf-parser.h"
29 #include "core-varlink.h"
30 #include "cpu-set-util.h"
31 #include "creds-util.h"
33 #include "errno-list.h"
35 #include "exec-credential.h"
39 #include "firewall-util.h"
41 #include "fstab-util.h"
42 #include "hexdecoct.h"
43 #include "iovec-util.h"
44 #include "ioprio-util.h"
45 #include "ip-protocol-list.h"
46 #include "journal-file.h"
47 #include "limits-util.h"
48 #include "load-fragment.h"
50 #include "missing_ioprio.h"
51 #include "mountpoint-util.h"
52 #include "nulstr-util.h"
53 #include "open-file.h"
54 #include "parse-helpers.h"
55 #include "parse-util.h"
56 #include "path-util.h"
57 #include "pcre2-util.h"
58 #include "percent-util.h"
59 #include "process-util.h"
60 #include "seccomp-util.h"
61 #include "securebits-util.h"
62 #include "selinux-util.h"
63 #include "signal-util.h"
64 #include "socket-netlink.h"
65 #include "specifier.h"
66 #include "stat-util.h"
67 #include "string-util.h"
69 #include "syslog-util.h"
70 #include "time-util.h"
71 #include "unit-name.h"
72 #include "unit-printf.h"
73 #include "user-util.h"
77 static int parse_socket_protocol(const char *s
) {
80 r
= parse_ip_protocol(s
);
83 if (!IN_SET(r
, IPPROTO_UDPLITE
, IPPROTO_SCTP
))
84 return -EPROTONOSUPPORT
;
89 int parse_crash_chvt(const char *value
, int *data
) {
92 if (safe_atoi(value
, data
) >= 0)
95 b
= parse_boolean(value
);
100 *data
= 0; /* switch to where kmsg goes */
102 *data
= -1; /* turn off switching */
107 int parse_confirm_spawn(const char *value
, char **console
) {
111 r
= value
? parse_boolean(value
) : 1;
115 } else if (r
> 0) /* on with default tty */
116 s
= strdup("/dev/console");
117 else if (is_path(value
)) /* on with fully qualified path */
119 else /* on with only a tty file name, not a fully qualified path */
120 s
= path_join("/dev/", value
);
128 DEFINE_CONFIG_PARSE(config_parse_socket_protocol
, parse_socket_protocol
, "Failed to parse socket protocol");
129 DEFINE_CONFIG_PARSE(config_parse_exec_secure_bits
, secure_bits_from_string
, "Failed to parse secure bits");
130 DEFINE_CONFIG_PARSE_ENUM(config_parse_collect_mode
, collect_mode
, CollectMode
, "Failed to parse garbage collection mode");
131 DEFINE_CONFIG_PARSE_ENUM(config_parse_device_policy
, cgroup_device_policy
, CGroupDevicePolicy
, "Failed to parse device policy");
132 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_keyring_mode
, exec_keyring_mode
, ExecKeyringMode
, "Failed to parse keyring mode");
133 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_proc
, protect_proc
, ProtectProc
, "Failed to parse /proc/ protection mode");
134 DEFINE_CONFIG_PARSE_ENUM(config_parse_proc_subset
, proc_subset
, ProcSubset
, "Failed to parse /proc/ subset mode");
135 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_utmp_mode
, exec_utmp_mode
, ExecUtmpMode
, "Failed to parse utmp mode");
136 DEFINE_CONFIG_PARSE_ENUM(config_parse_job_mode
, job_mode
, JobMode
, "Failed to parse job mode");
137 DEFINE_CONFIG_PARSE_ENUM(config_parse_notify_access
, notify_access
, NotifyAccess
, "Failed to parse notify access specifier");
138 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_home
, protect_home
, ProtectHome
, "Failed to parse protect home value");
139 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_system
, protect_system
, ProtectSystem
, "Failed to parse protect system value");
140 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_preserve_mode
, exec_preserve_mode
, ExecPreserveMode
, "Failed to parse resource preserve mode");
141 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_type
, service_type
, ServiceType
, "Failed to parse service type");
142 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_exit_type
, service_exit_type
, ServiceExitType
, "Failed to parse service exit type");
143 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart
, service_restart
, ServiceRestart
, "Failed to parse service restart specifier");
144 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart_mode
, service_restart_mode
, ServiceRestartMode
, "Failed to parse service restart mode");
145 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_timeout_failure_mode
, service_timeout_failure_mode
, ServiceTimeoutFailureMode
, "Failed to parse timeout failure mode");
146 DEFINE_CONFIG_PARSE_ENUM(config_parse_socket_bind
, socket_address_bind_ipv6_only_or_bool
, SocketAddressBindIPv6Only
, "Failed to parse bind IPv6 only value");
147 DEFINE_CONFIG_PARSE_ENUM(config_parse_oom_policy
, oom_policy
, OOMPolicy
, "Failed to parse OOM policy");
148 DEFINE_CONFIG_PARSE_ENUM(config_parse_managed_oom_preference
, managed_oom_preference
, ManagedOOMPreference
, "Failed to parse ManagedOOMPreference=");
149 DEFINE_CONFIG_PARSE_ENUM(config_parse_memory_pressure_watch
, cgroup_pressure_watch
, CGroupPressureWatch
, "Failed to parse memory pressure watch setting");
150 DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_ip_tos
, ip_tos
, int, -1, "Failed to parse IP TOS value");
151 DEFINE_CONFIG_PARSE_PTR(config_parse_blockio_weight
, cg_blkio_weight_parse
, uint64_t, "Invalid block IO weight");
152 DEFINE_CONFIG_PARSE_PTR(config_parse_cg_weight
, cg_weight_parse
, uint64_t, "Invalid weight");
153 DEFINE_CONFIG_PARSE_PTR(config_parse_cg_cpu_weight
, cg_cpu_weight_parse
, uint64_t, "Invalid CPU weight");
154 static DEFINE_CONFIG_PARSE_PTR(config_parse_cpu_shares_internal
, cg_cpu_shares_parse
, uint64_t, "Invalid CPU shares");
155 DEFINE_CONFIG_PARSE_PTR(config_parse_exec_mount_propagation_flag
, mount_propagation_flag_from_string
, unsigned long, "Failed to parse mount propagation flag");
156 DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_numa_policy
, mpol
, int, -1, "Invalid NUMA policy type");
157 DEFINE_CONFIG_PARSE_ENUM(config_parse_status_unit_format
, status_unit_format
, StatusUnitFormat
, "Failed to parse status unit format");
158 DEFINE_CONFIG_PARSE_ENUM_FULL(config_parse_socket_timestamping
, socket_timestamping_from_string_harder
, SocketTimestamping
, "Failed to parse timestamping precision");
160 int config_parse_cpu_shares(
162 const char *filename
,
165 unsigned section_line
,
177 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
178 "Unit uses %s=; please use CPUWeight= instead. Support for %s= will be removed soon.",
181 return config_parse_cpu_shares_internal(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
);
184 bool contains_instance_specifier_superset(const char *s
) {
186 bool percent
= false;
200 /* If the string is just the instance specifier, it's not a superset of the instance. */
201 if (memcmp_nn(p
, q
- p
, "%i", strlen("%i")) == 0)
204 /* %i, %n and %N all expand to the instance or a superset of it. */
209 if (IN_SET(*p
, 'n', 'N', 'i'))
217 /* `name` is the rendered version of `format` via `unit_printf` or similar functions. */
218 int unit_is_likely_recursive_template_dependency(Unit
*u
, const char *name
, const char *format
) {
219 const char *fragment_path
;
225 /* If a template unit has a direct dependency on itself that includes the unit instance as part of
226 * the template instance via a unit specifier (%i, %n or %N), this will almost certainly lead to
227 * infinite recursion as systemd will keep instantiating new instances of the template unit.
228 * https://github.com/systemd/systemd/issues/17602 shows a good example of how this can happen in
229 * practice. To guard against this, we check for templates that depend on themselves and have the
230 * instantiated unit instance included as part of the template instance of the dependency via a
233 * For example, if systemd-notify@.service depends on systemd-notify@%n.service, this will result in
234 * infinite recursion.
237 if (!unit_name_is_valid(name
, UNIT_NAME_INSTANCE
))
240 if (!unit_name_prefix_equal(u
->id
, name
))
243 if (u
->type
!= unit_name_to_type(name
))
246 r
= unit_file_find_fragment(u
->manager
->unit_id_map
, u
->manager
->unit_name_map
, name
, &fragment_path
, NULL
);
250 /* Fragment paths should also be equal as a custom fragment for a specific template instance
251 * wouldn't necessarily lead to infinite recursion. */
252 if (!path_equal(u
->fragment_path
, fragment_path
))
255 if (!contains_instance_specifier_superset(format
))
261 int config_parse_unit_deps(
263 const char *filename
,
266 unsigned section_line
,
273 UnitDependency d
= ltype
;
280 for (const char *p
= rvalue
;;) {
281 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
284 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_RETAIN_ESCAPE
);
290 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
294 r
= unit_name_printf(u
, word
, &k
);
296 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
300 r
= unit_is_likely_recursive_template_dependency(u
, k
, word
);
302 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to determine if '%s' is a recursive dependency, ignoring: %m", k
);
306 log_syntax(unit
, LOG_DEBUG
, filename
, line
, 0,
307 "Dropping dependency %s=%s that likely leads to infinite recursion.",
308 unit_dependency_to_string(d
), word
);
312 r
= unit_add_dependency_by_name(u
, d
, k
, true, UNIT_DEPENDENCY_FILE
);
314 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
318 int config_parse_obsolete_unit_deps(
320 const char *filename
,
323 unsigned section_line
,
330 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
331 "Unit dependency type %s= is obsolete, replacing by %s=, please update your unit file", lvalue
, unit_dependency_to_string(ltype
));
333 return config_parse_unit_deps(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
);
336 int config_parse_unit_string_printf(
338 const char *filename
,
341 unsigned section_line
,
348 _cleanup_free_
char *k
= NULL
;
349 const Unit
*u
= ASSERT_PTR(userdata
);
356 r
= unit_full_printf(u
, rvalue
, &k
);
358 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
362 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
365 int config_parse_unit_strv_printf(
367 const char *filename
,
370 unsigned section_line
,
377 const Unit
*u
= ASSERT_PTR(userdata
);
378 _cleanup_free_
char *k
= NULL
;
385 r
= unit_full_printf(u
, rvalue
, &k
);
387 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
391 return config_parse_strv(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
394 int config_parse_unit_path_printf(
396 const char *filename
,
399 unsigned section_line
,
406 _cleanup_free_
char *k
= NULL
;
407 const Unit
*u
= ASSERT_PTR(userdata
);
415 r
= unit_path_printf(u
, rvalue
, &k
);
417 log_syntax(unit
, fatal
? LOG_ERR
: LOG_WARNING
, filename
, line
, r
,
418 "Failed to resolve unit specifiers in '%s'%s: %m",
419 rvalue
, fatal
? "" : ", ignoring");
420 return fatal
? -ENOEXEC
: 0;
423 return config_parse_path(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
426 int config_parse_colon_separated_paths(
428 const char *filename
,
431 unsigned section_line
,
438 char ***sv
= ASSERT_PTR(data
);
439 const Unit
*u
= ASSERT_PTR(userdata
);
446 if (isempty(rvalue
)) {
447 /* Empty assignment resets the list */
448 *sv
= strv_free(*sv
);
452 for (const char *p
= rvalue
;;) {
453 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
455 r
= extract_first_word(&p
, &word
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
459 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
465 r
= unit_path_printf(u
, word
, &k
);
467 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
468 "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
472 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
476 r
= strv_consume(sv
, TAKE_PTR(k
));
484 int config_parse_unit_path_strv_printf(
486 const char *filename
,
489 unsigned section_line
,
497 const Unit
*u
= ASSERT_PTR(userdata
);
504 if (isempty(rvalue
)) {
509 for (const char *p
= rvalue
;;) {
510 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
512 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
518 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
519 "Invalid syntax, ignoring: %s", rvalue
);
523 r
= unit_path_printf(u
, word
, &k
);
525 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
526 "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
530 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
534 r
= strv_consume(x
, TAKE_PTR(k
));
540 static int patch_var_run(
542 const char *filename
,
550 e
= path_startswith(*path
, "/var/run/");
554 z
= path_join("/run/", e
);
558 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
559 "%s= references a path below legacy directory /var/run/, updating %s → %s; "
560 "please update the unit file accordingly.", lvalue
, *path
, z
);
562 free_and_replace(*path
, z
);
567 int config_parse_socket_listen(
569 const char *filename
,
572 unsigned section_line
,
579 Socket
*s
= ASSERT_PTR(SOCKET(data
));
580 _cleanup_free_ SocketPort
*p
= NULL
;
587 if (isempty(rvalue
)) {
588 /* An empty assignment removes all ports */
589 socket_free_ports(s
);
593 p
= new(SocketPort
, 1);
602 if (ltype
!= SOCKET_SOCKET
) {
603 _cleanup_free_
char *k
= NULL
;
605 r
= unit_path_printf(UNIT(s
), rvalue
, &k
);
607 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
611 PathSimplifyWarnFlags flags
= PATH_CHECK_ABSOLUTE
;
612 if (ltype
!= SOCKET_SPECIAL
)
613 flags
|= PATH_CHECK_NON_API_VFS
;
615 r
= path_simplify_and_warn(k
, flags
, unit
, filename
, line
, lvalue
);
619 if (ltype
== SOCKET_FIFO
) {
620 r
= patch_var_run(unit
, filename
, line
, lvalue
, &k
);
625 free_and_replace(p
->path
, k
);
628 } else if (streq(lvalue
, "ListenNetlink")) {
629 _cleanup_free_
char *k
= NULL
;
631 r
= unit_path_printf(UNIT(s
), rvalue
, &k
);
633 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
637 r
= socket_address_parse_netlink(&p
->address
, k
);
639 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse address value in '%s', ignoring: %m", k
);
643 p
->type
= SOCKET_SOCKET
;
646 _cleanup_free_
char *k
= NULL
;
648 r
= unit_path_printf(UNIT(s
), rvalue
, &k
);
650 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
654 if (path_is_absolute(k
)) { /* Only for AF_UNIX file system sockets… */
655 r
= patch_var_run(unit
, filename
, line
, lvalue
, &k
);
660 r
= socket_address_parse_and_warn(&p
->address
, k
);
662 if (r
!= -EAFNOSUPPORT
)
663 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse address value in '%s', ignoring: %m", k
);
667 if (streq(lvalue
, "ListenStream"))
668 p
->address
.type
= SOCK_STREAM
;
669 else if (streq(lvalue
, "ListenDatagram"))
670 p
->address
.type
= SOCK_DGRAM
;
672 assert(streq(lvalue
, "ListenSequentialPacket"));
673 p
->address
.type
= SOCK_SEQPACKET
;
676 if (socket_address_family(&p
->address
) != AF_UNIX
&& p
->address
.type
== SOCK_SEQPACKET
) {
677 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Address family not supported, ignoring: %s", rvalue
);
681 p
->type
= SOCKET_SOCKET
;
684 LIST_APPEND(port
, s
->ports
, TAKE_PTR(p
));
688 int config_parse_exec_nice(
690 const char *filename
,
693 unsigned section_line
,
700 ExecContext
*c
= ASSERT_PTR(data
);
707 if (isempty(rvalue
)) {
712 r
= parse_nice(rvalue
, &priority
);
715 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Nice priority out of range, ignoring: %s", rvalue
);
717 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse nice priority '%s', ignoring: %m", rvalue
);
727 int config_parse_exec_oom_score_adjust(
729 const char *filename
,
732 unsigned section_line
,
739 ExecContext
*c
= ASSERT_PTR(data
);
746 if (isempty(rvalue
)) {
747 c
->oom_score_adjust_set
= false;
751 r
= parse_oom_score_adjust(rvalue
, &oa
);
754 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "OOM score adjust value out of range, ignoring: %s", rvalue
);
756 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse the OOM score adjust value '%s', ignoring: %m", rvalue
);
760 c
->oom_score_adjust
= oa
;
761 c
->oom_score_adjust_set
= true;
766 int config_parse_exec_coredump_filter(
768 const char *filename
,
771 unsigned section_line
,
778 ExecContext
*c
= ASSERT_PTR(data
);
785 if (isempty(rvalue
)) {
786 c
->coredump_filter
= 0;
787 c
->coredump_filter_set
= false;
792 r
= coredump_filter_mask_from_string(rvalue
, &f
);
794 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
795 "Failed to parse the CoredumpFilter=%s, ignoring: %m", rvalue
);
799 c
->coredump_filter
|= f
;
800 c
->coredump_filter_set
= true;
804 int config_parse_kill_mode(
806 const char *filename
,
809 unsigned section_line
,
816 KillMode
*k
= data
, m
;
823 if (isempty(rvalue
)) {
824 *k
= KILL_CONTROL_GROUP
;
828 m
= kill_mode_from_string(rvalue
);
830 log_syntax(unit
, LOG_WARNING
, filename
, line
, m
,
831 "Failed to parse kill mode specification, ignoring: %s", rvalue
);
836 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
837 "Unit uses KillMode=none. "
838 "This is unsafe, as it disables systemd's process lifecycle management for the service. "
839 "Please update the service to use a safer KillMode=, such as 'mixed' or 'control-group'. "
840 "Support for KillMode=none is deprecated and will eventually be removed.");
846 int config_parse_exec(
848 const char *filename
,
851 unsigned section_line
,
858 ExecCommand
**e
= ASSERT_PTR(data
);
859 const Unit
*u
= ASSERT_PTR(userdata
);
868 if (isempty(rvalue
)) {
869 /* An empty assignment resets the list */
870 *e
= exec_command_free_list(*e
);
874 const char *p
= rvalue
;
878 _cleanup_free_
char *path
= NULL
, *firstword
= NULL
;
882 r
= extract_first_word_and_warn(&p
, &firstword
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
886 /* A lone ";" is a separator. Let's make sure we don't treat it as an executable name. */
887 if (streq(firstword
, ";")) {
892 const char *f
= firstword
;
893 bool ignore
, separate_argv0
= false;
894 ExecCommandFlags flags
= 0;
897 /* We accept an absolute path as first argument. Valid prefixes and their effect:
899 * "-": Ignore if the path doesn't exist
900 * "@": Allow overridding argv[0] (supplied as a separate argument)
901 * ":": Disable environment variable substitution
902 * "+": Run with full privileges and no sandboxing
903 * "!": Apply sandboxing except for user/group credentials
904 * "!!": Apply user/group credentials if the kernel supports ambient capabilities -
905 * if it doesn't we don't apply the credentials themselves, but do apply
906 * most other sandboxing, with some special exceptions for changing UID.
908 * The idea is that '!!' may be used to write services that can take benefit of
909 * systemd's UID/GID dropping if the kernel supports ambient creds, but provide
910 * an automatic fallback to privilege dropping within the daemon if the kernel
911 * does not offer that. */
913 if (*f
== '-' && !(flags
& EXEC_COMMAND_IGNORE_FAILURE
))
914 flags
|= EXEC_COMMAND_IGNORE_FAILURE
;
915 else if (*f
== '@' && !separate_argv0
)
916 separate_argv0
= true;
917 else if (*f
== ':' && !(flags
& EXEC_COMMAND_NO_ENV_EXPAND
))
918 flags
|= EXEC_COMMAND_NO_ENV_EXPAND
;
919 else if (*f
== '+' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
920 flags
|= EXEC_COMMAND_FULLY_PRIVILEGED
;
921 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
922 flags
|= EXEC_COMMAND_NO_SETUID
;
923 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_AMBIENT_MAGIC
))) {
924 flags
&= ~EXEC_COMMAND_NO_SETUID
;
925 flags
|= EXEC_COMMAND_AMBIENT_MAGIC
;
930 ignore
= FLAGS_SET(flags
, EXEC_COMMAND_IGNORE_FAILURE
);
932 r
= unit_path_printf(u
, f
, &path
);
934 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
935 "Failed to resolve unit specifiers in '%s'%s: %m",
936 f
, ignore
? ", ignoring" : "");
937 return ignore
? 0 : -ENOEXEC
;
941 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
942 "Empty path in command line%s: %s",
943 ignore
? ", ignoring" : "", rvalue
);
944 return ignore
? 0 : -ENOEXEC
;
946 if (!string_is_safe(path
)) {
947 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
948 "Executable path contains special characters%s: %s",
949 ignore
? ", ignoring" : "", path
);
950 return ignore
? 0 : -ENOEXEC
;
952 if (path_implies_directory(path
)) {
953 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
954 "Executable path specifies a directory%s: %s",
955 ignore
? ", ignoring" : "", path
);
956 return ignore
? 0 : -ENOEXEC
;
959 if (!(path_is_absolute(path
) ? path_is_valid(path
) : filename_is_valid(path
))) {
960 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
961 "Neither a valid executable name nor an absolute path%s: %s",
962 ignore
? ", ignoring" : "", path
);
963 return ignore
? 0 : -ENOEXEC
;
966 _cleanup_strv_free_
char **args
= NULL
;
969 if (strv_extend(&args
, path
) < 0)
972 while (!isempty(p
)) {
973 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
975 /* Check explicitly for an unquoted semicolon as command separator token. */
976 if (p
[0] == ';' && (!p
[1] || strchr(WHITESPACE
, p
[1]))) {
978 p
= skip_leading_chars(p
, /* bad = */ NULL
);
983 /* Check for \; explicitly, to not confuse it with \\; or "\;" or "\\;" etc.
984 * extract_first_word() would return the same for all of those. */
985 if (p
[0] == '\\' && p
[1] == ';' && (!p
[2] || strchr(WHITESPACE
, p
[2]))) {
987 p
= skip_leading_chars(p
, /* bad = */ NULL
);
989 if (strv_extend(&args
, ";") < 0)
995 r
= extract_first_word_and_warn(&p
, &word
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
997 return ignore
? 0 : -ENOEXEC
;
1001 r
= unit_full_printf(u
, word
, &resolved
);
1003 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
1004 "Failed to resolve unit specifiers in '%s'%s: %m",
1005 word
, ignore
? ", ignoring" : "");
1006 return ignore
? 0 : -ENOEXEC
;
1009 if (strv_consume(&args
, TAKE_PTR(resolved
)) < 0)
1013 if (strv_isempty(args
)) {
1014 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
1015 "Empty executable name or zeroeth argument%s: %s",
1016 ignore
? ", ignoring" : "", rvalue
);
1017 return ignore
? 0 : -ENOEXEC
;
1020 ExecCommand
*nec
= new(ExecCommand
, 1);
1024 *nec
= (ExecCommand
) {
1025 .path
= path_simplify(TAKE_PTR(path
)),
1026 .argv
= TAKE_PTR(args
),
1030 exec_command_append_list(e
, nec
);
1033 } while (semicolon
);
1038 int config_parse_socket_bindtodevice(
1040 const char *filename
,
1042 const char *section
,
1043 unsigned section_line
,
1050 Socket
*s
= ASSERT_PTR(data
);
1056 if (isempty(rvalue
) || streq(rvalue
, "*")) {
1057 s
->bind_to_device
= mfree(s
->bind_to_device
);
1061 if (!ifname_valid(rvalue
)) {
1062 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid interface name, ignoring: %s", rvalue
);
1066 return free_and_strdup_warn(&s
->bind_to_device
, rvalue
);
1069 int config_parse_exec_input(
1071 const char *filename
,
1073 const char *section
,
1074 unsigned section_line
,
1081 ExecContext
*c
= ASSERT_PTR(data
);
1082 const Unit
*u
= userdata
;
1091 n
= startswith(rvalue
, "fd:");
1093 _cleanup_free_
char *resolved
= NULL
;
1095 r
= unit_fd_printf(u
, n
, &resolved
);
1097 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", n
);
1101 if (isempty(resolved
))
1102 resolved
= mfree(resolved
);
1103 else if (!fdname_is_valid(resolved
)) {
1104 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", resolved
);
1108 free_and_replace(c
->stdio_fdname
[STDIN_FILENO
], resolved
);
1110 ei
= EXEC_INPUT_NAMED_FD
;
1112 } else if ((n
= startswith(rvalue
, "file:"))) {
1113 _cleanup_free_
char *resolved
= NULL
;
1115 r
= unit_path_printf(u
, n
, &resolved
);
1117 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", n
);
1121 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1125 free_and_replace(c
->stdio_file
[STDIN_FILENO
], resolved
);
1127 ei
= EXEC_INPUT_FILE
;
1130 ei
= exec_input_from_string(rvalue
);
1132 log_syntax(unit
, LOG_WARNING
, filename
, line
, ei
, "Failed to parse input specifier, ignoring: %s", rvalue
);
1141 int config_parse_exec_input_text(
1143 const char *filename
,
1145 const char *section
,
1146 unsigned section_line
,
1153 _cleanup_free_
char *unescaped
= NULL
, *resolved
= NULL
;
1154 ExecContext
*c
= ASSERT_PTR(data
);
1155 const Unit
*u
= userdata
;
1162 if (isempty(rvalue
)) {
1163 /* Reset if the empty string is assigned */
1164 c
->stdin_data
= mfree(c
->stdin_data
);
1165 c
->stdin_data_size
= 0;
1169 ssize_t l
= cunescape(rvalue
, 0, &unescaped
);
1171 log_syntax(unit
, LOG_WARNING
, filename
, line
, l
,
1172 "Failed to decode C escaped text '%s', ignoring: %m", rvalue
);
1176 r
= unit_full_printf_full(u
, unescaped
, EXEC_STDIN_DATA_MAX
, &resolved
);
1178 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1179 "Failed to resolve unit specifiers in '%s', ignoring: %m", unescaped
);
1183 size_t sz
= strlen(resolved
);
1184 if (c
->stdin_data_size
+ sz
+ 1 < c
->stdin_data_size
|| /* check for overflow */
1185 c
->stdin_data_size
+ sz
+ 1 > EXEC_STDIN_DATA_MAX
) {
1186 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
1187 "Standard input data too large (%zu), maximum of %zu permitted, ignoring.",
1188 c
->stdin_data_size
+ sz
, (size_t) EXEC_STDIN_DATA_MAX
);
1192 void *p
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
+ 1);
1196 *((char*) mempcpy((char*) p
+ c
->stdin_data_size
, resolved
, sz
)) = '\n';
1199 c
->stdin_data_size
+= sz
+ 1;
1204 int config_parse_exec_input_data(
1206 const char *filename
,
1208 const char *section
,
1209 unsigned section_line
,
1216 _cleanup_free_
void *p
= NULL
;
1217 ExecContext
*c
= ASSERT_PTR(data
);
1226 if (isempty(rvalue
)) {
1227 /* Reset if the empty string is assigned */
1228 c
->stdin_data
= mfree(c
->stdin_data
);
1229 c
->stdin_data_size
= 0;
1233 r
= unbase64mem(rvalue
, &p
, &sz
);
1235 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1236 "Failed to decode base64 data, ignoring: %s", rvalue
);
1242 if (c
->stdin_data_size
+ sz
< c
->stdin_data_size
|| /* check for overflow */
1243 c
->stdin_data_size
+ sz
> EXEC_STDIN_DATA_MAX
) {
1244 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
1245 "Standard input data too large (%zu), maximum of %zu permitted, ignoring.",
1246 c
->stdin_data_size
+ sz
, (size_t) EXEC_STDIN_DATA_MAX
);
1250 q
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
);
1254 memcpy((uint8_t*) q
+ c
->stdin_data_size
, p
, sz
);
1257 c
->stdin_data_size
+= sz
;
1262 int config_parse_exec_output(
1264 const char *filename
,
1266 const char *section
,
1267 unsigned section_line
,
1274 _cleanup_free_
char *resolved
= NULL
;
1276 ExecContext
*c
= ASSERT_PTR(data
);
1277 const Unit
*u
= userdata
;
1278 bool obsolete
= false;
1287 n
= startswith(rvalue
, "fd:");
1289 r
= unit_fd_printf(u
, n
, &resolved
);
1291 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", n
);
1295 if (isempty(resolved
))
1296 resolved
= mfree(resolved
);
1297 else if (!fdname_is_valid(resolved
)) {
1298 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", resolved
);
1302 eo
= EXEC_OUTPUT_NAMED_FD
;
1304 } else if (streq(rvalue
, "syslog")) {
1305 eo
= EXEC_OUTPUT_JOURNAL
;
1308 } else if (streq(rvalue
, "syslog+console")) {
1309 eo
= EXEC_OUTPUT_JOURNAL_AND_CONSOLE
;
1312 } else if ((n
= startswith(rvalue
, "file:"))) {
1314 r
= unit_path_printf(u
, n
, &resolved
);
1316 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", n
);
1320 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1324 eo
= EXEC_OUTPUT_FILE
;
1326 } else if ((n
= startswith(rvalue
, "append:"))) {
1328 r
= unit_path_printf(u
, n
, &resolved
);
1330 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", n
);
1334 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1338 eo
= EXEC_OUTPUT_FILE_APPEND
;
1340 } else if ((n
= startswith(rvalue
, "truncate:"))) {
1342 r
= unit_path_printf(u
, n
, &resolved
);
1344 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", n
);
1348 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1352 eo
= EXEC_OUTPUT_FILE_TRUNCATE
;
1354 eo
= exec_output_from_string(rvalue
);
1356 log_syntax(unit
, LOG_WARNING
, filename
, line
, eo
, "Failed to parse output specifier, ignoring: %s", rvalue
);
1362 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
1363 "Standard output type %s is obsolete, automatically updating to %s. Please update your unit file, and consider removing the setting altogether.",
1364 rvalue
, exec_output_to_string(eo
));
1366 if (streq(lvalue
, "StandardOutput")) {
1367 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1368 free_and_replace(c
->stdio_fdname
[STDOUT_FILENO
], resolved
);
1370 free_and_replace(c
->stdio_file
[STDOUT_FILENO
], resolved
);
1375 assert(streq(lvalue
, "StandardError"));
1377 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1378 free_and_replace(c
->stdio_fdname
[STDERR_FILENO
], resolved
);
1380 free_and_replace(c
->stdio_file
[STDERR_FILENO
], resolved
);
1388 int config_parse_exec_io_class(const char *unit
,
1389 const char *filename
,
1391 const char *section
,
1392 unsigned section_line
,
1399 ExecContext
*c
= ASSERT_PTR(data
);
1406 if (isempty(rvalue
)) {
1407 c
->ioprio_set
= false;
1408 c
->ioprio
= IOPRIO_DEFAULT_CLASS_AND_PRIO
;
1412 x
= ioprio_class_from_string(rvalue
);
1414 log_syntax(unit
, LOG_WARNING
, filename
, line
, x
, "Failed to parse IO scheduling class, ignoring: %s", rvalue
);
1418 c
->ioprio
= ioprio_normalize(ioprio_prio_value(x
, ioprio_prio_data(c
->ioprio
)));
1419 c
->ioprio_set
= true;
1424 int config_parse_exec_io_priority(const char *unit
,
1425 const char *filename
,
1427 const char *section
,
1428 unsigned section_line
,
1435 ExecContext
*c
= ASSERT_PTR(data
);
1442 if (isempty(rvalue
)) {
1443 c
->ioprio_set
= false;
1444 c
->ioprio
= IOPRIO_DEFAULT_CLASS_AND_PRIO
;
1448 r
= ioprio_parse_priority(rvalue
, &i
);
1450 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse IO priority, ignoring: %s", rvalue
);
1454 c
->ioprio
= ioprio_normalize(ioprio_prio_value(ioprio_prio_class(c
->ioprio
), i
));
1455 c
->ioprio_set
= true;
1460 int config_parse_exec_cpu_sched_policy(const char *unit
,
1461 const char *filename
,
1463 const char *section
,
1464 unsigned section_line
,
1471 ExecContext
*c
= ASSERT_PTR(data
);
1478 if (isempty(rvalue
)) {
1479 c
->cpu_sched_set
= false;
1480 c
->cpu_sched_policy
= SCHED_OTHER
;
1481 c
->cpu_sched_priority
= 0;
1485 x
= sched_policy_from_string(rvalue
);
1487 log_syntax(unit
, LOG_WARNING
, filename
, line
, x
, "Failed to parse CPU scheduling policy, ignoring: %s", rvalue
);
1491 c
->cpu_sched_policy
= x
;
1492 /* Moving to or from real-time policy? We need to adjust the priority */
1493 c
->cpu_sched_priority
= CLAMP(c
->cpu_sched_priority
, sched_get_priority_min(x
), sched_get_priority_max(x
));
1494 c
->cpu_sched_set
= true;
1499 int config_parse_exec_mount_apivfs(const char *unit
,
1500 const char *filename
,
1502 const char *section
,
1503 unsigned section_line
,
1510 ExecContext
*c
= ASSERT_PTR(data
);
1517 if (isempty(rvalue
)) {
1518 c
->mount_apivfs_set
= false;
1519 c
->mount_apivfs
= false;
1523 k
= parse_boolean(rvalue
);
1525 log_syntax(unit
, LOG_WARNING
, filename
, line
, k
,
1526 "Failed to parse boolean value, ignoring: %s",
1531 c
->mount_apivfs_set
= true;
1532 c
->mount_apivfs
= k
;
1536 int config_parse_numa_mask(const char *unit
,
1537 const char *filename
,
1539 const char *section
,
1540 unsigned section_line
,
1547 NUMAPolicy
*p
= ASSERT_PTR(data
);
1553 if (streq(rvalue
, "all")) {
1554 r
= numa_mask_add_all(&p
->nodes
);
1556 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1557 "Failed to create NUMA mask representing \"all\" NUMA nodes, ignoring: %m");
1559 r
= parse_cpu_set_extend(rvalue
, &p
->nodes
, true, unit
, filename
, line
, lvalue
);
1561 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse NUMA node mask, ignoring: %s", rvalue
);
1567 int config_parse_exec_cpu_sched_prio(const char *unit
,
1568 const char *filename
,
1570 const char *section
,
1571 unsigned section_line
,
1578 ExecContext
*c
= ASSERT_PTR(data
);
1585 r
= safe_atoi(rvalue
, &i
);
1587 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse CPU scheduling priority, ignoring: %s", rvalue
);
1591 /* On Linux RR/FIFO range from 1 to 99 and OTHER/BATCH may only be 0. Policy might be set later so
1592 * we do not check the precise range, but only the generic outer bounds. */
1593 if (i
< 0 || i
> 99) {
1594 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "CPU scheduling priority is out of range, ignoring: %s", rvalue
);
1598 c
->cpu_sched_priority
= i
;
1599 c
->cpu_sched_set
= true;
1604 int config_parse_root_image_options(
1606 const char *filename
,
1608 const char *section
,
1609 unsigned section_line
,
1616 _cleanup_(mount_options_free_allp
) MountOptions
*options
= NULL
;
1617 _cleanup_strv_free_
char **l
= NULL
;
1618 ExecContext
*c
= ASSERT_PTR(data
);
1619 const Unit
*u
= userdata
;
1626 if (isempty(rvalue
)) {
1627 c
->root_image_options
= mount_options_free_all(c
->root_image_options
);
1631 r
= strv_split_colon_pairs(&l
, rvalue
);
1635 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
1639 STRV_FOREACH_PAIR(first
, second
, l
) {
1640 MountOptions
*o
= NULL
;
1641 _cleanup_free_
char *mount_options_resolved
= NULL
;
1642 const char *mount_options
= NULL
, *partition
= "root";
1643 PartitionDesignator partition_designator
;
1645 /* Format is either 'root:foo' or 'foo' (root is implied) */
1646 if (!isempty(*second
)) {
1648 mount_options
= *second
;
1650 mount_options
= *first
;
1652 partition_designator
= partition_designator_from_string(partition
);
1653 if (partition_designator
< 0) {
1654 log_syntax(unit
, LOG_WARNING
, filename
, line
, partition_designator
,
1655 "Invalid partition name %s, ignoring", partition
);
1658 r
= unit_full_printf(u
, mount_options
, &mount_options_resolved
);
1660 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", mount_options
);
1664 o
= new(MountOptions
, 1);
1667 *o
= (MountOptions
) {
1668 .partition_designator
= partition_designator
,
1669 .options
= TAKE_PTR(mount_options_resolved
),
1671 LIST_APPEND(mount_options
, options
, TAKE_PTR(o
));
1675 LIST_JOIN(mount_options
, c
->root_image_options
, options
);
1677 /* empty spaces/separators only */
1678 c
->root_image_options
= mount_options_free_all(c
->root_image_options
);
1683 int config_parse_exec_root_hash(
1685 const char *filename
,
1687 const char *section
,
1688 unsigned section_line
,
1695 _cleanup_free_
void *roothash_decoded
= NULL
;
1696 ExecContext
*c
= ASSERT_PTR(data
);
1697 size_t roothash_decoded_size
= 0;
1704 if (isempty(rvalue
)) {
1705 /* Reset if the empty string is assigned */
1706 c
->root_hash_path
= mfree(c
->root_hash_path
);
1707 c
->root_hash
= mfree(c
->root_hash
);
1708 c
->root_hash_size
= 0;
1712 if (path_is_absolute(rvalue
)) {
1713 /* We have the path to a roothash to load and decode, eg: RootHash=/foo/bar.roothash */
1714 _cleanup_free_
char *p
= NULL
;
1720 free_and_replace(c
->root_hash_path
, p
);
1721 c
->root_hash
= mfree(c
->root_hash
);
1722 c
->root_hash_size
= 0;
1726 /* We have a roothash to decode, eg: RootHash=012345789abcdef */
1727 r
= unhexmem(rvalue
, &roothash_decoded
, &roothash_decoded_size
);
1729 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to decode RootHash=, ignoring: %s", rvalue
);
1732 if (roothash_decoded_size
< sizeof(sd_id128_t
)) {
1733 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "RootHash= is too short, ignoring: %s", rvalue
);
1737 free_and_replace(c
->root_hash
, roothash_decoded
);
1738 c
->root_hash_size
= roothash_decoded_size
;
1739 c
->root_hash_path
= mfree(c
->root_hash_path
);
1744 int config_parse_exec_root_hash_sig(
1746 const char *filename
,
1748 const char *section
,
1749 unsigned section_line
,
1756 _cleanup_free_
void *roothash_sig_decoded
= NULL
;
1758 ExecContext
*c
= ASSERT_PTR(data
);
1759 size_t roothash_sig_decoded_size
= 0;
1766 if (isempty(rvalue
)) {
1767 /* Reset if the empty string is assigned */
1768 c
->root_hash_sig_path
= mfree(c
->root_hash_sig_path
);
1769 c
->root_hash_sig
= mfree(c
->root_hash_sig
);
1770 c
->root_hash_sig_size
= 0;
1774 if (path_is_absolute(rvalue
)) {
1775 /* We have the path to a roothash signature to load and decode, eg: RootHashSignature=/foo/bar.roothash.p7s */
1776 _cleanup_free_
char *p
= NULL
;
1782 free_and_replace(c
->root_hash_sig_path
, p
);
1783 c
->root_hash_sig
= mfree(c
->root_hash_sig
);
1784 c
->root_hash_sig_size
= 0;
1788 if (!(value
= startswith(rvalue
, "base64:"))) {
1789 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
1790 "Failed to decode RootHashSignature=, not a path but doesn't start with 'base64:', ignoring: %s", rvalue
);
1794 /* We have a roothash signature to decode, eg: RootHashSignature=base64:012345789abcdef */
1795 r
= unbase64mem(value
, &roothash_sig_decoded
, &roothash_sig_decoded_size
);
1797 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to decode RootHashSignature=, ignoring: %s", rvalue
);
1801 free_and_replace(c
->root_hash_sig
, roothash_sig_decoded
);
1802 c
->root_hash_sig_size
= roothash_sig_decoded_size
;
1803 c
->root_hash_sig_path
= mfree(c
->root_hash_sig_path
);
1808 int config_parse_exec_cpu_affinity(
1810 const char *filename
,
1812 const char *section
,
1813 unsigned section_line
,
1820 ExecContext
*c
= ASSERT_PTR(data
);
1821 const Unit
*u
= userdata
;
1822 _cleanup_free_
char *k
= NULL
;
1829 if (streq(rvalue
, "numa")) {
1830 c
->cpu_affinity_from_numa
= true;
1831 cpu_set_reset(&c
->cpu_set
);
1836 r
= unit_full_printf(u
, rvalue
, &k
);
1838 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1839 "Failed to resolve unit specifiers in '%s', ignoring: %m",
1844 r
= parse_cpu_set_extend(k
, &c
->cpu_set
, true, unit
, filename
, line
, lvalue
);
1846 c
->cpu_affinity_from_numa
= false;
1851 int config_parse_capability_set(
1853 const char *filename
,
1855 const char *section
,
1856 unsigned section_line
,
1863 uint64_t *capability_set
= ASSERT_PTR(data
);
1864 uint64_t sum
= 0, initial
, def
;
1865 bool invert
= false;
1872 if (rvalue
[0] == '~') {
1877 if (streq(lvalue
, "CapabilityBoundingSet")) {
1878 initial
= CAP_MASK_ALL
; /* initialized to all bits on */
1879 def
= CAP_MASK_UNSET
; /* not set */
1881 def
= initial
= 0; /* All bits off */
1883 r
= capability_set_from_string(rvalue
, &sum
);
1885 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= specifier '%s', ignoring: %m", lvalue
, rvalue
);
1889 if (sum
== 0 || *capability_set
== def
)
1890 /* "", "~" or uninitialized data -> replace */
1891 *capability_set
= invert
? ~sum
: sum
;
1893 /* previous data -> merge */
1895 *capability_set
&= ~sum
;
1897 *capability_set
|= sum
;
1903 int config_parse_exec_selinux_context(
1905 const char *filename
,
1907 const char *section
,
1908 unsigned section_line
,
1915 ExecContext
*c
= ASSERT_PTR(data
);
1916 const Unit
*u
= userdata
;
1925 if (isempty(rvalue
)) {
1926 c
->selinux_context
= mfree(c
->selinux_context
);
1927 c
->selinux_context_ignore
= false;
1931 if (rvalue
[0] == '-') {
1937 r
= unit_full_printf(u
, rvalue
, &k
);
1939 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
1940 "Failed to resolve unit specifiers in '%s'%s: %m",
1941 rvalue
, ignore
? ", ignoring" : "");
1942 return ignore
? 0 : -ENOEXEC
;
1945 free_and_replace(c
->selinux_context
, k
);
1946 c
->selinux_context_ignore
= ignore
;
1951 int config_parse_exec_apparmor_profile(
1953 const char *filename
,
1955 const char *section
,
1956 unsigned section_line
,
1963 ExecContext
*c
= ASSERT_PTR(data
);
1964 const Unit
*u
= userdata
;
1973 if (isempty(rvalue
)) {
1974 c
->apparmor_profile
= mfree(c
->apparmor_profile
);
1975 c
->apparmor_profile_ignore
= false;
1979 if (rvalue
[0] == '-') {
1985 r
= unit_full_printf(u
, rvalue
, &k
);
1987 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
1988 "Failed to resolve unit specifiers in '%s'%s: %m",
1989 rvalue
, ignore
? ", ignoring" : "");
1990 return ignore
? 0 : -ENOEXEC
;
1993 free_and_replace(c
->apparmor_profile
, k
);
1994 c
->apparmor_profile_ignore
= ignore
;
1999 int config_parse_exec_smack_process_label(
2001 const char *filename
,
2003 const char *section
,
2004 unsigned section_line
,
2011 ExecContext
*c
= ASSERT_PTR(data
);
2012 const Unit
*u
= userdata
;
2021 if (isempty(rvalue
)) {
2022 c
->smack_process_label
= mfree(c
->smack_process_label
);
2023 c
->smack_process_label_ignore
= false;
2027 if (rvalue
[0] == '-') {
2033 r
= unit_full_printf(u
, rvalue
, &k
);
2035 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
2036 "Failed to resolve unit specifiers in '%s'%s: %m",
2037 rvalue
, ignore
? ", ignoring" : "");
2038 return ignore
? 0 : -ENOEXEC
;
2041 free_and_replace(c
->smack_process_label
, k
);
2042 c
->smack_process_label_ignore
= ignore
;
2047 int config_parse_timer(
2049 const char *filename
,
2051 const char *section
,
2052 unsigned section_line
,
2059 _cleanup_(calendar_spec_freep
) CalendarSpec
*c
= NULL
;
2060 _cleanup_free_
char *k
= NULL
;
2061 const Unit
*u
= userdata
;
2062 Timer
*t
= ASSERT_PTR(data
);
2071 if (isempty(rvalue
)) {
2072 /* Empty assignment resets list */
2073 timer_free_values(t
);
2077 r
= unit_full_printf(u
, rvalue
, &k
);
2079 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2083 if (ltype
== TIMER_CALENDAR
) {
2084 r
= calendar_spec_from_string(k
, &c
);
2086 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse calendar specification, ignoring: %s", k
);
2090 r
= parse_sec(k
, &usec
);
2092 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse timer value, ignoring: %s", k
);
2097 v
= new(TimerValue
, 1);
2104 .calendar_spec
= TAKE_PTR(c
),
2107 LIST_PREPEND(value
, t
->values
, v
);
2112 int config_parse_trigger_unit(
2114 const char *filename
,
2116 const char *section
,
2117 unsigned section_line
,
2124 _cleanup_free_
char *p
= NULL
;
2125 Unit
*u
= ASSERT_PTR(data
);
2133 if (UNIT_TRIGGER(u
)) {
2134 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Multiple units to trigger specified, ignoring: %s", rvalue
);
2138 r
= unit_name_printf(u
, rvalue
, &p
);
2140 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2144 type
= unit_name_to_type(p
);
2146 log_syntax(unit
, LOG_WARNING
, filename
, line
, type
, "Unit type not valid, ignoring: %s", rvalue
);
2149 if (unit_has_name(u
, p
)) {
2150 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Units cannot trigger themselves, ignoring: %s", rvalue
);
2154 r
= unit_add_two_dependencies_by_name(u
, UNIT_BEFORE
, UNIT_TRIGGERS
, p
, true, UNIT_DEPENDENCY_FILE
);
2156 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add trigger on %s, ignoring: %m", p
);
2163 int config_parse_path_spec(const char *unit
,
2164 const char *filename
,
2166 const char *section
,
2167 unsigned section_line
,
2174 Path
*p
= ASSERT_PTR(data
);
2177 _cleanup_free_
char *k
= NULL
;
2184 if (isempty(rvalue
)) {
2185 /* Empty assignment clears list */
2190 b
= path_type_from_string(lvalue
);
2192 log_syntax(unit
, LOG_WARNING
, filename
, line
, b
, "Failed to parse path type, ignoring: %s", lvalue
);
2196 r
= unit_path_printf(UNIT(p
), rvalue
, &k
);
2198 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2202 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2206 s
= new0(PathSpec
, 1);
2211 s
->path
= TAKE_PTR(k
);
2213 s
->inotify_fd
= -EBADF
;
2215 LIST_PREPEND(spec
, p
->specs
, s
);
2220 int config_parse_socket_service(
2222 const char *filename
,
2224 const char *section
,
2225 unsigned section_line
,
2232 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
2233 _cleanup_free_
char *p
= NULL
;
2234 Socket
*s
= ASSERT_PTR(data
);
2242 r
= unit_name_printf(UNIT(s
), rvalue
, &p
);
2244 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2248 if (!endswith(p
, ".service")) {
2249 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Unit must be of type service, ignoring: %s", rvalue
);
2253 r
= manager_load_unit(UNIT(s
)->manager
, p
, NULL
, &error
, &x
);
2255 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to load unit %s, ignoring: %s", rvalue
, bus_error_message(&error
, r
));
2259 unit_ref_set(&s
->service
, UNIT(s
), x
);
2264 int config_parse_fdname(
2266 const char *filename
,
2268 const char *section
,
2269 unsigned section_line
,
2276 _cleanup_free_
char *p
= NULL
;
2277 Socket
*s
= ASSERT_PTR(data
);
2284 if (isempty(rvalue
)) {
2285 s
->fdname
= mfree(s
->fdname
);
2289 r
= unit_fd_printf(UNIT(s
), rvalue
, &p
);
2291 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2295 if (!fdname_is_valid(p
)) {
2296 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", p
);
2300 return free_and_replace(s
->fdname
, p
);
2303 int config_parse_service_sockets(
2305 const char *filename
,
2307 const char *section
,
2308 unsigned section_line
,
2315 Service
*s
= ASSERT_PTR(data
);
2322 for (const char *p
= rvalue
;;) {
2323 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2325 r
= extract_first_word(&p
, &word
, NULL
, 0);
2329 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Trailing garbage in sockets, ignoring: %s", rvalue
);
2335 r
= unit_name_printf(UNIT(s
), word
, &k
);
2337 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
2341 if (!endswith(k
, ".socket")) {
2342 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Unit must be of type socket, ignoring: %s", k
);
2346 r
= unit_add_two_dependencies_by_name(UNIT(s
), UNIT_WANTS
, UNIT_AFTER
, k
, true, UNIT_DEPENDENCY_FILE
);
2348 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
2350 r
= unit_add_dependency_by_name(UNIT(s
), UNIT_TRIGGERED_BY
, k
, true, UNIT_DEPENDENCY_FILE
);
2352 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
2356 int config_parse_bus_name(
2358 const char *filename
,
2360 const char *section
,
2361 unsigned section_line
,
2368 _cleanup_free_
char *k
= NULL
;
2369 const Unit
*u
= ASSERT_PTR(userdata
);
2376 r
= unit_full_printf_full(u
, rvalue
, SD_BUS_MAXIMUM_NAME_LENGTH
, &k
);
2378 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2382 if (!sd_bus_service_name_is_valid(k
)) {
2383 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid bus name, ignoring: %s", k
);
2387 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
2390 int config_parse_service_timeout(
2392 const char *filename
,
2394 const char *section
,
2395 unsigned section_line
,
2402 Service
*s
= ASSERT_PTR(userdata
);
2410 /* This is called for two cases: TimeoutSec= and TimeoutStartSec=. */
2412 /* Traditionally, these options accepted 0 to disable the timeouts. However, a timeout of 0 suggests it happens
2413 * immediately, hence fix this to become USEC_INFINITY instead. This is in-line with how we internally handle
2414 * all other timeouts. */
2415 r
= parse_sec_fix_0(rvalue
, &usec
);
2417 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
2421 s
->start_timeout_defined
= true;
2422 s
->timeout_start_usec
= usec
;
2424 if (streq(lvalue
, "TimeoutSec"))
2425 s
->timeout_stop_usec
= usec
;
2430 int config_parse_timeout_abort(
2432 const char *filename
,
2434 const char *section
,
2435 unsigned section_line
,
2442 usec_t
*ret
= ASSERT_PTR(data
);
2449 /* Note: apart from setting the arg, this returns an extra bit of information in the return value. */
2451 if (isempty(rvalue
)) {
2453 return 0; /* "not set" */
2456 r
= parse_sec(rvalue
, ret
);
2458 return log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= setting, ignoring: %s", lvalue
, rvalue
);
2460 return 1; /* "set" */
2463 int config_parse_service_timeout_abort(
2465 const char *filename
,
2467 const char *section
,
2468 unsigned section_line
,
2475 Service
*s
= ASSERT_PTR(userdata
);
2478 r
= config_parse_timeout_abort(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
,
2479 &s
->timeout_abort_usec
, s
);
2481 s
->timeout_abort_set
= r
;
2485 int config_parse_user_group_compat(
2487 const char *filename
,
2489 const char *section
,
2490 unsigned section_line
,
2497 _cleanup_free_
char *k
= NULL
;
2499 const Unit
*u
= ASSERT_PTR(userdata
);
2506 if (isempty(rvalue
)) {
2507 *user
= mfree(*user
);
2511 r
= unit_full_printf(u
, rvalue
, &k
);
2513 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", rvalue
);
2517 if (!valid_user_group_name(k
, VALID_USER_ALLOW_NUMERIC
|VALID_USER_RELAX
|VALID_USER_WARN
)) {
2518 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2522 if (strstr(lvalue
, "User") && streq(k
, NOBODY_USER_NAME
))
2523 log_struct(LOG_NOTICE
,
2524 "MESSAGE=%s:%u: Special user %s configured, this is not safe!", filename
, line
, k
,
2526 "MESSAGE_ID=" SD_MESSAGE_NOBODY_USER_UNSUITABLE_STR
,
2527 "OFFENDING_USER=%s", k
,
2528 "CONFIG_FILE=%s", filename
,
2529 "CONFIG_LINE=%u", line
);
2531 return free_and_replace(*user
, k
);
2534 int config_parse_user_group_strv_compat(
2536 const char *filename
,
2538 const char *section
,
2539 unsigned section_line
,
2546 char ***users
= data
;
2547 const Unit
*u
= ASSERT_PTR(userdata
);
2554 if (isempty(rvalue
)) {
2555 *users
= strv_free(*users
);
2559 for (const char *p
= rvalue
;;) {
2560 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2562 r
= extract_first_word(&p
, &word
, NULL
, 0);
2566 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax: %s", rvalue
);
2572 r
= unit_full_printf(u
, word
, &k
);
2574 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", word
);
2578 if (!valid_user_group_name(k
, VALID_USER_ALLOW_NUMERIC
|VALID_USER_RELAX
|VALID_USER_WARN
)) {
2579 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2583 r
= strv_push(users
, k
);
2591 int config_parse_working_directory(
2593 const char *filename
,
2595 const char *section
,
2596 unsigned section_line
,
2603 ExecContext
*c
= ASSERT_PTR(data
);
2604 const Unit
*u
= ASSERT_PTR(userdata
);
2612 if (isempty(rvalue
)) {
2613 c
->working_directory_home
= false;
2614 c
->working_directory
= mfree(c
->working_directory
);
2618 if (rvalue
[0] == '-') {
2624 if (streq(rvalue
, "~")) {
2625 c
->working_directory_home
= true;
2626 c
->working_directory
= mfree(c
->working_directory
);
2628 _cleanup_free_
char *k
= NULL
;
2630 r
= unit_path_printf(u
, rvalue
, &k
);
2632 log_syntax(unit
, missing_ok
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
2633 "Failed to resolve unit specifiers in working directory path '%s'%s: %m",
2634 rvalue
, missing_ok
? ", ignoring" : "");
2635 return missing_ok
? 0 : -ENOEXEC
;
2638 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
|PATH_CHECK_NON_API_VFS
|(missing_ok
? 0 : PATH_CHECK_FATAL
), unit
, filename
, line
, lvalue
);
2640 return missing_ok
? 0 : -ENOEXEC
;
2642 c
->working_directory_home
= false;
2643 free_and_replace(c
->working_directory
, k
);
2646 c
->working_directory_missing_ok
= missing_ok
;
2650 int config_parse_unit_env_file(const char *unit
,
2651 const char *filename
,
2653 const char *section
,
2654 unsigned section_line
,
2661 char ***env
= ASSERT_PTR(data
);
2662 const Unit
*u
= userdata
;
2663 _cleanup_free_
char *n
= NULL
;
2670 if (isempty(rvalue
)) {
2671 /* Empty assignment frees the list */
2672 *env
= strv_free(*env
);
2676 r
= unit_path_printf(u
, rvalue
, &n
);
2678 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2682 r
= path_simplify_and_warn(n
[0] == '-' ? n
+ 1 : n
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2686 r
= strv_push(env
, n
);
2695 int config_parse_environ(
2697 const char *filename
,
2699 const char *section
,
2700 unsigned section_line
,
2707 const Unit
*u
= userdata
;
2708 char ***env
= ASSERT_PTR(data
);
2715 if (isempty(rvalue
)) {
2716 /* Empty assignment resets the list */
2717 *env
= strv_free(*env
);
2721 /* If 'u' is set, we operate on the regular unit specifier table. Otherwise we use a manager-specific
2722 * specifier table (in which case ltype must contain the runtime scope). */
2723 const Specifier
*table
= u
? NULL
: (const Specifier
[]) {
2724 COMMON_SYSTEM_SPECIFIERS
,
2725 COMMON_TMP_SPECIFIERS
,
2726 COMMON_CREDS_SPECIFIERS(ltype
),
2727 { 'h', specifier_user_home
, NULL
},
2728 { 's', specifier_user_shell
, NULL
},
2731 for (const char *p
= rvalue
;; ) {
2732 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
2734 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2738 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2739 "Invalid syntax, ignoring: %s", rvalue
);
2746 r
= specifier_printf(word
, sc_arg_max(), table
, NULL
, NULL
, &resolved
);
2748 r
= unit_env_printf(u
, word
, &resolved
);
2750 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2751 "Failed to resolve specifiers in %s, ignoring: %m", word
);
2755 if (!env_assignment_is_valid(resolved
)) {
2756 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
2757 "Invalid environment assignment, ignoring: %s", resolved
);
2761 r
= strv_env_replace_consume(env
, TAKE_PTR(resolved
));
2763 return log_error_errno(r
, "Failed to update environment: %m");
2767 int config_parse_pass_environ(
2769 const char *filename
,
2771 const char *section
,
2772 unsigned section_line
,
2779 _cleanup_strv_free_
char **n
= NULL
;
2780 const Unit
*u
= userdata
;
2781 char*** passenv
= ASSERT_PTR(data
);
2789 if (isempty(rvalue
)) {
2790 /* Empty assignment resets the list */
2791 *passenv
= strv_free(*passenv
);
2795 for (const char *p
= rvalue
;;) {
2796 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2798 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
2802 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2803 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2810 r
= unit_env_printf(u
, word
, &k
);
2812 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2813 "Failed to resolve specifiers in %s, ignoring: %m", word
);
2819 if (!env_name_is_valid(k
)) {
2820 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
2821 "Invalid environment name for %s, ignoring: %s", lvalue
, k
);
2825 if (!GREEDY_REALLOC(n
, nlen
+ 2))
2828 n
[nlen
++] = TAKE_PTR(k
);
2833 r
= strv_extend_strv(passenv
, n
, true);
2841 int config_parse_unset_environ(
2843 const char *filename
,
2845 const char *section
,
2846 unsigned section_line
,
2853 _cleanup_strv_free_
char **n
= NULL
;
2854 char*** unsetenv
= ASSERT_PTR(data
);
2855 const Unit
*u
= userdata
;
2863 if (isempty(rvalue
)) {
2864 /* Empty assignment resets the list */
2865 *unsetenv
= strv_free(*unsetenv
);
2869 for (const char *p
= rvalue
;;) {
2870 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2872 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2876 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2877 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2884 r
= unit_env_printf(u
, word
, &k
);
2886 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2887 "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2893 if (!env_assignment_is_valid(k
) && !env_name_is_valid(k
)) {
2894 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
2895 "Invalid environment name or assignment %s, ignoring: %s", lvalue
, k
);
2899 if (!GREEDY_REALLOC(n
, nlen
+ 2))
2902 n
[nlen
++] = TAKE_PTR(k
);
2907 r
= strv_extend_strv(unsetenv
, n
, true);
2915 int config_parse_log_extra_fields(
2917 const char *filename
,
2919 const char *section
,
2920 unsigned section_line
,
2927 ExecContext
*c
= ASSERT_PTR(data
);
2928 const Unit
*u
= userdata
;
2935 if (isempty(rvalue
)) {
2936 exec_context_free_log_extra_fields(c
);
2940 for (const char *p
= rvalue
;;) {
2941 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2945 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2949 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
2955 r
= unit_full_printf(u
, word
, &k
);
2957 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2961 eq
= strchr(k
, '=');
2963 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Log field lacks '=' character, ignoring: %s", k
);
2967 if (!journal_field_valid(k
, eq
-k
, false)) {
2968 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Log field name is invalid, ignoring: %s", k
);
2972 t
= reallocarray(c
->log_extra_fields
, c
->n_log_extra_fields
+1, sizeof(struct iovec
));
2976 c
->log_extra_fields
= t
;
2977 c
->log_extra_fields
[c
->n_log_extra_fields
++] = IOVEC_MAKE_STRING(k
);
2983 int config_parse_log_namespace(
2985 const char *filename
,
2987 const char *section
,
2988 unsigned section_line
,
2995 _cleanup_free_
char *k
= NULL
;
2996 ExecContext
*c
= ASSERT_PTR(data
);
2997 const Unit
*u
= userdata
;
3004 if (isempty(rvalue
)) {
3005 c
->log_namespace
= mfree(c
->log_namespace
);
3009 r
= unit_full_printf_full(u
, rvalue
, NAME_MAX
, &k
);
3011 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
3015 if (!log_namespace_name_valid(k
)) {
3016 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Specified log namespace name is not valid, ignoring: %s", k
);
3020 free_and_replace(c
->log_namespace
, k
);
3024 int config_parse_unit_condition_path(
3026 const char *filename
,
3028 const char *section
,
3029 unsigned section_line
,
3036 _cleanup_free_
char *p
= NULL
;
3037 Condition
**list
= ASSERT_PTR(data
), *c
;
3038 ConditionType t
= ltype
;
3039 bool trigger
, negate
;
3040 const Unit
*u
= userdata
;
3047 if (isempty(rvalue
)) {
3048 /* Empty assignment resets the list */
3049 *list
= condition_free_list(*list
);
3053 trigger
= rvalue
[0] == '|';
3057 negate
= rvalue
[0] == '!';
3061 r
= unit_path_printf(u
, rvalue
, &p
);
3063 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
3067 r
= path_simplify_and_warn(p
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
3071 c
= condition_new(t
, p
, trigger
, negate
);
3075 LIST_PREPEND(conditions
, *list
, c
);
3079 int config_parse_unit_condition_string(
3081 const char *filename
,
3083 const char *section
,
3084 unsigned section_line
,
3091 _cleanup_free_
char *s
= NULL
;
3092 Condition
**list
= ASSERT_PTR(data
), *c
;
3093 ConditionType t
= ltype
;
3094 bool trigger
, negate
;
3095 const Unit
*u
= userdata
;
3102 if (isempty(rvalue
)) {
3103 /* Empty assignment resets the list */
3104 *list
= condition_free_list(*list
);
3108 trigger
= *rvalue
== '|';
3110 rvalue
+= 1 + strspn(rvalue
+ 1, WHITESPACE
);
3112 negate
= *rvalue
== '!';
3114 rvalue
+= 1 + strspn(rvalue
+ 1, WHITESPACE
);
3116 r
= unit_full_printf(u
, rvalue
, &s
);
3118 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3119 "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
3123 c
= condition_new(t
, s
, trigger
, negate
);
3127 LIST_PREPEND(conditions
, *list
, c
);
3131 int config_parse_unit_mounts_for(
3133 const char *filename
,
3135 const char *section
,
3136 unsigned section_line
,
3150 assert(STR_IN_SET(lvalue
, "RequiresMountsFor", "WantsMountsFor"));
3152 for (const char *p
= rvalue
;;) {
3153 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
3155 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3159 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3160 "Invalid syntax, ignoring: %s", rvalue
);
3166 r
= unit_path_printf(u
, word
, &resolved
);
3168 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
3172 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
3176 r
= unit_add_mounts_for(u
, resolved
, UNIT_DEPENDENCY_FILE
, unit_mount_dependency_type_from_string(lvalue
));
3178 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add requested mount '%s', ignoring: %m", resolved
);
3184 int config_parse_documentation(
3186 const char *filename
,
3188 const char *section
,
3189 unsigned section_line
,
3196 Unit
*u
= ASSERT_PTR(userdata
);
3204 if (isempty(rvalue
)) {
3205 /* Empty assignment resets the list */
3206 u
->documentation
= strv_free(u
->documentation
);
3210 r
= config_parse_unit_strv_printf(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
,
3211 rvalue
, data
, userdata
);
3215 for (a
= b
= u
->documentation
; a
&& *a
; a
++) {
3217 if (documentation_url_is_valid(*a
))
3220 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid URL, ignoring: %s", *a
);
3231 int config_parse_syscall_filter(
3233 const char *filename
,
3235 const char *section
,
3236 unsigned section_line
,
3243 ExecContext
*c
= data
;
3244 _unused_
const Unit
*u
= ASSERT_PTR(userdata
);
3245 bool invert
= false;
3252 if (isempty(rvalue
)) {
3253 /* Empty assignment resets the list */
3254 c
->syscall_filter
= hashmap_free(c
->syscall_filter
);
3255 c
->syscall_allow_list
= false;
3259 if (rvalue
[0] == '~') {
3264 if (!c
->syscall_filter
) {
3265 c
->syscall_filter
= hashmap_new(NULL
);
3266 if (!c
->syscall_filter
)
3270 /* Allow everything but the ones listed */
3271 c
->syscall_allow_list
= false;
3273 /* Allow nothing but the ones listed */
3274 c
->syscall_allow_list
= true;
3276 /* Accept default syscalls if we are on an allow_list */
3277 r
= seccomp_parse_syscall_filter(
3278 "@default", -1, c
->syscall_filter
,
3279 SECCOMP_PARSE_PERMISSIVE
|SECCOMP_PARSE_ALLOW_LIST
,
3287 for (const char *p
= rvalue
;;) {
3288 _cleanup_free_
char *word
= NULL
, *name
= NULL
;
3291 r
= extract_first_word(&p
, &word
, NULL
, 0);
3295 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3296 "Invalid syntax, ignoring: %s", rvalue
);
3302 r
= parse_syscall_and_errno(word
, &name
, &num
);
3304 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3305 "Failed to parse syscall:errno, ignoring: %s", word
);
3308 if (!invert
&& num
>= 0) {
3309 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3310 "Allow-listed system calls cannot take error number, ignoring: %s", word
);
3314 r
= seccomp_parse_syscall_filter(
3315 name
, num
, c
->syscall_filter
,
3316 SECCOMP_PARSE_LOG
|SECCOMP_PARSE_PERMISSIVE
|
3317 (invert
? SECCOMP_PARSE_INVERT
: 0)|
3318 (c
->syscall_allow_list
? SECCOMP_PARSE_ALLOW_LIST
: 0),
3319 unit
, filename
, line
);
3325 int config_parse_syscall_log(
3327 const char *filename
,
3329 const char *section
,
3330 unsigned section_line
,
3337 ExecContext
*c
= data
;
3338 _unused_
const Unit
*u
= ASSERT_PTR(userdata
);
3339 bool invert
= false;
3347 if (isempty(rvalue
)) {
3348 /* Empty assignment resets the list */
3349 c
->syscall_log
= hashmap_free(c
->syscall_log
);
3350 c
->syscall_log_allow_list
= false;
3354 if (rvalue
[0] == '~') {
3359 if (!c
->syscall_log
) {
3360 c
->syscall_log
= hashmap_new(NULL
);
3361 if (!c
->syscall_log
)
3365 /* Log everything but the ones listed */
3366 c
->syscall_log_allow_list
= false;
3368 /* Log nothing but the ones listed */
3369 c
->syscall_log_allow_list
= true;
3374 _cleanup_free_
char *word
= NULL
;
3376 r
= extract_first_word(&p
, &word
, NULL
, 0);
3380 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3386 r
= seccomp_parse_syscall_filter(
3387 word
, -1, c
->syscall_log
,
3388 SECCOMP_PARSE_LOG
|SECCOMP_PARSE_PERMISSIVE
|
3389 (invert
? SECCOMP_PARSE_INVERT
: 0)|
3390 (c
->syscall_log_allow_list
? SECCOMP_PARSE_ALLOW_LIST
: 0),
3391 unit
, filename
, line
);
3397 int config_parse_syscall_archs(
3399 const char *filename
,
3401 const char *section
,
3402 unsigned section_line
,
3412 if (isempty(rvalue
)) {
3413 *archs
= set_free(*archs
);
3417 for (const char *p
= rvalue
;;) {
3418 _cleanup_free_
char *word
= NULL
;
3421 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3425 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3426 "Invalid syntax, ignoring: %s", rvalue
);
3432 r
= seccomp_arch_from_string(word
, &a
);
3434 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3435 "Failed to parse system call architecture \"%s\", ignoring: %m", word
);
3439 r
= set_ensure_put(archs
, NULL
, UINT32_TO_PTR(a
+ 1));
3445 int config_parse_syscall_errno(
3447 const char *filename
,
3449 const char *section
,
3450 unsigned section_line
,
3457 ExecContext
*c
= data
;
3464 if (isempty(rvalue
) || streq(rvalue
, "kill")) {
3465 /* Empty assignment resets to KILL */
3466 c
->syscall_errno
= SECCOMP_ERROR_NUMBER_KILL
;
3470 e
= parse_errno(rvalue
);
3472 log_syntax(unit
, LOG_WARNING
, filename
, line
, e
, "Failed to parse error number, ignoring: %s", rvalue
);
3476 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid error number, ignoring: %s", rvalue
);
3480 c
->syscall_errno
= e
;
3484 int config_parse_address_families(
3486 const char *filename
,
3488 const char *section
,
3489 unsigned section_line
,
3496 ExecContext
*c
= data
;
3497 bool invert
= false;
3504 if (isempty(rvalue
)) {
3505 /* Empty assignment resets the list */
3506 c
->address_families
= set_free(c
->address_families
);
3507 c
->address_families_allow_list
= false;
3511 if (streq(rvalue
, "none")) {
3512 /* Forbid all address families. */
3513 c
->address_families
= set_free(c
->address_families
);
3514 c
->address_families_allow_list
= true;
3518 if (rvalue
[0] == '~') {
3523 if (!c
->address_families
) {
3524 c
->address_families
= set_new(NULL
);
3525 if (!c
->address_families
)
3528 c
->address_families_allow_list
= !invert
;
3531 for (const char *p
= rvalue
;;) {
3532 _cleanup_free_
char *word
= NULL
;
3535 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3539 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3540 "Invalid syntax, ignoring: %s", rvalue
);
3546 af
= af_from_name(word
);
3548 log_syntax(unit
, LOG_WARNING
, filename
, line
, af
,
3549 "Failed to parse address family, ignoring: %s", word
);
3553 /* If we previously wanted to forbid an address family and now
3554 * we want to allow it, then just remove it from the list.
3556 if (!invert
== c
->address_families_allow_list
) {
3557 r
= set_put(c
->address_families
, INT_TO_PTR(af
));
3561 set_remove(c
->address_families
, INT_TO_PTR(af
));
3565 int config_parse_restrict_namespaces(
3567 const char *filename
,
3569 const char *section
,
3570 unsigned section_line
,
3577 ExecContext
*c
= data
;
3578 unsigned long flags
;
3579 bool invert
= false;
3582 if (isempty(rvalue
)) {
3583 /* Reset to the default. */
3584 c
->restrict_namespaces
= NAMESPACE_FLAGS_INITIAL
;
3588 /* Boolean parameter ignores the previous settings */
3589 r
= parse_boolean(rvalue
);
3591 c
->restrict_namespaces
= 0;
3593 } else if (r
== 0) {
3594 c
->restrict_namespaces
= NAMESPACE_FLAGS_ALL
;
3598 if (rvalue
[0] == '~') {
3603 /* Not a boolean argument, in this case it's a list of namespace types. */
3604 r
= namespace_flags_from_string(rvalue
, &flags
);
3606 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse namespace type string, ignoring: %s", rvalue
);
3610 if (c
->restrict_namespaces
== NAMESPACE_FLAGS_INITIAL
)
3611 /* Initial assignment. Just set the value. */
3612 c
->restrict_namespaces
= invert
? (~flags
) & NAMESPACE_FLAGS_ALL
: flags
;
3614 /* Merge the value with the previous one. */
3615 SET_FLAG(c
->restrict_namespaces
, flags
, !invert
);
3621 int config_parse_restrict_filesystems(
3623 const char *filename
,
3625 const char *section
,
3626 unsigned section_line
,
3632 ExecContext
*c
= ASSERT_PTR(data
);
3633 bool invert
= false;
3640 if (isempty(rvalue
)) {
3641 /* Empty assignment resets the list */
3642 c
->restrict_filesystems
= set_free_free(c
->restrict_filesystems
);
3643 c
->restrict_filesystems_allow_list
= false;
3647 if (rvalue
[0] == '~') {
3652 if (!c
->restrict_filesystems
) {
3654 /* Allow everything but the ones listed */
3655 c
->restrict_filesystems_allow_list
= false;
3657 /* Allow nothing but the ones listed */
3658 c
->restrict_filesystems_allow_list
= true;
3661 for (const char *p
= rvalue
;;) {
3662 _cleanup_free_
char *word
= NULL
;
3664 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3670 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3671 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
3675 r
= bpf_restrict_fs_parse_filesystem(
3677 &c
->restrict_filesystems
,
3678 FILESYSTEM_PARSE_LOG
|
3679 (invert
? FILESYSTEM_PARSE_INVERT
: 0)|
3680 (c
->restrict_filesystems_allow_list
? FILESYSTEM_PARSE_ALLOW_LIST
: 0),
3681 unit
, filename
, line
);
3690 int config_parse_unit_slice(
3692 const char *filename
,
3694 const char *section
,
3695 unsigned section_line
,
3702 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
3703 _cleanup_free_
char *k
= NULL
;
3704 Unit
*u
= userdata
, *slice
;
3712 r
= unit_name_printf(u
, rvalue
, &k
);
3714 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
3718 r
= manager_load_unit(u
->manager
, k
, NULL
, &error
, &slice
);
3720 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to load slice unit %s, ignoring: %s", k
, bus_error_message(&error
, r
));
3724 r
= unit_set_slice(u
, slice
);
3726 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to assign slice %s to unit %s, ignoring: %m", slice
->id
, u
->id
);
3733 int config_parse_cpu_quota(
3735 const char *filename
,
3737 const char *section
,
3738 unsigned section_line
,
3745 CGroupContext
*c
= data
;
3752 if (isempty(rvalue
)) {
3753 c
->cpu_quota_per_sec_usec
= USEC_INFINITY
;
3757 r
= parse_permyriad_unbounded(rvalue
);
3759 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid CPU quota '%s', ignoring.", rvalue
);
3763 c
->cpu_quota_per_sec_usec
= ((usec_t
) r
* USEC_PER_SEC
) / 10000U;
3767 int config_parse_allowed_cpuset(
3769 const char *filename
,
3771 const char *section
,
3772 unsigned section_line
,
3780 const Unit
*u
= userdata
;
3781 _cleanup_free_
char *k
= NULL
;
3788 r
= unit_full_printf(u
, rvalue
, &k
);
3790 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3791 "Failed to resolve unit specifiers in '%s', ignoring: %m",
3796 (void) parse_cpu_set_extend(k
, c
, true, unit
, filename
, line
, lvalue
);
3800 int config_parse_memory_limit(
3802 const char *filename
,
3804 const char *section
,
3805 unsigned section_line
,
3812 CGroupContext
*c
= data
;
3813 uint64_t bytes
= CGROUP_LIMIT_MAX
;
3816 if (isempty(rvalue
) && STR_IN_SET(lvalue
, "DefaultMemoryLow",
3821 bytes
= CGROUP_LIMIT_MIN
;
3822 else if (!isempty(rvalue
) && !streq(rvalue
, "infinity")) {
3824 r
= parse_permyriad(rvalue
);
3826 r
= parse_size(rvalue
, 1024, &bytes
);
3828 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid memory limit '%s', ignoring: %m", rvalue
);
3832 bytes
= physical_memory_scale(r
, 10000U);
3834 if (bytes
>= UINT64_MAX
||
3835 (bytes
<= 0 && !STR_IN_SET(lvalue
,
3837 "StartupMemorySwapMax",
3839 "StartupMemoryZSwapMax",
3844 "DefaultstartupMemoryLow",
3845 "DefaultMemoryMin"))) {
3846 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Memory limit '%s' out of range, ignoring.", rvalue
);
3851 if (streq(lvalue
, "DefaultMemoryLow")) {
3852 c
->default_memory_low
= bytes
;
3853 c
->default_memory_low_set
= true;
3854 } else if (streq(lvalue
, "DefaultStartupMemoryLow")) {
3855 c
->default_startup_memory_low
= bytes
;
3856 c
->default_startup_memory_low_set
= true;
3857 } else if (streq(lvalue
, "DefaultMemoryMin")) {
3858 c
->default_memory_min
= bytes
;
3859 c
->default_memory_min_set
= true;
3860 } else if (streq(lvalue
, "MemoryMin")) {
3861 c
->memory_min
= bytes
;
3862 c
->memory_min_set
= true;
3863 } else if (streq(lvalue
, "MemoryLow")) {
3864 c
->memory_low
= bytes
;
3865 c
->memory_low_set
= true;
3866 } else if (streq(lvalue
, "StartupMemoryLow")) {
3867 c
->startup_memory_low
= bytes
;
3868 c
->startup_memory_low_set
= true;
3869 } else if (streq(lvalue
, "MemoryHigh"))
3870 c
->memory_high
= bytes
;
3871 else if (streq(lvalue
, "StartupMemoryHigh")) {
3872 c
->startup_memory_high
= bytes
;
3873 c
->startup_memory_high_set
= true;
3874 } else if (streq(lvalue
, "MemoryMax"))
3875 c
->memory_max
= bytes
;
3876 else if (streq(lvalue
, "StartupMemoryMax")) {
3877 c
->startup_memory_max
= bytes
;
3878 c
->startup_memory_max_set
= true;
3879 } else if (streq(lvalue
, "MemorySwapMax"))
3880 c
->memory_swap_max
= bytes
;
3881 else if (streq(lvalue
, "StartupMemorySwapMax")) {
3882 c
->startup_memory_swap_max
= bytes
;
3883 c
->startup_memory_swap_max_set
= true;
3884 } else if (streq(lvalue
, "MemoryZSwapMax"))
3885 c
->memory_zswap_max
= bytes
;
3886 else if (streq(lvalue
, "StartupMemoryZSwapMax")) {
3887 c
->startup_memory_zswap_max
= bytes
;
3888 c
->startup_memory_zswap_max_set
= true;
3889 } else if (streq(lvalue
, "MemoryLimit")) {
3890 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3891 "Unit uses MemoryLimit=; please use MemoryMax= instead. Support for MemoryLimit= will be removed soon.");
3892 c
->memory_limit
= bytes
;
3899 int config_parse_tasks_max(
3901 const char *filename
,
3903 const char *section
,
3904 unsigned section_line
,
3911 const Unit
*u
= userdata
;
3912 CGroupTasksMax
*tasks_max
= data
;
3916 if (isempty(rvalue
)) {
3917 *tasks_max
= u
? u
->manager
->defaults
.tasks_max
: CGROUP_TASKS_MAX_UNSET
;
3921 if (streq(rvalue
, "infinity")) {
3922 *tasks_max
= CGROUP_TASKS_MAX_UNSET
;
3926 r
= parse_permyriad(rvalue
);
3928 *tasks_max
= (CGroupTasksMax
) { r
, 10000U }; /* r‱ */
3930 r
= safe_atou64(rvalue
, &v
);
3932 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid maximum tasks value '%s', ignoring: %m", rvalue
);
3936 if (v
<= 0 || v
>= UINT64_MAX
) {
3937 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Maximum tasks value '%s' out of range, ignoring.", rvalue
);
3941 *tasks_max
= (CGroupTasksMax
) { v
};
3947 int config_parse_delegate(
3949 const char *filename
,
3951 const char *section
,
3952 unsigned section_line
,
3959 CGroupContext
*c
= data
;
3963 t
= unit_name_to_type(unit
);
3964 assert(t
!= _UNIT_TYPE_INVALID
);
3966 if (!unit_vtable
[t
]->can_delegate
) {
3967 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Delegate= setting not supported for this unit type, ignoring.");
3971 /* We either accept a boolean value, which may be used to turn on delegation for all controllers, or
3972 * turn it off for all. Or it takes a list of controller names, in which case we add the specified
3973 * controllers to the mask to delegate. Delegate= enables delegation without any controllers. */
3975 if (isempty(rvalue
)) {
3976 /* An empty string resets controllers and sets Delegate=yes. */
3978 c
->delegate_controllers
= 0;
3982 r
= parse_boolean(rvalue
);
3984 CGroupMask mask
= 0;
3986 for (const char *p
= rvalue
;;) {
3987 _cleanup_free_
char *word
= NULL
;
3988 CGroupController cc
;
3990 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3994 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
4000 cc
= cgroup_controller_from_string(word
);
4002 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid controller name '%s', ignoring", word
);
4006 mask
|= CGROUP_CONTROLLER_TO_MASK(cc
);
4010 c
->delegate_controllers
|= mask
;
4014 c
->delegate_controllers
= CGROUP_MASK_DELEGATE
;
4016 c
->delegate
= false;
4017 c
->delegate_controllers
= 0;
4023 int config_parse_delegate_subgroup(
4025 const char *filename
,
4027 const char *section
,
4028 unsigned section_line
,
4035 CGroupContext
*c
= ASSERT_PTR(data
);
4038 t
= unit_name_to_type(unit
);
4041 if (!unit_vtable
[t
]->can_delegate
) {
4042 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "DelegateSubgroup= setting not supported for this unit type, ignoring.");
4046 if (isempty(rvalue
)) {
4047 c
->delegate_subgroup
= mfree(c
->delegate_subgroup
);
4051 if (cg_needs_escape(rvalue
)) { /* Insist that specified names don't need escaping */
4052 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid control group name, ignoring: %s", rvalue
);
4056 return free_and_strdup_warn(&c
->delegate_subgroup
, rvalue
);
4059 int config_parse_managed_oom_mode(
4061 const char *filename
,
4063 const char *section
,
4064 unsigned section_line
,
4071 ManagedOOMMode
*mode
= data
, m
;
4074 t
= unit_name_to_type(unit
);
4075 assert(t
!= _UNIT_TYPE_INVALID
);
4077 if (!unit_vtable
[t
]->can_set_managed_oom
)
4078 return log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "%s= is not supported for this unit type, ignoring.", lvalue
);
4080 if (isempty(rvalue
)) {
4081 *mode
= MANAGED_OOM_AUTO
;
4085 m
= managed_oom_mode_from_string(rvalue
);
4087 log_syntax(unit
, LOG_WARNING
, filename
, line
, m
, "Invalid syntax, ignoring: %s", rvalue
);
4095 int config_parse_managed_oom_mem_pressure_limit(
4097 const char *filename
,
4099 const char *section
,
4100 unsigned section_line
,
4107 uint32_t *limit
= data
;
4111 t
= unit_name_to_type(unit
);
4112 assert(t
!= _UNIT_TYPE_INVALID
);
4114 if (!unit_vtable
[t
]->can_set_managed_oom
)
4115 return log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "%s= is not supported for this unit type, ignoring.", lvalue
);
4117 if (isempty(rvalue
)) {
4122 r
= parse_permyriad(rvalue
);
4124 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse memory pressure limit value, ignoring: %s", rvalue
);
4128 /* Normalize to 2^32-1 == 100% */
4129 *limit
= UINT32_SCALE_FROM_PERMYRIAD(r
);
4133 int config_parse_device_allow(
4135 const char *filename
,
4137 const char *section
,
4138 unsigned section_line
,
4145 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4146 CGroupDevicePermissions permissions
;
4147 CGroupContext
*c
= data
;
4148 const char *p
= rvalue
;
4151 if (isempty(rvalue
)) {
4152 while (c
->device_allow
)
4153 cgroup_context_free_device_allow(c
, c
->device_allow
);
4158 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4162 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4163 "Failed to extract device path and rights from '%s', ignoring.", rvalue
);
4167 r
= unit_path_printf(userdata
, path
, &resolved
);
4169 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4170 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4174 if (!STARTSWITH_SET(resolved
, "block-", "char-")) {
4176 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4180 if (!valid_device_node_path(resolved
)) {
4181 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid device node path '%s', ignoring.", resolved
);
4186 permissions
= isempty(p
) ? 0 : cgroup_device_permissions_from_string(p
);
4187 if (permissions
< 0) {
4188 log_syntax(unit
, LOG_WARNING
, filename
, line
, permissions
, "Invalid device rights '%s', ignoring.", p
);
4192 return cgroup_context_add_device_allow(c
, resolved
, permissions
);
4195 int config_parse_io_device_weight(
4197 const char *filename
,
4199 const char *section
,
4200 unsigned section_line
,
4207 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4208 CGroupIODeviceWeight
*w
;
4209 CGroupContext
*c
= data
;
4210 const char *p
= ASSERT_PTR(rvalue
);
4217 if (isempty(rvalue
)) {
4218 while (c
->io_device_weights
)
4219 cgroup_context_free_io_device_weight(c
, c
->io_device_weights
);
4224 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4228 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4229 "Failed to extract device path and weight from '%s', ignoring.", rvalue
);
4232 if (r
== 0 || isempty(p
)) {
4233 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4234 "Invalid device path or weight specified in '%s', ignoring.", rvalue
);
4238 r
= unit_path_printf(userdata
, path
, &resolved
);
4240 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4241 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4245 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4249 r
= cg_weight_parse(p
, &u
);
4251 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "IO weight '%s' invalid, ignoring: %m", p
);
4255 assert(u
!= CGROUP_WEIGHT_INVALID
);
4257 w
= new0(CGroupIODeviceWeight
, 1);
4261 w
->path
= TAKE_PTR(resolved
);
4264 LIST_PREPEND(device_weights
, c
->io_device_weights
, w
);
4268 int config_parse_io_device_latency(
4270 const char *filename
,
4272 const char *section
,
4273 unsigned section_line
,
4280 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4281 CGroupIODeviceLatency
*l
;
4282 CGroupContext
*c
= data
;
4283 const char *p
= ASSERT_PTR(rvalue
);
4290 if (isempty(rvalue
)) {
4291 while (c
->io_device_latencies
)
4292 cgroup_context_free_io_device_latency(c
, c
->io_device_latencies
);
4297 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4301 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4302 "Failed to extract device path and latency from '%s', ignoring.", rvalue
);
4305 if (r
== 0 || isempty(p
)) {
4306 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4307 "Invalid device path or latency specified in '%s', ignoring.", rvalue
);
4311 r
= unit_path_printf(userdata
, path
, &resolved
);
4313 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4314 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4318 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4322 r
= parse_sec(p
, &usec
);
4324 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse timer value, ignoring: %s", p
);
4328 l
= new0(CGroupIODeviceLatency
, 1);
4332 l
->path
= TAKE_PTR(resolved
);
4333 l
->target_usec
= usec
;
4335 LIST_PREPEND(device_latencies
, c
->io_device_latencies
, l
);
4339 int config_parse_io_limit(
4341 const char *filename
,
4343 const char *section
,
4344 unsigned section_line
,
4351 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4352 CGroupIODeviceLimit
*l
= NULL
;
4353 CGroupContext
*c
= data
;
4354 CGroupIOLimitType type
;
4355 const char *p
= ASSERT_PTR(rvalue
);
4362 type
= cgroup_io_limit_type_from_string(lvalue
);
4365 if (isempty(rvalue
)) {
4366 LIST_FOREACH(device_limits
, t
, c
->io_device_limits
)
4367 t
->limits
[type
] = cgroup_io_limit_defaults
[type
];
4371 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4375 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4376 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
4379 if (r
== 0 || isempty(p
)) {
4380 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4381 "Invalid device node or bandwidth specified in '%s', ignoring.", rvalue
);
4385 r
= unit_path_printf(userdata
, path
, &resolved
);
4387 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4388 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4392 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4396 if (streq("infinity", p
))
4397 num
= CGROUP_LIMIT_MAX
;
4399 r
= parse_size(p
, 1000, &num
);
4400 if (r
< 0 || num
<= 0) {
4401 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid IO limit '%s', ignoring.", p
);
4406 LIST_FOREACH(device_limits
, t
, c
->io_device_limits
)
4407 if (path_equal(resolved
, t
->path
)) {
4413 l
= new0(CGroupIODeviceLimit
, 1);
4417 l
->path
= TAKE_PTR(resolved
);
4418 for (CGroupIOLimitType i
= 0; i
< _CGROUP_IO_LIMIT_TYPE_MAX
; i
++)
4419 l
->limits
[i
] = cgroup_io_limit_defaults
[i
];
4421 LIST_PREPEND(device_limits
, c
->io_device_limits
, l
);
4424 l
->limits
[type
] = num
;
4429 int config_parse_blockio_device_weight(
4431 const char *filename
,
4433 const char *section
,
4434 unsigned section_line
,
4441 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4442 CGroupBlockIODeviceWeight
*w
;
4443 CGroupContext
*c
= data
;
4444 const char *p
= ASSERT_PTR(rvalue
);
4451 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4452 "Unit uses %s=; please use IO*= settings instead. Support for %s= will be removed soon.",
4455 if (isempty(rvalue
)) {
4456 while (c
->blockio_device_weights
)
4457 cgroup_context_free_blockio_device_weight(c
, c
->blockio_device_weights
);
4462 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4466 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4467 "Failed to extract device node and weight from '%s', ignoring.", rvalue
);
4470 if (r
== 0 || isempty(p
)) {
4471 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4472 "Invalid device node or weight specified in '%s', ignoring.", rvalue
);
4476 r
= unit_path_printf(userdata
, path
, &resolved
);
4478 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4479 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4483 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4487 r
= cg_blkio_weight_parse(p
, &u
);
4489 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid block IO weight '%s', ignoring: %m", p
);
4493 assert(u
!= CGROUP_BLKIO_WEIGHT_INVALID
);
4495 w
= new0(CGroupBlockIODeviceWeight
, 1);
4499 w
->path
= TAKE_PTR(resolved
);
4502 LIST_PREPEND(device_weights
, c
->blockio_device_weights
, w
);
4506 int config_parse_blockio_bandwidth(
4508 const char *filename
,
4510 const char *section
,
4511 unsigned section_line
,
4518 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4519 CGroupBlockIODeviceBandwidth
*b
= NULL
;
4520 CGroupContext
*c
= data
;
4521 const char *p
= ASSERT_PTR(rvalue
);
4529 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4530 "Unit uses %s=; please use IO*= settings instead. Support for %s= will be removed soon.",
4533 read
= streq("BlockIOReadBandwidth", lvalue
);
4535 if (isempty(rvalue
)) {
4536 LIST_FOREACH(device_bandwidths
, t
, c
->blockio_device_bandwidths
) {
4537 t
->rbps
= CGROUP_LIMIT_MAX
;
4538 t
->wbps
= CGROUP_LIMIT_MAX
;
4543 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4547 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4548 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
4551 if (r
== 0 || isempty(p
)) {
4552 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4553 "Invalid device node or bandwidth specified in '%s', ignoring.", rvalue
);
4557 r
= unit_path_printf(userdata
, path
, &resolved
);
4559 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4560 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4564 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4568 r
= parse_size(p
, 1000, &bytes
);
4569 if (r
< 0 || bytes
<= 0) {
4570 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid Block IO Bandwidth '%s', ignoring.", p
);
4574 LIST_FOREACH(device_bandwidths
, t
, c
->blockio_device_bandwidths
)
4575 if (path_equal(resolved
, t
->path
)) {
4581 b
= new0(CGroupBlockIODeviceBandwidth
, 1);
4585 b
->path
= TAKE_PTR(resolved
);
4586 b
->rbps
= CGROUP_LIMIT_MAX
;
4587 b
->wbps
= CGROUP_LIMIT_MAX
;
4589 LIST_PREPEND(device_bandwidths
, c
->blockio_device_bandwidths
, b
);
4600 int config_parse_job_mode_isolate(
4602 const char *filename
,
4604 const char *section
,
4605 unsigned section_line
,
4619 r
= parse_boolean(rvalue
);
4621 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse boolean, ignoring: %s", rvalue
);
4625 log_notice("%s is deprecated. Please use OnFailureJobMode= instead", lvalue
);
4627 *m
= r
? JOB_ISOLATE
: JOB_REPLACE
;
4631 int config_parse_exec_directories(
4633 const char *filename
,
4635 const char *section
,
4636 unsigned section_line
,
4643 ExecDirectory
*ed
= ASSERT_PTR(data
);
4644 const Unit
*u
= userdata
;
4651 if (isempty(rvalue
)) {
4652 /* Empty assignment resets the list */
4653 exec_directory_done(ed
);
4657 for (const char *p
= rvalue
;;) {
4658 _cleanup_free_
char *tuple
= NULL
;
4660 r
= extract_first_word(&p
, &tuple
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_RETAIN_ESCAPE
);
4664 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4665 "Invalid syntax %s=%s, ignoring: %m", lvalue
, rvalue
);
4671 _cleanup_free_
char *src
= NULL
, *dest
= NULL
;
4672 const char *q
= tuple
;
4673 r
= extract_many_words(&q
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
, &src
, &dest
);
4677 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4678 "Invalid syntax in %s=, ignoring: %s", lvalue
, tuple
);
4682 _cleanup_free_
char *sresolved
= NULL
;
4683 r
= unit_path_printf(u
, src
, &sresolved
);
4685 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4686 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", src
);
4690 r
= path_simplify_and_warn(sresolved
, PATH_CHECK_RELATIVE
, unit
, filename
, line
, lvalue
);
4694 if (path_startswith(sresolved
, "private")) {
4695 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4696 "%s= path can't be 'private', ignoring assignment: %s", lvalue
, tuple
);
4700 /* For State and Runtime directories we support an optional destination parameter, which
4701 * will be used to create a symlink to the source. */
4702 _cleanup_free_
char *dresolved
= NULL
;
4703 if (!isempty(dest
)) {
4704 if (streq(lvalue
, "ConfigurationDirectory")) {
4705 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4706 "Destination parameter is not supported for ConfigurationDirectory, ignoring: %s", tuple
);
4710 r
= unit_path_printf(u
, dest
, &dresolved
);
4712 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4713 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", dest
);
4717 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_RELATIVE
, unit
, filename
, line
, lvalue
);
4722 r
= exec_directory_add(ed
, sresolved
, dresolved
);
4728 int config_parse_set_credential(
4730 const char *filename
,
4732 const char *section
,
4733 unsigned section_line
,
4740 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
4741 _cleanup_free_
void *d
= NULL
;
4742 ExecContext
*context
= ASSERT_PTR(data
);
4743 ExecSetCredential
*old
;
4745 bool encrypted
= ltype
;
4746 const char *p
= ASSERT_PTR(rvalue
);
4753 if (isempty(rvalue
)) {
4754 /* Empty assignment resets the list */
4755 context
->set_credentials
= hashmap_free(context
->set_credentials
);
4759 r
= extract_first_word(&p
, &word
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4763 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract credential name, ignoring: %s", rvalue
);
4766 if (r
== 0 || isempty(p
)) {
4767 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid syntax, ignoring: %s", rvalue
);
4771 r
= unit_cred_printf(u
, word
, &k
);
4773 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
4776 if (!credential_name_valid(k
)) {
4777 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Credential name \"%s\" not valid, ignoring.", k
);
4782 r
= unbase64mem_full(p
, SIZE_MAX
, true, &d
, &size
);
4784 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Encrypted credential data not valid Base64 data, ignoring.");
4791 /* We support escape codes here, so that users can insert trailing \n if they like */
4792 l
= cunescape(p
, UNESCAPE_ACCEPT_NUL
, &unescaped
);
4794 log_syntax(unit
, LOG_WARNING
, filename
, line
, l
, "Can't unescape \"%s\", ignoring: %m", p
);
4802 old
= hashmap_get(context
->set_credentials
, k
);
4804 free_and_replace(old
->data
, d
);
4806 old
->encrypted
= encrypted
;
4808 _cleanup_(exec_set_credential_freep
) ExecSetCredential
*sc
= NULL
;
4810 sc
= new(ExecSetCredential
, 1);
4814 *sc
= (ExecSetCredential
) {
4816 .data
= TAKE_PTR(d
),
4818 .encrypted
= encrypted
,
4821 r
= hashmap_ensure_put(&context
->set_credentials
, &exec_set_credential_hash_ops
, sc
->id
, sc
);
4825 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4826 "Duplicated credential value '%s', ignoring assignment: %s", sc
->id
, rvalue
);
4836 int hashmap_put_credential(Hashmap
**h
, const char *id
, const char *path
, bool encrypted
) {
4837 ExecLoadCredential
*old
;
4844 old
= hashmap_get(*h
, id
);
4846 r
= free_and_strdup(&old
->path
, path
);
4850 old
->encrypted
= encrypted
;
4852 _cleanup_(exec_load_credential_freep
) ExecLoadCredential
*lc
= NULL
;
4854 lc
= new(ExecLoadCredential
, 1);
4858 *lc
= (ExecLoadCredential
) {
4860 .path
= strdup(path
),
4861 .encrypted
= encrypted
,
4863 if (!lc
->id
|| !lc
->path
)
4866 r
= hashmap_ensure_put(h
, &exec_load_credential_hash_ops
, lc
->id
, lc
);
4876 int config_parse_load_credential(
4878 const char *filename
,
4880 const char *section
,
4881 unsigned section_line
,
4888 _cleanup_free_
char *word
= NULL
, *k
= NULL
, *q
= NULL
;
4889 ExecContext
*context
= ASSERT_PTR(data
);
4890 bool encrypted
= ltype
;
4899 if (isempty(rvalue
)) {
4900 /* Empty assignment resets the list */
4901 context
->load_credentials
= hashmap_free(context
->load_credentials
);
4906 r
= extract_first_word(&p
, &word
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4910 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
4914 r
= unit_cred_printf(u
, word
, &k
);
4916 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
4919 if (!credential_name_valid(k
)) {
4920 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Credential name \"%s\" not valid, ignoring.", k
);
4925 /* If only one field is specified take it as shortcut for inheriting a credential named
4926 * the same way from our parent */
4931 r
= unit_path_printf(u
, p
, &q
);
4933 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", p
);
4936 if (path_is_absolute(q
) ? !path_is_normalized(q
) : !credential_name_valid(q
)) {
4937 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Credential source \"%s\" not valid, ignoring.", q
);
4942 r
= hashmap_put_credential(&context
->load_credentials
, k
, q
, encrypted
);
4944 return log_error_errno(r
, "Failed to store load credential '%s': %m", rvalue
);
4949 int config_parse_import_credential(
4951 const char *filename
,
4953 const char *section
,
4954 unsigned section_line
,
4961 _cleanup_free_
char *s
= NULL
;
4962 Set
** import_credentials
= ASSERT_PTR(data
);
4970 if (isempty(rvalue
)) {
4971 /* Empty assignment resets the list */
4972 *import_credentials
= set_free_free(*import_credentials
);
4976 r
= unit_cred_printf(u
, rvalue
, &s
);
4978 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", s
);
4981 if (!credential_glob_valid(s
)) {
4982 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Credential name or glob \"%s\" not valid, ignoring.", s
);
4986 r
= set_put_strdup(import_credentials
, s
);
4988 return log_error_errno(r
, "Failed to store credential name '%s': %m", rvalue
);
4993 int config_parse_set_status(
4995 const char *filename
,
4997 const char *section
,
4998 unsigned section_line
,
5005 ExitStatusSet
*status_set
= ASSERT_PTR(data
);
5012 /* Empty assignment resets the list */
5013 if (isempty(rvalue
)) {
5014 exit_status_set_free(status_set
);
5018 for (const char *p
= rvalue
;;) {
5019 _cleanup_free_
char *word
= NULL
;
5022 r
= extract_first_word(&p
, &word
, NULL
, 0);
5026 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5027 "Failed to parse %s=%s, ignoring: %m", lvalue
, rvalue
);
5033 /* We need to call exit_status_from_string() first, because we want
5034 * to parse numbers as exit statuses, not signals. */
5036 r
= exit_status_from_string(word
);
5038 assert(r
>= 0 && r
< 256);
5039 bitmap
= &status_set
->status
;
5041 r
= signal_from_string(word
);
5043 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5044 "Failed to parse value, ignoring: %s", word
);
5047 bitmap
= &status_set
->signal
;
5050 r
= bitmap_set(bitmap
, r
);
5052 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5053 "Failed to set signal or status %s, ignoring: %m", word
);
5057 int config_parse_namespace_path_strv(
5059 const char *filename
,
5061 const char *section
,
5062 unsigned section_line
,
5069 const Unit
*u
= userdata
;
5070 char*** sv
= ASSERT_PTR(data
);
5077 if (isempty(rvalue
)) {
5078 /* Empty assignment resets the list */
5079 *sv
= strv_free(*sv
);
5083 for (const char *p
= rvalue
;;) {
5084 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
, *joined
= NULL
;
5086 bool ignore_enoent
= false, shall_prefix
= false;
5088 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
5092 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
5099 if (startswith(w
, "-")) {
5100 ignore_enoent
= true;
5103 if (startswith(w
, "+")) {
5104 shall_prefix
= true;
5108 r
= unit_path_printf(u
, w
, &resolved
);
5110 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", w
);
5114 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5118 joined
= strjoin(ignore_enoent
? "-" : "",
5119 shall_prefix
? "+" : "",
5122 r
= strv_push(sv
, joined
);
5132 int config_parse_temporary_filesystems(
5134 const char *filename
,
5136 const char *section
,
5137 unsigned section_line
,
5144 const Unit
*u
= userdata
;
5145 ExecContext
*c
= ASSERT_PTR(data
);
5152 if (isempty(rvalue
)) {
5153 /* Empty assignment resets the list */
5154 temporary_filesystem_free_many(c
->temporary_filesystems
, c
->n_temporary_filesystems
);
5155 c
->temporary_filesystems
= NULL
;
5156 c
->n_temporary_filesystems
= 0;
5160 for (const char *p
= rvalue
;;) {
5161 _cleanup_free_
char *word
= NULL
, *path
= NULL
, *resolved
= NULL
;
5164 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
5168 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
5175 r
= extract_first_word(&w
, &path
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
5179 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", word
);
5183 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid syntax, ignoring: %s", word
);
5187 r
= unit_path_printf(u
, path
, &resolved
);
5189 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", path
);
5193 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5197 r
= temporary_filesystem_add(&c
->temporary_filesystems
, &c
->n_temporary_filesystems
, resolved
, w
);
5203 int config_parse_bind_paths(
5205 const char *filename
,
5207 const char *section
,
5208 unsigned section_line
,
5215 ExecContext
*c
= ASSERT_PTR(data
);
5216 const Unit
*u
= userdata
;
5223 if (isempty(rvalue
)) {
5224 /* Empty assignment resets the list */
5225 bind_mount_free_many(c
->bind_mounts
, c
->n_bind_mounts
);
5226 c
->bind_mounts
= NULL
;
5227 c
->n_bind_mounts
= 0;
5231 for (const char *p
= rvalue
;;) {
5232 _cleanup_free_
char *source
= NULL
, *destination
= NULL
;
5233 _cleanup_free_
char *sresolved
= NULL
, *dresolved
= NULL
;
5234 char *s
= NULL
, *d
= NULL
;
5235 bool rbind
= true, ignore_enoent
= false;
5237 r
= extract_first_word(&p
, &source
, ":" WHITESPACE
, EXTRACT_UNQUOTE
|EXTRACT_DONT_COALESCE_SEPARATORS
);
5241 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
5247 r
= unit_path_printf(u
, source
, &sresolved
);
5249 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5250 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", source
);
5256 ignore_enoent
= true;
5260 r
= path_simplify_and_warn(s
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5264 /* Optionally, the destination is specified. */
5265 if (p
&& p
[-1] == ':') {
5266 r
= extract_first_word(&p
, &destination
, ":" WHITESPACE
, EXTRACT_UNQUOTE
|EXTRACT_DONT_COALESCE_SEPARATORS
);
5270 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
5274 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Missing argument after ':', ignoring: %s", s
);
5278 r
= unit_path_printf(u
, destination
, &dresolved
);
5280 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5281 "Failed to resolve specifiers in \"%s\", ignoring: %m", destination
);
5285 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5291 /* Optionally, there's also a short option string specified */
5292 if (p
&& p
[-1] == ':') {
5293 _cleanup_free_
char *options
= NULL
;
5295 r
= extract_first_word(&p
, &options
, NULL
, EXTRACT_UNQUOTE
);
5299 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s=, ignoring: %s", lvalue
, rvalue
);
5303 if (isempty(options
) || streq(options
, "rbind"))
5305 else if (streq(options
, "norbind"))
5308 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid option string, ignoring setting: %s", options
);
5315 r
= bind_mount_add(&c
->bind_mounts
, &c
->n_bind_mounts
,
5319 .read_only
= !!strstr(lvalue
, "ReadOnly"),
5321 .ignore_enoent
= ignore_enoent
,
5330 int config_parse_mount_images(
5332 const char *filename
,
5334 const char *section
,
5335 unsigned section_line
,
5342 ExecContext
*c
= ASSERT_PTR(data
);
5343 const Unit
*u
= userdata
;
5350 if (isempty(rvalue
)) {
5351 /* Empty assignment resets the list */
5352 c
->mount_images
= mount_image_free_many(c
->mount_images
, &c
->n_mount_images
);
5356 for (const char *p
= rvalue
;;) {
5357 _cleanup_(mount_options_free_allp
) MountOptions
*options
= NULL
;
5358 _cleanup_free_
char *first
= NULL
, *second
= NULL
, *tuple
= NULL
;
5359 _cleanup_free_
char *sresolved
= NULL
, *dresolved
= NULL
;
5360 const char *q
= NULL
;
5362 bool permissive
= false;
5364 r
= extract_first_word(&p
, &tuple
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_RETAIN_ESCAPE
);
5368 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5369 "Invalid syntax %s=%s, ignoring: %m", lvalue
, rvalue
);
5376 r
= extract_many_words(&q
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
, &first
, &second
);
5380 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5381 "Invalid syntax in %s=, ignoring: %s", lvalue
, tuple
);
5393 r
= unit_path_printf(u
, s
, &sresolved
);
5395 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5396 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", s
);
5400 r
= path_simplify_and_warn(sresolved
, PATH_CHECK_ABSOLUTE
|PATH_CHECK_NON_API_VFS
, unit
, filename
, line
, lvalue
);
5404 if (isempty(second
)) {
5405 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Missing destination in %s, ignoring: %s", lvalue
, rvalue
);
5409 r
= unit_path_printf(u
, second
, &dresolved
);
5411 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5412 "Failed to resolve specifiers in \"%s\", ignoring: %m", second
);
5416 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_ABSOLUTE
|PATH_CHECK_NON_API_VFS
, unit
, filename
, line
, lvalue
);
5421 _cleanup_free_
char *partition
= NULL
, *mount_options
= NULL
, *mount_options_resolved
= NULL
;
5422 MountOptions
*o
= NULL
;
5423 PartitionDesignator partition_designator
;
5425 r
= extract_many_words(&q
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
, &partition
, &mount_options
);
5429 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", q
);
5434 /* Single set of options, applying to the root partition/single filesystem */
5436 r
= unit_full_printf(u
, partition
, &mount_options_resolved
);
5438 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", first
);
5442 o
= new(MountOptions
, 1);
5445 *o
= (MountOptions
) {
5446 .partition_designator
= PARTITION_ROOT
,
5447 .options
= TAKE_PTR(mount_options_resolved
),
5449 LIST_APPEND(mount_options
, options
, o
);
5454 partition_designator
= partition_designator_from_string(partition
);
5455 if (partition_designator
< 0) {
5456 log_syntax(unit
, LOG_WARNING
, filename
, line
, partition_designator
,
5457 "Invalid partition name %s, ignoring", partition
);
5460 r
= unit_full_printf(u
, mount_options
, &mount_options_resolved
);
5462 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", mount_options
);
5466 o
= new(MountOptions
, 1);
5469 *o
= (MountOptions
) {
5470 .partition_designator
= partition_designator
,
5471 .options
= TAKE_PTR(mount_options_resolved
),
5473 LIST_APPEND(mount_options
, options
, o
);
5476 r
= mount_image_add(&c
->mount_images
, &c
->n_mount_images
,
5478 .source
= sresolved
,
5479 .destination
= dresolved
,
5480 .mount_options
= options
,
5481 .ignore_enoent
= permissive
,
5482 .type
= MOUNT_IMAGE_DISCRETE
,
5489 int config_parse_extension_images(
5491 const char *filename
,
5493 const char *section
,
5494 unsigned section_line
,
5501 ExecContext
*c
= ASSERT_PTR(data
);
5502 const Unit
*u
= userdata
;
5509 if (isempty(rvalue
)) {
5510 /* Empty assignment resets the list */
5511 c
->extension_images
= mount_image_free_many(c
->extension_images
, &c
->n_extension_images
);
5515 for (const char *p
= rvalue
;;) {
5516 _cleanup_free_
char *source
= NULL
, *tuple
= NULL
, *sresolved
= NULL
;
5517 _cleanup_(mount_options_free_allp
) MountOptions
*options
= NULL
;
5518 bool permissive
= false;
5519 const char *q
= NULL
;
5522 r
= extract_first_word(&p
, &tuple
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_RETAIN_ESCAPE
);
5526 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5527 "Invalid syntax %s=%s, ignoring: %m", lvalue
, rvalue
);
5534 r
= extract_first_word(&q
, &source
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
);
5538 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5539 "Invalid syntax in %s=, ignoring: %s", lvalue
, tuple
);
5551 r
= unit_path_printf(u
, s
, &sresolved
);
5553 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5554 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", s
);
5558 r
= path_simplify_and_warn(sresolved
, PATH_CHECK_ABSOLUTE
|PATH_CHECK_NON_API_VFS
, unit
, filename
, line
, lvalue
);
5563 _cleanup_free_
char *partition
= NULL
, *mount_options
= NULL
, *mount_options_resolved
= NULL
;
5564 MountOptions
*o
= NULL
;
5565 PartitionDesignator partition_designator
;
5567 r
= extract_many_words(&q
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
, &partition
, &mount_options
);
5571 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", q
);
5576 /* Single set of options, applying to the root partition/single filesystem */
5578 r
= unit_full_printf(u
, partition
, &mount_options_resolved
);
5580 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", partition
);
5584 o
= new(MountOptions
, 1);
5587 *o
= (MountOptions
) {
5588 .partition_designator
= PARTITION_ROOT
,
5589 .options
= TAKE_PTR(mount_options_resolved
),
5591 LIST_APPEND(mount_options
, options
, o
);
5596 partition_designator
= partition_designator_from_string(partition
);
5597 if (partition_designator
< 0) {
5598 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid partition name %s, ignoring", partition
);
5601 r
= unit_full_printf(u
, mount_options
, &mount_options_resolved
);
5603 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", mount_options
);
5607 o
= new(MountOptions
, 1);
5610 *o
= (MountOptions
) {
5611 .partition_designator
= partition_designator
,
5612 .options
= TAKE_PTR(mount_options_resolved
),
5614 LIST_APPEND(mount_options
, options
, o
);
5617 r
= mount_image_add(&c
->extension_images
, &c
->n_extension_images
,
5619 .source
= sresolved
,
5620 .mount_options
= options
,
5621 .ignore_enoent
= permissive
,
5622 .type
= MOUNT_IMAGE_EXTENSION
,
5629 int config_parse_job_timeout_sec(
5631 const char *filename
,
5633 const char *section
,
5634 unsigned section_line
,
5641 Unit
*u
= ASSERT_PTR(data
);
5649 r
= parse_sec_fix_0(rvalue
, &usec
);
5651 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse JobTimeoutSec= parameter, ignoring: %s", rvalue
);
5655 /* If the user explicitly changed JobTimeoutSec= also change JobRunningTimeoutSec=, for compatibility with old
5656 * versions. If JobRunningTimeoutSec= was explicitly set, avoid this however as whatever the user picked should
5659 if (!u
->job_running_timeout_set
)
5660 u
->job_running_timeout
= usec
;
5662 u
->job_timeout
= usec
;
5667 int config_parse_job_running_timeout_sec(
5669 const char *filename
,
5671 const char *section
,
5672 unsigned section_line
,
5679 Unit
*u
= ASSERT_PTR(data
);
5687 r
= parse_sec_fix_0(rvalue
, &usec
);
5689 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse JobRunningTimeoutSec= parameter, ignoring: %s", rvalue
);
5693 u
->job_running_timeout
= usec
;
5694 u
->job_running_timeout_set
= true;
5699 int config_parse_emergency_action(
5701 const char *filename
,
5703 const char *section
,
5704 unsigned section_line
,
5711 EmergencyAction
*x
= ASSERT_PTR(data
);
5712 RuntimeScope runtime_scope
;
5719 /* If we have a unit determine the scope based on it */
5721 runtime_scope
= ((Unit
*) ASSERT_PTR(userdata
))->manager
->runtime_scope
;
5723 runtime_scope
= ltype
; /* otherwise, assume the scope is passed in via ltype */
5725 r
= parse_emergency_action(rvalue
, runtime_scope
, x
);
5727 if (r
== -EOPNOTSUPP
)
5728 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5729 "%s= specified as %s mode action, ignoring: %s",
5730 lvalue
, runtime_scope_to_string(runtime_scope
), rvalue
);
5732 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5733 "Failed to parse %s=, ignoring: %s", lvalue
, rvalue
);
5740 int config_parse_pid_file(
5742 const char *filename
,
5744 const char *section
,
5745 unsigned section_line
,
5752 _cleanup_free_
char *k
= NULL
, *n
= NULL
;
5753 const Unit
*u
= ASSERT_PTR(userdata
);
5761 if (isempty(rvalue
)) {
5762 /* An empty assignment removes already set value. */
5767 r
= unit_path_printf(u
, rvalue
, &k
);
5769 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
5773 /* If this is a relative path make it absolute by prefixing the /run */
5774 n
= path_make_absolute(k
, u
->manager
->prefix
[EXEC_DIRECTORY_RUNTIME
]);
5778 /* Check that the result is a sensible path */
5779 r
= path_simplify_and_warn(n
, PATH_CHECK_ABSOLUTE
|PATH_CHECK_NON_API_VFS
, unit
, filename
, line
, lvalue
);
5783 r
= patch_var_run(unit
, filename
, line
, lvalue
, &n
);
5787 free_and_replace(*s
, n
);
5791 int config_parse_exit_status(
5793 const char *filename
,
5795 const char *section
,
5796 unsigned section_line
,
5803 int *exit_status
= data
, r
;
5809 assert(exit_status
);
5811 if (isempty(rvalue
)) {
5816 r
= safe_atou8(rvalue
, &u
);
5818 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse exit status '%s', ignoring: %m", rvalue
);
5826 int config_parse_disable_controllers(
5828 const char *filename
,
5830 const char *section
,
5831 unsigned section_line
,
5839 CGroupContext
*c
= data
;
5840 CGroupMask disabled_mask
;
5842 /* 1. If empty, make all controllers eligible for use again.
5843 * 2. If non-empty, merge all listed controllers, space separated. */
5845 if (isempty(rvalue
)) {
5846 c
->disable_controllers
= 0;
5850 r
= cg_mask_from_string(rvalue
, &disabled_mask
);
5851 if (r
< 0 || disabled_mask
<= 0) {
5852 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid cgroup string: %s, ignoring", rvalue
);
5856 c
->disable_controllers
|= disabled_mask
;
5861 int config_parse_ip_filter_bpf_progs(
5863 const char *filename
,
5865 const char *section
,
5866 unsigned section_line
,
5873 _cleanup_free_
char *resolved
= NULL
;
5874 const Unit
*u
= userdata
;
5875 char ***paths
= ASSERT_PTR(data
);
5882 if (isempty(rvalue
)) {
5883 *paths
= strv_free(*paths
);
5887 r
= unit_path_printf(u
, rvalue
, &resolved
);
5889 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
5893 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5897 if (strv_contains(*paths
, resolved
))
5900 r
= strv_extend(paths
, resolved
);
5904 r
= bpf_firewall_supported();
5907 if (r
!= BPF_FIREWALL_SUPPORTED_WITH_MULTI
) {
5908 static bool warned
= false;
5910 log_full(warned
? LOG_DEBUG
: LOG_WARNING
,
5911 "File %s:%u configures an IP firewall with BPF programs (%s=%s), but the local system does not support BPF/cgroup based firewalling with multiple filters.\n"
5912 "Starting this unit will fail! (This warning is only shown for the first loaded unit using IP firewalling.)", filename
, line
, lvalue
, rvalue
);
5920 int config_parse_bpf_foreign_program(
5922 const char *filename
,
5924 const char *section
,
5925 unsigned section_line
,
5931 _cleanup_free_
char *resolved
= NULL
, *word
= NULL
;
5932 CGroupContext
*c
= data
;
5933 const char *p
= ASSERT_PTR(rvalue
);
5940 if (isempty(rvalue
)) {
5941 while (c
->bpf_foreign_programs
)
5942 cgroup_context_remove_bpf_foreign_program(c
, c
->bpf_foreign_programs
);
5947 r
= extract_first_word(&p
, &word
, ":", 0);
5951 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse foreign BPF program, ignoring: %s", rvalue
);
5954 if (r
== 0 || isempty(p
)) {
5955 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid syntax in %s=, ignoring: %s", lvalue
, rvalue
);
5959 attach_type
= bpf_cgroup_attach_type_from_string(word
);
5960 if (attach_type
< 0) {
5961 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Unknown BPF attach type=%s, ignoring: %s", word
, rvalue
);
5965 r
= unit_path_printf(u
, p
, &resolved
);
5967 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %s", p
, rvalue
);
5971 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5975 r
= cgroup_context_add_bpf_foreign_program(c
, attach_type
, resolved
);
5977 return log_error_errno(r
, "Failed to add foreign BPF program to cgroup context: %m");
5982 int config_parse_cgroup_socket_bind(
5984 const char *filename
,
5986 const char *section
,
5987 unsigned section_line
,
5993 _cleanup_free_ CGroupSocketBindItem
*item
= NULL
;
5994 CGroupSocketBindItem
**head
= data
;
5995 uint16_t nr_ports
, port_min
;
5996 int af
, ip_protocol
, r
;
5998 if (isempty(rvalue
)) {
5999 cgroup_context_remove_socket_bind(head
);
6003 r
= parse_socket_bind_item(rvalue
, &af
, &ip_protocol
, &nr_ports
, &port_min
);
6007 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
6008 "Unable to parse %s= assignment, ignoring: %s", lvalue
, rvalue
);
6012 item
= new(CGroupSocketBindItem
, 1);
6015 *item
= (CGroupSocketBindItem
) {
6016 .address_family
= af
,
6017 .ip_protocol
= ip_protocol
,
6018 .nr_ports
= nr_ports
,
6019 .port_min
= port_min
,
6022 LIST_PREPEND(socket_bind_items
, *head
, TAKE_PTR(item
));
6027 int config_parse_restrict_network_interfaces(
6029 const char *filename
,
6031 const char *section
,
6032 unsigned section_line
,
6038 CGroupContext
*c
= ASSERT_PTR(data
);
6039 bool is_allow_rule
= true;
6046 if (isempty(rvalue
)) {
6047 /* Empty assignment resets the list */
6048 c
->restrict_network_interfaces
= set_free_free(c
->restrict_network_interfaces
);
6052 if (rvalue
[0] == '~') {
6053 is_allow_rule
= false;
6057 if (set_isempty(c
->restrict_network_interfaces
))
6058 /* Only initialize this when creating the set */
6059 c
->restrict_network_interfaces_is_allow_list
= is_allow_rule
;
6061 for (const char *p
= rvalue
;;) {
6062 _cleanup_free_
char *word
= NULL
;
6064 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
6070 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
6071 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
6075 if (!ifname_valid_full(word
, IFNAME_VALID_ALTERNATIVE
)) {
6076 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid interface name, ignoring: %s", word
);
6080 if (c
->restrict_network_interfaces_is_allow_list
!= is_allow_rule
)
6081 free(set_remove(c
->restrict_network_interfaces
, word
));
6083 r
= set_put_strdup(&c
->restrict_network_interfaces
, word
);
6092 int config_parse_mount_node(
6094 const char *filename
,
6096 const char *section
,
6097 unsigned section_line
,
6104 const Unit
*u
= ASSERT_PTR(userdata
);
6105 _cleanup_free_
char *resolved
= NULL
, *path
= NULL
;
6112 r
= unit_full_printf(u
, rvalue
, &resolved
);
6114 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
6118 path
= fstab_node_to_udev_node(resolved
);
6122 /* The source passed is not necessarily something we understand, and we pass it as-is to mount/swapon,
6123 * so path_is_valid is not used. But let's check for basic sanity, i.e. if the source is longer than
6124 * PATH_MAX, you're likely doing something wrong. */
6125 if (strlen(path
) >= PATH_MAX
) {
6126 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Resolved mount path '%s' too long, ignoring.", path
);
6130 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, path
, data
, userdata
);
6133 static int merge_by_names(Unit
*u
, Set
*names
, const char *id
) {
6139 /* Let's try to add in all names that are aliases of this unit */
6140 while ((k
= set_steal_first(names
))) {
6141 _cleanup_free_ _unused_
char *free_k
= k
;
6143 /* First try to merge in the other name into our unit */
6144 r
= unit_merge_by_name(u
, k
);
6148 /* Hmm, we couldn't merge the other unit into ours? Then let's try it the other way
6151 other
= manager_get_unit(u
->manager
, k
);
6153 return r
; /* return previous failure */
6155 r
= unit_merge(other
, u
);
6159 return merge_by_names(other
, names
, NULL
);
6162 if (streq_ptr(id
, k
))
6163 unit_choose_id(u
, id
);
6169 int unit_load_fragment(Unit
*u
) {
6170 const char *fragment
;
6171 _cleanup_set_free_free_ Set
*names
= NULL
;
6175 assert(u
->load_state
== UNIT_STUB
);
6179 u
->access_selinux_context
= mfree(u
->access_selinux_context
);
6180 u
->load_state
= UNIT_LOADED
;
6184 /* Possibly rebuild the fragment map to catch new units */
6185 r
= unit_file_build_name_map(&u
->manager
->lookup_paths
,
6186 &u
->manager
->unit_cache_timestamp_hash
,
6187 &u
->manager
->unit_id_map
,
6188 &u
->manager
->unit_name_map
,
6189 &u
->manager
->unit_path_cache
);
6191 return log_error_errno(r
, "Failed to rebuild name map: %m");
6193 r
= unit_file_find_fragment(u
->manager
->unit_id_map
,
6194 u
->manager
->unit_name_map
,
6198 if (r
< 0 && r
!= -ENOENT
)
6202 /* Open the file, check if this is a mask, otherwise read. */
6203 _cleanup_fclose_
FILE *f
= NULL
;
6206 /* Try to open the file name. A symlink is OK, for example for linked files or masks. We
6207 * expect that all symlinks within the lookup paths have been already resolved, but we don't
6208 * verify this here. */
6209 f
= fopen(fragment
, "re");
6211 return log_unit_notice_errno(u
, errno
, "Failed to open %s: %m", fragment
);
6213 if (fstat(fileno(f
), &st
) < 0)
6216 r
= free_and_strdup(&u
->fragment_path
, fragment
);
6220 if (null_or_empty(&st
)) {
6221 /* Unit file is masked */
6223 u
->load_state
= u
->perpetual
? UNIT_LOADED
: UNIT_MASKED
; /* don't allow perpetual units to ever be masked */
6224 u
->fragment_mtime
= 0;
6225 u
->access_selinux_context
= mfree(u
->access_selinux_context
);
6228 if (mac_selinux_use()) {
6229 _cleanup_freecon_
char *selcon
= NULL
;
6231 /* Cache the SELinux context of the unit file here. We'll make use of when checking access permissions to loaded units */
6232 r
= fgetfilecon_raw(fileno(f
), &selcon
);
6234 log_unit_warning_errno(u
, r
, "Failed to read SELinux context of '%s', ignoring: %m", fragment
);
6236 r
= free_and_strdup(&u
->access_selinux_context
, selcon
);
6241 u
->access_selinux_context
= mfree(u
->access_selinux_context
);
6243 u
->load_state
= UNIT_LOADED
;
6244 u
->fragment_mtime
= timespec_load(&st
.st_mtim
);
6246 /* Now, parse the file contents */
6247 r
= config_parse(u
->id
, fragment
, f
,
6248 UNIT_VTABLE(u
)->sections
,
6249 config_item_perf_lookup
, load_fragment_gperf_lookup
,
6254 log_unit_notice_errno(u
, r
, "Unit configuration has fatal error, unit will not be started.");
6260 /* Call merge_by_names with the name derived from the fragment path as the preferred name.
6262 * We do the merge dance here because for some unit types, the unit might have aliases which are not
6263 * declared in the file system. In particular, this is true (and frequent) for device and swap units.
6265 const char *id
= u
->id
;
6266 _cleanup_free_
char *filename
= NULL
, *free_id
= NULL
;
6269 r
= path_extract_filename(fragment
, &filename
);
6271 return log_debug_errno(r
, "Failed to extract filename from fragment '%s': %m", fragment
);
6274 if (unit_name_is_valid(id
, UNIT_NAME_TEMPLATE
)) {
6275 assert(u
->instance
); /* If we're not trying to use a template for non-instanced unit,
6276 * this must be set. */
6278 r
= unit_name_replace_instance(id
, u
->instance
, &free_id
);
6280 return log_debug_errno(r
, "Failed to build id (%s + %s): %m", id
, u
->instance
);
6285 return merge_by_names(u
, names
, id
);
6288 void unit_dump_config_items(FILE *f
) {
6289 static const struct {
6290 const ConfigParserCallback callback
;
6293 { config_parse_warn_compat
, "NOTSUPPORTED" },
6294 { config_parse_int
, "INTEGER" },
6295 { config_parse_unsigned
, "UNSIGNED" },
6296 { config_parse_iec_size
, "SIZE" },
6297 { config_parse_iec_uint64
, "SIZE" },
6298 { config_parse_si_uint64
, "SIZE" },
6299 { config_parse_bool
, "BOOLEAN" },
6300 { config_parse_string
, "STRING" },
6301 { config_parse_path
, "PATH" },
6302 { config_parse_unit_path_printf
, "PATH" },
6303 { config_parse_colon_separated_paths
, "PATH" },
6304 { config_parse_strv
, "STRING [...]" },
6305 { config_parse_exec_nice
, "NICE" },
6306 { config_parse_exec_oom_score_adjust
, "OOMSCOREADJUST" },
6307 { config_parse_exec_io_class
, "IOCLASS" },
6308 { config_parse_exec_io_priority
, "IOPRIORITY" },
6309 { config_parse_exec_cpu_sched_policy
, "CPUSCHEDPOLICY" },
6310 { config_parse_exec_cpu_sched_prio
, "CPUSCHEDPRIO" },
6311 { config_parse_exec_cpu_affinity
, "CPUAFFINITY" },
6312 { config_parse_mode
, "MODE" },
6313 { config_parse_unit_env_file
, "FILE" },
6314 { config_parse_exec_output
, "OUTPUT" },
6315 { config_parse_exec_input
, "INPUT" },
6316 { config_parse_log_facility
, "FACILITY" },
6317 { config_parse_log_level
, "LEVEL" },
6318 { config_parse_exec_secure_bits
, "SECUREBITS" },
6319 { config_parse_capability_set
, "BOUNDINGSET" },
6320 { config_parse_rlimit
, "LIMIT" },
6321 { config_parse_unit_deps
, "UNIT [...]" },
6322 { config_parse_exec
, "PATH [ARGUMENT [...]]" },
6323 { config_parse_service_type
, "SERVICETYPE" },
6324 { config_parse_service_exit_type
, "SERVICEEXITTYPE" },
6325 { config_parse_service_restart
, "SERVICERESTART" },
6326 { config_parse_service_restart_mode
, "SERVICERESTARTMODE" },
6327 { config_parse_service_timeout_failure_mode
, "TIMEOUTMODE" },
6328 { config_parse_kill_mode
, "KILLMODE" },
6329 { config_parse_signal
, "SIGNAL" },
6330 { config_parse_socket_listen
, "SOCKET [...]" },
6331 { config_parse_socket_bind
, "SOCKETBIND" },
6332 { config_parse_socket_bindtodevice
, "NETWORKINTERFACE" },
6333 { config_parse_sec
, "SECONDS" },
6334 { config_parse_nsec
, "NANOSECONDS" },
6335 { config_parse_namespace_path_strv
, "PATH [...]" },
6336 { config_parse_bind_paths
, "PATH[:PATH[:OPTIONS]] [...]" },
6337 { config_parse_unit_mounts_for
, "PATH [...]" },
6338 { config_parse_exec_mount_propagation_flag
,
6340 { config_parse_unit_string_printf
, "STRING" },
6341 { config_parse_trigger_unit
, "UNIT" },
6342 { config_parse_timer
, "TIMER" },
6343 { config_parse_path_spec
, "PATH" },
6344 { config_parse_notify_access
, "ACCESS" },
6345 { config_parse_ip_tos
, "TOS" },
6346 { config_parse_unit_condition_path
, "CONDITION" },
6347 { config_parse_unit_condition_string
, "CONDITION" },
6348 { config_parse_unit_slice
, "SLICE" },
6349 { config_parse_documentation
, "URL" },
6350 { config_parse_service_timeout
, "SECONDS" },
6351 { config_parse_emergency_action
, "ACTION" },
6352 { config_parse_set_status
, "STATUS" },
6353 { config_parse_service_sockets
, "SOCKETS" },
6354 { config_parse_environ
, "ENVIRON" },
6356 { config_parse_syscall_filter
, "SYSCALLS" },
6357 { config_parse_syscall_archs
, "ARCHS" },
6358 { config_parse_syscall_errno
, "ERRNO" },
6359 { config_parse_syscall_log
, "SYSCALLS" },
6360 { config_parse_address_families
, "FAMILIES" },
6361 { config_parse_restrict_namespaces
, "NAMESPACES" },
6363 { config_parse_restrict_filesystems
, "FILESYSTEMS" },
6364 { config_parse_cpu_shares
, "SHARES" },
6365 { config_parse_cg_weight
, "WEIGHT" },
6366 { config_parse_cg_cpu_weight
, "CPUWEIGHT" },
6367 { config_parse_memory_limit
, "LIMIT" },
6368 { config_parse_device_allow
, "DEVICE" },
6369 { config_parse_device_policy
, "POLICY" },
6370 { config_parse_io_limit
, "LIMIT" },
6371 { config_parse_io_device_weight
, "DEVICEWEIGHT" },
6372 { config_parse_io_device_latency
, "DEVICELATENCY" },
6373 { config_parse_blockio_bandwidth
, "BANDWIDTH" },
6374 { config_parse_blockio_weight
, "WEIGHT" },
6375 { config_parse_blockio_device_weight
, "DEVICEWEIGHT" },
6376 { config_parse_long
, "LONG" },
6377 { config_parse_socket_service
, "SERVICE" },
6379 { config_parse_exec_selinux_context
, "LABEL" },
6381 { config_parse_job_mode
, "MODE" },
6382 { config_parse_job_mode_isolate
, "BOOLEAN" },
6383 { config_parse_personality
, "PERSONALITY" },
6384 { config_parse_log_filter_patterns
, "REGEX" },
6385 { config_parse_mount_node
, "NODE" },
6388 const char *prev
= NULL
;
6392 NULSTR_FOREACH(i
, load_fragment_gperf_nulstr
) {
6393 const char *rvalue
= "OTHER", *lvalue
;
6394 const ConfigPerfItem
*p
;
6397 assert_se(p
= load_fragment_gperf_lookup(i
, strlen(i
)));
6399 /* Hide legacy settings */
6400 if (p
->parse
== config_parse_warn_compat
&&
6401 p
->ltype
== DISABLED_LEGACY
)
6404 for (size_t j
= 0; j
< ELEMENTSOF(table
); j
++)
6405 if (p
->parse
== table
[j
].callback
) {
6406 rvalue
= table
[j
].rvalue
;
6410 dot
= strchr(i
, '.');
6411 lvalue
= dot
? dot
+ 1 : i
;
6414 size_t prefix_len
= dot
- i
;
6416 if (!prev
|| !strneq(prev
, i
, prefix_len
+1)) {
6420 fprintf(f
, "[%.*s]\n", (int) prefix_len
, i
);
6424 fprintf(f
, "%s=%s\n", lvalue
, rvalue
);
6429 int config_parse_cpu_affinity2(
6431 const char *filename
,
6433 const char *section
,
6434 unsigned section_line
,
6441 CPUSet
*affinity
= ASSERT_PTR(data
);
6443 (void) parse_cpu_set_extend(rvalue
, affinity
, true, unit
, filename
, line
, lvalue
);
6448 int config_parse_show_status(
6450 const char *filename
,
6452 const char *section
,
6453 unsigned section_line
,
6461 ShowStatus
*b
= ASSERT_PTR(data
);
6467 k
= parse_show_status(rvalue
, b
);
6469 log_syntax(unit
, LOG_WARNING
, filename
, line
, k
, "Failed to parse show status setting, ignoring: %s", rvalue
);
6474 int config_parse_output_restricted(
6476 const char *filename
,
6478 const char *section
,
6479 unsigned section_line
,
6486 ExecOutput t
, *eo
= ASSERT_PTR(data
);
6487 bool obsolete
= false;
6493 if (streq(rvalue
, "syslog")) {
6494 t
= EXEC_OUTPUT_JOURNAL
;
6496 } else if (streq(rvalue
, "syslog+console")) {
6497 t
= EXEC_OUTPUT_JOURNAL_AND_CONSOLE
;
6500 t
= exec_output_from_string(rvalue
);
6502 log_syntax(unit
, LOG_WARNING
, filename
, line
, t
, "Failed to parse output type, ignoring: %s", rvalue
);
6506 if (IN_SET(t
, EXEC_OUTPUT_SOCKET
, EXEC_OUTPUT_NAMED_FD
, EXEC_OUTPUT_FILE
, EXEC_OUTPUT_FILE_APPEND
, EXEC_OUTPUT_FILE_TRUNCATE
)) {
6507 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Standard output types socket, fd:, file:, append:, truncate: are not supported as defaults, ignoring: %s", rvalue
);
6513 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
6514 "Standard output type %s is obsolete, automatically updating to %s. Please update your configuration.",
6515 rvalue
, exec_output_to_string(t
));
6521 int config_parse_crash_chvt(
6523 const char *filename
,
6525 const char *section
,
6526 unsigned section_line
,
6540 r
= parse_crash_chvt(rvalue
, data
);
6542 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse CrashChangeVT= setting, ignoring: %s", rvalue
);
6547 int config_parse_swap_priority(
6549 const char *filename
,
6551 const char *section
,
6552 unsigned section_line
,
6559 Swap
*s
= ASSERT_PTR(userdata
);
6567 if (isempty(rvalue
)) {
6568 s
->parameters_fragment
.priority
= -1;
6569 s
->parameters_fragment
.priority_set
= false;
6573 r
= safe_atoi(rvalue
, &priority
);
6575 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid swap priority '%s', ignoring.", rvalue
);
6579 if (priority
< -1) {
6580 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
);
6584 if (priority
> 32767) {
6585 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Swap priority out of range, ignoring: %s", rvalue
);
6589 s
->parameters_fragment
.priority
= priority
;
6590 s
->parameters_fragment
.priority_set
= true;
6594 int config_parse_watchdog_sec(
6596 const char *filename
,
6598 const char *section
,
6599 unsigned section_line
,
6606 usec_t
*usec
= data
;
6612 /* This is called for {Runtime,Reboot,KExec}WatchdogSec= where "default" maps to
6613 * USEC_INFINITY internally. */
6615 if (streq(rvalue
, "default"))
6616 *usec
= USEC_INFINITY
;
6617 else if (streq(rvalue
, "off"))
6620 return config_parse_sec(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
);
6625 int config_parse_tty_size(
6627 const char *filename
,
6629 const char *section
,
6630 unsigned section_line
,
6637 unsigned *sz
= data
;
6643 if (isempty(rvalue
)) {
6648 return config_parse_unsigned(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
);
6651 int config_parse_log_filter_patterns(
6653 const char *filename
,
6655 const char *section
,
6656 unsigned section_line
,
6663 ExecContext
*c
= ASSERT_PTR(data
);
6664 const char *pattern
= ASSERT_PTR(rvalue
);
6665 bool is_allowlist
= true;
6671 if (isempty(pattern
)) {
6672 /* Empty assignment resets the lists. */
6673 c
->log_filter_allowed_patterns
= set_free_free(c
->log_filter_allowed_patterns
);
6674 c
->log_filter_denied_patterns
= set_free_free(c
->log_filter_denied_patterns
);
6678 if (pattern
[0] == '~') {
6679 is_allowlist
= false;
6681 if (isempty(pattern
))
6682 /* LogFilterPatterns=~ is not considered a valid pattern. */
6683 return log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
6684 "Regex pattern invalid, ignoring: %s=%s", lvalue
, rvalue
);
6687 if (pattern_compile_and_log(pattern
, 0, NULL
) < 0)
6690 r
= set_put_strdup(is_allowlist
? &c
->log_filter_allowed_patterns
: &c
->log_filter_denied_patterns
,
6693 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
6694 "Failed to store log filtering pattern, ignoring: %s=%s", lvalue
, rvalue
);
6701 int config_parse_open_file(
6703 const char *filename
,
6705 const char *section
,
6706 unsigned section_line
,
6713 _cleanup_(open_file_freep
) OpenFile
*of
= NULL
;
6714 OpenFile
**head
= ASSERT_PTR(data
);
6721 if (isempty(rvalue
)) {
6722 open_file_free_many(head
);
6726 r
= open_file_parse(rvalue
, &of
);
6728 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse OpenFile= setting, ignoring: %s", rvalue
);
6732 LIST_APPEND(open_files
, *head
, TAKE_PTR(of
));
6737 int config_parse_cgroup_nft_set(
6739 const char *filename
,
6741 const char *section
,
6742 unsigned section_line
,
6749 CGroupContext
*c
= ASSERT_PTR(data
);
6750 Unit
*u
= ASSERT_PTR(userdata
);
6752 return config_parse_nft_set(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, &c
->nft_set_context
, u
);