1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 Copyright © 2012 Holger Hans Peter Freyther
14 #include <sys/resource.h>
17 #include "alloc-util.h"
18 #include "all-units.h"
19 #include "bpf-firewall.h"
20 #include "bus-error.h"
21 #include "bus-internal.h"
24 #include "capability-util.h"
25 #include "cgroup-setup.h"
26 #include "conf-parser.h"
27 #include "cpu-set-util.h"
29 #include "errno-list.h"
33 #include "hexdecoct.h"
36 #include "ip-protocol-list.h"
37 #include "journal-util.h"
38 #include "limits-util.h"
39 #include "load-fragment.h"
41 #include "mountpoint-util.h"
42 #include "nulstr-util.h"
43 #include "parse-util.h"
44 #include "path-util.h"
45 #include "process-util.h"
47 #include "seccomp-util.h"
49 #include "securebits-util.h"
50 #include "signal-util.h"
51 #include "stat-util.h"
52 #include "string-util.h"
54 #include "unit-name.h"
55 #include "unit-printf.h"
56 #include "user-util.h"
57 #include "time-util.h"
60 static int parse_socket_protocol(const char *s
) {
63 r
= parse_ip_protocol(s
);
66 if (!IN_SET(r
, IPPROTO_UDPLITE
, IPPROTO_SCTP
))
67 return -EPROTONOSUPPORT
;
72 int parse_crash_chvt(const char *value
, int *data
) {
75 if (safe_atoi(value
, data
) >= 0)
78 b
= parse_boolean(value
);
83 *data
= 0; /* switch to where kmsg goes */
85 *data
= -1; /* turn off switching */
90 int parse_confirm_spawn(const char *value
, char **console
) {
94 r
= value
? parse_boolean(value
) : 1;
98 } else if (r
> 0) /* on with default tty */
99 s
= strdup("/dev/console");
100 else if (is_path(value
)) /* on with fully qualified path */
102 else /* on with only a tty file name, not a fully qualified path */
103 s
= path_join("/dev/", value
);
111 DEFINE_CONFIG_PARSE(config_parse_socket_protocol
, parse_socket_protocol
, "Failed to parse socket protocol");
112 DEFINE_CONFIG_PARSE(config_parse_exec_secure_bits
, secure_bits_from_string
, "Failed to parse secure bits");
113 DEFINE_CONFIG_PARSE_ENUM(config_parse_collect_mode
, collect_mode
, CollectMode
, "Failed to parse garbage collection mode");
114 DEFINE_CONFIG_PARSE_ENUM(config_parse_device_policy
, cgroup_device_policy
, CGroupDevicePolicy
, "Failed to parse device policy");
115 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_keyring_mode
, exec_keyring_mode
, ExecKeyringMode
, "Failed to parse keyring mode");
116 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_utmp_mode
, exec_utmp_mode
, ExecUtmpMode
, "Failed to parse utmp mode");
117 DEFINE_CONFIG_PARSE_ENUM(config_parse_job_mode
, job_mode
, JobMode
, "Failed to parse job mode");
118 DEFINE_CONFIG_PARSE_ENUM(config_parse_kill_mode
, kill_mode
, KillMode
, "Failed to parse kill mode");
119 DEFINE_CONFIG_PARSE_ENUM(config_parse_notify_access
, notify_access
, NotifyAccess
, "Failed to parse notify access specifier");
120 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_home
, protect_home
, ProtectHome
, "Failed to parse protect home value");
121 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_system
, protect_system
, ProtectSystem
, "Failed to parse protect system value");
122 DEFINE_CONFIG_PARSE_ENUM(config_parse_runtime_preserve_mode
, exec_preserve_mode
, ExecPreserveMode
, "Failed to parse runtime directory preserve mode");
123 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_type
, service_type
, ServiceType
, "Failed to parse service type");
124 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart
, service_restart
, ServiceRestart
, "Failed to parse service restart specifier");
125 DEFINE_CONFIG_PARSE_ENUM(config_parse_socket_bind
, socket_address_bind_ipv6_only_or_bool
, SocketAddressBindIPv6Only
, "Failed to parse bind IPv6 only value");
126 DEFINE_CONFIG_PARSE_ENUM(config_parse_oom_policy
, oom_policy
, OOMPolicy
, "Failed to parse OOM policy");
127 DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_ip_tos
, ip_tos
, int, -1, "Failed to parse IP TOS value");
128 DEFINE_CONFIG_PARSE_PTR(config_parse_blockio_weight
, cg_blkio_weight_parse
, uint64_t, "Invalid block IO weight");
129 DEFINE_CONFIG_PARSE_PTR(config_parse_cg_weight
, cg_weight_parse
, uint64_t, "Invalid weight");
130 DEFINE_CONFIG_PARSE_PTR(config_parse_cpu_shares
, cg_cpu_shares_parse
, uint64_t, "Invalid CPU shares");
131 DEFINE_CONFIG_PARSE_PTR(config_parse_exec_mount_flags
, mount_propagation_flags_from_string
, unsigned long, "Failed to parse mount flag");
132 DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_numa_policy
, mpol
, int, -1, "Invalid NUMA policy type");
133 DEFINE_CONFIG_PARSE_ENUM(config_parse_status_unit_format
, status_unit_format
, StatusUnitFormat
, "Failed to parse status unit format");
135 int config_parse_unit_deps(
137 const char *filename
,
140 unsigned section_line
,
147 UnitDependency d
= ltype
;
157 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
160 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_RETAIN_ESCAPE
);
166 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
170 r
= unit_name_printf(u
, word
, &k
);
172 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
176 r
= unit_add_dependency_by_name(u
, d
, k
, true, UNIT_DEPENDENCY_FILE
);
178 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
184 int config_parse_obsolete_unit_deps(
186 const char *filename
,
189 unsigned section_line
,
196 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
197 "Unit dependency type %s= is obsolete, replacing by %s=, please update your unit file", lvalue
, unit_dependency_to_string(ltype
));
199 return config_parse_unit_deps(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
);
202 int config_parse_unit_string_printf(
204 const char *filename
,
207 unsigned section_line
,
214 _cleanup_free_
char *k
= NULL
;
215 const Unit
*u
= userdata
;
223 r
= unit_full_printf(u
, rvalue
, &k
);
225 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
229 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
232 int config_parse_unit_strv_printf(
234 const char *filename
,
237 unsigned section_line
,
244 const Unit
*u
= userdata
;
245 _cleanup_free_
char *k
= NULL
;
253 r
= unit_full_printf(u
, rvalue
, &k
);
255 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
259 return config_parse_strv(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
262 int config_parse_unit_path_printf(
264 const char *filename
,
267 unsigned section_line
,
274 _cleanup_free_
char *k
= NULL
;
275 const Unit
*u
= userdata
;
284 /* Let's not bother with anything that is too long */
285 if (strlen(rvalue
) >= PATH_MAX
) {
286 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
287 "%s value too long%s.",
288 lvalue
, fatal
? "" : ", ignoring");
289 return fatal
? -ENAMETOOLONG
: 0;
292 r
= unit_full_printf(u
, rvalue
, &k
);
294 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
295 "Failed to resolve unit specifiers in '%s'%s: %m",
296 rvalue
, fatal
? "" : ", ignoring");
297 return fatal
? -ENOEXEC
: 0;
300 return config_parse_path(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
303 int config_parse_unit_path_strv_printf(
305 const char *filename
,
308 unsigned section_line
,
316 const Unit
*u
= userdata
;
325 if (isempty(rvalue
)) {
331 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
333 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
339 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
340 "Invalid syntax, ignoring: %s", rvalue
);
344 r
= unit_full_printf(u
, word
, &k
);
346 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
347 "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
351 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
355 r
= strv_consume(x
, TAKE_PTR(k
));
361 static int patch_var_run(
363 const char *filename
,
371 e
= path_startswith(*path
, "/var/run/");
375 z
= path_join("/run/", e
);
379 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
380 "%s= references a path below legacy directory /var/run/, updating %s → %s; "
381 "please update the unit file accordingly.", lvalue
, *path
, z
);
383 free_and_replace(*path
, z
);
388 int config_parse_socket_listen(
390 const char *filename
,
393 unsigned section_line
,
400 _cleanup_free_ SocketPort
*p
= NULL
;
412 if (isempty(rvalue
)) {
413 /* An empty assignment removes all ports */
414 socket_free_ports(s
);
418 p
= new0(SocketPort
, 1);
422 if (ltype
!= SOCKET_SOCKET
) {
423 _cleanup_free_
char *k
= NULL
;
425 r
= unit_full_printf(UNIT(s
), rvalue
, &k
);
427 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
431 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
435 if (ltype
== SOCKET_FIFO
) {
436 r
= patch_var_run(unit
, filename
, line
, lvalue
, &k
);
441 free_and_replace(p
->path
, k
);
444 } else if (streq(lvalue
, "ListenNetlink")) {
445 _cleanup_free_
char *k
= NULL
;
447 r
= unit_full_printf(UNIT(s
), rvalue
, &k
);
449 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
453 r
= socket_address_parse_netlink(&p
->address
, k
);
455 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse address value in '%s', ignoring: %m", k
);
459 p
->type
= SOCKET_SOCKET
;
462 _cleanup_free_
char *k
= NULL
;
464 r
= unit_full_printf(UNIT(s
), rvalue
, &k
);
466 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
470 if (k
[0] == '/') { /* Only for AF_UNIX file system sockets… */
471 r
= patch_var_run(unit
, filename
, line
, lvalue
, &k
);
476 r
= socket_address_parse_and_warn(&p
->address
, k
);
478 if (r
!= -EAFNOSUPPORT
)
479 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse address value in '%s', ignoring: %m", k
);
483 if (streq(lvalue
, "ListenStream"))
484 p
->address
.type
= SOCK_STREAM
;
485 else if (streq(lvalue
, "ListenDatagram"))
486 p
->address
.type
= SOCK_DGRAM
;
488 assert(streq(lvalue
, "ListenSequentialPacket"));
489 p
->address
.type
= SOCK_SEQPACKET
;
492 if (socket_address_family(&p
->address
) != AF_LOCAL
&& p
->address
.type
== SOCK_SEQPACKET
) {
493 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Address family not supported, ignoring: %s", rvalue
);
497 p
->type
= SOCKET_SOCKET
;
501 p
->auxiliary_fds
= NULL
;
502 p
->n_auxiliary_fds
= 0;
505 LIST_FIND_TAIL(port
, s
->ports
, tail
);
506 LIST_INSERT_AFTER(port
, s
->ports
, tail
, p
);
513 int config_parse_exec_nice(
515 const char *filename
,
518 unsigned section_line
,
525 ExecContext
*c
= data
;
533 if (isempty(rvalue
)) {
538 r
= parse_nice(rvalue
, &priority
);
541 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Nice priority out of range, ignoring: %s", rvalue
);
543 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse nice priority '%s', ignoring: %m", rvalue
);
553 int config_parse_exec_oom_score_adjust(
555 const char *filename
,
558 unsigned section_line
,
565 ExecContext
*c
= data
;
573 if (isempty(rvalue
)) {
574 c
->oom_score_adjust_set
= false;
578 r
= parse_oom_score_adjust(rvalue
, &oa
);
581 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "OOM score adjust value out of range, ignoring: %s", rvalue
);
583 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse the OOM score adjust value '%s', ignoring: %m", rvalue
);
587 c
->oom_score_adjust
= oa
;
588 c
->oom_score_adjust_set
= true;
593 int config_parse_exec(
595 const char *filename
,
598 unsigned section_line
,
605 ExecCommand
**e
= data
;
606 const Unit
*u
= userdata
;
618 if (isempty(rvalue
)) {
619 /* An empty assignment resets the list */
620 *e
= exec_command_free_list(*e
);
626 _cleanup_free_
char *path
= NULL
, *firstword
= NULL
;
627 ExecCommandFlags flags
= 0;
628 bool ignore
= false, separate_argv0
= false;
629 _cleanup_free_ ExecCommand
*nce
= NULL
;
630 _cleanup_strv_free_
char **n
= NULL
;
631 size_t nlen
= 0, nbufsize
= 0;
636 r
= extract_first_word_and_warn(&p
, &firstword
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
642 /* We accept an absolute path as first argument. If it's prefixed with - and the path doesn't
643 * exist, we ignore it instead of erroring out; if it's prefixed with @, we allow overriding of
644 * argv[0]; if it's prefixed with :, we will not do environment variable substitution;
645 * if it's prefixed with +, it will be run with full privileges and no sandboxing; if
646 * it's prefixed with '!' we apply sandboxing, but do not change user/group credentials; if
647 * it's prefixed with '!!', then we apply user/group credentials if the kernel supports ambient
648 * capabilities -- if it doesn't we don't apply the credentials themselves, but do apply most
649 * other sandboxing, with some special exceptions for changing UID.
651 * The idea is that '!!' may be used to write services that can take benefit of systemd's
652 * UID/GID dropping if the kernel supports ambient creds, but provide an automatic fallback to
653 * privilege dropping within the daemon if the kernel does not offer that. */
655 if (*f
== '-' && !(flags
& EXEC_COMMAND_IGNORE_FAILURE
)) {
656 flags
|= EXEC_COMMAND_IGNORE_FAILURE
;
658 } else if (*f
== '@' && !separate_argv0
)
659 separate_argv0
= true;
660 else if (*f
== ':' && !(flags
& EXEC_COMMAND_NO_ENV_EXPAND
))
661 flags
|= EXEC_COMMAND_NO_ENV_EXPAND
;
662 else if (*f
== '+' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
663 flags
|= EXEC_COMMAND_FULLY_PRIVILEGED
;
664 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
665 flags
|= EXEC_COMMAND_NO_SETUID
;
666 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_AMBIENT_MAGIC
))) {
667 flags
&= ~EXEC_COMMAND_NO_SETUID
;
668 flags
|= EXEC_COMMAND_AMBIENT_MAGIC
;
674 r
= unit_full_printf(u
, f
, &path
);
676 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
677 "Failed to resolve unit specifiers in '%s'%s: %m",
678 f
, ignore
? ", ignoring" : "");
679 return ignore
? 0 : -ENOEXEC
;
683 /* First word is either "-" or "@" with no command. */
684 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
685 "Empty path in command line%s: '%s'",
686 ignore
? ", ignoring" : "", rvalue
);
687 return ignore
? 0 : -ENOEXEC
;
689 if (!string_is_safe(path
)) {
690 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
691 "Executable name contains special characters%s: %s",
692 ignore
? ", ignoring" : "", path
);
693 return ignore
? 0 : -ENOEXEC
;
695 if (endswith(path
, "/")) {
696 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
697 "Executable path specifies a directory%s: %s",
698 ignore
? ", ignoring" : "", path
);
699 return ignore
? 0 : -ENOEXEC
;
702 if (!path_is_absolute(path
)) {
706 if (!filename_is_valid(path
)) {
707 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
708 "Neither a valid executable name nor an absolute path%s: %s",
709 ignore
? ", ignoring" : "", path
);
710 return ignore
? 0 : -ENOEXEC
;
713 /* Resolve a single-component name to a full path */
714 NULSTR_FOREACH(prefix
, DEFAULT_PATH_NULSTR
) {
715 _cleanup_free_
char *fullpath
= NULL
;
717 fullpath
= path_join(prefix
, path
);
721 if (access(fullpath
, F_OK
) >= 0) {
722 free_and_replace(path
, fullpath
);
729 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
730 "Executable \"%s\" not found in path \"%s\"%s",
731 path
, DEFAULT_PATH
, ignore
? ", ignoring" : "");
732 return ignore
? 0 : -ENOEXEC
;
736 if (!separate_argv0
) {
739 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
749 path_simplify(path
, false);
751 while (!isempty(p
)) {
752 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
754 /* Check explicitly for an unquoted semicolon as
755 * command separator token. */
756 if (p
[0] == ';' && (!p
[1] || strchr(WHITESPACE
, p
[1]))) {
758 p
+= strspn(p
, WHITESPACE
);
763 /* Check for \; explicitly, to not confuse it with \\; or "\;" or "\\;" etc.
764 * extract_first_word() would return the same for all of those. */
765 if (p
[0] == '\\' && p
[1] == ';' && (!p
[2] || strchr(WHITESPACE
, p
[2]))) {
769 p
+= strspn(p
, WHITESPACE
);
771 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
782 r
= extract_first_word_and_warn(&p
, &word
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
786 return ignore
? 0 : -ENOEXEC
;
788 r
= unit_full_printf(u
, word
, &resolved
);
790 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
791 "Failed to resolve unit specifiers in %s%s: %m",
792 word
, ignore
? ", ignoring" : "");
793 return ignore
? 0 : -ENOEXEC
;
796 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
799 n
[nlen
++] = TAKE_PTR(resolved
);
804 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
805 "Empty executable name or zeroeth argument%s: %s",
806 ignore
? ", ignoring" : "", rvalue
);
807 return ignore
? 0 : -ENOEXEC
;
810 nce
= new0(ExecCommand
, 1);
814 nce
->argv
= TAKE_PTR(n
);
815 nce
->path
= TAKE_PTR(path
);
818 exec_command_append_list(e
, nce
);
820 /* Do not _cleanup_free_ these. */
829 int config_parse_socket_bindtodevice(
831 const char *filename
,
834 unsigned section_line
,
848 if (isempty(rvalue
) || streq(rvalue
, "*")) {
849 s
->bind_to_device
= mfree(s
->bind_to_device
);
853 if (!ifname_valid(rvalue
)) {
854 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid interface name, ignoring: %s", rvalue
);
858 if (free_and_strdup(&s
->bind_to_device
, rvalue
) < 0)
864 int config_parse_exec_input(
866 const char *filename
,
869 unsigned section_line
,
876 ExecContext
*c
= data
;
877 const Unit
*u
= userdata
;
887 n
= startswith(rvalue
, "fd:");
889 _cleanup_free_
char *resolved
= NULL
;
891 r
= unit_full_printf(u
, n
, &resolved
);
893 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s': %m", n
);
895 if (isempty(resolved
))
896 resolved
= mfree(resolved
);
897 else if (!fdname_is_valid(resolved
)) {
898 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name: %s", resolved
);
902 free_and_replace(c
->stdio_fdname
[STDIN_FILENO
], resolved
);
904 ei
= EXEC_INPUT_NAMED_FD
;
906 } else if ((n
= startswith(rvalue
, "file:"))) {
907 _cleanup_free_
char *resolved
= NULL
;
909 r
= unit_full_printf(u
, n
, &resolved
);
911 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s': %m", n
);
913 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
917 free_and_replace(c
->stdio_file
[STDIN_FILENO
], resolved
);
919 ei
= EXEC_INPUT_FILE
;
922 ei
= exec_input_from_string(rvalue
);
924 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse input specifier, ignoring: %s", rvalue
);
933 int config_parse_exec_input_text(
935 const char *filename
,
938 unsigned section_line
,
945 _cleanup_free_
char *unescaped
= NULL
, *resolved
= NULL
;
946 ExecContext
*c
= data
;
947 const Unit
*u
= userdata
;
957 if (isempty(rvalue
)) {
958 /* Reset if the empty string is assigned */
959 c
->stdin_data
= mfree(c
->stdin_data
);
960 c
->stdin_data_size
= 0;
964 r
= cunescape(rvalue
, 0, &unescaped
);
966 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to decode C escaped text '%s': %m", rvalue
);
968 r
= unit_full_printf(u
, unescaped
, &resolved
);
970 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s': %m", unescaped
);
972 sz
= strlen(resolved
);
973 if (c
->stdin_data_size
+ sz
+ 1 < c
->stdin_data_size
|| /* check for overflow */
974 c
->stdin_data_size
+ sz
+ 1 > EXEC_STDIN_DATA_MAX
) {
975 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Standard input data too large (%zu), maximum of %zu permitted, ignoring.", c
->stdin_data_size
+ sz
, (size_t) EXEC_STDIN_DATA_MAX
);
979 p
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
+ 1);
983 *((char*) mempcpy((char*) p
+ c
->stdin_data_size
, resolved
, sz
)) = '\n';
986 c
->stdin_data_size
+= sz
+ 1;
991 int config_parse_exec_input_data(
993 const char *filename
,
996 unsigned section_line
,
1003 _cleanup_free_
void *p
= NULL
;
1004 ExecContext
*c
= data
;
1014 if (isempty(rvalue
)) {
1015 /* Reset if the empty string is assigned */
1016 c
->stdin_data
= mfree(c
->stdin_data
);
1017 c
->stdin_data_size
= 0;
1021 r
= unbase64mem(rvalue
, (size_t) -1, &p
, &sz
);
1023 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to decode base64 data, ignoring: %s", rvalue
);
1027 if (c
->stdin_data_size
+ sz
< c
->stdin_data_size
|| /* check for overflow */
1028 c
->stdin_data_size
+ sz
> EXEC_STDIN_DATA_MAX
) {
1029 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Standard input data too large (%zu), maximum of %zu permitted, ignoring.", c
->stdin_data_size
+ sz
, (size_t) EXEC_STDIN_DATA_MAX
);
1033 q
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
);
1037 memcpy((uint8_t*) q
+ c
->stdin_data_size
, p
, sz
);
1040 c
->stdin_data_size
+= sz
;
1045 int config_parse_exec_output(
1047 const char *filename
,
1049 const char *section
,
1050 unsigned section_line
,
1057 _cleanup_free_
char *resolved
= NULL
;
1059 ExecContext
*c
= data
;
1060 const Unit
*u
= userdata
;
1070 n
= startswith(rvalue
, "fd:");
1072 r
= unit_full_printf(u
, n
, &resolved
);
1074 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", n
);
1076 if (isempty(resolved
))
1077 resolved
= mfree(resolved
);
1078 else if (!fdname_is_valid(resolved
)) {
1079 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name: %s", resolved
);
1083 eo
= EXEC_OUTPUT_NAMED_FD
;
1085 } else if ((n
= startswith(rvalue
, "file:"))) {
1087 r
= unit_full_printf(u
, n
, &resolved
);
1089 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", n
);
1091 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1095 eo
= EXEC_OUTPUT_FILE
;
1097 } else if ((n
= startswith(rvalue
, "append:"))) {
1099 r
= unit_full_printf(u
, n
, &resolved
);
1101 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", n
);
1103 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1107 eo
= EXEC_OUTPUT_FILE_APPEND
;
1109 eo
= exec_output_from_string(rvalue
);
1111 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse output specifier, ignoring: %s", rvalue
);
1116 if (streq(lvalue
, "StandardOutput")) {
1117 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1118 free_and_replace(c
->stdio_fdname
[STDOUT_FILENO
], resolved
);
1120 free_and_replace(c
->stdio_file
[STDOUT_FILENO
], resolved
);
1125 assert(streq(lvalue
, "StandardError"));
1127 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1128 free_and_replace(c
->stdio_fdname
[STDERR_FILENO
], resolved
);
1130 free_and_replace(c
->stdio_file
[STDERR_FILENO
], resolved
);
1138 int config_parse_exec_io_class(const char *unit
,
1139 const char *filename
,
1141 const char *section
,
1142 unsigned section_line
,
1149 ExecContext
*c
= data
;
1157 if (isempty(rvalue
)) {
1158 c
->ioprio_set
= false;
1159 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE
, 0);
1163 x
= ioprio_class_from_string(rvalue
);
1165 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse IO scheduling class, ignoring: %s", rvalue
);
1169 c
->ioprio
= IOPRIO_PRIO_VALUE(x
, IOPRIO_PRIO_DATA(c
->ioprio
));
1170 c
->ioprio_set
= true;
1175 int config_parse_exec_io_priority(const char *unit
,
1176 const char *filename
,
1178 const char *section
,
1179 unsigned section_line
,
1186 ExecContext
*c
= data
;
1194 if (isempty(rvalue
)) {
1195 c
->ioprio_set
= false;
1196 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE
, 0);
1200 r
= ioprio_parse_priority(rvalue
, &i
);
1202 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse IO priority, ignoring: %s", rvalue
);
1206 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_PRIO_CLASS(c
->ioprio
), i
);
1207 c
->ioprio_set
= true;
1212 int config_parse_exec_cpu_sched_policy(const char *unit
,
1213 const char *filename
,
1215 const char *section
,
1216 unsigned section_line
,
1223 ExecContext
*c
= data
;
1231 if (isempty(rvalue
)) {
1232 c
->cpu_sched_set
= false;
1233 c
->cpu_sched_policy
= SCHED_OTHER
;
1234 c
->cpu_sched_priority
= 0;
1238 x
= sched_policy_from_string(rvalue
);
1240 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse CPU scheduling policy, ignoring: %s", rvalue
);
1244 c
->cpu_sched_policy
= x
;
1245 /* Moving to or from real-time policy? We need to adjust the priority */
1246 c
->cpu_sched_priority
= CLAMP(c
->cpu_sched_priority
, sched_get_priority_min(x
), sched_get_priority_max(x
));
1247 c
->cpu_sched_set
= true;
1252 int config_parse_numa_mask(const char *unit
,
1253 const char *filename
,
1255 const char *section
,
1256 unsigned section_line
,
1263 NUMAPolicy
*p
= data
;
1270 r
= parse_cpu_set_extend(rvalue
, &p
->nodes
, true, unit
, filename
, line
, lvalue
);
1272 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse NUMA node mask, ignoring: %s", rvalue
);
1279 int config_parse_exec_cpu_sched_prio(const char *unit
,
1280 const char *filename
,
1282 const char *section
,
1283 unsigned section_line
,
1290 ExecContext
*c
= data
;
1298 r
= safe_atoi(rvalue
, &i
);
1300 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse CPU scheduling priority, ignoring: %s", rvalue
);
1304 /* On Linux RR/FIFO range from 1 to 99 and OTHER/BATCH may only be 0 */
1305 min
= sched_get_priority_min(c
->cpu_sched_policy
);
1306 max
= sched_get_priority_max(c
->cpu_sched_policy
);
1308 if (i
< min
|| i
> max
) {
1309 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "CPU scheduling priority is out of range, ignoring: %s", rvalue
);
1313 c
->cpu_sched_priority
= i
;
1314 c
->cpu_sched_set
= true;
1319 int config_parse_exec_cpu_affinity(const char *unit
,
1320 const char *filename
,
1322 const char *section
,
1323 unsigned section_line
,
1330 ExecContext
*c
= data
;
1337 return parse_cpu_set_extend(rvalue
, &c
->cpu_set
, true, unit
, filename
, line
, lvalue
);
1340 int config_parse_capability_set(
1342 const char *filename
,
1344 const char *section
,
1345 unsigned section_line
,
1352 uint64_t *capability_set
= data
;
1353 uint64_t sum
= 0, initial
= 0;
1354 bool invert
= false;
1362 if (rvalue
[0] == '~') {
1367 if (streq(lvalue
, "CapabilityBoundingSet"))
1368 initial
= CAP_ALL
; /* initialized to all bits on */
1369 /* else "AmbientCapabilities" initialized to all bits off */
1371 r
= capability_set_from_string(rvalue
, &sum
);
1373 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= specifier '%s', ignoring: %m", lvalue
, rvalue
);
1377 if (sum
== 0 || *capability_set
== initial
)
1378 /* "", "~" or uninitialized data -> replace */
1379 *capability_set
= invert
? ~sum
: sum
;
1381 /* previous data -> merge */
1383 *capability_set
&= ~sum
;
1385 *capability_set
|= sum
;
1391 int config_parse_exec_selinux_context(
1393 const char *filename
,
1395 const char *section
,
1396 unsigned section_line
,
1403 ExecContext
*c
= data
;
1404 const Unit
*u
= userdata
;
1414 if (isempty(rvalue
)) {
1415 c
->selinux_context
= mfree(c
->selinux_context
);
1416 c
->selinux_context_ignore
= false;
1420 if (rvalue
[0] == '-') {
1426 r
= unit_full_printf(u
, rvalue
, &k
);
1428 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1429 "Failed to resolve unit specifiers in '%s'%s: %m",
1430 rvalue
, ignore
? ", ignoring" : "");
1431 return ignore
? 0 : -ENOEXEC
;
1434 free_and_replace(c
->selinux_context
, k
);
1435 c
->selinux_context_ignore
= ignore
;
1440 int config_parse_exec_apparmor_profile(
1442 const char *filename
,
1444 const char *section
,
1445 unsigned section_line
,
1452 ExecContext
*c
= data
;
1453 const Unit
*u
= userdata
;
1463 if (isempty(rvalue
)) {
1464 c
->apparmor_profile
= mfree(c
->apparmor_profile
);
1465 c
->apparmor_profile_ignore
= false;
1469 if (rvalue
[0] == '-') {
1475 r
= unit_full_printf(u
, rvalue
, &k
);
1477 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1478 "Failed to resolve unit specifiers in '%s'%s: %m",
1479 rvalue
, ignore
? ", ignoring" : "");
1480 return ignore
? 0 : -ENOEXEC
;
1483 free_and_replace(c
->apparmor_profile
, k
);
1484 c
->apparmor_profile_ignore
= ignore
;
1489 int config_parse_exec_smack_process_label(
1491 const char *filename
,
1493 const char *section
,
1494 unsigned section_line
,
1501 ExecContext
*c
= data
;
1502 const Unit
*u
= userdata
;
1512 if (isempty(rvalue
)) {
1513 c
->smack_process_label
= mfree(c
->smack_process_label
);
1514 c
->smack_process_label_ignore
= false;
1518 if (rvalue
[0] == '-') {
1524 r
= unit_full_printf(u
, rvalue
, &k
);
1526 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1527 "Failed to resolve unit specifiers in '%s'%s: %m",
1528 rvalue
, ignore
? ", ignoring" : "");
1529 return ignore
? 0 : -ENOEXEC
;
1532 free_and_replace(c
->smack_process_label
, k
);
1533 c
->smack_process_label_ignore
= ignore
;
1538 int config_parse_timer(
1540 const char *filename
,
1542 const char *section
,
1543 unsigned section_line
,
1550 _cleanup_(calendar_spec_freep
) CalendarSpec
*c
= NULL
;
1551 _cleanup_free_
char *k
= NULL
;
1552 const Unit
*u
= userdata
;
1563 if (isempty(rvalue
)) {
1564 /* Empty assignment resets list */
1565 timer_free_values(t
);
1569 r
= unit_full_printf(u
, rvalue
, &k
);
1571 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
1575 if (ltype
== TIMER_CALENDAR
) {
1576 r
= calendar_spec_from_string(k
, &c
);
1578 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse calendar specification, ignoring: %s", k
);
1582 r
= parse_sec(k
, &usec
);
1584 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse timer value, ignoring: %s", k
);
1589 v
= new(TimerValue
, 1);
1596 .calendar_spec
= TAKE_PTR(c
),
1599 LIST_PREPEND(value
, t
->values
, v
);
1604 int config_parse_trigger_unit(
1606 const char *filename
,
1608 const char *section
,
1609 unsigned section_line
,
1616 _cleanup_free_
char *p
= NULL
;
1626 if (!hashmap_isempty(u
->dependencies
[UNIT_TRIGGERS
])) {
1627 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Multiple units to trigger specified, ignoring: %s", rvalue
);
1631 r
= unit_name_printf(u
, rvalue
, &p
);
1633 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
1637 type
= unit_name_to_type(p
);
1639 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit type not valid, ignoring: %s", rvalue
);
1642 if (unit_has_name(u
, p
)) {
1643 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Units cannot trigger themselves, ignoring: %s", rvalue
);
1647 r
= unit_add_two_dependencies_by_name(u
, UNIT_BEFORE
, UNIT_TRIGGERS
, p
, true, UNIT_DEPENDENCY_FILE
);
1649 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add trigger on %s, ignoring: %m", p
);
1656 int config_parse_path_spec(const char *unit
,
1657 const char *filename
,
1659 const char *section
,
1660 unsigned section_line
,
1670 _cleanup_free_
char *k
= NULL
;
1678 if (isempty(rvalue
)) {
1679 /* Empty assignment clears list */
1684 b
= path_type_from_string(lvalue
);
1686 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse path type, ignoring: %s", lvalue
);
1690 r
= unit_full_printf(UNIT(p
), rvalue
, &k
);
1692 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
1696 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
1700 s
= new0(PathSpec
, 1);
1705 s
->path
= TAKE_PTR(k
);
1709 LIST_PREPEND(spec
, p
->specs
, s
);
1714 int config_parse_socket_service(
1716 const char *filename
,
1718 const char *section
,
1719 unsigned section_line
,
1726 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1727 _cleanup_free_
char *p
= NULL
;
1737 r
= unit_name_printf(UNIT(s
), rvalue
, &p
);
1739 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", rvalue
);
1743 if (!endswith(p
, ".service")) {
1744 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit must be of type service: %s", rvalue
);
1748 r
= manager_load_unit(UNIT(s
)->manager
, p
, NULL
, &error
, &x
);
1750 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to load unit %s: %s", rvalue
, bus_error_message(&error
, r
));
1754 unit_ref_set(&s
->service
, UNIT(s
), x
);
1759 int config_parse_fdname(
1761 const char *filename
,
1763 const char *section
,
1764 unsigned section_line
,
1771 _cleanup_free_
char *p
= NULL
;
1780 if (isempty(rvalue
)) {
1781 s
->fdname
= mfree(s
->fdname
);
1785 r
= unit_full_printf(UNIT(s
), rvalue
, &p
);
1787 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
1791 if (!fdname_is_valid(p
)) {
1792 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", p
);
1796 return free_and_replace(s
->fdname
, p
);
1799 int config_parse_service_sockets(
1801 const char *filename
,
1803 const char *section
,
1804 unsigned section_line
,
1822 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
1824 r
= extract_first_word(&p
, &word
, NULL
, 0);
1830 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Trailing garbage in sockets, ignoring: %s", rvalue
);
1834 r
= unit_name_printf(UNIT(s
), word
, &k
);
1836 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
1840 if (!endswith(k
, ".socket")) {
1841 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit must be of type socket, ignoring: %s", k
);
1845 r
= unit_add_two_dependencies_by_name(UNIT(s
), UNIT_WANTS
, UNIT_AFTER
, k
, true, UNIT_DEPENDENCY_FILE
);
1847 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
1849 r
= unit_add_dependency_by_name(UNIT(s
), UNIT_TRIGGERED_BY
, k
, true, UNIT_DEPENDENCY_FILE
);
1851 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
1857 int config_parse_bus_name(
1859 const char *filename
,
1861 const char *section
,
1862 unsigned section_line
,
1869 _cleanup_free_
char *k
= NULL
;
1870 const Unit
*u
= userdata
;
1878 r
= unit_full_printf(u
, rvalue
, &k
);
1880 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
1884 if (!service_name_is_valid(k
)) {
1885 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid bus name, ignoring: %s", k
);
1889 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
1892 int config_parse_service_timeout(
1894 const char *filename
,
1896 const char *section
,
1897 unsigned section_line
,
1904 Service
*s
= userdata
;
1913 /* This is called for two cases: TimeoutSec= and TimeoutStartSec=. */
1915 /* Traditionally, these options accepted 0 to disable the timeouts. However, a timeout of 0 suggests it happens
1916 * immediately, hence fix this to become USEC_INFINITY instead. This is in-line with how we internally handle
1917 * all other timeouts. */
1918 r
= parse_sec_fix_0(rvalue
, &usec
);
1920 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
1924 s
->start_timeout_defined
= true;
1925 s
->timeout_start_usec
= usec
;
1927 if (streq(lvalue
, "TimeoutSec"))
1928 s
->timeout_stop_usec
= usec
;
1933 int config_parse_timeout_abort(
1935 const char *filename
,
1937 const char *section
,
1938 unsigned section_line
,
1953 /* Note: apart from setting the arg, this returns an extra bit of information in the return value. */
1955 if (isempty(rvalue
)) {
1957 return 0; /* "not set" */
1960 r
= parse_sec(rvalue
, ret
);
1962 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= setting, ignoring: %s", lvalue
, rvalue
);
1964 return 1; /* "set" */
1967 int config_parse_service_timeout_abort(
1969 const char *filename
,
1971 const char *section
,
1972 unsigned section_line
,
1979 Service
*s
= userdata
;
1984 r
= config_parse_timeout_abort(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
,
1985 &s
->timeout_abort_usec
, s
);
1987 s
->timeout_abort_set
= r
;
1991 int config_parse_sec_fix_0(
1993 const char *filename
,
1995 const char *section
,
1996 unsigned section_line
,
2003 usec_t
*usec
= data
;
2011 /* This is pretty much like config_parse_sec(), except that this treats a time of 0 as infinity, for
2012 * compatibility with older versions of systemd where 0 instead of infinity was used as indicator to turn off a
2015 r
= parse_sec_fix_0(rvalue
, usec
);
2017 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
2024 int config_parse_user_group_compat(
2026 const char *filename
,
2028 const char *section
,
2029 unsigned section_line
,
2036 _cleanup_free_
char *k
= NULL
;
2038 const Unit
*u
= userdata
;
2046 if (isempty(rvalue
)) {
2047 *user
= mfree(*user
);
2051 r
= unit_full_printf(u
, rvalue
, &k
);
2053 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", rvalue
);
2057 if (!valid_user_group_name_or_id_compat(k
)) {
2058 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2062 return free_and_replace(*user
, k
);
2065 int config_parse_user_group_strv_compat(
2067 const char *filename
,
2069 const char *section
,
2070 unsigned section_line
,
2077 char ***users
= data
;
2078 const Unit
*u
= userdata
;
2079 const char *p
= rvalue
;
2087 if (isempty(rvalue
)) {
2088 *users
= strv_free(*users
);
2093 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2095 r
= extract_first_word(&p
, &word
, NULL
, 0);
2101 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax: %s", rvalue
);
2105 r
= unit_full_printf(u
, word
, &k
);
2107 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", word
);
2111 if (!valid_user_group_name_or_id_compat(k
)) {
2112 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2116 r
= strv_push(users
, k
);
2126 int config_parse_working_directory(
2128 const char *filename
,
2130 const char *section
,
2131 unsigned section_line
,
2138 ExecContext
*c
= data
;
2139 const Unit
*u
= userdata
;
2149 if (isempty(rvalue
)) {
2150 c
->working_directory_home
= false;
2151 c
->working_directory
= mfree(c
->working_directory
);
2155 if (rvalue
[0] == '-') {
2161 if (streq(rvalue
, "~")) {
2162 c
->working_directory_home
= true;
2163 c
->working_directory
= mfree(c
->working_directory
);
2165 _cleanup_free_
char *k
= NULL
;
2167 r
= unit_full_printf(u
, rvalue
, &k
);
2169 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2170 "Failed to resolve unit specifiers in working directory path '%s'%s: %m",
2171 rvalue
, missing_ok
? ", ignoring" : "");
2172 return missing_ok
? 0 : -ENOEXEC
;
2175 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
| (missing_ok
? 0 : PATH_CHECK_FATAL
), unit
, filename
, line
, lvalue
);
2177 return missing_ok
? 0 : -ENOEXEC
;
2179 c
->working_directory_home
= false;
2180 free_and_replace(c
->working_directory
, k
);
2183 c
->working_directory_missing_ok
= missing_ok
;
2187 int config_parse_unit_env_file(const char *unit
,
2188 const char *filename
,
2190 const char *section
,
2191 unsigned section_line
,
2199 const Unit
*u
= userdata
;
2200 _cleanup_free_
char *n
= NULL
;
2208 if (isempty(rvalue
)) {
2209 /* Empty assignment frees the list */
2210 *env
= strv_free(*env
);
2214 r
= unit_full_printf(u
, rvalue
, &n
);
2216 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2220 r
= path_simplify_and_warn(n
[0] == '-' ? n
+ 1 : n
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2224 r
= strv_push(env
, n
);
2233 int config_parse_environ(
2235 const char *filename
,
2237 const char *section
,
2238 unsigned section_line
,
2245 const Unit
*u
= userdata
;
2255 if (isempty(rvalue
)) {
2256 /* Empty assignment resets the list */
2257 *env
= strv_free(*env
);
2261 for (p
= rvalue
;; ) {
2262 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2264 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2270 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2271 "Invalid syntax, ignoring: %s", rvalue
);
2276 r
= unit_full_printf(u
, word
, &k
);
2278 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2279 "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2285 if (!env_assignment_is_valid(k
)) {
2286 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2287 "Invalid environment assignment, ignoring: %s", k
);
2291 r
= strv_env_replace(env
, k
);
2299 int config_parse_pass_environ(
2301 const char *filename
,
2303 const char *section
,
2304 unsigned section_line
,
2311 _cleanup_strv_free_
char **n
= NULL
;
2312 size_t nlen
= 0, nbufsize
= 0;
2313 char*** passenv
= data
;
2314 const char *p
= rvalue
;
2315 const Unit
*u
= userdata
;
2323 if (isempty(rvalue
)) {
2324 /* Empty assignment resets the list */
2325 *passenv
= strv_free(*passenv
);
2330 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2332 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
2338 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2339 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2344 r
= unit_full_printf(u
, word
, &k
);
2346 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2347 "Failed to resolve specifiers in %s, ignoring: %m", word
);
2353 if (!env_name_is_valid(k
)) {
2354 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2355 "Invalid environment name for %s, ignoring: %s", lvalue
, k
);
2359 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
2362 n
[nlen
++] = TAKE_PTR(k
);
2367 r
= strv_extend_strv(passenv
, n
, true);
2375 int config_parse_unset_environ(
2377 const char *filename
,
2379 const char *section
,
2380 unsigned section_line
,
2387 _cleanup_strv_free_
char **n
= NULL
;
2388 size_t nlen
= 0, nbufsize
= 0;
2389 char*** unsetenv
= data
;
2390 const char *p
= rvalue
;
2391 const Unit
*u
= userdata
;
2399 if (isempty(rvalue
)) {
2400 /* Empty assignment resets the list */
2401 *unsetenv
= strv_free(*unsetenv
);
2406 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2408 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2414 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2415 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2420 r
= unit_full_printf(u
, word
, &k
);
2422 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2423 "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2429 if (!env_assignment_is_valid(k
) && !env_name_is_valid(k
)) {
2430 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2431 "Invalid environment name or assignment %s, ignoring: %s", lvalue
, k
);
2435 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
2438 n
[nlen
++] = TAKE_PTR(k
);
2443 r
= strv_extend_strv(unsetenv
, n
, true);
2451 int config_parse_log_extra_fields(
2453 const char *filename
,
2455 const char *section
,
2456 unsigned section_line
,
2463 ExecContext
*c
= data
;
2464 const Unit
*u
= userdata
;
2465 const char *p
= rvalue
;
2473 if (isempty(rvalue
)) {
2474 exec_context_free_log_extra_fields(c
);
2479 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2483 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2489 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
2493 r
= unit_full_printf(u
, word
, &k
);
2495 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2499 eq
= strchr(k
, '=');
2501 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Log field lacks '=' character, ignoring: %s", k
);
2505 if (!journal_field_valid(k
, eq
-k
, false)) {
2506 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Log field name is invalid, ignoring: %s", k
);
2510 t
= reallocarray(c
->log_extra_fields
, c
->n_log_extra_fields
+1, sizeof(struct iovec
));
2514 c
->log_extra_fields
= t
;
2515 c
->log_extra_fields
[c
->n_log_extra_fields
++] = IOVEC_MAKE_STRING(k
);
2521 int config_parse_unit_condition_path(
2523 const char *filename
,
2525 const char *section
,
2526 unsigned section_line
,
2533 _cleanup_free_
char *p
= NULL
;
2534 Condition
**list
= data
, *c
;
2535 ConditionType t
= ltype
;
2536 bool trigger
, negate
;
2537 const Unit
*u
= userdata
;
2545 if (isempty(rvalue
)) {
2546 /* Empty assignment resets the list */
2547 *list
= condition_free_list(*list
);
2551 trigger
= rvalue
[0] == '|';
2555 negate
= rvalue
[0] == '!';
2559 r
= unit_full_printf(u
, rvalue
, &p
);
2561 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2565 r
= path_simplify_and_warn(p
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2569 c
= condition_new(t
, p
, trigger
, negate
);
2573 LIST_PREPEND(conditions
, *list
, c
);
2577 int config_parse_unit_condition_string(
2579 const char *filename
,
2581 const char *section
,
2582 unsigned section_line
,
2589 _cleanup_free_
char *s
= NULL
;
2590 Condition
**list
= data
, *c
;
2591 ConditionType t
= ltype
;
2592 bool trigger
, negate
;
2593 const Unit
*u
= userdata
;
2601 if (isempty(rvalue
)) {
2602 /* Empty assignment resets the list */
2603 *list
= condition_free_list(*list
);
2607 trigger
= *rvalue
== '|';
2609 rvalue
+= 1 + strspn(rvalue
+ 1, WHITESPACE
);
2611 negate
= *rvalue
== '!';
2613 rvalue
+= 1 + strspn(rvalue
+ 1, WHITESPACE
);
2615 r
= unit_full_printf(u
, rvalue
, &s
);
2617 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2618 "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2622 c
= condition_new(t
, s
, trigger
, negate
);
2626 LIST_PREPEND(conditions
, *list
, c
);
2630 int config_parse_unit_condition_null(
2632 const char *filename
,
2634 const char *section
,
2635 unsigned section_line
,
2642 Condition
**list
= data
, *c
;
2643 bool trigger
, negate
;
2651 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "%s= is deprecated, please do not use.", lvalue
);
2653 if (isempty(rvalue
)) {
2654 /* Empty assignment resets the list */
2655 *list
= condition_free_list(*list
);
2659 trigger
= rvalue
[0] == '|';
2663 negate
= rvalue
[0] == '!';
2667 b
= parse_boolean(rvalue
);
2669 log_syntax(unit
, LOG_ERR
, filename
, line
, b
, "Failed to parse boolean value in condition, ignoring: %s", rvalue
);
2676 c
= condition_new(CONDITION_NULL
, NULL
, trigger
, negate
);
2680 LIST_PREPEND(conditions
, *list
, c
);
2684 int config_parse_unit_requires_mounts_for(
2686 const char *filename
,
2688 const char *section
,
2689 unsigned section_line
,
2696 const char *p
= rvalue
;
2706 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
2708 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
2714 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2715 "Invalid syntax, ignoring: %s", rvalue
);
2719 r
= unit_full_printf(u
, word
, &resolved
);
2721 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
2725 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2729 r
= unit_require_mounts_for(u
, resolved
, UNIT_DEPENDENCY_FILE
);
2731 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add required mount '%s', ignoring: %m", resolved
);
2737 int config_parse_documentation(const char *unit
,
2738 const char *filename
,
2740 const char *section
,
2741 unsigned section_line
,
2757 if (isempty(rvalue
)) {
2758 /* Empty assignment resets the list */
2759 u
->documentation
= strv_free(u
->documentation
);
2763 r
= config_parse_unit_strv_printf(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
,
2764 rvalue
, data
, userdata
);
2768 for (a
= b
= u
->documentation
; a
&& *a
; a
++) {
2770 if (documentation_url_is_valid(*a
))
2773 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid URL, ignoring: %s", *a
);
2784 int config_parse_syscall_filter(
2786 const char *filename
,
2788 const char *section
,
2789 unsigned section_line
,
2796 ExecContext
*c
= data
;
2797 const Unit
*u
= userdata
;
2798 bool invert
= false;
2807 if (isempty(rvalue
)) {
2808 /* Empty assignment resets the list */
2809 c
->syscall_filter
= hashmap_free(c
->syscall_filter
);
2810 c
->syscall_whitelist
= false;
2814 if (rvalue
[0] == '~') {
2819 if (!c
->syscall_filter
) {
2820 c
->syscall_filter
= hashmap_new(NULL
);
2821 if (!c
->syscall_filter
)
2825 /* Allow everything but the ones listed */
2826 c
->syscall_whitelist
= false;
2828 /* Allow nothing but the ones listed */
2829 c
->syscall_whitelist
= true;
2831 /* Accept default syscalls if we are on a whitelist */
2832 r
= seccomp_parse_syscall_filter(
2833 "@default", -1, c
->syscall_filter
,
2834 SECCOMP_PARSE_PERMISSIVE
|SECCOMP_PARSE_WHITELIST
,
2844 _cleanup_free_
char *word
= NULL
, *name
= NULL
;
2847 r
= extract_first_word(&p
, &word
, NULL
, 0);
2853 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
2857 r
= parse_syscall_and_errno(word
, &name
, &num
);
2859 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse syscall:errno, ignoring: %s", word
);
2863 r
= seccomp_parse_syscall_filter(
2864 name
, num
, c
->syscall_filter
,
2865 SECCOMP_PARSE_LOG
|SECCOMP_PARSE_PERMISSIVE
|
2866 (invert
? SECCOMP_PARSE_INVERT
: 0)|
2867 (c
->syscall_whitelist
? SECCOMP_PARSE_WHITELIST
: 0),
2868 unit
, filename
, line
);
2874 int config_parse_syscall_archs(
2876 const char *filename
,
2878 const char *section
,
2879 unsigned section_line
,
2886 const char *p
= rvalue
;
2890 if (isempty(rvalue
)) {
2891 *archs
= set_free(*archs
);
2895 r
= set_ensure_allocated(archs
, NULL
);
2900 _cleanup_free_
char *word
= NULL
;
2903 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
2909 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2910 "Invalid syntax, ignoring: %s", rvalue
);
2914 r
= seccomp_arch_from_string(word
, &a
);
2916 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2917 "Failed to parse system call architecture \"%s\", ignoring: %m", word
);
2921 r
= set_put(*archs
, UINT32_TO_PTR(a
+ 1));
2927 int config_parse_syscall_errno(
2929 const char *filename
,
2931 const char *section
,
2932 unsigned section_line
,
2939 ExecContext
*c
= data
;
2946 if (isempty(rvalue
)) {
2947 /* Empty assignment resets to KILL */
2948 c
->syscall_errno
= 0;
2952 e
= parse_errno(rvalue
);
2954 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse error number, ignoring: %s", rvalue
);
2958 c
->syscall_errno
= e
;
2962 int config_parse_address_families(
2964 const char *filename
,
2966 const char *section
,
2967 unsigned section_line
,
2974 ExecContext
*c
= data
;
2975 bool invert
= false;
2983 if (isempty(rvalue
)) {
2984 /* Empty assignment resets the list */
2985 c
->address_families
= set_free(c
->address_families
);
2986 c
->address_families_whitelist
= false;
2990 if (rvalue
[0] == '~') {
2995 if (!c
->address_families
) {
2996 c
->address_families
= set_new(NULL
);
2997 if (!c
->address_families
)
3000 c
->address_families_whitelist
= !invert
;
3003 for (p
= rvalue
;;) {
3004 _cleanup_free_
char *word
= NULL
;
3007 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3013 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3014 "Invalid syntax, ignoring: %s", rvalue
);
3018 af
= af_from_name(word
);
3020 log_syntax(unit
, LOG_ERR
, filename
, line
, af
,
3021 "Failed to parse address family, ignoring: %s", word
);
3025 /* If we previously wanted to forbid an address family and now
3026 * we want to allow it, then just remove it from the list.
3028 if (!invert
== c
->address_families_whitelist
) {
3029 r
= set_put(c
->address_families
, INT_TO_PTR(af
));
3033 set_remove(c
->address_families
, INT_TO_PTR(af
));
3037 int config_parse_restrict_namespaces(
3039 const char *filename
,
3041 const char *section
,
3042 unsigned section_line
,
3049 ExecContext
*c
= data
;
3050 unsigned long flags
;
3051 bool invert
= false;
3054 if (isempty(rvalue
)) {
3055 /* Reset to the default. */
3056 c
->restrict_namespaces
= NAMESPACE_FLAGS_INITIAL
;
3060 /* Boolean parameter ignores the previous settings */
3061 r
= parse_boolean(rvalue
);
3063 c
->restrict_namespaces
= 0;
3065 } else if (r
== 0) {
3066 c
->restrict_namespaces
= NAMESPACE_FLAGS_ALL
;
3070 if (rvalue
[0] == '~') {
3075 /* Not a boolean argument, in this case it's a list of namespace types. */
3076 r
= namespace_flags_from_string(rvalue
, &flags
);
3078 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse namespace type string, ignoring: %s", rvalue
);
3082 if (c
->restrict_namespaces
== NAMESPACE_FLAGS_INITIAL
)
3083 /* Initial assignment. Just set the value. */
3084 c
->restrict_namespaces
= invert
? (~flags
) & NAMESPACE_FLAGS_ALL
: flags
;
3086 /* Merge the value with the previous one. */
3087 SET_FLAG(c
->restrict_namespaces
, flags
, !invert
);
3093 int config_parse_unit_slice(
3095 const char *filename
,
3097 const char *section
,
3098 unsigned section_line
,
3105 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
3106 _cleanup_free_
char *k
= NULL
;
3107 Unit
*u
= userdata
, *slice
;
3115 r
= unit_name_printf(u
, rvalue
, &k
);
3117 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
3121 r
= manager_load_unit(u
->manager
, k
, NULL
, &error
, &slice
);
3123 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to load slice unit %s, ignoring: %s", k
, bus_error_message(&error
, r
));
3127 r
= unit_set_slice(u
, slice
);
3129 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to assign slice %s to unit %s, ignoring: %m", slice
->id
, u
->id
);
3136 int config_parse_cpu_quota(
3138 const char *filename
,
3140 const char *section
,
3141 unsigned section_line
,
3148 CGroupContext
*c
= data
;
3155 if (isempty(rvalue
)) {
3156 c
->cpu_quota_per_sec_usec
= USEC_INFINITY
;
3160 r
= parse_permille_unbounded(rvalue
);
3162 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid CPU quota '%s', ignoring.", rvalue
);
3166 c
->cpu_quota_per_sec_usec
= ((usec_t
) r
* USEC_PER_SEC
) / 1000U;
3170 int config_parse_allowed_cpus(
3172 const char *filename
,
3174 const char *section
,
3175 unsigned section_line
,
3182 CGroupContext
*c
= data
;
3184 (void) parse_cpu_set_extend(rvalue
, &c
->cpuset_cpus
, true, unit
, filename
, line
, lvalue
);
3189 int config_parse_allowed_mems(
3191 const char *filename
,
3193 const char *section
,
3194 unsigned section_line
,
3201 CGroupContext
*c
= data
;
3203 (void) parse_cpu_set_extend(rvalue
, &c
->cpuset_mems
, true, unit
, filename
, line
, lvalue
);
3208 int config_parse_memory_limit(
3210 const char *filename
,
3212 const char *section
,
3213 unsigned section_line
,
3220 CGroupContext
*c
= data
;
3221 uint64_t bytes
= CGROUP_LIMIT_MAX
;
3224 if (!isempty(rvalue
) && !streq(rvalue
, "infinity")) {
3226 r
= parse_permille(rvalue
);
3228 r
= parse_size(rvalue
, 1024, &bytes
);
3230 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid memory limit '%s', ignoring: %m", rvalue
);
3234 bytes
= physical_memory_scale(r
, 1000U);
3236 if (bytes
>= UINT64_MAX
||
3237 (bytes
<= 0 && !STR_IN_SET(lvalue
, "MemorySwapMax", "MemoryLow", "MemoryMin", "DefaultMemoryLow", "DefaultMemoryMin"))) {
3238 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Memory limit '%s' out of range, ignoring.", rvalue
);
3243 if (streq(lvalue
, "DefaultMemoryLow")) {
3244 c
->default_memory_low_set
= true;
3245 if (isempty(rvalue
))
3246 c
->default_memory_low
= CGROUP_LIMIT_MIN
;
3248 c
->default_memory_low
= bytes
;
3249 } else if (streq(lvalue
, "DefaultMemoryMin")) {
3250 c
->default_memory_min_set
= true;
3251 if (isempty(rvalue
))
3252 c
->default_memory_min
= CGROUP_LIMIT_MIN
;
3254 c
->default_memory_min
= bytes
;
3255 } else if (streq(lvalue
, "MemoryMin")) {
3256 c
->memory_min
= bytes
;
3257 c
->memory_min_set
= true;
3258 } else if (streq(lvalue
, "MemoryLow")) {
3259 c
->memory_low
= bytes
;
3260 c
->memory_low_set
= true;
3261 } else if (streq(lvalue
, "MemoryHigh"))
3262 c
->memory_high
= bytes
;
3263 else if (streq(lvalue
, "MemoryMax"))
3264 c
->memory_max
= bytes
;
3265 else if (streq(lvalue
, "MemorySwapMax"))
3266 c
->memory_swap_max
= bytes
;
3267 else if (streq(lvalue
, "MemoryLimit"))
3268 c
->memory_limit
= bytes
;
3275 int config_parse_tasks_max(
3277 const char *filename
,
3279 const char *section
,
3280 unsigned section_line
,
3287 const Unit
*u
= userdata
;
3288 TasksMax
*tasks_max
= data
;
3292 if (isempty(rvalue
)) {
3293 *tasks_max
= u
? u
->manager
->default_tasks_max
: TASKS_MAX_UNSET
;
3297 if (streq(rvalue
, "infinity")) {
3298 *tasks_max
= TASKS_MAX_UNSET
;
3302 r
= parse_permille(rvalue
);
3304 *tasks_max
= (TasksMax
) { r
, 1000U }; /* r‰ */
3306 r
= safe_atou64(rvalue
, &v
);
3308 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid maximum tasks value '%s', ignoring: %m", rvalue
);
3312 if (v
<= 0 || v
>= UINT64_MAX
) {
3313 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Maximum tasks value '%s' out of range, ignoring.", rvalue
);
3317 *tasks_max
= (TasksMax
) { v
};
3323 int config_parse_delegate(
3325 const char *filename
,
3327 const char *section
,
3328 unsigned section_line
,
3335 CGroupContext
*c
= data
;
3339 t
= unit_name_to_type(unit
);
3340 assert(t
!= _UNIT_TYPE_INVALID
);
3342 if (!unit_vtable
[t
]->can_delegate
) {
3343 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Delegate= setting not supported for this unit type, ignoring.");
3347 /* We either accept a boolean value, which may be used to turn on delegation for all controllers, or turn it
3348 * off for all. Or it takes a list of controller names, in which case we add the specified controllers to the
3349 * mask to delegate. */
3351 if (isempty(rvalue
)) {
3352 /* An empty string resets controllers and set Delegate=yes. */
3354 c
->delegate_controllers
= 0;
3358 r
= parse_boolean(rvalue
);
3360 const char *p
= rvalue
;
3361 CGroupMask mask
= 0;
3364 _cleanup_free_
char *word
= NULL
;
3365 CGroupController cc
;
3367 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3373 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3377 cc
= cgroup_controller_from_string(word
);
3379 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid controller name '%s', ignoring", word
);
3383 mask
|= CGROUP_CONTROLLER_TO_MASK(cc
);
3387 c
->delegate_controllers
|= mask
;
3391 c
->delegate_controllers
= _CGROUP_MASK_ALL
;
3393 c
->delegate
= false;
3394 c
->delegate_controllers
= 0;
3400 int config_parse_device_allow(
3402 const char *filename
,
3404 const char *section
,
3405 unsigned section_line
,
3412 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3413 CGroupContext
*c
= data
;
3414 const char *p
= rvalue
;
3417 if (isempty(rvalue
)) {
3418 while (c
->device_allow
)
3419 cgroup_context_free_device_allow(c
, c
->device_allow
);
3424 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3428 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3429 "Invalid syntax, ignoring: %s", rvalue
);
3433 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3434 "Failed to extract device path and rights from '%s', ignoring.", rvalue
);
3438 r
= unit_full_printf(userdata
, path
, &resolved
);
3440 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3441 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3445 if (!STARTSWITH_SET(resolved
, "block-", "char-")) {
3447 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3451 if (!valid_device_node_path(resolved
)) {
3452 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device node path '%s', ignoring.", resolved
);
3457 if (!isempty(p
) && !in_charset(p
, "rwm")) {
3458 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device rights '%s', ignoring.", p
);
3462 return cgroup_add_device_allow(c
, resolved
, p
);
3465 int config_parse_io_device_weight(
3467 const char *filename
,
3469 const char *section
,
3470 unsigned section_line
,
3477 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3478 CGroupIODeviceWeight
*w
;
3479 CGroupContext
*c
= data
;
3480 const char *p
= rvalue
;
3488 if (isempty(rvalue
)) {
3489 while (c
->io_device_weights
)
3490 cgroup_context_free_io_device_weight(c
, c
->io_device_weights
);
3495 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3499 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3500 "Invalid syntax, ignoring: %s", rvalue
);
3503 if (r
== 0 || isempty(p
)) {
3504 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3505 "Failed to extract device path and weight from '%s', ignoring.", rvalue
);
3509 r
= unit_full_printf(userdata
, path
, &resolved
);
3511 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3512 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3516 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3520 r
= cg_weight_parse(p
, &u
);
3522 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "IO weight '%s' invalid, ignoring: %m", p
);
3526 assert(u
!= CGROUP_WEIGHT_INVALID
);
3528 w
= new0(CGroupIODeviceWeight
, 1);
3532 w
->path
= TAKE_PTR(resolved
);
3535 LIST_PREPEND(device_weights
, c
->io_device_weights
, w
);
3539 int config_parse_io_device_latency(
3541 const char *filename
,
3543 const char *section
,
3544 unsigned section_line
,
3551 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3552 CGroupIODeviceLatency
*l
;
3553 CGroupContext
*c
= data
;
3554 const char *p
= rvalue
;
3562 if (isempty(rvalue
)) {
3563 while (c
->io_device_latencies
)
3564 cgroup_context_free_io_device_latency(c
, c
->io_device_latencies
);
3569 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3573 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3574 "Invalid syntax, ignoring: %s", rvalue
);
3577 if (r
== 0 || isempty(p
)) {
3578 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3579 "Failed to extract device path and latency from '%s', ignoring.", rvalue
);
3583 r
= unit_full_printf(userdata
, path
, &resolved
);
3585 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3586 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3590 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3594 if (parse_sec(p
, &usec
) < 0) {
3595 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse timer value, ignoring: %s", p
);
3599 l
= new0(CGroupIODeviceLatency
, 1);
3603 l
->path
= TAKE_PTR(resolved
);
3604 l
->target_usec
= usec
;
3606 LIST_PREPEND(device_latencies
, c
->io_device_latencies
, l
);
3610 int config_parse_io_limit(
3612 const char *filename
,
3614 const char *section
,
3615 unsigned section_line
,
3622 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3623 CGroupIODeviceLimit
*l
= NULL
, *t
;
3624 CGroupContext
*c
= data
;
3625 CGroupIOLimitType type
;
3626 const char *p
= rvalue
;
3634 type
= cgroup_io_limit_type_from_string(lvalue
);
3637 if (isempty(rvalue
)) {
3638 LIST_FOREACH(device_limits
, l
, c
->io_device_limits
)
3639 l
->limits
[type
] = cgroup_io_limit_defaults
[type
];
3643 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3647 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3648 "Invalid syntax, ignoring: %s", rvalue
);
3651 if (r
== 0 || isempty(p
)) {
3652 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3653 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
3657 r
= unit_full_printf(userdata
, path
, &resolved
);
3659 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3660 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3664 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3668 if (streq("infinity", p
))
3669 num
= CGROUP_LIMIT_MAX
;
3671 r
= parse_size(p
, 1000, &num
);
3672 if (r
< 0 || num
<= 0) {
3673 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid IO limit '%s', ignoring.", p
);
3678 LIST_FOREACH(device_limits
, t
, c
->io_device_limits
) {
3679 if (path_equal(resolved
, t
->path
)) {
3686 CGroupIOLimitType ttype
;
3688 l
= new0(CGroupIODeviceLimit
, 1);
3692 l
->path
= TAKE_PTR(resolved
);
3693 for (ttype
= 0; ttype
< _CGROUP_IO_LIMIT_TYPE_MAX
; ttype
++)
3694 l
->limits
[ttype
] = cgroup_io_limit_defaults
[ttype
];
3696 LIST_PREPEND(device_limits
, c
->io_device_limits
, l
);
3699 l
->limits
[type
] = num
;
3704 int config_parse_blockio_device_weight(
3706 const char *filename
,
3708 const char *section
,
3709 unsigned section_line
,
3716 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3717 CGroupBlockIODeviceWeight
*w
;
3718 CGroupContext
*c
= data
;
3719 const char *p
= rvalue
;
3727 if (isempty(rvalue
)) {
3728 while (c
->blockio_device_weights
)
3729 cgroup_context_free_blockio_device_weight(c
, c
->blockio_device_weights
);
3734 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3738 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3739 "Invalid syntax, ignoring: %s", rvalue
);
3742 if (r
== 0 || isempty(p
)) {
3743 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3744 "Failed to extract device node and weight from '%s', ignoring.", rvalue
);
3748 r
= unit_full_printf(userdata
, path
, &resolved
);
3750 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3751 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3755 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3759 r
= cg_blkio_weight_parse(p
, &u
);
3761 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid block IO weight '%s', ignoring: %m", p
);
3765 assert(u
!= CGROUP_BLKIO_WEIGHT_INVALID
);
3767 w
= new0(CGroupBlockIODeviceWeight
, 1);
3771 w
->path
= TAKE_PTR(resolved
);
3774 LIST_PREPEND(device_weights
, c
->blockio_device_weights
, w
);
3778 int config_parse_blockio_bandwidth(
3780 const char *filename
,
3782 const char *section
,
3783 unsigned section_line
,
3790 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3791 CGroupBlockIODeviceBandwidth
*b
= NULL
, *t
;
3792 CGroupContext
*c
= data
;
3793 const char *p
= rvalue
;
3802 read
= streq("BlockIOReadBandwidth", lvalue
);
3804 if (isempty(rvalue
)) {
3805 LIST_FOREACH(device_bandwidths
, b
, c
->blockio_device_bandwidths
) {
3806 b
->rbps
= CGROUP_LIMIT_MAX
;
3807 b
->wbps
= CGROUP_LIMIT_MAX
;
3812 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3816 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3817 "Invalid syntax, ignoring: %s", rvalue
);
3820 if (r
== 0 || isempty(p
)) {
3821 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3822 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
3826 r
= unit_full_printf(userdata
, path
, &resolved
);
3828 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3829 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3833 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3837 r
= parse_size(p
, 1000, &bytes
);
3838 if (r
< 0 || bytes
<= 0) {
3839 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid Block IO Bandwidth '%s', ignoring.", p
);
3843 LIST_FOREACH(device_bandwidths
, t
, c
->blockio_device_bandwidths
) {
3844 if (path_equal(resolved
, t
->path
)) {
3851 b
= new0(CGroupBlockIODeviceBandwidth
, 1);
3855 b
->path
= TAKE_PTR(resolved
);
3856 b
->rbps
= CGROUP_LIMIT_MAX
;
3857 b
->wbps
= CGROUP_LIMIT_MAX
;
3859 LIST_PREPEND(device_bandwidths
, c
->blockio_device_bandwidths
, b
);
3870 int config_parse_job_mode_isolate(
3872 const char *filename
,
3874 const char *section
,
3875 unsigned section_line
,
3889 r
= parse_boolean(rvalue
);
3891 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse boolean, ignoring: %s", rvalue
);
3895 log_notice("%s is deprecated. Please use OnFailureJobMode= instead", lvalue
);
3897 *m
= r
? JOB_ISOLATE
: JOB_REPLACE
;
3901 int config_parse_exec_directories(
3903 const char *filename
,
3905 const char *section
,
3906 unsigned section_line
,
3914 const Unit
*u
= userdata
;
3923 if (isempty(rvalue
)) {
3924 /* Empty assignment resets the list */
3925 *rt
= strv_free(*rt
);
3929 for (p
= rvalue
;;) {
3930 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
3932 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3936 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3937 "Invalid syntax, ignoring: %s", rvalue
);
3943 r
= unit_full_printf(u
, word
, &k
);
3945 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
3946 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
3950 r
= path_simplify_and_warn(k
, PATH_CHECK_RELATIVE
, unit
, filename
, line
, lvalue
);
3954 if (path_startswith(k
, "private")) {
3955 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
3956 "%s= path can't be 'private', ignoring assignment: %s", lvalue
, word
);
3960 r
= strv_push(rt
, k
);
3967 int config_parse_set_status(
3969 const char *filename
,
3971 const char *section
,
3972 unsigned section_line
,
3980 const char *word
, *state
;
3982 ExitStatusSet
*status_set
= data
;
3989 /* Empty assignment resets the list */
3990 if (isempty(rvalue
)) {
3991 exit_status_set_free(status_set
);
3995 FOREACH_WORD(word
, l
, rvalue
, state
) {
3996 _cleanup_free_
char *temp
;
3999 temp
= strndup(word
, l
);
4003 /* We need to call exit_status_from_string() first, because we want
4004 * to parse numbers as exit statuses, not signals. */
4006 r
= exit_status_from_string(temp
);
4008 assert(r
>= 0 && r
< 256);
4009 bitmap
= &status_set
->status
;
4011 r
= signal_from_string(temp
);
4014 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
4015 "Failed to parse value, ignoring: %s", word
);
4018 bitmap
= &status_set
->signal
;
4021 r
= bitmap_set(bitmap
, r
);
4023 return log_error_errno(r
, "Failed to set signal or status %s: %m", word
);
4025 if (!isempty(state
))
4026 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Trailing garbage, ignoring.");
4031 int config_parse_namespace_path_strv(
4033 const char *filename
,
4035 const char *section
,
4036 unsigned section_line
,
4043 const Unit
*u
= userdata
;
4045 const char *p
= rvalue
;
4053 if (isempty(rvalue
)) {
4054 /* Empty assignment resets the list */
4055 *sv
= strv_free(*sv
);
4060 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
, *joined
= NULL
;
4062 bool ignore_enoent
= false, shall_prefix
= false;
4064 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
4070 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
4075 if (startswith(w
, "-")) {
4076 ignore_enoent
= true;
4079 if (startswith(w
, "+")) {
4080 shall_prefix
= true;
4084 r
= unit_full_printf(u
, w
, &resolved
);
4086 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", w
);
4090 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4094 joined
= strjoin(ignore_enoent
? "-" : "",
4095 shall_prefix
? "+" : "",
4098 r
= strv_push(sv
, joined
);
4108 int config_parse_temporary_filesystems(
4110 const char *filename
,
4112 const char *section
,
4113 unsigned section_line
,
4120 const Unit
*u
= userdata
;
4121 ExecContext
*c
= data
;
4122 const char *p
= rvalue
;
4130 if (isempty(rvalue
)) {
4131 /* Empty assignment resets the list */
4132 temporary_filesystem_free_many(c
->temporary_filesystems
, c
->n_temporary_filesystems
);
4133 c
->temporary_filesystems
= NULL
;
4134 c
->n_temporary_filesystems
= 0;
4139 _cleanup_free_
char *word
= NULL
, *path
= NULL
, *resolved
= NULL
;
4142 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
4148 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
4153 r
= extract_first_word(&w
, &path
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4157 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", word
);
4161 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid syntax, ignoring: %s", word
);
4165 r
= unit_full_printf(u
, path
, &resolved
);
4167 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", path
);
4171 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4175 r
= temporary_filesystem_add(&c
->temporary_filesystems
, &c
->n_temporary_filesystems
, resolved
, w
);
4181 int config_parse_bind_paths(
4183 const char *filename
,
4185 const char *section
,
4186 unsigned section_line
,
4193 ExecContext
*c
= data
;
4194 const Unit
*u
= userdata
;
4203 if (isempty(rvalue
)) {
4204 /* Empty assignment resets the list */
4205 bind_mount_free_many(c
->bind_mounts
, c
->n_bind_mounts
);
4206 c
->bind_mounts
= NULL
;
4207 c
->n_bind_mounts
= 0;
4213 _cleanup_free_
char *source
= NULL
, *destination
= NULL
;
4214 _cleanup_free_
char *sresolved
= NULL
, *dresolved
= NULL
;
4215 char *s
= NULL
, *d
= NULL
;
4216 bool rbind
= true, ignore_enoent
= false;
4218 r
= extract_first_word(&p
, &source
, ":" WHITESPACE
, EXTRACT_UNQUOTE
|EXTRACT_DONT_COALESCE_SEPARATORS
);
4224 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
4228 r
= unit_full_printf(u
, source
, &sresolved
);
4230 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4231 "Failed to resolved unit specifiers in \"%s\", ignoring: %m", source
);
4237 ignore_enoent
= true;
4241 r
= path_simplify_and_warn(s
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4245 /* Optionally, the destination is specified. */
4246 if (p
&& p
[-1] == ':') {
4247 r
= extract_first_word(&p
, &destination
, ":" WHITESPACE
, EXTRACT_UNQUOTE
|EXTRACT_DONT_COALESCE_SEPARATORS
);
4251 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
4255 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Missing argument after ':', ignoring: %s", s
);
4259 r
= unit_full_printf(u
, destination
, &dresolved
);
4261 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4262 "Failed to resolved specifiers in \"%s\", ignoring: %m", destination
);
4266 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4272 /* Optionally, there's also a short option string specified */
4273 if (p
&& p
[-1] == ':') {
4274 _cleanup_free_
char *options
= NULL
;
4276 r
= extract_first_word(&p
, &options
, NULL
, EXTRACT_UNQUOTE
);
4280 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s: %s", lvalue
, rvalue
);
4284 if (isempty(options
) || streq(options
, "rbind"))
4286 else if (streq(options
, "norbind"))
4289 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid option string, ignoring setting: %s", options
);
4296 r
= bind_mount_add(&c
->bind_mounts
, &c
->n_bind_mounts
,
4300 .read_only
= !!strstr(lvalue
, "ReadOnly"),
4302 .ignore_enoent
= ignore_enoent
,
4311 int config_parse_job_timeout_sec(
4313 const char *filename
,
4315 const char *section
,
4316 unsigned section_line
,
4332 r
= parse_sec_fix_0(rvalue
, &usec
);
4334 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse JobTimeoutSec= parameter, ignoring: %s", rvalue
);
4338 /* If the user explicitly changed JobTimeoutSec= also change JobRunningTimeoutSec=, for compatibility with old
4339 * versions. If JobRunningTimeoutSec= was explicitly set, avoid this however as whatever the user picked should
4342 if (!u
->job_running_timeout_set
)
4343 u
->job_running_timeout
= usec
;
4345 u
->job_timeout
= usec
;
4350 int config_parse_job_running_timeout_sec(
4352 const char *filename
,
4354 const char *section
,
4355 unsigned section_line
,
4371 r
= parse_sec_fix_0(rvalue
, &usec
);
4373 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse JobRunningTimeoutSec= parameter, ignoring: %s", rvalue
);
4377 u
->job_running_timeout
= usec
;
4378 u
->job_running_timeout_set
= true;
4383 int config_parse_emergency_action(
4385 const char *filename
,
4387 const char *section
,
4388 unsigned section_line
,
4396 EmergencyAction
*x
= data
;
4405 m
= ((Unit
*) userdata
)->manager
;
4409 r
= parse_emergency_action(rvalue
, MANAGER_IS_SYSTEM(m
), x
);
4411 if (r
== -EOPNOTSUPP
&& MANAGER_IS_USER(m
)) {
4412 /* Compat mode: remove for systemd 241. */
4414 log_syntax(unit
, LOG_INFO
, filename
, line
, r
,
4415 "%s= in user mode specified as \"%s\", using \"exit-force\" instead.",
4417 *x
= EMERGENCY_ACTION_EXIT_FORCE
;
4421 if (r
== -EOPNOTSUPP
)
4422 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4423 "%s= specified as %s mode action, ignoring: %s",
4424 lvalue
, MANAGER_IS_SYSTEM(m
) ? "user" : "system", rvalue
);
4426 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4427 "Failed to parse %s=, ignoring: %s", lvalue
, rvalue
);
4434 int config_parse_pid_file(
4436 const char *filename
,
4438 const char *section
,
4439 unsigned section_line
,
4446 _cleanup_free_
char *k
= NULL
, *n
= NULL
;
4447 const Unit
*u
= userdata
;
4456 if (isempty(rvalue
)) {
4457 /* An empty assignment removes already set value. */
4462 r
= unit_full_printf(u
, rvalue
, &k
);
4464 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
4468 /* If this is a relative path make it absolute by prefixing the /run */
4469 n
= path_make_absolute(k
, u
->manager
->prefix
[EXEC_DIRECTORY_RUNTIME
]);
4473 /* Check that the result is a sensible path */
4474 r
= path_simplify_and_warn(n
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4478 r
= patch_var_run(unit
, filename
, line
, lvalue
, &n
);
4482 free_and_replace(*s
, n
);
4486 int config_parse_exit_status(
4488 const char *filename
,
4490 const char *section
,
4491 unsigned section_line
,
4498 int *exit_status
= data
, r
;
4504 assert(exit_status
);
4506 if (isempty(rvalue
)) {
4511 r
= safe_atou8(rvalue
, &u
);
4513 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse exit status '%s', ignoring: %m", rvalue
);
4521 int config_parse_disable_controllers(
4523 const char *filename
,
4525 const char *section
,
4526 unsigned section_line
,
4534 CGroupContext
*c
= data
;
4535 CGroupMask disabled_mask
;
4537 /* 1. If empty, make all controllers eligible for use again.
4538 * 2. If non-empty, merge all listed controllers, space separated. */
4540 if (isempty(rvalue
)) {
4541 c
->disable_controllers
= 0;
4545 r
= cg_mask_from_string(rvalue
, &disabled_mask
);
4546 if (r
< 0 || disabled_mask
<= 0) {
4547 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid cgroup string: %s, ignoring", rvalue
);
4551 c
->disable_controllers
|= disabled_mask
;
4556 int config_parse_ip_filter_bpf_progs(
4558 const char *filename
,
4560 const char *section
,
4561 unsigned section_line
,
4568 _cleanup_free_
char *resolved
= NULL
;
4569 const Unit
*u
= userdata
;
4570 char ***paths
= data
;
4578 if (isempty(rvalue
)) {
4579 *paths
= strv_free(*paths
);
4583 r
= unit_full_printf(u
, rvalue
, &resolved
);
4585 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
4589 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4593 if (strv_contains(*paths
, resolved
))
4596 r
= strv_extend(paths
, resolved
);
4600 r
= bpf_firewall_supported();
4603 if (r
!= BPF_FIREWALL_SUPPORTED_WITH_MULTI
) {
4604 static bool warned
= false;
4606 log_full(warned
? LOG_DEBUG
: LOG_WARNING
,
4607 "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"
4608 "Starting this unit will fail! (This warning is only shown for the first loaded unit using IP firewalling.)", filename
, line
, lvalue
, rvalue
);
4616 static int merge_by_names(Unit
**u
, Set
*names
, const char *id
) {
4623 /* Let's try to add in all names that are aliases of this unit */
4624 while ((k
= set_steal_first(names
))) {
4625 _cleanup_free_ _unused_
char *free_k
= k
;
4627 /* First try to merge in the other name into our unit */
4628 r
= unit_merge_by_name(*u
, k
);
4632 /* Hmm, we couldn't merge the other unit into ours? Then let's try it the other way
4635 other
= manager_get_unit((*u
)->manager
, k
);
4637 return r
; /* return previous failure */
4639 r
= unit_merge(other
, *u
);
4644 return merge_by_names(u
, names
, NULL
);
4647 if (streq_ptr(id
, k
))
4648 unit_choose_id(*u
, id
);
4654 int unit_load_fragment(Unit
*u
) {
4655 const char *fragment
;
4656 _cleanup_set_free_free_ Set
*names
= NULL
;
4661 assert(u
->load_state
== UNIT_STUB
);
4665 u
->load_state
= UNIT_LOADED
;
4669 /* Possibly rebuild the fragment map to catch new units */
4670 r
= unit_file_build_name_map(&u
->manager
->lookup_paths
,
4671 &u
->manager
->unit_cache_mtime
,
4672 &u
->manager
->unit_id_map
,
4673 &u
->manager
->unit_name_map
,
4674 &u
->manager
->unit_path_cache
);
4676 log_error_errno(r
, "Failed to rebuild name map: %m");
4678 r
= unit_file_find_fragment(u
->manager
->unit_id_map
,
4679 u
->manager
->unit_name_map
,
4683 if (r
< 0 && r
!= -ENOENT
)
4687 /* Open the file, check if this is a mask, otherwise read. */
4688 _cleanup_fclose_
FILE *f
= NULL
;
4690 /* Try to open the file name. A symlink is OK, for example for linked files or masks. We
4691 * expect that all symlinks within the lookup paths have been already resolved, but we don't
4692 * verify this here. */
4693 f
= fopen(fragment
, "re");
4695 return log_unit_notice_errno(u
, errno
, "Failed to open %s: %m", fragment
);
4697 if (fstat(fileno(f
), &st
) < 0)
4700 r
= free_and_strdup(&u
->fragment_path
, fragment
);
4704 if (null_or_empty(&st
)) {
4705 u
->load_state
= UNIT_MASKED
;
4706 u
->fragment_mtime
= 0;
4708 u
->load_state
= UNIT_LOADED
;
4709 u
->fragment_mtime
= timespec_load(&st
.st_mtim
);
4711 /* Now, parse the file contents */
4712 r
= config_parse(u
->id
, fragment
, f
,
4713 UNIT_VTABLE(u
)->sections
,
4714 config_item_perf_lookup
, load_fragment_gperf_lookup
,
4715 CONFIG_PARSE_ALLOW_INCLUDE
, u
);
4717 log_unit_notice_errno(u
, r
, "Unit configuration has fatal error, unit will not be started.");
4723 if (u
->source_path
) {
4724 if (stat(u
->source_path
, &st
) >= 0)
4725 u
->source_mtime
= timespec_load(&st
.st_mtim
);
4727 u
->source_mtime
= 0;
4730 /* We do the merge dance here because for some unit types, the unit might have aliases which are not
4731 * declared in the file system. In particular, this is true (and frequent) for device and swap units.
4734 const char *id
= u
->id
;
4735 _cleanup_free_
char *free_id
= NULL
;
4738 id
= basename(fragment
);
4739 if (unit_name_is_valid(id
, UNIT_NAME_TEMPLATE
)) {
4740 assert(u
->instance
); /* If we're not trying to use a template for non-instanced unit,
4741 * this must be set. */
4743 r
= unit_name_replace_instance(id
, u
->instance
, &free_id
);
4745 return log_debug_errno(r
, "Failed to build id (%s + %s): %m", id
, u
->instance
);
4751 r
= merge_by_names(&merged
, names
, id
);
4756 u
->load_state
= UNIT_MERGED
;
4761 void unit_dump_config_items(FILE *f
) {
4762 static const struct {
4763 const ConfigParserCallback callback
;
4766 { config_parse_warn_compat
, "NOTSUPPORTED" },
4767 { config_parse_int
, "INTEGER" },
4768 { config_parse_unsigned
, "UNSIGNED" },
4769 { config_parse_iec_size
, "SIZE" },
4770 { config_parse_iec_uint64
, "SIZE" },
4771 { config_parse_si_size
, "SIZE" },
4772 { config_parse_bool
, "BOOLEAN" },
4773 { config_parse_string
, "STRING" },
4774 { config_parse_path
, "PATH" },
4775 { config_parse_unit_path_printf
, "PATH" },
4776 { config_parse_strv
, "STRING [...]" },
4777 { config_parse_exec_nice
, "NICE" },
4778 { config_parse_exec_oom_score_adjust
, "OOMSCOREADJUST" },
4779 { config_parse_exec_io_class
, "IOCLASS" },
4780 { config_parse_exec_io_priority
, "IOPRIORITY" },
4781 { config_parse_exec_cpu_sched_policy
, "CPUSCHEDPOLICY" },
4782 { config_parse_exec_cpu_sched_prio
, "CPUSCHEDPRIO" },
4783 { config_parse_exec_cpu_affinity
, "CPUAFFINITY" },
4784 { config_parse_mode
, "MODE" },
4785 { config_parse_unit_env_file
, "FILE" },
4786 { config_parse_exec_output
, "OUTPUT" },
4787 { config_parse_exec_input
, "INPUT" },
4788 { config_parse_log_facility
, "FACILITY" },
4789 { config_parse_log_level
, "LEVEL" },
4790 { config_parse_exec_secure_bits
, "SECUREBITS" },
4791 { config_parse_capability_set
, "BOUNDINGSET" },
4792 { config_parse_rlimit
, "LIMIT" },
4793 { config_parse_unit_deps
, "UNIT [...]" },
4794 { config_parse_exec
, "PATH [ARGUMENT [...]]" },
4795 { config_parse_service_type
, "SERVICETYPE" },
4796 { config_parse_service_restart
, "SERVICERESTART" },
4797 { config_parse_kill_mode
, "KILLMODE" },
4798 { config_parse_signal
, "SIGNAL" },
4799 { config_parse_socket_listen
, "SOCKET [...]" },
4800 { config_parse_socket_bind
, "SOCKETBIND" },
4801 { config_parse_socket_bindtodevice
, "NETWORKINTERFACE" },
4802 { config_parse_sec
, "SECONDS" },
4803 { config_parse_nsec
, "NANOSECONDS" },
4804 { config_parse_namespace_path_strv
, "PATH [...]" },
4805 { config_parse_bind_paths
, "PATH[:PATH[:OPTIONS]] [...]" },
4806 { config_parse_unit_requires_mounts_for
, "PATH [...]" },
4807 { config_parse_exec_mount_flags
, "MOUNTFLAG [...]" },
4808 { config_parse_unit_string_printf
, "STRING" },
4809 { config_parse_trigger_unit
, "UNIT" },
4810 { config_parse_timer
, "TIMER" },
4811 { config_parse_path_spec
, "PATH" },
4812 { config_parse_notify_access
, "ACCESS" },
4813 { config_parse_ip_tos
, "TOS" },
4814 { config_parse_unit_condition_path
, "CONDITION" },
4815 { config_parse_unit_condition_string
, "CONDITION" },
4816 { config_parse_unit_condition_null
, "CONDITION" },
4817 { config_parse_unit_slice
, "SLICE" },
4818 { config_parse_documentation
, "URL" },
4819 { config_parse_service_timeout
, "SECONDS" },
4820 { config_parse_emergency_action
, "ACTION" },
4821 { config_parse_set_status
, "STATUS" },
4822 { config_parse_service_sockets
, "SOCKETS" },
4823 { config_parse_environ
, "ENVIRON" },
4825 { config_parse_syscall_filter
, "SYSCALLS" },
4826 { config_parse_syscall_archs
, "ARCHS" },
4827 { config_parse_syscall_errno
, "ERRNO" },
4828 { config_parse_address_families
, "FAMILIES" },
4829 { config_parse_restrict_namespaces
, "NAMESPACES" },
4831 { config_parse_cpu_shares
, "SHARES" },
4832 { config_parse_cg_weight
, "WEIGHT" },
4833 { config_parse_memory_limit
, "LIMIT" },
4834 { config_parse_device_allow
, "DEVICE" },
4835 { config_parse_device_policy
, "POLICY" },
4836 { config_parse_io_limit
, "LIMIT" },
4837 { config_parse_io_device_weight
, "DEVICEWEIGHT" },
4838 { config_parse_io_device_latency
, "DEVICELATENCY" },
4839 { config_parse_blockio_bandwidth
, "BANDWIDTH" },
4840 { config_parse_blockio_weight
, "WEIGHT" },
4841 { config_parse_blockio_device_weight
, "DEVICEWEIGHT" },
4842 { config_parse_long
, "LONG" },
4843 { config_parse_socket_service
, "SERVICE" },
4845 { config_parse_exec_selinux_context
, "LABEL" },
4847 { config_parse_job_mode
, "MODE" },
4848 { config_parse_job_mode_isolate
, "BOOLEAN" },
4849 { config_parse_personality
, "PERSONALITY" },
4852 const char *prev
= NULL
;
4857 NULSTR_FOREACH(i
, load_fragment_gperf_nulstr
) {
4858 const char *rvalue
= "OTHER", *lvalue
;
4859 const ConfigPerfItem
*p
;
4864 assert_se(p
= load_fragment_gperf_lookup(i
, strlen(i
)));
4866 /* Hide legacy settings */
4867 if (p
->parse
== config_parse_warn_compat
&&
4868 p
->ltype
== DISABLED_LEGACY
)
4871 for (j
= 0; j
< ELEMENTSOF(table
); j
++)
4872 if (p
->parse
== table
[j
].callback
) {
4873 rvalue
= table
[j
].rvalue
;
4877 dot
= strchr(i
, '.');
4878 lvalue
= dot
? dot
+ 1 : i
;
4882 if (!prev
|| !strneq(prev
, i
, prefix_len
+1)) {
4886 fprintf(f
, "[%.*s]\n", (int) prefix_len
, i
);
4889 fprintf(f
, "%s=%s\n", lvalue
, rvalue
);
4894 int config_parse_cpu_affinity2(
4896 const char *filename
,
4898 const char *section
,
4899 unsigned section_line
,
4906 CPUSet
*affinity
= data
;
4910 (void) parse_cpu_set_extend(rvalue
, affinity
, true, unit
, filename
, line
, lvalue
);
4915 int config_parse_show_status(
4917 const char *filename
,
4919 const char *section
,
4920 unsigned section_line
,
4928 ShowStatus
*b
= data
;
4935 k
= parse_show_status(rvalue
, b
);
4937 log_syntax(unit
, LOG_ERR
, filename
, line
, k
, "Failed to parse show status setting, ignoring: %s", rvalue
);
4944 int config_parse_output_restricted(
4946 const char *filename
,
4948 const char *section
,
4949 unsigned section_line
,
4956 ExecOutput t
, *eo
= data
;
4963 t
= exec_output_from_string(rvalue
);
4965 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse output type, ignoring: %s", rvalue
);
4969 if (IN_SET(t
, EXEC_OUTPUT_SOCKET
, EXEC_OUTPUT_NAMED_FD
, EXEC_OUTPUT_FILE
, EXEC_OUTPUT_FILE_APPEND
)) {
4970 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Standard output types socket, fd:, file:, append: are not supported as defaults, ignoring: %s", rvalue
);
4978 int config_parse_crash_chvt(
4980 const char *filename
,
4982 const char *section
,
4983 unsigned section_line
,
4997 r
= parse_crash_chvt(rvalue
, data
);
4999 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse CrashChangeVT= setting, ignoring: %s", rvalue
);