1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 Copyright © 2012 Holger Hans Peter Freyther
15 #include <sys/resource.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 "cpu-set-util.h"
31 #include "errno-list.h"
35 #include "hexdecoct.h"
38 #include "ip-protocol-list.h"
39 #include "journal-util.h"
40 #include "limits-util.h"
41 #include "load-fragment.h"
44 #include "mountpoint-util.h"
45 #include "nulstr-util.h"
46 #include "parse-util.h"
47 #include "path-util.h"
48 #include "process-util.h"
50 #include "seccomp-util.h"
52 #include "securebits-util.h"
53 #include "signal-util.h"
54 #include "stat-util.h"
55 #include "string-util.h"
57 #include "unit-name.h"
58 #include "unit-printf.h"
59 #include "user-util.h"
60 #include "time-util.h"
63 static int parse_socket_protocol(const char *s
) {
66 r
= parse_ip_protocol(s
);
69 if (!IN_SET(r
, IPPROTO_UDPLITE
, IPPROTO_SCTP
))
70 return -EPROTONOSUPPORT
;
75 int parse_crash_chvt(const char *value
, int *data
) {
78 if (safe_atoi(value
, data
) >= 0)
81 b
= parse_boolean(value
);
86 *data
= 0; /* switch to where kmsg goes */
88 *data
= -1; /* turn off switching */
93 int parse_confirm_spawn(const char *value
, char **console
) {
97 r
= value
? parse_boolean(value
) : 1;
101 } else if (r
> 0) /* on with default tty */
102 s
= strdup("/dev/console");
103 else if (is_path(value
)) /* on with fully qualified path */
105 else /* on with only a tty file name, not a fully qualified path */
106 s
= path_join("/dev/", value
);
114 DEFINE_CONFIG_PARSE(config_parse_socket_protocol
, parse_socket_protocol
, "Failed to parse socket protocol");
115 DEFINE_CONFIG_PARSE(config_parse_exec_secure_bits
, secure_bits_from_string
, "Failed to parse secure bits");
116 DEFINE_CONFIG_PARSE_ENUM(config_parse_collect_mode
, collect_mode
, CollectMode
, "Failed to parse garbage collection mode");
117 DEFINE_CONFIG_PARSE_ENUM(config_parse_device_policy
, cgroup_device_policy
, CGroupDevicePolicy
, "Failed to parse device policy");
118 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_keyring_mode
, exec_keyring_mode
, ExecKeyringMode
, "Failed to parse keyring mode");
119 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_utmp_mode
, exec_utmp_mode
, ExecUtmpMode
, "Failed to parse utmp mode");
120 DEFINE_CONFIG_PARSE_ENUM(config_parse_job_mode
, job_mode
, JobMode
, "Failed to parse job mode");
121 DEFINE_CONFIG_PARSE_ENUM(config_parse_kill_mode
, kill_mode
, KillMode
, "Failed to parse kill mode");
122 DEFINE_CONFIG_PARSE_ENUM(config_parse_notify_access
, notify_access
, NotifyAccess
, "Failed to parse notify access specifier");
123 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_home
, protect_home
, ProtectHome
, "Failed to parse protect home value");
124 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_system
, protect_system
, ProtectSystem
, "Failed to parse protect system value");
125 DEFINE_CONFIG_PARSE_ENUM(config_parse_runtime_preserve_mode
, exec_preserve_mode
, ExecPreserveMode
, "Failed to parse runtime directory preserve mode");
126 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_type
, service_type
, ServiceType
, "Failed to parse service type");
127 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart
, service_restart
, ServiceRestart
, "Failed to parse service restart specifier");
128 DEFINE_CONFIG_PARSE_ENUM(config_parse_socket_bind
, socket_address_bind_ipv6_only_or_bool
, SocketAddressBindIPv6Only
, "Failed to parse bind IPv6 only value");
129 DEFINE_CONFIG_PARSE_ENUM(config_parse_oom_policy
, oom_policy
, OOMPolicy
, "Failed to parse OOM policy");
130 DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_ip_tos
, ip_tos
, int, -1, "Failed to parse IP TOS value");
131 DEFINE_CONFIG_PARSE_PTR(config_parse_blockio_weight
, cg_blkio_weight_parse
, uint64_t, "Invalid block IO weight");
132 DEFINE_CONFIG_PARSE_PTR(config_parse_cg_weight
, cg_weight_parse
, uint64_t, "Invalid weight");
133 DEFINE_CONFIG_PARSE_PTR(config_parse_cpu_shares
, cg_cpu_shares_parse
, uint64_t, "Invalid CPU shares");
134 DEFINE_CONFIG_PARSE_PTR(config_parse_exec_mount_flags
, mount_propagation_flags_from_string
, unsigned long, "Failed to parse mount flag");
135 DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_numa_policy
, mpol
, int, -1, "Invalid NUMA policy type");
136 DEFINE_CONFIG_PARSE_ENUM(config_parse_status_unit_format
, status_unit_format
, StatusUnitFormat
, "Failed to parse status unit format");
138 int config_parse_unit_deps(
140 const char *filename
,
143 unsigned section_line
,
150 UnitDependency d
= ltype
;
160 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
163 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_RETAIN_ESCAPE
);
169 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
173 r
= unit_name_printf(u
, word
, &k
);
175 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
179 r
= unit_add_dependency_by_name(u
, d
, k
, true, UNIT_DEPENDENCY_FILE
);
181 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
187 int config_parse_obsolete_unit_deps(
189 const char *filename
,
192 unsigned section_line
,
199 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
200 "Unit dependency type %s= is obsolete, replacing by %s=, please update your unit file", lvalue
, unit_dependency_to_string(ltype
));
202 return config_parse_unit_deps(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
);
205 int config_parse_unit_string_printf(
207 const char *filename
,
210 unsigned section_line
,
217 _cleanup_free_
char *k
= NULL
;
226 r
= unit_full_printf(u
, rvalue
, &k
);
228 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
232 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
235 int config_parse_unit_strv_printf(
237 const char *filename
,
240 unsigned section_line
,
248 _cleanup_free_
char *k
= NULL
;
256 r
= unit_full_printf(u
, rvalue
, &k
);
258 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
262 return config_parse_strv(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
265 int config_parse_unit_path_printf(
267 const char *filename
,
270 unsigned section_line
,
277 _cleanup_free_
char *k
= NULL
;
287 /* Let's not bother with anything that is too long */
288 if (strlen(rvalue
) >= PATH_MAX
) {
289 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
290 "%s value too long%s.",
291 lvalue
, fatal
? "" : ", ignoring");
292 return fatal
? -ENAMETOOLONG
: 0;
295 r
= unit_full_printf(u
, rvalue
, &k
);
297 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
298 "Failed to resolve unit specifiers in '%s'%s: %m",
299 rvalue
, fatal
? "" : ", ignoring");
300 return fatal
? -ENOEXEC
: 0;
303 return config_parse_path(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
306 int config_parse_unit_path_strv_printf(
308 const char *filename
,
311 unsigned section_line
,
328 if (isempty(rvalue
)) {
334 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
336 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
342 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
343 "Invalid syntax, ignoring: %s", rvalue
);
347 r
= unit_full_printf(u
, word
, &k
);
349 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
350 "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
354 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
358 r
= strv_consume(x
, TAKE_PTR(k
));
364 static int patch_var_run(
366 const char *filename
,
374 e
= path_startswith(*path
, "/var/run/");
378 z
= path_join("/run/", e
);
382 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
383 "%s= references a path below legacy directory /var/run/, updating %s → %s; "
384 "please update the unit file accordingly.", lvalue
, *path
, z
);
386 free_and_replace(*path
, z
);
391 int config_parse_socket_listen(
393 const char *filename
,
396 unsigned section_line
,
403 _cleanup_free_ SocketPort
*p
= NULL
;
415 if (isempty(rvalue
)) {
416 /* An empty assignment removes all ports */
417 socket_free_ports(s
);
421 p
= new0(SocketPort
, 1);
425 if (ltype
!= SOCKET_SOCKET
) {
426 _cleanup_free_
char *k
= NULL
;
428 r
= unit_full_printf(UNIT(s
), rvalue
, &k
);
430 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
434 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
438 if (ltype
== SOCKET_FIFO
) {
439 r
= patch_var_run(unit
, filename
, line
, lvalue
, &k
);
444 free_and_replace(p
->path
, k
);
447 } else if (streq(lvalue
, "ListenNetlink")) {
448 _cleanup_free_
char *k
= NULL
;
450 r
= unit_full_printf(UNIT(s
), rvalue
, &k
);
452 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
456 r
= socket_address_parse_netlink(&p
->address
, k
);
458 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse address value in '%s', ignoring: %m", k
);
462 p
->type
= SOCKET_SOCKET
;
465 _cleanup_free_
char *k
= NULL
;
467 r
= unit_full_printf(UNIT(s
), rvalue
, &k
);
469 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
473 if (k
[0] == '/') { /* Only for AF_UNIX file system sockets… */
474 r
= patch_var_run(unit
, filename
, line
, lvalue
, &k
);
479 r
= socket_address_parse_and_warn(&p
->address
, k
);
481 if (r
!= -EAFNOSUPPORT
)
482 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse address value in '%s', ignoring: %m", k
);
486 if (streq(lvalue
, "ListenStream"))
487 p
->address
.type
= SOCK_STREAM
;
488 else if (streq(lvalue
, "ListenDatagram"))
489 p
->address
.type
= SOCK_DGRAM
;
491 assert(streq(lvalue
, "ListenSequentialPacket"));
492 p
->address
.type
= SOCK_SEQPACKET
;
495 if (socket_address_family(&p
->address
) != AF_LOCAL
&& p
->address
.type
== SOCK_SEQPACKET
) {
496 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Address family not supported, ignoring: %s", rvalue
);
500 p
->type
= SOCKET_SOCKET
;
504 p
->auxiliary_fds
= NULL
;
505 p
->n_auxiliary_fds
= 0;
508 LIST_FIND_TAIL(port
, s
->ports
, tail
);
509 LIST_INSERT_AFTER(port
, s
->ports
, tail
, p
);
516 int config_parse_exec_nice(
518 const char *filename
,
521 unsigned section_line
,
528 ExecContext
*c
= data
;
536 if (isempty(rvalue
)) {
541 r
= parse_nice(rvalue
, &priority
);
544 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Nice priority out of range, ignoring: %s", rvalue
);
546 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse nice priority '%s', ignoring: %m", rvalue
);
556 int config_parse_exec_oom_score_adjust(
558 const char *filename
,
561 unsigned section_line
,
568 ExecContext
*c
= data
;
576 if (isempty(rvalue
)) {
577 c
->oom_score_adjust_set
= false;
581 r
= parse_oom_score_adjust(rvalue
, &oa
);
584 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "OOM score adjust value out of range, ignoring: %s", rvalue
);
586 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse the OOM score adjust value '%s', ignoring: %m", rvalue
);
590 c
->oom_score_adjust
= oa
;
591 c
->oom_score_adjust_set
= true;
596 int config_parse_exec(
598 const char *filename
,
601 unsigned section_line
,
608 ExecCommand
**e
= data
;
620 rvalue
+= strspn(rvalue
, WHITESPACE
);
622 if (isempty(rvalue
)) {
623 /* An empty assignment resets the list */
624 *e
= exec_command_free_list(*e
);
630 _cleanup_free_
char *path
= NULL
, *firstword
= NULL
;
631 ExecCommandFlags flags
= 0;
632 bool ignore
= false, separate_argv0
= false;
633 _cleanup_free_ ExecCommand
*nce
= NULL
;
634 _cleanup_strv_free_
char **n
= NULL
;
635 size_t nlen
= 0, nbufsize
= 0;
640 r
= extract_first_word_and_warn(&p
, &firstword
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
646 /* We accept an absolute path as first argument. If it's prefixed with - and the path doesn't
647 * exist, we ignore it instead of erroring out; if it's prefixed with @, we allow overriding of
648 * argv[0]; if it's prefixed with :, we will not do environment variable substitution;
649 * if it's prefixed with +, it will be run with full privileges and no sandboxing; if
650 * it's prefixed with '!' we apply sandboxing, but do not change user/group credentials; if
651 * it's prefixed with '!!', then we apply user/group credentials if the kernel supports ambient
652 * capabilities -- if it doesn't we don't apply the credentials themselves, but do apply most
653 * other sandboxing, with some special exceptions for changing UID.
655 * The idea is that '!!' may be used to write services that can take benefit of systemd's
656 * UID/GID dropping if the kernel supports ambient creds, but provide an automatic fallback to
657 * privilege dropping within the daemon if the kernel does not offer that. */
659 if (*f
== '-' && !(flags
& EXEC_COMMAND_IGNORE_FAILURE
)) {
660 flags
|= EXEC_COMMAND_IGNORE_FAILURE
;
662 } else if (*f
== '@' && !separate_argv0
)
663 separate_argv0
= true;
664 else if (*f
== ':' && !(flags
& EXEC_COMMAND_NO_ENV_EXPAND
))
665 flags
|= EXEC_COMMAND_NO_ENV_EXPAND
;
666 else if (*f
== '+' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
667 flags
|= EXEC_COMMAND_FULLY_PRIVILEGED
;
668 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
669 flags
|= EXEC_COMMAND_NO_SETUID
;
670 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_AMBIENT_MAGIC
))) {
671 flags
&= ~EXEC_COMMAND_NO_SETUID
;
672 flags
|= EXEC_COMMAND_AMBIENT_MAGIC
;
678 r
= unit_full_printf(u
, f
, &path
);
680 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
681 "Failed to resolve unit specifiers in '%s'%s: %m",
682 f
, ignore
? ", ignoring" : "");
683 return ignore
? 0 : -ENOEXEC
;
687 /* First word is either "-" or "@" with no command. */
688 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
689 "Empty path in command line%s: '%s'",
690 ignore
? ", ignoring" : "", rvalue
);
691 return ignore
? 0 : -ENOEXEC
;
693 if (!string_is_safe(path
)) {
694 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
695 "Executable name contains special characters%s: %s",
696 ignore
? ", ignoring" : "", path
);
697 return ignore
? 0 : -ENOEXEC
;
699 if (endswith(path
, "/")) {
700 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
701 "Executable path specifies a directory%s: %s",
702 ignore
? ", ignoring" : "", path
);
703 return ignore
? 0 : -ENOEXEC
;
706 if (!path_is_absolute(path
)) {
710 if (!filename_is_valid(path
)) {
711 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
712 "Neither a valid executable name nor an absolute path%s: %s",
713 ignore
? ", ignoring" : "", path
);
714 return ignore
? 0 : -ENOEXEC
;
717 /* Resolve a single-component name to a full path */
718 NULSTR_FOREACH(prefix
, DEFAULT_PATH_NULSTR
) {
719 _cleanup_free_
char *fullpath
= NULL
;
721 fullpath
= path_join(prefix
, path
);
725 if (access(fullpath
, F_OK
) >= 0) {
726 free_and_replace(path
, fullpath
);
733 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
734 "Executable \"%s\" not found in path \"%s\"%s",
735 path
, DEFAULT_PATH
, ignore
? ", ignoring" : "");
736 return ignore
? 0 : -ENOEXEC
;
740 if (!separate_argv0
) {
743 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
753 path_simplify(path
, false);
755 while (!isempty(p
)) {
756 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
758 /* Check explicitly for an unquoted semicolon as
759 * command separator token. */
760 if (p
[0] == ';' && (!p
[1] || strchr(WHITESPACE
, p
[1]))) {
762 p
+= strspn(p
, WHITESPACE
);
767 /* Check for \; explicitly, to not confuse it with \\; or "\;" or "\\;" etc.
768 * extract_first_word() would return the same for all of those. */
769 if (p
[0] == '\\' && p
[1] == ';' && (!p
[2] || strchr(WHITESPACE
, p
[2]))) {
773 p
+= strspn(p
, WHITESPACE
);
775 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
786 r
= extract_first_word_and_warn(&p
, &word
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
790 return ignore
? 0 : -ENOEXEC
;
792 r
= unit_full_printf(u
, word
, &resolved
);
794 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
795 "Failed to resolve unit specifiers in %s%s: %m",
796 word
, ignore
? ", ignoring" : "");
797 return ignore
? 0 : -ENOEXEC
;
800 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
803 n
[nlen
++] = TAKE_PTR(resolved
);
808 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
809 "Empty executable name or zeroeth argument%s: %s",
810 ignore
? ", ignoring" : "", rvalue
);
811 return ignore
? 0 : -ENOEXEC
;
814 nce
= new0(ExecCommand
, 1);
818 nce
->argv
= TAKE_PTR(n
);
819 nce
->path
= TAKE_PTR(path
);
822 exec_command_append_list(e
, nce
);
824 /* Do not _cleanup_free_ these. */
833 int config_parse_socket_bindtodevice(
835 const char *filename
,
838 unsigned section_line
,
852 if (isempty(rvalue
) || streq(rvalue
, "*")) {
853 s
->bind_to_device
= mfree(s
->bind_to_device
);
857 if (!ifname_valid(rvalue
)) {
858 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid interface name, ignoring: %s", rvalue
);
862 if (free_and_strdup(&s
->bind_to_device
, rvalue
) < 0)
868 int config_parse_exec_input(
870 const char *filename
,
873 unsigned section_line
,
880 ExecContext
*c
= data
;
891 n
= startswith(rvalue
, "fd:");
893 _cleanup_free_
char *resolved
= NULL
;
895 r
= unit_full_printf(u
, n
, &resolved
);
897 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s': %m", n
);
899 if (isempty(resolved
))
900 resolved
= mfree(resolved
);
901 else if (!fdname_is_valid(resolved
)) {
902 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name: %s", resolved
);
906 free_and_replace(c
->stdio_fdname
[STDIN_FILENO
], resolved
);
908 ei
= EXEC_INPUT_NAMED_FD
;
910 } else if ((n
= startswith(rvalue
, "file:"))) {
911 _cleanup_free_
char *resolved
= NULL
;
913 r
= unit_full_printf(u
, n
, &resolved
);
915 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s': %m", n
);
917 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
921 free_and_replace(c
->stdio_file
[STDIN_FILENO
], resolved
);
923 ei
= EXEC_INPUT_FILE
;
926 ei
= exec_input_from_string(rvalue
);
928 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse input specifier, ignoring: %s", rvalue
);
937 int config_parse_exec_input_text(
939 const char *filename
,
942 unsigned section_line
,
949 _cleanup_free_
char *unescaped
= NULL
, *resolved
= NULL
;
950 ExecContext
*c
= data
;
961 if (isempty(rvalue
)) {
962 /* Reset if the empty string is assigned */
963 c
->stdin_data
= mfree(c
->stdin_data
);
964 c
->stdin_data_size
= 0;
968 r
= cunescape(rvalue
, 0, &unescaped
);
970 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to decode C escaped text '%s': %m", rvalue
);
972 r
= unit_full_printf(u
, unescaped
, &resolved
);
974 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s': %m", unescaped
);
976 sz
= strlen(resolved
);
977 if (c
->stdin_data_size
+ sz
+ 1 < c
->stdin_data_size
|| /* check for overflow */
978 c
->stdin_data_size
+ sz
+ 1 > EXEC_STDIN_DATA_MAX
) {
979 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
);
983 p
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
+ 1);
987 *((char*) mempcpy((char*) p
+ c
->stdin_data_size
, resolved
, sz
)) = '\n';
990 c
->stdin_data_size
+= sz
+ 1;
995 int config_parse_exec_input_data(
997 const char *filename
,
1000 unsigned section_line
,
1007 _cleanup_free_
void *p
= NULL
;
1008 ExecContext
*c
= data
;
1018 if (isempty(rvalue
)) {
1019 /* Reset if the empty string is assigned */
1020 c
->stdin_data
= mfree(c
->stdin_data
);
1021 c
->stdin_data_size
= 0;
1025 r
= unbase64mem(rvalue
, (size_t) -1, &p
, &sz
);
1027 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to decode base64 data, ignoring: %s", rvalue
);
1031 if (c
->stdin_data_size
+ sz
< c
->stdin_data_size
|| /* check for overflow */
1032 c
->stdin_data_size
+ sz
> EXEC_STDIN_DATA_MAX
) {
1033 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
);
1037 q
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
);
1041 memcpy((uint8_t*) q
+ c
->stdin_data_size
, p
, sz
);
1044 c
->stdin_data_size
+= sz
;
1049 int config_parse_exec_output(
1051 const char *filename
,
1053 const char *section
,
1054 unsigned section_line
,
1061 _cleanup_free_
char *resolved
= NULL
;
1063 ExecContext
*c
= data
;
1074 n
= startswith(rvalue
, "fd:");
1076 r
= unit_full_printf(u
, n
, &resolved
);
1078 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", n
);
1080 if (isempty(resolved
))
1081 resolved
= mfree(resolved
);
1082 else if (!fdname_is_valid(resolved
)) {
1083 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name: %s", resolved
);
1087 eo
= EXEC_OUTPUT_NAMED_FD
;
1089 } else if ((n
= startswith(rvalue
, "file:"))) {
1091 r
= unit_full_printf(u
, n
, &resolved
);
1093 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", n
);
1095 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1099 eo
= EXEC_OUTPUT_FILE
;
1101 } else if ((n
= startswith(rvalue
, "append:"))) {
1103 r
= unit_full_printf(u
, n
, &resolved
);
1105 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", n
);
1107 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1111 eo
= EXEC_OUTPUT_FILE_APPEND
;
1113 eo
= exec_output_from_string(rvalue
);
1115 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse output specifier, ignoring: %s", rvalue
);
1120 if (streq(lvalue
, "StandardOutput")) {
1121 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1122 free_and_replace(c
->stdio_fdname
[STDOUT_FILENO
], resolved
);
1124 free_and_replace(c
->stdio_file
[STDOUT_FILENO
], resolved
);
1129 assert(streq(lvalue
, "StandardError"));
1131 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1132 free_and_replace(c
->stdio_fdname
[STDERR_FILENO
], resolved
);
1134 free_and_replace(c
->stdio_file
[STDERR_FILENO
], resolved
);
1142 int config_parse_exec_io_class(const char *unit
,
1143 const char *filename
,
1145 const char *section
,
1146 unsigned section_line
,
1153 ExecContext
*c
= data
;
1161 if (isempty(rvalue
)) {
1162 c
->ioprio_set
= false;
1163 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE
, 0);
1167 x
= ioprio_class_from_string(rvalue
);
1169 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse IO scheduling class, ignoring: %s", rvalue
);
1173 c
->ioprio
= IOPRIO_PRIO_VALUE(x
, IOPRIO_PRIO_DATA(c
->ioprio
));
1174 c
->ioprio_set
= true;
1179 int config_parse_exec_io_priority(const char *unit
,
1180 const char *filename
,
1182 const char *section
,
1183 unsigned section_line
,
1190 ExecContext
*c
= data
;
1198 if (isempty(rvalue
)) {
1199 c
->ioprio_set
= false;
1200 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE
, 0);
1204 r
= ioprio_parse_priority(rvalue
, &i
);
1206 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse IO priority, ignoring: %s", rvalue
);
1210 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_PRIO_CLASS(c
->ioprio
), i
);
1211 c
->ioprio_set
= true;
1216 int config_parse_exec_cpu_sched_policy(const char *unit
,
1217 const char *filename
,
1219 const char *section
,
1220 unsigned section_line
,
1227 ExecContext
*c
= data
;
1235 if (isempty(rvalue
)) {
1236 c
->cpu_sched_set
= false;
1237 c
->cpu_sched_policy
= SCHED_OTHER
;
1238 c
->cpu_sched_priority
= 0;
1242 x
= sched_policy_from_string(rvalue
);
1244 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse CPU scheduling policy, ignoring: %s", rvalue
);
1248 c
->cpu_sched_policy
= x
;
1249 /* Moving to or from real-time policy? We need to adjust the priority */
1250 c
->cpu_sched_priority
= CLAMP(c
->cpu_sched_priority
, sched_get_priority_min(x
), sched_get_priority_max(x
));
1251 c
->cpu_sched_set
= true;
1256 int config_parse_numa_mask(const char *unit
,
1257 const char *filename
,
1259 const char *section
,
1260 unsigned section_line
,
1267 NUMAPolicy
*p
= data
;
1274 r
= parse_cpu_set_extend(rvalue
, &p
->nodes
, true, unit
, filename
, line
, lvalue
);
1276 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse NUMA node mask, ignoring: %s", rvalue
);
1283 int config_parse_exec_cpu_sched_prio(const char *unit
,
1284 const char *filename
,
1286 const char *section
,
1287 unsigned section_line
,
1294 ExecContext
*c
= data
;
1302 r
= safe_atoi(rvalue
, &i
);
1304 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse CPU scheduling priority, ignoring: %s", rvalue
);
1308 /* On Linux RR/FIFO range from 1 to 99 and OTHER/BATCH may only be 0 */
1309 min
= sched_get_priority_min(c
->cpu_sched_policy
);
1310 max
= sched_get_priority_max(c
->cpu_sched_policy
);
1312 if (i
< min
|| i
> max
) {
1313 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "CPU scheduling priority is out of range, ignoring: %s", rvalue
);
1317 c
->cpu_sched_priority
= i
;
1318 c
->cpu_sched_set
= true;
1323 int config_parse_exec_cpu_affinity(const char *unit
,
1324 const char *filename
,
1326 const char *section
,
1327 unsigned section_line
,
1334 ExecContext
*c
= data
;
1341 return parse_cpu_set_extend(rvalue
, &c
->cpu_set
, true, unit
, filename
, line
, lvalue
);
1344 int config_parse_capability_set(
1346 const char *filename
,
1348 const char *section
,
1349 unsigned section_line
,
1356 uint64_t *capability_set
= data
;
1357 uint64_t sum
= 0, initial
= 0;
1358 bool invert
= false;
1366 if (rvalue
[0] == '~') {
1371 if (streq(lvalue
, "CapabilityBoundingSet"))
1372 initial
= CAP_ALL
; /* initialized to all bits on */
1373 /* else "AmbientCapabilities" initialized to all bits off */
1375 r
= capability_set_from_string(rvalue
, &sum
);
1377 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= specifier '%s', ignoring: %m", lvalue
, rvalue
);
1381 if (sum
== 0 || *capability_set
== initial
)
1382 /* "", "~" or uninitialized data -> replace */
1383 *capability_set
= invert
? ~sum
: sum
;
1385 /* previous data -> merge */
1387 *capability_set
&= ~sum
;
1389 *capability_set
|= sum
;
1395 int config_parse_exec_selinux_context(
1397 const char *filename
,
1399 const char *section
,
1400 unsigned section_line
,
1407 ExecContext
*c
= data
;
1418 if (isempty(rvalue
)) {
1419 c
->selinux_context
= mfree(c
->selinux_context
);
1420 c
->selinux_context_ignore
= false;
1424 if (rvalue
[0] == '-') {
1430 r
= unit_full_printf(u
, rvalue
, &k
);
1432 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1433 "Failed to resolve unit specifiers in '%s'%s: %m",
1434 rvalue
, ignore
? ", ignoring" : "");
1435 return ignore
? 0 : -ENOEXEC
;
1438 free_and_replace(c
->selinux_context
, k
);
1439 c
->selinux_context_ignore
= ignore
;
1444 int config_parse_exec_apparmor_profile(
1446 const char *filename
,
1448 const char *section
,
1449 unsigned section_line
,
1456 ExecContext
*c
= data
;
1467 if (isempty(rvalue
)) {
1468 c
->apparmor_profile
= mfree(c
->apparmor_profile
);
1469 c
->apparmor_profile_ignore
= false;
1473 if (rvalue
[0] == '-') {
1479 r
= unit_full_printf(u
, rvalue
, &k
);
1481 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1482 "Failed to resolve unit specifiers in '%s'%s: %m",
1483 rvalue
, ignore
? ", ignoring" : "");
1484 return ignore
? 0 : -ENOEXEC
;
1487 free_and_replace(c
->apparmor_profile
, k
);
1488 c
->apparmor_profile_ignore
= ignore
;
1493 int config_parse_exec_smack_process_label(
1495 const char *filename
,
1497 const char *section
,
1498 unsigned section_line
,
1505 ExecContext
*c
= data
;
1516 if (isempty(rvalue
)) {
1517 c
->smack_process_label
= mfree(c
->smack_process_label
);
1518 c
->smack_process_label_ignore
= false;
1522 if (rvalue
[0] == '-') {
1528 r
= unit_full_printf(u
, rvalue
, &k
);
1530 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1531 "Failed to resolve unit specifiers in '%s'%s: %m",
1532 rvalue
, ignore
? ", ignoring" : "");
1533 return ignore
? 0 : -ENOEXEC
;
1536 free_and_replace(c
->smack_process_label
, k
);
1537 c
->smack_process_label_ignore
= ignore
;
1542 int config_parse_timer(
1544 const char *filename
,
1546 const char *section
,
1547 unsigned section_line
,
1554 _cleanup_(calendar_spec_freep
) CalendarSpec
*c
= NULL
;
1555 _cleanup_free_
char *k
= NULL
;
1567 if (isempty(rvalue
)) {
1568 /* Empty assignment resets list */
1569 timer_free_values(t
);
1573 r
= unit_full_printf(u
, rvalue
, &k
);
1575 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
1579 if (ltype
== TIMER_CALENDAR
) {
1580 r
= calendar_spec_from_string(k
, &c
);
1582 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse calendar specification, ignoring: %s", k
);
1586 r
= parse_sec(k
, &usec
);
1588 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse timer value, ignoring: %s", k
);
1593 v
= new(TimerValue
, 1);
1600 .calendar_spec
= TAKE_PTR(c
),
1603 LIST_PREPEND(value
, t
->values
, v
);
1608 int config_parse_trigger_unit(
1610 const char *filename
,
1612 const char *section
,
1613 unsigned section_line
,
1620 _cleanup_free_
char *p
= NULL
;
1630 if (!hashmap_isempty(u
->dependencies
[UNIT_TRIGGERS
])) {
1631 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Multiple units to trigger specified, ignoring: %s", rvalue
);
1635 r
= unit_name_printf(u
, rvalue
, &p
);
1637 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
1641 type
= unit_name_to_type(p
);
1643 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit type not valid, ignoring: %s", rvalue
);
1646 if (unit_has_name(u
, p
)) {
1647 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Units cannot trigger themselves, ignoring: %s", rvalue
);
1651 r
= unit_add_two_dependencies_by_name(u
, UNIT_BEFORE
, UNIT_TRIGGERS
, p
, true, UNIT_DEPENDENCY_FILE
);
1653 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add trigger on %s, ignoring: %m", p
);
1660 int config_parse_path_spec(const char *unit
,
1661 const char *filename
,
1663 const char *section
,
1664 unsigned section_line
,
1674 _cleanup_free_
char *k
= NULL
;
1682 if (isempty(rvalue
)) {
1683 /* Empty assignment clears list */
1688 b
= path_type_from_string(lvalue
);
1690 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse path type, ignoring: %s", lvalue
);
1694 r
= unit_full_printf(UNIT(p
), rvalue
, &k
);
1696 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
1700 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
1704 s
= new0(PathSpec
, 1);
1709 s
->path
= TAKE_PTR(k
);
1713 LIST_PREPEND(spec
, p
->specs
, s
);
1718 int config_parse_socket_service(
1720 const char *filename
,
1722 const char *section
,
1723 unsigned section_line
,
1730 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1731 _cleanup_free_
char *p
= NULL
;
1741 r
= unit_name_printf(UNIT(s
), rvalue
, &p
);
1743 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", rvalue
);
1747 if (!endswith(p
, ".service")) {
1748 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit must be of type service: %s", rvalue
);
1752 r
= manager_load_unit(UNIT(s
)->manager
, p
, NULL
, &error
, &x
);
1754 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to load unit %s: %s", rvalue
, bus_error_message(&error
, r
));
1758 unit_ref_set(&s
->service
, UNIT(s
), x
);
1763 int config_parse_fdname(
1765 const char *filename
,
1767 const char *section
,
1768 unsigned section_line
,
1775 _cleanup_free_
char *p
= NULL
;
1784 if (isempty(rvalue
)) {
1785 s
->fdname
= mfree(s
->fdname
);
1789 r
= unit_full_printf(UNIT(s
), rvalue
, &p
);
1791 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
1795 if (!fdname_is_valid(p
)) {
1796 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", p
);
1800 return free_and_replace(s
->fdname
, p
);
1803 int config_parse_service_sockets(
1805 const char *filename
,
1807 const char *section
,
1808 unsigned section_line
,
1826 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
1828 r
= extract_first_word(&p
, &word
, NULL
, 0);
1834 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Trailing garbage in sockets, ignoring: %s", rvalue
);
1838 r
= unit_name_printf(UNIT(s
), word
, &k
);
1840 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
1844 if (!endswith(k
, ".socket")) {
1845 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit must be of type socket, ignoring: %s", k
);
1849 r
= unit_add_two_dependencies_by_name(UNIT(s
), UNIT_WANTS
, UNIT_AFTER
, k
, true, UNIT_DEPENDENCY_FILE
);
1851 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
1853 r
= unit_add_dependency_by_name(UNIT(s
), UNIT_TRIGGERED_BY
, k
, true, UNIT_DEPENDENCY_FILE
);
1855 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
1861 int config_parse_bus_name(
1863 const char *filename
,
1865 const char *section
,
1866 unsigned section_line
,
1873 _cleanup_free_
char *k
= NULL
;
1882 r
= unit_full_printf(u
, rvalue
, &k
);
1884 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
1888 if (!service_name_is_valid(k
)) {
1889 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid bus name, ignoring: %s", k
);
1893 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
1896 int config_parse_service_timeout(
1898 const char *filename
,
1900 const char *section
,
1901 unsigned section_line
,
1908 Service
*s
= userdata
;
1917 /* This is called for two cases: TimeoutSec= and TimeoutStartSec=. */
1919 /* Traditionally, these options accepted 0 to disable the timeouts. However, a timeout of 0 suggests it happens
1920 * immediately, hence fix this to become USEC_INFINITY instead. This is in-line with how we internally handle
1921 * all other timeouts. */
1922 r
= parse_sec_fix_0(rvalue
, &usec
);
1924 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
1928 s
->start_timeout_defined
= true;
1929 s
->timeout_start_usec
= usec
;
1931 if (streq(lvalue
, "TimeoutSec"))
1932 s
->timeout_stop_usec
= usec
;
1937 int config_parse_service_timeout_abort(
1939 const char *filename
,
1941 const char *section
,
1942 unsigned section_line
,
1949 Service
*s
= userdata
;
1957 rvalue
+= strspn(rvalue
, WHITESPACE
);
1958 if (isempty(rvalue
)) {
1959 s
->timeout_abort_set
= false;
1963 r
= parse_sec(rvalue
, &s
->timeout_abort_usec
);
1965 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse TimeoutAbortSec= setting, ignoring: %s", rvalue
);
1969 s
->timeout_abort_set
= true;
1973 int config_parse_sec_fix_0(
1975 const char *filename
,
1977 const char *section
,
1978 unsigned section_line
,
1985 usec_t
*usec
= data
;
1993 /* This is pretty much like config_parse_sec(), except that this treats a time of 0 as infinity, for
1994 * compatibility with older versions of systemd where 0 instead of infinity was used as indicator to turn off a
1997 r
= parse_sec_fix_0(rvalue
, usec
);
1999 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
2006 int config_parse_user_group_compat(
2008 const char *filename
,
2010 const char *section
,
2011 unsigned section_line
,
2018 _cleanup_free_
char *k
= NULL
;
2028 if (isempty(rvalue
)) {
2029 *user
= mfree(*user
);
2033 r
= unit_full_printf(u
, rvalue
, &k
);
2035 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", rvalue
);
2039 if (!valid_user_group_name_or_id_compat(k
)) {
2040 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2044 return free_and_replace(*user
, k
);
2047 int config_parse_user_group_strv_compat(
2049 const char *filename
,
2051 const char *section
,
2052 unsigned section_line
,
2059 char ***users
= data
;
2061 const char *p
= rvalue
;
2069 if (isempty(rvalue
)) {
2070 *users
= strv_free(*users
);
2075 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2077 r
= extract_first_word(&p
, &word
, NULL
, 0);
2083 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax: %s", rvalue
);
2087 r
= unit_full_printf(u
, word
, &k
);
2089 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", word
);
2093 if (!valid_user_group_name_or_id_compat(k
)) {
2094 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2098 r
= strv_push(users
, k
);
2108 int config_parse_working_directory(
2110 const char *filename
,
2112 const char *section
,
2113 unsigned section_line
,
2120 ExecContext
*c
= data
;
2131 if (isempty(rvalue
)) {
2132 c
->working_directory_home
= false;
2133 c
->working_directory
= mfree(c
->working_directory
);
2137 if (rvalue
[0] == '-') {
2143 if (streq(rvalue
, "~")) {
2144 c
->working_directory_home
= true;
2145 c
->working_directory
= mfree(c
->working_directory
);
2147 _cleanup_free_
char *k
= NULL
;
2149 r
= unit_full_printf(u
, rvalue
, &k
);
2151 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2152 "Failed to resolve unit specifiers in working directory path '%s'%s: %m",
2153 rvalue
, missing_ok
? ", ignoring" : "");
2154 return missing_ok
? 0 : -ENOEXEC
;
2157 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
| (missing_ok
? 0 : PATH_CHECK_FATAL
), unit
, filename
, line
, lvalue
);
2159 return missing_ok
? 0 : -ENOEXEC
;
2161 c
->working_directory_home
= false;
2162 free_and_replace(c
->working_directory
, k
);
2165 c
->working_directory_missing_ok
= missing_ok
;
2169 int config_parse_unit_env_file(const char *unit
,
2170 const char *filename
,
2172 const char *section
,
2173 unsigned section_line
,
2182 _cleanup_free_
char *n
= NULL
;
2190 if (isempty(rvalue
)) {
2191 /* Empty assignment frees the list */
2192 *env
= strv_free(*env
);
2196 r
= unit_full_printf(u
, rvalue
, &n
);
2198 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2202 r
= path_simplify_and_warn(n
[0] == '-' ? n
+ 1 : n
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2206 r
= strv_push(env
, n
);
2215 int config_parse_environ(
2217 const char *filename
,
2219 const char *section
,
2220 unsigned section_line
,
2237 if (isempty(rvalue
)) {
2238 /* Empty assignment resets the list */
2239 *env
= strv_free(*env
);
2243 for (p
= rvalue
;; ) {
2244 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2246 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2252 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2253 "Invalid syntax, ignoring: %s", rvalue
);
2258 r
= unit_full_printf(u
, word
, &k
);
2260 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2261 "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2267 if (!env_assignment_is_valid(k
)) {
2268 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2269 "Invalid environment assignment, ignoring: %s", k
);
2273 r
= strv_env_replace(env
, k
);
2281 int config_parse_pass_environ(
2283 const char *filename
,
2285 const char *section
,
2286 unsigned section_line
,
2293 _cleanup_strv_free_
char **n
= NULL
;
2294 size_t nlen
= 0, nbufsize
= 0;
2295 char*** passenv
= data
;
2296 const char *p
= rvalue
;
2305 if (isempty(rvalue
)) {
2306 /* Empty assignment resets the list */
2307 *passenv
= strv_free(*passenv
);
2312 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2314 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
2320 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2321 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2326 r
= unit_full_printf(u
, word
, &k
);
2328 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2329 "Failed to resolve specifiers in %s, ignoring: %m", word
);
2335 if (!env_name_is_valid(k
)) {
2336 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2337 "Invalid environment name for %s, ignoring: %s", lvalue
, k
);
2341 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
2344 n
[nlen
++] = TAKE_PTR(k
);
2349 r
= strv_extend_strv(passenv
, n
, true);
2357 int config_parse_unset_environ(
2359 const char *filename
,
2361 const char *section
,
2362 unsigned section_line
,
2369 _cleanup_strv_free_
char **n
= NULL
;
2370 size_t nlen
= 0, nbufsize
= 0;
2371 char*** unsetenv
= data
;
2372 const char *p
= rvalue
;
2381 if (isempty(rvalue
)) {
2382 /* Empty assignment resets the list */
2383 *unsetenv
= strv_free(*unsetenv
);
2388 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2390 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2396 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2397 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2402 r
= unit_full_printf(u
, word
, &k
);
2404 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2405 "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2411 if (!env_assignment_is_valid(k
) && !env_name_is_valid(k
)) {
2412 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2413 "Invalid environment name or assignment %s, ignoring: %s", lvalue
, k
);
2417 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
2420 n
[nlen
++] = TAKE_PTR(k
);
2425 r
= strv_extend_strv(unsetenv
, n
, true);
2433 int config_parse_log_extra_fields(
2435 const char *filename
,
2437 const char *section
,
2438 unsigned section_line
,
2445 ExecContext
*c
= data
;
2447 const char *p
= rvalue
;
2455 if (isempty(rvalue
)) {
2456 exec_context_free_log_extra_fields(c
);
2461 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2465 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2471 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
2475 r
= unit_full_printf(u
, word
, &k
);
2477 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2481 eq
= strchr(k
, '=');
2483 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Log field lacks '=' character, ignoring: %s", k
);
2487 if (!journal_field_valid(k
, eq
-k
, false)) {
2488 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Log field name is invalid, ignoring: %s", k
);
2492 t
= reallocarray(c
->log_extra_fields
, c
->n_log_extra_fields
+1, sizeof(struct iovec
));
2496 c
->log_extra_fields
= t
;
2497 c
->log_extra_fields
[c
->n_log_extra_fields
++] = IOVEC_MAKE_STRING(k
);
2503 int config_parse_unit_condition_path(
2505 const char *filename
,
2507 const char *section
,
2508 unsigned section_line
,
2515 _cleanup_free_
char *p
= NULL
;
2516 Condition
**list
= data
, *c
;
2517 ConditionType t
= ltype
;
2518 bool trigger
, negate
;
2527 if (isempty(rvalue
)) {
2528 /* Empty assignment resets the list */
2529 *list
= condition_free_list(*list
);
2533 trigger
= rvalue
[0] == '|';
2537 negate
= rvalue
[0] == '!';
2541 r
= unit_full_printf(u
, rvalue
, &p
);
2543 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2547 r
= path_simplify_and_warn(p
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2551 c
= condition_new(t
, p
, trigger
, negate
);
2555 LIST_PREPEND(conditions
, *list
, c
);
2559 int config_parse_unit_condition_string(
2561 const char *filename
,
2563 const char *section
,
2564 unsigned section_line
,
2571 _cleanup_free_
char *s
= NULL
;
2572 Condition
**list
= data
, *c
;
2573 ConditionType t
= ltype
;
2574 bool trigger
, negate
;
2583 if (isempty(rvalue
)) {
2584 /* Empty assignment resets the list */
2585 *list
= condition_free_list(*list
);
2589 trigger
= *rvalue
== '|';
2591 rvalue
+= 1 + strspn(rvalue
+ 1, WHITESPACE
);
2593 negate
= *rvalue
== '!';
2595 rvalue
+= 1 + strspn(rvalue
+ 1, WHITESPACE
);
2597 r
= unit_full_printf(u
, rvalue
, &s
);
2599 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2600 "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2604 c
= condition_new(t
, s
, trigger
, negate
);
2608 LIST_PREPEND(conditions
, *list
, c
);
2612 int config_parse_unit_condition_null(
2614 const char *filename
,
2616 const char *section
,
2617 unsigned section_line
,
2624 Condition
**list
= data
, *c
;
2625 bool trigger
, negate
;
2633 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "%s= is deprecated, please do not use.", lvalue
);
2635 if (isempty(rvalue
)) {
2636 /* Empty assignment resets the list */
2637 *list
= condition_free_list(*list
);
2641 trigger
= rvalue
[0] == '|';
2645 negate
= rvalue
[0] == '!';
2649 b
= parse_boolean(rvalue
);
2651 log_syntax(unit
, LOG_ERR
, filename
, line
, b
, "Failed to parse boolean value in condition, ignoring: %s", rvalue
);
2658 c
= condition_new(CONDITION_NULL
, NULL
, trigger
, negate
);
2662 LIST_PREPEND(conditions
, *list
, c
);
2666 int config_parse_unit_requires_mounts_for(
2668 const char *filename
,
2670 const char *section
,
2671 unsigned section_line
,
2678 const char *p
= rvalue
;
2688 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
2690 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
2696 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2697 "Invalid syntax, ignoring: %s", rvalue
);
2701 r
= unit_full_printf(u
, word
, &resolved
);
2703 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
2707 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2711 r
= unit_require_mounts_for(u
, resolved
, UNIT_DEPENDENCY_FILE
);
2713 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add required mount '%s', ignoring: %m", resolved
);
2719 int config_parse_documentation(const char *unit
,
2720 const char *filename
,
2722 const char *section
,
2723 unsigned section_line
,
2739 if (isempty(rvalue
)) {
2740 /* Empty assignment resets the list */
2741 u
->documentation
= strv_free(u
->documentation
);
2745 r
= config_parse_unit_strv_printf(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
,
2746 rvalue
, data
, userdata
);
2750 for (a
= b
= u
->documentation
; a
&& *a
; a
++) {
2752 if (documentation_url_is_valid(*a
))
2755 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid URL, ignoring: %s", *a
);
2766 int config_parse_syscall_filter(
2768 const char *filename
,
2770 const char *section
,
2771 unsigned section_line
,
2778 ExecContext
*c
= data
;
2780 bool invert
= false;
2789 if (isempty(rvalue
)) {
2790 /* Empty assignment resets the list */
2791 c
->syscall_filter
= hashmap_free(c
->syscall_filter
);
2792 c
->syscall_whitelist
= false;
2796 if (rvalue
[0] == '~') {
2801 if (!c
->syscall_filter
) {
2802 c
->syscall_filter
= hashmap_new(NULL
);
2803 if (!c
->syscall_filter
)
2807 /* Allow everything but the ones listed */
2808 c
->syscall_whitelist
= false;
2810 /* Allow nothing but the ones listed */
2811 c
->syscall_whitelist
= true;
2813 /* Accept default syscalls if we are on a whitelist */
2814 r
= seccomp_parse_syscall_filter(
2815 "@default", -1, c
->syscall_filter
,
2816 SECCOMP_PARSE_PERMISSIVE
|SECCOMP_PARSE_WHITELIST
,
2826 _cleanup_free_
char *word
= NULL
, *name
= NULL
;
2829 r
= extract_first_word(&p
, &word
, NULL
, 0);
2835 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
2839 r
= parse_syscall_and_errno(word
, &name
, &num
);
2841 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse syscall:errno, ignoring: %s", word
);
2845 r
= seccomp_parse_syscall_filter(
2846 name
, num
, c
->syscall_filter
,
2847 SECCOMP_PARSE_LOG
|SECCOMP_PARSE_PERMISSIVE
|
2848 (invert
? SECCOMP_PARSE_INVERT
: 0)|
2849 (c
->syscall_whitelist
? SECCOMP_PARSE_WHITELIST
: 0),
2850 unit
, filename
, line
);
2856 int config_parse_syscall_archs(
2858 const char *filename
,
2860 const char *section
,
2861 unsigned section_line
,
2868 const char *p
= rvalue
;
2872 if (isempty(rvalue
)) {
2873 *archs
= set_free(*archs
);
2877 r
= set_ensure_allocated(archs
, NULL
);
2882 _cleanup_free_
char *word
= NULL
;
2885 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
2891 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2892 "Invalid syntax, ignoring: %s", rvalue
);
2896 r
= seccomp_arch_from_string(word
, &a
);
2898 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2899 "Failed to parse system call architecture \"%s\", ignoring: %m", word
);
2903 r
= set_put(*archs
, UINT32_TO_PTR(a
+ 1));
2909 int config_parse_syscall_errno(
2911 const char *filename
,
2913 const char *section
,
2914 unsigned section_line
,
2921 ExecContext
*c
= data
;
2928 if (isempty(rvalue
)) {
2929 /* Empty assignment resets to KILL */
2930 c
->syscall_errno
= 0;
2934 e
= parse_errno(rvalue
);
2936 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse error number, ignoring: %s", rvalue
);
2940 c
->syscall_errno
= e
;
2944 int config_parse_address_families(
2946 const char *filename
,
2948 const char *section
,
2949 unsigned section_line
,
2956 ExecContext
*c
= data
;
2957 bool invert
= false;
2965 if (isempty(rvalue
)) {
2966 /* Empty assignment resets the list */
2967 c
->address_families
= set_free(c
->address_families
);
2968 c
->address_families_whitelist
= false;
2972 if (rvalue
[0] == '~') {
2977 if (!c
->address_families
) {
2978 c
->address_families
= set_new(NULL
);
2979 if (!c
->address_families
)
2982 c
->address_families_whitelist
= !invert
;
2985 for (p
= rvalue
;;) {
2986 _cleanup_free_
char *word
= NULL
;
2989 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
2995 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2996 "Invalid syntax, ignoring: %s", rvalue
);
3000 af
= af_from_name(word
);
3002 log_syntax(unit
, LOG_ERR
, filename
, line
, af
,
3003 "Failed to parse address family, ignoring: %s", word
);
3007 /* If we previously wanted to forbid an address family and now
3008 * we want to allow it, then just remove it from the list.
3010 if (!invert
== c
->address_families_whitelist
) {
3011 r
= set_put(c
->address_families
, INT_TO_PTR(af
));
3015 set_remove(c
->address_families
, INT_TO_PTR(af
));
3019 int config_parse_restrict_namespaces(
3021 const char *filename
,
3023 const char *section
,
3024 unsigned section_line
,
3031 ExecContext
*c
= data
;
3032 unsigned long flags
;
3033 bool invert
= false;
3036 if (isempty(rvalue
)) {
3037 /* Reset to the default. */
3038 c
->restrict_namespaces
= NAMESPACE_FLAGS_INITIAL
;
3042 /* Boolean parameter ignores the previous settings */
3043 r
= parse_boolean(rvalue
);
3045 c
->restrict_namespaces
= 0;
3047 } else if (r
== 0) {
3048 c
->restrict_namespaces
= NAMESPACE_FLAGS_ALL
;
3052 if (rvalue
[0] == '~') {
3057 /* Not a boolean argument, in this case it's a list of namespace types. */
3058 r
= namespace_flags_from_string(rvalue
, &flags
);
3060 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse namespace type string, ignoring: %s", rvalue
);
3064 if (c
->restrict_namespaces
== NAMESPACE_FLAGS_INITIAL
)
3065 /* Initial assignment. Just set the value. */
3066 c
->restrict_namespaces
= invert
? (~flags
) & NAMESPACE_FLAGS_ALL
: flags
;
3068 /* Merge the value with the previous one. */
3069 SET_FLAG(c
->restrict_namespaces
, flags
, !invert
);
3075 int config_parse_unit_slice(
3077 const char *filename
,
3079 const char *section
,
3080 unsigned section_line
,
3087 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
3088 _cleanup_free_
char *k
= NULL
;
3089 Unit
*u
= userdata
, *slice
= NULL
;
3097 r
= unit_name_printf(u
, rvalue
, &k
);
3099 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
3103 r
= manager_load_unit(u
->manager
, k
, NULL
, &error
, &slice
);
3105 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to load slice unit %s, ignoring: %s", k
, bus_error_message(&error
, r
));
3109 r
= unit_set_slice(u
, slice
);
3111 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to assign slice %s to unit %s, ignoring: %m", slice
->id
, u
->id
);
3118 int config_parse_cpu_quota(
3120 const char *filename
,
3122 const char *section
,
3123 unsigned section_line
,
3130 CGroupContext
*c
= data
;
3137 if (isempty(rvalue
)) {
3138 c
->cpu_quota_per_sec_usec
= USEC_INFINITY
;
3142 r
= parse_permille_unbounded(rvalue
);
3144 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid CPU quota '%s', ignoring.", rvalue
);
3148 c
->cpu_quota_per_sec_usec
= ((usec_t
) r
* USEC_PER_SEC
) / 1000U;
3152 int config_parse_cpuset_cpus(
3154 const char *filename
,
3156 const char *section
,
3157 unsigned section_line
,
3164 CGroupContext
*c
= data
;
3166 (void) parse_cpu_set_extend(rvalue
, &c
->cpuset_cpus
, true, unit
, filename
, line
, lvalue
);
3171 int config_parse_cpuset_mems(
3173 const char *filename
,
3175 const char *section
,
3176 unsigned section_line
,
3183 CGroupContext
*c
= data
;
3185 (void) parse_cpu_set_extend(rvalue
, &c
->cpuset_mems
, true, unit
, filename
, line
, lvalue
);
3190 int config_parse_memory_limit(
3192 const char *filename
,
3194 const char *section
,
3195 unsigned section_line
,
3202 CGroupContext
*c
= data
;
3203 uint64_t bytes
= CGROUP_LIMIT_MAX
;
3206 if (!isempty(rvalue
) && !streq(rvalue
, "infinity")) {
3208 r
= parse_permille(rvalue
);
3210 r
= parse_size(rvalue
, 1024, &bytes
);
3212 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid memory limit '%s', ignoring: %m", rvalue
);
3216 bytes
= physical_memory_scale(r
, 1000U);
3218 if (bytes
>= UINT64_MAX
||
3219 (bytes
<= 0 && !STR_IN_SET(lvalue
, "MemorySwapMax", "MemoryLow", "MemoryMin", "DefaultMemoryLow", "DefaultMemoryMin"))) {
3220 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Memory limit '%s' out of range, ignoring.", rvalue
);
3225 if (streq(lvalue
, "DefaultMemoryLow")) {
3226 c
->default_memory_low_set
= true;
3227 if (isempty(rvalue
))
3228 c
->default_memory_low
= CGROUP_LIMIT_MIN
;
3230 c
->default_memory_low
= bytes
;
3231 } else if (streq(lvalue
, "DefaultMemoryMin")) {
3232 c
->default_memory_min_set
= true;
3233 if (isempty(rvalue
))
3234 c
->default_memory_min
= CGROUP_LIMIT_MIN
;
3236 c
->default_memory_min
= bytes
;
3237 } else if (streq(lvalue
, "MemoryMin")) {
3238 c
->memory_min
= bytes
;
3239 c
->memory_min_set
= true;
3240 } else if (streq(lvalue
, "MemoryLow")) {
3241 c
->memory_low
= bytes
;
3242 c
->memory_low_set
= true;
3243 } else if (streq(lvalue
, "MemoryHigh"))
3244 c
->memory_high
= bytes
;
3245 else if (streq(lvalue
, "MemoryMax"))
3246 c
->memory_max
= bytes
;
3247 else if (streq(lvalue
, "MemorySwapMax"))
3248 c
->memory_swap_max
= bytes
;
3249 else if (streq(lvalue
, "MemoryLimit"))
3250 c
->memory_limit
= bytes
;
3257 int config_parse_tasks_max(
3259 const char *filename
,
3261 const char *section
,
3262 unsigned section_line
,
3269 uint64_t *tasks_max
= data
, v
;
3273 if (isempty(rvalue
)) {
3274 *tasks_max
= u
? u
->manager
->default_tasks_max
: UINT64_MAX
;
3278 if (streq(rvalue
, "infinity")) {
3279 *tasks_max
= CGROUP_LIMIT_MAX
;
3283 r
= parse_permille(rvalue
);
3285 r
= safe_atou64(rvalue
, &v
);
3287 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid maximum tasks value '%s', ignoring: %m", rvalue
);
3291 v
= system_tasks_max_scale(r
, 1000U);
3293 if (v
<= 0 || v
>= UINT64_MAX
) {
3294 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Maximum tasks value '%s' out of range, ignoring.", rvalue
);
3302 int config_parse_delegate(
3304 const char *filename
,
3306 const char *section
,
3307 unsigned section_line
,
3314 CGroupContext
*c
= data
;
3318 t
= unit_name_to_type(unit
);
3319 assert(t
!= _UNIT_TYPE_INVALID
);
3321 if (!unit_vtable
[t
]->can_delegate
) {
3322 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Delegate= setting not supported for this unit type, ignoring.");
3326 /* We either accept a boolean value, which may be used to turn on delegation for all controllers, or turn it
3327 * off for all. Or it takes a list of controller names, in which case we add the specified controllers to the
3328 * mask to delegate. */
3330 if (isempty(rvalue
)) {
3331 /* An empty string resets controllers and set Delegate=yes. */
3333 c
->delegate_controllers
= 0;
3337 r
= parse_boolean(rvalue
);
3339 const char *p
= rvalue
;
3340 CGroupMask mask
= 0;
3343 _cleanup_free_
char *word
= NULL
;
3344 CGroupController cc
;
3346 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3352 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3356 cc
= cgroup_controller_from_string(word
);
3358 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid controller name '%s', ignoring", word
);
3362 mask
|= CGROUP_CONTROLLER_TO_MASK(cc
);
3366 c
->delegate_controllers
|= mask
;
3370 c
->delegate_controllers
= _CGROUP_MASK_ALL
;
3372 c
->delegate
= false;
3373 c
->delegate_controllers
= 0;
3379 int config_parse_device_allow(
3381 const char *filename
,
3383 const char *section
,
3384 unsigned section_line
,
3391 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3392 CGroupContext
*c
= data
;
3393 const char *p
= rvalue
;
3396 if (isempty(rvalue
)) {
3397 while (c
->device_allow
)
3398 cgroup_context_free_device_allow(c
, c
->device_allow
);
3403 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3407 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3408 "Invalid syntax, ignoring: %s", rvalue
);
3412 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3413 "Failed to extract device path and rights from '%s', ignoring.", rvalue
);
3417 r
= unit_full_printf(userdata
, path
, &resolved
);
3419 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3420 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3424 if (!STARTSWITH_SET(resolved
, "block-", "char-")) {
3426 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3430 if (!valid_device_node_path(resolved
)) {
3431 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device node path '%s', ignoring.", resolved
);
3436 if (!isempty(p
) && !in_charset(p
, "rwm")) {
3437 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device rights '%s', ignoring.", p
);
3441 return cgroup_add_device_allow(c
, resolved
, p
);
3444 int config_parse_io_device_weight(
3446 const char *filename
,
3448 const char *section
,
3449 unsigned section_line
,
3456 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3457 CGroupIODeviceWeight
*w
;
3458 CGroupContext
*c
= data
;
3459 const char *p
= rvalue
;
3467 if (isempty(rvalue
)) {
3468 while (c
->io_device_weights
)
3469 cgroup_context_free_io_device_weight(c
, c
->io_device_weights
);
3474 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3478 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3479 "Invalid syntax, ignoring: %s", rvalue
);
3482 if (r
== 0 || isempty(p
)) {
3483 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3484 "Failed to extract device path and weight from '%s', ignoring.", rvalue
);
3488 r
= unit_full_printf(userdata
, path
, &resolved
);
3490 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3491 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3495 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3499 r
= cg_weight_parse(p
, &u
);
3501 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "IO weight '%s' invalid, ignoring: %m", p
);
3505 assert(u
!= CGROUP_WEIGHT_INVALID
);
3507 w
= new0(CGroupIODeviceWeight
, 1);
3511 w
->path
= TAKE_PTR(resolved
);
3514 LIST_PREPEND(device_weights
, c
->io_device_weights
, w
);
3518 int config_parse_io_device_latency(
3520 const char *filename
,
3522 const char *section
,
3523 unsigned section_line
,
3530 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3531 CGroupIODeviceLatency
*l
;
3532 CGroupContext
*c
= data
;
3533 const char *p
= rvalue
;
3541 if (isempty(rvalue
)) {
3542 while (c
->io_device_latencies
)
3543 cgroup_context_free_io_device_latency(c
, c
->io_device_latencies
);
3548 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3552 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3553 "Invalid syntax, ignoring: %s", rvalue
);
3556 if (r
== 0 || isempty(p
)) {
3557 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3558 "Failed to extract device path and latency from '%s', ignoring.", rvalue
);
3562 r
= unit_full_printf(userdata
, path
, &resolved
);
3564 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3565 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3569 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3573 if (parse_sec(p
, &usec
) < 0) {
3574 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse timer value, ignoring: %s", p
);
3578 l
= new0(CGroupIODeviceLatency
, 1);
3582 l
->path
= TAKE_PTR(resolved
);
3583 l
->target_usec
= usec
;
3585 LIST_PREPEND(device_latencies
, c
->io_device_latencies
, l
);
3589 int config_parse_io_limit(
3591 const char *filename
,
3593 const char *section
,
3594 unsigned section_line
,
3601 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3602 CGroupIODeviceLimit
*l
= NULL
, *t
;
3603 CGroupContext
*c
= data
;
3604 CGroupIOLimitType type
;
3605 const char *p
= rvalue
;
3613 type
= cgroup_io_limit_type_from_string(lvalue
);
3616 if (isempty(rvalue
)) {
3617 LIST_FOREACH(device_limits
, l
, c
->io_device_limits
)
3618 l
->limits
[type
] = cgroup_io_limit_defaults
[type
];
3622 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3626 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3627 "Invalid syntax, ignoring: %s", rvalue
);
3630 if (r
== 0 || isempty(p
)) {
3631 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3632 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
3636 r
= unit_full_printf(userdata
, path
, &resolved
);
3638 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3639 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3643 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3647 if (streq("infinity", p
))
3648 num
= CGROUP_LIMIT_MAX
;
3650 r
= parse_size(p
, 1000, &num
);
3651 if (r
< 0 || num
<= 0) {
3652 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid IO limit '%s', ignoring.", p
);
3657 LIST_FOREACH(device_limits
, t
, c
->io_device_limits
) {
3658 if (path_equal(resolved
, t
->path
)) {
3665 CGroupIOLimitType ttype
;
3667 l
= new0(CGroupIODeviceLimit
, 1);
3671 l
->path
= TAKE_PTR(resolved
);
3672 for (ttype
= 0; ttype
< _CGROUP_IO_LIMIT_TYPE_MAX
; ttype
++)
3673 l
->limits
[ttype
] = cgroup_io_limit_defaults
[ttype
];
3675 LIST_PREPEND(device_limits
, c
->io_device_limits
, l
);
3678 l
->limits
[type
] = num
;
3683 int config_parse_blockio_device_weight(
3685 const char *filename
,
3687 const char *section
,
3688 unsigned section_line
,
3695 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3696 CGroupBlockIODeviceWeight
*w
;
3697 CGroupContext
*c
= data
;
3698 const char *p
= rvalue
;
3706 if (isempty(rvalue
)) {
3707 while (c
->blockio_device_weights
)
3708 cgroup_context_free_blockio_device_weight(c
, c
->blockio_device_weights
);
3713 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3717 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3718 "Invalid syntax, ignoring: %s", rvalue
);
3721 if (r
== 0 || isempty(p
)) {
3722 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3723 "Failed to extract device node and weight from '%s', ignoring.", rvalue
);
3727 r
= unit_full_printf(userdata
, path
, &resolved
);
3729 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3730 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3734 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3738 r
= cg_blkio_weight_parse(p
, &u
);
3740 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid block IO weight '%s', ignoring: %m", p
);
3744 assert(u
!= CGROUP_BLKIO_WEIGHT_INVALID
);
3746 w
= new0(CGroupBlockIODeviceWeight
, 1);
3750 w
->path
= TAKE_PTR(resolved
);
3753 LIST_PREPEND(device_weights
, c
->blockio_device_weights
, w
);
3757 int config_parse_blockio_bandwidth(
3759 const char *filename
,
3761 const char *section
,
3762 unsigned section_line
,
3769 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3770 CGroupBlockIODeviceBandwidth
*b
= NULL
, *t
;
3771 CGroupContext
*c
= data
;
3772 const char *p
= rvalue
;
3781 read
= streq("BlockIOReadBandwidth", lvalue
);
3783 if (isempty(rvalue
)) {
3784 LIST_FOREACH(device_bandwidths
, b
, c
->blockio_device_bandwidths
) {
3785 b
->rbps
= CGROUP_LIMIT_MAX
;
3786 b
->wbps
= CGROUP_LIMIT_MAX
;
3791 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3795 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3796 "Invalid syntax, ignoring: %s", rvalue
);
3799 if (r
== 0 || isempty(p
)) {
3800 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3801 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
3805 r
= unit_full_printf(userdata
, path
, &resolved
);
3807 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3808 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3812 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3816 r
= parse_size(p
, 1000, &bytes
);
3817 if (r
< 0 || bytes
<= 0) {
3818 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid Block IO Bandwidth '%s', ignoring.", p
);
3822 LIST_FOREACH(device_bandwidths
, t
, c
->blockio_device_bandwidths
) {
3823 if (path_equal(resolved
, t
->path
)) {
3830 b
= new0(CGroupBlockIODeviceBandwidth
, 1);
3834 b
->path
= TAKE_PTR(resolved
);
3835 b
->rbps
= CGROUP_LIMIT_MAX
;
3836 b
->wbps
= CGROUP_LIMIT_MAX
;
3838 LIST_PREPEND(device_bandwidths
, c
->blockio_device_bandwidths
, b
);
3849 int config_parse_job_mode_isolate(
3851 const char *filename
,
3853 const char *section
,
3854 unsigned section_line
,
3868 r
= parse_boolean(rvalue
);
3870 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse boolean, ignoring: %s", rvalue
);
3874 log_notice("%s is deprecated. Please use OnFailureJobMode= instead", lvalue
);
3876 *m
= r
? JOB_ISOLATE
: JOB_REPLACE
;
3880 int config_parse_exec_directories(
3882 const char *filename
,
3884 const char *section
,
3885 unsigned section_line
,
3902 if (isempty(rvalue
)) {
3903 /* Empty assignment resets the list */
3904 *rt
= strv_free(*rt
);
3908 for (p
= rvalue
;;) {
3909 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
3911 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3915 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3916 "Invalid syntax, ignoring: %s", rvalue
);
3922 r
= unit_full_printf(u
, word
, &k
);
3924 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
3925 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
3929 r
= path_simplify_and_warn(k
, PATH_CHECK_RELATIVE
, unit
, filename
, line
, lvalue
);
3933 if (path_startswith(k
, "private")) {
3934 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
3935 "%s= path can't be 'private', ignoring assignment: %s", lvalue
, word
);
3939 r
= strv_push(rt
, k
);
3946 int config_parse_set_status(
3948 const char *filename
,
3950 const char *section
,
3951 unsigned section_line
,
3959 const char *word
, *state
;
3961 ExitStatusSet
*status_set
= data
;
3968 /* Empty assignment resets the list */
3969 if (isempty(rvalue
)) {
3970 exit_status_set_free(status_set
);
3974 FOREACH_WORD(word
, l
, rvalue
, state
) {
3975 _cleanup_free_
char *temp
;
3978 temp
= strndup(word
, l
);
3982 /* We need to call exit_status_from_string() first, because we want
3983 * to parse numbers as exit statuses, not signals. */
3985 r
= exit_status_from_string(temp
);
3987 assert(r
>= 0 && r
< 256);
3988 bitmap
= &status_set
->status
;
3990 r
= signal_from_string(temp
);
3993 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
3994 "Failed to parse value, ignoring: %s", word
);
3997 bitmap
= &status_set
->signal
;
4000 r
= bitmap_set(bitmap
, r
);
4002 return log_error_errno(r
, "Failed to set signal or status %s: %m", word
);
4004 if (!isempty(state
))
4005 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Trailing garbage, ignoring.");
4010 int config_parse_namespace_path_strv(
4012 const char *filename
,
4014 const char *section
,
4015 unsigned section_line
,
4024 const char *p
= rvalue
;
4032 if (isempty(rvalue
)) {
4033 /* Empty assignment resets the list */
4034 *sv
= strv_free(*sv
);
4039 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
, *joined
= NULL
;
4041 bool ignore_enoent
= false, shall_prefix
= false;
4043 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
4049 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
4054 if (startswith(w
, "-")) {
4055 ignore_enoent
= true;
4058 if (startswith(w
, "+")) {
4059 shall_prefix
= true;
4063 r
= unit_full_printf(u
, w
, &resolved
);
4065 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", w
);
4069 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4073 joined
= strjoin(ignore_enoent
? "-" : "",
4074 shall_prefix
? "+" : "",
4077 r
= strv_push(sv
, joined
);
4087 int config_parse_temporary_filesystems(
4089 const char *filename
,
4091 const char *section
,
4092 unsigned section_line
,
4100 ExecContext
*c
= data
;
4101 const char *p
= rvalue
;
4109 if (isempty(rvalue
)) {
4110 /* Empty assignment resets the list */
4111 temporary_filesystem_free_many(c
->temporary_filesystems
, c
->n_temporary_filesystems
);
4112 c
->temporary_filesystems
= NULL
;
4113 c
->n_temporary_filesystems
= 0;
4118 _cleanup_free_
char *word
= NULL
, *path
= NULL
, *resolved
= NULL
;
4121 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
4127 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
4132 r
= extract_first_word(&w
, &path
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4136 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", word
);
4140 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid syntax, ignoring: %s", word
);
4144 r
= unit_full_printf(u
, path
, &resolved
);
4146 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", path
);
4150 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4154 r
= temporary_filesystem_add(&c
->temporary_filesystems
, &c
->n_temporary_filesystems
, resolved
, w
);
4160 int config_parse_bind_paths(
4162 const char *filename
,
4164 const char *section
,
4165 unsigned section_line
,
4172 ExecContext
*c
= data
;
4182 if (isempty(rvalue
)) {
4183 /* Empty assignment resets the list */
4184 bind_mount_free_many(c
->bind_mounts
, c
->n_bind_mounts
);
4185 c
->bind_mounts
= NULL
;
4186 c
->n_bind_mounts
= 0;
4192 _cleanup_free_
char *source
= NULL
, *destination
= NULL
;
4193 _cleanup_free_
char *sresolved
= NULL
, *dresolved
= NULL
;
4194 char *s
= NULL
, *d
= NULL
;
4195 bool rbind
= true, ignore_enoent
= false;
4197 r
= extract_first_word(&p
, &source
, ":" WHITESPACE
, EXTRACT_UNQUOTE
|EXTRACT_DONT_COALESCE_SEPARATORS
);
4203 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
4207 r
= unit_full_printf(u
, source
, &sresolved
);
4209 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4210 "Failed to resolved unit specifiers in \"%s\", ignoring: %m", source
);
4216 ignore_enoent
= true;
4220 r
= path_simplify_and_warn(s
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4224 /* Optionally, the destination is specified. */
4225 if (p
&& p
[-1] == ':') {
4226 r
= extract_first_word(&p
, &destination
, ":" WHITESPACE
, EXTRACT_UNQUOTE
|EXTRACT_DONT_COALESCE_SEPARATORS
);
4230 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
4234 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Missing argument after ':', ignoring: %s", s
);
4238 r
= unit_full_printf(u
, destination
, &dresolved
);
4240 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4241 "Failed to resolved specifiers in \"%s\", ignoring: %m", destination
);
4245 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4251 /* Optionally, there's also a short option string specified */
4252 if (p
&& p
[-1] == ':') {
4253 _cleanup_free_
char *options
= NULL
;
4255 r
= extract_first_word(&p
, &options
, NULL
, EXTRACT_UNQUOTE
);
4259 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s: %s", lvalue
, rvalue
);
4263 if (isempty(options
) || streq(options
, "rbind"))
4265 else if (streq(options
, "norbind"))
4268 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid option string, ignoring setting: %s", options
);
4275 r
= bind_mount_add(&c
->bind_mounts
, &c
->n_bind_mounts
,
4279 .read_only
= !!strstr(lvalue
, "ReadOnly"),
4281 .ignore_enoent
= ignore_enoent
,
4290 int config_parse_job_timeout_sec(
4292 const char *filename
,
4294 const char *section
,
4295 unsigned section_line
,
4311 r
= parse_sec_fix_0(rvalue
, &usec
);
4313 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse JobTimeoutSec= parameter, ignoring: %s", rvalue
);
4317 /* If the user explicitly changed JobTimeoutSec= also change JobRunningTimeoutSec=, for compatibility with old
4318 * versions. If JobRunningTimeoutSec= was explicitly set, avoid this however as whatever the user picked should
4321 if (!u
->job_running_timeout_set
)
4322 u
->job_running_timeout
= usec
;
4324 u
->job_timeout
= usec
;
4329 int config_parse_job_running_timeout_sec(
4331 const char *filename
,
4333 const char *section
,
4334 unsigned section_line
,
4350 r
= parse_sec_fix_0(rvalue
, &usec
);
4352 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse JobRunningTimeoutSec= parameter, ignoring: %s", rvalue
);
4356 u
->job_running_timeout
= usec
;
4357 u
->job_running_timeout_set
= true;
4362 int config_parse_emergency_action(
4364 const char *filename
,
4366 const char *section
,
4367 unsigned section_line
,
4375 EmergencyAction
*x
= data
;
4384 m
= ((Unit
*) userdata
)->manager
;
4388 r
= parse_emergency_action(rvalue
, MANAGER_IS_SYSTEM(m
), x
);
4390 if (r
== -EOPNOTSUPP
&& MANAGER_IS_USER(m
)) {
4391 /* Compat mode: remove for systemd 241. */
4393 log_syntax(unit
, LOG_INFO
, filename
, line
, r
,
4394 "%s= in user mode specified as \"%s\", using \"exit-force\" instead.",
4396 *x
= EMERGENCY_ACTION_EXIT_FORCE
;
4400 if (r
== -EOPNOTSUPP
)
4401 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4402 "%s= specified as %s mode action, ignoring: %s",
4403 lvalue
, MANAGER_IS_SYSTEM(m
) ? "user" : "system", rvalue
);
4405 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4406 "Failed to parse %s=, ignoring: %s", lvalue
, rvalue
);
4413 int config_parse_pid_file(
4415 const char *filename
,
4417 const char *section
,
4418 unsigned section_line
,
4425 _cleanup_free_
char *k
= NULL
, *n
= NULL
;
4435 if (isempty(rvalue
)) {
4436 /* An empty assignment removes already set value. */
4441 r
= unit_full_printf(u
, rvalue
, &k
);
4443 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
4447 /* If this is a relative path make it absolute by prefixing the /run */
4448 n
= path_make_absolute(k
, u
->manager
->prefix
[EXEC_DIRECTORY_RUNTIME
]);
4452 /* Check that the result is a sensible path */
4453 r
= path_simplify_and_warn(n
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4457 r
= patch_var_run(unit
, filename
, line
, lvalue
, &n
);
4461 free_and_replace(*s
, n
);
4465 int config_parse_exit_status(
4467 const char *filename
,
4469 const char *section
,
4470 unsigned section_line
,
4477 int *exit_status
= data
, r
;
4483 assert(exit_status
);
4485 if (isempty(rvalue
)) {
4490 r
= safe_atou8(rvalue
, &u
);
4492 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse exit status '%s', ignoring: %m", rvalue
);
4500 int config_parse_disable_controllers(
4502 const char *filename
,
4504 const char *section
,
4505 unsigned section_line
,
4513 CGroupContext
*c
= data
;
4514 CGroupMask disabled_mask
;
4516 /* 1. If empty, make all controllers eligible for use again.
4517 * 2. If non-empty, merge all listed controllers, space separated. */
4519 if (isempty(rvalue
)) {
4520 c
->disable_controllers
= 0;
4524 r
= cg_mask_from_string(rvalue
, &disabled_mask
);
4525 if (r
< 0 || disabled_mask
<= 0) {
4526 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid cgroup string: %s, ignoring", rvalue
);
4530 c
->disable_controllers
|= disabled_mask
;
4535 int config_parse_ip_filter_bpf_progs(
4537 const char *filename
,
4539 const char *section
,
4540 unsigned section_line
,
4547 _cleanup_free_
char *resolved
= NULL
;
4549 char ***paths
= data
;
4557 if (isempty(rvalue
)) {
4558 *paths
= strv_free(*paths
);
4562 r
= unit_full_printf(u
, rvalue
, &resolved
);
4564 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
4568 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4572 if (strv_contains(*paths
, resolved
))
4575 r
= strv_extend(paths
, resolved
);
4579 r
= bpf_firewall_supported();
4582 if (r
!= BPF_FIREWALL_SUPPORTED_WITH_MULTI
) {
4583 static bool warned
= false;
4585 log_full(warned
? LOG_DEBUG
: LOG_WARNING
,
4586 "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"
4587 "Starting this unit will fail! (This warning is only shown for the first loaded unit using IP firewalling.)", filename
, line
, lvalue
, rvalue
);
4595 static int merge_by_names(Unit
**u
, Set
*names
, const char *id
) {
4602 /* Let's try to add in all names that are aliases of this unit */
4603 while ((k
= set_steal_first(names
))) {
4604 _cleanup_free_ _unused_
char *free_k
= k
;
4606 /* First try to merge in the other name into our unit */
4607 r
= unit_merge_by_name(*u
, k
);
4611 /* Hmm, we couldn't merge the other unit into ours? Then let's try it the other way
4614 other
= manager_get_unit((*u
)->manager
, k
);
4616 return r
; /* return previous failure */
4618 r
= unit_merge(other
, *u
);
4623 return merge_by_names(u
, names
, NULL
);
4626 if (streq_ptr(id
, k
))
4627 unit_choose_id(*u
, id
);
4633 int unit_load_fragment(Unit
*u
) {
4634 const char *fragment
;
4635 _cleanup_set_free_free_ Set
*names
= NULL
;
4640 assert(u
->load_state
== UNIT_STUB
);
4644 u
->load_state
= UNIT_LOADED
;
4648 /* Possibly rebuild the fragment map to catch new units */
4649 r
= unit_file_build_name_map(&u
->manager
->lookup_paths
,
4650 &u
->manager
->unit_cache_mtime
,
4651 &u
->manager
->unit_id_map
,
4652 &u
->manager
->unit_name_map
,
4653 &u
->manager
->unit_path_cache
);
4655 log_error_errno(r
, "Failed to rebuild name map: %m");
4657 r
= unit_file_find_fragment(u
->manager
->unit_id_map
,
4658 u
->manager
->unit_name_map
,
4662 if (r
< 0 && r
!= -ENOENT
)
4666 /* Open the file, check if this is a mask, otherwise read. */
4667 _cleanup_fclose_
FILE *f
= NULL
;
4669 /* Try to open the file name. A symlink is OK, for example for linked files or masks. We
4670 * expect that all symlinks within the lookup paths have been already resolved, but we don't
4671 * verify this here. */
4672 f
= fopen(fragment
, "re");
4674 return log_unit_notice_errno(u
, errno
, "Failed to open %s: %m", fragment
);
4676 if (fstat(fileno(f
), &st
) < 0)
4679 r
= free_and_strdup(&u
->fragment_path
, fragment
);
4683 if (null_or_empty(&st
)) {
4684 u
->load_state
= UNIT_MASKED
;
4685 u
->fragment_mtime
= 0;
4687 u
->load_state
= UNIT_LOADED
;
4688 u
->fragment_mtime
= timespec_load(&st
.st_mtim
);
4690 /* Now, parse the file contents */
4691 r
= config_parse(u
->id
, fragment
, f
,
4692 UNIT_VTABLE(u
)->sections
,
4693 config_item_perf_lookup
, load_fragment_gperf_lookup
,
4694 CONFIG_PARSE_ALLOW_INCLUDE
, u
);
4696 log_unit_notice_errno(u
, r
, "Unit configuration has fatal error, unit will not be started.");
4702 if (u
->source_path
) {
4703 if (stat(u
->source_path
, &st
) >= 0)
4704 u
->source_mtime
= timespec_load(&st
.st_mtim
);
4706 u
->source_mtime
= 0;
4709 /* We do the merge dance here because for some unit types, the unit might have aliases which are not
4710 * declared in the file system. In particular, this is true (and frequent) for device and swap units.
4713 const char *id
= u
->id
;
4714 _cleanup_free_
char *free_id
= NULL
;
4717 id
= basename(fragment
);
4718 if (unit_name_is_valid(id
, UNIT_NAME_TEMPLATE
)) {
4719 assert(u
->instance
); /* If we're not trying to use a template for non-instanced unit,
4720 * this must be set. */
4722 r
= unit_name_replace_instance(id
, u
->instance
, &free_id
);
4724 return log_debug_errno(r
, "Failed to build id (%s + %s): %m", id
, u
->instance
);
4730 r
= merge_by_names(&merged
, names
, id
);
4735 u
->load_state
= UNIT_MERGED
;
4740 void unit_dump_config_items(FILE *f
) {
4741 static const struct {
4742 const ConfigParserCallback callback
;
4745 { config_parse_warn_compat
, "NOTSUPPORTED" },
4746 { config_parse_int
, "INTEGER" },
4747 { config_parse_unsigned
, "UNSIGNED" },
4748 { config_parse_iec_size
, "SIZE" },
4749 { config_parse_iec_uint64
, "SIZE" },
4750 { config_parse_si_size
, "SIZE" },
4751 { config_parse_bool
, "BOOLEAN" },
4752 { config_parse_string
, "STRING" },
4753 { config_parse_path
, "PATH" },
4754 { config_parse_unit_path_printf
, "PATH" },
4755 { config_parse_strv
, "STRING [...]" },
4756 { config_parse_exec_nice
, "NICE" },
4757 { config_parse_exec_oom_score_adjust
, "OOMSCOREADJUST" },
4758 { config_parse_exec_io_class
, "IOCLASS" },
4759 { config_parse_exec_io_priority
, "IOPRIORITY" },
4760 { config_parse_exec_cpu_sched_policy
, "CPUSCHEDPOLICY" },
4761 { config_parse_exec_cpu_sched_prio
, "CPUSCHEDPRIO" },
4762 { config_parse_exec_cpu_affinity
, "CPUAFFINITY" },
4763 { config_parse_mode
, "MODE" },
4764 { config_parse_unit_env_file
, "FILE" },
4765 { config_parse_exec_output
, "OUTPUT" },
4766 { config_parse_exec_input
, "INPUT" },
4767 { config_parse_log_facility
, "FACILITY" },
4768 { config_parse_log_level
, "LEVEL" },
4769 { config_parse_exec_secure_bits
, "SECUREBITS" },
4770 { config_parse_capability_set
, "BOUNDINGSET" },
4771 { config_parse_rlimit
, "LIMIT" },
4772 { config_parse_unit_deps
, "UNIT [...]" },
4773 { config_parse_exec
, "PATH [ARGUMENT [...]]" },
4774 { config_parse_service_type
, "SERVICETYPE" },
4775 { config_parse_service_restart
, "SERVICERESTART" },
4776 { config_parse_kill_mode
, "KILLMODE" },
4777 { config_parse_signal
, "SIGNAL" },
4778 { config_parse_socket_listen
, "SOCKET [...]" },
4779 { config_parse_socket_bind
, "SOCKETBIND" },
4780 { config_parse_socket_bindtodevice
, "NETWORKINTERFACE" },
4781 { config_parse_sec
, "SECONDS" },
4782 { config_parse_nsec
, "NANOSECONDS" },
4783 { config_parse_namespace_path_strv
, "PATH [...]" },
4784 { config_parse_bind_paths
, "PATH[:PATH[:OPTIONS]] [...]" },
4785 { config_parse_unit_requires_mounts_for
, "PATH [...]" },
4786 { config_parse_exec_mount_flags
, "MOUNTFLAG [...]" },
4787 { config_parse_unit_string_printf
, "STRING" },
4788 { config_parse_trigger_unit
, "UNIT" },
4789 { config_parse_timer
, "TIMER" },
4790 { config_parse_path_spec
, "PATH" },
4791 { config_parse_notify_access
, "ACCESS" },
4792 { config_parse_ip_tos
, "TOS" },
4793 { config_parse_unit_condition_path
, "CONDITION" },
4794 { config_parse_unit_condition_string
, "CONDITION" },
4795 { config_parse_unit_condition_null
, "CONDITION" },
4796 { config_parse_unit_slice
, "SLICE" },
4797 { config_parse_documentation
, "URL" },
4798 { config_parse_service_timeout
, "SECONDS" },
4799 { config_parse_emergency_action
, "ACTION" },
4800 { config_parse_set_status
, "STATUS" },
4801 { config_parse_service_sockets
, "SOCKETS" },
4802 { config_parse_environ
, "ENVIRON" },
4804 { config_parse_syscall_filter
, "SYSCALLS" },
4805 { config_parse_syscall_archs
, "ARCHS" },
4806 { config_parse_syscall_errno
, "ERRNO" },
4807 { config_parse_address_families
, "FAMILIES" },
4808 { config_parse_restrict_namespaces
, "NAMESPACES" },
4810 { config_parse_cpu_shares
, "SHARES" },
4811 { config_parse_cg_weight
, "WEIGHT" },
4812 { config_parse_memory_limit
, "LIMIT" },
4813 { config_parse_device_allow
, "DEVICE" },
4814 { config_parse_device_policy
, "POLICY" },
4815 { config_parse_io_limit
, "LIMIT" },
4816 { config_parse_io_device_weight
, "DEVICEWEIGHT" },
4817 { config_parse_io_device_latency
, "DEVICELATENCY" },
4818 { config_parse_blockio_bandwidth
, "BANDWIDTH" },
4819 { config_parse_blockio_weight
, "WEIGHT" },
4820 { config_parse_blockio_device_weight
, "DEVICEWEIGHT" },
4821 { config_parse_long
, "LONG" },
4822 { config_parse_socket_service
, "SERVICE" },
4824 { config_parse_exec_selinux_context
, "LABEL" },
4826 { config_parse_job_mode
, "MODE" },
4827 { config_parse_job_mode_isolate
, "BOOLEAN" },
4828 { config_parse_personality
, "PERSONALITY" },
4831 const char *prev
= NULL
;
4836 NULSTR_FOREACH(i
, load_fragment_gperf_nulstr
) {
4837 const char *rvalue
= "OTHER", *lvalue
;
4838 const ConfigPerfItem
*p
;
4843 assert_se(p
= load_fragment_gperf_lookup(i
, strlen(i
)));
4845 /* Hide legacy settings */
4846 if (p
->parse
== config_parse_warn_compat
&&
4847 p
->ltype
== DISABLED_LEGACY
)
4850 for (j
= 0; j
< ELEMENTSOF(table
); j
++)
4851 if (p
->parse
== table
[j
].callback
) {
4852 rvalue
= table
[j
].rvalue
;
4856 dot
= strchr(i
, '.');
4857 lvalue
= dot
? dot
+ 1 : i
;
4861 if (!prev
|| !strneq(prev
, i
, prefix_len
+1)) {
4865 fprintf(f
, "[%.*s]\n", (int) prefix_len
, i
);
4868 fprintf(f
, "%s=%s\n", lvalue
, rvalue
);
4873 int config_parse_cpu_affinity2(
4875 const char *filename
,
4877 const char *section
,
4878 unsigned section_line
,
4885 CPUSet
*affinity
= data
;
4889 (void) parse_cpu_set_extend(rvalue
, affinity
, true, unit
, filename
, line
, lvalue
);
4894 int config_parse_show_status(
4896 const char *filename
,
4898 const char *section
,
4899 unsigned section_line
,
4907 ShowStatus
*b
= data
;
4914 k
= parse_show_status(rvalue
, b
);
4916 log_syntax(unit
, LOG_ERR
, filename
, line
, k
, "Failed to parse show status setting, ignoring: %s", rvalue
);
4923 int config_parse_output_restricted(
4925 const char *filename
,
4927 const char *section
,
4928 unsigned section_line
,
4935 ExecOutput t
, *eo
= data
;
4942 t
= exec_output_from_string(rvalue
);
4944 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse output type, ignoring: %s", rvalue
);
4948 if (IN_SET(t
, EXEC_OUTPUT_SOCKET
, EXEC_OUTPUT_NAMED_FD
, EXEC_OUTPUT_FILE
, EXEC_OUTPUT_FILE_APPEND
)) {
4949 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Standard output types socket, fd:, file:, append: are not supported as defaults, ignoring: %s", rvalue
);
4957 int config_parse_crash_chvt(
4959 const char *filename
,
4961 const char *section
,
4962 unsigned section_line
,
4976 r
= parse_crash_chvt(rvalue
, data
);
4978 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse CrashChangeVT= setting, ignoring: %s", rvalue
);
4985 int config_parse_timeout_abort(
4987 const char *filename
,
4989 const char *section
,
4990 unsigned section_line
,
4997 usec_t
*timeout_usec
= data
;
5003 assert(timeout_usec
);
5005 rvalue
+= strspn(rvalue
, WHITESPACE
);
5006 if (isempty(rvalue
)) {
5007 *timeout_usec
= false;
5011 r
= parse_sec(rvalue
, timeout_usec
);
5013 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse DefaultTimeoutAbortSec= setting, ignoring: %s", rvalue
);
5017 *timeout_usec
= true;