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"
22 #include "bpf-program.h"
23 #include "bus-error.h"
24 #include "bus-internal.h"
27 #include "capability-util.h"
28 #include "cgroup-setup.h"
29 #include "conf-parser.h"
30 #include "core-varlink.h"
31 #include "cpu-set-util.h"
32 #include "creds-util.h"
34 #include "errno-list.h"
39 #include "hexdecoct.h"
42 #include "ip-protocol-list.h"
43 #include "journal-file.h"
44 #include "limits-util.h"
45 #include "load-fragment.h"
47 #include "mountpoint-util.h"
48 #include "nulstr-util.h"
49 #include "parse-util.h"
50 #include "path-util.h"
51 #include "percent-util.h"
52 #include "process-util.h"
54 #include "seccomp-util.h"
56 #include "securebits-util.h"
57 #include "signal-util.h"
58 #include "socket-bind.h"
59 #include "socket-netlink.h"
60 #include "specifier.h"
61 #include "stat-util.h"
62 #include "string-util.h"
64 #include "syslog-util.h"
65 #include "time-util.h"
66 #include "unit-name.h"
67 #include "unit-printf.h"
68 #include "user-util.h"
72 static int parse_socket_protocol(const char *s
) {
75 r
= parse_ip_protocol(s
);
78 if (!IN_SET(r
, IPPROTO_UDPLITE
, IPPROTO_SCTP
))
79 return -EPROTONOSUPPORT
;
84 int parse_crash_chvt(const char *value
, int *data
) {
87 if (safe_atoi(value
, data
) >= 0)
90 b
= parse_boolean(value
);
95 *data
= 0; /* switch to where kmsg goes */
97 *data
= -1; /* turn off switching */
102 int parse_confirm_spawn(const char *value
, char **console
) {
106 r
= value
? parse_boolean(value
) : 1;
110 } else if (r
> 0) /* on with default tty */
111 s
= strdup("/dev/console");
112 else if (is_path(value
)) /* on with fully qualified path */
114 else /* on with only a tty file name, not a fully qualified path */
115 s
= path_join("/dev/", value
);
123 DEFINE_CONFIG_PARSE(config_parse_socket_protocol
, parse_socket_protocol
, "Failed to parse socket protocol");
124 DEFINE_CONFIG_PARSE(config_parse_exec_secure_bits
, secure_bits_from_string
, "Failed to parse secure bits");
125 DEFINE_CONFIG_PARSE_ENUM(config_parse_collect_mode
, collect_mode
, CollectMode
, "Failed to parse garbage collection mode");
126 DEFINE_CONFIG_PARSE_ENUM(config_parse_device_policy
, cgroup_device_policy
, CGroupDevicePolicy
, "Failed to parse device policy");
127 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_keyring_mode
, exec_keyring_mode
, ExecKeyringMode
, "Failed to parse keyring mode");
128 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_proc
, protect_proc
, ProtectProc
, "Failed to parse /proc/ protection mode");
129 DEFINE_CONFIG_PARSE_ENUM(config_parse_proc_subset
, proc_subset
, ProcSubset
, "Failed to parse /proc/ subset mode");
130 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_utmp_mode
, exec_utmp_mode
, ExecUtmpMode
, "Failed to parse utmp mode");
131 DEFINE_CONFIG_PARSE_ENUM(config_parse_job_mode
, job_mode
, JobMode
, "Failed to parse job mode");
132 DEFINE_CONFIG_PARSE_ENUM(config_parse_notify_access
, notify_access
, NotifyAccess
, "Failed to parse notify access specifier");
133 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_home
, protect_home
, ProtectHome
, "Failed to parse protect home value");
134 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_system
, protect_system
, ProtectSystem
, "Failed to parse protect system value");
135 DEFINE_CONFIG_PARSE_ENUM(config_parse_runtime_preserve_mode
, exec_preserve_mode
, ExecPreserveMode
, "Failed to parse runtime directory preserve mode");
136 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_type
, service_type
, ServiceType
, "Failed to parse service type");
137 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_exit_type
, service_exit_type
, ServiceExitType
, "Failed to parse service exit type");
138 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart
, service_restart
, ServiceRestart
, "Failed to parse service restart specifier");
139 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_timeout_failure_mode
, service_timeout_failure_mode
, ServiceTimeoutFailureMode
, "Failed to parse timeout failure mode");
140 DEFINE_CONFIG_PARSE_ENUM(config_parse_socket_bind
, socket_address_bind_ipv6_only_or_bool
, SocketAddressBindIPv6Only
, "Failed to parse bind IPv6 only value");
141 DEFINE_CONFIG_PARSE_ENUM(config_parse_oom_policy
, oom_policy
, OOMPolicy
, "Failed to parse OOM policy");
142 DEFINE_CONFIG_PARSE_ENUM(config_parse_managed_oom_preference
, managed_oom_preference
, ManagedOOMPreference
, "Failed to parse ManagedOOMPreference=");
143 DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_ip_tos
, ip_tos
, int, -1, "Failed to parse IP TOS value");
144 DEFINE_CONFIG_PARSE_PTR(config_parse_blockio_weight
, cg_blkio_weight_parse
, uint64_t, "Invalid block IO weight");
145 DEFINE_CONFIG_PARSE_PTR(config_parse_cg_weight
, cg_weight_parse
, uint64_t, "Invalid weight");
146 DEFINE_CONFIG_PARSE_PTR(config_parse_cpu_shares
, cg_cpu_shares_parse
, uint64_t, "Invalid CPU shares");
147 DEFINE_CONFIG_PARSE_PTR(config_parse_exec_mount_flags
, mount_propagation_flags_from_string
, unsigned long, "Failed to parse mount flag");
148 DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_numa_policy
, mpol
, int, -1, "Invalid NUMA policy type");
149 DEFINE_CONFIG_PARSE_ENUM(config_parse_status_unit_format
, status_unit_format
, StatusUnitFormat
, "Failed to parse status unit format");
150 DEFINE_CONFIG_PARSE_ENUM_FULL(config_parse_socket_timestamping
, socket_timestamping_from_string_harder
, SocketTimestamping
, "Failed to parse timestamping precision");
152 int config_parse_unit_deps(
154 const char *filename
,
157 unsigned section_line
,
164 UnitDependency d
= ltype
;
171 for (const char *p
= rvalue
;;) {
172 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
175 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_RETAIN_ESCAPE
);
181 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
185 r
= unit_name_printf(u
, word
, &k
);
187 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
191 r
= unit_add_dependency_by_name(u
, d
, k
, true, UNIT_DEPENDENCY_FILE
);
193 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
197 int config_parse_obsolete_unit_deps(
199 const char *filename
,
202 unsigned section_line
,
209 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
210 "Unit dependency type %s= is obsolete, replacing by %s=, please update your unit file", lvalue
, unit_dependency_to_string(ltype
));
212 return config_parse_unit_deps(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
);
215 int config_parse_unit_string_printf(
217 const char *filename
,
220 unsigned section_line
,
227 _cleanup_free_
char *k
= NULL
;
228 const Unit
*u
= userdata
;
236 r
= unit_full_printf(u
, rvalue
, &k
);
238 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
242 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
245 int config_parse_unit_strv_printf(
247 const char *filename
,
250 unsigned section_line
,
257 const Unit
*u
= userdata
;
258 _cleanup_free_
char *k
= NULL
;
266 r
= unit_full_printf(u
, rvalue
, &k
);
268 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
272 return config_parse_strv(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
275 int config_parse_unit_path_printf(
277 const char *filename
,
280 unsigned section_line
,
287 _cleanup_free_
char *k
= NULL
;
288 const Unit
*u
= userdata
;
297 r
= unit_path_printf(u
, rvalue
, &k
);
299 log_syntax(unit
, fatal
? LOG_ERR
: LOG_WARNING
, filename
, line
, r
,
300 "Failed to resolve unit specifiers in '%s'%s: %m",
301 rvalue
, fatal
? "" : ", ignoring");
302 return fatal
? -ENOEXEC
: 0;
305 return config_parse_path(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
308 int config_parse_unit_path_strv_printf(
310 const char *filename
,
313 unsigned section_line
,
321 const Unit
*u
= userdata
;
329 if (isempty(rvalue
)) {
334 for (const char *p
= rvalue
;;) {
335 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
337 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
343 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
344 "Invalid syntax, ignoring: %s", rvalue
);
348 r
= unit_path_printf(u
, word
, &k
);
350 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
351 "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
355 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
359 r
= strv_consume(x
, TAKE_PTR(k
));
365 static int patch_var_run(
367 const char *filename
,
375 e
= path_startswith(*path
, "/var/run/");
379 z
= path_join("/run/", e
);
383 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
384 "%s= references a path below legacy directory /var/run/, updating %s → %s; "
385 "please update the unit file accordingly.", lvalue
, *path
, z
);
387 free_and_replace(*path
, z
);
392 int config_parse_socket_listen(
394 const char *filename
,
397 unsigned section_line
,
404 _cleanup_free_ SocketPort
*p
= NULL
;
416 if (isempty(rvalue
)) {
417 /* An empty assignment removes all ports */
418 socket_free_ports(s
);
422 p
= new0(SocketPort
, 1);
426 if (ltype
!= SOCKET_SOCKET
) {
427 _cleanup_free_
char *k
= NULL
;
429 r
= unit_path_printf(UNIT(s
), rvalue
, &k
);
431 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
435 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
439 if (ltype
== SOCKET_FIFO
) {
440 r
= patch_var_run(unit
, filename
, line
, lvalue
, &k
);
445 free_and_replace(p
->path
, k
);
448 } else if (streq(lvalue
, "ListenNetlink")) {
449 _cleanup_free_
char *k
= NULL
;
451 r
= unit_path_printf(UNIT(s
), rvalue
, &k
);
453 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
457 r
= socket_address_parse_netlink(&p
->address
, k
);
459 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse address value in '%s', ignoring: %m", k
);
463 p
->type
= SOCKET_SOCKET
;
466 _cleanup_free_
char *k
= NULL
;
468 r
= unit_path_printf(UNIT(s
), rvalue
, &k
);
470 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
474 if (k
[0] == '/') { /* Only for AF_UNIX file system sockets… */
475 r
= patch_var_run(unit
, filename
, line
, lvalue
, &k
);
480 r
= socket_address_parse_and_warn(&p
->address
, k
);
482 if (r
!= -EAFNOSUPPORT
)
483 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse address value in '%s', ignoring: %m", k
);
487 if (streq(lvalue
, "ListenStream"))
488 p
->address
.type
= SOCK_STREAM
;
489 else if (streq(lvalue
, "ListenDatagram"))
490 p
->address
.type
= SOCK_DGRAM
;
492 assert(streq(lvalue
, "ListenSequentialPacket"));
493 p
->address
.type
= SOCK_SEQPACKET
;
496 if (socket_address_family(&p
->address
) != AF_LOCAL
&& p
->address
.type
== SOCK_SEQPACKET
) {
497 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Address family not supported, ignoring: %s", rvalue
);
501 p
->type
= SOCKET_SOCKET
;
505 p
->auxiliary_fds
= NULL
;
506 p
->n_auxiliary_fds
= 0;
509 LIST_FIND_TAIL(port
, s
->ports
, tail
);
510 LIST_INSERT_AFTER(port
, s
->ports
, tail
, p
);
517 int config_parse_exec_nice(
519 const char *filename
,
522 unsigned section_line
,
529 ExecContext
*c
= data
;
537 if (isempty(rvalue
)) {
542 r
= parse_nice(rvalue
, &priority
);
545 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Nice priority out of range, ignoring: %s", rvalue
);
547 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse nice priority '%s', ignoring: %m", rvalue
);
557 int config_parse_exec_oom_score_adjust(
559 const char *filename
,
562 unsigned section_line
,
569 ExecContext
*c
= data
;
577 if (isempty(rvalue
)) {
578 c
->oom_score_adjust_set
= false;
582 r
= parse_oom_score_adjust(rvalue
, &oa
);
585 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "OOM score adjust value out of range, ignoring: %s", rvalue
);
587 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse the OOM score adjust value '%s', ignoring: %m", rvalue
);
591 c
->oom_score_adjust
= oa
;
592 c
->oom_score_adjust_set
= true;
597 int config_parse_exec_coredump_filter(
599 const char *filename
,
602 unsigned section_line
,
609 ExecContext
*c
= data
;
617 if (isempty(rvalue
)) {
618 c
->coredump_filter
= 0;
619 c
->coredump_filter_set
= false;
624 r
= coredump_filter_mask_from_string(rvalue
, &f
);
626 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
627 "Failed to parse the CoredumpFilter=%s, ignoring: %m", rvalue
);
631 c
->coredump_filter
|= f
;
632 c
->oom_score_adjust_set
= true;
636 int config_parse_kill_mode(
638 const char *filename
,
641 unsigned section_line
,
648 KillMode
*k
= data
, m
;
655 if (isempty(rvalue
)) {
656 *k
= KILL_CONTROL_GROUP
;
660 m
= kill_mode_from_string(rvalue
);
662 log_syntax(unit
, LOG_WARNING
, filename
, line
, m
,
663 "Failed to parse kill mode specification, ignoring: %s", rvalue
);
668 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
669 "Unit configured to use KillMode=none. "
670 "This is unsafe, as it disables systemd's process lifecycle management for the service. "
671 "Please update your service to use a safer KillMode=, such as 'mixed' or 'control-group'. "
672 "Support for KillMode=none is deprecated and will eventually be removed.");
678 int config_parse_exec(
680 const char *filename
,
683 unsigned section_line
,
690 ExecCommand
**e
= data
;
691 const Unit
*u
= userdata
;
703 if (isempty(rvalue
)) {
704 /* An empty assignment resets the list */
705 *e
= exec_command_free_list(*e
);
711 _cleanup_free_
char *path
= NULL
, *firstword
= NULL
;
712 ExecCommandFlags flags
= 0;
713 bool ignore
= false, separate_argv0
= false;
714 _cleanup_free_ ExecCommand
*nce
= NULL
;
715 _cleanup_strv_free_
char **n
= NULL
;
721 r
= extract_first_word_and_warn(&p
, &firstword
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
725 /* A lone ";" is a separator. Let's make sure we don't treat it as an executable name. */
726 if (streq(firstword
, ";")) {
733 /* We accept an absolute path as first argument. If it's prefixed with - and the path doesn't
734 * exist, we ignore it instead of erroring out; if it's prefixed with @, we allow overriding of
735 * argv[0]; if it's prefixed with :, we will not do environment variable substitution;
736 * if it's prefixed with +, it will be run with full privileges and no sandboxing; if
737 * it's prefixed with '!' we apply sandboxing, but do not change user/group credentials; if
738 * it's prefixed with '!!', then we apply user/group credentials if the kernel supports ambient
739 * capabilities -- if it doesn't we don't apply the credentials themselves, but do apply most
740 * other sandboxing, with some special exceptions for changing UID.
742 * The idea is that '!!' may be used to write services that can take benefit of systemd's
743 * UID/GID dropping if the kernel supports ambient creds, but provide an automatic fallback to
744 * privilege dropping within the daemon if the kernel does not offer that. */
746 if (*f
== '-' && !(flags
& EXEC_COMMAND_IGNORE_FAILURE
)) {
747 flags
|= EXEC_COMMAND_IGNORE_FAILURE
;
749 } else if (*f
== '@' && !separate_argv0
)
750 separate_argv0
= true;
751 else if (*f
== ':' && !(flags
& EXEC_COMMAND_NO_ENV_EXPAND
))
752 flags
|= EXEC_COMMAND_NO_ENV_EXPAND
;
753 else if (*f
== '+' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
754 flags
|= EXEC_COMMAND_FULLY_PRIVILEGED
;
755 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
756 flags
|= EXEC_COMMAND_NO_SETUID
;
757 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_AMBIENT_MAGIC
))) {
758 flags
&= ~EXEC_COMMAND_NO_SETUID
;
759 flags
|= EXEC_COMMAND_AMBIENT_MAGIC
;
765 r
= unit_path_printf(u
, f
, &path
);
767 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
768 "Failed to resolve unit specifiers in '%s'%s: %m",
769 f
, ignore
? ", ignoring" : "");
770 return ignore
? 0 : -ENOEXEC
;
774 /* First word is either "-" or "@" with no command. */
775 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
776 "Empty path in command line%s: '%s'",
777 ignore
? ", ignoring" : "", rvalue
);
778 return ignore
? 0 : -ENOEXEC
;
780 if (!string_is_safe(path
)) {
781 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
782 "Executable name contains special characters%s: %s",
783 ignore
? ", ignoring" : "", path
);
784 return ignore
? 0 : -ENOEXEC
;
786 if (endswith(path
, "/")) {
787 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
788 "Executable path specifies a directory%s: %s",
789 ignore
? ", ignoring" : "", path
);
790 return ignore
? 0 : -ENOEXEC
;
793 if (!(path_is_absolute(path
) ? path_is_valid(path
) : filename_is_valid(path
))) {
794 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
795 "Neither a valid executable name nor an absolute path%s: %s",
796 ignore
? ", ignoring" : "", path
);
797 return ignore
? 0 : -ENOEXEC
;
800 if (!separate_argv0
) {
803 if (!GREEDY_REALLOC(n
, nlen
+ 2))
815 while (!isempty(p
)) {
816 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
818 /* Check explicitly for an unquoted semicolon as
819 * command separator token. */
820 if (p
[0] == ';' && (!p
[1] || strchr(WHITESPACE
, p
[1]))) {
822 p
+= strspn(p
, WHITESPACE
);
827 /* Check for \; explicitly, to not confuse it with \\; or "\;" or "\\;" etc.
828 * extract_first_word() would return the same for all of those. */
829 if (p
[0] == '\\' && p
[1] == ';' && (!p
[2] || strchr(WHITESPACE
, p
[2]))) {
833 p
+= strspn(p
, WHITESPACE
);
835 if (!GREEDY_REALLOC(n
, nlen
+ 2))
846 r
= extract_first_word_and_warn(&p
, &word
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
850 return ignore
? 0 : -ENOEXEC
;
852 r
= unit_path_printf(u
, word
, &resolved
);
854 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
855 "Failed to resolve unit specifiers in %s%s: %m",
856 word
, ignore
? ", ignoring" : "");
857 return ignore
? 0 : -ENOEXEC
;
860 if (!GREEDY_REALLOC(n
, nlen
+ 2))
863 n
[nlen
++] = TAKE_PTR(resolved
);
868 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
869 "Empty executable name or zeroeth argument%s: %s",
870 ignore
? ", ignoring" : "", rvalue
);
871 return ignore
? 0 : -ENOEXEC
;
874 nce
= new0(ExecCommand
, 1);
878 nce
->argv
= TAKE_PTR(n
);
879 nce
->path
= TAKE_PTR(path
);
882 exec_command_append_list(e
, nce
);
884 /* Do not _cleanup_free_ these. */
893 int config_parse_socket_bindtodevice(
895 const char *filename
,
898 unsigned section_line
,
912 if (isempty(rvalue
) || streq(rvalue
, "*")) {
913 s
->bind_to_device
= mfree(s
->bind_to_device
);
917 if (!ifname_valid(rvalue
)) {
918 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid interface name, ignoring: %s", rvalue
);
922 return free_and_strdup_warn(&s
->bind_to_device
, rvalue
);
925 int config_parse_exec_input(
927 const char *filename
,
930 unsigned section_line
,
937 ExecContext
*c
= data
;
938 const Unit
*u
= userdata
;
948 n
= startswith(rvalue
, "fd:");
950 _cleanup_free_
char *resolved
= NULL
;
952 r
= unit_fd_printf(u
, n
, &resolved
);
954 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", n
);
958 if (isempty(resolved
))
959 resolved
= mfree(resolved
);
960 else if (!fdname_is_valid(resolved
)) {
961 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", resolved
);
965 free_and_replace(c
->stdio_fdname
[STDIN_FILENO
], resolved
);
967 ei
= EXEC_INPUT_NAMED_FD
;
969 } else if ((n
= startswith(rvalue
, "file:"))) {
970 _cleanup_free_
char *resolved
= NULL
;
972 r
= unit_path_printf(u
, n
, &resolved
);
974 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", n
);
978 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
982 free_and_replace(c
->stdio_file
[STDIN_FILENO
], resolved
);
984 ei
= EXEC_INPUT_FILE
;
987 ei
= exec_input_from_string(rvalue
);
989 log_syntax(unit
, LOG_WARNING
, filename
, line
, ei
, "Failed to parse input specifier, ignoring: %s", rvalue
);
998 int config_parse_exec_input_text(
1000 const char *filename
,
1002 const char *section
,
1003 unsigned section_line
,
1010 _cleanup_free_
char *unescaped
= NULL
, *resolved
= NULL
;
1011 ExecContext
*c
= data
;
1012 const Unit
*u
= userdata
;
1022 if (isempty(rvalue
)) {
1023 /* Reset if the empty string is assigned */
1024 c
->stdin_data
= mfree(c
->stdin_data
);
1025 c
->stdin_data_size
= 0;
1029 r
= cunescape(rvalue
, 0, &unescaped
);
1031 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1032 "Failed to decode C escaped text '%s', ignoring: %m", rvalue
);
1036 r
= unit_full_printf_full(u
, unescaped
, EXEC_STDIN_DATA_MAX
, &resolved
);
1038 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1039 "Failed to resolve unit specifiers in '%s', ignoring: %m", unescaped
);
1043 sz
= strlen(resolved
);
1044 if (c
->stdin_data_size
+ sz
+ 1 < c
->stdin_data_size
|| /* check for overflow */
1045 c
->stdin_data_size
+ sz
+ 1 > EXEC_STDIN_DATA_MAX
) {
1046 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
1047 "Standard input data too large (%zu), maximum of %zu permitted, ignoring.",
1048 c
->stdin_data_size
+ sz
, (size_t) EXEC_STDIN_DATA_MAX
);
1052 p
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
+ 1);
1056 *((char*) mempcpy((char*) p
+ c
->stdin_data_size
, resolved
, sz
)) = '\n';
1059 c
->stdin_data_size
+= sz
+ 1;
1064 int config_parse_exec_input_data(
1066 const char *filename
,
1068 const char *section
,
1069 unsigned section_line
,
1076 _cleanup_free_
void *p
= NULL
;
1077 ExecContext
*c
= data
;
1087 if (isempty(rvalue
)) {
1088 /* Reset if the empty string is assigned */
1089 c
->stdin_data
= mfree(c
->stdin_data
);
1090 c
->stdin_data_size
= 0;
1094 r
= unbase64mem(rvalue
, SIZE_MAX
, &p
, &sz
);
1096 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1097 "Failed to decode base64 data, ignoring: %s", rvalue
);
1103 if (c
->stdin_data_size
+ sz
< c
->stdin_data_size
|| /* check for overflow */
1104 c
->stdin_data_size
+ sz
> EXEC_STDIN_DATA_MAX
) {
1105 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
1106 "Standard input data too large (%zu), maximum of %zu permitted, ignoring.",
1107 c
->stdin_data_size
+ sz
, (size_t) EXEC_STDIN_DATA_MAX
);
1111 q
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
);
1115 memcpy((uint8_t*) q
+ c
->stdin_data_size
, p
, sz
);
1118 c
->stdin_data_size
+= sz
;
1123 int config_parse_exec_output(
1125 const char *filename
,
1127 const char *section
,
1128 unsigned section_line
,
1135 _cleanup_free_
char *resolved
= NULL
;
1137 ExecContext
*c
= data
;
1138 const Unit
*u
= userdata
;
1139 bool obsolete
= false;
1149 n
= startswith(rvalue
, "fd:");
1151 r
= unit_fd_printf(u
, n
, &resolved
);
1153 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", n
);
1157 if (isempty(resolved
))
1158 resolved
= mfree(resolved
);
1159 else if (!fdname_is_valid(resolved
)) {
1160 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", resolved
);
1164 eo
= EXEC_OUTPUT_NAMED_FD
;
1166 } else if (streq(rvalue
, "syslog")) {
1167 eo
= EXEC_OUTPUT_JOURNAL
;
1170 } else if (streq(rvalue
, "syslog+console")) {
1171 eo
= EXEC_OUTPUT_JOURNAL_AND_CONSOLE
;
1174 } else if ((n
= startswith(rvalue
, "file:"))) {
1176 r
= unit_path_printf(u
, n
, &resolved
);
1178 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", n
);
1182 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1186 eo
= EXEC_OUTPUT_FILE
;
1188 } else if ((n
= startswith(rvalue
, "append:"))) {
1190 r
= unit_path_printf(u
, n
, &resolved
);
1192 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", n
);
1196 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1200 eo
= EXEC_OUTPUT_FILE_APPEND
;
1202 } else if ((n
= startswith(rvalue
, "truncate:"))) {
1204 r
= unit_path_printf(u
, n
, &resolved
);
1206 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", n
);
1210 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1214 eo
= EXEC_OUTPUT_FILE_TRUNCATE
;
1216 eo
= exec_output_from_string(rvalue
);
1218 log_syntax(unit
, LOG_WARNING
, filename
, line
, eo
, "Failed to parse output specifier, ignoring: %s", rvalue
);
1224 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
1225 "Standard output type %s is obsolete, automatically updating to %s. Please update your unit file, and consider removing the setting altogether.",
1226 rvalue
, exec_output_to_string(eo
));
1228 if (streq(lvalue
, "StandardOutput")) {
1229 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1230 free_and_replace(c
->stdio_fdname
[STDOUT_FILENO
], resolved
);
1232 free_and_replace(c
->stdio_file
[STDOUT_FILENO
], resolved
);
1237 assert(streq(lvalue
, "StandardError"));
1239 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1240 free_and_replace(c
->stdio_fdname
[STDERR_FILENO
], resolved
);
1242 free_and_replace(c
->stdio_file
[STDERR_FILENO
], resolved
);
1250 int config_parse_exec_io_class(const char *unit
,
1251 const char *filename
,
1253 const char *section
,
1254 unsigned section_line
,
1261 ExecContext
*c
= data
;
1269 if (isempty(rvalue
)) {
1270 c
->ioprio_set
= false;
1271 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE
, 0);
1275 x
= ioprio_class_from_string(rvalue
);
1277 log_syntax(unit
, LOG_WARNING
, filename
, line
, x
, "Failed to parse IO scheduling class, ignoring: %s", rvalue
);
1281 c
->ioprio
= IOPRIO_PRIO_VALUE(x
, IOPRIO_PRIO_DATA(c
->ioprio
));
1282 c
->ioprio_set
= true;
1287 int config_parse_exec_io_priority(const char *unit
,
1288 const char *filename
,
1290 const char *section
,
1291 unsigned section_line
,
1298 ExecContext
*c
= data
;
1306 if (isempty(rvalue
)) {
1307 c
->ioprio_set
= false;
1308 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE
, 0);
1312 r
= ioprio_parse_priority(rvalue
, &i
);
1314 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse IO priority, ignoring: %s", rvalue
);
1318 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_PRIO_CLASS(c
->ioprio
), i
);
1319 c
->ioprio_set
= true;
1324 int config_parse_exec_cpu_sched_policy(const char *unit
,
1325 const char *filename
,
1327 const char *section
,
1328 unsigned section_line
,
1335 ExecContext
*c
= data
;
1343 if (isempty(rvalue
)) {
1344 c
->cpu_sched_set
= false;
1345 c
->cpu_sched_policy
= SCHED_OTHER
;
1346 c
->cpu_sched_priority
= 0;
1350 x
= sched_policy_from_string(rvalue
);
1352 log_syntax(unit
, LOG_WARNING
, filename
, line
, x
, "Failed to parse CPU scheduling policy, ignoring: %s", rvalue
);
1356 c
->cpu_sched_policy
= x
;
1357 /* Moving to or from real-time policy? We need to adjust the priority */
1358 c
->cpu_sched_priority
= CLAMP(c
->cpu_sched_priority
, sched_get_priority_min(x
), sched_get_priority_max(x
));
1359 c
->cpu_sched_set
= true;
1364 int config_parse_exec_mount_apivfs(const char *unit
,
1365 const char *filename
,
1367 const char *section
,
1368 unsigned section_line
,
1375 ExecContext
*c
= data
;
1383 if (isempty(rvalue
)) {
1384 c
->mount_apivfs_set
= false;
1385 c
->mount_apivfs
= false;
1389 k
= parse_boolean(rvalue
);
1391 log_syntax(unit
, LOG_WARNING
, filename
, line
, k
,
1392 "Failed to parse boolean value, ignoring: %s",
1397 c
->mount_apivfs_set
= true;
1398 c
->mount_apivfs
= k
;
1402 int config_parse_numa_mask(const char *unit
,
1403 const char *filename
,
1405 const char *section
,
1406 unsigned section_line
,
1413 NUMAPolicy
*p
= data
;
1420 if (streq(rvalue
, "all")) {
1421 r
= numa_mask_add_all(&p
->nodes
);
1423 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1424 "Failed to create NUMA mask representing \"all\" NUMA nodes, ignoring: %m");
1426 r
= parse_cpu_set_extend(rvalue
, &p
->nodes
, true, unit
, filename
, line
, lvalue
);
1428 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse NUMA node mask, ignoring: %s", rvalue
);
1434 int config_parse_exec_cpu_sched_prio(const char *unit
,
1435 const char *filename
,
1437 const char *section
,
1438 unsigned section_line
,
1445 ExecContext
*c
= data
;
1453 r
= safe_atoi(rvalue
, &i
);
1455 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse CPU scheduling priority, ignoring: %s", rvalue
);
1459 /* On Linux RR/FIFO range from 1 to 99 and OTHER/BATCH may only be 0 */
1460 min
= sched_get_priority_min(c
->cpu_sched_policy
);
1461 max
= sched_get_priority_max(c
->cpu_sched_policy
);
1463 if (i
< min
|| i
> max
) {
1464 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "CPU scheduling priority is out of range, ignoring: %s", rvalue
);
1468 c
->cpu_sched_priority
= i
;
1469 c
->cpu_sched_set
= true;
1474 int config_parse_root_image_options(
1476 const char *filename
,
1478 const char *section
,
1479 unsigned section_line
,
1486 _cleanup_(mount_options_free_allp
) MountOptions
*options
= NULL
;
1487 _cleanup_strv_free_
char **l
= NULL
;
1488 char **first
= NULL
, **second
= NULL
;
1489 ExecContext
*c
= data
;
1490 const Unit
*u
= userdata
;
1498 if (isempty(rvalue
)) {
1499 c
->root_image_options
= mount_options_free_all(c
->root_image_options
);
1503 r
= strv_split_colon_pairs(&l
, rvalue
);
1507 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
1511 STRV_FOREACH_PAIR(first
, second
, l
) {
1512 MountOptions
*o
= NULL
;
1513 _cleanup_free_
char *mount_options_resolved
= NULL
;
1514 const char *mount_options
= NULL
, *partition
= "root";
1515 PartitionDesignator partition_designator
;
1517 /* Format is either 'root:foo' or 'foo' (root is implied) */
1518 if (!isempty(*second
)) {
1520 mount_options
= *second
;
1522 mount_options
= *first
;
1524 partition_designator
= partition_designator_from_string(partition
);
1525 if (partition_designator
< 0) {
1526 log_syntax(unit
, LOG_WARNING
, filename
, line
, partition_designator
,
1527 "Invalid partition name %s, ignoring", partition
);
1530 r
= unit_full_printf(u
, mount_options
, &mount_options_resolved
);
1532 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", mount_options
);
1536 o
= new(MountOptions
, 1);
1539 *o
= (MountOptions
) {
1540 .partition_designator
= partition_designator
,
1541 .options
= TAKE_PTR(mount_options_resolved
),
1543 LIST_APPEND(mount_options
, options
, TAKE_PTR(o
));
1546 /* empty spaces/separators only */
1547 if (LIST_IS_EMPTY(options
))
1548 c
->root_image_options
= mount_options_free_all(c
->root_image_options
);
1550 LIST_JOIN(mount_options
, c
->root_image_options
, options
);
1555 int config_parse_exec_root_hash(
1557 const char *filename
,
1559 const char *section
,
1560 unsigned section_line
,
1567 _cleanup_free_
void *roothash_decoded
= NULL
;
1568 ExecContext
*c
= data
;
1569 size_t roothash_decoded_size
= 0;
1577 if (isempty(rvalue
)) {
1578 /* Reset if the empty string is assigned */
1579 c
->root_hash_path
= mfree(c
->root_hash_path
);
1580 c
->root_hash
= mfree(c
->root_hash
);
1581 c
->root_hash_size
= 0;
1585 if (path_is_absolute(rvalue
)) {
1586 /* We have the path to a roothash to load and decode, eg: RootHash=/foo/bar.roothash */
1587 _cleanup_free_
char *p
= NULL
;
1593 free_and_replace(c
->root_hash_path
, p
);
1594 c
->root_hash
= mfree(c
->root_hash
);
1595 c
->root_hash_size
= 0;
1599 /* We have a roothash to decode, eg: RootHash=012345789abcdef */
1600 r
= unhexmem(rvalue
, strlen(rvalue
), &roothash_decoded
, &roothash_decoded_size
);
1602 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to decode RootHash=, ignoring: %s", rvalue
);
1605 if (roothash_decoded_size
< sizeof(sd_id128_t
)) {
1606 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "RootHash= is too short, ignoring: %s", rvalue
);
1610 free_and_replace(c
->root_hash
, roothash_decoded
);
1611 c
->root_hash_size
= roothash_decoded_size
;
1612 c
->root_hash_path
= mfree(c
->root_hash_path
);
1617 int config_parse_exec_root_hash_sig(
1619 const char *filename
,
1621 const char *section
,
1622 unsigned section_line
,
1629 _cleanup_free_
void *roothash_sig_decoded
= NULL
;
1631 ExecContext
*c
= data
;
1632 size_t roothash_sig_decoded_size
= 0;
1640 if (isempty(rvalue
)) {
1641 /* Reset if the empty string is assigned */
1642 c
->root_hash_sig_path
= mfree(c
->root_hash_sig_path
);
1643 c
->root_hash_sig
= mfree(c
->root_hash_sig
);
1644 c
->root_hash_sig_size
= 0;
1648 if (path_is_absolute(rvalue
)) {
1649 /* We have the path to a roothash signature to load and decode, eg: RootHashSignature=/foo/bar.roothash.p7s */
1650 _cleanup_free_
char *p
= NULL
;
1656 free_and_replace(c
->root_hash_sig_path
, p
);
1657 c
->root_hash_sig
= mfree(c
->root_hash_sig
);
1658 c
->root_hash_sig_size
= 0;
1662 if (!(value
= startswith(rvalue
, "base64:"))) {
1663 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
1664 "Failed to decode RootHashSignature=, not a path but doesn't start with 'base64:', ignoring: %s", rvalue
);
1668 /* We have a roothash signature to decode, eg: RootHashSignature=base64:012345789abcdef */
1669 r
= unbase64mem(value
, strlen(value
), &roothash_sig_decoded
, &roothash_sig_decoded_size
);
1671 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to decode RootHashSignature=, ignoring: %s", rvalue
);
1675 free_and_replace(c
->root_hash_sig
, roothash_sig_decoded
);
1676 c
->root_hash_sig_size
= roothash_sig_decoded_size
;
1677 c
->root_hash_sig_path
= mfree(c
->root_hash_sig_path
);
1682 int config_parse_exec_cpu_affinity(
1684 const char *filename
,
1686 const char *section
,
1687 unsigned section_line
,
1694 ExecContext
*c
= data
;
1695 const Unit
*u
= userdata
;
1696 _cleanup_free_
char *k
= NULL
;
1704 if (streq(rvalue
, "numa")) {
1705 c
->cpu_affinity_from_numa
= true;
1706 cpu_set_reset(&c
->cpu_set
);
1711 r
= unit_full_printf(u
, rvalue
, &k
);
1713 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1714 "Failed to resolve unit specifiers in '%s', ignoring: %m",
1719 r
= parse_cpu_set_extend(k
, &c
->cpu_set
, true, unit
, filename
, line
, lvalue
);
1721 c
->cpu_affinity_from_numa
= false;
1726 int config_parse_capability_set(
1728 const char *filename
,
1730 const char *section
,
1731 unsigned section_line
,
1738 uint64_t *capability_set
= data
;
1739 uint64_t sum
= 0, initial
= 0;
1740 bool invert
= false;
1748 if (rvalue
[0] == '~') {
1753 if (streq(lvalue
, "CapabilityBoundingSet"))
1754 initial
= CAP_ALL
; /* initialized to all bits on */
1755 /* else "AmbientCapabilities" initialized to all bits off */
1757 r
= capability_set_from_string(rvalue
, &sum
);
1759 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= specifier '%s', ignoring: %m", lvalue
, rvalue
);
1763 if (sum
== 0 || *capability_set
== initial
)
1764 /* "", "~" or uninitialized data -> replace */
1765 *capability_set
= invert
? ~sum
: sum
;
1767 /* previous data -> merge */
1769 *capability_set
&= ~sum
;
1771 *capability_set
|= sum
;
1777 int config_parse_exec_selinux_context(
1779 const char *filename
,
1781 const char *section
,
1782 unsigned section_line
,
1789 ExecContext
*c
= data
;
1790 const Unit
*u
= userdata
;
1800 if (isempty(rvalue
)) {
1801 c
->selinux_context
= mfree(c
->selinux_context
);
1802 c
->selinux_context_ignore
= false;
1806 if (rvalue
[0] == '-') {
1812 r
= unit_full_printf(u
, rvalue
, &k
);
1814 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
1815 "Failed to resolve unit specifiers in '%s'%s: %m",
1816 rvalue
, ignore
? ", ignoring" : "");
1817 return ignore
? 0 : -ENOEXEC
;
1820 free_and_replace(c
->selinux_context
, k
);
1821 c
->selinux_context_ignore
= ignore
;
1826 int config_parse_exec_apparmor_profile(
1828 const char *filename
,
1830 const char *section
,
1831 unsigned section_line
,
1838 ExecContext
*c
= data
;
1839 const Unit
*u
= userdata
;
1849 if (isempty(rvalue
)) {
1850 c
->apparmor_profile
= mfree(c
->apparmor_profile
);
1851 c
->apparmor_profile_ignore
= false;
1855 if (rvalue
[0] == '-') {
1861 r
= unit_full_printf(u
, rvalue
, &k
);
1863 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
1864 "Failed to resolve unit specifiers in '%s'%s: %m",
1865 rvalue
, ignore
? ", ignoring" : "");
1866 return ignore
? 0 : -ENOEXEC
;
1869 free_and_replace(c
->apparmor_profile
, k
);
1870 c
->apparmor_profile_ignore
= ignore
;
1875 int config_parse_exec_smack_process_label(
1877 const char *filename
,
1879 const char *section
,
1880 unsigned section_line
,
1887 ExecContext
*c
= data
;
1888 const Unit
*u
= userdata
;
1898 if (isempty(rvalue
)) {
1899 c
->smack_process_label
= mfree(c
->smack_process_label
);
1900 c
->smack_process_label_ignore
= false;
1904 if (rvalue
[0] == '-') {
1910 r
= unit_full_printf(u
, rvalue
, &k
);
1912 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
1913 "Failed to resolve unit specifiers in '%s'%s: %m",
1914 rvalue
, ignore
? ", ignoring" : "");
1915 return ignore
? 0 : -ENOEXEC
;
1918 free_and_replace(c
->smack_process_label
, k
);
1919 c
->smack_process_label_ignore
= ignore
;
1924 int config_parse_timer(
1926 const char *filename
,
1928 const char *section
,
1929 unsigned section_line
,
1936 _cleanup_(calendar_spec_freep
) CalendarSpec
*c
= NULL
;
1937 _cleanup_free_
char *k
= NULL
;
1938 const Unit
*u
= userdata
;
1949 if (isempty(rvalue
)) {
1950 /* Empty assignment resets list */
1951 timer_free_values(t
);
1955 r
= unit_full_printf(u
, rvalue
, &k
);
1957 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
1961 if (ltype
== TIMER_CALENDAR
) {
1962 r
= calendar_spec_from_string(k
, &c
);
1964 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse calendar specification, ignoring: %s", k
);
1968 r
= parse_sec(k
, &usec
);
1970 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse timer value, ignoring: %s", k
);
1975 v
= new(TimerValue
, 1);
1982 .calendar_spec
= TAKE_PTR(c
),
1985 LIST_PREPEND(value
, t
->values
, v
);
1990 int config_parse_trigger_unit(
1992 const char *filename
,
1994 const char *section
,
1995 unsigned section_line
,
2002 _cleanup_free_
char *p
= NULL
;
2012 if (UNIT_TRIGGER(u
)) {
2013 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Multiple units to trigger specified, ignoring: %s", rvalue
);
2017 r
= unit_name_printf(u
, rvalue
, &p
);
2019 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2023 type
= unit_name_to_type(p
);
2025 log_syntax(unit
, LOG_WARNING
, filename
, line
, type
, "Unit type not valid, ignoring: %s", rvalue
);
2028 if (unit_has_name(u
, p
)) {
2029 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Units cannot trigger themselves, ignoring: %s", rvalue
);
2033 r
= unit_add_two_dependencies_by_name(u
, UNIT_BEFORE
, UNIT_TRIGGERS
, p
, true, UNIT_DEPENDENCY_FILE
);
2035 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add trigger on %s, ignoring: %m", p
);
2042 int config_parse_path_spec(const char *unit
,
2043 const char *filename
,
2045 const char *section
,
2046 unsigned section_line
,
2056 _cleanup_free_
char *k
= NULL
;
2064 if (isempty(rvalue
)) {
2065 /* Empty assignment clears list */
2070 b
= path_type_from_string(lvalue
);
2072 log_syntax(unit
, LOG_WARNING
, filename
, line
, b
, "Failed to parse path type, ignoring: %s", lvalue
);
2076 r
= unit_path_printf(UNIT(p
), rvalue
, &k
);
2078 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2082 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2086 s
= new0(PathSpec
, 1);
2091 s
->path
= TAKE_PTR(k
);
2095 LIST_PREPEND(spec
, p
->specs
, s
);
2100 int config_parse_socket_service(
2102 const char *filename
,
2104 const char *section
,
2105 unsigned section_line
,
2112 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
2113 _cleanup_free_
char *p
= NULL
;
2123 r
= unit_name_printf(UNIT(s
), rvalue
, &p
);
2125 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2129 if (!endswith(p
, ".service")) {
2130 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Unit must be of type service, ignoring: %s", rvalue
);
2134 r
= manager_load_unit(UNIT(s
)->manager
, p
, NULL
, &error
, &x
);
2136 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to load unit %s, ignoring: %s", rvalue
, bus_error_message(&error
, r
));
2140 unit_ref_set(&s
->service
, UNIT(s
), x
);
2145 int config_parse_fdname(
2147 const char *filename
,
2149 const char *section
,
2150 unsigned section_line
,
2157 _cleanup_free_
char *p
= NULL
;
2166 if (isempty(rvalue
)) {
2167 s
->fdname
= mfree(s
->fdname
);
2171 r
= unit_fd_printf(UNIT(s
), rvalue
, &p
);
2173 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2177 if (!fdname_is_valid(p
)) {
2178 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", p
);
2182 return free_and_replace(s
->fdname
, p
);
2185 int config_parse_service_sockets(
2187 const char *filename
,
2189 const char *section
,
2190 unsigned section_line
,
2205 for (const char *p
= rvalue
;;) {
2206 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2208 r
= extract_first_word(&p
, &word
, NULL
, 0);
2212 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Trailing garbage in sockets, ignoring: %s", rvalue
);
2218 r
= unit_name_printf(UNIT(s
), word
, &k
);
2220 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
2224 if (!endswith(k
, ".socket")) {
2225 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Unit must be of type socket, ignoring: %s", k
);
2229 r
= unit_add_two_dependencies_by_name(UNIT(s
), UNIT_WANTS
, UNIT_AFTER
, k
, true, UNIT_DEPENDENCY_FILE
);
2231 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
2233 r
= unit_add_dependency_by_name(UNIT(s
), UNIT_TRIGGERED_BY
, k
, true, UNIT_DEPENDENCY_FILE
);
2235 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
2239 int config_parse_bus_name(
2241 const char *filename
,
2243 const char *section
,
2244 unsigned section_line
,
2251 _cleanup_free_
char *k
= NULL
;
2252 const Unit
*u
= userdata
;
2260 r
= unit_full_printf_full(u
, rvalue
, SD_BUS_MAXIMUM_NAME_LENGTH
, &k
);
2262 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2266 if (!sd_bus_service_name_is_valid(k
)) {
2267 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid bus name, ignoring: %s", k
);
2271 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
2274 int config_parse_service_timeout(
2276 const char *filename
,
2278 const char *section
,
2279 unsigned section_line
,
2286 Service
*s
= userdata
;
2295 /* This is called for two cases: TimeoutSec= and TimeoutStartSec=. */
2297 /* Traditionally, these options accepted 0 to disable the timeouts. However, a timeout of 0 suggests it happens
2298 * immediately, hence fix this to become USEC_INFINITY instead. This is in-line with how we internally handle
2299 * all other timeouts. */
2300 r
= parse_sec_fix_0(rvalue
, &usec
);
2302 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
2306 s
->start_timeout_defined
= true;
2307 s
->timeout_start_usec
= usec
;
2309 if (streq(lvalue
, "TimeoutSec"))
2310 s
->timeout_stop_usec
= usec
;
2315 int config_parse_timeout_abort(
2317 const char *filename
,
2319 const char *section
,
2320 unsigned section_line
,
2335 /* Note: apart from setting the arg, this returns an extra bit of information in the return value. */
2337 if (isempty(rvalue
)) {
2339 return 0; /* "not set" */
2342 r
= parse_sec(rvalue
, ret
);
2344 return log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= setting, ignoring: %s", lvalue
, rvalue
);
2346 return 1; /* "set" */
2349 int config_parse_service_timeout_abort(
2351 const char *filename
,
2353 const char *section
,
2354 unsigned section_line
,
2361 Service
*s
= userdata
;
2366 r
= config_parse_timeout_abort(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
,
2367 &s
->timeout_abort_usec
, s
);
2369 s
->timeout_abort_set
= r
;
2373 int config_parse_sec_fix_0(
2375 const char *filename
,
2377 const char *section
,
2378 unsigned section_line
,
2385 usec_t
*usec
= data
;
2393 /* This is pretty much like config_parse_sec(), except that this treats a time of 0 as infinity, for
2394 * compatibility with older versions of systemd where 0 instead of infinity was used as indicator to turn off a
2397 r
= parse_sec_fix_0(rvalue
, usec
);
2399 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
2404 int config_parse_user_group_compat(
2406 const char *filename
,
2408 const char *section
,
2409 unsigned section_line
,
2416 _cleanup_free_
char *k
= NULL
;
2418 const Unit
*u
= userdata
;
2426 if (isempty(rvalue
)) {
2427 *user
= mfree(*user
);
2431 r
= unit_full_printf(u
, rvalue
, &k
);
2433 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", rvalue
);
2437 if (!valid_user_group_name(k
, VALID_USER_ALLOW_NUMERIC
|VALID_USER_RELAX
|VALID_USER_WARN
)) {
2438 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2442 if (strstr(lvalue
, "User") && streq(k
, NOBODY_USER_NAME
))
2443 log_struct(LOG_NOTICE
,
2444 "MESSAGE=%s:%u: Special user %s configured, this is not safe!", filename
, line
, k
,
2446 "MESSAGE_ID=" SD_MESSAGE_NOBODY_USER_UNSUITABLE_STR
,
2447 "OFFENDING_USER=%s", k
,
2448 "CONFIG_FILE=%s", filename
,
2449 "CONFIG_LINE=%u", line
);
2451 return free_and_replace(*user
, k
);
2454 int config_parse_user_group_strv_compat(
2456 const char *filename
,
2458 const char *section
,
2459 unsigned section_line
,
2466 char ***users
= data
;
2467 const Unit
*u
= userdata
;
2475 if (isempty(rvalue
)) {
2476 *users
= strv_free(*users
);
2480 for (const char *p
= rvalue
;;) {
2481 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2483 r
= extract_first_word(&p
, &word
, NULL
, 0);
2487 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax: %s", rvalue
);
2493 r
= unit_full_printf(u
, word
, &k
);
2495 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", word
);
2499 if (!valid_user_group_name(k
, VALID_USER_ALLOW_NUMERIC
|VALID_USER_RELAX
|VALID_USER_WARN
)) {
2500 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2504 r
= strv_push(users
, k
);
2512 int config_parse_working_directory(
2514 const char *filename
,
2516 const char *section
,
2517 unsigned section_line
,
2524 ExecContext
*c
= data
;
2525 const Unit
*u
= userdata
;
2535 if (isempty(rvalue
)) {
2536 c
->working_directory_home
= false;
2537 c
->working_directory
= mfree(c
->working_directory
);
2541 if (rvalue
[0] == '-') {
2547 if (streq(rvalue
, "~")) {
2548 c
->working_directory_home
= true;
2549 c
->working_directory
= mfree(c
->working_directory
);
2551 _cleanup_free_
char *k
= NULL
;
2553 r
= unit_path_printf(u
, rvalue
, &k
);
2555 log_syntax(unit
, missing_ok
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
2556 "Failed to resolve unit specifiers in working directory path '%s'%s: %m",
2557 rvalue
, missing_ok
? ", ignoring" : "");
2558 return missing_ok
? 0 : -ENOEXEC
;
2561 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
| (missing_ok
? 0 : PATH_CHECK_FATAL
), unit
, filename
, line
, lvalue
);
2563 return missing_ok
? 0 : -ENOEXEC
;
2565 c
->working_directory_home
= false;
2566 free_and_replace(c
->working_directory
, k
);
2569 c
->working_directory_missing_ok
= missing_ok
;
2573 int config_parse_unit_env_file(const char *unit
,
2574 const char *filename
,
2576 const char *section
,
2577 unsigned section_line
,
2585 const Unit
*u
= userdata
;
2586 _cleanup_free_
char *n
= NULL
;
2594 if (isempty(rvalue
)) {
2595 /* Empty assignment frees the list */
2596 *env
= strv_free(*env
);
2600 r
= unit_full_printf_full(u
, rvalue
, PATH_MAX
, &n
);
2602 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2606 r
= path_simplify_and_warn(n
[0] == '-' ? n
+ 1 : n
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2610 r
= strv_push(env
, n
);
2619 int config_parse_environ(
2621 const char *filename
,
2623 const char *section
,
2624 unsigned section_line
,
2631 const Unit
*u
= userdata
;
2640 if (isempty(rvalue
)) {
2641 /* Empty assignment resets the list */
2642 *env
= strv_free(*env
);
2646 for (const char *p
= rvalue
;; ) {
2647 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
2649 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2653 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2654 "Invalid syntax, ignoring: %s", rvalue
);
2661 r
= unit_env_printf(u
, word
, &resolved
);
2663 r
= specifier_printf(word
, sc_arg_max(), system_and_tmp_specifier_table
, NULL
, &resolved
);
2665 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2666 "Failed to resolve specifiers in %s, ignoring: %m", word
);
2670 if (!env_assignment_is_valid(resolved
)) {
2671 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
2672 "Invalid environment assignment, ignoring: %s", resolved
);
2676 r
= strv_env_replace_consume(env
, TAKE_PTR(resolved
));
2678 return log_error_errno(r
, "Failed to update environment: %m");
2682 int config_parse_pass_environ(
2684 const char *filename
,
2686 const char *section
,
2687 unsigned section_line
,
2694 _cleanup_strv_free_
char **n
= NULL
;
2695 const Unit
*u
= userdata
;
2696 char*** passenv
= data
;
2705 if (isempty(rvalue
)) {
2706 /* Empty assignment resets the list */
2707 *passenv
= strv_free(*passenv
);
2711 for (const char *p
= rvalue
;;) {
2712 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2714 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
2718 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2719 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2726 r
= unit_env_printf(u
, word
, &k
);
2728 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2729 "Failed to resolve specifiers in %s, ignoring: %m", word
);
2735 if (!env_name_is_valid(k
)) {
2736 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
2737 "Invalid environment name for %s, ignoring: %s", lvalue
, k
);
2741 if (!GREEDY_REALLOC(n
, nlen
+ 2))
2744 n
[nlen
++] = TAKE_PTR(k
);
2749 r
= strv_extend_strv(passenv
, n
, true);
2757 int config_parse_unset_environ(
2759 const char *filename
,
2761 const char *section
,
2762 unsigned section_line
,
2769 _cleanup_strv_free_
char **n
= NULL
;
2770 char*** unsetenv
= data
;
2771 const Unit
*u
= userdata
;
2780 if (isempty(rvalue
)) {
2781 /* Empty assignment resets the list */
2782 *unsetenv
= strv_free(*unsetenv
);
2786 for (const char *p
= rvalue
;;) {
2787 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2789 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2793 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2794 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2801 r
= unit_env_printf(u
, word
, &k
);
2803 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2804 "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2810 if (!env_assignment_is_valid(k
) && !env_name_is_valid(k
)) {
2811 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
2812 "Invalid environment name or assignment %s, ignoring: %s", lvalue
, k
);
2816 if (!GREEDY_REALLOC(n
, nlen
+ 2))
2819 n
[nlen
++] = TAKE_PTR(k
);
2824 r
= strv_extend_strv(unsetenv
, n
, true);
2832 int config_parse_log_extra_fields(
2834 const char *filename
,
2836 const char *section
,
2837 unsigned section_line
,
2844 ExecContext
*c
= data
;
2845 const Unit
*u
= userdata
;
2853 if (isempty(rvalue
)) {
2854 exec_context_free_log_extra_fields(c
);
2858 for (const char *p
= rvalue
;;) {
2859 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2863 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2867 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
2873 r
= unit_full_printf(u
, word
, &k
);
2875 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2879 eq
= strchr(k
, '=');
2881 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Log field lacks '=' character, ignoring: %s", k
);
2885 if (!journal_field_valid(k
, eq
-k
, false)) {
2886 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Log field name is invalid, ignoring: %s", k
);
2890 t
= reallocarray(c
->log_extra_fields
, c
->n_log_extra_fields
+1, sizeof(struct iovec
));
2894 c
->log_extra_fields
= t
;
2895 c
->log_extra_fields
[c
->n_log_extra_fields
++] = IOVEC_MAKE_STRING(k
);
2901 int config_parse_log_namespace(
2903 const char *filename
,
2905 const char *section
,
2906 unsigned section_line
,
2913 _cleanup_free_
char *k
= NULL
;
2914 ExecContext
*c
= data
;
2915 const Unit
*u
= userdata
;
2923 if (isempty(rvalue
)) {
2924 c
->log_namespace
= mfree(c
->log_namespace
);
2928 r
= unit_full_printf_full(u
, rvalue
, NAME_MAX
, &k
);
2930 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2934 if (!log_namespace_name_valid(k
)) {
2935 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Specified log namespace name is not valid, ignoring: %s", k
);
2939 free_and_replace(c
->log_namespace
, k
);
2943 int config_parse_unit_condition_path(
2945 const char *filename
,
2947 const char *section
,
2948 unsigned section_line
,
2955 _cleanup_free_
char *p
= NULL
;
2956 Condition
**list
= data
, *c
;
2957 ConditionType t
= ltype
;
2958 bool trigger
, negate
;
2959 const Unit
*u
= userdata
;
2967 if (isempty(rvalue
)) {
2968 /* Empty assignment resets the list */
2969 *list
= condition_free_list(*list
);
2973 trigger
= rvalue
[0] == '|';
2977 negate
= rvalue
[0] == '!';
2981 r
= unit_path_printf(u
, rvalue
, &p
);
2983 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2987 r
= path_simplify_and_warn(p
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2991 c
= condition_new(t
, p
, trigger
, negate
);
2995 LIST_PREPEND(conditions
, *list
, c
);
2999 int config_parse_unit_condition_string(
3001 const char *filename
,
3003 const char *section
,
3004 unsigned section_line
,
3011 _cleanup_free_
char *s
= NULL
;
3012 Condition
**list
= data
, *c
;
3013 ConditionType t
= ltype
;
3014 bool trigger
, negate
;
3015 const Unit
*u
= userdata
;
3023 if (isempty(rvalue
)) {
3024 /* Empty assignment resets the list */
3025 *list
= condition_free_list(*list
);
3029 trigger
= *rvalue
== '|';
3031 rvalue
+= 1 + strspn(rvalue
+ 1, WHITESPACE
);
3033 negate
= *rvalue
== '!';
3035 rvalue
+= 1 + strspn(rvalue
+ 1, WHITESPACE
);
3037 r
= unit_full_printf(u
, rvalue
, &s
);
3039 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3040 "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
3044 c
= condition_new(t
, s
, trigger
, negate
);
3048 LIST_PREPEND(conditions
, *list
, c
);
3052 int config_parse_unit_requires_mounts_for(
3054 const char *filename
,
3056 const char *section
,
3057 unsigned section_line
,
3072 for (const char *p
= rvalue
;;) {
3073 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
3075 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3079 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3080 "Invalid syntax, ignoring: %s", rvalue
);
3086 r
= unit_path_printf(u
, word
, &resolved
);
3088 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
3092 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
3096 r
= unit_require_mounts_for(u
, resolved
, UNIT_DEPENDENCY_FILE
);
3098 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add required mount '%s', ignoring: %m", resolved
);
3104 int config_parse_documentation(
3106 const char *filename
,
3108 const char *section
,
3109 unsigned section_line
,
3125 if (isempty(rvalue
)) {
3126 /* Empty assignment resets the list */
3127 u
->documentation
= strv_free(u
->documentation
);
3131 r
= config_parse_unit_strv_printf(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
,
3132 rvalue
, data
, userdata
);
3136 for (a
= b
= u
->documentation
; a
&& *a
; a
++) {
3138 if (documentation_url_is_valid(*a
))
3141 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid URL, ignoring: %s", *a
);
3152 int config_parse_syscall_filter(
3154 const char *filename
,
3156 const char *section
,
3157 unsigned section_line
,
3164 ExecContext
*c
= data
;
3165 _unused_
const Unit
*u
= userdata
;
3166 bool invert
= false;
3174 if (isempty(rvalue
)) {
3175 /* Empty assignment resets the list */
3176 c
->syscall_filter
= hashmap_free(c
->syscall_filter
);
3177 c
->syscall_allow_list
= false;
3181 if (rvalue
[0] == '~') {
3186 if (!c
->syscall_filter
) {
3187 c
->syscall_filter
= hashmap_new(NULL
);
3188 if (!c
->syscall_filter
)
3192 /* Allow everything but the ones listed */
3193 c
->syscall_allow_list
= false;
3195 /* Allow nothing but the ones listed */
3196 c
->syscall_allow_list
= true;
3198 /* Accept default syscalls if we are on a allow_list */
3199 r
= seccomp_parse_syscall_filter(
3200 "@default", -1, c
->syscall_filter
,
3201 SECCOMP_PARSE_PERMISSIVE
|SECCOMP_PARSE_ALLOW_LIST
,
3209 for (const char *p
= rvalue
;;) {
3210 _cleanup_free_
char *word
= NULL
, *name
= NULL
;
3213 r
= extract_first_word(&p
, &word
, NULL
, 0);
3217 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3218 "Invalid syntax, ignoring: %s", rvalue
);
3224 r
= parse_syscall_and_errno(word
, &name
, &num
);
3226 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3227 "Failed to parse syscall:errno, ignoring: %s", word
);
3230 if (!invert
&& num
>= 0) {
3231 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3232 "Allow-listed system calls cannot take error number, ignoring: %s", word
);
3236 r
= seccomp_parse_syscall_filter(
3237 name
, num
, c
->syscall_filter
,
3238 SECCOMP_PARSE_LOG
|SECCOMP_PARSE_PERMISSIVE
|
3239 (invert
? SECCOMP_PARSE_INVERT
: 0)|
3240 (c
->syscall_allow_list
? SECCOMP_PARSE_ALLOW_LIST
: 0),
3241 unit
, filename
, line
);
3247 int config_parse_syscall_log(
3249 const char *filename
,
3251 const char *section
,
3252 unsigned section_line
,
3259 ExecContext
*c
= data
;
3260 _unused_
const Unit
*u
= userdata
;
3261 bool invert
= false;
3270 if (isempty(rvalue
)) {
3271 /* Empty assignment resets the list */
3272 c
->syscall_log
= hashmap_free(c
->syscall_log
);
3273 c
->syscall_log_allow_list
= false;
3277 if (rvalue
[0] == '~') {
3282 if (!c
->syscall_log
) {
3283 c
->syscall_log
= hashmap_new(NULL
);
3284 if (!c
->syscall_log
)
3288 /* Log everything but the ones listed */
3289 c
->syscall_log_allow_list
= false;
3291 /* Log nothing but the ones listed */
3292 c
->syscall_log_allow_list
= true;
3297 _cleanup_free_
char *word
= NULL
;
3299 r
= extract_first_word(&p
, &word
, NULL
, 0);
3303 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3309 r
= seccomp_parse_syscall_filter(
3310 word
, -1, c
->syscall_log
,
3311 SECCOMP_PARSE_LOG
|SECCOMP_PARSE_PERMISSIVE
|
3312 (invert
? SECCOMP_PARSE_INVERT
: 0)|
3313 (c
->syscall_log_allow_list
? SECCOMP_PARSE_ALLOW_LIST
: 0),
3314 unit
, filename
, line
);
3320 int config_parse_syscall_archs(
3322 const char *filename
,
3324 const char *section
,
3325 unsigned section_line
,
3335 if (isempty(rvalue
)) {
3336 *archs
= set_free(*archs
);
3340 for (const char *p
= rvalue
;;) {
3341 _cleanup_free_
char *word
= NULL
;
3344 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3348 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3349 "Invalid syntax, ignoring: %s", rvalue
);
3355 r
= seccomp_arch_from_string(word
, &a
);
3357 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3358 "Failed to parse system call architecture \"%s\", ignoring: %m", word
);
3362 r
= set_ensure_put(archs
, NULL
, UINT32_TO_PTR(a
+ 1));
3368 int config_parse_syscall_errno(
3370 const char *filename
,
3372 const char *section
,
3373 unsigned section_line
,
3380 ExecContext
*c
= data
;
3387 if (isempty(rvalue
) || streq(rvalue
, "kill")) {
3388 /* Empty assignment resets to KILL */
3389 c
->syscall_errno
= SECCOMP_ERROR_NUMBER_KILL
;
3393 e
= parse_errno(rvalue
);
3395 log_syntax(unit
, LOG_WARNING
, filename
, line
, e
, "Failed to parse error number, ignoring: %s", rvalue
);
3399 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid error number, ignoring: %s", rvalue
);
3403 c
->syscall_errno
= e
;
3407 int config_parse_address_families(
3409 const char *filename
,
3411 const char *section
,
3412 unsigned section_line
,
3419 ExecContext
*c
= data
;
3420 bool invert
= false;
3427 if (isempty(rvalue
)) {
3428 /* Empty assignment resets the list */
3429 c
->address_families
= set_free(c
->address_families
);
3430 c
->address_families_allow_list
= false;
3434 if (streq(rvalue
, "none")) {
3435 /* Forbid all address families. */
3436 c
->address_families
= set_free(c
->address_families
);
3437 c
->address_families_allow_list
= true;
3441 if (rvalue
[0] == '~') {
3446 if (!c
->address_families
) {
3447 c
->address_families
= set_new(NULL
);
3448 if (!c
->address_families
)
3451 c
->address_families_allow_list
= !invert
;
3454 for (const char *p
= rvalue
;;) {
3455 _cleanup_free_
char *word
= NULL
;
3458 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3462 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3463 "Invalid syntax, ignoring: %s", rvalue
);
3469 af
= af_from_name(word
);
3471 log_syntax(unit
, LOG_WARNING
, filename
, line
, af
,
3472 "Failed to parse address family, ignoring: %s", word
);
3476 /* If we previously wanted to forbid an address family and now
3477 * we want to allow it, then just remove it from the list.
3479 if (!invert
== c
->address_families_allow_list
) {
3480 r
= set_put(c
->address_families
, INT_TO_PTR(af
));
3484 set_remove(c
->address_families
, INT_TO_PTR(af
));
3488 int config_parse_restrict_namespaces(
3490 const char *filename
,
3492 const char *section
,
3493 unsigned section_line
,
3500 ExecContext
*c
= data
;
3501 unsigned long flags
;
3502 bool invert
= false;
3505 if (isempty(rvalue
)) {
3506 /* Reset to the default. */
3507 c
->restrict_namespaces
= NAMESPACE_FLAGS_INITIAL
;
3511 /* Boolean parameter ignores the previous settings */
3512 r
= parse_boolean(rvalue
);
3514 c
->restrict_namespaces
= 0;
3516 } else if (r
== 0) {
3517 c
->restrict_namespaces
= NAMESPACE_FLAGS_ALL
;
3521 if (rvalue
[0] == '~') {
3526 /* Not a boolean argument, in this case it's a list of namespace types. */
3527 r
= namespace_flags_from_string(rvalue
, &flags
);
3529 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse namespace type string, ignoring: %s", rvalue
);
3533 if (c
->restrict_namespaces
== NAMESPACE_FLAGS_INITIAL
)
3534 /* Initial assignment. Just set the value. */
3535 c
->restrict_namespaces
= invert
? (~flags
) & NAMESPACE_FLAGS_ALL
: flags
;
3537 /* Merge the value with the previous one. */
3538 SET_FLAG(c
->restrict_namespaces
, flags
, !invert
);
3544 int config_parse_unit_slice(
3546 const char *filename
,
3548 const char *section
,
3549 unsigned section_line
,
3556 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
3557 _cleanup_free_
char *k
= NULL
;
3558 Unit
*u
= userdata
, *slice
;
3566 r
= unit_name_printf(u
, rvalue
, &k
);
3568 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
3572 r
= manager_load_unit(u
->manager
, k
, NULL
, &error
, &slice
);
3574 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to load slice unit %s, ignoring: %s", k
, bus_error_message(&error
, r
));
3578 r
= unit_set_slice(u
, slice
, UNIT_DEPENDENCY_FILE
);
3580 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to assign slice %s to unit %s, ignoring: %m", slice
->id
, u
->id
);
3587 int config_parse_cpu_quota(
3589 const char *filename
,
3591 const char *section
,
3592 unsigned section_line
,
3599 CGroupContext
*c
= data
;
3606 if (isempty(rvalue
)) {
3607 c
->cpu_quota_per_sec_usec
= USEC_INFINITY
;
3611 r
= parse_permyriad_unbounded(rvalue
);
3613 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid CPU quota '%s', ignoring.", rvalue
);
3617 c
->cpu_quota_per_sec_usec
= ((usec_t
) r
* USEC_PER_SEC
) / 10000U;
3621 int config_parse_allowed_cpus(
3623 const char *filename
,
3625 const char *section
,
3626 unsigned section_line
,
3633 CGroupContext
*c
= data
;
3635 (void) parse_cpu_set_extend(rvalue
, &c
->cpuset_cpus
, true, unit
, filename
, line
, lvalue
);
3640 int config_parse_allowed_mems(
3642 const char *filename
,
3644 const char *section
,
3645 unsigned section_line
,
3652 CGroupContext
*c
= data
;
3654 (void) parse_cpu_set_extend(rvalue
, &c
->cpuset_mems
, true, unit
, filename
, line
, lvalue
);
3659 int config_parse_memory_limit(
3661 const char *filename
,
3663 const char *section
,
3664 unsigned section_line
,
3671 CGroupContext
*c
= data
;
3672 uint64_t bytes
= CGROUP_LIMIT_MAX
;
3675 if (isempty(rvalue
) && STR_IN_SET(lvalue
, "DefaultMemoryLow",
3679 bytes
= CGROUP_LIMIT_MIN
;
3680 else if (!isempty(rvalue
) && !streq(rvalue
, "infinity")) {
3682 r
= parse_permyriad(rvalue
);
3684 r
= parse_size(rvalue
, 1024, &bytes
);
3686 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid memory limit '%s', ignoring: %m", rvalue
);
3690 bytes
= physical_memory_scale(r
, 10000U);
3692 if (bytes
>= UINT64_MAX
||
3693 (bytes
<= 0 && !STR_IN_SET(lvalue
, "MemorySwapMax", "MemoryLow", "MemoryMin", "DefaultMemoryLow", "DefaultMemoryMin"))) {
3694 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Memory limit '%s' out of range, ignoring.", rvalue
);
3699 if (streq(lvalue
, "DefaultMemoryLow")) {
3700 c
->default_memory_low
= bytes
;
3701 c
->default_memory_low_set
= true;
3702 } else if (streq(lvalue
, "DefaultMemoryMin")) {
3703 c
->default_memory_min
= bytes
;
3704 c
->default_memory_min_set
= true;
3705 } else if (streq(lvalue
, "MemoryMin")) {
3706 c
->memory_min
= bytes
;
3707 c
->memory_min_set
= true;
3708 } else if (streq(lvalue
, "MemoryLow")) {
3709 c
->memory_low
= bytes
;
3710 c
->memory_low_set
= true;
3711 } else if (streq(lvalue
, "MemoryHigh"))
3712 c
->memory_high
= bytes
;
3713 else if (streq(lvalue
, "MemoryMax"))
3714 c
->memory_max
= bytes
;
3715 else if (streq(lvalue
, "MemorySwapMax"))
3716 c
->memory_swap_max
= bytes
;
3717 else if (streq(lvalue
, "MemoryLimit"))
3718 c
->memory_limit
= bytes
;
3725 int config_parse_tasks_max(
3727 const char *filename
,
3729 const char *section
,
3730 unsigned section_line
,
3737 const Unit
*u
= userdata
;
3738 TasksMax
*tasks_max
= data
;
3742 if (isempty(rvalue
)) {
3743 *tasks_max
= u
? u
->manager
->default_tasks_max
: TASKS_MAX_UNSET
;
3747 if (streq(rvalue
, "infinity")) {
3748 *tasks_max
= TASKS_MAX_UNSET
;
3752 r
= parse_permyriad(rvalue
);
3754 *tasks_max
= (TasksMax
) { r
, 10000U }; /* r‱ */
3756 r
= safe_atou64(rvalue
, &v
);
3758 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid maximum tasks value '%s', ignoring: %m", rvalue
);
3762 if (v
<= 0 || v
>= UINT64_MAX
) {
3763 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Maximum tasks value '%s' out of range, ignoring.", rvalue
);
3767 *tasks_max
= (TasksMax
) { v
};
3773 int config_parse_delegate(
3775 const char *filename
,
3777 const char *section
,
3778 unsigned section_line
,
3785 CGroupContext
*c
= data
;
3789 t
= unit_name_to_type(unit
);
3790 assert(t
!= _UNIT_TYPE_INVALID
);
3792 if (!unit_vtable
[t
]->can_delegate
) {
3793 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Delegate= setting not supported for this unit type, ignoring.");
3797 /* We either accept a boolean value, which may be used to turn on delegation for all controllers, or turn it
3798 * off for all. Or it takes a list of controller names, in which case we add the specified controllers to the
3799 * mask to delegate. */
3801 if (isempty(rvalue
)) {
3802 /* An empty string resets controllers and set Delegate=yes. */
3804 c
->delegate_controllers
= 0;
3808 r
= parse_boolean(rvalue
);
3810 CGroupMask mask
= 0;
3812 for (const char *p
= rvalue
;;) {
3813 _cleanup_free_
char *word
= NULL
;
3814 CGroupController cc
;
3816 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3820 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3826 cc
= cgroup_controller_from_string(word
);
3828 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid controller name '%s', ignoring", word
);
3832 mask
|= CGROUP_CONTROLLER_TO_MASK(cc
);
3836 c
->delegate_controllers
|= mask
;
3840 c
->delegate_controllers
= _CGROUP_MASK_ALL
;
3842 c
->delegate
= false;
3843 c
->delegate_controllers
= 0;
3849 int config_parse_managed_oom_mode(
3851 const char *filename
,
3853 const char *section
,
3854 unsigned section_line
,
3861 ManagedOOMMode
*mode
= data
, m
;
3864 t
= unit_name_to_type(unit
);
3865 assert(t
!= _UNIT_TYPE_INVALID
);
3867 if (!unit_vtable
[t
]->can_set_managed_oom
)
3868 return log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "%s= is not supported for this unit type, ignoring.", lvalue
);
3870 if (isempty(rvalue
)) {
3871 *mode
= MANAGED_OOM_AUTO
;
3875 m
= managed_oom_mode_from_string(rvalue
);
3877 log_syntax(unit
, LOG_WARNING
, filename
, line
, m
, "Invalid syntax, ignoring: %s", rvalue
);
3885 int config_parse_managed_oom_mem_pressure_limit(
3887 const char *filename
,
3889 const char *section
,
3890 unsigned section_line
,
3897 uint32_t *limit
= data
;
3901 t
= unit_name_to_type(unit
);
3902 assert(t
!= _UNIT_TYPE_INVALID
);
3904 if (!unit_vtable
[t
]->can_set_managed_oom
)
3905 return log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "%s= is not supported for this unit type, ignoring.", lvalue
);
3907 if (isempty(rvalue
)) {
3912 r
= parse_permyriad(rvalue
);
3914 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse memory pressure limit value, ignoring: %s", rvalue
);
3918 /* Normalize to 2^32-1 == 100% */
3919 *limit
= UINT32_SCALE_FROM_PERMYRIAD(r
);
3923 int config_parse_device_allow(
3925 const char *filename
,
3927 const char *section
,
3928 unsigned section_line
,
3935 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3936 CGroupContext
*c
= data
;
3937 const char *p
= rvalue
;
3940 if (isempty(rvalue
)) {
3941 while (c
->device_allow
)
3942 cgroup_context_free_device_allow(c
, c
->device_allow
);
3947 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3951 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3952 "Failed to extract device path and rights from '%s', ignoring.", rvalue
);
3956 r
= unit_path_printf(userdata
, path
, &resolved
);
3958 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3959 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3963 if (!STARTSWITH_SET(resolved
, "block-", "char-")) {
3965 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3969 if (!valid_device_node_path(resolved
)) {
3970 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid device node path '%s', ignoring.", resolved
);
3975 if (!isempty(p
) && !in_charset(p
, "rwm")) {
3976 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid device rights '%s', ignoring.", p
);
3980 return cgroup_add_device_allow(c
, resolved
, p
);
3983 int config_parse_io_device_weight(
3985 const char *filename
,
3987 const char *section
,
3988 unsigned section_line
,
3995 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3996 CGroupIODeviceWeight
*w
;
3997 CGroupContext
*c
= data
;
3998 const char *p
= rvalue
;
4006 if (isempty(rvalue
)) {
4007 while (c
->io_device_weights
)
4008 cgroup_context_free_io_device_weight(c
, c
->io_device_weights
);
4013 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4016 if (r
<= 0 || isempty(p
)) {
4017 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4018 "Failed to extract device path and weight from '%s', ignoring.", rvalue
);
4022 r
= unit_path_printf(userdata
, path
, &resolved
);
4024 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4025 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4029 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4033 r
= cg_weight_parse(p
, &u
);
4035 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "IO weight '%s' invalid, ignoring: %m", p
);
4039 assert(u
!= CGROUP_WEIGHT_INVALID
);
4041 w
= new0(CGroupIODeviceWeight
, 1);
4045 w
->path
= TAKE_PTR(resolved
);
4048 LIST_PREPEND(device_weights
, c
->io_device_weights
, w
);
4052 int config_parse_io_device_latency(
4054 const char *filename
,
4056 const char *section
,
4057 unsigned section_line
,
4064 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4065 CGroupIODeviceLatency
*l
;
4066 CGroupContext
*c
= data
;
4067 const char *p
= rvalue
;
4075 if (isempty(rvalue
)) {
4076 while (c
->io_device_latencies
)
4077 cgroup_context_free_io_device_latency(c
, c
->io_device_latencies
);
4082 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4085 if (r
<= 0 || isempty(p
)) {
4086 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4087 "Failed to extract device path and latency from '%s', ignoring.", rvalue
);
4091 r
= unit_path_printf(userdata
, path
, &resolved
);
4093 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4094 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4098 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4102 r
= parse_sec(p
, &usec
);
4104 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse timer value, ignoring: %s", p
);
4108 l
= new0(CGroupIODeviceLatency
, 1);
4112 l
->path
= TAKE_PTR(resolved
);
4113 l
->target_usec
= usec
;
4115 LIST_PREPEND(device_latencies
, c
->io_device_latencies
, l
);
4119 int config_parse_io_limit(
4121 const char *filename
,
4123 const char *section
,
4124 unsigned section_line
,
4131 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4132 CGroupIODeviceLimit
*l
= NULL
, *t
;
4133 CGroupContext
*c
= data
;
4134 CGroupIOLimitType type
;
4135 const char *p
= rvalue
;
4143 type
= cgroup_io_limit_type_from_string(lvalue
);
4146 if (isempty(rvalue
)) {
4147 LIST_FOREACH(device_limits
, l
, c
->io_device_limits
)
4148 l
->limits
[type
] = cgroup_io_limit_defaults
[type
];
4152 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4155 if (r
<= 0 || isempty(p
)) {
4156 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4157 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
4161 r
= unit_path_printf(userdata
, path
, &resolved
);
4163 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4164 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4168 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4172 if (streq("infinity", p
))
4173 num
= CGROUP_LIMIT_MAX
;
4175 r
= parse_size(p
, 1000, &num
);
4176 if (r
< 0 || num
<= 0) {
4177 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid IO limit '%s', ignoring.", p
);
4182 LIST_FOREACH(device_limits
, t
, c
->io_device_limits
) {
4183 if (path_equal(resolved
, t
->path
)) {
4190 CGroupIOLimitType ttype
;
4192 l
= new0(CGroupIODeviceLimit
, 1);
4196 l
->path
= TAKE_PTR(resolved
);
4197 for (ttype
= 0; ttype
< _CGROUP_IO_LIMIT_TYPE_MAX
; ttype
++)
4198 l
->limits
[ttype
] = cgroup_io_limit_defaults
[ttype
];
4200 LIST_PREPEND(device_limits
, c
->io_device_limits
, l
);
4203 l
->limits
[type
] = num
;
4208 int config_parse_blockio_device_weight(
4210 const char *filename
,
4212 const char *section
,
4213 unsigned section_line
,
4220 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4221 CGroupBlockIODeviceWeight
*w
;
4222 CGroupContext
*c
= data
;
4223 const char *p
= rvalue
;
4231 if (isempty(rvalue
)) {
4232 while (c
->blockio_device_weights
)
4233 cgroup_context_free_blockio_device_weight(c
, c
->blockio_device_weights
);
4238 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4241 if (r
<= 0 || isempty(p
)) {
4242 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4243 "Failed to extract device node and weight from '%s', ignoring.", rvalue
);
4247 r
= unit_path_printf(userdata
, path
, &resolved
);
4249 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4250 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4254 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4258 r
= cg_blkio_weight_parse(p
, &u
);
4260 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid block IO weight '%s', ignoring: %m", p
);
4264 assert(u
!= CGROUP_BLKIO_WEIGHT_INVALID
);
4266 w
= new0(CGroupBlockIODeviceWeight
, 1);
4270 w
->path
= TAKE_PTR(resolved
);
4273 LIST_PREPEND(device_weights
, c
->blockio_device_weights
, w
);
4277 int config_parse_blockio_bandwidth(
4279 const char *filename
,
4281 const char *section
,
4282 unsigned section_line
,
4289 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4290 CGroupBlockIODeviceBandwidth
*b
= NULL
, *t
;
4291 CGroupContext
*c
= data
;
4292 const char *p
= rvalue
;
4301 read
= streq("BlockIOReadBandwidth", lvalue
);
4303 if (isempty(rvalue
)) {
4304 LIST_FOREACH(device_bandwidths
, b
, c
->blockio_device_bandwidths
) {
4305 b
->rbps
= CGROUP_LIMIT_MAX
;
4306 b
->wbps
= CGROUP_LIMIT_MAX
;
4311 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4314 if (r
<= 0 || isempty(p
)) {
4315 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4316 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
4320 r
= unit_path_printf(userdata
, path
, &resolved
);
4322 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4323 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4327 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4331 r
= parse_size(p
, 1000, &bytes
);
4332 if (r
< 0 || bytes
<= 0) {
4333 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid Block IO Bandwidth '%s', ignoring.", p
);
4337 LIST_FOREACH(device_bandwidths
, t
, c
->blockio_device_bandwidths
) {
4338 if (path_equal(resolved
, t
->path
)) {
4345 b
= new0(CGroupBlockIODeviceBandwidth
, 1);
4349 b
->path
= TAKE_PTR(resolved
);
4350 b
->rbps
= CGROUP_LIMIT_MAX
;
4351 b
->wbps
= CGROUP_LIMIT_MAX
;
4353 LIST_PREPEND(device_bandwidths
, c
->blockio_device_bandwidths
, b
);
4364 int config_parse_job_mode_isolate(
4366 const char *filename
,
4368 const char *section
,
4369 unsigned section_line
,
4383 r
= parse_boolean(rvalue
);
4385 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse boolean, ignoring: %s", rvalue
);
4389 log_notice("%s is deprecated. Please use OnFailureJobMode= instead", lvalue
);
4391 *m
= r
? JOB_ISOLATE
: JOB_REPLACE
;
4395 int config_parse_exec_directories(
4397 const char *filename
,
4399 const char *section
,
4400 unsigned section_line
,
4408 const Unit
*u
= userdata
;
4416 if (isempty(rvalue
)) {
4417 /* Empty assignment resets the list */
4418 *rt
= strv_free(*rt
);
4422 for (const char *p
= rvalue
;;) {
4423 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
4425 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
4429 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4430 "Invalid syntax, ignoring: %s", rvalue
);
4436 r
= unit_path_printf(u
, word
, &k
);
4438 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4439 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
4443 r
= path_simplify_and_warn(k
, PATH_CHECK_RELATIVE
, unit
, filename
, line
, lvalue
);
4447 if (path_startswith(k
, "private")) {
4448 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4449 "%s= path can't be 'private', ignoring assignment: %s", lvalue
, word
);
4453 r
= strv_push(rt
, k
);
4460 int config_parse_set_credential(
4462 const char *filename
,
4464 const char *section
,
4465 unsigned section_line
,
4472 _cleanup_free_
char *word
= NULL
, *k
= NULL
, *unescaped
= NULL
;
4473 ExecContext
*context
= data
;
4474 ExecSetCredential
*old
;
4484 if (isempty(rvalue
)) {
4485 /* Empty assignment resets the list */
4486 context
->set_credentials
= hashmap_free(context
->set_credentials
);
4491 r
= extract_first_word(&p
, &word
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4495 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
4499 r
= unit_cred_printf(u
, word
, &k
);
4501 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
4504 if (!credential_name_valid(k
)) {
4505 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Credential name \"%s\" not valid, ignoring.", k
);
4509 /* We support escape codes here, so that users can insert trailing \n if they like */
4510 l
= cunescape(p
, UNESCAPE_ACCEPT_NUL
, &unescaped
);
4512 log_syntax(unit
, LOG_WARNING
, filename
, line
, l
, "Can't unescape \"%s\", ignoring: %m", p
);
4516 old
= hashmap_get(context
->set_credentials
, k
);
4518 free_and_replace(old
->data
, unescaped
);
4521 _cleanup_(exec_set_credential_freep
) ExecSetCredential
*sc
= NULL
;
4523 sc
= new0(ExecSetCredential
, 1);
4527 sc
->id
= TAKE_PTR(k
);
4528 sc
->data
= TAKE_PTR(unescaped
);
4531 r
= hashmap_ensure_put(&context
->set_credentials
, &exec_set_credential_hash_ops
, sc
->id
, sc
);
4535 log_syntax(unit
, LOG_WARNING
, filename
, line
, l
,
4536 "Duplicated credential value '%s', ignoring assignment: %s", sc
->id
, rvalue
);
4546 int config_parse_load_credential(
4548 const char *filename
,
4550 const char *section
,
4551 unsigned section_line
,
4558 _cleanup_free_
char *word
= NULL
, *k
= NULL
, *q
= NULL
;
4559 ExecContext
*context
= data
;
4569 if (isempty(rvalue
)) {
4570 /* Empty assignment resets the list */
4571 context
->load_credentials
= strv_free(context
->load_credentials
);
4576 r
= extract_first_word(&p
, &word
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4580 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
4584 r
= unit_cred_printf(u
, word
, &k
);
4586 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
4589 if (!credential_name_valid(k
)) {
4590 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Credential name \"%s\" not valid, ignoring.", k
);
4595 /* If only one field field is specified take it as shortcut for inheriting a credential named
4596 * the same way from our parent */
4601 r
= unit_path_printf(u
, p
, &q
);
4603 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", p
);
4606 if (path_is_absolute(q
) ? !path_is_normalized(q
) : !credential_name_valid(q
)) {
4607 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Credential source \"%s\" not valid, ignoring.", q
);
4612 r
= strv_consume_pair(&context
->load_credentials
, TAKE_PTR(k
), TAKE_PTR(q
));
4619 int config_parse_set_status(
4621 const char *filename
,
4623 const char *section
,
4624 unsigned section_line
,
4631 ExitStatusSet
*status_set
= data
;
4639 /* Empty assignment resets the list */
4640 if (isempty(rvalue
)) {
4641 exit_status_set_free(status_set
);
4645 for (const char *p
= rvalue
;;) {
4646 _cleanup_free_
char *word
= NULL
;
4649 r
= extract_first_word(&p
, &word
, NULL
, 0);
4653 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4654 "Failed to parse %s=%s, ignoring: %m", lvalue
, rvalue
);
4660 /* We need to call exit_status_from_string() first, because we want
4661 * to parse numbers as exit statuses, not signals. */
4663 r
= exit_status_from_string(word
);
4665 assert(r
>= 0 && r
< 256);
4666 bitmap
= &status_set
->status
;
4668 r
= signal_from_string(word
);
4670 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4671 "Failed to parse value, ignoring: %s", word
);
4674 bitmap
= &status_set
->signal
;
4677 r
= bitmap_set(bitmap
, r
);
4679 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4680 "Failed to set signal or status %s, ignoring: %m", word
);
4684 int config_parse_namespace_path_strv(
4686 const char *filename
,
4688 const char *section
,
4689 unsigned section_line
,
4696 const Unit
*u
= userdata
;
4705 if (isempty(rvalue
)) {
4706 /* Empty assignment resets the list */
4707 *sv
= strv_free(*sv
);
4711 for (const char *p
= rvalue
;;) {
4712 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
, *joined
= NULL
;
4714 bool ignore_enoent
= false, shall_prefix
= false;
4716 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
4720 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
4727 if (startswith(w
, "-")) {
4728 ignore_enoent
= true;
4731 if (startswith(w
, "+")) {
4732 shall_prefix
= true;
4736 r
= unit_path_printf(u
, w
, &resolved
);
4738 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", w
);
4742 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4746 joined
= strjoin(ignore_enoent
? "-" : "",
4747 shall_prefix
? "+" : "",
4750 r
= strv_push(sv
, joined
);
4760 int config_parse_temporary_filesystems(
4762 const char *filename
,
4764 const char *section
,
4765 unsigned section_line
,
4772 const Unit
*u
= userdata
;
4773 ExecContext
*c
= data
;
4781 if (isempty(rvalue
)) {
4782 /* Empty assignment resets the list */
4783 temporary_filesystem_free_many(c
->temporary_filesystems
, c
->n_temporary_filesystems
);
4784 c
->temporary_filesystems
= NULL
;
4785 c
->n_temporary_filesystems
= 0;
4789 for (const char *p
= rvalue
;;) {
4790 _cleanup_free_
char *word
= NULL
, *path
= NULL
, *resolved
= NULL
;
4793 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
4797 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
4804 r
= extract_first_word(&w
, &path
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4808 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", word
);
4812 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid syntax, ignoring: %s", word
);
4816 r
= unit_path_printf(u
, path
, &resolved
);
4818 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", path
);
4822 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4826 r
= temporary_filesystem_add(&c
->temporary_filesystems
, &c
->n_temporary_filesystems
, resolved
, w
);
4832 int config_parse_bind_paths(
4834 const char *filename
,
4836 const char *section
,
4837 unsigned section_line
,
4844 ExecContext
*c
= data
;
4845 const Unit
*u
= userdata
;
4853 if (isempty(rvalue
)) {
4854 /* Empty assignment resets the list */
4855 bind_mount_free_many(c
->bind_mounts
, c
->n_bind_mounts
);
4856 c
->bind_mounts
= NULL
;
4857 c
->n_bind_mounts
= 0;
4861 for (const char *p
= rvalue
;;) {
4862 _cleanup_free_
char *source
= NULL
, *destination
= NULL
;
4863 _cleanup_free_
char *sresolved
= NULL
, *dresolved
= NULL
;
4864 char *s
= NULL
, *d
= NULL
;
4865 bool rbind
= true, ignore_enoent
= false;
4867 r
= extract_first_word(&p
, &source
, ":" WHITESPACE
, EXTRACT_UNQUOTE
|EXTRACT_DONT_COALESCE_SEPARATORS
);
4871 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
4877 r
= unit_full_printf_full(u
, source
, PATH_MAX
, &sresolved
);
4879 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4880 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", source
);
4886 ignore_enoent
= true;
4890 r
= path_simplify_and_warn(s
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4894 /* Optionally, the destination is specified. */
4895 if (p
&& p
[-1] == ':') {
4896 r
= extract_first_word(&p
, &destination
, ":" WHITESPACE
, EXTRACT_UNQUOTE
|EXTRACT_DONT_COALESCE_SEPARATORS
);
4900 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
4904 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Missing argument after ':', ignoring: %s", s
);
4908 r
= unit_path_printf(u
, destination
, &dresolved
);
4910 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4911 "Failed to resolve specifiers in \"%s\", ignoring: %m", destination
);
4915 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4921 /* Optionally, there's also a short option string specified */
4922 if (p
&& p
[-1] == ':') {
4923 _cleanup_free_
char *options
= NULL
;
4925 r
= extract_first_word(&p
, &options
, NULL
, EXTRACT_UNQUOTE
);
4929 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s: %s", lvalue
, rvalue
);
4933 if (isempty(options
) || streq(options
, "rbind"))
4935 else if (streq(options
, "norbind"))
4938 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid option string, ignoring setting: %s", options
);
4945 r
= bind_mount_add(&c
->bind_mounts
, &c
->n_bind_mounts
,
4949 .read_only
= !!strstr(lvalue
, "ReadOnly"),
4951 .ignore_enoent
= ignore_enoent
,
4960 int config_parse_mount_images(
4962 const char *filename
,
4964 const char *section
,
4965 unsigned section_line
,
4972 ExecContext
*c
= data
;
4973 const Unit
*u
= userdata
;
4981 if (isempty(rvalue
)) {
4982 /* Empty assignment resets the list */
4983 c
->mount_images
= mount_image_free_many(c
->mount_images
, &c
->n_mount_images
);
4987 for (const char *p
= rvalue
;;) {
4988 _cleanup_(mount_options_free_allp
) MountOptions
*options
= NULL
;
4989 _cleanup_free_
char *first
= NULL
, *second
= NULL
, *tuple
= NULL
;
4990 _cleanup_free_
char *sresolved
= NULL
, *dresolved
= NULL
;
4991 const char *q
= NULL
;
4993 bool permissive
= false;
4995 r
= extract_first_word(&p
, &tuple
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_RETAIN_ESCAPE
);
4999 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5000 "Invalid syntax %s=%s, ignoring: %m", lvalue
, rvalue
);
5007 r
= extract_many_words(&q
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
, &first
, &second
, NULL
);
5011 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5012 "Invalid syntax in %s=, ignoring: %s", lvalue
, tuple
);
5024 r
= unit_path_printf(u
, s
, &sresolved
);
5026 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5027 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", s
);
5031 r
= path_simplify_and_warn(sresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5035 if (isempty(second
)) {
5036 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Missing destination in %s, ignoring: %s", lvalue
, rvalue
);
5040 r
= unit_path_printf(u
, second
, &dresolved
);
5042 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5043 "Failed to resolve specifiers in \"%s\", ignoring: %m", second
);
5047 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5052 _cleanup_free_
char *partition
= NULL
, *mount_options
= NULL
, *mount_options_resolved
= NULL
;
5053 MountOptions
*o
= NULL
;
5054 PartitionDesignator partition_designator
;
5056 r
= extract_many_words(&q
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
, &partition
, &mount_options
, NULL
);
5060 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", q
);
5065 /* Single set of options, applying to the root partition/single filesystem */
5067 r
= unit_full_printf(u
, partition
, &mount_options_resolved
);
5069 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", first
);
5073 o
= new(MountOptions
, 1);
5076 *o
= (MountOptions
) {
5077 .partition_designator
= PARTITION_ROOT
,
5078 .options
= TAKE_PTR(mount_options_resolved
),
5080 LIST_APPEND(mount_options
, options
, o
);
5085 partition_designator
= partition_designator_from_string(partition
);
5086 if (partition_designator
< 0) {
5087 log_syntax(unit
, LOG_WARNING
, filename
, line
, partition_designator
,
5088 "Invalid partition name %s, ignoring", partition
);
5091 r
= unit_full_printf(u
, mount_options
, &mount_options_resolved
);
5093 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", mount_options
);
5097 o
= new(MountOptions
, 1);
5100 *o
= (MountOptions
) {
5101 .partition_designator
= partition_designator
,
5102 .options
= TAKE_PTR(mount_options_resolved
),
5104 LIST_APPEND(mount_options
, options
, o
);
5107 r
= mount_image_add(&c
->mount_images
, &c
->n_mount_images
,
5109 .source
= sresolved
,
5110 .destination
= dresolved
,
5111 .mount_options
= options
,
5112 .ignore_enoent
= permissive
,
5113 .type
= MOUNT_IMAGE_DISCRETE
,
5120 int config_parse_extension_images(
5122 const char *filename
,
5124 const char *section
,
5125 unsigned section_line
,
5132 ExecContext
*c
= data
;
5133 const Unit
*u
= userdata
;
5141 if (isempty(rvalue
)) {
5142 /* Empty assignment resets the list */
5143 c
->extension_images
= mount_image_free_many(c
->extension_images
, &c
->n_extension_images
);
5147 for (const char *p
= rvalue
;;) {
5148 _cleanup_free_
char *source
= NULL
, *tuple
= NULL
, *sresolved
= NULL
;
5149 _cleanup_(mount_options_free_allp
) MountOptions
*options
= NULL
;
5150 bool permissive
= false;
5151 const char *q
= NULL
;
5154 r
= extract_first_word(&p
, &tuple
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_RETAIN_ESCAPE
);
5158 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5159 "Invalid syntax %s=%s, ignoring: %m", lvalue
, rvalue
);
5166 r
= extract_first_word(&q
, &source
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
);
5170 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5171 "Invalid syntax in %s=, ignoring: %s", lvalue
, tuple
);
5183 r
= unit_path_printf(u
, s
, &sresolved
);
5185 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5186 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", s
);
5190 r
= path_simplify_and_warn(sresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5195 _cleanup_free_
char *partition
= NULL
, *mount_options
= NULL
, *mount_options_resolved
= NULL
;
5196 MountOptions
*o
= NULL
;
5197 PartitionDesignator partition_designator
;
5199 r
= extract_many_words(&q
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
, &partition
, &mount_options
, NULL
);
5203 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", q
);
5208 /* Single set of options, applying to the root partition/single filesystem */
5210 r
= unit_full_printf(u
, partition
, &mount_options_resolved
);
5212 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", partition
);
5216 o
= new(MountOptions
, 1);
5219 *o
= (MountOptions
) {
5220 .partition_designator
= PARTITION_ROOT
,
5221 .options
= TAKE_PTR(mount_options_resolved
),
5223 LIST_APPEND(mount_options
, options
, o
);
5228 partition_designator
= partition_designator_from_string(partition
);
5229 if (partition_designator
< 0) {
5230 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid partition name %s, ignoring", partition
);
5233 r
= unit_full_printf(u
, mount_options
, &mount_options_resolved
);
5235 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", mount_options
);
5239 o
= new(MountOptions
, 1);
5242 *o
= (MountOptions
) {
5243 .partition_designator
= partition_designator
,
5244 .options
= TAKE_PTR(mount_options_resolved
),
5246 LIST_APPEND(mount_options
, options
, o
);
5249 r
= mount_image_add(&c
->extension_images
, &c
->n_extension_images
,
5251 .source
= sresolved
,
5252 .mount_options
= options
,
5253 .ignore_enoent
= permissive
,
5254 .type
= MOUNT_IMAGE_EXTENSION
,
5261 int config_parse_job_timeout_sec(
5263 const char *filename
,
5265 const char *section
,
5266 unsigned section_line
,
5282 r
= parse_sec_fix_0(rvalue
, &usec
);
5284 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse JobTimeoutSec= parameter, ignoring: %s", rvalue
);
5288 /* If the user explicitly changed JobTimeoutSec= also change JobRunningTimeoutSec=, for compatibility with old
5289 * versions. If JobRunningTimeoutSec= was explicitly set, avoid this however as whatever the user picked should
5292 if (!u
->job_running_timeout_set
)
5293 u
->job_running_timeout
= usec
;
5295 u
->job_timeout
= usec
;
5300 int config_parse_job_running_timeout_sec(
5302 const char *filename
,
5304 const char *section
,
5305 unsigned section_line
,
5321 r
= parse_sec_fix_0(rvalue
, &usec
);
5323 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse JobRunningTimeoutSec= parameter, ignoring: %s", rvalue
);
5327 u
->job_running_timeout
= usec
;
5328 u
->job_running_timeout_set
= true;
5333 int config_parse_emergency_action(
5335 const char *filename
,
5337 const char *section
,
5338 unsigned section_line
,
5346 EmergencyAction
*x
= data
;
5355 m
= ((Unit
*) userdata
)->manager
;
5359 r
= parse_emergency_action(rvalue
, MANAGER_IS_SYSTEM(m
), x
);
5361 if (r
== -EOPNOTSUPP
&& MANAGER_IS_USER(m
)) {
5362 /* Compat mode: remove for systemd 241. */
5364 log_syntax(unit
, LOG_INFO
, filename
, line
, r
,
5365 "%s= in user mode specified as \"%s\", using \"exit-force\" instead.",
5367 *x
= EMERGENCY_ACTION_EXIT_FORCE
;
5371 if (r
== -EOPNOTSUPP
)
5372 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5373 "%s= specified as %s mode action, ignoring: %s",
5374 lvalue
, MANAGER_IS_SYSTEM(m
) ? "user" : "system", rvalue
);
5376 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5377 "Failed to parse %s=, ignoring: %s", lvalue
, rvalue
);
5384 int config_parse_pid_file(
5386 const char *filename
,
5388 const char *section
,
5389 unsigned section_line
,
5396 _cleanup_free_
char *k
= NULL
, *n
= NULL
;
5397 const Unit
*u
= userdata
;
5406 if (isempty(rvalue
)) {
5407 /* An empty assignment removes already set value. */
5412 r
= unit_path_printf(u
, rvalue
, &k
);
5414 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
5418 /* If this is a relative path make it absolute by prefixing the /run */
5419 n
= path_make_absolute(k
, u
->manager
->prefix
[EXEC_DIRECTORY_RUNTIME
]);
5423 /* Check that the result is a sensible path */
5424 r
= path_simplify_and_warn(n
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5428 r
= patch_var_run(unit
, filename
, line
, lvalue
, &n
);
5432 free_and_replace(*s
, n
);
5436 int config_parse_exit_status(
5438 const char *filename
,
5440 const char *section
,
5441 unsigned section_line
,
5448 int *exit_status
= data
, r
;
5454 assert(exit_status
);
5456 if (isempty(rvalue
)) {
5461 r
= safe_atou8(rvalue
, &u
);
5463 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse exit status '%s', ignoring: %m", rvalue
);
5471 int config_parse_disable_controllers(
5473 const char *filename
,
5475 const char *section
,
5476 unsigned section_line
,
5484 CGroupContext
*c
= data
;
5485 CGroupMask disabled_mask
;
5487 /* 1. If empty, make all controllers eligible for use again.
5488 * 2. If non-empty, merge all listed controllers, space separated. */
5490 if (isempty(rvalue
)) {
5491 c
->disable_controllers
= 0;
5495 r
= cg_mask_from_string(rvalue
, &disabled_mask
);
5496 if (r
< 0 || disabled_mask
<= 0) {
5497 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid cgroup string: %s, ignoring", rvalue
);
5501 c
->disable_controllers
|= disabled_mask
;
5506 int config_parse_ip_filter_bpf_progs(
5508 const char *filename
,
5510 const char *section
,
5511 unsigned section_line
,
5518 _cleanup_free_
char *resolved
= NULL
;
5519 const Unit
*u
= userdata
;
5520 char ***paths
= data
;
5528 if (isempty(rvalue
)) {
5529 *paths
= strv_free(*paths
);
5533 r
= unit_path_printf(u
, rvalue
, &resolved
);
5535 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
5539 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5543 if (strv_contains(*paths
, resolved
))
5546 r
= strv_extend(paths
, resolved
);
5550 r
= bpf_firewall_supported();
5553 if (r
!= BPF_FIREWALL_SUPPORTED_WITH_MULTI
) {
5554 static bool warned
= false;
5556 log_full(warned
? LOG_DEBUG
: LOG_WARNING
,
5557 "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"
5558 "Starting this unit will fail! (This warning is only shown for the first loaded unit using IP firewalling.)", filename
, line
, lvalue
, rvalue
);
5566 int config_parse_bpf_foreign_program(
5568 const char *filename
,
5570 const char *section
,
5571 unsigned section_line
,
5577 _cleanup_free_
char *resolved
= NULL
, *word
= NULL
;
5578 CGroupContext
*c
= data
;
5586 if (isempty(rvalue
)) {
5587 while (c
->bpf_foreign_programs
)
5588 cgroup_context_remove_bpf_foreign_program(c
, c
->bpf_foreign_programs
);
5593 r
= extract_first_word(&rvalue
, &word
, ":", 0);
5596 if (r
<= 0 || isempty(rvalue
)) {
5597 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse foreign BPF program, ignoring: %s", rvalue
);
5601 attach_type
= bpf_cgroup_attach_type_from_string(word
);
5602 if (attach_type
< 0) {
5603 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Unknown BPF attach type=%s, ignoring: %s", word
, rvalue
);
5607 r
= unit_path_printf(u
, rvalue
, &resolved
);
5609 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
5613 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5617 r
= cgroup_add_bpf_foreign_program(c
, attach_type
, resolved
);
5619 return log_error_errno(r
, "Failed to add foreign BPF program to cgroup context: %m");
5624 int config_parse_cgroup_socket_bind(
5626 const char *filename
,
5628 const char *section
,
5629 unsigned section_line
,
5635 _cleanup_free_ CGroupSocketBindItem
*item
= NULL
;
5636 const char *user_port
;
5637 uint16_t nr_ports
= 0, port_min
= 0;
5638 CGroupSocketBindItem
**head
= data
;
5639 _cleanup_free_
char *word
= NULL
;
5642 if (isempty(rvalue
)) {
5643 cgroup_context_remove_socket_bind(head
);
5647 r
= extract_first_word(&rvalue
, &word
, ":", 0);
5651 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5652 "Unable to parse %s= assignment, ignoring: %s", lvalue
, rvalue
);
5657 af
= af_from_ipv4_ipv6(word
);
5658 if (af
== AF_UNSPEC
) {
5659 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
5660 "Only \"ipv4\" and \"ipv6\" protocols are supported, ignoring.");
5670 if (!streq(user_port
, "any")) {
5673 r
= parse_ip_port_range(user_port
, &port_min
, &port_max
);
5677 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5678 "Invalid port or port range, ignoring: %m");
5682 nr_ports
= 1 + port_max
- port_min
;
5685 item
= new(CGroupSocketBindItem
, 1);
5688 *item
= (CGroupSocketBindItem
) {
5689 .address_family
= af
,
5690 .nr_ports
= nr_ports
,
5691 .port_min
= port_min
,
5694 LIST_PREPEND(socket_bind_items
, *head
, TAKE_PTR(item
));
5699 static int merge_by_names(Unit
**u
, Set
*names
, const char *id
) {
5706 /* Let's try to add in all names that are aliases of this unit */
5707 while ((k
= set_steal_first(names
))) {
5708 _cleanup_free_ _unused_
char *free_k
= k
;
5710 /* First try to merge in the other name into our unit */
5711 r
= unit_merge_by_name(*u
, k
);
5715 /* Hmm, we couldn't merge the other unit into ours? Then let's try it the other way
5718 other
= manager_get_unit((*u
)->manager
, k
);
5720 return r
; /* return previous failure */
5722 r
= unit_merge(other
, *u
);
5727 return merge_by_names(u
, names
, NULL
);
5730 if (streq_ptr(id
, k
))
5731 unit_choose_id(*u
, id
);
5737 int unit_load_fragment(Unit
*u
) {
5738 const char *fragment
;
5739 _cleanup_set_free_free_ Set
*names
= NULL
;
5743 assert(u
->load_state
== UNIT_STUB
);
5747 u
->load_state
= UNIT_LOADED
;
5751 /* Possibly rebuild the fragment map to catch new units */
5752 r
= unit_file_build_name_map(&u
->manager
->lookup_paths
,
5753 &u
->manager
->unit_cache_timestamp_hash
,
5754 &u
->manager
->unit_id_map
,
5755 &u
->manager
->unit_name_map
,
5756 &u
->manager
->unit_path_cache
);
5758 return log_error_errno(r
, "Failed to rebuild name map: %m");
5760 r
= unit_file_find_fragment(u
->manager
->unit_id_map
,
5761 u
->manager
->unit_name_map
,
5765 if (r
< 0 && r
!= -ENOENT
)
5769 /* Open the file, check if this is a mask, otherwise read. */
5770 _cleanup_fclose_
FILE *f
= NULL
;
5773 /* Try to open the file name. A symlink is OK, for example for linked files or masks. We
5774 * expect that all symlinks within the lookup paths have been already resolved, but we don't
5775 * verify this here. */
5776 f
= fopen(fragment
, "re");
5778 return log_unit_notice_errno(u
, errno
, "Failed to open %s: %m", fragment
);
5780 if (fstat(fileno(f
), &st
) < 0)
5783 r
= free_and_strdup(&u
->fragment_path
, fragment
);
5787 if (null_or_empty(&st
)) {
5788 /* Unit file is masked */
5790 u
->load_state
= u
->perpetual
? UNIT_LOADED
: UNIT_MASKED
; /* don't allow perpetual units to ever be masked */
5791 u
->fragment_mtime
= 0;
5793 u
->load_state
= UNIT_LOADED
;
5794 u
->fragment_mtime
= timespec_load(&st
.st_mtim
);
5796 /* Now, parse the file contents */
5797 r
= config_parse(u
->id
, fragment
, f
,
5798 UNIT_VTABLE(u
)->sections
,
5799 config_item_perf_lookup
, load_fragment_gperf_lookup
,
5804 log_unit_notice_errno(u
, r
, "Unit configuration has fatal error, unit will not be started.");
5810 /* Call merge_by_names with the name derived from the fragment path as the preferred name.
5812 * We do the merge dance here because for some unit types, the unit might have aliases which are not
5813 * declared in the file system. In particular, this is true (and frequent) for device and swap units.
5815 const char *id
= u
->id
;
5816 _cleanup_free_
char *free_id
= NULL
;
5819 id
= basename(fragment
);
5820 if (unit_name_is_valid(id
, UNIT_NAME_TEMPLATE
)) {
5821 assert(u
->instance
); /* If we're not trying to use a template for non-instanced unit,
5822 * this must be set. */
5824 r
= unit_name_replace_instance(id
, u
->instance
, &free_id
);
5826 return log_debug_errno(r
, "Failed to build id (%s + %s): %m", id
, u
->instance
);
5832 r
= merge_by_names(&merged
, names
, id
);
5837 u
->load_state
= UNIT_MERGED
;
5842 void unit_dump_config_items(FILE *f
) {
5843 static const struct {
5844 const ConfigParserCallback callback
;
5847 { config_parse_warn_compat
, "NOTSUPPORTED" },
5848 { config_parse_int
, "INTEGER" },
5849 { config_parse_unsigned
, "UNSIGNED" },
5850 { config_parse_iec_size
, "SIZE" },
5851 { config_parse_iec_uint64
, "SIZE" },
5852 { config_parse_si_uint64
, "SIZE" },
5853 { config_parse_bool
, "BOOLEAN" },
5854 { config_parse_string
, "STRING" },
5855 { config_parse_path
, "PATH" },
5856 { config_parse_unit_path_printf
, "PATH" },
5857 { config_parse_strv
, "STRING [...]" },
5858 { config_parse_exec_nice
, "NICE" },
5859 { config_parse_exec_oom_score_adjust
, "OOMSCOREADJUST" },
5860 { config_parse_exec_io_class
, "IOCLASS" },
5861 { config_parse_exec_io_priority
, "IOPRIORITY" },
5862 { config_parse_exec_cpu_sched_policy
, "CPUSCHEDPOLICY" },
5863 { config_parse_exec_cpu_sched_prio
, "CPUSCHEDPRIO" },
5864 { config_parse_exec_cpu_affinity
, "CPUAFFINITY" },
5865 { config_parse_mode
, "MODE" },
5866 { config_parse_unit_env_file
, "FILE" },
5867 { config_parse_exec_output
, "OUTPUT" },
5868 { config_parse_exec_input
, "INPUT" },
5869 { config_parse_log_facility
, "FACILITY" },
5870 { config_parse_log_level
, "LEVEL" },
5871 { config_parse_exec_secure_bits
, "SECUREBITS" },
5872 { config_parse_capability_set
, "BOUNDINGSET" },
5873 { config_parse_rlimit
, "LIMIT" },
5874 { config_parse_unit_deps
, "UNIT [...]" },
5875 { config_parse_exec
, "PATH [ARGUMENT [...]]" },
5876 { config_parse_service_type
, "SERVICETYPE" },
5877 { config_parse_service_exit_type
, "SERVICEEXITTYPE" },
5878 { config_parse_service_restart
, "SERVICERESTART" },
5879 { config_parse_service_timeout_failure_mode
, "TIMEOUTMODE" },
5880 { config_parse_kill_mode
, "KILLMODE" },
5881 { config_parse_signal
, "SIGNAL" },
5882 { config_parse_socket_listen
, "SOCKET [...]" },
5883 { config_parse_socket_bind
, "SOCKETBIND" },
5884 { config_parse_socket_bindtodevice
, "NETWORKINTERFACE" },
5885 { config_parse_sec
, "SECONDS" },
5886 { config_parse_nsec
, "NANOSECONDS" },
5887 { config_parse_namespace_path_strv
, "PATH [...]" },
5888 { config_parse_bind_paths
, "PATH[:PATH[:OPTIONS]] [...]" },
5889 { config_parse_unit_requires_mounts_for
, "PATH [...]" },
5890 { config_parse_exec_mount_flags
, "MOUNTFLAG [...]" },
5891 { config_parse_unit_string_printf
, "STRING" },
5892 { config_parse_trigger_unit
, "UNIT" },
5893 { config_parse_timer
, "TIMER" },
5894 { config_parse_path_spec
, "PATH" },
5895 { config_parse_notify_access
, "ACCESS" },
5896 { config_parse_ip_tos
, "TOS" },
5897 { config_parse_unit_condition_path
, "CONDITION" },
5898 { config_parse_unit_condition_string
, "CONDITION" },
5899 { config_parse_unit_slice
, "SLICE" },
5900 { config_parse_documentation
, "URL" },
5901 { config_parse_service_timeout
, "SECONDS" },
5902 { config_parse_emergency_action
, "ACTION" },
5903 { config_parse_set_status
, "STATUS" },
5904 { config_parse_service_sockets
, "SOCKETS" },
5905 { config_parse_environ
, "ENVIRON" },
5907 { config_parse_syscall_filter
, "SYSCALLS" },
5908 { config_parse_syscall_archs
, "ARCHS" },
5909 { config_parse_syscall_errno
, "ERRNO" },
5910 { config_parse_syscall_log
, "SYSCALLS" },
5911 { config_parse_address_families
, "FAMILIES" },
5912 { config_parse_restrict_namespaces
, "NAMESPACES" },
5914 { config_parse_cpu_shares
, "SHARES" },
5915 { config_parse_cg_weight
, "WEIGHT" },
5916 { config_parse_memory_limit
, "LIMIT" },
5917 { config_parse_device_allow
, "DEVICE" },
5918 { config_parse_device_policy
, "POLICY" },
5919 { config_parse_io_limit
, "LIMIT" },
5920 { config_parse_io_device_weight
, "DEVICEWEIGHT" },
5921 { config_parse_io_device_latency
, "DEVICELATENCY" },
5922 { config_parse_blockio_bandwidth
, "BANDWIDTH" },
5923 { config_parse_blockio_weight
, "WEIGHT" },
5924 { config_parse_blockio_device_weight
, "DEVICEWEIGHT" },
5925 { config_parse_long
, "LONG" },
5926 { config_parse_socket_service
, "SERVICE" },
5928 { config_parse_exec_selinux_context
, "LABEL" },
5930 { config_parse_job_mode
, "MODE" },
5931 { config_parse_job_mode_isolate
, "BOOLEAN" },
5932 { config_parse_personality
, "PERSONALITY" },
5935 const char *prev
= NULL
;
5940 NULSTR_FOREACH(i
, load_fragment_gperf_nulstr
) {
5941 const char *rvalue
= "OTHER", *lvalue
;
5942 const ConfigPerfItem
*p
;
5945 assert_se(p
= load_fragment_gperf_lookup(i
, strlen(i
)));
5947 /* Hide legacy settings */
5948 if (p
->parse
== config_parse_warn_compat
&&
5949 p
->ltype
== DISABLED_LEGACY
)
5952 for (size_t j
= 0; j
< ELEMENTSOF(table
); j
++)
5953 if (p
->parse
== table
[j
].callback
) {
5954 rvalue
= table
[j
].rvalue
;
5958 dot
= strchr(i
, '.');
5959 lvalue
= dot
? dot
+ 1 : i
;
5962 size_t prefix_len
= dot
- i
;
5964 if (!prev
|| !strneq(prev
, i
, prefix_len
+1)) {
5968 fprintf(f
, "[%.*s]\n", (int) prefix_len
, i
);
5972 fprintf(f
, "%s=%s\n", lvalue
, rvalue
);
5977 int config_parse_cpu_affinity2(
5979 const char *filename
,
5981 const char *section
,
5982 unsigned section_line
,
5989 CPUSet
*affinity
= data
;
5993 (void) parse_cpu_set_extend(rvalue
, affinity
, true, unit
, filename
, line
, lvalue
);
5998 int config_parse_show_status(
6000 const char *filename
,
6002 const char *section
,
6003 unsigned section_line
,
6011 ShowStatus
*b
= data
;
6018 k
= parse_show_status(rvalue
, b
);
6020 log_syntax(unit
, LOG_WARNING
, filename
, line
, k
, "Failed to parse show status setting, ignoring: %s", rvalue
);
6025 int config_parse_output_restricted(
6027 const char *filename
,
6029 const char *section
,
6030 unsigned section_line
,
6037 ExecOutput t
, *eo
= data
;
6038 bool obsolete
= false;
6045 if (streq(rvalue
, "syslog")) {
6046 t
= EXEC_OUTPUT_JOURNAL
;
6048 } else if (streq(rvalue
, "syslog+console")) {
6049 t
= EXEC_OUTPUT_JOURNAL_AND_CONSOLE
;
6052 t
= exec_output_from_string(rvalue
);
6054 log_syntax(unit
, LOG_WARNING
, filename
, line
, t
, "Failed to parse output type, ignoring: %s", rvalue
);
6058 if (IN_SET(t
, EXEC_OUTPUT_SOCKET
, EXEC_OUTPUT_NAMED_FD
, EXEC_OUTPUT_FILE
, EXEC_OUTPUT_FILE_APPEND
, EXEC_OUTPUT_FILE_TRUNCATE
)) {
6059 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Standard output types socket, fd:, file:, append:, truncate: are not supported as defaults, ignoring: %s", rvalue
);
6065 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
6066 "Standard output type %s is obsolete, automatically updating to %s. Please update your configuration.",
6067 rvalue
, exec_output_to_string(t
));
6073 int config_parse_crash_chvt(
6075 const char *filename
,
6077 const char *section
,
6078 unsigned section_line
,
6092 r
= parse_crash_chvt(rvalue
, data
);
6094 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse CrashChangeVT= setting, ignoring: %s", rvalue
);
6099 int config_parse_swap_priority(
6101 const char *filename
,
6103 const char *section
,
6104 unsigned section_line
,
6120 if (isempty(rvalue
)) {
6121 s
->parameters_fragment
.priority
= -1;
6122 s
->parameters_fragment
.priority_set
= false;
6126 r
= safe_atoi(rvalue
, &priority
);
6128 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid swap priority '%s', ignoring.", rvalue
);
6132 if (priority
< -1) {
6133 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
);
6137 if (priority
> 32767) {
6138 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Swap priority out of range, ignoring: %s", rvalue
);
6142 s
->parameters_fragment
.priority
= priority
;
6143 s
->parameters_fragment
.priority_set
= true;