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 "alloc-util.h"
20 #include "all-units.h"
21 #include "bpf-firewall.h"
22 #include "bus-error.h"
23 #include "bus-internal.h"
26 #include "capability-util.h"
27 #include "cgroup-setup.h"
28 #include "conf-parser.h"
29 #include "core-varlink.h"
30 #include "cpu-set-util.h"
32 #include "errno-list.h"
37 #include "hexdecoct.h"
40 #include "ip-protocol-list.h"
41 #include "journal-file.h"
42 #include "limits-util.h"
43 #include "load-fragment.h"
45 #include "mountpoint-util.h"
46 #include "nulstr-util.h"
47 #include "parse-util.h"
48 #include "path-util.h"
49 #include "percent-util.h"
50 #include "process-util.h"
52 #include "seccomp-util.h"
54 #include "securebits-util.h"
55 #include "signal-util.h"
56 #include "socket-netlink.h"
57 #include "stat-util.h"
58 #include "string-util.h"
60 #include "syslog-util.h"
61 #include "time-util.h"
62 #include "unit-name.h"
63 #include "unit-printf.h"
64 #include "user-util.h"
68 static int parse_socket_protocol(const char *s
) {
71 r
= parse_ip_protocol(s
);
74 if (!IN_SET(r
, IPPROTO_UDPLITE
, IPPROTO_SCTP
))
75 return -EPROTONOSUPPORT
;
80 int parse_crash_chvt(const char *value
, int *data
) {
83 if (safe_atoi(value
, data
) >= 0)
86 b
= parse_boolean(value
);
91 *data
= 0; /* switch to where kmsg goes */
93 *data
= -1; /* turn off switching */
98 int parse_confirm_spawn(const char *value
, char **console
) {
102 r
= value
? parse_boolean(value
) : 1;
106 } else if (r
> 0) /* on with default tty */
107 s
= strdup("/dev/console");
108 else if (is_path(value
)) /* on with fully qualified path */
110 else /* on with only a tty file name, not a fully qualified path */
111 s
= path_join("/dev/", value
);
119 DEFINE_CONFIG_PARSE(config_parse_socket_protocol
, parse_socket_protocol
, "Failed to parse socket protocol");
120 DEFINE_CONFIG_PARSE(config_parse_exec_secure_bits
, secure_bits_from_string
, "Failed to parse secure bits");
121 DEFINE_CONFIG_PARSE_ENUM(config_parse_collect_mode
, collect_mode
, CollectMode
, "Failed to parse garbage collection mode");
122 DEFINE_CONFIG_PARSE_ENUM(config_parse_device_policy
, cgroup_device_policy
, CGroupDevicePolicy
, "Failed to parse device policy");
123 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_keyring_mode
, exec_keyring_mode
, ExecKeyringMode
, "Failed to parse keyring mode");
124 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_proc
, protect_proc
, ProtectProc
, "Failed to parse /proc/ protection mode");
125 DEFINE_CONFIG_PARSE_ENUM(config_parse_proc_subset
, proc_subset
, ProcSubset
, "Failed to parse /proc/ subset mode");
126 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_utmp_mode
, exec_utmp_mode
, ExecUtmpMode
, "Failed to parse utmp mode");
127 DEFINE_CONFIG_PARSE_ENUM(config_parse_job_mode
, job_mode
, JobMode
, "Failed to parse job mode");
128 DEFINE_CONFIG_PARSE_ENUM(config_parse_notify_access
, notify_access
, NotifyAccess
, "Failed to parse notify access specifier");
129 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_home
, protect_home
, ProtectHome
, "Failed to parse protect home value");
130 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_system
, protect_system
, ProtectSystem
, "Failed to parse protect system value");
131 DEFINE_CONFIG_PARSE_ENUM(config_parse_runtime_preserve_mode
, exec_preserve_mode
, ExecPreserveMode
, "Failed to parse runtime directory preserve mode");
132 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_type
, service_type
, ServiceType
, "Failed to parse service type");
133 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart
, service_restart
, ServiceRestart
, "Failed to parse service restart specifier");
134 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_timeout_failure_mode
, service_timeout_failure_mode
, ServiceTimeoutFailureMode
, "Failed to parse timeout failure mode");
135 DEFINE_CONFIG_PARSE_ENUM(config_parse_socket_bind
, socket_address_bind_ipv6_only_or_bool
, SocketAddressBindIPv6Only
, "Failed to parse bind IPv6 only value");
136 DEFINE_CONFIG_PARSE_ENUM(config_parse_oom_policy
, oom_policy
, OOMPolicy
, "Failed to parse OOM policy");
137 DEFINE_CONFIG_PARSE_ENUM(config_parse_managed_oom_preference
, managed_oom_preference
, ManagedOOMPreference
, "Failed to parse ManagedOOMPreference=");
138 DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_ip_tos
, ip_tos
, int, -1, "Failed to parse IP TOS value");
139 DEFINE_CONFIG_PARSE_PTR(config_parse_blockio_weight
, cg_blkio_weight_parse
, uint64_t, "Invalid block IO weight");
140 DEFINE_CONFIG_PARSE_PTR(config_parse_cg_weight
, cg_weight_parse
, uint64_t, "Invalid weight");
141 DEFINE_CONFIG_PARSE_PTR(config_parse_cpu_shares
, cg_cpu_shares_parse
, uint64_t, "Invalid CPU shares");
142 DEFINE_CONFIG_PARSE_PTR(config_parse_exec_mount_flags
, mount_propagation_flags_from_string
, unsigned long, "Failed to parse mount flag");
143 DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_numa_policy
, mpol
, int, -1, "Invalid NUMA policy type");
144 DEFINE_CONFIG_PARSE_ENUM(config_parse_status_unit_format
, status_unit_format
, StatusUnitFormat
, "Failed to parse status unit format");
145 DEFINE_CONFIG_PARSE_ENUM_FULL(config_parse_socket_timestamping
, socket_timestamping_from_string_harder
, SocketTimestamping
, "Failed to parse timestamping precision");
147 int config_parse_unit_deps(
149 const char *filename
,
152 unsigned section_line
,
159 UnitDependency d
= ltype
;
166 for (const char *p
= rvalue
;;) {
167 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
170 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_RETAIN_ESCAPE
);
176 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
180 r
= unit_name_printf(u
, word
, &k
);
182 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
186 r
= unit_add_dependency_by_name(u
, d
, k
, true, UNIT_DEPENDENCY_FILE
);
188 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
192 int config_parse_obsolete_unit_deps(
194 const char *filename
,
197 unsigned section_line
,
204 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
205 "Unit dependency type %s= is obsolete, replacing by %s=, please update your unit file", lvalue
, unit_dependency_to_string(ltype
));
207 return config_parse_unit_deps(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
);
210 int config_parse_unit_string_printf(
212 const char *filename
,
215 unsigned section_line
,
222 _cleanup_free_
char *k
= NULL
;
223 const Unit
*u
= userdata
;
231 r
= unit_full_printf(u
, rvalue
, &k
);
233 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
237 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
240 int config_parse_unit_strv_printf(
242 const char *filename
,
245 unsigned section_line
,
252 const Unit
*u
= userdata
;
253 _cleanup_free_
char *k
= NULL
;
261 r
= unit_full_printf(u
, rvalue
, &k
);
263 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
267 return config_parse_strv(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
270 int config_parse_unit_path_printf(
272 const char *filename
,
275 unsigned section_line
,
282 _cleanup_free_
char *k
= NULL
;
283 const Unit
*u
= userdata
;
292 /* Let's not bother with anything that is too long */
293 if (strlen(rvalue
) >= PATH_MAX
) {
294 log_syntax(unit
, fatal
? LOG_ERR
: LOG_WARNING
, filename
, line
, 0,
295 "%s value too long%s.",
296 lvalue
, fatal
? "" : ", ignoring");
297 return fatal
? -ENAMETOOLONG
: 0;
300 r
= unit_full_printf(u
, rvalue
, &k
);
302 log_syntax(unit
, fatal
? LOG_ERR
: LOG_WARNING
, filename
, line
, r
,
303 "Failed to resolve unit specifiers in '%s'%s: %m",
304 rvalue
, fatal
? "" : ", ignoring");
305 return fatal
? -ENOEXEC
: 0;
308 return config_parse_path(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
311 int config_parse_unit_path_strv_printf(
313 const char *filename
,
316 unsigned section_line
,
324 const Unit
*u
= userdata
;
332 if (isempty(rvalue
)) {
337 for (const char *p
= rvalue
;;) {
338 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
340 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
346 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
347 "Invalid syntax, ignoring: %s", rvalue
);
351 r
= unit_full_printf(u
, word
, &k
);
353 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
354 "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
358 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
362 r
= strv_consume(x
, TAKE_PTR(k
));
368 static int patch_var_run(
370 const char *filename
,
378 e
= path_startswith(*path
, "/var/run/");
382 z
= path_join("/run/", e
);
386 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
387 "%s= references a path below legacy directory /var/run/, updating %s → %s; "
388 "please update the unit file accordingly.", lvalue
, *path
, z
);
390 free_and_replace(*path
, z
);
395 int config_parse_socket_listen(
397 const char *filename
,
400 unsigned section_line
,
407 _cleanup_free_ SocketPort
*p
= NULL
;
419 if (isempty(rvalue
)) {
420 /* An empty assignment removes all ports */
421 socket_free_ports(s
);
425 p
= new0(SocketPort
, 1);
429 if (ltype
!= SOCKET_SOCKET
) {
430 _cleanup_free_
char *k
= NULL
;
432 r
= unit_full_printf(UNIT(s
), rvalue
, &k
);
434 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
438 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
442 if (ltype
== SOCKET_FIFO
) {
443 r
= patch_var_run(unit
, filename
, line
, lvalue
, &k
);
448 free_and_replace(p
->path
, k
);
451 } else if (streq(lvalue
, "ListenNetlink")) {
452 _cleanup_free_
char *k
= NULL
;
454 r
= unit_full_printf(UNIT(s
), rvalue
, &k
);
456 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
460 r
= socket_address_parse_netlink(&p
->address
, k
);
462 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse address value in '%s', ignoring: %m", k
);
466 p
->type
= SOCKET_SOCKET
;
469 _cleanup_free_
char *k
= NULL
;
471 r
= unit_full_printf(UNIT(s
), rvalue
, &k
);
473 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
477 if (k
[0] == '/') { /* Only for AF_UNIX file system sockets… */
478 r
= patch_var_run(unit
, filename
, line
, lvalue
, &k
);
483 r
= socket_address_parse_and_warn(&p
->address
, k
);
485 if (r
!= -EAFNOSUPPORT
)
486 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse address value in '%s', ignoring: %m", k
);
490 if (streq(lvalue
, "ListenStream"))
491 p
->address
.type
= SOCK_STREAM
;
492 else if (streq(lvalue
, "ListenDatagram"))
493 p
->address
.type
= SOCK_DGRAM
;
495 assert(streq(lvalue
, "ListenSequentialPacket"));
496 p
->address
.type
= SOCK_SEQPACKET
;
499 if (socket_address_family(&p
->address
) != AF_LOCAL
&& p
->address
.type
== SOCK_SEQPACKET
) {
500 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Address family not supported, ignoring: %s", rvalue
);
504 p
->type
= SOCKET_SOCKET
;
508 p
->auxiliary_fds
= NULL
;
509 p
->n_auxiliary_fds
= 0;
512 LIST_FIND_TAIL(port
, s
->ports
, tail
);
513 LIST_INSERT_AFTER(port
, s
->ports
, tail
, p
);
520 int config_parse_exec_nice(
522 const char *filename
,
525 unsigned section_line
,
532 ExecContext
*c
= data
;
540 if (isempty(rvalue
)) {
545 r
= parse_nice(rvalue
, &priority
);
548 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Nice priority out of range, ignoring: %s", rvalue
);
550 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse nice priority '%s', ignoring: %m", rvalue
);
560 int config_parse_exec_oom_score_adjust(
562 const char *filename
,
565 unsigned section_line
,
572 ExecContext
*c
= data
;
580 if (isempty(rvalue
)) {
581 c
->oom_score_adjust_set
= false;
585 r
= parse_oom_score_adjust(rvalue
, &oa
);
588 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "OOM score adjust value out of range, ignoring: %s", rvalue
);
590 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse the OOM score adjust value '%s', ignoring: %m", rvalue
);
594 c
->oom_score_adjust
= oa
;
595 c
->oom_score_adjust_set
= true;
600 int config_parse_exec_coredump_filter(
602 const char *filename
,
605 unsigned section_line
,
612 ExecContext
*c
= data
;
620 if (isempty(rvalue
)) {
621 c
->coredump_filter
= 0;
622 c
->coredump_filter_set
= false;
627 r
= coredump_filter_mask_from_string(rvalue
, &f
);
629 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
630 "Failed to parse the CoredumpFilter=%s, ignoring: %m", rvalue
);
634 c
->coredump_filter
|= f
;
635 c
->oom_score_adjust_set
= true;
639 int config_parse_kill_mode(
641 const char *filename
,
644 unsigned section_line
,
651 KillMode
*k
= data
, m
;
658 if (isempty(rvalue
)) {
659 *k
= KILL_CONTROL_GROUP
;
663 m
= kill_mode_from_string(rvalue
);
665 log_syntax(unit
, LOG_WARNING
, filename
, line
, m
,
666 "Failed to parse kill mode specification, ignoring: %s", rvalue
);
671 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
672 "Unit configured to use KillMode=none. "
673 "This is unsafe, as it disables systemd's process lifecycle management for the service. "
674 "Please update your service to use a safer KillMode=, such as 'mixed' or 'control-group'. "
675 "Support for KillMode=none is deprecated and will eventually be removed.");
681 int config_parse_exec(
683 const char *filename
,
686 unsigned section_line
,
693 ExecCommand
**e
= data
;
694 const Unit
*u
= userdata
;
706 if (isempty(rvalue
)) {
707 /* An empty assignment resets the list */
708 *e
= exec_command_free_list(*e
);
714 _cleanup_free_
char *path
= NULL
, *firstword
= NULL
;
715 ExecCommandFlags flags
= 0;
716 bool ignore
= false, separate_argv0
= false;
717 _cleanup_free_ ExecCommand
*nce
= NULL
;
718 _cleanup_strv_free_
char **n
= NULL
;
719 size_t nlen
= 0, nbufsize
= 0;
724 r
= extract_first_word_and_warn(&p
, &firstword
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
728 /* A lone ";" is a separator. Let's make sure we don't treat it as an executable name. */
729 if (streq(firstword
, ";")) {
736 /* We accept an absolute path as first argument. If it's prefixed with - and the path doesn't
737 * exist, we ignore it instead of erroring out; if it's prefixed with @, we allow overriding of
738 * argv[0]; if it's prefixed with :, we will not do environment variable substitution;
739 * if it's prefixed with +, it will be run with full privileges and no sandboxing; if
740 * it's prefixed with '!' we apply sandboxing, but do not change user/group credentials; if
741 * it's prefixed with '!!', then we apply user/group credentials if the kernel supports ambient
742 * capabilities -- if it doesn't we don't apply the credentials themselves, but do apply most
743 * other sandboxing, with some special exceptions for changing UID.
745 * The idea is that '!!' may be used to write services that can take benefit of systemd's
746 * UID/GID dropping if the kernel supports ambient creds, but provide an automatic fallback to
747 * privilege dropping within the daemon if the kernel does not offer that. */
749 if (*f
== '-' && !(flags
& EXEC_COMMAND_IGNORE_FAILURE
)) {
750 flags
|= EXEC_COMMAND_IGNORE_FAILURE
;
752 } else if (*f
== '@' && !separate_argv0
)
753 separate_argv0
= true;
754 else if (*f
== ':' && !(flags
& EXEC_COMMAND_NO_ENV_EXPAND
))
755 flags
|= EXEC_COMMAND_NO_ENV_EXPAND
;
756 else if (*f
== '+' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
757 flags
|= EXEC_COMMAND_FULLY_PRIVILEGED
;
758 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
759 flags
|= EXEC_COMMAND_NO_SETUID
;
760 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_AMBIENT_MAGIC
))) {
761 flags
&= ~EXEC_COMMAND_NO_SETUID
;
762 flags
|= EXEC_COMMAND_AMBIENT_MAGIC
;
768 r
= unit_full_printf(u
, f
, &path
);
770 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
771 "Failed to resolve unit specifiers in '%s'%s: %m",
772 f
, ignore
? ", ignoring" : "");
773 return ignore
? 0 : -ENOEXEC
;
777 /* First word is either "-" or "@" with no command. */
778 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
779 "Empty path in command line%s: '%s'",
780 ignore
? ", ignoring" : "", rvalue
);
781 return ignore
? 0 : -ENOEXEC
;
783 if (!string_is_safe(path
)) {
784 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
785 "Executable name contains special characters%s: %s",
786 ignore
? ", ignoring" : "", path
);
787 return ignore
? 0 : -ENOEXEC
;
789 if (endswith(path
, "/")) {
790 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
791 "Executable path specifies a directory%s: %s",
792 ignore
? ", ignoring" : "", path
);
793 return ignore
? 0 : -ENOEXEC
;
796 if (!path_is_absolute(path
) && !filename_is_valid(path
)) {
797 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
798 "Neither a valid executable name nor an absolute path%s: %s",
799 ignore
? ", ignoring" : "", path
);
800 return ignore
? 0 : -ENOEXEC
;
803 if (!separate_argv0
) {
806 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
816 path_simplify(path
, false);
818 while (!isempty(p
)) {
819 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
821 /* Check explicitly for an unquoted semicolon as
822 * command separator token. */
823 if (p
[0] == ';' && (!p
[1] || strchr(WHITESPACE
, p
[1]))) {
825 p
+= strspn(p
, WHITESPACE
);
830 /* Check for \; explicitly, to not confuse it with \\; or "\;" or "\\;" etc.
831 * extract_first_word() would return the same for all of those. */
832 if (p
[0] == '\\' && p
[1] == ';' && (!p
[2] || strchr(WHITESPACE
, p
[2]))) {
836 p
+= strspn(p
, WHITESPACE
);
838 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
849 r
= extract_first_word_and_warn(&p
, &word
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
853 return ignore
? 0 : -ENOEXEC
;
855 r
= unit_full_printf(u
, word
, &resolved
);
857 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
858 "Failed to resolve unit specifiers in %s%s: %m",
859 word
, ignore
? ", ignoring" : "");
860 return ignore
? 0 : -ENOEXEC
;
863 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
866 n
[nlen
++] = TAKE_PTR(resolved
);
871 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
872 "Empty executable name or zeroeth argument%s: %s",
873 ignore
? ", ignoring" : "", rvalue
);
874 return ignore
? 0 : -ENOEXEC
;
877 nce
= new0(ExecCommand
, 1);
881 nce
->argv
= TAKE_PTR(n
);
882 nce
->path
= TAKE_PTR(path
);
885 exec_command_append_list(e
, nce
);
887 /* Do not _cleanup_free_ these. */
896 int config_parse_socket_bindtodevice(
898 const char *filename
,
901 unsigned section_line
,
915 if (isempty(rvalue
) || streq(rvalue
, "*")) {
916 s
->bind_to_device
= mfree(s
->bind_to_device
);
920 if (!ifname_valid(rvalue
)) {
921 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid interface name, ignoring: %s", rvalue
);
925 return free_and_strdup_warn(&s
->bind_to_device
, rvalue
);
928 int config_parse_exec_input(
930 const char *filename
,
933 unsigned section_line
,
940 ExecContext
*c
= data
;
941 const Unit
*u
= userdata
;
951 n
= startswith(rvalue
, "fd:");
953 _cleanup_free_
char *resolved
= NULL
;
955 r
= unit_full_printf(u
, n
, &resolved
);
957 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", n
);
961 if (isempty(resolved
))
962 resolved
= mfree(resolved
);
963 else if (!fdname_is_valid(resolved
)) {
964 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", resolved
);
968 free_and_replace(c
->stdio_fdname
[STDIN_FILENO
], resolved
);
970 ei
= EXEC_INPUT_NAMED_FD
;
972 } else if ((n
= startswith(rvalue
, "file:"))) {
973 _cleanup_free_
char *resolved
= NULL
;
975 r
= unit_full_printf(u
, n
, &resolved
);
977 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", n
);
981 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
985 free_and_replace(c
->stdio_file
[STDIN_FILENO
], resolved
);
987 ei
= EXEC_INPUT_FILE
;
990 ei
= exec_input_from_string(rvalue
);
992 log_syntax(unit
, LOG_WARNING
, filename
, line
, ei
, "Failed to parse input specifier, ignoring: %s", rvalue
);
1001 int config_parse_exec_input_text(
1003 const char *filename
,
1005 const char *section
,
1006 unsigned section_line
,
1013 _cleanup_free_
char *unescaped
= NULL
, *resolved
= NULL
;
1014 ExecContext
*c
= data
;
1015 const Unit
*u
= userdata
;
1025 if (isempty(rvalue
)) {
1026 /* Reset if the empty string is assigned */
1027 c
->stdin_data
= mfree(c
->stdin_data
);
1028 c
->stdin_data_size
= 0;
1032 r
= cunescape(rvalue
, 0, &unescaped
);
1034 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1035 "Failed to decode C escaped text '%s', ignoring: %m", rvalue
);
1039 r
= unit_full_printf(u
, unescaped
, &resolved
);
1041 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1042 "Failed to resolve unit specifiers in '%s', ignoring: %m", unescaped
);
1046 sz
= strlen(resolved
);
1047 if (c
->stdin_data_size
+ sz
+ 1 < c
->stdin_data_size
|| /* check for overflow */
1048 c
->stdin_data_size
+ sz
+ 1 > EXEC_STDIN_DATA_MAX
) {
1049 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
1050 "Standard input data too large (%zu), maximum of %zu permitted, ignoring.",
1051 c
->stdin_data_size
+ sz
, (size_t) EXEC_STDIN_DATA_MAX
);
1055 p
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
+ 1);
1059 *((char*) mempcpy((char*) p
+ c
->stdin_data_size
, resolved
, sz
)) = '\n';
1062 c
->stdin_data_size
+= sz
+ 1;
1067 int config_parse_exec_input_data(
1069 const char *filename
,
1071 const char *section
,
1072 unsigned section_line
,
1079 _cleanup_free_
void *p
= NULL
;
1080 ExecContext
*c
= data
;
1090 if (isempty(rvalue
)) {
1091 /* Reset if the empty string is assigned */
1092 c
->stdin_data
= mfree(c
->stdin_data
);
1093 c
->stdin_data_size
= 0;
1097 r
= unbase64mem(rvalue
, SIZE_MAX
, &p
, &sz
);
1099 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1100 "Failed to decode base64 data, ignoring: %s", rvalue
);
1106 if (c
->stdin_data_size
+ sz
< c
->stdin_data_size
|| /* check for overflow */
1107 c
->stdin_data_size
+ sz
> EXEC_STDIN_DATA_MAX
) {
1108 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
1109 "Standard input data too large (%zu), maximum of %zu permitted, ignoring.",
1110 c
->stdin_data_size
+ sz
, (size_t) EXEC_STDIN_DATA_MAX
);
1114 q
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
);
1118 memcpy((uint8_t*) q
+ c
->stdin_data_size
, p
, sz
);
1121 c
->stdin_data_size
+= sz
;
1126 int config_parse_exec_output(
1128 const char *filename
,
1130 const char *section
,
1131 unsigned section_line
,
1138 _cleanup_free_
char *resolved
= NULL
;
1140 ExecContext
*c
= data
;
1141 const Unit
*u
= userdata
;
1142 bool obsolete
= false;
1152 n
= startswith(rvalue
, "fd:");
1154 r
= unit_full_printf(u
, n
, &resolved
);
1156 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", n
);
1160 if (isempty(resolved
))
1161 resolved
= mfree(resolved
);
1162 else if (!fdname_is_valid(resolved
)) {
1163 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", resolved
);
1167 eo
= EXEC_OUTPUT_NAMED_FD
;
1169 } else if (streq(rvalue
, "syslog")) {
1170 eo
= EXEC_OUTPUT_JOURNAL
;
1173 } else if (streq(rvalue
, "syslog+console")) {
1174 eo
= EXEC_OUTPUT_JOURNAL_AND_CONSOLE
;
1177 } else if ((n
= startswith(rvalue
, "file:"))) {
1179 r
= unit_full_printf(u
, n
, &resolved
);
1181 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", n
);
1185 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1189 eo
= EXEC_OUTPUT_FILE
;
1191 } else if ((n
= startswith(rvalue
, "append:"))) {
1193 r
= unit_full_printf(u
, n
, &resolved
);
1195 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", n
);
1199 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1203 eo
= EXEC_OUTPUT_FILE_APPEND
;
1205 } else if ((n
= startswith(rvalue
, "truncate:"))) {
1207 r
= unit_full_printf(u
, n
, &resolved
);
1209 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", n
);
1213 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1217 eo
= EXEC_OUTPUT_FILE_TRUNCATE
;
1219 eo
= exec_output_from_string(rvalue
);
1221 log_syntax(unit
, LOG_WARNING
, filename
, line
, eo
, "Failed to parse output specifier, ignoring: %s", rvalue
);
1227 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
1228 "Standard output type %s is obsolete, automatically updating to %s. Please update your unit file, and consider removing the setting altogether.",
1229 rvalue
, exec_output_to_string(eo
));
1231 if (streq(lvalue
, "StandardOutput")) {
1232 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1233 free_and_replace(c
->stdio_fdname
[STDOUT_FILENO
], resolved
);
1235 free_and_replace(c
->stdio_file
[STDOUT_FILENO
], resolved
);
1240 assert(streq(lvalue
, "StandardError"));
1242 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1243 free_and_replace(c
->stdio_fdname
[STDERR_FILENO
], resolved
);
1245 free_and_replace(c
->stdio_file
[STDERR_FILENO
], resolved
);
1253 int config_parse_exec_io_class(const char *unit
,
1254 const char *filename
,
1256 const char *section
,
1257 unsigned section_line
,
1264 ExecContext
*c
= data
;
1272 if (isempty(rvalue
)) {
1273 c
->ioprio_set
= false;
1274 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE
, 0);
1278 x
= ioprio_class_from_string(rvalue
);
1280 log_syntax(unit
, LOG_WARNING
, filename
, line
, x
, "Failed to parse IO scheduling class, ignoring: %s", rvalue
);
1284 c
->ioprio
= IOPRIO_PRIO_VALUE(x
, IOPRIO_PRIO_DATA(c
->ioprio
));
1285 c
->ioprio_set
= true;
1290 int config_parse_exec_io_priority(const char *unit
,
1291 const char *filename
,
1293 const char *section
,
1294 unsigned section_line
,
1301 ExecContext
*c
= data
;
1309 if (isempty(rvalue
)) {
1310 c
->ioprio_set
= false;
1311 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE
, 0);
1315 r
= ioprio_parse_priority(rvalue
, &i
);
1317 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse IO priority, ignoring: %s", rvalue
);
1321 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_PRIO_CLASS(c
->ioprio
), i
);
1322 c
->ioprio_set
= true;
1327 int config_parse_exec_cpu_sched_policy(const char *unit
,
1328 const char *filename
,
1330 const char *section
,
1331 unsigned section_line
,
1338 ExecContext
*c
= data
;
1346 if (isempty(rvalue
)) {
1347 c
->cpu_sched_set
= false;
1348 c
->cpu_sched_policy
= SCHED_OTHER
;
1349 c
->cpu_sched_priority
= 0;
1353 x
= sched_policy_from_string(rvalue
);
1355 log_syntax(unit
, LOG_WARNING
, filename
, line
, x
, "Failed to parse CPU scheduling policy, ignoring: %s", rvalue
);
1359 c
->cpu_sched_policy
= x
;
1360 /* Moving to or from real-time policy? We need to adjust the priority */
1361 c
->cpu_sched_priority
= CLAMP(c
->cpu_sched_priority
, sched_get_priority_min(x
), sched_get_priority_max(x
));
1362 c
->cpu_sched_set
= true;
1367 int config_parse_exec_mount_apivfs(const char *unit
,
1368 const char *filename
,
1370 const char *section
,
1371 unsigned section_line
,
1378 ExecContext
*c
= data
;
1386 if (isempty(rvalue
)) {
1387 c
->mount_apivfs_set
= false;
1388 c
->mount_apivfs
= false;
1392 k
= parse_boolean(rvalue
);
1394 log_syntax(unit
, LOG_WARNING
, filename
, line
, k
,
1395 "Failed to parse boolean value, ignoring: %s",
1400 c
->mount_apivfs_set
= true;
1401 c
->mount_apivfs
= k
;
1405 int config_parse_numa_mask(const char *unit
,
1406 const char *filename
,
1408 const char *section
,
1409 unsigned section_line
,
1416 NUMAPolicy
*p
= data
;
1423 if (streq(rvalue
, "all")) {
1424 r
= numa_mask_add_all(&p
->nodes
);
1426 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1427 "Failed to create NUMA mask representing \"all\" NUMA nodes, ignoring: %m");
1429 r
= parse_cpu_set_extend(rvalue
, &p
->nodes
, true, unit
, filename
, line
, lvalue
);
1431 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse NUMA node mask, ignoring: %s", rvalue
);
1437 int config_parse_exec_cpu_sched_prio(const char *unit
,
1438 const char *filename
,
1440 const char *section
,
1441 unsigned section_line
,
1448 ExecContext
*c
= data
;
1456 r
= safe_atoi(rvalue
, &i
);
1458 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse CPU scheduling priority, ignoring: %s", rvalue
);
1462 /* On Linux RR/FIFO range from 1 to 99 and OTHER/BATCH may only be 0 */
1463 min
= sched_get_priority_min(c
->cpu_sched_policy
);
1464 max
= sched_get_priority_max(c
->cpu_sched_policy
);
1466 if (i
< min
|| i
> max
) {
1467 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "CPU scheduling priority is out of range, ignoring: %s", rvalue
);
1471 c
->cpu_sched_priority
= i
;
1472 c
->cpu_sched_set
= true;
1477 int config_parse_root_image_options(
1479 const char *filename
,
1481 const char *section
,
1482 unsigned section_line
,
1489 _cleanup_(mount_options_free_allp
) MountOptions
*options
= NULL
;
1490 _cleanup_strv_free_
char **l
= NULL
;
1491 char **first
= NULL
, **second
= NULL
;
1492 ExecContext
*c
= data
;
1493 const Unit
*u
= userdata
;
1501 if (isempty(rvalue
)) {
1502 c
->root_image_options
= mount_options_free_all(c
->root_image_options
);
1506 r
= strv_split_colon_pairs(&l
, rvalue
);
1510 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
1514 STRV_FOREACH_PAIR(first
, second
, l
) {
1515 MountOptions
*o
= NULL
;
1516 _cleanup_free_
char *mount_options_resolved
= NULL
;
1517 const char *mount_options
= NULL
, *partition
= "root";
1518 PartitionDesignator partition_designator
;
1520 /* Format is either 'root:foo' or 'foo' (root is implied) */
1521 if (!isempty(*second
)) {
1523 mount_options
= *second
;
1525 mount_options
= *first
;
1527 partition_designator
= partition_designator_from_string(partition
);
1528 if (partition_designator
< 0) {
1529 log_syntax(unit
, LOG_WARNING
, filename
, line
, partition_designator
,
1530 "Invalid partition name %s, ignoring", partition
);
1533 r
= unit_full_printf(u
, mount_options
, &mount_options_resolved
);
1535 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", mount_options
);
1539 o
= new(MountOptions
, 1);
1542 *o
= (MountOptions
) {
1543 .partition_designator
= partition_designator
,
1544 .options
= TAKE_PTR(mount_options_resolved
),
1546 LIST_APPEND(mount_options
, options
, TAKE_PTR(o
));
1549 /* empty spaces/separators only */
1550 if (LIST_IS_EMPTY(options
))
1551 c
->root_image_options
= mount_options_free_all(c
->root_image_options
);
1553 LIST_JOIN(mount_options
, c
->root_image_options
, options
);
1558 int config_parse_exec_root_hash(
1560 const char *filename
,
1562 const char *section
,
1563 unsigned section_line
,
1570 _cleanup_free_
void *roothash_decoded
= NULL
;
1571 ExecContext
*c
= data
;
1572 size_t roothash_decoded_size
= 0;
1580 if (isempty(rvalue
)) {
1581 /* Reset if the empty string is assigned */
1582 c
->root_hash_path
= mfree(c
->root_hash_path
);
1583 c
->root_hash
= mfree(c
->root_hash
);
1584 c
->root_hash_size
= 0;
1588 if (path_is_absolute(rvalue
)) {
1589 /* We have the path to a roothash to load and decode, eg: RootHash=/foo/bar.roothash */
1590 _cleanup_free_
char *p
= NULL
;
1596 free_and_replace(c
->root_hash_path
, p
);
1597 c
->root_hash
= mfree(c
->root_hash
);
1598 c
->root_hash_size
= 0;
1602 /* We have a roothash to decode, eg: RootHash=012345789abcdef */
1603 r
= unhexmem(rvalue
, strlen(rvalue
), &roothash_decoded
, &roothash_decoded_size
);
1605 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to decode RootHash=, ignoring: %s", rvalue
);
1608 if (roothash_decoded_size
< sizeof(sd_id128_t
)) {
1609 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "RootHash= is too short, ignoring: %s", rvalue
);
1613 free_and_replace(c
->root_hash
, roothash_decoded
);
1614 c
->root_hash_size
= roothash_decoded_size
;
1615 c
->root_hash_path
= mfree(c
->root_hash_path
);
1620 int config_parse_exec_root_hash_sig(
1622 const char *filename
,
1624 const char *section
,
1625 unsigned section_line
,
1632 _cleanup_free_
void *roothash_sig_decoded
= NULL
;
1634 ExecContext
*c
= data
;
1635 size_t roothash_sig_decoded_size
= 0;
1643 if (isempty(rvalue
)) {
1644 /* Reset if the empty string is assigned */
1645 c
->root_hash_sig_path
= mfree(c
->root_hash_sig_path
);
1646 c
->root_hash_sig
= mfree(c
->root_hash_sig
);
1647 c
->root_hash_sig_size
= 0;
1651 if (path_is_absolute(rvalue
)) {
1652 /* We have the path to a roothash signature to load and decode, eg: RootHashSignature=/foo/bar.roothash.p7s */
1653 _cleanup_free_
char *p
= NULL
;
1659 free_and_replace(c
->root_hash_sig_path
, p
);
1660 c
->root_hash_sig
= mfree(c
->root_hash_sig
);
1661 c
->root_hash_sig_size
= 0;
1665 if (!(value
= startswith(rvalue
, "base64:"))) {
1666 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
1667 "Failed to decode RootHashSignature=, not a path but doesn't start with 'base64:', ignoring: %s", rvalue
);
1671 /* We have a roothash signature to decode, eg: RootHashSignature=base64:012345789abcdef */
1672 r
= unbase64mem(value
, strlen(value
), &roothash_sig_decoded
, &roothash_sig_decoded_size
);
1674 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to decode RootHashSignature=, ignoring: %s", rvalue
);
1678 free_and_replace(c
->root_hash_sig
, roothash_sig_decoded
);
1679 c
->root_hash_sig_size
= roothash_sig_decoded_size
;
1680 c
->root_hash_sig_path
= mfree(c
->root_hash_sig_path
);
1685 int config_parse_exec_cpu_affinity(
1687 const char *filename
,
1689 const char *section
,
1690 unsigned section_line
,
1697 ExecContext
*c
= data
;
1705 if (streq(rvalue
, "numa")) {
1706 c
->cpu_affinity_from_numa
= true;
1707 cpu_set_reset(&c
->cpu_set
);
1712 r
= parse_cpu_set_extend(rvalue
, &c
->cpu_set
, true, unit
, filename
, line
, lvalue
);
1714 c
->cpu_affinity_from_numa
= false;
1719 int config_parse_capability_set(
1721 const char *filename
,
1723 const char *section
,
1724 unsigned section_line
,
1731 uint64_t *capability_set
= data
;
1732 uint64_t sum
= 0, initial
= 0;
1733 bool invert
= false;
1741 if (rvalue
[0] == '~') {
1746 if (streq(lvalue
, "CapabilityBoundingSet"))
1747 initial
= CAP_ALL
; /* initialized to all bits on */
1748 /* else "AmbientCapabilities" initialized to all bits off */
1750 r
= capability_set_from_string(rvalue
, &sum
);
1752 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= specifier '%s', ignoring: %m", lvalue
, rvalue
);
1756 if (sum
== 0 || *capability_set
== initial
)
1757 /* "", "~" or uninitialized data -> replace */
1758 *capability_set
= invert
? ~sum
: sum
;
1760 /* previous data -> merge */
1762 *capability_set
&= ~sum
;
1764 *capability_set
|= sum
;
1770 int config_parse_exec_selinux_context(
1772 const char *filename
,
1774 const char *section
,
1775 unsigned section_line
,
1782 ExecContext
*c
= data
;
1783 const Unit
*u
= userdata
;
1793 if (isempty(rvalue
)) {
1794 c
->selinux_context
= mfree(c
->selinux_context
);
1795 c
->selinux_context_ignore
= false;
1799 if (rvalue
[0] == '-') {
1805 r
= unit_full_printf(u
, rvalue
, &k
);
1807 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
1808 "Failed to resolve unit specifiers in '%s'%s: %m",
1809 rvalue
, ignore
? ", ignoring" : "");
1810 return ignore
? 0 : -ENOEXEC
;
1813 free_and_replace(c
->selinux_context
, k
);
1814 c
->selinux_context_ignore
= ignore
;
1819 int config_parse_exec_apparmor_profile(
1821 const char *filename
,
1823 const char *section
,
1824 unsigned section_line
,
1831 ExecContext
*c
= data
;
1832 const Unit
*u
= userdata
;
1842 if (isempty(rvalue
)) {
1843 c
->apparmor_profile
= mfree(c
->apparmor_profile
);
1844 c
->apparmor_profile_ignore
= false;
1848 if (rvalue
[0] == '-') {
1854 r
= unit_full_printf(u
, rvalue
, &k
);
1856 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
1857 "Failed to resolve unit specifiers in '%s'%s: %m",
1858 rvalue
, ignore
? ", ignoring" : "");
1859 return ignore
? 0 : -ENOEXEC
;
1862 free_and_replace(c
->apparmor_profile
, k
);
1863 c
->apparmor_profile_ignore
= ignore
;
1868 int config_parse_exec_smack_process_label(
1870 const char *filename
,
1872 const char *section
,
1873 unsigned section_line
,
1880 ExecContext
*c
= data
;
1881 const Unit
*u
= userdata
;
1891 if (isempty(rvalue
)) {
1892 c
->smack_process_label
= mfree(c
->smack_process_label
);
1893 c
->smack_process_label_ignore
= false;
1897 if (rvalue
[0] == '-') {
1903 r
= unit_full_printf(u
, rvalue
, &k
);
1905 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
1906 "Failed to resolve unit specifiers in '%s'%s: %m",
1907 rvalue
, ignore
? ", ignoring" : "");
1908 return ignore
? 0 : -ENOEXEC
;
1911 free_and_replace(c
->smack_process_label
, k
);
1912 c
->smack_process_label_ignore
= ignore
;
1917 int config_parse_timer(
1919 const char *filename
,
1921 const char *section
,
1922 unsigned section_line
,
1929 _cleanup_(calendar_spec_freep
) CalendarSpec
*c
= NULL
;
1930 _cleanup_free_
char *k
= NULL
;
1931 const Unit
*u
= userdata
;
1942 if (isempty(rvalue
)) {
1943 /* Empty assignment resets list */
1944 timer_free_values(t
);
1948 r
= unit_full_printf(u
, rvalue
, &k
);
1950 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
1954 if (ltype
== TIMER_CALENDAR
) {
1955 r
= calendar_spec_from_string(k
, &c
);
1957 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse calendar specification, ignoring: %s", k
);
1961 r
= parse_sec(k
, &usec
);
1963 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse timer value, ignoring: %s", k
);
1968 v
= new(TimerValue
, 1);
1975 .calendar_spec
= TAKE_PTR(c
),
1978 LIST_PREPEND(value
, t
->values
, v
);
1983 int config_parse_trigger_unit(
1985 const char *filename
,
1987 const char *section
,
1988 unsigned section_line
,
1995 _cleanup_free_
char *p
= NULL
;
2005 if (!hashmap_isempty(u
->dependencies
[UNIT_TRIGGERS
])) {
2006 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Multiple units to trigger specified, ignoring: %s", rvalue
);
2010 r
= unit_name_printf(u
, rvalue
, &p
);
2012 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2016 type
= unit_name_to_type(p
);
2018 log_syntax(unit
, LOG_WARNING
, filename
, line
, type
, "Unit type not valid, ignoring: %s", rvalue
);
2021 if (unit_has_name(u
, p
)) {
2022 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Units cannot trigger themselves, ignoring: %s", rvalue
);
2026 r
= unit_add_two_dependencies_by_name(u
, UNIT_BEFORE
, UNIT_TRIGGERS
, p
, true, UNIT_DEPENDENCY_FILE
);
2028 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add trigger on %s, ignoring: %m", p
);
2035 int config_parse_path_spec(const char *unit
,
2036 const char *filename
,
2038 const char *section
,
2039 unsigned section_line
,
2049 _cleanup_free_
char *k
= NULL
;
2057 if (isempty(rvalue
)) {
2058 /* Empty assignment clears list */
2063 b
= path_type_from_string(lvalue
);
2065 log_syntax(unit
, LOG_WARNING
, filename
, line
, b
, "Failed to parse path type, ignoring: %s", lvalue
);
2069 r
= unit_full_printf(UNIT(p
), rvalue
, &k
);
2071 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2075 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2079 s
= new0(PathSpec
, 1);
2084 s
->path
= TAKE_PTR(k
);
2088 LIST_PREPEND(spec
, p
->specs
, s
);
2093 int config_parse_socket_service(
2095 const char *filename
,
2097 const char *section
,
2098 unsigned section_line
,
2105 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
2106 _cleanup_free_
char *p
= NULL
;
2116 r
= unit_name_printf(UNIT(s
), rvalue
, &p
);
2118 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2122 if (!endswith(p
, ".service")) {
2123 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Unit must be of type service, ignoring: %s", rvalue
);
2127 r
= manager_load_unit(UNIT(s
)->manager
, p
, NULL
, &error
, &x
);
2129 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to load unit %s, ignoring: %s", rvalue
, bus_error_message(&error
, r
));
2133 unit_ref_set(&s
->service
, UNIT(s
), x
);
2138 int config_parse_fdname(
2140 const char *filename
,
2142 const char *section
,
2143 unsigned section_line
,
2150 _cleanup_free_
char *p
= NULL
;
2159 if (isempty(rvalue
)) {
2160 s
->fdname
= mfree(s
->fdname
);
2164 r
= unit_full_printf(UNIT(s
), rvalue
, &p
);
2166 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2170 if (!fdname_is_valid(p
)) {
2171 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", p
);
2175 return free_and_replace(s
->fdname
, p
);
2178 int config_parse_service_sockets(
2180 const char *filename
,
2182 const char *section
,
2183 unsigned section_line
,
2198 for (const char *p
= rvalue
;;) {
2199 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2201 r
= extract_first_word(&p
, &word
, NULL
, 0);
2207 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Trailing garbage in sockets, ignoring: %s", rvalue
);
2211 r
= unit_name_printf(UNIT(s
), word
, &k
);
2213 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
2217 if (!endswith(k
, ".socket")) {
2218 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Unit must be of type socket, ignoring: %s", k
);
2222 r
= unit_add_two_dependencies_by_name(UNIT(s
), UNIT_WANTS
, UNIT_AFTER
, k
, true, UNIT_DEPENDENCY_FILE
);
2224 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
2226 r
= unit_add_dependency_by_name(UNIT(s
), UNIT_TRIGGERED_BY
, k
, true, UNIT_DEPENDENCY_FILE
);
2228 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
2232 int config_parse_bus_name(
2234 const char *filename
,
2236 const char *section
,
2237 unsigned section_line
,
2244 _cleanup_free_
char *k
= NULL
;
2245 const Unit
*u
= userdata
;
2253 r
= unit_full_printf(u
, rvalue
, &k
);
2255 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2259 if (!sd_bus_service_name_is_valid(k
)) {
2260 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid bus name, ignoring: %s", k
);
2264 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
2267 int config_parse_service_timeout(
2269 const char *filename
,
2271 const char *section
,
2272 unsigned section_line
,
2279 Service
*s
= userdata
;
2288 /* This is called for two cases: TimeoutSec= and TimeoutStartSec=. */
2290 /* Traditionally, these options accepted 0 to disable the timeouts. However, a timeout of 0 suggests it happens
2291 * immediately, hence fix this to become USEC_INFINITY instead. This is in-line with how we internally handle
2292 * all other timeouts. */
2293 r
= parse_sec_fix_0(rvalue
, &usec
);
2295 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
2299 s
->start_timeout_defined
= true;
2300 s
->timeout_start_usec
= usec
;
2302 if (streq(lvalue
, "TimeoutSec"))
2303 s
->timeout_stop_usec
= usec
;
2308 int config_parse_timeout_abort(
2310 const char *filename
,
2312 const char *section
,
2313 unsigned section_line
,
2328 /* Note: apart from setting the arg, this returns an extra bit of information in the return value. */
2330 if (isempty(rvalue
)) {
2332 return 0; /* "not set" */
2335 r
= parse_sec(rvalue
, ret
);
2337 return log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= setting, ignoring: %s", lvalue
, rvalue
);
2339 return 1; /* "set" */
2342 int config_parse_service_timeout_abort(
2344 const char *filename
,
2346 const char *section
,
2347 unsigned section_line
,
2354 Service
*s
= userdata
;
2359 r
= config_parse_timeout_abort(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
,
2360 &s
->timeout_abort_usec
, s
);
2362 s
->timeout_abort_set
= r
;
2366 int config_parse_sec_fix_0(
2368 const char *filename
,
2370 const char *section
,
2371 unsigned section_line
,
2378 usec_t
*usec
= data
;
2386 /* This is pretty much like config_parse_sec(), except that this treats a time of 0 as infinity, for
2387 * compatibility with older versions of systemd where 0 instead of infinity was used as indicator to turn off a
2390 r
= parse_sec_fix_0(rvalue
, usec
);
2392 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
2397 int config_parse_user_group_compat(
2399 const char *filename
,
2401 const char *section
,
2402 unsigned section_line
,
2409 _cleanup_free_
char *k
= NULL
;
2411 const Unit
*u
= userdata
;
2419 if (isempty(rvalue
)) {
2420 *user
= mfree(*user
);
2424 r
= unit_full_printf(u
, rvalue
, &k
);
2426 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", rvalue
);
2430 if (!valid_user_group_name(k
, VALID_USER_ALLOW_NUMERIC
|VALID_USER_RELAX
|VALID_USER_WARN
)) {
2431 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2435 if (strstr(lvalue
, "User") && streq(k
, NOBODY_USER_NAME
))
2436 log_struct(LOG_NOTICE
,
2437 "MESSAGE=%s:%u: Special user %s configured, this is not safe!", filename
, line
, k
,
2439 "MESSAGE_ID=" SD_MESSAGE_NOBODY_USER_UNSUITABLE_STR
,
2440 "OFFENDING_USER=%s", k
,
2441 "CONFIG_FILE=%s", filename
,
2442 "CONFIG_LINE=%u", line
);
2444 return free_and_replace(*user
, k
);
2447 int config_parse_user_group_strv_compat(
2449 const char *filename
,
2451 const char *section
,
2452 unsigned section_line
,
2459 char ***users
= data
;
2460 const Unit
*u
= userdata
;
2468 if (isempty(rvalue
)) {
2469 *users
= strv_free(*users
);
2473 for (const char *p
= rvalue
;;) {
2474 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2476 r
= extract_first_word(&p
, &word
, NULL
, 0);
2482 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax: %s", rvalue
);
2486 r
= unit_full_printf(u
, word
, &k
);
2488 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", word
);
2492 if (!valid_user_group_name(k
, VALID_USER_ALLOW_NUMERIC
|VALID_USER_RELAX
|VALID_USER_WARN
)) {
2493 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2497 r
= strv_push(users
, k
);
2505 int config_parse_working_directory(
2507 const char *filename
,
2509 const char *section
,
2510 unsigned section_line
,
2517 ExecContext
*c
= data
;
2518 const Unit
*u
= userdata
;
2528 if (isempty(rvalue
)) {
2529 c
->working_directory_home
= false;
2530 c
->working_directory
= mfree(c
->working_directory
);
2534 if (rvalue
[0] == '-') {
2540 if (streq(rvalue
, "~")) {
2541 c
->working_directory_home
= true;
2542 c
->working_directory
= mfree(c
->working_directory
);
2544 _cleanup_free_
char *k
= NULL
;
2546 r
= unit_full_printf(u
, rvalue
, &k
);
2548 log_syntax(unit
, missing_ok
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
2549 "Failed to resolve unit specifiers in working directory path '%s'%s: %m",
2550 rvalue
, missing_ok
? ", ignoring" : "");
2551 return missing_ok
? 0 : -ENOEXEC
;
2554 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
| (missing_ok
? 0 : PATH_CHECK_FATAL
), unit
, filename
, line
, lvalue
);
2556 return missing_ok
? 0 : -ENOEXEC
;
2558 c
->working_directory_home
= false;
2559 free_and_replace(c
->working_directory
, k
);
2562 c
->working_directory_missing_ok
= missing_ok
;
2566 int config_parse_unit_env_file(const char *unit
,
2567 const char *filename
,
2569 const char *section
,
2570 unsigned section_line
,
2578 const Unit
*u
= userdata
;
2579 _cleanup_free_
char *n
= NULL
;
2587 if (isempty(rvalue
)) {
2588 /* Empty assignment frees the list */
2589 *env
= strv_free(*env
);
2593 r
= unit_full_printf(u
, rvalue
, &n
);
2595 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2599 r
= path_simplify_and_warn(n
[0] == '-' ? n
+ 1 : n
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2603 r
= strv_push(env
, n
);
2612 int config_parse_environ(
2614 const char *filename
,
2616 const char *section
,
2617 unsigned section_line
,
2624 const Unit
*u
= userdata
;
2633 if (isempty(rvalue
)) {
2634 /* Empty assignment resets the list */
2635 *env
= strv_free(*env
);
2639 for (const char *p
= rvalue
;; ) {
2640 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
2642 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2648 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2649 "Invalid syntax, ignoring: %s", rvalue
);
2654 r
= unit_full_printf(u
, word
, &resolved
);
2656 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2657 "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2661 resolved
= TAKE_PTR(word
);
2663 if (!env_assignment_is_valid(resolved
)) {
2664 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
2665 "Invalid environment assignment, ignoring: %s", resolved
);
2669 r
= strv_env_replace_consume(env
, TAKE_PTR(resolved
));
2671 return log_error_errno(r
, "Failed to update environment: %m");
2675 int config_parse_pass_environ(
2677 const char *filename
,
2679 const char *section
,
2680 unsigned section_line
,
2687 _cleanup_strv_free_
char **n
= NULL
;
2688 size_t nlen
= 0, nbufsize
= 0;
2689 char*** passenv
= data
;
2690 const Unit
*u
= userdata
;
2698 if (isempty(rvalue
)) {
2699 /* Empty assignment resets the list */
2700 *passenv
= strv_free(*passenv
);
2704 for (const char *p
= rvalue
;;) {
2705 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2707 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
2713 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2714 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2719 r
= unit_full_printf(u
, word
, &k
);
2721 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2722 "Failed to resolve specifiers in %s, ignoring: %m", word
);
2728 if (!env_name_is_valid(k
)) {
2729 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
2730 "Invalid environment name for %s, ignoring: %s", lvalue
, k
);
2734 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
2737 n
[nlen
++] = TAKE_PTR(k
);
2742 r
= strv_extend_strv(passenv
, n
, true);
2750 int config_parse_unset_environ(
2752 const char *filename
,
2754 const char *section
,
2755 unsigned section_line
,
2762 _cleanup_strv_free_
char **n
= NULL
;
2763 size_t nlen
= 0, nbufsize
= 0;
2764 char*** unsetenv
= data
;
2765 const Unit
*u
= userdata
;
2773 if (isempty(rvalue
)) {
2774 /* Empty assignment resets the list */
2775 *unsetenv
= strv_free(*unsetenv
);
2779 for (const char *p
= rvalue
;;) {
2780 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2782 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2788 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2789 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2794 r
= unit_full_printf(u
, word
, &k
);
2796 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2797 "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2803 if (!env_assignment_is_valid(k
) && !env_name_is_valid(k
)) {
2804 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
2805 "Invalid environment name or assignment %s, ignoring: %s", lvalue
, k
);
2809 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
2812 n
[nlen
++] = TAKE_PTR(k
);
2817 r
= strv_extend_strv(unsetenv
, n
, true);
2825 int config_parse_log_extra_fields(
2827 const char *filename
,
2829 const char *section
,
2830 unsigned section_line
,
2837 ExecContext
*c
= data
;
2838 const Unit
*u
= userdata
;
2846 if (isempty(rvalue
)) {
2847 exec_context_free_log_extra_fields(c
);
2851 for (const char *p
= rvalue
;;) {
2852 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2856 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2862 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
2866 r
= unit_full_printf(u
, word
, &k
);
2868 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2872 eq
= strchr(k
, '=');
2874 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Log field lacks '=' character, ignoring: %s", k
);
2878 if (!journal_field_valid(k
, eq
-k
, false)) {
2879 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Log field name is invalid, ignoring: %s", k
);
2883 t
= reallocarray(c
->log_extra_fields
, c
->n_log_extra_fields
+1, sizeof(struct iovec
));
2887 c
->log_extra_fields
= t
;
2888 c
->log_extra_fields
[c
->n_log_extra_fields
++] = IOVEC_MAKE_STRING(k
);
2894 int config_parse_log_namespace(
2896 const char *filename
,
2898 const char *section
,
2899 unsigned section_line
,
2906 _cleanup_free_
char *k
= NULL
;
2907 ExecContext
*c
= data
;
2908 const Unit
*u
= userdata
;
2916 if (isempty(rvalue
)) {
2917 c
->log_namespace
= mfree(c
->log_namespace
);
2921 r
= unit_full_printf(u
, rvalue
, &k
);
2923 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2927 if (!log_namespace_name_valid(k
)) {
2928 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Specified log namespace name is not valid, ignoring: %s", k
);
2932 free_and_replace(c
->log_namespace
, k
);
2936 int config_parse_unit_condition_path(
2938 const char *filename
,
2940 const char *section
,
2941 unsigned section_line
,
2948 _cleanup_free_
char *p
= NULL
;
2949 Condition
**list
= data
, *c
;
2950 ConditionType t
= ltype
;
2951 bool trigger
, negate
;
2952 const Unit
*u
= userdata
;
2960 if (isempty(rvalue
)) {
2961 /* Empty assignment resets the list */
2962 *list
= condition_free_list(*list
);
2966 trigger
= rvalue
[0] == '|';
2970 negate
= rvalue
[0] == '!';
2974 r
= unit_full_printf(u
, rvalue
, &p
);
2976 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2980 r
= path_simplify_and_warn(p
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2984 c
= condition_new(t
, p
, trigger
, negate
);
2988 LIST_PREPEND(conditions
, *list
, c
);
2992 int config_parse_unit_condition_string(
2994 const char *filename
,
2996 const char *section
,
2997 unsigned section_line
,
3004 _cleanup_free_
char *s
= NULL
;
3005 Condition
**list
= data
, *c
;
3006 ConditionType t
= ltype
;
3007 bool trigger
, negate
;
3008 const Unit
*u
= userdata
;
3016 if (isempty(rvalue
)) {
3017 /* Empty assignment resets the list */
3018 *list
= condition_free_list(*list
);
3022 trigger
= *rvalue
== '|';
3024 rvalue
+= 1 + strspn(rvalue
+ 1, WHITESPACE
);
3026 negate
= *rvalue
== '!';
3028 rvalue
+= 1 + strspn(rvalue
+ 1, WHITESPACE
);
3030 r
= unit_full_printf(u
, rvalue
, &s
);
3032 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3033 "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
3037 c
= condition_new(t
, s
, trigger
, negate
);
3041 LIST_PREPEND(conditions
, *list
, c
);
3045 int config_parse_unit_requires_mounts_for(
3047 const char *filename
,
3049 const char *section
,
3050 unsigned section_line
,
3065 for (const char *p
= rvalue
;;) {
3066 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
3068 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3074 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3075 "Invalid syntax, ignoring: %s", rvalue
);
3079 r
= unit_full_printf(u
, word
, &resolved
);
3081 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
3085 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
3089 r
= unit_require_mounts_for(u
, resolved
, UNIT_DEPENDENCY_FILE
);
3091 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add required mount '%s', ignoring: %m", resolved
);
3097 int config_parse_documentation(
3099 const char *filename
,
3101 const char *section
,
3102 unsigned section_line
,
3118 if (isempty(rvalue
)) {
3119 /* Empty assignment resets the list */
3120 u
->documentation
= strv_free(u
->documentation
);
3124 r
= config_parse_unit_strv_printf(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
,
3125 rvalue
, data
, userdata
);
3129 for (a
= b
= u
->documentation
; a
&& *a
; a
++) {
3131 if (documentation_url_is_valid(*a
))
3134 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid URL, ignoring: %s", *a
);
3145 int config_parse_syscall_filter(
3147 const char *filename
,
3149 const char *section
,
3150 unsigned section_line
,
3157 ExecContext
*c
= data
;
3158 _unused_
const Unit
*u
= userdata
;
3159 bool invert
= false;
3167 if (isempty(rvalue
)) {
3168 /* Empty assignment resets the list */
3169 c
->syscall_filter
= hashmap_free(c
->syscall_filter
);
3170 c
->syscall_allow_list
= false;
3174 if (rvalue
[0] == '~') {
3179 if (!c
->syscall_filter
) {
3180 c
->syscall_filter
= hashmap_new(NULL
);
3181 if (!c
->syscall_filter
)
3185 /* Allow everything but the ones listed */
3186 c
->syscall_allow_list
= false;
3188 /* Allow nothing but the ones listed */
3189 c
->syscall_allow_list
= true;
3191 /* Accept default syscalls if we are on a allow_list */
3192 r
= seccomp_parse_syscall_filter(
3193 "@default", -1, c
->syscall_filter
,
3194 SECCOMP_PARSE_PERMISSIVE
|SECCOMP_PARSE_ALLOW_LIST
,
3202 for (const char *p
= rvalue
;;) {
3203 _cleanup_free_
char *word
= NULL
, *name
= NULL
;
3206 r
= extract_first_word(&p
, &word
, NULL
, 0);
3212 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3213 "Invalid syntax, ignoring: %s", rvalue
);
3217 r
= parse_syscall_and_errno(word
, &name
, &num
);
3219 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3220 "Failed to parse syscall:errno, ignoring: %s", word
);
3223 if (!invert
&& num
>= 0) {
3224 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3225 "Allow-listed system calls cannot take error number, ignoring: %s", word
);
3229 r
= seccomp_parse_syscall_filter(
3230 name
, num
, c
->syscall_filter
,
3231 SECCOMP_PARSE_LOG
|SECCOMP_PARSE_PERMISSIVE
|
3232 (invert
? SECCOMP_PARSE_INVERT
: 0)|
3233 (c
->syscall_allow_list
? SECCOMP_PARSE_ALLOW_LIST
: 0),
3234 unit
, filename
, line
);
3240 int config_parse_syscall_log(
3242 const char *filename
,
3244 const char *section
,
3245 unsigned section_line
,
3252 ExecContext
*c
= data
;
3253 _unused_
const Unit
*u
= userdata
;
3254 bool invert
= false;
3263 if (isempty(rvalue
)) {
3264 /* Empty assignment resets the list */
3265 c
->syscall_log
= hashmap_free(c
->syscall_log
);
3266 c
->syscall_log_allow_list
= false;
3270 if (rvalue
[0] == '~') {
3275 if (!c
->syscall_log
) {
3276 c
->syscall_log
= hashmap_new(NULL
);
3277 if (!c
->syscall_log
)
3281 /* Log everything but the ones listed */
3282 c
->syscall_log_allow_list
= false;
3284 /* Log nothing but the ones listed */
3285 c
->syscall_log_allow_list
= true;
3290 _cleanup_free_
char *word
= NULL
;
3292 r
= extract_first_word(&p
, &word
, NULL
, 0);
3298 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3302 r
= seccomp_parse_syscall_filter(
3303 word
, -1, c
->syscall_log
,
3304 SECCOMP_PARSE_LOG
|SECCOMP_PARSE_PERMISSIVE
|
3305 (invert
? SECCOMP_PARSE_INVERT
: 0)|
3306 (c
->syscall_log_allow_list
? SECCOMP_PARSE_ALLOW_LIST
: 0),
3307 unit
, filename
, line
);
3313 int config_parse_syscall_archs(
3315 const char *filename
,
3317 const char *section
,
3318 unsigned section_line
,
3328 if (isempty(rvalue
)) {
3329 *archs
= set_free(*archs
);
3333 for (const char *p
= rvalue
;;) {
3334 _cleanup_free_
char *word
= NULL
;
3337 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3343 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3344 "Invalid syntax, ignoring: %s", rvalue
);
3348 r
= seccomp_arch_from_string(word
, &a
);
3350 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3351 "Failed to parse system call architecture \"%s\", ignoring: %m", word
);
3355 r
= set_ensure_put(archs
, NULL
, UINT32_TO_PTR(a
+ 1));
3361 int config_parse_syscall_errno(
3363 const char *filename
,
3365 const char *section
,
3366 unsigned section_line
,
3373 ExecContext
*c
= data
;
3380 if (isempty(rvalue
) || streq(rvalue
, "kill")) {
3381 /* Empty assignment resets to KILL */
3382 c
->syscall_errno
= SECCOMP_ERROR_NUMBER_KILL
;
3386 e
= parse_errno(rvalue
);
3388 log_syntax(unit
, LOG_WARNING
, filename
, line
, e
, "Failed to parse error number, ignoring: %s", rvalue
);
3392 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid error number, ignoring: %s", rvalue
);
3396 c
->syscall_errno
= e
;
3400 int config_parse_address_families(
3402 const char *filename
,
3404 const char *section
,
3405 unsigned section_line
,
3412 ExecContext
*c
= data
;
3413 bool invert
= false;
3420 if (isempty(rvalue
)) {
3421 /* Empty assignment resets the list */
3422 c
->address_families
= set_free(c
->address_families
);
3423 c
->address_families_allow_list
= false;
3427 if (rvalue
[0] == '~') {
3432 if (!c
->address_families
) {
3433 c
->address_families
= set_new(NULL
);
3434 if (!c
->address_families
)
3437 c
->address_families_allow_list
= !invert
;
3440 for (const char *p
= rvalue
;;) {
3441 _cleanup_free_
char *word
= NULL
;
3444 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3450 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3451 "Invalid syntax, ignoring: %s", rvalue
);
3455 af
= af_from_name(word
);
3457 log_syntax(unit
, LOG_WARNING
, filename
, line
, af
,
3458 "Failed to parse address family, ignoring: %s", word
);
3462 /* If we previously wanted to forbid an address family and now
3463 * we want to allow it, then just remove it from the list.
3465 if (!invert
== c
->address_families_allow_list
) {
3466 r
= set_put(c
->address_families
, INT_TO_PTR(af
));
3470 set_remove(c
->address_families
, INT_TO_PTR(af
));
3474 int config_parse_restrict_namespaces(
3476 const char *filename
,
3478 const char *section
,
3479 unsigned section_line
,
3486 ExecContext
*c
= data
;
3487 unsigned long flags
;
3488 bool invert
= false;
3491 if (isempty(rvalue
)) {
3492 /* Reset to the default. */
3493 c
->restrict_namespaces
= NAMESPACE_FLAGS_INITIAL
;
3497 /* Boolean parameter ignores the previous settings */
3498 r
= parse_boolean(rvalue
);
3500 c
->restrict_namespaces
= 0;
3502 } else if (r
== 0) {
3503 c
->restrict_namespaces
= NAMESPACE_FLAGS_ALL
;
3507 if (rvalue
[0] == '~') {
3512 /* Not a boolean argument, in this case it's a list of namespace types. */
3513 r
= namespace_flags_from_string(rvalue
, &flags
);
3515 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse namespace type string, ignoring: %s", rvalue
);
3519 if (c
->restrict_namespaces
== NAMESPACE_FLAGS_INITIAL
)
3520 /* Initial assignment. Just set the value. */
3521 c
->restrict_namespaces
= invert
? (~flags
) & NAMESPACE_FLAGS_ALL
: flags
;
3523 /* Merge the value with the previous one. */
3524 SET_FLAG(c
->restrict_namespaces
, flags
, !invert
);
3530 int config_parse_unit_slice(
3532 const char *filename
,
3534 const char *section
,
3535 unsigned section_line
,
3542 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
3543 _cleanup_free_
char *k
= NULL
;
3544 Unit
*u
= userdata
, *slice
;
3552 r
= unit_name_printf(u
, rvalue
, &k
);
3554 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
3558 r
= manager_load_unit(u
->manager
, k
, NULL
, &error
, &slice
);
3560 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to load slice unit %s, ignoring: %s", k
, bus_error_message(&error
, r
));
3564 r
= unit_set_slice(u
, slice
);
3566 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to assign slice %s to unit %s, ignoring: %m", slice
->id
, u
->id
);
3573 int config_parse_cpu_quota(
3575 const char *filename
,
3577 const char *section
,
3578 unsigned section_line
,
3585 CGroupContext
*c
= data
;
3592 if (isempty(rvalue
)) {
3593 c
->cpu_quota_per_sec_usec
= USEC_INFINITY
;
3597 r
= parse_permyriad_unbounded(rvalue
);
3599 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid CPU quota '%s', ignoring.", rvalue
);
3603 c
->cpu_quota_per_sec_usec
= ((usec_t
) r
* USEC_PER_SEC
) / 10000U;
3607 int config_parse_allowed_cpus(
3609 const char *filename
,
3611 const char *section
,
3612 unsigned section_line
,
3619 CGroupContext
*c
= data
;
3621 (void) parse_cpu_set_extend(rvalue
, &c
->cpuset_cpus
, true, unit
, filename
, line
, lvalue
);
3626 int config_parse_allowed_mems(
3628 const char *filename
,
3630 const char *section
,
3631 unsigned section_line
,
3638 CGroupContext
*c
= data
;
3640 (void) parse_cpu_set_extend(rvalue
, &c
->cpuset_mems
, true, unit
, filename
, line
, lvalue
);
3645 int config_parse_memory_limit(
3647 const char *filename
,
3649 const char *section
,
3650 unsigned section_line
,
3657 CGroupContext
*c
= data
;
3658 uint64_t bytes
= CGROUP_LIMIT_MAX
;
3661 if (isempty(rvalue
) && STR_IN_SET(lvalue
, "DefaultMemoryLow",
3665 bytes
= CGROUP_LIMIT_MIN
;
3666 else if (!isempty(rvalue
) && !streq(rvalue
, "infinity")) {
3668 r
= parse_permyriad(rvalue
);
3670 r
= parse_size(rvalue
, 1024, &bytes
);
3672 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid memory limit '%s', ignoring: %m", rvalue
);
3676 bytes
= physical_memory_scale(r
, 10000U);
3678 if (bytes
>= UINT64_MAX
||
3679 (bytes
<= 0 && !STR_IN_SET(lvalue
, "MemorySwapMax", "MemoryLow", "MemoryMin", "DefaultMemoryLow", "DefaultMemoryMin"))) {
3680 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Memory limit '%s' out of range, ignoring.", rvalue
);
3685 if (streq(lvalue
, "DefaultMemoryLow")) {
3686 c
->default_memory_low
= bytes
;
3687 c
->default_memory_low_set
= true;
3688 } else if (streq(lvalue
, "DefaultMemoryMin")) {
3689 c
->default_memory_min
= bytes
;
3690 c
->default_memory_min_set
= true;
3691 } else if (streq(lvalue
, "MemoryMin")) {
3692 c
->memory_min
= bytes
;
3693 c
->memory_min_set
= true;
3694 } else if (streq(lvalue
, "MemoryLow")) {
3695 c
->memory_low
= bytes
;
3696 c
->memory_low_set
= true;
3697 } else if (streq(lvalue
, "MemoryHigh"))
3698 c
->memory_high
= bytes
;
3699 else if (streq(lvalue
, "MemoryMax"))
3700 c
->memory_max
= bytes
;
3701 else if (streq(lvalue
, "MemorySwapMax"))
3702 c
->memory_swap_max
= bytes
;
3703 else if (streq(lvalue
, "MemoryLimit"))
3704 c
->memory_limit
= bytes
;
3711 int config_parse_tasks_max(
3713 const char *filename
,
3715 const char *section
,
3716 unsigned section_line
,
3723 const Unit
*u
= userdata
;
3724 TasksMax
*tasks_max
= data
;
3728 if (isempty(rvalue
)) {
3729 *tasks_max
= u
? u
->manager
->default_tasks_max
: TASKS_MAX_UNSET
;
3733 if (streq(rvalue
, "infinity")) {
3734 *tasks_max
= TASKS_MAX_UNSET
;
3738 r
= parse_permyriad(rvalue
);
3740 *tasks_max
= (TasksMax
) { r
, 10000U }; /* r‱ */
3742 r
= safe_atou64(rvalue
, &v
);
3744 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid maximum tasks value '%s', ignoring: %m", rvalue
);
3748 if (v
<= 0 || v
>= UINT64_MAX
) {
3749 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Maximum tasks value '%s' out of range, ignoring.", rvalue
);
3753 *tasks_max
= (TasksMax
) { v
};
3759 int config_parse_delegate(
3761 const char *filename
,
3763 const char *section
,
3764 unsigned section_line
,
3771 CGroupContext
*c
= data
;
3775 t
= unit_name_to_type(unit
);
3776 assert(t
!= _UNIT_TYPE_INVALID
);
3778 if (!unit_vtable
[t
]->can_delegate
) {
3779 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Delegate= setting not supported for this unit type, ignoring.");
3783 /* We either accept a boolean value, which may be used to turn on delegation for all controllers, or turn it
3784 * off for all. Or it takes a list of controller names, in which case we add the specified controllers to the
3785 * mask to delegate. */
3787 if (isempty(rvalue
)) {
3788 /* An empty string resets controllers and set Delegate=yes. */
3790 c
->delegate_controllers
= 0;
3794 r
= parse_boolean(rvalue
);
3796 CGroupMask mask
= 0;
3798 for (const char *p
= rvalue
;;) {
3799 _cleanup_free_
char *word
= NULL
;
3800 CGroupController cc
;
3802 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3808 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3812 cc
= cgroup_controller_from_string(word
);
3814 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid controller name '%s', ignoring", word
);
3818 mask
|= CGROUP_CONTROLLER_TO_MASK(cc
);
3822 c
->delegate_controllers
|= mask
;
3826 c
->delegate_controllers
= _CGROUP_MASK_ALL
;
3828 c
->delegate
= false;
3829 c
->delegate_controllers
= 0;
3835 int config_parse_managed_oom_mode(
3837 const char *filename
,
3839 const char *section
,
3840 unsigned section_line
,
3847 ManagedOOMMode
*mode
= data
, m
;
3850 t
= unit_name_to_type(unit
);
3851 assert(t
!= _UNIT_TYPE_INVALID
);
3853 if (!unit_vtable
[t
]->can_set_managed_oom
)
3854 return log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "%s= is not supported for this unit type, ignoring.", lvalue
);
3856 if (isempty(rvalue
)) {
3857 *mode
= MANAGED_OOM_AUTO
;
3861 m
= managed_oom_mode_from_string(rvalue
);
3863 log_syntax(unit
, LOG_WARNING
, filename
, line
, m
, "Invalid syntax, ignoring: %s", rvalue
);
3871 int config_parse_managed_oom_mem_pressure_limit(
3873 const char *filename
,
3875 const char *section
,
3876 unsigned section_line
,
3883 uint32_t *limit
= data
;
3887 t
= unit_name_to_type(unit
);
3888 assert(t
!= _UNIT_TYPE_INVALID
);
3890 if (!unit_vtable
[t
]->can_set_managed_oom
)
3891 return log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "%s= is not supported for this unit type, ignoring.", lvalue
);
3893 if (isempty(rvalue
)) {
3898 r
= parse_permyriad(rvalue
);
3900 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse memory pressure limit value, ignoring: %s", rvalue
);
3904 /* Normalize to 2^32-1 == 100% */
3905 *limit
= UINT32_SCALE_FROM_PERMYRIAD(r
);
3909 int config_parse_device_allow(
3911 const char *filename
,
3913 const char *section
,
3914 unsigned section_line
,
3921 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3922 CGroupContext
*c
= data
;
3923 const char *p
= rvalue
;
3926 if (isempty(rvalue
)) {
3927 while (c
->device_allow
)
3928 cgroup_context_free_device_allow(c
, c
->device_allow
);
3933 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3937 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3938 "Invalid syntax, ignoring: %s", rvalue
);
3942 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3943 "Failed to extract device path and rights from '%s', ignoring.", rvalue
);
3947 r
= unit_full_printf(userdata
, path
, &resolved
);
3949 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3950 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3954 if (!STARTSWITH_SET(resolved
, "block-", "char-")) {
3956 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3960 if (!valid_device_node_path(resolved
)) {
3961 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid device node path '%s', ignoring.", resolved
);
3966 if (!isempty(p
) && !in_charset(p
, "rwm")) {
3967 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid device rights '%s', ignoring.", p
);
3971 return cgroup_add_device_allow(c
, resolved
, p
);
3974 int config_parse_io_device_weight(
3976 const char *filename
,
3978 const char *section
,
3979 unsigned section_line
,
3986 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3987 CGroupIODeviceWeight
*w
;
3988 CGroupContext
*c
= data
;
3989 const char *p
= rvalue
;
3997 if (isempty(rvalue
)) {
3998 while (c
->io_device_weights
)
3999 cgroup_context_free_io_device_weight(c
, c
->io_device_weights
);
4004 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4008 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4009 "Invalid syntax, ignoring: %s", rvalue
);
4012 if (r
== 0 || isempty(p
)) {
4013 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4014 "Failed to extract device path and weight from '%s', ignoring.", rvalue
);
4018 r
= unit_full_printf(userdata
, path
, &resolved
);
4020 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4021 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4025 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4029 r
= cg_weight_parse(p
, &u
);
4031 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "IO weight '%s' invalid, ignoring: %m", p
);
4035 assert(u
!= CGROUP_WEIGHT_INVALID
);
4037 w
= new0(CGroupIODeviceWeight
, 1);
4041 w
->path
= TAKE_PTR(resolved
);
4044 LIST_PREPEND(device_weights
, c
->io_device_weights
, w
);
4048 int config_parse_io_device_latency(
4050 const char *filename
,
4052 const char *section
,
4053 unsigned section_line
,
4060 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4061 CGroupIODeviceLatency
*l
;
4062 CGroupContext
*c
= data
;
4063 const char *p
= rvalue
;
4071 if (isempty(rvalue
)) {
4072 while (c
->io_device_latencies
)
4073 cgroup_context_free_io_device_latency(c
, c
->io_device_latencies
);
4078 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4082 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4083 "Invalid syntax, ignoring: %s", rvalue
);
4086 if (r
== 0 || isempty(p
)) {
4087 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4088 "Failed to extract device path and latency from '%s', ignoring.", rvalue
);
4092 r
= unit_full_printf(userdata
, path
, &resolved
);
4094 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4095 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4099 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4103 r
= parse_sec(p
, &usec
);
4105 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse timer value, ignoring: %s", p
);
4109 l
= new0(CGroupIODeviceLatency
, 1);
4113 l
->path
= TAKE_PTR(resolved
);
4114 l
->target_usec
= usec
;
4116 LIST_PREPEND(device_latencies
, c
->io_device_latencies
, l
);
4120 int config_parse_io_limit(
4122 const char *filename
,
4124 const char *section
,
4125 unsigned section_line
,
4132 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4133 CGroupIODeviceLimit
*l
= NULL
, *t
;
4134 CGroupContext
*c
= data
;
4135 CGroupIOLimitType type
;
4136 const char *p
= rvalue
;
4144 type
= cgroup_io_limit_type_from_string(lvalue
);
4147 if (isempty(rvalue
)) {
4148 LIST_FOREACH(device_limits
, l
, c
->io_device_limits
)
4149 l
->limits
[type
] = cgroup_io_limit_defaults
[type
];
4153 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4157 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4158 "Invalid syntax, ignoring: %s", rvalue
);
4161 if (r
== 0 || isempty(p
)) {
4162 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4163 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
4167 r
= unit_full_printf(userdata
, path
, &resolved
);
4169 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4170 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4174 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4178 if (streq("infinity", p
))
4179 num
= CGROUP_LIMIT_MAX
;
4181 r
= parse_size(p
, 1000, &num
);
4182 if (r
< 0 || num
<= 0) {
4183 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid IO limit '%s', ignoring.", p
);
4188 LIST_FOREACH(device_limits
, t
, c
->io_device_limits
) {
4189 if (path_equal(resolved
, t
->path
)) {
4196 CGroupIOLimitType ttype
;
4198 l
= new0(CGroupIODeviceLimit
, 1);
4202 l
->path
= TAKE_PTR(resolved
);
4203 for (ttype
= 0; ttype
< _CGROUP_IO_LIMIT_TYPE_MAX
; ttype
++)
4204 l
->limits
[ttype
] = cgroup_io_limit_defaults
[ttype
];
4206 LIST_PREPEND(device_limits
, c
->io_device_limits
, l
);
4209 l
->limits
[type
] = num
;
4214 int config_parse_blockio_device_weight(
4216 const char *filename
,
4218 const char *section
,
4219 unsigned section_line
,
4226 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4227 CGroupBlockIODeviceWeight
*w
;
4228 CGroupContext
*c
= data
;
4229 const char *p
= rvalue
;
4237 if (isempty(rvalue
)) {
4238 while (c
->blockio_device_weights
)
4239 cgroup_context_free_blockio_device_weight(c
, c
->blockio_device_weights
);
4244 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4248 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4249 "Invalid syntax, ignoring: %s", rvalue
);
4252 if (r
== 0 || isempty(p
)) {
4253 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4254 "Failed to extract device node and weight from '%s', ignoring.", rvalue
);
4258 r
= unit_full_printf(userdata
, path
, &resolved
);
4260 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4261 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4265 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4269 r
= cg_blkio_weight_parse(p
, &u
);
4271 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid block IO weight '%s', ignoring: %m", p
);
4275 assert(u
!= CGROUP_BLKIO_WEIGHT_INVALID
);
4277 w
= new0(CGroupBlockIODeviceWeight
, 1);
4281 w
->path
= TAKE_PTR(resolved
);
4284 LIST_PREPEND(device_weights
, c
->blockio_device_weights
, w
);
4288 int config_parse_blockio_bandwidth(
4290 const char *filename
,
4292 const char *section
,
4293 unsigned section_line
,
4300 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4301 CGroupBlockIODeviceBandwidth
*b
= NULL
, *t
;
4302 CGroupContext
*c
= data
;
4303 const char *p
= rvalue
;
4312 read
= streq("BlockIOReadBandwidth", lvalue
);
4314 if (isempty(rvalue
)) {
4315 LIST_FOREACH(device_bandwidths
, b
, c
->blockio_device_bandwidths
) {
4316 b
->rbps
= CGROUP_LIMIT_MAX
;
4317 b
->wbps
= CGROUP_LIMIT_MAX
;
4322 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4326 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4327 "Invalid syntax, ignoring: %s", rvalue
);
4330 if (r
== 0 || isempty(p
)) {
4331 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4332 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
4336 r
= unit_full_printf(userdata
, path
, &resolved
);
4338 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4339 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4343 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4347 r
= parse_size(p
, 1000, &bytes
);
4348 if (r
< 0 || bytes
<= 0) {
4349 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid Block IO Bandwidth '%s', ignoring.", p
);
4353 LIST_FOREACH(device_bandwidths
, t
, c
->blockio_device_bandwidths
) {
4354 if (path_equal(resolved
, t
->path
)) {
4361 b
= new0(CGroupBlockIODeviceBandwidth
, 1);
4365 b
->path
= TAKE_PTR(resolved
);
4366 b
->rbps
= CGROUP_LIMIT_MAX
;
4367 b
->wbps
= CGROUP_LIMIT_MAX
;
4369 LIST_PREPEND(device_bandwidths
, c
->blockio_device_bandwidths
, b
);
4380 int config_parse_job_mode_isolate(
4382 const char *filename
,
4384 const char *section
,
4385 unsigned section_line
,
4399 r
= parse_boolean(rvalue
);
4401 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse boolean, ignoring: %s", rvalue
);
4405 log_notice("%s is deprecated. Please use OnFailureJobMode= instead", lvalue
);
4407 *m
= r
? JOB_ISOLATE
: JOB_REPLACE
;
4411 int config_parse_exec_directories(
4413 const char *filename
,
4415 const char *section
,
4416 unsigned section_line
,
4424 const Unit
*u
= userdata
;
4432 if (isempty(rvalue
)) {
4433 /* Empty assignment resets the list */
4434 *rt
= strv_free(*rt
);
4438 for (const char *p
= rvalue
;;) {
4439 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
4441 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
4445 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4446 "Invalid syntax, ignoring: %s", rvalue
);
4452 r
= unit_full_printf(u
, word
, &k
);
4454 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4455 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
4459 r
= path_simplify_and_warn(k
, PATH_CHECK_RELATIVE
, unit
, filename
, line
, lvalue
);
4463 if (path_startswith(k
, "private")) {
4464 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4465 "%s= path can't be 'private', ignoring assignment: %s", lvalue
, word
);
4469 r
= strv_push(rt
, k
);
4476 int config_parse_set_credential(
4478 const char *filename
,
4480 const char *section
,
4481 unsigned section_line
,
4488 _cleanup_free_
char *word
= NULL
, *k
= NULL
, *unescaped
= NULL
;
4489 ExecContext
*context
= data
;
4490 ExecSetCredential
*old
;
4500 if (isempty(rvalue
)) {
4501 /* Empty assignment resets the list */
4502 context
->set_credentials
= hashmap_free(context
->set_credentials
);
4507 r
= extract_first_word(&p
, &word
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4511 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
4515 r
= unit_full_printf(u
, word
, &k
);
4517 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
4520 if (!credential_name_valid(k
)) {
4521 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Credential name \"%s\" not valid, ignoring.", k
);
4525 /* We support escape codes here, so that users can insert trailing \n if they like */
4526 l
= cunescape(p
, UNESCAPE_ACCEPT_NUL
, &unescaped
);
4528 log_syntax(unit
, LOG_WARNING
, filename
, line
, l
, "Can't unescape \"%s\", ignoring: %m", p
);
4532 old
= hashmap_get(context
->set_credentials
, k
);
4534 free_and_replace(old
->data
, unescaped
);
4537 _cleanup_(exec_set_credential_freep
) ExecSetCredential
*sc
= NULL
;
4539 sc
= new0(ExecSetCredential
, 1);
4543 sc
->id
= TAKE_PTR(k
);
4544 sc
->data
= TAKE_PTR(unescaped
);
4547 r
= hashmap_ensure_put(&context
->set_credentials
, &exec_set_credential_hash_ops
, sc
->id
, sc
);
4551 log_syntax(unit
, LOG_WARNING
, filename
, line
, l
,
4552 "Duplicated credential value '%s', ignoring assignment: %s", sc
->id
, rvalue
);
4562 int config_parse_load_credential(
4564 const char *filename
,
4566 const char *section
,
4567 unsigned section_line
,
4574 _cleanup_free_
char *word
= NULL
, *k
= NULL
, *q
= NULL
;
4575 ExecContext
*context
= data
;
4585 if (isempty(rvalue
)) {
4586 /* Empty assignment resets the list */
4587 context
->load_credentials
= strv_free(context
->load_credentials
);
4592 r
= extract_first_word(&p
, &word
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4596 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
4600 r
= unit_full_printf(u
, word
, &k
);
4602 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
4605 if (!credential_name_valid(k
)) {
4606 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Credential name \"%s\" not valid, ignoring.", k
);
4609 r
= unit_full_printf(u
, p
, &q
);
4611 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", p
);
4614 if (path_is_absolute(q
) ? !path_is_normalized(q
) : !credential_name_valid(q
)) {
4615 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
);
4729 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
);
4806 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
);
4880 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 static int merge_by_names(Unit
**u
, Set
*names
, const char *id
) {
5580 /* Let's try to add in all names that are aliases of this unit */
5581 while ((k
= set_steal_first(names
))) {
5582 _cleanup_free_ _unused_
char *free_k
= k
;
5584 /* First try to merge in the other name into our unit */
5585 r
= unit_merge_by_name(*u
, k
);
5589 /* Hmm, we couldn't merge the other unit into ours? Then let's try it the other way
5592 other
= manager_get_unit((*u
)->manager
, k
);
5594 return r
; /* return previous failure */
5596 r
= unit_merge(other
, *u
);
5601 return merge_by_names(u
, names
, NULL
);
5604 if (streq_ptr(id
, k
))
5605 unit_choose_id(*u
, id
);
5611 int unit_load_fragment(Unit
*u
) {
5612 const char *fragment
;
5613 _cleanup_set_free_free_ Set
*names
= NULL
;
5617 assert(u
->load_state
== UNIT_STUB
);
5621 u
->load_state
= UNIT_LOADED
;
5625 /* Possibly rebuild the fragment map to catch new units */
5626 r
= unit_file_build_name_map(&u
->manager
->lookup_paths
,
5627 &u
->manager
->unit_cache_timestamp_hash
,
5628 &u
->manager
->unit_id_map
,
5629 &u
->manager
->unit_name_map
,
5630 &u
->manager
->unit_path_cache
);
5632 return log_error_errno(r
, "Failed to rebuild name map: %m");
5634 r
= unit_file_find_fragment(u
->manager
->unit_id_map
,
5635 u
->manager
->unit_name_map
,
5639 if (r
< 0 && r
!= -ENOENT
)
5643 /* Open the file, check if this is a mask, otherwise read. */
5644 _cleanup_fclose_
FILE *f
= NULL
;
5647 /* Try to open the file name. A symlink is OK, for example for linked files or masks. We
5648 * expect that all symlinks within the lookup paths have been already resolved, but we don't
5649 * verify this here. */
5650 f
= fopen(fragment
, "re");
5652 return log_unit_notice_errno(u
, errno
, "Failed to open %s: %m", fragment
);
5654 if (fstat(fileno(f
), &st
) < 0)
5657 r
= free_and_strdup(&u
->fragment_path
, fragment
);
5661 if (null_or_empty(&st
)) {
5662 /* Unit file is masked */
5664 u
->load_state
= u
->perpetual
? UNIT_LOADED
: UNIT_MASKED
; /* don't allow perpetual units to ever be masked */
5665 u
->fragment_mtime
= 0;
5667 u
->load_state
= UNIT_LOADED
;
5668 u
->fragment_mtime
= timespec_load(&st
.st_mtim
);
5670 /* Now, parse the file contents */
5671 r
= config_parse(u
->id
, fragment
, f
,
5672 UNIT_VTABLE(u
)->sections
,
5673 config_item_perf_lookup
, load_fragment_gperf_lookup
,
5678 log_unit_notice_errno(u
, r
, "Unit configuration has fatal error, unit will not be started.");
5684 /* Call merge_by_names with the name derived from the fragment path as the preferred name.
5686 * We do the merge dance here because for some unit types, the unit might have aliases which are not
5687 * declared in the file system. In particular, this is true (and frequent) for device and swap units.
5689 const char *id
= u
->id
;
5690 _cleanup_free_
char *free_id
= NULL
;
5693 id
= basename(fragment
);
5694 if (unit_name_is_valid(id
, UNIT_NAME_TEMPLATE
)) {
5695 assert(u
->instance
); /* If we're not trying to use a template for non-instanced unit,
5696 * this must be set. */
5698 r
= unit_name_replace_instance(id
, u
->instance
, &free_id
);
5700 return log_debug_errno(r
, "Failed to build id (%s + %s): %m", id
, u
->instance
);
5706 r
= merge_by_names(&merged
, names
, id
);
5711 u
->load_state
= UNIT_MERGED
;
5716 void unit_dump_config_items(FILE *f
) {
5717 static const struct {
5718 const ConfigParserCallback callback
;
5721 { config_parse_warn_compat
, "NOTSUPPORTED" },
5722 { config_parse_int
, "INTEGER" },
5723 { config_parse_unsigned
, "UNSIGNED" },
5724 { config_parse_iec_size
, "SIZE" },
5725 { config_parse_iec_uint64
, "SIZE" },
5726 { config_parse_si_uint64
, "SIZE" },
5727 { config_parse_bool
, "BOOLEAN" },
5728 { config_parse_string
, "STRING" },
5729 { config_parse_path
, "PATH" },
5730 { config_parse_unit_path_printf
, "PATH" },
5731 { config_parse_strv
, "STRING [...]" },
5732 { config_parse_exec_nice
, "NICE" },
5733 { config_parse_exec_oom_score_adjust
, "OOMSCOREADJUST" },
5734 { config_parse_exec_io_class
, "IOCLASS" },
5735 { config_parse_exec_io_priority
, "IOPRIORITY" },
5736 { config_parse_exec_cpu_sched_policy
, "CPUSCHEDPOLICY" },
5737 { config_parse_exec_cpu_sched_prio
, "CPUSCHEDPRIO" },
5738 { config_parse_exec_cpu_affinity
, "CPUAFFINITY" },
5739 { config_parse_mode
, "MODE" },
5740 { config_parse_unit_env_file
, "FILE" },
5741 { config_parse_exec_output
, "OUTPUT" },
5742 { config_parse_exec_input
, "INPUT" },
5743 { config_parse_log_facility
, "FACILITY" },
5744 { config_parse_log_level
, "LEVEL" },
5745 { config_parse_exec_secure_bits
, "SECUREBITS" },
5746 { config_parse_capability_set
, "BOUNDINGSET" },
5747 { config_parse_rlimit
, "LIMIT" },
5748 { config_parse_unit_deps
, "UNIT [...]" },
5749 { config_parse_exec
, "PATH [ARGUMENT [...]]" },
5750 { config_parse_service_type
, "SERVICETYPE" },
5751 { config_parse_service_restart
, "SERVICERESTART" },
5752 { config_parse_service_timeout_failure_mode
, "TIMEOUTMODE" },
5753 { config_parse_kill_mode
, "KILLMODE" },
5754 { config_parse_signal
, "SIGNAL" },
5755 { config_parse_socket_listen
, "SOCKET [...]" },
5756 { config_parse_socket_bind
, "SOCKETBIND" },
5757 { config_parse_socket_bindtodevice
, "NETWORKINTERFACE" },
5758 { config_parse_sec
, "SECONDS" },
5759 { config_parse_nsec
, "NANOSECONDS" },
5760 { config_parse_namespace_path_strv
, "PATH [...]" },
5761 { config_parse_bind_paths
, "PATH[:PATH[:OPTIONS]] [...]" },
5762 { config_parse_unit_requires_mounts_for
, "PATH [...]" },
5763 { config_parse_exec_mount_flags
, "MOUNTFLAG [...]" },
5764 { config_parse_unit_string_printf
, "STRING" },
5765 { config_parse_trigger_unit
, "UNIT" },
5766 { config_parse_timer
, "TIMER" },
5767 { config_parse_path_spec
, "PATH" },
5768 { config_parse_notify_access
, "ACCESS" },
5769 { config_parse_ip_tos
, "TOS" },
5770 { config_parse_unit_condition_path
, "CONDITION" },
5771 { config_parse_unit_condition_string
, "CONDITION" },
5772 { config_parse_unit_slice
, "SLICE" },
5773 { config_parse_documentation
, "URL" },
5774 { config_parse_service_timeout
, "SECONDS" },
5775 { config_parse_emergency_action
, "ACTION" },
5776 { config_parse_set_status
, "STATUS" },
5777 { config_parse_service_sockets
, "SOCKETS" },
5778 { config_parse_environ
, "ENVIRON" },
5780 { config_parse_syscall_filter
, "SYSCALLS" },
5781 { config_parse_syscall_archs
, "ARCHS" },
5782 { config_parse_syscall_errno
, "ERRNO" },
5783 { config_parse_syscall_log
, "SYSCALLS" },
5784 { config_parse_address_families
, "FAMILIES" },
5785 { config_parse_restrict_namespaces
, "NAMESPACES" },
5787 { config_parse_cpu_shares
, "SHARES" },
5788 { config_parse_cg_weight
, "WEIGHT" },
5789 { config_parse_memory_limit
, "LIMIT" },
5790 { config_parse_device_allow
, "DEVICE" },
5791 { config_parse_device_policy
, "POLICY" },
5792 { config_parse_io_limit
, "LIMIT" },
5793 { config_parse_io_device_weight
, "DEVICEWEIGHT" },
5794 { config_parse_io_device_latency
, "DEVICELATENCY" },
5795 { config_parse_blockio_bandwidth
, "BANDWIDTH" },
5796 { config_parse_blockio_weight
, "WEIGHT" },
5797 { config_parse_blockio_device_weight
, "DEVICEWEIGHT" },
5798 { config_parse_long
, "LONG" },
5799 { config_parse_socket_service
, "SERVICE" },
5801 { config_parse_exec_selinux_context
, "LABEL" },
5803 { config_parse_job_mode
, "MODE" },
5804 { config_parse_job_mode_isolate
, "BOOLEAN" },
5805 { config_parse_personality
, "PERSONALITY" },
5808 const char *prev
= NULL
;
5813 NULSTR_FOREACH(i
, load_fragment_gperf_nulstr
) {
5814 const char *rvalue
= "OTHER", *lvalue
;
5815 const ConfigPerfItem
*p
;
5818 assert_se(p
= load_fragment_gperf_lookup(i
, strlen(i
)));
5820 /* Hide legacy settings */
5821 if (p
->parse
== config_parse_warn_compat
&&
5822 p
->ltype
== DISABLED_LEGACY
)
5825 for (size_t j
= 0; j
< ELEMENTSOF(table
); j
++)
5826 if (p
->parse
== table
[j
].callback
) {
5827 rvalue
= table
[j
].rvalue
;
5831 dot
= strchr(i
, '.');
5832 lvalue
= dot
? dot
+ 1 : i
;
5835 size_t prefix_len
= dot
- i
;
5837 if (!prev
|| !strneq(prev
, i
, prefix_len
+1)) {
5841 fprintf(f
, "[%.*s]\n", (int) prefix_len
, i
);
5845 fprintf(f
, "%s=%s\n", lvalue
, rvalue
);
5850 int config_parse_cpu_affinity2(
5852 const char *filename
,
5854 const char *section
,
5855 unsigned section_line
,
5862 CPUSet
*affinity
= data
;
5866 (void) parse_cpu_set_extend(rvalue
, affinity
, true, unit
, filename
, line
, lvalue
);
5871 int config_parse_show_status(
5873 const char *filename
,
5875 const char *section
,
5876 unsigned section_line
,
5884 ShowStatus
*b
= data
;
5891 k
= parse_show_status(rvalue
, b
);
5893 log_syntax(unit
, LOG_WARNING
, filename
, line
, k
, "Failed to parse show status setting, ignoring: %s", rvalue
);
5898 int config_parse_output_restricted(
5900 const char *filename
,
5902 const char *section
,
5903 unsigned section_line
,
5910 ExecOutput t
, *eo
= data
;
5911 bool obsolete
= false;
5918 if (streq(rvalue
, "syslog")) {
5919 t
= EXEC_OUTPUT_JOURNAL
;
5921 } else if (streq(rvalue
, "syslog+console")) {
5922 t
= EXEC_OUTPUT_JOURNAL_AND_CONSOLE
;
5925 t
= exec_output_from_string(rvalue
);
5927 log_syntax(unit
, LOG_WARNING
, filename
, line
, t
, "Failed to parse output type, ignoring: %s", rvalue
);
5931 if (IN_SET(t
, EXEC_OUTPUT_SOCKET
, EXEC_OUTPUT_NAMED_FD
, EXEC_OUTPUT_FILE
, EXEC_OUTPUT_FILE_APPEND
, EXEC_OUTPUT_FILE_TRUNCATE
)) {
5932 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Standard output types socket, fd:, file:, append:, truncate: are not supported as defaults, ignoring: %s", rvalue
);
5938 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
5939 "Standard output type %s is obsolete, automatically updating to %s. Please update your configuration.",
5940 rvalue
, exec_output_to_string(t
));
5946 int config_parse_crash_chvt(
5948 const char *filename
,
5950 const char *section
,
5951 unsigned section_line
,
5965 r
= parse_crash_chvt(rvalue
, data
);
5967 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse CrashChangeVT= setting, ignoring: %s", rvalue
);
5972 int config_parse_swap_priority(
5974 const char *filename
,
5976 const char *section
,
5977 unsigned section_line
,
5993 if (isempty(rvalue
)) {
5994 s
->parameters_fragment
.priority
= -1;
5995 s
->parameters_fragment
.priority_set
= false;
5999 r
= safe_atoi(rvalue
, &priority
);
6001 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid swap priority '%s', ignoring.", rvalue
);
6005 if (priority
< -1) {
6006 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
);
6010 if (priority
> 32767) {
6011 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Swap priority out of range, ignoring: %s", rvalue
);
6015 s
->parameters_fragment
.priority
= priority
;
6016 s
->parameters_fragment
.priority_set
= true;