1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 Copyright © 2012 Holger Hans Peter Freyther
14 #include <sys/resource.h>
18 #include "alloc-util.h"
19 #include "all-units.h"
20 #include "bpf-firewall.h"
21 #include "bus-error.h"
22 #include "bus-internal.h"
25 #include "capability-util.h"
26 #include "cgroup-setup.h"
27 #include "conf-parser.h"
28 #include "cpu-set-util.h"
30 #include "errno-list.h"
34 #include "hexdecoct.h"
37 #include "ip-protocol-list.h"
38 #include "journal-util.h"
39 #include "limits-util.h"
40 #include "load-fragment.h"
42 #include "mountpoint-util.h"
43 #include "nulstr-util.h"
44 #include "parse-util.h"
45 #include "path-util.h"
46 #include "process-util.h"
48 #include "seccomp-util.h"
50 #include "securebits-util.h"
51 #include "signal-util.h"
52 #include "stat-util.h"
53 #include "string-util.h"
55 #include "unit-name.h"
56 #include "unit-printf.h"
57 #include "user-util.h"
58 #include "time-util.h"
61 static int parse_socket_protocol(const char *s
) {
64 r
= parse_ip_protocol(s
);
67 if (!IN_SET(r
, IPPROTO_UDPLITE
, IPPROTO_SCTP
))
68 return -EPROTONOSUPPORT
;
73 int parse_crash_chvt(const char *value
, int *data
) {
76 if (safe_atoi(value
, data
) >= 0)
79 b
= parse_boolean(value
);
84 *data
= 0; /* switch to where kmsg goes */
86 *data
= -1; /* turn off switching */
91 int parse_confirm_spawn(const char *value
, char **console
) {
95 r
= value
? parse_boolean(value
) : 1;
99 } else if (r
> 0) /* on with default tty */
100 s
= strdup("/dev/console");
101 else if (is_path(value
)) /* on with fully qualified path */
103 else /* on with only a tty file name, not a fully qualified path */
104 s
= path_join("/dev/", value
);
112 DEFINE_CONFIG_PARSE(config_parse_socket_protocol
, parse_socket_protocol
, "Failed to parse socket protocol");
113 DEFINE_CONFIG_PARSE(config_parse_exec_secure_bits
, secure_bits_from_string
, "Failed to parse secure bits");
114 DEFINE_CONFIG_PARSE_ENUM(config_parse_collect_mode
, collect_mode
, CollectMode
, "Failed to parse garbage collection mode");
115 DEFINE_CONFIG_PARSE_ENUM(config_parse_device_policy
, cgroup_device_policy
, CGroupDevicePolicy
, "Failed to parse device policy");
116 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_keyring_mode
, exec_keyring_mode
, ExecKeyringMode
, "Failed to parse keyring mode");
117 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_utmp_mode
, exec_utmp_mode
, ExecUtmpMode
, "Failed to parse utmp mode");
118 DEFINE_CONFIG_PARSE_ENUM(config_parse_job_mode
, job_mode
, JobMode
, "Failed to parse job mode");
119 DEFINE_CONFIG_PARSE_ENUM(config_parse_kill_mode
, kill_mode
, KillMode
, "Failed to parse kill mode");
120 DEFINE_CONFIG_PARSE_ENUM(config_parse_notify_access
, notify_access
, NotifyAccess
, "Failed to parse notify access specifier");
121 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_home
, protect_home
, ProtectHome
, "Failed to parse protect home value");
122 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_system
, protect_system
, ProtectSystem
, "Failed to parse protect system value");
123 DEFINE_CONFIG_PARSE_ENUM(config_parse_runtime_preserve_mode
, exec_preserve_mode
, ExecPreserveMode
, "Failed to parse runtime directory preserve mode");
124 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_type
, service_type
, ServiceType
, "Failed to parse service type");
125 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart
, service_restart
, ServiceRestart
, "Failed to parse service restart specifier");
126 DEFINE_CONFIG_PARSE_ENUM(config_parse_socket_bind
, socket_address_bind_ipv6_only_or_bool
, SocketAddressBindIPv6Only
, "Failed to parse bind IPv6 only value");
127 DEFINE_CONFIG_PARSE_ENUM(config_parse_oom_policy
, oom_policy
, OOMPolicy
, "Failed to parse OOM policy");
128 DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_ip_tos
, ip_tos
, int, -1, "Failed to parse IP TOS value");
129 DEFINE_CONFIG_PARSE_PTR(config_parse_blockio_weight
, cg_blkio_weight_parse
, uint64_t, "Invalid block IO weight");
130 DEFINE_CONFIG_PARSE_PTR(config_parse_cg_weight
, cg_weight_parse
, uint64_t, "Invalid weight");
131 DEFINE_CONFIG_PARSE_PTR(config_parse_cpu_shares
, cg_cpu_shares_parse
, uint64_t, "Invalid CPU shares");
132 DEFINE_CONFIG_PARSE_PTR(config_parse_exec_mount_flags
, mount_propagation_flags_from_string
, unsigned long, "Failed to parse mount flag");
133 DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_numa_policy
, mpol
, int, -1, "Invalid NUMA policy type");
134 DEFINE_CONFIG_PARSE_ENUM(config_parse_status_unit_format
, status_unit_format
, StatusUnitFormat
, "Failed to parse status unit format");
136 int config_parse_unit_deps(
138 const char *filename
,
141 unsigned section_line
,
148 UnitDependency d
= ltype
;
158 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
161 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_RETAIN_ESCAPE
);
167 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
171 r
= unit_name_printf(u
, word
, &k
);
173 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
177 r
= unit_add_dependency_by_name(u
, d
, k
, true, UNIT_DEPENDENCY_FILE
);
179 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
185 int config_parse_obsolete_unit_deps(
187 const char *filename
,
190 unsigned section_line
,
197 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
198 "Unit dependency type %s= is obsolete, replacing by %s=, please update your unit file", lvalue
, unit_dependency_to_string(ltype
));
200 return config_parse_unit_deps(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
);
203 int config_parse_unit_string_printf(
205 const char *filename
,
208 unsigned section_line
,
215 _cleanup_free_
char *k
= NULL
;
216 const Unit
*u
= userdata
;
224 r
= unit_full_printf(u
, rvalue
, &k
);
226 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
230 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
233 int config_parse_unit_strv_printf(
235 const char *filename
,
238 unsigned section_line
,
245 const Unit
*u
= userdata
;
246 _cleanup_free_
char *k
= NULL
;
254 r
= unit_full_printf(u
, rvalue
, &k
);
256 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
260 return config_parse_strv(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
263 int config_parse_unit_path_printf(
265 const char *filename
,
268 unsigned section_line
,
275 _cleanup_free_
char *k
= NULL
;
276 const Unit
*u
= userdata
;
285 /* Let's not bother with anything that is too long */
286 if (strlen(rvalue
) >= PATH_MAX
) {
287 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
288 "%s value too long%s.",
289 lvalue
, fatal
? "" : ", ignoring");
290 return fatal
? -ENAMETOOLONG
: 0;
293 r
= unit_full_printf(u
, rvalue
, &k
);
295 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
296 "Failed to resolve unit specifiers in '%s'%s: %m",
297 rvalue
, fatal
? "" : ", ignoring");
298 return fatal
? -ENOEXEC
: 0;
301 return config_parse_path(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
304 int config_parse_unit_path_strv_printf(
306 const char *filename
,
309 unsigned section_line
,
317 const Unit
*u
= userdata
;
326 if (isempty(rvalue
)) {
332 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
334 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
340 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
341 "Invalid syntax, ignoring: %s", rvalue
);
345 r
= unit_full_printf(u
, word
, &k
);
347 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
348 "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
352 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
356 r
= strv_consume(x
, TAKE_PTR(k
));
362 static int patch_var_run(
364 const char *filename
,
372 e
= path_startswith(*path
, "/var/run/");
376 z
= path_join("/run/", e
);
380 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
381 "%s= references a path below legacy directory /var/run/, updating %s → %s; "
382 "please update the unit file accordingly.", lvalue
, *path
, z
);
384 free_and_replace(*path
, z
);
389 int config_parse_socket_listen(
391 const char *filename
,
394 unsigned section_line
,
401 _cleanup_free_ SocketPort
*p
= NULL
;
413 if (isempty(rvalue
)) {
414 /* An empty assignment removes all ports */
415 socket_free_ports(s
);
419 p
= new0(SocketPort
, 1);
423 if (ltype
!= SOCKET_SOCKET
) {
424 _cleanup_free_
char *k
= NULL
;
426 r
= unit_full_printf(UNIT(s
), rvalue
, &k
);
428 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
432 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
436 if (ltype
== SOCKET_FIFO
) {
437 r
= patch_var_run(unit
, filename
, line
, lvalue
, &k
);
442 free_and_replace(p
->path
, k
);
445 } else if (streq(lvalue
, "ListenNetlink")) {
446 _cleanup_free_
char *k
= NULL
;
448 r
= unit_full_printf(UNIT(s
), rvalue
, &k
);
450 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
454 r
= socket_address_parse_netlink(&p
->address
, k
);
456 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse address value in '%s', ignoring: %m", k
);
460 p
->type
= SOCKET_SOCKET
;
463 _cleanup_free_
char *k
= NULL
;
465 r
= unit_full_printf(UNIT(s
), rvalue
, &k
);
467 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
471 if (k
[0] == '/') { /* Only for AF_UNIX file system sockets… */
472 r
= patch_var_run(unit
, filename
, line
, lvalue
, &k
);
477 r
= socket_address_parse_and_warn(&p
->address
, k
);
479 if (r
!= -EAFNOSUPPORT
)
480 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse address value in '%s', ignoring: %m", k
);
484 if (streq(lvalue
, "ListenStream"))
485 p
->address
.type
= SOCK_STREAM
;
486 else if (streq(lvalue
, "ListenDatagram"))
487 p
->address
.type
= SOCK_DGRAM
;
489 assert(streq(lvalue
, "ListenSequentialPacket"));
490 p
->address
.type
= SOCK_SEQPACKET
;
493 if (socket_address_family(&p
->address
) != AF_LOCAL
&& p
->address
.type
== SOCK_SEQPACKET
) {
494 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Address family not supported, ignoring: %s", rvalue
);
498 p
->type
= SOCKET_SOCKET
;
502 p
->auxiliary_fds
= NULL
;
503 p
->n_auxiliary_fds
= 0;
506 LIST_FIND_TAIL(port
, s
->ports
, tail
);
507 LIST_INSERT_AFTER(port
, s
->ports
, tail
, p
);
514 int config_parse_exec_nice(
516 const char *filename
,
519 unsigned section_line
,
526 ExecContext
*c
= data
;
534 if (isempty(rvalue
)) {
539 r
= parse_nice(rvalue
, &priority
);
542 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Nice priority out of range, ignoring: %s", rvalue
);
544 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse nice priority '%s', ignoring: %m", rvalue
);
554 int config_parse_exec_oom_score_adjust(
556 const char *filename
,
559 unsigned section_line
,
566 ExecContext
*c
= data
;
574 if (isempty(rvalue
)) {
575 c
->oom_score_adjust_set
= false;
579 r
= parse_oom_score_adjust(rvalue
, &oa
);
582 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "OOM score adjust value out of range, ignoring: %s", rvalue
);
584 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse the OOM score adjust value '%s', ignoring: %m", rvalue
);
588 c
->oom_score_adjust
= oa
;
589 c
->oom_score_adjust_set
= true;
594 int config_parse_exec(
596 const char *filename
,
599 unsigned section_line
,
606 ExecCommand
**e
= data
;
607 const Unit
*u
= userdata
;
618 rvalue
+= strspn(rvalue
, WHITESPACE
);
620 if (isempty(rvalue
)) {
621 /* An empty assignment resets the list */
622 *e
= exec_command_free_list(*e
);
628 _cleanup_free_
char *path
= NULL
, *firstword
= NULL
;
629 ExecCommandFlags flags
= 0;
630 bool ignore
= false, separate_argv0
= false;
631 _cleanup_free_ ExecCommand
*nce
= NULL
;
632 _cleanup_strv_free_
char **n
= NULL
;
633 size_t nlen
= 0, nbufsize
= 0;
638 r
= extract_first_word_and_warn(&p
, &firstword
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
644 /* We accept an absolute path as first argument. If it's prefixed with - and the path doesn't
645 * exist, we ignore it instead of erroring out; if it's prefixed with @, we allow overriding of
646 * argv[0]; if it's prefixed with :, we will not do environment variable substitution;
647 * if it's prefixed with +, it will be run with full privileges and no sandboxing; if
648 * it's prefixed with '!' we apply sandboxing, but do not change user/group credentials; if
649 * it's prefixed with '!!', then we apply user/group credentials if the kernel supports ambient
650 * capabilities -- if it doesn't we don't apply the credentials themselves, but do apply most
651 * other sandboxing, with some special exceptions for changing UID.
653 * The idea is that '!!' may be used to write services that can take benefit of systemd's
654 * UID/GID dropping if the kernel supports ambient creds, but provide an automatic fallback to
655 * privilege dropping within the daemon if the kernel does not offer that. */
657 if (*f
== '-' && !(flags
& EXEC_COMMAND_IGNORE_FAILURE
)) {
658 flags
|= EXEC_COMMAND_IGNORE_FAILURE
;
660 } else if (*f
== '@' && !separate_argv0
)
661 separate_argv0
= true;
662 else if (*f
== ':' && !(flags
& EXEC_COMMAND_NO_ENV_EXPAND
))
663 flags
|= EXEC_COMMAND_NO_ENV_EXPAND
;
664 else if (*f
== '+' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
665 flags
|= EXEC_COMMAND_FULLY_PRIVILEGED
;
666 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
667 flags
|= EXEC_COMMAND_NO_SETUID
;
668 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_AMBIENT_MAGIC
))) {
669 flags
&= ~EXEC_COMMAND_NO_SETUID
;
670 flags
|= EXEC_COMMAND_AMBIENT_MAGIC
;
676 r
= unit_full_printf(u
, f
, &path
);
678 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
679 "Failed to resolve unit specifiers in '%s'%s: %m",
680 f
, ignore
? ", ignoring" : "");
681 return ignore
? 0 : -ENOEXEC
;
685 /* First word is either "-" or "@" with no command. */
686 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
687 "Empty path in command line%s: '%s'",
688 ignore
? ", ignoring" : "", rvalue
);
689 return ignore
? 0 : -ENOEXEC
;
691 if (!string_is_safe(path
)) {
692 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
693 "Executable name contains special characters%s: %s",
694 ignore
? ", ignoring" : "", path
);
695 return ignore
? 0 : -ENOEXEC
;
697 if (endswith(path
, "/")) {
698 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
699 "Executable path specifies a directory%s: %s",
700 ignore
? ", ignoring" : "", path
);
701 return ignore
? 0 : -ENOEXEC
;
704 if (!path_is_absolute(path
)) {
708 if (!filename_is_valid(path
)) {
709 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
710 "Neither a valid executable name nor an absolute path%s: %s",
711 ignore
? ", ignoring" : "", path
);
712 return ignore
? 0 : -ENOEXEC
;
715 /* Resolve a single-component name to a full path */
716 NULSTR_FOREACH(prefix
, DEFAULT_PATH_NULSTR
) {
717 _cleanup_free_
char *fullpath
= NULL
;
719 fullpath
= path_join(prefix
, path
);
723 if (access(fullpath
, F_OK
) >= 0) {
724 free_and_replace(path
, fullpath
);
731 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
732 "Executable \"%s\" not found in path \"%s\"%s",
733 path
, DEFAULT_PATH
, ignore
? ", ignoring" : "");
734 return ignore
? 0 : -ENOEXEC
;
738 if (!separate_argv0
) {
741 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
751 path_simplify(path
, false);
753 while (!isempty(p
)) {
754 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
756 /* Check explicitly for an unquoted semicolon as
757 * command separator token. */
758 if (p
[0] == ';' && (!p
[1] || strchr(WHITESPACE
, p
[1]))) {
760 p
+= strspn(p
, WHITESPACE
);
765 /* Check for \; explicitly, to not confuse it with \\; or "\;" or "\\;" etc.
766 * extract_first_word() would return the same for all of those. */
767 if (p
[0] == '\\' && p
[1] == ';' && (!p
[2] || strchr(WHITESPACE
, p
[2]))) {
771 p
+= strspn(p
, WHITESPACE
);
773 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
784 r
= extract_first_word_and_warn(&p
, &word
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
788 return ignore
? 0 : -ENOEXEC
;
790 r
= unit_full_printf(u
, word
, &resolved
);
792 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
793 "Failed to resolve unit specifiers in %s%s: %m",
794 word
, ignore
? ", ignoring" : "");
795 return ignore
? 0 : -ENOEXEC
;
798 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
801 n
[nlen
++] = TAKE_PTR(resolved
);
806 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
807 "Empty executable name or zeroeth argument%s: %s",
808 ignore
? ", ignoring" : "", rvalue
);
809 return ignore
? 0 : -ENOEXEC
;
812 nce
= new0(ExecCommand
, 1);
816 nce
->argv
= TAKE_PTR(n
);
817 nce
->path
= TAKE_PTR(path
);
820 exec_command_append_list(e
, nce
);
822 /* Do not _cleanup_free_ these. */
831 int config_parse_socket_bindtodevice(
833 const char *filename
,
836 unsigned section_line
,
850 if (isempty(rvalue
) || streq(rvalue
, "*")) {
851 s
->bind_to_device
= mfree(s
->bind_to_device
);
855 if (!ifname_valid(rvalue
)) {
856 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid interface name, ignoring: %s", rvalue
);
860 if (free_and_strdup(&s
->bind_to_device
, rvalue
) < 0)
866 int config_parse_exec_input(
868 const char *filename
,
871 unsigned section_line
,
878 ExecContext
*c
= data
;
879 const Unit
*u
= userdata
;
889 n
= startswith(rvalue
, "fd:");
891 _cleanup_free_
char *resolved
= NULL
;
893 r
= unit_full_printf(u
, n
, &resolved
);
895 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s': %m", n
);
897 if (isempty(resolved
))
898 resolved
= mfree(resolved
);
899 else if (!fdname_is_valid(resolved
)) {
900 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name: %s", resolved
);
904 free_and_replace(c
->stdio_fdname
[STDIN_FILENO
], resolved
);
906 ei
= EXEC_INPUT_NAMED_FD
;
908 } else if ((n
= startswith(rvalue
, "file:"))) {
909 _cleanup_free_
char *resolved
= NULL
;
911 r
= unit_full_printf(u
, n
, &resolved
);
913 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s': %m", n
);
915 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
919 free_and_replace(c
->stdio_file
[STDIN_FILENO
], resolved
);
921 ei
= EXEC_INPUT_FILE
;
924 ei
= exec_input_from_string(rvalue
);
926 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse input specifier, ignoring: %s", rvalue
);
935 int config_parse_exec_input_text(
937 const char *filename
,
940 unsigned section_line
,
947 _cleanup_free_
char *unescaped
= NULL
, *resolved
= NULL
;
948 ExecContext
*c
= data
;
949 const Unit
*u
= userdata
;
959 if (isempty(rvalue
)) {
960 /* Reset if the empty string is assigned */
961 c
->stdin_data
= mfree(c
->stdin_data
);
962 c
->stdin_data_size
= 0;
966 r
= cunescape(rvalue
, 0, &unescaped
);
968 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to decode C escaped text '%s': %m", rvalue
);
970 r
= unit_full_printf(u
, unescaped
, &resolved
);
972 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s': %m", unescaped
);
974 sz
= strlen(resolved
);
975 if (c
->stdin_data_size
+ sz
+ 1 < c
->stdin_data_size
|| /* check for overflow */
976 c
->stdin_data_size
+ sz
+ 1 > EXEC_STDIN_DATA_MAX
) {
977 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
);
981 p
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
+ 1);
985 *((char*) mempcpy((char*) p
+ c
->stdin_data_size
, resolved
, sz
)) = '\n';
988 c
->stdin_data_size
+= sz
+ 1;
993 int config_parse_exec_input_data(
995 const char *filename
,
998 unsigned section_line
,
1005 _cleanup_free_
void *p
= NULL
;
1006 ExecContext
*c
= data
;
1016 if (isempty(rvalue
)) {
1017 /* Reset if the empty string is assigned */
1018 c
->stdin_data
= mfree(c
->stdin_data
);
1019 c
->stdin_data_size
= 0;
1023 r
= unbase64mem(rvalue
, (size_t) -1, &p
, &sz
);
1025 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to decode base64 data, ignoring: %s", rvalue
);
1029 if (c
->stdin_data_size
+ sz
< c
->stdin_data_size
|| /* check for overflow */
1030 c
->stdin_data_size
+ sz
> EXEC_STDIN_DATA_MAX
) {
1031 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
);
1035 q
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
);
1039 memcpy((uint8_t*) q
+ c
->stdin_data_size
, p
, sz
);
1042 c
->stdin_data_size
+= sz
;
1047 int config_parse_exec_output(
1049 const char *filename
,
1051 const char *section
,
1052 unsigned section_line
,
1059 _cleanup_free_
char *resolved
= NULL
;
1061 ExecContext
*c
= data
;
1062 const Unit
*u
= userdata
;
1072 n
= startswith(rvalue
, "fd:");
1074 r
= unit_full_printf(u
, n
, &resolved
);
1076 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", n
);
1078 if (isempty(resolved
))
1079 resolved
= mfree(resolved
);
1080 else if (!fdname_is_valid(resolved
)) {
1081 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name: %s", resolved
);
1085 eo
= EXEC_OUTPUT_NAMED_FD
;
1087 } else if ((n
= startswith(rvalue
, "file:"))) {
1089 r
= unit_full_printf(u
, n
, &resolved
);
1091 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", n
);
1093 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1097 eo
= EXEC_OUTPUT_FILE
;
1099 } else if ((n
= startswith(rvalue
, "append:"))) {
1101 r
= unit_full_printf(u
, n
, &resolved
);
1103 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", n
);
1105 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1109 eo
= EXEC_OUTPUT_FILE_APPEND
;
1111 eo
= exec_output_from_string(rvalue
);
1113 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse output specifier, ignoring: %s", rvalue
);
1118 if (streq(lvalue
, "StandardOutput")) {
1119 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1120 free_and_replace(c
->stdio_fdname
[STDOUT_FILENO
], resolved
);
1122 free_and_replace(c
->stdio_file
[STDOUT_FILENO
], resolved
);
1127 assert(streq(lvalue
, "StandardError"));
1129 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1130 free_and_replace(c
->stdio_fdname
[STDERR_FILENO
], resolved
);
1132 free_and_replace(c
->stdio_file
[STDERR_FILENO
], resolved
);
1140 int config_parse_exec_io_class(const char *unit
,
1141 const char *filename
,
1143 const char *section
,
1144 unsigned section_line
,
1151 ExecContext
*c
= data
;
1159 if (isempty(rvalue
)) {
1160 c
->ioprio_set
= false;
1161 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE
, 0);
1165 x
= ioprio_class_from_string(rvalue
);
1167 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse IO scheduling class, ignoring: %s", rvalue
);
1171 c
->ioprio
= IOPRIO_PRIO_VALUE(x
, IOPRIO_PRIO_DATA(c
->ioprio
));
1172 c
->ioprio_set
= true;
1177 int config_parse_exec_io_priority(const char *unit
,
1178 const char *filename
,
1180 const char *section
,
1181 unsigned section_line
,
1188 ExecContext
*c
= data
;
1196 if (isempty(rvalue
)) {
1197 c
->ioprio_set
= false;
1198 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE
, 0);
1202 r
= ioprio_parse_priority(rvalue
, &i
);
1204 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse IO priority, ignoring: %s", rvalue
);
1208 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_PRIO_CLASS(c
->ioprio
), i
);
1209 c
->ioprio_set
= true;
1214 int config_parse_exec_cpu_sched_policy(const char *unit
,
1215 const char *filename
,
1217 const char *section
,
1218 unsigned section_line
,
1225 ExecContext
*c
= data
;
1233 if (isempty(rvalue
)) {
1234 c
->cpu_sched_set
= false;
1235 c
->cpu_sched_policy
= SCHED_OTHER
;
1236 c
->cpu_sched_priority
= 0;
1240 x
= sched_policy_from_string(rvalue
);
1242 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse CPU scheduling policy, ignoring: %s", rvalue
);
1246 c
->cpu_sched_policy
= x
;
1247 /* Moving to or from real-time policy? We need to adjust the priority */
1248 c
->cpu_sched_priority
= CLAMP(c
->cpu_sched_priority
, sched_get_priority_min(x
), sched_get_priority_max(x
));
1249 c
->cpu_sched_set
= true;
1254 int config_parse_numa_mask(const char *unit
,
1255 const char *filename
,
1257 const char *section
,
1258 unsigned section_line
,
1265 NUMAPolicy
*p
= data
;
1272 r
= parse_cpu_set_extend(rvalue
, &p
->nodes
, true, unit
, filename
, line
, lvalue
);
1274 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse NUMA node mask, ignoring: %s", rvalue
);
1281 int config_parse_exec_cpu_sched_prio(const char *unit
,
1282 const char *filename
,
1284 const char *section
,
1285 unsigned section_line
,
1292 ExecContext
*c
= data
;
1300 r
= safe_atoi(rvalue
, &i
);
1302 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse CPU scheduling priority, ignoring: %s", rvalue
);
1306 /* On Linux RR/FIFO range from 1 to 99 and OTHER/BATCH may only be 0 */
1307 min
= sched_get_priority_min(c
->cpu_sched_policy
);
1308 max
= sched_get_priority_max(c
->cpu_sched_policy
);
1310 if (i
< min
|| i
> max
) {
1311 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "CPU scheduling priority is out of range, ignoring: %s", rvalue
);
1315 c
->cpu_sched_priority
= i
;
1316 c
->cpu_sched_set
= true;
1321 int config_parse_exec_cpu_affinity(const char *unit
,
1322 const char *filename
,
1324 const char *section
,
1325 unsigned section_line
,
1332 ExecContext
*c
= data
;
1339 return parse_cpu_set_extend(rvalue
, &c
->cpu_set
, true, unit
, filename
, line
, lvalue
);
1342 int config_parse_capability_set(
1344 const char *filename
,
1346 const char *section
,
1347 unsigned section_line
,
1354 uint64_t *capability_set
= data
;
1355 uint64_t sum
= 0, initial
= 0;
1356 bool invert
= false;
1364 if (rvalue
[0] == '~') {
1369 if (streq(lvalue
, "CapabilityBoundingSet"))
1370 initial
= CAP_ALL
; /* initialized to all bits on */
1371 /* else "AmbientCapabilities" initialized to all bits off */
1373 r
= capability_set_from_string(rvalue
, &sum
);
1375 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= specifier '%s', ignoring: %m", lvalue
, rvalue
);
1379 if (sum
== 0 || *capability_set
== initial
)
1380 /* "", "~" or uninitialized data -> replace */
1381 *capability_set
= invert
? ~sum
: sum
;
1383 /* previous data -> merge */
1385 *capability_set
&= ~sum
;
1387 *capability_set
|= sum
;
1393 int config_parse_exec_selinux_context(
1395 const char *filename
,
1397 const char *section
,
1398 unsigned section_line
,
1405 ExecContext
*c
= data
;
1406 const Unit
*u
= userdata
;
1416 if (isempty(rvalue
)) {
1417 c
->selinux_context
= mfree(c
->selinux_context
);
1418 c
->selinux_context_ignore
= false;
1422 if (rvalue
[0] == '-') {
1428 r
= unit_full_printf(u
, rvalue
, &k
);
1430 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1431 "Failed to resolve unit specifiers in '%s'%s: %m",
1432 rvalue
, ignore
? ", ignoring" : "");
1433 return ignore
? 0 : -ENOEXEC
;
1436 free_and_replace(c
->selinux_context
, k
);
1437 c
->selinux_context_ignore
= ignore
;
1442 int config_parse_exec_apparmor_profile(
1444 const char *filename
,
1446 const char *section
,
1447 unsigned section_line
,
1454 ExecContext
*c
= data
;
1455 const Unit
*u
= userdata
;
1465 if (isempty(rvalue
)) {
1466 c
->apparmor_profile
= mfree(c
->apparmor_profile
);
1467 c
->apparmor_profile_ignore
= false;
1471 if (rvalue
[0] == '-') {
1477 r
= unit_full_printf(u
, rvalue
, &k
);
1479 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1480 "Failed to resolve unit specifiers in '%s'%s: %m",
1481 rvalue
, ignore
? ", ignoring" : "");
1482 return ignore
? 0 : -ENOEXEC
;
1485 free_and_replace(c
->apparmor_profile
, k
);
1486 c
->apparmor_profile_ignore
= ignore
;
1491 int config_parse_exec_smack_process_label(
1493 const char *filename
,
1495 const char *section
,
1496 unsigned section_line
,
1503 ExecContext
*c
= data
;
1504 const Unit
*u
= userdata
;
1514 if (isempty(rvalue
)) {
1515 c
->smack_process_label
= mfree(c
->smack_process_label
);
1516 c
->smack_process_label_ignore
= false;
1520 if (rvalue
[0] == '-') {
1526 r
= unit_full_printf(u
, rvalue
, &k
);
1528 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1529 "Failed to resolve unit specifiers in '%s'%s: %m",
1530 rvalue
, ignore
? ", ignoring" : "");
1531 return ignore
? 0 : -ENOEXEC
;
1534 free_and_replace(c
->smack_process_label
, k
);
1535 c
->smack_process_label_ignore
= ignore
;
1540 int config_parse_timer(
1542 const char *filename
,
1544 const char *section
,
1545 unsigned section_line
,
1552 _cleanup_(calendar_spec_freep
) CalendarSpec
*c
= NULL
;
1553 _cleanup_free_
char *k
= NULL
;
1554 const Unit
*u
= userdata
;
1565 if (isempty(rvalue
)) {
1566 /* Empty assignment resets list */
1567 timer_free_values(t
);
1571 r
= unit_full_printf(u
, rvalue
, &k
);
1573 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
1577 if (ltype
== TIMER_CALENDAR
) {
1578 r
= calendar_spec_from_string(k
, &c
);
1580 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse calendar specification, ignoring: %s", k
);
1584 r
= parse_sec(k
, &usec
);
1586 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse timer value, ignoring: %s", k
);
1591 v
= new(TimerValue
, 1);
1598 .calendar_spec
= TAKE_PTR(c
),
1601 LIST_PREPEND(value
, t
->values
, v
);
1606 int config_parse_trigger_unit(
1608 const char *filename
,
1610 const char *section
,
1611 unsigned section_line
,
1618 _cleanup_free_
char *p
= NULL
;
1628 if (!hashmap_isempty(u
->dependencies
[UNIT_TRIGGERS
])) {
1629 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Multiple units to trigger specified, ignoring: %s", rvalue
);
1633 r
= unit_name_printf(u
, rvalue
, &p
);
1635 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
1639 type
= unit_name_to_type(p
);
1641 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit type not valid, ignoring: %s", rvalue
);
1644 if (unit_has_name(u
, p
)) {
1645 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Units cannot trigger themselves, ignoring: %s", rvalue
);
1649 r
= unit_add_two_dependencies_by_name(u
, UNIT_BEFORE
, UNIT_TRIGGERS
, p
, true, UNIT_DEPENDENCY_FILE
);
1651 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add trigger on %s, ignoring: %m", p
);
1658 int config_parse_path_spec(const char *unit
,
1659 const char *filename
,
1661 const char *section
,
1662 unsigned section_line
,
1672 _cleanup_free_
char *k
= NULL
;
1680 if (isempty(rvalue
)) {
1681 /* Empty assignment clears list */
1686 b
= path_type_from_string(lvalue
);
1688 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse path type, ignoring: %s", lvalue
);
1692 r
= unit_full_printf(UNIT(p
), rvalue
, &k
);
1694 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
1698 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
1702 s
= new0(PathSpec
, 1);
1707 s
->path
= TAKE_PTR(k
);
1711 LIST_PREPEND(spec
, p
->specs
, s
);
1716 int config_parse_socket_service(
1718 const char *filename
,
1720 const char *section
,
1721 unsigned section_line
,
1728 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1729 _cleanup_free_
char *p
= NULL
;
1739 r
= unit_name_printf(UNIT(s
), rvalue
, &p
);
1741 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", rvalue
);
1745 if (!endswith(p
, ".service")) {
1746 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit must be of type service: %s", rvalue
);
1750 r
= manager_load_unit(UNIT(s
)->manager
, p
, NULL
, &error
, &x
);
1752 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to load unit %s: %s", rvalue
, bus_error_message(&error
, r
));
1756 unit_ref_set(&s
->service
, UNIT(s
), x
);
1761 int config_parse_fdname(
1763 const char *filename
,
1765 const char *section
,
1766 unsigned section_line
,
1773 _cleanup_free_
char *p
= NULL
;
1782 if (isempty(rvalue
)) {
1783 s
->fdname
= mfree(s
->fdname
);
1787 r
= unit_full_printf(UNIT(s
), rvalue
, &p
);
1789 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
1793 if (!fdname_is_valid(p
)) {
1794 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", p
);
1798 return free_and_replace(s
->fdname
, p
);
1801 int config_parse_service_sockets(
1803 const char *filename
,
1805 const char *section
,
1806 unsigned section_line
,
1824 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
1826 r
= extract_first_word(&p
, &word
, NULL
, 0);
1832 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Trailing garbage in sockets, ignoring: %s", rvalue
);
1836 r
= unit_name_printf(UNIT(s
), word
, &k
);
1838 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
1842 if (!endswith(k
, ".socket")) {
1843 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit must be of type socket, ignoring: %s", k
);
1847 r
= unit_add_two_dependencies_by_name(UNIT(s
), UNIT_WANTS
, UNIT_AFTER
, k
, true, UNIT_DEPENDENCY_FILE
);
1849 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
1851 r
= unit_add_dependency_by_name(UNIT(s
), UNIT_TRIGGERED_BY
, k
, true, UNIT_DEPENDENCY_FILE
);
1853 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
1859 int config_parse_bus_name(
1861 const char *filename
,
1863 const char *section
,
1864 unsigned section_line
,
1871 _cleanup_free_
char *k
= NULL
;
1872 const Unit
*u
= userdata
;
1880 r
= unit_full_printf(u
, rvalue
, &k
);
1882 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
1886 if (!service_name_is_valid(k
)) {
1887 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid bus name, ignoring: %s", k
);
1891 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
1894 int config_parse_service_timeout(
1896 const char *filename
,
1898 const char *section
,
1899 unsigned section_line
,
1906 Service
*s
= userdata
;
1915 /* This is called for two cases: TimeoutSec= and TimeoutStartSec=. */
1917 /* Traditionally, these options accepted 0 to disable the timeouts. However, a timeout of 0 suggests it happens
1918 * immediately, hence fix this to become USEC_INFINITY instead. This is in-line with how we internally handle
1919 * all other timeouts. */
1920 r
= parse_sec_fix_0(rvalue
, &usec
);
1922 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
1926 s
->start_timeout_defined
= true;
1927 s
->timeout_start_usec
= usec
;
1929 if (streq(lvalue
, "TimeoutSec"))
1930 s
->timeout_stop_usec
= usec
;
1935 int config_parse_service_timeout_abort(
1937 const char *filename
,
1939 const char *section
,
1940 unsigned section_line
,
1947 Service
*s
= userdata
;
1955 rvalue
+= strspn(rvalue
, WHITESPACE
);
1956 if (isempty(rvalue
)) {
1957 s
->timeout_abort_set
= false;
1961 r
= parse_sec(rvalue
, &s
->timeout_abort_usec
);
1963 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse TimeoutAbortSec= setting, ignoring: %s", rvalue
);
1967 s
->timeout_abort_set
= true;
1971 int config_parse_sec_fix_0(
1973 const char *filename
,
1975 const char *section
,
1976 unsigned section_line
,
1983 usec_t
*usec
= data
;
1991 /* This is pretty much like config_parse_sec(), except that this treats a time of 0 as infinity, for
1992 * compatibility with older versions of systemd where 0 instead of infinity was used as indicator to turn off a
1995 r
= parse_sec_fix_0(rvalue
, usec
);
1997 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
2004 int config_parse_user_group_compat(
2006 const char *filename
,
2008 const char *section
,
2009 unsigned section_line
,
2016 _cleanup_free_
char *k
= NULL
;
2018 const Unit
*u
= userdata
;
2026 if (isempty(rvalue
)) {
2027 *user
= mfree(*user
);
2031 r
= unit_full_printf(u
, rvalue
, &k
);
2033 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", rvalue
);
2037 if (!valid_user_group_name_or_id_compat(k
)) {
2038 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2042 return free_and_replace(*user
, k
);
2045 int config_parse_user_group_strv_compat(
2047 const char *filename
,
2049 const char *section
,
2050 unsigned section_line
,
2057 char ***users
= data
;
2058 const Unit
*u
= userdata
;
2059 const char *p
= rvalue
;
2067 if (isempty(rvalue
)) {
2068 *users
= strv_free(*users
);
2073 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2075 r
= extract_first_word(&p
, &word
, NULL
, 0);
2081 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax: %s", rvalue
);
2085 r
= unit_full_printf(u
, word
, &k
);
2087 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", word
);
2091 if (!valid_user_group_name_or_id_compat(k
)) {
2092 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2096 r
= strv_push(users
, k
);
2106 int config_parse_working_directory(
2108 const char *filename
,
2110 const char *section
,
2111 unsigned section_line
,
2118 ExecContext
*c
= data
;
2119 const Unit
*u
= userdata
;
2129 if (isempty(rvalue
)) {
2130 c
->working_directory_home
= false;
2131 c
->working_directory
= mfree(c
->working_directory
);
2135 if (rvalue
[0] == '-') {
2141 if (streq(rvalue
, "~")) {
2142 c
->working_directory_home
= true;
2143 c
->working_directory
= mfree(c
->working_directory
);
2145 _cleanup_free_
char *k
= NULL
;
2147 r
= unit_full_printf(u
, rvalue
, &k
);
2149 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2150 "Failed to resolve unit specifiers in working directory path '%s'%s: %m",
2151 rvalue
, missing_ok
? ", ignoring" : "");
2152 return missing_ok
? 0 : -ENOEXEC
;
2155 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
| (missing_ok
? 0 : PATH_CHECK_FATAL
), unit
, filename
, line
, lvalue
);
2157 return missing_ok
? 0 : -ENOEXEC
;
2159 c
->working_directory_home
= false;
2160 free_and_replace(c
->working_directory
, k
);
2163 c
->working_directory_missing_ok
= missing_ok
;
2167 int config_parse_unit_env_file(const char *unit
,
2168 const char *filename
,
2170 const char *section
,
2171 unsigned section_line
,
2179 const Unit
*u
= userdata
;
2180 _cleanup_free_
char *n
= NULL
;
2188 if (isempty(rvalue
)) {
2189 /* Empty assignment frees the list */
2190 *env
= strv_free(*env
);
2194 r
= unit_full_printf(u
, rvalue
, &n
);
2196 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2200 r
= path_simplify_and_warn(n
[0] == '-' ? n
+ 1 : n
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2204 r
= strv_push(env
, n
);
2213 int config_parse_environ(
2215 const char *filename
,
2217 const char *section
,
2218 unsigned section_line
,
2225 const Unit
*u
= userdata
;
2235 if (isempty(rvalue
)) {
2236 /* Empty assignment resets the list */
2237 *env
= strv_free(*env
);
2241 for (p
= rvalue
;; ) {
2242 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2244 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2250 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2251 "Invalid syntax, ignoring: %s", rvalue
);
2256 r
= unit_full_printf(u
, word
, &k
);
2258 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2259 "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2265 if (!env_assignment_is_valid(k
)) {
2266 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2267 "Invalid environment assignment, ignoring: %s", k
);
2271 r
= strv_env_replace(env
, k
);
2279 int config_parse_pass_environ(
2281 const char *filename
,
2283 const char *section
,
2284 unsigned section_line
,
2291 _cleanup_strv_free_
char **n
= NULL
;
2292 size_t nlen
= 0, nbufsize
= 0;
2293 char*** passenv
= data
;
2294 const char *p
= rvalue
;
2295 const Unit
*u
= userdata
;
2303 if (isempty(rvalue
)) {
2304 /* Empty assignment resets the list */
2305 *passenv
= strv_free(*passenv
);
2310 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2312 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
2318 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2319 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2324 r
= unit_full_printf(u
, word
, &k
);
2326 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2327 "Failed to resolve specifiers in %s, ignoring: %m", word
);
2333 if (!env_name_is_valid(k
)) {
2334 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2335 "Invalid environment name for %s, ignoring: %s", lvalue
, k
);
2339 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
2342 n
[nlen
++] = TAKE_PTR(k
);
2347 r
= strv_extend_strv(passenv
, n
, true);
2355 int config_parse_unset_environ(
2357 const char *filename
,
2359 const char *section
,
2360 unsigned section_line
,
2367 _cleanup_strv_free_
char **n
= NULL
;
2368 size_t nlen
= 0, nbufsize
= 0;
2369 char*** unsetenv
= data
;
2370 const char *p
= rvalue
;
2371 const Unit
*u
= userdata
;
2379 if (isempty(rvalue
)) {
2380 /* Empty assignment resets the list */
2381 *unsetenv
= strv_free(*unsetenv
);
2386 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2388 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2394 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2395 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2400 r
= unit_full_printf(u
, word
, &k
);
2402 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2403 "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2409 if (!env_assignment_is_valid(k
) && !env_name_is_valid(k
)) {
2410 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2411 "Invalid environment name or assignment %s, ignoring: %s", lvalue
, k
);
2415 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
2418 n
[nlen
++] = TAKE_PTR(k
);
2423 r
= strv_extend_strv(unsetenv
, n
, true);
2431 int config_parse_log_extra_fields(
2433 const char *filename
,
2435 const char *section
,
2436 unsigned section_line
,
2443 ExecContext
*c
= data
;
2444 const Unit
*u
= userdata
;
2445 const char *p
= rvalue
;
2453 if (isempty(rvalue
)) {
2454 exec_context_free_log_extra_fields(c
);
2459 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2463 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2469 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
2473 r
= unit_full_printf(u
, word
, &k
);
2475 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2479 eq
= strchr(k
, '=');
2481 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Log field lacks '=' character, ignoring: %s", k
);
2485 if (!journal_field_valid(k
, eq
-k
, false)) {
2486 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Log field name is invalid, ignoring: %s", k
);
2490 t
= reallocarray(c
->log_extra_fields
, c
->n_log_extra_fields
+1, sizeof(struct iovec
));
2494 c
->log_extra_fields
= t
;
2495 c
->log_extra_fields
[c
->n_log_extra_fields
++] = IOVEC_MAKE_STRING(k
);
2501 int config_parse_unit_condition_path(
2503 const char *filename
,
2505 const char *section
,
2506 unsigned section_line
,
2513 _cleanup_free_
char *p
= NULL
;
2514 Condition
**list
= data
, *c
;
2515 ConditionType t
= ltype
;
2516 bool trigger
, negate
;
2517 const Unit
*u
= userdata
;
2525 if (isempty(rvalue
)) {
2526 /* Empty assignment resets the list */
2527 *list
= condition_free_list(*list
);
2531 trigger
= rvalue
[0] == '|';
2535 negate
= rvalue
[0] == '!';
2539 r
= unit_full_printf(u
, rvalue
, &p
);
2541 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2545 r
= path_simplify_and_warn(p
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2549 c
= condition_new(t
, p
, trigger
, negate
);
2553 LIST_PREPEND(conditions
, *list
, c
);
2557 int config_parse_unit_condition_string(
2559 const char *filename
,
2561 const char *section
,
2562 unsigned section_line
,
2569 _cleanup_free_
char *s
= NULL
;
2570 Condition
**list
= data
, *c
;
2571 ConditionType t
= ltype
;
2572 bool trigger
, negate
;
2573 const Unit
*u
= userdata
;
2581 if (isempty(rvalue
)) {
2582 /* Empty assignment resets the list */
2583 *list
= condition_free_list(*list
);
2587 trigger
= *rvalue
== '|';
2589 rvalue
+= 1 + strspn(rvalue
+ 1, WHITESPACE
);
2591 negate
= *rvalue
== '!';
2593 rvalue
+= 1 + strspn(rvalue
+ 1, WHITESPACE
);
2595 r
= unit_full_printf(u
, rvalue
, &s
);
2597 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2598 "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2602 c
= condition_new(t
, s
, trigger
, negate
);
2606 LIST_PREPEND(conditions
, *list
, c
);
2610 int config_parse_unit_condition_null(
2612 const char *filename
,
2614 const char *section
,
2615 unsigned section_line
,
2622 Condition
**list
= data
, *c
;
2623 bool trigger
, negate
;
2631 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "%s= is deprecated, please do not use.", lvalue
);
2633 if (isempty(rvalue
)) {
2634 /* Empty assignment resets the list */
2635 *list
= condition_free_list(*list
);
2639 trigger
= rvalue
[0] == '|';
2643 negate
= rvalue
[0] == '!';
2647 b
= parse_boolean(rvalue
);
2649 log_syntax(unit
, LOG_ERR
, filename
, line
, b
, "Failed to parse boolean value in condition, ignoring: %s", rvalue
);
2656 c
= condition_new(CONDITION_NULL
, NULL
, trigger
, negate
);
2660 LIST_PREPEND(conditions
, *list
, c
);
2664 int config_parse_unit_requires_mounts_for(
2666 const char *filename
,
2668 const char *section
,
2669 unsigned section_line
,
2676 const char *p
= rvalue
;
2686 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
2688 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
2694 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2695 "Invalid syntax, ignoring: %s", rvalue
);
2699 r
= unit_full_printf(u
, word
, &resolved
);
2701 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
2705 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2709 r
= unit_require_mounts_for(u
, resolved
, UNIT_DEPENDENCY_FILE
);
2711 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add required mount '%s', ignoring: %m", resolved
);
2717 int config_parse_documentation(const char *unit
,
2718 const char *filename
,
2720 const char *section
,
2721 unsigned section_line
,
2737 if (isempty(rvalue
)) {
2738 /* Empty assignment resets the list */
2739 u
->documentation
= strv_free(u
->documentation
);
2743 r
= config_parse_unit_strv_printf(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
,
2744 rvalue
, data
, userdata
);
2748 for (a
= b
= u
->documentation
; a
&& *a
; a
++) {
2750 if (documentation_url_is_valid(*a
))
2753 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid URL, ignoring: %s", *a
);
2764 int config_parse_syscall_filter(
2766 const char *filename
,
2768 const char *section
,
2769 unsigned section_line
,
2776 ExecContext
*c
= data
;
2777 const Unit
*u
= userdata
;
2778 bool invert
= false;
2787 if (isempty(rvalue
)) {
2788 /* Empty assignment resets the list */
2789 c
->syscall_filter
= hashmap_free(c
->syscall_filter
);
2790 c
->syscall_whitelist
= false;
2794 if (rvalue
[0] == '~') {
2799 if (!c
->syscall_filter
) {
2800 c
->syscall_filter
= hashmap_new(NULL
);
2801 if (!c
->syscall_filter
)
2805 /* Allow everything but the ones listed */
2806 c
->syscall_whitelist
= false;
2808 /* Allow nothing but the ones listed */
2809 c
->syscall_whitelist
= true;
2811 /* Accept default syscalls if we are on a whitelist */
2812 r
= seccomp_parse_syscall_filter(
2813 "@default", -1, c
->syscall_filter
,
2814 SECCOMP_PARSE_PERMISSIVE
|SECCOMP_PARSE_WHITELIST
,
2824 _cleanup_free_
char *word
= NULL
, *name
= NULL
;
2827 r
= extract_first_word(&p
, &word
, NULL
, 0);
2833 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
2837 r
= parse_syscall_and_errno(word
, &name
, &num
);
2839 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse syscall:errno, ignoring: %s", word
);
2843 r
= seccomp_parse_syscall_filter(
2844 name
, num
, c
->syscall_filter
,
2845 SECCOMP_PARSE_LOG
|SECCOMP_PARSE_PERMISSIVE
|
2846 (invert
? SECCOMP_PARSE_INVERT
: 0)|
2847 (c
->syscall_whitelist
? SECCOMP_PARSE_WHITELIST
: 0),
2848 unit
, filename
, line
);
2854 int config_parse_syscall_archs(
2856 const char *filename
,
2858 const char *section
,
2859 unsigned section_line
,
2866 const char *p
= rvalue
;
2870 if (isempty(rvalue
)) {
2871 *archs
= set_free(*archs
);
2875 r
= set_ensure_allocated(archs
, NULL
);
2880 _cleanup_free_
char *word
= NULL
;
2883 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
2889 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2890 "Invalid syntax, ignoring: %s", rvalue
);
2894 r
= seccomp_arch_from_string(word
, &a
);
2896 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2897 "Failed to parse system call architecture \"%s\", ignoring: %m", word
);
2901 r
= set_put(*archs
, UINT32_TO_PTR(a
+ 1));
2907 int config_parse_syscall_errno(
2909 const char *filename
,
2911 const char *section
,
2912 unsigned section_line
,
2919 ExecContext
*c
= data
;
2926 if (isempty(rvalue
)) {
2927 /* Empty assignment resets to KILL */
2928 c
->syscall_errno
= 0;
2932 e
= parse_errno(rvalue
);
2934 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse error number, ignoring: %s", rvalue
);
2938 c
->syscall_errno
= e
;
2942 int config_parse_address_families(
2944 const char *filename
,
2946 const char *section
,
2947 unsigned section_line
,
2954 ExecContext
*c
= data
;
2955 bool invert
= false;
2963 if (isempty(rvalue
)) {
2964 /* Empty assignment resets the list */
2965 c
->address_families
= set_free(c
->address_families
);
2966 c
->address_families_whitelist
= false;
2970 if (rvalue
[0] == '~') {
2975 if (!c
->address_families
) {
2976 c
->address_families
= set_new(NULL
);
2977 if (!c
->address_families
)
2980 c
->address_families_whitelist
= !invert
;
2983 for (p
= rvalue
;;) {
2984 _cleanup_free_
char *word
= NULL
;
2987 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
2993 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2994 "Invalid syntax, ignoring: %s", rvalue
);
2998 af
= af_from_name(word
);
3000 log_syntax(unit
, LOG_ERR
, filename
, line
, af
,
3001 "Failed to parse address family, ignoring: %s", word
);
3005 /* If we previously wanted to forbid an address family and now
3006 * we want to allow it, then just remove it from the list.
3008 if (!invert
== c
->address_families_whitelist
) {
3009 r
= set_put(c
->address_families
, INT_TO_PTR(af
));
3013 set_remove(c
->address_families
, INT_TO_PTR(af
));
3017 int config_parse_restrict_namespaces(
3019 const char *filename
,
3021 const char *section
,
3022 unsigned section_line
,
3029 ExecContext
*c
= data
;
3030 unsigned long flags
;
3031 bool invert
= false;
3034 if (isempty(rvalue
)) {
3035 /* Reset to the default. */
3036 c
->restrict_namespaces
= NAMESPACE_FLAGS_INITIAL
;
3040 /* Boolean parameter ignores the previous settings */
3041 r
= parse_boolean(rvalue
);
3043 c
->restrict_namespaces
= 0;
3045 } else if (r
== 0) {
3046 c
->restrict_namespaces
= NAMESPACE_FLAGS_ALL
;
3050 if (rvalue
[0] == '~') {
3055 /* Not a boolean argument, in this case it's a list of namespace types. */
3056 r
= namespace_flags_from_string(rvalue
, &flags
);
3058 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse namespace type string, ignoring: %s", rvalue
);
3062 if (c
->restrict_namespaces
== NAMESPACE_FLAGS_INITIAL
)
3063 /* Initial assignment. Just set the value. */
3064 c
->restrict_namespaces
= invert
? (~flags
) & NAMESPACE_FLAGS_ALL
: flags
;
3066 /* Merge the value with the previous one. */
3067 SET_FLAG(c
->restrict_namespaces
, flags
, !invert
);
3073 int config_parse_unit_slice(
3075 const char *filename
,
3077 const char *section
,
3078 unsigned section_line
,
3085 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
3086 _cleanup_free_
char *k
= NULL
;
3087 Unit
*u
= userdata
, *slice
;
3095 r
= unit_name_printf(u
, rvalue
, &k
);
3097 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
3101 r
= manager_load_unit(u
->manager
, k
, NULL
, &error
, &slice
);
3103 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to load slice unit %s, ignoring: %s", k
, bus_error_message(&error
, r
));
3107 r
= unit_set_slice(u
, slice
);
3109 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to assign slice %s to unit %s, ignoring: %m", slice
->id
, u
->id
);
3116 int config_parse_cpu_quota(
3118 const char *filename
,
3120 const char *section
,
3121 unsigned section_line
,
3128 CGroupContext
*c
= data
;
3135 if (isempty(rvalue
)) {
3136 c
->cpu_quota_per_sec_usec
= USEC_INFINITY
;
3140 r
= parse_permille_unbounded(rvalue
);
3142 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid CPU quota '%s', ignoring.", rvalue
);
3146 c
->cpu_quota_per_sec_usec
= ((usec_t
) r
* USEC_PER_SEC
) / 1000U;
3150 int config_parse_cpuset_cpus(
3152 const char *filename
,
3154 const char *section
,
3155 unsigned section_line
,
3162 CGroupContext
*c
= data
;
3164 (void) parse_cpu_set_extend(rvalue
, &c
->cpuset_cpus
, true, unit
, filename
, line
, lvalue
);
3169 int config_parse_cpuset_mems(
3171 const char *filename
,
3173 const char *section
,
3174 unsigned section_line
,
3181 CGroupContext
*c
= data
;
3183 (void) parse_cpu_set_extend(rvalue
, &c
->cpuset_mems
, true, unit
, filename
, line
, lvalue
);
3188 int config_parse_memory_limit(
3190 const char *filename
,
3192 const char *section
,
3193 unsigned section_line
,
3200 CGroupContext
*c
= data
;
3201 uint64_t bytes
= CGROUP_LIMIT_MAX
;
3204 if (!isempty(rvalue
) && !streq(rvalue
, "infinity")) {
3206 r
= parse_permille(rvalue
);
3208 r
= parse_size(rvalue
, 1024, &bytes
);
3210 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid memory limit '%s', ignoring: %m", rvalue
);
3214 bytes
= physical_memory_scale(r
, 1000U);
3216 if (bytes
>= UINT64_MAX
||
3217 (bytes
<= 0 && !STR_IN_SET(lvalue
, "MemorySwapMax", "MemoryLow", "MemoryMin", "DefaultMemoryLow", "DefaultMemoryMin"))) {
3218 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Memory limit '%s' out of range, ignoring.", rvalue
);
3223 if (streq(lvalue
, "DefaultMemoryLow")) {
3224 c
->default_memory_low_set
= true;
3225 if (isempty(rvalue
))
3226 c
->default_memory_low
= CGROUP_LIMIT_MIN
;
3228 c
->default_memory_low
= bytes
;
3229 } else if (streq(lvalue
, "DefaultMemoryMin")) {
3230 c
->default_memory_min_set
= true;
3231 if (isempty(rvalue
))
3232 c
->default_memory_min
= CGROUP_LIMIT_MIN
;
3234 c
->default_memory_min
= bytes
;
3235 } else if (streq(lvalue
, "MemoryMin")) {
3236 c
->memory_min
= bytes
;
3237 c
->memory_min_set
= true;
3238 } else if (streq(lvalue
, "MemoryLow")) {
3239 c
->memory_low
= bytes
;
3240 c
->memory_low_set
= true;
3241 } else if (streq(lvalue
, "MemoryHigh"))
3242 c
->memory_high
= bytes
;
3243 else if (streq(lvalue
, "MemoryMax"))
3244 c
->memory_max
= bytes
;
3245 else if (streq(lvalue
, "MemorySwapMax"))
3246 c
->memory_swap_max
= bytes
;
3247 else if (streq(lvalue
, "MemoryLimit"))
3248 c
->memory_limit
= bytes
;
3255 int config_parse_tasks_max(
3257 const char *filename
,
3259 const char *section
,
3260 unsigned section_line
,
3267 uint64_t *tasks_max
= data
, v
;
3268 const Unit
*u
= userdata
;
3271 if (isempty(rvalue
)) {
3272 *tasks_max
= u
? u
->manager
->default_tasks_max
: UINT64_MAX
;
3276 if (streq(rvalue
, "infinity")) {
3277 *tasks_max
= CGROUP_LIMIT_MAX
;
3281 r
= parse_permille(rvalue
);
3283 r
= safe_atou64(rvalue
, &v
);
3285 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid maximum tasks value '%s', ignoring: %m", rvalue
);
3289 v
= system_tasks_max_scale(r
, 1000U);
3291 if (v
<= 0 || v
>= UINT64_MAX
) {
3292 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Maximum tasks value '%s' out of range, ignoring.", rvalue
);
3300 int config_parse_delegate(
3302 const char *filename
,
3304 const char *section
,
3305 unsigned section_line
,
3312 CGroupContext
*c
= data
;
3316 t
= unit_name_to_type(unit
);
3317 assert(t
!= _UNIT_TYPE_INVALID
);
3319 if (!unit_vtable
[t
]->can_delegate
) {
3320 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Delegate= setting not supported for this unit type, ignoring.");
3324 /* We either accept a boolean value, which may be used to turn on delegation for all controllers, or turn it
3325 * off for all. Or it takes a list of controller names, in which case we add the specified controllers to the
3326 * mask to delegate. */
3328 if (isempty(rvalue
)) {
3329 /* An empty string resets controllers and set Delegate=yes. */
3331 c
->delegate_controllers
= 0;
3335 r
= parse_boolean(rvalue
);
3337 const char *p
= rvalue
;
3338 CGroupMask mask
= 0;
3341 _cleanup_free_
char *word
= NULL
;
3342 CGroupController cc
;
3344 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3350 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3354 cc
= cgroup_controller_from_string(word
);
3356 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid controller name '%s', ignoring", word
);
3360 mask
|= CGROUP_CONTROLLER_TO_MASK(cc
);
3364 c
->delegate_controllers
|= mask
;
3368 c
->delegate_controllers
= _CGROUP_MASK_ALL
;
3370 c
->delegate
= false;
3371 c
->delegate_controllers
= 0;
3377 int config_parse_device_allow(
3379 const char *filename
,
3381 const char *section
,
3382 unsigned section_line
,
3389 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3390 CGroupContext
*c
= data
;
3391 const char *p
= rvalue
;
3394 if (isempty(rvalue
)) {
3395 while (c
->device_allow
)
3396 cgroup_context_free_device_allow(c
, c
->device_allow
);
3401 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3405 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3406 "Invalid syntax, ignoring: %s", rvalue
);
3410 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3411 "Failed to extract device path and rights from '%s', ignoring.", rvalue
);
3415 r
= unit_full_printf(userdata
, path
, &resolved
);
3417 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3418 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3422 if (!STARTSWITH_SET(resolved
, "block-", "char-")) {
3424 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3428 if (!valid_device_node_path(resolved
)) {
3429 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device node path '%s', ignoring.", resolved
);
3434 if (!isempty(p
) && !in_charset(p
, "rwm")) {
3435 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device rights '%s', ignoring.", p
);
3439 return cgroup_add_device_allow(c
, resolved
, p
);
3442 int config_parse_io_device_weight(
3444 const char *filename
,
3446 const char *section
,
3447 unsigned section_line
,
3454 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3455 CGroupIODeviceWeight
*w
;
3456 CGroupContext
*c
= data
;
3457 const char *p
= rvalue
;
3465 if (isempty(rvalue
)) {
3466 while (c
->io_device_weights
)
3467 cgroup_context_free_io_device_weight(c
, c
->io_device_weights
);
3472 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3476 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3477 "Invalid syntax, ignoring: %s", rvalue
);
3480 if (r
== 0 || isempty(p
)) {
3481 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3482 "Failed to extract device path and weight from '%s', ignoring.", rvalue
);
3486 r
= unit_full_printf(userdata
, path
, &resolved
);
3488 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3489 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3493 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3497 r
= cg_weight_parse(p
, &u
);
3499 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "IO weight '%s' invalid, ignoring: %m", p
);
3503 assert(u
!= CGROUP_WEIGHT_INVALID
);
3505 w
= new0(CGroupIODeviceWeight
, 1);
3509 w
->path
= TAKE_PTR(resolved
);
3512 LIST_PREPEND(device_weights
, c
->io_device_weights
, w
);
3516 int config_parse_io_device_latency(
3518 const char *filename
,
3520 const char *section
,
3521 unsigned section_line
,
3528 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3529 CGroupIODeviceLatency
*l
;
3530 CGroupContext
*c
= data
;
3531 const char *p
= rvalue
;
3539 if (isempty(rvalue
)) {
3540 while (c
->io_device_latencies
)
3541 cgroup_context_free_io_device_latency(c
, c
->io_device_latencies
);
3546 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3550 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3551 "Invalid syntax, ignoring: %s", rvalue
);
3554 if (r
== 0 || isempty(p
)) {
3555 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3556 "Failed to extract device path and latency from '%s', ignoring.", rvalue
);
3560 r
= unit_full_printf(userdata
, path
, &resolved
);
3562 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3563 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3567 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3571 if (parse_sec(p
, &usec
) < 0) {
3572 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse timer value, ignoring: %s", p
);
3576 l
= new0(CGroupIODeviceLatency
, 1);
3580 l
->path
= TAKE_PTR(resolved
);
3581 l
->target_usec
= usec
;
3583 LIST_PREPEND(device_latencies
, c
->io_device_latencies
, l
);
3587 int config_parse_io_limit(
3589 const char *filename
,
3591 const char *section
,
3592 unsigned section_line
,
3599 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3600 CGroupIODeviceLimit
*l
= NULL
, *t
;
3601 CGroupContext
*c
= data
;
3602 CGroupIOLimitType type
;
3603 const char *p
= rvalue
;
3611 type
= cgroup_io_limit_type_from_string(lvalue
);
3614 if (isempty(rvalue
)) {
3615 LIST_FOREACH(device_limits
, l
, c
->io_device_limits
)
3616 l
->limits
[type
] = cgroup_io_limit_defaults
[type
];
3620 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3624 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3625 "Invalid syntax, ignoring: %s", rvalue
);
3628 if (r
== 0 || isempty(p
)) {
3629 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3630 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
3634 r
= unit_full_printf(userdata
, path
, &resolved
);
3636 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3637 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3641 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3645 if (streq("infinity", p
))
3646 num
= CGROUP_LIMIT_MAX
;
3648 r
= parse_size(p
, 1000, &num
);
3649 if (r
< 0 || num
<= 0) {
3650 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid IO limit '%s', ignoring.", p
);
3655 LIST_FOREACH(device_limits
, t
, c
->io_device_limits
) {
3656 if (path_equal(resolved
, t
->path
)) {
3663 CGroupIOLimitType ttype
;
3665 l
= new0(CGroupIODeviceLimit
, 1);
3669 l
->path
= TAKE_PTR(resolved
);
3670 for (ttype
= 0; ttype
< _CGROUP_IO_LIMIT_TYPE_MAX
; ttype
++)
3671 l
->limits
[ttype
] = cgroup_io_limit_defaults
[ttype
];
3673 LIST_PREPEND(device_limits
, c
->io_device_limits
, l
);
3676 l
->limits
[type
] = num
;
3681 int config_parse_blockio_device_weight(
3683 const char *filename
,
3685 const char *section
,
3686 unsigned section_line
,
3693 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3694 CGroupBlockIODeviceWeight
*w
;
3695 CGroupContext
*c
= data
;
3696 const char *p
= rvalue
;
3704 if (isempty(rvalue
)) {
3705 while (c
->blockio_device_weights
)
3706 cgroup_context_free_blockio_device_weight(c
, c
->blockio_device_weights
);
3711 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3715 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3716 "Invalid syntax, ignoring: %s", rvalue
);
3719 if (r
== 0 || isempty(p
)) {
3720 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3721 "Failed to extract device node and weight from '%s', ignoring.", rvalue
);
3725 r
= unit_full_printf(userdata
, path
, &resolved
);
3727 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3728 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3732 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3736 r
= cg_blkio_weight_parse(p
, &u
);
3738 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid block IO weight '%s', ignoring: %m", p
);
3742 assert(u
!= CGROUP_BLKIO_WEIGHT_INVALID
);
3744 w
= new0(CGroupBlockIODeviceWeight
, 1);
3748 w
->path
= TAKE_PTR(resolved
);
3751 LIST_PREPEND(device_weights
, c
->blockio_device_weights
, w
);
3755 int config_parse_blockio_bandwidth(
3757 const char *filename
,
3759 const char *section
,
3760 unsigned section_line
,
3767 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3768 CGroupBlockIODeviceBandwidth
*b
= NULL
, *t
;
3769 CGroupContext
*c
= data
;
3770 const char *p
= rvalue
;
3779 read
= streq("BlockIOReadBandwidth", lvalue
);
3781 if (isempty(rvalue
)) {
3782 LIST_FOREACH(device_bandwidths
, b
, c
->blockio_device_bandwidths
) {
3783 b
->rbps
= CGROUP_LIMIT_MAX
;
3784 b
->wbps
= CGROUP_LIMIT_MAX
;
3789 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3793 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3794 "Invalid syntax, ignoring: %s", rvalue
);
3797 if (r
== 0 || isempty(p
)) {
3798 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3799 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
3803 r
= unit_full_printf(userdata
, path
, &resolved
);
3805 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3806 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3810 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3814 r
= parse_size(p
, 1000, &bytes
);
3815 if (r
< 0 || bytes
<= 0) {
3816 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid Block IO Bandwidth '%s', ignoring.", p
);
3820 LIST_FOREACH(device_bandwidths
, t
, c
->blockio_device_bandwidths
) {
3821 if (path_equal(resolved
, t
->path
)) {
3828 b
= new0(CGroupBlockIODeviceBandwidth
, 1);
3832 b
->path
= TAKE_PTR(resolved
);
3833 b
->rbps
= CGROUP_LIMIT_MAX
;
3834 b
->wbps
= CGROUP_LIMIT_MAX
;
3836 LIST_PREPEND(device_bandwidths
, c
->blockio_device_bandwidths
, b
);
3847 int config_parse_job_mode_isolate(
3849 const char *filename
,
3851 const char *section
,
3852 unsigned section_line
,
3866 r
= parse_boolean(rvalue
);
3868 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse boolean, ignoring: %s", rvalue
);
3872 log_notice("%s is deprecated. Please use OnFailureJobMode= instead", lvalue
);
3874 *m
= r
? JOB_ISOLATE
: JOB_REPLACE
;
3878 int config_parse_exec_directories(
3880 const char *filename
,
3882 const char *section
,
3883 unsigned section_line
,
3891 const Unit
*u
= userdata
;
3900 if (isempty(rvalue
)) {
3901 /* Empty assignment resets the list */
3902 *rt
= strv_free(*rt
);
3906 for (p
= rvalue
;;) {
3907 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
3909 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3913 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3914 "Invalid syntax, ignoring: %s", rvalue
);
3920 r
= unit_full_printf(u
, word
, &k
);
3922 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
3923 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
3927 r
= path_simplify_and_warn(k
, PATH_CHECK_RELATIVE
, unit
, filename
, line
, lvalue
);
3931 if (path_startswith(k
, "private")) {
3932 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
3933 "%s= path can't be 'private', ignoring assignment: %s", lvalue
, word
);
3937 r
= strv_push(rt
, k
);
3944 int config_parse_set_status(
3946 const char *filename
,
3948 const char *section
,
3949 unsigned section_line
,
3957 const char *word
, *state
;
3959 ExitStatusSet
*status_set
= data
;
3966 /* Empty assignment resets the list */
3967 if (isempty(rvalue
)) {
3968 exit_status_set_free(status_set
);
3972 FOREACH_WORD(word
, l
, rvalue
, state
) {
3973 _cleanup_free_
char *temp
;
3976 temp
= strndup(word
, l
);
3980 /* We need to call exit_status_from_string() first, because we want
3981 * to parse numbers as exit statuses, not signals. */
3983 r
= exit_status_from_string(temp
);
3985 assert(r
>= 0 && r
< 256);
3986 bitmap
= &status_set
->status
;
3988 r
= signal_from_string(temp
);
3991 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
3992 "Failed to parse value, ignoring: %s", word
);
3995 bitmap
= &status_set
->signal
;
3998 r
= bitmap_set(bitmap
, r
);
4000 return log_error_errno(r
, "Failed to set signal or status %s: %m", word
);
4002 if (!isempty(state
))
4003 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Trailing garbage, ignoring.");
4008 int config_parse_namespace_path_strv(
4010 const char *filename
,
4012 const char *section
,
4013 unsigned section_line
,
4020 const Unit
*u
= userdata
;
4022 const char *p
= rvalue
;
4030 if (isempty(rvalue
)) {
4031 /* Empty assignment resets the list */
4032 *sv
= strv_free(*sv
);
4037 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
, *joined
= NULL
;
4039 bool ignore_enoent
= false, shall_prefix
= false;
4041 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
4047 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
4052 if (startswith(w
, "-")) {
4053 ignore_enoent
= true;
4056 if (startswith(w
, "+")) {
4057 shall_prefix
= true;
4061 r
= unit_full_printf(u
, w
, &resolved
);
4063 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", w
);
4067 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4071 joined
= strjoin(ignore_enoent
? "-" : "",
4072 shall_prefix
? "+" : "",
4075 r
= strv_push(sv
, joined
);
4085 int config_parse_temporary_filesystems(
4087 const char *filename
,
4089 const char *section
,
4090 unsigned section_line
,
4097 const Unit
*u
= userdata
;
4098 ExecContext
*c
= data
;
4099 const char *p
= rvalue
;
4107 if (isempty(rvalue
)) {
4108 /* Empty assignment resets the list */
4109 temporary_filesystem_free_many(c
->temporary_filesystems
, c
->n_temporary_filesystems
);
4110 c
->temporary_filesystems
= NULL
;
4111 c
->n_temporary_filesystems
= 0;
4116 _cleanup_free_
char *word
= NULL
, *path
= NULL
, *resolved
= NULL
;
4119 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
4125 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
4130 r
= extract_first_word(&w
, &path
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4134 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", word
);
4138 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid syntax, ignoring: %s", word
);
4142 r
= unit_full_printf(u
, path
, &resolved
);
4144 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", path
);
4148 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4152 r
= temporary_filesystem_add(&c
->temporary_filesystems
, &c
->n_temporary_filesystems
, resolved
, w
);
4158 int config_parse_bind_paths(
4160 const char *filename
,
4162 const char *section
,
4163 unsigned section_line
,
4170 ExecContext
*c
= data
;
4171 const Unit
*u
= userdata
;
4180 if (isempty(rvalue
)) {
4181 /* Empty assignment resets the list */
4182 bind_mount_free_many(c
->bind_mounts
, c
->n_bind_mounts
);
4183 c
->bind_mounts
= NULL
;
4184 c
->n_bind_mounts
= 0;
4190 _cleanup_free_
char *source
= NULL
, *destination
= NULL
;
4191 _cleanup_free_
char *sresolved
= NULL
, *dresolved
= NULL
;
4192 char *s
= NULL
, *d
= NULL
;
4193 bool rbind
= true, ignore_enoent
= false;
4195 r
= extract_first_word(&p
, &source
, ":" WHITESPACE
, EXTRACT_UNQUOTE
|EXTRACT_DONT_COALESCE_SEPARATORS
);
4201 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
4205 r
= unit_full_printf(u
, source
, &sresolved
);
4207 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4208 "Failed to resolved unit specifiers in \"%s\", ignoring: %m", source
);
4214 ignore_enoent
= true;
4218 r
= path_simplify_and_warn(s
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4222 /* Optionally, the destination is specified. */
4223 if (p
&& p
[-1] == ':') {
4224 r
= extract_first_word(&p
, &destination
, ":" WHITESPACE
, EXTRACT_UNQUOTE
|EXTRACT_DONT_COALESCE_SEPARATORS
);
4228 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
4232 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Missing argument after ':', ignoring: %s", s
);
4236 r
= unit_full_printf(u
, destination
, &dresolved
);
4238 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4239 "Failed to resolved specifiers in \"%s\", ignoring: %m", destination
);
4243 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4249 /* Optionally, there's also a short option string specified */
4250 if (p
&& p
[-1] == ':') {
4251 _cleanup_free_
char *options
= NULL
;
4253 r
= extract_first_word(&p
, &options
, NULL
, EXTRACT_UNQUOTE
);
4257 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s: %s", lvalue
, rvalue
);
4261 if (isempty(options
) || streq(options
, "rbind"))
4263 else if (streq(options
, "norbind"))
4266 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid option string, ignoring setting: %s", options
);
4273 r
= bind_mount_add(&c
->bind_mounts
, &c
->n_bind_mounts
,
4277 .read_only
= !!strstr(lvalue
, "ReadOnly"),
4279 .ignore_enoent
= ignore_enoent
,
4288 int config_parse_job_timeout_sec(
4290 const char *filename
,
4292 const char *section
,
4293 unsigned section_line
,
4309 r
= parse_sec_fix_0(rvalue
, &usec
);
4311 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse JobTimeoutSec= parameter, ignoring: %s", rvalue
);
4315 /* If the user explicitly changed JobTimeoutSec= also change JobRunningTimeoutSec=, for compatibility with old
4316 * versions. If JobRunningTimeoutSec= was explicitly set, avoid this however as whatever the user picked should
4319 if (!u
->job_running_timeout_set
)
4320 u
->job_running_timeout
= usec
;
4322 u
->job_timeout
= usec
;
4327 int config_parse_job_running_timeout_sec(
4329 const char *filename
,
4331 const char *section
,
4332 unsigned section_line
,
4348 r
= parse_sec_fix_0(rvalue
, &usec
);
4350 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse JobRunningTimeoutSec= parameter, ignoring: %s", rvalue
);
4354 u
->job_running_timeout
= usec
;
4355 u
->job_running_timeout_set
= true;
4360 int config_parse_emergency_action(
4362 const char *filename
,
4364 const char *section
,
4365 unsigned section_line
,
4373 EmergencyAction
*x
= data
;
4382 m
= ((Unit
*) userdata
)->manager
;
4386 r
= parse_emergency_action(rvalue
, MANAGER_IS_SYSTEM(m
), x
);
4388 if (r
== -EOPNOTSUPP
&& MANAGER_IS_USER(m
)) {
4389 /* Compat mode: remove for systemd 241. */
4391 log_syntax(unit
, LOG_INFO
, filename
, line
, r
,
4392 "%s= in user mode specified as \"%s\", using \"exit-force\" instead.",
4394 *x
= EMERGENCY_ACTION_EXIT_FORCE
;
4398 if (r
== -EOPNOTSUPP
)
4399 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4400 "%s= specified as %s mode action, ignoring: %s",
4401 lvalue
, MANAGER_IS_SYSTEM(m
) ? "user" : "system", rvalue
);
4403 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4404 "Failed to parse %s=, ignoring: %s", lvalue
, rvalue
);
4411 int config_parse_pid_file(
4413 const char *filename
,
4415 const char *section
,
4416 unsigned section_line
,
4423 _cleanup_free_
char *k
= NULL
, *n
= NULL
;
4424 const Unit
*u
= userdata
;
4433 if (isempty(rvalue
)) {
4434 /* An empty assignment removes already set value. */
4439 r
= unit_full_printf(u
, rvalue
, &k
);
4441 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
4445 /* If this is a relative path make it absolute by prefixing the /run */
4446 n
= path_make_absolute(k
, u
->manager
->prefix
[EXEC_DIRECTORY_RUNTIME
]);
4450 /* Check that the result is a sensible path */
4451 r
= path_simplify_and_warn(n
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4455 r
= patch_var_run(unit
, filename
, line
, lvalue
, &n
);
4459 free_and_replace(*s
, n
);
4463 int config_parse_exit_status(
4465 const char *filename
,
4467 const char *section
,
4468 unsigned section_line
,
4475 int *exit_status
= data
, r
;
4481 assert(exit_status
);
4483 if (isempty(rvalue
)) {
4488 r
= safe_atou8(rvalue
, &u
);
4490 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse exit status '%s', ignoring: %m", rvalue
);
4498 int config_parse_disable_controllers(
4500 const char *filename
,
4502 const char *section
,
4503 unsigned section_line
,
4511 CGroupContext
*c
= data
;
4512 CGroupMask disabled_mask
;
4514 /* 1. If empty, make all controllers eligible for use again.
4515 * 2. If non-empty, merge all listed controllers, space separated. */
4517 if (isempty(rvalue
)) {
4518 c
->disable_controllers
= 0;
4522 r
= cg_mask_from_string(rvalue
, &disabled_mask
);
4523 if (r
< 0 || disabled_mask
<= 0) {
4524 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid cgroup string: %s, ignoring", rvalue
);
4528 c
->disable_controllers
|= disabled_mask
;
4533 int config_parse_ip_filter_bpf_progs(
4535 const char *filename
,
4537 const char *section
,
4538 unsigned section_line
,
4545 _cleanup_free_
char *resolved
= NULL
;
4546 const Unit
*u
= userdata
;
4547 char ***paths
= data
;
4555 if (isempty(rvalue
)) {
4556 *paths
= strv_free(*paths
);
4560 r
= unit_full_printf(u
, rvalue
, &resolved
);
4562 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
4566 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4570 if (strv_contains(*paths
, resolved
))
4573 r
= strv_extend(paths
, resolved
);
4577 r
= bpf_firewall_supported();
4580 if (r
!= BPF_FIREWALL_SUPPORTED_WITH_MULTI
) {
4581 static bool warned
= false;
4583 log_full(warned
? LOG_DEBUG
: LOG_WARNING
,
4584 "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"
4585 "Starting this unit will fail! (This warning is only shown for the first loaded unit using IP firewalling.)", filename
, line
, lvalue
, rvalue
);
4593 static int merge_by_names(Unit
**u
, Set
*names
, const char *id
) {
4600 /* Let's try to add in all names that are aliases of this unit */
4601 while ((k
= set_steal_first(names
))) {
4602 _cleanup_free_ _unused_
char *free_k
= k
;
4604 /* First try to merge in the other name into our unit */
4605 r
= unit_merge_by_name(*u
, k
);
4609 /* Hmm, we couldn't merge the other unit into ours? Then let's try it the other way
4612 other
= manager_get_unit((*u
)->manager
, k
);
4614 return r
; /* return previous failure */
4616 r
= unit_merge(other
, *u
);
4621 return merge_by_names(u
, names
, NULL
);
4624 if (streq_ptr(id
, k
))
4625 unit_choose_id(*u
, id
);
4631 int unit_load_fragment(Unit
*u
) {
4632 const char *fragment
;
4633 _cleanup_set_free_free_ Set
*names
= NULL
;
4638 assert(u
->load_state
== UNIT_STUB
);
4642 u
->load_state
= UNIT_LOADED
;
4646 /* Possibly rebuild the fragment map to catch new units */
4647 r
= unit_file_build_name_map(&u
->manager
->lookup_paths
,
4648 &u
->manager
->unit_cache_mtime
,
4649 &u
->manager
->unit_id_map
,
4650 &u
->manager
->unit_name_map
,
4651 &u
->manager
->unit_path_cache
);
4653 log_error_errno(r
, "Failed to rebuild name map: %m");
4655 r
= unit_file_find_fragment(u
->manager
->unit_id_map
,
4656 u
->manager
->unit_name_map
,
4660 if (r
< 0 && r
!= -ENOENT
)
4664 /* Open the file, check if this is a mask, otherwise read. */
4665 _cleanup_fclose_
FILE *f
= NULL
;
4667 /* Try to open the file name. A symlink is OK, for example for linked files or masks. We
4668 * expect that all symlinks within the lookup paths have been already resolved, but we don't
4669 * verify this here. */
4670 f
= fopen(fragment
, "re");
4672 return log_unit_notice_errno(u
, errno
, "Failed to open %s: %m", fragment
);
4674 if (fstat(fileno(f
), &st
) < 0)
4677 r
= free_and_strdup(&u
->fragment_path
, fragment
);
4681 if (null_or_empty(&st
)) {
4682 u
->load_state
= UNIT_MASKED
;
4683 u
->fragment_mtime
= 0;
4685 u
->load_state
= UNIT_LOADED
;
4686 u
->fragment_mtime
= timespec_load(&st
.st_mtim
);
4688 /* Now, parse the file contents */
4689 r
= config_parse(u
->id
, fragment
, f
,
4690 UNIT_VTABLE(u
)->sections
,
4691 config_item_perf_lookup
, load_fragment_gperf_lookup
,
4692 CONFIG_PARSE_ALLOW_INCLUDE
, u
);
4694 log_unit_notice_errno(u
, r
, "Unit configuration has fatal error, unit will not be started.");
4700 if (u
->source_path
) {
4701 if (stat(u
->source_path
, &st
) >= 0)
4702 u
->source_mtime
= timespec_load(&st
.st_mtim
);
4704 u
->source_mtime
= 0;
4707 /* We do the merge dance here because for some unit types, the unit might have aliases which are not
4708 * declared in the file system. In particular, this is true (and frequent) for device and swap units.
4711 const char *id
= u
->id
;
4712 _cleanup_free_
char *free_id
= NULL
;
4715 id
= basename(fragment
);
4716 if (unit_name_is_valid(id
, UNIT_NAME_TEMPLATE
)) {
4717 assert(u
->instance
); /* If we're not trying to use a template for non-instanced unit,
4718 * this must be set. */
4720 r
= unit_name_replace_instance(id
, u
->instance
, &free_id
);
4722 return log_debug_errno(r
, "Failed to build id (%s + %s): %m", id
, u
->instance
);
4728 r
= merge_by_names(&merged
, names
, id
);
4733 u
->load_state
= UNIT_MERGED
;
4738 void unit_dump_config_items(FILE *f
) {
4739 static const struct {
4740 const ConfigParserCallback callback
;
4743 { config_parse_warn_compat
, "NOTSUPPORTED" },
4744 { config_parse_int
, "INTEGER" },
4745 { config_parse_unsigned
, "UNSIGNED" },
4746 { config_parse_iec_size
, "SIZE" },
4747 { config_parse_iec_uint64
, "SIZE" },
4748 { config_parse_si_size
, "SIZE" },
4749 { config_parse_bool
, "BOOLEAN" },
4750 { config_parse_string
, "STRING" },
4751 { config_parse_path
, "PATH" },
4752 { config_parse_unit_path_printf
, "PATH" },
4753 { config_parse_strv
, "STRING [...]" },
4754 { config_parse_exec_nice
, "NICE" },
4755 { config_parse_exec_oom_score_adjust
, "OOMSCOREADJUST" },
4756 { config_parse_exec_io_class
, "IOCLASS" },
4757 { config_parse_exec_io_priority
, "IOPRIORITY" },
4758 { config_parse_exec_cpu_sched_policy
, "CPUSCHEDPOLICY" },
4759 { config_parse_exec_cpu_sched_prio
, "CPUSCHEDPRIO" },
4760 { config_parse_exec_cpu_affinity
, "CPUAFFINITY" },
4761 { config_parse_mode
, "MODE" },
4762 { config_parse_unit_env_file
, "FILE" },
4763 { config_parse_exec_output
, "OUTPUT" },
4764 { config_parse_exec_input
, "INPUT" },
4765 { config_parse_log_facility
, "FACILITY" },
4766 { config_parse_log_level
, "LEVEL" },
4767 { config_parse_exec_secure_bits
, "SECUREBITS" },
4768 { config_parse_capability_set
, "BOUNDINGSET" },
4769 { config_parse_rlimit
, "LIMIT" },
4770 { config_parse_unit_deps
, "UNIT [...]" },
4771 { config_parse_exec
, "PATH [ARGUMENT [...]]" },
4772 { config_parse_service_type
, "SERVICETYPE" },
4773 { config_parse_service_restart
, "SERVICERESTART" },
4774 { config_parse_kill_mode
, "KILLMODE" },
4775 { config_parse_signal
, "SIGNAL" },
4776 { config_parse_socket_listen
, "SOCKET [...]" },
4777 { config_parse_socket_bind
, "SOCKETBIND" },
4778 { config_parse_socket_bindtodevice
, "NETWORKINTERFACE" },
4779 { config_parse_sec
, "SECONDS" },
4780 { config_parse_nsec
, "NANOSECONDS" },
4781 { config_parse_namespace_path_strv
, "PATH [...]" },
4782 { config_parse_bind_paths
, "PATH[:PATH[:OPTIONS]] [...]" },
4783 { config_parse_unit_requires_mounts_for
, "PATH [...]" },
4784 { config_parse_exec_mount_flags
, "MOUNTFLAG [...]" },
4785 { config_parse_unit_string_printf
, "STRING" },
4786 { config_parse_trigger_unit
, "UNIT" },
4787 { config_parse_timer
, "TIMER" },
4788 { config_parse_path_spec
, "PATH" },
4789 { config_parse_notify_access
, "ACCESS" },
4790 { config_parse_ip_tos
, "TOS" },
4791 { config_parse_unit_condition_path
, "CONDITION" },
4792 { config_parse_unit_condition_string
, "CONDITION" },
4793 { config_parse_unit_condition_null
, "CONDITION" },
4794 { config_parse_unit_slice
, "SLICE" },
4795 { config_parse_documentation
, "URL" },
4796 { config_parse_service_timeout
, "SECONDS" },
4797 { config_parse_emergency_action
, "ACTION" },
4798 { config_parse_set_status
, "STATUS" },
4799 { config_parse_service_sockets
, "SOCKETS" },
4800 { config_parse_environ
, "ENVIRON" },
4802 { config_parse_syscall_filter
, "SYSCALLS" },
4803 { config_parse_syscall_archs
, "ARCHS" },
4804 { config_parse_syscall_errno
, "ERRNO" },
4805 { config_parse_address_families
, "FAMILIES" },
4806 { config_parse_restrict_namespaces
, "NAMESPACES" },
4808 { config_parse_cpu_shares
, "SHARES" },
4809 { config_parse_cg_weight
, "WEIGHT" },
4810 { config_parse_memory_limit
, "LIMIT" },
4811 { config_parse_device_allow
, "DEVICE" },
4812 { config_parse_device_policy
, "POLICY" },
4813 { config_parse_io_limit
, "LIMIT" },
4814 { config_parse_io_device_weight
, "DEVICEWEIGHT" },
4815 { config_parse_io_device_latency
, "DEVICELATENCY" },
4816 { config_parse_blockio_bandwidth
, "BANDWIDTH" },
4817 { config_parse_blockio_weight
, "WEIGHT" },
4818 { config_parse_blockio_device_weight
, "DEVICEWEIGHT" },
4819 { config_parse_long
, "LONG" },
4820 { config_parse_socket_service
, "SERVICE" },
4822 { config_parse_exec_selinux_context
, "LABEL" },
4824 { config_parse_job_mode
, "MODE" },
4825 { config_parse_job_mode_isolate
, "BOOLEAN" },
4826 { config_parse_personality
, "PERSONALITY" },
4829 const char *prev
= NULL
;
4834 NULSTR_FOREACH(i
, load_fragment_gperf_nulstr
) {
4835 const char *rvalue
= "OTHER", *lvalue
;
4836 const ConfigPerfItem
*p
;
4841 assert_se(p
= load_fragment_gperf_lookup(i
, strlen(i
)));
4843 /* Hide legacy settings */
4844 if (p
->parse
== config_parse_warn_compat
&&
4845 p
->ltype
== DISABLED_LEGACY
)
4848 for (j
= 0; j
< ELEMENTSOF(table
); j
++)
4849 if (p
->parse
== table
[j
].callback
) {
4850 rvalue
= table
[j
].rvalue
;
4854 dot
= strchr(i
, '.');
4855 lvalue
= dot
? dot
+ 1 : i
;
4859 if (!prev
|| !strneq(prev
, i
, prefix_len
+1)) {
4863 fprintf(f
, "[%.*s]\n", (int) prefix_len
, i
);
4866 fprintf(f
, "%s=%s\n", lvalue
, rvalue
);
4871 int config_parse_cpu_affinity2(
4873 const char *filename
,
4875 const char *section
,
4876 unsigned section_line
,
4883 CPUSet
*affinity
= data
;
4887 (void) parse_cpu_set_extend(rvalue
, affinity
, true, unit
, filename
, line
, lvalue
);
4892 int config_parse_show_status(
4894 const char *filename
,
4896 const char *section
,
4897 unsigned section_line
,
4905 ShowStatus
*b
= data
;
4912 k
= parse_show_status(rvalue
, b
);
4914 log_syntax(unit
, LOG_ERR
, filename
, line
, k
, "Failed to parse show status setting, ignoring: %s", rvalue
);
4921 int config_parse_output_restricted(
4923 const char *filename
,
4925 const char *section
,
4926 unsigned section_line
,
4933 ExecOutput t
, *eo
= data
;
4940 t
= exec_output_from_string(rvalue
);
4942 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse output type, ignoring: %s", rvalue
);
4946 if (IN_SET(t
, EXEC_OUTPUT_SOCKET
, EXEC_OUTPUT_NAMED_FD
, EXEC_OUTPUT_FILE
, EXEC_OUTPUT_FILE_APPEND
)) {
4947 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Standard output types socket, fd:, file:, append: are not supported as defaults, ignoring: %s", rvalue
);
4955 int config_parse_crash_chvt(
4957 const char *filename
,
4959 const char *section
,
4960 unsigned section_line
,
4974 r
= parse_crash_chvt(rvalue
, data
);
4976 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse CrashChangeVT= setting, ignoring: %s", rvalue
);
4983 int config_parse_timeout_abort(
4985 const char *filename
,
4987 const char *section
,
4988 unsigned section_line
,
4995 usec_t
*timeout_usec
= data
;
5001 assert(timeout_usec
);
5003 rvalue
+= strspn(rvalue
, WHITESPACE
);
5004 if (isempty(rvalue
)) {
5005 *timeout_usec
= false;
5009 r
= parse_sec(rvalue
, timeout_usec
);
5011 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse DefaultTimeoutAbortSec= setting, ignoring: %s", rvalue
);
5015 *timeout_usec
= true;