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 "stat-util.h"
61 #include "string-util.h"
63 #include "syslog-util.h"
64 #include "time-util.h"
65 #include "unit-name.h"
66 #include "unit-printf.h"
67 #include "user-util.h"
71 static int parse_socket_protocol(const char *s
) {
74 r
= parse_ip_protocol(s
);
77 if (!IN_SET(r
, IPPROTO_UDPLITE
, IPPROTO_SCTP
))
78 return -EPROTONOSUPPORT
;
83 int parse_crash_chvt(const char *value
, int *data
) {
86 if (safe_atoi(value
, data
) >= 0)
89 b
= parse_boolean(value
);
94 *data
= 0; /* switch to where kmsg goes */
96 *data
= -1; /* turn off switching */
101 int parse_confirm_spawn(const char *value
, char **console
) {
105 r
= value
? parse_boolean(value
) : 1;
109 } else if (r
> 0) /* on with default tty */
110 s
= strdup("/dev/console");
111 else if (is_path(value
)) /* on with fully qualified path */
113 else /* on with only a tty file name, not a fully qualified path */
114 s
= path_join("/dev/", value
);
122 DEFINE_CONFIG_PARSE(config_parse_socket_protocol
, parse_socket_protocol
, "Failed to parse socket protocol");
123 DEFINE_CONFIG_PARSE(config_parse_exec_secure_bits
, secure_bits_from_string
, "Failed to parse secure bits");
124 DEFINE_CONFIG_PARSE_ENUM(config_parse_collect_mode
, collect_mode
, CollectMode
, "Failed to parse garbage collection mode");
125 DEFINE_CONFIG_PARSE_ENUM(config_parse_device_policy
, cgroup_device_policy
, CGroupDevicePolicy
, "Failed to parse device policy");
126 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_keyring_mode
, exec_keyring_mode
, ExecKeyringMode
, "Failed to parse keyring mode");
127 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_proc
, protect_proc
, ProtectProc
, "Failed to parse /proc/ protection mode");
128 DEFINE_CONFIG_PARSE_ENUM(config_parse_proc_subset
, proc_subset
, ProcSubset
, "Failed to parse /proc/ subset mode");
129 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_utmp_mode
, exec_utmp_mode
, ExecUtmpMode
, "Failed to parse utmp mode");
130 DEFINE_CONFIG_PARSE_ENUM(config_parse_job_mode
, job_mode
, JobMode
, "Failed to parse job mode");
131 DEFINE_CONFIG_PARSE_ENUM(config_parse_notify_access
, notify_access
, NotifyAccess
, "Failed to parse notify access specifier");
132 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_home
, protect_home
, ProtectHome
, "Failed to parse protect home value");
133 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_system
, protect_system
, ProtectSystem
, "Failed to parse protect system value");
134 DEFINE_CONFIG_PARSE_ENUM(config_parse_runtime_preserve_mode
, exec_preserve_mode
, ExecPreserveMode
, "Failed to parse runtime directory preserve mode");
135 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_type
, service_type
, ServiceType
, "Failed to parse service type");
136 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_exit_type
, service_exit_type
, ServiceExitType
, "Failed to parse service exit type");
137 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart
, service_restart
, ServiceRestart
, "Failed to parse service restart specifier");
138 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_timeout_failure_mode
, service_timeout_failure_mode
, ServiceTimeoutFailureMode
, "Failed to parse timeout failure mode");
139 DEFINE_CONFIG_PARSE_ENUM(config_parse_socket_bind
, socket_address_bind_ipv6_only_or_bool
, SocketAddressBindIPv6Only
, "Failed to parse bind IPv6 only value");
140 DEFINE_CONFIG_PARSE_ENUM(config_parse_oom_policy
, oom_policy
, OOMPolicy
, "Failed to parse OOM policy");
141 DEFINE_CONFIG_PARSE_ENUM(config_parse_managed_oom_preference
, managed_oom_preference
, ManagedOOMPreference
, "Failed to parse ManagedOOMPreference=");
142 DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_ip_tos
, ip_tos
, int, -1, "Failed to parse IP TOS value");
143 DEFINE_CONFIG_PARSE_PTR(config_parse_blockio_weight
, cg_blkio_weight_parse
, uint64_t, "Invalid block IO weight");
144 DEFINE_CONFIG_PARSE_PTR(config_parse_cg_weight
, cg_weight_parse
, uint64_t, "Invalid weight");
145 DEFINE_CONFIG_PARSE_PTR(config_parse_cpu_shares
, cg_cpu_shares_parse
, uint64_t, "Invalid CPU shares");
146 DEFINE_CONFIG_PARSE_PTR(config_parse_exec_mount_flags
, mount_propagation_flags_from_string
, unsigned long, "Failed to parse mount flag");
147 DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_numa_policy
, mpol
, int, -1, "Invalid NUMA policy type");
148 DEFINE_CONFIG_PARSE_ENUM(config_parse_status_unit_format
, status_unit_format
, StatusUnitFormat
, "Failed to parse status unit format");
149 DEFINE_CONFIG_PARSE_ENUM_FULL(config_parse_socket_timestamping
, socket_timestamping_from_string_harder
, SocketTimestamping
, "Failed to parse timestamping precision");
151 int config_parse_unit_deps(
153 const char *filename
,
156 unsigned section_line
,
163 UnitDependency d
= ltype
;
170 for (const char *p
= rvalue
;;) {
171 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
174 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_RETAIN_ESCAPE
);
180 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
184 r
= unit_name_printf(u
, word
, &k
);
186 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
190 r
= unit_add_dependency_by_name(u
, d
, k
, true, UNIT_DEPENDENCY_FILE
);
192 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
196 int config_parse_obsolete_unit_deps(
198 const char *filename
,
201 unsigned section_line
,
208 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
209 "Unit dependency type %s= is obsolete, replacing by %s=, please update your unit file", lvalue
, unit_dependency_to_string(ltype
));
211 return config_parse_unit_deps(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
);
214 int config_parse_unit_string_printf(
216 const char *filename
,
219 unsigned section_line
,
226 _cleanup_free_
char *k
= NULL
;
227 const Unit
*u
= userdata
;
235 r
= unit_full_printf(u
, rvalue
, &k
);
237 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
241 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
244 int config_parse_unit_strv_printf(
246 const char *filename
,
249 unsigned section_line
,
256 const Unit
*u
= userdata
;
257 _cleanup_free_
char *k
= NULL
;
265 r
= unit_full_printf(u
, rvalue
, &k
);
267 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
271 return config_parse_strv(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
274 int config_parse_unit_path_printf(
276 const char *filename
,
279 unsigned section_line
,
286 _cleanup_free_
char *k
= NULL
;
287 const Unit
*u
= userdata
;
296 /* Let's not bother with anything that is too long */
297 if (strlen(rvalue
) >= PATH_MAX
) {
298 log_syntax(unit
, fatal
? LOG_ERR
: LOG_WARNING
, filename
, line
, 0,
299 "%s value too long%s.",
300 lvalue
, fatal
? "" : ", ignoring");
301 return fatal
? -ENAMETOOLONG
: 0;
304 r
= unit_full_printf(u
, rvalue
, &k
);
306 log_syntax(unit
, fatal
? LOG_ERR
: LOG_WARNING
, filename
, line
, r
,
307 "Failed to resolve unit specifiers in '%s'%s: %m",
308 rvalue
, fatal
? "" : ", ignoring");
309 return fatal
? -ENOEXEC
: 0;
312 return config_parse_path(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
315 int config_parse_unit_path_strv_printf(
317 const char *filename
,
320 unsigned section_line
,
328 const Unit
*u
= userdata
;
336 if (isempty(rvalue
)) {
341 for (const char *p
= rvalue
;;) {
342 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
344 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
350 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
351 "Invalid syntax, ignoring: %s", rvalue
);
355 r
= unit_full_printf(u
, word
, &k
);
357 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
358 "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
362 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
366 r
= strv_consume(x
, TAKE_PTR(k
));
372 static int patch_var_run(
374 const char *filename
,
382 e
= path_startswith(*path
, "/var/run/");
386 z
= path_join("/run/", e
);
390 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
391 "%s= references a path below legacy directory /var/run/, updating %s → %s; "
392 "please update the unit file accordingly.", lvalue
, *path
, z
);
394 free_and_replace(*path
, z
);
399 int config_parse_socket_listen(
401 const char *filename
,
404 unsigned section_line
,
411 _cleanup_free_ SocketPort
*p
= NULL
;
423 if (isempty(rvalue
)) {
424 /* An empty assignment removes all ports */
425 socket_free_ports(s
);
429 p
= new0(SocketPort
, 1);
433 if (ltype
!= SOCKET_SOCKET
) {
434 _cleanup_free_
char *k
= NULL
;
436 r
= unit_full_printf(UNIT(s
), rvalue
, &k
);
438 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
442 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
446 if (ltype
== SOCKET_FIFO
) {
447 r
= patch_var_run(unit
, filename
, line
, lvalue
, &k
);
452 free_and_replace(p
->path
, k
);
455 } else if (streq(lvalue
, "ListenNetlink")) {
456 _cleanup_free_
char *k
= NULL
;
458 r
= unit_full_printf(UNIT(s
), rvalue
, &k
);
460 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
464 r
= socket_address_parse_netlink(&p
->address
, k
);
466 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse address value in '%s', ignoring: %m", k
);
470 p
->type
= SOCKET_SOCKET
;
473 _cleanup_free_
char *k
= NULL
;
475 r
= unit_full_printf(UNIT(s
), rvalue
, &k
);
477 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
481 if (k
[0] == '/') { /* Only for AF_UNIX file system sockets… */
482 r
= patch_var_run(unit
, filename
, line
, lvalue
, &k
);
487 r
= socket_address_parse_and_warn(&p
->address
, k
);
489 if (r
!= -EAFNOSUPPORT
)
490 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse address value in '%s', ignoring: %m", k
);
494 if (streq(lvalue
, "ListenStream"))
495 p
->address
.type
= SOCK_STREAM
;
496 else if (streq(lvalue
, "ListenDatagram"))
497 p
->address
.type
= SOCK_DGRAM
;
499 assert(streq(lvalue
, "ListenSequentialPacket"));
500 p
->address
.type
= SOCK_SEQPACKET
;
503 if (socket_address_family(&p
->address
) != AF_LOCAL
&& p
->address
.type
== SOCK_SEQPACKET
) {
504 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Address family not supported, ignoring: %s", rvalue
);
508 p
->type
= SOCKET_SOCKET
;
512 p
->auxiliary_fds
= NULL
;
513 p
->n_auxiliary_fds
= 0;
516 LIST_FIND_TAIL(port
, s
->ports
, tail
);
517 LIST_INSERT_AFTER(port
, s
->ports
, tail
, p
);
524 int config_parse_exec_nice(
526 const char *filename
,
529 unsigned section_line
,
536 ExecContext
*c
= data
;
544 if (isempty(rvalue
)) {
549 r
= parse_nice(rvalue
, &priority
);
552 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Nice priority out of range, ignoring: %s", rvalue
);
554 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse nice priority '%s', ignoring: %m", rvalue
);
564 int config_parse_exec_oom_score_adjust(
566 const char *filename
,
569 unsigned section_line
,
576 ExecContext
*c
= data
;
584 if (isempty(rvalue
)) {
585 c
->oom_score_adjust_set
= false;
589 r
= parse_oom_score_adjust(rvalue
, &oa
);
592 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "OOM score adjust value out of range, ignoring: %s", rvalue
);
594 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse the OOM score adjust value '%s', ignoring: %m", rvalue
);
598 c
->oom_score_adjust
= oa
;
599 c
->oom_score_adjust_set
= true;
604 int config_parse_exec_coredump_filter(
606 const char *filename
,
609 unsigned section_line
,
616 ExecContext
*c
= data
;
624 if (isempty(rvalue
)) {
625 c
->coredump_filter
= 0;
626 c
->coredump_filter_set
= false;
631 r
= coredump_filter_mask_from_string(rvalue
, &f
);
633 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
634 "Failed to parse the CoredumpFilter=%s, ignoring: %m", rvalue
);
638 c
->coredump_filter
|= f
;
639 c
->oom_score_adjust_set
= true;
643 int config_parse_kill_mode(
645 const char *filename
,
648 unsigned section_line
,
655 KillMode
*k
= data
, m
;
662 if (isempty(rvalue
)) {
663 *k
= KILL_CONTROL_GROUP
;
667 m
= kill_mode_from_string(rvalue
);
669 log_syntax(unit
, LOG_WARNING
, filename
, line
, m
,
670 "Failed to parse kill mode specification, ignoring: %s", rvalue
);
675 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
676 "Unit configured to use KillMode=none. "
677 "This is unsafe, as it disables systemd's process lifecycle management for the service. "
678 "Please update your service to use a safer KillMode=, such as 'mixed' or 'control-group'. "
679 "Support for KillMode=none is deprecated and will eventually be removed.");
685 int config_parse_exec(
687 const char *filename
,
690 unsigned section_line
,
697 ExecCommand
**e
= data
;
698 const Unit
*u
= userdata
;
710 if (isempty(rvalue
)) {
711 /* An empty assignment resets the list */
712 *e
= exec_command_free_list(*e
);
718 _cleanup_free_
char *path
= NULL
, *firstword
= NULL
;
719 ExecCommandFlags flags
= 0;
720 bool ignore
= false, separate_argv0
= false;
721 _cleanup_free_ ExecCommand
*nce
= NULL
;
722 _cleanup_strv_free_
char **n
= NULL
;
723 size_t nlen
= 0, nbufsize
= 0;
728 r
= extract_first_word_and_warn(&p
, &firstword
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
732 /* A lone ";" is a separator. Let's make sure we don't treat it as an executable name. */
733 if (streq(firstword
, ";")) {
740 /* We accept an absolute path as first argument. If it's prefixed with - and the path doesn't
741 * exist, we ignore it instead of erroring out; if it's prefixed with @, we allow overriding of
742 * argv[0]; if it's prefixed with :, we will not do environment variable substitution;
743 * if it's prefixed with +, it will be run with full privileges and no sandboxing; if
744 * it's prefixed with '!' we apply sandboxing, but do not change user/group credentials; if
745 * it's prefixed with '!!', then we apply user/group credentials if the kernel supports ambient
746 * capabilities -- if it doesn't we don't apply the credentials themselves, but do apply most
747 * other sandboxing, with some special exceptions for changing UID.
749 * The idea is that '!!' may be used to write services that can take benefit of systemd's
750 * UID/GID dropping if the kernel supports ambient creds, but provide an automatic fallback to
751 * privilege dropping within the daemon if the kernel does not offer that. */
753 if (*f
== '-' && !(flags
& EXEC_COMMAND_IGNORE_FAILURE
)) {
754 flags
|= EXEC_COMMAND_IGNORE_FAILURE
;
756 } else if (*f
== '@' && !separate_argv0
)
757 separate_argv0
= true;
758 else if (*f
== ':' && !(flags
& EXEC_COMMAND_NO_ENV_EXPAND
))
759 flags
|= EXEC_COMMAND_NO_ENV_EXPAND
;
760 else if (*f
== '+' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
761 flags
|= EXEC_COMMAND_FULLY_PRIVILEGED
;
762 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
763 flags
|= EXEC_COMMAND_NO_SETUID
;
764 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_AMBIENT_MAGIC
))) {
765 flags
&= ~EXEC_COMMAND_NO_SETUID
;
766 flags
|= EXEC_COMMAND_AMBIENT_MAGIC
;
772 r
= unit_full_printf(u
, f
, &path
);
774 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
775 "Failed to resolve unit specifiers in '%s'%s: %m",
776 f
, ignore
? ", ignoring" : "");
777 return ignore
? 0 : -ENOEXEC
;
781 /* First word is either "-" or "@" with no command. */
782 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
783 "Empty path in command line%s: '%s'",
784 ignore
? ", ignoring" : "", rvalue
);
785 return ignore
? 0 : -ENOEXEC
;
787 if (!string_is_safe(path
)) {
788 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
789 "Executable name contains special characters%s: %s",
790 ignore
? ", ignoring" : "", path
);
791 return ignore
? 0 : -ENOEXEC
;
793 if (endswith(path
, "/")) {
794 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
795 "Executable path specifies a directory%s: %s",
796 ignore
? ", ignoring" : "", path
);
797 return ignore
? 0 : -ENOEXEC
;
800 if (!path_is_absolute(path
) && !filename_is_valid(path
)) {
801 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
802 "Neither a valid executable name nor an absolute path%s: %s",
803 ignore
? ", ignoring" : "", path
);
804 return ignore
? 0 : -ENOEXEC
;
807 if (!separate_argv0
) {
810 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
820 path_simplify(path
, false);
822 while (!isempty(p
)) {
823 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
825 /* Check explicitly for an unquoted semicolon as
826 * command separator token. */
827 if (p
[0] == ';' && (!p
[1] || strchr(WHITESPACE
, p
[1]))) {
829 p
+= strspn(p
, WHITESPACE
);
834 /* Check for \; explicitly, to not confuse it with \\; or "\;" or "\\;" etc.
835 * extract_first_word() would return the same for all of those. */
836 if (p
[0] == '\\' && p
[1] == ';' && (!p
[2] || strchr(WHITESPACE
, p
[2]))) {
840 p
+= strspn(p
, WHITESPACE
);
842 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
853 r
= extract_first_word_and_warn(&p
, &word
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
857 return ignore
? 0 : -ENOEXEC
;
859 r
= unit_full_printf(u
, word
, &resolved
);
861 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
862 "Failed to resolve unit specifiers in %s%s: %m",
863 word
, ignore
? ", ignoring" : "");
864 return ignore
? 0 : -ENOEXEC
;
867 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
870 n
[nlen
++] = TAKE_PTR(resolved
);
875 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
876 "Empty executable name or zeroeth argument%s: %s",
877 ignore
? ", ignoring" : "", rvalue
);
878 return ignore
? 0 : -ENOEXEC
;
881 nce
= new0(ExecCommand
, 1);
885 nce
->argv
= TAKE_PTR(n
);
886 nce
->path
= TAKE_PTR(path
);
889 exec_command_append_list(e
, nce
);
891 /* Do not _cleanup_free_ these. */
900 int config_parse_socket_bindtodevice(
902 const char *filename
,
905 unsigned section_line
,
919 if (isempty(rvalue
) || streq(rvalue
, "*")) {
920 s
->bind_to_device
= mfree(s
->bind_to_device
);
924 if (!ifname_valid(rvalue
)) {
925 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid interface name, ignoring: %s", rvalue
);
929 return free_and_strdup_warn(&s
->bind_to_device
, rvalue
);
932 int config_parse_exec_input(
934 const char *filename
,
937 unsigned section_line
,
944 ExecContext
*c
= data
;
945 const Unit
*u
= userdata
;
955 n
= startswith(rvalue
, "fd:");
957 _cleanup_free_
char *resolved
= NULL
;
959 r
= unit_full_printf(u
, n
, &resolved
);
961 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", n
);
965 if (isempty(resolved
))
966 resolved
= mfree(resolved
);
967 else if (!fdname_is_valid(resolved
)) {
968 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", resolved
);
972 free_and_replace(c
->stdio_fdname
[STDIN_FILENO
], resolved
);
974 ei
= EXEC_INPUT_NAMED_FD
;
976 } else if ((n
= startswith(rvalue
, "file:"))) {
977 _cleanup_free_
char *resolved
= NULL
;
979 r
= unit_full_printf(u
, n
, &resolved
);
981 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", n
);
985 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
989 free_and_replace(c
->stdio_file
[STDIN_FILENO
], resolved
);
991 ei
= EXEC_INPUT_FILE
;
994 ei
= exec_input_from_string(rvalue
);
996 log_syntax(unit
, LOG_WARNING
, filename
, line
, ei
, "Failed to parse input specifier, ignoring: %s", rvalue
);
1005 int config_parse_exec_input_text(
1007 const char *filename
,
1009 const char *section
,
1010 unsigned section_line
,
1017 _cleanup_free_
char *unescaped
= NULL
, *resolved
= NULL
;
1018 ExecContext
*c
= data
;
1019 const Unit
*u
= userdata
;
1029 if (isempty(rvalue
)) {
1030 /* Reset if the empty string is assigned */
1031 c
->stdin_data
= mfree(c
->stdin_data
);
1032 c
->stdin_data_size
= 0;
1036 r
= cunescape(rvalue
, 0, &unescaped
);
1038 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1039 "Failed to decode C escaped text '%s', ignoring: %m", rvalue
);
1043 r
= unit_full_printf(u
, unescaped
, &resolved
);
1045 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1046 "Failed to resolve unit specifiers in '%s', ignoring: %m", unescaped
);
1050 sz
= strlen(resolved
);
1051 if (c
->stdin_data_size
+ sz
+ 1 < c
->stdin_data_size
|| /* check for overflow */
1052 c
->stdin_data_size
+ sz
+ 1 > EXEC_STDIN_DATA_MAX
) {
1053 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
1054 "Standard input data too large (%zu), maximum of %zu permitted, ignoring.",
1055 c
->stdin_data_size
+ sz
, (size_t) EXEC_STDIN_DATA_MAX
);
1059 p
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
+ 1);
1063 *((char*) mempcpy((char*) p
+ c
->stdin_data_size
, resolved
, sz
)) = '\n';
1066 c
->stdin_data_size
+= sz
+ 1;
1071 int config_parse_exec_input_data(
1073 const char *filename
,
1075 const char *section
,
1076 unsigned section_line
,
1083 _cleanup_free_
void *p
= NULL
;
1084 ExecContext
*c
= data
;
1094 if (isempty(rvalue
)) {
1095 /* Reset if the empty string is assigned */
1096 c
->stdin_data
= mfree(c
->stdin_data
);
1097 c
->stdin_data_size
= 0;
1101 r
= unbase64mem(rvalue
, SIZE_MAX
, &p
, &sz
);
1103 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1104 "Failed to decode base64 data, ignoring: %s", rvalue
);
1110 if (c
->stdin_data_size
+ sz
< c
->stdin_data_size
|| /* check for overflow */
1111 c
->stdin_data_size
+ sz
> EXEC_STDIN_DATA_MAX
) {
1112 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
1113 "Standard input data too large (%zu), maximum of %zu permitted, ignoring.",
1114 c
->stdin_data_size
+ sz
, (size_t) EXEC_STDIN_DATA_MAX
);
1118 q
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
);
1122 memcpy((uint8_t*) q
+ c
->stdin_data_size
, p
, sz
);
1125 c
->stdin_data_size
+= sz
;
1130 int config_parse_exec_output(
1132 const char *filename
,
1134 const char *section
,
1135 unsigned section_line
,
1142 _cleanup_free_
char *resolved
= NULL
;
1144 ExecContext
*c
= data
;
1145 const Unit
*u
= userdata
;
1146 bool obsolete
= false;
1156 n
= startswith(rvalue
, "fd:");
1158 r
= unit_full_printf(u
, n
, &resolved
);
1160 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", n
);
1164 if (isempty(resolved
))
1165 resolved
= mfree(resolved
);
1166 else if (!fdname_is_valid(resolved
)) {
1167 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", resolved
);
1171 eo
= EXEC_OUTPUT_NAMED_FD
;
1173 } else if (streq(rvalue
, "syslog")) {
1174 eo
= EXEC_OUTPUT_JOURNAL
;
1177 } else if (streq(rvalue
, "syslog+console")) {
1178 eo
= EXEC_OUTPUT_JOURNAL_AND_CONSOLE
;
1181 } else if ((n
= startswith(rvalue
, "file:"))) {
1183 r
= unit_full_printf(u
, n
, &resolved
);
1185 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", n
);
1189 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1193 eo
= EXEC_OUTPUT_FILE
;
1195 } else if ((n
= startswith(rvalue
, "append:"))) {
1197 r
= unit_full_printf(u
, n
, &resolved
);
1199 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", n
);
1203 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1207 eo
= EXEC_OUTPUT_FILE_APPEND
;
1209 } else if ((n
= startswith(rvalue
, "truncate:"))) {
1211 r
= unit_full_printf(u
, n
, &resolved
);
1213 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", n
);
1217 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1221 eo
= EXEC_OUTPUT_FILE_TRUNCATE
;
1223 eo
= exec_output_from_string(rvalue
);
1225 log_syntax(unit
, LOG_WARNING
, filename
, line
, eo
, "Failed to parse output specifier, ignoring: %s", rvalue
);
1231 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
1232 "Standard output type %s is obsolete, automatically updating to %s. Please update your unit file, and consider removing the setting altogether.",
1233 rvalue
, exec_output_to_string(eo
));
1235 if (streq(lvalue
, "StandardOutput")) {
1236 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1237 free_and_replace(c
->stdio_fdname
[STDOUT_FILENO
], resolved
);
1239 free_and_replace(c
->stdio_file
[STDOUT_FILENO
], resolved
);
1244 assert(streq(lvalue
, "StandardError"));
1246 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1247 free_and_replace(c
->stdio_fdname
[STDERR_FILENO
], resolved
);
1249 free_and_replace(c
->stdio_file
[STDERR_FILENO
], resolved
);
1257 int config_parse_exec_io_class(const char *unit
,
1258 const char *filename
,
1260 const char *section
,
1261 unsigned section_line
,
1268 ExecContext
*c
= data
;
1276 if (isempty(rvalue
)) {
1277 c
->ioprio_set
= false;
1278 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE
, 0);
1282 x
= ioprio_class_from_string(rvalue
);
1284 log_syntax(unit
, LOG_WARNING
, filename
, line
, x
, "Failed to parse IO scheduling class, ignoring: %s", rvalue
);
1288 c
->ioprio
= IOPRIO_PRIO_VALUE(x
, IOPRIO_PRIO_DATA(c
->ioprio
));
1289 c
->ioprio_set
= true;
1294 int config_parse_exec_io_priority(const char *unit
,
1295 const char *filename
,
1297 const char *section
,
1298 unsigned section_line
,
1305 ExecContext
*c
= data
;
1313 if (isempty(rvalue
)) {
1314 c
->ioprio_set
= false;
1315 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE
, 0);
1319 r
= ioprio_parse_priority(rvalue
, &i
);
1321 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse IO priority, ignoring: %s", rvalue
);
1325 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_PRIO_CLASS(c
->ioprio
), i
);
1326 c
->ioprio_set
= true;
1331 int config_parse_exec_cpu_sched_policy(const char *unit
,
1332 const char *filename
,
1334 const char *section
,
1335 unsigned section_line
,
1342 ExecContext
*c
= data
;
1350 if (isempty(rvalue
)) {
1351 c
->cpu_sched_set
= false;
1352 c
->cpu_sched_policy
= SCHED_OTHER
;
1353 c
->cpu_sched_priority
= 0;
1357 x
= sched_policy_from_string(rvalue
);
1359 log_syntax(unit
, LOG_WARNING
, filename
, line
, x
, "Failed to parse CPU scheduling policy, ignoring: %s", rvalue
);
1363 c
->cpu_sched_policy
= x
;
1364 /* Moving to or from real-time policy? We need to adjust the priority */
1365 c
->cpu_sched_priority
= CLAMP(c
->cpu_sched_priority
, sched_get_priority_min(x
), sched_get_priority_max(x
));
1366 c
->cpu_sched_set
= true;
1371 int config_parse_exec_mount_apivfs(const char *unit
,
1372 const char *filename
,
1374 const char *section
,
1375 unsigned section_line
,
1382 ExecContext
*c
= data
;
1390 if (isempty(rvalue
)) {
1391 c
->mount_apivfs_set
= false;
1392 c
->mount_apivfs
= false;
1396 k
= parse_boolean(rvalue
);
1398 log_syntax(unit
, LOG_WARNING
, filename
, line
, k
,
1399 "Failed to parse boolean value, ignoring: %s",
1404 c
->mount_apivfs_set
= true;
1405 c
->mount_apivfs
= k
;
1409 int config_parse_numa_mask(const char *unit
,
1410 const char *filename
,
1412 const char *section
,
1413 unsigned section_line
,
1420 NUMAPolicy
*p
= data
;
1427 if (streq(rvalue
, "all")) {
1428 r
= numa_mask_add_all(&p
->nodes
);
1430 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1431 "Failed to create NUMA mask representing \"all\" NUMA nodes, ignoring: %m");
1433 r
= parse_cpu_set_extend(rvalue
, &p
->nodes
, true, unit
, filename
, line
, lvalue
);
1435 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse NUMA node mask, ignoring: %s", rvalue
);
1441 int config_parse_exec_cpu_sched_prio(const char *unit
,
1442 const char *filename
,
1444 const char *section
,
1445 unsigned section_line
,
1452 ExecContext
*c
= data
;
1460 r
= safe_atoi(rvalue
, &i
);
1462 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse CPU scheduling priority, ignoring: %s", rvalue
);
1466 /* On Linux RR/FIFO range from 1 to 99 and OTHER/BATCH may only be 0 */
1467 min
= sched_get_priority_min(c
->cpu_sched_policy
);
1468 max
= sched_get_priority_max(c
->cpu_sched_policy
);
1470 if (i
< min
|| i
> max
) {
1471 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "CPU scheduling priority is out of range, ignoring: %s", rvalue
);
1475 c
->cpu_sched_priority
= i
;
1476 c
->cpu_sched_set
= true;
1481 int config_parse_root_image_options(
1483 const char *filename
,
1485 const char *section
,
1486 unsigned section_line
,
1493 _cleanup_(mount_options_free_allp
) MountOptions
*options
= NULL
;
1494 _cleanup_strv_free_
char **l
= NULL
;
1495 char **first
= NULL
, **second
= NULL
;
1496 ExecContext
*c
= data
;
1497 const Unit
*u
= userdata
;
1505 if (isempty(rvalue
)) {
1506 c
->root_image_options
= mount_options_free_all(c
->root_image_options
);
1510 r
= strv_split_colon_pairs(&l
, rvalue
);
1514 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
1518 STRV_FOREACH_PAIR(first
, second
, l
) {
1519 MountOptions
*o
= NULL
;
1520 _cleanup_free_
char *mount_options_resolved
= NULL
;
1521 const char *mount_options
= NULL
, *partition
= "root";
1522 PartitionDesignator partition_designator
;
1524 /* Format is either 'root:foo' or 'foo' (root is implied) */
1525 if (!isempty(*second
)) {
1527 mount_options
= *second
;
1529 mount_options
= *first
;
1531 partition_designator
= partition_designator_from_string(partition
);
1532 if (partition_designator
< 0) {
1533 log_syntax(unit
, LOG_WARNING
, filename
, line
, partition_designator
,
1534 "Invalid partition name %s, ignoring", partition
);
1537 r
= unit_full_printf(u
, mount_options
, &mount_options_resolved
);
1539 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", mount_options
);
1543 o
= new(MountOptions
, 1);
1546 *o
= (MountOptions
) {
1547 .partition_designator
= partition_designator
,
1548 .options
= TAKE_PTR(mount_options_resolved
),
1550 LIST_APPEND(mount_options
, options
, TAKE_PTR(o
));
1553 /* empty spaces/separators only */
1554 if (LIST_IS_EMPTY(options
))
1555 c
->root_image_options
= mount_options_free_all(c
->root_image_options
);
1557 LIST_JOIN(mount_options
, c
->root_image_options
, options
);
1562 int config_parse_exec_root_hash(
1564 const char *filename
,
1566 const char *section
,
1567 unsigned section_line
,
1574 _cleanup_free_
void *roothash_decoded
= NULL
;
1575 ExecContext
*c
= data
;
1576 size_t roothash_decoded_size
= 0;
1584 if (isempty(rvalue
)) {
1585 /* Reset if the empty string is assigned */
1586 c
->root_hash_path
= mfree(c
->root_hash_path
);
1587 c
->root_hash
= mfree(c
->root_hash
);
1588 c
->root_hash_size
= 0;
1592 if (path_is_absolute(rvalue
)) {
1593 /* We have the path to a roothash to load and decode, eg: RootHash=/foo/bar.roothash */
1594 _cleanup_free_
char *p
= NULL
;
1600 free_and_replace(c
->root_hash_path
, p
);
1601 c
->root_hash
= mfree(c
->root_hash
);
1602 c
->root_hash_size
= 0;
1606 /* We have a roothash to decode, eg: RootHash=012345789abcdef */
1607 r
= unhexmem(rvalue
, strlen(rvalue
), &roothash_decoded
, &roothash_decoded_size
);
1609 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to decode RootHash=, ignoring: %s", rvalue
);
1612 if (roothash_decoded_size
< sizeof(sd_id128_t
)) {
1613 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "RootHash= is too short, ignoring: %s", rvalue
);
1617 free_and_replace(c
->root_hash
, roothash_decoded
);
1618 c
->root_hash_size
= roothash_decoded_size
;
1619 c
->root_hash_path
= mfree(c
->root_hash_path
);
1624 int config_parse_exec_root_hash_sig(
1626 const char *filename
,
1628 const char *section
,
1629 unsigned section_line
,
1636 _cleanup_free_
void *roothash_sig_decoded
= NULL
;
1638 ExecContext
*c
= data
;
1639 size_t roothash_sig_decoded_size
= 0;
1647 if (isempty(rvalue
)) {
1648 /* Reset if the empty string is assigned */
1649 c
->root_hash_sig_path
= mfree(c
->root_hash_sig_path
);
1650 c
->root_hash_sig
= mfree(c
->root_hash_sig
);
1651 c
->root_hash_sig_size
= 0;
1655 if (path_is_absolute(rvalue
)) {
1656 /* We have the path to a roothash signature to load and decode, eg: RootHashSignature=/foo/bar.roothash.p7s */
1657 _cleanup_free_
char *p
= NULL
;
1663 free_and_replace(c
->root_hash_sig_path
, p
);
1664 c
->root_hash_sig
= mfree(c
->root_hash_sig
);
1665 c
->root_hash_sig_size
= 0;
1669 if (!(value
= startswith(rvalue
, "base64:"))) {
1670 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
1671 "Failed to decode RootHashSignature=, not a path but doesn't start with 'base64:', ignoring: %s", rvalue
);
1675 /* We have a roothash signature to decode, eg: RootHashSignature=base64:012345789abcdef */
1676 r
= unbase64mem(value
, strlen(value
), &roothash_sig_decoded
, &roothash_sig_decoded_size
);
1678 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to decode RootHashSignature=, ignoring: %s", rvalue
);
1682 free_and_replace(c
->root_hash_sig
, roothash_sig_decoded
);
1683 c
->root_hash_sig_size
= roothash_sig_decoded_size
;
1684 c
->root_hash_sig_path
= mfree(c
->root_hash_sig_path
);
1689 int config_parse_exec_cpu_affinity(
1691 const char *filename
,
1693 const char *section
,
1694 unsigned section_line
,
1701 ExecContext
*c
= data
;
1702 const Unit
*u
= userdata
;
1703 _cleanup_free_
char *k
= NULL
;
1711 if (streq(rvalue
, "numa")) {
1712 c
->cpu_affinity_from_numa
= true;
1713 cpu_set_reset(&c
->cpu_set
);
1718 r
= unit_full_printf(u
, rvalue
, &k
);
1720 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1721 "Failed to resolve unit specifiers in '%s', ignoring: %m",
1726 r
= parse_cpu_set_extend(k
, &c
->cpu_set
, true, unit
, filename
, line
, lvalue
);
1728 c
->cpu_affinity_from_numa
= false;
1733 int config_parse_capability_set(
1735 const char *filename
,
1737 const char *section
,
1738 unsigned section_line
,
1745 uint64_t *capability_set
= data
;
1746 uint64_t sum
= 0, initial
= 0;
1747 bool invert
= false;
1755 if (rvalue
[0] == '~') {
1760 if (streq(lvalue
, "CapabilityBoundingSet"))
1761 initial
= CAP_ALL
; /* initialized to all bits on */
1762 /* else "AmbientCapabilities" initialized to all bits off */
1764 r
= capability_set_from_string(rvalue
, &sum
);
1766 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= specifier '%s', ignoring: %m", lvalue
, rvalue
);
1770 if (sum
== 0 || *capability_set
== initial
)
1771 /* "", "~" or uninitialized data -> replace */
1772 *capability_set
= invert
? ~sum
: sum
;
1774 /* previous data -> merge */
1776 *capability_set
&= ~sum
;
1778 *capability_set
|= sum
;
1784 int config_parse_exec_selinux_context(
1786 const char *filename
,
1788 const char *section
,
1789 unsigned section_line
,
1796 ExecContext
*c
= data
;
1797 const Unit
*u
= userdata
;
1807 if (isempty(rvalue
)) {
1808 c
->selinux_context
= mfree(c
->selinux_context
);
1809 c
->selinux_context_ignore
= false;
1813 if (rvalue
[0] == '-') {
1819 r
= unit_full_printf(u
, rvalue
, &k
);
1821 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
1822 "Failed to resolve unit specifiers in '%s'%s: %m",
1823 rvalue
, ignore
? ", ignoring" : "");
1824 return ignore
? 0 : -ENOEXEC
;
1827 free_and_replace(c
->selinux_context
, k
);
1828 c
->selinux_context_ignore
= ignore
;
1833 int config_parse_exec_apparmor_profile(
1835 const char *filename
,
1837 const char *section
,
1838 unsigned section_line
,
1845 ExecContext
*c
= data
;
1846 const Unit
*u
= userdata
;
1856 if (isempty(rvalue
)) {
1857 c
->apparmor_profile
= mfree(c
->apparmor_profile
);
1858 c
->apparmor_profile_ignore
= false;
1862 if (rvalue
[0] == '-') {
1868 r
= unit_full_printf(u
, rvalue
, &k
);
1870 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
1871 "Failed to resolve unit specifiers in '%s'%s: %m",
1872 rvalue
, ignore
? ", ignoring" : "");
1873 return ignore
? 0 : -ENOEXEC
;
1876 free_and_replace(c
->apparmor_profile
, k
);
1877 c
->apparmor_profile_ignore
= ignore
;
1882 int config_parse_exec_smack_process_label(
1884 const char *filename
,
1886 const char *section
,
1887 unsigned section_line
,
1894 ExecContext
*c
= data
;
1895 const Unit
*u
= userdata
;
1905 if (isempty(rvalue
)) {
1906 c
->smack_process_label
= mfree(c
->smack_process_label
);
1907 c
->smack_process_label_ignore
= false;
1911 if (rvalue
[0] == '-') {
1917 r
= unit_full_printf(u
, rvalue
, &k
);
1919 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
1920 "Failed to resolve unit specifiers in '%s'%s: %m",
1921 rvalue
, ignore
? ", ignoring" : "");
1922 return ignore
? 0 : -ENOEXEC
;
1925 free_and_replace(c
->smack_process_label
, k
);
1926 c
->smack_process_label_ignore
= ignore
;
1931 int config_parse_timer(
1933 const char *filename
,
1935 const char *section
,
1936 unsigned section_line
,
1943 _cleanup_(calendar_spec_freep
) CalendarSpec
*c
= NULL
;
1944 _cleanup_free_
char *k
= NULL
;
1945 const Unit
*u
= userdata
;
1956 if (isempty(rvalue
)) {
1957 /* Empty assignment resets list */
1958 timer_free_values(t
);
1962 r
= unit_full_printf(u
, rvalue
, &k
);
1964 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
1968 if (ltype
== TIMER_CALENDAR
) {
1969 r
= calendar_spec_from_string(k
, &c
);
1971 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse calendar specification, ignoring: %s", k
);
1975 r
= parse_sec(k
, &usec
);
1977 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse timer value, ignoring: %s", k
);
1982 v
= new(TimerValue
, 1);
1989 .calendar_spec
= TAKE_PTR(c
),
1992 LIST_PREPEND(value
, t
->values
, v
);
1997 int config_parse_trigger_unit(
1999 const char *filename
,
2001 const char *section
,
2002 unsigned section_line
,
2009 _cleanup_free_
char *p
= NULL
;
2019 if (UNIT_TRIGGER(u
)) {
2020 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Multiple units to trigger specified, ignoring: %s", rvalue
);
2024 r
= unit_name_printf(u
, rvalue
, &p
);
2026 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2030 type
= unit_name_to_type(p
);
2032 log_syntax(unit
, LOG_WARNING
, filename
, line
, type
, "Unit type not valid, ignoring: %s", rvalue
);
2035 if (unit_has_name(u
, p
)) {
2036 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Units cannot trigger themselves, ignoring: %s", rvalue
);
2040 r
= unit_add_two_dependencies_by_name(u
, UNIT_BEFORE
, UNIT_TRIGGERS
, p
, true, UNIT_DEPENDENCY_FILE
);
2042 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add trigger on %s, ignoring: %m", p
);
2049 int config_parse_path_spec(const char *unit
,
2050 const char *filename
,
2052 const char *section
,
2053 unsigned section_line
,
2063 _cleanup_free_
char *k
= NULL
;
2071 if (isempty(rvalue
)) {
2072 /* Empty assignment clears list */
2077 b
= path_type_from_string(lvalue
);
2079 log_syntax(unit
, LOG_WARNING
, filename
, line
, b
, "Failed to parse path type, ignoring: %s", lvalue
);
2083 r
= unit_full_printf(UNIT(p
), rvalue
, &k
);
2085 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2089 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2093 s
= new0(PathSpec
, 1);
2098 s
->path
= TAKE_PTR(k
);
2102 LIST_PREPEND(spec
, p
->specs
, s
);
2107 int config_parse_socket_service(
2109 const char *filename
,
2111 const char *section
,
2112 unsigned section_line
,
2119 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
2120 _cleanup_free_
char *p
= NULL
;
2130 r
= unit_name_printf(UNIT(s
), rvalue
, &p
);
2132 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2136 if (!endswith(p
, ".service")) {
2137 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Unit must be of type service, ignoring: %s", rvalue
);
2141 r
= manager_load_unit(UNIT(s
)->manager
, p
, NULL
, &error
, &x
);
2143 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to load unit %s, ignoring: %s", rvalue
, bus_error_message(&error
, r
));
2147 unit_ref_set(&s
->service
, UNIT(s
), x
);
2152 int config_parse_fdname(
2154 const char *filename
,
2156 const char *section
,
2157 unsigned section_line
,
2164 _cleanup_free_
char *p
= NULL
;
2173 if (isempty(rvalue
)) {
2174 s
->fdname
= mfree(s
->fdname
);
2178 r
= unit_full_printf(UNIT(s
), rvalue
, &p
);
2180 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2184 if (!fdname_is_valid(p
)) {
2185 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", p
);
2189 return free_and_replace(s
->fdname
, p
);
2192 int config_parse_service_sockets(
2194 const char *filename
,
2196 const char *section
,
2197 unsigned section_line
,
2212 for (const char *p
= rvalue
;;) {
2213 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2215 r
= extract_first_word(&p
, &word
, NULL
, 0);
2219 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Trailing garbage in sockets, ignoring: %s", rvalue
);
2225 r
= unit_name_printf(UNIT(s
), word
, &k
);
2227 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
2231 if (!endswith(k
, ".socket")) {
2232 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Unit must be of type socket, ignoring: %s", k
);
2236 r
= unit_add_two_dependencies_by_name(UNIT(s
), UNIT_WANTS
, UNIT_AFTER
, k
, true, UNIT_DEPENDENCY_FILE
);
2238 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
2240 r
= unit_add_dependency_by_name(UNIT(s
), UNIT_TRIGGERED_BY
, k
, true, UNIT_DEPENDENCY_FILE
);
2242 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
2246 int config_parse_bus_name(
2248 const char *filename
,
2250 const char *section
,
2251 unsigned section_line
,
2258 _cleanup_free_
char *k
= NULL
;
2259 const Unit
*u
= userdata
;
2267 r
= unit_full_printf(u
, rvalue
, &k
);
2269 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2273 if (!sd_bus_service_name_is_valid(k
)) {
2274 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid bus name, ignoring: %s", k
);
2278 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
2281 int config_parse_service_timeout(
2283 const char *filename
,
2285 const char *section
,
2286 unsigned section_line
,
2293 Service
*s
= userdata
;
2302 /* This is called for two cases: TimeoutSec= and TimeoutStartSec=. */
2304 /* Traditionally, these options accepted 0 to disable the timeouts. However, a timeout of 0 suggests it happens
2305 * immediately, hence fix this to become USEC_INFINITY instead. This is in-line with how we internally handle
2306 * all other timeouts. */
2307 r
= parse_sec_fix_0(rvalue
, &usec
);
2309 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
2313 s
->start_timeout_defined
= true;
2314 s
->timeout_start_usec
= usec
;
2316 if (streq(lvalue
, "TimeoutSec"))
2317 s
->timeout_stop_usec
= usec
;
2322 int config_parse_timeout_abort(
2324 const char *filename
,
2326 const char *section
,
2327 unsigned section_line
,
2342 /* Note: apart from setting the arg, this returns an extra bit of information in the return value. */
2344 if (isempty(rvalue
)) {
2346 return 0; /* "not set" */
2349 r
= parse_sec(rvalue
, ret
);
2351 return log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= setting, ignoring: %s", lvalue
, rvalue
);
2353 return 1; /* "set" */
2356 int config_parse_service_timeout_abort(
2358 const char *filename
,
2360 const char *section
,
2361 unsigned section_line
,
2368 Service
*s
= userdata
;
2373 r
= config_parse_timeout_abort(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
,
2374 &s
->timeout_abort_usec
, s
);
2376 s
->timeout_abort_set
= r
;
2380 int config_parse_sec_fix_0(
2382 const char *filename
,
2384 const char *section
,
2385 unsigned section_line
,
2392 usec_t
*usec
= data
;
2400 /* This is pretty much like config_parse_sec(), except that this treats a time of 0 as infinity, for
2401 * compatibility with older versions of systemd where 0 instead of infinity was used as indicator to turn off a
2404 r
= parse_sec_fix_0(rvalue
, usec
);
2406 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
2411 int config_parse_user_group_compat(
2413 const char *filename
,
2415 const char *section
,
2416 unsigned section_line
,
2423 _cleanup_free_
char *k
= NULL
;
2425 const Unit
*u
= userdata
;
2433 if (isempty(rvalue
)) {
2434 *user
= mfree(*user
);
2438 r
= unit_full_printf(u
, rvalue
, &k
);
2440 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", rvalue
);
2444 if (!valid_user_group_name(k
, VALID_USER_ALLOW_NUMERIC
|VALID_USER_RELAX
|VALID_USER_WARN
)) {
2445 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2449 if (strstr(lvalue
, "User") && streq(k
, NOBODY_USER_NAME
))
2450 log_struct(LOG_NOTICE
,
2451 "MESSAGE=%s:%u: Special user %s configured, this is not safe!", filename
, line
, k
,
2453 "MESSAGE_ID=" SD_MESSAGE_NOBODY_USER_UNSUITABLE_STR
,
2454 "OFFENDING_USER=%s", k
,
2455 "CONFIG_FILE=%s", filename
,
2456 "CONFIG_LINE=%u", line
);
2458 return free_and_replace(*user
, k
);
2461 int config_parse_user_group_strv_compat(
2463 const char *filename
,
2465 const char *section
,
2466 unsigned section_line
,
2473 char ***users
= data
;
2474 const Unit
*u
= userdata
;
2482 if (isempty(rvalue
)) {
2483 *users
= strv_free(*users
);
2487 for (const char *p
= rvalue
;;) {
2488 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2490 r
= extract_first_word(&p
, &word
, NULL
, 0);
2494 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax: %s", rvalue
);
2500 r
= unit_full_printf(u
, word
, &k
);
2502 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", word
);
2506 if (!valid_user_group_name(k
, VALID_USER_ALLOW_NUMERIC
|VALID_USER_RELAX
|VALID_USER_WARN
)) {
2507 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2511 r
= strv_push(users
, k
);
2519 int config_parse_working_directory(
2521 const char *filename
,
2523 const char *section
,
2524 unsigned section_line
,
2531 ExecContext
*c
= data
;
2532 const Unit
*u
= userdata
;
2542 if (isempty(rvalue
)) {
2543 c
->working_directory_home
= false;
2544 c
->working_directory
= mfree(c
->working_directory
);
2548 if (rvalue
[0] == '-') {
2554 if (streq(rvalue
, "~")) {
2555 c
->working_directory_home
= true;
2556 c
->working_directory
= mfree(c
->working_directory
);
2558 _cleanup_free_
char *k
= NULL
;
2560 r
= unit_full_printf(u
, rvalue
, &k
);
2562 log_syntax(unit
, missing_ok
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
2563 "Failed to resolve unit specifiers in working directory path '%s'%s: %m",
2564 rvalue
, missing_ok
? ", ignoring" : "");
2565 return missing_ok
? 0 : -ENOEXEC
;
2568 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
| (missing_ok
? 0 : PATH_CHECK_FATAL
), unit
, filename
, line
, lvalue
);
2570 return missing_ok
? 0 : -ENOEXEC
;
2572 c
->working_directory_home
= false;
2573 free_and_replace(c
->working_directory
, k
);
2576 c
->working_directory_missing_ok
= missing_ok
;
2580 int config_parse_unit_env_file(const char *unit
,
2581 const char *filename
,
2583 const char *section
,
2584 unsigned section_line
,
2592 const Unit
*u
= userdata
;
2593 _cleanup_free_
char *n
= NULL
;
2601 if (isempty(rvalue
)) {
2602 /* Empty assignment frees the list */
2603 *env
= strv_free(*env
);
2607 r
= unit_full_printf(u
, rvalue
, &n
);
2609 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2613 r
= path_simplify_and_warn(n
[0] == '-' ? n
+ 1 : n
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2617 r
= strv_push(env
, n
);
2626 int config_parse_environ(
2628 const char *filename
,
2630 const char *section
,
2631 unsigned section_line
,
2638 const Unit
*u
= userdata
;
2647 if (isempty(rvalue
)) {
2648 /* Empty assignment resets the list */
2649 *env
= strv_free(*env
);
2653 for (const char *p
= rvalue
;; ) {
2654 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
2656 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2660 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2661 "Invalid syntax, ignoring: %s", rvalue
);
2668 r
= unit_full_printf(u
, word
, &resolved
);
2670 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2671 "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2675 resolved
= TAKE_PTR(word
);
2677 if (!env_assignment_is_valid(resolved
)) {
2678 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
2679 "Invalid environment assignment, ignoring: %s", resolved
);
2683 r
= strv_env_replace_consume(env
, TAKE_PTR(resolved
));
2685 return log_error_errno(r
, "Failed to update environment: %m");
2689 int config_parse_pass_environ(
2691 const char *filename
,
2693 const char *section
,
2694 unsigned section_line
,
2701 _cleanup_strv_free_
char **n
= NULL
;
2702 size_t nlen
= 0, nbufsize
= 0;
2703 char*** passenv
= data
;
2704 const Unit
*u
= userdata
;
2712 if (isempty(rvalue
)) {
2713 /* Empty assignment resets the list */
2714 *passenv
= strv_free(*passenv
);
2718 for (const char *p
= rvalue
;;) {
2719 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2721 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
2725 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2726 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2733 r
= unit_full_printf(u
, word
, &k
);
2735 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2736 "Failed to resolve specifiers in %s, ignoring: %m", word
);
2742 if (!env_name_is_valid(k
)) {
2743 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
2744 "Invalid environment name for %s, ignoring: %s", lvalue
, k
);
2748 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
2751 n
[nlen
++] = TAKE_PTR(k
);
2756 r
= strv_extend_strv(passenv
, n
, true);
2764 int config_parse_unset_environ(
2766 const char *filename
,
2768 const char *section
,
2769 unsigned section_line
,
2776 _cleanup_strv_free_
char **n
= NULL
;
2777 size_t nlen
= 0, nbufsize
= 0;
2778 char*** unsetenv
= data
;
2779 const Unit
*u
= userdata
;
2787 if (isempty(rvalue
)) {
2788 /* Empty assignment resets the list */
2789 *unsetenv
= strv_free(*unsetenv
);
2793 for (const char *p
= rvalue
;;) {
2794 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2796 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2800 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2801 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2808 r
= unit_full_printf(u
, word
, &k
);
2810 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2811 "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2817 if (!env_assignment_is_valid(k
) && !env_name_is_valid(k
)) {
2818 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
2819 "Invalid environment name or assignment %s, ignoring: %s", lvalue
, k
);
2823 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
2826 n
[nlen
++] = TAKE_PTR(k
);
2831 r
= strv_extend_strv(unsetenv
, n
, true);
2839 int config_parse_log_extra_fields(
2841 const char *filename
,
2843 const char *section
,
2844 unsigned section_line
,
2851 ExecContext
*c
= data
;
2852 const Unit
*u
= userdata
;
2860 if (isempty(rvalue
)) {
2861 exec_context_free_log_extra_fields(c
);
2865 for (const char *p
= rvalue
;;) {
2866 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2870 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2874 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
2880 r
= unit_full_printf(u
, word
, &k
);
2882 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2886 eq
= strchr(k
, '=');
2888 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Log field lacks '=' character, ignoring: %s", k
);
2892 if (!journal_field_valid(k
, eq
-k
, false)) {
2893 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Log field name is invalid, ignoring: %s", k
);
2897 t
= reallocarray(c
->log_extra_fields
, c
->n_log_extra_fields
+1, sizeof(struct iovec
));
2901 c
->log_extra_fields
= t
;
2902 c
->log_extra_fields
[c
->n_log_extra_fields
++] = IOVEC_MAKE_STRING(k
);
2908 int config_parse_log_namespace(
2910 const char *filename
,
2912 const char *section
,
2913 unsigned section_line
,
2920 _cleanup_free_
char *k
= NULL
;
2921 ExecContext
*c
= data
;
2922 const Unit
*u
= userdata
;
2930 if (isempty(rvalue
)) {
2931 c
->log_namespace
= mfree(c
->log_namespace
);
2935 r
= unit_full_printf(u
, rvalue
, &k
);
2937 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2941 if (!log_namespace_name_valid(k
)) {
2942 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Specified log namespace name is not valid, ignoring: %s", k
);
2946 free_and_replace(c
->log_namespace
, k
);
2950 int config_parse_unit_condition_path(
2952 const char *filename
,
2954 const char *section
,
2955 unsigned section_line
,
2962 _cleanup_free_
char *p
= NULL
;
2963 Condition
**list
= data
, *c
;
2964 ConditionType t
= ltype
;
2965 bool trigger
, negate
;
2966 const Unit
*u
= userdata
;
2974 if (isempty(rvalue
)) {
2975 /* Empty assignment resets the list */
2976 *list
= condition_free_list(*list
);
2980 trigger
= rvalue
[0] == '|';
2984 negate
= rvalue
[0] == '!';
2988 r
= unit_full_printf(u
, rvalue
, &p
);
2990 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2994 r
= path_simplify_and_warn(p
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2998 c
= condition_new(t
, p
, trigger
, negate
);
3002 LIST_PREPEND(conditions
, *list
, c
);
3006 int config_parse_unit_condition_string(
3008 const char *filename
,
3010 const char *section
,
3011 unsigned section_line
,
3018 _cleanup_free_
char *s
= NULL
;
3019 Condition
**list
= data
, *c
;
3020 ConditionType t
= ltype
;
3021 bool trigger
, negate
;
3022 const Unit
*u
= userdata
;
3030 if (isempty(rvalue
)) {
3031 /* Empty assignment resets the list */
3032 *list
= condition_free_list(*list
);
3036 trigger
= *rvalue
== '|';
3038 rvalue
+= 1 + strspn(rvalue
+ 1, WHITESPACE
);
3040 negate
= *rvalue
== '!';
3042 rvalue
+= 1 + strspn(rvalue
+ 1, WHITESPACE
);
3044 r
= unit_full_printf(u
, rvalue
, &s
);
3046 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3047 "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
3051 c
= condition_new(t
, s
, trigger
, negate
);
3055 LIST_PREPEND(conditions
, *list
, c
);
3059 int config_parse_unit_requires_mounts_for(
3061 const char *filename
,
3063 const char *section
,
3064 unsigned section_line
,
3079 for (const char *p
= rvalue
;;) {
3080 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
3082 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3086 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3087 "Invalid syntax, ignoring: %s", rvalue
);
3093 r
= unit_full_printf(u
, word
, &resolved
);
3095 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
3099 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
3103 r
= unit_require_mounts_for(u
, resolved
, UNIT_DEPENDENCY_FILE
);
3105 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add required mount '%s', ignoring: %m", resolved
);
3111 int config_parse_documentation(
3113 const char *filename
,
3115 const char *section
,
3116 unsigned section_line
,
3132 if (isempty(rvalue
)) {
3133 /* Empty assignment resets the list */
3134 u
->documentation
= strv_free(u
->documentation
);
3138 r
= config_parse_unit_strv_printf(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
,
3139 rvalue
, data
, userdata
);
3143 for (a
= b
= u
->documentation
; a
&& *a
; a
++) {
3145 if (documentation_url_is_valid(*a
))
3148 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid URL, ignoring: %s", *a
);
3159 int config_parse_syscall_filter(
3161 const char *filename
,
3163 const char *section
,
3164 unsigned section_line
,
3171 ExecContext
*c
= data
;
3172 _unused_
const Unit
*u
= userdata
;
3173 bool invert
= false;
3181 if (isempty(rvalue
)) {
3182 /* Empty assignment resets the list */
3183 c
->syscall_filter
= hashmap_free(c
->syscall_filter
);
3184 c
->syscall_allow_list
= false;
3188 if (rvalue
[0] == '~') {
3193 if (!c
->syscall_filter
) {
3194 c
->syscall_filter
= hashmap_new(NULL
);
3195 if (!c
->syscall_filter
)
3199 /* Allow everything but the ones listed */
3200 c
->syscall_allow_list
= false;
3202 /* Allow nothing but the ones listed */
3203 c
->syscall_allow_list
= true;
3205 /* Accept default syscalls if we are on a allow_list */
3206 r
= seccomp_parse_syscall_filter(
3207 "@default", -1, c
->syscall_filter
,
3208 SECCOMP_PARSE_PERMISSIVE
|SECCOMP_PARSE_ALLOW_LIST
,
3216 for (const char *p
= rvalue
;;) {
3217 _cleanup_free_
char *word
= NULL
, *name
= NULL
;
3220 r
= extract_first_word(&p
, &word
, NULL
, 0);
3224 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3225 "Invalid syntax, ignoring: %s", rvalue
);
3231 r
= parse_syscall_and_errno(word
, &name
, &num
);
3233 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3234 "Failed to parse syscall:errno, ignoring: %s", word
);
3237 if (!invert
&& num
>= 0) {
3238 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3239 "Allow-listed system calls cannot take error number, ignoring: %s", word
);
3243 r
= seccomp_parse_syscall_filter(
3244 name
, num
, c
->syscall_filter
,
3245 SECCOMP_PARSE_LOG
|SECCOMP_PARSE_PERMISSIVE
|
3246 (invert
? SECCOMP_PARSE_INVERT
: 0)|
3247 (c
->syscall_allow_list
? SECCOMP_PARSE_ALLOW_LIST
: 0),
3248 unit
, filename
, line
);
3254 int config_parse_syscall_log(
3256 const char *filename
,
3258 const char *section
,
3259 unsigned section_line
,
3266 ExecContext
*c
= data
;
3267 _unused_
const Unit
*u
= userdata
;
3268 bool invert
= false;
3277 if (isempty(rvalue
)) {
3278 /* Empty assignment resets the list */
3279 c
->syscall_log
= hashmap_free(c
->syscall_log
);
3280 c
->syscall_log_allow_list
= false;
3284 if (rvalue
[0] == '~') {
3289 if (!c
->syscall_log
) {
3290 c
->syscall_log
= hashmap_new(NULL
);
3291 if (!c
->syscall_log
)
3295 /* Log everything but the ones listed */
3296 c
->syscall_log_allow_list
= false;
3298 /* Log nothing but the ones listed */
3299 c
->syscall_log_allow_list
= true;
3304 _cleanup_free_
char *word
= NULL
;
3306 r
= extract_first_word(&p
, &word
, NULL
, 0);
3310 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3316 r
= seccomp_parse_syscall_filter(
3317 word
, -1, c
->syscall_log
,
3318 SECCOMP_PARSE_LOG
|SECCOMP_PARSE_PERMISSIVE
|
3319 (invert
? SECCOMP_PARSE_INVERT
: 0)|
3320 (c
->syscall_log_allow_list
? SECCOMP_PARSE_ALLOW_LIST
: 0),
3321 unit
, filename
, line
);
3327 int config_parse_syscall_archs(
3329 const char *filename
,
3331 const char *section
,
3332 unsigned section_line
,
3342 if (isempty(rvalue
)) {
3343 *archs
= set_free(*archs
);
3347 for (const char *p
= rvalue
;;) {
3348 _cleanup_free_
char *word
= NULL
;
3351 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3355 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3356 "Invalid syntax, ignoring: %s", rvalue
);
3362 r
= seccomp_arch_from_string(word
, &a
);
3364 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3365 "Failed to parse system call architecture \"%s\", ignoring: %m", word
);
3369 r
= set_ensure_put(archs
, NULL
, UINT32_TO_PTR(a
+ 1));
3375 int config_parse_syscall_errno(
3377 const char *filename
,
3379 const char *section
,
3380 unsigned section_line
,
3387 ExecContext
*c
= data
;
3394 if (isempty(rvalue
) || streq(rvalue
, "kill")) {
3395 /* Empty assignment resets to KILL */
3396 c
->syscall_errno
= SECCOMP_ERROR_NUMBER_KILL
;
3400 e
= parse_errno(rvalue
);
3402 log_syntax(unit
, LOG_WARNING
, filename
, line
, e
, "Failed to parse error number, ignoring: %s", rvalue
);
3406 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid error number, ignoring: %s", rvalue
);
3410 c
->syscall_errno
= e
;
3414 int config_parse_address_families(
3416 const char *filename
,
3418 const char *section
,
3419 unsigned section_line
,
3426 ExecContext
*c
= data
;
3427 bool invert
= false;
3434 if (isempty(rvalue
)) {
3435 /* Empty assignment resets the list */
3436 c
->address_families
= set_free(c
->address_families
);
3437 c
->address_families_allow_list
= false;
3441 if (streq(rvalue
, "none")) {
3442 /* Forbid all address families. */
3443 c
->address_families
= set_free(c
->address_families
);
3444 c
->address_families_allow_list
= true;
3448 if (rvalue
[0] == '~') {
3453 if (!c
->address_families
) {
3454 c
->address_families
= set_new(NULL
);
3455 if (!c
->address_families
)
3458 c
->address_families_allow_list
= !invert
;
3461 for (const char *p
= rvalue
;;) {
3462 _cleanup_free_
char *word
= NULL
;
3465 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3469 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3470 "Invalid syntax, ignoring: %s", rvalue
);
3476 af
= af_from_name(word
);
3478 log_syntax(unit
, LOG_WARNING
, filename
, line
, af
,
3479 "Failed to parse address family, ignoring: %s", word
);
3483 /* If we previously wanted to forbid an address family and now
3484 * we want to allow it, then just remove it from the list.
3486 if (!invert
== c
->address_families_allow_list
) {
3487 r
= set_put(c
->address_families
, INT_TO_PTR(af
));
3491 set_remove(c
->address_families
, INT_TO_PTR(af
));
3495 int config_parse_restrict_namespaces(
3497 const char *filename
,
3499 const char *section
,
3500 unsigned section_line
,
3507 ExecContext
*c
= data
;
3508 unsigned long flags
;
3509 bool invert
= false;
3512 if (isempty(rvalue
)) {
3513 /* Reset to the default. */
3514 c
->restrict_namespaces
= NAMESPACE_FLAGS_INITIAL
;
3518 /* Boolean parameter ignores the previous settings */
3519 r
= parse_boolean(rvalue
);
3521 c
->restrict_namespaces
= 0;
3523 } else if (r
== 0) {
3524 c
->restrict_namespaces
= NAMESPACE_FLAGS_ALL
;
3528 if (rvalue
[0] == '~') {
3533 /* Not a boolean argument, in this case it's a list of namespace types. */
3534 r
= namespace_flags_from_string(rvalue
, &flags
);
3536 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse namespace type string, ignoring: %s", rvalue
);
3540 if (c
->restrict_namespaces
== NAMESPACE_FLAGS_INITIAL
)
3541 /* Initial assignment. Just set the value. */
3542 c
->restrict_namespaces
= invert
? (~flags
) & NAMESPACE_FLAGS_ALL
: flags
;
3544 /* Merge the value with the previous one. */
3545 SET_FLAG(c
->restrict_namespaces
, flags
, !invert
);
3551 int config_parse_unit_slice(
3553 const char *filename
,
3555 const char *section
,
3556 unsigned section_line
,
3563 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
3564 _cleanup_free_
char *k
= NULL
;
3565 Unit
*u
= userdata
, *slice
;
3573 r
= unit_name_printf(u
, rvalue
, &k
);
3575 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
3579 r
= manager_load_unit(u
->manager
, k
, NULL
, &error
, &slice
);
3581 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to load slice unit %s, ignoring: %s", k
, bus_error_message(&error
, r
));
3585 r
= unit_set_slice(u
, slice
);
3587 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to assign slice %s to unit %s, ignoring: %m", slice
->id
, u
->id
);
3594 int config_parse_cpu_quota(
3596 const char *filename
,
3598 const char *section
,
3599 unsigned section_line
,
3606 CGroupContext
*c
= data
;
3613 if (isempty(rvalue
)) {
3614 c
->cpu_quota_per_sec_usec
= USEC_INFINITY
;
3618 r
= parse_permyriad_unbounded(rvalue
);
3620 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid CPU quota '%s', ignoring.", rvalue
);
3624 c
->cpu_quota_per_sec_usec
= ((usec_t
) r
* USEC_PER_SEC
) / 10000U;
3628 int config_parse_allowed_cpus(
3630 const char *filename
,
3632 const char *section
,
3633 unsigned section_line
,
3640 CGroupContext
*c
= data
;
3642 (void) parse_cpu_set_extend(rvalue
, &c
->cpuset_cpus
, true, unit
, filename
, line
, lvalue
);
3647 int config_parse_allowed_mems(
3649 const char *filename
,
3651 const char *section
,
3652 unsigned section_line
,
3659 CGroupContext
*c
= data
;
3661 (void) parse_cpu_set_extend(rvalue
, &c
->cpuset_mems
, true, unit
, filename
, line
, lvalue
);
3666 int config_parse_memory_limit(
3668 const char *filename
,
3670 const char *section
,
3671 unsigned section_line
,
3678 CGroupContext
*c
= data
;
3679 uint64_t bytes
= CGROUP_LIMIT_MAX
;
3682 if (isempty(rvalue
) && STR_IN_SET(lvalue
, "DefaultMemoryLow",
3686 bytes
= CGROUP_LIMIT_MIN
;
3687 else if (!isempty(rvalue
) && !streq(rvalue
, "infinity")) {
3689 r
= parse_permyriad(rvalue
);
3691 r
= parse_size(rvalue
, 1024, &bytes
);
3693 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid memory limit '%s', ignoring: %m", rvalue
);
3697 bytes
= physical_memory_scale(r
, 10000U);
3699 if (bytes
>= UINT64_MAX
||
3700 (bytes
<= 0 && !STR_IN_SET(lvalue
, "MemorySwapMax", "MemoryLow", "MemoryMin", "DefaultMemoryLow", "DefaultMemoryMin"))) {
3701 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Memory limit '%s' out of range, ignoring.", rvalue
);
3706 if (streq(lvalue
, "DefaultMemoryLow")) {
3707 c
->default_memory_low
= bytes
;
3708 c
->default_memory_low_set
= true;
3709 } else if (streq(lvalue
, "DefaultMemoryMin")) {
3710 c
->default_memory_min
= bytes
;
3711 c
->default_memory_min_set
= true;
3712 } else if (streq(lvalue
, "MemoryMin")) {
3713 c
->memory_min
= bytes
;
3714 c
->memory_min_set
= true;
3715 } else if (streq(lvalue
, "MemoryLow")) {
3716 c
->memory_low
= bytes
;
3717 c
->memory_low_set
= true;
3718 } else if (streq(lvalue
, "MemoryHigh"))
3719 c
->memory_high
= bytes
;
3720 else if (streq(lvalue
, "MemoryMax"))
3721 c
->memory_max
= bytes
;
3722 else if (streq(lvalue
, "MemorySwapMax"))
3723 c
->memory_swap_max
= bytes
;
3724 else if (streq(lvalue
, "MemoryLimit"))
3725 c
->memory_limit
= bytes
;
3732 int config_parse_tasks_max(
3734 const char *filename
,
3736 const char *section
,
3737 unsigned section_line
,
3744 const Unit
*u
= userdata
;
3745 TasksMax
*tasks_max
= data
;
3749 if (isempty(rvalue
)) {
3750 *tasks_max
= u
? u
->manager
->default_tasks_max
: TASKS_MAX_UNSET
;
3754 if (streq(rvalue
, "infinity")) {
3755 *tasks_max
= TASKS_MAX_UNSET
;
3759 r
= parse_permyriad(rvalue
);
3761 *tasks_max
= (TasksMax
) { r
, 10000U }; /* r‱ */
3763 r
= safe_atou64(rvalue
, &v
);
3765 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid maximum tasks value '%s', ignoring: %m", rvalue
);
3769 if (v
<= 0 || v
>= UINT64_MAX
) {
3770 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Maximum tasks value '%s' out of range, ignoring.", rvalue
);
3774 *tasks_max
= (TasksMax
) { v
};
3780 int config_parse_delegate(
3782 const char *filename
,
3784 const char *section
,
3785 unsigned section_line
,
3792 CGroupContext
*c
= data
;
3796 t
= unit_name_to_type(unit
);
3797 assert(t
!= _UNIT_TYPE_INVALID
);
3799 if (!unit_vtable
[t
]->can_delegate
) {
3800 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Delegate= setting not supported for this unit type, ignoring.");
3804 /* We either accept a boolean value, which may be used to turn on delegation for all controllers, or turn it
3805 * off for all. Or it takes a list of controller names, in which case we add the specified controllers to the
3806 * mask to delegate. */
3808 if (isempty(rvalue
)) {
3809 /* An empty string resets controllers and set Delegate=yes. */
3811 c
->delegate_controllers
= 0;
3815 r
= parse_boolean(rvalue
);
3817 CGroupMask mask
= 0;
3819 for (const char *p
= rvalue
;;) {
3820 _cleanup_free_
char *word
= NULL
;
3821 CGroupController cc
;
3823 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3827 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3833 cc
= cgroup_controller_from_string(word
);
3835 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid controller name '%s', ignoring", word
);
3839 mask
|= CGROUP_CONTROLLER_TO_MASK(cc
);
3843 c
->delegate_controllers
|= mask
;
3847 c
->delegate_controllers
= _CGROUP_MASK_ALL
;
3849 c
->delegate
= false;
3850 c
->delegate_controllers
= 0;
3856 int config_parse_managed_oom_mode(
3858 const char *filename
,
3860 const char *section
,
3861 unsigned section_line
,
3868 ManagedOOMMode
*mode
= data
, m
;
3871 t
= unit_name_to_type(unit
);
3872 assert(t
!= _UNIT_TYPE_INVALID
);
3874 if (!unit_vtable
[t
]->can_set_managed_oom
)
3875 return log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "%s= is not supported for this unit type, ignoring.", lvalue
);
3877 if (isempty(rvalue
)) {
3878 *mode
= MANAGED_OOM_AUTO
;
3882 m
= managed_oom_mode_from_string(rvalue
);
3884 log_syntax(unit
, LOG_WARNING
, filename
, line
, m
, "Invalid syntax, ignoring: %s", rvalue
);
3892 int config_parse_managed_oom_mem_pressure_limit(
3894 const char *filename
,
3896 const char *section
,
3897 unsigned section_line
,
3904 uint32_t *limit
= data
;
3908 t
= unit_name_to_type(unit
);
3909 assert(t
!= _UNIT_TYPE_INVALID
);
3911 if (!unit_vtable
[t
]->can_set_managed_oom
)
3912 return log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "%s= is not supported for this unit type, ignoring.", lvalue
);
3914 if (isempty(rvalue
)) {
3919 r
= parse_permyriad(rvalue
);
3921 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse memory pressure limit value, ignoring: %s", rvalue
);
3925 /* Normalize to 2^32-1 == 100% */
3926 *limit
= UINT32_SCALE_FROM_PERMYRIAD(r
);
3930 int config_parse_device_allow(
3932 const char *filename
,
3934 const char *section
,
3935 unsigned section_line
,
3942 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3943 CGroupContext
*c
= data
;
3944 const char *p
= rvalue
;
3947 if (isempty(rvalue
)) {
3948 while (c
->device_allow
)
3949 cgroup_context_free_device_allow(c
, c
->device_allow
);
3954 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3958 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3959 "Failed to extract device path and rights from '%s', ignoring.", rvalue
);
3963 r
= unit_full_printf(userdata
, path
, &resolved
);
3965 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3966 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3970 if (!STARTSWITH_SET(resolved
, "block-", "char-")) {
3972 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3976 if (!valid_device_node_path(resolved
)) {
3977 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid device node path '%s', ignoring.", resolved
);
3982 if (!isempty(p
) && !in_charset(p
, "rwm")) {
3983 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid device rights '%s', ignoring.", p
);
3987 return cgroup_add_device_allow(c
, resolved
, p
);
3990 int config_parse_io_device_weight(
3992 const char *filename
,
3994 const char *section
,
3995 unsigned section_line
,
4002 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4003 CGroupIODeviceWeight
*w
;
4004 CGroupContext
*c
= data
;
4005 const char *p
= rvalue
;
4013 if (isempty(rvalue
)) {
4014 while (c
->io_device_weights
)
4015 cgroup_context_free_io_device_weight(c
, c
->io_device_weights
);
4020 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4023 if (r
<= 0 || isempty(p
)) {
4024 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4025 "Failed to extract device path and weight from '%s', ignoring.", rvalue
);
4029 r
= unit_full_printf(userdata
, path
, &resolved
);
4031 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4032 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4036 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4040 r
= cg_weight_parse(p
, &u
);
4042 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "IO weight '%s' invalid, ignoring: %m", p
);
4046 assert(u
!= CGROUP_WEIGHT_INVALID
);
4048 w
= new0(CGroupIODeviceWeight
, 1);
4052 w
->path
= TAKE_PTR(resolved
);
4055 LIST_PREPEND(device_weights
, c
->io_device_weights
, w
);
4059 int config_parse_io_device_latency(
4061 const char *filename
,
4063 const char *section
,
4064 unsigned section_line
,
4071 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4072 CGroupIODeviceLatency
*l
;
4073 CGroupContext
*c
= data
;
4074 const char *p
= rvalue
;
4082 if (isempty(rvalue
)) {
4083 while (c
->io_device_latencies
)
4084 cgroup_context_free_io_device_latency(c
, c
->io_device_latencies
);
4089 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4092 if (r
<= 0 || isempty(p
)) {
4093 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4094 "Failed to extract device path and latency from '%s', ignoring.", rvalue
);
4098 r
= unit_full_printf(userdata
, path
, &resolved
);
4100 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4101 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4105 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4109 r
= parse_sec(p
, &usec
);
4111 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse timer value, ignoring: %s", p
);
4115 l
= new0(CGroupIODeviceLatency
, 1);
4119 l
->path
= TAKE_PTR(resolved
);
4120 l
->target_usec
= usec
;
4122 LIST_PREPEND(device_latencies
, c
->io_device_latencies
, l
);
4126 int config_parse_io_limit(
4128 const char *filename
,
4130 const char *section
,
4131 unsigned section_line
,
4138 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4139 CGroupIODeviceLimit
*l
= NULL
, *t
;
4140 CGroupContext
*c
= data
;
4141 CGroupIOLimitType type
;
4142 const char *p
= rvalue
;
4150 type
= cgroup_io_limit_type_from_string(lvalue
);
4153 if (isempty(rvalue
)) {
4154 LIST_FOREACH(device_limits
, l
, c
->io_device_limits
)
4155 l
->limits
[type
] = cgroup_io_limit_defaults
[type
];
4159 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4162 if (r
<= 0 || isempty(p
)) {
4163 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4164 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
4168 r
= unit_full_printf(userdata
, path
, &resolved
);
4170 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4171 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4175 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4179 if (streq("infinity", p
))
4180 num
= CGROUP_LIMIT_MAX
;
4182 r
= parse_size(p
, 1000, &num
);
4183 if (r
< 0 || num
<= 0) {
4184 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid IO limit '%s', ignoring.", p
);
4189 LIST_FOREACH(device_limits
, t
, c
->io_device_limits
) {
4190 if (path_equal(resolved
, t
->path
)) {
4197 CGroupIOLimitType ttype
;
4199 l
= new0(CGroupIODeviceLimit
, 1);
4203 l
->path
= TAKE_PTR(resolved
);
4204 for (ttype
= 0; ttype
< _CGROUP_IO_LIMIT_TYPE_MAX
; ttype
++)
4205 l
->limits
[ttype
] = cgroup_io_limit_defaults
[ttype
];
4207 LIST_PREPEND(device_limits
, c
->io_device_limits
, l
);
4210 l
->limits
[type
] = num
;
4215 int config_parse_blockio_device_weight(
4217 const char *filename
,
4219 const char *section
,
4220 unsigned section_line
,
4227 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4228 CGroupBlockIODeviceWeight
*w
;
4229 CGroupContext
*c
= data
;
4230 const char *p
= rvalue
;
4238 if (isempty(rvalue
)) {
4239 while (c
->blockio_device_weights
)
4240 cgroup_context_free_blockio_device_weight(c
, c
->blockio_device_weights
);
4245 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4248 if (r
<= 0 || isempty(p
)) {
4249 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4250 "Failed to extract device node and weight from '%s', ignoring.", rvalue
);
4254 r
= unit_full_printf(userdata
, path
, &resolved
);
4256 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4257 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4261 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4265 r
= cg_blkio_weight_parse(p
, &u
);
4267 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid block IO weight '%s', ignoring: %m", p
);
4271 assert(u
!= CGROUP_BLKIO_WEIGHT_INVALID
);
4273 w
= new0(CGroupBlockIODeviceWeight
, 1);
4277 w
->path
= TAKE_PTR(resolved
);
4280 LIST_PREPEND(device_weights
, c
->blockio_device_weights
, w
);
4284 int config_parse_blockio_bandwidth(
4286 const char *filename
,
4288 const char *section
,
4289 unsigned section_line
,
4296 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4297 CGroupBlockIODeviceBandwidth
*b
= NULL
, *t
;
4298 CGroupContext
*c
= data
;
4299 const char *p
= rvalue
;
4308 read
= streq("BlockIOReadBandwidth", lvalue
);
4310 if (isempty(rvalue
)) {
4311 LIST_FOREACH(device_bandwidths
, b
, c
->blockio_device_bandwidths
) {
4312 b
->rbps
= CGROUP_LIMIT_MAX
;
4313 b
->wbps
= CGROUP_LIMIT_MAX
;
4318 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4321 if (r
<= 0 || isempty(p
)) {
4322 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4323 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
4327 r
= unit_full_printf(userdata
, path
, &resolved
);
4329 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4330 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4334 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4338 r
= parse_size(p
, 1000, &bytes
);
4339 if (r
< 0 || bytes
<= 0) {
4340 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid Block IO Bandwidth '%s', ignoring.", p
);
4344 LIST_FOREACH(device_bandwidths
, t
, c
->blockio_device_bandwidths
) {
4345 if (path_equal(resolved
, t
->path
)) {
4352 b
= new0(CGroupBlockIODeviceBandwidth
, 1);
4356 b
->path
= TAKE_PTR(resolved
);
4357 b
->rbps
= CGROUP_LIMIT_MAX
;
4358 b
->wbps
= CGROUP_LIMIT_MAX
;
4360 LIST_PREPEND(device_bandwidths
, c
->blockio_device_bandwidths
, b
);
4371 int config_parse_job_mode_isolate(
4373 const char *filename
,
4375 const char *section
,
4376 unsigned section_line
,
4390 r
= parse_boolean(rvalue
);
4392 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse boolean, ignoring: %s", rvalue
);
4396 log_notice("%s is deprecated. Please use OnFailureJobMode= instead", lvalue
);
4398 *m
= r
? JOB_ISOLATE
: JOB_REPLACE
;
4402 int config_parse_exec_directories(
4404 const char *filename
,
4406 const char *section
,
4407 unsigned section_line
,
4415 const Unit
*u
= userdata
;
4423 if (isempty(rvalue
)) {
4424 /* Empty assignment resets the list */
4425 *rt
= strv_free(*rt
);
4429 for (const char *p
= rvalue
;;) {
4430 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
4432 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
4436 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4437 "Invalid syntax, ignoring: %s", rvalue
);
4443 r
= unit_full_printf(u
, word
, &k
);
4445 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4446 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
4450 r
= path_simplify_and_warn(k
, PATH_CHECK_RELATIVE
, unit
, filename
, line
, lvalue
);
4454 if (path_startswith(k
, "private")) {
4455 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4456 "%s= path can't be 'private', ignoring assignment: %s", lvalue
, word
);
4460 r
= strv_push(rt
, k
);
4467 int config_parse_set_credential(
4469 const char *filename
,
4471 const char *section
,
4472 unsigned section_line
,
4479 _cleanup_free_
char *word
= NULL
, *k
= NULL
, *unescaped
= NULL
;
4480 ExecContext
*context
= data
;
4481 ExecSetCredential
*old
;
4491 if (isempty(rvalue
)) {
4492 /* Empty assignment resets the list */
4493 context
->set_credentials
= hashmap_free(context
->set_credentials
);
4498 r
= extract_first_word(&p
, &word
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4502 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
4506 r
= unit_full_printf(u
, word
, &k
);
4508 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
4511 if (!credential_name_valid(k
)) {
4512 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Credential name \"%s\" not valid, ignoring.", k
);
4516 /* We support escape codes here, so that users can insert trailing \n if they like */
4517 l
= cunescape(p
, UNESCAPE_ACCEPT_NUL
, &unescaped
);
4519 log_syntax(unit
, LOG_WARNING
, filename
, line
, l
, "Can't unescape \"%s\", ignoring: %m", p
);
4523 old
= hashmap_get(context
->set_credentials
, k
);
4525 free_and_replace(old
->data
, unescaped
);
4528 _cleanup_(exec_set_credential_freep
) ExecSetCredential
*sc
= NULL
;
4530 sc
= new0(ExecSetCredential
, 1);
4534 sc
->id
= TAKE_PTR(k
);
4535 sc
->data
= TAKE_PTR(unescaped
);
4538 r
= hashmap_ensure_put(&context
->set_credentials
, &exec_set_credential_hash_ops
, sc
->id
, sc
);
4542 log_syntax(unit
, LOG_WARNING
, filename
, line
, l
,
4543 "Duplicated credential value '%s', ignoring assignment: %s", sc
->id
, rvalue
);
4553 int config_parse_load_credential(
4555 const char *filename
,
4557 const char *section
,
4558 unsigned section_line
,
4565 _cleanup_free_
char *word
= NULL
, *k
= NULL
, *q
= NULL
;
4566 ExecContext
*context
= data
;
4576 if (isempty(rvalue
)) {
4577 /* Empty assignment resets the list */
4578 context
->load_credentials
= strv_free(context
->load_credentials
);
4583 r
= extract_first_word(&p
, &word
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4587 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
4591 r
= unit_full_printf(u
, word
, &k
);
4593 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
4596 if (!credential_name_valid(k
)) {
4597 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Credential name \"%s\" not valid, ignoring.", k
);
4602 /* If only one field field is specified take it as shortcut for inheriting a credential named
4603 * the same way from our parent */
4608 r
= unit_full_printf(u
, p
, &q
);
4610 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", p
);
4613 if (path_is_absolute(q
) ? !path_is_normalized(q
) : !credential_name_valid(q
)) {
4614 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Credential source \"%s\" not valid, ignoring.", q
);
4619 r
= strv_consume_pair(&context
->load_credentials
, TAKE_PTR(k
), TAKE_PTR(q
));
4626 int config_parse_set_status(
4628 const char *filename
,
4630 const char *section
,
4631 unsigned section_line
,
4638 ExitStatusSet
*status_set
= data
;
4646 /* Empty assignment resets the list */
4647 if (isempty(rvalue
)) {
4648 exit_status_set_free(status_set
);
4652 for (const char *p
= rvalue
;;) {
4653 _cleanup_free_
char *word
= NULL
;
4656 r
= extract_first_word(&p
, &word
, NULL
, 0);
4660 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4661 "Failed to parse %s=%s, ignoring: %m", lvalue
, rvalue
);
4667 /* We need to call exit_status_from_string() first, because we want
4668 * to parse numbers as exit statuses, not signals. */
4670 r
= exit_status_from_string(word
);
4672 assert(r
>= 0 && r
< 256);
4673 bitmap
= &status_set
->status
;
4675 r
= signal_from_string(word
);
4677 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4678 "Failed to parse value, ignoring: %s", word
);
4681 bitmap
= &status_set
->signal
;
4684 r
= bitmap_set(bitmap
, r
);
4686 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4687 "Failed to set signal or status %s, ignoring: %m", word
);
4691 int config_parse_namespace_path_strv(
4693 const char *filename
,
4695 const char *section
,
4696 unsigned section_line
,
4703 const Unit
*u
= userdata
;
4712 if (isempty(rvalue
)) {
4713 /* Empty assignment resets the list */
4714 *sv
= strv_free(*sv
);
4718 for (const char *p
= rvalue
;;) {
4719 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
, *joined
= NULL
;
4721 bool ignore_enoent
= false, shall_prefix
= false;
4723 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
4727 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
4734 if (startswith(w
, "-")) {
4735 ignore_enoent
= true;
4738 if (startswith(w
, "+")) {
4739 shall_prefix
= true;
4743 r
= unit_full_printf(u
, w
, &resolved
);
4745 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", w
);
4749 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4753 joined
= strjoin(ignore_enoent
? "-" : "",
4754 shall_prefix
? "+" : "",
4757 r
= strv_push(sv
, joined
);
4767 int config_parse_temporary_filesystems(
4769 const char *filename
,
4771 const char *section
,
4772 unsigned section_line
,
4779 const Unit
*u
= userdata
;
4780 ExecContext
*c
= data
;
4788 if (isempty(rvalue
)) {
4789 /* Empty assignment resets the list */
4790 temporary_filesystem_free_many(c
->temporary_filesystems
, c
->n_temporary_filesystems
);
4791 c
->temporary_filesystems
= NULL
;
4792 c
->n_temporary_filesystems
= 0;
4796 for (const char *p
= rvalue
;;) {
4797 _cleanup_free_
char *word
= NULL
, *path
= NULL
, *resolved
= NULL
;
4800 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
4804 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
4811 r
= extract_first_word(&w
, &path
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4815 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", word
);
4819 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid syntax, ignoring: %s", word
);
4823 r
= unit_full_printf(u
, path
, &resolved
);
4825 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", path
);
4829 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4833 r
= temporary_filesystem_add(&c
->temporary_filesystems
, &c
->n_temporary_filesystems
, resolved
, w
);
4839 int config_parse_bind_paths(
4841 const char *filename
,
4843 const char *section
,
4844 unsigned section_line
,
4851 ExecContext
*c
= data
;
4852 const Unit
*u
= userdata
;
4860 if (isempty(rvalue
)) {
4861 /* Empty assignment resets the list */
4862 bind_mount_free_many(c
->bind_mounts
, c
->n_bind_mounts
);
4863 c
->bind_mounts
= NULL
;
4864 c
->n_bind_mounts
= 0;
4868 for (const char *p
= rvalue
;;) {
4869 _cleanup_free_
char *source
= NULL
, *destination
= NULL
;
4870 _cleanup_free_
char *sresolved
= NULL
, *dresolved
= NULL
;
4871 char *s
= NULL
, *d
= NULL
;
4872 bool rbind
= true, ignore_enoent
= false;
4874 r
= extract_first_word(&p
, &source
, ":" WHITESPACE
, EXTRACT_UNQUOTE
|EXTRACT_DONT_COALESCE_SEPARATORS
);
4878 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
4884 r
= unit_full_printf(u
, source
, &sresolved
);
4886 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4887 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", source
);
4893 ignore_enoent
= true;
4897 r
= path_simplify_and_warn(s
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4901 /* Optionally, the destination is specified. */
4902 if (p
&& p
[-1] == ':') {
4903 r
= extract_first_word(&p
, &destination
, ":" WHITESPACE
, EXTRACT_UNQUOTE
|EXTRACT_DONT_COALESCE_SEPARATORS
);
4907 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
4911 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Missing argument after ':', ignoring: %s", s
);
4915 r
= unit_full_printf(u
, destination
, &dresolved
);
4917 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4918 "Failed to resolve specifiers in \"%s\", ignoring: %m", destination
);
4922 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4928 /* Optionally, there's also a short option string specified */
4929 if (p
&& p
[-1] == ':') {
4930 _cleanup_free_
char *options
= NULL
;
4932 r
= extract_first_word(&p
, &options
, NULL
, EXTRACT_UNQUOTE
);
4936 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s: %s", lvalue
, rvalue
);
4940 if (isempty(options
) || streq(options
, "rbind"))
4942 else if (streq(options
, "norbind"))
4945 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid option string, ignoring setting: %s", options
);
4952 r
= bind_mount_add(&c
->bind_mounts
, &c
->n_bind_mounts
,
4956 .read_only
= !!strstr(lvalue
, "ReadOnly"),
4958 .ignore_enoent
= ignore_enoent
,
4967 int config_parse_mount_images(
4969 const char *filename
,
4971 const char *section
,
4972 unsigned section_line
,
4979 ExecContext
*c
= data
;
4980 const Unit
*u
= userdata
;
4988 if (isempty(rvalue
)) {
4989 /* Empty assignment resets the list */
4990 c
->mount_images
= mount_image_free_many(c
->mount_images
, &c
->n_mount_images
);
4994 for (const char *p
= rvalue
;;) {
4995 _cleanup_(mount_options_free_allp
) MountOptions
*options
= NULL
;
4996 _cleanup_free_
char *first
= NULL
, *second
= NULL
, *tuple
= NULL
;
4997 _cleanup_free_
char *sresolved
= NULL
, *dresolved
= NULL
;
4998 const char *q
= NULL
;
5000 bool permissive
= false;
5002 r
= extract_first_word(&p
, &tuple
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_RETAIN_ESCAPE
);
5006 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5007 "Invalid syntax %s=%s, ignoring: %m", lvalue
, rvalue
);
5014 r
= extract_many_words(&q
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
, &first
, &second
, NULL
);
5018 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5019 "Invalid syntax in %s=, ignoring: %s", lvalue
, tuple
);
5031 r
= unit_full_printf(u
, s
, &sresolved
);
5033 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5034 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", s
);
5038 r
= path_simplify_and_warn(sresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5042 if (isempty(second
)) {
5043 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Missing destination in %s, ignoring: %s", lvalue
, rvalue
);
5047 r
= unit_full_printf(u
, second
, &dresolved
);
5049 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5050 "Failed to resolve specifiers in \"%s\", ignoring: %m", second
);
5054 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5059 _cleanup_free_
char *partition
= NULL
, *mount_options
= NULL
, *mount_options_resolved
= NULL
;
5060 MountOptions
*o
= NULL
;
5061 PartitionDesignator partition_designator
;
5063 r
= extract_many_words(&q
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
, &partition
, &mount_options
, NULL
);
5067 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", q
);
5072 /* Single set of options, applying to the root partition/single filesystem */
5074 r
= unit_full_printf(u
, partition
, &mount_options_resolved
);
5076 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", first
);
5080 o
= new(MountOptions
, 1);
5083 *o
= (MountOptions
) {
5084 .partition_designator
= PARTITION_ROOT
,
5085 .options
= TAKE_PTR(mount_options_resolved
),
5087 LIST_APPEND(mount_options
, options
, o
);
5092 partition_designator
= partition_designator_from_string(partition
);
5093 if (partition_designator
< 0) {
5094 log_syntax(unit
, LOG_WARNING
, filename
, line
, partition_designator
,
5095 "Invalid partition name %s, ignoring", partition
);
5098 r
= unit_full_printf(u
, mount_options
, &mount_options_resolved
);
5100 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", mount_options
);
5104 o
= new(MountOptions
, 1);
5107 *o
= (MountOptions
) {
5108 .partition_designator
= partition_designator
,
5109 .options
= TAKE_PTR(mount_options_resolved
),
5111 LIST_APPEND(mount_options
, options
, o
);
5114 r
= mount_image_add(&c
->mount_images
, &c
->n_mount_images
,
5116 .source
= sresolved
,
5117 .destination
= dresolved
,
5118 .mount_options
= options
,
5119 .ignore_enoent
= permissive
,
5120 .type
= MOUNT_IMAGE_DISCRETE
,
5127 int config_parse_extension_images(
5129 const char *filename
,
5131 const char *section
,
5132 unsigned section_line
,
5139 ExecContext
*c
= data
;
5140 const Unit
*u
= userdata
;
5148 if (isempty(rvalue
)) {
5149 /* Empty assignment resets the list */
5150 c
->extension_images
= mount_image_free_many(c
->extension_images
, &c
->n_extension_images
);
5154 for (const char *p
= rvalue
;;) {
5155 _cleanup_free_
char *source
= NULL
, *tuple
= NULL
, *sresolved
= NULL
;
5156 _cleanup_(mount_options_free_allp
) MountOptions
*options
= NULL
;
5157 bool permissive
= false;
5158 const char *q
= NULL
;
5161 r
= extract_first_word(&p
, &tuple
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_RETAIN_ESCAPE
);
5165 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5166 "Invalid syntax %s=%s, ignoring: %m", lvalue
, rvalue
);
5173 r
= extract_first_word(&q
, &source
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
);
5177 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5178 "Invalid syntax in %s=, ignoring: %s", lvalue
, tuple
);
5190 r
= unit_full_printf(u
, s
, &sresolved
);
5192 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5193 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", s
);
5197 r
= path_simplify_and_warn(sresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5202 _cleanup_free_
char *partition
= NULL
, *mount_options
= NULL
, *mount_options_resolved
= NULL
;
5203 MountOptions
*o
= NULL
;
5204 PartitionDesignator partition_designator
;
5206 r
= extract_many_words(&q
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
, &partition
, &mount_options
, NULL
);
5210 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", q
);
5215 /* Single set of options, applying to the root partition/single filesystem */
5217 r
= unit_full_printf(u
, partition
, &mount_options_resolved
);
5219 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", partition
);
5223 o
= new(MountOptions
, 1);
5226 *o
= (MountOptions
) {
5227 .partition_designator
= PARTITION_ROOT
,
5228 .options
= TAKE_PTR(mount_options_resolved
),
5230 LIST_APPEND(mount_options
, options
, o
);
5235 partition_designator
= partition_designator_from_string(partition
);
5236 if (partition_designator
< 0) {
5237 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid partition name %s, ignoring", partition
);
5240 r
= unit_full_printf(u
, mount_options
, &mount_options_resolved
);
5242 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", mount_options
);
5246 o
= new(MountOptions
, 1);
5249 *o
= (MountOptions
) {
5250 .partition_designator
= partition_designator
,
5251 .options
= TAKE_PTR(mount_options_resolved
),
5253 LIST_APPEND(mount_options
, options
, o
);
5256 r
= mount_image_add(&c
->extension_images
, &c
->n_extension_images
,
5258 .source
= sresolved
,
5259 .mount_options
= options
,
5260 .ignore_enoent
= permissive
,
5261 .type
= MOUNT_IMAGE_EXTENSION
,
5268 int config_parse_job_timeout_sec(
5270 const char *filename
,
5272 const char *section
,
5273 unsigned section_line
,
5289 r
= parse_sec_fix_0(rvalue
, &usec
);
5291 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse JobTimeoutSec= parameter, ignoring: %s", rvalue
);
5295 /* If the user explicitly changed JobTimeoutSec= also change JobRunningTimeoutSec=, for compatibility with old
5296 * versions. If JobRunningTimeoutSec= was explicitly set, avoid this however as whatever the user picked should
5299 if (!u
->job_running_timeout_set
)
5300 u
->job_running_timeout
= usec
;
5302 u
->job_timeout
= usec
;
5307 int config_parse_job_running_timeout_sec(
5309 const char *filename
,
5311 const char *section
,
5312 unsigned section_line
,
5328 r
= parse_sec_fix_0(rvalue
, &usec
);
5330 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse JobRunningTimeoutSec= parameter, ignoring: %s", rvalue
);
5334 u
->job_running_timeout
= usec
;
5335 u
->job_running_timeout_set
= true;
5340 int config_parse_emergency_action(
5342 const char *filename
,
5344 const char *section
,
5345 unsigned section_line
,
5353 EmergencyAction
*x
= data
;
5362 m
= ((Unit
*) userdata
)->manager
;
5366 r
= parse_emergency_action(rvalue
, MANAGER_IS_SYSTEM(m
), x
);
5368 if (r
== -EOPNOTSUPP
&& MANAGER_IS_USER(m
)) {
5369 /* Compat mode: remove for systemd 241. */
5371 log_syntax(unit
, LOG_INFO
, filename
, line
, r
,
5372 "%s= in user mode specified as \"%s\", using \"exit-force\" instead.",
5374 *x
= EMERGENCY_ACTION_EXIT_FORCE
;
5378 if (r
== -EOPNOTSUPP
)
5379 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5380 "%s= specified as %s mode action, ignoring: %s",
5381 lvalue
, MANAGER_IS_SYSTEM(m
) ? "user" : "system", rvalue
);
5383 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5384 "Failed to parse %s=, ignoring: %s", lvalue
, rvalue
);
5391 int config_parse_pid_file(
5393 const char *filename
,
5395 const char *section
,
5396 unsigned section_line
,
5403 _cleanup_free_
char *k
= NULL
, *n
= NULL
;
5404 const Unit
*u
= userdata
;
5413 if (isempty(rvalue
)) {
5414 /* An empty assignment removes already set value. */
5419 r
= unit_full_printf(u
, rvalue
, &k
);
5421 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
5425 /* If this is a relative path make it absolute by prefixing the /run */
5426 n
= path_make_absolute(k
, u
->manager
->prefix
[EXEC_DIRECTORY_RUNTIME
]);
5430 /* Check that the result is a sensible path */
5431 r
= path_simplify_and_warn(n
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5435 r
= patch_var_run(unit
, filename
, line
, lvalue
, &n
);
5439 free_and_replace(*s
, n
);
5443 int config_parse_exit_status(
5445 const char *filename
,
5447 const char *section
,
5448 unsigned section_line
,
5455 int *exit_status
= data
, r
;
5461 assert(exit_status
);
5463 if (isempty(rvalue
)) {
5468 r
= safe_atou8(rvalue
, &u
);
5470 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse exit status '%s', ignoring: %m", rvalue
);
5478 int config_parse_disable_controllers(
5480 const char *filename
,
5482 const char *section
,
5483 unsigned section_line
,
5491 CGroupContext
*c
= data
;
5492 CGroupMask disabled_mask
;
5494 /* 1. If empty, make all controllers eligible for use again.
5495 * 2. If non-empty, merge all listed controllers, space separated. */
5497 if (isempty(rvalue
)) {
5498 c
->disable_controllers
= 0;
5502 r
= cg_mask_from_string(rvalue
, &disabled_mask
);
5503 if (r
< 0 || disabled_mask
<= 0) {
5504 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid cgroup string: %s, ignoring", rvalue
);
5508 c
->disable_controllers
|= disabled_mask
;
5513 int config_parse_ip_filter_bpf_progs(
5515 const char *filename
,
5517 const char *section
,
5518 unsigned section_line
,
5525 _cleanup_free_
char *resolved
= NULL
;
5526 const Unit
*u
= userdata
;
5527 char ***paths
= data
;
5535 if (isempty(rvalue
)) {
5536 *paths
= strv_free(*paths
);
5540 r
= unit_full_printf(u
, rvalue
, &resolved
);
5542 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
5546 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5550 if (strv_contains(*paths
, resolved
))
5553 r
= strv_extend(paths
, resolved
);
5557 r
= bpf_firewall_supported();
5560 if (r
!= BPF_FIREWALL_SUPPORTED_WITH_MULTI
) {
5561 static bool warned
= false;
5563 log_full(warned
? LOG_DEBUG
: LOG_WARNING
,
5564 "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"
5565 "Starting this unit will fail! (This warning is only shown for the first loaded unit using IP firewalling.)", filename
, line
, lvalue
, rvalue
);
5573 int config_parse_bpf_foreign_program(
5575 const char *filename
,
5577 const char *section
,
5578 unsigned section_line
,
5584 _cleanup_free_
char *resolved
= NULL
, *word
= NULL
;
5585 CGroupContext
*c
= data
;
5593 if (isempty(rvalue
)) {
5594 while (c
->bpf_foreign_programs
)
5595 cgroup_context_remove_bpf_foreign_program(c
, c
->bpf_foreign_programs
);
5600 r
= extract_first_word(&rvalue
, &word
, ":", 0);
5603 if (r
<= 0 || isempty(rvalue
)) {
5604 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse foreign BPF program, ignoring: %s", rvalue
);
5608 attach_type
= bpf_cgroup_attach_type_from_string(word
);
5609 if (attach_type
< 0) {
5610 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Unknown BPF attach type=%s, ignoring: %s", word
, rvalue
);
5614 r
= unit_full_printf(u
, rvalue
, &resolved
);
5616 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
5620 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5624 r
= cgroup_add_bpf_foreign_program(c
, attach_type
, resolved
);
5626 return log_error_errno(r
, "Failed to add foreign BPF program to cgroup context: %m");
5631 int config_parse_cgroup_socket_bind(
5633 const char *filename
,
5635 const char *section
,
5636 unsigned section_line
,
5642 _cleanup_free_ CGroupSocketBindItem
*item
= NULL
;
5643 const char *user_port
;
5644 uint16_t nr_ports
= 0, port_min
= 0;
5645 CGroupSocketBindItem
**head
= data
;
5646 _cleanup_free_
char *word
= NULL
;
5649 if (isempty(rvalue
)) {
5650 cgroup_context_remove_socket_bind(head
);
5654 r
= extract_first_word(&rvalue
, &word
, ":", 0);
5658 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5659 "Unable to parse %s= assignment, ignoring: %s", lvalue
, rvalue
);
5664 if (streq(word
, "IPv4"))
5666 else if (streq(word
, "IPv6"))
5669 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
5670 "Only IPv4 and IPv6 protocols are supported, ignoring.");
5680 if (!streq(user_port
, "any")) {
5683 r
= parse_ip_port_range(user_port
, &port_min
, &port_max
);
5687 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5688 "Invalid port or port range, ignoring: %m");
5692 nr_ports
= 1 + port_max
- port_min
;
5695 item
= new(CGroupSocketBindItem
, 1);
5698 *item
= (CGroupSocketBindItem
) {
5699 .address_family
= af
,
5700 .nr_ports
= nr_ports
,
5701 .port_min
= port_min
,
5704 LIST_PREPEND(socket_bind_items
, *head
, TAKE_PTR(item
));
5709 static int merge_by_names(Unit
**u
, Set
*names
, const char *id
) {
5716 /* Let's try to add in all names that are aliases of this unit */
5717 while ((k
= set_steal_first(names
))) {
5718 _cleanup_free_ _unused_
char *free_k
= k
;
5720 /* First try to merge in the other name into our unit */
5721 r
= unit_merge_by_name(*u
, k
);
5725 /* Hmm, we couldn't merge the other unit into ours? Then let's try it the other way
5728 other
= manager_get_unit((*u
)->manager
, k
);
5730 return r
; /* return previous failure */
5732 r
= unit_merge(other
, *u
);
5737 return merge_by_names(u
, names
, NULL
);
5740 if (streq_ptr(id
, k
))
5741 unit_choose_id(*u
, id
);
5747 int unit_load_fragment(Unit
*u
) {
5748 const char *fragment
;
5749 _cleanup_set_free_free_ Set
*names
= NULL
;
5753 assert(u
->load_state
== UNIT_STUB
);
5757 u
->load_state
= UNIT_LOADED
;
5761 /* Possibly rebuild the fragment map to catch new units */
5762 r
= unit_file_build_name_map(&u
->manager
->lookup_paths
,
5763 &u
->manager
->unit_cache_timestamp_hash
,
5764 &u
->manager
->unit_id_map
,
5765 &u
->manager
->unit_name_map
,
5766 &u
->manager
->unit_path_cache
);
5768 return log_error_errno(r
, "Failed to rebuild name map: %m");
5770 r
= unit_file_find_fragment(u
->manager
->unit_id_map
,
5771 u
->manager
->unit_name_map
,
5775 if (r
< 0 && r
!= -ENOENT
)
5779 /* Open the file, check if this is a mask, otherwise read. */
5780 _cleanup_fclose_
FILE *f
= NULL
;
5783 /* Try to open the file name. A symlink is OK, for example for linked files or masks. We
5784 * expect that all symlinks within the lookup paths have been already resolved, but we don't
5785 * verify this here. */
5786 f
= fopen(fragment
, "re");
5788 return log_unit_notice_errno(u
, errno
, "Failed to open %s: %m", fragment
);
5790 if (fstat(fileno(f
), &st
) < 0)
5793 r
= free_and_strdup(&u
->fragment_path
, fragment
);
5797 if (null_or_empty(&st
)) {
5798 /* Unit file is masked */
5800 u
->load_state
= u
->perpetual
? UNIT_LOADED
: UNIT_MASKED
; /* don't allow perpetual units to ever be masked */
5801 u
->fragment_mtime
= 0;
5803 u
->load_state
= UNIT_LOADED
;
5804 u
->fragment_mtime
= timespec_load(&st
.st_mtim
);
5806 /* Now, parse the file contents */
5807 r
= config_parse(u
->id
, fragment
, f
,
5808 UNIT_VTABLE(u
)->sections
,
5809 config_item_perf_lookup
, load_fragment_gperf_lookup
,
5814 log_unit_notice_errno(u
, r
, "Unit configuration has fatal error, unit will not be started.");
5820 /* Call merge_by_names with the name derived from the fragment path as the preferred name.
5822 * We do the merge dance here because for some unit types, the unit might have aliases which are not
5823 * declared in the file system. In particular, this is true (and frequent) for device and swap units.
5825 const char *id
= u
->id
;
5826 _cleanup_free_
char *free_id
= NULL
;
5829 id
= basename(fragment
);
5830 if (unit_name_is_valid(id
, UNIT_NAME_TEMPLATE
)) {
5831 assert(u
->instance
); /* If we're not trying to use a template for non-instanced unit,
5832 * this must be set. */
5834 r
= unit_name_replace_instance(id
, u
->instance
, &free_id
);
5836 return log_debug_errno(r
, "Failed to build id (%s + %s): %m", id
, u
->instance
);
5842 r
= merge_by_names(&merged
, names
, id
);
5847 u
->load_state
= UNIT_MERGED
;
5852 void unit_dump_config_items(FILE *f
) {
5853 static const struct {
5854 const ConfigParserCallback callback
;
5857 { config_parse_warn_compat
, "NOTSUPPORTED" },
5858 { config_parse_int
, "INTEGER" },
5859 { config_parse_unsigned
, "UNSIGNED" },
5860 { config_parse_iec_size
, "SIZE" },
5861 { config_parse_iec_uint64
, "SIZE" },
5862 { config_parse_si_uint64
, "SIZE" },
5863 { config_parse_bool
, "BOOLEAN" },
5864 { config_parse_string
, "STRING" },
5865 { config_parse_path
, "PATH" },
5866 { config_parse_unit_path_printf
, "PATH" },
5867 { config_parse_strv
, "STRING [...]" },
5868 { config_parse_exec_nice
, "NICE" },
5869 { config_parse_exec_oom_score_adjust
, "OOMSCOREADJUST" },
5870 { config_parse_exec_io_class
, "IOCLASS" },
5871 { config_parse_exec_io_priority
, "IOPRIORITY" },
5872 { config_parse_exec_cpu_sched_policy
, "CPUSCHEDPOLICY" },
5873 { config_parse_exec_cpu_sched_prio
, "CPUSCHEDPRIO" },
5874 { config_parse_exec_cpu_affinity
, "CPUAFFINITY" },
5875 { config_parse_mode
, "MODE" },
5876 { config_parse_unit_env_file
, "FILE" },
5877 { config_parse_exec_output
, "OUTPUT" },
5878 { config_parse_exec_input
, "INPUT" },
5879 { config_parse_log_facility
, "FACILITY" },
5880 { config_parse_log_level
, "LEVEL" },
5881 { config_parse_exec_secure_bits
, "SECUREBITS" },
5882 { config_parse_capability_set
, "BOUNDINGSET" },
5883 { config_parse_rlimit
, "LIMIT" },
5884 { config_parse_unit_deps
, "UNIT [...]" },
5885 { config_parse_exec
, "PATH [ARGUMENT [...]]" },
5886 { config_parse_service_type
, "SERVICETYPE" },
5887 { config_parse_service_exit_type
, "SERVICEEXITTYPE" },
5888 { config_parse_service_restart
, "SERVICERESTART" },
5889 { config_parse_service_timeout_failure_mode
, "TIMEOUTMODE" },
5890 { config_parse_kill_mode
, "KILLMODE" },
5891 { config_parse_signal
, "SIGNAL" },
5892 { config_parse_socket_listen
, "SOCKET [...]" },
5893 { config_parse_socket_bind
, "SOCKETBIND" },
5894 { config_parse_socket_bindtodevice
, "NETWORKINTERFACE" },
5895 { config_parse_sec
, "SECONDS" },
5896 { config_parse_nsec
, "NANOSECONDS" },
5897 { config_parse_namespace_path_strv
, "PATH [...]" },
5898 { config_parse_bind_paths
, "PATH[:PATH[:OPTIONS]] [...]" },
5899 { config_parse_unit_requires_mounts_for
, "PATH [...]" },
5900 { config_parse_exec_mount_flags
, "MOUNTFLAG [...]" },
5901 { config_parse_unit_string_printf
, "STRING" },
5902 { config_parse_trigger_unit
, "UNIT" },
5903 { config_parse_timer
, "TIMER" },
5904 { config_parse_path_spec
, "PATH" },
5905 { config_parse_notify_access
, "ACCESS" },
5906 { config_parse_ip_tos
, "TOS" },
5907 { config_parse_unit_condition_path
, "CONDITION" },
5908 { config_parse_unit_condition_string
, "CONDITION" },
5909 { config_parse_unit_slice
, "SLICE" },
5910 { config_parse_documentation
, "URL" },
5911 { config_parse_service_timeout
, "SECONDS" },
5912 { config_parse_emergency_action
, "ACTION" },
5913 { config_parse_set_status
, "STATUS" },
5914 { config_parse_service_sockets
, "SOCKETS" },
5915 { config_parse_environ
, "ENVIRON" },
5917 { config_parse_syscall_filter
, "SYSCALLS" },
5918 { config_parse_syscall_archs
, "ARCHS" },
5919 { config_parse_syscall_errno
, "ERRNO" },
5920 { config_parse_syscall_log
, "SYSCALLS" },
5921 { config_parse_address_families
, "FAMILIES" },
5922 { config_parse_restrict_namespaces
, "NAMESPACES" },
5924 { config_parse_cpu_shares
, "SHARES" },
5925 { config_parse_cg_weight
, "WEIGHT" },
5926 { config_parse_memory_limit
, "LIMIT" },
5927 { config_parse_device_allow
, "DEVICE" },
5928 { config_parse_device_policy
, "POLICY" },
5929 { config_parse_io_limit
, "LIMIT" },
5930 { config_parse_io_device_weight
, "DEVICEWEIGHT" },
5931 { config_parse_io_device_latency
, "DEVICELATENCY" },
5932 { config_parse_blockio_bandwidth
, "BANDWIDTH" },
5933 { config_parse_blockio_weight
, "WEIGHT" },
5934 { config_parse_blockio_device_weight
, "DEVICEWEIGHT" },
5935 { config_parse_long
, "LONG" },
5936 { config_parse_socket_service
, "SERVICE" },
5938 { config_parse_exec_selinux_context
, "LABEL" },
5940 { config_parse_job_mode
, "MODE" },
5941 { config_parse_job_mode_isolate
, "BOOLEAN" },
5942 { config_parse_personality
, "PERSONALITY" },
5945 const char *prev
= NULL
;
5950 NULSTR_FOREACH(i
, load_fragment_gperf_nulstr
) {
5951 const char *rvalue
= "OTHER", *lvalue
;
5952 const ConfigPerfItem
*p
;
5955 assert_se(p
= load_fragment_gperf_lookup(i
, strlen(i
)));
5957 /* Hide legacy settings */
5958 if (p
->parse
== config_parse_warn_compat
&&
5959 p
->ltype
== DISABLED_LEGACY
)
5962 for (size_t j
= 0; j
< ELEMENTSOF(table
); j
++)
5963 if (p
->parse
== table
[j
].callback
) {
5964 rvalue
= table
[j
].rvalue
;
5968 dot
= strchr(i
, '.');
5969 lvalue
= dot
? dot
+ 1 : i
;
5972 size_t prefix_len
= dot
- i
;
5974 if (!prev
|| !strneq(prev
, i
, prefix_len
+1)) {
5978 fprintf(f
, "[%.*s]\n", (int) prefix_len
, i
);
5982 fprintf(f
, "%s=%s\n", lvalue
, rvalue
);
5987 int config_parse_cpu_affinity2(
5989 const char *filename
,
5991 const char *section
,
5992 unsigned section_line
,
5999 CPUSet
*affinity
= data
;
6003 (void) parse_cpu_set_extend(rvalue
, affinity
, true, unit
, filename
, line
, lvalue
);
6008 int config_parse_show_status(
6010 const char *filename
,
6012 const char *section
,
6013 unsigned section_line
,
6021 ShowStatus
*b
= data
;
6028 k
= parse_show_status(rvalue
, b
);
6030 log_syntax(unit
, LOG_WARNING
, filename
, line
, k
, "Failed to parse show status setting, ignoring: %s", rvalue
);
6035 int config_parse_output_restricted(
6037 const char *filename
,
6039 const char *section
,
6040 unsigned section_line
,
6047 ExecOutput t
, *eo
= data
;
6048 bool obsolete
= false;
6055 if (streq(rvalue
, "syslog")) {
6056 t
= EXEC_OUTPUT_JOURNAL
;
6058 } else if (streq(rvalue
, "syslog+console")) {
6059 t
= EXEC_OUTPUT_JOURNAL_AND_CONSOLE
;
6062 t
= exec_output_from_string(rvalue
);
6064 log_syntax(unit
, LOG_WARNING
, filename
, line
, t
, "Failed to parse output type, ignoring: %s", rvalue
);
6068 if (IN_SET(t
, EXEC_OUTPUT_SOCKET
, EXEC_OUTPUT_NAMED_FD
, EXEC_OUTPUT_FILE
, EXEC_OUTPUT_FILE_APPEND
, EXEC_OUTPUT_FILE_TRUNCATE
)) {
6069 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Standard output types socket, fd:, file:, append:, truncate: are not supported as defaults, ignoring: %s", rvalue
);
6075 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
6076 "Standard output type %s is obsolete, automatically updating to %s. Please update your configuration.",
6077 rvalue
, exec_output_to_string(t
));
6083 int config_parse_crash_chvt(
6085 const char *filename
,
6087 const char *section
,
6088 unsigned section_line
,
6102 r
= parse_crash_chvt(rvalue
, data
);
6104 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse CrashChangeVT= setting, ignoring: %s", rvalue
);
6109 int config_parse_swap_priority(
6111 const char *filename
,
6113 const char *section
,
6114 unsigned section_line
,
6130 if (isempty(rvalue
)) {
6131 s
->parameters_fragment
.priority
= -1;
6132 s
->parameters_fragment
.priority_set
= false;
6136 r
= safe_atoi(rvalue
, &priority
);
6138 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid swap priority '%s', ignoring.", rvalue
);
6142 if (priority
< -1) {
6143 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
);
6147 if (priority
> 32767) {
6148 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Swap priority out of range, ignoring: %s", rvalue
);
6152 s
->parameters_fragment
.priority
= priority
;
6153 s
->parameters_fragment
.priority_set
= true;