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 "process-util.h"
51 #include "seccomp-util.h"
53 #include "securebits-util.h"
54 #include "signal-util.h"
55 #include "socket-netlink.h"
56 #include "stat-util.h"
57 #include "string-util.h"
59 #include "syslog-util.h"
60 #include "time-util.h"
61 #include "unit-name.h"
62 #include "unit-printf.h"
63 #include "user-util.h"
67 static int parse_socket_protocol(const char *s
) {
70 r
= parse_ip_protocol(s
);
73 if (!IN_SET(r
, IPPROTO_UDPLITE
, IPPROTO_SCTP
))
74 return -EPROTONOSUPPORT
;
79 int parse_crash_chvt(const char *value
, int *data
) {
82 if (safe_atoi(value
, data
) >= 0)
85 b
= parse_boolean(value
);
90 *data
= 0; /* switch to where kmsg goes */
92 *data
= -1; /* turn off switching */
97 int parse_confirm_spawn(const char *value
, char **console
) {
101 r
= value
? parse_boolean(value
) : 1;
105 } else if (r
> 0) /* on with default tty */
106 s
= strdup("/dev/console");
107 else if (is_path(value
)) /* on with fully qualified path */
109 else /* on with only a tty file name, not a fully qualified path */
110 s
= path_join("/dev/", value
);
118 DEFINE_CONFIG_PARSE(config_parse_socket_protocol
, parse_socket_protocol
, "Failed to parse socket protocol");
119 DEFINE_CONFIG_PARSE(config_parse_exec_secure_bits
, secure_bits_from_string
, "Failed to parse secure bits");
120 DEFINE_CONFIG_PARSE_ENUM(config_parse_collect_mode
, collect_mode
, CollectMode
, "Failed to parse garbage collection mode");
121 DEFINE_CONFIG_PARSE_ENUM(config_parse_device_policy
, cgroup_device_policy
, CGroupDevicePolicy
, "Failed to parse device policy");
122 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_keyring_mode
, exec_keyring_mode
, ExecKeyringMode
, "Failed to parse keyring mode");
123 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_proc
, protect_proc
, ProtectProc
, "Failed to parse /proc/ protection mode");
124 DEFINE_CONFIG_PARSE_ENUM(config_parse_proc_subset
, proc_subset
, ProcSubset
, "Failed to parse /proc/ subset mode");
125 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_utmp_mode
, exec_utmp_mode
, ExecUtmpMode
, "Failed to parse utmp mode");
126 DEFINE_CONFIG_PARSE_ENUM(config_parse_job_mode
, job_mode
, JobMode
, "Failed to parse job mode");
127 DEFINE_CONFIG_PARSE_ENUM(config_parse_notify_access
, notify_access
, NotifyAccess
, "Failed to parse notify access specifier");
128 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_home
, protect_home
, ProtectHome
, "Failed to parse protect home value");
129 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_system
, protect_system
, ProtectSystem
, "Failed to parse protect system value");
130 DEFINE_CONFIG_PARSE_ENUM(config_parse_runtime_preserve_mode
, exec_preserve_mode
, ExecPreserveMode
, "Failed to parse runtime directory preserve mode");
131 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_type
, service_type
, ServiceType
, "Failed to parse service type");
132 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart
, service_restart
, ServiceRestart
, "Failed to parse service restart specifier");
133 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_timeout_failure_mode
, service_timeout_failure_mode
, ServiceTimeoutFailureMode
, "Failed to parse timeout failure mode");
134 DEFINE_CONFIG_PARSE_ENUM(config_parse_socket_bind
, socket_address_bind_ipv6_only_or_bool
, SocketAddressBindIPv6Only
, "Failed to parse bind IPv6 only value");
135 DEFINE_CONFIG_PARSE_ENUM(config_parse_oom_policy
, oom_policy
, OOMPolicy
, "Failed to parse OOM policy");
136 DEFINE_CONFIG_PARSE_ENUM(config_parse_managed_oom_preference
, managed_oom_preference
, ManagedOOMPreference
, "Failed to parse ManagedOOMPreference=");
137 DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_ip_tos
, ip_tos
, int, -1, "Failed to parse IP TOS value");
138 DEFINE_CONFIG_PARSE_PTR(config_parse_blockio_weight
, cg_blkio_weight_parse
, uint64_t, "Invalid block IO weight");
139 DEFINE_CONFIG_PARSE_PTR(config_parse_cg_weight
, cg_weight_parse
, uint64_t, "Invalid weight");
140 DEFINE_CONFIG_PARSE_PTR(config_parse_cpu_shares
, cg_cpu_shares_parse
, uint64_t, "Invalid CPU shares");
141 DEFINE_CONFIG_PARSE_PTR(config_parse_exec_mount_flags
, mount_propagation_flags_from_string
, unsigned long, "Failed to parse mount flag");
142 DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_numa_policy
, mpol
, int, -1, "Invalid NUMA policy type");
143 DEFINE_CONFIG_PARSE_ENUM(config_parse_status_unit_format
, status_unit_format
, StatusUnitFormat
, "Failed to parse status unit format");
144 DEFINE_CONFIG_PARSE_ENUM_FULL(config_parse_socket_timestamping
, socket_timestamping_from_string_harder
, SocketTimestamping
, "Failed to parse timestamping precision");
146 int config_parse_unit_deps(
148 const char *filename
,
151 unsigned section_line
,
158 UnitDependency d
= ltype
;
165 for (const char *p
= rvalue
;;) {
166 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
169 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_RETAIN_ESCAPE
);
175 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
179 r
= unit_name_printf(u
, word
, &k
);
181 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
185 r
= unit_add_dependency_by_name(u
, d
, k
, true, UNIT_DEPENDENCY_FILE
);
187 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
191 int config_parse_obsolete_unit_deps(
193 const char *filename
,
196 unsigned section_line
,
203 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
204 "Unit dependency type %s= is obsolete, replacing by %s=, please update your unit file", lvalue
, unit_dependency_to_string(ltype
));
206 return config_parse_unit_deps(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
);
209 int config_parse_unit_string_printf(
211 const char *filename
,
214 unsigned section_line
,
221 _cleanup_free_
char *k
= NULL
;
222 const Unit
*u
= userdata
;
230 r
= unit_full_printf(u
, rvalue
, &k
);
232 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
236 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
239 int config_parse_unit_strv_printf(
241 const char *filename
,
244 unsigned section_line
,
251 const Unit
*u
= userdata
;
252 _cleanup_free_
char *k
= NULL
;
260 r
= unit_full_printf(u
, rvalue
, &k
);
262 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
266 return config_parse_strv(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
269 int config_parse_unit_path_printf(
271 const char *filename
,
274 unsigned section_line
,
281 _cleanup_free_
char *k
= NULL
;
282 const Unit
*u
= userdata
;
291 /* Let's not bother with anything that is too long */
292 if (strlen(rvalue
) >= PATH_MAX
) {
293 log_syntax(unit
, fatal
? LOG_ERR
: LOG_WARNING
, filename
, line
, 0,
294 "%s value too long%s.",
295 lvalue
, fatal
? "" : ", ignoring");
296 return fatal
? -ENAMETOOLONG
: 0;
299 r
= unit_full_printf(u
, rvalue
, &k
);
301 log_syntax(unit
, fatal
? LOG_ERR
: LOG_WARNING
, filename
, line
, r
,
302 "Failed to resolve unit specifiers in '%s'%s: %m",
303 rvalue
, fatal
? "" : ", ignoring");
304 return fatal
? -ENOEXEC
: 0;
307 return config_parse_path(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
310 int config_parse_unit_path_strv_printf(
312 const char *filename
,
315 unsigned section_line
,
323 const Unit
*u
= userdata
;
331 if (isempty(rvalue
)) {
336 for (const char *p
= rvalue
;;) {
337 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
339 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
345 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
346 "Invalid syntax, ignoring: %s", rvalue
);
350 r
= unit_full_printf(u
, word
, &k
);
352 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
353 "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
357 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
361 r
= strv_consume(x
, TAKE_PTR(k
));
367 static int patch_var_run(
369 const char *filename
,
377 e
= path_startswith(*path
, "/var/run/");
381 z
= path_join("/run/", e
);
385 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
386 "%s= references a path below legacy directory /var/run/, updating %s → %s; "
387 "please update the unit file accordingly.", lvalue
, *path
, z
);
389 free_and_replace(*path
, z
);
394 int config_parse_socket_listen(
396 const char *filename
,
399 unsigned section_line
,
406 _cleanup_free_ SocketPort
*p
= NULL
;
418 if (isempty(rvalue
)) {
419 /* An empty assignment removes all ports */
420 socket_free_ports(s
);
424 p
= new0(SocketPort
, 1);
428 if (ltype
!= SOCKET_SOCKET
) {
429 _cleanup_free_
char *k
= NULL
;
431 r
= unit_full_printf(UNIT(s
), rvalue
, &k
);
433 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
437 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
441 if (ltype
== SOCKET_FIFO
) {
442 r
= patch_var_run(unit
, filename
, line
, lvalue
, &k
);
447 free_and_replace(p
->path
, k
);
450 } else if (streq(lvalue
, "ListenNetlink")) {
451 _cleanup_free_
char *k
= NULL
;
453 r
= unit_full_printf(UNIT(s
), rvalue
, &k
);
455 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
459 r
= socket_address_parse_netlink(&p
->address
, k
);
461 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse address value in '%s', ignoring: %m", k
);
465 p
->type
= SOCKET_SOCKET
;
468 _cleanup_free_
char *k
= NULL
;
470 r
= unit_full_printf(UNIT(s
), rvalue
, &k
);
472 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
476 if (k
[0] == '/') { /* Only for AF_UNIX file system sockets… */
477 r
= patch_var_run(unit
, filename
, line
, lvalue
, &k
);
482 r
= socket_address_parse_and_warn(&p
->address
, k
);
484 if (r
!= -EAFNOSUPPORT
)
485 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse address value in '%s', ignoring: %m", k
);
489 if (streq(lvalue
, "ListenStream"))
490 p
->address
.type
= SOCK_STREAM
;
491 else if (streq(lvalue
, "ListenDatagram"))
492 p
->address
.type
= SOCK_DGRAM
;
494 assert(streq(lvalue
, "ListenSequentialPacket"));
495 p
->address
.type
= SOCK_SEQPACKET
;
498 if (socket_address_family(&p
->address
) != AF_LOCAL
&& p
->address
.type
== SOCK_SEQPACKET
) {
499 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Address family not supported, ignoring: %s", rvalue
);
503 p
->type
= SOCKET_SOCKET
;
507 p
->auxiliary_fds
= NULL
;
508 p
->n_auxiliary_fds
= 0;
511 LIST_FIND_TAIL(port
, s
->ports
, tail
);
512 LIST_INSERT_AFTER(port
, s
->ports
, tail
, p
);
519 int config_parse_exec_nice(
521 const char *filename
,
524 unsigned section_line
,
531 ExecContext
*c
= data
;
539 if (isempty(rvalue
)) {
544 r
= parse_nice(rvalue
, &priority
);
547 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Nice priority out of range, ignoring: %s", rvalue
);
549 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse nice priority '%s', ignoring: %m", rvalue
);
559 int config_parse_exec_oom_score_adjust(
561 const char *filename
,
564 unsigned section_line
,
571 ExecContext
*c
= data
;
579 if (isempty(rvalue
)) {
580 c
->oom_score_adjust_set
= false;
584 r
= parse_oom_score_adjust(rvalue
, &oa
);
587 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "OOM score adjust value out of range, ignoring: %s", rvalue
);
589 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse the OOM score adjust value '%s', ignoring: %m", rvalue
);
593 c
->oom_score_adjust
= oa
;
594 c
->oom_score_adjust_set
= true;
599 int config_parse_exec_coredump_filter(
601 const char *filename
,
604 unsigned section_line
,
611 ExecContext
*c
= data
;
619 if (isempty(rvalue
)) {
620 c
->coredump_filter
= 0;
621 c
->coredump_filter_set
= false;
626 r
= coredump_filter_mask_from_string(rvalue
, &f
);
628 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
629 "Failed to parse the CoredumpFilter=%s, ignoring: %m", rvalue
);
633 c
->coredump_filter
|= f
;
634 c
->oom_score_adjust_set
= true;
638 int config_parse_kill_mode(
640 const char *filename
,
643 unsigned section_line
,
650 KillMode
*k
= data
, m
;
657 if (isempty(rvalue
)) {
658 *k
= KILL_CONTROL_GROUP
;
662 m
= kill_mode_from_string(rvalue
);
664 log_syntax(unit
, LOG_WARNING
, filename
, line
, m
,
665 "Failed to parse kill mode specification, ignoring: %s", rvalue
);
670 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
671 "Unit configured to use KillMode=none. "
672 "This is unsafe, as it disables systemd's process lifecycle management for the service. "
673 "Please update your service to use a safer KillMode=, such as 'mixed' or 'control-group'. "
674 "Support for KillMode=none is deprecated and will eventually be removed.");
680 int config_parse_exec(
682 const char *filename
,
685 unsigned section_line
,
692 ExecCommand
**e
= data
;
693 const Unit
*u
= userdata
;
705 if (isempty(rvalue
)) {
706 /* An empty assignment resets the list */
707 *e
= exec_command_free_list(*e
);
713 _cleanup_free_
char *path
= NULL
, *firstword
= NULL
;
714 ExecCommandFlags flags
= 0;
715 bool ignore
= false, separate_argv0
= false;
716 _cleanup_free_ ExecCommand
*nce
= NULL
;
717 _cleanup_strv_free_
char **n
= NULL
;
718 size_t nlen
= 0, nbufsize
= 0;
723 r
= extract_first_word_and_warn(&p
, &firstword
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
727 /* A lone ";" is a separator. Let's make sure we don't treat it as an executable name. */
728 if (streq(firstword
, ";")) {
735 /* We accept an absolute path as first argument. If it's prefixed with - and the path doesn't
736 * exist, we ignore it instead of erroring out; if it's prefixed with @, we allow overriding of
737 * argv[0]; if it's prefixed with :, we will not do environment variable substitution;
738 * if it's prefixed with +, it will be run with full privileges and no sandboxing; if
739 * it's prefixed with '!' we apply sandboxing, but do not change user/group credentials; if
740 * it's prefixed with '!!', then we apply user/group credentials if the kernel supports ambient
741 * capabilities -- if it doesn't we don't apply the credentials themselves, but do apply most
742 * other sandboxing, with some special exceptions for changing UID.
744 * The idea is that '!!' may be used to write services that can take benefit of systemd's
745 * UID/GID dropping if the kernel supports ambient creds, but provide an automatic fallback to
746 * privilege dropping within the daemon if the kernel does not offer that. */
748 if (*f
== '-' && !(flags
& EXEC_COMMAND_IGNORE_FAILURE
)) {
749 flags
|= EXEC_COMMAND_IGNORE_FAILURE
;
751 } else if (*f
== '@' && !separate_argv0
)
752 separate_argv0
= true;
753 else if (*f
== ':' && !(flags
& EXEC_COMMAND_NO_ENV_EXPAND
))
754 flags
|= EXEC_COMMAND_NO_ENV_EXPAND
;
755 else if (*f
== '+' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
756 flags
|= EXEC_COMMAND_FULLY_PRIVILEGED
;
757 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
758 flags
|= EXEC_COMMAND_NO_SETUID
;
759 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_AMBIENT_MAGIC
))) {
760 flags
&= ~EXEC_COMMAND_NO_SETUID
;
761 flags
|= EXEC_COMMAND_AMBIENT_MAGIC
;
767 r
= unit_full_printf(u
, f
, &path
);
769 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
770 "Failed to resolve unit specifiers in '%s'%s: %m",
771 f
, ignore
? ", ignoring" : "");
772 return ignore
? 0 : -ENOEXEC
;
776 /* First word is either "-" or "@" with no command. */
777 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
778 "Empty path in command line%s: '%s'",
779 ignore
? ", ignoring" : "", rvalue
);
780 return ignore
? 0 : -ENOEXEC
;
782 if (!string_is_safe(path
)) {
783 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
784 "Executable name contains special characters%s: %s",
785 ignore
? ", ignoring" : "", path
);
786 return ignore
? 0 : -ENOEXEC
;
788 if (endswith(path
, "/")) {
789 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
790 "Executable path specifies a directory%s: %s",
791 ignore
? ", ignoring" : "", path
);
792 return ignore
? 0 : -ENOEXEC
;
795 if (!path_is_absolute(path
) && !filename_is_valid(path
)) {
796 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
797 "Neither a valid executable name nor an absolute path%s: %s",
798 ignore
? ", ignoring" : "", path
);
799 return ignore
? 0 : -ENOEXEC
;
802 if (!separate_argv0
) {
805 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
815 path_simplify(path
, false);
817 while (!isempty(p
)) {
818 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
820 /* Check explicitly for an unquoted semicolon as
821 * command separator token. */
822 if (p
[0] == ';' && (!p
[1] || strchr(WHITESPACE
, p
[1]))) {
824 p
+= strspn(p
, WHITESPACE
);
829 /* Check for \; explicitly, to not confuse it with \\; or "\;" or "\\;" etc.
830 * extract_first_word() would return the same for all of those. */
831 if (p
[0] == '\\' && p
[1] == ';' && (!p
[2] || strchr(WHITESPACE
, p
[2]))) {
835 p
+= strspn(p
, WHITESPACE
);
837 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
848 r
= extract_first_word_and_warn(&p
, &word
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
852 return ignore
? 0 : -ENOEXEC
;
854 r
= unit_full_printf(u
, word
, &resolved
);
856 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
857 "Failed to resolve unit specifiers in %s%s: %m",
858 word
, ignore
? ", ignoring" : "");
859 return ignore
? 0 : -ENOEXEC
;
862 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
865 n
[nlen
++] = TAKE_PTR(resolved
);
870 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
871 "Empty executable name or zeroeth argument%s: %s",
872 ignore
? ", ignoring" : "", rvalue
);
873 return ignore
? 0 : -ENOEXEC
;
876 nce
= new0(ExecCommand
, 1);
880 nce
->argv
= TAKE_PTR(n
);
881 nce
->path
= TAKE_PTR(path
);
884 exec_command_append_list(e
, nce
);
886 /* Do not _cleanup_free_ these. */
895 int config_parse_socket_bindtodevice(
897 const char *filename
,
900 unsigned section_line
,
914 if (isempty(rvalue
) || streq(rvalue
, "*")) {
915 s
->bind_to_device
= mfree(s
->bind_to_device
);
919 if (!ifname_valid(rvalue
)) {
920 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid interface name, ignoring: %s", rvalue
);
924 return free_and_strdup_warn(&s
->bind_to_device
, rvalue
);
927 int config_parse_exec_input(
929 const char *filename
,
932 unsigned section_line
,
939 ExecContext
*c
= data
;
940 const Unit
*u
= userdata
;
950 n
= startswith(rvalue
, "fd:");
952 _cleanup_free_
char *resolved
= NULL
;
954 r
= unit_full_printf(u
, n
, &resolved
);
956 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", n
);
960 if (isempty(resolved
))
961 resolved
= mfree(resolved
);
962 else if (!fdname_is_valid(resolved
)) {
963 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", resolved
);
967 free_and_replace(c
->stdio_fdname
[STDIN_FILENO
], resolved
);
969 ei
= EXEC_INPUT_NAMED_FD
;
971 } else if ((n
= startswith(rvalue
, "file:"))) {
972 _cleanup_free_
char *resolved
= NULL
;
974 r
= unit_full_printf(u
, n
, &resolved
);
976 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", n
);
980 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
984 free_and_replace(c
->stdio_file
[STDIN_FILENO
], resolved
);
986 ei
= EXEC_INPUT_FILE
;
989 ei
= exec_input_from_string(rvalue
);
991 log_syntax(unit
, LOG_WARNING
, filename
, line
, ei
, "Failed to parse input specifier, ignoring: %s", rvalue
);
1000 int config_parse_exec_input_text(
1002 const char *filename
,
1004 const char *section
,
1005 unsigned section_line
,
1012 _cleanup_free_
char *unescaped
= NULL
, *resolved
= NULL
;
1013 ExecContext
*c
= data
;
1014 const Unit
*u
= userdata
;
1024 if (isempty(rvalue
)) {
1025 /* Reset if the empty string is assigned */
1026 c
->stdin_data
= mfree(c
->stdin_data
);
1027 c
->stdin_data_size
= 0;
1031 r
= cunescape(rvalue
, 0, &unescaped
);
1033 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1034 "Failed to decode C escaped text '%s', ignoring: %m", rvalue
);
1038 r
= unit_full_printf(u
, unescaped
, &resolved
);
1040 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1041 "Failed to resolve unit specifiers in '%s', ignoring: %m", unescaped
);
1045 sz
= strlen(resolved
);
1046 if (c
->stdin_data_size
+ sz
+ 1 < c
->stdin_data_size
|| /* check for overflow */
1047 c
->stdin_data_size
+ sz
+ 1 > EXEC_STDIN_DATA_MAX
) {
1048 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
1049 "Standard input data too large (%zu), maximum of %zu permitted, ignoring.",
1050 c
->stdin_data_size
+ sz
, (size_t) EXEC_STDIN_DATA_MAX
);
1054 p
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
+ 1);
1058 *((char*) mempcpy((char*) p
+ c
->stdin_data_size
, resolved
, sz
)) = '\n';
1061 c
->stdin_data_size
+= sz
+ 1;
1066 int config_parse_exec_input_data(
1068 const char *filename
,
1070 const char *section
,
1071 unsigned section_line
,
1078 _cleanup_free_
void *p
= NULL
;
1079 ExecContext
*c
= data
;
1089 if (isempty(rvalue
)) {
1090 /* Reset if the empty string is assigned */
1091 c
->stdin_data
= mfree(c
->stdin_data
);
1092 c
->stdin_data_size
= 0;
1096 r
= unbase64mem(rvalue
, (size_t) -1, &p
, &sz
);
1098 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1099 "Failed to decode base64 data, ignoring: %s", rvalue
);
1105 if (c
->stdin_data_size
+ sz
< c
->stdin_data_size
|| /* check for overflow */
1106 c
->stdin_data_size
+ sz
> EXEC_STDIN_DATA_MAX
) {
1107 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
1108 "Standard input data too large (%zu), maximum of %zu permitted, ignoring.",
1109 c
->stdin_data_size
+ sz
, (size_t) EXEC_STDIN_DATA_MAX
);
1113 q
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
);
1117 memcpy((uint8_t*) q
+ c
->stdin_data_size
, p
, sz
);
1120 c
->stdin_data_size
+= sz
;
1125 int config_parse_exec_output(
1127 const char *filename
,
1129 const char *section
,
1130 unsigned section_line
,
1137 _cleanup_free_
char *resolved
= NULL
;
1139 ExecContext
*c
= data
;
1140 const Unit
*u
= userdata
;
1141 bool obsolete
= false;
1151 n
= startswith(rvalue
, "fd:");
1153 r
= unit_full_printf(u
, n
, &resolved
);
1155 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", n
);
1159 if (isempty(resolved
))
1160 resolved
= mfree(resolved
);
1161 else if (!fdname_is_valid(resolved
)) {
1162 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", resolved
);
1166 eo
= EXEC_OUTPUT_NAMED_FD
;
1168 } else if (streq(rvalue
, "syslog")) {
1169 eo
= EXEC_OUTPUT_JOURNAL
;
1172 } else if (streq(rvalue
, "syslog+console")) {
1173 eo
= EXEC_OUTPUT_JOURNAL_AND_CONSOLE
;
1176 } else if ((n
= startswith(rvalue
, "file:"))) {
1178 r
= unit_full_printf(u
, n
, &resolved
);
1180 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", n
);
1184 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1188 eo
= EXEC_OUTPUT_FILE
;
1190 } else if ((n
= startswith(rvalue
, "append:"))) {
1192 r
= unit_full_printf(u
, n
, &resolved
);
1194 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", n
);
1198 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1202 eo
= EXEC_OUTPUT_FILE_APPEND
;
1204 } else if ((n
= startswith(rvalue
, "truncate:"))) {
1206 r
= unit_full_printf(u
, n
, &resolved
);
1208 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", n
);
1212 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1216 eo
= EXEC_OUTPUT_FILE_TRUNCATE
;
1218 eo
= exec_output_from_string(rvalue
);
1220 log_syntax(unit
, LOG_WARNING
, filename
, line
, eo
, "Failed to parse output specifier, ignoring: %s", rvalue
);
1226 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
1227 "Standard output type %s is obsolete, automatically updating to %s. Please update your unit file, and consider removing the setting altogether.",
1228 rvalue
, exec_output_to_string(eo
));
1230 if (streq(lvalue
, "StandardOutput")) {
1231 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1232 free_and_replace(c
->stdio_fdname
[STDOUT_FILENO
], resolved
);
1234 free_and_replace(c
->stdio_file
[STDOUT_FILENO
], resolved
);
1239 assert(streq(lvalue
, "StandardError"));
1241 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1242 free_and_replace(c
->stdio_fdname
[STDERR_FILENO
], resolved
);
1244 free_and_replace(c
->stdio_file
[STDERR_FILENO
], resolved
);
1252 int config_parse_exec_io_class(const char *unit
,
1253 const char *filename
,
1255 const char *section
,
1256 unsigned section_line
,
1263 ExecContext
*c
= data
;
1271 if (isempty(rvalue
)) {
1272 c
->ioprio_set
= false;
1273 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE
, 0);
1277 x
= ioprio_class_from_string(rvalue
);
1279 log_syntax(unit
, LOG_WARNING
, filename
, line
, x
, "Failed to parse IO scheduling class, ignoring: %s", rvalue
);
1283 c
->ioprio
= IOPRIO_PRIO_VALUE(x
, IOPRIO_PRIO_DATA(c
->ioprio
));
1284 c
->ioprio_set
= true;
1289 int config_parse_exec_io_priority(const char *unit
,
1290 const char *filename
,
1292 const char *section
,
1293 unsigned section_line
,
1300 ExecContext
*c
= data
;
1308 if (isempty(rvalue
)) {
1309 c
->ioprio_set
= false;
1310 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE
, 0);
1314 r
= ioprio_parse_priority(rvalue
, &i
);
1316 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse IO priority, ignoring: %s", rvalue
);
1320 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_PRIO_CLASS(c
->ioprio
), i
);
1321 c
->ioprio_set
= true;
1326 int config_parse_exec_cpu_sched_policy(const char *unit
,
1327 const char *filename
,
1329 const char *section
,
1330 unsigned section_line
,
1337 ExecContext
*c
= data
;
1345 if (isempty(rvalue
)) {
1346 c
->cpu_sched_set
= false;
1347 c
->cpu_sched_policy
= SCHED_OTHER
;
1348 c
->cpu_sched_priority
= 0;
1352 x
= sched_policy_from_string(rvalue
);
1354 log_syntax(unit
, LOG_WARNING
, filename
, line
, x
, "Failed to parse CPU scheduling policy, ignoring: %s", rvalue
);
1358 c
->cpu_sched_policy
= x
;
1359 /* Moving to or from real-time policy? We need to adjust the priority */
1360 c
->cpu_sched_priority
= CLAMP(c
->cpu_sched_priority
, sched_get_priority_min(x
), sched_get_priority_max(x
));
1361 c
->cpu_sched_set
= true;
1366 int config_parse_exec_mount_apivfs(const char *unit
,
1367 const char *filename
,
1369 const char *section
,
1370 unsigned section_line
,
1377 ExecContext
*c
= data
;
1385 if (isempty(rvalue
)) {
1386 c
->mount_apivfs_set
= false;
1387 c
->mount_apivfs
= false;
1391 k
= parse_boolean(rvalue
);
1393 log_syntax(unit
, LOG_WARNING
, filename
, line
, k
,
1394 "Failed to parse boolean value, ignoring: %s",
1399 c
->mount_apivfs_set
= true;
1400 c
->mount_apivfs
= k
;
1404 int config_parse_numa_mask(const char *unit
,
1405 const char *filename
,
1407 const char *section
,
1408 unsigned section_line
,
1415 NUMAPolicy
*p
= data
;
1422 if (streq(rvalue
, "all")) {
1423 r
= numa_mask_add_all(&p
->nodes
);
1425 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1426 "Failed to create NUMA mask representing \"all\" NUMA nodes, ignoring: %m");
1428 r
= parse_cpu_set_extend(rvalue
, &p
->nodes
, true, unit
, filename
, line
, lvalue
);
1430 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse NUMA node mask, ignoring: %s", rvalue
);
1436 int config_parse_exec_cpu_sched_prio(const char *unit
,
1437 const char *filename
,
1439 const char *section
,
1440 unsigned section_line
,
1447 ExecContext
*c
= data
;
1455 r
= safe_atoi(rvalue
, &i
);
1457 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse CPU scheduling priority, ignoring: %s", rvalue
);
1461 /* On Linux RR/FIFO range from 1 to 99 and OTHER/BATCH may only be 0 */
1462 min
= sched_get_priority_min(c
->cpu_sched_policy
);
1463 max
= sched_get_priority_max(c
->cpu_sched_policy
);
1465 if (i
< min
|| i
> max
) {
1466 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "CPU scheduling priority is out of range, ignoring: %s", rvalue
);
1470 c
->cpu_sched_priority
= i
;
1471 c
->cpu_sched_set
= true;
1476 int config_parse_root_image_options(
1478 const char *filename
,
1480 const char *section
,
1481 unsigned section_line
,
1488 _cleanup_(mount_options_free_allp
) MountOptions
*options
= NULL
;
1489 _cleanup_strv_free_
char **l
= NULL
;
1490 char **first
= NULL
, **second
= NULL
;
1491 ExecContext
*c
= data
;
1492 const Unit
*u
= userdata
;
1500 if (isempty(rvalue
)) {
1501 c
->root_image_options
= mount_options_free_all(c
->root_image_options
);
1505 r
= strv_split_colon_pairs(&l
, rvalue
);
1509 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
1513 STRV_FOREACH_PAIR(first
, second
, l
) {
1514 MountOptions
*o
= NULL
;
1515 _cleanup_free_
char *mount_options_resolved
= NULL
;
1516 const char *mount_options
= NULL
, *partition
= "root";
1517 PartitionDesignator partition_designator
;
1519 /* Format is either 'root:foo' or 'foo' (root is implied) */
1520 if (!isempty(*second
)) {
1522 mount_options
= *second
;
1524 mount_options
= *first
;
1526 partition_designator
= partition_designator_from_string(partition
);
1527 if (partition_designator
< 0) {
1528 log_syntax(unit
, LOG_WARNING
, filename
, line
, partition_designator
,
1529 "Invalid partition name %s, ignoring", partition
);
1532 r
= unit_full_printf(u
, mount_options
, &mount_options_resolved
);
1534 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", mount_options
);
1538 o
= new(MountOptions
, 1);
1541 *o
= (MountOptions
) {
1542 .partition_designator
= partition_designator
,
1543 .options
= TAKE_PTR(mount_options_resolved
),
1545 LIST_APPEND(mount_options
, options
, TAKE_PTR(o
));
1548 /* empty spaces/separators only */
1549 if (LIST_IS_EMPTY(options
))
1550 c
->root_image_options
= mount_options_free_all(c
->root_image_options
);
1552 LIST_JOIN(mount_options
, c
->root_image_options
, options
);
1557 int config_parse_exec_root_hash(
1559 const char *filename
,
1561 const char *section
,
1562 unsigned section_line
,
1569 _cleanup_free_
void *roothash_decoded
= NULL
;
1570 ExecContext
*c
= data
;
1571 size_t roothash_decoded_size
= 0;
1579 if (isempty(rvalue
)) {
1580 /* Reset if the empty string is assigned */
1581 c
->root_hash_path
= mfree(c
->root_hash_path
);
1582 c
->root_hash
= mfree(c
->root_hash
);
1583 c
->root_hash_size
= 0;
1587 if (path_is_absolute(rvalue
)) {
1588 /* We have the path to a roothash to load and decode, eg: RootHash=/foo/bar.roothash */
1589 _cleanup_free_
char *p
= NULL
;
1595 free_and_replace(c
->root_hash_path
, p
);
1596 c
->root_hash
= mfree(c
->root_hash
);
1597 c
->root_hash_size
= 0;
1601 /* We have a roothash to decode, eg: RootHash=012345789abcdef */
1602 r
= unhexmem(rvalue
, strlen(rvalue
), &roothash_decoded
, &roothash_decoded_size
);
1604 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to decode RootHash=, ignoring: %s", rvalue
);
1607 if (roothash_decoded_size
< sizeof(sd_id128_t
)) {
1608 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "RootHash= is too short, ignoring: %s", rvalue
);
1612 free_and_replace(c
->root_hash
, roothash_decoded
);
1613 c
->root_hash_size
= roothash_decoded_size
;
1614 c
->root_hash_path
= mfree(c
->root_hash_path
);
1619 int config_parse_exec_root_hash_sig(
1621 const char *filename
,
1623 const char *section
,
1624 unsigned section_line
,
1631 _cleanup_free_
void *roothash_sig_decoded
= NULL
;
1633 ExecContext
*c
= data
;
1634 size_t roothash_sig_decoded_size
= 0;
1642 if (isempty(rvalue
)) {
1643 /* Reset if the empty string is assigned */
1644 c
->root_hash_sig_path
= mfree(c
->root_hash_sig_path
);
1645 c
->root_hash_sig
= mfree(c
->root_hash_sig
);
1646 c
->root_hash_sig_size
= 0;
1650 if (path_is_absolute(rvalue
)) {
1651 /* We have the path to a roothash signature to load and decode, eg: RootHashSignature=/foo/bar.roothash.p7s */
1652 _cleanup_free_
char *p
= NULL
;
1658 free_and_replace(c
->root_hash_sig_path
, p
);
1659 c
->root_hash_sig
= mfree(c
->root_hash_sig
);
1660 c
->root_hash_sig_size
= 0;
1664 if (!(value
= startswith(rvalue
, "base64:"))) {
1665 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
1666 "Failed to decode RootHashSignature=, not a path but doesn't start with 'base64:', ignoring: %s", rvalue
);
1670 /* We have a roothash signature to decode, eg: RootHashSignature=base64:012345789abcdef */
1671 r
= unbase64mem(value
, strlen(value
), &roothash_sig_decoded
, &roothash_sig_decoded_size
);
1673 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to decode RootHashSignature=, ignoring: %s", rvalue
);
1677 free_and_replace(c
->root_hash_sig
, roothash_sig_decoded
);
1678 c
->root_hash_sig_size
= roothash_sig_decoded_size
;
1679 c
->root_hash_sig_path
= mfree(c
->root_hash_sig_path
);
1684 int config_parse_exec_cpu_affinity(
1686 const char *filename
,
1688 const char *section
,
1689 unsigned section_line
,
1696 ExecContext
*c
= data
;
1704 if (streq(rvalue
, "numa")) {
1705 c
->cpu_affinity_from_numa
= true;
1706 cpu_set_reset(&c
->cpu_set
);
1711 r
= parse_cpu_set_extend(rvalue
, &c
->cpu_set
, true, unit
, filename
, line
, lvalue
);
1713 c
->cpu_affinity_from_numa
= false;
1718 int config_parse_capability_set(
1720 const char *filename
,
1722 const char *section
,
1723 unsigned section_line
,
1730 uint64_t *capability_set
= data
;
1731 uint64_t sum
= 0, initial
= 0;
1732 bool invert
= false;
1740 if (rvalue
[0] == '~') {
1745 if (streq(lvalue
, "CapabilityBoundingSet"))
1746 initial
= CAP_ALL
; /* initialized to all bits on */
1747 /* else "AmbientCapabilities" initialized to all bits off */
1749 r
= capability_set_from_string(rvalue
, &sum
);
1751 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= specifier '%s', ignoring: %m", lvalue
, rvalue
);
1755 if (sum
== 0 || *capability_set
== initial
)
1756 /* "", "~" or uninitialized data -> replace */
1757 *capability_set
= invert
? ~sum
: sum
;
1759 /* previous data -> merge */
1761 *capability_set
&= ~sum
;
1763 *capability_set
|= sum
;
1769 int config_parse_exec_selinux_context(
1771 const char *filename
,
1773 const char *section
,
1774 unsigned section_line
,
1781 ExecContext
*c
= data
;
1782 const Unit
*u
= userdata
;
1792 if (isempty(rvalue
)) {
1793 c
->selinux_context
= mfree(c
->selinux_context
);
1794 c
->selinux_context_ignore
= false;
1798 if (rvalue
[0] == '-') {
1804 r
= unit_full_printf(u
, rvalue
, &k
);
1806 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
1807 "Failed to resolve unit specifiers in '%s'%s: %m",
1808 rvalue
, ignore
? ", ignoring" : "");
1809 return ignore
? 0 : -ENOEXEC
;
1812 free_and_replace(c
->selinux_context
, k
);
1813 c
->selinux_context_ignore
= ignore
;
1818 int config_parse_exec_apparmor_profile(
1820 const char *filename
,
1822 const char *section
,
1823 unsigned section_line
,
1830 ExecContext
*c
= data
;
1831 const Unit
*u
= userdata
;
1841 if (isempty(rvalue
)) {
1842 c
->apparmor_profile
= mfree(c
->apparmor_profile
);
1843 c
->apparmor_profile_ignore
= false;
1847 if (rvalue
[0] == '-') {
1853 r
= unit_full_printf(u
, rvalue
, &k
);
1855 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
1856 "Failed to resolve unit specifiers in '%s'%s: %m",
1857 rvalue
, ignore
? ", ignoring" : "");
1858 return ignore
? 0 : -ENOEXEC
;
1861 free_and_replace(c
->apparmor_profile
, k
);
1862 c
->apparmor_profile_ignore
= ignore
;
1867 int config_parse_exec_smack_process_label(
1869 const char *filename
,
1871 const char *section
,
1872 unsigned section_line
,
1879 ExecContext
*c
= data
;
1880 const Unit
*u
= userdata
;
1890 if (isempty(rvalue
)) {
1891 c
->smack_process_label
= mfree(c
->smack_process_label
);
1892 c
->smack_process_label_ignore
= false;
1896 if (rvalue
[0] == '-') {
1902 r
= unit_full_printf(u
, rvalue
, &k
);
1904 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
1905 "Failed to resolve unit specifiers in '%s'%s: %m",
1906 rvalue
, ignore
? ", ignoring" : "");
1907 return ignore
? 0 : -ENOEXEC
;
1910 free_and_replace(c
->smack_process_label
, k
);
1911 c
->smack_process_label_ignore
= ignore
;
1916 int config_parse_timer(
1918 const char *filename
,
1920 const char *section
,
1921 unsigned section_line
,
1928 _cleanup_(calendar_spec_freep
) CalendarSpec
*c
= NULL
;
1929 _cleanup_free_
char *k
= NULL
;
1930 const Unit
*u
= userdata
;
1941 if (isempty(rvalue
)) {
1942 /* Empty assignment resets list */
1943 timer_free_values(t
);
1947 r
= unit_full_printf(u
, rvalue
, &k
);
1949 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
1953 if (ltype
== TIMER_CALENDAR
) {
1954 r
= calendar_spec_from_string(k
, &c
);
1956 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse calendar specification, ignoring: %s", k
);
1960 r
= parse_sec(k
, &usec
);
1962 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse timer value, ignoring: %s", k
);
1967 v
= new(TimerValue
, 1);
1974 .calendar_spec
= TAKE_PTR(c
),
1977 LIST_PREPEND(value
, t
->values
, v
);
1982 int config_parse_trigger_unit(
1984 const char *filename
,
1986 const char *section
,
1987 unsigned section_line
,
1994 _cleanup_free_
char *p
= NULL
;
2004 if (!hashmap_isempty(u
->dependencies
[UNIT_TRIGGERS
])) {
2005 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Multiple units to trigger specified, ignoring: %s", rvalue
);
2009 r
= unit_name_printf(u
, rvalue
, &p
);
2011 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2015 type
= unit_name_to_type(p
);
2017 log_syntax(unit
, LOG_WARNING
, filename
, line
, type
, "Unit type not valid, ignoring: %s", rvalue
);
2020 if (unit_has_name(u
, p
)) {
2021 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Units cannot trigger themselves, ignoring: %s", rvalue
);
2025 r
= unit_add_two_dependencies_by_name(u
, UNIT_BEFORE
, UNIT_TRIGGERS
, p
, true, UNIT_DEPENDENCY_FILE
);
2027 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add trigger on %s, ignoring: %m", p
);
2034 int config_parse_path_spec(const char *unit
,
2035 const char *filename
,
2037 const char *section
,
2038 unsigned section_line
,
2048 _cleanup_free_
char *k
= NULL
;
2056 if (isempty(rvalue
)) {
2057 /* Empty assignment clears list */
2062 b
= path_type_from_string(lvalue
);
2064 log_syntax(unit
, LOG_WARNING
, filename
, line
, b
, "Failed to parse path type, ignoring: %s", lvalue
);
2068 r
= unit_full_printf(UNIT(p
), rvalue
, &k
);
2070 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2074 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2078 s
= new0(PathSpec
, 1);
2083 s
->path
= TAKE_PTR(k
);
2087 LIST_PREPEND(spec
, p
->specs
, s
);
2092 int config_parse_socket_service(
2094 const char *filename
,
2096 const char *section
,
2097 unsigned section_line
,
2104 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
2105 _cleanup_free_
char *p
= NULL
;
2115 r
= unit_name_printf(UNIT(s
), rvalue
, &p
);
2117 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2121 if (!endswith(p
, ".service")) {
2122 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Unit must be of type service, ignoring: %s", rvalue
);
2126 r
= manager_load_unit(UNIT(s
)->manager
, p
, NULL
, &error
, &x
);
2128 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to load unit %s, ignoring: %s", rvalue
, bus_error_message(&error
, r
));
2132 unit_ref_set(&s
->service
, UNIT(s
), x
);
2137 int config_parse_fdname(
2139 const char *filename
,
2141 const char *section
,
2142 unsigned section_line
,
2149 _cleanup_free_
char *p
= NULL
;
2158 if (isempty(rvalue
)) {
2159 s
->fdname
= mfree(s
->fdname
);
2163 r
= unit_full_printf(UNIT(s
), rvalue
, &p
);
2165 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2169 if (!fdname_is_valid(p
)) {
2170 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", p
);
2174 return free_and_replace(s
->fdname
, p
);
2177 int config_parse_service_sockets(
2179 const char *filename
,
2181 const char *section
,
2182 unsigned section_line
,
2197 for (const char *p
= rvalue
;;) {
2198 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2200 r
= extract_first_word(&p
, &word
, NULL
, 0);
2206 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Trailing garbage in sockets, ignoring: %s", rvalue
);
2210 r
= unit_name_printf(UNIT(s
), word
, &k
);
2212 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
2216 if (!endswith(k
, ".socket")) {
2217 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Unit must be of type socket, ignoring: %s", k
);
2221 r
= unit_add_two_dependencies_by_name(UNIT(s
), UNIT_WANTS
, UNIT_AFTER
, k
, true, UNIT_DEPENDENCY_FILE
);
2223 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
2225 r
= unit_add_dependency_by_name(UNIT(s
), UNIT_TRIGGERED_BY
, k
, true, UNIT_DEPENDENCY_FILE
);
2227 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
2231 int config_parse_bus_name(
2233 const char *filename
,
2235 const char *section
,
2236 unsigned section_line
,
2243 _cleanup_free_
char *k
= NULL
;
2244 const Unit
*u
= userdata
;
2252 r
= unit_full_printf(u
, rvalue
, &k
);
2254 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2258 if (!sd_bus_service_name_is_valid(k
)) {
2259 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid bus name, ignoring: %s", k
);
2263 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
2266 int config_parse_service_timeout(
2268 const char *filename
,
2270 const char *section
,
2271 unsigned section_line
,
2278 Service
*s
= userdata
;
2287 /* This is called for two cases: TimeoutSec= and TimeoutStartSec=. */
2289 /* Traditionally, these options accepted 0 to disable the timeouts. However, a timeout of 0 suggests it happens
2290 * immediately, hence fix this to become USEC_INFINITY instead. This is in-line with how we internally handle
2291 * all other timeouts. */
2292 r
= parse_sec_fix_0(rvalue
, &usec
);
2294 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
2298 s
->start_timeout_defined
= true;
2299 s
->timeout_start_usec
= usec
;
2301 if (streq(lvalue
, "TimeoutSec"))
2302 s
->timeout_stop_usec
= usec
;
2307 int config_parse_timeout_abort(
2309 const char *filename
,
2311 const char *section
,
2312 unsigned section_line
,
2327 /* Note: apart from setting the arg, this returns an extra bit of information in the return value. */
2329 if (isempty(rvalue
)) {
2331 return 0; /* "not set" */
2334 r
= parse_sec(rvalue
, ret
);
2336 return log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= setting, ignoring: %s", lvalue
, rvalue
);
2338 return 1; /* "set" */
2341 int config_parse_service_timeout_abort(
2343 const char *filename
,
2345 const char *section
,
2346 unsigned section_line
,
2353 Service
*s
= userdata
;
2358 r
= config_parse_timeout_abort(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
,
2359 &s
->timeout_abort_usec
, s
);
2361 s
->timeout_abort_set
= r
;
2365 int config_parse_sec_fix_0(
2367 const char *filename
,
2369 const char *section
,
2370 unsigned section_line
,
2377 usec_t
*usec
= data
;
2385 /* This is pretty much like config_parse_sec(), except that this treats a time of 0 as infinity, for
2386 * compatibility with older versions of systemd where 0 instead of infinity was used as indicator to turn off a
2389 r
= parse_sec_fix_0(rvalue
, usec
);
2391 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
2396 int config_parse_user_group_compat(
2398 const char *filename
,
2400 const char *section
,
2401 unsigned section_line
,
2408 _cleanup_free_
char *k
= NULL
;
2410 const Unit
*u
= userdata
;
2418 if (isempty(rvalue
)) {
2419 *user
= mfree(*user
);
2423 r
= unit_full_printf(u
, rvalue
, &k
);
2425 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", rvalue
);
2429 if (!valid_user_group_name(k
, VALID_USER_ALLOW_NUMERIC
|VALID_USER_RELAX
|VALID_USER_WARN
)) {
2430 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2434 if (strstr(lvalue
, "User") && streq(k
, NOBODY_USER_NAME
))
2435 log_struct(LOG_NOTICE
,
2436 "MESSAGE=%s:%u: Special user %s configured, this is not safe!", filename
, line
, k
,
2438 "MESSAGE_ID=" SD_MESSAGE_NOBODY_USER_UNSUITABLE_STR
,
2439 "OFFENDING_USER=%s", k
,
2440 "CONFIG_FILE=%s", filename
,
2441 "CONFIG_LINE=%u", line
);
2443 return free_and_replace(*user
, k
);
2446 int config_parse_user_group_strv_compat(
2448 const char *filename
,
2450 const char *section
,
2451 unsigned section_line
,
2458 char ***users
= data
;
2459 const Unit
*u
= userdata
;
2467 if (isempty(rvalue
)) {
2468 *users
= strv_free(*users
);
2472 for (const char *p
= rvalue
;;) {
2473 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2475 r
= extract_first_word(&p
, &word
, NULL
, 0);
2481 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax: %s", rvalue
);
2485 r
= unit_full_printf(u
, word
, &k
);
2487 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", word
);
2491 if (!valid_user_group_name(k
, VALID_USER_ALLOW_NUMERIC
|VALID_USER_RELAX
|VALID_USER_WARN
)) {
2492 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2496 r
= strv_push(users
, k
);
2504 int config_parse_working_directory(
2506 const char *filename
,
2508 const char *section
,
2509 unsigned section_line
,
2516 ExecContext
*c
= data
;
2517 const Unit
*u
= userdata
;
2527 if (isempty(rvalue
)) {
2528 c
->working_directory_home
= false;
2529 c
->working_directory
= mfree(c
->working_directory
);
2533 if (rvalue
[0] == '-') {
2539 if (streq(rvalue
, "~")) {
2540 c
->working_directory_home
= true;
2541 c
->working_directory
= mfree(c
->working_directory
);
2543 _cleanup_free_
char *k
= NULL
;
2545 r
= unit_full_printf(u
, rvalue
, &k
);
2547 log_syntax(unit
, missing_ok
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
2548 "Failed to resolve unit specifiers in working directory path '%s'%s: %m",
2549 rvalue
, missing_ok
? ", ignoring" : "");
2550 return missing_ok
? 0 : -ENOEXEC
;
2553 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
| (missing_ok
? 0 : PATH_CHECK_FATAL
), unit
, filename
, line
, lvalue
);
2555 return missing_ok
? 0 : -ENOEXEC
;
2557 c
->working_directory_home
= false;
2558 free_and_replace(c
->working_directory
, k
);
2561 c
->working_directory_missing_ok
= missing_ok
;
2565 int config_parse_unit_env_file(const char *unit
,
2566 const char *filename
,
2568 const char *section
,
2569 unsigned section_line
,
2577 const Unit
*u
= userdata
;
2578 _cleanup_free_
char *n
= NULL
;
2586 if (isempty(rvalue
)) {
2587 /* Empty assignment frees the list */
2588 *env
= strv_free(*env
);
2592 r
= unit_full_printf(u
, rvalue
, &n
);
2594 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2598 r
= path_simplify_and_warn(n
[0] == '-' ? n
+ 1 : n
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2602 r
= strv_push(env
, n
);
2611 int config_parse_environ(
2613 const char *filename
,
2615 const char *section
,
2616 unsigned section_line
,
2623 const Unit
*u
= userdata
;
2632 if (isempty(rvalue
)) {
2633 /* Empty assignment resets the list */
2634 *env
= strv_free(*env
);
2638 for (const char *p
= rvalue
;; ) {
2639 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
2641 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2647 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2648 "Invalid syntax, ignoring: %s", rvalue
);
2653 r
= unit_full_printf(u
, word
, &resolved
);
2655 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2656 "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2660 resolved
= TAKE_PTR(word
);
2662 if (!env_assignment_is_valid(resolved
)) {
2663 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
2664 "Invalid environment assignment, ignoring: %s", resolved
);
2668 r
= strv_env_replace_consume(env
, TAKE_PTR(resolved
));
2670 return log_error_errno(r
, "Failed to update environment: %m");
2674 int config_parse_pass_environ(
2676 const char *filename
,
2678 const char *section
,
2679 unsigned section_line
,
2686 _cleanup_strv_free_
char **n
= NULL
;
2687 size_t nlen
= 0, nbufsize
= 0;
2688 char*** passenv
= data
;
2689 const Unit
*u
= userdata
;
2697 if (isempty(rvalue
)) {
2698 /* Empty assignment resets the list */
2699 *passenv
= strv_free(*passenv
);
2703 for (const char *p
= rvalue
;;) {
2704 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2706 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
2712 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2713 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2718 r
= unit_full_printf(u
, word
, &k
);
2720 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2721 "Failed to resolve specifiers in %s, ignoring: %m", word
);
2727 if (!env_name_is_valid(k
)) {
2728 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
2729 "Invalid environment name for %s, ignoring: %s", lvalue
, k
);
2733 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
2736 n
[nlen
++] = TAKE_PTR(k
);
2741 r
= strv_extend_strv(passenv
, n
, true);
2749 int config_parse_unset_environ(
2751 const char *filename
,
2753 const char *section
,
2754 unsigned section_line
,
2761 _cleanup_strv_free_
char **n
= NULL
;
2762 size_t nlen
= 0, nbufsize
= 0;
2763 char*** unsetenv
= data
;
2764 const Unit
*u
= userdata
;
2772 if (isempty(rvalue
)) {
2773 /* Empty assignment resets the list */
2774 *unsetenv
= strv_free(*unsetenv
);
2778 for (const char *p
= rvalue
;;) {
2779 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2781 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2787 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2788 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2793 r
= unit_full_printf(u
, word
, &k
);
2795 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2796 "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2802 if (!env_assignment_is_valid(k
) && !env_name_is_valid(k
)) {
2803 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
2804 "Invalid environment name or assignment %s, ignoring: %s", lvalue
, k
);
2808 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
2811 n
[nlen
++] = TAKE_PTR(k
);
2816 r
= strv_extend_strv(unsetenv
, n
, true);
2824 int config_parse_log_extra_fields(
2826 const char *filename
,
2828 const char *section
,
2829 unsigned section_line
,
2836 ExecContext
*c
= data
;
2837 const Unit
*u
= userdata
;
2845 if (isempty(rvalue
)) {
2846 exec_context_free_log_extra_fields(c
);
2850 for (const char *p
= rvalue
;;) {
2851 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2855 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2861 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
2865 r
= unit_full_printf(u
, word
, &k
);
2867 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2871 eq
= strchr(k
, '=');
2873 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Log field lacks '=' character, ignoring: %s", k
);
2877 if (!journal_field_valid(k
, eq
-k
, false)) {
2878 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Log field name is invalid, ignoring: %s", k
);
2882 t
= reallocarray(c
->log_extra_fields
, c
->n_log_extra_fields
+1, sizeof(struct iovec
));
2886 c
->log_extra_fields
= t
;
2887 c
->log_extra_fields
[c
->n_log_extra_fields
++] = IOVEC_MAKE_STRING(k
);
2893 int config_parse_log_namespace(
2895 const char *filename
,
2897 const char *section
,
2898 unsigned section_line
,
2905 _cleanup_free_
char *k
= NULL
;
2906 ExecContext
*c
= data
;
2907 const Unit
*u
= userdata
;
2915 if (isempty(rvalue
)) {
2916 c
->log_namespace
= mfree(c
->log_namespace
);
2920 r
= unit_full_printf(u
, rvalue
, &k
);
2922 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2926 if (!log_namespace_name_valid(k
)) {
2927 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Specified log namespace name is not valid, ignoring: %s", k
);
2931 free_and_replace(c
->log_namespace
, k
);
2935 int config_parse_unit_condition_path(
2937 const char *filename
,
2939 const char *section
,
2940 unsigned section_line
,
2947 _cleanup_free_
char *p
= NULL
;
2948 Condition
**list
= data
, *c
;
2949 ConditionType t
= ltype
;
2950 bool trigger
, negate
;
2951 const Unit
*u
= userdata
;
2959 if (isempty(rvalue
)) {
2960 /* Empty assignment resets the list */
2961 *list
= condition_free_list(*list
);
2965 trigger
= rvalue
[0] == '|';
2969 negate
= rvalue
[0] == '!';
2973 r
= unit_full_printf(u
, rvalue
, &p
);
2975 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2979 r
= path_simplify_and_warn(p
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2983 c
= condition_new(t
, p
, trigger
, negate
);
2987 LIST_PREPEND(conditions
, *list
, c
);
2991 int config_parse_unit_condition_string(
2993 const char *filename
,
2995 const char *section
,
2996 unsigned section_line
,
3003 _cleanup_free_
char *s
= NULL
;
3004 Condition
**list
= data
, *c
;
3005 ConditionType t
= ltype
;
3006 bool trigger
, negate
;
3007 const Unit
*u
= userdata
;
3015 if (isempty(rvalue
)) {
3016 /* Empty assignment resets the list */
3017 *list
= condition_free_list(*list
);
3021 trigger
= *rvalue
== '|';
3023 rvalue
+= 1 + strspn(rvalue
+ 1, WHITESPACE
);
3025 negate
= *rvalue
== '!';
3027 rvalue
+= 1 + strspn(rvalue
+ 1, WHITESPACE
);
3029 r
= unit_full_printf(u
, rvalue
, &s
);
3031 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3032 "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
3036 c
= condition_new(t
, s
, trigger
, negate
);
3040 LIST_PREPEND(conditions
, *list
, c
);
3044 int config_parse_unit_requires_mounts_for(
3046 const char *filename
,
3048 const char *section
,
3049 unsigned section_line
,
3064 for (const char *p
= rvalue
;;) {
3065 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
3067 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3073 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3074 "Invalid syntax, ignoring: %s", rvalue
);
3078 r
= unit_full_printf(u
, word
, &resolved
);
3080 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
3084 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
3088 r
= unit_require_mounts_for(u
, resolved
, UNIT_DEPENDENCY_FILE
);
3090 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add required mount '%s', ignoring: %m", resolved
);
3096 int config_parse_documentation(
3098 const char *filename
,
3100 const char *section
,
3101 unsigned section_line
,
3117 if (isempty(rvalue
)) {
3118 /* Empty assignment resets the list */
3119 u
->documentation
= strv_free(u
->documentation
);
3123 r
= config_parse_unit_strv_printf(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
,
3124 rvalue
, data
, userdata
);
3128 for (a
= b
= u
->documentation
; a
&& *a
; a
++) {
3130 if (documentation_url_is_valid(*a
))
3133 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid URL, ignoring: %s", *a
);
3144 int config_parse_syscall_filter(
3146 const char *filename
,
3148 const char *section
,
3149 unsigned section_line
,
3156 ExecContext
*c
= data
;
3157 _unused_
const Unit
*u
= userdata
;
3158 bool invert
= false;
3166 if (isempty(rvalue
)) {
3167 /* Empty assignment resets the list */
3168 c
->syscall_filter
= hashmap_free(c
->syscall_filter
);
3169 c
->syscall_allow_list
= false;
3173 if (rvalue
[0] == '~') {
3178 if (!c
->syscall_filter
) {
3179 c
->syscall_filter
= hashmap_new(NULL
);
3180 if (!c
->syscall_filter
)
3184 /* Allow everything but the ones listed */
3185 c
->syscall_allow_list
= false;
3187 /* Allow nothing but the ones listed */
3188 c
->syscall_allow_list
= true;
3190 /* Accept default syscalls if we are on a allow_list */
3191 r
= seccomp_parse_syscall_filter(
3192 "@default", -1, c
->syscall_filter
,
3193 SECCOMP_PARSE_PERMISSIVE
|SECCOMP_PARSE_ALLOW_LIST
,
3201 for (const char *p
= rvalue
;;) {
3202 _cleanup_free_
char *word
= NULL
, *name
= NULL
;
3205 r
= extract_first_word(&p
, &word
, NULL
, 0);
3211 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3215 r
= parse_syscall_and_errno(word
, &name
, &num
);
3217 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse syscall:errno, ignoring: %s", word
);
3221 r
= seccomp_parse_syscall_filter(
3222 name
, num
, c
->syscall_filter
,
3223 SECCOMP_PARSE_LOG
|SECCOMP_PARSE_PERMISSIVE
|
3224 (invert
? SECCOMP_PARSE_INVERT
: 0)|
3225 (c
->syscall_allow_list
? SECCOMP_PARSE_ALLOW_LIST
: 0),
3226 unit
, filename
, line
);
3232 int config_parse_syscall_log(
3234 const char *filename
,
3236 const char *section
,
3237 unsigned section_line
,
3244 ExecContext
*c
= data
;
3245 _unused_
const Unit
*u
= userdata
;
3246 bool invert
= false;
3255 if (isempty(rvalue
)) {
3256 /* Empty assignment resets the list */
3257 c
->syscall_log
= hashmap_free(c
->syscall_log
);
3258 c
->syscall_log_allow_list
= false;
3262 if (rvalue
[0] == '~') {
3267 if (!c
->syscall_log
) {
3268 c
->syscall_log
= hashmap_new(NULL
);
3269 if (!c
->syscall_log
)
3273 /* Log everything but the ones listed */
3274 c
->syscall_log_allow_list
= false;
3276 /* Log nothing but the ones listed */
3277 c
->syscall_log_allow_list
= true;
3282 _cleanup_free_
char *word
= NULL
, *name
= NULL
;
3285 r
= extract_first_word(&p
, &word
, NULL
, 0);
3291 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3295 r
= parse_syscall_and_errno(word
, &name
, &num
);
3296 if (r
< 0 || num
>= 0) { /* errno code not allowed */
3297 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse syscall, ignoring: %s", word
);
3301 r
= seccomp_parse_syscall_filter(
3302 name
, 0, c
->syscall_log
,
3303 SECCOMP_PARSE_LOG
|SECCOMP_PARSE_PERMISSIVE
|
3304 (invert
? SECCOMP_PARSE_INVERT
: 0)|
3305 (c
->syscall_log_allow_list
? SECCOMP_PARSE_ALLOW_LIST
: 0),
3306 unit
, filename
, line
);
3312 int config_parse_syscall_archs(
3314 const char *filename
,
3316 const char *section
,
3317 unsigned section_line
,
3327 if (isempty(rvalue
)) {
3328 *archs
= set_free(*archs
);
3332 for (const char *p
= rvalue
;;) {
3333 _cleanup_free_
char *word
= NULL
;
3336 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3342 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3343 "Invalid syntax, ignoring: %s", rvalue
);
3347 r
= seccomp_arch_from_string(word
, &a
);
3349 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3350 "Failed to parse system call architecture \"%s\", ignoring: %m", word
);
3354 r
= set_ensure_put(archs
, NULL
, UINT32_TO_PTR(a
+ 1));
3360 int config_parse_syscall_errno(
3362 const char *filename
,
3364 const char *section
,
3365 unsigned section_line
,
3372 ExecContext
*c
= data
;
3379 if (isempty(rvalue
) || streq(rvalue
, "kill")) {
3380 /* Empty assignment resets to KILL */
3381 c
->syscall_errno
= SECCOMP_ERROR_NUMBER_KILL
;
3385 e
= parse_errno(rvalue
);
3387 log_syntax(unit
, LOG_WARNING
, filename
, line
, e
, "Failed to parse error number, ignoring: %s", rvalue
);
3391 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid error number, ignoring: %s", rvalue
);
3395 c
->syscall_errno
= e
;
3399 int config_parse_address_families(
3401 const char *filename
,
3403 const char *section
,
3404 unsigned section_line
,
3411 ExecContext
*c
= data
;
3412 bool invert
= false;
3419 if (isempty(rvalue
)) {
3420 /* Empty assignment resets the list */
3421 c
->address_families
= set_free(c
->address_families
);
3422 c
->address_families_allow_list
= false;
3426 if (rvalue
[0] == '~') {
3431 if (!c
->address_families
) {
3432 c
->address_families
= set_new(NULL
);
3433 if (!c
->address_families
)
3436 c
->address_families_allow_list
= !invert
;
3439 for (const char *p
= rvalue
;;) {
3440 _cleanup_free_
char *word
= NULL
;
3443 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3449 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3450 "Invalid syntax, ignoring: %s", rvalue
);
3454 af
= af_from_name(word
);
3456 log_syntax(unit
, LOG_WARNING
, filename
, line
, af
,
3457 "Failed to parse address family, ignoring: %s", word
);
3461 /* If we previously wanted to forbid an address family and now
3462 * we want to allow it, then just remove it from the list.
3464 if (!invert
== c
->address_families_allow_list
) {
3465 r
= set_put(c
->address_families
, INT_TO_PTR(af
));
3469 set_remove(c
->address_families
, INT_TO_PTR(af
));
3473 int config_parse_restrict_namespaces(
3475 const char *filename
,
3477 const char *section
,
3478 unsigned section_line
,
3485 ExecContext
*c
= data
;
3486 unsigned long flags
;
3487 bool invert
= false;
3490 if (isempty(rvalue
)) {
3491 /* Reset to the default. */
3492 c
->restrict_namespaces
= NAMESPACE_FLAGS_INITIAL
;
3496 /* Boolean parameter ignores the previous settings */
3497 r
= parse_boolean(rvalue
);
3499 c
->restrict_namespaces
= 0;
3501 } else if (r
== 0) {
3502 c
->restrict_namespaces
= NAMESPACE_FLAGS_ALL
;
3506 if (rvalue
[0] == '~') {
3511 /* Not a boolean argument, in this case it's a list of namespace types. */
3512 r
= namespace_flags_from_string(rvalue
, &flags
);
3514 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse namespace type string, ignoring: %s", rvalue
);
3518 if (c
->restrict_namespaces
== NAMESPACE_FLAGS_INITIAL
)
3519 /* Initial assignment. Just set the value. */
3520 c
->restrict_namespaces
= invert
? (~flags
) & NAMESPACE_FLAGS_ALL
: flags
;
3522 /* Merge the value with the previous one. */
3523 SET_FLAG(c
->restrict_namespaces
, flags
, !invert
);
3529 int config_parse_unit_slice(
3531 const char *filename
,
3533 const char *section
,
3534 unsigned section_line
,
3541 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
3542 _cleanup_free_
char *k
= NULL
;
3543 Unit
*u
= userdata
, *slice
;
3551 r
= unit_name_printf(u
, rvalue
, &k
);
3553 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
3557 r
= manager_load_unit(u
->manager
, k
, NULL
, &error
, &slice
);
3559 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to load slice unit %s, ignoring: %s", k
, bus_error_message(&error
, r
));
3563 r
= unit_set_slice(u
, slice
);
3565 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to assign slice %s to unit %s, ignoring: %m", slice
->id
, u
->id
);
3572 int config_parse_cpu_quota(
3574 const char *filename
,
3576 const char *section
,
3577 unsigned section_line
,
3584 CGroupContext
*c
= data
;
3591 if (isempty(rvalue
)) {
3592 c
->cpu_quota_per_sec_usec
= USEC_INFINITY
;
3596 r
= parse_permille_unbounded(rvalue
);
3598 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid CPU quota '%s', ignoring.", rvalue
);
3602 c
->cpu_quota_per_sec_usec
= ((usec_t
) r
* USEC_PER_SEC
) / 1000U;
3606 int config_parse_allowed_cpus(
3608 const char *filename
,
3610 const char *section
,
3611 unsigned section_line
,
3618 CGroupContext
*c
= data
;
3620 (void) parse_cpu_set_extend(rvalue
, &c
->cpuset_cpus
, true, unit
, filename
, line
, lvalue
);
3625 int config_parse_allowed_mems(
3627 const char *filename
,
3629 const char *section
,
3630 unsigned section_line
,
3637 CGroupContext
*c
= data
;
3639 (void) parse_cpu_set_extend(rvalue
, &c
->cpuset_mems
, true, unit
, filename
, line
, lvalue
);
3644 int config_parse_memory_limit(
3646 const char *filename
,
3648 const char *section
,
3649 unsigned section_line
,
3656 CGroupContext
*c
= data
;
3657 uint64_t bytes
= CGROUP_LIMIT_MAX
;
3660 if (isempty(rvalue
) && STR_IN_SET(lvalue
, "DefaultMemoryLow",
3664 bytes
= CGROUP_LIMIT_MIN
;
3665 else if (!isempty(rvalue
) && !streq(rvalue
, "infinity")) {
3667 r
= parse_permille(rvalue
);
3669 r
= parse_size(rvalue
, 1024, &bytes
);
3671 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid memory limit '%s', ignoring: %m", rvalue
);
3675 bytes
= physical_memory_scale(r
, 1000U);
3677 if (bytes
>= UINT64_MAX
||
3678 (bytes
<= 0 && !STR_IN_SET(lvalue
, "MemorySwapMax", "MemoryLow", "MemoryMin", "DefaultMemoryLow", "DefaultMemoryMin"))) {
3679 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Memory limit '%s' out of range, ignoring.", rvalue
);
3684 if (streq(lvalue
, "DefaultMemoryLow")) {
3685 c
->default_memory_low
= bytes
;
3686 c
->default_memory_low_set
= true;
3687 } else if (streq(lvalue
, "DefaultMemoryMin")) {
3688 c
->default_memory_min
= bytes
;
3689 c
->default_memory_min_set
= true;
3690 } else if (streq(lvalue
, "MemoryMin")) {
3691 c
->memory_min
= bytes
;
3692 c
->memory_min_set
= true;
3693 } else if (streq(lvalue
, "MemoryLow")) {
3694 c
->memory_low
= bytes
;
3695 c
->memory_low_set
= true;
3696 } else if (streq(lvalue
, "MemoryHigh"))
3697 c
->memory_high
= bytes
;
3698 else if (streq(lvalue
, "MemoryMax"))
3699 c
->memory_max
= bytes
;
3700 else if (streq(lvalue
, "MemorySwapMax"))
3701 c
->memory_swap_max
= bytes
;
3702 else if (streq(lvalue
, "MemoryLimit"))
3703 c
->memory_limit
= bytes
;
3710 int config_parse_tasks_max(
3712 const char *filename
,
3714 const char *section
,
3715 unsigned section_line
,
3722 const Unit
*u
= userdata
;
3723 TasksMax
*tasks_max
= data
;
3727 if (isempty(rvalue
)) {
3728 *tasks_max
= u
? u
->manager
->default_tasks_max
: TASKS_MAX_UNSET
;
3732 if (streq(rvalue
, "infinity")) {
3733 *tasks_max
= TASKS_MAX_UNSET
;
3737 r
= parse_permille(rvalue
);
3739 *tasks_max
= (TasksMax
) { r
, 1000U }; /* r‰ */
3741 r
= safe_atou64(rvalue
, &v
);
3743 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid maximum tasks value '%s', ignoring: %m", rvalue
);
3747 if (v
<= 0 || v
>= UINT64_MAX
) {
3748 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Maximum tasks value '%s' out of range, ignoring.", rvalue
);
3752 *tasks_max
= (TasksMax
) { v
};
3758 int config_parse_delegate(
3760 const char *filename
,
3762 const char *section
,
3763 unsigned section_line
,
3770 CGroupContext
*c
= data
;
3774 t
= unit_name_to_type(unit
);
3775 assert(t
!= _UNIT_TYPE_INVALID
);
3777 if (!unit_vtable
[t
]->can_delegate
) {
3778 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Delegate= setting not supported for this unit type, ignoring.");
3782 /* We either accept a boolean value, which may be used to turn on delegation for all controllers, or turn it
3783 * off for all. Or it takes a list of controller names, in which case we add the specified controllers to the
3784 * mask to delegate. */
3786 if (isempty(rvalue
)) {
3787 /* An empty string resets controllers and set Delegate=yes. */
3789 c
->delegate_controllers
= 0;
3793 r
= parse_boolean(rvalue
);
3795 CGroupMask mask
= 0;
3797 for (const char *p
= rvalue
;;) {
3798 _cleanup_free_
char *word
= NULL
;
3799 CGroupController cc
;
3801 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3807 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3811 cc
= cgroup_controller_from_string(word
);
3813 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid controller name '%s', ignoring", word
);
3817 mask
|= CGROUP_CONTROLLER_TO_MASK(cc
);
3821 c
->delegate_controllers
|= mask
;
3825 c
->delegate_controllers
= _CGROUP_MASK_ALL
;
3827 c
->delegate
= false;
3828 c
->delegate_controllers
= 0;
3834 int config_parse_managed_oom_mode(
3836 const char *filename
,
3838 const char *section
,
3839 unsigned section_line
,
3845 ManagedOOMMode
*mode
= data
, m
;
3848 t
= unit_name_to_type(unit
);
3849 assert(t
!= _UNIT_TYPE_INVALID
);
3851 if (!unit_vtable
[t
]->can_set_managed_oom
)
3852 return log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "%s= is not supported for this unit type, ignoring.", lvalue
);
3854 if (isempty(rvalue
)) {
3855 *mode
= MANAGED_OOM_AUTO
;
3859 m
= managed_oom_mode_from_string(rvalue
);
3861 log_syntax(unit
, LOG_WARNING
, filename
, line
, m
, "Invalid syntax, ignoring: %s", rvalue
);
3868 int config_parse_managed_oom_mem_pressure_limit(
3870 const char *filename
,
3872 const char *section
,
3873 unsigned section_line
,
3879 uint32_t *limit
= data
;
3883 t
= unit_name_to_type(unit
);
3884 assert(t
!= _UNIT_TYPE_INVALID
);
3886 if (!unit_vtable
[t
]->can_set_managed_oom
)
3887 return log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "%s= is not supported for this unit type, ignoring.", lvalue
);
3889 if (isempty(rvalue
)) {
3894 r
= parse_permyriad(rvalue
);
3896 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse memory pressure limit value, ignoring: %s", rvalue
);
3904 int config_parse_device_allow(
3906 const char *filename
,
3908 const char *section
,
3909 unsigned section_line
,
3916 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3917 CGroupContext
*c
= data
;
3918 const char *p
= rvalue
;
3921 if (isempty(rvalue
)) {
3922 while (c
->device_allow
)
3923 cgroup_context_free_device_allow(c
, c
->device_allow
);
3928 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3932 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3933 "Invalid syntax, ignoring: %s", rvalue
);
3937 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3938 "Failed to extract device path and rights from '%s', ignoring.", rvalue
);
3942 r
= unit_full_printf(userdata
, path
, &resolved
);
3944 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3945 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3949 if (!STARTSWITH_SET(resolved
, "block-", "char-")) {
3951 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3955 if (!valid_device_node_path(resolved
)) {
3956 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid device node path '%s', ignoring.", resolved
);
3961 if (!isempty(p
) && !in_charset(p
, "rwm")) {
3962 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid device rights '%s', ignoring.", p
);
3966 return cgroup_add_device_allow(c
, resolved
, p
);
3969 int config_parse_io_device_weight(
3971 const char *filename
,
3973 const char *section
,
3974 unsigned section_line
,
3981 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3982 CGroupIODeviceWeight
*w
;
3983 CGroupContext
*c
= data
;
3984 const char *p
= rvalue
;
3992 if (isempty(rvalue
)) {
3993 while (c
->io_device_weights
)
3994 cgroup_context_free_io_device_weight(c
, c
->io_device_weights
);
3999 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4003 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4004 "Invalid syntax, ignoring: %s", rvalue
);
4007 if (r
== 0 || isempty(p
)) {
4008 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4009 "Failed to extract device path and weight from '%s', ignoring.", rvalue
);
4013 r
= unit_full_printf(userdata
, path
, &resolved
);
4015 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4016 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4020 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4024 r
= cg_weight_parse(p
, &u
);
4026 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "IO weight '%s' invalid, ignoring: %m", p
);
4030 assert(u
!= CGROUP_WEIGHT_INVALID
);
4032 w
= new0(CGroupIODeviceWeight
, 1);
4036 w
->path
= TAKE_PTR(resolved
);
4039 LIST_PREPEND(device_weights
, c
->io_device_weights
, w
);
4043 int config_parse_io_device_latency(
4045 const char *filename
,
4047 const char *section
,
4048 unsigned section_line
,
4055 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4056 CGroupIODeviceLatency
*l
;
4057 CGroupContext
*c
= data
;
4058 const char *p
= rvalue
;
4066 if (isempty(rvalue
)) {
4067 while (c
->io_device_latencies
)
4068 cgroup_context_free_io_device_latency(c
, c
->io_device_latencies
);
4073 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4077 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4078 "Invalid syntax, ignoring: %s", rvalue
);
4081 if (r
== 0 || isempty(p
)) {
4082 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4083 "Failed to extract device path and latency from '%s', ignoring.", rvalue
);
4087 r
= unit_full_printf(userdata
, path
, &resolved
);
4089 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4090 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4094 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4098 r
= parse_sec(p
, &usec
);
4100 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse timer value, ignoring: %s", p
);
4104 l
= new0(CGroupIODeviceLatency
, 1);
4108 l
->path
= TAKE_PTR(resolved
);
4109 l
->target_usec
= usec
;
4111 LIST_PREPEND(device_latencies
, c
->io_device_latencies
, l
);
4115 int config_parse_io_limit(
4117 const char *filename
,
4119 const char *section
,
4120 unsigned section_line
,
4127 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4128 CGroupIODeviceLimit
*l
= NULL
, *t
;
4129 CGroupContext
*c
= data
;
4130 CGroupIOLimitType type
;
4131 const char *p
= rvalue
;
4139 type
= cgroup_io_limit_type_from_string(lvalue
);
4142 if (isempty(rvalue
)) {
4143 LIST_FOREACH(device_limits
, l
, c
->io_device_limits
)
4144 l
->limits
[type
] = cgroup_io_limit_defaults
[type
];
4148 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4152 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4153 "Invalid syntax, ignoring: %s", rvalue
);
4156 if (r
== 0 || isempty(p
)) {
4157 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4158 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
4162 r
= unit_full_printf(userdata
, path
, &resolved
);
4164 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4165 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4169 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4173 if (streq("infinity", p
))
4174 num
= CGROUP_LIMIT_MAX
;
4176 r
= parse_size(p
, 1000, &num
);
4177 if (r
< 0 || num
<= 0) {
4178 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid IO limit '%s', ignoring.", p
);
4183 LIST_FOREACH(device_limits
, t
, c
->io_device_limits
) {
4184 if (path_equal(resolved
, t
->path
)) {
4191 CGroupIOLimitType ttype
;
4193 l
= new0(CGroupIODeviceLimit
, 1);
4197 l
->path
= TAKE_PTR(resolved
);
4198 for (ttype
= 0; ttype
< _CGROUP_IO_LIMIT_TYPE_MAX
; ttype
++)
4199 l
->limits
[ttype
] = cgroup_io_limit_defaults
[ttype
];
4201 LIST_PREPEND(device_limits
, c
->io_device_limits
, l
);
4204 l
->limits
[type
] = num
;
4209 int config_parse_blockio_device_weight(
4211 const char *filename
,
4213 const char *section
,
4214 unsigned section_line
,
4221 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4222 CGroupBlockIODeviceWeight
*w
;
4223 CGroupContext
*c
= data
;
4224 const char *p
= rvalue
;
4232 if (isempty(rvalue
)) {
4233 while (c
->blockio_device_weights
)
4234 cgroup_context_free_blockio_device_weight(c
, c
->blockio_device_weights
);
4239 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4243 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4244 "Invalid syntax, ignoring: %s", rvalue
);
4247 if (r
== 0 || isempty(p
)) {
4248 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4249 "Failed to extract device node and weight from '%s', ignoring.", rvalue
);
4253 r
= unit_full_printf(userdata
, path
, &resolved
);
4255 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4256 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4260 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4264 r
= cg_blkio_weight_parse(p
, &u
);
4266 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid block IO weight '%s', ignoring: %m", p
);
4270 assert(u
!= CGROUP_BLKIO_WEIGHT_INVALID
);
4272 w
= new0(CGroupBlockIODeviceWeight
, 1);
4276 w
->path
= TAKE_PTR(resolved
);
4279 LIST_PREPEND(device_weights
, c
->blockio_device_weights
, w
);
4283 int config_parse_blockio_bandwidth(
4285 const char *filename
,
4287 const char *section
,
4288 unsigned section_line
,
4295 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4296 CGroupBlockIODeviceBandwidth
*b
= NULL
, *t
;
4297 CGroupContext
*c
= data
;
4298 const char *p
= rvalue
;
4307 read
= streq("BlockIOReadBandwidth", lvalue
);
4309 if (isempty(rvalue
)) {
4310 LIST_FOREACH(device_bandwidths
, b
, c
->blockio_device_bandwidths
) {
4311 b
->rbps
= CGROUP_LIMIT_MAX
;
4312 b
->wbps
= CGROUP_LIMIT_MAX
;
4317 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4321 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4322 "Invalid syntax, ignoring: %s", rvalue
);
4325 if (r
== 0 || isempty(p
)) {
4326 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4327 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
4331 r
= unit_full_printf(userdata
, path
, &resolved
);
4333 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4334 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4338 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4342 r
= parse_size(p
, 1000, &bytes
);
4343 if (r
< 0 || bytes
<= 0) {
4344 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid Block IO Bandwidth '%s', ignoring.", p
);
4348 LIST_FOREACH(device_bandwidths
, t
, c
->blockio_device_bandwidths
) {
4349 if (path_equal(resolved
, t
->path
)) {
4356 b
= new0(CGroupBlockIODeviceBandwidth
, 1);
4360 b
->path
= TAKE_PTR(resolved
);
4361 b
->rbps
= CGROUP_LIMIT_MAX
;
4362 b
->wbps
= CGROUP_LIMIT_MAX
;
4364 LIST_PREPEND(device_bandwidths
, c
->blockio_device_bandwidths
, b
);
4375 int config_parse_job_mode_isolate(
4377 const char *filename
,
4379 const char *section
,
4380 unsigned section_line
,
4394 r
= parse_boolean(rvalue
);
4396 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse boolean, ignoring: %s", rvalue
);
4400 log_notice("%s is deprecated. Please use OnFailureJobMode= instead", lvalue
);
4402 *m
= r
? JOB_ISOLATE
: JOB_REPLACE
;
4406 int config_parse_exec_directories(
4408 const char *filename
,
4410 const char *section
,
4411 unsigned section_line
,
4419 const Unit
*u
= userdata
;
4427 if (isempty(rvalue
)) {
4428 /* Empty assignment resets the list */
4429 *rt
= strv_free(*rt
);
4433 for (const char *p
= rvalue
;;) {
4434 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
4436 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
4440 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4441 "Invalid syntax, ignoring: %s", rvalue
);
4447 r
= unit_full_printf(u
, word
, &k
);
4449 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4450 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
4454 r
= path_simplify_and_warn(k
, PATH_CHECK_RELATIVE
, unit
, filename
, line
, lvalue
);
4458 if (path_startswith(k
, "private")) {
4459 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4460 "%s= path can't be 'private', ignoring assignment: %s", lvalue
, word
);
4464 r
= strv_push(rt
, k
);
4471 int config_parse_set_credential(
4473 const char *filename
,
4475 const char *section
,
4476 unsigned section_line
,
4483 _cleanup_free_
char *word
= NULL
, *k
= NULL
, *unescaped
= NULL
;
4484 ExecContext
*context
= data
;
4485 ExecSetCredential
*old
;
4495 if (isempty(rvalue
)) {
4496 /* Empty assignment resets the list */
4497 context
->set_credentials
= hashmap_free(context
->set_credentials
);
4502 r
= extract_first_word(&p
, &word
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4506 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
4510 r
= unit_full_printf(u
, word
, &k
);
4512 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
4515 if (!credential_name_valid(k
)) {
4516 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Credential name \"%s\" not valid, ignoring.", k
);
4520 /* We support escape codes here, so that users can insert trailing \n if they like */
4521 l
= cunescape(p
, UNESCAPE_ACCEPT_NUL
, &unescaped
);
4523 log_syntax(unit
, LOG_WARNING
, filename
, line
, l
, "Can't unescape \"%s\", ignoring: %m", p
);
4527 old
= hashmap_get(context
->set_credentials
, k
);
4529 free_and_replace(old
->data
, unescaped
);
4532 _cleanup_(exec_set_credential_freep
) ExecSetCredential
*sc
= NULL
;
4534 sc
= new0(ExecSetCredential
, 1);
4538 sc
->id
= TAKE_PTR(k
);
4539 sc
->data
= TAKE_PTR(unescaped
);
4542 r
= hashmap_ensure_put(&context
->set_credentials
, &exec_set_credential_hash_ops
, sc
->id
, sc
);
4546 log_syntax(unit
, LOG_WARNING
, filename
, line
, l
,
4547 "Duplicated credential value '%s', ignoring assignment: %s", sc
->id
, rvalue
);
4557 int config_parse_load_credential(
4559 const char *filename
,
4561 const char *section
,
4562 unsigned section_line
,
4569 _cleanup_free_
char *word
= NULL
, *k
= NULL
, *q
= NULL
;
4570 ExecContext
*context
= data
;
4580 if (isempty(rvalue
)) {
4581 /* Empty assignment resets the list */
4582 context
->load_credentials
= strv_free(context
->load_credentials
);
4587 r
= extract_first_word(&p
, &word
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4591 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
4595 r
= unit_full_printf(u
, word
, &k
);
4597 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
4600 if (!credential_name_valid(k
)) {
4601 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Credential name \"%s\" not valid, ignoring.", k
);
4604 r
= unit_full_printf(u
, p
, &q
);
4606 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", p
);
4609 if (path_is_absolute(q
) ? !path_is_normalized(q
) : !credential_name_valid(q
)) {
4610 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Credential source \"%s\" not valid, ignoring.", q
);
4614 r
= strv_consume_pair(&context
->load_credentials
, TAKE_PTR(k
), TAKE_PTR(q
));
4621 int config_parse_set_status(
4623 const char *filename
,
4625 const char *section
,
4626 unsigned section_line
,
4633 ExitStatusSet
*status_set
= data
;
4641 /* Empty assignment resets the list */
4642 if (isempty(rvalue
)) {
4643 exit_status_set_free(status_set
);
4647 for (const char *p
= rvalue
;;) {
4648 _cleanup_free_
char *word
= NULL
;
4651 r
= extract_first_word(&p
, &word
, NULL
, 0);
4655 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4656 "Failed to parse %s=%s, ignoring: %m", lvalue
, rvalue
);
4662 /* We need to call exit_status_from_string() first, because we want
4663 * to parse numbers as exit statuses, not signals. */
4665 r
= exit_status_from_string(word
);
4667 assert(r
>= 0 && r
< 256);
4668 bitmap
= &status_set
->status
;
4670 r
= signal_from_string(word
);
4672 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4673 "Failed to parse value, ignoring: %s", word
);
4676 bitmap
= &status_set
->signal
;
4679 r
= bitmap_set(bitmap
, r
);
4681 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4682 "Failed to set signal or status %s, ignoring: %m", word
);
4686 int config_parse_namespace_path_strv(
4688 const char *filename
,
4690 const char *section
,
4691 unsigned section_line
,
4698 const Unit
*u
= userdata
;
4707 if (isempty(rvalue
)) {
4708 /* Empty assignment resets the list */
4709 *sv
= strv_free(*sv
);
4713 for (const char *p
= rvalue
;;) {
4714 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
, *joined
= NULL
;
4716 bool ignore_enoent
= false, shall_prefix
= false;
4718 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
4724 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
4729 if (startswith(w
, "-")) {
4730 ignore_enoent
= true;
4733 if (startswith(w
, "+")) {
4734 shall_prefix
= true;
4738 r
= unit_full_printf(u
, w
, &resolved
);
4740 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", w
);
4744 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4748 joined
= strjoin(ignore_enoent
? "-" : "",
4749 shall_prefix
? "+" : "",
4752 r
= strv_push(sv
, joined
);
4762 int config_parse_temporary_filesystems(
4764 const char *filename
,
4766 const char *section
,
4767 unsigned section_line
,
4774 const Unit
*u
= userdata
;
4775 ExecContext
*c
= data
;
4783 if (isempty(rvalue
)) {
4784 /* Empty assignment resets the list */
4785 temporary_filesystem_free_many(c
->temporary_filesystems
, c
->n_temporary_filesystems
);
4786 c
->temporary_filesystems
= NULL
;
4787 c
->n_temporary_filesystems
= 0;
4791 for (const char *p
= rvalue
;;) {
4792 _cleanup_free_
char *word
= NULL
, *path
= NULL
, *resolved
= NULL
;
4795 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
4801 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
4806 r
= extract_first_word(&w
, &path
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4810 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", word
);
4814 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid syntax, ignoring: %s", word
);
4818 r
= unit_full_printf(u
, path
, &resolved
);
4820 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", path
);
4824 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4828 r
= temporary_filesystem_add(&c
->temporary_filesystems
, &c
->n_temporary_filesystems
, resolved
, w
);
4834 int config_parse_bind_paths(
4836 const char *filename
,
4838 const char *section
,
4839 unsigned section_line
,
4846 ExecContext
*c
= data
;
4847 const Unit
*u
= userdata
;
4855 if (isempty(rvalue
)) {
4856 /* Empty assignment resets the list */
4857 bind_mount_free_many(c
->bind_mounts
, c
->n_bind_mounts
);
4858 c
->bind_mounts
= NULL
;
4859 c
->n_bind_mounts
= 0;
4863 for (const char *p
= rvalue
;;) {
4864 _cleanup_free_
char *source
= NULL
, *destination
= NULL
;
4865 _cleanup_free_
char *sresolved
= NULL
, *dresolved
= NULL
;
4866 char *s
= NULL
, *d
= NULL
;
4867 bool rbind
= true, ignore_enoent
= false;
4869 r
= extract_first_word(&p
, &source
, ":" WHITESPACE
, EXTRACT_UNQUOTE
|EXTRACT_DONT_COALESCE_SEPARATORS
);
4875 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
4879 r
= unit_full_printf(u
, source
, &sresolved
);
4881 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4882 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", source
);
4888 ignore_enoent
= true;
4892 r
= path_simplify_and_warn(s
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4896 /* Optionally, the destination is specified. */
4897 if (p
&& p
[-1] == ':') {
4898 r
= extract_first_word(&p
, &destination
, ":" WHITESPACE
, EXTRACT_UNQUOTE
|EXTRACT_DONT_COALESCE_SEPARATORS
);
4902 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
4906 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Missing argument after ':', ignoring: %s", s
);
4910 r
= unit_full_printf(u
, destination
, &dresolved
);
4912 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4913 "Failed to resolve specifiers in \"%s\", ignoring: %m", destination
);
4917 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4923 /* Optionally, there's also a short option string specified */
4924 if (p
&& p
[-1] == ':') {
4925 _cleanup_free_
char *options
= NULL
;
4927 r
= extract_first_word(&p
, &options
, NULL
, EXTRACT_UNQUOTE
);
4931 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s: %s", lvalue
, rvalue
);
4935 if (isempty(options
) || streq(options
, "rbind"))
4937 else if (streq(options
, "norbind"))
4940 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid option string, ignoring setting: %s", options
);
4947 r
= bind_mount_add(&c
->bind_mounts
, &c
->n_bind_mounts
,
4951 .read_only
= !!strstr(lvalue
, "ReadOnly"),
4953 .ignore_enoent
= ignore_enoent
,
4962 int config_parse_mount_images(
4964 const char *filename
,
4966 const char *section
,
4967 unsigned section_line
,
4974 ExecContext
*c
= data
;
4975 const Unit
*u
= userdata
;
4983 if (isempty(rvalue
)) {
4984 /* Empty assignment resets the list */
4985 c
->mount_images
= mount_image_free_many(c
->mount_images
, &c
->n_mount_images
);
4989 for (const char *p
= rvalue
;;) {
4990 _cleanup_(mount_options_free_allp
) MountOptions
*options
= NULL
;
4991 _cleanup_free_
char *first
= NULL
, *second
= NULL
, *tuple
= NULL
;
4992 _cleanup_free_
char *sresolved
= NULL
, *dresolved
= NULL
;
4993 const char *q
= NULL
;
4995 bool permissive
= false;
4997 r
= extract_first_word(&p
, &tuple
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_RETAIN_ESCAPE
);
5001 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5002 "Invalid syntax %s=%s, ignoring: %m", lvalue
, rvalue
);
5009 r
= extract_many_words(&q
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
, &first
, &second
, NULL
);
5013 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5014 "Invalid syntax in %s=, ignoring: %s", lvalue
, tuple
);
5020 r
= unit_full_printf(u
, first
, &sresolved
);
5022 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5023 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", first
);
5033 r
= path_simplify_and_warn(s
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5037 if (isempty(second
)) {
5038 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Missing destination in %s, ignoring: %s", lvalue
, rvalue
);
5042 r
= unit_full_printf(u
, second
, &dresolved
);
5044 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5045 "Failed to resolve specifiers in \"%s\", ignoring: %m", second
);
5049 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5054 _cleanup_free_
char *partition
= NULL
, *mount_options
= NULL
, *mount_options_resolved
= NULL
;
5055 MountOptions
*o
= NULL
;
5056 PartitionDesignator partition_designator
;
5058 r
= extract_many_words(&q
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
, &partition
, &mount_options
, NULL
);
5062 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", q
);
5067 /* Single set of options, applying to the root partition/single filesystem */
5069 r
= unit_full_printf(u
, partition
, &mount_options_resolved
);
5071 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", first
);
5075 o
= new(MountOptions
, 1);
5078 *o
= (MountOptions
) {
5079 .partition_designator
= PARTITION_ROOT
,
5080 .options
= TAKE_PTR(mount_options_resolved
),
5082 LIST_APPEND(mount_options
, options
, o
);
5087 partition_designator
= partition_designator_from_string(partition
);
5088 if (partition_designator
< 0) {
5089 log_syntax(unit
, LOG_WARNING
, filename
, line
, partition_designator
,
5090 "Invalid partition name %s, ignoring", partition
);
5093 r
= unit_full_printf(u
, mount_options
, &mount_options_resolved
);
5095 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", mount_options
);
5099 o
= new(MountOptions
, 1);
5102 *o
= (MountOptions
) {
5103 .partition_designator
= partition_designator
,
5104 .options
= TAKE_PTR(mount_options_resolved
),
5106 LIST_APPEND(mount_options
, options
, o
);
5109 r
= mount_image_add(&c
->mount_images
, &c
->n_mount_images
,
5112 .destination
= dresolved
,
5113 .mount_options
= options
,
5114 .ignore_enoent
= permissive
,
5121 int config_parse_job_timeout_sec(
5123 const char *filename
,
5125 const char *section
,
5126 unsigned section_line
,
5142 r
= parse_sec_fix_0(rvalue
, &usec
);
5144 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse JobTimeoutSec= parameter, ignoring: %s", rvalue
);
5148 /* If the user explicitly changed JobTimeoutSec= also change JobRunningTimeoutSec=, for compatibility with old
5149 * versions. If JobRunningTimeoutSec= was explicitly set, avoid this however as whatever the user picked should
5152 if (!u
->job_running_timeout_set
)
5153 u
->job_running_timeout
= usec
;
5155 u
->job_timeout
= usec
;
5160 int config_parse_job_running_timeout_sec(
5162 const char *filename
,
5164 const char *section
,
5165 unsigned section_line
,
5181 r
= parse_sec_fix_0(rvalue
, &usec
);
5183 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse JobRunningTimeoutSec= parameter, ignoring: %s", rvalue
);
5187 u
->job_running_timeout
= usec
;
5188 u
->job_running_timeout_set
= true;
5193 int config_parse_emergency_action(
5195 const char *filename
,
5197 const char *section
,
5198 unsigned section_line
,
5206 EmergencyAction
*x
= data
;
5215 m
= ((Unit
*) userdata
)->manager
;
5219 r
= parse_emergency_action(rvalue
, MANAGER_IS_SYSTEM(m
), x
);
5221 if (r
== -EOPNOTSUPP
&& MANAGER_IS_USER(m
)) {
5222 /* Compat mode: remove for systemd 241. */
5224 log_syntax(unit
, LOG_INFO
, filename
, line
, r
,
5225 "%s= in user mode specified as \"%s\", using \"exit-force\" instead.",
5227 *x
= EMERGENCY_ACTION_EXIT_FORCE
;
5231 if (r
== -EOPNOTSUPP
)
5232 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5233 "%s= specified as %s mode action, ignoring: %s",
5234 lvalue
, MANAGER_IS_SYSTEM(m
) ? "user" : "system", rvalue
);
5236 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5237 "Failed to parse %s=, ignoring: %s", lvalue
, rvalue
);
5244 int config_parse_pid_file(
5246 const char *filename
,
5248 const char *section
,
5249 unsigned section_line
,
5256 _cleanup_free_
char *k
= NULL
, *n
= NULL
;
5257 const Unit
*u
= userdata
;
5266 if (isempty(rvalue
)) {
5267 /* An empty assignment removes already set value. */
5272 r
= unit_full_printf(u
, rvalue
, &k
);
5274 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
5278 /* If this is a relative path make it absolute by prefixing the /run */
5279 n
= path_make_absolute(k
, u
->manager
->prefix
[EXEC_DIRECTORY_RUNTIME
]);
5283 /* Check that the result is a sensible path */
5284 r
= path_simplify_and_warn(n
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5288 r
= patch_var_run(unit
, filename
, line
, lvalue
, &n
);
5292 free_and_replace(*s
, n
);
5296 int config_parse_exit_status(
5298 const char *filename
,
5300 const char *section
,
5301 unsigned section_line
,
5308 int *exit_status
= data
, r
;
5314 assert(exit_status
);
5316 if (isempty(rvalue
)) {
5321 r
= safe_atou8(rvalue
, &u
);
5323 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse exit status '%s', ignoring: %m", rvalue
);
5331 int config_parse_disable_controllers(
5333 const char *filename
,
5335 const char *section
,
5336 unsigned section_line
,
5344 CGroupContext
*c
= data
;
5345 CGroupMask disabled_mask
;
5347 /* 1. If empty, make all controllers eligible for use again.
5348 * 2. If non-empty, merge all listed controllers, space separated. */
5350 if (isempty(rvalue
)) {
5351 c
->disable_controllers
= 0;
5355 r
= cg_mask_from_string(rvalue
, &disabled_mask
);
5356 if (r
< 0 || disabled_mask
<= 0) {
5357 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid cgroup string: %s, ignoring", rvalue
);
5361 c
->disable_controllers
|= disabled_mask
;
5366 int config_parse_ip_filter_bpf_progs(
5368 const char *filename
,
5370 const char *section
,
5371 unsigned section_line
,
5378 _cleanup_free_
char *resolved
= NULL
;
5379 const Unit
*u
= userdata
;
5380 char ***paths
= data
;
5388 if (isempty(rvalue
)) {
5389 *paths
= strv_free(*paths
);
5393 r
= unit_full_printf(u
, rvalue
, &resolved
);
5395 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
5399 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5403 if (strv_contains(*paths
, resolved
))
5406 r
= strv_extend(paths
, resolved
);
5410 r
= bpf_firewall_supported();
5413 if (r
!= BPF_FIREWALL_SUPPORTED_WITH_MULTI
) {
5414 static bool warned
= false;
5416 log_full(warned
? LOG_DEBUG
: LOG_WARNING
,
5417 "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"
5418 "Starting this unit will fail! (This warning is only shown for the first loaded unit using IP firewalling.)", filename
, line
, lvalue
, rvalue
);
5426 static int merge_by_names(Unit
**u
, Set
*names
, const char *id
) {
5433 /* Let's try to add in all names that are aliases of this unit */
5434 while ((k
= set_steal_first(names
))) {
5435 _cleanup_free_ _unused_
char *free_k
= k
;
5437 /* First try to merge in the other name into our unit */
5438 r
= unit_merge_by_name(*u
, k
);
5442 /* Hmm, we couldn't merge the other unit into ours? Then let's try it the other way
5445 other
= manager_get_unit((*u
)->manager
, k
);
5447 return r
; /* return previous failure */
5449 r
= unit_merge(other
, *u
);
5454 return merge_by_names(u
, names
, NULL
);
5457 if (streq_ptr(id
, k
))
5458 unit_choose_id(*u
, id
);
5464 int unit_load_fragment(Unit
*u
) {
5465 const char *fragment
;
5466 _cleanup_set_free_free_ Set
*names
= NULL
;
5470 assert(u
->load_state
== UNIT_STUB
);
5474 u
->load_state
= UNIT_LOADED
;
5478 /* Possibly rebuild the fragment map to catch new units */
5479 r
= unit_file_build_name_map(&u
->manager
->lookup_paths
,
5480 &u
->manager
->unit_cache_timestamp_hash
,
5481 &u
->manager
->unit_id_map
,
5482 &u
->manager
->unit_name_map
,
5483 &u
->manager
->unit_path_cache
);
5485 return log_error_errno(r
, "Failed to rebuild name map: %m");
5487 r
= unit_file_find_fragment(u
->manager
->unit_id_map
,
5488 u
->manager
->unit_name_map
,
5492 if (r
< 0 && r
!= -ENOENT
)
5496 /* Open the file, check if this is a mask, otherwise read. */
5497 _cleanup_fclose_
FILE *f
= NULL
;
5500 /* Try to open the file name. A symlink is OK, for example for linked files or masks. We
5501 * expect that all symlinks within the lookup paths have been already resolved, but we don't
5502 * verify this here. */
5503 f
= fopen(fragment
, "re");
5505 return log_unit_notice_errno(u
, errno
, "Failed to open %s: %m", fragment
);
5507 if (fstat(fileno(f
), &st
) < 0)
5510 r
= free_and_strdup(&u
->fragment_path
, fragment
);
5514 if (null_or_empty(&st
)) {
5515 /* Unit file is masked */
5517 u
->load_state
= u
->perpetual
? UNIT_LOADED
: UNIT_MASKED
; /* don't allow perpetual units to ever be masked */
5518 u
->fragment_mtime
= 0;
5520 u
->load_state
= UNIT_LOADED
;
5521 u
->fragment_mtime
= timespec_load(&st
.st_mtim
);
5523 /* Now, parse the file contents */
5524 r
= config_parse(u
->id
, fragment
, f
,
5525 UNIT_VTABLE(u
)->sections
,
5526 config_item_perf_lookup
, load_fragment_gperf_lookup
,
5531 log_unit_notice_errno(u
, r
, "Unit configuration has fatal error, unit will not be started.");
5537 /* We do the merge dance here because for some unit types, the unit might have aliases which are not
5538 * declared in the file system. In particular, this is true (and frequent) for device and swap units.
5541 const char *id
= u
->id
;
5542 _cleanup_free_
char *free_id
= NULL
;
5545 id
= basename(fragment
);
5546 if (unit_name_is_valid(id
, UNIT_NAME_TEMPLATE
)) {
5547 assert(u
->instance
); /* If we're not trying to use a template for non-instanced unit,
5548 * this must be set. */
5550 r
= unit_name_replace_instance(id
, u
->instance
, &free_id
);
5552 return log_debug_errno(r
, "Failed to build id (%s + %s): %m", id
, u
->instance
);
5558 r
= merge_by_names(&merged
, names
, id
);
5563 u
->load_state
= UNIT_MERGED
;
5568 void unit_dump_config_items(FILE *f
) {
5569 static const struct {
5570 const ConfigParserCallback callback
;
5573 { config_parse_warn_compat
, "NOTSUPPORTED" },
5574 { config_parse_int
, "INTEGER" },
5575 { config_parse_unsigned
, "UNSIGNED" },
5576 { config_parse_iec_size
, "SIZE" },
5577 { config_parse_iec_uint64
, "SIZE" },
5578 { config_parse_si_uint64
, "SIZE" },
5579 { config_parse_bool
, "BOOLEAN" },
5580 { config_parse_string
, "STRING" },
5581 { config_parse_path
, "PATH" },
5582 { config_parse_unit_path_printf
, "PATH" },
5583 { config_parse_strv
, "STRING [...]" },
5584 { config_parse_exec_nice
, "NICE" },
5585 { config_parse_exec_oom_score_adjust
, "OOMSCOREADJUST" },
5586 { config_parse_exec_io_class
, "IOCLASS" },
5587 { config_parse_exec_io_priority
, "IOPRIORITY" },
5588 { config_parse_exec_cpu_sched_policy
, "CPUSCHEDPOLICY" },
5589 { config_parse_exec_cpu_sched_prio
, "CPUSCHEDPRIO" },
5590 { config_parse_exec_cpu_affinity
, "CPUAFFINITY" },
5591 { config_parse_mode
, "MODE" },
5592 { config_parse_unit_env_file
, "FILE" },
5593 { config_parse_exec_output
, "OUTPUT" },
5594 { config_parse_exec_input
, "INPUT" },
5595 { config_parse_log_facility
, "FACILITY" },
5596 { config_parse_log_level
, "LEVEL" },
5597 { config_parse_exec_secure_bits
, "SECUREBITS" },
5598 { config_parse_capability_set
, "BOUNDINGSET" },
5599 { config_parse_rlimit
, "LIMIT" },
5600 { config_parse_unit_deps
, "UNIT [...]" },
5601 { config_parse_exec
, "PATH [ARGUMENT [...]]" },
5602 { config_parse_service_type
, "SERVICETYPE" },
5603 { config_parse_service_restart
, "SERVICERESTART" },
5604 { config_parse_service_timeout_failure_mode
, "TIMEOUTMODE" },
5605 { config_parse_kill_mode
, "KILLMODE" },
5606 { config_parse_signal
, "SIGNAL" },
5607 { config_parse_socket_listen
, "SOCKET [...]" },
5608 { config_parse_socket_bind
, "SOCKETBIND" },
5609 { config_parse_socket_bindtodevice
, "NETWORKINTERFACE" },
5610 { config_parse_sec
, "SECONDS" },
5611 { config_parse_nsec
, "NANOSECONDS" },
5612 { config_parse_namespace_path_strv
, "PATH [...]" },
5613 { config_parse_bind_paths
, "PATH[:PATH[:OPTIONS]] [...]" },
5614 { config_parse_unit_requires_mounts_for
, "PATH [...]" },
5615 { config_parse_exec_mount_flags
, "MOUNTFLAG [...]" },
5616 { config_parse_unit_string_printf
, "STRING" },
5617 { config_parse_trigger_unit
, "UNIT" },
5618 { config_parse_timer
, "TIMER" },
5619 { config_parse_path_spec
, "PATH" },
5620 { config_parse_notify_access
, "ACCESS" },
5621 { config_parse_ip_tos
, "TOS" },
5622 { config_parse_unit_condition_path
, "CONDITION" },
5623 { config_parse_unit_condition_string
, "CONDITION" },
5624 { config_parse_unit_slice
, "SLICE" },
5625 { config_parse_documentation
, "URL" },
5626 { config_parse_service_timeout
, "SECONDS" },
5627 { config_parse_emergency_action
, "ACTION" },
5628 { config_parse_set_status
, "STATUS" },
5629 { config_parse_service_sockets
, "SOCKETS" },
5630 { config_parse_environ
, "ENVIRON" },
5632 { config_parse_syscall_filter
, "SYSCALLS" },
5633 { config_parse_syscall_archs
, "ARCHS" },
5634 { config_parse_syscall_errno
, "ERRNO" },
5635 { config_parse_syscall_log
, "SYSCALLS" },
5636 { config_parse_address_families
, "FAMILIES" },
5637 { config_parse_restrict_namespaces
, "NAMESPACES" },
5639 { config_parse_cpu_shares
, "SHARES" },
5640 { config_parse_cg_weight
, "WEIGHT" },
5641 { config_parse_memory_limit
, "LIMIT" },
5642 { config_parse_device_allow
, "DEVICE" },
5643 { config_parse_device_policy
, "POLICY" },
5644 { config_parse_io_limit
, "LIMIT" },
5645 { config_parse_io_device_weight
, "DEVICEWEIGHT" },
5646 { config_parse_io_device_latency
, "DEVICELATENCY" },
5647 { config_parse_blockio_bandwidth
, "BANDWIDTH" },
5648 { config_parse_blockio_weight
, "WEIGHT" },
5649 { config_parse_blockio_device_weight
, "DEVICEWEIGHT" },
5650 { config_parse_long
, "LONG" },
5651 { config_parse_socket_service
, "SERVICE" },
5653 { config_parse_exec_selinux_context
, "LABEL" },
5655 { config_parse_job_mode
, "MODE" },
5656 { config_parse_job_mode_isolate
, "BOOLEAN" },
5657 { config_parse_personality
, "PERSONALITY" },
5660 const char *prev
= NULL
;
5665 NULSTR_FOREACH(i
, load_fragment_gperf_nulstr
) {
5666 const char *rvalue
= "OTHER", *lvalue
;
5667 const ConfigPerfItem
*p
;
5670 assert_se(p
= load_fragment_gperf_lookup(i
, strlen(i
)));
5672 /* Hide legacy settings */
5673 if (p
->parse
== config_parse_warn_compat
&&
5674 p
->ltype
== DISABLED_LEGACY
)
5677 for (size_t j
= 0; j
< ELEMENTSOF(table
); j
++)
5678 if (p
->parse
== table
[j
].callback
) {
5679 rvalue
= table
[j
].rvalue
;
5683 dot
= strchr(i
, '.');
5684 lvalue
= dot
? dot
+ 1 : i
;
5687 size_t prefix_len
= dot
- i
;
5689 if (!prev
|| !strneq(prev
, i
, prefix_len
+1)) {
5693 fprintf(f
, "[%.*s]\n", (int) prefix_len
, i
);
5697 fprintf(f
, "%s=%s\n", lvalue
, rvalue
);
5702 int config_parse_cpu_affinity2(
5704 const char *filename
,
5706 const char *section
,
5707 unsigned section_line
,
5714 CPUSet
*affinity
= data
;
5718 (void) parse_cpu_set_extend(rvalue
, affinity
, true, unit
, filename
, line
, lvalue
);
5723 int config_parse_show_status(
5725 const char *filename
,
5727 const char *section
,
5728 unsigned section_line
,
5736 ShowStatus
*b
= data
;
5743 k
= parse_show_status(rvalue
, b
);
5745 log_syntax(unit
, LOG_WARNING
, filename
, line
, k
, "Failed to parse show status setting, ignoring: %s", rvalue
);
5750 int config_parse_output_restricted(
5752 const char *filename
,
5754 const char *section
,
5755 unsigned section_line
,
5762 ExecOutput t
, *eo
= data
;
5763 bool obsolete
= false;
5770 if (streq(rvalue
, "syslog")) {
5771 t
= EXEC_OUTPUT_JOURNAL
;
5773 } else if (streq(rvalue
, "syslog+console")) {
5774 t
= EXEC_OUTPUT_JOURNAL_AND_CONSOLE
;
5777 t
= exec_output_from_string(rvalue
);
5779 log_syntax(unit
, LOG_WARNING
, filename
, line
, t
, "Failed to parse output type, ignoring: %s", rvalue
);
5783 if (IN_SET(t
, EXEC_OUTPUT_SOCKET
, EXEC_OUTPUT_NAMED_FD
, EXEC_OUTPUT_FILE
, EXEC_OUTPUT_FILE_APPEND
, EXEC_OUTPUT_FILE_TRUNCATE
)) {
5784 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Standard output types socket, fd:, file:, append:, truncate: are not supported as defaults, ignoring: %s", rvalue
);
5790 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
5791 "Standard output type %s is obsolete, automatically updating to %s. Please update your configuration.",
5792 rvalue
, exec_output_to_string(t
));
5798 int config_parse_crash_chvt(
5800 const char *filename
,
5802 const char *section
,
5803 unsigned section_line
,
5817 r
= parse_crash_chvt(rvalue
, data
);
5819 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse CrashChangeVT= setting, ignoring: %s", rvalue
);
5824 int config_parse_swap_priority(
5826 const char *filename
,
5828 const char *section
,
5829 unsigned section_line
,
5845 if (isempty(rvalue
)) {
5846 s
->parameters_fragment
.priority
= -1;
5847 s
->parameters_fragment
.priority_set
= false;
5851 r
= safe_atoi(rvalue
, &priority
);
5853 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid swap priority '%s', ignoring.", rvalue
);
5857 if (priority
< -1) {
5858 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
);
5862 if (priority
> 32767) {
5863 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Swap priority out of range, ignoring: %s", rvalue
);
5867 s
->parameters_fragment
.priority
= priority
;
5868 s
->parameters_fragment
.priority_set
= true;