1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
3 Copyright © 2012 Holger Hans Peter Freyther
14 #include <sys/resource.h>
16 #include "sd-messages.h"
19 #include "all-units.h"
20 #include "alloc-util.h"
21 #include "bpf-firewall.h"
23 #include "bpf-program.h"
24 #include "bpf-socket-bind.h"
25 #include "bus-error.h"
26 #include "bus-internal.h"
29 #include "capability-util.h"
30 #include "cgroup-setup.h"
31 #include "conf-parser.h"
32 #include "core-varlink.h"
33 #include "cpu-set-util.h"
34 #include "creds-util.h"
36 #include "errno-list.h"
41 #include "hexdecoct.h"
43 #include "ioprio-util.h"
44 #include "ip-protocol-list.h"
45 #include "journal-file.h"
46 #include "limits-util.h"
47 #include "load-fragment.h"
49 #include "missing_ioprio.h"
50 #include "mountpoint-util.h"
51 #include "nulstr-util.h"
52 #include "open-file.h"
53 #include "parse-helpers.h"
54 #include "parse-util.h"
55 #include "path-util.h"
56 #include "pcre2-util.h"
57 #include "percent-util.h"
58 #include "process-util.h"
60 #include "seccomp-util.h"
62 #include "securebits-util.h"
63 #include "selinux-util.h"
64 #include "signal-util.h"
65 #include "socket-netlink.h"
66 #include "specifier.h"
67 #include "stat-util.h"
68 #include "string-util.h"
70 #include "syslog-util.h"
71 #include "time-util.h"
72 #include "unit-name.h"
73 #include "unit-printf.h"
74 #include "user-util.h"
78 static int parse_socket_protocol(const char *s
) {
81 r
= parse_ip_protocol(s
);
84 if (!IN_SET(r
, IPPROTO_UDPLITE
, IPPROTO_SCTP
))
85 return -EPROTONOSUPPORT
;
90 int parse_crash_chvt(const char *value
, int *data
) {
93 if (safe_atoi(value
, data
) >= 0)
96 b
= parse_boolean(value
);
101 *data
= 0; /* switch to where kmsg goes */
103 *data
= -1; /* turn off switching */
108 int parse_confirm_spawn(const char *value
, char **console
) {
112 r
= value
? parse_boolean(value
) : 1;
116 } else if (r
> 0) /* on with default tty */
117 s
= strdup("/dev/console");
118 else if (is_path(value
)) /* on with fully qualified path */
120 else /* on with only a tty file name, not a fully qualified path */
121 s
= path_join("/dev/", value
);
129 DEFINE_CONFIG_PARSE(config_parse_socket_protocol
, parse_socket_protocol
, "Failed to parse socket protocol");
130 DEFINE_CONFIG_PARSE(config_parse_exec_secure_bits
, secure_bits_from_string
, "Failed to parse secure bits");
131 DEFINE_CONFIG_PARSE_ENUM(config_parse_collect_mode
, collect_mode
, CollectMode
, "Failed to parse garbage collection mode");
132 DEFINE_CONFIG_PARSE_ENUM(config_parse_device_policy
, cgroup_device_policy
, CGroupDevicePolicy
, "Failed to parse device policy");
133 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_keyring_mode
, exec_keyring_mode
, ExecKeyringMode
, "Failed to parse keyring mode");
134 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_proc
, protect_proc
, ProtectProc
, "Failed to parse /proc/ protection mode");
135 DEFINE_CONFIG_PARSE_ENUM(config_parse_proc_subset
, proc_subset
, ProcSubset
, "Failed to parse /proc/ subset mode");
136 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_utmp_mode
, exec_utmp_mode
, ExecUtmpMode
, "Failed to parse utmp mode");
137 DEFINE_CONFIG_PARSE_ENUM(config_parse_job_mode
, job_mode
, JobMode
, "Failed to parse job mode");
138 DEFINE_CONFIG_PARSE_ENUM(config_parse_notify_access
, notify_access
, NotifyAccess
, "Failed to parse notify access specifier");
139 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_home
, protect_home
, ProtectHome
, "Failed to parse protect home value");
140 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_system
, protect_system
, ProtectSystem
, "Failed to parse protect system value");
141 DEFINE_CONFIG_PARSE_ENUM(config_parse_runtime_preserve_mode
, exec_preserve_mode
, ExecPreserveMode
, "Failed to parse runtime directory preserve mode");
142 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_type
, service_type
, ServiceType
, "Failed to parse service type");
143 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_exit_type
, service_exit_type
, ServiceExitType
, "Failed to parse service exit type");
144 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart
, service_restart
, ServiceRestart
, "Failed to parse service restart specifier");
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_ptr(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
,
437 char ***sv
= ASSERT_PTR(data
);
438 const Unit
*u
= userdata
;
445 if (isempty(rvalue
)) {
446 /* Empty assignment resets the list */
447 *sv
= strv_free(*sv
);
451 for (const char *p
= rvalue
;;) {
452 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
454 r
= extract_first_word(&p
, &word
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
458 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
464 r
= unit_path_printf(u
, word
, &k
);
466 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
467 "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
471 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
475 r
= strv_consume(sv
, TAKE_PTR(k
));
483 int config_parse_unit_path_strv_printf(
485 const char *filename
,
488 unsigned section_line
,
496 const Unit
*u
= ASSERT_PTR(userdata
);
503 if (isempty(rvalue
)) {
508 for (const char *p
= rvalue
;;) {
509 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
511 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
517 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
518 "Invalid syntax, ignoring: %s", rvalue
);
522 r
= unit_path_printf(u
, word
, &k
);
524 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
525 "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
529 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
533 r
= strv_consume(x
, TAKE_PTR(k
));
539 static int patch_var_run(
541 const char *filename
,
549 e
= path_startswith(*path
, "/var/run/");
553 z
= path_join("/run/", e
);
557 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
558 "%s= references a path below legacy directory /var/run/, updating %s → %s; "
559 "please update the unit file accordingly.", lvalue
, *path
, z
);
561 free_and_replace(*path
, z
);
566 int config_parse_socket_listen(
568 const char *filename
,
571 unsigned section_line
,
578 _cleanup_free_ SocketPort
*p
= NULL
;
590 if (isempty(rvalue
)) {
591 /* An empty assignment removes all ports */
592 socket_free_ports(s
);
596 p
= new0(SocketPort
, 1);
600 if (ltype
!= SOCKET_SOCKET
) {
601 _cleanup_free_
char *k
= NULL
;
603 r
= unit_path_printf(UNIT(s
), rvalue
, &k
);
605 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
609 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
613 if (ltype
== SOCKET_FIFO
) {
614 r
= patch_var_run(unit
, filename
, line
, lvalue
, &k
);
619 free_and_replace(p
->path
, k
);
622 } else if (streq(lvalue
, "ListenNetlink")) {
623 _cleanup_free_
char *k
= NULL
;
625 r
= unit_path_printf(UNIT(s
), rvalue
, &k
);
627 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
631 r
= socket_address_parse_netlink(&p
->address
, k
);
633 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse address value in '%s', ignoring: %m", k
);
637 p
->type
= SOCKET_SOCKET
;
640 _cleanup_free_
char *k
= NULL
;
642 r
= unit_path_printf(UNIT(s
), rvalue
, &k
);
644 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
648 if (k
[0] == '/') { /* Only for AF_UNIX file system sockets… */
649 r
= patch_var_run(unit
, filename
, line
, lvalue
, &k
);
654 r
= socket_address_parse_and_warn(&p
->address
, k
);
656 if (r
!= -EAFNOSUPPORT
)
657 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse address value in '%s', ignoring: %m", k
);
661 if (streq(lvalue
, "ListenStream"))
662 p
->address
.type
= SOCK_STREAM
;
663 else if (streq(lvalue
, "ListenDatagram"))
664 p
->address
.type
= SOCK_DGRAM
;
666 assert(streq(lvalue
, "ListenSequentialPacket"));
667 p
->address
.type
= SOCK_SEQPACKET
;
670 if (socket_address_family(&p
->address
) != AF_UNIX
&& p
->address
.type
== SOCK_SEQPACKET
) {
671 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Address family not supported, ignoring: %s", rvalue
);
675 p
->type
= SOCKET_SOCKET
;
679 p
->auxiliary_fds
= NULL
;
680 p
->n_auxiliary_fds
= 0;
683 tail
= LIST_FIND_TAIL(port
, s
->ports
);
684 LIST_INSERT_AFTER(port
, s
->ports
, tail
, p
);
691 int config_parse_exec_nice(
693 const char *filename
,
696 unsigned section_line
,
703 ExecContext
*c
= ASSERT_PTR(data
);
710 if (isempty(rvalue
)) {
715 r
= parse_nice(rvalue
, &priority
);
718 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Nice priority out of range, ignoring: %s", rvalue
);
720 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse nice priority '%s', ignoring: %m", rvalue
);
730 int config_parse_exec_oom_score_adjust(
732 const char *filename
,
735 unsigned section_line
,
742 ExecContext
*c
= ASSERT_PTR(data
);
749 if (isempty(rvalue
)) {
750 c
->oom_score_adjust_set
= false;
754 r
= parse_oom_score_adjust(rvalue
, &oa
);
757 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "OOM score adjust value out of range, ignoring: %s", rvalue
);
759 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse the OOM score adjust value '%s', ignoring: %m", rvalue
);
763 c
->oom_score_adjust
= oa
;
764 c
->oom_score_adjust_set
= true;
769 int config_parse_exec_coredump_filter(
771 const char *filename
,
774 unsigned section_line
,
781 ExecContext
*c
= ASSERT_PTR(data
);
788 if (isempty(rvalue
)) {
789 c
->coredump_filter
= 0;
790 c
->coredump_filter_set
= false;
795 r
= coredump_filter_mask_from_string(rvalue
, &f
);
797 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
798 "Failed to parse the CoredumpFilter=%s, ignoring: %m", rvalue
);
802 c
->coredump_filter
|= f
;
803 c
->oom_score_adjust_set
= true;
807 int config_parse_kill_mode(
809 const char *filename
,
812 unsigned section_line
,
819 KillMode
*k
= data
, m
;
826 if (isempty(rvalue
)) {
827 *k
= KILL_CONTROL_GROUP
;
831 m
= kill_mode_from_string(rvalue
);
833 log_syntax(unit
, LOG_WARNING
, filename
, line
, m
,
834 "Failed to parse kill mode specification, ignoring: %s", rvalue
);
839 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
840 "Unit uses KillMode=none. "
841 "This is unsafe, as it disables systemd's process lifecycle management for the service. "
842 "Please update the service to use a safer KillMode=, such as 'mixed' or 'control-group'. "
843 "Support for KillMode=none is deprecated and will eventually be removed.");
849 int config_parse_exec(
851 const char *filename
,
854 unsigned section_line
,
861 ExecCommand
**e
= ASSERT_PTR(data
);
862 const Unit
*u
= userdata
;
873 if (isempty(rvalue
)) {
874 /* An empty assignment resets the list */
875 *e
= exec_command_free_list(*e
);
881 _cleanup_free_
char *path
= NULL
, *firstword
= NULL
;
882 ExecCommandFlags flags
= 0;
883 bool ignore
= false, separate_argv0
= false;
884 _cleanup_free_ ExecCommand
*nce
= NULL
;
885 _cleanup_strv_free_
char **n
= NULL
;
891 r
= extract_first_word_and_warn(&p
, &firstword
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
895 /* A lone ";" is a separator. Let's make sure we don't treat it as an executable name. */
896 if (streq(firstword
, ";")) {
903 /* We accept an absolute path as first argument. If it's prefixed with - and the path doesn't
904 * exist, we ignore it instead of erroring out; if it's prefixed with @, we allow overriding of
905 * argv[0]; if it's prefixed with :, we will not do environment variable substitution;
906 * if it's prefixed with +, it will be run with full privileges and no sandboxing; if
907 * it's prefixed with '!' we apply sandboxing, but do not change user/group credentials; if
908 * it's prefixed with '!!', then we apply user/group credentials if the kernel supports ambient
909 * capabilities -- if it doesn't we don't apply the credentials themselves, but do apply most
910 * other sandboxing, with some special exceptions for changing UID.
912 * The idea is that '!!' may be used to write services that can take benefit of systemd's
913 * UID/GID dropping if the kernel supports ambient creds, but provide an automatic fallback to
914 * privilege dropping within the daemon if the kernel does not offer that. */
916 if (*f
== '-' && !(flags
& EXEC_COMMAND_IGNORE_FAILURE
)) {
917 flags
|= EXEC_COMMAND_IGNORE_FAILURE
;
919 } else if (*f
== '@' && !separate_argv0
)
920 separate_argv0
= true;
921 else if (*f
== ':' && !(flags
& EXEC_COMMAND_NO_ENV_EXPAND
))
922 flags
|= EXEC_COMMAND_NO_ENV_EXPAND
;
923 else if (*f
== '+' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
924 flags
|= EXEC_COMMAND_FULLY_PRIVILEGED
;
925 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
926 flags
|= EXEC_COMMAND_NO_SETUID
;
927 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_AMBIENT_MAGIC
))) {
928 flags
&= ~EXEC_COMMAND_NO_SETUID
;
929 flags
|= EXEC_COMMAND_AMBIENT_MAGIC
;
935 r
= unit_path_printf(u
, f
, &path
);
937 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
938 "Failed to resolve unit specifiers in '%s'%s: %m",
939 f
, ignore
? ", ignoring" : "");
940 return ignore
? 0 : -ENOEXEC
;
944 /* First word is either "-" or "@" with no command. */
945 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
946 "Empty path in command line%s: '%s'",
947 ignore
? ", ignoring" : "", rvalue
);
948 return ignore
? 0 : -ENOEXEC
;
950 if (!string_is_safe(path
)) {
951 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
952 "Executable name contains special characters%s: %s",
953 ignore
? ", ignoring" : "", path
);
954 return ignore
? 0 : -ENOEXEC
;
956 if (endswith(path
, "/")) {
957 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
958 "Executable path specifies a directory%s: %s",
959 ignore
? ", ignoring" : "", path
);
960 return ignore
? 0 : -ENOEXEC
;
963 if (!(path_is_absolute(path
) ? path_is_valid(path
) : filename_is_valid(path
))) {
964 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
965 "Neither a valid executable name nor an absolute path%s: %s",
966 ignore
? ", ignoring" : "", path
);
967 return ignore
? 0 : -ENOEXEC
;
970 if (!separate_argv0
) {
973 if (!GREEDY_REALLOC0(n
, nlen
+ 2))
985 while (!isempty(p
)) {
986 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
988 /* Check explicitly for an unquoted semicolon as
989 * command separator token. */
990 if (p
[0] == ';' && (!p
[1] || strchr(WHITESPACE
, p
[1]))) {
992 p
+= strspn(p
, WHITESPACE
);
997 /* Check for \; explicitly, to not confuse it with \\; or "\;" or "\\;" etc.
998 * extract_first_word() would return the same for all of those. */
999 if (p
[0] == '\\' && p
[1] == ';' && (!p
[2] || strchr(WHITESPACE
, p
[2]))) {
1003 p
+= strspn(p
, WHITESPACE
);
1005 if (!GREEDY_REALLOC0(n
, nlen
+ 2))
1016 r
= extract_first_word_and_warn(&p
, &word
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
1020 return ignore
? 0 : -ENOEXEC
;
1022 r
= unit_full_printf(u
, word
, &resolved
);
1024 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
1025 "Failed to resolve unit specifiers in %s%s: %m",
1026 word
, ignore
? ", ignoring" : "");
1027 return ignore
? 0 : -ENOEXEC
;
1030 if (!GREEDY_REALLOC(n
, nlen
+ 2))
1033 n
[nlen
++] = TAKE_PTR(resolved
);
1038 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
1039 "Empty executable name or zeroeth argument%s: %s",
1040 ignore
? ", ignoring" : "", rvalue
);
1041 return ignore
? 0 : -ENOEXEC
;
1044 nce
= new0(ExecCommand
, 1);
1048 nce
->argv
= TAKE_PTR(n
);
1049 nce
->path
= TAKE_PTR(path
);
1052 exec_command_append_list(e
, nce
);
1054 /* Do not _cleanup_free_ these. */
1058 } while (semicolon
);
1063 int config_parse_socket_bindtodevice(
1065 const char *filename
,
1067 const char *section
,
1068 unsigned section_line
,
1075 Socket
*s
= ASSERT_PTR(data
);
1081 if (isempty(rvalue
) || streq(rvalue
, "*")) {
1082 s
->bind_to_device
= mfree(s
->bind_to_device
);
1086 if (!ifname_valid(rvalue
)) {
1087 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid interface name, ignoring: %s", rvalue
);
1091 return free_and_strdup_warn(&s
->bind_to_device
, rvalue
);
1094 int config_parse_exec_input(
1096 const char *filename
,
1098 const char *section
,
1099 unsigned section_line
,
1106 ExecContext
*c
= ASSERT_PTR(data
);
1107 const Unit
*u
= userdata
;
1116 n
= startswith(rvalue
, "fd:");
1118 _cleanup_free_
char *resolved
= NULL
;
1120 r
= unit_fd_printf(u
, n
, &resolved
);
1122 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", n
);
1126 if (isempty(resolved
))
1127 resolved
= mfree(resolved
);
1128 else if (!fdname_is_valid(resolved
)) {
1129 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", resolved
);
1133 free_and_replace(c
->stdio_fdname
[STDIN_FILENO
], resolved
);
1135 ei
= EXEC_INPUT_NAMED_FD
;
1137 } else if ((n
= startswith(rvalue
, "file:"))) {
1138 _cleanup_free_
char *resolved
= NULL
;
1140 r
= unit_path_printf(u
, n
, &resolved
);
1142 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", n
);
1146 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1150 free_and_replace(c
->stdio_file
[STDIN_FILENO
], resolved
);
1152 ei
= EXEC_INPUT_FILE
;
1155 ei
= exec_input_from_string(rvalue
);
1157 log_syntax(unit
, LOG_WARNING
, filename
, line
, ei
, "Failed to parse input specifier, ignoring: %s", rvalue
);
1166 int config_parse_exec_input_text(
1168 const char *filename
,
1170 const char *section
,
1171 unsigned section_line
,
1178 _cleanup_free_
char *unescaped
= NULL
, *resolved
= NULL
;
1179 ExecContext
*c
= ASSERT_PTR(data
);
1180 const Unit
*u
= userdata
;
1187 if (isempty(rvalue
)) {
1188 /* Reset if the empty string is assigned */
1189 c
->stdin_data
= mfree(c
->stdin_data
);
1190 c
->stdin_data_size
= 0;
1194 ssize_t l
= cunescape(rvalue
, 0, &unescaped
);
1196 log_syntax(unit
, LOG_WARNING
, filename
, line
, l
,
1197 "Failed to decode C escaped text '%s', ignoring: %m", rvalue
);
1201 r
= unit_full_printf_full(u
, unescaped
, EXEC_STDIN_DATA_MAX
, &resolved
);
1203 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1204 "Failed to resolve unit specifiers in '%s', ignoring: %m", unescaped
);
1208 size_t sz
= strlen(resolved
);
1209 if (c
->stdin_data_size
+ sz
+ 1 < c
->stdin_data_size
|| /* check for overflow */
1210 c
->stdin_data_size
+ sz
+ 1 > EXEC_STDIN_DATA_MAX
) {
1211 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
1212 "Standard input data too large (%zu), maximum of %zu permitted, ignoring.",
1213 c
->stdin_data_size
+ sz
, (size_t) EXEC_STDIN_DATA_MAX
);
1217 void *p
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
+ 1);
1221 *((char*) mempcpy((char*) p
+ c
->stdin_data_size
, resolved
, sz
)) = '\n';
1224 c
->stdin_data_size
+= sz
+ 1;
1229 int config_parse_exec_input_data(
1231 const char *filename
,
1233 const char *section
,
1234 unsigned section_line
,
1241 _cleanup_free_
void *p
= NULL
;
1242 ExecContext
*c
= ASSERT_PTR(data
);
1251 if (isempty(rvalue
)) {
1252 /* Reset if the empty string is assigned */
1253 c
->stdin_data
= mfree(c
->stdin_data
);
1254 c
->stdin_data_size
= 0;
1258 r
= unbase64mem(rvalue
, SIZE_MAX
, &p
, &sz
);
1260 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1261 "Failed to decode base64 data, ignoring: %s", rvalue
);
1267 if (c
->stdin_data_size
+ sz
< c
->stdin_data_size
|| /* check for overflow */
1268 c
->stdin_data_size
+ sz
> EXEC_STDIN_DATA_MAX
) {
1269 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
1270 "Standard input data too large (%zu), maximum of %zu permitted, ignoring.",
1271 c
->stdin_data_size
+ sz
, (size_t) EXEC_STDIN_DATA_MAX
);
1275 q
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
);
1279 memcpy((uint8_t*) q
+ c
->stdin_data_size
, p
, sz
);
1282 c
->stdin_data_size
+= sz
;
1287 int config_parse_exec_output(
1289 const char *filename
,
1291 const char *section
,
1292 unsigned section_line
,
1299 _cleanup_free_
char *resolved
= NULL
;
1301 ExecContext
*c
= ASSERT_PTR(data
);
1302 const Unit
*u
= userdata
;
1303 bool obsolete
= false;
1312 n
= startswith(rvalue
, "fd:");
1314 r
= unit_fd_printf(u
, n
, &resolved
);
1316 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", n
);
1320 if (isempty(resolved
))
1321 resolved
= mfree(resolved
);
1322 else if (!fdname_is_valid(resolved
)) {
1323 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", resolved
);
1327 eo
= EXEC_OUTPUT_NAMED_FD
;
1329 } else if (streq(rvalue
, "syslog")) {
1330 eo
= EXEC_OUTPUT_JOURNAL
;
1333 } else if (streq(rvalue
, "syslog+console")) {
1334 eo
= EXEC_OUTPUT_JOURNAL_AND_CONSOLE
;
1337 } else if ((n
= startswith(rvalue
, "file:"))) {
1339 r
= unit_path_printf(u
, n
, &resolved
);
1341 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", n
);
1345 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1349 eo
= EXEC_OUTPUT_FILE
;
1351 } else if ((n
= startswith(rvalue
, "append:"))) {
1353 r
= unit_path_printf(u
, n
, &resolved
);
1355 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", n
);
1359 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1363 eo
= EXEC_OUTPUT_FILE_APPEND
;
1365 } else if ((n
= startswith(rvalue
, "truncate:"))) {
1367 r
= unit_path_printf(u
, n
, &resolved
);
1369 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", n
);
1373 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1377 eo
= EXEC_OUTPUT_FILE_TRUNCATE
;
1379 eo
= exec_output_from_string(rvalue
);
1381 log_syntax(unit
, LOG_WARNING
, filename
, line
, eo
, "Failed to parse output specifier, ignoring: %s", rvalue
);
1387 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
1388 "Standard output type %s is obsolete, automatically updating to %s. Please update your unit file, and consider removing the setting altogether.",
1389 rvalue
, exec_output_to_string(eo
));
1391 if (streq(lvalue
, "StandardOutput")) {
1392 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1393 free_and_replace(c
->stdio_fdname
[STDOUT_FILENO
], resolved
);
1395 free_and_replace(c
->stdio_file
[STDOUT_FILENO
], resolved
);
1400 assert(streq(lvalue
, "StandardError"));
1402 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1403 free_and_replace(c
->stdio_fdname
[STDERR_FILENO
], resolved
);
1405 free_and_replace(c
->stdio_file
[STDERR_FILENO
], resolved
);
1413 int config_parse_exec_io_class(const char *unit
,
1414 const char *filename
,
1416 const char *section
,
1417 unsigned section_line
,
1424 ExecContext
*c
= ASSERT_PTR(data
);
1431 if (isempty(rvalue
)) {
1432 c
->ioprio_set
= false;
1433 c
->ioprio
= IOPRIO_DEFAULT_CLASS_AND_PRIO
;
1437 x
= ioprio_class_from_string(rvalue
);
1439 log_syntax(unit
, LOG_WARNING
, filename
, line
, x
, "Failed to parse IO scheduling class, ignoring: %s", rvalue
);
1443 c
->ioprio
= ioprio_normalize(ioprio_prio_value(x
, ioprio_prio_data(c
->ioprio
)));
1444 c
->ioprio_set
= true;
1449 int config_parse_exec_io_priority(const char *unit
,
1450 const char *filename
,
1452 const char *section
,
1453 unsigned section_line
,
1460 ExecContext
*c
= ASSERT_PTR(data
);
1467 if (isempty(rvalue
)) {
1468 c
->ioprio_set
= false;
1469 c
->ioprio
= IOPRIO_DEFAULT_CLASS_AND_PRIO
;
1473 r
= ioprio_parse_priority(rvalue
, &i
);
1475 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse IO priority, ignoring: %s", rvalue
);
1479 c
->ioprio
= ioprio_normalize(ioprio_prio_value(ioprio_prio_class(c
->ioprio
), i
));
1480 c
->ioprio_set
= true;
1485 int config_parse_exec_cpu_sched_policy(const char *unit
,
1486 const char *filename
,
1488 const char *section
,
1489 unsigned section_line
,
1496 ExecContext
*c
= ASSERT_PTR(data
);
1503 if (isempty(rvalue
)) {
1504 c
->cpu_sched_set
= false;
1505 c
->cpu_sched_policy
= SCHED_OTHER
;
1506 c
->cpu_sched_priority
= 0;
1510 x
= sched_policy_from_string(rvalue
);
1512 log_syntax(unit
, LOG_WARNING
, filename
, line
, x
, "Failed to parse CPU scheduling policy, ignoring: %s", rvalue
);
1516 c
->cpu_sched_policy
= x
;
1517 /* Moving to or from real-time policy? We need to adjust the priority */
1518 c
->cpu_sched_priority
= CLAMP(c
->cpu_sched_priority
, sched_get_priority_min(x
), sched_get_priority_max(x
));
1519 c
->cpu_sched_set
= true;
1524 int config_parse_exec_mount_apivfs(const char *unit
,
1525 const char *filename
,
1527 const char *section
,
1528 unsigned section_line
,
1535 ExecContext
*c
= ASSERT_PTR(data
);
1542 if (isempty(rvalue
)) {
1543 c
->mount_apivfs_set
= false;
1544 c
->mount_apivfs
= false;
1548 k
= parse_boolean(rvalue
);
1550 log_syntax(unit
, LOG_WARNING
, filename
, line
, k
,
1551 "Failed to parse boolean value, ignoring: %s",
1556 c
->mount_apivfs_set
= true;
1557 c
->mount_apivfs
= k
;
1561 int config_parse_numa_mask(const char *unit
,
1562 const char *filename
,
1564 const char *section
,
1565 unsigned section_line
,
1572 NUMAPolicy
*p
= ASSERT_PTR(data
);
1578 if (streq(rvalue
, "all")) {
1579 r
= numa_mask_add_all(&p
->nodes
);
1581 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1582 "Failed to create NUMA mask representing \"all\" NUMA nodes, ignoring: %m");
1584 r
= parse_cpu_set_extend(rvalue
, &p
->nodes
, true, unit
, filename
, line
, lvalue
);
1586 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse NUMA node mask, ignoring: %s", rvalue
);
1592 int config_parse_exec_cpu_sched_prio(const char *unit
,
1593 const char *filename
,
1595 const char *section
,
1596 unsigned section_line
,
1603 ExecContext
*c
= ASSERT_PTR(data
);
1610 r
= safe_atoi(rvalue
, &i
);
1612 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse CPU scheduling priority, ignoring: %s", rvalue
);
1616 /* On Linux RR/FIFO range from 1 to 99 and OTHER/BATCH may only be 0. Policy might be set later so
1617 * we do not check the precise range, but only the generic outer bounds. */
1618 if (i
< 0 || i
> 99) {
1619 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "CPU scheduling priority is out of range, ignoring: %s", rvalue
);
1623 c
->cpu_sched_priority
= i
;
1624 c
->cpu_sched_set
= true;
1629 int config_parse_root_image_options(
1631 const char *filename
,
1633 const char *section
,
1634 unsigned section_line
,
1641 _cleanup_(mount_options_free_allp
) MountOptions
*options
= NULL
;
1642 _cleanup_strv_free_
char **l
= NULL
;
1643 ExecContext
*c
= ASSERT_PTR(data
);
1644 const Unit
*u
= userdata
;
1651 if (isempty(rvalue
)) {
1652 c
->root_image_options
= mount_options_free_all(c
->root_image_options
);
1656 r
= strv_split_colon_pairs(&l
, rvalue
);
1660 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
1664 STRV_FOREACH_PAIR(first
, second
, l
) {
1665 MountOptions
*o
= NULL
;
1666 _cleanup_free_
char *mount_options_resolved
= NULL
;
1667 const char *mount_options
= NULL
, *partition
= "root";
1668 PartitionDesignator partition_designator
;
1670 /* Format is either 'root:foo' or 'foo' (root is implied) */
1671 if (!isempty(*second
)) {
1673 mount_options
= *second
;
1675 mount_options
= *first
;
1677 partition_designator
= partition_designator_from_string(partition
);
1678 if (partition_designator
< 0) {
1679 log_syntax(unit
, LOG_WARNING
, filename
, line
, partition_designator
,
1680 "Invalid partition name %s, ignoring", partition
);
1683 r
= unit_full_printf(u
, mount_options
, &mount_options_resolved
);
1685 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", mount_options
);
1689 o
= new(MountOptions
, 1);
1692 *o
= (MountOptions
) {
1693 .partition_designator
= partition_designator
,
1694 .options
= TAKE_PTR(mount_options_resolved
),
1696 LIST_APPEND(mount_options
, options
, TAKE_PTR(o
));
1700 LIST_JOIN(mount_options
, c
->root_image_options
, options
);
1702 /* empty spaces/separators only */
1703 c
->root_image_options
= mount_options_free_all(c
->root_image_options
);
1708 int config_parse_image_policy(
1710 const char *filename
,
1712 const char *section
,
1713 unsigned section_line
,
1720 _cleanup_(image_policy_freep
) ImagePolicy
*np
= NULL
;
1721 ImagePolicy
**p
= ASSERT_PTR(data
);
1726 if (isempty(rvalue
)) {
1727 *p
= image_policy_free(*p
);
1731 r
= image_policy_from_string(rvalue
, &np
);
1733 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Duplicate rule in image policy, refusing: %s", rvalue
);
1735 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Unknown partition type in image policy, refusing: %s", rvalue
);
1737 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Unknown partition policy flag in image policy, refusing: %s", rvalue
);
1739 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse image policy, refusing: %s", rvalue
);
1741 image_policy_free(*p
);
1747 int config_parse_exec_root_hash(
1749 const char *filename
,
1751 const char *section
,
1752 unsigned section_line
,
1759 _cleanup_free_
void *roothash_decoded
= NULL
;
1760 ExecContext
*c
= ASSERT_PTR(data
);
1761 size_t roothash_decoded_size
= 0;
1768 if (isempty(rvalue
)) {
1769 /* Reset if the empty string is assigned */
1770 c
->root_hash_path
= mfree(c
->root_hash_path
);
1771 c
->root_hash
= mfree(c
->root_hash
);
1772 c
->root_hash_size
= 0;
1776 if (path_is_absolute(rvalue
)) {
1777 /* We have the path to a roothash to load and decode, eg: RootHash=/foo/bar.roothash */
1778 _cleanup_free_
char *p
= NULL
;
1784 free_and_replace(c
->root_hash_path
, p
);
1785 c
->root_hash
= mfree(c
->root_hash
);
1786 c
->root_hash_size
= 0;
1790 /* We have a roothash to decode, eg: RootHash=012345789abcdef */
1791 r
= unhexmem(rvalue
, strlen(rvalue
), &roothash_decoded
, &roothash_decoded_size
);
1793 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to decode RootHash=, ignoring: %s", rvalue
);
1796 if (roothash_decoded_size
< sizeof(sd_id128_t
)) {
1797 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "RootHash= is too short, ignoring: %s", rvalue
);
1801 free_and_replace(c
->root_hash
, roothash_decoded
);
1802 c
->root_hash_size
= roothash_decoded_size
;
1803 c
->root_hash_path
= mfree(c
->root_hash_path
);
1808 int config_parse_exec_root_hash_sig(
1810 const char *filename
,
1812 const char *section
,
1813 unsigned section_line
,
1820 _cleanup_free_
void *roothash_sig_decoded
= NULL
;
1822 ExecContext
*c
= ASSERT_PTR(data
);
1823 size_t roothash_sig_decoded_size
= 0;
1830 if (isempty(rvalue
)) {
1831 /* Reset if the empty string is assigned */
1832 c
->root_hash_sig_path
= mfree(c
->root_hash_sig_path
);
1833 c
->root_hash_sig
= mfree(c
->root_hash_sig
);
1834 c
->root_hash_sig_size
= 0;
1838 if (path_is_absolute(rvalue
)) {
1839 /* We have the path to a roothash signature to load and decode, eg: RootHashSignature=/foo/bar.roothash.p7s */
1840 _cleanup_free_
char *p
= NULL
;
1846 free_and_replace(c
->root_hash_sig_path
, p
);
1847 c
->root_hash_sig
= mfree(c
->root_hash_sig
);
1848 c
->root_hash_sig_size
= 0;
1852 if (!(value
= startswith(rvalue
, "base64:"))) {
1853 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
1854 "Failed to decode RootHashSignature=, not a path but doesn't start with 'base64:', ignoring: %s", rvalue
);
1858 /* We have a roothash signature to decode, eg: RootHashSignature=base64:012345789abcdef */
1859 r
= unbase64mem(value
, strlen(value
), &roothash_sig_decoded
, &roothash_sig_decoded_size
);
1861 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to decode RootHashSignature=, ignoring: %s", rvalue
);
1865 free_and_replace(c
->root_hash_sig
, roothash_sig_decoded
);
1866 c
->root_hash_sig_size
= roothash_sig_decoded_size
;
1867 c
->root_hash_sig_path
= mfree(c
->root_hash_sig_path
);
1872 int config_parse_exec_cpu_affinity(
1874 const char *filename
,
1876 const char *section
,
1877 unsigned section_line
,
1884 ExecContext
*c
= ASSERT_PTR(data
);
1885 const Unit
*u
= userdata
;
1886 _cleanup_free_
char *k
= NULL
;
1893 if (streq(rvalue
, "numa")) {
1894 c
->cpu_affinity_from_numa
= true;
1895 cpu_set_reset(&c
->cpu_set
);
1900 r
= unit_full_printf(u
, rvalue
, &k
);
1902 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1903 "Failed to resolve unit specifiers in '%s', ignoring: %m",
1908 r
= parse_cpu_set_extend(k
, &c
->cpu_set
, true, unit
, filename
, line
, lvalue
);
1910 c
->cpu_affinity_from_numa
= false;
1915 int config_parse_capability_set(
1917 const char *filename
,
1919 const char *section
,
1920 unsigned section_line
,
1927 uint64_t *capability_set
= ASSERT_PTR(data
);
1928 uint64_t sum
= 0, initial
, def
;
1929 bool invert
= false;
1936 if (rvalue
[0] == '~') {
1941 if (streq(lvalue
, "CapabilityBoundingSet")) {
1942 initial
= CAP_MASK_ALL
; /* initialized to all bits on */
1943 def
= CAP_MASK_UNSET
; /* not set */
1945 def
= initial
= 0; /* All bits off */
1947 r
= capability_set_from_string(rvalue
, &sum
);
1949 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= specifier '%s', ignoring: %m", lvalue
, rvalue
);
1953 if (sum
== 0 || *capability_set
== def
)
1954 /* "", "~" or uninitialized data -> replace */
1955 *capability_set
= invert
? ~sum
: sum
;
1957 /* previous data -> merge */
1959 *capability_set
&= ~sum
;
1961 *capability_set
|= sum
;
1967 int config_parse_exec_selinux_context(
1969 const char *filename
,
1971 const char *section
,
1972 unsigned section_line
,
1979 ExecContext
*c
= ASSERT_PTR(data
);
1980 const Unit
*u
= userdata
;
1989 if (isempty(rvalue
)) {
1990 c
->selinux_context
= mfree(c
->selinux_context
);
1991 c
->selinux_context_ignore
= false;
1995 if (rvalue
[0] == '-') {
2001 r
= unit_full_printf(u
, rvalue
, &k
);
2003 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
2004 "Failed to resolve unit specifiers in '%s'%s: %m",
2005 rvalue
, ignore
? ", ignoring" : "");
2006 return ignore
? 0 : -ENOEXEC
;
2009 free_and_replace(c
->selinux_context
, k
);
2010 c
->selinux_context_ignore
= ignore
;
2015 int config_parse_exec_apparmor_profile(
2017 const char *filename
,
2019 const char *section
,
2020 unsigned section_line
,
2027 ExecContext
*c
= ASSERT_PTR(data
);
2028 const Unit
*u
= userdata
;
2037 if (isempty(rvalue
)) {
2038 c
->apparmor_profile
= mfree(c
->apparmor_profile
);
2039 c
->apparmor_profile_ignore
= false;
2043 if (rvalue
[0] == '-') {
2049 r
= unit_full_printf(u
, rvalue
, &k
);
2051 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
2052 "Failed to resolve unit specifiers in '%s'%s: %m",
2053 rvalue
, ignore
? ", ignoring" : "");
2054 return ignore
? 0 : -ENOEXEC
;
2057 free_and_replace(c
->apparmor_profile
, k
);
2058 c
->apparmor_profile_ignore
= ignore
;
2063 int config_parse_exec_smack_process_label(
2065 const char *filename
,
2067 const char *section
,
2068 unsigned section_line
,
2075 ExecContext
*c
= ASSERT_PTR(data
);
2076 const Unit
*u
= userdata
;
2085 if (isempty(rvalue
)) {
2086 c
->smack_process_label
= mfree(c
->smack_process_label
);
2087 c
->smack_process_label_ignore
= false;
2091 if (rvalue
[0] == '-') {
2097 r
= unit_full_printf(u
, rvalue
, &k
);
2099 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
2100 "Failed to resolve unit specifiers in '%s'%s: %m",
2101 rvalue
, ignore
? ", ignoring" : "");
2102 return ignore
? 0 : -ENOEXEC
;
2105 free_and_replace(c
->smack_process_label
, k
);
2106 c
->smack_process_label_ignore
= ignore
;
2111 int config_parse_timer(
2113 const char *filename
,
2115 const char *section
,
2116 unsigned section_line
,
2123 _cleanup_(calendar_spec_freep
) CalendarSpec
*c
= NULL
;
2124 _cleanup_free_
char *k
= NULL
;
2125 const Unit
*u
= userdata
;
2126 Timer
*t
= ASSERT_PTR(data
);
2135 if (isempty(rvalue
)) {
2136 /* Empty assignment resets list */
2137 timer_free_values(t
);
2141 r
= unit_full_printf(u
, rvalue
, &k
);
2143 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2147 if (ltype
== TIMER_CALENDAR
) {
2148 r
= calendar_spec_from_string(k
, &c
);
2150 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse calendar specification, ignoring: %s", k
);
2154 r
= parse_sec(k
, &usec
);
2156 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse timer value, ignoring: %s", k
);
2161 v
= new(TimerValue
, 1);
2168 .calendar_spec
= TAKE_PTR(c
),
2171 LIST_PREPEND(value
, t
->values
, v
);
2176 int config_parse_trigger_unit(
2178 const char *filename
,
2180 const char *section
,
2181 unsigned section_line
,
2188 _cleanup_free_
char *p
= NULL
;
2189 Unit
*u
= ASSERT_PTR(data
);
2197 if (UNIT_TRIGGER(u
)) {
2198 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Multiple units to trigger specified, ignoring: %s", rvalue
);
2202 r
= unit_name_printf(u
, rvalue
, &p
);
2204 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2208 type
= unit_name_to_type(p
);
2210 log_syntax(unit
, LOG_WARNING
, filename
, line
, type
, "Unit type not valid, ignoring: %s", rvalue
);
2213 if (unit_has_name(u
, p
)) {
2214 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Units cannot trigger themselves, ignoring: %s", rvalue
);
2218 r
= unit_add_two_dependencies_by_name(u
, UNIT_BEFORE
, UNIT_TRIGGERS
, p
, true, UNIT_DEPENDENCY_FILE
);
2220 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add trigger on %s, ignoring: %m", p
);
2227 int config_parse_path_spec(const char *unit
,
2228 const char *filename
,
2230 const char *section
,
2231 unsigned section_line
,
2238 Path
*p
= ASSERT_PTR(data
);
2241 _cleanup_free_
char *k
= NULL
;
2248 if (isempty(rvalue
)) {
2249 /* Empty assignment clears list */
2254 b
= path_type_from_string(lvalue
);
2256 log_syntax(unit
, LOG_WARNING
, filename
, line
, b
, "Failed to parse path type, ignoring: %s", lvalue
);
2260 r
= unit_path_printf(UNIT(p
), rvalue
, &k
);
2262 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2266 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2270 s
= new0(PathSpec
, 1);
2275 s
->path
= TAKE_PTR(k
);
2277 s
->inotify_fd
= -EBADF
;
2279 LIST_PREPEND(spec
, p
->specs
, s
);
2284 int config_parse_socket_service(
2286 const char *filename
,
2288 const char *section
,
2289 unsigned section_line
,
2296 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
2297 _cleanup_free_
char *p
= NULL
;
2298 Socket
*s
= ASSERT_PTR(data
);
2306 r
= unit_name_printf(UNIT(s
), rvalue
, &p
);
2308 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2312 if (!endswith(p
, ".service")) {
2313 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Unit must be of type service, ignoring: %s", rvalue
);
2317 r
= manager_load_unit(UNIT(s
)->manager
, p
, NULL
, &error
, &x
);
2319 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to load unit %s, ignoring: %s", rvalue
, bus_error_message(&error
, r
));
2323 unit_ref_set(&s
->service
, UNIT(s
), x
);
2328 int config_parse_fdname(
2330 const char *filename
,
2332 const char *section
,
2333 unsigned section_line
,
2340 _cleanup_free_
char *p
= NULL
;
2341 Socket
*s
= ASSERT_PTR(data
);
2348 if (isempty(rvalue
)) {
2349 s
->fdname
= mfree(s
->fdname
);
2353 r
= unit_fd_printf(UNIT(s
), rvalue
, &p
);
2355 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2359 if (!fdname_is_valid(p
)) {
2360 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", p
);
2364 return free_and_replace(s
->fdname
, p
);
2367 int config_parse_service_sockets(
2369 const char *filename
,
2371 const char *section
,
2372 unsigned section_line
,
2379 Service
*s
= ASSERT_PTR(data
);
2386 for (const char *p
= rvalue
;;) {
2387 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2389 r
= extract_first_word(&p
, &word
, NULL
, 0);
2393 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Trailing garbage in sockets, ignoring: %s", rvalue
);
2399 r
= unit_name_printf(UNIT(s
), word
, &k
);
2401 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
2405 if (!endswith(k
, ".socket")) {
2406 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Unit must be of type socket, ignoring: %s", k
);
2410 r
= unit_add_two_dependencies_by_name(UNIT(s
), UNIT_WANTS
, UNIT_AFTER
, k
, true, UNIT_DEPENDENCY_FILE
);
2412 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
2414 r
= unit_add_dependency_by_name(UNIT(s
), UNIT_TRIGGERED_BY
, k
, true, UNIT_DEPENDENCY_FILE
);
2416 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
2420 int config_parse_bus_name(
2422 const char *filename
,
2424 const char *section
,
2425 unsigned section_line
,
2432 _cleanup_free_
char *k
= NULL
;
2433 const Unit
*u
= ASSERT_PTR(userdata
);
2440 r
= unit_full_printf_full(u
, rvalue
, SD_BUS_MAXIMUM_NAME_LENGTH
, &k
);
2442 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2446 if (!sd_bus_service_name_is_valid(k
)) {
2447 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid bus name, ignoring: %s", k
);
2451 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
2454 int config_parse_service_timeout(
2456 const char *filename
,
2458 const char *section
,
2459 unsigned section_line
,
2466 Service
*s
= ASSERT_PTR(userdata
);
2474 /* This is called for two cases: TimeoutSec= and TimeoutStartSec=. */
2476 /* Traditionally, these options accepted 0 to disable the timeouts. However, a timeout of 0 suggests it happens
2477 * immediately, hence fix this to become USEC_INFINITY instead. This is in-line with how we internally handle
2478 * all other timeouts. */
2479 r
= parse_sec_fix_0(rvalue
, &usec
);
2481 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
2485 s
->start_timeout_defined
= true;
2486 s
->timeout_start_usec
= usec
;
2488 if (streq(lvalue
, "TimeoutSec"))
2489 s
->timeout_stop_usec
= usec
;
2494 int config_parse_timeout_abort(
2496 const char *filename
,
2498 const char *section
,
2499 unsigned section_line
,
2506 usec_t
*ret
= ASSERT_PTR(data
);
2513 /* Note: apart from setting the arg, this returns an extra bit of information in the return value. */
2515 if (isempty(rvalue
)) {
2517 return 0; /* "not set" */
2520 r
= parse_sec(rvalue
, ret
);
2522 return log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= setting, ignoring: %s", lvalue
, rvalue
);
2524 return 1; /* "set" */
2527 int config_parse_service_timeout_abort(
2529 const char *filename
,
2531 const char *section
,
2532 unsigned section_line
,
2539 Service
*s
= ASSERT_PTR(userdata
);
2542 r
= config_parse_timeout_abort(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
,
2543 &s
->timeout_abort_usec
, s
);
2545 s
->timeout_abort_set
= r
;
2549 int config_parse_user_group_compat(
2551 const char *filename
,
2553 const char *section
,
2554 unsigned section_line
,
2561 _cleanup_free_
char *k
= NULL
;
2563 const Unit
*u
= ASSERT_PTR(userdata
);
2570 if (isempty(rvalue
)) {
2571 *user
= mfree(*user
);
2575 r
= unit_full_printf(u
, rvalue
, &k
);
2577 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", rvalue
);
2581 if (!valid_user_group_name(k
, VALID_USER_ALLOW_NUMERIC
|VALID_USER_RELAX
|VALID_USER_WARN
)) {
2582 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2586 if (strstr(lvalue
, "User") && streq(k
, NOBODY_USER_NAME
))
2587 log_struct(LOG_NOTICE
,
2588 "MESSAGE=%s:%u: Special user %s configured, this is not safe!", filename
, line
, k
,
2590 "MESSAGE_ID=" SD_MESSAGE_NOBODY_USER_UNSUITABLE_STR
,
2591 "OFFENDING_USER=%s", k
,
2592 "CONFIG_FILE=%s", filename
,
2593 "CONFIG_LINE=%u", line
);
2595 return free_and_replace(*user
, k
);
2598 int config_parse_user_group_strv_compat(
2600 const char *filename
,
2602 const char *section
,
2603 unsigned section_line
,
2610 char ***users
= data
;
2611 const Unit
*u
= ASSERT_PTR(userdata
);
2618 if (isempty(rvalue
)) {
2619 *users
= strv_free(*users
);
2623 for (const char *p
= rvalue
;;) {
2624 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2626 r
= extract_first_word(&p
, &word
, NULL
, 0);
2630 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax: %s", rvalue
);
2636 r
= unit_full_printf(u
, word
, &k
);
2638 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", word
);
2642 if (!valid_user_group_name(k
, VALID_USER_ALLOW_NUMERIC
|VALID_USER_RELAX
|VALID_USER_WARN
)) {
2643 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2647 r
= strv_push(users
, k
);
2655 int config_parse_working_directory(
2657 const char *filename
,
2659 const char *section
,
2660 unsigned section_line
,
2667 ExecContext
*c
= ASSERT_PTR(data
);
2668 const Unit
*u
= ASSERT_PTR(userdata
);
2676 if (isempty(rvalue
)) {
2677 c
->working_directory_home
= false;
2678 c
->working_directory
= mfree(c
->working_directory
);
2682 if (rvalue
[0] == '-') {
2688 if (streq(rvalue
, "~")) {
2689 c
->working_directory_home
= true;
2690 c
->working_directory
= mfree(c
->working_directory
);
2692 _cleanup_free_
char *k
= NULL
;
2694 r
= unit_path_printf(u
, rvalue
, &k
);
2696 log_syntax(unit
, missing_ok
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
2697 "Failed to resolve unit specifiers in working directory path '%s'%s: %m",
2698 rvalue
, missing_ok
? ", ignoring" : "");
2699 return missing_ok
? 0 : -ENOEXEC
;
2702 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
| (missing_ok
? 0 : PATH_CHECK_FATAL
), unit
, filename
, line
, lvalue
);
2704 return missing_ok
? 0 : -ENOEXEC
;
2706 c
->working_directory_home
= false;
2707 free_and_replace(c
->working_directory
, k
);
2710 c
->working_directory_missing_ok
= missing_ok
;
2714 int config_parse_unit_env_file(const char *unit
,
2715 const char *filename
,
2717 const char *section
,
2718 unsigned section_line
,
2725 char ***env
= ASSERT_PTR(data
);
2726 const Unit
*u
= userdata
;
2727 _cleanup_free_
char *n
= NULL
;
2734 if (isempty(rvalue
)) {
2735 /* Empty assignment frees the list */
2736 *env
= strv_free(*env
);
2740 r
= unit_full_printf_full(u
, rvalue
, PATH_MAX
, &n
);
2742 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2746 r
= path_simplify_and_warn(n
[0] == '-' ? n
+ 1 : n
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2750 r
= strv_push(env
, n
);
2759 int config_parse_environ(
2761 const char *filename
,
2763 const char *section
,
2764 unsigned section_line
,
2771 const Unit
*u
= userdata
;
2772 char ***env
= ASSERT_PTR(data
);
2779 if (isempty(rvalue
)) {
2780 /* Empty assignment resets the list */
2781 *env
= strv_free(*env
);
2785 /* If 'u' is set, we operate on the regular unit specifier table. Otherwise we use a manager-specific
2786 * specifier table (in which case ltype must contain the runtime scope). */
2787 const Specifier
*table
= u
? NULL
: (const Specifier
[]) {
2788 COMMON_SYSTEM_SPECIFIERS
,
2789 COMMON_TMP_SPECIFIERS
,
2790 COMMON_CREDS_SPECIFIERS(ltype
),
2791 { 'h', specifier_user_home
, NULL
},
2792 { 's', specifier_user_shell
, NULL
},
2795 for (const char *p
= rvalue
;; ) {
2796 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
2798 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2802 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2803 "Invalid syntax, ignoring: %s", rvalue
);
2810 r
= specifier_printf(word
, sc_arg_max(), table
, NULL
, NULL
, &resolved
);
2812 r
= unit_env_printf(u
, word
, &resolved
);
2814 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2815 "Failed to resolve specifiers in %s, ignoring: %m", word
);
2819 if (!env_assignment_is_valid(resolved
)) {
2820 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
2821 "Invalid environment assignment, ignoring: %s", resolved
);
2825 r
= strv_env_replace_consume(env
, TAKE_PTR(resolved
));
2827 return log_error_errno(r
, "Failed to update environment: %m");
2831 int config_parse_pass_environ(
2833 const char *filename
,
2835 const char *section
,
2836 unsigned section_line
,
2843 _cleanup_strv_free_
char **n
= NULL
;
2844 const Unit
*u
= userdata
;
2845 char*** passenv
= ASSERT_PTR(data
);
2853 if (isempty(rvalue
)) {
2854 /* Empty assignment resets the list */
2855 *passenv
= strv_free(*passenv
);
2859 for (const char *p
= rvalue
;;) {
2860 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2862 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
2866 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2867 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2874 r
= unit_env_printf(u
, word
, &k
);
2876 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2877 "Failed to resolve specifiers in %s, ignoring: %m", word
);
2883 if (!env_name_is_valid(k
)) {
2884 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
2885 "Invalid environment name for %s, ignoring: %s", lvalue
, k
);
2889 if (!GREEDY_REALLOC(n
, nlen
+ 2))
2892 n
[nlen
++] = TAKE_PTR(k
);
2897 r
= strv_extend_strv(passenv
, n
, true);
2905 int config_parse_unset_environ(
2907 const char *filename
,
2909 const char *section
,
2910 unsigned section_line
,
2917 _cleanup_strv_free_
char **n
= NULL
;
2918 char*** unsetenv
= ASSERT_PTR(data
);
2919 const Unit
*u
= userdata
;
2927 if (isempty(rvalue
)) {
2928 /* Empty assignment resets the list */
2929 *unsetenv
= strv_free(*unsetenv
);
2933 for (const char *p
= rvalue
;;) {
2934 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2936 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2940 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2941 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2948 r
= unit_env_printf(u
, word
, &k
);
2950 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2951 "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2957 if (!env_assignment_is_valid(k
) && !env_name_is_valid(k
)) {
2958 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
2959 "Invalid environment name or assignment %s, ignoring: %s", lvalue
, k
);
2963 if (!GREEDY_REALLOC(n
, nlen
+ 2))
2966 n
[nlen
++] = TAKE_PTR(k
);
2971 r
= strv_extend_strv(unsetenv
, n
, true);
2979 int config_parse_log_extra_fields(
2981 const char *filename
,
2983 const char *section
,
2984 unsigned section_line
,
2991 ExecContext
*c
= ASSERT_PTR(data
);
2992 const Unit
*u
= userdata
;
2999 if (isempty(rvalue
)) {
3000 exec_context_free_log_extra_fields(c
);
3004 for (const char *p
= rvalue
;;) {
3005 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
3009 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
3013 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3019 r
= unit_full_printf(u
, word
, &k
);
3021 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
3025 eq
= strchr(k
, '=');
3027 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Log field lacks '=' character, ignoring: %s", k
);
3031 if (!journal_field_valid(k
, eq
-k
, false)) {
3032 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Log field name is invalid, ignoring: %s", k
);
3036 t
= reallocarray(c
->log_extra_fields
, c
->n_log_extra_fields
+1, sizeof(struct iovec
));
3040 c
->log_extra_fields
= t
;
3041 c
->log_extra_fields
[c
->n_log_extra_fields
++] = IOVEC_MAKE_STRING(k
);
3047 int config_parse_log_namespace(
3049 const char *filename
,
3051 const char *section
,
3052 unsigned section_line
,
3059 _cleanup_free_
char *k
= NULL
;
3060 ExecContext
*c
= ASSERT_PTR(data
);
3061 const Unit
*u
= userdata
;
3068 if (isempty(rvalue
)) {
3069 c
->log_namespace
= mfree(c
->log_namespace
);
3073 r
= unit_full_printf_full(u
, rvalue
, NAME_MAX
, &k
);
3075 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
3079 if (!log_namespace_name_valid(k
)) {
3080 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Specified log namespace name is not valid, ignoring: %s", k
);
3084 free_and_replace(c
->log_namespace
, k
);
3088 int config_parse_unit_condition_path(
3090 const char *filename
,
3092 const char *section
,
3093 unsigned section_line
,
3100 _cleanup_free_
char *p
= NULL
;
3101 Condition
**list
= ASSERT_PTR(data
), *c
;
3102 ConditionType t
= ltype
;
3103 bool trigger
, negate
;
3104 const Unit
*u
= userdata
;
3111 if (isempty(rvalue
)) {
3112 /* Empty assignment resets the list */
3113 *list
= condition_free_list(*list
);
3117 trigger
= rvalue
[0] == '|';
3121 negate
= rvalue
[0] == '!';
3125 r
= unit_path_printf(u
, rvalue
, &p
);
3127 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
3131 r
= path_simplify_and_warn(p
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
3135 c
= condition_new(t
, p
, trigger
, negate
);
3139 LIST_PREPEND(conditions
, *list
, c
);
3143 int config_parse_unit_condition_string(
3145 const char *filename
,
3147 const char *section
,
3148 unsigned section_line
,
3155 _cleanup_free_
char *s
= NULL
;
3156 Condition
**list
= ASSERT_PTR(data
), *c
;
3157 ConditionType t
= ltype
;
3158 bool trigger
, negate
;
3159 const Unit
*u
= userdata
;
3166 if (isempty(rvalue
)) {
3167 /* Empty assignment resets the list */
3168 *list
= condition_free_list(*list
);
3172 trigger
= *rvalue
== '|';
3174 rvalue
+= 1 + strspn(rvalue
+ 1, WHITESPACE
);
3176 negate
= *rvalue
== '!';
3178 rvalue
+= 1 + strspn(rvalue
+ 1, WHITESPACE
);
3180 r
= unit_full_printf(u
, rvalue
, &s
);
3182 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3183 "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
3187 c
= condition_new(t
, s
, trigger
, negate
);
3191 LIST_PREPEND(conditions
, *list
, c
);
3195 int config_parse_unit_requires_mounts_for(
3197 const char *filename
,
3199 const char *section
,
3200 unsigned section_line
,
3215 for (const char *p
= rvalue
;;) {
3216 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
3218 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3222 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3223 "Invalid syntax, ignoring: %s", rvalue
);
3229 r
= unit_path_printf(u
, word
, &resolved
);
3231 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
3235 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
3239 r
= unit_require_mounts_for(u
, resolved
, UNIT_DEPENDENCY_FILE
);
3241 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add required mount '%s', ignoring: %m", resolved
);
3247 int config_parse_documentation(
3249 const char *filename
,
3251 const char *section
,
3252 unsigned section_line
,
3259 Unit
*u
= ASSERT_PTR(userdata
);
3267 if (isempty(rvalue
)) {
3268 /* Empty assignment resets the list */
3269 u
->documentation
= strv_free(u
->documentation
);
3273 r
= config_parse_unit_strv_printf(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
,
3274 rvalue
, data
, userdata
);
3278 for (a
= b
= u
->documentation
; a
&& *a
; a
++) {
3280 if (documentation_url_is_valid(*a
))
3283 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid URL, ignoring: %s", *a
);
3294 int config_parse_syscall_filter(
3296 const char *filename
,
3298 const char *section
,
3299 unsigned section_line
,
3306 ExecContext
*c
= data
;
3307 _unused_
const Unit
*u
= ASSERT_PTR(userdata
);
3308 bool invert
= false;
3315 if (isempty(rvalue
)) {
3316 /* Empty assignment resets the list */
3317 c
->syscall_filter
= hashmap_free(c
->syscall_filter
);
3318 c
->syscall_allow_list
= false;
3322 if (rvalue
[0] == '~') {
3327 if (!c
->syscall_filter
) {
3328 c
->syscall_filter
= hashmap_new(NULL
);
3329 if (!c
->syscall_filter
)
3333 /* Allow everything but the ones listed */
3334 c
->syscall_allow_list
= false;
3336 /* Allow nothing but the ones listed */
3337 c
->syscall_allow_list
= true;
3339 /* Accept default syscalls if we are on an allow_list */
3340 r
= seccomp_parse_syscall_filter(
3341 "@default", -1, c
->syscall_filter
,
3342 SECCOMP_PARSE_PERMISSIVE
|SECCOMP_PARSE_ALLOW_LIST
,
3350 for (const char *p
= rvalue
;;) {
3351 _cleanup_free_
char *word
= NULL
, *name
= NULL
;
3354 r
= extract_first_word(&p
, &word
, NULL
, 0);
3358 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3359 "Invalid syntax, ignoring: %s", rvalue
);
3365 r
= parse_syscall_and_errno(word
, &name
, &num
);
3367 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3368 "Failed to parse syscall:errno, ignoring: %s", word
);
3371 if (!invert
&& num
>= 0) {
3372 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3373 "Allow-listed system calls cannot take error number, ignoring: %s", word
);
3377 r
= seccomp_parse_syscall_filter(
3378 name
, num
, c
->syscall_filter
,
3379 SECCOMP_PARSE_LOG
|SECCOMP_PARSE_PERMISSIVE
|
3380 (invert
? SECCOMP_PARSE_INVERT
: 0)|
3381 (c
->syscall_allow_list
? SECCOMP_PARSE_ALLOW_LIST
: 0),
3382 unit
, filename
, line
);
3388 int config_parse_syscall_log(
3390 const char *filename
,
3392 const char *section
,
3393 unsigned section_line
,
3400 ExecContext
*c
= data
;
3401 _unused_
const Unit
*u
= ASSERT_PTR(userdata
);
3402 bool invert
= false;
3410 if (isempty(rvalue
)) {
3411 /* Empty assignment resets the list */
3412 c
->syscall_log
= hashmap_free(c
->syscall_log
);
3413 c
->syscall_log_allow_list
= false;
3417 if (rvalue
[0] == '~') {
3422 if (!c
->syscall_log
) {
3423 c
->syscall_log
= hashmap_new(NULL
);
3424 if (!c
->syscall_log
)
3428 /* Log everything but the ones listed */
3429 c
->syscall_log_allow_list
= false;
3431 /* Log nothing but the ones listed */
3432 c
->syscall_log_allow_list
= true;
3437 _cleanup_free_
char *word
= NULL
;
3439 r
= extract_first_word(&p
, &word
, NULL
, 0);
3443 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3449 r
= seccomp_parse_syscall_filter(
3450 word
, -1, c
->syscall_log
,
3451 SECCOMP_PARSE_LOG
|SECCOMP_PARSE_PERMISSIVE
|
3452 (invert
? SECCOMP_PARSE_INVERT
: 0)|
3453 (c
->syscall_log_allow_list
? SECCOMP_PARSE_ALLOW_LIST
: 0),
3454 unit
, filename
, line
);
3460 int config_parse_syscall_archs(
3462 const char *filename
,
3464 const char *section
,
3465 unsigned section_line
,
3475 if (isempty(rvalue
)) {
3476 *archs
= set_free(*archs
);
3480 for (const char *p
= rvalue
;;) {
3481 _cleanup_free_
char *word
= NULL
;
3484 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3488 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3489 "Invalid syntax, ignoring: %s", rvalue
);
3495 r
= seccomp_arch_from_string(word
, &a
);
3497 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3498 "Failed to parse system call architecture \"%s\", ignoring: %m", word
);
3502 r
= set_ensure_put(archs
, NULL
, UINT32_TO_PTR(a
+ 1));
3508 int config_parse_syscall_errno(
3510 const char *filename
,
3512 const char *section
,
3513 unsigned section_line
,
3520 ExecContext
*c
= data
;
3527 if (isempty(rvalue
) || streq(rvalue
, "kill")) {
3528 /* Empty assignment resets to KILL */
3529 c
->syscall_errno
= SECCOMP_ERROR_NUMBER_KILL
;
3533 e
= parse_errno(rvalue
);
3535 log_syntax(unit
, LOG_WARNING
, filename
, line
, e
, "Failed to parse error number, ignoring: %s", rvalue
);
3539 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid error number, ignoring: %s", rvalue
);
3543 c
->syscall_errno
= e
;
3547 int config_parse_address_families(
3549 const char *filename
,
3551 const char *section
,
3552 unsigned section_line
,
3559 ExecContext
*c
= data
;
3560 bool invert
= false;
3567 if (isempty(rvalue
)) {
3568 /* Empty assignment resets the list */
3569 c
->address_families
= set_free(c
->address_families
);
3570 c
->address_families_allow_list
= false;
3574 if (streq(rvalue
, "none")) {
3575 /* Forbid all address families. */
3576 c
->address_families
= set_free(c
->address_families
);
3577 c
->address_families_allow_list
= true;
3581 if (rvalue
[0] == '~') {
3586 if (!c
->address_families
) {
3587 c
->address_families
= set_new(NULL
);
3588 if (!c
->address_families
)
3591 c
->address_families_allow_list
= !invert
;
3594 for (const char *p
= rvalue
;;) {
3595 _cleanup_free_
char *word
= NULL
;
3598 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3602 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3603 "Invalid syntax, ignoring: %s", rvalue
);
3609 af
= af_from_name(word
);
3611 log_syntax(unit
, LOG_WARNING
, filename
, line
, af
,
3612 "Failed to parse address family, ignoring: %s", word
);
3616 /* If we previously wanted to forbid an address family and now
3617 * we want to allow it, then just remove it from the list.
3619 if (!invert
== c
->address_families_allow_list
) {
3620 r
= set_put(c
->address_families
, INT_TO_PTR(af
));
3624 set_remove(c
->address_families
, INT_TO_PTR(af
));
3628 int config_parse_restrict_namespaces(
3630 const char *filename
,
3632 const char *section
,
3633 unsigned section_line
,
3640 ExecContext
*c
= data
;
3641 unsigned long flags
;
3642 bool invert
= false;
3645 if (isempty(rvalue
)) {
3646 /* Reset to the default. */
3647 c
->restrict_namespaces
= NAMESPACE_FLAGS_INITIAL
;
3651 /* Boolean parameter ignores the previous settings */
3652 r
= parse_boolean(rvalue
);
3654 c
->restrict_namespaces
= 0;
3656 } else if (r
== 0) {
3657 c
->restrict_namespaces
= NAMESPACE_FLAGS_ALL
;
3661 if (rvalue
[0] == '~') {
3666 /* Not a boolean argument, in this case it's a list of namespace types. */
3667 r
= namespace_flags_from_string(rvalue
, &flags
);
3669 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse namespace type string, ignoring: %s", rvalue
);
3673 if (c
->restrict_namespaces
== NAMESPACE_FLAGS_INITIAL
)
3674 /* Initial assignment. Just set the value. */
3675 c
->restrict_namespaces
= invert
? (~flags
) & NAMESPACE_FLAGS_ALL
: flags
;
3677 /* Merge the value with the previous one. */
3678 SET_FLAG(c
->restrict_namespaces
, flags
, !invert
);
3684 int config_parse_restrict_filesystems(
3686 const char *filename
,
3688 const char *section
,
3689 unsigned section_line
,
3695 ExecContext
*c
= ASSERT_PTR(data
);
3696 bool invert
= false;
3703 if (isempty(rvalue
)) {
3704 /* Empty assignment resets the list */
3705 c
->restrict_filesystems
= set_free(c
->restrict_filesystems
);
3706 c
->restrict_filesystems_allow_list
= false;
3710 if (rvalue
[0] == '~') {
3715 if (!c
->restrict_filesystems
) {
3717 /* Allow everything but the ones listed */
3718 c
->restrict_filesystems_allow_list
= false;
3720 /* Allow nothing but the ones listed */
3721 c
->restrict_filesystems_allow_list
= true;
3724 for (const char *p
= rvalue
;;) {
3725 _cleanup_free_
char *word
= NULL
;
3727 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3733 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3734 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
3738 r
= lsm_bpf_parse_filesystem(
3740 &c
->restrict_filesystems
,
3741 FILESYSTEM_PARSE_LOG
|
3742 (invert
? FILESYSTEM_PARSE_INVERT
: 0)|
3743 (c
->restrict_filesystems_allow_list
? FILESYSTEM_PARSE_ALLOW_LIST
: 0),
3744 unit
, filename
, line
);
3753 int config_parse_unit_slice(
3755 const char *filename
,
3757 const char *section
,
3758 unsigned section_line
,
3765 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
3766 _cleanup_free_
char *k
= NULL
;
3767 Unit
*u
= userdata
, *slice
;
3775 r
= unit_name_printf(u
, rvalue
, &k
);
3777 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
3781 r
= manager_load_unit(u
->manager
, k
, NULL
, &error
, &slice
);
3783 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to load slice unit %s, ignoring: %s", k
, bus_error_message(&error
, r
));
3787 r
= unit_set_slice(u
, slice
);
3789 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to assign slice %s to unit %s, ignoring: %m", slice
->id
, u
->id
);
3796 int config_parse_cpu_quota(
3798 const char *filename
,
3800 const char *section
,
3801 unsigned section_line
,
3808 CGroupContext
*c
= data
;
3815 if (isempty(rvalue
)) {
3816 c
->cpu_quota_per_sec_usec
= USEC_INFINITY
;
3820 r
= parse_permyriad_unbounded(rvalue
);
3822 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid CPU quota '%s', ignoring.", rvalue
);
3826 c
->cpu_quota_per_sec_usec
= ((usec_t
) r
* USEC_PER_SEC
) / 10000U;
3830 int config_parse_allowed_cpuset(
3832 const char *filename
,
3834 const char *section
,
3835 unsigned section_line
,
3844 (void) parse_cpu_set_extend(rvalue
, c
, true, unit
, filename
, line
, lvalue
);
3848 int config_parse_memory_limit(
3850 const char *filename
,
3852 const char *section
,
3853 unsigned section_line
,
3860 CGroupContext
*c
= data
;
3861 uint64_t bytes
= CGROUP_LIMIT_MAX
;
3864 if (isempty(rvalue
) && STR_IN_SET(lvalue
, "DefaultMemoryLow",
3869 bytes
= CGROUP_LIMIT_MIN
;
3870 else if (!isempty(rvalue
) && !streq(rvalue
, "infinity")) {
3872 r
= parse_permyriad(rvalue
);
3874 r
= parse_size(rvalue
, 1024, &bytes
);
3876 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid memory limit '%s', ignoring: %m", rvalue
);
3880 bytes
= physical_memory_scale(r
, 10000U);
3882 if (bytes
>= UINT64_MAX
||
3883 (bytes
<= 0 && !STR_IN_SET(lvalue
,
3885 "StartupMemorySwapMax",
3887 "StartupMemoryZSwapMax",
3892 "DefaultstartupMemoryLow",
3893 "DefaultMemoryMin"))) {
3894 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Memory limit '%s' out of range, ignoring.", rvalue
);
3899 if (streq(lvalue
, "DefaultMemoryLow")) {
3900 c
->default_memory_low
= bytes
;
3901 c
->default_memory_low_set
= true;
3902 } else if (streq(lvalue
, "DefaultStartupMemoryLow")) {
3903 c
->default_startup_memory_low
= bytes
;
3904 c
->default_startup_memory_low_set
= true;
3905 } else if (streq(lvalue
, "DefaultMemoryMin")) {
3906 c
->default_memory_min
= bytes
;
3907 c
->default_memory_min_set
= true;
3908 } else if (streq(lvalue
, "MemoryMin")) {
3909 c
->memory_min
= bytes
;
3910 c
->memory_min_set
= true;
3911 } else if (streq(lvalue
, "MemoryLow")) {
3912 c
->memory_low
= bytes
;
3913 c
->memory_low_set
= true;
3914 } else if (streq(lvalue
, "StartupMemoryLow")) {
3915 c
->startup_memory_low
= bytes
;
3916 c
->startup_memory_low_set
= true;
3917 } else if (streq(lvalue
, "MemoryHigh"))
3918 c
->memory_high
= bytes
;
3919 else if (streq(lvalue
, "StartupMemoryHigh")) {
3920 c
->startup_memory_high
= bytes
;
3921 c
->startup_memory_high_set
= true;
3922 } else if (streq(lvalue
, "MemoryMax"))
3923 c
->memory_max
= bytes
;
3924 else if (streq(lvalue
, "StartupMemoryMax")) {
3925 c
->startup_memory_max
= bytes
;
3926 c
->startup_memory_max_set
= true;
3927 } else if (streq(lvalue
, "MemorySwapMax"))
3928 c
->memory_swap_max
= bytes
;
3929 else if (streq(lvalue
, "StartupMemorySwapMax")) {
3930 c
->startup_memory_swap_max
= bytes
;
3931 c
->startup_memory_swap_max_set
= true;
3932 } else if (streq(lvalue
, "MemoryZSwapMax"))
3933 c
->memory_zswap_max
= bytes
;
3934 else if (streq(lvalue
, "StartupMemoryZSwapMax")) {
3935 c
->startup_memory_zswap_max
= bytes
;
3936 c
->startup_memory_zswap_max_set
= true;
3937 } else if (streq(lvalue
, "MemoryLimit")) {
3938 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3939 "Unit uses MemoryLimit=; please use MemoryMax= instead. Support for MemoryLimit= will be removed soon.");
3940 c
->memory_limit
= bytes
;
3947 int config_parse_tasks_max(
3949 const char *filename
,
3951 const char *section
,
3952 unsigned section_line
,
3959 const Unit
*u
= userdata
;
3960 TasksMax
*tasks_max
= data
;
3964 if (isempty(rvalue
)) {
3965 *tasks_max
= u
? u
->manager
->default_tasks_max
: TASKS_MAX_UNSET
;
3969 if (streq(rvalue
, "infinity")) {
3970 *tasks_max
= TASKS_MAX_UNSET
;
3974 r
= parse_permyriad(rvalue
);
3976 *tasks_max
= (TasksMax
) { r
, 10000U }; /* r‱ */
3978 r
= safe_atou64(rvalue
, &v
);
3980 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid maximum tasks value '%s', ignoring: %m", rvalue
);
3984 if (v
<= 0 || v
>= UINT64_MAX
) {
3985 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Maximum tasks value '%s' out of range, ignoring.", rvalue
);
3989 *tasks_max
= (TasksMax
) { v
};
3995 int config_parse_delegate(
3997 const char *filename
,
3999 const char *section
,
4000 unsigned section_line
,
4007 CGroupContext
*c
= data
;
4011 t
= unit_name_to_type(unit
);
4012 assert(t
!= _UNIT_TYPE_INVALID
);
4014 if (!unit_vtable
[t
]->can_delegate
) {
4015 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Delegate= setting not supported for this unit type, ignoring.");
4019 /* We either accept a boolean value, which may be used to turn on delegation for all controllers, or
4020 * turn it off for all. Or it takes a list of controller names, in which case we add the specified
4021 * controllers to the mask to delegate. Delegate= enables delegation without any controllers. */
4023 if (isempty(rvalue
)) {
4024 /* An empty string resets controllers and sets Delegate=yes. */
4026 c
->delegate_controllers
= 0;
4030 r
= parse_boolean(rvalue
);
4032 CGroupMask mask
= 0;
4034 for (const char *p
= rvalue
;;) {
4035 _cleanup_free_
char *word
= NULL
;
4036 CGroupController cc
;
4038 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
4042 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
4048 cc
= cgroup_controller_from_string(word
);
4050 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid controller name '%s', ignoring", word
);
4054 mask
|= CGROUP_CONTROLLER_TO_MASK(cc
);
4058 c
->delegate_controllers
|= mask
;
4062 c
->delegate_controllers
= _CGROUP_MASK_ALL
;
4064 c
->delegate
= false;
4065 c
->delegate_controllers
= 0;
4071 int config_parse_managed_oom_mode(
4073 const char *filename
,
4075 const char *section
,
4076 unsigned section_line
,
4083 ManagedOOMMode
*mode
= data
, m
;
4086 t
= unit_name_to_type(unit
);
4087 assert(t
!= _UNIT_TYPE_INVALID
);
4089 if (!unit_vtable
[t
]->can_set_managed_oom
)
4090 return log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "%s= is not supported for this unit type, ignoring.", lvalue
);
4092 if (isempty(rvalue
)) {
4093 *mode
= MANAGED_OOM_AUTO
;
4097 m
= managed_oom_mode_from_string(rvalue
);
4099 log_syntax(unit
, LOG_WARNING
, filename
, line
, m
, "Invalid syntax, ignoring: %s", rvalue
);
4107 int config_parse_managed_oom_mem_pressure_limit(
4109 const char *filename
,
4111 const char *section
,
4112 unsigned section_line
,
4119 uint32_t *limit
= data
;
4123 t
= unit_name_to_type(unit
);
4124 assert(t
!= _UNIT_TYPE_INVALID
);
4126 if (!unit_vtable
[t
]->can_set_managed_oom
)
4127 return log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "%s= is not supported for this unit type, ignoring.", lvalue
);
4129 if (isempty(rvalue
)) {
4134 r
= parse_permyriad(rvalue
);
4136 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse memory pressure limit value, ignoring: %s", rvalue
);
4140 /* Normalize to 2^32-1 == 100% */
4141 *limit
= UINT32_SCALE_FROM_PERMYRIAD(r
);
4145 int config_parse_device_allow(
4147 const char *filename
,
4149 const char *section
,
4150 unsigned section_line
,
4157 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4158 CGroupContext
*c
= data
;
4159 const char *p
= rvalue
;
4162 if (isempty(rvalue
)) {
4163 while (c
->device_allow
)
4164 cgroup_context_free_device_allow(c
, c
->device_allow
);
4169 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4173 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4174 "Failed to extract device path and rights from '%s', ignoring.", rvalue
);
4178 r
= unit_path_printf(userdata
, path
, &resolved
);
4180 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4181 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4185 if (!STARTSWITH_SET(resolved
, "block-", "char-")) {
4187 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4191 if (!valid_device_node_path(resolved
)) {
4192 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid device node path '%s', ignoring.", resolved
);
4197 if (!isempty(p
) && !in_charset(p
, "rwm")) {
4198 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid device rights '%s', ignoring.", p
);
4202 return cgroup_add_device_allow(c
, resolved
, p
);
4205 int config_parse_io_device_weight(
4207 const char *filename
,
4209 const char *section
,
4210 unsigned section_line
,
4217 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4218 CGroupIODeviceWeight
*w
;
4219 CGroupContext
*c
= data
;
4220 const char *p
= ASSERT_PTR(rvalue
);
4227 if (isempty(rvalue
)) {
4228 while (c
->io_device_weights
)
4229 cgroup_context_free_io_device_weight(c
, c
->io_device_weights
);
4234 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4238 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4239 "Failed to extract device path and weight from '%s', ignoring.", rvalue
);
4242 if (r
== 0 || isempty(p
)) {
4243 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4244 "Invalid device path or weight specified in '%s', ignoring.", rvalue
);
4248 r
= unit_path_printf(userdata
, path
, &resolved
);
4250 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4251 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4255 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4259 r
= cg_weight_parse(p
, &u
);
4261 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "IO weight '%s' invalid, ignoring: %m", p
);
4265 assert(u
!= CGROUP_WEIGHT_INVALID
);
4267 w
= new0(CGroupIODeviceWeight
, 1);
4271 w
->path
= TAKE_PTR(resolved
);
4274 LIST_PREPEND(device_weights
, c
->io_device_weights
, w
);
4278 int config_parse_io_device_latency(
4280 const char *filename
,
4282 const char *section
,
4283 unsigned section_line
,
4290 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4291 CGroupIODeviceLatency
*l
;
4292 CGroupContext
*c
= data
;
4293 const char *p
= ASSERT_PTR(rvalue
);
4300 if (isempty(rvalue
)) {
4301 while (c
->io_device_latencies
)
4302 cgroup_context_free_io_device_latency(c
, c
->io_device_latencies
);
4307 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4311 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4312 "Failed to extract device path and latency from '%s', ignoring.", rvalue
);
4315 if (r
== 0 || isempty(p
)) {
4316 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4317 "Invalid device path or latency specified in '%s', ignoring.", rvalue
);
4321 r
= unit_path_printf(userdata
, path
, &resolved
);
4323 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4324 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4328 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4332 r
= parse_sec(p
, &usec
);
4334 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse timer value, ignoring: %s", p
);
4338 l
= new0(CGroupIODeviceLatency
, 1);
4342 l
->path
= TAKE_PTR(resolved
);
4343 l
->target_usec
= usec
;
4345 LIST_PREPEND(device_latencies
, c
->io_device_latencies
, l
);
4349 int config_parse_io_limit(
4351 const char *filename
,
4353 const char *section
,
4354 unsigned section_line
,
4361 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4362 CGroupIODeviceLimit
*l
= NULL
;
4363 CGroupContext
*c
= data
;
4364 CGroupIOLimitType type
;
4365 const char *p
= ASSERT_PTR(rvalue
);
4372 type
= cgroup_io_limit_type_from_string(lvalue
);
4375 if (isempty(rvalue
)) {
4376 LIST_FOREACH(device_limits
, t
, c
->io_device_limits
)
4377 t
->limits
[type
] = cgroup_io_limit_defaults
[type
];
4381 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4385 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4386 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
4389 if (r
== 0 || isempty(p
)) {
4390 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4391 "Invalid device node or bandwidth specified in '%s', ignoring.", rvalue
);
4395 r
= unit_path_printf(userdata
, path
, &resolved
);
4397 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4398 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4402 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4406 if (streq("infinity", p
))
4407 num
= CGROUP_LIMIT_MAX
;
4409 r
= parse_size(p
, 1000, &num
);
4410 if (r
< 0 || num
<= 0) {
4411 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid IO limit '%s', ignoring.", p
);
4416 LIST_FOREACH(device_limits
, t
, c
->io_device_limits
)
4417 if (path_equal(resolved
, t
->path
)) {
4423 l
= new0(CGroupIODeviceLimit
, 1);
4427 l
->path
= TAKE_PTR(resolved
);
4428 for (CGroupIOLimitType i
= 0; i
< _CGROUP_IO_LIMIT_TYPE_MAX
; i
++)
4429 l
->limits
[i
] = cgroup_io_limit_defaults
[i
];
4431 LIST_PREPEND(device_limits
, c
->io_device_limits
, l
);
4434 l
->limits
[type
] = num
;
4439 int config_parse_blockio_device_weight(
4441 const char *filename
,
4443 const char *section
,
4444 unsigned section_line
,
4451 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4452 CGroupBlockIODeviceWeight
*w
;
4453 CGroupContext
*c
= data
;
4454 const char *p
= ASSERT_PTR(rvalue
);
4461 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4462 "Unit uses %s=; please use IO*= settings instead. Support for %s= will be removed soon.",
4465 if (isempty(rvalue
)) {
4466 while (c
->blockio_device_weights
)
4467 cgroup_context_free_blockio_device_weight(c
, c
->blockio_device_weights
);
4472 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4476 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4477 "Failed to extract device node and weight from '%s', ignoring.", rvalue
);
4480 if (r
== 0 || isempty(p
)) {
4481 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4482 "Invalid device node or weight specified in '%s', ignoring.", rvalue
);
4486 r
= unit_path_printf(userdata
, path
, &resolved
);
4488 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4489 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4493 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4497 r
= cg_blkio_weight_parse(p
, &u
);
4499 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid block IO weight '%s', ignoring: %m", p
);
4503 assert(u
!= CGROUP_BLKIO_WEIGHT_INVALID
);
4505 w
= new0(CGroupBlockIODeviceWeight
, 1);
4509 w
->path
= TAKE_PTR(resolved
);
4512 LIST_PREPEND(device_weights
, c
->blockio_device_weights
, w
);
4516 int config_parse_blockio_bandwidth(
4518 const char *filename
,
4520 const char *section
,
4521 unsigned section_line
,
4528 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4529 CGroupBlockIODeviceBandwidth
*b
= NULL
;
4530 CGroupContext
*c
= data
;
4531 const char *p
= ASSERT_PTR(rvalue
);
4539 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4540 "Unit uses %s=; please use IO*= settings instead. Support for %s= will be removed soon.",
4543 read
= streq("BlockIOReadBandwidth", lvalue
);
4545 if (isempty(rvalue
)) {
4546 LIST_FOREACH(device_bandwidths
, t
, c
->blockio_device_bandwidths
) {
4547 t
->rbps
= CGROUP_LIMIT_MAX
;
4548 t
->wbps
= CGROUP_LIMIT_MAX
;
4553 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4557 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4558 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
4561 if (r
== 0 || isempty(p
)) {
4562 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4563 "Invalid device node or bandwidth specified in '%s', ignoring.", rvalue
);
4567 r
= unit_path_printf(userdata
, path
, &resolved
);
4569 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4570 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4574 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4578 r
= parse_size(p
, 1000, &bytes
);
4579 if (r
< 0 || bytes
<= 0) {
4580 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid Block IO Bandwidth '%s', ignoring.", p
);
4584 LIST_FOREACH(device_bandwidths
, t
, c
->blockio_device_bandwidths
)
4585 if (path_equal(resolved
, t
->path
)) {
4591 b
= new0(CGroupBlockIODeviceBandwidth
, 1);
4595 b
->path
= TAKE_PTR(resolved
);
4596 b
->rbps
= CGROUP_LIMIT_MAX
;
4597 b
->wbps
= CGROUP_LIMIT_MAX
;
4599 LIST_PREPEND(device_bandwidths
, c
->blockio_device_bandwidths
, b
);
4610 int config_parse_job_mode_isolate(
4612 const char *filename
,
4614 const char *section
,
4615 unsigned section_line
,
4629 r
= parse_boolean(rvalue
);
4631 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse boolean, ignoring: %s", rvalue
);
4635 log_notice("%s is deprecated. Please use OnFailureJobMode= instead", lvalue
);
4637 *m
= r
? JOB_ISOLATE
: JOB_REPLACE
;
4641 int config_parse_exec_directories(
4643 const char *filename
,
4645 const char *section
,
4646 unsigned section_line
,
4653 ExecDirectory
*ed
= ASSERT_PTR(data
);
4654 const Unit
*u
= userdata
;
4661 if (isempty(rvalue
)) {
4662 /* Empty assignment resets the list */
4663 exec_directory_done(ed
);
4667 for (const char *p
= rvalue
;;) {
4668 _cleanup_free_
char *tuple
= NULL
;
4670 r
= extract_first_word(&p
, &tuple
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_RETAIN_ESCAPE
);
4674 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4675 "Invalid syntax %s=%s, ignoring: %m", lvalue
, rvalue
);
4681 _cleanup_free_
char *src
= NULL
, *dest
= NULL
;
4682 const char *q
= tuple
;
4683 r
= extract_many_words(&q
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
, &src
, &dest
, NULL
);
4687 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4688 "Invalid syntax in %s=, ignoring: %s", lvalue
, tuple
);
4692 _cleanup_free_
char *sresolved
= NULL
;
4693 r
= unit_path_printf(u
, src
, &sresolved
);
4695 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4696 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", src
);
4700 r
= path_simplify_and_warn(sresolved
, PATH_CHECK_RELATIVE
, unit
, filename
, line
, lvalue
);
4704 if (path_startswith(sresolved
, "private")) {
4705 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4706 "%s= path can't be 'private', ignoring assignment: %s", lvalue
, tuple
);
4710 /* For State and Runtime directories we support an optional destination parameter, which
4711 * will be used to create a symlink to the source. */
4712 _cleanup_free_
char *dresolved
= NULL
;
4713 if (!isempty(dest
)) {
4714 if (streq(lvalue
, "ConfigurationDirectory")) {
4715 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4716 "Destination parameter is not supported for ConfigurationDirectory, ignoring: %s", tuple
);
4720 r
= unit_path_printf(u
, dest
, &dresolved
);
4722 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4723 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", dest
);
4727 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_RELATIVE
, unit
, filename
, line
, lvalue
);
4732 r
= exec_directory_add(ed
, sresolved
, dresolved
);
4738 int config_parse_set_credential(
4740 const char *filename
,
4742 const char *section
,
4743 unsigned section_line
,
4750 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
4751 _cleanup_free_
void *d
= NULL
;
4752 ExecContext
*context
= ASSERT_PTR(data
);
4753 ExecSetCredential
*old
;
4755 bool encrypted
= ltype
;
4756 const char *p
= ASSERT_PTR(rvalue
);
4763 if (isempty(rvalue
)) {
4764 /* Empty assignment resets the list */
4765 context
->set_credentials
= hashmap_free(context
->set_credentials
);
4769 r
= extract_first_word(&p
, &word
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4773 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract credential name, ignoring: %s", rvalue
);
4776 if (r
== 0 || isempty(p
)) {
4777 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid syntax, ignoring: %s", rvalue
);
4781 r
= unit_cred_printf(u
, word
, &k
);
4783 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
4786 if (!credential_name_valid(k
)) {
4787 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Credential name \"%s\" not valid, ignoring.", k
);
4792 r
= unbase64mem_full(p
, SIZE_MAX
, true, &d
, &size
);
4794 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Encrypted credential data not valid Base64 data, ignoring.");
4801 /* We support escape codes here, so that users can insert trailing \n if they like */
4802 l
= cunescape(p
, UNESCAPE_ACCEPT_NUL
, &unescaped
);
4804 log_syntax(unit
, LOG_WARNING
, filename
, line
, l
, "Can't unescape \"%s\", ignoring: %m", p
);
4812 old
= hashmap_get(context
->set_credentials
, k
);
4814 free_and_replace(old
->data
, d
);
4816 old
->encrypted
= encrypted
;
4818 _cleanup_(exec_set_credential_freep
) ExecSetCredential
*sc
= NULL
;
4820 sc
= new(ExecSetCredential
, 1);
4824 *sc
= (ExecSetCredential
) {
4826 .data
= TAKE_PTR(d
),
4828 .encrypted
= encrypted
,
4831 r
= hashmap_ensure_put(&context
->set_credentials
, &exec_set_credential_hash_ops
, sc
->id
, sc
);
4835 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4836 "Duplicated credential value '%s', ignoring assignment: %s", sc
->id
, rvalue
);
4846 int config_parse_load_credential(
4848 const char *filename
,
4850 const char *section
,
4851 unsigned section_line
,
4858 _cleanup_free_
char *word
= NULL
, *k
= NULL
, *q
= NULL
;
4859 ExecContext
*context
= ASSERT_PTR(data
);
4860 ExecLoadCredential
*old
;
4861 bool encrypted
= ltype
;
4870 if (isempty(rvalue
)) {
4871 /* Empty assignment resets the list */
4872 context
->load_credentials
= hashmap_free(context
->load_credentials
);
4877 r
= extract_first_word(&p
, &word
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4881 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
4885 r
= unit_cred_printf(u
, word
, &k
);
4887 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
4890 if (!credential_name_valid(k
)) {
4891 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Credential name \"%s\" not valid, ignoring.", k
);
4896 /* If only one field is specified take it as shortcut for inheriting a credential named
4897 * the same way from our parent */
4902 r
= unit_path_printf(u
, p
, &q
);
4904 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", p
);
4907 if (path_is_absolute(q
) ? !path_is_normalized(q
) : !credential_name_valid(q
)) {
4908 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Credential source \"%s\" not valid, ignoring.", q
);
4913 old
= hashmap_get(context
->load_credentials
, k
);
4915 free_and_replace(old
->path
, q
);
4916 old
->encrypted
= encrypted
;
4918 _cleanup_(exec_load_credential_freep
) ExecLoadCredential
*lc
= NULL
;
4920 lc
= new(ExecLoadCredential
, 1);
4924 *lc
= (ExecLoadCredential
) {
4926 .path
= TAKE_PTR(q
),
4927 .encrypted
= encrypted
,
4930 r
= hashmap_ensure_put(&context
->load_credentials
, &exec_load_credential_hash_ops
, lc
->id
, lc
);
4934 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4935 "Duplicated credential value '%s', ignoring assignment: %s", lc
->id
, rvalue
);
4945 int config_parse_set_status(
4947 const char *filename
,
4949 const char *section
,
4950 unsigned section_line
,
4957 ExitStatusSet
*status_set
= ASSERT_PTR(data
);
4964 /* Empty assignment resets the list */
4965 if (isempty(rvalue
)) {
4966 exit_status_set_free(status_set
);
4970 for (const char *p
= rvalue
;;) {
4971 _cleanup_free_
char *word
= NULL
;
4974 r
= extract_first_word(&p
, &word
, NULL
, 0);
4978 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4979 "Failed to parse %s=%s, ignoring: %m", lvalue
, rvalue
);
4985 /* We need to call exit_status_from_string() first, because we want
4986 * to parse numbers as exit statuses, not signals. */
4988 r
= exit_status_from_string(word
);
4990 assert(r
>= 0 && r
< 256);
4991 bitmap
= &status_set
->status
;
4993 r
= signal_from_string(word
);
4995 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4996 "Failed to parse value, ignoring: %s", word
);
4999 bitmap
= &status_set
->signal
;
5002 r
= bitmap_set(bitmap
, r
);
5004 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5005 "Failed to set signal or status %s, ignoring: %m", word
);
5009 int config_parse_namespace_path_strv(
5011 const char *filename
,
5013 const char *section
,
5014 unsigned section_line
,
5021 const Unit
*u
= userdata
;
5022 char*** sv
= ASSERT_PTR(data
);
5029 if (isempty(rvalue
)) {
5030 /* Empty assignment resets the list */
5031 *sv
= strv_free(*sv
);
5035 for (const char *p
= rvalue
;;) {
5036 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
, *joined
= NULL
;
5038 bool ignore_enoent
= false, shall_prefix
= false;
5040 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
5044 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
5051 if (startswith(w
, "-")) {
5052 ignore_enoent
= true;
5055 if (startswith(w
, "+")) {
5056 shall_prefix
= true;
5060 r
= unit_path_printf(u
, w
, &resolved
);
5062 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", w
);
5066 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5070 joined
= strjoin(ignore_enoent
? "-" : "",
5071 shall_prefix
? "+" : "",
5074 r
= strv_push(sv
, joined
);
5084 int config_parse_temporary_filesystems(
5086 const char *filename
,
5088 const char *section
,
5089 unsigned section_line
,
5096 const Unit
*u
= userdata
;
5097 ExecContext
*c
= ASSERT_PTR(data
);
5104 if (isempty(rvalue
)) {
5105 /* Empty assignment resets the list */
5106 temporary_filesystem_free_many(c
->temporary_filesystems
, c
->n_temporary_filesystems
);
5107 c
->temporary_filesystems
= NULL
;
5108 c
->n_temporary_filesystems
= 0;
5112 for (const char *p
= rvalue
;;) {
5113 _cleanup_free_
char *word
= NULL
, *path
= NULL
, *resolved
= NULL
;
5116 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
5120 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
5127 r
= extract_first_word(&w
, &path
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
5131 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", word
);
5135 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid syntax, ignoring: %s", word
);
5139 r
= unit_path_printf(u
, path
, &resolved
);
5141 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", path
);
5145 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5149 r
= temporary_filesystem_add(&c
->temporary_filesystems
, &c
->n_temporary_filesystems
, resolved
, w
);
5155 int config_parse_bind_paths(
5157 const char *filename
,
5159 const char *section
,
5160 unsigned section_line
,
5167 ExecContext
*c
= ASSERT_PTR(data
);
5168 const Unit
*u
= userdata
;
5175 if (isempty(rvalue
)) {
5176 /* Empty assignment resets the list */
5177 bind_mount_free_many(c
->bind_mounts
, c
->n_bind_mounts
);
5178 c
->bind_mounts
= NULL
;
5179 c
->n_bind_mounts
= 0;
5183 for (const char *p
= rvalue
;;) {
5184 _cleanup_free_
char *source
= NULL
, *destination
= NULL
;
5185 _cleanup_free_
char *sresolved
= NULL
, *dresolved
= NULL
;
5186 char *s
= NULL
, *d
= NULL
;
5187 bool rbind
= true, ignore_enoent
= false;
5189 r
= extract_first_word(&p
, &source
, ":" WHITESPACE
, EXTRACT_UNQUOTE
|EXTRACT_DONT_COALESCE_SEPARATORS
);
5193 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
5199 r
= unit_full_printf_full(u
, source
, PATH_MAX
, &sresolved
);
5201 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5202 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", source
);
5208 ignore_enoent
= true;
5212 r
= path_simplify_and_warn(s
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5216 /* Optionally, the destination is specified. */
5217 if (p
&& p
[-1] == ':') {
5218 r
= extract_first_word(&p
, &destination
, ":" WHITESPACE
, EXTRACT_UNQUOTE
|EXTRACT_DONT_COALESCE_SEPARATORS
);
5222 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
5226 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Missing argument after ':', ignoring: %s", s
);
5230 r
= unit_path_printf(u
, destination
, &dresolved
);
5232 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5233 "Failed to resolve specifiers in \"%s\", ignoring: %m", destination
);
5237 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5243 /* Optionally, there's also a short option string specified */
5244 if (p
&& p
[-1] == ':') {
5245 _cleanup_free_
char *options
= NULL
;
5247 r
= extract_first_word(&p
, &options
, NULL
, EXTRACT_UNQUOTE
);
5251 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s=, ignoring: %s", lvalue
, rvalue
);
5255 if (isempty(options
) || streq(options
, "rbind"))
5257 else if (streq(options
, "norbind"))
5260 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid option string, ignoring setting: %s", options
);
5267 r
= bind_mount_add(&c
->bind_mounts
, &c
->n_bind_mounts
,
5271 .read_only
= !!strstr(lvalue
, "ReadOnly"),
5273 .ignore_enoent
= ignore_enoent
,
5282 int config_parse_mount_images(
5284 const char *filename
,
5286 const char *section
,
5287 unsigned section_line
,
5294 ExecContext
*c
= ASSERT_PTR(data
);
5295 const Unit
*u
= userdata
;
5302 if (isempty(rvalue
)) {
5303 /* Empty assignment resets the list */
5304 c
->mount_images
= mount_image_free_many(c
->mount_images
, &c
->n_mount_images
);
5308 for (const char *p
= rvalue
;;) {
5309 _cleanup_(mount_options_free_allp
) MountOptions
*options
= NULL
;
5310 _cleanup_free_
char *first
= NULL
, *second
= NULL
, *tuple
= NULL
;
5311 _cleanup_free_
char *sresolved
= NULL
, *dresolved
= NULL
;
5312 const char *q
= NULL
;
5314 bool permissive
= false;
5316 r
= extract_first_word(&p
, &tuple
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_RETAIN_ESCAPE
);
5320 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5321 "Invalid syntax %s=%s, ignoring: %m", lvalue
, rvalue
);
5328 r
= extract_many_words(&q
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
, &first
, &second
, NULL
);
5332 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5333 "Invalid syntax in %s=, ignoring: %s", lvalue
, tuple
);
5345 r
= unit_path_printf(u
, s
, &sresolved
);
5347 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5348 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", s
);
5352 r
= path_simplify_and_warn(sresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5356 if (isempty(second
)) {
5357 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Missing destination in %s, ignoring: %s", lvalue
, rvalue
);
5361 r
= unit_path_printf(u
, second
, &dresolved
);
5363 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5364 "Failed to resolve specifiers in \"%s\", ignoring: %m", second
);
5368 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5373 _cleanup_free_
char *partition
= NULL
, *mount_options
= NULL
, *mount_options_resolved
= NULL
;
5374 MountOptions
*o
= NULL
;
5375 PartitionDesignator partition_designator
;
5377 r
= extract_many_words(&q
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
, &partition
, &mount_options
, NULL
);
5381 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", q
);
5386 /* Single set of options, applying to the root partition/single filesystem */
5388 r
= unit_full_printf(u
, partition
, &mount_options_resolved
);
5390 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", first
);
5394 o
= new(MountOptions
, 1);
5397 *o
= (MountOptions
) {
5398 .partition_designator
= PARTITION_ROOT
,
5399 .options
= TAKE_PTR(mount_options_resolved
),
5401 LIST_APPEND(mount_options
, options
, o
);
5406 partition_designator
= partition_designator_from_string(partition
);
5407 if (partition_designator
< 0) {
5408 log_syntax(unit
, LOG_WARNING
, filename
, line
, partition_designator
,
5409 "Invalid partition name %s, ignoring", partition
);
5412 r
= unit_full_printf(u
, mount_options
, &mount_options_resolved
);
5414 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", mount_options
);
5418 o
= new(MountOptions
, 1);
5421 *o
= (MountOptions
) {
5422 .partition_designator
= partition_designator
,
5423 .options
= TAKE_PTR(mount_options_resolved
),
5425 LIST_APPEND(mount_options
, options
, o
);
5428 r
= mount_image_add(&c
->mount_images
, &c
->n_mount_images
,
5430 .source
= sresolved
,
5431 .destination
= dresolved
,
5432 .mount_options
= options
,
5433 .ignore_enoent
= permissive
,
5434 .type
= MOUNT_IMAGE_DISCRETE
,
5441 int config_parse_extension_images(
5443 const char *filename
,
5445 const char *section
,
5446 unsigned section_line
,
5453 ExecContext
*c
= ASSERT_PTR(data
);
5454 const Unit
*u
= userdata
;
5461 if (isempty(rvalue
)) {
5462 /* Empty assignment resets the list */
5463 c
->extension_images
= mount_image_free_many(c
->extension_images
, &c
->n_extension_images
);
5467 for (const char *p
= rvalue
;;) {
5468 _cleanup_free_
char *source
= NULL
, *tuple
= NULL
, *sresolved
= NULL
;
5469 _cleanup_(mount_options_free_allp
) MountOptions
*options
= NULL
;
5470 bool permissive
= false;
5471 const char *q
= NULL
;
5474 r
= extract_first_word(&p
, &tuple
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_RETAIN_ESCAPE
);
5478 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5479 "Invalid syntax %s=%s, ignoring: %m", lvalue
, rvalue
);
5486 r
= extract_first_word(&q
, &source
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
);
5490 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5491 "Invalid syntax in %s=, ignoring: %s", lvalue
, tuple
);
5503 r
= unit_path_printf(u
, s
, &sresolved
);
5505 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5506 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", s
);
5510 r
= path_simplify_and_warn(sresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5515 _cleanup_free_
char *partition
= NULL
, *mount_options
= NULL
, *mount_options_resolved
= NULL
;
5516 MountOptions
*o
= NULL
;
5517 PartitionDesignator partition_designator
;
5519 r
= extract_many_words(&q
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
, &partition
, &mount_options
, NULL
);
5523 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", q
);
5528 /* Single set of options, applying to the root partition/single filesystem */
5530 r
= unit_full_printf(u
, partition
, &mount_options_resolved
);
5532 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", partition
);
5536 o
= new(MountOptions
, 1);
5539 *o
= (MountOptions
) {
5540 .partition_designator
= PARTITION_ROOT
,
5541 .options
= TAKE_PTR(mount_options_resolved
),
5543 LIST_APPEND(mount_options
, options
, o
);
5548 partition_designator
= partition_designator_from_string(partition
);
5549 if (partition_designator
< 0) {
5550 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid partition name %s, ignoring", partition
);
5553 r
= unit_full_printf(u
, mount_options
, &mount_options_resolved
);
5555 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", mount_options
);
5559 o
= new(MountOptions
, 1);
5562 *o
= (MountOptions
) {
5563 .partition_designator
= partition_designator
,
5564 .options
= TAKE_PTR(mount_options_resolved
),
5566 LIST_APPEND(mount_options
, options
, o
);
5569 r
= mount_image_add(&c
->extension_images
, &c
->n_extension_images
,
5571 .source
= sresolved
,
5572 .mount_options
= options
,
5573 .ignore_enoent
= permissive
,
5574 .type
= MOUNT_IMAGE_EXTENSION
,
5581 int config_parse_job_timeout_sec(
5583 const char *filename
,
5585 const char *section
,
5586 unsigned section_line
,
5593 Unit
*u
= ASSERT_PTR(data
);
5601 r
= parse_sec_fix_0(rvalue
, &usec
);
5603 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse JobTimeoutSec= parameter, ignoring: %s", rvalue
);
5607 /* If the user explicitly changed JobTimeoutSec= also change JobRunningTimeoutSec=, for compatibility with old
5608 * versions. If JobRunningTimeoutSec= was explicitly set, avoid this however as whatever the user picked should
5611 if (!u
->job_running_timeout_set
)
5612 u
->job_running_timeout
= usec
;
5614 u
->job_timeout
= usec
;
5619 int config_parse_job_running_timeout_sec(
5621 const char *filename
,
5623 const char *section
,
5624 unsigned section_line
,
5631 Unit
*u
= ASSERT_PTR(data
);
5639 r
= parse_sec_fix_0(rvalue
, &usec
);
5641 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse JobRunningTimeoutSec= parameter, ignoring: %s", rvalue
);
5645 u
->job_running_timeout
= usec
;
5646 u
->job_running_timeout_set
= true;
5651 int config_parse_emergency_action(
5653 const char *filename
,
5655 const char *section
,
5656 unsigned section_line
,
5663 EmergencyAction
*x
= ASSERT_PTR(data
);
5664 RuntimeScope runtime_scope
;
5671 /* If we have a unit determine the scope based on it */
5673 runtime_scope
= ((Unit
*) ASSERT_PTR(userdata
))->manager
->runtime_scope
;
5675 runtime_scope
= ltype
; /* otherwise, assume the scope is passed in via ltype */
5677 r
= parse_emergency_action(rvalue
, runtime_scope
, x
);
5679 if (r
== -EOPNOTSUPP
)
5680 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5681 "%s= specified as %s mode action, ignoring: %s",
5682 lvalue
, runtime_scope_to_string(runtime_scope
), rvalue
);
5684 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5685 "Failed to parse %s=, ignoring: %s", lvalue
, rvalue
);
5692 int config_parse_pid_file(
5694 const char *filename
,
5696 const char *section
,
5697 unsigned section_line
,
5704 _cleanup_free_
char *k
= NULL
, *n
= NULL
;
5705 const Unit
*u
= ASSERT_PTR(userdata
);
5713 if (isempty(rvalue
)) {
5714 /* An empty assignment removes already set value. */
5719 r
= unit_path_printf(u
, rvalue
, &k
);
5721 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
5725 /* If this is a relative path make it absolute by prefixing the /run */
5726 n
= path_make_absolute(k
, u
->manager
->prefix
[EXEC_DIRECTORY_RUNTIME
]);
5730 /* Check that the result is a sensible path */
5731 r
= path_simplify_and_warn(n
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5735 r
= patch_var_run(unit
, filename
, line
, lvalue
, &n
);
5739 free_and_replace(*s
, n
);
5743 int config_parse_exit_status(
5745 const char *filename
,
5747 const char *section
,
5748 unsigned section_line
,
5755 int *exit_status
= data
, r
;
5761 assert(exit_status
);
5763 if (isempty(rvalue
)) {
5768 r
= safe_atou8(rvalue
, &u
);
5770 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse exit status '%s', ignoring: %m", rvalue
);
5778 int config_parse_disable_controllers(
5780 const char *filename
,
5782 const char *section
,
5783 unsigned section_line
,
5791 CGroupContext
*c
= data
;
5792 CGroupMask disabled_mask
;
5794 /* 1. If empty, make all controllers eligible for use again.
5795 * 2. If non-empty, merge all listed controllers, space separated. */
5797 if (isempty(rvalue
)) {
5798 c
->disable_controllers
= 0;
5802 r
= cg_mask_from_string(rvalue
, &disabled_mask
);
5803 if (r
< 0 || disabled_mask
<= 0) {
5804 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid cgroup string: %s, ignoring", rvalue
);
5808 c
->disable_controllers
|= disabled_mask
;
5813 int config_parse_ip_filter_bpf_progs(
5815 const char *filename
,
5817 const char *section
,
5818 unsigned section_line
,
5825 _cleanup_free_
char *resolved
= NULL
;
5826 const Unit
*u
= userdata
;
5827 char ***paths
= ASSERT_PTR(data
);
5834 if (isempty(rvalue
)) {
5835 *paths
= strv_free(*paths
);
5839 r
= unit_path_printf(u
, rvalue
, &resolved
);
5841 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
5845 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5849 if (strv_contains(*paths
, resolved
))
5852 r
= strv_extend(paths
, resolved
);
5856 r
= bpf_firewall_supported();
5859 if (r
!= BPF_FIREWALL_SUPPORTED_WITH_MULTI
) {
5860 static bool warned
= false;
5862 log_full(warned
? LOG_DEBUG
: LOG_WARNING
,
5863 "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"
5864 "Starting this unit will fail! (This warning is only shown for the first loaded unit using IP firewalling.)", filename
, line
, lvalue
, rvalue
);
5872 int config_parse_bpf_foreign_program(
5874 const char *filename
,
5876 const char *section
,
5877 unsigned section_line
,
5883 _cleanup_free_
char *resolved
= NULL
, *word
= NULL
;
5884 CGroupContext
*c
= data
;
5885 const char *p
= ASSERT_PTR(rvalue
);
5892 if (isempty(rvalue
)) {
5893 while (c
->bpf_foreign_programs
)
5894 cgroup_context_remove_bpf_foreign_program(c
, c
->bpf_foreign_programs
);
5899 r
= extract_first_word(&p
, &word
, ":", 0);
5903 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse foreign BPF program, ignoring: %s", rvalue
);
5906 if (r
== 0 || isempty(p
)) {
5907 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid syntax in %s=, ignoring: %s", lvalue
, rvalue
);
5911 attach_type
= bpf_cgroup_attach_type_from_string(word
);
5912 if (attach_type
< 0) {
5913 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Unknown BPF attach type=%s, ignoring: %s", word
, rvalue
);
5917 r
= unit_path_printf(u
, p
, &resolved
);
5919 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %s", p
, rvalue
);
5923 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5927 r
= cgroup_add_bpf_foreign_program(c
, attach_type
, resolved
);
5929 return log_error_errno(r
, "Failed to add foreign BPF program to cgroup context: %m");
5934 int config_parse_cgroup_socket_bind(
5936 const char *filename
,
5938 const char *section
,
5939 unsigned section_line
,
5945 _cleanup_free_ CGroupSocketBindItem
*item
= NULL
;
5946 CGroupSocketBindItem
**head
= data
;
5947 uint16_t nr_ports
, port_min
;
5948 int af
, ip_protocol
, r
;
5950 if (isempty(rvalue
)) {
5951 cgroup_context_remove_socket_bind(head
);
5955 r
= parse_socket_bind_item(rvalue
, &af
, &ip_protocol
, &nr_ports
, &port_min
);
5959 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5960 "Unable to parse %s= assignment, ignoring: %s", lvalue
, rvalue
);
5964 item
= new(CGroupSocketBindItem
, 1);
5967 *item
= (CGroupSocketBindItem
) {
5968 .address_family
= af
,
5969 .ip_protocol
= ip_protocol
,
5970 .nr_ports
= nr_ports
,
5971 .port_min
= port_min
,
5974 LIST_PREPEND(socket_bind_items
, *head
, TAKE_PTR(item
));
5979 int config_parse_restrict_network_interfaces(
5981 const char *filename
,
5983 const char *section
,
5984 unsigned section_line
,
5990 CGroupContext
*c
= ASSERT_PTR(data
);
5991 bool is_allow_rule
= true;
5998 if (isempty(rvalue
)) {
5999 /* Empty assignment resets the list */
6000 c
->restrict_network_interfaces
= set_free(c
->restrict_network_interfaces
);
6004 if (rvalue
[0] == '~') {
6005 is_allow_rule
= false;
6009 if (set_isempty(c
->restrict_network_interfaces
))
6010 /* Only initialize this when creating the set */
6011 c
->restrict_network_interfaces_is_allow_list
= is_allow_rule
;
6013 for (const char *p
= rvalue
;;) {
6014 _cleanup_free_
char *word
= NULL
;
6016 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
6022 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
6023 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
6027 if (!ifname_valid(word
)) {
6028 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid interface name, ignoring: %s", word
);
6032 if (c
->restrict_network_interfaces_is_allow_list
!= is_allow_rule
)
6033 free(set_remove(c
->restrict_network_interfaces
, word
));
6035 r
= set_put_strdup(&c
->restrict_network_interfaces
, word
);
6044 static int merge_by_names(Unit
**u
, Set
*names
, const char *id
) {
6051 /* Let's try to add in all names that are aliases of this unit */
6052 while ((k
= set_steal_first(names
))) {
6053 _cleanup_free_ _unused_
char *free_k
= k
;
6055 /* First try to merge in the other name into our unit */
6056 r
= unit_merge_by_name(*u
, k
);
6060 /* Hmm, we couldn't merge the other unit into ours? Then let's try it the other way
6063 other
= manager_get_unit((*u
)->manager
, k
);
6065 return r
; /* return previous failure */
6067 r
= unit_merge(other
, *u
);
6072 return merge_by_names(u
, names
, NULL
);
6075 if (streq_ptr(id
, k
))
6076 unit_choose_id(*u
, id
);
6082 int unit_load_fragment(Unit
*u
) {
6083 const char *fragment
;
6084 _cleanup_set_free_free_ Set
*names
= NULL
;
6088 assert(u
->load_state
== UNIT_STUB
);
6092 u
->access_selinux_context
= mfree(u
->access_selinux_context
);
6093 u
->load_state
= UNIT_LOADED
;
6097 /* Possibly rebuild the fragment map to catch new units */
6098 r
= unit_file_build_name_map(&u
->manager
->lookup_paths
,
6099 &u
->manager
->unit_cache_timestamp_hash
,
6100 &u
->manager
->unit_id_map
,
6101 &u
->manager
->unit_name_map
,
6102 &u
->manager
->unit_path_cache
);
6104 return log_error_errno(r
, "Failed to rebuild name map: %m");
6106 r
= unit_file_find_fragment(u
->manager
->unit_id_map
,
6107 u
->manager
->unit_name_map
,
6111 if (r
< 0 && r
!= -ENOENT
)
6115 /* Open the file, check if this is a mask, otherwise read. */
6116 _cleanup_fclose_
FILE *f
= NULL
;
6119 /* Try to open the file name. A symlink is OK, for example for linked files or masks. We
6120 * expect that all symlinks within the lookup paths have been already resolved, but we don't
6121 * verify this here. */
6122 f
= fopen(fragment
, "re");
6124 return log_unit_notice_errno(u
, errno
, "Failed to open %s: %m", fragment
);
6126 if (fstat(fileno(f
), &st
) < 0)
6129 r
= free_and_strdup(&u
->fragment_path
, fragment
);
6133 if (null_or_empty(&st
)) {
6134 /* Unit file is masked */
6136 u
->load_state
= u
->perpetual
? UNIT_LOADED
: UNIT_MASKED
; /* don't allow perpetual units to ever be masked */
6137 u
->fragment_mtime
= 0;
6138 u
->access_selinux_context
= mfree(u
->access_selinux_context
);
6141 if (mac_selinux_use()) {
6142 _cleanup_freecon_
char *selcon
= NULL
;
6144 /* Cache the SELinux context of the unit file here. We'll make use of when checking access permissions to loaded units */
6145 r
= fgetfilecon_raw(fileno(f
), &selcon
);
6147 log_unit_warning_errno(u
, r
, "Failed to read SELinux context of '%s', ignoring: %m", fragment
);
6149 r
= free_and_strdup(&u
->access_selinux_context
, selcon
);
6154 u
->access_selinux_context
= mfree(u
->access_selinux_context
);
6156 u
->load_state
= UNIT_LOADED
;
6157 u
->fragment_mtime
= timespec_load(&st
.st_mtim
);
6159 /* Now, parse the file contents */
6160 r
= config_parse(u
->id
, fragment
, f
,
6161 UNIT_VTABLE(u
)->sections
,
6162 config_item_perf_lookup
, load_fragment_gperf_lookup
,
6167 log_unit_notice_errno(u
, r
, "Unit configuration has fatal error, unit will not be started.");
6173 /* Call merge_by_names with the name derived from the fragment path as the preferred name.
6175 * We do the merge dance here because for some unit types, the unit might have aliases which are not
6176 * declared in the file system. In particular, this is true (and frequent) for device and swap units.
6178 const char *id
= u
->id
;
6179 _cleanup_free_
char *free_id
= NULL
;
6182 id
= basename(fragment
);
6183 if (unit_name_is_valid(id
, UNIT_NAME_TEMPLATE
)) {
6184 assert(u
->instance
); /* If we're not trying to use a template for non-instanced unit,
6185 * this must be set. */
6187 r
= unit_name_replace_instance(id
, u
->instance
, &free_id
);
6189 return log_debug_errno(r
, "Failed to build id (%s + %s): %m", id
, u
->instance
);
6195 r
= merge_by_names(&merged
, names
, id
);
6200 u
->load_state
= UNIT_MERGED
;
6205 void unit_dump_config_items(FILE *f
) {
6206 static const struct {
6207 const ConfigParserCallback callback
;
6210 { config_parse_warn_compat
, "NOTSUPPORTED" },
6211 { config_parse_int
, "INTEGER" },
6212 { config_parse_unsigned
, "UNSIGNED" },
6213 { config_parse_iec_size
, "SIZE" },
6214 { config_parse_iec_uint64
, "SIZE" },
6215 { config_parse_si_uint64
, "SIZE" },
6216 { config_parse_bool
, "BOOLEAN" },
6217 { config_parse_string
, "STRING" },
6218 { config_parse_path
, "PATH" },
6219 { config_parse_unit_path_printf
, "PATH" },
6220 { config_parse_colon_separated_paths
, "PATH" },
6221 { config_parse_strv
, "STRING [...]" },
6222 { config_parse_exec_nice
, "NICE" },
6223 { config_parse_exec_oom_score_adjust
, "OOMSCOREADJUST" },
6224 { config_parse_exec_io_class
, "IOCLASS" },
6225 { config_parse_exec_io_priority
, "IOPRIORITY" },
6226 { config_parse_exec_cpu_sched_policy
, "CPUSCHEDPOLICY" },
6227 { config_parse_exec_cpu_sched_prio
, "CPUSCHEDPRIO" },
6228 { config_parse_exec_cpu_affinity
, "CPUAFFINITY" },
6229 { config_parse_mode
, "MODE" },
6230 { config_parse_unit_env_file
, "FILE" },
6231 { config_parse_exec_output
, "OUTPUT" },
6232 { config_parse_exec_input
, "INPUT" },
6233 { config_parse_log_facility
, "FACILITY" },
6234 { config_parse_log_level
, "LEVEL" },
6235 { config_parse_exec_secure_bits
, "SECUREBITS" },
6236 { config_parse_capability_set
, "BOUNDINGSET" },
6237 { config_parse_rlimit
, "LIMIT" },
6238 { config_parse_unit_deps
, "UNIT [...]" },
6239 { config_parse_exec
, "PATH [ARGUMENT [...]]" },
6240 { config_parse_service_type
, "SERVICETYPE" },
6241 { config_parse_service_exit_type
, "SERVICEEXITTYPE" },
6242 { config_parse_service_restart
, "SERVICERESTART" },
6243 { config_parse_service_timeout_failure_mode
, "TIMEOUTMODE" },
6244 { config_parse_kill_mode
, "KILLMODE" },
6245 { config_parse_signal
, "SIGNAL" },
6246 { config_parse_socket_listen
, "SOCKET [...]" },
6247 { config_parse_socket_bind
, "SOCKETBIND" },
6248 { config_parse_socket_bindtodevice
, "NETWORKINTERFACE" },
6249 { config_parse_sec
, "SECONDS" },
6250 { config_parse_nsec
, "NANOSECONDS" },
6251 { config_parse_namespace_path_strv
, "PATH [...]" },
6252 { config_parse_bind_paths
, "PATH[:PATH[:OPTIONS]] [...]" },
6253 { config_parse_unit_requires_mounts_for
,
6255 { config_parse_exec_mount_propagation_flag
,
6257 { config_parse_unit_string_printf
, "STRING" },
6258 { config_parse_trigger_unit
, "UNIT" },
6259 { config_parse_timer
, "TIMER" },
6260 { config_parse_path_spec
, "PATH" },
6261 { config_parse_notify_access
, "ACCESS" },
6262 { config_parse_ip_tos
, "TOS" },
6263 { config_parse_unit_condition_path
, "CONDITION" },
6264 { config_parse_unit_condition_string
, "CONDITION" },
6265 { config_parse_unit_slice
, "SLICE" },
6266 { config_parse_documentation
, "URL" },
6267 { config_parse_service_timeout
, "SECONDS" },
6268 { config_parse_emergency_action
, "ACTION" },
6269 { config_parse_set_status
, "STATUS" },
6270 { config_parse_service_sockets
, "SOCKETS" },
6271 { config_parse_environ
, "ENVIRON" },
6273 { config_parse_syscall_filter
, "SYSCALLS" },
6274 { config_parse_syscall_archs
, "ARCHS" },
6275 { config_parse_syscall_errno
, "ERRNO" },
6276 { config_parse_syscall_log
, "SYSCALLS" },
6277 { config_parse_address_families
, "FAMILIES" },
6278 { config_parse_restrict_namespaces
, "NAMESPACES" },
6280 { config_parse_restrict_filesystems
, "FILESYSTEMS" },
6281 { config_parse_cpu_shares
, "SHARES" },
6282 { config_parse_cg_weight
, "WEIGHT" },
6283 { config_parse_cg_cpu_weight
, "CPUWEIGHT" },
6284 { config_parse_memory_limit
, "LIMIT" },
6285 { config_parse_device_allow
, "DEVICE" },
6286 { config_parse_device_policy
, "POLICY" },
6287 { config_parse_io_limit
, "LIMIT" },
6288 { config_parse_io_device_weight
, "DEVICEWEIGHT" },
6289 { config_parse_io_device_latency
, "DEVICELATENCY" },
6290 { config_parse_blockio_bandwidth
, "BANDWIDTH" },
6291 { config_parse_blockio_weight
, "WEIGHT" },
6292 { config_parse_blockio_device_weight
, "DEVICEWEIGHT" },
6293 { config_parse_long
, "LONG" },
6294 { config_parse_socket_service
, "SERVICE" },
6296 { config_parse_exec_selinux_context
, "LABEL" },
6298 { config_parse_job_mode
, "MODE" },
6299 { config_parse_job_mode_isolate
, "BOOLEAN" },
6300 { config_parse_personality
, "PERSONALITY" },
6301 { config_parse_log_filter_patterns
, "REGEX" },
6304 const char *prev
= NULL
;
6308 NULSTR_FOREACH(i
, load_fragment_gperf_nulstr
) {
6309 const char *rvalue
= "OTHER", *lvalue
;
6310 const ConfigPerfItem
*p
;
6313 assert_se(p
= load_fragment_gperf_lookup(i
, strlen(i
)));
6315 /* Hide legacy settings */
6316 if (p
->parse
== config_parse_warn_compat
&&
6317 p
->ltype
== DISABLED_LEGACY
)
6320 for (size_t j
= 0; j
< ELEMENTSOF(table
); j
++)
6321 if (p
->parse
== table
[j
].callback
) {
6322 rvalue
= table
[j
].rvalue
;
6326 dot
= strchr(i
, '.');
6327 lvalue
= dot
? dot
+ 1 : i
;
6330 size_t prefix_len
= dot
- i
;
6332 if (!prev
|| !strneq(prev
, i
, prefix_len
+1)) {
6336 fprintf(f
, "[%.*s]\n", (int) prefix_len
, i
);
6340 fprintf(f
, "%s=%s\n", lvalue
, rvalue
);
6345 int config_parse_cpu_affinity2(
6347 const char *filename
,
6349 const char *section
,
6350 unsigned section_line
,
6357 CPUSet
*affinity
= ASSERT_PTR(data
);
6359 (void) parse_cpu_set_extend(rvalue
, affinity
, true, unit
, filename
, line
, lvalue
);
6364 int config_parse_show_status(
6366 const char *filename
,
6368 const char *section
,
6369 unsigned section_line
,
6377 ShowStatus
*b
= ASSERT_PTR(data
);
6383 k
= parse_show_status(rvalue
, b
);
6385 log_syntax(unit
, LOG_WARNING
, filename
, line
, k
, "Failed to parse show status setting, ignoring: %s", rvalue
);
6390 int config_parse_output_restricted(
6392 const char *filename
,
6394 const char *section
,
6395 unsigned section_line
,
6402 ExecOutput t
, *eo
= ASSERT_PTR(data
);
6403 bool obsolete
= false;
6409 if (streq(rvalue
, "syslog")) {
6410 t
= EXEC_OUTPUT_JOURNAL
;
6412 } else if (streq(rvalue
, "syslog+console")) {
6413 t
= EXEC_OUTPUT_JOURNAL_AND_CONSOLE
;
6416 t
= exec_output_from_string(rvalue
);
6418 log_syntax(unit
, LOG_WARNING
, filename
, line
, t
, "Failed to parse output type, ignoring: %s", rvalue
);
6422 if (IN_SET(t
, EXEC_OUTPUT_SOCKET
, EXEC_OUTPUT_NAMED_FD
, EXEC_OUTPUT_FILE
, EXEC_OUTPUT_FILE_APPEND
, EXEC_OUTPUT_FILE_TRUNCATE
)) {
6423 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Standard output types socket, fd:, file:, append:, truncate: are not supported as defaults, ignoring: %s", rvalue
);
6429 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
6430 "Standard output type %s is obsolete, automatically updating to %s. Please update your configuration.",
6431 rvalue
, exec_output_to_string(t
));
6437 int config_parse_crash_chvt(
6439 const char *filename
,
6441 const char *section
,
6442 unsigned section_line
,
6456 r
= parse_crash_chvt(rvalue
, data
);
6458 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse CrashChangeVT= setting, ignoring: %s", rvalue
);
6463 int config_parse_swap_priority(
6465 const char *filename
,
6467 const char *section
,
6468 unsigned section_line
,
6475 Swap
*s
= ASSERT_PTR(userdata
);
6483 if (isempty(rvalue
)) {
6484 s
->parameters_fragment
.priority
= -1;
6485 s
->parameters_fragment
.priority_set
= false;
6489 r
= safe_atoi(rvalue
, &priority
);
6491 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid swap priority '%s', ignoring.", rvalue
);
6495 if (priority
< -1) {
6496 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
);
6500 if (priority
> 32767) {
6501 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Swap priority out of range, ignoring: %s", rvalue
);
6505 s
->parameters_fragment
.priority
= priority
;
6506 s
->parameters_fragment
.priority_set
= true;
6510 int config_parse_watchdog_sec(
6512 const char *filename
,
6514 const char *section
,
6515 unsigned section_line
,
6522 usec_t
*usec
= data
;
6528 /* This is called for {Runtime,Reboot,KExec}WatchdogSec= where "default" maps to
6529 * USEC_INFINITY internally. */
6531 if (streq(rvalue
, "default"))
6532 *usec
= USEC_INFINITY
;
6533 else if (streq(rvalue
, "off"))
6536 return config_parse_sec(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
);
6541 int config_parse_tty_size(
6543 const char *filename
,
6545 const char *section
,
6546 unsigned section_line
,
6553 unsigned *sz
= data
;
6559 if (isempty(rvalue
)) {
6564 return config_parse_unsigned(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
);
6567 int config_parse_log_filter_patterns(
6569 const char *filename
,
6571 const char *section
,
6572 unsigned section_line
,
6579 ExecContext
*c
= ASSERT_PTR(data
);
6580 const char *pattern
= ASSERT_PTR(rvalue
);
6581 bool is_allowlist
= true;
6587 if (isempty(pattern
)) {
6588 /* Empty assignment resets the lists. */
6589 c
->log_filter_allowed_patterns
= set_free(c
->log_filter_allowed_patterns
);
6590 c
->log_filter_denied_patterns
= set_free(c
->log_filter_denied_patterns
);
6594 if (pattern
[0] == '~') {
6595 is_allowlist
= false;
6597 if (isempty(pattern
))
6598 /* LogFilterPatterns=~ is not considered a valid pattern. */
6599 return log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
6600 "Regex pattern invalid, ignoring: %s=%s", lvalue
, rvalue
);
6603 if (pattern_compile_and_log(pattern
, 0, NULL
) < 0)
6606 r
= set_put_strdup(is_allowlist
? &c
->log_filter_allowed_patterns
: &c
->log_filter_denied_patterns
,
6609 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
6610 "Failed to store log filtering pattern, ignoring: %s=%s", lvalue
, rvalue
);
6617 int config_parse_open_file(
6619 const char *filename
,
6621 const char *section
,
6622 unsigned section_line
,
6629 _cleanup_(open_file_freep
) OpenFile
*of
= NULL
;
6630 OpenFile
**head
= ASSERT_PTR(data
);
6637 if (isempty(rvalue
)) {
6638 open_file_free_many(head
);
6642 r
= open_file_parse(rvalue
, &of
);
6644 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse OpenFile= setting, ignoring: %s", rvalue
);
6648 LIST_APPEND(open_files
, *head
, TAKE_PTR(of
));