1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
3 Copyright © 2012 Holger Hans Peter Freyther
14 #include <sys/resource.h>
16 #include "sd-messages.h"
19 #include "all-units.h"
20 #include "alloc-util.h"
21 #include "bpf-firewall.h"
23 #include "bpf-program.h"
24 #include "bpf-socket-bind.h"
25 #include "bus-error.h"
26 #include "bus-internal.h"
29 #include "capability-util.h"
30 #include "cgroup-setup.h"
31 #include "conf-parser.h"
32 #include "core-varlink.h"
33 #include "cpu-set-util.h"
34 #include "creds-util.h"
36 #include "errno-list.h"
41 #include "hexdecoct.h"
43 #include "ioprio-util.h"
44 #include "ip-protocol-list.h"
45 #include "journal-file.h"
46 #include "limits-util.h"
47 #include "load-fragment.h"
49 #include "missing_ioprio.h"
50 #include "mountpoint-util.h"
51 #include "nulstr-util.h"
52 #include "parse-helpers.h"
53 #include "parse-util.h"
54 #include "path-util.h"
55 #include "percent-util.h"
56 #include "process-util.h"
58 #include "seccomp-util.h"
60 #include "securebits-util.h"
61 #include "selinux-util.h"
62 #include "signal-util.h"
63 #include "socket-netlink.h"
64 #include "specifier.h"
65 #include "stat-util.h"
66 #include "string-util.h"
68 #include "syslog-util.h"
69 #include "time-util.h"
70 #include "unit-name.h"
71 #include "unit-printf.h"
72 #include "user-util.h"
76 static int parse_socket_protocol(const char *s
) {
79 r
= parse_ip_protocol(s
);
82 if (!IN_SET(r
, IPPROTO_UDPLITE
, IPPROTO_SCTP
))
83 return -EPROTONOSUPPORT
;
88 int parse_crash_chvt(const char *value
, int *data
) {
91 if (safe_atoi(value
, data
) >= 0)
94 b
= parse_boolean(value
);
99 *data
= 0; /* switch to where kmsg goes */
101 *data
= -1; /* turn off switching */
106 int parse_confirm_spawn(const char *value
, char **console
) {
110 r
= value
? parse_boolean(value
) : 1;
114 } else if (r
> 0) /* on with default tty */
115 s
= strdup("/dev/console");
116 else if (is_path(value
)) /* on with fully qualified path */
118 else /* on with only a tty file name, not a fully qualified path */
119 s
= path_join("/dev/", value
);
127 DEFINE_CONFIG_PARSE(config_parse_socket_protocol
, parse_socket_protocol
, "Failed to parse socket protocol");
128 DEFINE_CONFIG_PARSE(config_parse_exec_secure_bits
, secure_bits_from_string
, "Failed to parse secure bits");
129 DEFINE_CONFIG_PARSE_ENUM(config_parse_collect_mode
, collect_mode
, CollectMode
, "Failed to parse garbage collection mode");
130 DEFINE_CONFIG_PARSE_ENUM(config_parse_device_policy
, cgroup_device_policy
, CGroupDevicePolicy
, "Failed to parse device policy");
131 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_keyring_mode
, exec_keyring_mode
, ExecKeyringMode
, "Failed to parse keyring mode");
132 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_proc
, protect_proc
, ProtectProc
, "Failed to parse /proc/ protection mode");
133 DEFINE_CONFIG_PARSE_ENUM(config_parse_proc_subset
, proc_subset
, ProcSubset
, "Failed to parse /proc/ subset mode");
134 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_utmp_mode
, exec_utmp_mode
, ExecUtmpMode
, "Failed to parse utmp mode");
135 DEFINE_CONFIG_PARSE_ENUM(config_parse_job_mode
, job_mode
, JobMode
, "Failed to parse job mode");
136 DEFINE_CONFIG_PARSE_ENUM(config_parse_notify_access
, notify_access
, NotifyAccess
, "Failed to parse notify access specifier");
137 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_home
, protect_home
, ProtectHome
, "Failed to parse protect home value");
138 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_system
, protect_system
, ProtectSystem
, "Failed to parse protect system value");
139 DEFINE_CONFIG_PARSE_ENUM(config_parse_runtime_preserve_mode
, exec_preserve_mode
, ExecPreserveMode
, "Failed to parse runtime directory preserve mode");
140 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_type
, service_type
, ServiceType
, "Failed to parse service type");
141 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_exit_type
, service_exit_type
, ServiceExitType
, "Failed to parse service exit type");
142 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart
, service_restart
, ServiceRestart
, "Failed to parse service restart specifier");
143 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_timeout_failure_mode
, service_timeout_failure_mode
, ServiceTimeoutFailureMode
, "Failed to parse timeout failure mode");
144 DEFINE_CONFIG_PARSE_ENUM(config_parse_socket_bind
, socket_address_bind_ipv6_only_or_bool
, SocketAddressBindIPv6Only
, "Failed to parse bind IPv6 only value");
145 DEFINE_CONFIG_PARSE_ENUM(config_parse_oom_policy
, oom_policy
, OOMPolicy
, "Failed to parse OOM policy");
146 DEFINE_CONFIG_PARSE_ENUM(config_parse_managed_oom_preference
, managed_oom_preference
, ManagedOOMPreference
, "Failed to parse ManagedOOMPreference=");
147 DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_ip_tos
, ip_tos
, int, -1, "Failed to parse IP TOS value");
148 DEFINE_CONFIG_PARSE_PTR(config_parse_blockio_weight
, cg_blkio_weight_parse
, uint64_t, "Invalid block IO weight");
149 DEFINE_CONFIG_PARSE_PTR(config_parse_cg_weight
, cg_weight_parse
, uint64_t, "Invalid weight");
150 DEFINE_CONFIG_PARSE_PTR(config_parse_cg_cpu_weight
, cg_cpu_weight_parse
, uint64_t, "Invalid CPU weight");
151 DEFINE_CONFIG_PARSE_PTR(config_parse_cpu_shares
, cg_cpu_shares_parse
, uint64_t, "Invalid CPU shares");
152 DEFINE_CONFIG_PARSE_PTR(config_parse_exec_mount_flags
, mount_propagation_flags_from_string
, unsigned long, "Failed to parse mount flag");
153 DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_numa_policy
, mpol
, int, -1, "Invalid NUMA policy type");
154 DEFINE_CONFIG_PARSE_ENUM(config_parse_status_unit_format
, status_unit_format
, StatusUnitFormat
, "Failed to parse status unit format");
155 DEFINE_CONFIG_PARSE_ENUM_FULL(config_parse_socket_timestamping
, socket_timestamping_from_string_harder
, SocketTimestamping
, "Failed to parse timestamping precision");
157 bool contains_instance_specifier_superset(const char *s
) {
159 bool percent
= false;
173 /* If the string is just the instance specifier, it's not a superset of the instance. */
174 if (memcmp_nn(p
, q
- p
, "%i", strlen("%i")) == 0)
177 /* %i, %n and %N all expand to the instance or a superset of it. */
182 if (IN_SET(*p
, 'n', 'N', 'i'))
191 /* `name` is the rendered version of `format` via `unit_printf` or similar functions. */
192 int unit_is_likely_recursive_template_dependency(Unit
*u
, const char *name
, const char *format
) {
193 const char *fragment_path
;
199 /* If a template unit has a direct dependency on itself that includes the unit instance as part of
200 * the template instance via a unit specifier (%i, %n or %N), this will almost certainly lead to
201 * infinite recursion as systemd will keep instantiating new instances of the template unit.
202 * https://github.com/systemd/systemd/issues/17602 shows a good example of how this can happen in
203 * practice. To guard against this, we check for templates that depend on themselves and have the
204 * instantiated unit instance included as part of the template instance of the dependency via a
207 * For example, if systemd-notify@.service depends on systemd-notify@%n.service, this will result in
208 * infinite recursion.
211 if (!unit_name_is_valid(name
, UNIT_NAME_INSTANCE
))
214 if (!unit_name_prefix_equal(u
->id
, name
))
217 if (u
->type
!= unit_name_to_type(name
))
220 r
= unit_file_find_fragment(u
->manager
->unit_id_map
, u
->manager
->unit_name_map
, name
, &fragment_path
, NULL
);
224 /* Fragment paths should also be equal as a custom fragment for a specific template instance
225 * wouldn't necessarily lead to infinite recursion. */
226 if (!path_equal_ptr(u
->fragment_path
, fragment_path
))
229 if (!contains_instance_specifier_superset(format
))
235 int config_parse_unit_deps(
237 const char *filename
,
240 unsigned section_line
,
247 UnitDependency d
= ltype
;
254 for (const char *p
= rvalue
;;) {
255 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
258 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_RETAIN_ESCAPE
);
264 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
268 r
= unit_name_printf(u
, word
, &k
);
270 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
274 r
= unit_is_likely_recursive_template_dependency(u
, k
, word
);
276 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to determine if '%s' is a recursive dependency, ignoring: %m", k
);
280 log_syntax(unit
, LOG_DEBUG
, filename
, line
, 0,
281 "Dropping dependency %s=%s that likely leads to infinite recursion.",
282 unit_dependency_to_string(d
), word
);
286 r
= unit_add_dependency_by_name(u
, d
, k
, true, UNIT_DEPENDENCY_FILE
);
288 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
292 int config_parse_obsolete_unit_deps(
294 const char *filename
,
297 unsigned section_line
,
304 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
305 "Unit dependency type %s= is obsolete, replacing by %s=, please update your unit file", lvalue
, unit_dependency_to_string(ltype
));
307 return config_parse_unit_deps(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
);
310 int config_parse_unit_string_printf(
312 const char *filename
,
315 unsigned section_line
,
322 _cleanup_free_
char *k
= NULL
;
323 const Unit
*u
= userdata
;
331 r
= unit_full_printf(u
, rvalue
, &k
);
333 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
337 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
340 int config_parse_unit_strv_printf(
342 const char *filename
,
345 unsigned section_line
,
352 const Unit
*u
= userdata
;
353 _cleanup_free_
char *k
= NULL
;
361 r
= unit_full_printf(u
, rvalue
, &k
);
363 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
367 return config_parse_strv(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
370 int config_parse_unit_path_printf(
372 const char *filename
,
375 unsigned section_line
,
382 _cleanup_free_
char *k
= NULL
;
383 const Unit
*u
= userdata
;
392 r
= unit_path_printf(u
, rvalue
, &k
);
394 log_syntax(unit
, fatal
? LOG_ERR
: LOG_WARNING
, filename
, line
, r
,
395 "Failed to resolve unit specifiers in '%s'%s: %m",
396 rvalue
, fatal
? "" : ", ignoring");
397 return fatal
? -ENOEXEC
: 0;
400 return config_parse_path(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
403 int config_parse_colon_separated_paths(
405 const char *filename
,
408 unsigned section_line
,
415 const Unit
*u
= userdata
;
423 if (isempty(rvalue
)) {
424 /* Empty assignment resets the list */
425 *sv
= strv_free(*sv
);
429 for (const char *p
= rvalue
;;) {
430 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
432 r
= extract_first_word(&p
, &word
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
436 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
442 r
= unit_path_printf(u
, word
, &k
);
444 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
445 "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
449 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
453 r
= strv_consume(sv
, TAKE_PTR(k
));
461 int config_parse_unit_path_strv_printf(
463 const char *filename
,
466 unsigned section_line
,
474 const Unit
*u
= userdata
;
482 if (isempty(rvalue
)) {
487 for (const char *p
= rvalue
;;) {
488 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
490 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
496 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
497 "Invalid syntax, ignoring: %s", rvalue
);
501 r
= unit_path_printf(u
, word
, &k
);
503 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
504 "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
508 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
512 r
= strv_consume(x
, TAKE_PTR(k
));
518 static int patch_var_run(
520 const char *filename
,
528 e
= path_startswith(*path
, "/var/run/");
532 z
= path_join("/run/", e
);
536 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
537 "%s= references a path below legacy directory /var/run/, updating %s → %s; "
538 "please update the unit file accordingly.", lvalue
, *path
, z
);
540 free_and_replace(*path
, z
);
545 int config_parse_socket_listen(
547 const char *filename
,
550 unsigned section_line
,
557 _cleanup_free_ SocketPort
*p
= NULL
;
569 if (isempty(rvalue
)) {
570 /* An empty assignment removes all ports */
571 socket_free_ports(s
);
575 p
= new0(SocketPort
, 1);
579 if (ltype
!= SOCKET_SOCKET
) {
580 _cleanup_free_
char *k
= NULL
;
582 r
= unit_path_printf(UNIT(s
), rvalue
, &k
);
584 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
588 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
592 if (ltype
== SOCKET_FIFO
) {
593 r
= patch_var_run(unit
, filename
, line
, lvalue
, &k
);
598 free_and_replace(p
->path
, k
);
601 } else if (streq(lvalue
, "ListenNetlink")) {
602 _cleanup_free_
char *k
= NULL
;
604 r
= unit_path_printf(UNIT(s
), rvalue
, &k
);
606 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
610 r
= socket_address_parse_netlink(&p
->address
, k
);
612 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse address value in '%s', ignoring: %m", k
);
616 p
->type
= SOCKET_SOCKET
;
619 _cleanup_free_
char *k
= NULL
;
621 r
= unit_path_printf(UNIT(s
), rvalue
, &k
);
623 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
627 if (k
[0] == '/') { /* Only for AF_UNIX file system sockets… */
628 r
= patch_var_run(unit
, filename
, line
, lvalue
, &k
);
633 r
= socket_address_parse_and_warn(&p
->address
, k
);
635 if (r
!= -EAFNOSUPPORT
)
636 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse address value in '%s', ignoring: %m", k
);
640 if (streq(lvalue
, "ListenStream"))
641 p
->address
.type
= SOCK_STREAM
;
642 else if (streq(lvalue
, "ListenDatagram"))
643 p
->address
.type
= SOCK_DGRAM
;
645 assert(streq(lvalue
, "ListenSequentialPacket"));
646 p
->address
.type
= SOCK_SEQPACKET
;
649 if (socket_address_family(&p
->address
) != AF_UNIX
&& p
->address
.type
== SOCK_SEQPACKET
) {
650 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Address family not supported, ignoring: %s", rvalue
);
654 p
->type
= SOCKET_SOCKET
;
658 p
->auxiliary_fds
= NULL
;
659 p
->n_auxiliary_fds
= 0;
662 LIST_FIND_TAIL(port
, s
->ports
, tail
);
663 LIST_INSERT_AFTER(port
, s
->ports
, tail
, p
);
670 int config_parse_exec_nice(
672 const char *filename
,
675 unsigned section_line
,
682 ExecContext
*c
= data
;
690 if (isempty(rvalue
)) {
695 r
= parse_nice(rvalue
, &priority
);
698 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Nice priority out of range, ignoring: %s", rvalue
);
700 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse nice priority '%s', ignoring: %m", rvalue
);
710 int config_parse_exec_oom_score_adjust(
712 const char *filename
,
715 unsigned section_line
,
722 ExecContext
*c
= data
;
730 if (isempty(rvalue
)) {
731 c
->oom_score_adjust_set
= false;
735 r
= parse_oom_score_adjust(rvalue
, &oa
);
738 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "OOM score adjust value out of range, ignoring: %s", rvalue
);
740 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse the OOM score adjust value '%s', ignoring: %m", rvalue
);
744 c
->oom_score_adjust
= oa
;
745 c
->oom_score_adjust_set
= true;
750 int config_parse_exec_coredump_filter(
752 const char *filename
,
755 unsigned section_line
,
762 ExecContext
*c
= data
;
770 if (isempty(rvalue
)) {
771 c
->coredump_filter
= 0;
772 c
->coredump_filter_set
= false;
777 r
= coredump_filter_mask_from_string(rvalue
, &f
);
779 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
780 "Failed to parse the CoredumpFilter=%s, ignoring: %m", rvalue
);
784 c
->coredump_filter
|= f
;
785 c
->oom_score_adjust_set
= true;
789 int config_parse_kill_mode(
791 const char *filename
,
794 unsigned section_line
,
801 KillMode
*k
= data
, m
;
808 if (isempty(rvalue
)) {
809 *k
= KILL_CONTROL_GROUP
;
813 m
= kill_mode_from_string(rvalue
);
815 log_syntax(unit
, LOG_WARNING
, filename
, line
, m
,
816 "Failed to parse kill mode specification, ignoring: %s", rvalue
);
821 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
822 "Unit configured to use KillMode=none. "
823 "This is unsafe, as it disables systemd's process lifecycle management for the service. "
824 "Please update your service to use a safer KillMode=, such as 'mixed' or 'control-group'. "
825 "Support for KillMode=none is deprecated and will eventually be removed.");
831 int config_parse_exec(
833 const char *filename
,
836 unsigned section_line
,
843 ExecCommand
**e
= data
;
844 const Unit
*u
= userdata
;
856 if (isempty(rvalue
)) {
857 /* An empty assignment resets the list */
858 *e
= exec_command_free_list(*e
);
864 _cleanup_free_
char *path
= NULL
, *firstword
= NULL
;
865 ExecCommandFlags flags
= 0;
866 bool ignore
= false, separate_argv0
= false;
867 _cleanup_free_ ExecCommand
*nce
= NULL
;
868 _cleanup_strv_free_
char **n
= NULL
;
874 r
= extract_first_word_and_warn(&p
, &firstword
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
878 /* A lone ";" is a separator. Let's make sure we don't treat it as an executable name. */
879 if (streq(firstword
, ";")) {
886 /* We accept an absolute path as first argument. If it's prefixed with - and the path doesn't
887 * exist, we ignore it instead of erroring out; if it's prefixed with @, we allow overriding of
888 * argv[0]; if it's prefixed with :, we will not do environment variable substitution;
889 * if it's prefixed with +, it will be run with full privileges and no sandboxing; if
890 * it's prefixed with '!' we apply sandboxing, but do not change user/group credentials; if
891 * it's prefixed with '!!', then we apply user/group credentials if the kernel supports ambient
892 * capabilities -- if it doesn't we don't apply the credentials themselves, but do apply most
893 * other sandboxing, with some special exceptions for changing UID.
895 * The idea is that '!!' may be used to write services that can take benefit of systemd's
896 * UID/GID dropping if the kernel supports ambient creds, but provide an automatic fallback to
897 * privilege dropping within the daemon if the kernel does not offer that. */
899 if (*f
== '-' && !(flags
& EXEC_COMMAND_IGNORE_FAILURE
)) {
900 flags
|= EXEC_COMMAND_IGNORE_FAILURE
;
902 } else if (*f
== '@' && !separate_argv0
)
903 separate_argv0
= true;
904 else if (*f
== ':' && !(flags
& EXEC_COMMAND_NO_ENV_EXPAND
))
905 flags
|= EXEC_COMMAND_NO_ENV_EXPAND
;
906 else if (*f
== '+' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
907 flags
|= EXEC_COMMAND_FULLY_PRIVILEGED
;
908 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
909 flags
|= EXEC_COMMAND_NO_SETUID
;
910 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_AMBIENT_MAGIC
))) {
911 flags
&= ~EXEC_COMMAND_NO_SETUID
;
912 flags
|= EXEC_COMMAND_AMBIENT_MAGIC
;
918 r
= unit_path_printf(u
, f
, &path
);
920 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
921 "Failed to resolve unit specifiers in '%s'%s: %m",
922 f
, ignore
? ", ignoring" : "");
923 return ignore
? 0 : -ENOEXEC
;
927 /* First word is either "-" or "@" with no command. */
928 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
929 "Empty path in command line%s: '%s'",
930 ignore
? ", ignoring" : "", rvalue
);
931 return ignore
? 0 : -ENOEXEC
;
933 if (!string_is_safe(path
)) {
934 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
935 "Executable name contains special characters%s: %s",
936 ignore
? ", ignoring" : "", path
);
937 return ignore
? 0 : -ENOEXEC
;
939 if (endswith(path
, "/")) {
940 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
941 "Executable path specifies a directory%s: %s",
942 ignore
? ", ignoring" : "", path
);
943 return ignore
? 0 : -ENOEXEC
;
946 if (!(path_is_absolute(path
) ? path_is_valid(path
) : filename_is_valid(path
))) {
947 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
948 "Neither a valid executable name nor an absolute path%s: %s",
949 ignore
? ", ignoring" : "", path
);
950 return ignore
? 0 : -ENOEXEC
;
953 if (!separate_argv0
) {
956 if (!GREEDY_REALLOC0(n
, nlen
+ 2))
968 while (!isempty(p
)) {
969 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
971 /* Check explicitly for an unquoted semicolon as
972 * command separator token. */
973 if (p
[0] == ';' && (!p
[1] || strchr(WHITESPACE
, p
[1]))) {
975 p
+= strspn(p
, WHITESPACE
);
980 /* Check for \; explicitly, to not confuse it with \\; or "\;" or "\\;" etc.
981 * extract_first_word() would return the same for all of those. */
982 if (p
[0] == '\\' && p
[1] == ';' && (!p
[2] || strchr(WHITESPACE
, p
[2]))) {
986 p
+= strspn(p
, WHITESPACE
);
988 if (!GREEDY_REALLOC0(n
, nlen
+ 2))
999 r
= extract_first_word_and_warn(&p
, &word
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
1003 return ignore
? 0 : -ENOEXEC
;
1005 r
= unit_full_printf(u
, word
, &resolved
);
1007 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
1008 "Failed to resolve unit specifiers in %s%s: %m",
1009 word
, ignore
? ", ignoring" : "");
1010 return ignore
? 0 : -ENOEXEC
;
1013 if (!GREEDY_REALLOC(n
, nlen
+ 2))
1016 n
[nlen
++] = TAKE_PTR(resolved
);
1021 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
1022 "Empty executable name or zeroeth argument%s: %s",
1023 ignore
? ", ignoring" : "", rvalue
);
1024 return ignore
? 0 : -ENOEXEC
;
1027 nce
= new0(ExecCommand
, 1);
1031 nce
->argv
= TAKE_PTR(n
);
1032 nce
->path
= TAKE_PTR(path
);
1035 exec_command_append_list(e
, nce
);
1037 /* Do not _cleanup_free_ these. */
1041 } while (semicolon
);
1046 int config_parse_socket_bindtodevice(
1048 const char *filename
,
1050 const char *section
,
1051 unsigned section_line
,
1065 if (isempty(rvalue
) || streq(rvalue
, "*")) {
1066 s
->bind_to_device
= mfree(s
->bind_to_device
);
1070 if (!ifname_valid(rvalue
)) {
1071 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid interface name, ignoring: %s", rvalue
);
1075 return free_and_strdup_warn(&s
->bind_to_device
, rvalue
);
1078 int config_parse_exec_input(
1080 const char *filename
,
1082 const char *section
,
1083 unsigned section_line
,
1090 ExecContext
*c
= data
;
1091 const Unit
*u
= userdata
;
1101 n
= startswith(rvalue
, "fd:");
1103 _cleanup_free_
char *resolved
= NULL
;
1105 r
= unit_fd_printf(u
, n
, &resolved
);
1107 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", n
);
1111 if (isempty(resolved
))
1112 resolved
= mfree(resolved
);
1113 else if (!fdname_is_valid(resolved
)) {
1114 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", resolved
);
1118 free_and_replace(c
->stdio_fdname
[STDIN_FILENO
], resolved
);
1120 ei
= EXEC_INPUT_NAMED_FD
;
1122 } else if ((n
= startswith(rvalue
, "file:"))) {
1123 _cleanup_free_
char *resolved
= NULL
;
1125 r
= unit_path_printf(u
, n
, &resolved
);
1127 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", n
);
1131 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1135 free_and_replace(c
->stdio_file
[STDIN_FILENO
], resolved
);
1137 ei
= EXEC_INPUT_FILE
;
1140 ei
= exec_input_from_string(rvalue
);
1142 log_syntax(unit
, LOG_WARNING
, filename
, line
, ei
, "Failed to parse input specifier, ignoring: %s", rvalue
);
1151 int config_parse_exec_input_text(
1153 const char *filename
,
1155 const char *section
,
1156 unsigned section_line
,
1163 _cleanup_free_
char *unescaped
= NULL
, *resolved
= NULL
;
1164 ExecContext
*c
= data
;
1165 const Unit
*u
= userdata
;
1173 if (isempty(rvalue
)) {
1174 /* Reset if the empty string is assigned */
1175 c
->stdin_data
= mfree(c
->stdin_data
);
1176 c
->stdin_data_size
= 0;
1180 ssize_t l
= cunescape(rvalue
, 0, &unescaped
);
1182 log_syntax(unit
, LOG_WARNING
, filename
, line
, l
,
1183 "Failed to decode C escaped text '%s', ignoring: %m", rvalue
);
1187 r
= unit_full_printf_full(u
, unescaped
, EXEC_STDIN_DATA_MAX
, &resolved
);
1189 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1190 "Failed to resolve unit specifiers in '%s', ignoring: %m", unescaped
);
1194 size_t sz
= strlen(resolved
);
1195 if (c
->stdin_data_size
+ sz
+ 1 < c
->stdin_data_size
|| /* check for overflow */
1196 c
->stdin_data_size
+ sz
+ 1 > EXEC_STDIN_DATA_MAX
) {
1197 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
1198 "Standard input data too large (%zu), maximum of %zu permitted, ignoring.",
1199 c
->stdin_data_size
+ sz
, (size_t) EXEC_STDIN_DATA_MAX
);
1203 void *p
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
+ 1);
1207 *((char*) mempcpy((char*) p
+ c
->stdin_data_size
, resolved
, sz
)) = '\n';
1210 c
->stdin_data_size
+= sz
+ 1;
1215 int config_parse_exec_input_data(
1217 const char *filename
,
1219 const char *section
,
1220 unsigned section_line
,
1227 _cleanup_free_
void *p
= NULL
;
1228 ExecContext
*c
= data
;
1238 if (isempty(rvalue
)) {
1239 /* Reset if the empty string is assigned */
1240 c
->stdin_data
= mfree(c
->stdin_data
);
1241 c
->stdin_data_size
= 0;
1245 r
= unbase64mem(rvalue
, SIZE_MAX
, &p
, &sz
);
1247 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1248 "Failed to decode base64 data, ignoring: %s", rvalue
);
1254 if (c
->stdin_data_size
+ sz
< c
->stdin_data_size
|| /* check for overflow */
1255 c
->stdin_data_size
+ sz
> EXEC_STDIN_DATA_MAX
) {
1256 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
1257 "Standard input data too large (%zu), maximum of %zu permitted, ignoring.",
1258 c
->stdin_data_size
+ sz
, (size_t) EXEC_STDIN_DATA_MAX
);
1262 q
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
);
1266 memcpy((uint8_t*) q
+ c
->stdin_data_size
, p
, sz
);
1269 c
->stdin_data_size
+= sz
;
1274 int config_parse_exec_output(
1276 const char *filename
,
1278 const char *section
,
1279 unsigned section_line
,
1286 _cleanup_free_
char *resolved
= NULL
;
1288 ExecContext
*c
= data
;
1289 const Unit
*u
= userdata
;
1290 bool obsolete
= false;
1300 n
= startswith(rvalue
, "fd:");
1302 r
= unit_fd_printf(u
, n
, &resolved
);
1304 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", n
);
1308 if (isempty(resolved
))
1309 resolved
= mfree(resolved
);
1310 else if (!fdname_is_valid(resolved
)) {
1311 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", resolved
);
1315 eo
= EXEC_OUTPUT_NAMED_FD
;
1317 } else if (streq(rvalue
, "syslog")) {
1318 eo
= EXEC_OUTPUT_JOURNAL
;
1321 } else if (streq(rvalue
, "syslog+console")) {
1322 eo
= EXEC_OUTPUT_JOURNAL_AND_CONSOLE
;
1325 } else if ((n
= startswith(rvalue
, "file:"))) {
1327 r
= unit_path_printf(u
, n
, &resolved
);
1329 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", n
);
1333 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1337 eo
= EXEC_OUTPUT_FILE
;
1339 } else if ((n
= startswith(rvalue
, "append:"))) {
1341 r
= unit_path_printf(u
, n
, &resolved
);
1343 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", n
);
1347 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1351 eo
= EXEC_OUTPUT_FILE_APPEND
;
1353 } else if ((n
= startswith(rvalue
, "truncate:"))) {
1355 r
= unit_path_printf(u
, n
, &resolved
);
1357 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", n
);
1361 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1365 eo
= EXEC_OUTPUT_FILE_TRUNCATE
;
1367 eo
= exec_output_from_string(rvalue
);
1369 log_syntax(unit
, LOG_WARNING
, filename
, line
, eo
, "Failed to parse output specifier, ignoring: %s", rvalue
);
1375 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
1376 "Standard output type %s is obsolete, automatically updating to %s. Please update your unit file, and consider removing the setting altogether.",
1377 rvalue
, exec_output_to_string(eo
));
1379 if (streq(lvalue
, "StandardOutput")) {
1380 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1381 free_and_replace(c
->stdio_fdname
[STDOUT_FILENO
], resolved
);
1383 free_and_replace(c
->stdio_file
[STDOUT_FILENO
], resolved
);
1388 assert(streq(lvalue
, "StandardError"));
1390 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1391 free_and_replace(c
->stdio_fdname
[STDERR_FILENO
], resolved
);
1393 free_and_replace(c
->stdio_file
[STDERR_FILENO
], resolved
);
1401 int config_parse_exec_io_class(const char *unit
,
1402 const char *filename
,
1404 const char *section
,
1405 unsigned section_line
,
1412 ExecContext
*c
= data
;
1420 if (isempty(rvalue
)) {
1421 c
->ioprio_set
= false;
1422 c
->ioprio
= IOPRIO_DEFAULT_CLASS_AND_PRIO
;
1426 x
= ioprio_class_from_string(rvalue
);
1428 log_syntax(unit
, LOG_WARNING
, filename
, line
, x
, "Failed to parse IO scheduling class, ignoring: %s", rvalue
);
1432 c
->ioprio
= ioprio_normalize(ioprio_prio_value(x
, ioprio_prio_data(c
->ioprio
)));
1433 c
->ioprio_set
= true;
1438 int config_parse_exec_io_priority(const char *unit
,
1439 const char *filename
,
1441 const char *section
,
1442 unsigned section_line
,
1449 ExecContext
*c
= data
;
1457 if (isempty(rvalue
)) {
1458 c
->ioprio_set
= false;
1459 c
->ioprio
= IOPRIO_DEFAULT_CLASS_AND_PRIO
;
1463 r
= ioprio_parse_priority(rvalue
, &i
);
1465 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse IO priority, ignoring: %s", rvalue
);
1469 c
->ioprio
= ioprio_normalize(ioprio_prio_value(ioprio_prio_class(c
->ioprio
), i
));
1470 c
->ioprio_set
= true;
1475 int config_parse_exec_cpu_sched_policy(const char *unit
,
1476 const char *filename
,
1478 const char *section
,
1479 unsigned section_line
,
1486 ExecContext
*c
= data
;
1494 if (isempty(rvalue
)) {
1495 c
->cpu_sched_set
= false;
1496 c
->cpu_sched_policy
= SCHED_OTHER
;
1497 c
->cpu_sched_priority
= 0;
1501 x
= sched_policy_from_string(rvalue
);
1503 log_syntax(unit
, LOG_WARNING
, filename
, line
, x
, "Failed to parse CPU scheduling policy, ignoring: %s", rvalue
);
1507 c
->cpu_sched_policy
= x
;
1508 /* Moving to or from real-time policy? We need to adjust the priority */
1509 c
->cpu_sched_priority
= CLAMP(c
->cpu_sched_priority
, sched_get_priority_min(x
), sched_get_priority_max(x
));
1510 c
->cpu_sched_set
= true;
1515 int config_parse_exec_mount_apivfs(const char *unit
,
1516 const char *filename
,
1518 const char *section
,
1519 unsigned section_line
,
1526 ExecContext
*c
= data
;
1534 if (isempty(rvalue
)) {
1535 c
->mount_apivfs_set
= false;
1536 c
->mount_apivfs
= false;
1540 k
= parse_boolean(rvalue
);
1542 log_syntax(unit
, LOG_WARNING
, filename
, line
, k
,
1543 "Failed to parse boolean value, ignoring: %s",
1548 c
->mount_apivfs_set
= true;
1549 c
->mount_apivfs
= k
;
1553 int config_parse_numa_mask(const char *unit
,
1554 const char *filename
,
1556 const char *section
,
1557 unsigned section_line
,
1564 NUMAPolicy
*p
= data
;
1571 if (streq(rvalue
, "all")) {
1572 r
= numa_mask_add_all(&p
->nodes
);
1574 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1575 "Failed to create NUMA mask representing \"all\" NUMA nodes, ignoring: %m");
1577 r
= parse_cpu_set_extend(rvalue
, &p
->nodes
, true, unit
, filename
, line
, lvalue
);
1579 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse NUMA node mask, ignoring: %s", rvalue
);
1585 int config_parse_exec_cpu_sched_prio(const char *unit
,
1586 const char *filename
,
1588 const char *section
,
1589 unsigned section_line
,
1596 ExecContext
*c
= data
;
1604 r
= safe_atoi(rvalue
, &i
);
1606 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse CPU scheduling priority, ignoring: %s", rvalue
);
1610 /* On Linux RR/FIFO range from 1 to 99 and OTHER/BATCH may only be 0 */
1611 min
= sched_get_priority_min(c
->cpu_sched_policy
);
1612 max
= sched_get_priority_max(c
->cpu_sched_policy
);
1614 if (i
< min
|| i
> max
) {
1615 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "CPU scheduling priority is out of range, ignoring: %s", rvalue
);
1619 c
->cpu_sched_priority
= i
;
1620 c
->cpu_sched_set
= true;
1625 int config_parse_root_image_options(
1627 const char *filename
,
1629 const char *section
,
1630 unsigned section_line
,
1637 _cleanup_(mount_options_free_allp
) MountOptions
*options
= NULL
;
1638 _cleanup_strv_free_
char **l
= NULL
;
1639 ExecContext
*c
= data
;
1640 const Unit
*u
= userdata
;
1648 if (isempty(rvalue
)) {
1649 c
->root_image_options
= mount_options_free_all(c
->root_image_options
);
1653 r
= strv_split_colon_pairs(&l
, rvalue
);
1657 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
1661 STRV_FOREACH_PAIR(first
, second
, l
) {
1662 MountOptions
*o
= NULL
;
1663 _cleanup_free_
char *mount_options_resolved
= NULL
;
1664 const char *mount_options
= NULL
, *partition
= "root";
1665 PartitionDesignator partition_designator
;
1667 /* Format is either 'root:foo' or 'foo' (root is implied) */
1668 if (!isempty(*second
)) {
1670 mount_options
= *second
;
1672 mount_options
= *first
;
1674 partition_designator
= partition_designator_from_string(partition
);
1675 if (partition_designator
< 0) {
1676 log_syntax(unit
, LOG_WARNING
, filename
, line
, partition_designator
,
1677 "Invalid partition name %s, ignoring", partition
);
1680 r
= unit_full_printf(u
, mount_options
, &mount_options_resolved
);
1682 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", mount_options
);
1686 o
= new(MountOptions
, 1);
1689 *o
= (MountOptions
) {
1690 .partition_designator
= partition_designator
,
1691 .options
= TAKE_PTR(mount_options_resolved
),
1693 LIST_APPEND(mount_options
, options
, TAKE_PTR(o
));
1697 LIST_JOIN(mount_options
, c
->root_image_options
, options
);
1699 /* empty spaces/separators only */
1700 c
->root_image_options
= mount_options_free_all(c
->root_image_options
);
1705 int config_parse_exec_root_hash(
1707 const char *filename
,
1709 const char *section
,
1710 unsigned section_line
,
1717 _cleanup_free_
void *roothash_decoded
= NULL
;
1718 ExecContext
*c
= data
;
1719 size_t roothash_decoded_size
= 0;
1727 if (isempty(rvalue
)) {
1728 /* Reset if the empty string is assigned */
1729 c
->root_hash_path
= mfree(c
->root_hash_path
);
1730 c
->root_hash
= mfree(c
->root_hash
);
1731 c
->root_hash_size
= 0;
1735 if (path_is_absolute(rvalue
)) {
1736 /* We have the path to a roothash to load and decode, eg: RootHash=/foo/bar.roothash */
1737 _cleanup_free_
char *p
= NULL
;
1743 free_and_replace(c
->root_hash_path
, p
);
1744 c
->root_hash
= mfree(c
->root_hash
);
1745 c
->root_hash_size
= 0;
1749 /* We have a roothash to decode, eg: RootHash=012345789abcdef */
1750 r
= unhexmem(rvalue
, strlen(rvalue
), &roothash_decoded
, &roothash_decoded_size
);
1752 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to decode RootHash=, ignoring: %s", rvalue
);
1755 if (roothash_decoded_size
< sizeof(sd_id128_t
)) {
1756 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "RootHash= is too short, ignoring: %s", rvalue
);
1760 free_and_replace(c
->root_hash
, roothash_decoded
);
1761 c
->root_hash_size
= roothash_decoded_size
;
1762 c
->root_hash_path
= mfree(c
->root_hash_path
);
1767 int config_parse_exec_root_hash_sig(
1769 const char *filename
,
1771 const char *section
,
1772 unsigned section_line
,
1779 _cleanup_free_
void *roothash_sig_decoded
= NULL
;
1781 ExecContext
*c
= data
;
1782 size_t roothash_sig_decoded_size
= 0;
1790 if (isempty(rvalue
)) {
1791 /* Reset if the empty string is assigned */
1792 c
->root_hash_sig_path
= mfree(c
->root_hash_sig_path
);
1793 c
->root_hash_sig
= mfree(c
->root_hash_sig
);
1794 c
->root_hash_sig_size
= 0;
1798 if (path_is_absolute(rvalue
)) {
1799 /* We have the path to a roothash signature to load and decode, eg: RootHashSignature=/foo/bar.roothash.p7s */
1800 _cleanup_free_
char *p
= NULL
;
1806 free_and_replace(c
->root_hash_sig_path
, p
);
1807 c
->root_hash_sig
= mfree(c
->root_hash_sig
);
1808 c
->root_hash_sig_size
= 0;
1812 if (!(value
= startswith(rvalue
, "base64:"))) {
1813 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
1814 "Failed to decode RootHashSignature=, not a path but doesn't start with 'base64:', ignoring: %s", rvalue
);
1818 /* We have a roothash signature to decode, eg: RootHashSignature=base64:012345789abcdef */
1819 r
= unbase64mem(value
, strlen(value
), &roothash_sig_decoded
, &roothash_sig_decoded_size
);
1821 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to decode RootHashSignature=, ignoring: %s", rvalue
);
1825 free_and_replace(c
->root_hash_sig
, roothash_sig_decoded
);
1826 c
->root_hash_sig_size
= roothash_sig_decoded_size
;
1827 c
->root_hash_sig_path
= mfree(c
->root_hash_sig_path
);
1832 int config_parse_exec_cpu_affinity(
1834 const char *filename
,
1836 const char *section
,
1837 unsigned section_line
,
1844 ExecContext
*c
= data
;
1845 const Unit
*u
= userdata
;
1846 _cleanup_free_
char *k
= NULL
;
1854 if (streq(rvalue
, "numa")) {
1855 c
->cpu_affinity_from_numa
= true;
1856 cpu_set_reset(&c
->cpu_set
);
1861 r
= unit_full_printf(u
, rvalue
, &k
);
1863 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1864 "Failed to resolve unit specifiers in '%s', ignoring: %m",
1869 r
= parse_cpu_set_extend(k
, &c
->cpu_set
, true, unit
, filename
, line
, lvalue
);
1871 c
->cpu_affinity_from_numa
= false;
1876 int config_parse_capability_set(
1878 const char *filename
,
1880 const char *section
,
1881 unsigned section_line
,
1888 uint64_t *capability_set
= data
;
1889 uint64_t sum
= 0, initial
= 0;
1890 bool invert
= false;
1898 if (rvalue
[0] == '~') {
1903 if (streq(lvalue
, "CapabilityBoundingSet"))
1904 initial
= CAP_ALL
; /* initialized to all bits on */
1905 /* else "AmbientCapabilities" initialized to all bits off */
1907 r
= capability_set_from_string(rvalue
, &sum
);
1909 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= specifier '%s', ignoring: %m", lvalue
, rvalue
);
1913 if (sum
== 0 || *capability_set
== initial
)
1914 /* "", "~" or uninitialized data -> replace */
1915 *capability_set
= invert
? ~sum
: sum
;
1917 /* previous data -> merge */
1919 *capability_set
&= ~sum
;
1921 *capability_set
|= sum
;
1927 int config_parse_exec_selinux_context(
1929 const char *filename
,
1931 const char *section
,
1932 unsigned section_line
,
1939 ExecContext
*c
= data
;
1940 const Unit
*u
= userdata
;
1950 if (isempty(rvalue
)) {
1951 c
->selinux_context
= mfree(c
->selinux_context
);
1952 c
->selinux_context_ignore
= false;
1956 if (rvalue
[0] == '-') {
1962 r
= unit_full_printf(u
, rvalue
, &k
);
1964 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
1965 "Failed to resolve unit specifiers in '%s'%s: %m",
1966 rvalue
, ignore
? ", ignoring" : "");
1967 return ignore
? 0 : -ENOEXEC
;
1970 free_and_replace(c
->selinux_context
, k
);
1971 c
->selinux_context_ignore
= ignore
;
1976 int config_parse_exec_apparmor_profile(
1978 const char *filename
,
1980 const char *section
,
1981 unsigned section_line
,
1988 ExecContext
*c
= data
;
1989 const Unit
*u
= userdata
;
1999 if (isempty(rvalue
)) {
2000 c
->apparmor_profile
= mfree(c
->apparmor_profile
);
2001 c
->apparmor_profile_ignore
= false;
2005 if (rvalue
[0] == '-') {
2011 r
= unit_full_printf(u
, rvalue
, &k
);
2013 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
2014 "Failed to resolve unit specifiers in '%s'%s: %m",
2015 rvalue
, ignore
? ", ignoring" : "");
2016 return ignore
? 0 : -ENOEXEC
;
2019 free_and_replace(c
->apparmor_profile
, k
);
2020 c
->apparmor_profile_ignore
= ignore
;
2025 int config_parse_exec_smack_process_label(
2027 const char *filename
,
2029 const char *section
,
2030 unsigned section_line
,
2037 ExecContext
*c
= data
;
2038 const Unit
*u
= userdata
;
2048 if (isempty(rvalue
)) {
2049 c
->smack_process_label
= mfree(c
->smack_process_label
);
2050 c
->smack_process_label_ignore
= false;
2054 if (rvalue
[0] == '-') {
2060 r
= unit_full_printf(u
, rvalue
, &k
);
2062 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
2063 "Failed to resolve unit specifiers in '%s'%s: %m",
2064 rvalue
, ignore
? ", ignoring" : "");
2065 return ignore
? 0 : -ENOEXEC
;
2068 free_and_replace(c
->smack_process_label
, k
);
2069 c
->smack_process_label_ignore
= ignore
;
2074 int config_parse_timer(
2076 const char *filename
,
2078 const char *section
,
2079 unsigned section_line
,
2086 _cleanup_(calendar_spec_freep
) CalendarSpec
*c
= NULL
;
2087 _cleanup_free_
char *k
= NULL
;
2088 const Unit
*u
= userdata
;
2099 if (isempty(rvalue
)) {
2100 /* Empty assignment resets list */
2101 timer_free_values(t
);
2105 r
= unit_full_printf(u
, rvalue
, &k
);
2107 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2111 if (ltype
== TIMER_CALENDAR
) {
2112 r
= calendar_spec_from_string(k
, &c
);
2114 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse calendar specification, ignoring: %s", k
);
2118 r
= parse_sec(k
, &usec
);
2120 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse timer value, ignoring: %s", k
);
2125 v
= new(TimerValue
, 1);
2132 .calendar_spec
= TAKE_PTR(c
),
2135 LIST_PREPEND(value
, t
->values
, v
);
2140 int config_parse_trigger_unit(
2142 const char *filename
,
2144 const char *section
,
2145 unsigned section_line
,
2152 _cleanup_free_
char *p
= NULL
;
2162 if (UNIT_TRIGGER(u
)) {
2163 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Multiple units to trigger specified, ignoring: %s", rvalue
);
2167 r
= unit_name_printf(u
, rvalue
, &p
);
2169 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2173 type
= unit_name_to_type(p
);
2175 log_syntax(unit
, LOG_WARNING
, filename
, line
, type
, "Unit type not valid, ignoring: %s", rvalue
);
2178 if (unit_has_name(u
, p
)) {
2179 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Units cannot trigger themselves, ignoring: %s", rvalue
);
2183 r
= unit_add_two_dependencies_by_name(u
, UNIT_BEFORE
, UNIT_TRIGGERS
, p
, true, UNIT_DEPENDENCY_FILE
);
2185 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add trigger on %s, ignoring: %m", p
);
2192 int config_parse_path_spec(const char *unit
,
2193 const char *filename
,
2195 const char *section
,
2196 unsigned section_line
,
2206 _cleanup_free_
char *k
= NULL
;
2214 if (isempty(rvalue
)) {
2215 /* Empty assignment clears list */
2220 b
= path_type_from_string(lvalue
);
2222 log_syntax(unit
, LOG_WARNING
, filename
, line
, b
, "Failed to parse path type, ignoring: %s", lvalue
);
2226 r
= unit_path_printf(UNIT(p
), rvalue
, &k
);
2228 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2232 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2236 s
= new0(PathSpec
, 1);
2241 s
->path
= TAKE_PTR(k
);
2245 LIST_PREPEND(spec
, p
->specs
, s
);
2250 int config_parse_socket_service(
2252 const char *filename
,
2254 const char *section
,
2255 unsigned section_line
,
2262 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
2263 _cleanup_free_
char *p
= NULL
;
2273 r
= unit_name_printf(UNIT(s
), rvalue
, &p
);
2275 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2279 if (!endswith(p
, ".service")) {
2280 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Unit must be of type service, ignoring: %s", rvalue
);
2284 r
= manager_load_unit(UNIT(s
)->manager
, p
, NULL
, &error
, &x
);
2286 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to load unit %s, ignoring: %s", rvalue
, bus_error_message(&error
, r
));
2290 unit_ref_set(&s
->service
, UNIT(s
), x
);
2295 int config_parse_fdname(
2297 const char *filename
,
2299 const char *section
,
2300 unsigned section_line
,
2307 _cleanup_free_
char *p
= NULL
;
2316 if (isempty(rvalue
)) {
2317 s
->fdname
= mfree(s
->fdname
);
2321 r
= unit_fd_printf(UNIT(s
), rvalue
, &p
);
2323 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2327 if (!fdname_is_valid(p
)) {
2328 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", p
);
2332 return free_and_replace(s
->fdname
, p
);
2335 int config_parse_service_sockets(
2337 const char *filename
,
2339 const char *section
,
2340 unsigned section_line
,
2355 for (const char *p
= rvalue
;;) {
2356 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2358 r
= extract_first_word(&p
, &word
, NULL
, 0);
2362 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Trailing garbage in sockets, ignoring: %s", rvalue
);
2368 r
= unit_name_printf(UNIT(s
), word
, &k
);
2370 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
2374 if (!endswith(k
, ".socket")) {
2375 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Unit must be of type socket, ignoring: %s", k
);
2379 r
= unit_add_two_dependencies_by_name(UNIT(s
), UNIT_WANTS
, UNIT_AFTER
, k
, true, UNIT_DEPENDENCY_FILE
);
2381 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
2383 r
= unit_add_dependency_by_name(UNIT(s
), UNIT_TRIGGERED_BY
, k
, true, UNIT_DEPENDENCY_FILE
);
2385 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
2389 int config_parse_bus_name(
2391 const char *filename
,
2393 const char *section
,
2394 unsigned section_line
,
2401 _cleanup_free_
char *k
= NULL
;
2402 const Unit
*u
= userdata
;
2410 r
= unit_full_printf_full(u
, rvalue
, SD_BUS_MAXIMUM_NAME_LENGTH
, &k
);
2412 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2416 if (!sd_bus_service_name_is_valid(k
)) {
2417 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid bus name, ignoring: %s", k
);
2421 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
2424 int config_parse_service_timeout(
2426 const char *filename
,
2428 const char *section
,
2429 unsigned section_line
,
2436 Service
*s
= userdata
;
2445 /* This is called for two cases: TimeoutSec= and TimeoutStartSec=. */
2447 /* Traditionally, these options accepted 0 to disable the timeouts. However, a timeout of 0 suggests it happens
2448 * immediately, hence fix this to become USEC_INFINITY instead. This is in-line with how we internally handle
2449 * all other timeouts. */
2450 r
= parse_sec_fix_0(rvalue
, &usec
);
2452 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
2456 s
->start_timeout_defined
= true;
2457 s
->timeout_start_usec
= usec
;
2459 if (streq(lvalue
, "TimeoutSec"))
2460 s
->timeout_stop_usec
= usec
;
2465 int config_parse_timeout_abort(
2467 const char *filename
,
2469 const char *section
,
2470 unsigned section_line
,
2485 /* Note: apart from setting the arg, this returns an extra bit of information in the return value. */
2487 if (isempty(rvalue
)) {
2489 return 0; /* "not set" */
2492 r
= parse_sec(rvalue
, ret
);
2494 return log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= setting, ignoring: %s", lvalue
, rvalue
);
2496 return 1; /* "set" */
2499 int config_parse_service_timeout_abort(
2501 const char *filename
,
2503 const char *section
,
2504 unsigned section_line
,
2511 Service
*s
= userdata
;
2516 r
= config_parse_timeout_abort(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
,
2517 &s
->timeout_abort_usec
, s
);
2519 s
->timeout_abort_set
= r
;
2523 int config_parse_sec_fix_0(
2525 const char *filename
,
2527 const char *section
,
2528 unsigned section_line
,
2535 usec_t
*usec
= data
;
2543 /* This is pretty much like config_parse_sec(), except that this treats a time of 0 as infinity, for
2544 * compatibility with older versions of systemd where 0 instead of infinity was used as indicator to turn off a
2547 r
= parse_sec_fix_0(rvalue
, usec
);
2549 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
2554 int config_parse_user_group_compat(
2556 const char *filename
,
2558 const char *section
,
2559 unsigned section_line
,
2566 _cleanup_free_
char *k
= NULL
;
2568 const Unit
*u
= userdata
;
2576 if (isempty(rvalue
)) {
2577 *user
= mfree(*user
);
2581 r
= unit_full_printf(u
, rvalue
, &k
);
2583 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", rvalue
);
2587 if (!valid_user_group_name(k
, VALID_USER_ALLOW_NUMERIC
|VALID_USER_RELAX
|VALID_USER_WARN
)) {
2588 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2592 if (strstr(lvalue
, "User") && streq(k
, NOBODY_USER_NAME
))
2593 log_struct(LOG_NOTICE
,
2594 "MESSAGE=%s:%u: Special user %s configured, this is not safe!", filename
, line
, k
,
2596 "MESSAGE_ID=" SD_MESSAGE_NOBODY_USER_UNSUITABLE_STR
,
2597 "OFFENDING_USER=%s", k
,
2598 "CONFIG_FILE=%s", filename
,
2599 "CONFIG_LINE=%u", line
);
2601 return free_and_replace(*user
, k
);
2604 int config_parse_user_group_strv_compat(
2606 const char *filename
,
2608 const char *section
,
2609 unsigned section_line
,
2616 char ***users
= data
;
2617 const Unit
*u
= userdata
;
2625 if (isempty(rvalue
)) {
2626 *users
= strv_free(*users
);
2630 for (const char *p
= rvalue
;;) {
2631 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2633 r
= extract_first_word(&p
, &word
, NULL
, 0);
2637 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax: %s", rvalue
);
2643 r
= unit_full_printf(u
, word
, &k
);
2645 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", word
);
2649 if (!valid_user_group_name(k
, VALID_USER_ALLOW_NUMERIC
|VALID_USER_RELAX
|VALID_USER_WARN
)) {
2650 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2654 r
= strv_push(users
, k
);
2662 int config_parse_working_directory(
2664 const char *filename
,
2666 const char *section
,
2667 unsigned section_line
,
2674 ExecContext
*c
= data
;
2675 const Unit
*u
= userdata
;
2685 if (isempty(rvalue
)) {
2686 c
->working_directory_home
= false;
2687 c
->working_directory
= mfree(c
->working_directory
);
2691 if (rvalue
[0] == '-') {
2697 if (streq(rvalue
, "~")) {
2698 c
->working_directory_home
= true;
2699 c
->working_directory
= mfree(c
->working_directory
);
2701 _cleanup_free_
char *k
= NULL
;
2703 r
= unit_path_printf(u
, rvalue
, &k
);
2705 log_syntax(unit
, missing_ok
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
2706 "Failed to resolve unit specifiers in working directory path '%s'%s: %m",
2707 rvalue
, missing_ok
? ", ignoring" : "");
2708 return missing_ok
? 0 : -ENOEXEC
;
2711 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
| (missing_ok
? 0 : PATH_CHECK_FATAL
), unit
, filename
, line
, lvalue
);
2713 return missing_ok
? 0 : -ENOEXEC
;
2715 c
->working_directory_home
= false;
2716 free_and_replace(c
->working_directory
, k
);
2719 c
->working_directory_missing_ok
= missing_ok
;
2723 int config_parse_unit_env_file(const char *unit
,
2724 const char *filename
,
2726 const char *section
,
2727 unsigned section_line
,
2735 const Unit
*u
= userdata
;
2736 _cleanup_free_
char *n
= NULL
;
2744 if (isempty(rvalue
)) {
2745 /* Empty assignment frees the list */
2746 *env
= strv_free(*env
);
2750 r
= unit_full_printf_full(u
, rvalue
, PATH_MAX
, &n
);
2752 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2756 r
= path_simplify_and_warn(n
[0] == '-' ? n
+ 1 : n
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2760 r
= strv_push(env
, n
);
2769 int config_parse_environ(
2771 const char *filename
,
2773 const char *section
,
2774 unsigned section_line
,
2781 const Unit
*u
= userdata
;
2790 if (isempty(rvalue
)) {
2791 /* Empty assignment resets the list */
2792 *env
= strv_free(*env
);
2796 for (const char *p
= rvalue
;; ) {
2797 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
2799 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2803 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2804 "Invalid syntax, ignoring: %s", rvalue
);
2811 r
= unit_env_printf(u
, word
, &resolved
);
2813 r
= specifier_printf(word
, sc_arg_max(), system_and_tmp_specifier_table
, NULL
, NULL
, &resolved
);
2815 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2816 "Failed to resolve specifiers in %s, ignoring: %m", word
);
2820 if (!env_assignment_is_valid(resolved
)) {
2821 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
2822 "Invalid environment assignment, ignoring: %s", resolved
);
2826 r
= strv_env_replace_consume(env
, TAKE_PTR(resolved
));
2828 return log_error_errno(r
, "Failed to update environment: %m");
2832 int config_parse_pass_environ(
2834 const char *filename
,
2836 const char *section
,
2837 unsigned section_line
,
2844 _cleanup_strv_free_
char **n
= NULL
;
2845 const Unit
*u
= userdata
;
2846 char*** passenv
= data
;
2855 if (isempty(rvalue
)) {
2856 /* Empty assignment resets the list */
2857 *passenv
= strv_free(*passenv
);
2861 for (const char *p
= rvalue
;;) {
2862 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2864 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
2868 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2869 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2876 r
= unit_env_printf(u
, word
, &k
);
2878 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2879 "Failed to resolve specifiers in %s, ignoring: %m", word
);
2885 if (!env_name_is_valid(k
)) {
2886 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
2887 "Invalid environment name for %s, ignoring: %s", lvalue
, k
);
2891 if (!GREEDY_REALLOC(n
, nlen
+ 2))
2894 n
[nlen
++] = TAKE_PTR(k
);
2899 r
= strv_extend_strv(passenv
, n
, true);
2907 int config_parse_unset_environ(
2909 const char *filename
,
2911 const char *section
,
2912 unsigned section_line
,
2919 _cleanup_strv_free_
char **n
= NULL
;
2920 char*** unsetenv
= data
;
2921 const Unit
*u
= userdata
;
2930 if (isempty(rvalue
)) {
2931 /* Empty assignment resets the list */
2932 *unsetenv
= strv_free(*unsetenv
);
2936 for (const char *p
= rvalue
;;) {
2937 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2939 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2943 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2944 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2951 r
= unit_env_printf(u
, word
, &k
);
2953 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2954 "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2960 if (!env_assignment_is_valid(k
) && !env_name_is_valid(k
)) {
2961 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
2962 "Invalid environment name or assignment %s, ignoring: %s", lvalue
, k
);
2966 if (!GREEDY_REALLOC(n
, nlen
+ 2))
2969 n
[nlen
++] = TAKE_PTR(k
);
2974 r
= strv_extend_strv(unsetenv
, n
, true);
2982 int config_parse_log_extra_fields(
2984 const char *filename
,
2986 const char *section
,
2987 unsigned section_line
,
2994 ExecContext
*c
= data
;
2995 const Unit
*u
= userdata
;
3003 if (isempty(rvalue
)) {
3004 exec_context_free_log_extra_fields(c
);
3008 for (const char *p
= rvalue
;;) {
3009 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
3013 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
3017 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3023 r
= unit_full_printf(u
, word
, &k
);
3025 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
3029 eq
= strchr(k
, '=');
3031 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Log field lacks '=' character, ignoring: %s", k
);
3035 if (!journal_field_valid(k
, eq
-k
, false)) {
3036 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Log field name is invalid, ignoring: %s", k
);
3040 t
= reallocarray(c
->log_extra_fields
, c
->n_log_extra_fields
+1, sizeof(struct iovec
));
3044 c
->log_extra_fields
= t
;
3045 c
->log_extra_fields
[c
->n_log_extra_fields
++] = IOVEC_MAKE_STRING(k
);
3051 int config_parse_log_namespace(
3053 const char *filename
,
3055 const char *section
,
3056 unsigned section_line
,
3063 _cleanup_free_
char *k
= NULL
;
3064 ExecContext
*c
= data
;
3065 const Unit
*u
= userdata
;
3073 if (isempty(rvalue
)) {
3074 c
->log_namespace
= mfree(c
->log_namespace
);
3078 r
= unit_full_printf_full(u
, rvalue
, NAME_MAX
, &k
);
3080 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
3084 if (!log_namespace_name_valid(k
)) {
3085 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Specified log namespace name is not valid, ignoring: %s", k
);
3089 free_and_replace(c
->log_namespace
, k
);
3093 int config_parse_unit_condition_path(
3095 const char *filename
,
3097 const char *section
,
3098 unsigned section_line
,
3105 _cleanup_free_
char *p
= NULL
;
3106 Condition
**list
= data
, *c
;
3107 ConditionType t
= ltype
;
3108 bool trigger
, negate
;
3109 const Unit
*u
= userdata
;
3117 if (isempty(rvalue
)) {
3118 /* Empty assignment resets the list */
3119 *list
= condition_free_list(*list
);
3123 trigger
= rvalue
[0] == '|';
3127 negate
= rvalue
[0] == '!';
3131 r
= unit_path_printf(u
, rvalue
, &p
);
3133 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
3137 r
= path_simplify_and_warn(p
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
3141 c
= condition_new(t
, p
, trigger
, negate
);
3145 LIST_PREPEND(conditions
, *list
, c
);
3149 int config_parse_unit_condition_string(
3151 const char *filename
,
3153 const char *section
,
3154 unsigned section_line
,
3161 _cleanup_free_
char *s
= NULL
;
3162 Condition
**list
= data
, *c
;
3163 ConditionType t
= ltype
;
3164 bool trigger
, negate
;
3165 const Unit
*u
= userdata
;
3173 if (isempty(rvalue
)) {
3174 /* Empty assignment resets the list */
3175 *list
= condition_free_list(*list
);
3179 trigger
= *rvalue
== '|';
3181 rvalue
+= 1 + strspn(rvalue
+ 1, WHITESPACE
);
3183 negate
= *rvalue
== '!';
3185 rvalue
+= 1 + strspn(rvalue
+ 1, WHITESPACE
);
3187 r
= unit_full_printf(u
, rvalue
, &s
);
3189 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3190 "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
3194 c
= condition_new(t
, s
, trigger
, negate
);
3198 LIST_PREPEND(conditions
, *list
, c
);
3202 int config_parse_unit_requires_mounts_for(
3204 const char *filename
,
3206 const char *section
,
3207 unsigned section_line
,
3222 for (const char *p
= rvalue
;;) {
3223 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
3225 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3229 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3230 "Invalid syntax, ignoring: %s", rvalue
);
3236 r
= unit_path_printf(u
, word
, &resolved
);
3238 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
3242 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
3246 r
= unit_require_mounts_for(u
, resolved
, UNIT_DEPENDENCY_FILE
);
3248 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add required mount '%s', ignoring: %m", resolved
);
3254 int config_parse_documentation(
3256 const char *filename
,
3258 const char *section
,
3259 unsigned section_line
,
3275 if (isempty(rvalue
)) {
3276 /* Empty assignment resets the list */
3277 u
->documentation
= strv_free(u
->documentation
);
3281 r
= config_parse_unit_strv_printf(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
,
3282 rvalue
, data
, userdata
);
3286 for (a
= b
= u
->documentation
; a
&& *a
; a
++) {
3288 if (documentation_url_is_valid(*a
))
3291 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid URL, ignoring: %s", *a
);
3302 int config_parse_syscall_filter(
3304 const char *filename
,
3306 const char *section
,
3307 unsigned section_line
,
3314 ExecContext
*c
= data
;
3315 _unused_
const Unit
*u
= userdata
;
3316 bool invert
= false;
3324 if (isempty(rvalue
)) {
3325 /* Empty assignment resets the list */
3326 c
->syscall_filter
= hashmap_free(c
->syscall_filter
);
3327 c
->syscall_allow_list
= false;
3331 if (rvalue
[0] == '~') {
3336 if (!c
->syscall_filter
) {
3337 c
->syscall_filter
= hashmap_new(NULL
);
3338 if (!c
->syscall_filter
)
3342 /* Allow everything but the ones listed */
3343 c
->syscall_allow_list
= false;
3345 /* Allow nothing but the ones listed */
3346 c
->syscall_allow_list
= true;
3348 /* Accept default syscalls if we are on an allow_list */
3349 r
= seccomp_parse_syscall_filter(
3350 "@default", -1, c
->syscall_filter
,
3351 SECCOMP_PARSE_PERMISSIVE
|SECCOMP_PARSE_ALLOW_LIST
,
3359 for (const char *p
= rvalue
;;) {
3360 _cleanup_free_
char *word
= NULL
, *name
= NULL
;
3363 r
= extract_first_word(&p
, &word
, NULL
, 0);
3367 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3368 "Invalid syntax, ignoring: %s", rvalue
);
3374 r
= parse_syscall_and_errno(word
, &name
, &num
);
3376 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3377 "Failed to parse syscall:errno, ignoring: %s", word
);
3380 if (!invert
&& num
>= 0) {
3381 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3382 "Allow-listed system calls cannot take error number, ignoring: %s", word
);
3386 r
= seccomp_parse_syscall_filter(
3387 name
, num
, c
->syscall_filter
,
3388 SECCOMP_PARSE_LOG
|SECCOMP_PARSE_PERMISSIVE
|
3389 (invert
? SECCOMP_PARSE_INVERT
: 0)|
3390 (c
->syscall_allow_list
? SECCOMP_PARSE_ALLOW_LIST
: 0),
3391 unit
, filename
, line
);
3397 int config_parse_syscall_log(
3399 const char *filename
,
3401 const char *section
,
3402 unsigned section_line
,
3409 ExecContext
*c
= data
;
3410 _unused_
const Unit
*u
= userdata
;
3411 bool invert
= false;
3420 if (isempty(rvalue
)) {
3421 /* Empty assignment resets the list */
3422 c
->syscall_log
= hashmap_free(c
->syscall_log
);
3423 c
->syscall_log_allow_list
= false;
3427 if (rvalue
[0] == '~') {
3432 if (!c
->syscall_log
) {
3433 c
->syscall_log
= hashmap_new(NULL
);
3434 if (!c
->syscall_log
)
3438 /* Log everything but the ones listed */
3439 c
->syscall_log_allow_list
= false;
3441 /* Log nothing but the ones listed */
3442 c
->syscall_log_allow_list
= true;
3447 _cleanup_free_
char *word
= NULL
;
3449 r
= extract_first_word(&p
, &word
, NULL
, 0);
3453 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3459 r
= seccomp_parse_syscall_filter(
3460 word
, -1, c
->syscall_log
,
3461 SECCOMP_PARSE_LOG
|SECCOMP_PARSE_PERMISSIVE
|
3462 (invert
? SECCOMP_PARSE_INVERT
: 0)|
3463 (c
->syscall_log_allow_list
? SECCOMP_PARSE_ALLOW_LIST
: 0),
3464 unit
, filename
, line
);
3470 int config_parse_syscall_archs(
3472 const char *filename
,
3474 const char *section
,
3475 unsigned section_line
,
3485 if (isempty(rvalue
)) {
3486 *archs
= set_free(*archs
);
3490 for (const char *p
= rvalue
;;) {
3491 _cleanup_free_
char *word
= NULL
;
3494 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3498 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3499 "Invalid syntax, ignoring: %s", rvalue
);
3505 r
= seccomp_arch_from_string(word
, &a
);
3507 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3508 "Failed to parse system call architecture \"%s\", ignoring: %m", word
);
3512 r
= set_ensure_put(archs
, NULL
, UINT32_TO_PTR(a
+ 1));
3518 int config_parse_syscall_errno(
3520 const char *filename
,
3522 const char *section
,
3523 unsigned section_line
,
3530 ExecContext
*c
= data
;
3537 if (isempty(rvalue
) || streq(rvalue
, "kill")) {
3538 /* Empty assignment resets to KILL */
3539 c
->syscall_errno
= SECCOMP_ERROR_NUMBER_KILL
;
3543 e
= parse_errno(rvalue
);
3545 log_syntax(unit
, LOG_WARNING
, filename
, line
, e
, "Failed to parse error number, ignoring: %s", rvalue
);
3549 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid error number, ignoring: %s", rvalue
);
3553 c
->syscall_errno
= e
;
3557 int config_parse_address_families(
3559 const char *filename
,
3561 const char *section
,
3562 unsigned section_line
,
3569 ExecContext
*c
= data
;
3570 bool invert
= false;
3577 if (isempty(rvalue
)) {
3578 /* Empty assignment resets the list */
3579 c
->address_families
= set_free(c
->address_families
);
3580 c
->address_families_allow_list
= false;
3584 if (streq(rvalue
, "none")) {
3585 /* Forbid all address families. */
3586 c
->address_families
= set_free(c
->address_families
);
3587 c
->address_families_allow_list
= true;
3591 if (rvalue
[0] == '~') {
3596 if (!c
->address_families
) {
3597 c
->address_families
= set_new(NULL
);
3598 if (!c
->address_families
)
3601 c
->address_families_allow_list
= !invert
;
3604 for (const char *p
= rvalue
;;) {
3605 _cleanup_free_
char *word
= NULL
;
3608 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3612 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3613 "Invalid syntax, ignoring: %s", rvalue
);
3619 af
= af_from_name(word
);
3621 log_syntax(unit
, LOG_WARNING
, filename
, line
, af
,
3622 "Failed to parse address family, ignoring: %s", word
);
3626 /* If we previously wanted to forbid an address family and now
3627 * we want to allow it, then just remove it from the list.
3629 if (!invert
== c
->address_families_allow_list
) {
3630 r
= set_put(c
->address_families
, INT_TO_PTR(af
));
3634 set_remove(c
->address_families
, INT_TO_PTR(af
));
3638 int config_parse_restrict_namespaces(
3640 const char *filename
,
3642 const char *section
,
3643 unsigned section_line
,
3650 ExecContext
*c
= data
;
3651 unsigned long flags
;
3652 bool invert
= false;
3655 if (isempty(rvalue
)) {
3656 /* Reset to the default. */
3657 c
->restrict_namespaces
= NAMESPACE_FLAGS_INITIAL
;
3661 /* Boolean parameter ignores the previous settings */
3662 r
= parse_boolean(rvalue
);
3664 c
->restrict_namespaces
= 0;
3666 } else if (r
== 0) {
3667 c
->restrict_namespaces
= NAMESPACE_FLAGS_ALL
;
3671 if (rvalue
[0] == '~') {
3676 /* Not a boolean argument, in this case it's a list of namespace types. */
3677 r
= namespace_flags_from_string(rvalue
, &flags
);
3679 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse namespace type string, ignoring: %s", rvalue
);
3683 if (c
->restrict_namespaces
== NAMESPACE_FLAGS_INITIAL
)
3684 /* Initial assignment. Just set the value. */
3685 c
->restrict_namespaces
= invert
? (~flags
) & NAMESPACE_FLAGS_ALL
: flags
;
3687 /* Merge the value with the previous one. */
3688 SET_FLAG(c
->restrict_namespaces
, flags
, !invert
);
3694 int config_parse_restrict_filesystems(
3696 const char *filename
,
3698 const char *section
,
3699 unsigned section_line
,
3705 ExecContext
*c
= data
;
3706 bool invert
= false;
3714 if (isempty(rvalue
)) {
3715 /* Empty assignment resets the list */
3716 c
->restrict_filesystems
= set_free(c
->restrict_filesystems
);
3717 c
->restrict_filesystems_allow_list
= false;
3721 if (rvalue
[0] == '~') {
3726 if (!c
->restrict_filesystems
) {
3728 /* Allow everything but the ones listed */
3729 c
->restrict_filesystems_allow_list
= false;
3731 /* Allow nothing but the ones listed */
3732 c
->restrict_filesystems_allow_list
= true;
3735 for (const char *p
= rvalue
;;) {
3736 _cleanup_free_
char *word
= NULL
;
3738 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3744 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3745 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
3749 r
= lsm_bpf_parse_filesystem(
3751 &c
->restrict_filesystems
,
3752 FILESYSTEM_PARSE_LOG
|
3753 (invert
? FILESYSTEM_PARSE_INVERT
: 0)|
3754 (c
->restrict_filesystems_allow_list
? FILESYSTEM_PARSE_ALLOW_LIST
: 0),
3755 unit
, filename
, line
);
3764 int config_parse_unit_slice(
3766 const char *filename
,
3768 const char *section
,
3769 unsigned section_line
,
3776 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
3777 _cleanup_free_
char *k
= NULL
;
3778 Unit
*u
= userdata
, *slice
;
3786 r
= unit_name_printf(u
, rvalue
, &k
);
3788 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
3792 r
= manager_load_unit(u
->manager
, k
, NULL
, &error
, &slice
);
3794 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to load slice unit %s, ignoring: %s", k
, bus_error_message(&error
, r
));
3798 r
= unit_set_slice(u
, slice
);
3800 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to assign slice %s to unit %s, ignoring: %m", slice
->id
, u
->id
);
3807 int config_parse_cpu_quota(
3809 const char *filename
,
3811 const char *section
,
3812 unsigned section_line
,
3819 CGroupContext
*c
= data
;
3826 if (isempty(rvalue
)) {
3827 c
->cpu_quota_per_sec_usec
= USEC_INFINITY
;
3831 r
= parse_permyriad_unbounded(rvalue
);
3833 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid CPU quota '%s', ignoring.", rvalue
);
3837 c
->cpu_quota_per_sec_usec
= ((usec_t
) r
* USEC_PER_SEC
) / 10000U;
3841 int config_parse_allowed_cpuset(
3843 const char *filename
,
3845 const char *section
,
3846 unsigned section_line
,
3855 (void) parse_cpu_set_extend(rvalue
, c
, true, unit
, filename
, line
, lvalue
);
3859 int config_parse_memory_limit(
3861 const char *filename
,
3863 const char *section
,
3864 unsigned section_line
,
3871 CGroupContext
*c
= data
;
3872 uint64_t bytes
= CGROUP_LIMIT_MAX
;
3875 if (isempty(rvalue
) && STR_IN_SET(lvalue
, "DefaultMemoryLow",
3879 bytes
= CGROUP_LIMIT_MIN
;
3880 else if (!isempty(rvalue
) && !streq(rvalue
, "infinity")) {
3882 r
= parse_permyriad(rvalue
);
3884 r
= parse_size(rvalue
, 1024, &bytes
);
3886 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid memory limit '%s', ignoring: %m", rvalue
);
3890 bytes
= physical_memory_scale(r
, 10000U);
3892 if (bytes
>= UINT64_MAX
||
3893 (bytes
<= 0 && !STR_IN_SET(lvalue
, "MemorySwapMax", "MemoryLow", "MemoryMin", "DefaultMemoryLow", "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
, "DefaultMemoryMin")) {
3903 c
->default_memory_min
= bytes
;
3904 c
->default_memory_min_set
= true;
3905 } else if (streq(lvalue
, "MemoryMin")) {
3906 c
->memory_min
= bytes
;
3907 c
->memory_min_set
= true;
3908 } else if (streq(lvalue
, "MemoryLow")) {
3909 c
->memory_low
= bytes
;
3910 c
->memory_low_set
= true;
3911 } else if (streq(lvalue
, "MemoryHigh"))
3912 c
->memory_high
= bytes
;
3913 else if (streq(lvalue
, "MemoryMax"))
3914 c
->memory_max
= bytes
;
3915 else if (streq(lvalue
, "MemorySwapMax"))
3916 c
->memory_swap_max
= bytes
;
3917 else if (streq(lvalue
, "MemoryLimit"))
3918 c
->memory_limit
= bytes
;
3925 int config_parse_tasks_max(
3927 const char *filename
,
3929 const char *section
,
3930 unsigned section_line
,
3937 const Unit
*u
= userdata
;
3938 TasksMax
*tasks_max
= data
;
3942 if (isempty(rvalue
)) {
3943 *tasks_max
= u
? u
->manager
->default_tasks_max
: TASKS_MAX_UNSET
;
3947 if (streq(rvalue
, "infinity")) {
3948 *tasks_max
= TASKS_MAX_UNSET
;
3952 r
= parse_permyriad(rvalue
);
3954 *tasks_max
= (TasksMax
) { r
, 10000U }; /* r‱ */
3956 r
= safe_atou64(rvalue
, &v
);
3958 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid maximum tasks value '%s', ignoring: %m", rvalue
);
3962 if (v
<= 0 || v
>= UINT64_MAX
) {
3963 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Maximum tasks value '%s' out of range, ignoring.", rvalue
);
3967 *tasks_max
= (TasksMax
) { v
};
3973 int config_parse_delegate(
3975 const char *filename
,
3977 const char *section
,
3978 unsigned section_line
,
3985 CGroupContext
*c
= data
;
3989 t
= unit_name_to_type(unit
);
3990 assert(t
!= _UNIT_TYPE_INVALID
);
3992 if (!unit_vtable
[t
]->can_delegate
) {
3993 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Delegate= setting not supported for this unit type, ignoring.");
3997 /* We either accept a boolean value, which may be used to turn on delegation for all controllers, or turn it
3998 * off for all. Or it takes a list of controller names, in which case we add the specified controllers to the
3999 * mask to delegate. */
4001 if (isempty(rvalue
)) {
4002 /* An empty string resets controllers and set Delegate=yes. */
4004 c
->delegate_controllers
= 0;
4008 r
= parse_boolean(rvalue
);
4010 CGroupMask mask
= 0;
4012 for (const char *p
= rvalue
;;) {
4013 _cleanup_free_
char *word
= NULL
;
4014 CGroupController cc
;
4016 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
4020 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
4026 cc
= cgroup_controller_from_string(word
);
4028 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid controller name '%s', ignoring", word
);
4032 mask
|= CGROUP_CONTROLLER_TO_MASK(cc
);
4036 c
->delegate_controllers
|= mask
;
4040 c
->delegate_controllers
= _CGROUP_MASK_ALL
;
4042 c
->delegate
= false;
4043 c
->delegate_controllers
= 0;
4049 int config_parse_managed_oom_mode(
4051 const char *filename
,
4053 const char *section
,
4054 unsigned section_line
,
4061 ManagedOOMMode
*mode
= data
, m
;
4064 t
= unit_name_to_type(unit
);
4065 assert(t
!= _UNIT_TYPE_INVALID
);
4067 if (!unit_vtable
[t
]->can_set_managed_oom
)
4068 return log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "%s= is not supported for this unit type, ignoring.", lvalue
);
4070 if (isempty(rvalue
)) {
4071 *mode
= MANAGED_OOM_AUTO
;
4075 m
= managed_oom_mode_from_string(rvalue
);
4077 log_syntax(unit
, LOG_WARNING
, filename
, line
, m
, "Invalid syntax, ignoring: %s", rvalue
);
4085 int config_parse_managed_oom_mem_pressure_limit(
4087 const char *filename
,
4089 const char *section
,
4090 unsigned section_line
,
4097 uint32_t *limit
= data
;
4101 t
= unit_name_to_type(unit
);
4102 assert(t
!= _UNIT_TYPE_INVALID
);
4104 if (!unit_vtable
[t
]->can_set_managed_oom
)
4105 return log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "%s= is not supported for this unit type, ignoring.", lvalue
);
4107 if (isempty(rvalue
)) {
4112 r
= parse_permyriad(rvalue
);
4114 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse memory pressure limit value, ignoring: %s", rvalue
);
4118 /* Normalize to 2^32-1 == 100% */
4119 *limit
= UINT32_SCALE_FROM_PERMYRIAD(r
);
4123 int config_parse_device_allow(
4125 const char *filename
,
4127 const char *section
,
4128 unsigned section_line
,
4135 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4136 CGroupContext
*c
= data
;
4137 const char *p
= rvalue
;
4140 if (isempty(rvalue
)) {
4141 while (c
->device_allow
)
4142 cgroup_context_free_device_allow(c
, c
->device_allow
);
4147 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4151 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4152 "Failed to extract device path and rights from '%s', ignoring.", rvalue
);
4156 r
= unit_path_printf(userdata
, path
, &resolved
);
4158 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4159 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4163 if (!STARTSWITH_SET(resolved
, "block-", "char-")) {
4165 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4169 if (!valid_device_node_path(resolved
)) {
4170 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid device node path '%s', ignoring.", resolved
);
4175 if (!isempty(p
) && !in_charset(p
, "rwm")) {
4176 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid device rights '%s', ignoring.", p
);
4180 return cgroup_add_device_allow(c
, resolved
, p
);
4183 int config_parse_io_device_weight(
4185 const char *filename
,
4187 const char *section
,
4188 unsigned section_line
,
4195 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4196 CGroupIODeviceWeight
*w
;
4197 CGroupContext
*c
= data
;
4198 const char *p
= rvalue
;
4206 if (isempty(rvalue
)) {
4207 while (c
->io_device_weights
)
4208 cgroup_context_free_io_device_weight(c
, c
->io_device_weights
);
4213 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4217 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4218 "Failed to extract device path and weight from '%s', ignoring.", rvalue
);
4221 if (r
== 0 || isempty(p
)) {
4222 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4223 "Invalid device path or weight specified in '%s', ignoring.", rvalue
);
4227 r
= unit_path_printf(userdata
, path
, &resolved
);
4229 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4230 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4234 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4238 r
= cg_weight_parse(p
, &u
);
4240 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "IO weight '%s' invalid, ignoring: %m", p
);
4244 assert(u
!= CGROUP_WEIGHT_INVALID
);
4246 w
= new0(CGroupIODeviceWeight
, 1);
4250 w
->path
= TAKE_PTR(resolved
);
4253 LIST_PREPEND(device_weights
, c
->io_device_weights
, w
);
4257 int config_parse_io_device_latency(
4259 const char *filename
,
4261 const char *section
,
4262 unsigned section_line
,
4269 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4270 CGroupIODeviceLatency
*l
;
4271 CGroupContext
*c
= data
;
4272 const char *p
= rvalue
;
4280 if (isempty(rvalue
)) {
4281 while (c
->io_device_latencies
)
4282 cgroup_context_free_io_device_latency(c
, c
->io_device_latencies
);
4287 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4291 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4292 "Failed to extract device path and latency from '%s', ignoring.", rvalue
);
4295 if (r
== 0 || isempty(p
)) {
4296 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4297 "Invalid device path or latency specified in '%s', ignoring.", rvalue
);
4301 r
= unit_path_printf(userdata
, path
, &resolved
);
4303 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4304 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4308 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4312 r
= parse_sec(p
, &usec
);
4314 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse timer value, ignoring: %s", p
);
4318 l
= new0(CGroupIODeviceLatency
, 1);
4322 l
->path
= TAKE_PTR(resolved
);
4323 l
->target_usec
= usec
;
4325 LIST_PREPEND(device_latencies
, c
->io_device_latencies
, l
);
4329 int config_parse_io_limit(
4331 const char *filename
,
4333 const char *section
,
4334 unsigned section_line
,
4341 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4342 CGroupIODeviceLimit
*l
= NULL
;
4343 CGroupContext
*c
= data
;
4344 CGroupIOLimitType type
;
4345 const char *p
= rvalue
;
4353 type
= cgroup_io_limit_type_from_string(lvalue
);
4356 if (isempty(rvalue
)) {
4357 LIST_FOREACH(device_limits
, t
, c
->io_device_limits
)
4358 t
->limits
[type
] = cgroup_io_limit_defaults
[type
];
4362 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4366 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4367 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
4370 if (r
== 0 || isempty(p
)) {
4371 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4372 "Invalid device node or bandwidth specified in '%s', ignoring.", rvalue
);
4376 r
= unit_path_printf(userdata
, path
, &resolved
);
4378 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4379 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4383 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4387 if (streq("infinity", p
))
4388 num
= CGROUP_LIMIT_MAX
;
4390 r
= parse_size(p
, 1000, &num
);
4391 if (r
< 0 || num
<= 0) {
4392 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid IO limit '%s', ignoring.", p
);
4397 LIST_FOREACH(device_limits
, t
, c
->io_device_limits
)
4398 if (path_equal(resolved
, t
->path
)) {
4404 CGroupIOLimitType ttype
;
4406 l
= new0(CGroupIODeviceLimit
, 1);
4410 l
->path
= TAKE_PTR(resolved
);
4411 for (ttype
= 0; ttype
< _CGROUP_IO_LIMIT_TYPE_MAX
; ttype
++)
4412 l
->limits
[ttype
] = cgroup_io_limit_defaults
[ttype
];
4414 LIST_PREPEND(device_limits
, c
->io_device_limits
, l
);
4417 l
->limits
[type
] = num
;
4422 int config_parse_blockio_device_weight(
4424 const char *filename
,
4426 const char *section
,
4427 unsigned section_line
,
4434 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4435 CGroupBlockIODeviceWeight
*w
;
4436 CGroupContext
*c
= data
;
4437 const char *p
= rvalue
;
4445 if (isempty(rvalue
)) {
4446 while (c
->blockio_device_weights
)
4447 cgroup_context_free_blockio_device_weight(c
, c
->blockio_device_weights
);
4452 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4456 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4457 "Failed to extract device node and weight from '%s', ignoring.", rvalue
);
4460 if (r
== 0 || isempty(p
)) {
4461 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4462 "Invalid device node or weight specified in '%s', ignoring.", rvalue
);
4466 r
= unit_path_printf(userdata
, path
, &resolved
);
4468 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4469 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4473 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4477 r
= cg_blkio_weight_parse(p
, &u
);
4479 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid block IO weight '%s', ignoring: %m", p
);
4483 assert(u
!= CGROUP_BLKIO_WEIGHT_INVALID
);
4485 w
= new0(CGroupBlockIODeviceWeight
, 1);
4489 w
->path
= TAKE_PTR(resolved
);
4492 LIST_PREPEND(device_weights
, c
->blockio_device_weights
, w
);
4496 int config_parse_blockio_bandwidth(
4498 const char *filename
,
4500 const char *section
,
4501 unsigned section_line
,
4508 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4509 CGroupBlockIODeviceBandwidth
*b
= NULL
;
4510 CGroupContext
*c
= data
;
4511 const char *p
= rvalue
;
4520 read
= streq("BlockIOReadBandwidth", lvalue
);
4522 if (isempty(rvalue
)) {
4523 LIST_FOREACH(device_bandwidths
, t
, c
->blockio_device_bandwidths
) {
4524 t
->rbps
= CGROUP_LIMIT_MAX
;
4525 t
->wbps
= CGROUP_LIMIT_MAX
;
4530 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4534 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4535 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
4538 if (r
== 0 || isempty(p
)) {
4539 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4540 "Invalid device node or bandwidth specified in '%s', ignoring.", rvalue
);
4544 r
= unit_path_printf(userdata
, path
, &resolved
);
4546 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4547 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4551 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4555 r
= parse_size(p
, 1000, &bytes
);
4556 if (r
< 0 || bytes
<= 0) {
4557 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid Block IO Bandwidth '%s', ignoring.", p
);
4561 LIST_FOREACH(device_bandwidths
, t
, c
->blockio_device_bandwidths
)
4562 if (path_equal(resolved
, t
->path
)) {
4568 b
= new0(CGroupBlockIODeviceBandwidth
, 1);
4572 b
->path
= TAKE_PTR(resolved
);
4573 b
->rbps
= CGROUP_LIMIT_MAX
;
4574 b
->wbps
= CGROUP_LIMIT_MAX
;
4576 LIST_PREPEND(device_bandwidths
, c
->blockio_device_bandwidths
, b
);
4587 int config_parse_job_mode_isolate(
4589 const char *filename
,
4591 const char *section
,
4592 unsigned section_line
,
4606 r
= parse_boolean(rvalue
);
4608 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse boolean, ignoring: %s", rvalue
);
4612 log_notice("%s is deprecated. Please use OnFailureJobMode= instead", lvalue
);
4614 *m
= r
? JOB_ISOLATE
: JOB_REPLACE
;
4618 int config_parse_exec_directories(
4620 const char *filename
,
4622 const char *section
,
4623 unsigned section_line
,
4630 ExecDirectory
*ed
= data
;
4631 const Unit
*u
= userdata
;
4639 if (isempty(rvalue
)) {
4640 /* Empty assignment resets the list */
4641 exec_directory_done(ed
);
4645 for (const char *p
= rvalue
;;) {
4646 _cleanup_free_
char *tuple
= NULL
;
4648 r
= extract_first_word(&p
, &tuple
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_RETAIN_ESCAPE
);
4652 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4653 "Invalid syntax %s=%s, ignoring: %m", lvalue
, rvalue
);
4659 _cleanup_free_
char *src
= NULL
, *dest
= NULL
;
4660 const char *q
= tuple
;
4661 r
= extract_many_words(&q
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
, &src
, &dest
, NULL
);
4665 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
?: SYNTHETIC_ERRNO(EINVAL
),
4666 "Invalid syntax in %s=, ignoring: %s", lvalue
, tuple
);
4670 _cleanup_free_
char *sresolved
= NULL
;
4671 r
= unit_path_printf(u
, src
, &sresolved
);
4673 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4674 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", src
);
4678 r
= path_simplify_and_warn(sresolved
, PATH_CHECK_RELATIVE
, unit
, filename
, line
, lvalue
);
4682 if (path_startswith(sresolved
, "private")) {
4683 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4684 "%s= path can't be 'private', ignoring assignment: %s", lvalue
, tuple
);
4688 /* For State and Runtime directories we support an optional destination parameter, which
4689 * will be used to create a symlink to the source. */
4690 _cleanup_strv_free_
char **symlinks
= NULL
;
4691 if (!isempty(dest
)) {
4692 _cleanup_free_
char *dresolved
= NULL
;
4694 if (streq(lvalue
, "ConfigurationDirectory")) {
4695 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4696 "Destination parameter is not supported for ConfigurationDirectory, ignoring: %s", tuple
);
4700 r
= unit_path_printf(u
, dest
, &dresolved
);
4702 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4703 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", dest
);
4707 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_RELATIVE
, unit
, filename
, line
, lvalue
);
4711 r
= strv_consume(&symlinks
, TAKE_PTR(dresolved
));
4716 r
= exec_directory_add(&ed
->items
, &ed
->n_items
, sresolved
, symlinks
);
4722 int config_parse_set_credential(
4724 const char *filename
,
4726 const char *section
,
4727 unsigned section_line
,
4734 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
4735 _cleanup_free_
void *d
= NULL
;
4736 ExecContext
*context
= data
;
4737 ExecSetCredential
*old
;
4739 bool encrypted
= ltype
;
4740 const char *p
= rvalue
;
4749 if (isempty(rvalue
)) {
4750 /* Empty assignment resets the list */
4751 context
->set_credentials
= hashmap_free(context
->set_credentials
);
4755 r
= extract_first_word(&p
, &word
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4759 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract credential name, ignoring: %s", rvalue
);
4762 if (r
== 0 || isempty(p
)) {
4763 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid syntax, ignoring: %s", rvalue
);
4767 r
= unit_cred_printf(u
, word
, &k
);
4769 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
4772 if (!credential_name_valid(k
)) {
4773 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Credential name \"%s\" not valid, ignoring.", k
);
4778 r
= unbase64mem_full(p
, SIZE_MAX
, true, &d
, &size
);
4780 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Encrypted credential data not valid Base64 data, ignoring.");
4787 /* We support escape codes here, so that users can insert trailing \n if they like */
4788 l
= cunescape(p
, UNESCAPE_ACCEPT_NUL
, &unescaped
);
4790 log_syntax(unit
, LOG_WARNING
, filename
, line
, l
, "Can't unescape \"%s\", ignoring: %m", p
);
4798 old
= hashmap_get(context
->set_credentials
, k
);
4800 free_and_replace(old
->data
, d
);
4802 old
->encrypted
= encrypted
;
4804 _cleanup_(exec_set_credential_freep
) ExecSetCredential
*sc
= NULL
;
4806 sc
= new(ExecSetCredential
, 1);
4810 *sc
= (ExecSetCredential
) {
4812 .data
= TAKE_PTR(d
),
4814 .encrypted
= encrypted
,
4817 r
= hashmap_ensure_put(&context
->set_credentials
, &exec_set_credential_hash_ops
, sc
->id
, sc
);
4821 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4822 "Duplicated credential value '%s', ignoring assignment: %s", sc
->id
, rvalue
);
4832 int config_parse_load_credential(
4834 const char *filename
,
4836 const char *section
,
4837 unsigned section_line
,
4844 _cleanup_free_
char *word
= NULL
, *k
= NULL
, *q
= NULL
;
4845 ExecContext
*context
= data
;
4846 ExecLoadCredential
*old
;
4847 bool encrypted
= ltype
;
4857 if (isempty(rvalue
)) {
4858 /* Empty assignment resets the list */
4859 context
->load_credentials
= hashmap_free(context
->load_credentials
);
4864 r
= extract_first_word(&p
, &word
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4868 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
4872 r
= unit_cred_printf(u
, word
, &k
);
4874 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
4877 if (!credential_name_valid(k
)) {
4878 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Credential name \"%s\" not valid, ignoring.", k
);
4883 /* If only one field is specified take it as shortcut for inheriting a credential named
4884 * the same way from our parent */
4889 r
= unit_path_printf(u
, p
, &q
);
4891 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", p
);
4894 if (path_is_absolute(q
) ? !path_is_normalized(q
) : !credential_name_valid(q
)) {
4895 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Credential source \"%s\" not valid, ignoring.", q
);
4900 old
= hashmap_get(context
->load_credentials
, k
);
4902 free_and_replace(old
->path
, q
);
4903 old
->encrypted
= encrypted
;
4905 _cleanup_(exec_load_credential_freep
) ExecLoadCredential
*lc
= NULL
;
4907 lc
= new(ExecLoadCredential
, 1);
4911 *lc
= (ExecLoadCredential
) {
4913 .path
= TAKE_PTR(q
),
4914 .encrypted
= encrypted
,
4917 r
= hashmap_ensure_put(&context
->load_credentials
, &exec_load_credential_hash_ops
, lc
->id
, lc
);
4921 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4922 "Duplicated credential value '%s', ignoring assignment: %s", lc
->id
, rvalue
);
4932 int config_parse_set_status(
4934 const char *filename
,
4936 const char *section
,
4937 unsigned section_line
,
4944 ExitStatusSet
*status_set
= data
;
4952 /* Empty assignment resets the list */
4953 if (isempty(rvalue
)) {
4954 exit_status_set_free(status_set
);
4958 for (const char *p
= rvalue
;;) {
4959 _cleanup_free_
char *word
= NULL
;
4962 r
= extract_first_word(&p
, &word
, NULL
, 0);
4966 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4967 "Failed to parse %s=%s, ignoring: %m", lvalue
, rvalue
);
4973 /* We need to call exit_status_from_string() first, because we want
4974 * to parse numbers as exit statuses, not signals. */
4976 r
= exit_status_from_string(word
);
4978 assert(r
>= 0 && r
< 256);
4979 bitmap
= &status_set
->status
;
4981 r
= signal_from_string(word
);
4983 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4984 "Failed to parse value, ignoring: %s", word
);
4987 bitmap
= &status_set
->signal
;
4990 r
= bitmap_set(bitmap
, r
);
4992 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4993 "Failed to set signal or status %s, ignoring: %m", word
);
4997 int config_parse_namespace_path_strv(
4999 const char *filename
,
5001 const char *section
,
5002 unsigned section_line
,
5009 const Unit
*u
= userdata
;
5018 if (isempty(rvalue
)) {
5019 /* Empty assignment resets the list */
5020 *sv
= strv_free(*sv
);
5024 for (const char *p
= rvalue
;;) {
5025 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
, *joined
= NULL
;
5027 bool ignore_enoent
= false, shall_prefix
= false;
5029 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
5033 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
5040 if (startswith(w
, "-")) {
5041 ignore_enoent
= true;
5044 if (startswith(w
, "+")) {
5045 shall_prefix
= true;
5049 r
= unit_path_printf(u
, w
, &resolved
);
5051 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", w
);
5055 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5059 joined
= strjoin(ignore_enoent
? "-" : "",
5060 shall_prefix
? "+" : "",
5063 r
= strv_push(sv
, joined
);
5073 int config_parse_temporary_filesystems(
5075 const char *filename
,
5077 const char *section
,
5078 unsigned section_line
,
5085 const Unit
*u
= userdata
;
5086 ExecContext
*c
= data
;
5094 if (isempty(rvalue
)) {
5095 /* Empty assignment resets the list */
5096 temporary_filesystem_free_many(c
->temporary_filesystems
, c
->n_temporary_filesystems
);
5097 c
->temporary_filesystems
= NULL
;
5098 c
->n_temporary_filesystems
= 0;
5102 for (const char *p
= rvalue
;;) {
5103 _cleanup_free_
char *word
= NULL
, *path
= NULL
, *resolved
= NULL
;
5106 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
5110 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
5117 r
= extract_first_word(&w
, &path
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
5121 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", word
);
5125 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid syntax, ignoring: %s", word
);
5129 r
= unit_path_printf(u
, path
, &resolved
);
5131 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", path
);
5135 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5139 r
= temporary_filesystem_add(&c
->temporary_filesystems
, &c
->n_temporary_filesystems
, resolved
, w
);
5145 int config_parse_bind_paths(
5147 const char *filename
,
5149 const char *section
,
5150 unsigned section_line
,
5157 ExecContext
*c
= data
;
5158 const Unit
*u
= userdata
;
5166 if (isempty(rvalue
)) {
5167 /* Empty assignment resets the list */
5168 bind_mount_free_many(c
->bind_mounts
, c
->n_bind_mounts
);
5169 c
->bind_mounts
= NULL
;
5170 c
->n_bind_mounts
= 0;
5174 for (const char *p
= rvalue
;;) {
5175 _cleanup_free_
char *source
= NULL
, *destination
= NULL
;
5176 _cleanup_free_
char *sresolved
= NULL
, *dresolved
= NULL
;
5177 char *s
= NULL
, *d
= NULL
;
5178 bool rbind
= true, ignore_enoent
= false;
5180 r
= extract_first_word(&p
, &source
, ":" WHITESPACE
, EXTRACT_UNQUOTE
|EXTRACT_DONT_COALESCE_SEPARATORS
);
5184 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
5190 r
= unit_full_printf_full(u
, source
, PATH_MAX
, &sresolved
);
5192 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5193 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", source
);
5199 ignore_enoent
= true;
5203 r
= path_simplify_and_warn(s
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5207 /* Optionally, the destination is specified. */
5208 if (p
&& p
[-1] == ':') {
5209 r
= extract_first_word(&p
, &destination
, ":" WHITESPACE
, EXTRACT_UNQUOTE
|EXTRACT_DONT_COALESCE_SEPARATORS
);
5213 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
5217 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Missing argument after ':', ignoring: %s", s
);
5221 r
= unit_path_printf(u
, destination
, &dresolved
);
5223 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5224 "Failed to resolve specifiers in \"%s\", ignoring: %m", destination
);
5228 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5234 /* Optionally, there's also a short option string specified */
5235 if (p
&& p
[-1] == ':') {
5236 _cleanup_free_
char *options
= NULL
;
5238 r
= extract_first_word(&p
, &options
, NULL
, EXTRACT_UNQUOTE
);
5242 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s=, ignoring: %s", lvalue
, rvalue
);
5246 if (isempty(options
) || streq(options
, "rbind"))
5248 else if (streq(options
, "norbind"))
5251 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid option string, ignoring setting: %s", options
);
5258 r
= bind_mount_add(&c
->bind_mounts
, &c
->n_bind_mounts
,
5262 .read_only
= !!strstr(lvalue
, "ReadOnly"),
5264 .ignore_enoent
= ignore_enoent
,
5273 int config_parse_mount_images(
5275 const char *filename
,
5277 const char *section
,
5278 unsigned section_line
,
5285 ExecContext
*c
= data
;
5286 const Unit
*u
= userdata
;
5294 if (isempty(rvalue
)) {
5295 /* Empty assignment resets the list */
5296 c
->mount_images
= mount_image_free_many(c
->mount_images
, &c
->n_mount_images
);
5300 for (const char *p
= rvalue
;;) {
5301 _cleanup_(mount_options_free_allp
) MountOptions
*options
= NULL
;
5302 _cleanup_free_
char *first
= NULL
, *second
= NULL
, *tuple
= NULL
;
5303 _cleanup_free_
char *sresolved
= NULL
, *dresolved
= NULL
;
5304 const char *q
= NULL
;
5306 bool permissive
= false;
5308 r
= extract_first_word(&p
, &tuple
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_RETAIN_ESCAPE
);
5312 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5313 "Invalid syntax %s=%s, ignoring: %m", lvalue
, rvalue
);
5320 r
= extract_many_words(&q
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
, &first
, &second
, NULL
);
5324 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5325 "Invalid syntax in %s=, ignoring: %s", lvalue
, tuple
);
5337 r
= unit_path_printf(u
, s
, &sresolved
);
5339 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5340 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", s
);
5344 r
= path_simplify_and_warn(sresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5348 if (isempty(second
)) {
5349 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Missing destination in %s, ignoring: %s", lvalue
, rvalue
);
5353 r
= unit_path_printf(u
, second
, &dresolved
);
5355 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5356 "Failed to resolve specifiers in \"%s\", ignoring: %m", second
);
5360 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5365 _cleanup_free_
char *partition
= NULL
, *mount_options
= NULL
, *mount_options_resolved
= NULL
;
5366 MountOptions
*o
= NULL
;
5367 PartitionDesignator partition_designator
;
5369 r
= extract_many_words(&q
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
, &partition
, &mount_options
, NULL
);
5373 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", q
);
5378 /* Single set of options, applying to the root partition/single filesystem */
5380 r
= unit_full_printf(u
, partition
, &mount_options_resolved
);
5382 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", first
);
5386 o
= new(MountOptions
, 1);
5389 *o
= (MountOptions
) {
5390 .partition_designator
= PARTITION_ROOT
,
5391 .options
= TAKE_PTR(mount_options_resolved
),
5393 LIST_APPEND(mount_options
, options
, o
);
5398 partition_designator
= partition_designator_from_string(partition
);
5399 if (partition_designator
< 0) {
5400 log_syntax(unit
, LOG_WARNING
, filename
, line
, partition_designator
,
5401 "Invalid partition name %s, ignoring", partition
);
5404 r
= unit_full_printf(u
, mount_options
, &mount_options_resolved
);
5406 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", mount_options
);
5410 o
= new(MountOptions
, 1);
5413 *o
= (MountOptions
) {
5414 .partition_designator
= partition_designator
,
5415 .options
= TAKE_PTR(mount_options_resolved
),
5417 LIST_APPEND(mount_options
, options
, o
);
5420 r
= mount_image_add(&c
->mount_images
, &c
->n_mount_images
,
5422 .source
= sresolved
,
5423 .destination
= dresolved
,
5424 .mount_options
= options
,
5425 .ignore_enoent
= permissive
,
5426 .type
= MOUNT_IMAGE_DISCRETE
,
5433 int config_parse_extension_images(
5435 const char *filename
,
5437 const char *section
,
5438 unsigned section_line
,
5445 ExecContext
*c
= data
;
5446 const Unit
*u
= userdata
;
5454 if (isempty(rvalue
)) {
5455 /* Empty assignment resets the list */
5456 c
->extension_images
= mount_image_free_many(c
->extension_images
, &c
->n_extension_images
);
5460 for (const char *p
= rvalue
;;) {
5461 _cleanup_free_
char *source
= NULL
, *tuple
= NULL
, *sresolved
= NULL
;
5462 _cleanup_(mount_options_free_allp
) MountOptions
*options
= NULL
;
5463 bool permissive
= false;
5464 const char *q
= NULL
;
5467 r
= extract_first_word(&p
, &tuple
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_RETAIN_ESCAPE
);
5471 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5472 "Invalid syntax %s=%s, ignoring: %m", lvalue
, rvalue
);
5479 r
= extract_first_word(&q
, &source
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
);
5483 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5484 "Invalid syntax in %s=, ignoring: %s", lvalue
, tuple
);
5496 r
= unit_path_printf(u
, s
, &sresolved
);
5498 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5499 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", s
);
5503 r
= path_simplify_and_warn(sresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5508 _cleanup_free_
char *partition
= NULL
, *mount_options
= NULL
, *mount_options_resolved
= NULL
;
5509 MountOptions
*o
= NULL
;
5510 PartitionDesignator partition_designator
;
5512 r
= extract_many_words(&q
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
, &partition
, &mount_options
, NULL
);
5516 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", q
);
5521 /* Single set of options, applying to the root partition/single filesystem */
5523 r
= unit_full_printf(u
, partition
, &mount_options_resolved
);
5525 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", partition
);
5529 o
= new(MountOptions
, 1);
5532 *o
= (MountOptions
) {
5533 .partition_designator
= PARTITION_ROOT
,
5534 .options
= TAKE_PTR(mount_options_resolved
),
5536 LIST_APPEND(mount_options
, options
, o
);
5541 partition_designator
= partition_designator_from_string(partition
);
5542 if (partition_designator
< 0) {
5543 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid partition name %s, ignoring", partition
);
5546 r
= unit_full_printf(u
, mount_options
, &mount_options_resolved
);
5548 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", mount_options
);
5552 o
= new(MountOptions
, 1);
5555 *o
= (MountOptions
) {
5556 .partition_designator
= partition_designator
,
5557 .options
= TAKE_PTR(mount_options_resolved
),
5559 LIST_APPEND(mount_options
, options
, o
);
5562 r
= mount_image_add(&c
->extension_images
, &c
->n_extension_images
,
5564 .source
= sresolved
,
5565 .mount_options
= options
,
5566 .ignore_enoent
= permissive
,
5567 .type
= MOUNT_IMAGE_EXTENSION
,
5574 int config_parse_job_timeout_sec(
5576 const char *filename
,
5578 const char *section
,
5579 unsigned section_line
,
5595 r
= parse_sec_fix_0(rvalue
, &usec
);
5597 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse JobTimeoutSec= parameter, ignoring: %s", rvalue
);
5601 /* If the user explicitly changed JobTimeoutSec= also change JobRunningTimeoutSec=, for compatibility with old
5602 * versions. If JobRunningTimeoutSec= was explicitly set, avoid this however as whatever the user picked should
5605 if (!u
->job_running_timeout_set
)
5606 u
->job_running_timeout
= usec
;
5608 u
->job_timeout
= usec
;
5613 int config_parse_job_running_timeout_sec(
5615 const char *filename
,
5617 const char *section
,
5618 unsigned section_line
,
5634 r
= parse_sec_fix_0(rvalue
, &usec
);
5636 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse JobRunningTimeoutSec= parameter, ignoring: %s", rvalue
);
5640 u
->job_running_timeout
= usec
;
5641 u
->job_running_timeout_set
= true;
5646 int config_parse_emergency_action(
5648 const char *filename
,
5650 const char *section
,
5651 unsigned section_line
,
5659 EmergencyAction
*x
= data
;
5668 m
= ((Unit
*) userdata
)->manager
;
5672 r
= parse_emergency_action(rvalue
, MANAGER_IS_SYSTEM(m
), x
);
5674 if (r
== -EOPNOTSUPP
&& MANAGER_IS_USER(m
)) {
5675 /* Compat mode: remove for systemd 241. */
5677 log_syntax(unit
, LOG_INFO
, filename
, line
, r
,
5678 "%s= in user mode specified as \"%s\", using \"exit-force\" instead.",
5680 *x
= EMERGENCY_ACTION_EXIT_FORCE
;
5684 if (r
== -EOPNOTSUPP
)
5685 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5686 "%s= specified as %s mode action, ignoring: %s",
5687 lvalue
, MANAGER_IS_SYSTEM(m
) ? "user" : "system", rvalue
);
5689 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5690 "Failed to parse %s=, ignoring: %s", lvalue
, rvalue
);
5697 int config_parse_pid_file(
5699 const char *filename
,
5701 const char *section
,
5702 unsigned section_line
,
5709 _cleanup_free_
char *k
= NULL
, *n
= NULL
;
5710 const Unit
*u
= userdata
;
5719 if (isempty(rvalue
)) {
5720 /* An empty assignment removes already set value. */
5725 r
= unit_path_printf(u
, rvalue
, &k
);
5727 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
5731 /* If this is a relative path make it absolute by prefixing the /run */
5732 n
= path_make_absolute(k
, u
->manager
->prefix
[EXEC_DIRECTORY_RUNTIME
]);
5736 /* Check that the result is a sensible path */
5737 r
= path_simplify_and_warn(n
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5741 r
= patch_var_run(unit
, filename
, line
, lvalue
, &n
);
5745 free_and_replace(*s
, n
);
5749 int config_parse_exit_status(
5751 const char *filename
,
5753 const char *section
,
5754 unsigned section_line
,
5761 int *exit_status
= data
, r
;
5767 assert(exit_status
);
5769 if (isempty(rvalue
)) {
5774 r
= safe_atou8(rvalue
, &u
);
5776 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse exit status '%s', ignoring: %m", rvalue
);
5784 int config_parse_disable_controllers(
5786 const char *filename
,
5788 const char *section
,
5789 unsigned section_line
,
5797 CGroupContext
*c
= data
;
5798 CGroupMask disabled_mask
;
5800 /* 1. If empty, make all controllers eligible for use again.
5801 * 2. If non-empty, merge all listed controllers, space separated. */
5803 if (isempty(rvalue
)) {
5804 c
->disable_controllers
= 0;
5808 r
= cg_mask_from_string(rvalue
, &disabled_mask
);
5809 if (r
< 0 || disabled_mask
<= 0) {
5810 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid cgroup string: %s, ignoring", rvalue
);
5814 c
->disable_controllers
|= disabled_mask
;
5819 int config_parse_ip_filter_bpf_progs(
5821 const char *filename
,
5823 const char *section
,
5824 unsigned section_line
,
5831 _cleanup_free_
char *resolved
= NULL
;
5832 const Unit
*u
= userdata
;
5833 char ***paths
= data
;
5841 if (isempty(rvalue
)) {
5842 *paths
= strv_free(*paths
);
5846 r
= unit_path_printf(u
, rvalue
, &resolved
);
5848 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
5852 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5856 if (strv_contains(*paths
, resolved
))
5859 r
= strv_extend(paths
, resolved
);
5863 r
= bpf_firewall_supported();
5866 if (r
!= BPF_FIREWALL_SUPPORTED_WITH_MULTI
) {
5867 static bool warned
= false;
5869 log_full(warned
? LOG_DEBUG
: LOG_WARNING
,
5870 "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"
5871 "Starting this unit will fail! (This warning is only shown for the first loaded unit using IP firewalling.)", filename
, line
, lvalue
, rvalue
);
5879 int config_parse_bpf_foreign_program(
5881 const char *filename
,
5883 const char *section
,
5884 unsigned section_line
,
5890 _cleanup_free_
char *resolved
= NULL
, *word
= NULL
;
5891 CGroupContext
*c
= data
;
5892 const char *p
= rvalue
;
5900 if (isempty(rvalue
)) {
5901 while (c
->bpf_foreign_programs
)
5902 cgroup_context_remove_bpf_foreign_program(c
, c
->bpf_foreign_programs
);
5907 r
= extract_first_word(&p
, &word
, ":", 0);
5911 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse foreign BPF program, ignoring: %s", rvalue
);
5914 if (r
== 0 || isempty(p
)) {
5915 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid syntax in %s=, ignoring: %s", lvalue
, rvalue
);
5919 attach_type
= bpf_cgroup_attach_type_from_string(word
);
5920 if (attach_type
< 0) {
5921 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Unknown BPF attach type=%s, ignoring: %s", word
, rvalue
);
5925 r
= unit_path_printf(u
, p
, &resolved
);
5927 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %s", p
, rvalue
);
5931 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5935 r
= cgroup_add_bpf_foreign_program(c
, attach_type
, resolved
);
5937 return log_error_errno(r
, "Failed to add foreign BPF program to cgroup context: %m");
5942 int config_parse_cgroup_socket_bind(
5944 const char *filename
,
5946 const char *section
,
5947 unsigned section_line
,
5953 _cleanup_free_ CGroupSocketBindItem
*item
= NULL
;
5954 CGroupSocketBindItem
**head
= data
;
5955 uint16_t nr_ports
, port_min
;
5956 int af
, ip_protocol
, r
;
5958 if (isempty(rvalue
)) {
5959 cgroup_context_remove_socket_bind(head
);
5963 r
= parse_socket_bind_item(rvalue
, &af
, &ip_protocol
, &nr_ports
, &port_min
);
5967 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5968 "Unable to parse %s= assignment, ignoring: %s", lvalue
, rvalue
);
5972 item
= new(CGroupSocketBindItem
, 1);
5975 *item
= (CGroupSocketBindItem
) {
5976 .address_family
= af
,
5977 .ip_protocol
= ip_protocol
,
5978 .nr_ports
= nr_ports
,
5979 .port_min
= port_min
,
5982 LIST_PREPEND(socket_bind_items
, *head
, TAKE_PTR(item
));
5987 int config_parse_restrict_network_interfaces(
5989 const char *filename
,
5991 const char *section
,
5992 unsigned section_line
,
5998 CGroupContext
*c
= data
;
5999 bool is_allow_rule
= true;
6007 if (isempty(rvalue
)) {
6008 /* Empty assignment resets the list */
6009 c
->restrict_network_interfaces
= set_free(c
->restrict_network_interfaces
);
6013 if (rvalue
[0] == '~') {
6014 is_allow_rule
= false;
6018 if (set_isempty(c
->restrict_network_interfaces
))
6019 /* Only initialize this when creating the set */
6020 c
->restrict_network_interfaces_is_allow_list
= is_allow_rule
;
6022 for (const char *p
= rvalue
;;) {
6023 _cleanup_free_
char *word
= NULL
;
6025 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
6031 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
6032 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
6036 if (!ifname_valid(word
)) {
6037 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid interface name, ignoring: %s", word
);
6041 if (c
->restrict_network_interfaces_is_allow_list
!= is_allow_rule
)
6042 free(set_remove(c
->restrict_network_interfaces
, word
));
6044 r
= set_put_strdup(&c
->restrict_network_interfaces
, word
);
6053 static int merge_by_names(Unit
**u
, Set
*names
, const char *id
) {
6060 /* Let's try to add in all names that are aliases of this unit */
6061 while ((k
= set_steal_first(names
))) {
6062 _cleanup_free_ _unused_
char *free_k
= k
;
6064 /* First try to merge in the other name into our unit */
6065 r
= unit_merge_by_name(*u
, k
);
6069 /* Hmm, we couldn't merge the other unit into ours? Then let's try it the other way
6072 other
= manager_get_unit((*u
)->manager
, k
);
6074 return r
; /* return previous failure */
6076 r
= unit_merge(other
, *u
);
6081 return merge_by_names(u
, names
, NULL
);
6084 if (streq_ptr(id
, k
))
6085 unit_choose_id(*u
, id
);
6091 int unit_load_fragment(Unit
*u
) {
6092 const char *fragment
;
6093 _cleanup_set_free_free_ Set
*names
= NULL
;
6097 assert(u
->load_state
== UNIT_STUB
);
6101 u
->access_selinux_context
= mfree(u
->access_selinux_context
);
6102 u
->load_state
= UNIT_LOADED
;
6106 /* Possibly rebuild the fragment map to catch new units */
6107 r
= unit_file_build_name_map(&u
->manager
->lookup_paths
,
6108 &u
->manager
->unit_cache_timestamp_hash
,
6109 &u
->manager
->unit_id_map
,
6110 &u
->manager
->unit_name_map
,
6111 &u
->manager
->unit_path_cache
);
6113 return log_error_errno(r
, "Failed to rebuild name map: %m");
6115 r
= unit_file_find_fragment(u
->manager
->unit_id_map
,
6116 u
->manager
->unit_name_map
,
6120 if (r
< 0 && r
!= -ENOENT
)
6124 /* Open the file, check if this is a mask, otherwise read. */
6125 _cleanup_fclose_
FILE *f
= NULL
;
6128 /* Try to open the file name. A symlink is OK, for example for linked files or masks. We
6129 * expect that all symlinks within the lookup paths have been already resolved, but we don't
6130 * verify this here. */
6131 f
= fopen(fragment
, "re");
6133 return log_unit_notice_errno(u
, errno
, "Failed to open %s: %m", fragment
);
6135 if (fstat(fileno(f
), &st
) < 0)
6138 r
= free_and_strdup(&u
->fragment_path
, fragment
);
6142 if (null_or_empty(&st
)) {
6143 /* Unit file is masked */
6145 u
->load_state
= u
->perpetual
? UNIT_LOADED
: UNIT_MASKED
; /* don't allow perpetual units to ever be masked */
6146 u
->fragment_mtime
= 0;
6147 u
->access_selinux_context
= mfree(u
->access_selinux_context
);
6150 if (mac_selinux_use()) {
6151 _cleanup_freecon_
char *selcon
= NULL
;
6153 /* Cache the SELinux context of the unit file here. We'll make use of when checking access permissions to loaded units */
6154 r
= fgetfilecon_raw(fileno(f
), &selcon
);
6156 log_unit_warning_errno(u
, r
, "Failed to read SELinux context of '%s', ignoring: %m", fragment
);
6158 r
= free_and_strdup(&u
->access_selinux_context
, selcon
);
6163 u
->access_selinux_context
= mfree(u
->access_selinux_context
);
6165 u
->load_state
= UNIT_LOADED
;
6166 u
->fragment_mtime
= timespec_load(&st
.st_mtim
);
6168 /* Now, parse the file contents */
6169 r
= config_parse(u
->id
, fragment
, f
,
6170 UNIT_VTABLE(u
)->sections
,
6171 config_item_perf_lookup
, load_fragment_gperf_lookup
,
6176 log_unit_notice_errno(u
, r
, "Unit configuration has fatal error, unit will not be started.");
6182 /* Call merge_by_names with the name derived from the fragment path as the preferred name.
6184 * We do the merge dance here because for some unit types, the unit might have aliases which are not
6185 * declared in the file system. In particular, this is true (and frequent) for device and swap units.
6187 const char *id
= u
->id
;
6188 _cleanup_free_
char *free_id
= NULL
;
6191 id
= basename(fragment
);
6192 if (unit_name_is_valid(id
, UNIT_NAME_TEMPLATE
)) {
6193 assert(u
->instance
); /* If we're not trying to use a template for non-instanced unit,
6194 * this must be set. */
6196 r
= unit_name_replace_instance(id
, u
->instance
, &free_id
);
6198 return log_debug_errno(r
, "Failed to build id (%s + %s): %m", id
, u
->instance
);
6204 r
= merge_by_names(&merged
, names
, id
);
6209 u
->load_state
= UNIT_MERGED
;
6214 void unit_dump_config_items(FILE *f
) {
6215 static const struct {
6216 const ConfigParserCallback callback
;
6219 { config_parse_warn_compat
, "NOTSUPPORTED" },
6220 { config_parse_int
, "INTEGER" },
6221 { config_parse_unsigned
, "UNSIGNED" },
6222 { config_parse_iec_size
, "SIZE" },
6223 { config_parse_iec_uint64
, "SIZE" },
6224 { config_parse_si_uint64
, "SIZE" },
6225 { config_parse_bool
, "BOOLEAN" },
6226 { config_parse_string
, "STRING" },
6227 { config_parse_path
, "PATH" },
6228 { config_parse_unit_path_printf
, "PATH" },
6229 { config_parse_colon_separated_paths
, "PATH" },
6230 { config_parse_strv
, "STRING [...]" },
6231 { config_parse_exec_nice
, "NICE" },
6232 { config_parse_exec_oom_score_adjust
, "OOMSCOREADJUST" },
6233 { config_parse_exec_io_class
, "IOCLASS" },
6234 { config_parse_exec_io_priority
, "IOPRIORITY" },
6235 { config_parse_exec_cpu_sched_policy
, "CPUSCHEDPOLICY" },
6236 { config_parse_exec_cpu_sched_prio
, "CPUSCHEDPRIO" },
6237 { config_parse_exec_cpu_affinity
, "CPUAFFINITY" },
6238 { config_parse_mode
, "MODE" },
6239 { config_parse_unit_env_file
, "FILE" },
6240 { config_parse_exec_output
, "OUTPUT" },
6241 { config_parse_exec_input
, "INPUT" },
6242 { config_parse_log_facility
, "FACILITY" },
6243 { config_parse_log_level
, "LEVEL" },
6244 { config_parse_exec_secure_bits
, "SECUREBITS" },
6245 { config_parse_capability_set
, "BOUNDINGSET" },
6246 { config_parse_rlimit
, "LIMIT" },
6247 { config_parse_unit_deps
, "UNIT [...]" },
6248 { config_parse_exec
, "PATH [ARGUMENT [...]]" },
6249 { config_parse_service_type
, "SERVICETYPE" },
6250 { config_parse_service_exit_type
, "SERVICEEXITTYPE" },
6251 { config_parse_service_restart
, "SERVICERESTART" },
6252 { config_parse_service_timeout_failure_mode
, "TIMEOUTMODE" },
6253 { config_parse_kill_mode
, "KILLMODE" },
6254 { config_parse_signal
, "SIGNAL" },
6255 { config_parse_socket_listen
, "SOCKET [...]" },
6256 { config_parse_socket_bind
, "SOCKETBIND" },
6257 { config_parse_socket_bindtodevice
, "NETWORKINTERFACE" },
6258 { config_parse_sec
, "SECONDS" },
6259 { config_parse_nsec
, "NANOSECONDS" },
6260 { config_parse_namespace_path_strv
, "PATH [...]" },
6261 { config_parse_bind_paths
, "PATH[:PATH[:OPTIONS]] [...]" },
6262 { config_parse_unit_requires_mounts_for
, "PATH [...]" },
6263 { config_parse_exec_mount_flags
, "MOUNTFLAG [...]" },
6264 { config_parse_unit_string_printf
, "STRING" },
6265 { config_parse_trigger_unit
, "UNIT" },
6266 { config_parse_timer
, "TIMER" },
6267 { config_parse_path_spec
, "PATH" },
6268 { config_parse_notify_access
, "ACCESS" },
6269 { config_parse_ip_tos
, "TOS" },
6270 { config_parse_unit_condition_path
, "CONDITION" },
6271 { config_parse_unit_condition_string
, "CONDITION" },
6272 { config_parse_unit_slice
, "SLICE" },
6273 { config_parse_documentation
, "URL" },
6274 { config_parse_service_timeout
, "SECONDS" },
6275 { config_parse_emergency_action
, "ACTION" },
6276 { config_parse_set_status
, "STATUS" },
6277 { config_parse_service_sockets
, "SOCKETS" },
6278 { config_parse_environ
, "ENVIRON" },
6280 { config_parse_syscall_filter
, "SYSCALLS" },
6281 { config_parse_syscall_archs
, "ARCHS" },
6282 { config_parse_syscall_errno
, "ERRNO" },
6283 { config_parse_syscall_log
, "SYSCALLS" },
6284 { config_parse_address_families
, "FAMILIES" },
6285 { config_parse_restrict_namespaces
, "NAMESPACES" },
6287 { config_parse_restrict_filesystems
, "FILESYSTEMS" },
6288 { config_parse_cpu_shares
, "SHARES" },
6289 { config_parse_cg_weight
, "WEIGHT" },
6290 { config_parse_cg_cpu_weight
, "CPUWEIGHT" },
6291 { config_parse_memory_limit
, "LIMIT" },
6292 { config_parse_device_allow
, "DEVICE" },
6293 { config_parse_device_policy
, "POLICY" },
6294 { config_parse_io_limit
, "LIMIT" },
6295 { config_parse_io_device_weight
, "DEVICEWEIGHT" },
6296 { config_parse_io_device_latency
, "DEVICELATENCY" },
6297 { config_parse_blockio_bandwidth
, "BANDWIDTH" },
6298 { config_parse_blockio_weight
, "WEIGHT" },
6299 { config_parse_blockio_device_weight
, "DEVICEWEIGHT" },
6300 { config_parse_long
, "LONG" },
6301 { config_parse_socket_service
, "SERVICE" },
6303 { config_parse_exec_selinux_context
, "LABEL" },
6305 { config_parse_job_mode
, "MODE" },
6306 { config_parse_job_mode_isolate
, "BOOLEAN" },
6307 { config_parse_personality
, "PERSONALITY" },
6310 const char *prev
= NULL
;
6315 NULSTR_FOREACH(i
, load_fragment_gperf_nulstr
) {
6316 const char *rvalue
= "OTHER", *lvalue
;
6317 const ConfigPerfItem
*p
;
6320 assert_se(p
= load_fragment_gperf_lookup(i
, strlen(i
)));
6322 /* Hide legacy settings */
6323 if (p
->parse
== config_parse_warn_compat
&&
6324 p
->ltype
== DISABLED_LEGACY
)
6327 for (size_t j
= 0; j
< ELEMENTSOF(table
); j
++)
6328 if (p
->parse
== table
[j
].callback
) {
6329 rvalue
= table
[j
].rvalue
;
6333 dot
= strchr(i
, '.');
6334 lvalue
= dot
? dot
+ 1 : i
;
6337 size_t prefix_len
= dot
- i
;
6339 if (!prev
|| !strneq(prev
, i
, prefix_len
+1)) {
6343 fprintf(f
, "[%.*s]\n", (int) prefix_len
, i
);
6347 fprintf(f
, "%s=%s\n", lvalue
, rvalue
);
6352 int config_parse_cpu_affinity2(
6354 const char *filename
,
6356 const char *section
,
6357 unsigned section_line
,
6364 CPUSet
*affinity
= data
;
6368 (void) parse_cpu_set_extend(rvalue
, affinity
, true, unit
, filename
, line
, lvalue
);
6373 int config_parse_show_status(
6375 const char *filename
,
6377 const char *section
,
6378 unsigned section_line
,
6386 ShowStatus
*b
= data
;
6393 k
= parse_show_status(rvalue
, b
);
6395 log_syntax(unit
, LOG_WARNING
, filename
, line
, k
, "Failed to parse show status setting, ignoring: %s", rvalue
);
6400 int config_parse_output_restricted(
6402 const char *filename
,
6404 const char *section
,
6405 unsigned section_line
,
6412 ExecOutput t
, *eo
= data
;
6413 bool obsolete
= false;
6420 if (streq(rvalue
, "syslog")) {
6421 t
= EXEC_OUTPUT_JOURNAL
;
6423 } else if (streq(rvalue
, "syslog+console")) {
6424 t
= EXEC_OUTPUT_JOURNAL_AND_CONSOLE
;
6427 t
= exec_output_from_string(rvalue
);
6429 log_syntax(unit
, LOG_WARNING
, filename
, line
, t
, "Failed to parse output type, ignoring: %s", rvalue
);
6433 if (IN_SET(t
, EXEC_OUTPUT_SOCKET
, EXEC_OUTPUT_NAMED_FD
, EXEC_OUTPUT_FILE
, EXEC_OUTPUT_FILE_APPEND
, EXEC_OUTPUT_FILE_TRUNCATE
)) {
6434 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Standard output types socket, fd:, file:, append:, truncate: are not supported as defaults, ignoring: %s", rvalue
);
6440 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
6441 "Standard output type %s is obsolete, automatically updating to %s. Please update your configuration.",
6442 rvalue
, exec_output_to_string(t
));
6448 int config_parse_crash_chvt(
6450 const char *filename
,
6452 const char *section
,
6453 unsigned section_line
,
6467 r
= parse_crash_chvt(rvalue
, data
);
6469 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse CrashChangeVT= setting, ignoring: %s", rvalue
);
6474 int config_parse_swap_priority(
6476 const char *filename
,
6478 const char *section
,
6479 unsigned section_line
,
6495 if (isempty(rvalue
)) {
6496 s
->parameters_fragment
.priority
= -1;
6497 s
->parameters_fragment
.priority_set
= false;
6501 r
= safe_atoi(rvalue
, &priority
);
6503 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid swap priority '%s', ignoring.", rvalue
);
6507 if (priority
< -1) {
6508 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
);
6512 if (priority
> 32767) {
6513 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Swap priority out of range, ignoring: %s", rvalue
);
6517 s
->parameters_fragment
.priority
= priority
;
6518 s
->parameters_fragment
.priority_set
= true;
6522 int config_parse_watchdog_sec(
6524 const char *filename
,
6526 const char *section
,
6527 unsigned section_line
,
6534 usec_t
*usec
= data
;
6540 /* This is called for {Runtime,Reboot,KExec}WatchdogSec= where "default" maps to
6541 * USEC_INFINITY internally. */
6543 if (streq(rvalue
, "default"))
6544 *usec
= USEC_INFINITY
;
6545 else if (streq(rvalue
, "off"))
6548 return config_parse_sec(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
);
6553 int config_parse_tty_size(
6555 const char *filename
,
6557 const char *section
,
6558 unsigned section_line
,
6565 unsigned *sz
= data
;
6571 if (isempty(rvalue
)) {
6576 return config_parse_unsigned(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
);