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
, *k
= 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
, &k
);
2655 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2656 "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2662 if (!env_assignment_is_valid(k
)) {
2663 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
2664 "Invalid environment assignment, ignoring: %s", k
);
2668 r
= strv_env_replace(env
, k
);
2676 int config_parse_pass_environ(
2678 const char *filename
,
2680 const char *section
,
2681 unsigned section_line
,
2688 _cleanup_strv_free_
char **n
= NULL
;
2689 size_t nlen
= 0, nbufsize
= 0;
2690 char*** passenv
= data
;
2691 const Unit
*u
= userdata
;
2699 if (isempty(rvalue
)) {
2700 /* Empty assignment resets the list */
2701 *passenv
= strv_free(*passenv
);
2705 for (const char *p
= rvalue
;;) {
2706 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2708 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
2714 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2715 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2720 r
= unit_full_printf(u
, word
, &k
);
2722 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2723 "Failed to resolve specifiers in %s, ignoring: %m", word
);
2729 if (!env_name_is_valid(k
)) {
2730 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
2731 "Invalid environment name for %s, ignoring: %s", lvalue
, k
);
2735 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
2738 n
[nlen
++] = TAKE_PTR(k
);
2743 r
= strv_extend_strv(passenv
, n
, true);
2751 int config_parse_unset_environ(
2753 const char *filename
,
2755 const char *section
,
2756 unsigned section_line
,
2763 _cleanup_strv_free_
char **n
= NULL
;
2764 size_t nlen
= 0, nbufsize
= 0;
2765 char*** unsetenv
= data
;
2766 const Unit
*u
= userdata
;
2774 if (isempty(rvalue
)) {
2775 /* Empty assignment resets the list */
2776 *unsetenv
= strv_free(*unsetenv
);
2780 for (const char *p
= rvalue
;;) {
2781 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2783 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2789 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2790 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2795 r
= unit_full_printf(u
, word
, &k
);
2797 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2798 "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2804 if (!env_assignment_is_valid(k
) && !env_name_is_valid(k
)) {
2805 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
2806 "Invalid environment name or assignment %s, ignoring: %s", lvalue
, k
);
2810 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
2813 n
[nlen
++] = TAKE_PTR(k
);
2818 r
= strv_extend_strv(unsetenv
, n
, true);
2826 int config_parse_log_extra_fields(
2828 const char *filename
,
2830 const char *section
,
2831 unsigned section_line
,
2838 ExecContext
*c
= data
;
2839 const Unit
*u
= userdata
;
2847 if (isempty(rvalue
)) {
2848 exec_context_free_log_extra_fields(c
);
2852 for (const char *p
= rvalue
;;) {
2853 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2857 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2863 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
2867 r
= unit_full_printf(u
, word
, &k
);
2869 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2873 eq
= strchr(k
, '=');
2875 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Log field lacks '=' character, ignoring: %s", k
);
2879 if (!journal_field_valid(k
, eq
-k
, false)) {
2880 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Log field name is invalid, ignoring: %s", k
);
2884 t
= reallocarray(c
->log_extra_fields
, c
->n_log_extra_fields
+1, sizeof(struct iovec
));
2888 c
->log_extra_fields
= t
;
2889 c
->log_extra_fields
[c
->n_log_extra_fields
++] = IOVEC_MAKE_STRING(k
);
2895 int config_parse_log_namespace(
2897 const char *filename
,
2899 const char *section
,
2900 unsigned section_line
,
2907 _cleanup_free_
char *k
= NULL
;
2908 ExecContext
*c
= data
;
2909 const Unit
*u
= userdata
;
2917 if (isempty(rvalue
)) {
2918 c
->log_namespace
= mfree(c
->log_namespace
);
2922 r
= unit_full_printf(u
, rvalue
, &k
);
2924 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2928 if (!log_namespace_name_valid(k
)) {
2929 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Specified log namespace name is not valid, ignoring: %s", k
);
2933 free_and_replace(c
->log_namespace
, k
);
2937 int config_parse_unit_condition_path(
2939 const char *filename
,
2941 const char *section
,
2942 unsigned section_line
,
2949 _cleanup_free_
char *p
= NULL
;
2950 Condition
**list
= data
, *c
;
2951 ConditionType t
= ltype
;
2952 bool trigger
, negate
;
2953 const Unit
*u
= userdata
;
2961 if (isempty(rvalue
)) {
2962 /* Empty assignment resets the list */
2963 *list
= condition_free_list(*list
);
2967 trigger
= rvalue
[0] == '|';
2971 negate
= rvalue
[0] == '!';
2975 r
= unit_full_printf(u
, rvalue
, &p
);
2977 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2981 r
= path_simplify_and_warn(p
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2985 c
= condition_new(t
, p
, trigger
, negate
);
2989 LIST_PREPEND(conditions
, *list
, c
);
2993 int config_parse_unit_condition_string(
2995 const char *filename
,
2997 const char *section
,
2998 unsigned section_line
,
3005 _cleanup_free_
char *s
= NULL
;
3006 Condition
**list
= data
, *c
;
3007 ConditionType t
= ltype
;
3008 bool trigger
, negate
;
3009 const Unit
*u
= userdata
;
3017 if (isempty(rvalue
)) {
3018 /* Empty assignment resets the list */
3019 *list
= condition_free_list(*list
);
3023 trigger
= *rvalue
== '|';
3025 rvalue
+= 1 + strspn(rvalue
+ 1, WHITESPACE
);
3027 negate
= *rvalue
== '!';
3029 rvalue
+= 1 + strspn(rvalue
+ 1, WHITESPACE
);
3031 r
= unit_full_printf(u
, rvalue
, &s
);
3033 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3034 "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
3038 c
= condition_new(t
, s
, trigger
, negate
);
3042 LIST_PREPEND(conditions
, *list
, c
);
3046 int config_parse_unit_requires_mounts_for(
3048 const char *filename
,
3050 const char *section
,
3051 unsigned section_line
,
3066 for (const char *p
= rvalue
;;) {
3067 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
3069 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3075 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3076 "Invalid syntax, ignoring: %s", rvalue
);
3080 r
= unit_full_printf(u
, word
, &resolved
);
3082 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
3086 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
3090 r
= unit_require_mounts_for(u
, resolved
, UNIT_DEPENDENCY_FILE
);
3092 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add required mount '%s', ignoring: %m", resolved
);
3098 int config_parse_documentation(
3100 const char *filename
,
3102 const char *section
,
3103 unsigned section_line
,
3119 if (isempty(rvalue
)) {
3120 /* Empty assignment resets the list */
3121 u
->documentation
= strv_free(u
->documentation
);
3125 r
= config_parse_unit_strv_printf(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
,
3126 rvalue
, data
, userdata
);
3130 for (a
= b
= u
->documentation
; a
&& *a
; a
++) {
3132 if (documentation_url_is_valid(*a
))
3135 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid URL, ignoring: %s", *a
);
3146 int config_parse_syscall_filter(
3148 const char *filename
,
3150 const char *section
,
3151 unsigned section_line
,
3158 ExecContext
*c
= data
;
3159 _unused_
const Unit
*u
= userdata
;
3160 bool invert
= false;
3168 if (isempty(rvalue
)) {
3169 /* Empty assignment resets the list */
3170 c
->syscall_filter
= hashmap_free(c
->syscall_filter
);
3171 c
->syscall_allow_list
= false;
3175 if (rvalue
[0] == '~') {
3180 if (!c
->syscall_filter
) {
3181 c
->syscall_filter
= hashmap_new(NULL
);
3182 if (!c
->syscall_filter
)
3186 /* Allow everything but the ones listed */
3187 c
->syscall_allow_list
= false;
3189 /* Allow nothing but the ones listed */
3190 c
->syscall_allow_list
= true;
3192 /* Accept default syscalls if we are on a allow_list */
3193 r
= seccomp_parse_syscall_filter(
3194 "@default", -1, c
->syscall_filter
,
3195 SECCOMP_PARSE_PERMISSIVE
|SECCOMP_PARSE_ALLOW_LIST
,
3203 for (const char *p
= rvalue
;;) {
3204 _cleanup_free_
char *word
= NULL
, *name
= NULL
;
3207 r
= extract_first_word(&p
, &word
, NULL
, 0);
3213 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3217 r
= parse_syscall_and_errno(word
, &name
, &num
);
3219 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse syscall:errno, ignoring: %s", word
);
3223 r
= seccomp_parse_syscall_filter(
3224 name
, num
, c
->syscall_filter
,
3225 SECCOMP_PARSE_LOG
|SECCOMP_PARSE_PERMISSIVE
|
3226 (invert
? SECCOMP_PARSE_INVERT
: 0)|
3227 (c
->syscall_allow_list
? SECCOMP_PARSE_ALLOW_LIST
: 0),
3228 unit
, filename
, line
);
3234 int config_parse_syscall_log(
3236 const char *filename
,
3238 const char *section
,
3239 unsigned section_line
,
3246 ExecContext
*c
= data
;
3247 _unused_
const Unit
*u
= userdata
;
3248 bool invert
= false;
3257 if (isempty(rvalue
)) {
3258 /* Empty assignment resets the list */
3259 c
->syscall_log
= hashmap_free(c
->syscall_log
);
3260 c
->syscall_log_allow_list
= false;
3264 if (rvalue
[0] == '~') {
3269 if (!c
->syscall_log
) {
3270 c
->syscall_log
= hashmap_new(NULL
);
3271 if (!c
->syscall_log
)
3275 /* Log everything but the ones listed */
3276 c
->syscall_log_allow_list
= false;
3278 /* Log nothing but the ones listed */
3279 c
->syscall_log_allow_list
= true;
3284 _cleanup_free_
char *word
= NULL
, *name
= NULL
;
3287 r
= extract_first_word(&p
, &word
, NULL
, 0);
3293 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3297 r
= parse_syscall_and_errno(word
, &name
, &num
);
3298 if (r
< 0 || num
>= 0) { /* errno code not allowed */
3299 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse syscall, ignoring: %s", word
);
3303 r
= seccomp_parse_syscall_filter(
3304 name
, 0, c
->syscall_log
,
3305 SECCOMP_PARSE_LOG
|SECCOMP_PARSE_PERMISSIVE
|
3306 (invert
? SECCOMP_PARSE_INVERT
: 0)|
3307 (c
->syscall_log_allow_list
? SECCOMP_PARSE_ALLOW_LIST
: 0),
3308 unit
, filename
, line
);
3314 int config_parse_syscall_archs(
3316 const char *filename
,
3318 const char *section
,
3319 unsigned section_line
,
3329 if (isempty(rvalue
)) {
3330 *archs
= set_free(*archs
);
3334 for (const char *p
= rvalue
;;) {
3335 _cleanup_free_
char *word
= NULL
;
3338 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3344 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3345 "Invalid syntax, ignoring: %s", rvalue
);
3349 r
= seccomp_arch_from_string(word
, &a
);
3351 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3352 "Failed to parse system call architecture \"%s\", ignoring: %m", word
);
3356 r
= set_ensure_put(archs
, NULL
, UINT32_TO_PTR(a
+ 1));
3362 int config_parse_syscall_errno(
3364 const char *filename
,
3366 const char *section
,
3367 unsigned section_line
,
3374 ExecContext
*c
= data
;
3381 if (isempty(rvalue
) || streq(rvalue
, "kill")) {
3382 /* Empty assignment resets to KILL */
3383 c
->syscall_errno
= SECCOMP_ERROR_NUMBER_KILL
;
3387 e
= parse_errno(rvalue
);
3389 log_syntax(unit
, LOG_WARNING
, filename
, line
, e
, "Failed to parse error number, ignoring: %s", rvalue
);
3393 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid error number, ignoring: %s", rvalue
);
3397 c
->syscall_errno
= e
;
3401 int config_parse_address_families(
3403 const char *filename
,
3405 const char *section
,
3406 unsigned section_line
,
3413 ExecContext
*c
= data
;
3414 bool invert
= false;
3421 if (isempty(rvalue
)) {
3422 /* Empty assignment resets the list */
3423 c
->address_families
= set_free(c
->address_families
);
3424 c
->address_families_allow_list
= false;
3428 if (rvalue
[0] == '~') {
3433 if (!c
->address_families
) {
3434 c
->address_families
= set_new(NULL
);
3435 if (!c
->address_families
)
3438 c
->address_families_allow_list
= !invert
;
3441 for (const char *p
= rvalue
;;) {
3442 _cleanup_free_
char *word
= NULL
;
3445 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3451 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3452 "Invalid syntax, ignoring: %s", rvalue
);
3456 af
= af_from_name(word
);
3458 log_syntax(unit
, LOG_WARNING
, filename
, line
, af
,
3459 "Failed to parse address family, ignoring: %s", word
);
3463 /* If we previously wanted to forbid an address family and now
3464 * we want to allow it, then just remove it from the list.
3466 if (!invert
== c
->address_families_allow_list
) {
3467 r
= set_put(c
->address_families
, INT_TO_PTR(af
));
3471 set_remove(c
->address_families
, INT_TO_PTR(af
));
3475 int config_parse_restrict_namespaces(
3477 const char *filename
,
3479 const char *section
,
3480 unsigned section_line
,
3487 ExecContext
*c
= data
;
3488 unsigned long flags
;
3489 bool invert
= false;
3492 if (isempty(rvalue
)) {
3493 /* Reset to the default. */
3494 c
->restrict_namespaces
= NAMESPACE_FLAGS_INITIAL
;
3498 /* Boolean parameter ignores the previous settings */
3499 r
= parse_boolean(rvalue
);
3501 c
->restrict_namespaces
= 0;
3503 } else if (r
== 0) {
3504 c
->restrict_namespaces
= NAMESPACE_FLAGS_ALL
;
3508 if (rvalue
[0] == '~') {
3513 /* Not a boolean argument, in this case it's a list of namespace types. */
3514 r
= namespace_flags_from_string(rvalue
, &flags
);
3516 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse namespace type string, ignoring: %s", rvalue
);
3520 if (c
->restrict_namespaces
== NAMESPACE_FLAGS_INITIAL
)
3521 /* Initial assignment. Just set the value. */
3522 c
->restrict_namespaces
= invert
? (~flags
) & NAMESPACE_FLAGS_ALL
: flags
;
3524 /* Merge the value with the previous one. */
3525 SET_FLAG(c
->restrict_namespaces
, flags
, !invert
);
3531 int config_parse_unit_slice(
3533 const char *filename
,
3535 const char *section
,
3536 unsigned section_line
,
3543 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
3544 _cleanup_free_
char *k
= NULL
;
3545 Unit
*u
= userdata
, *slice
;
3553 r
= unit_name_printf(u
, rvalue
, &k
);
3555 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
3559 r
= manager_load_unit(u
->manager
, k
, NULL
, &error
, &slice
);
3561 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to load slice unit %s, ignoring: %s", k
, bus_error_message(&error
, r
));
3565 r
= unit_set_slice(u
, slice
);
3567 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to assign slice %s to unit %s, ignoring: %m", slice
->id
, u
->id
);
3574 int config_parse_cpu_quota(
3576 const char *filename
,
3578 const char *section
,
3579 unsigned section_line
,
3586 CGroupContext
*c
= data
;
3593 if (isempty(rvalue
)) {
3594 c
->cpu_quota_per_sec_usec
= USEC_INFINITY
;
3598 r
= parse_permille_unbounded(rvalue
);
3600 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid CPU quota '%s', ignoring.", rvalue
);
3604 c
->cpu_quota_per_sec_usec
= ((usec_t
) r
* USEC_PER_SEC
) / 1000U;
3608 int config_parse_allowed_cpus(
3610 const char *filename
,
3612 const char *section
,
3613 unsigned section_line
,
3620 CGroupContext
*c
= data
;
3622 (void) parse_cpu_set_extend(rvalue
, &c
->cpuset_cpus
, true, unit
, filename
, line
, lvalue
);
3627 int config_parse_allowed_mems(
3629 const char *filename
,
3631 const char *section
,
3632 unsigned section_line
,
3639 CGroupContext
*c
= data
;
3641 (void) parse_cpu_set_extend(rvalue
, &c
->cpuset_mems
, true, unit
, filename
, line
, lvalue
);
3646 int config_parse_memory_limit(
3648 const char *filename
,
3650 const char *section
,
3651 unsigned section_line
,
3658 CGroupContext
*c
= data
;
3659 uint64_t bytes
= CGROUP_LIMIT_MAX
;
3662 if (isempty(rvalue
) && STR_IN_SET(lvalue
, "DefaultMemoryLow",
3666 bytes
= CGROUP_LIMIT_MIN
;
3667 else if (!isempty(rvalue
) && !streq(rvalue
, "infinity")) {
3669 r
= parse_permille(rvalue
);
3671 r
= parse_size(rvalue
, 1024, &bytes
);
3673 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid memory limit '%s', ignoring: %m", rvalue
);
3677 bytes
= physical_memory_scale(r
, 1000U);
3679 if (bytes
>= UINT64_MAX
||
3680 (bytes
<= 0 && !STR_IN_SET(lvalue
, "MemorySwapMax", "MemoryLow", "MemoryMin", "DefaultMemoryLow", "DefaultMemoryMin"))) {
3681 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Memory limit '%s' out of range, ignoring.", rvalue
);
3686 if (streq(lvalue
, "DefaultMemoryLow")) {
3687 c
->default_memory_low
= bytes
;
3688 c
->default_memory_low_set
= true;
3689 } else if (streq(lvalue
, "DefaultMemoryMin")) {
3690 c
->default_memory_min
= bytes
;
3691 c
->default_memory_min_set
= true;
3692 } else if (streq(lvalue
, "MemoryMin")) {
3693 c
->memory_min
= bytes
;
3694 c
->memory_min_set
= true;
3695 } else if (streq(lvalue
, "MemoryLow")) {
3696 c
->memory_low
= bytes
;
3697 c
->memory_low_set
= true;
3698 } else if (streq(lvalue
, "MemoryHigh"))
3699 c
->memory_high
= bytes
;
3700 else if (streq(lvalue
, "MemoryMax"))
3701 c
->memory_max
= bytes
;
3702 else if (streq(lvalue
, "MemorySwapMax"))
3703 c
->memory_swap_max
= bytes
;
3704 else if (streq(lvalue
, "MemoryLimit"))
3705 c
->memory_limit
= bytes
;
3712 int config_parse_tasks_max(
3714 const char *filename
,
3716 const char *section
,
3717 unsigned section_line
,
3724 const Unit
*u
= userdata
;
3725 TasksMax
*tasks_max
= data
;
3729 if (isempty(rvalue
)) {
3730 *tasks_max
= u
? u
->manager
->default_tasks_max
: TASKS_MAX_UNSET
;
3734 if (streq(rvalue
, "infinity")) {
3735 *tasks_max
= TASKS_MAX_UNSET
;
3739 r
= parse_permille(rvalue
);
3741 *tasks_max
= (TasksMax
) { r
, 1000U }; /* r‰ */
3743 r
= safe_atou64(rvalue
, &v
);
3745 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid maximum tasks value '%s', ignoring: %m", rvalue
);
3749 if (v
<= 0 || v
>= UINT64_MAX
) {
3750 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Maximum tasks value '%s' out of range, ignoring.", rvalue
);
3754 *tasks_max
= (TasksMax
) { v
};
3760 int config_parse_delegate(
3762 const char *filename
,
3764 const char *section
,
3765 unsigned section_line
,
3772 CGroupContext
*c
= data
;
3776 t
= unit_name_to_type(unit
);
3777 assert(t
!= _UNIT_TYPE_INVALID
);
3779 if (!unit_vtable
[t
]->can_delegate
) {
3780 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Delegate= setting not supported for this unit type, ignoring.");
3784 /* We either accept a boolean value, which may be used to turn on delegation for all controllers, or turn it
3785 * off for all. Or it takes a list of controller names, in which case we add the specified controllers to the
3786 * mask to delegate. */
3788 if (isempty(rvalue
)) {
3789 /* An empty string resets controllers and set Delegate=yes. */
3791 c
->delegate_controllers
= 0;
3795 r
= parse_boolean(rvalue
);
3797 CGroupMask mask
= 0;
3799 for (const char *p
= rvalue
;;) {
3800 _cleanup_free_
char *word
= NULL
;
3801 CGroupController cc
;
3803 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3809 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3813 cc
= cgroup_controller_from_string(word
);
3815 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid controller name '%s', ignoring", word
);
3819 mask
|= CGROUP_CONTROLLER_TO_MASK(cc
);
3823 c
->delegate_controllers
|= mask
;
3827 c
->delegate_controllers
= _CGROUP_MASK_ALL
;
3829 c
->delegate
= false;
3830 c
->delegate_controllers
= 0;
3836 int config_parse_managed_oom_mode(
3838 const char *filename
,
3840 const char *section
,
3841 unsigned section_line
,
3847 ManagedOOMMode
*mode
= data
, m
;
3850 t
= unit_name_to_type(unit
);
3851 assert(t
!= _UNIT_TYPE_INVALID
);
3853 if (!unit_vtable
[t
]->can_set_managed_oom
)
3854 return log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "%s= is not supported for this unit type, ignoring.", lvalue
);
3856 if (isempty(rvalue
)) {
3857 *mode
= MANAGED_OOM_AUTO
;
3861 m
= managed_oom_mode_from_string(rvalue
);
3863 log_syntax(unit
, LOG_WARNING
, filename
, line
, m
, "Invalid syntax, ignoring: %s", rvalue
);
3870 int config_parse_managed_oom_mem_pressure_limit(
3872 const char *filename
,
3874 const char *section
,
3875 unsigned section_line
,
3881 uint32_t *limit
= data
;
3885 t
= unit_name_to_type(unit
);
3886 assert(t
!= _UNIT_TYPE_INVALID
);
3888 if (!unit_vtable
[t
]->can_set_managed_oom
)
3889 return log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "%s= is not supported for this unit type, ignoring.", lvalue
);
3891 if (isempty(rvalue
)) {
3896 r
= parse_permyriad(rvalue
);
3898 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse memory pressure limit value, ignoring: %s", rvalue
);
3906 int config_parse_device_allow(
3908 const char *filename
,
3910 const char *section
,
3911 unsigned section_line
,
3918 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3919 CGroupContext
*c
= data
;
3920 const char *p
= rvalue
;
3923 if (isempty(rvalue
)) {
3924 while (c
->device_allow
)
3925 cgroup_context_free_device_allow(c
, c
->device_allow
);
3930 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3934 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3935 "Invalid syntax, ignoring: %s", rvalue
);
3939 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3940 "Failed to extract device path and rights from '%s', ignoring.", rvalue
);
3944 r
= unit_full_printf(userdata
, path
, &resolved
);
3946 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3947 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3951 if (!STARTSWITH_SET(resolved
, "block-", "char-")) {
3953 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3957 if (!valid_device_node_path(resolved
)) {
3958 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid device node path '%s', ignoring.", resolved
);
3963 if (!isempty(p
) && !in_charset(p
, "rwm")) {
3964 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid device rights '%s', ignoring.", p
);
3968 return cgroup_add_device_allow(c
, resolved
, p
);
3971 int config_parse_io_device_weight(
3973 const char *filename
,
3975 const char *section
,
3976 unsigned section_line
,
3983 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3984 CGroupIODeviceWeight
*w
;
3985 CGroupContext
*c
= data
;
3986 const char *p
= rvalue
;
3994 if (isempty(rvalue
)) {
3995 while (c
->io_device_weights
)
3996 cgroup_context_free_io_device_weight(c
, c
->io_device_weights
);
4001 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4005 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4006 "Invalid syntax, ignoring: %s", rvalue
);
4009 if (r
== 0 || isempty(p
)) {
4010 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4011 "Failed to extract device path and weight from '%s', ignoring.", rvalue
);
4015 r
= unit_full_printf(userdata
, path
, &resolved
);
4017 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4018 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4022 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4026 r
= cg_weight_parse(p
, &u
);
4028 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "IO weight '%s' invalid, ignoring: %m", p
);
4032 assert(u
!= CGROUP_WEIGHT_INVALID
);
4034 w
= new0(CGroupIODeviceWeight
, 1);
4038 w
->path
= TAKE_PTR(resolved
);
4041 LIST_PREPEND(device_weights
, c
->io_device_weights
, w
);
4045 int config_parse_io_device_latency(
4047 const char *filename
,
4049 const char *section
,
4050 unsigned section_line
,
4057 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4058 CGroupIODeviceLatency
*l
;
4059 CGroupContext
*c
= data
;
4060 const char *p
= rvalue
;
4068 if (isempty(rvalue
)) {
4069 while (c
->io_device_latencies
)
4070 cgroup_context_free_io_device_latency(c
, c
->io_device_latencies
);
4075 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4079 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4080 "Invalid syntax, ignoring: %s", rvalue
);
4083 if (r
== 0 || isempty(p
)) {
4084 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4085 "Failed to extract device path and latency from '%s', ignoring.", rvalue
);
4089 r
= unit_full_printf(userdata
, path
, &resolved
);
4091 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4092 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4096 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4100 r
= parse_sec(p
, &usec
);
4102 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse timer value, ignoring: %s", p
);
4106 l
= new0(CGroupIODeviceLatency
, 1);
4110 l
->path
= TAKE_PTR(resolved
);
4111 l
->target_usec
= usec
;
4113 LIST_PREPEND(device_latencies
, c
->io_device_latencies
, l
);
4117 int config_parse_io_limit(
4119 const char *filename
,
4121 const char *section
,
4122 unsigned section_line
,
4129 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4130 CGroupIODeviceLimit
*l
= NULL
, *t
;
4131 CGroupContext
*c
= data
;
4132 CGroupIOLimitType type
;
4133 const char *p
= rvalue
;
4141 type
= cgroup_io_limit_type_from_string(lvalue
);
4144 if (isempty(rvalue
)) {
4145 LIST_FOREACH(device_limits
, l
, c
->io_device_limits
)
4146 l
->limits
[type
] = cgroup_io_limit_defaults
[type
];
4150 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4154 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4155 "Invalid syntax, ignoring: %s", rvalue
);
4158 if (r
== 0 || isempty(p
)) {
4159 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4160 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
4164 r
= unit_full_printf(userdata
, path
, &resolved
);
4166 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4167 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4171 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4175 if (streq("infinity", p
))
4176 num
= CGROUP_LIMIT_MAX
;
4178 r
= parse_size(p
, 1000, &num
);
4179 if (r
< 0 || num
<= 0) {
4180 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid IO limit '%s', ignoring.", p
);
4185 LIST_FOREACH(device_limits
, t
, c
->io_device_limits
) {
4186 if (path_equal(resolved
, t
->path
)) {
4193 CGroupIOLimitType ttype
;
4195 l
= new0(CGroupIODeviceLimit
, 1);
4199 l
->path
= TAKE_PTR(resolved
);
4200 for (ttype
= 0; ttype
< _CGROUP_IO_LIMIT_TYPE_MAX
; ttype
++)
4201 l
->limits
[ttype
] = cgroup_io_limit_defaults
[ttype
];
4203 LIST_PREPEND(device_limits
, c
->io_device_limits
, l
);
4206 l
->limits
[type
] = num
;
4211 int config_parse_blockio_device_weight(
4213 const char *filename
,
4215 const char *section
,
4216 unsigned section_line
,
4223 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4224 CGroupBlockIODeviceWeight
*w
;
4225 CGroupContext
*c
= data
;
4226 const char *p
= rvalue
;
4234 if (isempty(rvalue
)) {
4235 while (c
->blockio_device_weights
)
4236 cgroup_context_free_blockio_device_weight(c
, c
->blockio_device_weights
);
4241 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4245 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4246 "Invalid syntax, ignoring: %s", rvalue
);
4249 if (r
== 0 || isempty(p
)) {
4250 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4251 "Failed to extract device node and weight from '%s', ignoring.", rvalue
);
4255 r
= unit_full_printf(userdata
, path
, &resolved
);
4257 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4258 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4262 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4266 r
= cg_blkio_weight_parse(p
, &u
);
4268 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid block IO weight '%s', ignoring: %m", p
);
4272 assert(u
!= CGROUP_BLKIO_WEIGHT_INVALID
);
4274 w
= new0(CGroupBlockIODeviceWeight
, 1);
4278 w
->path
= TAKE_PTR(resolved
);
4281 LIST_PREPEND(device_weights
, c
->blockio_device_weights
, w
);
4285 int config_parse_blockio_bandwidth(
4287 const char *filename
,
4289 const char *section
,
4290 unsigned section_line
,
4297 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4298 CGroupBlockIODeviceBandwidth
*b
= NULL
, *t
;
4299 CGroupContext
*c
= data
;
4300 const char *p
= rvalue
;
4309 read
= streq("BlockIOReadBandwidth", lvalue
);
4311 if (isempty(rvalue
)) {
4312 LIST_FOREACH(device_bandwidths
, b
, c
->blockio_device_bandwidths
) {
4313 b
->rbps
= CGROUP_LIMIT_MAX
;
4314 b
->wbps
= CGROUP_LIMIT_MAX
;
4319 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4323 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4324 "Invalid syntax, ignoring: %s", rvalue
);
4327 if (r
== 0 || isempty(p
)) {
4328 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4329 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
4333 r
= unit_full_printf(userdata
, path
, &resolved
);
4335 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4336 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4340 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4344 r
= parse_size(p
, 1000, &bytes
);
4345 if (r
< 0 || bytes
<= 0) {
4346 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid Block IO Bandwidth '%s', ignoring.", p
);
4350 LIST_FOREACH(device_bandwidths
, t
, c
->blockio_device_bandwidths
) {
4351 if (path_equal(resolved
, t
->path
)) {
4358 b
= new0(CGroupBlockIODeviceBandwidth
, 1);
4362 b
->path
= TAKE_PTR(resolved
);
4363 b
->rbps
= CGROUP_LIMIT_MAX
;
4364 b
->wbps
= CGROUP_LIMIT_MAX
;
4366 LIST_PREPEND(device_bandwidths
, c
->blockio_device_bandwidths
, b
);
4377 int config_parse_job_mode_isolate(
4379 const char *filename
,
4381 const char *section
,
4382 unsigned section_line
,
4396 r
= parse_boolean(rvalue
);
4398 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse boolean, ignoring: %s", rvalue
);
4402 log_notice("%s is deprecated. Please use OnFailureJobMode= instead", lvalue
);
4404 *m
= r
? JOB_ISOLATE
: JOB_REPLACE
;
4408 int config_parse_exec_directories(
4410 const char *filename
,
4412 const char *section
,
4413 unsigned section_line
,
4421 const Unit
*u
= userdata
;
4429 if (isempty(rvalue
)) {
4430 /* Empty assignment resets the list */
4431 *rt
= strv_free(*rt
);
4435 for (const char *p
= rvalue
;;) {
4436 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
4438 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
4442 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4443 "Invalid syntax, ignoring: %s", rvalue
);
4449 r
= unit_full_printf(u
, word
, &k
);
4451 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4452 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
4456 r
= path_simplify_and_warn(k
, PATH_CHECK_RELATIVE
, unit
, filename
, line
, lvalue
);
4460 if (path_startswith(k
, "private")) {
4461 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4462 "%s= path can't be 'private', ignoring assignment: %s", lvalue
, word
);
4466 r
= strv_push(rt
, k
);
4473 int config_parse_set_credential(
4475 const char *filename
,
4477 const char *section
,
4478 unsigned section_line
,
4485 _cleanup_free_
char *word
= NULL
, *k
= NULL
, *unescaped
= NULL
;
4486 ExecContext
*context
= data
;
4487 ExecSetCredential
*old
;
4497 if (isempty(rvalue
)) {
4498 /* Empty assignment resets the list */
4499 context
->set_credentials
= hashmap_free(context
->set_credentials
);
4504 r
= extract_first_word(&p
, &word
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4508 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
4512 r
= unit_full_printf(u
, word
, &k
);
4514 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
4517 if (!credential_name_valid(k
)) {
4518 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Credential name \"%s\" not valid, ignoring.", k
);
4522 /* We support escape codes here, so that users can insert trailing \n if they like */
4523 l
= cunescape(p
, UNESCAPE_ACCEPT_NUL
, &unescaped
);
4525 log_syntax(unit
, LOG_WARNING
, filename
, line
, l
, "Can't unescape \"%s\", ignoring: %m", p
);
4529 old
= hashmap_get(context
->set_credentials
, k
);
4531 free_and_replace(old
->data
, unescaped
);
4534 _cleanup_(exec_set_credential_freep
) ExecSetCredential
*sc
= NULL
;
4536 sc
= new0(ExecSetCredential
, 1);
4540 sc
->id
= TAKE_PTR(k
);
4541 sc
->data
= TAKE_PTR(unescaped
);
4544 r
= hashmap_ensure_put(&context
->set_credentials
, &exec_set_credential_hash_ops
, sc
->id
, sc
);
4548 log_syntax(unit
, LOG_WARNING
, filename
, line
, l
,
4549 "Duplicated credential value '%s', ignoring assignment: %s", sc
->id
, rvalue
);
4559 int config_parse_load_credential(
4561 const char *filename
,
4563 const char *section
,
4564 unsigned section_line
,
4571 _cleanup_free_
char *word
= NULL
, *k
= NULL
, *q
= NULL
;
4572 ExecContext
*context
= data
;
4582 if (isempty(rvalue
)) {
4583 /* Empty assignment resets the list */
4584 context
->load_credentials
= strv_free(context
->load_credentials
);
4589 r
= extract_first_word(&p
, &word
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4593 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
4597 r
= unit_full_printf(u
, word
, &k
);
4599 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
4602 if (!credential_name_valid(k
)) {
4603 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Credential name \"%s\" not valid, ignoring.", k
);
4606 r
= unit_full_printf(u
, p
, &q
);
4608 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", p
);
4611 if (path_is_absolute(q
) ? !path_is_normalized(q
) : !credential_name_valid(q
)) {
4612 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Credential source \"%s\" not valid, ignoring.", q
);
4616 r
= strv_consume_pair(&context
->load_credentials
, TAKE_PTR(k
), TAKE_PTR(q
));
4623 int config_parse_set_status(
4625 const char *filename
,
4627 const char *section
,
4628 unsigned section_line
,
4635 ExitStatusSet
*status_set
= data
;
4643 /* Empty assignment resets the list */
4644 if (isempty(rvalue
)) {
4645 exit_status_set_free(status_set
);
4649 for (const char *p
= rvalue
;;) {
4650 _cleanup_free_
char *word
= NULL
;
4653 r
= extract_first_word(&p
, &word
, NULL
, 0);
4657 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4658 "Failed to parse %s=%s, ignoring: %m", lvalue
, rvalue
);
4664 /* We need to call exit_status_from_string() first, because we want
4665 * to parse numbers as exit statuses, not signals. */
4667 r
= exit_status_from_string(word
);
4669 assert(r
>= 0 && r
< 256);
4670 bitmap
= &status_set
->status
;
4672 r
= signal_from_string(word
);
4674 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4675 "Failed to parse value, ignoring: %s", word
);
4678 bitmap
= &status_set
->signal
;
4681 r
= bitmap_set(bitmap
, r
);
4683 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4684 "Failed to set signal or status %s, ignoring: %m", word
);
4688 int config_parse_namespace_path_strv(
4690 const char *filename
,
4692 const char *section
,
4693 unsigned section_line
,
4700 const Unit
*u
= userdata
;
4709 if (isempty(rvalue
)) {
4710 /* Empty assignment resets the list */
4711 *sv
= strv_free(*sv
);
4715 for (const char *p
= rvalue
;;) {
4716 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
, *joined
= NULL
;
4718 bool ignore_enoent
= false, shall_prefix
= false;
4720 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
4726 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
4731 if (startswith(w
, "-")) {
4732 ignore_enoent
= true;
4735 if (startswith(w
, "+")) {
4736 shall_prefix
= true;
4740 r
= unit_full_printf(u
, w
, &resolved
);
4742 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", w
);
4746 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4750 joined
= strjoin(ignore_enoent
? "-" : "",
4751 shall_prefix
? "+" : "",
4754 r
= strv_push(sv
, joined
);
4764 int config_parse_temporary_filesystems(
4766 const char *filename
,
4768 const char *section
,
4769 unsigned section_line
,
4776 const Unit
*u
= userdata
;
4777 ExecContext
*c
= data
;
4785 if (isempty(rvalue
)) {
4786 /* Empty assignment resets the list */
4787 temporary_filesystem_free_many(c
->temporary_filesystems
, c
->n_temporary_filesystems
);
4788 c
->temporary_filesystems
= NULL
;
4789 c
->n_temporary_filesystems
= 0;
4793 for (const char *p
= rvalue
;;) {
4794 _cleanup_free_
char *word
= NULL
, *path
= NULL
, *resolved
= NULL
;
4797 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
4803 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
4808 r
= extract_first_word(&w
, &path
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4812 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", word
);
4816 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid syntax, ignoring: %s", word
);
4820 r
= unit_full_printf(u
, path
, &resolved
);
4822 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", path
);
4826 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4830 r
= temporary_filesystem_add(&c
->temporary_filesystems
, &c
->n_temporary_filesystems
, resolved
, w
);
4836 int config_parse_bind_paths(
4838 const char *filename
,
4840 const char *section
,
4841 unsigned section_line
,
4848 ExecContext
*c
= data
;
4849 const Unit
*u
= userdata
;
4857 if (isempty(rvalue
)) {
4858 /* Empty assignment resets the list */
4859 bind_mount_free_many(c
->bind_mounts
, c
->n_bind_mounts
);
4860 c
->bind_mounts
= NULL
;
4861 c
->n_bind_mounts
= 0;
4865 for (const char *p
= rvalue
;;) {
4866 _cleanup_free_
char *source
= NULL
, *destination
= NULL
;
4867 _cleanup_free_
char *sresolved
= NULL
, *dresolved
= NULL
;
4868 char *s
= NULL
, *d
= NULL
;
4869 bool rbind
= true, ignore_enoent
= false;
4871 r
= extract_first_word(&p
, &source
, ":" WHITESPACE
, EXTRACT_UNQUOTE
|EXTRACT_DONT_COALESCE_SEPARATORS
);
4877 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
4881 r
= unit_full_printf(u
, source
, &sresolved
);
4883 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4884 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", source
);
4890 ignore_enoent
= true;
4894 r
= path_simplify_and_warn(s
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4898 /* Optionally, the destination is specified. */
4899 if (p
&& p
[-1] == ':') {
4900 r
= extract_first_word(&p
, &destination
, ":" WHITESPACE
, EXTRACT_UNQUOTE
|EXTRACT_DONT_COALESCE_SEPARATORS
);
4904 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
4908 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Missing argument after ':', ignoring: %s", s
);
4912 r
= unit_full_printf(u
, destination
, &dresolved
);
4914 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4915 "Failed to resolve specifiers in \"%s\", ignoring: %m", destination
);
4919 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4925 /* Optionally, there's also a short option string specified */
4926 if (p
&& p
[-1] == ':') {
4927 _cleanup_free_
char *options
= NULL
;
4929 r
= extract_first_word(&p
, &options
, NULL
, EXTRACT_UNQUOTE
);
4933 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s: %s", lvalue
, rvalue
);
4937 if (isempty(options
) || streq(options
, "rbind"))
4939 else if (streq(options
, "norbind"))
4942 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid option string, ignoring setting: %s", options
);
4949 r
= bind_mount_add(&c
->bind_mounts
, &c
->n_bind_mounts
,
4953 .read_only
= !!strstr(lvalue
, "ReadOnly"),
4955 .ignore_enoent
= ignore_enoent
,
4964 int config_parse_mount_images(
4966 const char *filename
,
4968 const char *section
,
4969 unsigned section_line
,
4976 ExecContext
*c
= data
;
4977 const Unit
*u
= userdata
;
4985 if (isempty(rvalue
)) {
4986 /* Empty assignment resets the list */
4987 c
->mount_images
= mount_image_free_many(c
->mount_images
, &c
->n_mount_images
);
4991 for (const char *p
= rvalue
;;) {
4992 _cleanup_(mount_options_free_allp
) MountOptions
*options
= NULL
;
4993 _cleanup_free_
char *first
= NULL
, *second
= NULL
, *tuple
= NULL
;
4994 _cleanup_free_
char *sresolved
= NULL
, *dresolved
= NULL
;
4995 const char *q
= NULL
;
4997 bool permissive
= false;
4999 r
= extract_first_word(&p
, &tuple
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_RETAIN_ESCAPE
);
5003 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5004 "Invalid syntax %s=%s, ignoring: %m", lvalue
, rvalue
);
5011 r
= extract_many_words(&q
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
, &first
, &second
, NULL
);
5015 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5016 "Invalid syntax in %s=, ignoring: %s", lvalue
, tuple
);
5022 r
= unit_full_printf(u
, first
, &sresolved
);
5024 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5025 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", first
);
5035 r
= path_simplify_and_warn(s
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5039 if (isempty(second
)) {
5040 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Missing destination in %s, ignoring: %s", lvalue
, rvalue
);
5044 r
= unit_full_printf(u
, second
, &dresolved
);
5046 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5047 "Failed to resolve specifiers in \"%s\", ignoring: %m", second
);
5051 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5056 _cleanup_free_
char *partition
= NULL
, *mount_options
= NULL
, *mount_options_resolved
= NULL
;
5057 MountOptions
*o
= NULL
;
5058 PartitionDesignator partition_designator
;
5060 r
= extract_many_words(&q
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
, &partition
, &mount_options
, NULL
);
5064 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", q
);
5069 /* Single set of options, applying to the root partition/single filesystem */
5071 r
= unit_full_printf(u
, partition
, &mount_options_resolved
);
5073 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", first
);
5077 o
= new(MountOptions
, 1);
5080 *o
= (MountOptions
) {
5081 .partition_designator
= PARTITION_ROOT
,
5082 .options
= TAKE_PTR(mount_options_resolved
),
5084 LIST_APPEND(mount_options
, options
, o
);
5089 partition_designator
= partition_designator_from_string(partition
);
5090 if (partition_designator
< 0) {
5091 log_syntax(unit
, LOG_WARNING
, filename
, line
, partition_designator
,
5092 "Invalid partition name %s, ignoring", partition
);
5095 r
= unit_full_printf(u
, mount_options
, &mount_options_resolved
);
5097 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", mount_options
);
5101 o
= new(MountOptions
, 1);
5104 *o
= (MountOptions
) {
5105 .partition_designator
= partition_designator
,
5106 .options
= TAKE_PTR(mount_options_resolved
),
5108 LIST_APPEND(mount_options
, options
, o
);
5111 r
= mount_image_add(&c
->mount_images
, &c
->n_mount_images
,
5114 .destination
= dresolved
,
5115 .mount_options
= options
,
5116 .ignore_enoent
= permissive
,
5123 int config_parse_job_timeout_sec(
5125 const char *filename
,
5127 const char *section
,
5128 unsigned section_line
,
5144 r
= parse_sec_fix_0(rvalue
, &usec
);
5146 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse JobTimeoutSec= parameter, ignoring: %s", rvalue
);
5150 /* If the user explicitly changed JobTimeoutSec= also change JobRunningTimeoutSec=, for compatibility with old
5151 * versions. If JobRunningTimeoutSec= was explicitly set, avoid this however as whatever the user picked should
5154 if (!u
->job_running_timeout_set
)
5155 u
->job_running_timeout
= usec
;
5157 u
->job_timeout
= usec
;
5162 int config_parse_job_running_timeout_sec(
5164 const char *filename
,
5166 const char *section
,
5167 unsigned section_line
,
5183 r
= parse_sec_fix_0(rvalue
, &usec
);
5185 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse JobRunningTimeoutSec= parameter, ignoring: %s", rvalue
);
5189 u
->job_running_timeout
= usec
;
5190 u
->job_running_timeout_set
= true;
5195 int config_parse_emergency_action(
5197 const char *filename
,
5199 const char *section
,
5200 unsigned section_line
,
5208 EmergencyAction
*x
= data
;
5217 m
= ((Unit
*) userdata
)->manager
;
5221 r
= parse_emergency_action(rvalue
, MANAGER_IS_SYSTEM(m
), x
);
5223 if (r
== -EOPNOTSUPP
&& MANAGER_IS_USER(m
)) {
5224 /* Compat mode: remove for systemd 241. */
5226 log_syntax(unit
, LOG_INFO
, filename
, line
, r
,
5227 "%s= in user mode specified as \"%s\", using \"exit-force\" instead.",
5229 *x
= EMERGENCY_ACTION_EXIT_FORCE
;
5233 if (r
== -EOPNOTSUPP
)
5234 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5235 "%s= specified as %s mode action, ignoring: %s",
5236 lvalue
, MANAGER_IS_SYSTEM(m
) ? "user" : "system", rvalue
);
5238 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5239 "Failed to parse %s=, ignoring: %s", lvalue
, rvalue
);
5246 int config_parse_pid_file(
5248 const char *filename
,
5250 const char *section
,
5251 unsigned section_line
,
5258 _cleanup_free_
char *k
= NULL
, *n
= NULL
;
5259 const Unit
*u
= userdata
;
5268 if (isempty(rvalue
)) {
5269 /* An empty assignment removes already set value. */
5274 r
= unit_full_printf(u
, rvalue
, &k
);
5276 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
5280 /* If this is a relative path make it absolute by prefixing the /run */
5281 n
= path_make_absolute(k
, u
->manager
->prefix
[EXEC_DIRECTORY_RUNTIME
]);
5285 /* Check that the result is a sensible path */
5286 r
= path_simplify_and_warn(n
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5290 r
= patch_var_run(unit
, filename
, line
, lvalue
, &n
);
5294 free_and_replace(*s
, n
);
5298 int config_parse_exit_status(
5300 const char *filename
,
5302 const char *section
,
5303 unsigned section_line
,
5310 int *exit_status
= data
, r
;
5316 assert(exit_status
);
5318 if (isempty(rvalue
)) {
5323 r
= safe_atou8(rvalue
, &u
);
5325 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse exit status '%s', ignoring: %m", rvalue
);
5333 int config_parse_disable_controllers(
5335 const char *filename
,
5337 const char *section
,
5338 unsigned section_line
,
5346 CGroupContext
*c
= data
;
5347 CGroupMask disabled_mask
;
5349 /* 1. If empty, make all controllers eligible for use again.
5350 * 2. If non-empty, merge all listed controllers, space separated. */
5352 if (isempty(rvalue
)) {
5353 c
->disable_controllers
= 0;
5357 r
= cg_mask_from_string(rvalue
, &disabled_mask
);
5358 if (r
< 0 || disabled_mask
<= 0) {
5359 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid cgroup string: %s, ignoring", rvalue
);
5363 c
->disable_controllers
|= disabled_mask
;
5368 int config_parse_ip_filter_bpf_progs(
5370 const char *filename
,
5372 const char *section
,
5373 unsigned section_line
,
5380 _cleanup_free_
char *resolved
= NULL
;
5381 const Unit
*u
= userdata
;
5382 char ***paths
= data
;
5390 if (isempty(rvalue
)) {
5391 *paths
= strv_free(*paths
);
5395 r
= unit_full_printf(u
, rvalue
, &resolved
);
5397 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
5401 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5405 if (strv_contains(*paths
, resolved
))
5408 r
= strv_extend(paths
, resolved
);
5412 r
= bpf_firewall_supported();
5415 if (r
!= BPF_FIREWALL_SUPPORTED_WITH_MULTI
) {
5416 static bool warned
= false;
5418 log_full(warned
? LOG_DEBUG
: LOG_WARNING
,
5419 "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"
5420 "Starting this unit will fail! (This warning is only shown for the first loaded unit using IP firewalling.)", filename
, line
, lvalue
, rvalue
);
5428 static int merge_by_names(Unit
**u
, Set
*names
, const char *id
) {
5435 /* Let's try to add in all names that are aliases of this unit */
5436 while ((k
= set_steal_first(names
))) {
5437 _cleanup_free_ _unused_
char *free_k
= k
;
5439 /* First try to merge in the other name into our unit */
5440 r
= unit_merge_by_name(*u
, k
);
5444 /* Hmm, we couldn't merge the other unit into ours? Then let's try it the other way
5447 other
= manager_get_unit((*u
)->manager
, k
);
5449 return r
; /* return previous failure */
5451 r
= unit_merge(other
, *u
);
5456 return merge_by_names(u
, names
, NULL
);
5459 if (streq_ptr(id
, k
))
5460 unit_choose_id(*u
, id
);
5466 int unit_load_fragment(Unit
*u
) {
5467 const char *fragment
;
5468 _cleanup_set_free_free_ Set
*names
= NULL
;
5472 assert(u
->load_state
== UNIT_STUB
);
5476 u
->load_state
= UNIT_LOADED
;
5480 /* Possibly rebuild the fragment map to catch new units */
5481 r
= unit_file_build_name_map(&u
->manager
->lookup_paths
,
5482 &u
->manager
->unit_cache_timestamp_hash
,
5483 &u
->manager
->unit_id_map
,
5484 &u
->manager
->unit_name_map
,
5485 &u
->manager
->unit_path_cache
);
5487 return log_error_errno(r
, "Failed to rebuild name map: %m");
5489 r
= unit_file_find_fragment(u
->manager
->unit_id_map
,
5490 u
->manager
->unit_name_map
,
5494 if (r
< 0 && r
!= -ENOENT
)
5498 /* Open the file, check if this is a mask, otherwise read. */
5499 _cleanup_fclose_
FILE *f
= NULL
;
5502 /* Try to open the file name. A symlink is OK, for example for linked files or masks. We
5503 * expect that all symlinks within the lookup paths have been already resolved, but we don't
5504 * verify this here. */
5505 f
= fopen(fragment
, "re");
5507 return log_unit_notice_errno(u
, errno
, "Failed to open %s: %m", fragment
);
5509 if (fstat(fileno(f
), &st
) < 0)
5512 r
= free_and_strdup(&u
->fragment_path
, fragment
);
5516 if (null_or_empty(&st
)) {
5517 /* Unit file is masked */
5519 u
->load_state
= u
->perpetual
? UNIT_LOADED
: UNIT_MASKED
; /* don't allow perpetual units to ever be masked */
5520 u
->fragment_mtime
= 0;
5522 u
->load_state
= UNIT_LOADED
;
5523 u
->fragment_mtime
= timespec_load(&st
.st_mtim
);
5525 /* Now, parse the file contents */
5526 r
= config_parse(u
->id
, fragment
, f
,
5527 UNIT_VTABLE(u
)->sections
,
5528 config_item_perf_lookup
, load_fragment_gperf_lookup
,
5533 log_unit_notice_errno(u
, r
, "Unit configuration has fatal error, unit will not be started.");
5539 /* Call merge_by_names with the name derived from the fragment path as the preferred name.
5541 * We do the merge dance here because for some unit types, the unit might have aliases which are not
5542 * declared in the file system. In particular, this is true (and frequent) for device and swap units.
5544 const char *id
= u
->id
;
5545 _cleanup_free_
char *free_id
= NULL
;
5548 id
= basename(fragment
);
5549 if (unit_name_is_valid(id
, UNIT_NAME_TEMPLATE
)) {
5550 assert(u
->instance
); /* If we're not trying to use a template for non-instanced unit,
5551 * this must be set. */
5553 r
= unit_name_replace_instance(id
, u
->instance
, &free_id
);
5555 return log_debug_errno(r
, "Failed to build id (%s + %s): %m", id
, u
->instance
);
5561 r
= merge_by_names(&merged
, names
, id
);
5566 u
->load_state
= UNIT_MERGED
;
5571 void unit_dump_config_items(FILE *f
) {
5572 static const struct {
5573 const ConfigParserCallback callback
;
5576 { config_parse_warn_compat
, "NOTSUPPORTED" },
5577 { config_parse_int
, "INTEGER" },
5578 { config_parse_unsigned
, "UNSIGNED" },
5579 { config_parse_iec_size
, "SIZE" },
5580 { config_parse_iec_uint64
, "SIZE" },
5581 { config_parse_si_uint64
, "SIZE" },
5582 { config_parse_bool
, "BOOLEAN" },
5583 { config_parse_string
, "STRING" },
5584 { config_parse_path
, "PATH" },
5585 { config_parse_unit_path_printf
, "PATH" },
5586 { config_parse_strv
, "STRING [...]" },
5587 { config_parse_exec_nice
, "NICE" },
5588 { config_parse_exec_oom_score_adjust
, "OOMSCOREADJUST" },
5589 { config_parse_exec_io_class
, "IOCLASS" },
5590 { config_parse_exec_io_priority
, "IOPRIORITY" },
5591 { config_parse_exec_cpu_sched_policy
, "CPUSCHEDPOLICY" },
5592 { config_parse_exec_cpu_sched_prio
, "CPUSCHEDPRIO" },
5593 { config_parse_exec_cpu_affinity
, "CPUAFFINITY" },
5594 { config_parse_mode
, "MODE" },
5595 { config_parse_unit_env_file
, "FILE" },
5596 { config_parse_exec_output
, "OUTPUT" },
5597 { config_parse_exec_input
, "INPUT" },
5598 { config_parse_log_facility
, "FACILITY" },
5599 { config_parse_log_level
, "LEVEL" },
5600 { config_parse_exec_secure_bits
, "SECUREBITS" },
5601 { config_parse_capability_set
, "BOUNDINGSET" },
5602 { config_parse_rlimit
, "LIMIT" },
5603 { config_parse_unit_deps
, "UNIT [...]" },
5604 { config_parse_exec
, "PATH [ARGUMENT [...]]" },
5605 { config_parse_service_type
, "SERVICETYPE" },
5606 { config_parse_service_restart
, "SERVICERESTART" },
5607 { config_parse_service_timeout_failure_mode
, "TIMEOUTMODE" },
5608 { config_parse_kill_mode
, "KILLMODE" },
5609 { config_parse_signal
, "SIGNAL" },
5610 { config_parse_socket_listen
, "SOCKET [...]" },
5611 { config_parse_socket_bind
, "SOCKETBIND" },
5612 { config_parse_socket_bindtodevice
, "NETWORKINTERFACE" },
5613 { config_parse_sec
, "SECONDS" },
5614 { config_parse_nsec
, "NANOSECONDS" },
5615 { config_parse_namespace_path_strv
, "PATH [...]" },
5616 { config_parse_bind_paths
, "PATH[:PATH[:OPTIONS]] [...]" },
5617 { config_parse_unit_requires_mounts_for
, "PATH [...]" },
5618 { config_parse_exec_mount_flags
, "MOUNTFLAG [...]" },
5619 { config_parse_unit_string_printf
, "STRING" },
5620 { config_parse_trigger_unit
, "UNIT" },
5621 { config_parse_timer
, "TIMER" },
5622 { config_parse_path_spec
, "PATH" },
5623 { config_parse_notify_access
, "ACCESS" },
5624 { config_parse_ip_tos
, "TOS" },
5625 { config_parse_unit_condition_path
, "CONDITION" },
5626 { config_parse_unit_condition_string
, "CONDITION" },
5627 { config_parse_unit_slice
, "SLICE" },
5628 { config_parse_documentation
, "URL" },
5629 { config_parse_service_timeout
, "SECONDS" },
5630 { config_parse_emergency_action
, "ACTION" },
5631 { config_parse_set_status
, "STATUS" },
5632 { config_parse_service_sockets
, "SOCKETS" },
5633 { config_parse_environ
, "ENVIRON" },
5635 { config_parse_syscall_filter
, "SYSCALLS" },
5636 { config_parse_syscall_archs
, "ARCHS" },
5637 { config_parse_syscall_errno
, "ERRNO" },
5638 { config_parse_syscall_log
, "SYSCALLS" },
5639 { config_parse_address_families
, "FAMILIES" },
5640 { config_parse_restrict_namespaces
, "NAMESPACES" },
5642 { config_parse_cpu_shares
, "SHARES" },
5643 { config_parse_cg_weight
, "WEIGHT" },
5644 { config_parse_memory_limit
, "LIMIT" },
5645 { config_parse_device_allow
, "DEVICE" },
5646 { config_parse_device_policy
, "POLICY" },
5647 { config_parse_io_limit
, "LIMIT" },
5648 { config_parse_io_device_weight
, "DEVICEWEIGHT" },
5649 { config_parse_io_device_latency
, "DEVICELATENCY" },
5650 { config_parse_blockio_bandwidth
, "BANDWIDTH" },
5651 { config_parse_blockio_weight
, "WEIGHT" },
5652 { config_parse_blockio_device_weight
, "DEVICEWEIGHT" },
5653 { config_parse_long
, "LONG" },
5654 { config_parse_socket_service
, "SERVICE" },
5656 { config_parse_exec_selinux_context
, "LABEL" },
5658 { config_parse_job_mode
, "MODE" },
5659 { config_parse_job_mode_isolate
, "BOOLEAN" },
5660 { config_parse_personality
, "PERSONALITY" },
5663 const char *prev
= NULL
;
5668 NULSTR_FOREACH(i
, load_fragment_gperf_nulstr
) {
5669 const char *rvalue
= "OTHER", *lvalue
;
5670 const ConfigPerfItem
*p
;
5673 assert_se(p
= load_fragment_gperf_lookup(i
, strlen(i
)));
5675 /* Hide legacy settings */
5676 if (p
->parse
== config_parse_warn_compat
&&
5677 p
->ltype
== DISABLED_LEGACY
)
5680 for (size_t j
= 0; j
< ELEMENTSOF(table
); j
++)
5681 if (p
->parse
== table
[j
].callback
) {
5682 rvalue
= table
[j
].rvalue
;
5686 dot
= strchr(i
, '.');
5687 lvalue
= dot
? dot
+ 1 : i
;
5690 size_t prefix_len
= dot
- i
;
5692 if (!prev
|| !strneq(prev
, i
, prefix_len
+1)) {
5696 fprintf(f
, "[%.*s]\n", (int) prefix_len
, i
);
5700 fprintf(f
, "%s=%s\n", lvalue
, rvalue
);
5705 int config_parse_cpu_affinity2(
5707 const char *filename
,
5709 const char *section
,
5710 unsigned section_line
,
5717 CPUSet
*affinity
= data
;
5721 (void) parse_cpu_set_extend(rvalue
, affinity
, true, unit
, filename
, line
, lvalue
);
5726 int config_parse_show_status(
5728 const char *filename
,
5730 const char *section
,
5731 unsigned section_line
,
5739 ShowStatus
*b
= data
;
5746 k
= parse_show_status(rvalue
, b
);
5748 log_syntax(unit
, LOG_WARNING
, filename
, line
, k
, "Failed to parse show status setting, ignoring: %s", rvalue
);
5753 int config_parse_output_restricted(
5755 const char *filename
,
5757 const char *section
,
5758 unsigned section_line
,
5765 ExecOutput t
, *eo
= data
;
5766 bool obsolete
= false;
5773 if (streq(rvalue
, "syslog")) {
5774 t
= EXEC_OUTPUT_JOURNAL
;
5776 } else if (streq(rvalue
, "syslog+console")) {
5777 t
= EXEC_OUTPUT_JOURNAL_AND_CONSOLE
;
5780 t
= exec_output_from_string(rvalue
);
5782 log_syntax(unit
, LOG_WARNING
, filename
, line
, t
, "Failed to parse output type, ignoring: %s", rvalue
);
5786 if (IN_SET(t
, EXEC_OUTPUT_SOCKET
, EXEC_OUTPUT_NAMED_FD
, EXEC_OUTPUT_FILE
, EXEC_OUTPUT_FILE_APPEND
, EXEC_OUTPUT_FILE_TRUNCATE
)) {
5787 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Standard output types socket, fd:, file:, append:, truncate: are not supported as defaults, ignoring: %s", rvalue
);
5793 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
5794 "Standard output type %s is obsolete, automatically updating to %s. Please update your configuration.",
5795 rvalue
, exec_output_to_string(t
));
5801 int config_parse_crash_chvt(
5803 const char *filename
,
5805 const char *section
,
5806 unsigned section_line
,
5820 r
= parse_crash_chvt(rvalue
, data
);
5822 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse CrashChangeVT= setting, ignoring: %s", rvalue
);
5827 int config_parse_swap_priority(
5829 const char *filename
,
5831 const char *section
,
5832 unsigned section_line
,
5848 if (isempty(rvalue
)) {
5849 s
->parameters_fragment
.priority
= -1;
5850 s
->parameters_fragment
.priority_set
= false;
5854 r
= safe_atoi(rvalue
, &priority
);
5856 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid swap priority '%s', ignoring.", rvalue
);
5860 if (priority
< -1) {
5861 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
);
5865 if (priority
> 32767) {
5866 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Swap priority out of range, ignoring: %s", rvalue
);
5870 s
->parameters_fragment
.priority
= priority
;
5871 s
->parameters_fragment
.priority_set
= true;