1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 Copyright © 2012 Holger Hans Peter Freyther
15 #include <sys/resource.h>
19 #include "alloc-util.h"
20 #include "all-units.h"
21 #include "bpf-firewall.h"
22 #include "bus-error.h"
23 #include "bus-internal.h"
26 #include "capability-util.h"
28 #include "conf-parser.h"
29 #include "cpu-set-util.h"
31 #include "errno-list.h"
35 #include "hexdecoct.h"
38 #include "ip-protocol-list.h"
39 #include "journal-util.h"
40 #include "limits-util.h"
41 #include "load-fragment.h"
44 #include "mountpoint-util.h"
45 #include "nulstr-util.h"
46 #include "parse-util.h"
47 #include "path-util.h"
48 #include "process-util.h"
50 #include "seccomp-util.h"
52 #include "securebits-util.h"
53 #include "signal-util.h"
54 #include "stat-util.h"
55 #include "string-util.h"
57 #include "unit-name.h"
58 #include "unit-printf.h"
59 #include "user-util.h"
60 #include "time-util.h"
63 static int parse_socket_protocol(const char *s
) {
66 r
= parse_ip_protocol(s
);
69 if (!IN_SET(r
, IPPROTO_UDPLITE
, IPPROTO_SCTP
))
70 return -EPROTONOSUPPORT
;
75 int parse_crash_chvt(const char *value
, int *data
) {
78 if (safe_atoi(value
, data
) >= 0)
81 b
= parse_boolean(value
);
86 *data
= 0; /* switch to where kmsg goes */
88 *data
= -1; /* turn off switching */
93 int parse_confirm_spawn(const char *value
, char **console
) {
97 r
= value
? parse_boolean(value
) : 1;
103 if (r
> 0) /* on with default tty */
104 s
= strdup("/dev/console");
105 else if (is_path(value
)) /* on with fully qualified path */
107 else /* on with only a tty file name, not a fully qualified path */
108 s
= strjoin("/dev/", value
);
116 DEFINE_CONFIG_PARSE(config_parse_socket_protocol
, parse_socket_protocol
, "Failed to parse socket protocol");
117 DEFINE_CONFIG_PARSE(config_parse_exec_secure_bits
, secure_bits_from_string
, "Failed to parse secure bits");
118 DEFINE_CONFIG_PARSE_ENUM(config_parse_collect_mode
, collect_mode
, CollectMode
, "Failed to parse garbage collection mode");
119 DEFINE_CONFIG_PARSE_ENUM(config_parse_device_policy
, cgroup_device_policy
, CGroupDevicePolicy
, "Failed to parse device policy");
120 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_keyring_mode
, exec_keyring_mode
, ExecKeyringMode
, "Failed to parse keyring mode");
121 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_utmp_mode
, exec_utmp_mode
, ExecUtmpMode
, "Failed to parse utmp mode");
122 DEFINE_CONFIG_PARSE_ENUM(config_parse_job_mode
, job_mode
, JobMode
, "Failed to parse job mode");
123 DEFINE_CONFIG_PARSE_ENUM(config_parse_kill_mode
, kill_mode
, KillMode
, "Failed to parse kill mode");
124 DEFINE_CONFIG_PARSE_ENUM(config_parse_notify_access
, notify_access
, NotifyAccess
, "Failed to parse notify access specifier");
125 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_home
, protect_home
, ProtectHome
, "Failed to parse protect home value");
126 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_system
, protect_system
, ProtectSystem
, "Failed to parse protect system value");
127 DEFINE_CONFIG_PARSE_ENUM(config_parse_runtime_preserve_mode
, exec_preserve_mode
, ExecPreserveMode
, "Failed to parse runtime directory preserve mode");
128 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_type
, service_type
, ServiceType
, "Failed to parse service type");
129 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart
, service_restart
, ServiceRestart
, "Failed to parse service restart specifier");
130 DEFINE_CONFIG_PARSE_ENUM(config_parse_socket_bind
, socket_address_bind_ipv6_only_or_bool
, SocketAddressBindIPv6Only
, "Failed to parse bind IPv6 only value");
131 DEFINE_CONFIG_PARSE_ENUM(config_parse_oom_policy
, oom_policy
, OOMPolicy
, "Failed to parse OOM policy");
132 DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_ip_tos
, ip_tos
, int, -1, "Failed to parse IP TOS value");
133 DEFINE_CONFIG_PARSE_PTR(config_parse_blockio_weight
, cg_blkio_weight_parse
, uint64_t, "Invalid block IO weight");
134 DEFINE_CONFIG_PARSE_PTR(config_parse_cg_weight
, cg_weight_parse
, uint64_t, "Invalid weight");
135 DEFINE_CONFIG_PARSE_PTR(config_parse_cpu_shares
, cg_cpu_shares_parse
, uint64_t, "Invalid CPU shares");
136 DEFINE_CONFIG_PARSE_PTR(config_parse_exec_mount_flags
, mount_propagation_flags_from_string
, unsigned long, "Failed to parse mount flag");
137 DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_numa_policy
, mpol
, int, -1, "Invalid NUMA policy type");
139 int config_parse_unit_deps(
141 const char *filename
,
144 unsigned section_line
,
151 UnitDependency d
= ltype
;
161 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
164 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_RETAIN_ESCAPE
);
170 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
174 r
= unit_name_printf(u
, word
, &k
);
176 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
180 r
= unit_add_dependency_by_name(u
, d
, k
, true, UNIT_DEPENDENCY_FILE
);
182 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
188 int config_parse_obsolete_unit_deps(
190 const char *filename
,
193 unsigned section_line
,
200 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
201 "Unit dependency type %s= is obsolete, replacing by %s=, please update your unit file", lvalue
, unit_dependency_to_string(ltype
));
203 return config_parse_unit_deps(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
);
206 int config_parse_unit_string_printf(
208 const char *filename
,
211 unsigned section_line
,
218 _cleanup_free_
char *k
= NULL
;
227 r
= unit_full_printf(u
, rvalue
, &k
);
229 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
233 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
236 int config_parse_unit_strv_printf(
238 const char *filename
,
241 unsigned section_line
,
249 _cleanup_free_
char *k
= NULL
;
257 r
= unit_full_printf(u
, rvalue
, &k
);
259 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
263 return config_parse_strv(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
266 int config_parse_unit_path_printf(
268 const char *filename
,
271 unsigned section_line
,
278 _cleanup_free_
char *k
= NULL
;
288 /* Let's not bother with anything that is too long */
289 if (strlen(rvalue
) >= PATH_MAX
) {
290 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
291 "%s value too long%s.",
292 lvalue
, fatal
? "" : ", ignoring");
293 return fatal
? -ENAMETOOLONG
: 0;
296 r
= unit_full_printf(u
, rvalue
, &k
);
298 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
299 "Failed to resolve unit specifiers in '%s'%s: %m",
300 rvalue
, fatal
? "" : ", ignoring");
301 return fatal
? -ENOEXEC
: 0;
304 return config_parse_path(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
307 int config_parse_unit_path_strv_printf(
309 const char *filename
,
312 unsigned section_line
,
329 if (isempty(rvalue
)) {
335 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
337 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
343 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
344 "Invalid syntax, ignoring: %s", rvalue
);
348 r
= unit_full_printf(u
, word
, &k
);
350 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
351 "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
355 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
359 r
= strv_consume(x
, TAKE_PTR(k
));
365 static int patch_var_run(
367 const char *filename
,
375 e
= path_startswith(*path
, "/var/run/");
379 z
= path_join("/run/", e
);
383 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
384 "%s= references a path below legacy directory /var/run/, updating %s → %s; "
385 "please update the unit file accordingly.", lvalue
, *path
, z
);
387 free_and_replace(*path
, z
);
392 int config_parse_socket_listen(
394 const char *filename
,
397 unsigned section_line
,
404 _cleanup_free_ SocketPort
*p
= NULL
;
416 if (isempty(rvalue
)) {
417 /* An empty assignment removes all ports */
418 socket_free_ports(s
);
422 p
= new0(SocketPort
, 1);
426 if (ltype
!= SOCKET_SOCKET
) {
427 _cleanup_free_
char *k
= NULL
;
429 r
= unit_full_printf(UNIT(s
), rvalue
, &k
);
431 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
435 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
439 if (ltype
== SOCKET_FIFO
) {
440 r
= patch_var_run(unit
, filename
, line
, lvalue
, &k
);
445 free_and_replace(p
->path
, k
);
448 } else if (streq(lvalue
, "ListenNetlink")) {
449 _cleanup_free_
char *k
= NULL
;
451 r
= unit_full_printf(UNIT(s
), rvalue
, &k
);
453 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
457 r
= socket_address_parse_netlink(&p
->address
, k
);
459 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse address value in '%s', ignoring: %m", k
);
463 p
->type
= SOCKET_SOCKET
;
466 _cleanup_free_
char *k
= NULL
;
468 r
= unit_full_printf(UNIT(s
), rvalue
, &k
);
470 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
474 if (k
[0] == '/') { /* Only for AF_UNIX file system sockets… */
475 r
= patch_var_run(unit
, filename
, line
, lvalue
, &k
);
480 r
= socket_address_parse_and_warn(&p
->address
, k
);
482 if (r
!= -EAFNOSUPPORT
)
483 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse address value in '%s', ignoring: %m", k
);
487 if (streq(lvalue
, "ListenStream"))
488 p
->address
.type
= SOCK_STREAM
;
489 else if (streq(lvalue
, "ListenDatagram"))
490 p
->address
.type
= SOCK_DGRAM
;
492 assert(streq(lvalue
, "ListenSequentialPacket"));
493 p
->address
.type
= SOCK_SEQPACKET
;
496 if (socket_address_family(&p
->address
) != AF_LOCAL
&& p
->address
.type
== SOCK_SEQPACKET
) {
497 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Address family not supported, ignoring: %s", rvalue
);
501 p
->type
= SOCKET_SOCKET
;
505 p
->auxiliary_fds
= NULL
;
506 p
->n_auxiliary_fds
= 0;
509 LIST_FIND_TAIL(port
, s
->ports
, tail
);
510 LIST_INSERT_AFTER(port
, s
->ports
, tail
, p
);
517 int config_parse_exec_nice(
519 const char *filename
,
522 unsigned section_line
,
529 ExecContext
*c
= data
;
537 if (isempty(rvalue
)) {
542 r
= parse_nice(rvalue
, &priority
);
545 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Nice priority out of range, ignoring: %s", rvalue
);
547 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse nice priority '%s', ignoring: %m", rvalue
);
557 int config_parse_exec_oom_score_adjust(
559 const char *filename
,
562 unsigned section_line
,
569 ExecContext
*c
= data
;
577 if (isempty(rvalue
)) {
578 c
->oom_score_adjust_set
= false;
582 r
= parse_oom_score_adjust(rvalue
, &oa
);
585 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "OOM score adjust value out of range, ignoring: %s", rvalue
);
587 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse the OOM score adjust value '%s', ignoring: %m", rvalue
);
591 c
->oom_score_adjust
= oa
;
592 c
->oom_score_adjust_set
= true;
597 int config_parse_exec(
599 const char *filename
,
602 unsigned section_line
,
609 ExecCommand
**e
= data
;
621 rvalue
+= strspn(rvalue
, WHITESPACE
);
623 if (isempty(rvalue
)) {
624 /* An empty assignment resets the list */
625 *e
= exec_command_free_list(*e
);
631 _cleanup_free_
char *path
= NULL
, *firstword
= NULL
;
632 ExecCommandFlags flags
= 0;
633 bool ignore
= false, separate_argv0
= false;
634 _cleanup_free_ ExecCommand
*nce
= NULL
;
635 _cleanup_strv_free_
char **n
= NULL
;
636 size_t nlen
= 0, nbufsize
= 0;
641 r
= extract_first_word_and_warn(&p
, &firstword
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
647 /* We accept an absolute path as first argument. If it's prefixed with - and the path doesn't
648 * exist, we ignore it instead of erroring out; if it's prefixed with @, we allow overriding of
649 * argv[0]; if it's prefixed with :, we will not do environment variable substitution;
650 * if it's prefixed with +, it will be run with full privileges and no sandboxing; if
651 * it's prefixed with '!' we apply sandboxing, but do not change user/group credentials; if
652 * it's prefixed with '!!', then we apply user/group credentials if the kernel supports ambient
653 * capabilities -- if it doesn't we don't apply the credentials themselves, but do apply most
654 * other sandboxing, with some special exceptions for changing UID.
656 * The idea is that '!!' may be used to write services that can take benefit of systemd's
657 * UID/GID dropping if the kernel supports ambient creds, but provide an automatic fallback to
658 * privilege dropping within the daemon if the kernel does not offer that. */
660 if (*f
== '-' && !(flags
& EXEC_COMMAND_IGNORE_FAILURE
)) {
661 flags
|= EXEC_COMMAND_IGNORE_FAILURE
;
663 } else if (*f
== '@' && !separate_argv0
)
664 separate_argv0
= true;
665 else if (*f
== ':' && !(flags
& EXEC_COMMAND_NO_ENV_EXPAND
))
666 flags
|= EXEC_COMMAND_NO_ENV_EXPAND
;
667 else if (*f
== '+' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
668 flags
|= EXEC_COMMAND_FULLY_PRIVILEGED
;
669 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
670 flags
|= EXEC_COMMAND_NO_SETUID
;
671 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_AMBIENT_MAGIC
))) {
672 flags
&= ~EXEC_COMMAND_NO_SETUID
;
673 flags
|= EXEC_COMMAND_AMBIENT_MAGIC
;
679 r
= unit_full_printf(u
, f
, &path
);
681 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
682 "Failed to resolve unit specifiers in '%s'%s: %m",
683 f
, ignore
? ", ignoring" : "");
684 return ignore
? 0 : -ENOEXEC
;
688 /* First word is either "-" or "@" with no command. */
689 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
690 "Empty path in command line%s: '%s'",
691 ignore
? ", ignoring" : "", rvalue
);
692 return ignore
? 0 : -ENOEXEC
;
694 if (!string_is_safe(path
)) {
695 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
696 "Executable name contains special characters%s: %s",
697 ignore
? ", ignoring" : "", path
);
698 return ignore
? 0 : -ENOEXEC
;
700 if (endswith(path
, "/")) {
701 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
702 "Executable path specifies a directory%s: %s",
703 ignore
? ", ignoring" : "", path
);
704 return ignore
? 0 : -ENOEXEC
;
707 if (!path_is_absolute(path
)) {
711 if (!filename_is_valid(path
)) {
712 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
713 "Neither a valid executable name nor an absolute path%s: %s",
714 ignore
? ", ignoring" : "", path
);
715 return ignore
? 0 : -ENOEXEC
;
718 /* Resolve a single-component name to a full path */
719 NULSTR_FOREACH(prefix
, DEFAULT_PATH_NULSTR
) {
720 _cleanup_free_
char *fullpath
= NULL
;
722 fullpath
= path_join(prefix
, path
);
726 if (access(fullpath
, F_OK
) >= 0) {
727 free_and_replace(path
, fullpath
);
734 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
735 "Executable \"%s\" not found in path \"%s\"%s",
736 path
, DEFAULT_PATH
, ignore
? ", ignoring" : "");
737 return ignore
? 0 : -ENOEXEC
;
741 if (!separate_argv0
) {
744 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
754 path_simplify(path
, false);
756 while (!isempty(p
)) {
757 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
759 /* Check explicitly for an unquoted semicolon as
760 * command separator token. */
761 if (p
[0] == ';' && (!p
[1] || strchr(WHITESPACE
, p
[1]))) {
763 p
+= strspn(p
, WHITESPACE
);
768 /* Check for \; explicitly, to not confuse it with \\; or "\;" or "\\;" etc.
769 * extract_first_word() would return the same for all of those. */
770 if (p
[0] == '\\' && p
[1] == ';' && (!p
[2] || strchr(WHITESPACE
, p
[2]))) {
774 p
+= strspn(p
, WHITESPACE
);
776 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
787 r
= extract_first_word_and_warn(&p
, &word
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
791 return ignore
? 0 : -ENOEXEC
;
793 r
= unit_full_printf(u
, word
, &resolved
);
795 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
796 "Failed to resolve unit specifiers in %s%s: %m",
797 word
, ignore
? ", ignoring" : "");
798 return ignore
? 0 : -ENOEXEC
;
801 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
804 n
[nlen
++] = TAKE_PTR(resolved
);
809 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
810 "Empty executable name or zeroeth argument%s: %s",
811 ignore
? ", ignoring" : "", rvalue
);
812 return ignore
? 0 : -ENOEXEC
;
815 nce
= new0(ExecCommand
, 1);
819 nce
->argv
= TAKE_PTR(n
);
820 nce
->path
= TAKE_PTR(path
);
823 exec_command_append_list(e
, nce
);
825 /* Do not _cleanup_free_ these. */
834 int config_parse_socket_bindtodevice(
836 const char *filename
,
839 unsigned section_line
,
853 if (isempty(rvalue
) || streq(rvalue
, "*")) {
854 s
->bind_to_device
= mfree(s
->bind_to_device
);
858 if (!ifname_valid(rvalue
)) {
859 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid interface name, ignoring: %s", rvalue
);
863 if (free_and_strdup(&s
->bind_to_device
, rvalue
) < 0)
869 int config_parse_exec_input(
871 const char *filename
,
874 unsigned section_line
,
881 ExecContext
*c
= data
;
892 n
= startswith(rvalue
, "fd:");
894 _cleanup_free_
char *resolved
= NULL
;
896 r
= unit_full_printf(u
, n
, &resolved
);
898 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s': %m", n
);
900 if (isempty(resolved
))
901 resolved
= mfree(resolved
);
902 else if (!fdname_is_valid(resolved
)) {
903 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name: %s", resolved
);
907 free_and_replace(c
->stdio_fdname
[STDIN_FILENO
], resolved
);
909 ei
= EXEC_INPUT_NAMED_FD
;
911 } else if ((n
= startswith(rvalue
, "file:"))) {
912 _cleanup_free_
char *resolved
= NULL
;
914 r
= unit_full_printf(u
, n
, &resolved
);
916 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s': %m", n
);
918 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
922 free_and_replace(c
->stdio_file
[STDIN_FILENO
], resolved
);
924 ei
= EXEC_INPUT_FILE
;
927 ei
= exec_input_from_string(rvalue
);
929 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse input specifier, ignoring: %s", rvalue
);
938 int config_parse_exec_input_text(
940 const char *filename
,
943 unsigned section_line
,
950 _cleanup_free_
char *unescaped
= NULL
, *resolved
= NULL
;
951 ExecContext
*c
= data
;
962 if (isempty(rvalue
)) {
963 /* Reset if the empty string is assigned */
964 c
->stdin_data
= mfree(c
->stdin_data
);
965 c
->stdin_data_size
= 0;
969 r
= cunescape(rvalue
, 0, &unescaped
);
971 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to decode C escaped text '%s': %m", rvalue
);
973 r
= unit_full_printf(u
, unescaped
, &resolved
);
975 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s': %m", unescaped
);
977 sz
= strlen(resolved
);
978 if (c
->stdin_data_size
+ sz
+ 1 < c
->stdin_data_size
|| /* check for overflow */
979 c
->stdin_data_size
+ sz
+ 1 > EXEC_STDIN_DATA_MAX
) {
980 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
);
984 p
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
+ 1);
988 *((char*) mempcpy((char*) p
+ c
->stdin_data_size
, resolved
, sz
)) = '\n';
991 c
->stdin_data_size
+= sz
+ 1;
996 int config_parse_exec_input_data(
998 const char *filename
,
1000 const char *section
,
1001 unsigned section_line
,
1008 _cleanup_free_
void *p
= NULL
;
1009 ExecContext
*c
= data
;
1019 if (isempty(rvalue
)) {
1020 /* Reset if the empty string is assigned */
1021 c
->stdin_data
= mfree(c
->stdin_data
);
1022 c
->stdin_data_size
= 0;
1026 r
= unbase64mem(rvalue
, (size_t) -1, &p
, &sz
);
1028 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to decode base64 data, ignoring: %s", rvalue
);
1032 if (c
->stdin_data_size
+ sz
< c
->stdin_data_size
|| /* check for overflow */
1033 c
->stdin_data_size
+ sz
> EXEC_STDIN_DATA_MAX
) {
1034 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
);
1038 q
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
);
1042 memcpy((uint8_t*) q
+ c
->stdin_data_size
, p
, sz
);
1045 c
->stdin_data_size
+= sz
;
1050 int config_parse_exec_output(
1052 const char *filename
,
1054 const char *section
,
1055 unsigned section_line
,
1062 _cleanup_free_
char *resolved
= NULL
;
1064 ExecContext
*c
= data
;
1075 n
= startswith(rvalue
, "fd:");
1077 r
= unit_full_printf(u
, n
, &resolved
);
1079 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", n
);
1081 if (isempty(resolved
))
1082 resolved
= mfree(resolved
);
1083 else if (!fdname_is_valid(resolved
)) {
1084 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name: %s", resolved
);
1088 eo
= EXEC_OUTPUT_NAMED_FD
;
1090 } else if ((n
= startswith(rvalue
, "file:"))) {
1092 r
= unit_full_printf(u
, n
, &resolved
);
1094 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", n
);
1096 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1100 eo
= EXEC_OUTPUT_FILE
;
1102 } else if ((n
= startswith(rvalue
, "append:"))) {
1104 r
= unit_full_printf(u
, n
, &resolved
);
1106 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", n
);
1108 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1112 eo
= EXEC_OUTPUT_FILE_APPEND
;
1114 eo
= exec_output_from_string(rvalue
);
1116 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse output specifier, ignoring: %s", rvalue
);
1121 if (streq(lvalue
, "StandardOutput")) {
1122 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1123 free_and_replace(c
->stdio_fdname
[STDOUT_FILENO
], resolved
);
1125 free_and_replace(c
->stdio_file
[STDOUT_FILENO
], resolved
);
1130 assert(streq(lvalue
, "StandardError"));
1132 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1133 free_and_replace(c
->stdio_fdname
[STDERR_FILENO
], resolved
);
1135 free_and_replace(c
->stdio_file
[STDERR_FILENO
], resolved
);
1143 int config_parse_exec_io_class(const char *unit
,
1144 const char *filename
,
1146 const char *section
,
1147 unsigned section_line
,
1154 ExecContext
*c
= data
;
1162 if (isempty(rvalue
)) {
1163 c
->ioprio_set
= false;
1164 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE
, 0);
1168 x
= ioprio_class_from_string(rvalue
);
1170 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse IO scheduling class, ignoring: %s", rvalue
);
1174 c
->ioprio
= IOPRIO_PRIO_VALUE(x
, IOPRIO_PRIO_DATA(c
->ioprio
));
1175 c
->ioprio_set
= true;
1180 int config_parse_exec_io_priority(const char *unit
,
1181 const char *filename
,
1183 const char *section
,
1184 unsigned section_line
,
1191 ExecContext
*c
= data
;
1199 if (isempty(rvalue
)) {
1200 c
->ioprio_set
= false;
1201 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE
, 0);
1205 r
= ioprio_parse_priority(rvalue
, &i
);
1207 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse IO priority, ignoring: %s", rvalue
);
1211 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_PRIO_CLASS(c
->ioprio
), i
);
1212 c
->ioprio_set
= true;
1217 int config_parse_exec_cpu_sched_policy(const char *unit
,
1218 const char *filename
,
1220 const char *section
,
1221 unsigned section_line
,
1228 ExecContext
*c
= data
;
1236 if (isempty(rvalue
)) {
1237 c
->cpu_sched_set
= false;
1238 c
->cpu_sched_policy
= SCHED_OTHER
;
1239 c
->cpu_sched_priority
= 0;
1243 x
= sched_policy_from_string(rvalue
);
1245 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse CPU scheduling policy, ignoring: %s", rvalue
);
1249 c
->cpu_sched_policy
= x
;
1250 /* Moving to or from real-time policy? We need to adjust the priority */
1251 c
->cpu_sched_priority
= CLAMP(c
->cpu_sched_priority
, sched_get_priority_min(x
), sched_get_priority_max(x
));
1252 c
->cpu_sched_set
= true;
1257 int config_parse_numa_mask(const char *unit
,
1258 const char *filename
,
1260 const char *section
,
1261 unsigned section_line
,
1268 NUMAPolicy
*p
= data
;
1275 r
= parse_cpu_set_extend(rvalue
, &p
->nodes
, true, unit
, filename
, line
, lvalue
);
1277 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse NUMA node mask, ignoring: %s", rvalue
);
1284 int config_parse_exec_cpu_sched_prio(const char *unit
,
1285 const char *filename
,
1287 const char *section
,
1288 unsigned section_line
,
1295 ExecContext
*c
= data
;
1303 r
= safe_atoi(rvalue
, &i
);
1305 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse CPU scheduling priority, ignoring: %s", rvalue
);
1309 /* On Linux RR/FIFO range from 1 to 99 and OTHER/BATCH may only be 0 */
1310 min
= sched_get_priority_min(c
->cpu_sched_policy
);
1311 max
= sched_get_priority_max(c
->cpu_sched_policy
);
1313 if (i
< min
|| i
> max
) {
1314 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "CPU scheduling priority is out of range, ignoring: %s", rvalue
);
1318 c
->cpu_sched_priority
= i
;
1319 c
->cpu_sched_set
= true;
1324 int config_parse_exec_cpu_affinity(const char *unit
,
1325 const char *filename
,
1327 const char *section
,
1328 unsigned section_line
,
1335 ExecContext
*c
= data
;
1342 return parse_cpu_set_extend(rvalue
, &c
->cpu_set
, true, unit
, filename
, line
, lvalue
);
1345 int config_parse_capability_set(
1347 const char *filename
,
1349 const char *section
,
1350 unsigned section_line
,
1357 uint64_t *capability_set
= data
;
1358 uint64_t sum
= 0, initial
= 0;
1359 bool invert
= false;
1367 if (rvalue
[0] == '~') {
1372 if (streq(lvalue
, "CapabilityBoundingSet"))
1373 initial
= CAP_ALL
; /* initialized to all bits on */
1374 /* else "AmbientCapabilities" initialized to all bits off */
1376 r
= capability_set_from_string(rvalue
, &sum
);
1378 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= specifier '%s', ignoring: %m", lvalue
, rvalue
);
1382 if (sum
== 0 || *capability_set
== initial
)
1383 /* "", "~" or uninitialized data -> replace */
1384 *capability_set
= invert
? ~sum
: sum
;
1386 /* previous data -> merge */
1388 *capability_set
&= ~sum
;
1390 *capability_set
|= sum
;
1396 int config_parse_exec_selinux_context(
1398 const char *filename
,
1400 const char *section
,
1401 unsigned section_line
,
1408 ExecContext
*c
= data
;
1419 if (isempty(rvalue
)) {
1420 c
->selinux_context
= mfree(c
->selinux_context
);
1421 c
->selinux_context_ignore
= false;
1425 if (rvalue
[0] == '-') {
1431 r
= unit_full_printf(u
, rvalue
, &k
);
1433 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1434 "Failed to resolve unit specifiers in '%s'%s: %m",
1435 rvalue
, ignore
? ", ignoring" : "");
1436 return ignore
? 0 : -ENOEXEC
;
1439 free_and_replace(c
->selinux_context
, k
);
1440 c
->selinux_context_ignore
= ignore
;
1445 int config_parse_exec_apparmor_profile(
1447 const char *filename
,
1449 const char *section
,
1450 unsigned section_line
,
1457 ExecContext
*c
= data
;
1468 if (isempty(rvalue
)) {
1469 c
->apparmor_profile
= mfree(c
->apparmor_profile
);
1470 c
->apparmor_profile_ignore
= false;
1474 if (rvalue
[0] == '-') {
1480 r
= unit_full_printf(u
, rvalue
, &k
);
1482 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1483 "Failed to resolve unit specifiers in '%s'%s: %m",
1484 rvalue
, ignore
? ", ignoring" : "");
1485 return ignore
? 0 : -ENOEXEC
;
1488 free_and_replace(c
->apparmor_profile
, k
);
1489 c
->apparmor_profile_ignore
= ignore
;
1494 int config_parse_exec_smack_process_label(
1496 const char *filename
,
1498 const char *section
,
1499 unsigned section_line
,
1506 ExecContext
*c
= data
;
1517 if (isempty(rvalue
)) {
1518 c
->smack_process_label
= mfree(c
->smack_process_label
);
1519 c
->smack_process_label_ignore
= false;
1523 if (rvalue
[0] == '-') {
1529 r
= unit_full_printf(u
, rvalue
, &k
);
1531 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1532 "Failed to resolve unit specifiers in '%s'%s: %m",
1533 rvalue
, ignore
? ", ignoring" : "");
1534 return ignore
? 0 : -ENOEXEC
;
1537 free_and_replace(c
->smack_process_label
, k
);
1538 c
->smack_process_label_ignore
= ignore
;
1543 int config_parse_timer(
1545 const char *filename
,
1547 const char *section
,
1548 unsigned section_line
,
1555 _cleanup_(calendar_spec_freep
) CalendarSpec
*c
= NULL
;
1556 _cleanup_free_
char *k
= NULL
;
1568 if (isempty(rvalue
)) {
1569 /* Empty assignment resets list */
1570 timer_free_values(t
);
1574 r
= unit_full_printf(u
, rvalue
, &k
);
1576 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
1580 if (ltype
== TIMER_CALENDAR
) {
1581 r
= calendar_spec_from_string(k
, &c
);
1583 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse calendar specification, ignoring: %s", k
);
1587 r
= parse_sec(k
, &usec
);
1589 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse timer value, ignoring: %s", k
);
1594 v
= new(TimerValue
, 1);
1601 .calendar_spec
= TAKE_PTR(c
),
1604 LIST_PREPEND(value
, t
->values
, v
);
1609 int config_parse_trigger_unit(
1611 const char *filename
,
1613 const char *section
,
1614 unsigned section_line
,
1621 _cleanup_free_
char *p
= NULL
;
1631 if (!hashmap_isempty(u
->dependencies
[UNIT_TRIGGERS
])) {
1632 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Multiple units to trigger specified, ignoring: %s", rvalue
);
1636 r
= unit_name_printf(u
, rvalue
, &p
);
1638 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
1642 type
= unit_name_to_type(p
);
1644 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit type not valid, ignoring: %s", rvalue
);
1647 if (unit_has_name(u
, p
)) {
1648 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Units cannot trigger themselves, ignoring: %s", rvalue
);
1652 r
= unit_add_two_dependencies_by_name(u
, UNIT_BEFORE
, UNIT_TRIGGERS
, p
, true, UNIT_DEPENDENCY_FILE
);
1654 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add trigger on %s, ignoring: %m", p
);
1661 int config_parse_path_spec(const char *unit
,
1662 const char *filename
,
1664 const char *section
,
1665 unsigned section_line
,
1675 _cleanup_free_
char *k
= NULL
;
1683 if (isempty(rvalue
)) {
1684 /* Empty assignment clears list */
1689 b
= path_type_from_string(lvalue
);
1691 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse path type, ignoring: %s", lvalue
);
1695 r
= unit_full_printf(UNIT(p
), rvalue
, &k
);
1697 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
1701 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
1705 s
= new0(PathSpec
, 1);
1710 s
->path
= TAKE_PTR(k
);
1714 LIST_PREPEND(spec
, p
->specs
, s
);
1719 int config_parse_socket_service(
1721 const char *filename
,
1723 const char *section
,
1724 unsigned section_line
,
1731 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1732 _cleanup_free_
char *p
= NULL
;
1742 r
= unit_name_printf(UNIT(s
), rvalue
, &p
);
1744 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", rvalue
);
1748 if (!endswith(p
, ".service")) {
1749 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit must be of type service: %s", rvalue
);
1753 r
= manager_load_unit(UNIT(s
)->manager
, p
, NULL
, &error
, &x
);
1755 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to load unit %s: %s", rvalue
, bus_error_message(&error
, r
));
1759 unit_ref_set(&s
->service
, UNIT(s
), x
);
1764 int config_parse_fdname(
1766 const char *filename
,
1768 const char *section
,
1769 unsigned section_line
,
1776 _cleanup_free_
char *p
= NULL
;
1785 if (isempty(rvalue
)) {
1786 s
->fdname
= mfree(s
->fdname
);
1790 r
= unit_full_printf(UNIT(s
), rvalue
, &p
);
1792 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
1796 if (!fdname_is_valid(p
)) {
1797 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", p
);
1801 return free_and_replace(s
->fdname
, p
);
1804 int config_parse_service_sockets(
1806 const char *filename
,
1808 const char *section
,
1809 unsigned section_line
,
1827 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
1829 r
= extract_first_word(&p
, &word
, NULL
, 0);
1835 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Trailing garbage in sockets, ignoring: %s", rvalue
);
1839 r
= unit_name_printf(UNIT(s
), word
, &k
);
1841 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
1845 if (!endswith(k
, ".socket")) {
1846 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit must be of type socket, ignoring: %s", k
);
1850 r
= unit_add_two_dependencies_by_name(UNIT(s
), UNIT_WANTS
, UNIT_AFTER
, k
, true, UNIT_DEPENDENCY_FILE
);
1852 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
1854 r
= unit_add_dependency_by_name(UNIT(s
), UNIT_TRIGGERED_BY
, k
, true, UNIT_DEPENDENCY_FILE
);
1856 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
1862 int config_parse_bus_name(
1864 const char *filename
,
1866 const char *section
,
1867 unsigned section_line
,
1874 _cleanup_free_
char *k
= NULL
;
1883 r
= unit_full_printf(u
, rvalue
, &k
);
1885 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
1889 if (!service_name_is_valid(k
)) {
1890 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid bus name, ignoring: %s", k
);
1894 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
1897 int config_parse_service_timeout(
1899 const char *filename
,
1901 const char *section
,
1902 unsigned section_line
,
1909 Service
*s
= userdata
;
1918 /* This is called for two cases: TimeoutSec= and TimeoutStartSec=. */
1920 /* Traditionally, these options accepted 0 to disable the timeouts. However, a timeout of 0 suggests it happens
1921 * immediately, hence fix this to become USEC_INFINITY instead. This is in-line with how we internally handle
1922 * all other timeouts. */
1923 r
= parse_sec_fix_0(rvalue
, &usec
);
1925 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
1929 s
->start_timeout_defined
= true;
1930 s
->timeout_start_usec
= usec
;
1932 if (streq(lvalue
, "TimeoutSec"))
1933 s
->timeout_stop_usec
= usec
;
1938 int config_parse_service_timeout_abort(
1940 const char *filename
,
1942 const char *section
,
1943 unsigned section_line
,
1950 Service
*s
= userdata
;
1958 rvalue
+= strspn(rvalue
, WHITESPACE
);
1959 if (isempty(rvalue
)) {
1960 s
->timeout_abort_set
= false;
1964 r
= parse_sec(rvalue
, &s
->timeout_abort_usec
);
1966 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse TimeoutAbortSec= setting, ignoring: %s", rvalue
);
1970 s
->timeout_abort_set
= true;
1974 int config_parse_sec_fix_0(
1976 const char *filename
,
1978 const char *section
,
1979 unsigned section_line
,
1986 usec_t
*usec
= data
;
1994 /* This is pretty much like config_parse_sec(), except that this treats a time of 0 as infinity, for
1995 * compatibility with older versions of systemd where 0 instead of infinity was used as indicator to turn off a
1998 r
= parse_sec_fix_0(rvalue
, usec
);
2000 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
2007 int config_parse_user_group(
2009 const char *filename
,
2011 const char *section
,
2012 unsigned section_line
,
2019 _cleanup_free_
char *k
= NULL
;
2029 if (isempty(rvalue
)) {
2030 *user
= mfree(*user
);
2034 r
= unit_full_printf(u
, rvalue
, &k
);
2036 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", rvalue
);
2040 if (!valid_user_group_name_or_id(k
)) {
2041 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2045 return free_and_replace(*user
, k
);
2048 int config_parse_user_group_strv(
2050 const char *filename
,
2052 const char *section
,
2053 unsigned section_line
,
2060 char ***users
= data
;
2062 const char *p
= rvalue
;
2070 if (isempty(rvalue
)) {
2071 *users
= strv_free(*users
);
2076 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2078 r
= extract_first_word(&p
, &word
, NULL
, 0);
2084 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax: %s", rvalue
);
2088 r
= unit_full_printf(u
, word
, &k
);
2090 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", word
);
2094 if (!valid_user_group_name_or_id(k
)) {
2095 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2099 r
= strv_push(users
, k
);
2109 int config_parse_working_directory(
2111 const char *filename
,
2113 const char *section
,
2114 unsigned section_line
,
2121 ExecContext
*c
= data
;
2132 if (isempty(rvalue
)) {
2133 c
->working_directory_home
= false;
2134 c
->working_directory
= mfree(c
->working_directory
);
2138 if (rvalue
[0] == '-') {
2144 if (streq(rvalue
, "~")) {
2145 c
->working_directory_home
= true;
2146 c
->working_directory
= mfree(c
->working_directory
);
2148 _cleanup_free_
char *k
= NULL
;
2150 r
= unit_full_printf(u
, rvalue
, &k
);
2152 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2153 "Failed to resolve unit specifiers in working directory path '%s'%s: %m",
2154 rvalue
, missing_ok
? ", ignoring" : "");
2155 return missing_ok
? 0 : -ENOEXEC
;
2158 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
| (missing_ok
? 0 : PATH_CHECK_FATAL
), unit
, filename
, line
, lvalue
);
2160 return missing_ok
? 0 : -ENOEXEC
;
2162 c
->working_directory_home
= false;
2163 free_and_replace(c
->working_directory
, k
);
2166 c
->working_directory_missing_ok
= missing_ok
;
2170 int config_parse_unit_env_file(const char *unit
,
2171 const char *filename
,
2173 const char *section
,
2174 unsigned section_line
,
2183 _cleanup_free_
char *n
= NULL
;
2191 if (isempty(rvalue
)) {
2192 /* Empty assignment frees the list */
2193 *env
= strv_free(*env
);
2197 r
= unit_full_printf(u
, rvalue
, &n
);
2199 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2203 r
= path_simplify_and_warn(n
[0] == '-' ? n
+ 1 : n
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2207 r
= strv_push(env
, n
);
2216 int config_parse_environ(
2218 const char *filename
,
2220 const char *section
,
2221 unsigned section_line
,
2238 if (isempty(rvalue
)) {
2239 /* Empty assignment resets the list */
2240 *env
= strv_free(*env
);
2244 for (p
= rvalue
;; ) {
2245 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2247 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2253 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2254 "Invalid syntax, ignoring: %s", rvalue
);
2259 r
= unit_full_printf(u
, word
, &k
);
2261 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2262 "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2268 if (!env_assignment_is_valid(k
)) {
2269 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2270 "Invalid environment assignment, ignoring: %s", k
);
2274 r
= strv_env_replace(env
, k
);
2282 int config_parse_pass_environ(
2284 const char *filename
,
2286 const char *section
,
2287 unsigned section_line
,
2294 _cleanup_strv_free_
char **n
= NULL
;
2295 size_t nlen
= 0, nbufsize
= 0;
2296 char*** passenv
= data
;
2297 const char *p
= rvalue
;
2306 if (isempty(rvalue
)) {
2307 /* Empty assignment resets the list */
2308 *passenv
= strv_free(*passenv
);
2313 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2315 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
2321 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2322 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2327 r
= unit_full_printf(u
, word
, &k
);
2329 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2330 "Failed to resolve specifiers in %s, ignoring: %m", word
);
2336 if (!env_name_is_valid(k
)) {
2337 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2338 "Invalid environment name for %s, ignoring: %s", lvalue
, k
);
2342 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
2345 n
[nlen
++] = TAKE_PTR(k
);
2350 r
= strv_extend_strv(passenv
, n
, true);
2358 int config_parse_unset_environ(
2360 const char *filename
,
2362 const char *section
,
2363 unsigned section_line
,
2370 _cleanup_strv_free_
char **n
= NULL
;
2371 size_t nlen
= 0, nbufsize
= 0;
2372 char*** unsetenv
= data
;
2373 const char *p
= rvalue
;
2382 if (isempty(rvalue
)) {
2383 /* Empty assignment resets the list */
2384 *unsetenv
= strv_free(*unsetenv
);
2389 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2391 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2397 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2398 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2403 r
= unit_full_printf(u
, word
, &k
);
2405 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2406 "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2412 if (!env_assignment_is_valid(k
) && !env_name_is_valid(k
)) {
2413 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2414 "Invalid environment name or assignment %s, ignoring: %s", lvalue
, k
);
2418 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
2421 n
[nlen
++] = TAKE_PTR(k
);
2426 r
= strv_extend_strv(unsetenv
, n
, true);
2434 int config_parse_log_extra_fields(
2436 const char *filename
,
2438 const char *section
,
2439 unsigned section_line
,
2446 ExecContext
*c
= data
;
2448 const char *p
= rvalue
;
2456 if (isempty(rvalue
)) {
2457 exec_context_free_log_extra_fields(c
);
2462 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2466 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2472 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
2476 r
= unit_full_printf(u
, word
, &k
);
2478 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2482 eq
= strchr(k
, '=');
2484 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Log field lacks '=' character, ignoring: %s", k
);
2488 if (!journal_field_valid(k
, eq
-k
, false)) {
2489 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Log field name is invalid, ignoring: %s", k
);
2493 t
= reallocarray(c
->log_extra_fields
, c
->n_log_extra_fields
+1, sizeof(struct iovec
));
2497 c
->log_extra_fields
= t
;
2498 c
->log_extra_fields
[c
->n_log_extra_fields
++] = IOVEC_MAKE_STRING(k
);
2504 int config_parse_unit_condition_path(
2506 const char *filename
,
2508 const char *section
,
2509 unsigned section_line
,
2516 _cleanup_free_
char *p
= NULL
;
2517 Condition
**list
= data
, *c
;
2518 ConditionType t
= ltype
;
2519 bool trigger
, negate
;
2528 if (isempty(rvalue
)) {
2529 /* Empty assignment resets the list */
2530 *list
= condition_free_list(*list
);
2534 trigger
= rvalue
[0] == '|';
2538 negate
= rvalue
[0] == '!';
2542 r
= unit_full_printf(u
, rvalue
, &p
);
2544 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2548 r
= path_simplify_and_warn(p
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2552 c
= condition_new(t
, p
, trigger
, negate
);
2556 LIST_PREPEND(conditions
, *list
, c
);
2560 int config_parse_unit_condition_string(
2562 const char *filename
,
2564 const char *section
,
2565 unsigned section_line
,
2572 _cleanup_free_
char *s
= NULL
;
2573 Condition
**list
= data
, *c
;
2574 ConditionType t
= ltype
;
2575 bool trigger
, negate
;
2584 if (isempty(rvalue
)) {
2585 /* Empty assignment resets the list */
2586 *list
= condition_free_list(*list
);
2590 trigger
= *rvalue
== '|';
2592 rvalue
+= 1 + strspn(rvalue
+ 1, WHITESPACE
);
2594 negate
= *rvalue
== '!';
2596 rvalue
+= 1 + strspn(rvalue
+ 1, WHITESPACE
);
2598 r
= unit_full_printf(u
, rvalue
, &s
);
2600 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2601 "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2605 c
= condition_new(t
, s
, trigger
, negate
);
2609 LIST_PREPEND(conditions
, *list
, c
);
2613 int config_parse_unit_condition_null(
2615 const char *filename
,
2617 const char *section
,
2618 unsigned section_line
,
2625 Condition
**list
= data
, *c
;
2626 bool trigger
, negate
;
2634 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "%s= is deprecated, please do not use.", lvalue
);
2636 if (isempty(rvalue
)) {
2637 /* Empty assignment resets the list */
2638 *list
= condition_free_list(*list
);
2642 trigger
= rvalue
[0] == '|';
2646 negate
= rvalue
[0] == '!';
2650 b
= parse_boolean(rvalue
);
2652 log_syntax(unit
, LOG_ERR
, filename
, line
, b
, "Failed to parse boolean value in condition, ignoring: %s", rvalue
);
2659 c
= condition_new(CONDITION_NULL
, NULL
, trigger
, negate
);
2663 LIST_PREPEND(conditions
, *list
, c
);
2667 int config_parse_unit_requires_mounts_for(
2669 const char *filename
,
2671 const char *section
,
2672 unsigned section_line
,
2679 const char *p
= rvalue
;
2689 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
2691 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
2697 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2698 "Invalid syntax, ignoring: %s", rvalue
);
2702 r
= unit_full_printf(u
, word
, &resolved
);
2704 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
2708 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2712 r
= unit_require_mounts_for(u
, resolved
, UNIT_DEPENDENCY_FILE
);
2714 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add required mount '%s', ignoring: %m", resolved
);
2720 int config_parse_documentation(const char *unit
,
2721 const char *filename
,
2723 const char *section
,
2724 unsigned section_line
,
2740 if (isempty(rvalue
)) {
2741 /* Empty assignment resets the list */
2742 u
->documentation
= strv_free(u
->documentation
);
2746 r
= config_parse_unit_strv_printf(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
,
2747 rvalue
, data
, userdata
);
2751 for (a
= b
= u
->documentation
; a
&& *a
; a
++) {
2753 if (documentation_url_is_valid(*a
))
2756 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid URL, ignoring: %s", *a
);
2767 int config_parse_syscall_filter(
2769 const char *filename
,
2771 const char *section
,
2772 unsigned section_line
,
2779 ExecContext
*c
= data
;
2781 bool invert
= false;
2790 if (isempty(rvalue
)) {
2791 /* Empty assignment resets the list */
2792 c
->syscall_filter
= hashmap_free(c
->syscall_filter
);
2793 c
->syscall_whitelist
= false;
2797 if (rvalue
[0] == '~') {
2802 if (!c
->syscall_filter
) {
2803 c
->syscall_filter
= hashmap_new(NULL
);
2804 if (!c
->syscall_filter
)
2808 /* Allow everything but the ones listed */
2809 c
->syscall_whitelist
= false;
2811 /* Allow nothing but the ones listed */
2812 c
->syscall_whitelist
= true;
2814 /* Accept default syscalls if we are on a whitelist */
2815 r
= seccomp_parse_syscall_filter(
2816 "@default", -1, c
->syscall_filter
,
2817 SECCOMP_PARSE_PERMISSIVE
|SECCOMP_PARSE_WHITELIST
,
2827 _cleanup_free_
char *word
= NULL
, *name
= NULL
;
2830 r
= extract_first_word(&p
, &word
, NULL
, 0);
2836 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
2840 r
= parse_syscall_and_errno(word
, &name
, &num
);
2842 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse syscall:errno, ignoring: %s", word
);
2846 r
= seccomp_parse_syscall_filter(
2847 name
, num
, c
->syscall_filter
,
2848 SECCOMP_PARSE_LOG
|SECCOMP_PARSE_PERMISSIVE
|
2849 (invert
? SECCOMP_PARSE_INVERT
: 0)|
2850 (c
->syscall_whitelist
? SECCOMP_PARSE_WHITELIST
: 0),
2851 unit
, filename
, line
);
2857 int config_parse_syscall_archs(
2859 const char *filename
,
2861 const char *section
,
2862 unsigned section_line
,
2869 const char *p
= rvalue
;
2873 if (isempty(rvalue
)) {
2874 *archs
= set_free(*archs
);
2878 r
= set_ensure_allocated(archs
, NULL
);
2883 _cleanup_free_
char *word
= NULL
;
2886 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
2892 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2893 "Invalid syntax, ignoring: %s", rvalue
);
2897 r
= seccomp_arch_from_string(word
, &a
);
2899 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2900 "Failed to parse system call architecture \"%s\", ignoring: %m", word
);
2904 r
= set_put(*archs
, UINT32_TO_PTR(a
+ 1));
2910 int config_parse_syscall_errno(
2912 const char *filename
,
2914 const char *section
,
2915 unsigned section_line
,
2922 ExecContext
*c
= data
;
2929 if (isempty(rvalue
)) {
2930 /* Empty assignment resets to KILL */
2931 c
->syscall_errno
= 0;
2935 e
= parse_errno(rvalue
);
2937 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse error number, ignoring: %s", rvalue
);
2941 c
->syscall_errno
= e
;
2945 int config_parse_address_families(
2947 const char *filename
,
2949 const char *section
,
2950 unsigned section_line
,
2957 ExecContext
*c
= data
;
2958 bool invert
= false;
2966 if (isempty(rvalue
)) {
2967 /* Empty assignment resets the list */
2968 c
->address_families
= set_free(c
->address_families
);
2969 c
->address_families_whitelist
= false;
2973 if (rvalue
[0] == '~') {
2978 if (!c
->address_families
) {
2979 c
->address_families
= set_new(NULL
);
2980 if (!c
->address_families
)
2983 c
->address_families_whitelist
= !invert
;
2986 for (p
= rvalue
;;) {
2987 _cleanup_free_
char *word
= NULL
;
2990 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
2996 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2997 "Invalid syntax, ignoring: %s", rvalue
);
3001 af
= af_from_name(word
);
3003 log_syntax(unit
, LOG_ERR
, filename
, line
, af
,
3004 "Failed to parse address family, ignoring: %s", word
);
3008 /* If we previously wanted to forbid an address family and now
3009 * we want to allow it, then just remove it from the list.
3011 if (!invert
== c
->address_families_whitelist
) {
3012 r
= set_put(c
->address_families
, INT_TO_PTR(af
));
3016 set_remove(c
->address_families
, INT_TO_PTR(af
));
3020 int config_parse_restrict_namespaces(
3022 const char *filename
,
3024 const char *section
,
3025 unsigned section_line
,
3032 ExecContext
*c
= data
;
3033 unsigned long flags
;
3034 bool invert
= false;
3037 if (isempty(rvalue
)) {
3038 /* Reset to the default. */
3039 c
->restrict_namespaces
= NAMESPACE_FLAGS_INITIAL
;
3043 /* Boolean parameter ignores the previous settings */
3044 r
= parse_boolean(rvalue
);
3046 c
->restrict_namespaces
= 0;
3048 } else if (r
== 0) {
3049 c
->restrict_namespaces
= NAMESPACE_FLAGS_ALL
;
3053 if (rvalue
[0] == '~') {
3058 /* Not a boolean argument, in this case it's a list of namespace types. */
3059 r
= namespace_flags_from_string(rvalue
, &flags
);
3061 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse namespace type string, ignoring: %s", rvalue
);
3065 if (c
->restrict_namespaces
== NAMESPACE_FLAGS_INITIAL
)
3066 /* Initial assignment. Just set the value. */
3067 c
->restrict_namespaces
= invert
? (~flags
) & NAMESPACE_FLAGS_ALL
: flags
;
3069 /* Merge the value with the previous one. */
3070 SET_FLAG(c
->restrict_namespaces
, flags
, !invert
);
3076 int config_parse_unit_slice(
3078 const char *filename
,
3080 const char *section
,
3081 unsigned section_line
,
3088 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
3089 _cleanup_free_
char *k
= NULL
;
3090 Unit
*u
= userdata
, *slice
= NULL
;
3098 r
= unit_name_printf(u
, rvalue
, &k
);
3100 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
3104 r
= manager_load_unit(u
->manager
, k
, NULL
, &error
, &slice
);
3106 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to load slice unit %s, ignoring: %s", k
, bus_error_message(&error
, r
));
3110 r
= unit_set_slice(u
, slice
);
3112 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to assign slice %s to unit %s, ignoring: %m", slice
->id
, u
->id
);
3119 int config_parse_cpu_quota(
3121 const char *filename
,
3123 const char *section
,
3124 unsigned section_line
,
3131 CGroupContext
*c
= data
;
3138 if (isempty(rvalue
)) {
3139 c
->cpu_quota_per_sec_usec
= USEC_INFINITY
;
3143 r
= parse_permille_unbounded(rvalue
);
3145 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid CPU quota '%s', ignoring.", rvalue
);
3149 c
->cpu_quota_per_sec_usec
= ((usec_t
) r
* USEC_PER_SEC
) / 1000U;
3153 int config_parse_memory_limit(
3155 const char *filename
,
3157 const char *section
,
3158 unsigned section_line
,
3165 CGroupContext
*c
= data
;
3166 uint64_t bytes
= CGROUP_LIMIT_MAX
;
3169 if (!isempty(rvalue
) && !streq(rvalue
, "infinity")) {
3171 r
= parse_permille(rvalue
);
3173 r
= parse_size(rvalue
, 1024, &bytes
);
3175 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid memory limit '%s', ignoring: %m", rvalue
);
3179 bytes
= physical_memory_scale(r
, 1000U);
3181 if (bytes
>= UINT64_MAX
||
3182 (bytes
<= 0 && !STR_IN_SET(lvalue
, "MemorySwapMax", "MemoryLow", "MemoryMin", "DefaultMemoryLow", "DefaultMemoryMin"))) {
3183 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Memory limit '%s' out of range, ignoring.", rvalue
);
3188 if (streq(lvalue
, "DefaultMemoryLow")) {
3189 c
->default_memory_low_set
= true;
3190 if (isempty(rvalue
))
3191 c
->default_memory_low
= CGROUP_LIMIT_MIN
;
3193 c
->default_memory_low
= bytes
;
3194 } else if (streq(lvalue
, "DefaultMemoryMin")) {
3195 c
->default_memory_min_set
= true;
3196 if (isempty(rvalue
))
3197 c
->default_memory_min
= CGROUP_LIMIT_MIN
;
3199 c
->default_memory_min
= bytes
;
3200 } else if (streq(lvalue
, "MemoryMin")) {
3201 c
->memory_min
= bytes
;
3202 c
->memory_min_set
= true;
3203 } else if (streq(lvalue
, "MemoryLow")) {
3204 c
->memory_low
= bytes
;
3205 c
->memory_low_set
= true;
3206 } else if (streq(lvalue
, "MemoryHigh"))
3207 c
->memory_high
= bytes
;
3208 else if (streq(lvalue
, "MemoryMax"))
3209 c
->memory_max
= bytes
;
3210 else if (streq(lvalue
, "MemorySwapMax"))
3211 c
->memory_swap_max
= bytes
;
3212 else if (streq(lvalue
, "MemoryLimit"))
3213 c
->memory_limit
= bytes
;
3220 int config_parse_tasks_max(
3222 const char *filename
,
3224 const char *section
,
3225 unsigned section_line
,
3232 uint64_t *tasks_max
= data
, v
;
3236 if (isempty(rvalue
)) {
3237 *tasks_max
= u
? u
->manager
->default_tasks_max
: UINT64_MAX
;
3241 if (streq(rvalue
, "infinity")) {
3242 *tasks_max
= CGROUP_LIMIT_MAX
;
3246 r
= parse_permille(rvalue
);
3248 r
= safe_atou64(rvalue
, &v
);
3250 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid maximum tasks value '%s', ignoring: %m", rvalue
);
3254 v
= system_tasks_max_scale(r
, 1000U);
3256 if (v
<= 0 || v
>= UINT64_MAX
) {
3257 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Maximum tasks value '%s' out of range, ignoring.", rvalue
);
3265 int config_parse_delegate(
3267 const char *filename
,
3269 const char *section
,
3270 unsigned section_line
,
3277 CGroupContext
*c
= data
;
3281 t
= unit_name_to_type(unit
);
3282 assert(t
!= _UNIT_TYPE_INVALID
);
3284 if (!unit_vtable
[t
]->can_delegate
) {
3285 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Delegate= setting not supported for this unit type, ignoring.");
3289 /* We either accept a boolean value, which may be used to turn on delegation for all controllers, or turn it
3290 * off for all. Or it takes a list of controller names, in which case we add the specified controllers to the
3291 * mask to delegate. */
3293 if (isempty(rvalue
)) {
3294 /* An empty string resets controllers and set Delegate=yes. */
3296 c
->delegate_controllers
= 0;
3300 r
= parse_boolean(rvalue
);
3302 const char *p
= rvalue
;
3303 CGroupMask mask
= 0;
3306 _cleanup_free_
char *word
= NULL
;
3307 CGroupController cc
;
3309 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3315 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3319 cc
= cgroup_controller_from_string(word
);
3321 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid controller name '%s', ignoring", word
);
3325 mask
|= CGROUP_CONTROLLER_TO_MASK(cc
);
3329 c
->delegate_controllers
|= mask
;
3333 c
->delegate_controllers
= _CGROUP_MASK_ALL
;
3335 c
->delegate
= false;
3336 c
->delegate_controllers
= 0;
3342 int config_parse_device_allow(
3344 const char *filename
,
3346 const char *section
,
3347 unsigned section_line
,
3354 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3355 CGroupContext
*c
= data
;
3356 const char *p
= rvalue
;
3359 if (isempty(rvalue
)) {
3360 while (c
->device_allow
)
3361 cgroup_context_free_device_allow(c
, c
->device_allow
);
3366 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3370 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3371 "Invalid syntax, ignoring: %s", rvalue
);
3375 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3376 "Failed to extract device path and rights from '%s', ignoring.", rvalue
);
3380 r
= unit_full_printf(userdata
, path
, &resolved
);
3382 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3383 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3387 if (!STARTSWITH_SET(resolved
, "block-", "char-")) {
3389 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3393 if (!valid_device_node_path(resolved
)) {
3394 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device node path '%s', ignoring.", resolved
);
3399 if (!isempty(p
) && !in_charset(p
, "rwm")) {
3400 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device rights '%s', ignoring.", p
);
3404 return cgroup_add_device_allow(c
, resolved
, p
);
3407 int config_parse_io_device_weight(
3409 const char *filename
,
3411 const char *section
,
3412 unsigned section_line
,
3419 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3420 CGroupIODeviceWeight
*w
;
3421 CGroupContext
*c
= data
;
3422 const char *p
= rvalue
;
3430 if (isempty(rvalue
)) {
3431 while (c
->io_device_weights
)
3432 cgroup_context_free_io_device_weight(c
, c
->io_device_weights
);
3437 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3441 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3442 "Invalid syntax, ignoring: %s", rvalue
);
3445 if (r
== 0 || isempty(p
)) {
3446 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3447 "Failed to extract device path and weight from '%s', ignoring.", rvalue
);
3451 r
= unit_full_printf(userdata
, path
, &resolved
);
3453 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3454 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3458 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3462 r
= cg_weight_parse(p
, &u
);
3464 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "IO weight '%s' invalid, ignoring: %m", p
);
3468 assert(u
!= CGROUP_WEIGHT_INVALID
);
3470 w
= new0(CGroupIODeviceWeight
, 1);
3474 w
->path
= TAKE_PTR(resolved
);
3477 LIST_PREPEND(device_weights
, c
->io_device_weights
, w
);
3481 int config_parse_io_device_latency(
3483 const char *filename
,
3485 const char *section
,
3486 unsigned section_line
,
3493 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3494 CGroupIODeviceLatency
*l
;
3495 CGroupContext
*c
= data
;
3496 const char *p
= rvalue
;
3504 if (isempty(rvalue
)) {
3505 while (c
->io_device_latencies
)
3506 cgroup_context_free_io_device_latency(c
, c
->io_device_latencies
);
3511 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3515 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3516 "Invalid syntax, ignoring: %s", rvalue
);
3519 if (r
== 0 || isempty(p
)) {
3520 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3521 "Failed to extract device path and latency from '%s', ignoring.", rvalue
);
3525 r
= unit_full_printf(userdata
, path
, &resolved
);
3527 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3528 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3532 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3536 if (parse_sec(p
, &usec
) < 0) {
3537 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse timer value, ignoring: %s", p
);
3541 l
= new0(CGroupIODeviceLatency
, 1);
3545 l
->path
= TAKE_PTR(resolved
);
3546 l
->target_usec
= usec
;
3548 LIST_PREPEND(device_latencies
, c
->io_device_latencies
, l
);
3552 int config_parse_io_limit(
3554 const char *filename
,
3556 const char *section
,
3557 unsigned section_line
,
3564 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3565 CGroupIODeviceLimit
*l
= NULL
, *t
;
3566 CGroupContext
*c
= data
;
3567 CGroupIOLimitType type
;
3568 const char *p
= rvalue
;
3576 type
= cgroup_io_limit_type_from_string(lvalue
);
3579 if (isempty(rvalue
)) {
3580 LIST_FOREACH(device_limits
, l
, c
->io_device_limits
)
3581 l
->limits
[type
] = cgroup_io_limit_defaults
[type
];
3585 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3589 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3590 "Invalid syntax, ignoring: %s", rvalue
);
3593 if (r
== 0 || isempty(p
)) {
3594 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3595 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
3599 r
= unit_full_printf(userdata
, path
, &resolved
);
3601 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3602 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3606 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3610 if (streq("infinity", p
))
3611 num
= CGROUP_LIMIT_MAX
;
3613 r
= parse_size(p
, 1000, &num
);
3614 if (r
< 0 || num
<= 0) {
3615 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid IO limit '%s', ignoring.", p
);
3620 LIST_FOREACH(device_limits
, t
, c
->io_device_limits
) {
3621 if (path_equal(resolved
, t
->path
)) {
3628 CGroupIOLimitType ttype
;
3630 l
= new0(CGroupIODeviceLimit
, 1);
3634 l
->path
= TAKE_PTR(resolved
);
3635 for (ttype
= 0; ttype
< _CGROUP_IO_LIMIT_TYPE_MAX
; ttype
++)
3636 l
->limits
[ttype
] = cgroup_io_limit_defaults
[ttype
];
3638 LIST_PREPEND(device_limits
, c
->io_device_limits
, l
);
3641 l
->limits
[type
] = num
;
3646 int config_parse_blockio_device_weight(
3648 const char *filename
,
3650 const char *section
,
3651 unsigned section_line
,
3658 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3659 CGroupBlockIODeviceWeight
*w
;
3660 CGroupContext
*c
= data
;
3661 const char *p
= rvalue
;
3669 if (isempty(rvalue
)) {
3670 while (c
->blockio_device_weights
)
3671 cgroup_context_free_blockio_device_weight(c
, c
->blockio_device_weights
);
3676 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3680 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3681 "Invalid syntax, ignoring: %s", rvalue
);
3684 if (r
== 0 || isempty(p
)) {
3685 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3686 "Failed to extract device node and weight from '%s', ignoring.", rvalue
);
3690 r
= unit_full_printf(userdata
, path
, &resolved
);
3692 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3693 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3697 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3701 r
= cg_blkio_weight_parse(p
, &u
);
3703 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid block IO weight '%s', ignoring: %m", p
);
3707 assert(u
!= CGROUP_BLKIO_WEIGHT_INVALID
);
3709 w
= new0(CGroupBlockIODeviceWeight
, 1);
3713 w
->path
= TAKE_PTR(resolved
);
3716 LIST_PREPEND(device_weights
, c
->blockio_device_weights
, w
);
3720 int config_parse_blockio_bandwidth(
3722 const char *filename
,
3724 const char *section
,
3725 unsigned section_line
,
3732 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3733 CGroupBlockIODeviceBandwidth
*b
= NULL
, *t
;
3734 CGroupContext
*c
= data
;
3735 const char *p
= rvalue
;
3744 read
= streq("BlockIOReadBandwidth", lvalue
);
3746 if (isempty(rvalue
)) {
3747 LIST_FOREACH(device_bandwidths
, b
, c
->blockio_device_bandwidths
) {
3748 b
->rbps
= CGROUP_LIMIT_MAX
;
3749 b
->wbps
= CGROUP_LIMIT_MAX
;
3754 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3758 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3759 "Invalid syntax, ignoring: %s", rvalue
);
3762 if (r
== 0 || isempty(p
)) {
3763 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3764 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
3768 r
= unit_full_printf(userdata
, path
, &resolved
);
3770 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3771 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3775 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3779 r
= parse_size(p
, 1000, &bytes
);
3780 if (r
< 0 || bytes
<= 0) {
3781 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid Block IO Bandwidth '%s', ignoring.", p
);
3785 LIST_FOREACH(device_bandwidths
, t
, c
->blockio_device_bandwidths
) {
3786 if (path_equal(resolved
, t
->path
)) {
3793 b
= new0(CGroupBlockIODeviceBandwidth
, 1);
3797 b
->path
= TAKE_PTR(resolved
);
3798 b
->rbps
= CGROUP_LIMIT_MAX
;
3799 b
->wbps
= CGROUP_LIMIT_MAX
;
3801 LIST_PREPEND(device_bandwidths
, c
->blockio_device_bandwidths
, b
);
3812 int config_parse_job_mode_isolate(
3814 const char *filename
,
3816 const char *section
,
3817 unsigned section_line
,
3831 r
= parse_boolean(rvalue
);
3833 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse boolean, ignoring: %s", rvalue
);
3837 log_notice("%s is deprecated. Please use OnFailureJobMode= instead", lvalue
);
3839 *m
= r
? JOB_ISOLATE
: JOB_REPLACE
;
3843 int config_parse_exec_directories(
3845 const char *filename
,
3847 const char *section
,
3848 unsigned section_line
,
3865 if (isempty(rvalue
)) {
3866 /* Empty assignment resets the list */
3867 *rt
= strv_free(*rt
);
3871 for (p
= rvalue
;;) {
3872 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
3874 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3878 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3879 "Invalid syntax, ignoring: %s", rvalue
);
3885 r
= unit_full_printf(u
, word
, &k
);
3887 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
3888 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
3892 r
= path_simplify_and_warn(k
, PATH_CHECK_RELATIVE
, unit
, filename
, line
, lvalue
);
3896 if (path_startswith(k
, "private")) {
3897 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
3898 "%s= path can't be 'private', ignoring assignment: %s", lvalue
, word
);
3902 r
= strv_push(rt
, k
);
3909 int config_parse_set_status(
3911 const char *filename
,
3913 const char *section
,
3914 unsigned section_line
,
3922 const char *word
, *state
;
3924 ExitStatusSet
*status_set
= data
;
3931 /* Empty assignment resets the list */
3932 if (isempty(rvalue
)) {
3933 exit_status_set_free(status_set
);
3937 FOREACH_WORD(word
, l
, rvalue
, state
) {
3938 _cleanup_free_
char *temp
;
3942 temp
= strndup(word
, l
);
3946 r
= safe_atoi(temp
, &val
);
3948 val
= signal_from_string(temp
);
3951 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse value, ignoring: %s", word
);
3954 set
= &status_set
->signal
;
3956 if (val
< 0 || val
> 255) {
3957 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Value %d is outside range 0-255, ignoring", val
);
3960 set
= &status_set
->status
;
3963 r
= set_ensure_allocated(set
, NULL
);
3967 r
= set_put(*set
, INT_TO_PTR(val
));
3971 if (!isempty(state
))
3972 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Trailing garbage, ignoring.");
3977 int config_parse_namespace_path_strv(
3979 const char *filename
,
3981 const char *section
,
3982 unsigned section_line
,
3991 const char *p
= rvalue
;
3999 if (isempty(rvalue
)) {
4000 /* Empty assignment resets the list */
4001 *sv
= strv_free(*sv
);
4006 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
, *joined
= NULL
;
4008 bool ignore_enoent
= false, shall_prefix
= false;
4010 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
4016 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
4021 if (startswith(w
, "-")) {
4022 ignore_enoent
= true;
4025 if (startswith(w
, "+")) {
4026 shall_prefix
= true;
4030 r
= unit_full_printf(u
, w
, &resolved
);
4032 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", w
);
4036 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4040 joined
= strjoin(ignore_enoent
? "-" : "",
4041 shall_prefix
? "+" : "",
4044 r
= strv_push(sv
, joined
);
4054 int config_parse_temporary_filesystems(
4056 const char *filename
,
4058 const char *section
,
4059 unsigned section_line
,
4067 ExecContext
*c
= data
;
4068 const char *p
= rvalue
;
4076 if (isempty(rvalue
)) {
4077 /* Empty assignment resets the list */
4078 temporary_filesystem_free_many(c
->temporary_filesystems
, c
->n_temporary_filesystems
);
4079 c
->temporary_filesystems
= NULL
;
4080 c
->n_temporary_filesystems
= 0;
4085 _cleanup_free_
char *word
= NULL
, *path
= NULL
, *resolved
= NULL
;
4088 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
4094 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
4099 r
= extract_first_word(&w
, &path
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4103 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", word
);
4107 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid syntax, ignoring: %s", word
);
4111 r
= unit_full_printf(u
, path
, &resolved
);
4113 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", path
);
4117 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4121 r
= temporary_filesystem_add(&c
->temporary_filesystems
, &c
->n_temporary_filesystems
, resolved
, w
);
4127 int config_parse_bind_paths(
4129 const char *filename
,
4131 const char *section
,
4132 unsigned section_line
,
4139 ExecContext
*c
= data
;
4149 if (isempty(rvalue
)) {
4150 /* Empty assignment resets the list */
4151 bind_mount_free_many(c
->bind_mounts
, c
->n_bind_mounts
);
4152 c
->bind_mounts
= NULL
;
4153 c
->n_bind_mounts
= 0;
4159 _cleanup_free_
char *source
= NULL
, *destination
= NULL
;
4160 _cleanup_free_
char *sresolved
= NULL
, *dresolved
= NULL
;
4161 char *s
= NULL
, *d
= NULL
;
4162 bool rbind
= true, ignore_enoent
= false;
4164 r
= extract_first_word(&p
, &source
, ":" WHITESPACE
, EXTRACT_UNQUOTE
|EXTRACT_DONT_COALESCE_SEPARATORS
);
4170 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
4174 r
= unit_full_printf(u
, source
, &sresolved
);
4176 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4177 "Failed to resolved unit specifiers in \"%s\", ignoring: %m", source
);
4183 ignore_enoent
= true;
4187 r
= path_simplify_and_warn(s
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4191 /* Optionally, the destination is specified. */
4192 if (p
&& p
[-1] == ':') {
4193 r
= extract_first_word(&p
, &destination
, ":" WHITESPACE
, EXTRACT_UNQUOTE
|EXTRACT_DONT_COALESCE_SEPARATORS
);
4197 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
4201 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Missing argument after ':', ignoring: %s", s
);
4205 r
= unit_full_printf(u
, destination
, &dresolved
);
4207 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4208 "Failed to resolved specifiers in \"%s\", ignoring: %m", destination
);
4212 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4218 /* Optionally, there's also a short option string specified */
4219 if (p
&& p
[-1] == ':') {
4220 _cleanup_free_
char *options
= NULL
;
4222 r
= extract_first_word(&p
, &options
, NULL
, EXTRACT_UNQUOTE
);
4226 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s: %s", lvalue
, rvalue
);
4230 if (isempty(options
) || streq(options
, "rbind"))
4232 else if (streq(options
, "norbind"))
4235 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid option string, ignoring setting: %s", options
);
4242 r
= bind_mount_add(&c
->bind_mounts
, &c
->n_bind_mounts
,
4246 .read_only
= !!strstr(lvalue
, "ReadOnly"),
4248 .ignore_enoent
= ignore_enoent
,
4257 int config_parse_job_timeout_sec(
4259 const char *filename
,
4261 const char *section
,
4262 unsigned section_line
,
4278 r
= parse_sec_fix_0(rvalue
, &usec
);
4280 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse JobTimeoutSec= parameter, ignoring: %s", rvalue
);
4284 /* If the user explicitly changed JobTimeoutSec= also change JobRunningTimeoutSec=, for compatibility with old
4285 * versions. If JobRunningTimeoutSec= was explicitly set, avoid this however as whatever the user picked should
4288 if (!u
->job_running_timeout_set
)
4289 u
->job_running_timeout
= usec
;
4291 u
->job_timeout
= usec
;
4296 int config_parse_job_running_timeout_sec(
4298 const char *filename
,
4300 const char *section
,
4301 unsigned section_line
,
4317 r
= parse_sec_fix_0(rvalue
, &usec
);
4319 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse JobRunningTimeoutSec= parameter, ignoring: %s", rvalue
);
4323 u
->job_running_timeout
= usec
;
4324 u
->job_running_timeout_set
= true;
4329 int config_parse_emergency_action(
4331 const char *filename
,
4333 const char *section
,
4334 unsigned section_line
,
4342 EmergencyAction
*x
= data
;
4351 m
= ((Unit
*) userdata
)->manager
;
4355 r
= parse_emergency_action(rvalue
, MANAGER_IS_SYSTEM(m
), x
);
4357 if (r
== -EOPNOTSUPP
&& MANAGER_IS_USER(m
)) {
4358 /* Compat mode: remove for systemd 241. */
4360 log_syntax(unit
, LOG_INFO
, filename
, line
, r
,
4361 "%s= in user mode specified as \"%s\", using \"exit-force\" instead.",
4363 *x
= EMERGENCY_ACTION_EXIT_FORCE
;
4367 if (r
== -EOPNOTSUPP
)
4368 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4369 "%s= specified as %s mode action, ignoring: %s",
4370 lvalue
, MANAGER_IS_SYSTEM(m
) ? "user" : "system", rvalue
);
4372 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4373 "Failed to parse %s=, ignoring: %s", lvalue
, rvalue
);
4380 int config_parse_pid_file(
4382 const char *filename
,
4384 const char *section
,
4385 unsigned section_line
,
4392 _cleanup_free_
char *k
= NULL
, *n
= NULL
;
4402 if (isempty(rvalue
)) {
4403 /* An empty assignment removes already set value. */
4408 r
= unit_full_printf(u
, rvalue
, &k
);
4410 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
4414 /* If this is a relative path make it absolute by prefixing the /run */
4415 n
= path_make_absolute(k
, u
->manager
->prefix
[EXEC_DIRECTORY_RUNTIME
]);
4419 /* Check that the result is a sensible path */
4420 r
= path_simplify_and_warn(n
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4424 r
= patch_var_run(unit
, filename
, line
, lvalue
, &n
);
4428 free_and_replace(*s
, n
);
4432 int config_parse_exit_status(
4434 const char *filename
,
4436 const char *section
,
4437 unsigned section_line
,
4444 int *exit_status
= data
, r
;
4450 assert(exit_status
);
4452 if (isempty(rvalue
)) {
4457 r
= safe_atou8(rvalue
, &u
);
4459 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse exit status '%s', ignoring: %m", rvalue
);
4467 int config_parse_disable_controllers(
4469 const char *filename
,
4471 const char *section
,
4472 unsigned section_line
,
4480 CGroupContext
*c
= data
;
4481 CGroupMask disabled_mask
;
4483 /* 1. If empty, make all controllers eligible for use again.
4484 * 2. If non-empty, merge all listed controllers, space separated. */
4486 if (isempty(rvalue
)) {
4487 c
->disable_controllers
= 0;
4491 r
= cg_mask_from_string(rvalue
, &disabled_mask
);
4492 if (r
< 0 || disabled_mask
<= 0) {
4493 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid cgroup string: %s, ignoring", rvalue
);
4497 c
->disable_controllers
|= disabled_mask
;
4502 int config_parse_ip_filter_bpf_progs(
4504 const char *filename
,
4506 const char *section
,
4507 unsigned section_line
,
4514 _cleanup_free_
char *resolved
= NULL
;
4516 char ***paths
= data
;
4524 if (isempty(rvalue
)) {
4525 *paths
= strv_free(*paths
);
4529 r
= unit_full_printf(u
, rvalue
, &resolved
);
4531 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
4535 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4539 if (strv_contains(*paths
, resolved
))
4542 r
= strv_extend(paths
, resolved
);
4546 r
= bpf_firewall_supported();
4549 if (r
!= BPF_FIREWALL_SUPPORTED_WITH_MULTI
) {
4550 static bool warned
= false;
4552 log_full(warned
? LOG_DEBUG
: LOG_WARNING
,
4553 "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"
4554 "Starting this unit will fail! (This warning is only shown for the first loaded unit using IP firewalling.)", filename
, line
, lvalue
, rvalue
);
4562 #define FOLLOW_MAX 8
4564 static int open_follow(char **filename
, FILE **_f
, Set
*names
, char **_final
) {
4575 /* This will update the filename pointer if the loaded file is
4576 * reached by a symlink. The old string will be freed. */
4579 char *target
, *name
;
4581 if (c
++ >= FOLLOW_MAX
)
4584 path_simplify(*filename
, false);
4586 /* Add the file name we are currently looking at to
4587 * the names of this unit, but only if it is a valid
4589 name
= basename(*filename
);
4590 if (unit_name_is_valid(name
, UNIT_NAME_ANY
)) {
4592 id
= set_get(names
, name
);
4598 r
= set_consume(names
, id
);
4604 /* Try to open the file name, but don't if its a symlink */
4605 fd
= open(*filename
, O_RDONLY
|O_CLOEXEC
|O_NOCTTY
|O_NOFOLLOW
);
4612 /* Hmm, so this is a symlink. Let's read the name, and follow it manually */
4613 r
= readlink_and_make_absolute(*filename
, &target
);
4617 free_and_replace(*filename
, target
);
4620 f
= fdopen(fd
, "r");
4632 static int merge_by_names(Unit
**u
, Set
*names
, const char *id
) {
4640 /* Let's try to add in all symlink names we found */
4641 while ((k
= set_steal_first(names
))) {
4643 /* First try to merge in the other name into our
4645 r
= unit_merge_by_name(*u
, k
);
4649 /* Hmm, we couldn't merge the other unit into
4650 * ours? Then let's try it the other way
4653 /* If the symlink name we are looking at is unit template, then
4654 we must search for instance of this template */
4655 if (unit_name_is_valid(k
, UNIT_NAME_TEMPLATE
) && (*u
)->instance
) {
4656 _cleanup_free_
char *instance
= NULL
;
4658 r
= unit_name_replace_instance(k
, (*u
)->instance
, &instance
);
4662 other
= manager_get_unit((*u
)->manager
, instance
);
4664 other
= manager_get_unit((*u
)->manager
, k
);
4669 r
= unit_merge(other
, *u
);
4672 return merge_by_names(u
, names
, NULL
);
4680 unit_choose_id(*u
, id
);
4688 static int load_from_path(Unit
*u
, const char *path
) {
4689 _cleanup_set_free_free_ Set
*symlink_names
= NULL
;
4690 _cleanup_fclose_
FILE *f
= NULL
;
4691 _cleanup_free_
char *filename
= NULL
;
4700 symlink_names
= set_new(&string_hash_ops
);
4704 if (path_is_absolute(path
)) {
4706 filename
= strdup(path
);
4710 r
= open_follow(&filename
, &f
, symlink_names
, &id
);
4712 filename
= mfree(filename
);
4720 STRV_FOREACH(p
, u
->manager
->lookup_paths
.search_path
) {
4722 /* Instead of opening the path right away, we manually
4723 * follow all symlinks and add their name to our unit
4724 * name set while doing so */
4725 filename
= path_make_absolute(path
, *p
);
4729 if (u
->manager
->unit_path_cache
&&
4730 !set_get(u
->manager
->unit_path_cache
, filename
))
4733 r
= open_follow(&filename
, &f
, symlink_names
, &id
);
4737 /* ENOENT means that the file is missing or is a dangling symlink.
4738 * ENOTDIR means that one of paths we expect to be is a directory
4739 * is not a directory, we should just ignore that.
4740 * EACCES means that the directory or file permissions are wrong.
4743 log_debug_errno(r
, "Cannot access \"%s\": %m", filename
);
4744 else if (!IN_SET(r
, -ENOENT
, -ENOTDIR
))
4747 filename
= mfree(filename
);
4748 /* Empty the symlink names for the next run */
4749 set_clear_free(symlink_names
);
4754 /* Hmm, no suitable file found? */
4757 if (!unit_type_may_alias(u
->type
) && set_size(symlink_names
) > 1) {
4758 log_unit_warning(u
, "Unit type of %s does not support alias names, refusing loading via symlink.", u
->id
);
4763 r
= merge_by_names(&merged
, symlink_names
, id
);
4768 u
->load_state
= UNIT_MERGED
;
4772 if (fstat(fileno(f
), &st
) < 0)
4775 if (null_or_empty(&st
)) {
4776 u
->load_state
= UNIT_MASKED
;
4777 u
->fragment_mtime
= 0;
4779 u
->load_state
= UNIT_LOADED
;
4780 u
->fragment_mtime
= timespec_load(&st
.st_mtim
);
4782 /* Now, parse the file contents */
4783 r
= config_parse(u
->id
, filename
, f
,
4784 UNIT_VTABLE(u
)->sections
,
4785 config_item_perf_lookup
, load_fragment_gperf_lookup
,
4786 CONFIG_PARSE_ALLOW_INCLUDE
, u
);
4791 free_and_replace(u
->fragment_path
, filename
);
4793 if (u
->source_path
) {
4794 if (stat(u
->source_path
, &st
) >= 0)
4795 u
->source_mtime
= timespec_load(&st
.st_mtim
);
4797 u
->source_mtime
= 0;
4803 int unit_load_fragment(Unit
*u
) {
4809 assert(u
->load_state
== UNIT_STUB
);
4813 u
->load_state
= UNIT_LOADED
;
4817 /* First, try to find the unit under its id. We always look
4818 * for unit files in the default directories, to make it easy
4819 * to override things by placing things in /etc/systemd/system */
4820 r
= load_from_path(u
, u
->id
);
4824 /* Try to find an alias we can load this with */
4825 if (u
->load_state
== UNIT_STUB
) {
4826 SET_FOREACH(t
, u
->names
, i
) {
4831 r
= load_from_path(u
, t
);
4835 if (u
->load_state
!= UNIT_STUB
)
4840 /* And now, try looking for it under the suggested (originally linked) path */
4841 if (u
->load_state
== UNIT_STUB
&& u
->fragment_path
) {
4843 r
= load_from_path(u
, u
->fragment_path
);
4847 if (u
->load_state
== UNIT_STUB
)
4848 /* Hmm, this didn't work? Then let's get rid
4849 * of the fragment path stored for us, so that
4850 * we don't point to an invalid location. */
4851 u
->fragment_path
= mfree(u
->fragment_path
);
4854 /* Look for a template */
4855 if (u
->load_state
== UNIT_STUB
&& u
->instance
) {
4856 _cleanup_free_
char *k
= NULL
;
4858 r
= unit_name_template(u
->id
, &k
);
4862 r
= load_from_path(u
, k
);
4865 log_unit_notice(u
, "Unit configuration has fatal error, unit will not be started.");
4869 if (u
->load_state
== UNIT_STUB
) {
4870 SET_FOREACH(t
, u
->names
, i
) {
4871 _cleanup_free_
char *z
= NULL
;
4876 r
= unit_name_template(t
, &z
);
4880 r
= load_from_path(u
, z
);
4884 if (u
->load_state
!= UNIT_STUB
)
4893 void unit_dump_config_items(FILE *f
) {
4894 static const struct {
4895 const ConfigParserCallback callback
;
4898 { config_parse_warn_compat
, "NOTSUPPORTED" },
4899 { config_parse_int
, "INTEGER" },
4900 { config_parse_unsigned
, "UNSIGNED" },
4901 { config_parse_iec_size
, "SIZE" },
4902 { config_parse_iec_uint64
, "SIZE" },
4903 { config_parse_si_size
, "SIZE" },
4904 { config_parse_bool
, "BOOLEAN" },
4905 { config_parse_string
, "STRING" },
4906 { config_parse_path
, "PATH" },
4907 { config_parse_unit_path_printf
, "PATH" },
4908 { config_parse_strv
, "STRING [...]" },
4909 { config_parse_exec_nice
, "NICE" },
4910 { config_parse_exec_oom_score_adjust
, "OOMSCOREADJUST" },
4911 { config_parse_exec_io_class
, "IOCLASS" },
4912 { config_parse_exec_io_priority
, "IOPRIORITY" },
4913 { config_parse_exec_cpu_sched_policy
, "CPUSCHEDPOLICY" },
4914 { config_parse_exec_cpu_sched_prio
, "CPUSCHEDPRIO" },
4915 { config_parse_exec_cpu_affinity
, "CPUAFFINITY" },
4916 { config_parse_mode
, "MODE" },
4917 { config_parse_unit_env_file
, "FILE" },
4918 { config_parse_exec_output
, "OUTPUT" },
4919 { config_parse_exec_input
, "INPUT" },
4920 { config_parse_log_facility
, "FACILITY" },
4921 { config_parse_log_level
, "LEVEL" },
4922 { config_parse_exec_secure_bits
, "SECUREBITS" },
4923 { config_parse_capability_set
, "BOUNDINGSET" },
4924 { config_parse_rlimit
, "LIMIT" },
4925 { config_parse_unit_deps
, "UNIT [...]" },
4926 { config_parse_exec
, "PATH [ARGUMENT [...]]" },
4927 { config_parse_service_type
, "SERVICETYPE" },
4928 { config_parse_service_restart
, "SERVICERESTART" },
4929 { config_parse_kill_mode
, "KILLMODE" },
4930 { config_parse_signal
, "SIGNAL" },
4931 { config_parse_socket_listen
, "SOCKET [...]" },
4932 { config_parse_socket_bind
, "SOCKETBIND" },
4933 { config_parse_socket_bindtodevice
, "NETWORKINTERFACE" },
4934 { config_parse_sec
, "SECONDS" },
4935 { config_parse_nsec
, "NANOSECONDS" },
4936 { config_parse_namespace_path_strv
, "PATH [...]" },
4937 { config_parse_bind_paths
, "PATH[:PATH[:OPTIONS]] [...]" },
4938 { config_parse_unit_requires_mounts_for
, "PATH [...]" },
4939 { config_parse_exec_mount_flags
, "MOUNTFLAG [...]" },
4940 { config_parse_unit_string_printf
, "STRING" },
4941 { config_parse_trigger_unit
, "UNIT" },
4942 { config_parse_timer
, "TIMER" },
4943 { config_parse_path_spec
, "PATH" },
4944 { config_parse_notify_access
, "ACCESS" },
4945 { config_parse_ip_tos
, "TOS" },
4946 { config_parse_unit_condition_path
, "CONDITION" },
4947 { config_parse_unit_condition_string
, "CONDITION" },
4948 { config_parse_unit_condition_null
, "CONDITION" },
4949 { config_parse_unit_slice
, "SLICE" },
4950 { config_parse_documentation
, "URL" },
4951 { config_parse_service_timeout
, "SECONDS" },
4952 { config_parse_emergency_action
, "ACTION" },
4953 { config_parse_set_status
, "STATUS" },
4954 { config_parse_service_sockets
, "SOCKETS" },
4955 { config_parse_environ
, "ENVIRON" },
4957 { config_parse_syscall_filter
, "SYSCALLS" },
4958 { config_parse_syscall_archs
, "ARCHS" },
4959 { config_parse_syscall_errno
, "ERRNO" },
4960 { config_parse_address_families
, "FAMILIES" },
4961 { config_parse_restrict_namespaces
, "NAMESPACES" },
4963 { config_parse_cpu_shares
, "SHARES" },
4964 { config_parse_cg_weight
, "WEIGHT" },
4965 { config_parse_memory_limit
, "LIMIT" },
4966 { config_parse_device_allow
, "DEVICE" },
4967 { config_parse_device_policy
, "POLICY" },
4968 { config_parse_io_limit
, "LIMIT" },
4969 { config_parse_io_device_weight
, "DEVICEWEIGHT" },
4970 { config_parse_io_device_latency
, "DEVICELATENCY" },
4971 { config_parse_blockio_bandwidth
, "BANDWIDTH" },
4972 { config_parse_blockio_weight
, "WEIGHT" },
4973 { config_parse_blockio_device_weight
, "DEVICEWEIGHT" },
4974 { config_parse_long
, "LONG" },
4975 { config_parse_socket_service
, "SERVICE" },
4977 { config_parse_exec_selinux_context
, "LABEL" },
4979 { config_parse_job_mode
, "MODE" },
4980 { config_parse_job_mode_isolate
, "BOOLEAN" },
4981 { config_parse_personality
, "PERSONALITY" },
4984 const char *prev
= NULL
;
4989 NULSTR_FOREACH(i
, load_fragment_gperf_nulstr
) {
4990 const char *rvalue
= "OTHER", *lvalue
;
4991 const ConfigPerfItem
*p
;
4996 assert_se(p
= load_fragment_gperf_lookup(i
, strlen(i
)));
4998 /* Hide legacy settings */
4999 if (p
->parse
== config_parse_warn_compat
&&
5000 p
->ltype
== DISABLED_LEGACY
)
5003 for (j
= 0; j
< ELEMENTSOF(table
); j
++)
5004 if (p
->parse
== table
[j
].callback
) {
5005 rvalue
= table
[j
].rvalue
;
5009 dot
= strchr(i
, '.');
5010 lvalue
= dot
? dot
+ 1 : i
;
5014 if (!prev
|| !strneq(prev
, i
, prefix_len
+1)) {
5018 fprintf(f
, "[%.*s]\n", (int) prefix_len
, i
);
5021 fprintf(f
, "%s=%s\n", lvalue
, rvalue
);
5026 int config_parse_cpu_affinity2(
5028 const char *filename
,
5030 const char *section
,
5031 unsigned section_line
,
5038 CPUSet
*affinity
= data
;
5042 (void) parse_cpu_set_extend(rvalue
, affinity
, true, unit
, filename
, line
, lvalue
);
5047 int config_parse_show_status(
5049 const char *filename
,
5051 const char *section
,
5052 unsigned section_line
,
5060 ShowStatus
*b
= data
;
5067 k
= parse_show_status(rvalue
, b
);
5069 log_syntax(unit
, LOG_ERR
, filename
, line
, k
, "Failed to parse show status setting, ignoring: %s", rvalue
);
5076 int config_parse_output_restricted(
5078 const char *filename
,
5080 const char *section
,
5081 unsigned section_line
,
5088 ExecOutput t
, *eo
= data
;
5095 t
= exec_output_from_string(rvalue
);
5097 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse output type, ignoring: %s", rvalue
);
5101 if (IN_SET(t
, EXEC_OUTPUT_SOCKET
, EXEC_OUTPUT_NAMED_FD
, EXEC_OUTPUT_FILE
, EXEC_OUTPUT_FILE_APPEND
)) {
5102 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Standard output types socket, fd:, file:, append: are not supported as defaults, ignoring: %s", rvalue
);
5110 int config_parse_crash_chvt(
5112 const char *filename
,
5114 const char *section
,
5115 unsigned section_line
,
5129 r
= parse_crash_chvt(rvalue
, data
);
5131 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse CrashChangeVT= setting, ignoring: %s", rvalue
);
5138 int config_parse_timeout_abort(
5140 const char *filename
,
5142 const char *section
,
5143 unsigned section_line
,
5150 usec_t
*timeout_usec
= data
;
5156 assert(timeout_usec
);
5158 rvalue
+= strspn(rvalue
, WHITESPACE
);
5159 if (isempty(rvalue
)) {
5160 *timeout_usec
= false;
5164 r
= parse_sec(rvalue
, timeout_usec
);
5166 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse DefaultTimeoutAbortSec= setting, ignoring: %s", rvalue
);
5170 *timeout_usec
= true;