1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 Copyright © 2012 Holger Hans Peter Freyther
14 #include <sys/resource.h>
17 #include "alloc-util.h"
18 #include "all-units.h"
19 #include "bpf-firewall.h"
20 #include "bus-error.h"
21 #include "bus-internal.h"
24 #include "capability-util.h"
25 #include "cgroup-setup.h"
26 #include "conf-parser.h"
27 #include "cpu-set-util.h"
29 #include "errno-list.h"
33 #include "hexdecoct.h"
36 #include "ip-protocol-list.h"
37 #include "journal-util.h"
38 #include "limits-util.h"
39 #include "load-fragment.h"
41 #include "mountpoint-util.h"
42 #include "nulstr-util.h"
43 #include "parse-util.h"
44 #include "path-util.h"
45 #include "process-util.h"
47 #include "seccomp-util.h"
49 #include "securebits-util.h"
50 #include "signal-util.h"
51 #include "socket-netlink.h"
52 #include "stat-util.h"
53 #include "string-util.h"
55 #include "syslog-util.h"
56 #include "time-util.h"
57 #include "unit-name.h"
58 #include "unit-printf.h"
59 #include "user-util.h"
62 static int parse_socket_protocol(const char *s
) {
65 r
= parse_ip_protocol(s
);
68 if (!IN_SET(r
, IPPROTO_UDPLITE
, IPPROTO_SCTP
))
69 return -EPROTONOSUPPORT
;
74 int parse_crash_chvt(const char *value
, int *data
) {
77 if (safe_atoi(value
, data
) >= 0)
80 b
= parse_boolean(value
);
85 *data
= 0; /* switch to where kmsg goes */
87 *data
= -1; /* turn off switching */
92 int parse_confirm_spawn(const char *value
, char **console
) {
96 r
= value
? parse_boolean(value
) : 1;
100 } else if (r
> 0) /* on with default tty */
101 s
= strdup("/dev/console");
102 else if (is_path(value
)) /* on with fully qualified path */
104 else /* on with only a tty file name, not a fully qualified path */
105 s
= path_join("/dev/", value
);
113 DEFINE_CONFIG_PARSE(config_parse_socket_protocol
, parse_socket_protocol
, "Failed to parse socket protocol");
114 DEFINE_CONFIG_PARSE(config_parse_exec_secure_bits
, secure_bits_from_string
, "Failed to parse secure bits");
115 DEFINE_CONFIG_PARSE_ENUM(config_parse_collect_mode
, collect_mode
, CollectMode
, "Failed to parse garbage collection mode");
116 DEFINE_CONFIG_PARSE_ENUM(config_parse_device_policy
, cgroup_device_policy
, CGroupDevicePolicy
, "Failed to parse device policy");
117 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_keyring_mode
, exec_keyring_mode
, ExecKeyringMode
, "Failed to parse keyring mode");
118 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_utmp_mode
, exec_utmp_mode
, ExecUtmpMode
, "Failed to parse utmp mode");
119 DEFINE_CONFIG_PARSE_ENUM(config_parse_job_mode
, job_mode
, JobMode
, "Failed to parse job mode");
120 DEFINE_CONFIG_PARSE_ENUM(config_parse_kill_mode
, kill_mode
, KillMode
, "Failed to parse kill mode");
121 DEFINE_CONFIG_PARSE_ENUM(config_parse_notify_access
, notify_access
, NotifyAccess
, "Failed to parse notify access specifier");
122 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_home
, protect_home
, ProtectHome
, "Failed to parse protect home value");
123 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_system
, protect_system
, ProtectSystem
, "Failed to parse protect system value");
124 DEFINE_CONFIG_PARSE_ENUM(config_parse_runtime_preserve_mode
, exec_preserve_mode
, ExecPreserveMode
, "Failed to parse runtime directory preserve mode");
125 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_type
, service_type
, ServiceType
, "Failed to parse service type");
126 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart
, service_restart
, ServiceRestart
, "Failed to parse service restart specifier");
127 DEFINE_CONFIG_PARSE_ENUM(config_parse_socket_bind
, socket_address_bind_ipv6_only_or_bool
, SocketAddressBindIPv6Only
, "Failed to parse bind IPv6 only value");
128 DEFINE_CONFIG_PARSE_ENUM(config_parse_oom_policy
, oom_policy
, OOMPolicy
, "Failed to parse OOM policy");
129 DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_ip_tos
, ip_tos
, int, -1, "Failed to parse IP TOS value");
130 DEFINE_CONFIG_PARSE_PTR(config_parse_blockio_weight
, cg_blkio_weight_parse
, uint64_t, "Invalid block IO weight");
131 DEFINE_CONFIG_PARSE_PTR(config_parse_cg_weight
, cg_weight_parse
, uint64_t, "Invalid weight");
132 DEFINE_CONFIG_PARSE_PTR(config_parse_cpu_shares
, cg_cpu_shares_parse
, uint64_t, "Invalid CPU shares");
133 DEFINE_CONFIG_PARSE_PTR(config_parse_exec_mount_flags
, mount_propagation_flags_from_string
, unsigned long, "Failed to parse mount flag");
134 DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_numa_policy
, mpol
, int, -1, "Invalid NUMA policy type");
135 DEFINE_CONFIG_PARSE_ENUM(config_parse_status_unit_format
, status_unit_format
, StatusUnitFormat
, "Failed to parse status unit format");
137 int config_parse_unit_deps(
139 const char *filename
,
142 unsigned section_line
,
149 UnitDependency d
= ltype
;
159 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
162 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_RETAIN_ESCAPE
);
168 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
172 r
= unit_name_printf(u
, word
, &k
);
174 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
178 r
= unit_add_dependency_by_name(u
, d
, k
, true, UNIT_DEPENDENCY_FILE
);
180 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
186 int config_parse_obsolete_unit_deps(
188 const char *filename
,
191 unsigned section_line
,
198 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
199 "Unit dependency type %s= is obsolete, replacing by %s=, please update your unit file", lvalue
, unit_dependency_to_string(ltype
));
201 return config_parse_unit_deps(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
);
204 int config_parse_unit_string_printf(
206 const char *filename
,
209 unsigned section_line
,
216 _cleanup_free_
char *k
= NULL
;
217 const Unit
*u
= userdata
;
225 r
= unit_full_printf(u
, rvalue
, &k
);
227 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
231 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
234 int config_parse_unit_strv_printf(
236 const char *filename
,
239 unsigned section_line
,
246 const Unit
*u
= userdata
;
247 _cleanup_free_
char *k
= NULL
;
255 r
= unit_full_printf(u
, rvalue
, &k
);
257 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
261 return config_parse_strv(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
264 int config_parse_unit_path_printf(
266 const char *filename
,
269 unsigned section_line
,
276 _cleanup_free_
char *k
= NULL
;
277 const Unit
*u
= userdata
;
286 /* Let's not bother with anything that is too long */
287 if (strlen(rvalue
) >= PATH_MAX
) {
288 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
289 "%s value too long%s.",
290 lvalue
, fatal
? "" : ", ignoring");
291 return fatal
? -ENAMETOOLONG
: 0;
294 r
= unit_full_printf(u
, rvalue
, &k
);
296 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
297 "Failed to resolve unit specifiers in '%s'%s: %m",
298 rvalue
, fatal
? "" : ", ignoring");
299 return fatal
? -ENOEXEC
: 0;
302 return config_parse_path(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
305 int config_parse_unit_path_strv_printf(
307 const char *filename
,
310 unsigned section_line
,
318 const Unit
*u
= userdata
;
327 if (isempty(rvalue
)) {
333 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
335 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
341 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
342 "Invalid syntax, ignoring: %s", rvalue
);
346 r
= unit_full_printf(u
, word
, &k
);
348 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
349 "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
353 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
357 r
= strv_consume(x
, TAKE_PTR(k
));
363 static int patch_var_run(
365 const char *filename
,
373 e
= path_startswith(*path
, "/var/run/");
377 z
= path_join("/run/", e
);
381 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
382 "%s= references a path below legacy directory /var/run/, updating %s → %s; "
383 "please update the unit file accordingly.", lvalue
, *path
, z
);
385 free_and_replace(*path
, z
);
390 int config_parse_socket_listen(
392 const char *filename
,
395 unsigned section_line
,
402 _cleanup_free_ SocketPort
*p
= NULL
;
414 if (isempty(rvalue
)) {
415 /* An empty assignment removes all ports */
416 socket_free_ports(s
);
420 p
= new0(SocketPort
, 1);
424 if (ltype
!= SOCKET_SOCKET
) {
425 _cleanup_free_
char *k
= NULL
;
427 r
= unit_full_printf(UNIT(s
), rvalue
, &k
);
429 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
433 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
437 if (ltype
== SOCKET_FIFO
) {
438 r
= patch_var_run(unit
, filename
, line
, lvalue
, &k
);
443 free_and_replace(p
->path
, k
);
446 } else if (streq(lvalue
, "ListenNetlink")) {
447 _cleanup_free_
char *k
= NULL
;
449 r
= unit_full_printf(UNIT(s
), rvalue
, &k
);
451 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
455 r
= socket_address_parse_netlink(&p
->address
, k
);
457 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse address value in '%s', ignoring: %m", k
);
461 p
->type
= SOCKET_SOCKET
;
464 _cleanup_free_
char *k
= NULL
;
466 r
= unit_full_printf(UNIT(s
), rvalue
, &k
);
468 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
472 if (k
[0] == '/') { /* Only for AF_UNIX file system sockets… */
473 r
= patch_var_run(unit
, filename
, line
, lvalue
, &k
);
478 r
= socket_address_parse_and_warn(&p
->address
, k
);
480 if (r
!= -EAFNOSUPPORT
)
481 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse address value in '%s', ignoring: %m", k
);
485 if (streq(lvalue
, "ListenStream"))
486 p
->address
.type
= SOCK_STREAM
;
487 else if (streq(lvalue
, "ListenDatagram"))
488 p
->address
.type
= SOCK_DGRAM
;
490 assert(streq(lvalue
, "ListenSequentialPacket"));
491 p
->address
.type
= SOCK_SEQPACKET
;
494 if (socket_address_family(&p
->address
) != AF_LOCAL
&& p
->address
.type
== SOCK_SEQPACKET
) {
495 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Address family not supported, ignoring: %s", rvalue
);
499 p
->type
= SOCKET_SOCKET
;
503 p
->auxiliary_fds
= NULL
;
504 p
->n_auxiliary_fds
= 0;
507 LIST_FIND_TAIL(port
, s
->ports
, tail
);
508 LIST_INSERT_AFTER(port
, s
->ports
, tail
, p
);
515 int config_parse_exec_nice(
517 const char *filename
,
520 unsigned section_line
,
527 ExecContext
*c
= data
;
535 if (isempty(rvalue
)) {
540 r
= parse_nice(rvalue
, &priority
);
543 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Nice priority out of range, ignoring: %s", rvalue
);
545 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse nice priority '%s', ignoring: %m", rvalue
);
555 int config_parse_exec_oom_score_adjust(
557 const char *filename
,
560 unsigned section_line
,
567 ExecContext
*c
= data
;
575 if (isempty(rvalue
)) {
576 c
->oom_score_adjust_set
= false;
580 r
= parse_oom_score_adjust(rvalue
, &oa
);
583 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "OOM score adjust value out of range, ignoring: %s", rvalue
);
585 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse the OOM score adjust value '%s', ignoring: %m", rvalue
);
589 c
->oom_score_adjust
= oa
;
590 c
->oom_score_adjust_set
= true;
595 int config_parse_exec(
597 const char *filename
,
600 unsigned section_line
,
607 ExecCommand
**e
= data
;
608 const Unit
*u
= userdata
;
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
;
1340 if (streq(rvalue
, "numa")) {
1341 c
->cpu_affinity_from_numa
= true;
1342 cpu_set_reset(&c
->cpu_set
);
1347 r
= parse_cpu_set_extend(rvalue
, &c
->cpu_set
, true, unit
, filename
, line
, lvalue
);
1349 c
->cpu_affinity_from_numa
= false;
1354 int config_parse_capability_set(
1356 const char *filename
,
1358 const char *section
,
1359 unsigned section_line
,
1366 uint64_t *capability_set
= data
;
1367 uint64_t sum
= 0, initial
= 0;
1368 bool invert
= false;
1376 if (rvalue
[0] == '~') {
1381 if (streq(lvalue
, "CapabilityBoundingSet"))
1382 initial
= CAP_ALL
; /* initialized to all bits on */
1383 /* else "AmbientCapabilities" initialized to all bits off */
1385 r
= capability_set_from_string(rvalue
, &sum
);
1387 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= specifier '%s', ignoring: %m", lvalue
, rvalue
);
1391 if (sum
== 0 || *capability_set
== initial
)
1392 /* "", "~" or uninitialized data -> replace */
1393 *capability_set
= invert
? ~sum
: sum
;
1395 /* previous data -> merge */
1397 *capability_set
&= ~sum
;
1399 *capability_set
|= sum
;
1405 int config_parse_exec_selinux_context(
1407 const char *filename
,
1409 const char *section
,
1410 unsigned section_line
,
1417 ExecContext
*c
= data
;
1418 const Unit
*u
= userdata
;
1428 if (isempty(rvalue
)) {
1429 c
->selinux_context
= mfree(c
->selinux_context
);
1430 c
->selinux_context_ignore
= false;
1434 if (rvalue
[0] == '-') {
1440 r
= unit_full_printf(u
, rvalue
, &k
);
1442 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1443 "Failed to resolve unit specifiers in '%s'%s: %m",
1444 rvalue
, ignore
? ", ignoring" : "");
1445 return ignore
? 0 : -ENOEXEC
;
1448 free_and_replace(c
->selinux_context
, k
);
1449 c
->selinux_context_ignore
= ignore
;
1454 int config_parse_exec_apparmor_profile(
1456 const char *filename
,
1458 const char *section
,
1459 unsigned section_line
,
1466 ExecContext
*c
= data
;
1467 const Unit
*u
= userdata
;
1477 if (isempty(rvalue
)) {
1478 c
->apparmor_profile
= mfree(c
->apparmor_profile
);
1479 c
->apparmor_profile_ignore
= false;
1483 if (rvalue
[0] == '-') {
1489 r
= unit_full_printf(u
, rvalue
, &k
);
1491 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1492 "Failed to resolve unit specifiers in '%s'%s: %m",
1493 rvalue
, ignore
? ", ignoring" : "");
1494 return ignore
? 0 : -ENOEXEC
;
1497 free_and_replace(c
->apparmor_profile
, k
);
1498 c
->apparmor_profile_ignore
= ignore
;
1503 int config_parse_exec_smack_process_label(
1505 const char *filename
,
1507 const char *section
,
1508 unsigned section_line
,
1515 ExecContext
*c
= data
;
1516 const Unit
*u
= userdata
;
1526 if (isempty(rvalue
)) {
1527 c
->smack_process_label
= mfree(c
->smack_process_label
);
1528 c
->smack_process_label_ignore
= false;
1532 if (rvalue
[0] == '-') {
1538 r
= unit_full_printf(u
, rvalue
, &k
);
1540 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1541 "Failed to resolve unit specifiers in '%s'%s: %m",
1542 rvalue
, ignore
? ", ignoring" : "");
1543 return ignore
? 0 : -ENOEXEC
;
1546 free_and_replace(c
->smack_process_label
, k
);
1547 c
->smack_process_label_ignore
= ignore
;
1552 int config_parse_timer(
1554 const char *filename
,
1556 const char *section
,
1557 unsigned section_line
,
1564 _cleanup_(calendar_spec_freep
) CalendarSpec
*c
= NULL
;
1565 _cleanup_free_
char *k
= NULL
;
1566 const Unit
*u
= userdata
;
1577 if (isempty(rvalue
)) {
1578 /* Empty assignment resets list */
1579 timer_free_values(t
);
1583 r
= unit_full_printf(u
, rvalue
, &k
);
1585 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
1589 if (ltype
== TIMER_CALENDAR
) {
1590 r
= calendar_spec_from_string(k
, &c
);
1592 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse calendar specification, ignoring: %s", k
);
1596 r
= parse_sec(k
, &usec
);
1598 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse timer value, ignoring: %s", k
);
1603 v
= new(TimerValue
, 1);
1610 .calendar_spec
= TAKE_PTR(c
),
1613 LIST_PREPEND(value
, t
->values
, v
);
1618 int config_parse_trigger_unit(
1620 const char *filename
,
1622 const char *section
,
1623 unsigned section_line
,
1630 _cleanup_free_
char *p
= NULL
;
1640 if (!hashmap_isempty(u
->dependencies
[UNIT_TRIGGERS
])) {
1641 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Multiple units to trigger specified, ignoring: %s", rvalue
);
1645 r
= unit_name_printf(u
, rvalue
, &p
);
1647 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
1651 type
= unit_name_to_type(p
);
1653 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit type not valid, ignoring: %s", rvalue
);
1656 if (unit_has_name(u
, p
)) {
1657 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Units cannot trigger themselves, ignoring: %s", rvalue
);
1661 r
= unit_add_two_dependencies_by_name(u
, UNIT_BEFORE
, UNIT_TRIGGERS
, p
, true, UNIT_DEPENDENCY_FILE
);
1663 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add trigger on %s, ignoring: %m", p
);
1670 int config_parse_path_spec(const char *unit
,
1671 const char *filename
,
1673 const char *section
,
1674 unsigned section_line
,
1684 _cleanup_free_
char *k
= NULL
;
1692 if (isempty(rvalue
)) {
1693 /* Empty assignment clears list */
1698 b
= path_type_from_string(lvalue
);
1700 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse path type, ignoring: %s", lvalue
);
1704 r
= unit_full_printf(UNIT(p
), rvalue
, &k
);
1706 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
1710 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
1714 s
= new0(PathSpec
, 1);
1719 s
->path
= TAKE_PTR(k
);
1723 LIST_PREPEND(spec
, p
->specs
, s
);
1728 int config_parse_socket_service(
1730 const char *filename
,
1732 const char *section
,
1733 unsigned section_line
,
1740 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1741 _cleanup_free_
char *p
= NULL
;
1751 r
= unit_name_printf(UNIT(s
), rvalue
, &p
);
1753 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", rvalue
);
1757 if (!endswith(p
, ".service")) {
1758 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit must be of type service: %s", rvalue
);
1762 r
= manager_load_unit(UNIT(s
)->manager
, p
, NULL
, &error
, &x
);
1764 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to load unit %s: %s", rvalue
, bus_error_message(&error
, r
));
1768 unit_ref_set(&s
->service
, UNIT(s
), x
);
1773 int config_parse_fdname(
1775 const char *filename
,
1777 const char *section
,
1778 unsigned section_line
,
1785 _cleanup_free_
char *p
= NULL
;
1794 if (isempty(rvalue
)) {
1795 s
->fdname
= mfree(s
->fdname
);
1799 r
= unit_full_printf(UNIT(s
), rvalue
, &p
);
1801 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
1805 if (!fdname_is_valid(p
)) {
1806 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", p
);
1810 return free_and_replace(s
->fdname
, p
);
1813 int config_parse_service_sockets(
1815 const char *filename
,
1817 const char *section
,
1818 unsigned section_line
,
1836 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
1838 r
= extract_first_word(&p
, &word
, NULL
, 0);
1844 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Trailing garbage in sockets, ignoring: %s", rvalue
);
1848 r
= unit_name_printf(UNIT(s
), word
, &k
);
1850 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
1854 if (!endswith(k
, ".socket")) {
1855 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit must be of type socket, ignoring: %s", k
);
1859 r
= unit_add_two_dependencies_by_name(UNIT(s
), UNIT_WANTS
, UNIT_AFTER
, k
, true, UNIT_DEPENDENCY_FILE
);
1861 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
1863 r
= unit_add_dependency_by_name(UNIT(s
), UNIT_TRIGGERED_BY
, k
, true, UNIT_DEPENDENCY_FILE
);
1865 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
1871 int config_parse_bus_name(
1873 const char *filename
,
1875 const char *section
,
1876 unsigned section_line
,
1883 _cleanup_free_
char *k
= NULL
;
1884 const Unit
*u
= userdata
;
1892 r
= unit_full_printf(u
, rvalue
, &k
);
1894 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
1898 if (!service_name_is_valid(k
)) {
1899 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid bus name, ignoring: %s", k
);
1903 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
1906 int config_parse_service_timeout(
1908 const char *filename
,
1910 const char *section
,
1911 unsigned section_line
,
1918 Service
*s
= userdata
;
1927 /* This is called for two cases: TimeoutSec= and TimeoutStartSec=. */
1929 /* Traditionally, these options accepted 0 to disable the timeouts. However, a timeout of 0 suggests it happens
1930 * immediately, hence fix this to become USEC_INFINITY instead. This is in-line with how we internally handle
1931 * all other timeouts. */
1932 r
= parse_sec_fix_0(rvalue
, &usec
);
1934 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
1938 s
->start_timeout_defined
= true;
1939 s
->timeout_start_usec
= usec
;
1941 if (streq(lvalue
, "TimeoutSec"))
1942 s
->timeout_stop_usec
= usec
;
1947 int config_parse_timeout_abort(
1949 const char *filename
,
1951 const char *section
,
1952 unsigned section_line
,
1967 /* Note: apart from setting the arg, this returns an extra bit of information in the return value. */
1969 if (isempty(rvalue
)) {
1971 return 0; /* "not set" */
1974 r
= parse_sec(rvalue
, ret
);
1976 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= setting, ignoring: %s", lvalue
, rvalue
);
1978 return 1; /* "set" */
1981 int config_parse_service_timeout_abort(
1983 const char *filename
,
1985 const char *section
,
1986 unsigned section_line
,
1993 Service
*s
= userdata
;
1998 r
= config_parse_timeout_abort(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
,
1999 &s
->timeout_abort_usec
, s
);
2001 s
->timeout_abort_set
= r
;
2005 int config_parse_sec_fix_0(
2007 const char *filename
,
2009 const char *section
,
2010 unsigned section_line
,
2017 usec_t
*usec
= data
;
2025 /* This is pretty much like config_parse_sec(), except that this treats a time of 0 as infinity, for
2026 * compatibility with older versions of systemd where 0 instead of infinity was used as indicator to turn off a
2029 r
= parse_sec_fix_0(rvalue
, usec
);
2031 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
2038 int config_parse_user_group_compat(
2040 const char *filename
,
2042 const char *section
,
2043 unsigned section_line
,
2050 _cleanup_free_
char *k
= NULL
;
2052 const Unit
*u
= userdata
;
2060 if (isempty(rvalue
)) {
2061 *user
= mfree(*user
);
2065 r
= unit_full_printf(u
, rvalue
, &k
);
2067 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", rvalue
);
2071 if (!valid_user_group_name_or_id_compat(k
)) {
2072 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2076 return free_and_replace(*user
, k
);
2079 int config_parse_user_group_strv_compat(
2081 const char *filename
,
2083 const char *section
,
2084 unsigned section_line
,
2091 char ***users
= data
;
2092 const Unit
*u
= userdata
;
2093 const char *p
= rvalue
;
2101 if (isempty(rvalue
)) {
2102 *users
= strv_free(*users
);
2107 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2109 r
= extract_first_word(&p
, &word
, NULL
, 0);
2115 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax: %s", rvalue
);
2119 r
= unit_full_printf(u
, word
, &k
);
2121 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", word
);
2125 if (!valid_user_group_name_or_id_compat(k
)) {
2126 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2130 r
= strv_push(users
, k
);
2140 int config_parse_working_directory(
2142 const char *filename
,
2144 const char *section
,
2145 unsigned section_line
,
2152 ExecContext
*c
= data
;
2153 const Unit
*u
= userdata
;
2163 if (isempty(rvalue
)) {
2164 c
->working_directory_home
= false;
2165 c
->working_directory
= mfree(c
->working_directory
);
2169 if (rvalue
[0] == '-') {
2175 if (streq(rvalue
, "~")) {
2176 c
->working_directory_home
= true;
2177 c
->working_directory
= mfree(c
->working_directory
);
2179 _cleanup_free_
char *k
= NULL
;
2181 r
= unit_full_printf(u
, rvalue
, &k
);
2183 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2184 "Failed to resolve unit specifiers in working directory path '%s'%s: %m",
2185 rvalue
, missing_ok
? ", ignoring" : "");
2186 return missing_ok
? 0 : -ENOEXEC
;
2189 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
| (missing_ok
? 0 : PATH_CHECK_FATAL
), unit
, filename
, line
, lvalue
);
2191 return missing_ok
? 0 : -ENOEXEC
;
2193 c
->working_directory_home
= false;
2194 free_and_replace(c
->working_directory
, k
);
2197 c
->working_directory_missing_ok
= missing_ok
;
2201 int config_parse_unit_env_file(const char *unit
,
2202 const char *filename
,
2204 const char *section
,
2205 unsigned section_line
,
2213 const Unit
*u
= userdata
;
2214 _cleanup_free_
char *n
= NULL
;
2222 if (isempty(rvalue
)) {
2223 /* Empty assignment frees the list */
2224 *env
= strv_free(*env
);
2228 r
= unit_full_printf(u
, rvalue
, &n
);
2230 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2234 r
= path_simplify_and_warn(n
[0] == '-' ? n
+ 1 : n
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2238 r
= strv_push(env
, n
);
2247 int config_parse_environ(
2249 const char *filename
,
2251 const char *section
,
2252 unsigned section_line
,
2259 const Unit
*u
= userdata
;
2269 if (isempty(rvalue
)) {
2270 /* Empty assignment resets the list */
2271 *env
= strv_free(*env
);
2275 for (p
= rvalue
;; ) {
2276 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2278 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2284 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2285 "Invalid syntax, ignoring: %s", rvalue
);
2290 r
= unit_full_printf(u
, word
, &k
);
2292 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2293 "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2299 if (!env_assignment_is_valid(k
)) {
2300 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2301 "Invalid environment assignment, ignoring: %s", k
);
2305 r
= strv_env_replace(env
, k
);
2313 int config_parse_pass_environ(
2315 const char *filename
,
2317 const char *section
,
2318 unsigned section_line
,
2325 _cleanup_strv_free_
char **n
= NULL
;
2326 size_t nlen
= 0, nbufsize
= 0;
2327 char*** passenv
= data
;
2328 const char *p
= rvalue
;
2329 const Unit
*u
= userdata
;
2337 if (isempty(rvalue
)) {
2338 /* Empty assignment resets the list */
2339 *passenv
= strv_free(*passenv
);
2344 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2346 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
2352 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2353 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2358 r
= unit_full_printf(u
, word
, &k
);
2360 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2361 "Failed to resolve specifiers in %s, ignoring: %m", word
);
2367 if (!env_name_is_valid(k
)) {
2368 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2369 "Invalid environment name for %s, ignoring: %s", lvalue
, k
);
2373 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
2376 n
[nlen
++] = TAKE_PTR(k
);
2381 r
= strv_extend_strv(passenv
, n
, true);
2389 int config_parse_unset_environ(
2391 const char *filename
,
2393 const char *section
,
2394 unsigned section_line
,
2401 _cleanup_strv_free_
char **n
= NULL
;
2402 size_t nlen
= 0, nbufsize
= 0;
2403 char*** unsetenv
= data
;
2404 const char *p
= rvalue
;
2405 const Unit
*u
= userdata
;
2413 if (isempty(rvalue
)) {
2414 /* Empty assignment resets the list */
2415 *unsetenv
= strv_free(*unsetenv
);
2420 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2422 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2428 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2429 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2434 r
= unit_full_printf(u
, word
, &k
);
2436 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2437 "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2443 if (!env_assignment_is_valid(k
) && !env_name_is_valid(k
)) {
2444 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2445 "Invalid environment name or assignment %s, ignoring: %s", lvalue
, k
);
2449 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
2452 n
[nlen
++] = TAKE_PTR(k
);
2457 r
= strv_extend_strv(unsetenv
, n
, true);
2465 int config_parse_log_extra_fields(
2467 const char *filename
,
2469 const char *section
,
2470 unsigned section_line
,
2477 ExecContext
*c
= data
;
2478 const Unit
*u
= userdata
;
2479 const char *p
= rvalue
;
2487 if (isempty(rvalue
)) {
2488 exec_context_free_log_extra_fields(c
);
2493 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2497 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2503 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
2507 r
= unit_full_printf(u
, word
, &k
);
2509 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2513 eq
= strchr(k
, '=');
2515 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Log field lacks '=' character, ignoring: %s", k
);
2519 if (!journal_field_valid(k
, eq
-k
, false)) {
2520 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Log field name is invalid, ignoring: %s", k
);
2524 t
= reallocarray(c
->log_extra_fields
, c
->n_log_extra_fields
+1, sizeof(struct iovec
));
2528 c
->log_extra_fields
= t
;
2529 c
->log_extra_fields
[c
->n_log_extra_fields
++] = IOVEC_MAKE_STRING(k
);
2535 int config_parse_log_namespace(
2537 const char *filename
,
2539 const char *section
,
2540 unsigned section_line
,
2547 _cleanup_free_
char *k
= NULL
;
2548 ExecContext
*c
= data
;
2549 const Unit
*u
= userdata
;
2557 if (isempty(rvalue
)) {
2558 c
->log_namespace
= mfree(c
->log_namespace
);
2562 r
= unit_full_printf(u
, rvalue
, &k
);
2564 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2568 if (!log_namespace_name_valid(k
)) {
2569 log_syntax(unit
, LOG_ERR
, filename
, line
, SYNTHETIC_ERRNO(EINVAL
), "Specified log namespace name is not valid: %s", k
);
2573 free_and_replace(c
->log_namespace
, k
);
2577 int config_parse_unit_condition_path(
2579 const char *filename
,
2581 const char *section
,
2582 unsigned section_line
,
2589 _cleanup_free_
char *p
= NULL
;
2590 Condition
**list
= data
, *c
;
2591 ConditionType t
= ltype
;
2592 bool trigger
, negate
;
2593 const Unit
*u
= userdata
;
2601 if (isempty(rvalue
)) {
2602 /* Empty assignment resets the list */
2603 *list
= condition_free_list(*list
);
2607 trigger
= rvalue
[0] == '|';
2611 negate
= rvalue
[0] == '!';
2615 r
= unit_full_printf(u
, rvalue
, &p
);
2617 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2621 r
= path_simplify_and_warn(p
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2625 c
= condition_new(t
, p
, trigger
, negate
);
2629 LIST_PREPEND(conditions
, *list
, c
);
2633 int config_parse_unit_condition_string(
2635 const char *filename
,
2637 const char *section
,
2638 unsigned section_line
,
2645 _cleanup_free_
char *s
= NULL
;
2646 Condition
**list
= data
, *c
;
2647 ConditionType t
= ltype
;
2648 bool trigger
, negate
;
2649 const Unit
*u
= userdata
;
2657 if (isempty(rvalue
)) {
2658 /* Empty assignment resets the list */
2659 *list
= condition_free_list(*list
);
2663 trigger
= *rvalue
== '|';
2665 rvalue
+= 1 + strspn(rvalue
+ 1, WHITESPACE
);
2667 negate
= *rvalue
== '!';
2669 rvalue
+= 1 + strspn(rvalue
+ 1, WHITESPACE
);
2671 r
= unit_full_printf(u
, rvalue
, &s
);
2673 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2674 "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2678 c
= condition_new(t
, s
, trigger
, negate
);
2682 LIST_PREPEND(conditions
, *list
, c
);
2686 int config_parse_unit_condition_null(
2688 const char *filename
,
2690 const char *section
,
2691 unsigned section_line
,
2698 Condition
**list
= data
, *c
;
2699 bool trigger
, negate
;
2707 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "%s= is deprecated, please do not use.", lvalue
);
2709 if (isempty(rvalue
)) {
2710 /* Empty assignment resets the list */
2711 *list
= condition_free_list(*list
);
2715 trigger
= rvalue
[0] == '|';
2719 negate
= rvalue
[0] == '!';
2723 b
= parse_boolean(rvalue
);
2725 log_syntax(unit
, LOG_ERR
, filename
, line
, b
, "Failed to parse boolean value in condition, ignoring: %s", rvalue
);
2732 c
= condition_new(CONDITION_NULL
, NULL
, trigger
, negate
);
2736 LIST_PREPEND(conditions
, *list
, c
);
2740 int config_parse_unit_requires_mounts_for(
2742 const char *filename
,
2744 const char *section
,
2745 unsigned section_line
,
2752 const char *p
= rvalue
;
2762 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
2764 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
2770 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2771 "Invalid syntax, ignoring: %s", rvalue
);
2775 r
= unit_full_printf(u
, word
, &resolved
);
2777 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
2781 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2785 r
= unit_require_mounts_for(u
, resolved
, UNIT_DEPENDENCY_FILE
);
2787 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add required mount '%s', ignoring: %m", resolved
);
2793 int config_parse_documentation(const char *unit
,
2794 const char *filename
,
2796 const char *section
,
2797 unsigned section_line
,
2813 if (isempty(rvalue
)) {
2814 /* Empty assignment resets the list */
2815 u
->documentation
= strv_free(u
->documentation
);
2819 r
= config_parse_unit_strv_printf(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
,
2820 rvalue
, data
, userdata
);
2824 for (a
= b
= u
->documentation
; a
&& *a
; a
++) {
2826 if (documentation_url_is_valid(*a
))
2829 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid URL, ignoring: %s", *a
);
2840 int config_parse_syscall_filter(
2842 const char *filename
,
2844 const char *section
,
2845 unsigned section_line
,
2852 ExecContext
*c
= data
;
2853 const Unit
*u
= userdata
;
2854 bool invert
= false;
2863 if (isempty(rvalue
)) {
2864 /* Empty assignment resets the list */
2865 c
->syscall_filter
= hashmap_free(c
->syscall_filter
);
2866 c
->syscall_whitelist
= false;
2870 if (rvalue
[0] == '~') {
2875 if (!c
->syscall_filter
) {
2876 c
->syscall_filter
= hashmap_new(NULL
);
2877 if (!c
->syscall_filter
)
2881 /* Allow everything but the ones listed */
2882 c
->syscall_whitelist
= false;
2884 /* Allow nothing but the ones listed */
2885 c
->syscall_whitelist
= true;
2887 /* Accept default syscalls if we are on a whitelist */
2888 r
= seccomp_parse_syscall_filter(
2889 "@default", -1, c
->syscall_filter
,
2890 SECCOMP_PARSE_PERMISSIVE
|SECCOMP_PARSE_WHITELIST
,
2900 _cleanup_free_
char *word
= NULL
, *name
= NULL
;
2903 r
= extract_first_word(&p
, &word
, NULL
, 0);
2909 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
2913 r
= parse_syscall_and_errno(word
, &name
, &num
);
2915 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse syscall:errno, ignoring: %s", word
);
2919 r
= seccomp_parse_syscall_filter(
2920 name
, num
, c
->syscall_filter
,
2921 SECCOMP_PARSE_LOG
|SECCOMP_PARSE_PERMISSIVE
|
2922 (invert
? SECCOMP_PARSE_INVERT
: 0)|
2923 (c
->syscall_whitelist
? SECCOMP_PARSE_WHITELIST
: 0),
2924 unit
, filename
, line
);
2930 int config_parse_syscall_archs(
2932 const char *filename
,
2934 const char *section
,
2935 unsigned section_line
,
2942 const char *p
= rvalue
;
2946 if (isempty(rvalue
)) {
2947 *archs
= set_free(*archs
);
2951 r
= set_ensure_allocated(archs
, NULL
);
2956 _cleanup_free_
char *word
= NULL
;
2959 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
2965 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2966 "Invalid syntax, ignoring: %s", rvalue
);
2970 r
= seccomp_arch_from_string(word
, &a
);
2972 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2973 "Failed to parse system call architecture \"%s\", ignoring: %m", word
);
2977 r
= set_put(*archs
, UINT32_TO_PTR(a
+ 1));
2983 int config_parse_syscall_errno(
2985 const char *filename
,
2987 const char *section
,
2988 unsigned section_line
,
2995 ExecContext
*c
= data
;
3002 if (isempty(rvalue
)) {
3003 /* Empty assignment resets to KILL */
3004 c
->syscall_errno
= 0;
3008 e
= parse_errno(rvalue
);
3010 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse error number, ignoring: %s", rvalue
);
3014 c
->syscall_errno
= e
;
3018 int config_parse_address_families(
3020 const char *filename
,
3022 const char *section
,
3023 unsigned section_line
,
3030 ExecContext
*c
= data
;
3031 bool invert
= false;
3039 if (isempty(rvalue
)) {
3040 /* Empty assignment resets the list */
3041 c
->address_families
= set_free(c
->address_families
);
3042 c
->address_families_whitelist
= false;
3046 if (rvalue
[0] == '~') {
3051 if (!c
->address_families
) {
3052 c
->address_families
= set_new(NULL
);
3053 if (!c
->address_families
)
3056 c
->address_families_whitelist
= !invert
;
3059 for (p
= rvalue
;;) {
3060 _cleanup_free_
char *word
= NULL
;
3063 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3069 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3070 "Invalid syntax, ignoring: %s", rvalue
);
3074 af
= af_from_name(word
);
3076 log_syntax(unit
, LOG_ERR
, filename
, line
, af
,
3077 "Failed to parse address family, ignoring: %s", word
);
3081 /* If we previously wanted to forbid an address family and now
3082 * we want to allow it, then just remove it from the list.
3084 if (!invert
== c
->address_families_whitelist
) {
3085 r
= set_put(c
->address_families
, INT_TO_PTR(af
));
3089 set_remove(c
->address_families
, INT_TO_PTR(af
));
3093 int config_parse_restrict_namespaces(
3095 const char *filename
,
3097 const char *section
,
3098 unsigned section_line
,
3105 ExecContext
*c
= data
;
3106 unsigned long flags
;
3107 bool invert
= false;
3110 if (isempty(rvalue
)) {
3111 /* Reset to the default. */
3112 c
->restrict_namespaces
= NAMESPACE_FLAGS_INITIAL
;
3116 /* Boolean parameter ignores the previous settings */
3117 r
= parse_boolean(rvalue
);
3119 c
->restrict_namespaces
= 0;
3121 } else if (r
== 0) {
3122 c
->restrict_namespaces
= NAMESPACE_FLAGS_ALL
;
3126 if (rvalue
[0] == '~') {
3131 /* Not a boolean argument, in this case it's a list of namespace types. */
3132 r
= namespace_flags_from_string(rvalue
, &flags
);
3134 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse namespace type string, ignoring: %s", rvalue
);
3138 if (c
->restrict_namespaces
== NAMESPACE_FLAGS_INITIAL
)
3139 /* Initial assignment. Just set the value. */
3140 c
->restrict_namespaces
= invert
? (~flags
) & NAMESPACE_FLAGS_ALL
: flags
;
3142 /* Merge the value with the previous one. */
3143 SET_FLAG(c
->restrict_namespaces
, flags
, !invert
);
3149 int config_parse_unit_slice(
3151 const char *filename
,
3153 const char *section
,
3154 unsigned section_line
,
3161 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
3162 _cleanup_free_
char *k
= NULL
;
3163 Unit
*u
= userdata
, *slice
;
3171 r
= unit_name_printf(u
, rvalue
, &k
);
3173 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
3177 r
= manager_load_unit(u
->manager
, k
, NULL
, &error
, &slice
);
3179 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to load slice unit %s, ignoring: %s", k
, bus_error_message(&error
, r
));
3183 r
= unit_set_slice(u
, slice
);
3185 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to assign slice %s to unit %s, ignoring: %m", slice
->id
, u
->id
);
3192 int config_parse_cpu_quota(
3194 const char *filename
,
3196 const char *section
,
3197 unsigned section_line
,
3204 CGroupContext
*c
= data
;
3211 if (isempty(rvalue
)) {
3212 c
->cpu_quota_per_sec_usec
= USEC_INFINITY
;
3216 r
= parse_permille_unbounded(rvalue
);
3218 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid CPU quota '%s', ignoring.", rvalue
);
3222 c
->cpu_quota_per_sec_usec
= ((usec_t
) r
* USEC_PER_SEC
) / 1000U;
3226 int config_parse_allowed_cpus(
3228 const char *filename
,
3230 const char *section
,
3231 unsigned section_line
,
3238 CGroupContext
*c
= data
;
3240 (void) parse_cpu_set_extend(rvalue
, &c
->cpuset_cpus
, true, unit
, filename
, line
, lvalue
);
3245 int config_parse_allowed_mems(
3247 const char *filename
,
3249 const char *section
,
3250 unsigned section_line
,
3257 CGroupContext
*c
= data
;
3259 (void) parse_cpu_set_extend(rvalue
, &c
->cpuset_mems
, true, unit
, filename
, line
, lvalue
);
3264 int config_parse_memory_limit(
3266 const char *filename
,
3268 const char *section
,
3269 unsigned section_line
,
3276 CGroupContext
*c
= data
;
3277 uint64_t bytes
= CGROUP_LIMIT_MAX
;
3280 if (!isempty(rvalue
) && !streq(rvalue
, "infinity")) {
3282 r
= parse_permille(rvalue
);
3284 r
= parse_size(rvalue
, 1024, &bytes
);
3286 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid memory limit '%s', ignoring: %m", rvalue
);
3290 bytes
= physical_memory_scale(r
, 1000U);
3292 if (bytes
>= UINT64_MAX
||
3293 (bytes
<= 0 && !STR_IN_SET(lvalue
, "MemorySwapMax", "MemoryLow", "MemoryMin", "DefaultMemoryLow", "DefaultMemoryMin"))) {
3294 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Memory limit '%s' out of range, ignoring.", rvalue
);
3299 if (streq(lvalue
, "DefaultMemoryLow")) {
3300 c
->default_memory_low_set
= true;
3301 if (isempty(rvalue
))
3302 c
->default_memory_low
= CGROUP_LIMIT_MIN
;
3304 c
->default_memory_low
= bytes
;
3305 } else if (streq(lvalue
, "DefaultMemoryMin")) {
3306 c
->default_memory_min_set
= true;
3307 if (isempty(rvalue
))
3308 c
->default_memory_min
= CGROUP_LIMIT_MIN
;
3310 c
->default_memory_min
= bytes
;
3311 } else if (streq(lvalue
, "MemoryMin")) {
3312 c
->memory_min
= bytes
;
3313 c
->memory_min_set
= true;
3314 } else if (streq(lvalue
, "MemoryLow")) {
3315 c
->memory_low
= bytes
;
3316 c
->memory_low_set
= true;
3317 } else if (streq(lvalue
, "MemoryHigh"))
3318 c
->memory_high
= bytes
;
3319 else if (streq(lvalue
, "MemoryMax"))
3320 c
->memory_max
= bytes
;
3321 else if (streq(lvalue
, "MemorySwapMax"))
3322 c
->memory_swap_max
= bytes
;
3323 else if (streq(lvalue
, "MemoryLimit"))
3324 c
->memory_limit
= bytes
;
3331 int config_parse_tasks_max(
3333 const char *filename
,
3335 const char *section
,
3336 unsigned section_line
,
3343 const Unit
*u
= userdata
;
3344 TasksMax
*tasks_max
= data
;
3348 if (isempty(rvalue
)) {
3349 *tasks_max
= u
? u
->manager
->default_tasks_max
: TASKS_MAX_UNSET
;
3353 if (streq(rvalue
, "infinity")) {
3354 *tasks_max
= TASKS_MAX_UNSET
;
3358 r
= parse_permille(rvalue
);
3360 *tasks_max
= (TasksMax
) { r
, 1000U }; /* r‰ */
3362 r
= safe_atou64(rvalue
, &v
);
3364 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid maximum tasks value '%s', ignoring: %m", rvalue
);
3368 if (v
<= 0 || v
>= UINT64_MAX
) {
3369 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Maximum tasks value '%s' out of range, ignoring.", rvalue
);
3373 *tasks_max
= (TasksMax
) { v
};
3379 int config_parse_delegate(
3381 const char *filename
,
3383 const char *section
,
3384 unsigned section_line
,
3391 CGroupContext
*c
= data
;
3395 t
= unit_name_to_type(unit
);
3396 assert(t
!= _UNIT_TYPE_INVALID
);
3398 if (!unit_vtable
[t
]->can_delegate
) {
3399 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Delegate= setting not supported for this unit type, ignoring.");
3403 /* We either accept a boolean value, which may be used to turn on delegation for all controllers, or turn it
3404 * off for all. Or it takes a list of controller names, in which case we add the specified controllers to the
3405 * mask to delegate. */
3407 if (isempty(rvalue
)) {
3408 /* An empty string resets controllers and set Delegate=yes. */
3410 c
->delegate_controllers
= 0;
3414 r
= parse_boolean(rvalue
);
3416 const char *p
= rvalue
;
3417 CGroupMask mask
= 0;
3420 _cleanup_free_
char *word
= NULL
;
3421 CGroupController cc
;
3423 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3429 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3433 cc
= cgroup_controller_from_string(word
);
3435 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid controller name '%s', ignoring", word
);
3439 mask
|= CGROUP_CONTROLLER_TO_MASK(cc
);
3443 c
->delegate_controllers
|= mask
;
3447 c
->delegate_controllers
= _CGROUP_MASK_ALL
;
3449 c
->delegate
= false;
3450 c
->delegate_controllers
= 0;
3456 int config_parse_device_allow(
3458 const char *filename
,
3460 const char *section
,
3461 unsigned section_line
,
3468 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3469 CGroupContext
*c
= data
;
3470 const char *p
= rvalue
;
3473 if (isempty(rvalue
)) {
3474 while (c
->device_allow
)
3475 cgroup_context_free_device_allow(c
, c
->device_allow
);
3480 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3484 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3485 "Invalid syntax, ignoring: %s", rvalue
);
3489 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3490 "Failed to extract device path and rights from '%s', ignoring.", rvalue
);
3494 r
= unit_full_printf(userdata
, path
, &resolved
);
3496 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3497 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3501 if (!STARTSWITH_SET(resolved
, "block-", "char-")) {
3503 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3507 if (!valid_device_node_path(resolved
)) {
3508 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device node path '%s', ignoring.", resolved
);
3513 if (!isempty(p
) && !in_charset(p
, "rwm")) {
3514 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device rights '%s', ignoring.", p
);
3518 return cgroup_add_device_allow(c
, resolved
, p
);
3521 int config_parse_io_device_weight(
3523 const char *filename
,
3525 const char *section
,
3526 unsigned section_line
,
3533 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3534 CGroupIODeviceWeight
*w
;
3535 CGroupContext
*c
= data
;
3536 const char *p
= rvalue
;
3544 if (isempty(rvalue
)) {
3545 while (c
->io_device_weights
)
3546 cgroup_context_free_io_device_weight(c
, c
->io_device_weights
);
3551 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3555 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3556 "Invalid syntax, ignoring: %s", rvalue
);
3559 if (r
== 0 || isempty(p
)) {
3560 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3561 "Failed to extract device path and weight from '%s', ignoring.", rvalue
);
3565 r
= unit_full_printf(userdata
, path
, &resolved
);
3567 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3568 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3572 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3576 r
= cg_weight_parse(p
, &u
);
3578 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "IO weight '%s' invalid, ignoring: %m", p
);
3582 assert(u
!= CGROUP_WEIGHT_INVALID
);
3584 w
= new0(CGroupIODeviceWeight
, 1);
3588 w
->path
= TAKE_PTR(resolved
);
3591 LIST_PREPEND(device_weights
, c
->io_device_weights
, w
);
3595 int config_parse_io_device_latency(
3597 const char *filename
,
3599 const char *section
,
3600 unsigned section_line
,
3607 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3608 CGroupIODeviceLatency
*l
;
3609 CGroupContext
*c
= data
;
3610 const char *p
= rvalue
;
3618 if (isempty(rvalue
)) {
3619 while (c
->io_device_latencies
)
3620 cgroup_context_free_io_device_latency(c
, c
->io_device_latencies
);
3625 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3629 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3630 "Invalid syntax, ignoring: %s", rvalue
);
3633 if (r
== 0 || isempty(p
)) {
3634 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3635 "Failed to extract device path and latency from '%s', ignoring.", rvalue
);
3639 r
= unit_full_printf(userdata
, path
, &resolved
);
3641 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3642 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3646 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3650 if (parse_sec(p
, &usec
) < 0) {
3651 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse timer value, ignoring: %s", p
);
3655 l
= new0(CGroupIODeviceLatency
, 1);
3659 l
->path
= TAKE_PTR(resolved
);
3660 l
->target_usec
= usec
;
3662 LIST_PREPEND(device_latencies
, c
->io_device_latencies
, l
);
3666 int config_parse_io_limit(
3668 const char *filename
,
3670 const char *section
,
3671 unsigned section_line
,
3678 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3679 CGroupIODeviceLimit
*l
= NULL
, *t
;
3680 CGroupContext
*c
= data
;
3681 CGroupIOLimitType type
;
3682 const char *p
= rvalue
;
3690 type
= cgroup_io_limit_type_from_string(lvalue
);
3693 if (isempty(rvalue
)) {
3694 LIST_FOREACH(device_limits
, l
, c
->io_device_limits
)
3695 l
->limits
[type
] = cgroup_io_limit_defaults
[type
];
3699 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3703 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3704 "Invalid syntax, ignoring: %s", rvalue
);
3707 if (r
== 0 || isempty(p
)) {
3708 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3709 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
3713 r
= unit_full_printf(userdata
, path
, &resolved
);
3715 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3716 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3720 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3724 if (streq("infinity", p
))
3725 num
= CGROUP_LIMIT_MAX
;
3727 r
= parse_size(p
, 1000, &num
);
3728 if (r
< 0 || num
<= 0) {
3729 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid IO limit '%s', ignoring.", p
);
3734 LIST_FOREACH(device_limits
, t
, c
->io_device_limits
) {
3735 if (path_equal(resolved
, t
->path
)) {
3742 CGroupIOLimitType ttype
;
3744 l
= new0(CGroupIODeviceLimit
, 1);
3748 l
->path
= TAKE_PTR(resolved
);
3749 for (ttype
= 0; ttype
< _CGROUP_IO_LIMIT_TYPE_MAX
; ttype
++)
3750 l
->limits
[ttype
] = cgroup_io_limit_defaults
[ttype
];
3752 LIST_PREPEND(device_limits
, c
->io_device_limits
, l
);
3755 l
->limits
[type
] = num
;
3760 int config_parse_blockio_device_weight(
3762 const char *filename
,
3764 const char *section
,
3765 unsigned section_line
,
3772 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3773 CGroupBlockIODeviceWeight
*w
;
3774 CGroupContext
*c
= data
;
3775 const char *p
= rvalue
;
3783 if (isempty(rvalue
)) {
3784 while (c
->blockio_device_weights
)
3785 cgroup_context_free_blockio_device_weight(c
, c
->blockio_device_weights
);
3790 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3794 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3795 "Invalid syntax, ignoring: %s", rvalue
);
3798 if (r
== 0 || isempty(p
)) {
3799 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3800 "Failed to extract device node and weight from '%s', ignoring.", rvalue
);
3804 r
= unit_full_printf(userdata
, path
, &resolved
);
3806 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3807 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3811 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3815 r
= cg_blkio_weight_parse(p
, &u
);
3817 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid block IO weight '%s', ignoring: %m", p
);
3821 assert(u
!= CGROUP_BLKIO_WEIGHT_INVALID
);
3823 w
= new0(CGroupBlockIODeviceWeight
, 1);
3827 w
->path
= TAKE_PTR(resolved
);
3830 LIST_PREPEND(device_weights
, c
->blockio_device_weights
, w
);
3834 int config_parse_blockio_bandwidth(
3836 const char *filename
,
3838 const char *section
,
3839 unsigned section_line
,
3846 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3847 CGroupBlockIODeviceBandwidth
*b
= NULL
, *t
;
3848 CGroupContext
*c
= data
;
3849 const char *p
= rvalue
;
3858 read
= streq("BlockIOReadBandwidth", lvalue
);
3860 if (isempty(rvalue
)) {
3861 LIST_FOREACH(device_bandwidths
, b
, c
->blockio_device_bandwidths
) {
3862 b
->rbps
= CGROUP_LIMIT_MAX
;
3863 b
->wbps
= CGROUP_LIMIT_MAX
;
3868 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3872 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3873 "Invalid syntax, ignoring: %s", rvalue
);
3876 if (r
== 0 || isempty(p
)) {
3877 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3878 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
3882 r
= unit_full_printf(userdata
, path
, &resolved
);
3884 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3885 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3889 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3893 r
= parse_size(p
, 1000, &bytes
);
3894 if (r
< 0 || bytes
<= 0) {
3895 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid Block IO Bandwidth '%s', ignoring.", p
);
3899 LIST_FOREACH(device_bandwidths
, t
, c
->blockio_device_bandwidths
) {
3900 if (path_equal(resolved
, t
->path
)) {
3907 b
= new0(CGroupBlockIODeviceBandwidth
, 1);
3911 b
->path
= TAKE_PTR(resolved
);
3912 b
->rbps
= CGROUP_LIMIT_MAX
;
3913 b
->wbps
= CGROUP_LIMIT_MAX
;
3915 LIST_PREPEND(device_bandwidths
, c
->blockio_device_bandwidths
, b
);
3926 int config_parse_job_mode_isolate(
3928 const char *filename
,
3930 const char *section
,
3931 unsigned section_line
,
3945 r
= parse_boolean(rvalue
);
3947 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse boolean, ignoring: %s", rvalue
);
3951 log_notice("%s is deprecated. Please use OnFailureJobMode= instead", lvalue
);
3953 *m
= r
? JOB_ISOLATE
: JOB_REPLACE
;
3957 int config_parse_exec_directories(
3959 const char *filename
,
3961 const char *section
,
3962 unsigned section_line
,
3970 const Unit
*u
= userdata
;
3979 if (isempty(rvalue
)) {
3980 /* Empty assignment resets the list */
3981 *rt
= strv_free(*rt
);
3985 for (p
= rvalue
;;) {
3986 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
3988 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3992 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3993 "Invalid syntax, ignoring: %s", rvalue
);
3999 r
= unit_full_printf(u
, word
, &k
);
4001 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4002 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
4006 r
= path_simplify_and_warn(k
, PATH_CHECK_RELATIVE
, unit
, filename
, line
, lvalue
);
4010 if (path_startswith(k
, "private")) {
4011 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
4012 "%s= path can't be 'private', ignoring assignment: %s", lvalue
, word
);
4016 r
= strv_push(rt
, k
);
4023 int config_parse_set_status(
4025 const char *filename
,
4027 const char *section
,
4028 unsigned section_line
,
4036 const char *word
, *state
;
4038 ExitStatusSet
*status_set
= data
;
4045 /* Empty assignment resets the list */
4046 if (isempty(rvalue
)) {
4047 exit_status_set_free(status_set
);
4051 FOREACH_WORD(word
, l
, rvalue
, state
) {
4052 _cleanup_free_
char *temp
;
4055 temp
= strndup(word
, l
);
4059 /* We need to call exit_status_from_string() first, because we want
4060 * to parse numbers as exit statuses, not signals. */
4062 r
= exit_status_from_string(temp
);
4064 assert(r
>= 0 && r
< 256);
4065 bitmap
= &status_set
->status
;
4067 r
= signal_from_string(temp
);
4070 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
4071 "Failed to parse value, ignoring: %s", word
);
4074 bitmap
= &status_set
->signal
;
4077 r
= bitmap_set(bitmap
, r
);
4079 return log_error_errno(r
, "Failed to set signal or status %s: %m", word
);
4081 if (!isempty(state
))
4082 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Trailing garbage, ignoring.");
4087 int config_parse_namespace_path_strv(
4089 const char *filename
,
4091 const char *section
,
4092 unsigned section_line
,
4099 const Unit
*u
= userdata
;
4101 const char *p
= rvalue
;
4109 if (isempty(rvalue
)) {
4110 /* Empty assignment resets the list */
4111 *sv
= strv_free(*sv
);
4116 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
, *joined
= NULL
;
4118 bool ignore_enoent
= false, shall_prefix
= false;
4120 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
4126 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
4131 if (startswith(w
, "-")) {
4132 ignore_enoent
= true;
4135 if (startswith(w
, "+")) {
4136 shall_prefix
= true;
4140 r
= unit_full_printf(u
, w
, &resolved
);
4142 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", w
);
4146 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4150 joined
= strjoin(ignore_enoent
? "-" : "",
4151 shall_prefix
? "+" : "",
4154 r
= strv_push(sv
, joined
);
4164 int config_parse_temporary_filesystems(
4166 const char *filename
,
4168 const char *section
,
4169 unsigned section_line
,
4176 const Unit
*u
= userdata
;
4177 ExecContext
*c
= data
;
4178 const char *p
= rvalue
;
4186 if (isempty(rvalue
)) {
4187 /* Empty assignment resets the list */
4188 temporary_filesystem_free_many(c
->temporary_filesystems
, c
->n_temporary_filesystems
);
4189 c
->temporary_filesystems
= NULL
;
4190 c
->n_temporary_filesystems
= 0;
4195 _cleanup_free_
char *word
= NULL
, *path
= NULL
, *resolved
= NULL
;
4198 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
4204 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
4209 r
= extract_first_word(&w
, &path
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4213 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", word
);
4217 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid syntax, ignoring: %s", word
);
4221 r
= unit_full_printf(u
, path
, &resolved
);
4223 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", path
);
4227 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4231 r
= temporary_filesystem_add(&c
->temporary_filesystems
, &c
->n_temporary_filesystems
, resolved
, w
);
4237 int config_parse_bind_paths(
4239 const char *filename
,
4241 const char *section
,
4242 unsigned section_line
,
4249 ExecContext
*c
= data
;
4250 const Unit
*u
= userdata
;
4259 if (isempty(rvalue
)) {
4260 /* Empty assignment resets the list */
4261 bind_mount_free_many(c
->bind_mounts
, c
->n_bind_mounts
);
4262 c
->bind_mounts
= NULL
;
4263 c
->n_bind_mounts
= 0;
4269 _cleanup_free_
char *source
= NULL
, *destination
= NULL
;
4270 _cleanup_free_
char *sresolved
= NULL
, *dresolved
= NULL
;
4271 char *s
= NULL
, *d
= NULL
;
4272 bool rbind
= true, ignore_enoent
= false;
4274 r
= extract_first_word(&p
, &source
, ":" WHITESPACE
, EXTRACT_UNQUOTE
|EXTRACT_DONT_COALESCE_SEPARATORS
);
4280 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
4284 r
= unit_full_printf(u
, source
, &sresolved
);
4286 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4287 "Failed to resolved unit specifiers in \"%s\", ignoring: %m", source
);
4293 ignore_enoent
= true;
4297 r
= path_simplify_and_warn(s
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4301 /* Optionally, the destination is specified. */
4302 if (p
&& p
[-1] == ':') {
4303 r
= extract_first_word(&p
, &destination
, ":" WHITESPACE
, EXTRACT_UNQUOTE
|EXTRACT_DONT_COALESCE_SEPARATORS
);
4307 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
4311 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Missing argument after ':', ignoring: %s", s
);
4315 r
= unit_full_printf(u
, destination
, &dresolved
);
4317 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4318 "Failed to resolved specifiers in \"%s\", ignoring: %m", destination
);
4322 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4328 /* Optionally, there's also a short option string specified */
4329 if (p
&& p
[-1] == ':') {
4330 _cleanup_free_
char *options
= NULL
;
4332 r
= extract_first_word(&p
, &options
, NULL
, EXTRACT_UNQUOTE
);
4336 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s: %s", lvalue
, rvalue
);
4340 if (isempty(options
) || streq(options
, "rbind"))
4342 else if (streq(options
, "norbind"))
4345 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid option string, ignoring setting: %s", options
);
4352 r
= bind_mount_add(&c
->bind_mounts
, &c
->n_bind_mounts
,
4356 .read_only
= !!strstr(lvalue
, "ReadOnly"),
4358 .ignore_enoent
= ignore_enoent
,
4367 int config_parse_job_timeout_sec(
4369 const char *filename
,
4371 const char *section
,
4372 unsigned section_line
,
4388 r
= parse_sec_fix_0(rvalue
, &usec
);
4390 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse JobTimeoutSec= parameter, ignoring: %s", rvalue
);
4394 /* If the user explicitly changed JobTimeoutSec= also change JobRunningTimeoutSec=, for compatibility with old
4395 * versions. If JobRunningTimeoutSec= was explicitly set, avoid this however as whatever the user picked should
4398 if (!u
->job_running_timeout_set
)
4399 u
->job_running_timeout
= usec
;
4401 u
->job_timeout
= usec
;
4406 int config_parse_job_running_timeout_sec(
4408 const char *filename
,
4410 const char *section
,
4411 unsigned section_line
,
4427 r
= parse_sec_fix_0(rvalue
, &usec
);
4429 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse JobRunningTimeoutSec= parameter, ignoring: %s", rvalue
);
4433 u
->job_running_timeout
= usec
;
4434 u
->job_running_timeout_set
= true;
4439 int config_parse_emergency_action(
4441 const char *filename
,
4443 const char *section
,
4444 unsigned section_line
,
4452 EmergencyAction
*x
= data
;
4461 m
= ((Unit
*) userdata
)->manager
;
4465 r
= parse_emergency_action(rvalue
, MANAGER_IS_SYSTEM(m
), x
);
4467 if (r
== -EOPNOTSUPP
&& MANAGER_IS_USER(m
)) {
4468 /* Compat mode: remove for systemd 241. */
4470 log_syntax(unit
, LOG_INFO
, filename
, line
, r
,
4471 "%s= in user mode specified as \"%s\", using \"exit-force\" instead.",
4473 *x
= EMERGENCY_ACTION_EXIT_FORCE
;
4477 if (r
== -EOPNOTSUPP
)
4478 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4479 "%s= specified as %s mode action, ignoring: %s",
4480 lvalue
, MANAGER_IS_SYSTEM(m
) ? "user" : "system", rvalue
);
4482 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4483 "Failed to parse %s=, ignoring: %s", lvalue
, rvalue
);
4490 int config_parse_pid_file(
4492 const char *filename
,
4494 const char *section
,
4495 unsigned section_line
,
4502 _cleanup_free_
char *k
= NULL
, *n
= NULL
;
4503 const Unit
*u
= userdata
;
4512 if (isempty(rvalue
)) {
4513 /* An empty assignment removes already set value. */
4518 r
= unit_full_printf(u
, rvalue
, &k
);
4520 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
4524 /* If this is a relative path make it absolute by prefixing the /run */
4525 n
= path_make_absolute(k
, u
->manager
->prefix
[EXEC_DIRECTORY_RUNTIME
]);
4529 /* Check that the result is a sensible path */
4530 r
= path_simplify_and_warn(n
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4534 r
= patch_var_run(unit
, filename
, line
, lvalue
, &n
);
4538 free_and_replace(*s
, n
);
4542 int config_parse_exit_status(
4544 const char *filename
,
4546 const char *section
,
4547 unsigned section_line
,
4554 int *exit_status
= data
, r
;
4560 assert(exit_status
);
4562 if (isempty(rvalue
)) {
4567 r
= safe_atou8(rvalue
, &u
);
4569 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse exit status '%s', ignoring: %m", rvalue
);
4577 int config_parse_disable_controllers(
4579 const char *filename
,
4581 const char *section
,
4582 unsigned section_line
,
4590 CGroupContext
*c
= data
;
4591 CGroupMask disabled_mask
;
4593 /* 1. If empty, make all controllers eligible for use again.
4594 * 2. If non-empty, merge all listed controllers, space separated. */
4596 if (isempty(rvalue
)) {
4597 c
->disable_controllers
= 0;
4601 r
= cg_mask_from_string(rvalue
, &disabled_mask
);
4602 if (r
< 0 || disabled_mask
<= 0) {
4603 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid cgroup string: %s, ignoring", rvalue
);
4607 c
->disable_controllers
|= disabled_mask
;
4612 int config_parse_ip_filter_bpf_progs(
4614 const char *filename
,
4616 const char *section
,
4617 unsigned section_line
,
4624 _cleanup_free_
char *resolved
= NULL
;
4625 const Unit
*u
= userdata
;
4626 char ***paths
= data
;
4634 if (isempty(rvalue
)) {
4635 *paths
= strv_free(*paths
);
4639 r
= unit_full_printf(u
, rvalue
, &resolved
);
4641 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
4645 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4649 if (strv_contains(*paths
, resolved
))
4652 r
= strv_extend(paths
, resolved
);
4656 r
= bpf_firewall_supported();
4659 if (r
!= BPF_FIREWALL_SUPPORTED_WITH_MULTI
) {
4660 static bool warned
= false;
4662 log_full(warned
? LOG_DEBUG
: LOG_WARNING
,
4663 "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"
4664 "Starting this unit will fail! (This warning is only shown for the first loaded unit using IP firewalling.)", filename
, line
, lvalue
, rvalue
);
4672 static int merge_by_names(Unit
**u
, Set
*names
, const char *id
) {
4679 /* Let's try to add in all names that are aliases of this unit */
4680 while ((k
= set_steal_first(names
))) {
4681 _cleanup_free_ _unused_
char *free_k
= k
;
4683 /* First try to merge in the other name into our unit */
4684 r
= unit_merge_by_name(*u
, k
);
4688 /* Hmm, we couldn't merge the other unit into ours? Then let's try it the other way
4691 other
= manager_get_unit((*u
)->manager
, k
);
4693 return r
; /* return previous failure */
4695 r
= unit_merge(other
, *u
);
4700 return merge_by_names(u
, names
, NULL
);
4703 if (streq_ptr(id
, k
))
4704 unit_choose_id(*u
, id
);
4710 int unit_load_fragment(Unit
*u
) {
4711 const char *fragment
;
4712 _cleanup_set_free_free_ Set
*names
= NULL
;
4717 assert(u
->load_state
== UNIT_STUB
);
4721 u
->load_state
= UNIT_LOADED
;
4725 /* Possibly rebuild the fragment map to catch new units */
4726 r
= unit_file_build_name_map(&u
->manager
->lookup_paths
,
4727 &u
->manager
->unit_cache_mtime
,
4728 &u
->manager
->unit_id_map
,
4729 &u
->manager
->unit_name_map
,
4730 &u
->manager
->unit_path_cache
);
4732 log_error_errno(r
, "Failed to rebuild name map: %m");
4734 r
= unit_file_find_fragment(u
->manager
->unit_id_map
,
4735 u
->manager
->unit_name_map
,
4739 if (r
< 0 && r
!= -ENOENT
)
4743 /* Open the file, check if this is a mask, otherwise read. */
4744 _cleanup_fclose_
FILE *f
= NULL
;
4746 /* Try to open the file name. A symlink is OK, for example for linked files or masks. We
4747 * expect that all symlinks within the lookup paths have been already resolved, but we don't
4748 * verify this here. */
4749 f
= fopen(fragment
, "re");
4751 return log_unit_notice_errno(u
, errno
, "Failed to open %s: %m", fragment
);
4753 if (fstat(fileno(f
), &st
) < 0)
4756 r
= free_and_strdup(&u
->fragment_path
, fragment
);
4760 if (null_or_empty(&st
)) {
4761 /* Unit file is masked */
4763 u
->load_state
= u
->perpetual
? UNIT_LOADED
: UNIT_MASKED
; /* don't allow perpetual units to ever be masked */
4764 u
->fragment_mtime
= 0;
4766 u
->load_state
= UNIT_LOADED
;
4767 u
->fragment_mtime
= timespec_load(&st
.st_mtim
);
4769 /* Now, parse the file contents */
4770 r
= config_parse(u
->id
, fragment
, f
,
4771 UNIT_VTABLE(u
)->sections
,
4772 config_item_perf_lookup
, load_fragment_gperf_lookup
,
4773 CONFIG_PARSE_ALLOW_INCLUDE
, u
);
4775 log_unit_notice_errno(u
, r
, "Unit configuration has fatal error, unit will not be started.");
4781 if (u
->source_path
) {
4782 if (stat(u
->source_path
, &st
) >= 0)
4783 u
->source_mtime
= timespec_load(&st
.st_mtim
);
4785 u
->source_mtime
= 0;
4788 /* We do the merge dance here because for some unit types, the unit might have aliases which are not
4789 * declared in the file system. In particular, this is true (and frequent) for device and swap units.
4792 const char *id
= u
->id
;
4793 _cleanup_free_
char *free_id
= NULL
;
4796 id
= basename(fragment
);
4797 if (unit_name_is_valid(id
, UNIT_NAME_TEMPLATE
)) {
4798 assert(u
->instance
); /* If we're not trying to use a template for non-instanced unit,
4799 * this must be set. */
4801 r
= unit_name_replace_instance(id
, u
->instance
, &free_id
);
4803 return log_debug_errno(r
, "Failed to build id (%s + %s): %m", id
, u
->instance
);
4809 r
= merge_by_names(&merged
, names
, id
);
4814 u
->load_state
= UNIT_MERGED
;
4819 void unit_dump_config_items(FILE *f
) {
4820 static const struct {
4821 const ConfigParserCallback callback
;
4824 { config_parse_warn_compat
, "NOTSUPPORTED" },
4825 { config_parse_int
, "INTEGER" },
4826 { config_parse_unsigned
, "UNSIGNED" },
4827 { config_parse_iec_size
, "SIZE" },
4828 { config_parse_iec_uint64
, "SIZE" },
4829 { config_parse_si_uint64
, "SIZE" },
4830 { config_parse_bool
, "BOOLEAN" },
4831 { config_parse_string
, "STRING" },
4832 { config_parse_path
, "PATH" },
4833 { config_parse_unit_path_printf
, "PATH" },
4834 { config_parse_strv
, "STRING [...]" },
4835 { config_parse_exec_nice
, "NICE" },
4836 { config_parse_exec_oom_score_adjust
, "OOMSCOREADJUST" },
4837 { config_parse_exec_io_class
, "IOCLASS" },
4838 { config_parse_exec_io_priority
, "IOPRIORITY" },
4839 { config_parse_exec_cpu_sched_policy
, "CPUSCHEDPOLICY" },
4840 { config_parse_exec_cpu_sched_prio
, "CPUSCHEDPRIO" },
4841 { config_parse_exec_cpu_affinity
, "CPUAFFINITY" },
4842 { config_parse_mode
, "MODE" },
4843 { config_parse_unit_env_file
, "FILE" },
4844 { config_parse_exec_output
, "OUTPUT" },
4845 { config_parse_exec_input
, "INPUT" },
4846 { config_parse_log_facility
, "FACILITY" },
4847 { config_parse_log_level
, "LEVEL" },
4848 { config_parse_exec_secure_bits
, "SECUREBITS" },
4849 { config_parse_capability_set
, "BOUNDINGSET" },
4850 { config_parse_rlimit
, "LIMIT" },
4851 { config_parse_unit_deps
, "UNIT [...]" },
4852 { config_parse_exec
, "PATH [ARGUMENT [...]]" },
4853 { config_parse_service_type
, "SERVICETYPE" },
4854 { config_parse_service_restart
, "SERVICERESTART" },
4855 { config_parse_kill_mode
, "KILLMODE" },
4856 { config_parse_signal
, "SIGNAL" },
4857 { config_parse_socket_listen
, "SOCKET [...]" },
4858 { config_parse_socket_bind
, "SOCKETBIND" },
4859 { config_parse_socket_bindtodevice
, "NETWORKINTERFACE" },
4860 { config_parse_sec
, "SECONDS" },
4861 { config_parse_nsec
, "NANOSECONDS" },
4862 { config_parse_namespace_path_strv
, "PATH [...]" },
4863 { config_parse_bind_paths
, "PATH[:PATH[:OPTIONS]] [...]" },
4864 { config_parse_unit_requires_mounts_for
, "PATH [...]" },
4865 { config_parse_exec_mount_flags
, "MOUNTFLAG [...]" },
4866 { config_parse_unit_string_printf
, "STRING" },
4867 { config_parse_trigger_unit
, "UNIT" },
4868 { config_parse_timer
, "TIMER" },
4869 { config_parse_path_spec
, "PATH" },
4870 { config_parse_notify_access
, "ACCESS" },
4871 { config_parse_ip_tos
, "TOS" },
4872 { config_parse_unit_condition_path
, "CONDITION" },
4873 { config_parse_unit_condition_string
, "CONDITION" },
4874 { config_parse_unit_condition_null
, "CONDITION" },
4875 { config_parse_unit_slice
, "SLICE" },
4876 { config_parse_documentation
, "URL" },
4877 { config_parse_service_timeout
, "SECONDS" },
4878 { config_parse_emergency_action
, "ACTION" },
4879 { config_parse_set_status
, "STATUS" },
4880 { config_parse_service_sockets
, "SOCKETS" },
4881 { config_parse_environ
, "ENVIRON" },
4883 { config_parse_syscall_filter
, "SYSCALLS" },
4884 { config_parse_syscall_archs
, "ARCHS" },
4885 { config_parse_syscall_errno
, "ERRNO" },
4886 { config_parse_address_families
, "FAMILIES" },
4887 { config_parse_restrict_namespaces
, "NAMESPACES" },
4889 { config_parse_cpu_shares
, "SHARES" },
4890 { config_parse_cg_weight
, "WEIGHT" },
4891 { config_parse_memory_limit
, "LIMIT" },
4892 { config_parse_device_allow
, "DEVICE" },
4893 { config_parse_device_policy
, "POLICY" },
4894 { config_parse_io_limit
, "LIMIT" },
4895 { config_parse_io_device_weight
, "DEVICEWEIGHT" },
4896 { config_parse_io_device_latency
, "DEVICELATENCY" },
4897 { config_parse_blockio_bandwidth
, "BANDWIDTH" },
4898 { config_parse_blockio_weight
, "WEIGHT" },
4899 { config_parse_blockio_device_weight
, "DEVICEWEIGHT" },
4900 { config_parse_long
, "LONG" },
4901 { config_parse_socket_service
, "SERVICE" },
4903 { config_parse_exec_selinux_context
, "LABEL" },
4905 { config_parse_job_mode
, "MODE" },
4906 { config_parse_job_mode_isolate
, "BOOLEAN" },
4907 { config_parse_personality
, "PERSONALITY" },
4910 const char *prev
= NULL
;
4915 NULSTR_FOREACH(i
, load_fragment_gperf_nulstr
) {
4916 const char *rvalue
= "OTHER", *lvalue
;
4917 const ConfigPerfItem
*p
;
4922 assert_se(p
= load_fragment_gperf_lookup(i
, strlen(i
)));
4924 /* Hide legacy settings */
4925 if (p
->parse
== config_parse_warn_compat
&&
4926 p
->ltype
== DISABLED_LEGACY
)
4929 for (j
= 0; j
< ELEMENTSOF(table
); j
++)
4930 if (p
->parse
== table
[j
].callback
) {
4931 rvalue
= table
[j
].rvalue
;
4935 dot
= strchr(i
, '.');
4936 lvalue
= dot
? dot
+ 1 : i
;
4940 if (!prev
|| !strneq(prev
, i
, prefix_len
+1)) {
4944 fprintf(f
, "[%.*s]\n", (int) prefix_len
, i
);
4947 fprintf(f
, "%s=%s\n", lvalue
, rvalue
);
4952 int config_parse_cpu_affinity2(
4954 const char *filename
,
4956 const char *section
,
4957 unsigned section_line
,
4964 CPUSet
*affinity
= data
;
4968 (void) parse_cpu_set_extend(rvalue
, affinity
, true, unit
, filename
, line
, lvalue
);
4973 int config_parse_show_status(
4975 const char *filename
,
4977 const char *section
,
4978 unsigned section_line
,
4986 ShowStatus
*b
= data
;
4993 k
= parse_show_status(rvalue
, b
);
4995 log_syntax(unit
, LOG_ERR
, filename
, line
, k
, "Failed to parse show status setting, ignoring: %s", rvalue
);
5002 int config_parse_output_restricted(
5004 const char *filename
,
5006 const char *section
,
5007 unsigned section_line
,
5014 ExecOutput t
, *eo
= data
;
5021 t
= exec_output_from_string(rvalue
);
5023 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse output type, ignoring: %s", rvalue
);
5027 if (IN_SET(t
, EXEC_OUTPUT_SOCKET
, EXEC_OUTPUT_NAMED_FD
, EXEC_OUTPUT_FILE
, EXEC_OUTPUT_FILE_APPEND
)) {
5028 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Standard output types socket, fd:, file:, append: are not supported as defaults, ignoring: %s", rvalue
);
5036 int config_parse_crash_chvt(
5038 const char *filename
,
5040 const char *section
,
5041 unsigned section_line
,
5055 r
= parse_crash_chvt(rvalue
, data
);
5057 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse CrashChangeVT= setting, ignoring: %s", rvalue
);
5064 int config_parse_swap_priority(
5066 const char *filename
,
5068 const char *section
,
5069 unsigned section_line
,
5085 if (isempty(rvalue
)) {
5086 s
->parameters_fragment
.priority
= -1;
5087 s
->parameters_fragment
.priority_set
= false;
5091 r
= safe_atoi(rvalue
, &priority
);
5093 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid swap pririty '%s', ignoring.", rvalue
);
5097 if (priority
< -1) {
5098 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Sorry, swap priorities smaller than -1 may only be assigned by the kernel itself, ignoring: %s", rvalue
);
5102 if (priority
> 32767) {
5103 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Swap priority out of range, ignoring: %s", rvalue
);
5107 s
->parameters_fragment
.priority
= priority
;
5108 s
->parameters_fragment
.priority_set
= true;