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_WITH_DEFAULT(config_parse_ip_tos
, ip_tos
, int, -1, "Failed to parse IP TOS value");
137 DEFINE_CONFIG_PARSE_PTR(config_parse_blockio_weight
, cg_blkio_weight_parse
, uint64_t, "Invalid block IO weight");
138 DEFINE_CONFIG_PARSE_PTR(config_parse_cg_weight
, cg_weight_parse
, uint64_t, "Invalid weight");
139 DEFINE_CONFIG_PARSE_PTR(config_parse_cpu_shares
, cg_cpu_shares_parse
, uint64_t, "Invalid CPU shares");
140 DEFINE_CONFIG_PARSE_PTR(config_parse_exec_mount_flags
, mount_propagation_flags_from_string
, unsigned long, "Failed to parse mount flag");
141 DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_numa_policy
, mpol
, int, -1, "Invalid NUMA policy type");
142 DEFINE_CONFIG_PARSE_ENUM(config_parse_status_unit_format
, status_unit_format
, StatusUnitFormat
, "Failed to parse status unit format");
143 DEFINE_CONFIG_PARSE_ENUM_FULL(config_parse_socket_timestamping
, socket_timestamping_from_string_harder
, SocketTimestamping
, "Failed to parse timestamping precision");
145 int config_parse_unit_deps(
147 const char *filename
,
150 unsigned section_line
,
157 UnitDependency d
= ltype
;
164 for (const char *p
= rvalue
;;) {
165 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
168 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_RETAIN_ESCAPE
);
174 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
178 r
= unit_name_printf(u
, word
, &k
);
180 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
184 r
= unit_add_dependency_by_name(u
, d
, k
, true, UNIT_DEPENDENCY_FILE
);
186 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
190 int config_parse_obsolete_unit_deps(
192 const char *filename
,
195 unsigned section_line
,
202 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
203 "Unit dependency type %s= is obsolete, replacing by %s=, please update your unit file", lvalue
, unit_dependency_to_string(ltype
));
205 return config_parse_unit_deps(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
);
208 int config_parse_unit_string_printf(
210 const char *filename
,
213 unsigned section_line
,
220 _cleanup_free_
char *k
= NULL
;
221 const Unit
*u
= userdata
;
229 r
= unit_full_printf(u
, rvalue
, &k
);
231 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
235 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
238 int config_parse_unit_strv_printf(
240 const char *filename
,
243 unsigned section_line
,
250 const Unit
*u
= userdata
;
251 _cleanup_free_
char *k
= NULL
;
259 r
= unit_full_printf(u
, rvalue
, &k
);
261 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
265 return config_parse_strv(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
268 int config_parse_unit_path_printf(
270 const char *filename
,
273 unsigned section_line
,
280 _cleanup_free_
char *k
= NULL
;
281 const Unit
*u
= userdata
;
290 /* Let's not bother with anything that is too long */
291 if (strlen(rvalue
) >= PATH_MAX
) {
292 log_syntax(unit
, fatal
? LOG_ERR
: LOG_WARNING
, filename
, line
, 0,
293 "%s value too long%s.",
294 lvalue
, fatal
? "" : ", ignoring");
295 return fatal
? -ENAMETOOLONG
: 0;
298 r
= unit_full_printf(u
, rvalue
, &k
);
300 log_syntax(unit
, fatal
? LOG_ERR
: LOG_WARNING
, filename
, line
, r
,
301 "Failed to resolve unit specifiers in '%s'%s: %m",
302 rvalue
, fatal
? "" : ", ignoring");
303 return fatal
? -ENOEXEC
: 0;
306 return config_parse_path(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
309 int config_parse_unit_path_strv_printf(
311 const char *filename
,
314 unsigned section_line
,
322 const Unit
*u
= userdata
;
330 if (isempty(rvalue
)) {
335 for (const char *p
= rvalue
;;) {
336 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
338 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
344 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
345 "Invalid syntax, ignoring: %s", rvalue
);
349 r
= unit_full_printf(u
, word
, &k
);
351 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
352 "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
356 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
360 r
= strv_consume(x
, TAKE_PTR(k
));
366 static int patch_var_run(
368 const char *filename
,
376 e
= path_startswith(*path
, "/var/run/");
380 z
= path_join("/run/", e
);
384 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
385 "%s= references a path below legacy directory /var/run/, updating %s → %s; "
386 "please update the unit file accordingly.", lvalue
, *path
, z
);
388 free_and_replace(*path
, z
);
393 int config_parse_socket_listen(
395 const char *filename
,
398 unsigned section_line
,
405 _cleanup_free_ SocketPort
*p
= NULL
;
417 if (isempty(rvalue
)) {
418 /* An empty assignment removes all ports */
419 socket_free_ports(s
);
423 p
= new0(SocketPort
, 1);
427 if (ltype
!= SOCKET_SOCKET
) {
428 _cleanup_free_
char *k
= NULL
;
430 r
= unit_full_printf(UNIT(s
), rvalue
, &k
);
432 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
436 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
440 if (ltype
== SOCKET_FIFO
) {
441 r
= patch_var_run(unit
, filename
, line
, lvalue
, &k
);
446 free_and_replace(p
->path
, k
);
449 } else if (streq(lvalue
, "ListenNetlink")) {
450 _cleanup_free_
char *k
= NULL
;
452 r
= unit_full_printf(UNIT(s
), rvalue
, &k
);
454 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
458 r
= socket_address_parse_netlink(&p
->address
, k
);
460 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse address value in '%s', ignoring: %m", k
);
464 p
->type
= SOCKET_SOCKET
;
467 _cleanup_free_
char *k
= NULL
;
469 r
= unit_full_printf(UNIT(s
), rvalue
, &k
);
471 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
475 if (k
[0] == '/') { /* Only for AF_UNIX file system sockets… */
476 r
= patch_var_run(unit
, filename
, line
, lvalue
, &k
);
481 r
= socket_address_parse_and_warn(&p
->address
, k
);
483 if (r
!= -EAFNOSUPPORT
)
484 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse address value in '%s', ignoring: %m", k
);
488 if (streq(lvalue
, "ListenStream"))
489 p
->address
.type
= SOCK_STREAM
;
490 else if (streq(lvalue
, "ListenDatagram"))
491 p
->address
.type
= SOCK_DGRAM
;
493 assert(streq(lvalue
, "ListenSequentialPacket"));
494 p
->address
.type
= SOCK_SEQPACKET
;
497 if (socket_address_family(&p
->address
) != AF_LOCAL
&& p
->address
.type
== SOCK_SEQPACKET
) {
498 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Address family not supported, ignoring: %s", rvalue
);
502 p
->type
= SOCKET_SOCKET
;
506 p
->auxiliary_fds
= NULL
;
507 p
->n_auxiliary_fds
= 0;
510 LIST_FIND_TAIL(port
, s
->ports
, tail
);
511 LIST_INSERT_AFTER(port
, s
->ports
, tail
, p
);
518 int config_parse_exec_nice(
520 const char *filename
,
523 unsigned section_line
,
530 ExecContext
*c
= data
;
538 if (isempty(rvalue
)) {
543 r
= parse_nice(rvalue
, &priority
);
546 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Nice priority out of range, ignoring: %s", rvalue
);
548 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse nice priority '%s', ignoring: %m", rvalue
);
558 int config_parse_exec_oom_score_adjust(
560 const char *filename
,
563 unsigned section_line
,
570 ExecContext
*c
= data
;
578 if (isempty(rvalue
)) {
579 c
->oom_score_adjust_set
= false;
583 r
= parse_oom_score_adjust(rvalue
, &oa
);
586 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "OOM score adjust value out of range, ignoring: %s", rvalue
);
588 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse the OOM score adjust value '%s', ignoring: %m", rvalue
);
592 c
->oom_score_adjust
= oa
;
593 c
->oom_score_adjust_set
= true;
598 int config_parse_exec_coredump_filter(
600 const char *filename
,
603 unsigned section_line
,
610 ExecContext
*c
= data
;
618 if (isempty(rvalue
)) {
619 c
->coredump_filter
= 0;
620 c
->coredump_filter_set
= false;
625 r
= coredump_filter_mask_from_string(rvalue
, &f
);
627 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
628 "Failed to parse the CoredumpFilter=%s, ignoring: %m", rvalue
);
632 c
->coredump_filter
|= f
;
633 c
->oom_score_adjust_set
= true;
637 int config_parse_kill_mode(
639 const char *filename
,
642 unsigned section_line
,
649 KillMode
*k
= data
, m
;
656 if (isempty(rvalue
)) {
657 *k
= KILL_CONTROL_GROUP
;
661 m
= kill_mode_from_string(rvalue
);
663 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
664 "Failed to parse kill mode specification, ignoring: %s", rvalue
);
669 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
670 "Unit configured to use KillMode=none. "
671 "This is unsafe, as it disables systemd's process lifecycle management for the service. "
672 "Please update your service to use a safer KillMode=, such as 'mixed' or 'control-group'. "
673 "Support for KillMode=none is deprecated and will eventually be removed.");
679 int config_parse_exec(
681 const char *filename
,
684 unsigned section_line
,
691 ExecCommand
**e
= data
;
692 const Unit
*u
= userdata
;
704 if (isempty(rvalue
)) {
705 /* An empty assignment resets the list */
706 *e
= exec_command_free_list(*e
);
712 _cleanup_free_
char *path
= NULL
, *firstword
= NULL
;
713 ExecCommandFlags flags
= 0;
714 bool ignore
= false, separate_argv0
= false;
715 _cleanup_free_ ExecCommand
*nce
= NULL
;
716 _cleanup_strv_free_
char **n
= NULL
;
717 size_t nlen
= 0, nbufsize
= 0;
722 r
= extract_first_word_and_warn(&p
, &firstword
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
726 /* A lone ";" is a separator. Let's make sure we don't treat it as an executable name. */
727 if (streq(firstword
, ";")) {
734 /* We accept an absolute path as first argument. If it's prefixed with - and the path doesn't
735 * exist, we ignore it instead of erroring out; if it's prefixed with @, we allow overriding of
736 * argv[0]; if it's prefixed with :, we will not do environment variable substitution;
737 * if it's prefixed with +, it will be run with full privileges and no sandboxing; if
738 * it's prefixed with '!' we apply sandboxing, but do not change user/group credentials; if
739 * it's prefixed with '!!', then we apply user/group credentials if the kernel supports ambient
740 * capabilities -- if it doesn't we don't apply the credentials themselves, but do apply most
741 * other sandboxing, with some special exceptions for changing UID.
743 * The idea is that '!!' may be used to write services that can take benefit of systemd's
744 * UID/GID dropping if the kernel supports ambient creds, but provide an automatic fallback to
745 * privilege dropping within the daemon if the kernel does not offer that. */
747 if (*f
== '-' && !(flags
& EXEC_COMMAND_IGNORE_FAILURE
)) {
748 flags
|= EXEC_COMMAND_IGNORE_FAILURE
;
750 } else if (*f
== '@' && !separate_argv0
)
751 separate_argv0
= true;
752 else if (*f
== ':' && !(flags
& EXEC_COMMAND_NO_ENV_EXPAND
))
753 flags
|= EXEC_COMMAND_NO_ENV_EXPAND
;
754 else if (*f
== '+' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
755 flags
|= EXEC_COMMAND_FULLY_PRIVILEGED
;
756 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
757 flags
|= EXEC_COMMAND_NO_SETUID
;
758 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_AMBIENT_MAGIC
))) {
759 flags
&= ~EXEC_COMMAND_NO_SETUID
;
760 flags
|= EXEC_COMMAND_AMBIENT_MAGIC
;
766 r
= unit_full_printf(u
, f
, &path
);
768 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
769 "Failed to resolve unit specifiers in '%s'%s: %m",
770 f
, ignore
? ", ignoring" : "");
771 return ignore
? 0 : -ENOEXEC
;
775 /* First word is either "-" or "@" with no command. */
776 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
777 "Empty path in command line%s: '%s'",
778 ignore
? ", ignoring" : "", rvalue
);
779 return ignore
? 0 : -ENOEXEC
;
781 if (!string_is_safe(path
)) {
782 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
783 "Executable name contains special characters%s: %s",
784 ignore
? ", ignoring" : "", path
);
785 return ignore
? 0 : -ENOEXEC
;
787 if (endswith(path
, "/")) {
788 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
789 "Executable path specifies a directory%s: %s",
790 ignore
? ", ignoring" : "", path
);
791 return ignore
? 0 : -ENOEXEC
;
794 if (!path_is_absolute(path
) && !filename_is_valid(path
)) {
795 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
796 "Neither a valid executable name nor an absolute path%s: %s",
797 ignore
? ", ignoring" : "", path
);
798 return ignore
? 0 : -ENOEXEC
;
801 if (!separate_argv0
) {
804 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
814 path_simplify(path
, false);
816 while (!isempty(p
)) {
817 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
819 /* Check explicitly for an unquoted semicolon as
820 * command separator token. */
821 if (p
[0] == ';' && (!p
[1] || strchr(WHITESPACE
, p
[1]))) {
823 p
+= strspn(p
, WHITESPACE
);
828 /* Check for \; explicitly, to not confuse it with \\; or "\;" or "\\;" etc.
829 * extract_first_word() would return the same for all of those. */
830 if (p
[0] == '\\' && p
[1] == ';' && (!p
[2] || strchr(WHITESPACE
, p
[2]))) {
834 p
+= strspn(p
, WHITESPACE
);
836 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
847 r
= extract_first_word_and_warn(&p
, &word
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
851 return ignore
? 0 : -ENOEXEC
;
853 r
= unit_full_printf(u
, word
, &resolved
);
855 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
856 "Failed to resolve unit specifiers in %s%s: %m",
857 word
, ignore
? ", ignoring" : "");
858 return ignore
? 0 : -ENOEXEC
;
861 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
864 n
[nlen
++] = TAKE_PTR(resolved
);
869 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
870 "Empty executable name or zeroeth argument%s: %s",
871 ignore
? ", ignoring" : "", rvalue
);
872 return ignore
? 0 : -ENOEXEC
;
875 nce
= new0(ExecCommand
, 1);
879 nce
->argv
= TAKE_PTR(n
);
880 nce
->path
= TAKE_PTR(path
);
883 exec_command_append_list(e
, nce
);
885 /* Do not _cleanup_free_ these. */
894 int config_parse_socket_bindtodevice(
896 const char *filename
,
899 unsigned section_line
,
913 if (isempty(rvalue
) || streq(rvalue
, "*")) {
914 s
->bind_to_device
= mfree(s
->bind_to_device
);
918 if (!ifname_valid(rvalue
)) {
919 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid interface name, ignoring: %s", rvalue
);
923 if (free_and_strdup(&s
->bind_to_device
, rvalue
) < 0)
929 int config_parse_exec_input(
931 const char *filename
,
934 unsigned section_line
,
941 ExecContext
*c
= data
;
942 const Unit
*u
= userdata
;
952 n
= startswith(rvalue
, "fd:");
954 _cleanup_free_
char *resolved
= NULL
;
956 r
= unit_full_printf(u
, n
, &resolved
);
958 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", n
);
962 if (isempty(resolved
))
963 resolved
= mfree(resolved
);
964 else if (!fdname_is_valid(resolved
)) {
965 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", resolved
);
969 free_and_replace(c
->stdio_fdname
[STDIN_FILENO
], resolved
);
971 ei
= EXEC_INPUT_NAMED_FD
;
973 } else if ((n
= startswith(rvalue
, "file:"))) {
974 _cleanup_free_
char *resolved
= NULL
;
976 r
= unit_full_printf(u
, n
, &resolved
);
978 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", n
);
982 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
986 free_and_replace(c
->stdio_file
[STDIN_FILENO
], resolved
);
988 ei
= EXEC_INPUT_FILE
;
991 ei
= exec_input_from_string(rvalue
);
993 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Failed to parse input specifier, ignoring: %s", rvalue
);
1002 int config_parse_exec_input_text(
1004 const char *filename
,
1006 const char *section
,
1007 unsigned section_line
,
1014 _cleanup_free_
char *unescaped
= NULL
, *resolved
= NULL
;
1015 ExecContext
*c
= data
;
1016 const Unit
*u
= userdata
;
1026 if (isempty(rvalue
)) {
1027 /* Reset if the empty string is assigned */
1028 c
->stdin_data
= mfree(c
->stdin_data
);
1029 c
->stdin_data_size
= 0;
1033 r
= cunescape(rvalue
, 0, &unescaped
);
1035 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1036 "Failed to decode C escaped text '%s', ignoring: %m", rvalue
);
1040 r
= unit_full_printf(u
, unescaped
, &resolved
);
1042 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1043 "Failed to resolve unit specifiers in '%s', ignoring: %m", unescaped
);
1047 sz
= strlen(resolved
);
1048 if (c
->stdin_data_size
+ sz
+ 1 < c
->stdin_data_size
|| /* check for overflow */
1049 c
->stdin_data_size
+ sz
+ 1 > EXEC_STDIN_DATA_MAX
) {
1050 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
1051 "Standard input data too large (%zu), maximum of %zu permitted, ignoring.",
1052 c
->stdin_data_size
+ sz
, (size_t) EXEC_STDIN_DATA_MAX
);
1056 p
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
+ 1);
1060 *((char*) mempcpy((char*) p
+ c
->stdin_data_size
, resolved
, sz
)) = '\n';
1063 c
->stdin_data_size
+= sz
+ 1;
1068 int config_parse_exec_input_data(
1070 const char *filename
,
1072 const char *section
,
1073 unsigned section_line
,
1080 _cleanup_free_
void *p
= NULL
;
1081 ExecContext
*c
= data
;
1091 if (isempty(rvalue
)) {
1092 /* Reset if the empty string is assigned */
1093 c
->stdin_data
= mfree(c
->stdin_data
);
1094 c
->stdin_data_size
= 0;
1098 r
= unbase64mem(rvalue
, (size_t) -1, &p
, &sz
);
1100 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1101 "Failed to decode base64 data, ignoring: %s", rvalue
);
1107 if (c
->stdin_data_size
+ sz
< c
->stdin_data_size
|| /* check for overflow */
1108 c
->stdin_data_size
+ sz
> EXEC_STDIN_DATA_MAX
) {
1109 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
1110 "Standard input data too large (%zu), maximum of %zu permitted, ignoring.",
1111 c
->stdin_data_size
+ sz
, (size_t) EXEC_STDIN_DATA_MAX
);
1115 q
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
);
1119 memcpy((uint8_t*) q
+ c
->stdin_data_size
, p
, sz
);
1122 c
->stdin_data_size
+= sz
;
1127 int config_parse_exec_output(
1129 const char *filename
,
1131 const char *section
,
1132 unsigned section_line
,
1139 _cleanup_free_
char *resolved
= NULL
;
1141 ExecContext
*c
= data
;
1142 const Unit
*u
= userdata
;
1143 bool obsolete
= false;
1153 n
= startswith(rvalue
, "fd:");
1155 r
= unit_full_printf(u
, n
, &resolved
);
1157 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", n
);
1161 if (isempty(resolved
))
1162 resolved
= mfree(resolved
);
1163 else if (!fdname_is_valid(resolved
)) {
1164 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", resolved
);
1168 eo
= EXEC_OUTPUT_NAMED_FD
;
1170 } else if (streq(rvalue
, "syslog")) {
1171 eo
= EXEC_OUTPUT_JOURNAL
;
1174 } else if (streq(rvalue
, "syslog+console")) {
1175 eo
= EXEC_OUTPUT_JOURNAL_AND_CONSOLE
;
1178 } else if ((n
= startswith(rvalue
, "file:"))) {
1180 r
= unit_full_printf(u
, n
, &resolved
);
1182 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", n
);
1186 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1190 eo
= EXEC_OUTPUT_FILE
;
1192 } else if ((n
= startswith(rvalue
, "append:"))) {
1194 r
= unit_full_printf(u
, n
, &resolved
);
1196 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", n
);
1200 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1204 eo
= EXEC_OUTPUT_FILE_APPEND
;
1206 eo
= exec_output_from_string(rvalue
);
1208 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Failed to parse output specifier, ignoring: %s", rvalue
);
1214 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
1215 "Standard output type %s is obsolete, automatically updating to %s. Please update your unit file, and consider removing the setting altogether.",
1216 rvalue
, exec_output_to_string(eo
));
1218 if (streq(lvalue
, "StandardOutput")) {
1219 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1220 free_and_replace(c
->stdio_fdname
[STDOUT_FILENO
], resolved
);
1222 free_and_replace(c
->stdio_file
[STDOUT_FILENO
], resolved
);
1227 assert(streq(lvalue
, "StandardError"));
1229 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1230 free_and_replace(c
->stdio_fdname
[STDERR_FILENO
], resolved
);
1232 free_and_replace(c
->stdio_file
[STDERR_FILENO
], resolved
);
1240 int config_parse_exec_io_class(const char *unit
,
1241 const char *filename
,
1243 const char *section
,
1244 unsigned section_line
,
1251 ExecContext
*c
= data
;
1259 if (isempty(rvalue
)) {
1260 c
->ioprio_set
= false;
1261 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE
, 0);
1265 x
= ioprio_class_from_string(rvalue
);
1267 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Failed to parse IO scheduling class, ignoring: %s", rvalue
);
1271 c
->ioprio
= IOPRIO_PRIO_VALUE(x
, IOPRIO_PRIO_DATA(c
->ioprio
));
1272 c
->ioprio_set
= true;
1277 int config_parse_exec_io_priority(const char *unit
,
1278 const char *filename
,
1280 const char *section
,
1281 unsigned section_line
,
1288 ExecContext
*c
= data
;
1296 if (isempty(rvalue
)) {
1297 c
->ioprio_set
= false;
1298 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE
, 0);
1302 r
= ioprio_parse_priority(rvalue
, &i
);
1304 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse IO priority, ignoring: %s", rvalue
);
1308 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_PRIO_CLASS(c
->ioprio
), i
);
1309 c
->ioprio_set
= true;
1314 int config_parse_exec_cpu_sched_policy(const char *unit
,
1315 const char *filename
,
1317 const char *section
,
1318 unsigned section_line
,
1325 ExecContext
*c
= data
;
1333 if (isempty(rvalue
)) {
1334 c
->cpu_sched_set
= false;
1335 c
->cpu_sched_policy
= SCHED_OTHER
;
1336 c
->cpu_sched_priority
= 0;
1340 x
= sched_policy_from_string(rvalue
);
1342 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Failed to parse CPU scheduling policy, ignoring: %s", rvalue
);
1346 c
->cpu_sched_policy
= x
;
1347 /* Moving to or from real-time policy? We need to adjust the priority */
1348 c
->cpu_sched_priority
= CLAMP(c
->cpu_sched_priority
, sched_get_priority_min(x
), sched_get_priority_max(x
));
1349 c
->cpu_sched_set
= true;
1354 int config_parse_exec_mount_apivfs(const char *unit
,
1355 const char *filename
,
1357 const char *section
,
1358 unsigned section_line
,
1365 ExecContext
*c
= data
;
1373 if (isempty(rvalue
)) {
1374 c
->mount_apivfs_set
= false;
1375 c
->mount_apivfs
= false;
1379 k
= parse_boolean(rvalue
);
1381 log_syntax(unit
, LOG_WARNING
, filename
, line
, k
,
1382 "Failed to parse boolean value, ignoring: %s",
1387 c
->mount_apivfs_set
= true;
1388 c
->mount_apivfs
= k
;
1392 int config_parse_numa_mask(const char *unit
,
1393 const char *filename
,
1395 const char *section
,
1396 unsigned section_line
,
1403 NUMAPolicy
*p
= data
;
1410 if (streq(rvalue
, "all")) {
1411 r
= numa_mask_add_all(&p
->nodes
);
1413 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1414 "Failed to create NUMA mask representing \"all\" NUMA nodes, ignoring: %m");
1416 r
= parse_cpu_set_extend(rvalue
, &p
->nodes
, true, unit
, filename
, line
, lvalue
);
1418 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse NUMA node mask, ignoring: %s", rvalue
);
1424 int config_parse_exec_cpu_sched_prio(const char *unit
,
1425 const char *filename
,
1427 const char *section
,
1428 unsigned section_line
,
1435 ExecContext
*c
= data
;
1443 r
= safe_atoi(rvalue
, &i
);
1445 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse CPU scheduling priority, ignoring: %s", rvalue
);
1449 /* On Linux RR/FIFO range from 1 to 99 and OTHER/BATCH may only be 0 */
1450 min
= sched_get_priority_min(c
->cpu_sched_policy
);
1451 max
= sched_get_priority_max(c
->cpu_sched_policy
);
1453 if (i
< min
|| i
> max
) {
1454 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "CPU scheduling priority is out of range, ignoring: %s", rvalue
);
1458 c
->cpu_sched_priority
= i
;
1459 c
->cpu_sched_set
= true;
1464 int config_parse_root_image_options(
1466 const char *filename
,
1468 const char *section
,
1469 unsigned section_line
,
1476 _cleanup_(mount_options_free_allp
) MountOptions
*options
= NULL
;
1477 _cleanup_strv_free_
char **l
= NULL
;
1478 char **first
= NULL
, **second
= NULL
;
1479 ExecContext
*c
= data
;
1480 const Unit
*u
= userdata
;
1488 if (isempty(rvalue
)) {
1489 c
->root_image_options
= mount_options_free_all(c
->root_image_options
);
1493 r
= strv_split_colon_pairs(&l
, rvalue
);
1497 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
1501 STRV_FOREACH_PAIR(first
, second
, l
) {
1502 MountOptions
*o
= NULL
;
1503 _cleanup_free_
char *mount_options_resolved
= NULL
;
1504 const char *mount_options
= NULL
, *partition
= "root";
1505 PartitionDesignator partition_designator
;
1507 /* Format is either 'root:foo' or 'foo' (root is implied) */
1508 if (!isempty(*second
)) {
1510 mount_options
= *second
;
1512 mount_options
= *first
;
1514 partition_designator
= partition_designator_from_string(partition
);
1515 if (partition_designator
< 0) {
1516 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid partition name %s, ignoring", partition
);
1519 r
= unit_full_printf(u
, mount_options
, &mount_options_resolved
);
1521 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", mount_options
);
1525 o
= new(MountOptions
, 1);
1528 *o
= (MountOptions
) {
1529 .partition_designator
= partition_designator
,
1530 .options
= TAKE_PTR(mount_options_resolved
),
1532 LIST_APPEND(mount_options
, options
, TAKE_PTR(o
));
1535 /* empty spaces/separators only */
1536 if (LIST_IS_EMPTY(options
))
1537 c
->root_image_options
= mount_options_free_all(c
->root_image_options
);
1539 LIST_JOIN(mount_options
, c
->root_image_options
, options
);
1544 int config_parse_exec_root_hash(
1546 const char *filename
,
1548 const char *section
,
1549 unsigned section_line
,
1556 _cleanup_free_
void *roothash_decoded
= NULL
;
1557 ExecContext
*c
= data
;
1558 size_t roothash_decoded_size
= 0;
1566 if (isempty(rvalue
)) {
1567 /* Reset if the empty string is assigned */
1568 c
->root_hash_path
= mfree(c
->root_hash_path
);
1569 c
->root_hash
= mfree(c
->root_hash
);
1570 c
->root_hash_size
= 0;
1574 if (path_is_absolute(rvalue
)) {
1575 /* We have the path to a roothash to load and decode, eg: RootHash=/foo/bar.roothash */
1576 _cleanup_free_
char *p
= NULL
;
1582 free_and_replace(c
->root_hash_path
, p
);
1583 c
->root_hash
= mfree(c
->root_hash
);
1584 c
->root_hash_size
= 0;
1588 /* We have a roothash to decode, eg: RootHash=012345789abcdef */
1589 r
= unhexmem(rvalue
, strlen(rvalue
), &roothash_decoded
, &roothash_decoded_size
);
1591 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to decode RootHash=, ignoring: %s", rvalue
);
1594 if (roothash_decoded_size
< sizeof(sd_id128_t
)) {
1595 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "RootHash= is too short, ignoring: %s", rvalue
);
1599 free_and_replace(c
->root_hash
, roothash_decoded
);
1600 c
->root_hash_size
= roothash_decoded_size
;
1601 c
->root_hash_path
= mfree(c
->root_hash_path
);
1606 int config_parse_exec_root_hash_sig(
1608 const char *filename
,
1610 const char *section
,
1611 unsigned section_line
,
1618 _cleanup_free_
void *roothash_sig_decoded
= NULL
;
1620 ExecContext
*c
= data
;
1621 size_t roothash_sig_decoded_size
= 0;
1629 if (isempty(rvalue
)) {
1630 /* Reset if the empty string is assigned */
1631 c
->root_hash_sig_path
= mfree(c
->root_hash_sig_path
);
1632 c
->root_hash_sig
= mfree(c
->root_hash_sig
);
1633 c
->root_hash_sig_size
= 0;
1637 if (path_is_absolute(rvalue
)) {
1638 /* We have the path to a roothash signature to load and decode, eg: RootHashSignature=/foo/bar.roothash.p7s */
1639 _cleanup_free_
char *p
= NULL
;
1645 free_and_replace(c
->root_hash_sig_path
, p
);
1646 c
->root_hash_sig
= mfree(c
->root_hash_sig
);
1647 c
->root_hash_sig_size
= 0;
1651 if (!(value
= startswith(rvalue
, "base64:"))) {
1652 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
1653 "Failed to decode RootHashSignature=, not a path but doesn't start with 'base64:', ignoring: %s", rvalue
);
1657 /* We have a roothash signature to decode, eg: RootHashSignature=base64:012345789abcdef */
1658 r
= unbase64mem(value
, strlen(value
), &roothash_sig_decoded
, &roothash_sig_decoded_size
);
1660 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to decode RootHashSignature=, ignoring: %s", rvalue
);
1664 free_and_replace(c
->root_hash_sig
, roothash_sig_decoded
);
1665 c
->root_hash_sig_size
= roothash_sig_decoded_size
;
1666 c
->root_hash_sig_path
= mfree(c
->root_hash_sig_path
);
1671 int config_parse_exec_cpu_affinity(const char *unit
,
1672 const char *filename
,
1674 const char *section
,
1675 unsigned section_line
,
1682 ExecContext
*c
= data
;
1690 if (streq(rvalue
, "numa")) {
1691 c
->cpu_affinity_from_numa
= true;
1692 cpu_set_reset(&c
->cpu_set
);
1697 r
= parse_cpu_set_extend(rvalue
, &c
->cpu_set
, true, unit
, filename
, line
, lvalue
);
1699 c
->cpu_affinity_from_numa
= false;
1704 int config_parse_capability_set(
1706 const char *filename
,
1708 const char *section
,
1709 unsigned section_line
,
1716 uint64_t *capability_set
= data
;
1717 uint64_t sum
= 0, initial
= 0;
1718 bool invert
= false;
1726 if (rvalue
[0] == '~') {
1731 if (streq(lvalue
, "CapabilityBoundingSet"))
1732 initial
= CAP_ALL
; /* initialized to all bits on */
1733 /* else "AmbientCapabilities" initialized to all bits off */
1735 r
= capability_set_from_string(rvalue
, &sum
);
1737 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= specifier '%s', ignoring: %m", lvalue
, rvalue
);
1741 if (sum
== 0 || *capability_set
== initial
)
1742 /* "", "~" or uninitialized data -> replace */
1743 *capability_set
= invert
? ~sum
: sum
;
1745 /* previous data -> merge */
1747 *capability_set
&= ~sum
;
1749 *capability_set
|= sum
;
1755 int config_parse_exec_selinux_context(
1757 const char *filename
,
1759 const char *section
,
1760 unsigned section_line
,
1767 ExecContext
*c
= data
;
1768 const Unit
*u
= userdata
;
1778 if (isempty(rvalue
)) {
1779 c
->selinux_context
= mfree(c
->selinux_context
);
1780 c
->selinux_context_ignore
= false;
1784 if (rvalue
[0] == '-') {
1790 r
= unit_full_printf(u
, rvalue
, &k
);
1792 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
1793 "Failed to resolve unit specifiers in '%s'%s: %m",
1794 rvalue
, ignore
? ", ignoring" : "");
1795 return ignore
? 0 : -ENOEXEC
;
1798 free_and_replace(c
->selinux_context
, k
);
1799 c
->selinux_context_ignore
= ignore
;
1804 int config_parse_exec_apparmor_profile(
1806 const char *filename
,
1808 const char *section
,
1809 unsigned section_line
,
1816 ExecContext
*c
= data
;
1817 const Unit
*u
= userdata
;
1827 if (isempty(rvalue
)) {
1828 c
->apparmor_profile
= mfree(c
->apparmor_profile
);
1829 c
->apparmor_profile_ignore
= false;
1833 if (rvalue
[0] == '-') {
1839 r
= unit_full_printf(u
, rvalue
, &k
);
1841 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
1842 "Failed to resolve unit specifiers in '%s'%s: %m",
1843 rvalue
, ignore
? ", ignoring" : "");
1844 return ignore
? 0 : -ENOEXEC
;
1847 free_and_replace(c
->apparmor_profile
, k
);
1848 c
->apparmor_profile_ignore
= ignore
;
1853 int config_parse_exec_smack_process_label(
1855 const char *filename
,
1857 const char *section
,
1858 unsigned section_line
,
1865 ExecContext
*c
= data
;
1866 const Unit
*u
= userdata
;
1876 if (isempty(rvalue
)) {
1877 c
->smack_process_label
= mfree(c
->smack_process_label
);
1878 c
->smack_process_label_ignore
= false;
1882 if (rvalue
[0] == '-') {
1888 r
= unit_full_printf(u
, rvalue
, &k
);
1890 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
1891 "Failed to resolve unit specifiers in '%s'%s: %m",
1892 rvalue
, ignore
? ", ignoring" : "");
1893 return ignore
? 0 : -ENOEXEC
;
1896 free_and_replace(c
->smack_process_label
, k
);
1897 c
->smack_process_label_ignore
= ignore
;
1902 int config_parse_timer(
1904 const char *filename
,
1906 const char *section
,
1907 unsigned section_line
,
1914 _cleanup_(calendar_spec_freep
) CalendarSpec
*c
= NULL
;
1915 _cleanup_free_
char *k
= NULL
;
1916 const Unit
*u
= userdata
;
1927 if (isempty(rvalue
)) {
1928 /* Empty assignment resets list */
1929 timer_free_values(t
);
1933 r
= unit_full_printf(u
, rvalue
, &k
);
1935 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
1939 if (ltype
== TIMER_CALENDAR
) {
1940 r
= calendar_spec_from_string(k
, &c
);
1942 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse calendar specification, ignoring: %s", k
);
1946 r
= parse_sec(k
, &usec
);
1948 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse timer value, ignoring: %s", k
);
1953 v
= new(TimerValue
, 1);
1960 .calendar_spec
= TAKE_PTR(c
),
1963 LIST_PREPEND(value
, t
->values
, v
);
1968 int config_parse_trigger_unit(
1970 const char *filename
,
1972 const char *section
,
1973 unsigned section_line
,
1980 _cleanup_free_
char *p
= NULL
;
1990 if (!hashmap_isempty(u
->dependencies
[UNIT_TRIGGERS
])) {
1991 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Multiple units to trigger specified, ignoring: %s", rvalue
);
1995 r
= unit_name_printf(u
, rvalue
, &p
);
1997 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2001 type
= unit_name_to_type(p
);
2003 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Unit type not valid, ignoring: %s", rvalue
);
2006 if (unit_has_name(u
, p
)) {
2007 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Units cannot trigger themselves, ignoring: %s", rvalue
);
2011 r
= unit_add_two_dependencies_by_name(u
, UNIT_BEFORE
, UNIT_TRIGGERS
, p
, true, UNIT_DEPENDENCY_FILE
);
2013 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add trigger on %s, ignoring: %m", p
);
2020 int config_parse_path_spec(const char *unit
,
2021 const char *filename
,
2023 const char *section
,
2024 unsigned section_line
,
2034 _cleanup_free_
char *k
= NULL
;
2042 if (isempty(rvalue
)) {
2043 /* Empty assignment clears list */
2048 b
= path_type_from_string(lvalue
);
2050 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Failed to parse path type, ignoring: %s", lvalue
);
2054 r
= unit_full_printf(UNIT(p
), rvalue
, &k
);
2056 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2060 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2064 s
= new0(PathSpec
, 1);
2069 s
->path
= TAKE_PTR(k
);
2073 LIST_PREPEND(spec
, p
->specs
, s
);
2078 int config_parse_socket_service(
2080 const char *filename
,
2082 const char *section
,
2083 unsigned section_line
,
2090 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
2091 _cleanup_free_
char *p
= NULL
;
2101 r
= unit_name_printf(UNIT(s
), rvalue
, &p
);
2103 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2107 if (!endswith(p
, ".service")) {
2108 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Unit must be of type service, ignoring: %s", rvalue
);
2112 r
= manager_load_unit(UNIT(s
)->manager
, p
, NULL
, &error
, &x
);
2114 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to load unit %s, ignoring: %s", rvalue
, bus_error_message(&error
, r
));
2118 unit_ref_set(&s
->service
, UNIT(s
), x
);
2123 int config_parse_fdname(
2125 const char *filename
,
2127 const char *section
,
2128 unsigned section_line
,
2135 _cleanup_free_
char *p
= NULL
;
2144 if (isempty(rvalue
)) {
2145 s
->fdname
= mfree(s
->fdname
);
2149 r
= unit_full_printf(UNIT(s
), rvalue
, &p
);
2151 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2155 if (!fdname_is_valid(p
)) {
2156 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", p
);
2160 return free_and_replace(s
->fdname
, p
);
2163 int config_parse_service_sockets(
2165 const char *filename
,
2167 const char *section
,
2168 unsigned section_line
,
2183 for (const char *p
= rvalue
;;) {
2184 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2186 r
= extract_first_word(&p
, &word
, NULL
, 0);
2192 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Trailing garbage in sockets, ignoring: %s", rvalue
);
2196 r
= unit_name_printf(UNIT(s
), word
, &k
);
2198 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
2202 if (!endswith(k
, ".socket")) {
2203 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Unit must be of type socket, ignoring: %s", k
);
2207 r
= unit_add_two_dependencies_by_name(UNIT(s
), UNIT_WANTS
, UNIT_AFTER
, k
, true, UNIT_DEPENDENCY_FILE
);
2209 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
2211 r
= unit_add_dependency_by_name(UNIT(s
), UNIT_TRIGGERED_BY
, k
, true, UNIT_DEPENDENCY_FILE
);
2213 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
2217 int config_parse_bus_name(
2219 const char *filename
,
2221 const char *section
,
2222 unsigned section_line
,
2229 _cleanup_free_
char *k
= NULL
;
2230 const Unit
*u
= userdata
;
2238 r
= unit_full_printf(u
, rvalue
, &k
);
2240 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2244 if (!sd_bus_service_name_is_valid(k
)) {
2245 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid bus name, ignoring: %s", k
);
2249 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
2252 int config_parse_service_timeout(
2254 const char *filename
,
2256 const char *section
,
2257 unsigned section_line
,
2264 Service
*s
= userdata
;
2273 /* This is called for two cases: TimeoutSec= and TimeoutStartSec=. */
2275 /* Traditionally, these options accepted 0 to disable the timeouts. However, a timeout of 0 suggests it happens
2276 * immediately, hence fix this to become USEC_INFINITY instead. This is in-line with how we internally handle
2277 * all other timeouts. */
2278 r
= parse_sec_fix_0(rvalue
, &usec
);
2280 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
2284 s
->start_timeout_defined
= true;
2285 s
->timeout_start_usec
= usec
;
2287 if (streq(lvalue
, "TimeoutSec"))
2288 s
->timeout_stop_usec
= usec
;
2293 int config_parse_timeout_abort(
2295 const char *filename
,
2297 const char *section
,
2298 unsigned section_line
,
2313 /* Note: apart from setting the arg, this returns an extra bit of information in the return value. */
2315 if (isempty(rvalue
)) {
2317 return 0; /* "not set" */
2320 r
= parse_sec(rvalue
, ret
);
2322 return log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= setting, ignoring: %s", lvalue
, rvalue
);
2324 return 1; /* "set" */
2327 int config_parse_service_timeout_abort(
2329 const char *filename
,
2331 const char *section
,
2332 unsigned section_line
,
2339 Service
*s
= userdata
;
2344 r
= config_parse_timeout_abort(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
,
2345 &s
->timeout_abort_usec
, s
);
2347 s
->timeout_abort_set
= r
;
2351 int config_parse_sec_fix_0(
2353 const char *filename
,
2355 const char *section
,
2356 unsigned section_line
,
2363 usec_t
*usec
= data
;
2371 /* This is pretty much like config_parse_sec(), except that this treats a time of 0 as infinity, for
2372 * compatibility with older versions of systemd where 0 instead of infinity was used as indicator to turn off a
2375 r
= parse_sec_fix_0(rvalue
, usec
);
2377 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
2382 int config_parse_user_group_compat(
2384 const char *filename
,
2386 const char *section
,
2387 unsigned section_line
,
2394 _cleanup_free_
char *k
= NULL
;
2396 const Unit
*u
= userdata
;
2404 if (isempty(rvalue
)) {
2405 *user
= mfree(*user
);
2409 r
= unit_full_printf(u
, rvalue
, &k
);
2411 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", rvalue
);
2415 if (!valid_user_group_name(k
, VALID_USER_ALLOW_NUMERIC
|VALID_USER_RELAX
|VALID_USER_WARN
)) {
2416 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2420 if (strstr(lvalue
, "User") && streq(k
, NOBODY_USER_NAME
))
2421 log_struct(LOG_NOTICE
,
2422 "MESSAGE=%s:%u: Special user %s configured, this is not safe!", filename
, line
, k
,
2424 "MESSAGE_ID=" SD_MESSAGE_NOBODY_USER_UNSUITABLE_STR
,
2425 "OFFENDING_USER=%s", k
,
2426 "CONFIG_FILE=%s", filename
,
2427 "CONFIG_LINE=%u", line
);
2429 return free_and_replace(*user
, k
);
2432 int config_parse_user_group_strv_compat(
2434 const char *filename
,
2436 const char *section
,
2437 unsigned section_line
,
2444 char ***users
= data
;
2445 const Unit
*u
= userdata
;
2453 if (isempty(rvalue
)) {
2454 *users
= strv_free(*users
);
2458 for (const char *p
= rvalue
;;) {
2459 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2461 r
= extract_first_word(&p
, &word
, NULL
, 0);
2467 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax: %s", rvalue
);
2471 r
= unit_full_printf(u
, word
, &k
);
2473 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", word
);
2477 if (!valid_user_group_name(k
, VALID_USER_ALLOW_NUMERIC
|VALID_USER_RELAX
|VALID_USER_WARN
)) {
2478 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2482 r
= strv_push(users
, k
);
2490 int config_parse_working_directory(
2492 const char *filename
,
2494 const char *section
,
2495 unsigned section_line
,
2502 ExecContext
*c
= data
;
2503 const Unit
*u
= userdata
;
2513 if (isempty(rvalue
)) {
2514 c
->working_directory_home
= false;
2515 c
->working_directory
= mfree(c
->working_directory
);
2519 if (rvalue
[0] == '-') {
2525 if (streq(rvalue
, "~")) {
2526 c
->working_directory_home
= true;
2527 c
->working_directory
= mfree(c
->working_directory
);
2529 _cleanup_free_
char *k
= NULL
;
2531 r
= unit_full_printf(u
, rvalue
, &k
);
2533 log_syntax(unit
, missing_ok
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
2534 "Failed to resolve unit specifiers in working directory path '%s'%s: %m",
2535 rvalue
, missing_ok
? ", ignoring" : "");
2536 return missing_ok
? 0 : -ENOEXEC
;
2539 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
| (missing_ok
? 0 : PATH_CHECK_FATAL
), unit
, filename
, line
, lvalue
);
2541 return missing_ok
? 0 : -ENOEXEC
;
2543 c
->working_directory_home
= false;
2544 free_and_replace(c
->working_directory
, k
);
2547 c
->working_directory_missing_ok
= missing_ok
;
2551 int config_parse_unit_env_file(const char *unit
,
2552 const char *filename
,
2554 const char *section
,
2555 unsigned section_line
,
2563 const Unit
*u
= userdata
;
2564 _cleanup_free_
char *n
= NULL
;
2572 if (isempty(rvalue
)) {
2573 /* Empty assignment frees the list */
2574 *env
= strv_free(*env
);
2578 r
= unit_full_printf(u
, rvalue
, &n
);
2580 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2584 r
= path_simplify_and_warn(n
[0] == '-' ? n
+ 1 : n
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2588 r
= strv_push(env
, n
);
2597 int config_parse_environ(
2599 const char *filename
,
2601 const char *section
,
2602 unsigned section_line
,
2609 const Unit
*u
= userdata
;
2618 if (isempty(rvalue
)) {
2619 /* Empty assignment resets the list */
2620 *env
= strv_free(*env
);
2624 for (const char *p
= rvalue
;; ) {
2625 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2627 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2633 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2634 "Invalid syntax, ignoring: %s", rvalue
);
2639 r
= unit_full_printf(u
, word
, &k
);
2641 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2642 "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2648 if (!env_assignment_is_valid(k
)) {
2649 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
2650 "Invalid environment assignment, ignoring: %s", k
);
2654 r
= strv_env_replace(env
, k
);
2662 int config_parse_pass_environ(
2664 const char *filename
,
2666 const char *section
,
2667 unsigned section_line
,
2674 _cleanup_strv_free_
char **n
= NULL
;
2675 size_t nlen
= 0, nbufsize
= 0;
2676 char*** passenv
= data
;
2677 const Unit
*u
= userdata
;
2685 if (isempty(rvalue
)) {
2686 /* Empty assignment resets the list */
2687 *passenv
= strv_free(*passenv
);
2691 for (const char *p
= rvalue
;;) {
2692 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2694 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
2700 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2701 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2706 r
= unit_full_printf(u
, word
, &k
);
2708 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2709 "Failed to resolve specifiers in %s, ignoring: %m", word
);
2715 if (!env_name_is_valid(k
)) {
2716 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
2717 "Invalid environment name for %s, ignoring: %s", lvalue
, k
);
2721 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
2724 n
[nlen
++] = TAKE_PTR(k
);
2729 r
= strv_extend_strv(passenv
, n
, true);
2737 int config_parse_unset_environ(
2739 const char *filename
,
2741 const char *section
,
2742 unsigned section_line
,
2749 _cleanup_strv_free_
char **n
= NULL
;
2750 size_t nlen
= 0, nbufsize
= 0;
2751 char*** unsetenv
= data
;
2752 const Unit
*u
= userdata
;
2760 if (isempty(rvalue
)) {
2761 /* Empty assignment resets the list */
2762 *unsetenv
= strv_free(*unsetenv
);
2766 for (const char *p
= rvalue
;;) {
2767 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2769 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2775 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2776 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2781 r
= unit_full_printf(u
, word
, &k
);
2783 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2784 "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2790 if (!env_assignment_is_valid(k
) && !env_name_is_valid(k
)) {
2791 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
2792 "Invalid environment name or assignment %s, ignoring: %s", lvalue
, k
);
2796 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
2799 n
[nlen
++] = TAKE_PTR(k
);
2804 r
= strv_extend_strv(unsetenv
, n
, true);
2812 int config_parse_log_extra_fields(
2814 const char *filename
,
2816 const char *section
,
2817 unsigned section_line
,
2824 ExecContext
*c
= data
;
2825 const Unit
*u
= userdata
;
2833 if (isempty(rvalue
)) {
2834 exec_context_free_log_extra_fields(c
);
2838 for (const char *p
= rvalue
;;) {
2839 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2843 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2849 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
2853 r
= unit_full_printf(u
, word
, &k
);
2855 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2859 eq
= strchr(k
, '=');
2861 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Log field lacks '=' character, ignoring: %s", k
);
2865 if (!journal_field_valid(k
, eq
-k
, false)) {
2866 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Log field name is invalid, ignoring: %s", k
);
2870 t
= reallocarray(c
->log_extra_fields
, c
->n_log_extra_fields
+1, sizeof(struct iovec
));
2874 c
->log_extra_fields
= t
;
2875 c
->log_extra_fields
[c
->n_log_extra_fields
++] = IOVEC_MAKE_STRING(k
);
2881 int config_parse_log_namespace(
2883 const char *filename
,
2885 const char *section
,
2886 unsigned section_line
,
2893 _cleanup_free_
char *k
= NULL
;
2894 ExecContext
*c
= data
;
2895 const Unit
*u
= userdata
;
2903 if (isempty(rvalue
)) {
2904 c
->log_namespace
= mfree(c
->log_namespace
);
2908 r
= unit_full_printf(u
, rvalue
, &k
);
2910 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2914 if (!log_namespace_name_valid(k
)) {
2915 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Specified log namespace name is not valid, ignoring: %s", k
);
2919 free_and_replace(c
->log_namespace
, k
);
2923 int config_parse_unit_condition_path(
2925 const char *filename
,
2927 const char *section
,
2928 unsigned section_line
,
2935 _cleanup_free_
char *p
= NULL
;
2936 Condition
**list
= data
, *c
;
2937 ConditionType t
= ltype
;
2938 bool trigger
, negate
;
2939 const Unit
*u
= userdata
;
2947 if (isempty(rvalue
)) {
2948 /* Empty assignment resets the list */
2949 *list
= condition_free_list(*list
);
2953 trigger
= rvalue
[0] == '|';
2957 negate
= rvalue
[0] == '!';
2961 r
= unit_full_printf(u
, rvalue
, &p
);
2963 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2967 r
= path_simplify_and_warn(p
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2971 c
= condition_new(t
, p
, trigger
, negate
);
2975 LIST_PREPEND(conditions
, *list
, c
);
2979 int config_parse_unit_condition_string(
2981 const char *filename
,
2983 const char *section
,
2984 unsigned section_line
,
2991 _cleanup_free_
char *s
= NULL
;
2992 Condition
**list
= data
, *c
;
2993 ConditionType t
= ltype
;
2994 bool trigger
, negate
;
2995 const Unit
*u
= userdata
;
3003 if (isempty(rvalue
)) {
3004 /* Empty assignment resets the list */
3005 *list
= condition_free_list(*list
);
3009 trigger
= *rvalue
== '|';
3011 rvalue
+= 1 + strspn(rvalue
+ 1, WHITESPACE
);
3013 negate
= *rvalue
== '!';
3015 rvalue
+= 1 + strspn(rvalue
+ 1, WHITESPACE
);
3017 r
= unit_full_printf(u
, rvalue
, &s
);
3019 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3020 "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
3024 c
= condition_new(t
, s
, trigger
, negate
);
3028 LIST_PREPEND(conditions
, *list
, c
);
3032 int config_parse_unit_requires_mounts_for(
3034 const char *filename
,
3036 const char *section
,
3037 unsigned section_line
,
3052 for (const char *p
= rvalue
;;) {
3053 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
3055 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3061 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3062 "Invalid syntax, ignoring: %s", rvalue
);
3066 r
= unit_full_printf(u
, word
, &resolved
);
3068 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
3072 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
3076 r
= unit_require_mounts_for(u
, resolved
, UNIT_DEPENDENCY_FILE
);
3078 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add required mount '%s', ignoring: %m", resolved
);
3084 int config_parse_documentation(const char *unit
,
3085 const char *filename
,
3087 const char *section
,
3088 unsigned section_line
,
3104 if (isempty(rvalue
)) {
3105 /* Empty assignment resets the list */
3106 u
->documentation
= strv_free(u
->documentation
);
3110 r
= config_parse_unit_strv_printf(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
,
3111 rvalue
, data
, userdata
);
3115 for (a
= b
= u
->documentation
; a
&& *a
; a
++) {
3117 if (documentation_url_is_valid(*a
))
3120 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid URL, ignoring: %s", *a
);
3131 int config_parse_syscall_filter(
3133 const char *filename
,
3135 const char *section
,
3136 unsigned section_line
,
3143 ExecContext
*c
= data
;
3144 _unused_
const Unit
*u
= userdata
;
3145 bool invert
= false;
3153 if (isempty(rvalue
)) {
3154 /* Empty assignment resets the list */
3155 c
->syscall_filter
= hashmap_free(c
->syscall_filter
);
3156 c
->syscall_allow_list
= false;
3160 if (rvalue
[0] == '~') {
3165 if (!c
->syscall_filter
) {
3166 c
->syscall_filter
= hashmap_new(NULL
);
3167 if (!c
->syscall_filter
)
3171 /* Allow everything but the ones listed */
3172 c
->syscall_allow_list
= false;
3174 /* Allow nothing but the ones listed */
3175 c
->syscall_allow_list
= true;
3177 /* Accept default syscalls if we are on a allow_list */
3178 r
= seccomp_parse_syscall_filter(
3179 "@default", -1, c
->syscall_filter
,
3180 SECCOMP_PARSE_PERMISSIVE
|SECCOMP_PARSE_ALLOW_LIST
,
3188 for (const char *p
= rvalue
;;) {
3189 _cleanup_free_
char *word
= NULL
, *name
= NULL
;
3192 r
= extract_first_word(&p
, &word
, NULL
, 0);
3198 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3202 r
= parse_syscall_and_errno(word
, &name
, &num
);
3204 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse syscall:errno, ignoring: %s", word
);
3208 r
= seccomp_parse_syscall_filter(
3209 name
, num
, c
->syscall_filter
,
3210 SECCOMP_PARSE_LOG
|SECCOMP_PARSE_PERMISSIVE
|
3211 (invert
? SECCOMP_PARSE_INVERT
: 0)|
3212 (c
->syscall_allow_list
? SECCOMP_PARSE_ALLOW_LIST
: 0),
3213 unit
, filename
, line
);
3219 int config_parse_syscall_log(
3221 const char *filename
,
3223 const char *section
,
3224 unsigned section_line
,
3231 ExecContext
*c
= data
;
3232 _unused_
const Unit
*u
= userdata
;
3233 bool invert
= false;
3242 if (isempty(rvalue
)) {
3243 /* Empty assignment resets the list */
3244 c
->syscall_log
= hashmap_free(c
->syscall_log
);
3245 c
->syscall_log_allow_list
= false;
3249 if (rvalue
[0] == '~') {
3254 if (!c
->syscall_log
) {
3255 c
->syscall_log
= hashmap_new(NULL
);
3256 if (!c
->syscall_log
)
3260 /* Log everything but the ones listed */
3261 c
->syscall_log_allow_list
= false;
3263 /* Log nothing but the ones listed */
3264 c
->syscall_log_allow_list
= true;
3269 _cleanup_free_
char *word
= NULL
, *name
= NULL
;
3272 r
= extract_first_word(&p
, &word
, NULL
, 0);
3278 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3282 r
= parse_syscall_and_errno(word
, &name
, &num
);
3283 if (r
< 0 || num
>= 0) { /* errno code not allowed */
3284 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse syscall, ignoring: %s", word
);
3288 r
= seccomp_parse_syscall_filter(
3289 name
, 0, c
->syscall_log
,
3290 SECCOMP_PARSE_LOG
|SECCOMP_PARSE_PERMISSIVE
|
3291 (invert
? SECCOMP_PARSE_INVERT
: 0)|
3292 (c
->syscall_log_allow_list
? SECCOMP_PARSE_ALLOW_LIST
: 0),
3293 unit
, filename
, line
);
3299 int config_parse_syscall_archs(
3301 const char *filename
,
3303 const char *section
,
3304 unsigned section_line
,
3314 if (isempty(rvalue
)) {
3315 *archs
= set_free(*archs
);
3319 for (const char *p
= rvalue
;;) {
3320 _cleanup_free_
char *word
= NULL
;
3323 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3329 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3330 "Invalid syntax, ignoring: %s", rvalue
);
3334 r
= seccomp_arch_from_string(word
, &a
);
3336 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3337 "Failed to parse system call architecture \"%s\", ignoring: %m", word
);
3341 r
= set_ensure_put(archs
, NULL
, UINT32_TO_PTR(a
+ 1));
3347 int config_parse_syscall_errno(
3349 const char *filename
,
3351 const char *section
,
3352 unsigned section_line
,
3359 ExecContext
*c
= data
;
3366 if (isempty(rvalue
) || streq(rvalue
, "kill")) {
3367 /* Empty assignment resets to KILL */
3368 c
->syscall_errno
= SECCOMP_ERROR_NUMBER_KILL
;
3372 e
= parse_errno(rvalue
);
3374 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Failed to parse error number, ignoring: %s", rvalue
);
3378 c
->syscall_errno
= e
;
3382 int config_parse_address_families(
3384 const char *filename
,
3386 const char *section
,
3387 unsigned section_line
,
3394 ExecContext
*c
= data
;
3395 bool invert
= false;
3402 if (isempty(rvalue
)) {
3403 /* Empty assignment resets the list */
3404 c
->address_families
= set_free(c
->address_families
);
3405 c
->address_families_allow_list
= false;
3409 if (rvalue
[0] == '~') {
3414 if (!c
->address_families
) {
3415 c
->address_families
= set_new(NULL
);
3416 if (!c
->address_families
)
3419 c
->address_families_allow_list
= !invert
;
3422 for (const char *p
= rvalue
;;) {
3423 _cleanup_free_
char *word
= NULL
;
3426 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3432 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3433 "Invalid syntax, ignoring: %s", rvalue
);
3437 af
= af_from_name(word
);
3439 log_syntax(unit
, LOG_WARNING
, filename
, line
, af
,
3440 "Failed to parse address family, ignoring: %s", word
);
3444 /* If we previously wanted to forbid an address family and now
3445 * we want to allow it, then just remove it from the list.
3447 if (!invert
== c
->address_families_allow_list
) {
3448 r
= set_put(c
->address_families
, INT_TO_PTR(af
));
3452 set_remove(c
->address_families
, INT_TO_PTR(af
));
3456 int config_parse_restrict_namespaces(
3458 const char *filename
,
3460 const char *section
,
3461 unsigned section_line
,
3468 ExecContext
*c
= data
;
3469 unsigned long flags
;
3470 bool invert
= false;
3473 if (isempty(rvalue
)) {
3474 /* Reset to the default. */
3475 c
->restrict_namespaces
= NAMESPACE_FLAGS_INITIAL
;
3479 /* Boolean parameter ignores the previous settings */
3480 r
= parse_boolean(rvalue
);
3482 c
->restrict_namespaces
= 0;
3484 } else if (r
== 0) {
3485 c
->restrict_namespaces
= NAMESPACE_FLAGS_ALL
;
3489 if (rvalue
[0] == '~') {
3494 /* Not a boolean argument, in this case it's a list of namespace types. */
3495 r
= namespace_flags_from_string(rvalue
, &flags
);
3497 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse namespace type string, ignoring: %s", rvalue
);
3501 if (c
->restrict_namespaces
== NAMESPACE_FLAGS_INITIAL
)
3502 /* Initial assignment. Just set the value. */
3503 c
->restrict_namespaces
= invert
? (~flags
) & NAMESPACE_FLAGS_ALL
: flags
;
3505 /* Merge the value with the previous one. */
3506 SET_FLAG(c
->restrict_namespaces
, flags
, !invert
);
3512 int config_parse_unit_slice(
3514 const char *filename
,
3516 const char *section
,
3517 unsigned section_line
,
3524 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
3525 _cleanup_free_
char *k
= NULL
;
3526 Unit
*u
= userdata
, *slice
;
3534 r
= unit_name_printf(u
, rvalue
, &k
);
3536 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
3540 r
= manager_load_unit(u
->manager
, k
, NULL
, &error
, &slice
);
3542 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to load slice unit %s, ignoring: %s", k
, bus_error_message(&error
, r
));
3546 r
= unit_set_slice(u
, slice
);
3548 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to assign slice %s to unit %s, ignoring: %m", slice
->id
, u
->id
);
3555 int config_parse_cpu_quota(
3557 const char *filename
,
3559 const char *section
,
3560 unsigned section_line
,
3567 CGroupContext
*c
= data
;
3574 if (isempty(rvalue
)) {
3575 c
->cpu_quota_per_sec_usec
= USEC_INFINITY
;
3579 r
= parse_permille_unbounded(rvalue
);
3581 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid CPU quota '%s', ignoring.", rvalue
);
3585 c
->cpu_quota_per_sec_usec
= ((usec_t
) r
* USEC_PER_SEC
) / 1000U;
3589 int config_parse_allowed_cpus(
3591 const char *filename
,
3593 const char *section
,
3594 unsigned section_line
,
3601 CGroupContext
*c
= data
;
3603 (void) parse_cpu_set_extend(rvalue
, &c
->cpuset_cpus
, true, unit
, filename
, line
, lvalue
);
3608 int config_parse_allowed_mems(
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_mems
, true, unit
, filename
, line
, lvalue
);
3627 int config_parse_memory_limit(
3629 const char *filename
,
3631 const char *section
,
3632 unsigned section_line
,
3639 CGroupContext
*c
= data
;
3640 uint64_t bytes
= CGROUP_LIMIT_MAX
;
3643 if (isempty(rvalue
) && STR_IN_SET(lvalue
, "DefaultMemoryLow",
3647 bytes
= CGROUP_LIMIT_MIN
;
3648 else if (!isempty(rvalue
) && !streq(rvalue
, "infinity")) {
3650 r
= parse_permille(rvalue
);
3652 r
= parse_size(rvalue
, 1024, &bytes
);
3654 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid memory limit '%s', ignoring: %m", rvalue
);
3658 bytes
= physical_memory_scale(r
, 1000U);
3660 if (bytes
>= UINT64_MAX
||
3661 (bytes
<= 0 && !STR_IN_SET(lvalue
, "MemorySwapMax", "MemoryLow", "MemoryMin", "DefaultMemoryLow", "DefaultMemoryMin"))) {
3662 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Memory limit '%s' out of range, ignoring.", rvalue
);
3667 if (streq(lvalue
, "DefaultMemoryLow")) {
3668 c
->default_memory_low
= bytes
;
3669 c
->default_memory_low_set
= true;
3670 } else if (streq(lvalue
, "DefaultMemoryMin")) {
3671 c
->default_memory_min
= bytes
;
3672 c
->default_memory_min_set
= true;
3673 } else if (streq(lvalue
, "MemoryMin")) {
3674 c
->memory_min
= bytes
;
3675 c
->memory_min_set
= true;
3676 } else if (streq(lvalue
, "MemoryLow")) {
3677 c
->memory_low
= bytes
;
3678 c
->memory_low_set
= true;
3679 } else if (streq(lvalue
, "MemoryHigh"))
3680 c
->memory_high
= bytes
;
3681 else if (streq(lvalue
, "MemoryMax"))
3682 c
->memory_max
= bytes
;
3683 else if (streq(lvalue
, "MemorySwapMax"))
3684 c
->memory_swap_max
= bytes
;
3685 else if (streq(lvalue
, "MemoryLimit"))
3686 c
->memory_limit
= bytes
;
3693 int config_parse_tasks_max(
3695 const char *filename
,
3697 const char *section
,
3698 unsigned section_line
,
3705 const Unit
*u
= userdata
;
3706 TasksMax
*tasks_max
= data
;
3710 if (isempty(rvalue
)) {
3711 *tasks_max
= u
? u
->manager
->default_tasks_max
: TASKS_MAX_UNSET
;
3715 if (streq(rvalue
, "infinity")) {
3716 *tasks_max
= TASKS_MAX_UNSET
;
3720 r
= parse_permille(rvalue
);
3722 *tasks_max
= (TasksMax
) { r
, 1000U }; /* r‰ */
3724 r
= safe_atou64(rvalue
, &v
);
3726 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid maximum tasks value '%s', ignoring: %m", rvalue
);
3730 if (v
<= 0 || v
>= UINT64_MAX
) {
3731 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Maximum tasks value '%s' out of range, ignoring.", rvalue
);
3735 *tasks_max
= (TasksMax
) { v
};
3741 int config_parse_delegate(
3743 const char *filename
,
3745 const char *section
,
3746 unsigned section_line
,
3753 CGroupContext
*c
= data
;
3757 t
= unit_name_to_type(unit
);
3758 assert(t
!= _UNIT_TYPE_INVALID
);
3760 if (!unit_vtable
[t
]->can_delegate
) {
3761 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Delegate= setting not supported for this unit type, ignoring.");
3765 /* We either accept a boolean value, which may be used to turn on delegation for all controllers, or turn it
3766 * off for all. Or it takes a list of controller names, in which case we add the specified controllers to the
3767 * mask to delegate. */
3769 if (isempty(rvalue
)) {
3770 /* An empty string resets controllers and set Delegate=yes. */
3772 c
->delegate_controllers
= 0;
3776 r
= parse_boolean(rvalue
);
3778 CGroupMask mask
= 0;
3780 for (const char *p
= rvalue
;;) {
3781 _cleanup_free_
char *word
= NULL
;
3782 CGroupController cc
;
3784 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3790 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3794 cc
= cgroup_controller_from_string(word
);
3796 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid controller name '%s', ignoring", word
);
3800 mask
|= CGROUP_CONTROLLER_TO_MASK(cc
);
3804 c
->delegate_controllers
|= mask
;
3808 c
->delegate_controllers
= _CGROUP_MASK_ALL
;
3810 c
->delegate
= false;
3811 c
->delegate_controllers
= 0;
3817 int config_parse_managed_oom_mode(
3819 const char *filename
,
3821 const char *section
,
3822 unsigned section_line
,
3828 ManagedOOMMode
*mode
= data
, m
;
3831 t
= unit_name_to_type(unit
);
3832 assert(t
!= _UNIT_TYPE_INVALID
);
3834 if (!unit_vtable
[t
]->can_set_managed_oom
)
3835 return log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "%s= is not supported for this unit type, ignoring.", lvalue
);
3837 if (isempty(rvalue
)) {
3838 *mode
= MANAGED_OOM_AUTO
;
3842 m
= managed_oom_mode_from_string(rvalue
);
3844 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid syntax, ignoring: %s", rvalue
);
3851 int config_parse_managed_oom_mem_pressure_limit(
3853 const char *filename
,
3855 const char *section
,
3856 unsigned section_line
,
3866 t
= unit_name_to_type(unit
);
3867 assert(t
!= _UNIT_TYPE_INVALID
);
3869 if (!unit_vtable
[t
]->can_set_managed_oom
)
3870 return log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "%s= is not supported for this unit type, ignoring.", lvalue
);
3872 if (isempty(rvalue
)) {
3877 r
= parse_percent(rvalue
);
3879 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse limit percent value, ignoring: %s", rvalue
);
3887 int config_parse_device_allow(
3889 const char *filename
,
3891 const char *section
,
3892 unsigned section_line
,
3899 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3900 CGroupContext
*c
= data
;
3901 const char *p
= rvalue
;
3904 if (isempty(rvalue
)) {
3905 while (c
->device_allow
)
3906 cgroup_context_free_device_allow(c
, c
->device_allow
);
3911 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3915 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3916 "Invalid syntax, ignoring: %s", rvalue
);
3920 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3921 "Failed to extract device path and rights from '%s', ignoring.", rvalue
);
3925 r
= unit_full_printf(userdata
, path
, &resolved
);
3927 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3928 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3932 if (!STARTSWITH_SET(resolved
, "block-", "char-")) {
3934 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3938 if (!valid_device_node_path(resolved
)) {
3939 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid device node path '%s', ignoring.", resolved
);
3944 if (!isempty(p
) && !in_charset(p
, "rwm")) {
3945 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid device rights '%s', ignoring.", p
);
3949 return cgroup_add_device_allow(c
, resolved
, p
);
3952 int config_parse_io_device_weight(
3954 const char *filename
,
3956 const char *section
,
3957 unsigned section_line
,
3964 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3965 CGroupIODeviceWeight
*w
;
3966 CGroupContext
*c
= data
;
3967 const char *p
= rvalue
;
3975 if (isempty(rvalue
)) {
3976 while (c
->io_device_weights
)
3977 cgroup_context_free_io_device_weight(c
, c
->io_device_weights
);
3982 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3986 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3987 "Invalid syntax, ignoring: %s", rvalue
);
3990 if (r
== 0 || isempty(p
)) {
3991 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3992 "Failed to extract device path and weight from '%s', ignoring.", rvalue
);
3996 r
= unit_full_printf(userdata
, path
, &resolved
);
3998 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3999 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4003 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4007 r
= cg_weight_parse(p
, &u
);
4009 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "IO weight '%s' invalid, ignoring: %m", p
);
4013 assert(u
!= CGROUP_WEIGHT_INVALID
);
4015 w
= new0(CGroupIODeviceWeight
, 1);
4019 w
->path
= TAKE_PTR(resolved
);
4022 LIST_PREPEND(device_weights
, c
->io_device_weights
, w
);
4026 int config_parse_io_device_latency(
4028 const char *filename
,
4030 const char *section
,
4031 unsigned section_line
,
4038 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4039 CGroupIODeviceLatency
*l
;
4040 CGroupContext
*c
= data
;
4041 const char *p
= rvalue
;
4049 if (isempty(rvalue
)) {
4050 while (c
->io_device_latencies
)
4051 cgroup_context_free_io_device_latency(c
, c
->io_device_latencies
);
4056 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4060 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4061 "Invalid syntax, ignoring: %s", rvalue
);
4064 if (r
== 0 || isempty(p
)) {
4065 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4066 "Failed to extract device path and latency from '%s', ignoring.", rvalue
);
4070 r
= unit_full_printf(userdata
, path
, &resolved
);
4072 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4073 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4077 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4081 r
= parse_sec(p
, &usec
);
4083 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse timer value, ignoring: %s", p
);
4087 l
= new0(CGroupIODeviceLatency
, 1);
4091 l
->path
= TAKE_PTR(resolved
);
4092 l
->target_usec
= usec
;
4094 LIST_PREPEND(device_latencies
, c
->io_device_latencies
, l
);
4098 int config_parse_io_limit(
4100 const char *filename
,
4102 const char *section
,
4103 unsigned section_line
,
4110 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4111 CGroupIODeviceLimit
*l
= NULL
, *t
;
4112 CGroupContext
*c
= data
;
4113 CGroupIOLimitType type
;
4114 const char *p
= rvalue
;
4122 type
= cgroup_io_limit_type_from_string(lvalue
);
4125 if (isempty(rvalue
)) {
4126 LIST_FOREACH(device_limits
, l
, c
->io_device_limits
)
4127 l
->limits
[type
] = cgroup_io_limit_defaults
[type
];
4131 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4135 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4136 "Invalid syntax, ignoring: %s", rvalue
);
4139 if (r
== 0 || isempty(p
)) {
4140 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4141 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
4145 r
= unit_full_printf(userdata
, path
, &resolved
);
4147 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4148 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4152 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4156 if (streq("infinity", p
))
4157 num
= CGROUP_LIMIT_MAX
;
4159 r
= parse_size(p
, 1000, &num
);
4160 if (r
< 0 || num
<= 0) {
4161 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid IO limit '%s', ignoring.", p
);
4166 LIST_FOREACH(device_limits
, t
, c
->io_device_limits
) {
4167 if (path_equal(resolved
, t
->path
)) {
4174 CGroupIOLimitType ttype
;
4176 l
= new0(CGroupIODeviceLimit
, 1);
4180 l
->path
= TAKE_PTR(resolved
);
4181 for (ttype
= 0; ttype
< _CGROUP_IO_LIMIT_TYPE_MAX
; ttype
++)
4182 l
->limits
[ttype
] = cgroup_io_limit_defaults
[ttype
];
4184 LIST_PREPEND(device_limits
, c
->io_device_limits
, l
);
4187 l
->limits
[type
] = num
;
4192 int config_parse_blockio_device_weight(
4194 const char *filename
,
4196 const char *section
,
4197 unsigned section_line
,
4204 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4205 CGroupBlockIODeviceWeight
*w
;
4206 CGroupContext
*c
= data
;
4207 const char *p
= rvalue
;
4215 if (isempty(rvalue
)) {
4216 while (c
->blockio_device_weights
)
4217 cgroup_context_free_blockio_device_weight(c
, c
->blockio_device_weights
);
4222 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4226 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4227 "Invalid syntax, ignoring: %s", rvalue
);
4230 if (r
== 0 || isempty(p
)) {
4231 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4232 "Failed to extract device node and weight from '%s', ignoring.", rvalue
);
4236 r
= unit_full_printf(userdata
, path
, &resolved
);
4238 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4239 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4243 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4247 r
= cg_blkio_weight_parse(p
, &u
);
4249 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid block IO weight '%s', ignoring: %m", p
);
4253 assert(u
!= CGROUP_BLKIO_WEIGHT_INVALID
);
4255 w
= new0(CGroupBlockIODeviceWeight
, 1);
4259 w
->path
= TAKE_PTR(resolved
);
4262 LIST_PREPEND(device_weights
, c
->blockio_device_weights
, w
);
4266 int config_parse_blockio_bandwidth(
4268 const char *filename
,
4270 const char *section
,
4271 unsigned section_line
,
4278 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4279 CGroupBlockIODeviceBandwidth
*b
= NULL
, *t
;
4280 CGroupContext
*c
= data
;
4281 const char *p
= rvalue
;
4290 read
= streq("BlockIOReadBandwidth", lvalue
);
4292 if (isempty(rvalue
)) {
4293 LIST_FOREACH(device_bandwidths
, b
, c
->blockio_device_bandwidths
) {
4294 b
->rbps
= CGROUP_LIMIT_MAX
;
4295 b
->wbps
= CGROUP_LIMIT_MAX
;
4300 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4304 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4305 "Invalid syntax, ignoring: %s", rvalue
);
4308 if (r
== 0 || isempty(p
)) {
4309 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4310 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
4314 r
= unit_full_printf(userdata
, path
, &resolved
);
4316 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4317 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4321 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4325 r
= parse_size(p
, 1000, &bytes
);
4326 if (r
< 0 || bytes
<= 0) {
4327 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid Block IO Bandwidth '%s', ignoring.", p
);
4331 LIST_FOREACH(device_bandwidths
, t
, c
->blockio_device_bandwidths
) {
4332 if (path_equal(resolved
, t
->path
)) {
4339 b
= new0(CGroupBlockIODeviceBandwidth
, 1);
4343 b
->path
= TAKE_PTR(resolved
);
4344 b
->rbps
= CGROUP_LIMIT_MAX
;
4345 b
->wbps
= CGROUP_LIMIT_MAX
;
4347 LIST_PREPEND(device_bandwidths
, c
->blockio_device_bandwidths
, b
);
4358 int config_parse_job_mode_isolate(
4360 const char *filename
,
4362 const char *section
,
4363 unsigned section_line
,
4377 r
= parse_boolean(rvalue
);
4379 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse boolean, ignoring: %s", rvalue
);
4383 log_notice("%s is deprecated. Please use OnFailureJobMode= instead", lvalue
);
4385 *m
= r
? JOB_ISOLATE
: JOB_REPLACE
;
4389 int config_parse_exec_directories(
4391 const char *filename
,
4393 const char *section
,
4394 unsigned section_line
,
4402 const Unit
*u
= userdata
;
4410 if (isempty(rvalue
)) {
4411 /* Empty assignment resets the list */
4412 *rt
= strv_free(*rt
);
4416 for (const char *p
= rvalue
;;) {
4417 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
4419 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
4423 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4424 "Invalid syntax, ignoring: %s", rvalue
);
4430 r
= unit_full_printf(u
, word
, &k
);
4432 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4433 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
4437 r
= path_simplify_and_warn(k
, PATH_CHECK_RELATIVE
, unit
, filename
, line
, lvalue
);
4441 if (path_startswith(k
, "private")) {
4442 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4443 "%s= path can't be 'private', ignoring assignment: %s", lvalue
, word
);
4447 r
= strv_push(rt
, k
);
4454 int config_parse_set_credential(
4456 const char *filename
,
4458 const char *section
,
4459 unsigned section_line
,
4466 _cleanup_free_
char *word
= NULL
, *k
= NULL
, *unescaped
= NULL
;
4467 ExecContext
*context
= data
;
4468 ExecSetCredential
*old
;
4478 if (isempty(rvalue
)) {
4479 /* Empty assignment resets the list */
4480 context
->set_credentials
= hashmap_free(context
->set_credentials
);
4485 r
= extract_first_word(&p
, &word
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4489 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
4493 r
= unit_full_printf(u
, word
, &k
);
4495 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
4498 if (!credential_name_valid(k
)) {
4499 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Credential name \"%s\" not valid, ignoring.", k
);
4503 /* We support escape codes here, so that users can insert trailing \n if they like */
4504 l
= cunescape(p
, UNESCAPE_ACCEPT_NUL
, &unescaped
);
4506 log_syntax(unit
, LOG_WARNING
, filename
, line
, l
, "Can't unescape \"%s\", ignoring: %m", p
);
4510 old
= hashmap_get(context
->set_credentials
, k
);
4512 free_and_replace(old
->data
, unescaped
);
4515 _cleanup_(exec_set_credential_freep
) ExecSetCredential
*sc
= NULL
;
4517 sc
= new0(ExecSetCredential
, 1);
4521 sc
->id
= TAKE_PTR(k
);
4522 sc
->data
= TAKE_PTR(unescaped
);
4525 r
= hashmap_ensure_allocated(&context
->set_credentials
, &exec_set_credential_hash_ops
);
4529 r
= hashmap_put(context
->set_credentials
, sc
->id
, sc
);
4539 int config_parse_load_credential(
4541 const char *filename
,
4543 const char *section
,
4544 unsigned section_line
,
4551 _cleanup_free_
char *word
= NULL
, *k
= NULL
, *q
= NULL
;
4552 ExecContext
*context
= data
;
4562 if (isempty(rvalue
)) {
4563 /* Empty assignment resets the list */
4564 context
->load_credentials
= strv_free(context
->load_credentials
);
4569 r
= extract_first_word(&p
, &word
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4573 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
4577 r
= unit_full_printf(u
, word
, &k
);
4579 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
4582 if (!credential_name_valid(k
)) {
4583 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Credential name \"%s\" not valid, ignoring.", k
);
4586 r
= unit_full_printf(u
, p
, &q
);
4588 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", p
);
4591 if (path_is_absolute(q
) ? !path_is_normalized(q
) : !credential_name_valid(q
)) {
4592 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Credential source \"%s\" not valid, ignoring.", q
);
4596 r
= strv_consume_pair(&context
->load_credentials
, TAKE_PTR(k
), TAKE_PTR(q
));
4603 int config_parse_set_status(
4605 const char *filename
,
4607 const char *section
,
4608 unsigned section_line
,
4615 ExitStatusSet
*status_set
= data
;
4623 /* Empty assignment resets the list */
4624 if (isempty(rvalue
)) {
4625 exit_status_set_free(status_set
);
4629 for (const char *p
= rvalue
;;) {
4630 _cleanup_free_
char *word
= NULL
;
4633 r
= extract_first_word(&p
, &word
, NULL
, 0);
4637 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4638 "Failed to parse %s=%s, ignoring: %m", lvalue
, rvalue
);
4644 /* We need to call exit_status_from_string() first, because we want
4645 * to parse numbers as exit statuses, not signals. */
4647 r
= exit_status_from_string(word
);
4649 assert(r
>= 0 && r
< 256);
4650 bitmap
= &status_set
->status
;
4652 r
= signal_from_string(word
);
4654 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4655 "Failed to parse value, ignoring: %s", word
);
4658 bitmap
= &status_set
->signal
;
4661 r
= bitmap_set(bitmap
, r
);
4663 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4664 "Failed to set signal or status %s, ignoring: %m", word
);
4668 int config_parse_namespace_path_strv(
4670 const char *filename
,
4672 const char *section
,
4673 unsigned section_line
,
4680 const Unit
*u
= userdata
;
4689 if (isempty(rvalue
)) {
4690 /* Empty assignment resets the list */
4691 *sv
= strv_free(*sv
);
4695 for (const char *p
= rvalue
;;) {
4696 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
, *joined
= NULL
;
4698 bool ignore_enoent
= false, shall_prefix
= false;
4700 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
4706 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
4711 if (startswith(w
, "-")) {
4712 ignore_enoent
= true;
4715 if (startswith(w
, "+")) {
4716 shall_prefix
= true;
4720 r
= unit_full_printf(u
, w
, &resolved
);
4722 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", w
);
4726 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4730 joined
= strjoin(ignore_enoent
? "-" : "",
4731 shall_prefix
? "+" : "",
4734 r
= strv_push(sv
, joined
);
4744 int config_parse_temporary_filesystems(
4746 const char *filename
,
4748 const char *section
,
4749 unsigned section_line
,
4756 const Unit
*u
= userdata
;
4757 ExecContext
*c
= data
;
4765 if (isempty(rvalue
)) {
4766 /* Empty assignment resets the list */
4767 temporary_filesystem_free_many(c
->temporary_filesystems
, c
->n_temporary_filesystems
);
4768 c
->temporary_filesystems
= NULL
;
4769 c
->n_temporary_filesystems
= 0;
4773 for (const char *p
= rvalue
;;) {
4774 _cleanup_free_
char *word
= NULL
, *path
= NULL
, *resolved
= NULL
;
4777 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
4783 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
4788 r
= extract_first_word(&w
, &path
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4792 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", word
);
4796 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid syntax, ignoring: %s", word
);
4800 r
= unit_full_printf(u
, path
, &resolved
);
4802 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", path
);
4806 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4810 r
= temporary_filesystem_add(&c
->temporary_filesystems
, &c
->n_temporary_filesystems
, resolved
, w
);
4816 int config_parse_bind_paths(
4818 const char *filename
,
4820 const char *section
,
4821 unsigned section_line
,
4828 ExecContext
*c
= data
;
4829 const Unit
*u
= userdata
;
4837 if (isempty(rvalue
)) {
4838 /* Empty assignment resets the list */
4839 bind_mount_free_many(c
->bind_mounts
, c
->n_bind_mounts
);
4840 c
->bind_mounts
= NULL
;
4841 c
->n_bind_mounts
= 0;
4845 for (const char *p
= rvalue
;;) {
4846 _cleanup_free_
char *source
= NULL
, *destination
= NULL
;
4847 _cleanup_free_
char *sresolved
= NULL
, *dresolved
= NULL
;
4848 char *s
= NULL
, *d
= NULL
;
4849 bool rbind
= true, ignore_enoent
= false;
4851 r
= extract_first_word(&p
, &source
, ":" WHITESPACE
, EXTRACT_UNQUOTE
|EXTRACT_DONT_COALESCE_SEPARATORS
);
4857 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
4861 r
= unit_full_printf(u
, source
, &sresolved
);
4863 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4864 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", source
);
4870 ignore_enoent
= true;
4874 r
= path_simplify_and_warn(s
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4878 /* Optionally, the destination is specified. */
4879 if (p
&& p
[-1] == ':') {
4880 r
= extract_first_word(&p
, &destination
, ":" WHITESPACE
, EXTRACT_UNQUOTE
|EXTRACT_DONT_COALESCE_SEPARATORS
);
4884 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
4888 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Missing argument after ':', ignoring: %s", s
);
4892 r
= unit_full_printf(u
, destination
, &dresolved
);
4894 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4895 "Failed to resolve specifiers in \"%s\", ignoring: %m", destination
);
4899 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4905 /* Optionally, there's also a short option string specified */
4906 if (p
&& p
[-1] == ':') {
4907 _cleanup_free_
char *options
= NULL
;
4909 r
= extract_first_word(&p
, &options
, NULL
, EXTRACT_UNQUOTE
);
4913 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s: %s", lvalue
, rvalue
);
4917 if (isempty(options
) || streq(options
, "rbind"))
4919 else if (streq(options
, "norbind"))
4922 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid option string, ignoring setting: %s", options
);
4929 r
= bind_mount_add(&c
->bind_mounts
, &c
->n_bind_mounts
,
4933 .read_only
= !!strstr(lvalue
, "ReadOnly"),
4935 .ignore_enoent
= ignore_enoent
,
4944 int config_parse_mount_images(
4946 const char *filename
,
4948 const char *section
,
4949 unsigned section_line
,
4956 ExecContext
*c
= data
;
4957 const Unit
*u
= userdata
;
4965 if (isempty(rvalue
)) {
4966 /* Empty assignment resets the list */
4967 c
->mount_images
= mount_image_free_many(c
->mount_images
, &c
->n_mount_images
);
4971 for (const char *p
= rvalue
;;) {
4972 _cleanup_(mount_options_free_allp
) MountOptions
*options
= NULL
;
4973 _cleanup_free_
char *first
= NULL
, *second
= NULL
, *tuple
= NULL
;
4974 _cleanup_free_
char *sresolved
= NULL
, *dresolved
= NULL
;
4975 const char *q
= NULL
;
4977 bool permissive
= false;
4979 r
= extract_first_word(&p
, &tuple
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_RETAIN_ESCAPE
);
4983 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4984 "Invalid syntax %s=%s, ignoring: %m", lvalue
, rvalue
);
4991 r
= extract_many_words(&q
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
, &first
, &second
, NULL
);
4995 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4996 "Invalid syntax in %s=, ignoring: %s", lvalue
, tuple
);
5002 r
= unit_full_printf(u
, first
, &sresolved
);
5004 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5005 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", first
);
5015 r
= path_simplify_and_warn(s
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5019 if (isempty(second
)) {
5020 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Missing destination in %s, ignoring: %s", lvalue
, rvalue
);
5024 r
= unit_full_printf(u
, second
, &dresolved
);
5026 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5027 "Failed to resolve specifiers in \"%s\", ignoring: %m", second
);
5031 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5036 _cleanup_free_
char *partition
= NULL
, *mount_options
= NULL
, *mount_options_resolved
= NULL
;
5037 MountOptions
*o
= NULL
;
5038 PartitionDesignator partition_designator
;
5040 r
= extract_many_words(&q
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
, &partition
, &mount_options
, NULL
);
5044 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", q
);
5049 /* Single set of options, applying to the root partition/single filesystem */
5051 r
= unit_full_printf(u
, partition
, &mount_options_resolved
);
5053 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", first
);
5057 o
= new(MountOptions
, 1);
5060 *o
= (MountOptions
) {
5061 .partition_designator
= PARTITION_ROOT
,
5062 .options
= TAKE_PTR(mount_options_resolved
),
5064 LIST_APPEND(mount_options
, options
, o
);
5069 partition_designator
= partition_designator_from_string(partition
);
5070 if (partition_designator
< 0) {
5071 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid partition name %s, ignoring", partition
);
5074 r
= unit_full_printf(u
, mount_options
, &mount_options_resolved
);
5076 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", mount_options
);
5080 o
= new(MountOptions
, 1);
5083 *o
= (MountOptions
) {
5084 .partition_designator
= partition_designator
,
5085 .options
= TAKE_PTR(mount_options_resolved
),
5087 LIST_APPEND(mount_options
, options
, o
);
5090 r
= mount_image_add(&c
->mount_images
, &c
->n_mount_images
,
5093 .destination
= dresolved
,
5094 .mount_options
= options
,
5095 .ignore_enoent
= permissive
,
5102 int config_parse_job_timeout_sec(
5104 const char *filename
,
5106 const char *section
,
5107 unsigned section_line
,
5123 r
= parse_sec_fix_0(rvalue
, &usec
);
5125 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse JobTimeoutSec= parameter, ignoring: %s", rvalue
);
5129 /* If the user explicitly changed JobTimeoutSec= also change JobRunningTimeoutSec=, for compatibility with old
5130 * versions. If JobRunningTimeoutSec= was explicitly set, avoid this however as whatever the user picked should
5133 if (!u
->job_running_timeout_set
)
5134 u
->job_running_timeout
= usec
;
5136 u
->job_timeout
= usec
;
5141 int config_parse_job_running_timeout_sec(
5143 const char *filename
,
5145 const char *section
,
5146 unsigned section_line
,
5162 r
= parse_sec_fix_0(rvalue
, &usec
);
5164 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse JobRunningTimeoutSec= parameter, ignoring: %s", rvalue
);
5168 u
->job_running_timeout
= usec
;
5169 u
->job_running_timeout_set
= true;
5174 int config_parse_emergency_action(
5176 const char *filename
,
5178 const char *section
,
5179 unsigned section_line
,
5187 EmergencyAction
*x
= data
;
5196 m
= ((Unit
*) userdata
)->manager
;
5200 r
= parse_emergency_action(rvalue
, MANAGER_IS_SYSTEM(m
), x
);
5202 if (r
== -EOPNOTSUPP
&& MANAGER_IS_USER(m
)) {
5203 /* Compat mode: remove for systemd 241. */
5205 log_syntax(unit
, LOG_INFO
, filename
, line
, r
,
5206 "%s= in user mode specified as \"%s\", using \"exit-force\" instead.",
5208 *x
= EMERGENCY_ACTION_EXIT_FORCE
;
5212 if (r
== -EOPNOTSUPP
)
5213 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5214 "%s= specified as %s mode action, ignoring: %s",
5215 lvalue
, MANAGER_IS_SYSTEM(m
) ? "user" : "system", rvalue
);
5217 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5218 "Failed to parse %s=, ignoring: %s", lvalue
, rvalue
);
5225 int config_parse_pid_file(
5227 const char *filename
,
5229 const char *section
,
5230 unsigned section_line
,
5237 _cleanup_free_
char *k
= NULL
, *n
= NULL
;
5238 const Unit
*u
= userdata
;
5247 if (isempty(rvalue
)) {
5248 /* An empty assignment removes already set value. */
5253 r
= unit_full_printf(u
, rvalue
, &k
);
5255 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
5259 /* If this is a relative path make it absolute by prefixing the /run */
5260 n
= path_make_absolute(k
, u
->manager
->prefix
[EXEC_DIRECTORY_RUNTIME
]);
5264 /* Check that the result is a sensible path */
5265 r
= path_simplify_and_warn(n
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5269 r
= patch_var_run(unit
, filename
, line
, lvalue
, &n
);
5273 free_and_replace(*s
, n
);
5277 int config_parse_exit_status(
5279 const char *filename
,
5281 const char *section
,
5282 unsigned section_line
,
5289 int *exit_status
= data
, r
;
5295 assert(exit_status
);
5297 if (isempty(rvalue
)) {
5302 r
= safe_atou8(rvalue
, &u
);
5304 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse exit status '%s', ignoring: %m", rvalue
);
5312 int config_parse_disable_controllers(
5314 const char *filename
,
5316 const char *section
,
5317 unsigned section_line
,
5325 CGroupContext
*c
= data
;
5326 CGroupMask disabled_mask
;
5328 /* 1. If empty, make all controllers eligible for use again.
5329 * 2. If non-empty, merge all listed controllers, space separated. */
5331 if (isempty(rvalue
)) {
5332 c
->disable_controllers
= 0;
5336 r
= cg_mask_from_string(rvalue
, &disabled_mask
);
5337 if (r
< 0 || disabled_mask
<= 0) {
5338 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid cgroup string: %s, ignoring", rvalue
);
5342 c
->disable_controllers
|= disabled_mask
;
5347 int config_parse_ip_filter_bpf_progs(
5349 const char *filename
,
5351 const char *section
,
5352 unsigned section_line
,
5359 _cleanup_free_
char *resolved
= NULL
;
5360 const Unit
*u
= userdata
;
5361 char ***paths
= data
;
5369 if (isempty(rvalue
)) {
5370 *paths
= strv_free(*paths
);
5374 r
= unit_full_printf(u
, rvalue
, &resolved
);
5376 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
5380 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5384 if (strv_contains(*paths
, resolved
))
5387 r
= strv_extend(paths
, resolved
);
5391 r
= bpf_firewall_supported();
5394 if (r
!= BPF_FIREWALL_SUPPORTED_WITH_MULTI
) {
5395 static bool warned
= false;
5397 log_full(warned
? LOG_DEBUG
: LOG_WARNING
,
5398 "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"
5399 "Starting this unit will fail! (This warning is only shown for the first loaded unit using IP firewalling.)", filename
, line
, lvalue
, rvalue
);
5407 static int merge_by_names(Unit
**u
, Set
*names
, const char *id
) {
5414 /* Let's try to add in all names that are aliases of this unit */
5415 while ((k
= set_steal_first(names
))) {
5416 _cleanup_free_ _unused_
char *free_k
= k
;
5418 /* First try to merge in the other name into our unit */
5419 r
= unit_merge_by_name(*u
, k
);
5423 /* Hmm, we couldn't merge the other unit into ours? Then let's try it the other way
5426 other
= manager_get_unit((*u
)->manager
, k
);
5428 return r
; /* return previous failure */
5430 r
= unit_merge(other
, *u
);
5435 return merge_by_names(u
, names
, NULL
);
5438 if (streq_ptr(id
, k
))
5439 unit_choose_id(*u
, id
);
5445 int unit_load_fragment(Unit
*u
) {
5446 const char *fragment
;
5447 _cleanup_set_free_free_ Set
*names
= NULL
;
5451 assert(u
->load_state
== UNIT_STUB
);
5455 u
->load_state
= UNIT_LOADED
;
5459 /* Possibly rebuild the fragment map to catch new units */
5460 r
= unit_file_build_name_map(&u
->manager
->lookup_paths
,
5461 &u
->manager
->unit_cache_timestamp_hash
,
5462 &u
->manager
->unit_id_map
,
5463 &u
->manager
->unit_name_map
,
5464 &u
->manager
->unit_path_cache
);
5466 return log_error_errno(r
, "Failed to rebuild name map: %m");
5468 r
= unit_file_find_fragment(u
->manager
->unit_id_map
,
5469 u
->manager
->unit_name_map
,
5473 if (r
< 0 && r
!= -ENOENT
)
5477 /* Open the file, check if this is a mask, otherwise read. */
5478 _cleanup_fclose_
FILE *f
= NULL
;
5481 /* Try to open the file name. A symlink is OK, for example for linked files or masks. We
5482 * expect that all symlinks within the lookup paths have been already resolved, but we don't
5483 * verify this here. */
5484 f
= fopen(fragment
, "re");
5486 return log_unit_notice_errno(u
, errno
, "Failed to open %s: %m", fragment
);
5488 if (fstat(fileno(f
), &st
) < 0)
5491 r
= free_and_strdup(&u
->fragment_path
, fragment
);
5495 if (null_or_empty(&st
)) {
5496 /* Unit file is masked */
5498 u
->load_state
= u
->perpetual
? UNIT_LOADED
: UNIT_MASKED
; /* don't allow perpetual units to ever be masked */
5499 u
->fragment_mtime
= 0;
5501 u
->load_state
= UNIT_LOADED
;
5502 u
->fragment_mtime
= timespec_load(&st
.st_mtim
);
5504 /* Now, parse the file contents */
5505 r
= config_parse(u
->id
, fragment
, f
,
5506 UNIT_VTABLE(u
)->sections
,
5507 config_item_perf_lookup
, load_fragment_gperf_lookup
,
5512 log_unit_notice_errno(u
, r
, "Unit configuration has fatal error, unit will not be started.");
5518 /* We do the merge dance here because for some unit types, the unit might have aliases which are not
5519 * declared in the file system. In particular, this is true (and frequent) for device and swap units.
5522 const char *id
= u
->id
;
5523 _cleanup_free_
char *free_id
= NULL
;
5526 id
= basename(fragment
);
5527 if (unit_name_is_valid(id
, UNIT_NAME_TEMPLATE
)) {
5528 assert(u
->instance
); /* If we're not trying to use a template for non-instanced unit,
5529 * this must be set. */
5531 r
= unit_name_replace_instance(id
, u
->instance
, &free_id
);
5533 return log_debug_errno(r
, "Failed to build id (%s + %s): %m", id
, u
->instance
);
5539 r
= merge_by_names(&merged
, names
, id
);
5544 u
->load_state
= UNIT_MERGED
;
5549 void unit_dump_config_items(FILE *f
) {
5550 static const struct {
5551 const ConfigParserCallback callback
;
5554 { config_parse_warn_compat
, "NOTSUPPORTED" },
5555 { config_parse_int
, "INTEGER" },
5556 { config_parse_unsigned
, "UNSIGNED" },
5557 { config_parse_iec_size
, "SIZE" },
5558 { config_parse_iec_uint64
, "SIZE" },
5559 { config_parse_si_uint64
, "SIZE" },
5560 { config_parse_bool
, "BOOLEAN" },
5561 { config_parse_string
, "STRING" },
5562 { config_parse_path
, "PATH" },
5563 { config_parse_unit_path_printf
, "PATH" },
5564 { config_parse_strv
, "STRING [...]" },
5565 { config_parse_exec_nice
, "NICE" },
5566 { config_parse_exec_oom_score_adjust
, "OOMSCOREADJUST" },
5567 { config_parse_exec_io_class
, "IOCLASS" },
5568 { config_parse_exec_io_priority
, "IOPRIORITY" },
5569 { config_parse_exec_cpu_sched_policy
, "CPUSCHEDPOLICY" },
5570 { config_parse_exec_cpu_sched_prio
, "CPUSCHEDPRIO" },
5571 { config_parse_exec_cpu_affinity
, "CPUAFFINITY" },
5572 { config_parse_mode
, "MODE" },
5573 { config_parse_unit_env_file
, "FILE" },
5574 { config_parse_exec_output
, "OUTPUT" },
5575 { config_parse_exec_input
, "INPUT" },
5576 { config_parse_log_facility
, "FACILITY" },
5577 { config_parse_log_level
, "LEVEL" },
5578 { config_parse_exec_secure_bits
, "SECUREBITS" },
5579 { config_parse_capability_set
, "BOUNDINGSET" },
5580 { config_parse_rlimit
, "LIMIT" },
5581 { config_parse_unit_deps
, "UNIT [...]" },
5582 { config_parse_exec
, "PATH [ARGUMENT [...]]" },
5583 { config_parse_service_type
, "SERVICETYPE" },
5584 { config_parse_service_restart
, "SERVICERESTART" },
5585 { config_parse_service_timeout_failure_mode
, "TIMEOUTMODE" },
5586 { config_parse_kill_mode
, "KILLMODE" },
5587 { config_parse_signal
, "SIGNAL" },
5588 { config_parse_socket_listen
, "SOCKET [...]" },
5589 { config_parse_socket_bind
, "SOCKETBIND" },
5590 { config_parse_socket_bindtodevice
, "NETWORKINTERFACE" },
5591 { config_parse_sec
, "SECONDS" },
5592 { config_parse_nsec
, "NANOSECONDS" },
5593 { config_parse_namespace_path_strv
, "PATH [...]" },
5594 { config_parse_bind_paths
, "PATH[:PATH[:OPTIONS]] [...]" },
5595 { config_parse_unit_requires_mounts_for
, "PATH [...]" },
5596 { config_parse_exec_mount_flags
, "MOUNTFLAG [...]" },
5597 { config_parse_unit_string_printf
, "STRING" },
5598 { config_parse_trigger_unit
, "UNIT" },
5599 { config_parse_timer
, "TIMER" },
5600 { config_parse_path_spec
, "PATH" },
5601 { config_parse_notify_access
, "ACCESS" },
5602 { config_parse_ip_tos
, "TOS" },
5603 { config_parse_unit_condition_path
, "CONDITION" },
5604 { config_parse_unit_condition_string
, "CONDITION" },
5605 { config_parse_unit_slice
, "SLICE" },
5606 { config_parse_documentation
, "URL" },
5607 { config_parse_service_timeout
, "SECONDS" },
5608 { config_parse_emergency_action
, "ACTION" },
5609 { config_parse_set_status
, "STATUS" },
5610 { config_parse_service_sockets
, "SOCKETS" },
5611 { config_parse_environ
, "ENVIRON" },
5613 { config_parse_syscall_filter
, "SYSCALLS" },
5614 { config_parse_syscall_archs
, "ARCHS" },
5615 { config_parse_syscall_errno
, "ERRNO" },
5616 { config_parse_syscall_log
, "SYSCALLS" },
5617 { config_parse_address_families
, "FAMILIES" },
5618 { config_parse_restrict_namespaces
, "NAMESPACES" },
5620 { config_parse_cpu_shares
, "SHARES" },
5621 { config_parse_cg_weight
, "WEIGHT" },
5622 { config_parse_memory_limit
, "LIMIT" },
5623 { config_parse_device_allow
, "DEVICE" },
5624 { config_parse_device_policy
, "POLICY" },
5625 { config_parse_io_limit
, "LIMIT" },
5626 { config_parse_io_device_weight
, "DEVICEWEIGHT" },
5627 { config_parse_io_device_latency
, "DEVICELATENCY" },
5628 { config_parse_blockio_bandwidth
, "BANDWIDTH" },
5629 { config_parse_blockio_weight
, "WEIGHT" },
5630 { config_parse_blockio_device_weight
, "DEVICEWEIGHT" },
5631 { config_parse_long
, "LONG" },
5632 { config_parse_socket_service
, "SERVICE" },
5634 { config_parse_exec_selinux_context
, "LABEL" },
5636 { config_parse_job_mode
, "MODE" },
5637 { config_parse_job_mode_isolate
, "BOOLEAN" },
5638 { config_parse_personality
, "PERSONALITY" },
5641 const char *prev
= NULL
;
5646 NULSTR_FOREACH(i
, load_fragment_gperf_nulstr
) {
5647 const char *rvalue
= "OTHER", *lvalue
;
5648 const ConfigPerfItem
*p
;
5651 assert_se(p
= load_fragment_gperf_lookup(i
, strlen(i
)));
5653 /* Hide legacy settings */
5654 if (p
->parse
== config_parse_warn_compat
&&
5655 p
->ltype
== DISABLED_LEGACY
)
5658 for (size_t j
= 0; j
< ELEMENTSOF(table
); j
++)
5659 if (p
->parse
== table
[j
].callback
) {
5660 rvalue
= table
[j
].rvalue
;
5664 dot
= strchr(i
, '.');
5665 lvalue
= dot
? dot
+ 1 : i
;
5668 size_t prefix_len
= dot
- i
;
5670 if (!prev
|| !strneq(prev
, i
, prefix_len
+1)) {
5674 fprintf(f
, "[%.*s]\n", (int) prefix_len
, i
);
5678 fprintf(f
, "%s=%s\n", lvalue
, rvalue
);
5683 int config_parse_cpu_affinity2(
5685 const char *filename
,
5687 const char *section
,
5688 unsigned section_line
,
5695 CPUSet
*affinity
= data
;
5699 (void) parse_cpu_set_extend(rvalue
, affinity
, true, unit
, filename
, line
, lvalue
);
5704 int config_parse_show_status(
5706 const char *filename
,
5708 const char *section
,
5709 unsigned section_line
,
5717 ShowStatus
*b
= data
;
5724 k
= parse_show_status(rvalue
, b
);
5726 log_syntax(unit
, LOG_WARNING
, filename
, line
, k
, "Failed to parse show status setting, ignoring: %s", rvalue
);
5731 int config_parse_output_restricted(
5733 const char *filename
,
5735 const char *section
,
5736 unsigned section_line
,
5743 ExecOutput t
, *eo
= data
;
5744 bool obsolete
= false;
5751 if (streq(rvalue
, "syslog")) {
5752 t
= EXEC_OUTPUT_JOURNAL
;
5754 } else if (streq(rvalue
, "syslog+console")) {
5755 t
= EXEC_OUTPUT_JOURNAL_AND_CONSOLE
;
5758 t
= exec_output_from_string(rvalue
);
5760 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Failed to parse output type, ignoring: %s", rvalue
);
5764 if (IN_SET(t
, EXEC_OUTPUT_SOCKET
, EXEC_OUTPUT_NAMED_FD
, EXEC_OUTPUT_FILE
, EXEC_OUTPUT_FILE_APPEND
)) {
5765 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Standard output types socket, fd:, file:, append: are not supported as defaults, ignoring: %s", rvalue
);
5771 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
5772 "Standard output type %s is obsolete, automatically updating to %s. Please update your configuration.",
5773 rvalue
, exec_output_to_string(t
));
5779 int config_parse_crash_chvt(
5781 const char *filename
,
5783 const char *section
,
5784 unsigned section_line
,
5798 r
= parse_crash_chvt(rvalue
, data
);
5800 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse CrashChangeVT= setting, ignoring: %s", rvalue
);
5805 int config_parse_swap_priority(
5807 const char *filename
,
5809 const char *section
,
5810 unsigned section_line
,
5826 if (isempty(rvalue
)) {
5827 s
->parameters_fragment
.priority
= -1;
5828 s
->parameters_fragment
.priority_set
= false;
5832 r
= safe_atoi(rvalue
, &priority
);
5834 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid swap priority '%s', ignoring.", rvalue
);
5838 if (priority
< -1) {
5839 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
);
5843 if (priority
> 32767) {
5844 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Swap priority out of range, ignoring: %s", rvalue
);
5848 s
->parameters_fragment
.priority
= priority
;
5849 s
->parameters_fragment
.priority_set
= true;