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 } else if ((n
= startswith(rvalue
, "truncate:"))) {
1208 r
= unit_full_printf(u
, n
, &resolved
);
1210 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", n
);
1214 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1218 eo
= EXEC_OUTPUT_FILE_TRUNCATE
;
1220 eo
= exec_output_from_string(rvalue
);
1222 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Failed to parse output specifier, ignoring: %s", rvalue
);
1228 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
1229 "Standard output type %s is obsolete, automatically updating to %s. Please update your unit file, and consider removing the setting altogether.",
1230 rvalue
, exec_output_to_string(eo
));
1232 if (streq(lvalue
, "StandardOutput")) {
1233 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1234 free_and_replace(c
->stdio_fdname
[STDOUT_FILENO
], resolved
);
1236 free_and_replace(c
->stdio_file
[STDOUT_FILENO
], resolved
);
1241 assert(streq(lvalue
, "StandardError"));
1243 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1244 free_and_replace(c
->stdio_fdname
[STDERR_FILENO
], resolved
);
1246 free_and_replace(c
->stdio_file
[STDERR_FILENO
], resolved
);
1254 int config_parse_exec_io_class(const char *unit
,
1255 const char *filename
,
1257 const char *section
,
1258 unsigned section_line
,
1265 ExecContext
*c
= data
;
1273 if (isempty(rvalue
)) {
1274 c
->ioprio_set
= false;
1275 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE
, 0);
1279 x
= ioprio_class_from_string(rvalue
);
1281 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Failed to parse IO scheduling class, ignoring: %s", rvalue
);
1285 c
->ioprio
= IOPRIO_PRIO_VALUE(x
, IOPRIO_PRIO_DATA(c
->ioprio
));
1286 c
->ioprio_set
= true;
1291 int config_parse_exec_io_priority(const char *unit
,
1292 const char *filename
,
1294 const char *section
,
1295 unsigned section_line
,
1302 ExecContext
*c
= data
;
1310 if (isempty(rvalue
)) {
1311 c
->ioprio_set
= false;
1312 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE
, 0);
1316 r
= ioprio_parse_priority(rvalue
, &i
);
1318 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse IO priority, ignoring: %s", rvalue
);
1322 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_PRIO_CLASS(c
->ioprio
), i
);
1323 c
->ioprio_set
= true;
1328 int config_parse_exec_cpu_sched_policy(const char *unit
,
1329 const char *filename
,
1331 const char *section
,
1332 unsigned section_line
,
1339 ExecContext
*c
= data
;
1347 if (isempty(rvalue
)) {
1348 c
->cpu_sched_set
= false;
1349 c
->cpu_sched_policy
= SCHED_OTHER
;
1350 c
->cpu_sched_priority
= 0;
1354 x
= sched_policy_from_string(rvalue
);
1356 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Failed to parse CPU scheduling policy, ignoring: %s", rvalue
);
1360 c
->cpu_sched_policy
= x
;
1361 /* Moving to or from real-time policy? We need to adjust the priority */
1362 c
->cpu_sched_priority
= CLAMP(c
->cpu_sched_priority
, sched_get_priority_min(x
), sched_get_priority_max(x
));
1363 c
->cpu_sched_set
= true;
1368 int config_parse_exec_mount_apivfs(const char *unit
,
1369 const char *filename
,
1371 const char *section
,
1372 unsigned section_line
,
1379 ExecContext
*c
= data
;
1387 if (isempty(rvalue
)) {
1388 c
->mount_apivfs_set
= false;
1389 c
->mount_apivfs
= false;
1393 k
= parse_boolean(rvalue
);
1395 log_syntax(unit
, LOG_WARNING
, filename
, line
, k
,
1396 "Failed to parse boolean value, ignoring: %s",
1401 c
->mount_apivfs_set
= true;
1402 c
->mount_apivfs
= k
;
1406 int config_parse_numa_mask(const char *unit
,
1407 const char *filename
,
1409 const char *section
,
1410 unsigned section_line
,
1417 NUMAPolicy
*p
= data
;
1424 if (streq(rvalue
, "all")) {
1425 r
= numa_mask_add_all(&p
->nodes
);
1427 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1428 "Failed to create NUMA mask representing \"all\" NUMA nodes, ignoring: %m");
1430 r
= parse_cpu_set_extend(rvalue
, &p
->nodes
, true, unit
, filename
, line
, lvalue
);
1432 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse NUMA node mask, ignoring: %s", rvalue
);
1438 int config_parse_exec_cpu_sched_prio(const char *unit
,
1439 const char *filename
,
1441 const char *section
,
1442 unsigned section_line
,
1449 ExecContext
*c
= data
;
1457 r
= safe_atoi(rvalue
, &i
);
1459 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse CPU scheduling priority, ignoring: %s", rvalue
);
1463 /* On Linux RR/FIFO range from 1 to 99 and OTHER/BATCH may only be 0 */
1464 min
= sched_get_priority_min(c
->cpu_sched_policy
);
1465 max
= sched_get_priority_max(c
->cpu_sched_policy
);
1467 if (i
< min
|| i
> max
) {
1468 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "CPU scheduling priority is out of range, ignoring: %s", rvalue
);
1472 c
->cpu_sched_priority
= i
;
1473 c
->cpu_sched_set
= true;
1478 int config_parse_root_image_options(
1480 const char *filename
,
1482 const char *section
,
1483 unsigned section_line
,
1490 _cleanup_(mount_options_free_allp
) MountOptions
*options
= NULL
;
1491 _cleanup_strv_free_
char **l
= NULL
;
1492 char **first
= NULL
, **second
= NULL
;
1493 ExecContext
*c
= data
;
1494 const Unit
*u
= userdata
;
1502 if (isempty(rvalue
)) {
1503 c
->root_image_options
= mount_options_free_all(c
->root_image_options
);
1507 r
= strv_split_colon_pairs(&l
, rvalue
);
1511 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
1515 STRV_FOREACH_PAIR(first
, second
, l
) {
1516 MountOptions
*o
= NULL
;
1517 _cleanup_free_
char *mount_options_resolved
= NULL
;
1518 const char *mount_options
= NULL
, *partition
= "root";
1519 PartitionDesignator partition_designator
;
1521 /* Format is either 'root:foo' or 'foo' (root is implied) */
1522 if (!isempty(*second
)) {
1524 mount_options
= *second
;
1526 mount_options
= *first
;
1528 partition_designator
= partition_designator_from_string(partition
);
1529 if (partition_designator
< 0) {
1530 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid partition name %s, ignoring", partition
);
1533 r
= unit_full_printf(u
, mount_options
, &mount_options_resolved
);
1535 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", mount_options
);
1539 o
= new(MountOptions
, 1);
1542 *o
= (MountOptions
) {
1543 .partition_designator
= partition_designator
,
1544 .options
= TAKE_PTR(mount_options_resolved
),
1546 LIST_APPEND(mount_options
, options
, TAKE_PTR(o
));
1549 /* empty spaces/separators only */
1550 if (LIST_IS_EMPTY(options
))
1551 c
->root_image_options
= mount_options_free_all(c
->root_image_options
);
1553 LIST_JOIN(mount_options
, c
->root_image_options
, options
);
1558 int config_parse_exec_root_hash(
1560 const char *filename
,
1562 const char *section
,
1563 unsigned section_line
,
1570 _cleanup_free_
void *roothash_decoded
= NULL
;
1571 ExecContext
*c
= data
;
1572 size_t roothash_decoded_size
= 0;
1580 if (isempty(rvalue
)) {
1581 /* Reset if the empty string is assigned */
1582 c
->root_hash_path
= mfree(c
->root_hash_path
);
1583 c
->root_hash
= mfree(c
->root_hash
);
1584 c
->root_hash_size
= 0;
1588 if (path_is_absolute(rvalue
)) {
1589 /* We have the path to a roothash to load and decode, eg: RootHash=/foo/bar.roothash */
1590 _cleanup_free_
char *p
= NULL
;
1596 free_and_replace(c
->root_hash_path
, p
);
1597 c
->root_hash
= mfree(c
->root_hash
);
1598 c
->root_hash_size
= 0;
1602 /* We have a roothash to decode, eg: RootHash=012345789abcdef */
1603 r
= unhexmem(rvalue
, strlen(rvalue
), &roothash_decoded
, &roothash_decoded_size
);
1605 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to decode RootHash=, ignoring: %s", rvalue
);
1608 if (roothash_decoded_size
< sizeof(sd_id128_t
)) {
1609 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "RootHash= is too short, ignoring: %s", rvalue
);
1613 free_and_replace(c
->root_hash
, roothash_decoded
);
1614 c
->root_hash_size
= roothash_decoded_size
;
1615 c
->root_hash_path
= mfree(c
->root_hash_path
);
1620 int config_parse_exec_root_hash_sig(
1622 const char *filename
,
1624 const char *section
,
1625 unsigned section_line
,
1632 _cleanup_free_
void *roothash_sig_decoded
= NULL
;
1634 ExecContext
*c
= data
;
1635 size_t roothash_sig_decoded_size
= 0;
1643 if (isempty(rvalue
)) {
1644 /* Reset if the empty string is assigned */
1645 c
->root_hash_sig_path
= mfree(c
->root_hash_sig_path
);
1646 c
->root_hash_sig
= mfree(c
->root_hash_sig
);
1647 c
->root_hash_sig_size
= 0;
1651 if (path_is_absolute(rvalue
)) {
1652 /* We have the path to a roothash signature to load and decode, eg: RootHashSignature=/foo/bar.roothash.p7s */
1653 _cleanup_free_
char *p
= NULL
;
1659 free_and_replace(c
->root_hash_sig_path
, p
);
1660 c
->root_hash_sig
= mfree(c
->root_hash_sig
);
1661 c
->root_hash_sig_size
= 0;
1665 if (!(value
= startswith(rvalue
, "base64:"))) {
1666 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
1667 "Failed to decode RootHashSignature=, not a path but doesn't start with 'base64:', ignoring: %s", rvalue
);
1671 /* We have a roothash signature to decode, eg: RootHashSignature=base64:012345789abcdef */
1672 r
= unbase64mem(value
, strlen(value
), &roothash_sig_decoded
, &roothash_sig_decoded_size
);
1674 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to decode RootHashSignature=, ignoring: %s", rvalue
);
1678 free_and_replace(c
->root_hash_sig
, roothash_sig_decoded
);
1679 c
->root_hash_sig_size
= roothash_sig_decoded_size
;
1680 c
->root_hash_sig_path
= mfree(c
->root_hash_sig_path
);
1685 int config_parse_exec_cpu_affinity(const char *unit
,
1686 const char *filename
,
1688 const char *section
,
1689 unsigned section_line
,
1696 ExecContext
*c
= data
;
1704 if (streq(rvalue
, "numa")) {
1705 c
->cpu_affinity_from_numa
= true;
1706 cpu_set_reset(&c
->cpu_set
);
1711 r
= parse_cpu_set_extend(rvalue
, &c
->cpu_set
, true, unit
, filename
, line
, lvalue
);
1713 c
->cpu_affinity_from_numa
= false;
1718 int config_parse_capability_set(
1720 const char *filename
,
1722 const char *section
,
1723 unsigned section_line
,
1730 uint64_t *capability_set
= data
;
1731 uint64_t sum
= 0, initial
= 0;
1732 bool invert
= false;
1740 if (rvalue
[0] == '~') {
1745 if (streq(lvalue
, "CapabilityBoundingSet"))
1746 initial
= CAP_ALL
; /* initialized to all bits on */
1747 /* else "AmbientCapabilities" initialized to all bits off */
1749 r
= capability_set_from_string(rvalue
, &sum
);
1751 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= specifier '%s', ignoring: %m", lvalue
, rvalue
);
1755 if (sum
== 0 || *capability_set
== initial
)
1756 /* "", "~" or uninitialized data -> replace */
1757 *capability_set
= invert
? ~sum
: sum
;
1759 /* previous data -> merge */
1761 *capability_set
&= ~sum
;
1763 *capability_set
|= sum
;
1769 int config_parse_exec_selinux_context(
1771 const char *filename
,
1773 const char *section
,
1774 unsigned section_line
,
1781 ExecContext
*c
= data
;
1782 const Unit
*u
= userdata
;
1792 if (isempty(rvalue
)) {
1793 c
->selinux_context
= mfree(c
->selinux_context
);
1794 c
->selinux_context_ignore
= false;
1798 if (rvalue
[0] == '-') {
1804 r
= unit_full_printf(u
, rvalue
, &k
);
1806 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
1807 "Failed to resolve unit specifiers in '%s'%s: %m",
1808 rvalue
, ignore
? ", ignoring" : "");
1809 return ignore
? 0 : -ENOEXEC
;
1812 free_and_replace(c
->selinux_context
, k
);
1813 c
->selinux_context_ignore
= ignore
;
1818 int config_parse_exec_apparmor_profile(
1820 const char *filename
,
1822 const char *section
,
1823 unsigned section_line
,
1830 ExecContext
*c
= data
;
1831 const Unit
*u
= userdata
;
1841 if (isempty(rvalue
)) {
1842 c
->apparmor_profile
= mfree(c
->apparmor_profile
);
1843 c
->apparmor_profile_ignore
= false;
1847 if (rvalue
[0] == '-') {
1853 r
= unit_full_printf(u
, rvalue
, &k
);
1855 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
1856 "Failed to resolve unit specifiers in '%s'%s: %m",
1857 rvalue
, ignore
? ", ignoring" : "");
1858 return ignore
? 0 : -ENOEXEC
;
1861 free_and_replace(c
->apparmor_profile
, k
);
1862 c
->apparmor_profile_ignore
= ignore
;
1867 int config_parse_exec_smack_process_label(
1869 const char *filename
,
1871 const char *section
,
1872 unsigned section_line
,
1879 ExecContext
*c
= data
;
1880 const Unit
*u
= userdata
;
1890 if (isempty(rvalue
)) {
1891 c
->smack_process_label
= mfree(c
->smack_process_label
);
1892 c
->smack_process_label_ignore
= false;
1896 if (rvalue
[0] == '-') {
1902 r
= unit_full_printf(u
, rvalue
, &k
);
1904 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
1905 "Failed to resolve unit specifiers in '%s'%s: %m",
1906 rvalue
, ignore
? ", ignoring" : "");
1907 return ignore
? 0 : -ENOEXEC
;
1910 free_and_replace(c
->smack_process_label
, k
);
1911 c
->smack_process_label_ignore
= ignore
;
1916 int config_parse_timer(
1918 const char *filename
,
1920 const char *section
,
1921 unsigned section_line
,
1928 _cleanup_(calendar_spec_freep
) CalendarSpec
*c
= NULL
;
1929 _cleanup_free_
char *k
= NULL
;
1930 const Unit
*u
= userdata
;
1941 if (isempty(rvalue
)) {
1942 /* Empty assignment resets list */
1943 timer_free_values(t
);
1947 r
= unit_full_printf(u
, rvalue
, &k
);
1949 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
1953 if (ltype
== TIMER_CALENDAR
) {
1954 r
= calendar_spec_from_string(k
, &c
);
1956 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse calendar specification, ignoring: %s", k
);
1960 r
= parse_sec(k
, &usec
);
1962 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse timer value, ignoring: %s", k
);
1967 v
= new(TimerValue
, 1);
1974 .calendar_spec
= TAKE_PTR(c
),
1977 LIST_PREPEND(value
, t
->values
, v
);
1982 int config_parse_trigger_unit(
1984 const char *filename
,
1986 const char *section
,
1987 unsigned section_line
,
1994 _cleanup_free_
char *p
= NULL
;
2004 if (!hashmap_isempty(u
->dependencies
[UNIT_TRIGGERS
])) {
2005 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Multiple units to trigger specified, ignoring: %s", rvalue
);
2009 r
= unit_name_printf(u
, rvalue
, &p
);
2011 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2015 type
= unit_name_to_type(p
);
2017 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Unit type not valid, ignoring: %s", rvalue
);
2020 if (unit_has_name(u
, p
)) {
2021 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Units cannot trigger themselves, ignoring: %s", rvalue
);
2025 r
= unit_add_two_dependencies_by_name(u
, UNIT_BEFORE
, UNIT_TRIGGERS
, p
, true, UNIT_DEPENDENCY_FILE
);
2027 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add trigger on %s, ignoring: %m", p
);
2034 int config_parse_path_spec(const char *unit
,
2035 const char *filename
,
2037 const char *section
,
2038 unsigned section_line
,
2048 _cleanup_free_
char *k
= NULL
;
2056 if (isempty(rvalue
)) {
2057 /* Empty assignment clears list */
2062 b
= path_type_from_string(lvalue
);
2064 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Failed to parse path type, ignoring: %s", lvalue
);
2068 r
= unit_full_printf(UNIT(p
), rvalue
, &k
);
2070 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2074 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2078 s
= new0(PathSpec
, 1);
2083 s
->path
= TAKE_PTR(k
);
2087 LIST_PREPEND(spec
, p
->specs
, s
);
2092 int config_parse_socket_service(
2094 const char *filename
,
2096 const char *section
,
2097 unsigned section_line
,
2104 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
2105 _cleanup_free_
char *p
= NULL
;
2115 r
= unit_name_printf(UNIT(s
), rvalue
, &p
);
2117 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2121 if (!endswith(p
, ".service")) {
2122 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Unit must be of type service, ignoring: %s", rvalue
);
2126 r
= manager_load_unit(UNIT(s
)->manager
, p
, NULL
, &error
, &x
);
2128 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to load unit %s, ignoring: %s", rvalue
, bus_error_message(&error
, r
));
2132 unit_ref_set(&s
->service
, UNIT(s
), x
);
2137 int config_parse_fdname(
2139 const char *filename
,
2141 const char *section
,
2142 unsigned section_line
,
2149 _cleanup_free_
char *p
= NULL
;
2158 if (isempty(rvalue
)) {
2159 s
->fdname
= mfree(s
->fdname
);
2163 r
= unit_full_printf(UNIT(s
), rvalue
, &p
);
2165 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2169 if (!fdname_is_valid(p
)) {
2170 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", p
);
2174 return free_and_replace(s
->fdname
, p
);
2177 int config_parse_service_sockets(
2179 const char *filename
,
2181 const char *section
,
2182 unsigned section_line
,
2197 for (const char *p
= rvalue
;;) {
2198 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2200 r
= extract_first_word(&p
, &word
, NULL
, 0);
2206 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Trailing garbage in sockets, ignoring: %s", rvalue
);
2210 r
= unit_name_printf(UNIT(s
), word
, &k
);
2212 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
2216 if (!endswith(k
, ".socket")) {
2217 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Unit must be of type socket, ignoring: %s", k
);
2221 r
= unit_add_two_dependencies_by_name(UNIT(s
), UNIT_WANTS
, UNIT_AFTER
, k
, true, UNIT_DEPENDENCY_FILE
);
2223 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
2225 r
= unit_add_dependency_by_name(UNIT(s
), UNIT_TRIGGERED_BY
, k
, true, UNIT_DEPENDENCY_FILE
);
2227 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
2231 int config_parse_bus_name(
2233 const char *filename
,
2235 const char *section
,
2236 unsigned section_line
,
2243 _cleanup_free_
char *k
= NULL
;
2244 const Unit
*u
= userdata
;
2252 r
= unit_full_printf(u
, rvalue
, &k
);
2254 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2258 if (!sd_bus_service_name_is_valid(k
)) {
2259 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid bus name, ignoring: %s", k
);
2263 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
2266 int config_parse_service_timeout(
2268 const char *filename
,
2270 const char *section
,
2271 unsigned section_line
,
2278 Service
*s
= userdata
;
2287 /* This is called for two cases: TimeoutSec= and TimeoutStartSec=. */
2289 /* Traditionally, these options accepted 0 to disable the timeouts. However, a timeout of 0 suggests it happens
2290 * immediately, hence fix this to become USEC_INFINITY instead. This is in-line with how we internally handle
2291 * all other timeouts. */
2292 r
= parse_sec_fix_0(rvalue
, &usec
);
2294 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
2298 s
->start_timeout_defined
= true;
2299 s
->timeout_start_usec
= usec
;
2301 if (streq(lvalue
, "TimeoutSec"))
2302 s
->timeout_stop_usec
= usec
;
2307 int config_parse_timeout_abort(
2309 const char *filename
,
2311 const char *section
,
2312 unsigned section_line
,
2327 /* Note: apart from setting the arg, this returns an extra bit of information in the return value. */
2329 if (isempty(rvalue
)) {
2331 return 0; /* "not set" */
2334 r
= parse_sec(rvalue
, ret
);
2336 return log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= setting, ignoring: %s", lvalue
, rvalue
);
2338 return 1; /* "set" */
2341 int config_parse_service_timeout_abort(
2343 const char *filename
,
2345 const char *section
,
2346 unsigned section_line
,
2353 Service
*s
= userdata
;
2358 r
= config_parse_timeout_abort(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
,
2359 &s
->timeout_abort_usec
, s
);
2361 s
->timeout_abort_set
= r
;
2365 int config_parse_sec_fix_0(
2367 const char *filename
,
2369 const char *section
,
2370 unsigned section_line
,
2377 usec_t
*usec
= data
;
2385 /* This is pretty much like config_parse_sec(), except that this treats a time of 0 as infinity, for
2386 * compatibility with older versions of systemd where 0 instead of infinity was used as indicator to turn off a
2389 r
= parse_sec_fix_0(rvalue
, usec
);
2391 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
2396 int config_parse_user_group_compat(
2398 const char *filename
,
2400 const char *section
,
2401 unsigned section_line
,
2408 _cleanup_free_
char *k
= NULL
;
2410 const Unit
*u
= userdata
;
2418 if (isempty(rvalue
)) {
2419 *user
= mfree(*user
);
2423 r
= unit_full_printf(u
, rvalue
, &k
);
2425 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", rvalue
);
2429 if (!valid_user_group_name(k
, VALID_USER_ALLOW_NUMERIC
|VALID_USER_RELAX
|VALID_USER_WARN
)) {
2430 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2434 if (strstr(lvalue
, "User") && streq(k
, NOBODY_USER_NAME
))
2435 log_struct(LOG_NOTICE
,
2436 "MESSAGE=%s:%u: Special user %s configured, this is not safe!", filename
, line
, k
,
2438 "MESSAGE_ID=" SD_MESSAGE_NOBODY_USER_UNSUITABLE_STR
,
2439 "OFFENDING_USER=%s", k
,
2440 "CONFIG_FILE=%s", filename
,
2441 "CONFIG_LINE=%u", line
);
2443 return free_and_replace(*user
, k
);
2446 int config_parse_user_group_strv_compat(
2448 const char *filename
,
2450 const char *section
,
2451 unsigned section_line
,
2458 char ***users
= data
;
2459 const Unit
*u
= userdata
;
2467 if (isempty(rvalue
)) {
2468 *users
= strv_free(*users
);
2472 for (const char *p
= rvalue
;;) {
2473 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2475 r
= extract_first_word(&p
, &word
, NULL
, 0);
2481 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax: %s", rvalue
);
2485 r
= unit_full_printf(u
, word
, &k
);
2487 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", word
);
2491 if (!valid_user_group_name(k
, VALID_USER_ALLOW_NUMERIC
|VALID_USER_RELAX
|VALID_USER_WARN
)) {
2492 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2496 r
= strv_push(users
, k
);
2504 int config_parse_working_directory(
2506 const char *filename
,
2508 const char *section
,
2509 unsigned section_line
,
2516 ExecContext
*c
= data
;
2517 const Unit
*u
= userdata
;
2527 if (isempty(rvalue
)) {
2528 c
->working_directory_home
= false;
2529 c
->working_directory
= mfree(c
->working_directory
);
2533 if (rvalue
[0] == '-') {
2539 if (streq(rvalue
, "~")) {
2540 c
->working_directory_home
= true;
2541 c
->working_directory
= mfree(c
->working_directory
);
2543 _cleanup_free_
char *k
= NULL
;
2545 r
= unit_full_printf(u
, rvalue
, &k
);
2547 log_syntax(unit
, missing_ok
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
2548 "Failed to resolve unit specifiers in working directory path '%s'%s: %m",
2549 rvalue
, missing_ok
? ", ignoring" : "");
2550 return missing_ok
? 0 : -ENOEXEC
;
2553 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
| (missing_ok
? 0 : PATH_CHECK_FATAL
), unit
, filename
, line
, lvalue
);
2555 return missing_ok
? 0 : -ENOEXEC
;
2557 c
->working_directory_home
= false;
2558 free_and_replace(c
->working_directory
, k
);
2561 c
->working_directory_missing_ok
= missing_ok
;
2565 int config_parse_unit_env_file(const char *unit
,
2566 const char *filename
,
2568 const char *section
,
2569 unsigned section_line
,
2577 const Unit
*u
= userdata
;
2578 _cleanup_free_
char *n
= NULL
;
2586 if (isempty(rvalue
)) {
2587 /* Empty assignment frees the list */
2588 *env
= strv_free(*env
);
2592 r
= unit_full_printf(u
, rvalue
, &n
);
2594 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2598 r
= path_simplify_and_warn(n
[0] == '-' ? n
+ 1 : n
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2602 r
= strv_push(env
, n
);
2611 int config_parse_environ(
2613 const char *filename
,
2615 const char *section
,
2616 unsigned section_line
,
2623 const Unit
*u
= userdata
;
2632 if (isempty(rvalue
)) {
2633 /* Empty assignment resets the list */
2634 *env
= strv_free(*env
);
2638 for (const char *p
= rvalue
;; ) {
2639 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2641 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2647 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2648 "Invalid syntax, ignoring: %s", rvalue
);
2653 r
= unit_full_printf(u
, word
, &k
);
2655 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2656 "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2662 if (!env_assignment_is_valid(k
)) {
2663 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
2664 "Invalid environment assignment, ignoring: %s", k
);
2668 r
= strv_env_replace(env
, k
);
2676 int config_parse_pass_environ(
2678 const char *filename
,
2680 const char *section
,
2681 unsigned section_line
,
2688 _cleanup_strv_free_
char **n
= NULL
;
2689 size_t nlen
= 0, nbufsize
= 0;
2690 char*** passenv
= data
;
2691 const Unit
*u
= userdata
;
2699 if (isempty(rvalue
)) {
2700 /* Empty assignment resets the list */
2701 *passenv
= strv_free(*passenv
);
2705 for (const char *p
= rvalue
;;) {
2706 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2708 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
2714 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2715 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2720 r
= unit_full_printf(u
, word
, &k
);
2722 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2723 "Failed to resolve specifiers in %s, ignoring: %m", word
);
2729 if (!env_name_is_valid(k
)) {
2730 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
2731 "Invalid environment name for %s, ignoring: %s", lvalue
, k
);
2735 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
2738 n
[nlen
++] = TAKE_PTR(k
);
2743 r
= strv_extend_strv(passenv
, n
, true);
2751 int config_parse_unset_environ(
2753 const char *filename
,
2755 const char *section
,
2756 unsigned section_line
,
2763 _cleanup_strv_free_
char **n
= NULL
;
2764 size_t nlen
= 0, nbufsize
= 0;
2765 char*** unsetenv
= data
;
2766 const Unit
*u
= userdata
;
2774 if (isempty(rvalue
)) {
2775 /* Empty assignment resets the list */
2776 *unsetenv
= strv_free(*unsetenv
);
2780 for (const char *p
= rvalue
;;) {
2781 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2783 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2789 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2790 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2795 r
= unit_full_printf(u
, word
, &k
);
2797 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2798 "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2804 if (!env_assignment_is_valid(k
) && !env_name_is_valid(k
)) {
2805 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
2806 "Invalid environment name or assignment %s, ignoring: %s", lvalue
, k
);
2810 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
2813 n
[nlen
++] = TAKE_PTR(k
);
2818 r
= strv_extend_strv(unsetenv
, n
, true);
2826 int config_parse_log_extra_fields(
2828 const char *filename
,
2830 const char *section
,
2831 unsigned section_line
,
2838 ExecContext
*c
= data
;
2839 const Unit
*u
= userdata
;
2847 if (isempty(rvalue
)) {
2848 exec_context_free_log_extra_fields(c
);
2852 for (const char *p
= rvalue
;;) {
2853 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2857 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2863 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
2867 r
= unit_full_printf(u
, word
, &k
);
2869 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2873 eq
= strchr(k
, '=');
2875 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Log field lacks '=' character, ignoring: %s", k
);
2879 if (!journal_field_valid(k
, eq
-k
, false)) {
2880 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Log field name is invalid, ignoring: %s", k
);
2884 t
= reallocarray(c
->log_extra_fields
, c
->n_log_extra_fields
+1, sizeof(struct iovec
));
2888 c
->log_extra_fields
= t
;
2889 c
->log_extra_fields
[c
->n_log_extra_fields
++] = IOVEC_MAKE_STRING(k
);
2895 int config_parse_log_namespace(
2897 const char *filename
,
2899 const char *section
,
2900 unsigned section_line
,
2907 _cleanup_free_
char *k
= NULL
;
2908 ExecContext
*c
= data
;
2909 const Unit
*u
= userdata
;
2917 if (isempty(rvalue
)) {
2918 c
->log_namespace
= mfree(c
->log_namespace
);
2922 r
= unit_full_printf(u
, rvalue
, &k
);
2924 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2928 if (!log_namespace_name_valid(k
)) {
2929 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Specified log namespace name is not valid, ignoring: %s", k
);
2933 free_and_replace(c
->log_namespace
, k
);
2937 int config_parse_unit_condition_path(
2939 const char *filename
,
2941 const char *section
,
2942 unsigned section_line
,
2949 _cleanup_free_
char *p
= NULL
;
2950 Condition
**list
= data
, *c
;
2951 ConditionType t
= ltype
;
2952 bool trigger
, negate
;
2953 const Unit
*u
= userdata
;
2961 if (isempty(rvalue
)) {
2962 /* Empty assignment resets the list */
2963 *list
= condition_free_list(*list
);
2967 trigger
= rvalue
[0] == '|';
2971 negate
= rvalue
[0] == '!';
2975 r
= unit_full_printf(u
, rvalue
, &p
);
2977 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2981 r
= path_simplify_and_warn(p
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2985 c
= condition_new(t
, p
, trigger
, negate
);
2989 LIST_PREPEND(conditions
, *list
, c
);
2993 int config_parse_unit_condition_string(
2995 const char *filename
,
2997 const char *section
,
2998 unsigned section_line
,
3005 _cleanup_free_
char *s
= NULL
;
3006 Condition
**list
= data
, *c
;
3007 ConditionType t
= ltype
;
3008 bool trigger
, negate
;
3009 const Unit
*u
= userdata
;
3017 if (isempty(rvalue
)) {
3018 /* Empty assignment resets the list */
3019 *list
= condition_free_list(*list
);
3023 trigger
= *rvalue
== '|';
3025 rvalue
+= 1 + strspn(rvalue
+ 1, WHITESPACE
);
3027 negate
= *rvalue
== '!';
3029 rvalue
+= 1 + strspn(rvalue
+ 1, WHITESPACE
);
3031 r
= unit_full_printf(u
, rvalue
, &s
);
3033 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3034 "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
3038 c
= condition_new(t
, s
, trigger
, negate
);
3042 LIST_PREPEND(conditions
, *list
, c
);
3046 int config_parse_unit_requires_mounts_for(
3048 const char *filename
,
3050 const char *section
,
3051 unsigned section_line
,
3066 for (const char *p
= rvalue
;;) {
3067 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
3069 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3075 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3076 "Invalid syntax, ignoring: %s", rvalue
);
3080 r
= unit_full_printf(u
, word
, &resolved
);
3082 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
3086 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
3090 r
= unit_require_mounts_for(u
, resolved
, UNIT_DEPENDENCY_FILE
);
3092 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add required mount '%s', ignoring: %m", resolved
);
3098 int config_parse_documentation(const char *unit
,
3099 const char *filename
,
3101 const char *section
,
3102 unsigned section_line
,
3118 if (isempty(rvalue
)) {
3119 /* Empty assignment resets the list */
3120 u
->documentation
= strv_free(u
->documentation
);
3124 r
= config_parse_unit_strv_printf(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
,
3125 rvalue
, data
, userdata
);
3129 for (a
= b
= u
->documentation
; a
&& *a
; a
++) {
3131 if (documentation_url_is_valid(*a
))
3134 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid URL, ignoring: %s", *a
);
3145 int config_parse_syscall_filter(
3147 const char *filename
,
3149 const char *section
,
3150 unsigned section_line
,
3157 ExecContext
*c
= data
;
3158 _unused_
const Unit
*u
= userdata
;
3159 bool invert
= false;
3167 if (isempty(rvalue
)) {
3168 /* Empty assignment resets the list */
3169 c
->syscall_filter
= hashmap_free(c
->syscall_filter
);
3170 c
->syscall_allow_list
= false;
3174 if (rvalue
[0] == '~') {
3179 if (!c
->syscall_filter
) {
3180 c
->syscall_filter
= hashmap_new(NULL
);
3181 if (!c
->syscall_filter
)
3185 /* Allow everything but the ones listed */
3186 c
->syscall_allow_list
= false;
3188 /* Allow nothing but the ones listed */
3189 c
->syscall_allow_list
= true;
3191 /* Accept default syscalls if we are on a allow_list */
3192 r
= seccomp_parse_syscall_filter(
3193 "@default", -1, c
->syscall_filter
,
3194 SECCOMP_PARSE_PERMISSIVE
|SECCOMP_PARSE_ALLOW_LIST
,
3202 for (const char *p
= rvalue
;;) {
3203 _cleanup_free_
char *word
= NULL
, *name
= NULL
;
3206 r
= extract_first_word(&p
, &word
, NULL
, 0);
3212 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3216 r
= parse_syscall_and_errno(word
, &name
, &num
);
3218 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse syscall:errno, ignoring: %s", word
);
3222 r
= seccomp_parse_syscall_filter(
3223 name
, num
, c
->syscall_filter
,
3224 SECCOMP_PARSE_LOG
|SECCOMP_PARSE_PERMISSIVE
|
3225 (invert
? SECCOMP_PARSE_INVERT
: 0)|
3226 (c
->syscall_allow_list
? SECCOMP_PARSE_ALLOW_LIST
: 0),
3227 unit
, filename
, line
);
3233 int config_parse_syscall_log(
3235 const char *filename
,
3237 const char *section
,
3238 unsigned section_line
,
3245 ExecContext
*c
= data
;
3246 _unused_
const Unit
*u
= userdata
;
3247 bool invert
= false;
3256 if (isempty(rvalue
)) {
3257 /* Empty assignment resets the list */
3258 c
->syscall_log
= hashmap_free(c
->syscall_log
);
3259 c
->syscall_log_allow_list
= false;
3263 if (rvalue
[0] == '~') {
3268 if (!c
->syscall_log
) {
3269 c
->syscall_log
= hashmap_new(NULL
);
3270 if (!c
->syscall_log
)
3274 /* Log everything but the ones listed */
3275 c
->syscall_log_allow_list
= false;
3277 /* Log nothing but the ones listed */
3278 c
->syscall_log_allow_list
= true;
3283 _cleanup_free_
char *word
= NULL
, *name
= NULL
;
3286 r
= extract_first_word(&p
, &word
, NULL
, 0);
3292 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3296 r
= parse_syscall_and_errno(word
, &name
, &num
);
3297 if (r
< 0 || num
>= 0) { /* errno code not allowed */
3298 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse syscall, ignoring: %s", word
);
3302 r
= seccomp_parse_syscall_filter(
3303 name
, 0, c
->syscall_log
,
3304 SECCOMP_PARSE_LOG
|SECCOMP_PARSE_PERMISSIVE
|
3305 (invert
? SECCOMP_PARSE_INVERT
: 0)|
3306 (c
->syscall_log_allow_list
? SECCOMP_PARSE_ALLOW_LIST
: 0),
3307 unit
, filename
, line
);
3313 int config_parse_syscall_archs(
3315 const char *filename
,
3317 const char *section
,
3318 unsigned section_line
,
3328 if (isempty(rvalue
)) {
3329 *archs
= set_free(*archs
);
3333 for (const char *p
= rvalue
;;) {
3334 _cleanup_free_
char *word
= NULL
;
3337 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3343 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3344 "Invalid syntax, ignoring: %s", rvalue
);
3348 r
= seccomp_arch_from_string(word
, &a
);
3350 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3351 "Failed to parse system call architecture \"%s\", ignoring: %m", word
);
3355 r
= set_ensure_put(archs
, NULL
, UINT32_TO_PTR(a
+ 1));
3361 int config_parse_syscall_errno(
3363 const char *filename
,
3365 const char *section
,
3366 unsigned section_line
,
3373 ExecContext
*c
= data
;
3380 if (isempty(rvalue
) || streq(rvalue
, "kill")) {
3381 /* Empty assignment resets to KILL */
3382 c
->syscall_errno
= SECCOMP_ERROR_NUMBER_KILL
;
3386 e
= parse_errno(rvalue
);
3388 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Failed to parse error number, ignoring: %s", rvalue
);
3392 c
->syscall_errno
= e
;
3396 int config_parse_address_families(
3398 const char *filename
,
3400 const char *section
,
3401 unsigned section_line
,
3408 ExecContext
*c
= data
;
3409 bool invert
= false;
3416 if (isempty(rvalue
)) {
3417 /* Empty assignment resets the list */
3418 c
->address_families
= set_free(c
->address_families
);
3419 c
->address_families_allow_list
= false;
3423 if (rvalue
[0] == '~') {
3428 if (!c
->address_families
) {
3429 c
->address_families
= set_new(NULL
);
3430 if (!c
->address_families
)
3433 c
->address_families_allow_list
= !invert
;
3436 for (const char *p
= rvalue
;;) {
3437 _cleanup_free_
char *word
= NULL
;
3440 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3446 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3447 "Invalid syntax, ignoring: %s", rvalue
);
3451 af
= af_from_name(word
);
3453 log_syntax(unit
, LOG_WARNING
, filename
, line
, af
,
3454 "Failed to parse address family, ignoring: %s", word
);
3458 /* If we previously wanted to forbid an address family and now
3459 * we want to allow it, then just remove it from the list.
3461 if (!invert
== c
->address_families_allow_list
) {
3462 r
= set_put(c
->address_families
, INT_TO_PTR(af
));
3466 set_remove(c
->address_families
, INT_TO_PTR(af
));
3470 int config_parse_restrict_namespaces(
3472 const char *filename
,
3474 const char *section
,
3475 unsigned section_line
,
3482 ExecContext
*c
= data
;
3483 unsigned long flags
;
3484 bool invert
= false;
3487 if (isempty(rvalue
)) {
3488 /* Reset to the default. */
3489 c
->restrict_namespaces
= NAMESPACE_FLAGS_INITIAL
;
3493 /* Boolean parameter ignores the previous settings */
3494 r
= parse_boolean(rvalue
);
3496 c
->restrict_namespaces
= 0;
3498 } else if (r
== 0) {
3499 c
->restrict_namespaces
= NAMESPACE_FLAGS_ALL
;
3503 if (rvalue
[0] == '~') {
3508 /* Not a boolean argument, in this case it's a list of namespace types. */
3509 r
= namespace_flags_from_string(rvalue
, &flags
);
3511 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse namespace type string, ignoring: %s", rvalue
);
3515 if (c
->restrict_namespaces
== NAMESPACE_FLAGS_INITIAL
)
3516 /* Initial assignment. Just set the value. */
3517 c
->restrict_namespaces
= invert
? (~flags
) & NAMESPACE_FLAGS_ALL
: flags
;
3519 /* Merge the value with the previous one. */
3520 SET_FLAG(c
->restrict_namespaces
, flags
, !invert
);
3526 int config_parse_unit_slice(
3528 const char *filename
,
3530 const char *section
,
3531 unsigned section_line
,
3538 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
3539 _cleanup_free_
char *k
= NULL
;
3540 Unit
*u
= userdata
, *slice
;
3548 r
= unit_name_printf(u
, rvalue
, &k
);
3550 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
3554 r
= manager_load_unit(u
->manager
, k
, NULL
, &error
, &slice
);
3556 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to load slice unit %s, ignoring: %s", k
, bus_error_message(&error
, r
));
3560 r
= unit_set_slice(u
, slice
);
3562 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to assign slice %s to unit %s, ignoring: %m", slice
->id
, u
->id
);
3569 int config_parse_cpu_quota(
3571 const char *filename
,
3573 const char *section
,
3574 unsigned section_line
,
3581 CGroupContext
*c
= data
;
3588 if (isempty(rvalue
)) {
3589 c
->cpu_quota_per_sec_usec
= USEC_INFINITY
;
3593 r
= parse_permille_unbounded(rvalue
);
3595 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid CPU quota '%s', ignoring.", rvalue
);
3599 c
->cpu_quota_per_sec_usec
= ((usec_t
) r
* USEC_PER_SEC
) / 1000U;
3603 int config_parse_allowed_cpus(
3605 const char *filename
,
3607 const char *section
,
3608 unsigned section_line
,
3615 CGroupContext
*c
= data
;
3617 (void) parse_cpu_set_extend(rvalue
, &c
->cpuset_cpus
, true, unit
, filename
, line
, lvalue
);
3622 int config_parse_allowed_mems(
3624 const char *filename
,
3626 const char *section
,
3627 unsigned section_line
,
3634 CGroupContext
*c
= data
;
3636 (void) parse_cpu_set_extend(rvalue
, &c
->cpuset_mems
, true, unit
, filename
, line
, lvalue
);
3641 int config_parse_memory_limit(
3643 const char *filename
,
3645 const char *section
,
3646 unsigned section_line
,
3653 CGroupContext
*c
= data
;
3654 uint64_t bytes
= CGROUP_LIMIT_MAX
;
3657 if (isempty(rvalue
) && STR_IN_SET(lvalue
, "DefaultMemoryLow",
3661 bytes
= CGROUP_LIMIT_MIN
;
3662 else if (!isempty(rvalue
) && !streq(rvalue
, "infinity")) {
3664 r
= parse_permille(rvalue
);
3666 r
= parse_size(rvalue
, 1024, &bytes
);
3668 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid memory limit '%s', ignoring: %m", rvalue
);
3672 bytes
= physical_memory_scale(r
, 1000U);
3674 if (bytes
>= UINT64_MAX
||
3675 (bytes
<= 0 && !STR_IN_SET(lvalue
, "MemorySwapMax", "MemoryLow", "MemoryMin", "DefaultMemoryLow", "DefaultMemoryMin"))) {
3676 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Memory limit '%s' out of range, ignoring.", rvalue
);
3681 if (streq(lvalue
, "DefaultMemoryLow")) {
3682 c
->default_memory_low
= bytes
;
3683 c
->default_memory_low_set
= true;
3684 } else if (streq(lvalue
, "DefaultMemoryMin")) {
3685 c
->default_memory_min
= bytes
;
3686 c
->default_memory_min_set
= true;
3687 } else if (streq(lvalue
, "MemoryMin")) {
3688 c
->memory_min
= bytes
;
3689 c
->memory_min_set
= true;
3690 } else if (streq(lvalue
, "MemoryLow")) {
3691 c
->memory_low
= bytes
;
3692 c
->memory_low_set
= true;
3693 } else if (streq(lvalue
, "MemoryHigh"))
3694 c
->memory_high
= bytes
;
3695 else if (streq(lvalue
, "MemoryMax"))
3696 c
->memory_max
= bytes
;
3697 else if (streq(lvalue
, "MemorySwapMax"))
3698 c
->memory_swap_max
= bytes
;
3699 else if (streq(lvalue
, "MemoryLimit"))
3700 c
->memory_limit
= bytes
;
3707 int config_parse_tasks_max(
3709 const char *filename
,
3711 const char *section
,
3712 unsigned section_line
,
3719 const Unit
*u
= userdata
;
3720 TasksMax
*tasks_max
= data
;
3724 if (isempty(rvalue
)) {
3725 *tasks_max
= u
? u
->manager
->default_tasks_max
: TASKS_MAX_UNSET
;
3729 if (streq(rvalue
, "infinity")) {
3730 *tasks_max
= TASKS_MAX_UNSET
;
3734 r
= parse_permille(rvalue
);
3736 *tasks_max
= (TasksMax
) { r
, 1000U }; /* r‰ */
3738 r
= safe_atou64(rvalue
, &v
);
3740 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid maximum tasks value '%s', ignoring: %m", rvalue
);
3744 if (v
<= 0 || v
>= UINT64_MAX
) {
3745 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Maximum tasks value '%s' out of range, ignoring.", rvalue
);
3749 *tasks_max
= (TasksMax
) { v
};
3755 int config_parse_delegate(
3757 const char *filename
,
3759 const char *section
,
3760 unsigned section_line
,
3767 CGroupContext
*c
= data
;
3771 t
= unit_name_to_type(unit
);
3772 assert(t
!= _UNIT_TYPE_INVALID
);
3774 if (!unit_vtable
[t
]->can_delegate
) {
3775 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Delegate= setting not supported for this unit type, ignoring.");
3779 /* We either accept a boolean value, which may be used to turn on delegation for all controllers, or turn it
3780 * off for all. Or it takes a list of controller names, in which case we add the specified controllers to the
3781 * mask to delegate. */
3783 if (isempty(rvalue
)) {
3784 /* An empty string resets controllers and set Delegate=yes. */
3786 c
->delegate_controllers
= 0;
3790 r
= parse_boolean(rvalue
);
3792 CGroupMask mask
= 0;
3794 for (const char *p
= rvalue
;;) {
3795 _cleanup_free_
char *word
= NULL
;
3796 CGroupController cc
;
3798 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3804 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3808 cc
= cgroup_controller_from_string(word
);
3810 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid controller name '%s', ignoring", word
);
3814 mask
|= CGROUP_CONTROLLER_TO_MASK(cc
);
3818 c
->delegate_controllers
|= mask
;
3822 c
->delegate_controllers
= _CGROUP_MASK_ALL
;
3824 c
->delegate
= false;
3825 c
->delegate_controllers
= 0;
3831 int config_parse_managed_oom_mode(
3833 const char *filename
,
3835 const char *section
,
3836 unsigned section_line
,
3842 ManagedOOMMode
*mode
= data
, m
;
3845 t
= unit_name_to_type(unit
);
3846 assert(t
!= _UNIT_TYPE_INVALID
);
3848 if (!unit_vtable
[t
]->can_set_managed_oom
)
3849 return log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "%s= is not supported for this unit type, ignoring.", lvalue
);
3851 if (isempty(rvalue
)) {
3852 *mode
= MANAGED_OOM_AUTO
;
3856 m
= managed_oom_mode_from_string(rvalue
);
3858 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid syntax, ignoring: %s", rvalue
);
3865 int config_parse_managed_oom_mem_pressure_limit(
3867 const char *filename
,
3869 const char *section
,
3870 unsigned section_line
,
3880 t
= unit_name_to_type(unit
);
3881 assert(t
!= _UNIT_TYPE_INVALID
);
3883 if (!unit_vtable
[t
]->can_set_managed_oom
)
3884 return log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "%s= is not supported for this unit type, ignoring.", lvalue
);
3886 if (isempty(rvalue
)) {
3891 r
= parse_percent(rvalue
);
3893 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse limit percent value, ignoring: %s", rvalue
);
3901 int config_parse_device_allow(
3903 const char *filename
,
3905 const char *section
,
3906 unsigned section_line
,
3913 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3914 CGroupContext
*c
= data
;
3915 const char *p
= rvalue
;
3918 if (isempty(rvalue
)) {
3919 while (c
->device_allow
)
3920 cgroup_context_free_device_allow(c
, c
->device_allow
);
3925 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3929 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3930 "Invalid syntax, ignoring: %s", rvalue
);
3934 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3935 "Failed to extract device path and rights from '%s', ignoring.", rvalue
);
3939 r
= unit_full_printf(userdata
, path
, &resolved
);
3941 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3942 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3946 if (!STARTSWITH_SET(resolved
, "block-", "char-")) {
3948 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3952 if (!valid_device_node_path(resolved
)) {
3953 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid device node path '%s', ignoring.", resolved
);
3958 if (!isempty(p
) && !in_charset(p
, "rwm")) {
3959 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid device rights '%s', ignoring.", p
);
3963 return cgroup_add_device_allow(c
, resolved
, p
);
3966 int config_parse_io_device_weight(
3968 const char *filename
,
3970 const char *section
,
3971 unsigned section_line
,
3978 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3979 CGroupIODeviceWeight
*w
;
3980 CGroupContext
*c
= data
;
3981 const char *p
= rvalue
;
3989 if (isempty(rvalue
)) {
3990 while (c
->io_device_weights
)
3991 cgroup_context_free_io_device_weight(c
, c
->io_device_weights
);
3996 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4000 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4001 "Invalid syntax, ignoring: %s", rvalue
);
4004 if (r
== 0 || isempty(p
)) {
4005 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4006 "Failed to extract device path and weight from '%s', ignoring.", rvalue
);
4010 r
= unit_full_printf(userdata
, path
, &resolved
);
4012 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4013 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4017 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4021 r
= cg_weight_parse(p
, &u
);
4023 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "IO weight '%s' invalid, ignoring: %m", p
);
4027 assert(u
!= CGROUP_WEIGHT_INVALID
);
4029 w
= new0(CGroupIODeviceWeight
, 1);
4033 w
->path
= TAKE_PTR(resolved
);
4036 LIST_PREPEND(device_weights
, c
->io_device_weights
, w
);
4040 int config_parse_io_device_latency(
4042 const char *filename
,
4044 const char *section
,
4045 unsigned section_line
,
4052 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4053 CGroupIODeviceLatency
*l
;
4054 CGroupContext
*c
= data
;
4055 const char *p
= rvalue
;
4063 if (isempty(rvalue
)) {
4064 while (c
->io_device_latencies
)
4065 cgroup_context_free_io_device_latency(c
, c
->io_device_latencies
);
4070 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4074 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4075 "Invalid syntax, ignoring: %s", rvalue
);
4078 if (r
== 0 || isempty(p
)) {
4079 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4080 "Failed to extract device path and latency from '%s', ignoring.", rvalue
);
4084 r
= unit_full_printf(userdata
, path
, &resolved
);
4086 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4087 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4091 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4095 r
= parse_sec(p
, &usec
);
4097 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse timer value, ignoring: %s", p
);
4101 l
= new0(CGroupIODeviceLatency
, 1);
4105 l
->path
= TAKE_PTR(resolved
);
4106 l
->target_usec
= usec
;
4108 LIST_PREPEND(device_latencies
, c
->io_device_latencies
, l
);
4112 int config_parse_io_limit(
4114 const char *filename
,
4116 const char *section
,
4117 unsigned section_line
,
4124 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4125 CGroupIODeviceLimit
*l
= NULL
, *t
;
4126 CGroupContext
*c
= data
;
4127 CGroupIOLimitType type
;
4128 const char *p
= rvalue
;
4136 type
= cgroup_io_limit_type_from_string(lvalue
);
4139 if (isempty(rvalue
)) {
4140 LIST_FOREACH(device_limits
, l
, c
->io_device_limits
)
4141 l
->limits
[type
] = cgroup_io_limit_defaults
[type
];
4145 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4149 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4150 "Invalid syntax, ignoring: %s", rvalue
);
4153 if (r
== 0 || isempty(p
)) {
4154 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4155 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
4159 r
= unit_full_printf(userdata
, path
, &resolved
);
4161 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4162 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4166 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4170 if (streq("infinity", p
))
4171 num
= CGROUP_LIMIT_MAX
;
4173 r
= parse_size(p
, 1000, &num
);
4174 if (r
< 0 || num
<= 0) {
4175 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid IO limit '%s', ignoring.", p
);
4180 LIST_FOREACH(device_limits
, t
, c
->io_device_limits
) {
4181 if (path_equal(resolved
, t
->path
)) {
4188 CGroupIOLimitType ttype
;
4190 l
= new0(CGroupIODeviceLimit
, 1);
4194 l
->path
= TAKE_PTR(resolved
);
4195 for (ttype
= 0; ttype
< _CGROUP_IO_LIMIT_TYPE_MAX
; ttype
++)
4196 l
->limits
[ttype
] = cgroup_io_limit_defaults
[ttype
];
4198 LIST_PREPEND(device_limits
, c
->io_device_limits
, l
);
4201 l
->limits
[type
] = num
;
4206 int config_parse_blockio_device_weight(
4208 const char *filename
,
4210 const char *section
,
4211 unsigned section_line
,
4218 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4219 CGroupBlockIODeviceWeight
*w
;
4220 CGroupContext
*c
= data
;
4221 const char *p
= rvalue
;
4229 if (isempty(rvalue
)) {
4230 while (c
->blockio_device_weights
)
4231 cgroup_context_free_blockio_device_weight(c
, c
->blockio_device_weights
);
4236 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4240 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4241 "Invalid syntax, ignoring: %s", rvalue
);
4244 if (r
== 0 || isempty(p
)) {
4245 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4246 "Failed to extract device node and weight from '%s', ignoring.", rvalue
);
4250 r
= unit_full_printf(userdata
, path
, &resolved
);
4252 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4253 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4257 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4261 r
= cg_blkio_weight_parse(p
, &u
);
4263 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid block IO weight '%s', ignoring: %m", p
);
4267 assert(u
!= CGROUP_BLKIO_WEIGHT_INVALID
);
4269 w
= new0(CGroupBlockIODeviceWeight
, 1);
4273 w
->path
= TAKE_PTR(resolved
);
4276 LIST_PREPEND(device_weights
, c
->blockio_device_weights
, w
);
4280 int config_parse_blockio_bandwidth(
4282 const char *filename
,
4284 const char *section
,
4285 unsigned section_line
,
4292 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4293 CGroupBlockIODeviceBandwidth
*b
= NULL
, *t
;
4294 CGroupContext
*c
= data
;
4295 const char *p
= rvalue
;
4304 read
= streq("BlockIOReadBandwidth", lvalue
);
4306 if (isempty(rvalue
)) {
4307 LIST_FOREACH(device_bandwidths
, b
, c
->blockio_device_bandwidths
) {
4308 b
->rbps
= CGROUP_LIMIT_MAX
;
4309 b
->wbps
= CGROUP_LIMIT_MAX
;
4314 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4318 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4319 "Invalid syntax, ignoring: %s", rvalue
);
4322 if (r
== 0 || isempty(p
)) {
4323 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4324 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
4328 r
= unit_full_printf(userdata
, path
, &resolved
);
4330 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4331 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4335 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4339 r
= parse_size(p
, 1000, &bytes
);
4340 if (r
< 0 || bytes
<= 0) {
4341 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid Block IO Bandwidth '%s', ignoring.", p
);
4345 LIST_FOREACH(device_bandwidths
, t
, c
->blockio_device_bandwidths
) {
4346 if (path_equal(resolved
, t
->path
)) {
4353 b
= new0(CGroupBlockIODeviceBandwidth
, 1);
4357 b
->path
= TAKE_PTR(resolved
);
4358 b
->rbps
= CGROUP_LIMIT_MAX
;
4359 b
->wbps
= CGROUP_LIMIT_MAX
;
4361 LIST_PREPEND(device_bandwidths
, c
->blockio_device_bandwidths
, b
);
4372 int config_parse_job_mode_isolate(
4374 const char *filename
,
4376 const char *section
,
4377 unsigned section_line
,
4391 r
= parse_boolean(rvalue
);
4393 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse boolean, ignoring: %s", rvalue
);
4397 log_notice("%s is deprecated. Please use OnFailureJobMode= instead", lvalue
);
4399 *m
= r
? JOB_ISOLATE
: JOB_REPLACE
;
4403 int config_parse_exec_directories(
4405 const char *filename
,
4407 const char *section
,
4408 unsigned section_line
,
4416 const Unit
*u
= userdata
;
4424 if (isempty(rvalue
)) {
4425 /* Empty assignment resets the list */
4426 *rt
= strv_free(*rt
);
4430 for (const char *p
= rvalue
;;) {
4431 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
4433 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
4437 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4438 "Invalid syntax, ignoring: %s", rvalue
);
4444 r
= unit_full_printf(u
, word
, &k
);
4446 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4447 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
4451 r
= path_simplify_and_warn(k
, PATH_CHECK_RELATIVE
, unit
, filename
, line
, lvalue
);
4455 if (path_startswith(k
, "private")) {
4456 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4457 "%s= path can't be 'private', ignoring assignment: %s", lvalue
, word
);
4461 r
= strv_push(rt
, k
);
4468 int config_parse_set_credential(
4470 const char *filename
,
4472 const char *section
,
4473 unsigned section_line
,
4480 _cleanup_free_
char *word
= NULL
, *k
= NULL
, *unescaped
= NULL
;
4481 ExecContext
*context
= data
;
4482 ExecSetCredential
*old
;
4492 if (isempty(rvalue
)) {
4493 /* Empty assignment resets the list */
4494 context
->set_credentials
= hashmap_free(context
->set_credentials
);
4499 r
= extract_first_word(&p
, &word
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4503 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
4507 r
= unit_full_printf(u
, word
, &k
);
4509 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
4512 if (!credential_name_valid(k
)) {
4513 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Credential name \"%s\" not valid, ignoring.", k
);
4517 /* We support escape codes here, so that users can insert trailing \n if they like */
4518 l
= cunescape(p
, UNESCAPE_ACCEPT_NUL
, &unescaped
);
4520 log_syntax(unit
, LOG_WARNING
, filename
, line
, l
, "Can't unescape \"%s\", ignoring: %m", p
);
4524 old
= hashmap_get(context
->set_credentials
, k
);
4526 free_and_replace(old
->data
, unescaped
);
4529 _cleanup_(exec_set_credential_freep
) ExecSetCredential
*sc
= NULL
;
4531 sc
= new0(ExecSetCredential
, 1);
4535 sc
->id
= TAKE_PTR(k
);
4536 sc
->data
= TAKE_PTR(unescaped
);
4539 r
= hashmap_ensure_allocated(&context
->set_credentials
, &exec_set_credential_hash_ops
);
4543 r
= hashmap_put(context
->set_credentials
, sc
->id
, sc
);
4553 int config_parse_load_credential(
4555 const char *filename
,
4557 const char *section
,
4558 unsigned section_line
,
4565 _cleanup_free_
char *word
= NULL
, *k
= NULL
, *q
= NULL
;
4566 ExecContext
*context
= data
;
4576 if (isempty(rvalue
)) {
4577 /* Empty assignment resets the list */
4578 context
->load_credentials
= strv_free(context
->load_credentials
);
4583 r
= extract_first_word(&p
, &word
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4587 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
4591 r
= unit_full_printf(u
, word
, &k
);
4593 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
4596 if (!credential_name_valid(k
)) {
4597 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Credential name \"%s\" not valid, ignoring.", k
);
4600 r
= unit_full_printf(u
, p
, &q
);
4602 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", p
);
4605 if (path_is_absolute(q
) ? !path_is_normalized(q
) : !credential_name_valid(q
)) {
4606 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Credential source \"%s\" not valid, ignoring.", q
);
4610 r
= strv_consume_pair(&context
->load_credentials
, TAKE_PTR(k
), TAKE_PTR(q
));
4617 int config_parse_set_status(
4619 const char *filename
,
4621 const char *section
,
4622 unsigned section_line
,
4629 ExitStatusSet
*status_set
= data
;
4637 /* Empty assignment resets the list */
4638 if (isempty(rvalue
)) {
4639 exit_status_set_free(status_set
);
4643 for (const char *p
= rvalue
;;) {
4644 _cleanup_free_
char *word
= NULL
;
4647 r
= extract_first_word(&p
, &word
, NULL
, 0);
4651 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4652 "Failed to parse %s=%s, ignoring: %m", lvalue
, rvalue
);
4658 /* We need to call exit_status_from_string() first, because we want
4659 * to parse numbers as exit statuses, not signals. */
4661 r
= exit_status_from_string(word
);
4663 assert(r
>= 0 && r
< 256);
4664 bitmap
= &status_set
->status
;
4666 r
= signal_from_string(word
);
4668 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4669 "Failed to parse value, ignoring: %s", word
);
4672 bitmap
= &status_set
->signal
;
4675 r
= bitmap_set(bitmap
, r
);
4677 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4678 "Failed to set signal or status %s, ignoring: %m", word
);
4682 int config_parse_namespace_path_strv(
4684 const char *filename
,
4686 const char *section
,
4687 unsigned section_line
,
4694 const Unit
*u
= userdata
;
4703 if (isempty(rvalue
)) {
4704 /* Empty assignment resets the list */
4705 *sv
= strv_free(*sv
);
4709 for (const char *p
= rvalue
;;) {
4710 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
, *joined
= NULL
;
4712 bool ignore_enoent
= false, shall_prefix
= false;
4714 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
4720 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
4725 if (startswith(w
, "-")) {
4726 ignore_enoent
= true;
4729 if (startswith(w
, "+")) {
4730 shall_prefix
= true;
4734 r
= unit_full_printf(u
, w
, &resolved
);
4736 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", w
);
4740 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4744 joined
= strjoin(ignore_enoent
? "-" : "",
4745 shall_prefix
? "+" : "",
4748 r
= strv_push(sv
, joined
);
4758 int config_parse_temporary_filesystems(
4760 const char *filename
,
4762 const char *section
,
4763 unsigned section_line
,
4770 const Unit
*u
= userdata
;
4771 ExecContext
*c
= data
;
4779 if (isempty(rvalue
)) {
4780 /* Empty assignment resets the list */
4781 temporary_filesystem_free_many(c
->temporary_filesystems
, c
->n_temporary_filesystems
);
4782 c
->temporary_filesystems
= NULL
;
4783 c
->n_temporary_filesystems
= 0;
4787 for (const char *p
= rvalue
;;) {
4788 _cleanup_free_
char *word
= NULL
, *path
= NULL
, *resolved
= NULL
;
4791 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
4797 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
4802 r
= extract_first_word(&w
, &path
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4806 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", word
);
4810 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid syntax, ignoring: %s", word
);
4814 r
= unit_full_printf(u
, path
, &resolved
);
4816 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", path
);
4820 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4824 r
= temporary_filesystem_add(&c
->temporary_filesystems
, &c
->n_temporary_filesystems
, resolved
, w
);
4830 int config_parse_bind_paths(
4832 const char *filename
,
4834 const char *section
,
4835 unsigned section_line
,
4842 ExecContext
*c
= data
;
4843 const Unit
*u
= userdata
;
4851 if (isempty(rvalue
)) {
4852 /* Empty assignment resets the list */
4853 bind_mount_free_many(c
->bind_mounts
, c
->n_bind_mounts
);
4854 c
->bind_mounts
= NULL
;
4855 c
->n_bind_mounts
= 0;
4859 for (const char *p
= rvalue
;;) {
4860 _cleanup_free_
char *source
= NULL
, *destination
= NULL
;
4861 _cleanup_free_
char *sresolved
= NULL
, *dresolved
= NULL
;
4862 char *s
= NULL
, *d
= NULL
;
4863 bool rbind
= true, ignore_enoent
= false;
4865 r
= extract_first_word(&p
, &source
, ":" WHITESPACE
, EXTRACT_UNQUOTE
|EXTRACT_DONT_COALESCE_SEPARATORS
);
4871 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
4875 r
= unit_full_printf(u
, source
, &sresolved
);
4877 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4878 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", source
);
4884 ignore_enoent
= true;
4888 r
= path_simplify_and_warn(s
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4892 /* Optionally, the destination is specified. */
4893 if (p
&& p
[-1] == ':') {
4894 r
= extract_first_word(&p
, &destination
, ":" WHITESPACE
, EXTRACT_UNQUOTE
|EXTRACT_DONT_COALESCE_SEPARATORS
);
4898 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
4902 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Missing argument after ':', ignoring: %s", s
);
4906 r
= unit_full_printf(u
, destination
, &dresolved
);
4908 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4909 "Failed to resolve specifiers in \"%s\", ignoring: %m", destination
);
4913 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4919 /* Optionally, there's also a short option string specified */
4920 if (p
&& p
[-1] == ':') {
4921 _cleanup_free_
char *options
= NULL
;
4923 r
= extract_first_word(&p
, &options
, NULL
, EXTRACT_UNQUOTE
);
4927 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s: %s", lvalue
, rvalue
);
4931 if (isempty(options
) || streq(options
, "rbind"))
4933 else if (streq(options
, "norbind"))
4936 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid option string, ignoring setting: %s", options
);
4943 r
= bind_mount_add(&c
->bind_mounts
, &c
->n_bind_mounts
,
4947 .read_only
= !!strstr(lvalue
, "ReadOnly"),
4949 .ignore_enoent
= ignore_enoent
,
4958 int config_parse_mount_images(
4960 const char *filename
,
4962 const char *section
,
4963 unsigned section_line
,
4970 ExecContext
*c
= data
;
4971 const Unit
*u
= userdata
;
4979 if (isempty(rvalue
)) {
4980 /* Empty assignment resets the list */
4981 c
->mount_images
= mount_image_free_many(c
->mount_images
, &c
->n_mount_images
);
4985 for (const char *p
= rvalue
;;) {
4986 _cleanup_(mount_options_free_allp
) MountOptions
*options
= NULL
;
4987 _cleanup_free_
char *first
= NULL
, *second
= NULL
, *tuple
= NULL
;
4988 _cleanup_free_
char *sresolved
= NULL
, *dresolved
= NULL
;
4989 const char *q
= NULL
;
4991 bool permissive
= false;
4993 r
= extract_first_word(&p
, &tuple
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_RETAIN_ESCAPE
);
4997 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4998 "Invalid syntax %s=%s, ignoring: %m", lvalue
, rvalue
);
5005 r
= extract_many_words(&q
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
, &first
, &second
, NULL
);
5009 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5010 "Invalid syntax in %s=, ignoring: %s", lvalue
, tuple
);
5016 r
= unit_full_printf(u
, first
, &sresolved
);
5018 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5019 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", first
);
5029 r
= path_simplify_and_warn(s
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5033 if (isempty(second
)) {
5034 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Missing destination in %s, ignoring: %s", lvalue
, rvalue
);
5038 r
= unit_full_printf(u
, second
, &dresolved
);
5040 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5041 "Failed to resolve specifiers in \"%s\", ignoring: %m", second
);
5045 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5050 _cleanup_free_
char *partition
= NULL
, *mount_options
= NULL
, *mount_options_resolved
= NULL
;
5051 MountOptions
*o
= NULL
;
5052 PartitionDesignator partition_designator
;
5054 r
= extract_many_words(&q
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
, &partition
, &mount_options
, NULL
);
5058 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", q
);
5063 /* Single set of options, applying to the root partition/single filesystem */
5065 r
= unit_full_printf(u
, partition
, &mount_options_resolved
);
5067 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", first
);
5071 o
= new(MountOptions
, 1);
5074 *o
= (MountOptions
) {
5075 .partition_designator
= PARTITION_ROOT
,
5076 .options
= TAKE_PTR(mount_options_resolved
),
5078 LIST_APPEND(mount_options
, options
, o
);
5083 partition_designator
= partition_designator_from_string(partition
);
5084 if (partition_designator
< 0) {
5085 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid partition name %s, ignoring", partition
);
5088 r
= unit_full_printf(u
, mount_options
, &mount_options_resolved
);
5090 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", mount_options
);
5094 o
= new(MountOptions
, 1);
5097 *o
= (MountOptions
) {
5098 .partition_designator
= partition_designator
,
5099 .options
= TAKE_PTR(mount_options_resolved
),
5101 LIST_APPEND(mount_options
, options
, o
);
5104 r
= mount_image_add(&c
->mount_images
, &c
->n_mount_images
,
5107 .destination
= dresolved
,
5108 .mount_options
= options
,
5109 .ignore_enoent
= permissive
,
5116 int config_parse_job_timeout_sec(
5118 const char *filename
,
5120 const char *section
,
5121 unsigned section_line
,
5137 r
= parse_sec_fix_0(rvalue
, &usec
);
5139 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse JobTimeoutSec= parameter, ignoring: %s", rvalue
);
5143 /* If the user explicitly changed JobTimeoutSec= also change JobRunningTimeoutSec=, for compatibility with old
5144 * versions. If JobRunningTimeoutSec= was explicitly set, avoid this however as whatever the user picked should
5147 if (!u
->job_running_timeout_set
)
5148 u
->job_running_timeout
= usec
;
5150 u
->job_timeout
= usec
;
5155 int config_parse_job_running_timeout_sec(
5157 const char *filename
,
5159 const char *section
,
5160 unsigned section_line
,
5176 r
= parse_sec_fix_0(rvalue
, &usec
);
5178 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse JobRunningTimeoutSec= parameter, ignoring: %s", rvalue
);
5182 u
->job_running_timeout
= usec
;
5183 u
->job_running_timeout_set
= true;
5188 int config_parse_emergency_action(
5190 const char *filename
,
5192 const char *section
,
5193 unsigned section_line
,
5201 EmergencyAction
*x
= data
;
5210 m
= ((Unit
*) userdata
)->manager
;
5214 r
= parse_emergency_action(rvalue
, MANAGER_IS_SYSTEM(m
), x
);
5216 if (r
== -EOPNOTSUPP
&& MANAGER_IS_USER(m
)) {
5217 /* Compat mode: remove for systemd 241. */
5219 log_syntax(unit
, LOG_INFO
, filename
, line
, r
,
5220 "%s= in user mode specified as \"%s\", using \"exit-force\" instead.",
5222 *x
= EMERGENCY_ACTION_EXIT_FORCE
;
5226 if (r
== -EOPNOTSUPP
)
5227 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5228 "%s= specified as %s mode action, ignoring: %s",
5229 lvalue
, MANAGER_IS_SYSTEM(m
) ? "user" : "system", rvalue
);
5231 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5232 "Failed to parse %s=, ignoring: %s", lvalue
, rvalue
);
5239 int config_parse_pid_file(
5241 const char *filename
,
5243 const char *section
,
5244 unsigned section_line
,
5251 _cleanup_free_
char *k
= NULL
, *n
= NULL
;
5252 const Unit
*u
= userdata
;
5261 if (isempty(rvalue
)) {
5262 /* An empty assignment removes already set value. */
5267 r
= unit_full_printf(u
, rvalue
, &k
);
5269 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
5273 /* If this is a relative path make it absolute by prefixing the /run */
5274 n
= path_make_absolute(k
, u
->manager
->prefix
[EXEC_DIRECTORY_RUNTIME
]);
5278 /* Check that the result is a sensible path */
5279 r
= path_simplify_and_warn(n
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5283 r
= patch_var_run(unit
, filename
, line
, lvalue
, &n
);
5287 free_and_replace(*s
, n
);
5291 int config_parse_exit_status(
5293 const char *filename
,
5295 const char *section
,
5296 unsigned section_line
,
5303 int *exit_status
= data
, r
;
5309 assert(exit_status
);
5311 if (isempty(rvalue
)) {
5316 r
= safe_atou8(rvalue
, &u
);
5318 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse exit status '%s', ignoring: %m", rvalue
);
5326 int config_parse_disable_controllers(
5328 const char *filename
,
5330 const char *section
,
5331 unsigned section_line
,
5339 CGroupContext
*c
= data
;
5340 CGroupMask disabled_mask
;
5342 /* 1. If empty, make all controllers eligible for use again.
5343 * 2. If non-empty, merge all listed controllers, space separated. */
5345 if (isempty(rvalue
)) {
5346 c
->disable_controllers
= 0;
5350 r
= cg_mask_from_string(rvalue
, &disabled_mask
);
5351 if (r
< 0 || disabled_mask
<= 0) {
5352 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid cgroup string: %s, ignoring", rvalue
);
5356 c
->disable_controllers
|= disabled_mask
;
5361 int config_parse_ip_filter_bpf_progs(
5363 const char *filename
,
5365 const char *section
,
5366 unsigned section_line
,
5373 _cleanup_free_
char *resolved
= NULL
;
5374 const Unit
*u
= userdata
;
5375 char ***paths
= data
;
5383 if (isempty(rvalue
)) {
5384 *paths
= strv_free(*paths
);
5388 r
= unit_full_printf(u
, rvalue
, &resolved
);
5390 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
5394 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5398 if (strv_contains(*paths
, resolved
))
5401 r
= strv_extend(paths
, resolved
);
5405 r
= bpf_firewall_supported();
5408 if (r
!= BPF_FIREWALL_SUPPORTED_WITH_MULTI
) {
5409 static bool warned
= false;
5411 log_full(warned
? LOG_DEBUG
: LOG_WARNING
,
5412 "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"
5413 "Starting this unit will fail! (This warning is only shown for the first loaded unit using IP firewalling.)", filename
, line
, lvalue
, rvalue
);
5421 static int merge_by_names(Unit
**u
, Set
*names
, const char *id
) {
5428 /* Let's try to add in all names that are aliases of this unit */
5429 while ((k
= set_steal_first(names
))) {
5430 _cleanup_free_ _unused_
char *free_k
= k
;
5432 /* First try to merge in the other name into our unit */
5433 r
= unit_merge_by_name(*u
, k
);
5437 /* Hmm, we couldn't merge the other unit into ours? Then let's try it the other way
5440 other
= manager_get_unit((*u
)->manager
, k
);
5442 return r
; /* return previous failure */
5444 r
= unit_merge(other
, *u
);
5449 return merge_by_names(u
, names
, NULL
);
5452 if (streq_ptr(id
, k
))
5453 unit_choose_id(*u
, id
);
5459 int unit_load_fragment(Unit
*u
) {
5460 const char *fragment
;
5461 _cleanup_set_free_free_ Set
*names
= NULL
;
5465 assert(u
->load_state
== UNIT_STUB
);
5469 u
->load_state
= UNIT_LOADED
;
5473 /* Possibly rebuild the fragment map to catch new units */
5474 r
= unit_file_build_name_map(&u
->manager
->lookup_paths
,
5475 &u
->manager
->unit_cache_timestamp_hash
,
5476 &u
->manager
->unit_id_map
,
5477 &u
->manager
->unit_name_map
,
5478 &u
->manager
->unit_path_cache
);
5480 return log_error_errno(r
, "Failed to rebuild name map: %m");
5482 r
= unit_file_find_fragment(u
->manager
->unit_id_map
,
5483 u
->manager
->unit_name_map
,
5487 if (r
< 0 && r
!= -ENOENT
)
5491 /* Open the file, check if this is a mask, otherwise read. */
5492 _cleanup_fclose_
FILE *f
= NULL
;
5495 /* Try to open the file name. A symlink is OK, for example for linked files or masks. We
5496 * expect that all symlinks within the lookup paths have been already resolved, but we don't
5497 * verify this here. */
5498 f
= fopen(fragment
, "re");
5500 return log_unit_notice_errno(u
, errno
, "Failed to open %s: %m", fragment
);
5502 if (fstat(fileno(f
), &st
) < 0)
5505 r
= free_and_strdup(&u
->fragment_path
, fragment
);
5509 if (null_or_empty(&st
)) {
5510 /* Unit file is masked */
5512 u
->load_state
= u
->perpetual
? UNIT_LOADED
: UNIT_MASKED
; /* don't allow perpetual units to ever be masked */
5513 u
->fragment_mtime
= 0;
5515 u
->load_state
= UNIT_LOADED
;
5516 u
->fragment_mtime
= timespec_load(&st
.st_mtim
);
5518 /* Now, parse the file contents */
5519 r
= config_parse(u
->id
, fragment
, f
,
5520 UNIT_VTABLE(u
)->sections
,
5521 config_item_perf_lookup
, load_fragment_gperf_lookup
,
5526 log_unit_notice_errno(u
, r
, "Unit configuration has fatal error, unit will not be started.");
5532 /* We do the merge dance here because for some unit types, the unit might have aliases which are not
5533 * declared in the file system. In particular, this is true (and frequent) for device and swap units.
5536 const char *id
= u
->id
;
5537 _cleanup_free_
char *free_id
= NULL
;
5540 id
= basename(fragment
);
5541 if (unit_name_is_valid(id
, UNIT_NAME_TEMPLATE
)) {
5542 assert(u
->instance
); /* If we're not trying to use a template for non-instanced unit,
5543 * this must be set. */
5545 r
= unit_name_replace_instance(id
, u
->instance
, &free_id
);
5547 return log_debug_errno(r
, "Failed to build id (%s + %s): %m", id
, u
->instance
);
5553 r
= merge_by_names(&merged
, names
, id
);
5558 u
->load_state
= UNIT_MERGED
;
5563 void unit_dump_config_items(FILE *f
) {
5564 static const struct {
5565 const ConfigParserCallback callback
;
5568 { config_parse_warn_compat
, "NOTSUPPORTED" },
5569 { config_parse_int
, "INTEGER" },
5570 { config_parse_unsigned
, "UNSIGNED" },
5571 { config_parse_iec_size
, "SIZE" },
5572 { config_parse_iec_uint64
, "SIZE" },
5573 { config_parse_si_uint64
, "SIZE" },
5574 { config_parse_bool
, "BOOLEAN" },
5575 { config_parse_string
, "STRING" },
5576 { config_parse_path
, "PATH" },
5577 { config_parse_unit_path_printf
, "PATH" },
5578 { config_parse_strv
, "STRING [...]" },
5579 { config_parse_exec_nice
, "NICE" },
5580 { config_parse_exec_oom_score_adjust
, "OOMSCOREADJUST" },
5581 { config_parse_exec_io_class
, "IOCLASS" },
5582 { config_parse_exec_io_priority
, "IOPRIORITY" },
5583 { config_parse_exec_cpu_sched_policy
, "CPUSCHEDPOLICY" },
5584 { config_parse_exec_cpu_sched_prio
, "CPUSCHEDPRIO" },
5585 { config_parse_exec_cpu_affinity
, "CPUAFFINITY" },
5586 { config_parse_mode
, "MODE" },
5587 { config_parse_unit_env_file
, "FILE" },
5588 { config_parse_exec_output
, "OUTPUT" },
5589 { config_parse_exec_input
, "INPUT" },
5590 { config_parse_log_facility
, "FACILITY" },
5591 { config_parse_log_level
, "LEVEL" },
5592 { config_parse_exec_secure_bits
, "SECUREBITS" },
5593 { config_parse_capability_set
, "BOUNDINGSET" },
5594 { config_parse_rlimit
, "LIMIT" },
5595 { config_parse_unit_deps
, "UNIT [...]" },
5596 { config_parse_exec
, "PATH [ARGUMENT [...]]" },
5597 { config_parse_service_type
, "SERVICETYPE" },
5598 { config_parse_service_restart
, "SERVICERESTART" },
5599 { config_parse_service_timeout_failure_mode
, "TIMEOUTMODE" },
5600 { config_parse_kill_mode
, "KILLMODE" },
5601 { config_parse_signal
, "SIGNAL" },
5602 { config_parse_socket_listen
, "SOCKET [...]" },
5603 { config_parse_socket_bind
, "SOCKETBIND" },
5604 { config_parse_socket_bindtodevice
, "NETWORKINTERFACE" },
5605 { config_parse_sec
, "SECONDS" },
5606 { config_parse_nsec
, "NANOSECONDS" },
5607 { config_parse_namespace_path_strv
, "PATH [...]" },
5608 { config_parse_bind_paths
, "PATH[:PATH[:OPTIONS]] [...]" },
5609 { config_parse_unit_requires_mounts_for
, "PATH [...]" },
5610 { config_parse_exec_mount_flags
, "MOUNTFLAG [...]" },
5611 { config_parse_unit_string_printf
, "STRING" },
5612 { config_parse_trigger_unit
, "UNIT" },
5613 { config_parse_timer
, "TIMER" },
5614 { config_parse_path_spec
, "PATH" },
5615 { config_parse_notify_access
, "ACCESS" },
5616 { config_parse_ip_tos
, "TOS" },
5617 { config_parse_unit_condition_path
, "CONDITION" },
5618 { config_parse_unit_condition_string
, "CONDITION" },
5619 { config_parse_unit_slice
, "SLICE" },
5620 { config_parse_documentation
, "URL" },
5621 { config_parse_service_timeout
, "SECONDS" },
5622 { config_parse_emergency_action
, "ACTION" },
5623 { config_parse_set_status
, "STATUS" },
5624 { config_parse_service_sockets
, "SOCKETS" },
5625 { config_parse_environ
, "ENVIRON" },
5627 { config_parse_syscall_filter
, "SYSCALLS" },
5628 { config_parse_syscall_archs
, "ARCHS" },
5629 { config_parse_syscall_errno
, "ERRNO" },
5630 { config_parse_syscall_log
, "SYSCALLS" },
5631 { config_parse_address_families
, "FAMILIES" },
5632 { config_parse_restrict_namespaces
, "NAMESPACES" },
5634 { config_parse_cpu_shares
, "SHARES" },
5635 { config_parse_cg_weight
, "WEIGHT" },
5636 { config_parse_memory_limit
, "LIMIT" },
5637 { config_parse_device_allow
, "DEVICE" },
5638 { config_parse_device_policy
, "POLICY" },
5639 { config_parse_io_limit
, "LIMIT" },
5640 { config_parse_io_device_weight
, "DEVICEWEIGHT" },
5641 { config_parse_io_device_latency
, "DEVICELATENCY" },
5642 { config_parse_blockio_bandwidth
, "BANDWIDTH" },
5643 { config_parse_blockio_weight
, "WEIGHT" },
5644 { config_parse_blockio_device_weight
, "DEVICEWEIGHT" },
5645 { config_parse_long
, "LONG" },
5646 { config_parse_socket_service
, "SERVICE" },
5648 { config_parse_exec_selinux_context
, "LABEL" },
5650 { config_parse_job_mode
, "MODE" },
5651 { config_parse_job_mode_isolate
, "BOOLEAN" },
5652 { config_parse_personality
, "PERSONALITY" },
5655 const char *prev
= NULL
;
5660 NULSTR_FOREACH(i
, load_fragment_gperf_nulstr
) {
5661 const char *rvalue
= "OTHER", *lvalue
;
5662 const ConfigPerfItem
*p
;
5665 assert_se(p
= load_fragment_gperf_lookup(i
, strlen(i
)));
5667 /* Hide legacy settings */
5668 if (p
->parse
== config_parse_warn_compat
&&
5669 p
->ltype
== DISABLED_LEGACY
)
5672 for (size_t j
= 0; j
< ELEMENTSOF(table
); j
++)
5673 if (p
->parse
== table
[j
].callback
) {
5674 rvalue
= table
[j
].rvalue
;
5678 dot
= strchr(i
, '.');
5679 lvalue
= dot
? dot
+ 1 : i
;
5682 size_t prefix_len
= dot
- i
;
5684 if (!prev
|| !strneq(prev
, i
, prefix_len
+1)) {
5688 fprintf(f
, "[%.*s]\n", (int) prefix_len
, i
);
5692 fprintf(f
, "%s=%s\n", lvalue
, rvalue
);
5697 int config_parse_cpu_affinity2(
5699 const char *filename
,
5701 const char *section
,
5702 unsigned section_line
,
5709 CPUSet
*affinity
= data
;
5713 (void) parse_cpu_set_extend(rvalue
, affinity
, true, unit
, filename
, line
, lvalue
);
5718 int config_parse_show_status(
5720 const char *filename
,
5722 const char *section
,
5723 unsigned section_line
,
5731 ShowStatus
*b
= data
;
5738 k
= parse_show_status(rvalue
, b
);
5740 log_syntax(unit
, LOG_WARNING
, filename
, line
, k
, "Failed to parse show status setting, ignoring: %s", rvalue
);
5745 int config_parse_output_restricted(
5747 const char *filename
,
5749 const char *section
,
5750 unsigned section_line
,
5757 ExecOutput t
, *eo
= data
;
5758 bool obsolete
= false;
5765 if (streq(rvalue
, "syslog")) {
5766 t
= EXEC_OUTPUT_JOURNAL
;
5768 } else if (streq(rvalue
, "syslog+console")) {
5769 t
= EXEC_OUTPUT_JOURNAL_AND_CONSOLE
;
5772 t
= exec_output_from_string(rvalue
);
5774 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Failed to parse output type, ignoring: %s", rvalue
);
5778 if (IN_SET(t
, EXEC_OUTPUT_SOCKET
, EXEC_OUTPUT_NAMED_FD
, EXEC_OUTPUT_FILE
, EXEC_OUTPUT_FILE_APPEND
, EXEC_OUTPUT_FILE_TRUNCATE
)) {
5779 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Standard output types socket, fd:, file:, append:, truncate: are not supported as defaults, ignoring: %s", rvalue
);
5785 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
5786 "Standard output type %s is obsolete, automatically updating to %s. Please update your configuration.",
5787 rvalue
, exec_output_to_string(t
));
5793 int config_parse_crash_chvt(
5795 const char *filename
,
5797 const char *section
,
5798 unsigned section_line
,
5812 r
= parse_crash_chvt(rvalue
, data
);
5814 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse CrashChangeVT= setting, ignoring: %s", rvalue
);
5819 int config_parse_swap_priority(
5821 const char *filename
,
5823 const char *section
,
5824 unsigned section_line
,
5840 if (isempty(rvalue
)) {
5841 s
->parameters_fragment
.priority
= -1;
5842 s
->parameters_fragment
.priority_set
= false;
5846 r
= safe_atoi(rvalue
, &priority
);
5848 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid swap priority '%s', ignoring.", rvalue
);
5852 if (priority
< -1) {
5853 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
);
5857 if (priority
> 32767) {
5858 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Swap priority out of range, ignoring: %s", rvalue
);
5862 s
->parameters_fragment
.priority
= priority
;
5863 s
->parameters_fragment
.priority_set
= true;