1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 This file is part of systemd.
5 Copyright 2010 Lennart Poettering
6 Copyright 2012 Holger Hans Peter Freyther
12 #include <linux/oom.h>
18 #include <sys/resource.h>
22 #include "alloc-util.h"
23 #include "all-units.h"
24 #include "bus-error.h"
25 #include "bus-internal.h"
28 #include "capability-util.h"
30 #include "conf-parser.h"
31 #include "cpu-set-util.h"
33 #include "errno-list.h"
37 #include "hexdecoct.h"
40 #include "journal-util.h"
41 #include "load-fragment.h"
44 #include "mount-util.h"
45 #include "parse-util.h"
46 #include "path-util.h"
47 #include "process-util.h"
49 #include "seccomp-util.h"
51 #include "securebits.h"
52 #include "securebits-util.h"
53 #include "signal-util.h"
54 #include "socket-protocol-list.h"
55 #include "stat-util.h"
56 #include "string-util.h"
58 #include "unit-name.h"
59 #include "unit-printf.h"
60 #include "user-util.h"
64 DEFINE_CONFIG_PARSE_ENUM(config_parse_collect_mode
, collect_mode
, CollectMode
, "Failed to parse garbage collection mode");
66 int config_parse_unit_deps(
71 unsigned section_line
,
78 UnitDependency d
= ltype
;
88 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
91 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_RETAIN_ESCAPE
);
97 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
101 r
= unit_name_printf(u
, word
, &k
);
103 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
107 r
= unit_add_dependency_by_name(u
, d
, k
, NULL
, true, UNIT_DEPENDENCY_FILE
);
109 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
115 int config_parse_obsolete_unit_deps(
117 const char *filename
,
120 unsigned section_line
,
127 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
128 "Unit dependency type %s= is obsolete, replacing by %s=, please update your unit file", lvalue
, unit_dependency_to_string(ltype
));
130 return config_parse_unit_deps(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
);
133 int config_parse_unit_string_printf(
135 const char *filename
,
138 unsigned section_line
,
145 _cleanup_free_
char *k
= NULL
;
154 r
= unit_full_printf(u
, rvalue
, &k
);
156 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
160 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
163 int config_parse_unit_strv_printf(
165 const char *filename
,
168 unsigned section_line
,
176 _cleanup_free_
char *k
= NULL
;
184 r
= unit_full_printf(u
, rvalue
, &k
);
186 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
190 return config_parse_strv(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
193 int config_parse_unit_path_printf(
195 const char *filename
,
198 unsigned section_line
,
205 _cleanup_free_
char *k
= NULL
;
215 /* Let's not bother with anything that is too long */
216 if (strlen(rvalue
) >= PATH_MAX
) {
217 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
218 "%s value too long%s.",
219 lvalue
, fatal
? "" : ", ignoring");
220 return fatal
? -ENAMETOOLONG
: 0;
223 r
= unit_full_printf(u
, rvalue
, &k
);
225 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
226 "Failed to resolve unit specifiers in '%s'%s: %m",
227 rvalue
, fatal
? "" : ", ignoring");
228 return fatal
? -ENOEXEC
: 0;
231 return config_parse_path(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
234 int config_parse_unit_path_strv_printf(
236 const char *filename
,
239 unsigned section_line
,
256 if (isempty(rvalue
)) {
262 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
264 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
270 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
271 "Invalid syntax, ignoring: %s", rvalue
);
275 r
= unit_full_printf(u
, word
, &k
);
277 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
278 "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
282 if (!utf8_is_valid(k
)) {
283 log_syntax_invalid_utf8(unit
, LOG_ERR
, filename
, line
, rvalue
);
287 if (!path_is_absolute(k
)) {
288 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
289 "Symlink path is not absolute: %s", k
);
293 path_kill_slashes(k
);
302 int config_parse_socket_listen(const char *unit
,
303 const char *filename
,
306 unsigned section_line
,
313 _cleanup_free_ SocketPort
*p
= NULL
;
325 if (isempty(rvalue
)) {
326 /* An empty assignment removes all ports */
327 socket_free_ports(s
);
331 p
= new0(SocketPort
, 1);
335 if (ltype
!= SOCKET_SOCKET
) {
338 r
= unit_full_printf(UNIT(s
), rvalue
, &p
->path
);
340 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
344 path_kill_slashes(p
->path
);
346 } else if (streq(lvalue
, "ListenNetlink")) {
347 _cleanup_free_
char *k
= NULL
;
349 p
->type
= SOCKET_SOCKET
;
350 r
= unit_full_printf(UNIT(s
), rvalue
, &k
);
352 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
356 r
= socket_address_parse_netlink(&p
->address
, k
);
358 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse address value in '%s', ignoring: %m", k
);
363 _cleanup_free_
char *k
= NULL
;
365 p
->type
= SOCKET_SOCKET
;
366 r
= unit_full_printf(UNIT(s
), rvalue
, &k
);
368 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
372 r
= socket_address_parse_and_warn(&p
->address
, k
);
374 if (r
!= -EAFNOSUPPORT
)
375 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse address value in '%s', ignoring: %m", k
);
379 if (streq(lvalue
, "ListenStream"))
380 p
->address
.type
= SOCK_STREAM
;
381 else if (streq(lvalue
, "ListenDatagram"))
382 p
->address
.type
= SOCK_DGRAM
;
384 assert(streq(lvalue
, "ListenSequentialPacket"));
385 p
->address
.type
= SOCK_SEQPACKET
;
388 if (socket_address_family(&p
->address
) != AF_LOCAL
&& p
->address
.type
== SOCK_SEQPACKET
) {
389 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Address family not supported, ignoring: %s", rvalue
);
395 p
->auxiliary_fds
= NULL
;
396 p
->n_auxiliary_fds
= 0;
399 LIST_FIND_TAIL(port
, s
->ports
, tail
);
400 LIST_INSERT_AFTER(port
, s
->ports
, tail
, p
);
407 int config_parse_socket_protocol(const char *unit
,
408 const char *filename
,
411 unsigned section_line
,
427 r
= socket_protocol_from_name(rvalue
);
429 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid socket protocol '%s', ignoring: %m", rvalue
);
431 } else if (!IN_SET(r
, IPPROTO_UDPLITE
, IPPROTO_SCTP
)) {
432 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Socket protocol not supported, ignoring: %s", rvalue
);
436 s
->socket_protocol
= r
;
441 int config_parse_socket_bind(const char *unit
,
442 const char *filename
,
445 unsigned section_line
,
453 SocketAddressBindIPv6Only b
;
462 b
= parse_socket_address_bind_ipv6_only_or_bool(rvalue
);
464 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse bind IPv6 only value, ignoring: %s", rvalue
);
468 s
->bind_ipv6_only
= b
;
473 int config_parse_exec_nice(
475 const char *filename
,
478 unsigned section_line
,
485 ExecContext
*c
= data
;
493 if (isempty(rvalue
)) {
498 r
= parse_nice(rvalue
, &priority
);
501 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Nice priority out of range, ignoring: %s", rvalue
);
503 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse nice priority '%s', ignoring: %m", rvalue
);
513 int config_parse_exec_oom_score_adjust(
515 const char *filename
,
518 unsigned section_line
,
525 ExecContext
*c
= data
;
533 if (isempty(rvalue
)) {
534 c
->oom_score_adjust_set
= false;
538 r
= parse_oom_score_adjust(rvalue
, &oa
);
541 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "OOM score adjust value out of range, ignoring: %s", rvalue
);
543 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse the OOM score adjust value '%s', ignoring: %m", rvalue
);
547 c
->oom_score_adjust
= oa
;
548 c
->oom_score_adjust_set
= true;
553 int config_parse_exec(
555 const char *filename
,
558 unsigned section_line
,
565 ExecCommand
**e
= data
;
577 rvalue
+= strspn(rvalue
, WHITESPACE
);
579 if (isempty(rvalue
)) {
580 /* An empty assignment resets the list */
581 *e
= exec_command_free_list(*e
);
587 _cleanup_free_
char *path
= NULL
, *firstword
= NULL
;
588 ExecCommandFlags flags
= 0;
589 bool ignore
= false, separate_argv0
= false;
590 _cleanup_free_ ExecCommand
*nce
= NULL
;
591 _cleanup_strv_free_
char **n
= NULL
;
592 size_t nlen
= 0, nbufsize
= 0;
597 r
= extract_first_word_and_warn(&p
, &firstword
, NULL
, EXTRACT_QUOTES
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
603 /* We accept an absolute path as first argument. If it's prefixed with - and the path doesn't
604 * exist, we ignore it instead of erroring out; if it's prefixed with @, we allow overriding of
605 * argv[0]; if it's prefixed with +, it will be run with full privileges and no sandboxing; if
606 * it's prefixed with '!' we apply sandboxing, but do not change user/group credentials; if
607 * it's prefixed with '!!', then we apply user/group credentials if the kernel supports ambient
608 * capabilities -- if it doesn't we don't apply the credentials themselves, but do apply most
609 * other sandboxing, with some special exceptions for changing UID.
611 * The idea is that '!!' may be used to write services that can take benefit of systemd's
612 * UID/GID dropping if the kernel supports ambient creds, but provide an automatic fallback to
613 * privilege dropping within the daemon if the kernel does not offer that. */
615 if (*f
== '-' && !(flags
& EXEC_COMMAND_IGNORE_FAILURE
)) {
616 flags
|= EXEC_COMMAND_IGNORE_FAILURE
;
618 } else if (*f
== '@' && !separate_argv0
)
619 separate_argv0
= true;
620 else if (*f
== '+' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
621 flags
|= EXEC_COMMAND_FULLY_PRIVILEGED
;
622 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
623 flags
|= EXEC_COMMAND_NO_SETUID
;
624 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_AMBIENT_MAGIC
))) {
625 flags
&= ~EXEC_COMMAND_NO_SETUID
;
626 flags
|= EXEC_COMMAND_AMBIENT_MAGIC
;
632 r
= unit_full_printf(u
, f
, &path
);
634 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
635 "Failed to resolve unit specifiers in '%s'%s: %m",
636 f
, ignore
? ", ignoring" : "");
637 return ignore
? 0 : -ENOEXEC
;
641 /* First word is either "-" or "@" with no command. */
642 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
643 "Empty path in command line%s: '%s'",
644 ignore
? ", ignoring" : "", rvalue
);
645 return ignore
? 0 : -ENOEXEC
;
647 if (!string_is_safe(path
)) {
648 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
649 "Executable name contains special characters%s: %s",
650 ignore
? ", ignoring" : "", path
);
651 return ignore
? 0 : -ENOEXEC
;
653 if (endswith(path
, "/")) {
654 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
655 "Executable path specifies a directory%s: %s",
656 ignore
? ", ignoring" : "", path
);
657 return ignore
? 0 : -ENOEXEC
;
660 if (!path_is_absolute(path
)) {
664 if (!filename_is_valid(path
)) {
665 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
666 "Neither a valid executable name nor an absolute path%s: %s",
667 ignore
? ", ignoring" : "", path
);
668 return ignore
? 0 : -ENOEXEC
;
671 /* Resolve a single-component name to a full path */
672 NULSTR_FOREACH(prefix
, DEFAULT_PATH_NULSTR
) {
673 _cleanup_free_
char *fullpath
= NULL
;
675 fullpath
= strjoin(prefix
, "/", path
);
679 if (access(fullpath
, F_OK
) >= 0) {
680 free_and_replace(path
, fullpath
);
687 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
688 "Executable \"%s\" not found in path \"%s\"%s",
689 path
, DEFAULT_PATH
, ignore
? ", ignoring" : "");
690 return ignore
? 0 : -ENOEXEC
;
694 if (!separate_argv0
) {
697 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
707 path_kill_slashes(path
);
709 while (!isempty(p
)) {
710 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
712 /* Check explicitly for an unquoted semicolon as
713 * command separator token. */
714 if (p
[0] == ';' && (!p
[1] || strchr(WHITESPACE
, p
[1]))) {
716 p
+= strspn(p
, WHITESPACE
);
721 /* Check for \; explicitly, to not confuse it with \\; or "\;" or "\\;" etc.
722 * extract_first_word() would return the same for all of those. */
723 if (p
[0] == '\\' && p
[1] == ';' && (!p
[2] || strchr(WHITESPACE
, p
[2]))) {
727 p
+= strspn(p
, WHITESPACE
);
729 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
740 r
= extract_first_word_and_warn(&p
, &word
, NULL
, EXTRACT_QUOTES
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
744 return ignore
? 0 : -ENOEXEC
;
746 r
= unit_full_printf(u
, word
, &resolved
);
748 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
749 "Failed to resolve unit specifiers in %s%s: %m",
750 word
, ignore
? ", ignoring" : "");
751 return ignore
? 0 : -ENOEXEC
;
754 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
757 n
[nlen
++] = TAKE_PTR(resolved
);
762 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
763 "Empty executable name or zeroeth argument%s: %s",
764 ignore
? ", ignoring" : "", rvalue
);
765 return ignore
? 0 : -ENOEXEC
;
768 nce
= new0(ExecCommand
, 1);
772 nce
->argv
= TAKE_PTR(n
);
773 nce
->path
= TAKE_PTR(path
);
776 exec_command_append_list(e
, nce
);
778 /* Do not _cleanup_free_ these. */
787 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_type
, service_type
, ServiceType
, "Failed to parse service type");
788 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart
, service_restart
, ServiceRestart
, "Failed to parse service restart specifier");
790 int config_parse_socket_bindtodevice(
792 const char *filename
,
795 unsigned section_line
,
809 if (isempty(rvalue
) || streq(rvalue
, "*")) {
810 s
->bind_to_device
= mfree(s
->bind_to_device
);
814 if (!ifname_valid(rvalue
)) {
815 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid interface name, ignoring: %s", rvalue
);
819 free_and_strdup(&s
->bind_to_device
, rvalue
);
824 int config_parse_exec_input(
826 const char *filename
,
829 unsigned section_line
,
836 ExecContext
*c
= data
;
847 n
= startswith(rvalue
, "fd:");
849 _cleanup_free_
char *resolved
= NULL
;
851 r
= unit_full_printf(u
, n
, &resolved
);
853 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s': %m", n
);
855 if (isempty(resolved
))
856 resolved
= mfree(resolved
);
857 else if (!fdname_is_valid(resolved
)) {
858 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name: %s", resolved
);
862 free_and_replace(c
->stdio_fdname
[STDIN_FILENO
], resolved
);
864 ei
= EXEC_INPUT_NAMED_FD
;
866 } else if ((n
= startswith(rvalue
, "file:"))) {
867 _cleanup_free_
char *resolved
= NULL
;
869 r
= unit_full_printf(u
, n
, &resolved
);
871 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s': %m", n
);
873 if (!path_is_absolute(resolved
)) {
874 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "file: requires an absolute path name: %s", resolved
);
878 if (!path_is_normalized(resolved
)) {
879 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "file: requires a normalized path name: %s", resolved
);
883 free_and_replace(c
->stdio_file
[STDIN_FILENO
], resolved
);
885 ei
= EXEC_INPUT_FILE
;
888 ei
= exec_input_from_string(rvalue
);
890 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse input specifier, ignoring: %s", rvalue
);
899 int config_parse_exec_input_text(
901 const char *filename
,
904 unsigned section_line
,
911 _cleanup_free_
char *unescaped
= NULL
, *resolved
= NULL
;
912 ExecContext
*c
= data
;
923 if (isempty(rvalue
)) {
924 /* Reset if the empty string is assigned */
925 c
->stdin_data
= mfree(c
->stdin_data
);
926 c
->stdin_data_size
= 0;
930 r
= cunescape(rvalue
, 0, &unescaped
);
932 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to decode C escaped text '%s': %m", rvalue
);
934 r
= unit_full_printf(u
, unescaped
, &resolved
);
936 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s': %m", unescaped
);
938 sz
= strlen(resolved
);
939 if (c
->stdin_data_size
+ sz
+ 1 < c
->stdin_data_size
|| /* check for overflow */
940 c
->stdin_data_size
+ sz
+ 1 > EXEC_STDIN_DATA_MAX
) {
941 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
);
945 p
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
+ 1);
949 *((char*) mempcpy((char*) p
+ c
->stdin_data_size
, resolved
, sz
)) = '\n';
952 c
->stdin_data_size
+= sz
+ 1;
957 int config_parse_exec_input_data(
959 const char *filename
,
962 unsigned section_line
,
969 _cleanup_free_
void *p
= NULL
;
970 ExecContext
*c
= data
;
980 if (isempty(rvalue
)) {
981 /* Reset if the empty string is assigned */
982 c
->stdin_data
= mfree(c
->stdin_data
);
983 c
->stdin_data_size
= 0;
987 r
= unbase64mem(rvalue
, (size_t) -1, &p
, &sz
);
989 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to decode base64 data, ignoring: %s", rvalue
);
993 if (c
->stdin_data_size
+ sz
< c
->stdin_data_size
|| /* check for overflow */
994 c
->stdin_data_size
+ sz
> EXEC_STDIN_DATA_MAX
) {
995 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
);
999 q
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
);
1003 memcpy((uint8_t*) q
+ c
->stdin_data_size
, p
, sz
);
1006 c
->stdin_data_size
+= sz
;
1011 int config_parse_exec_output(
1013 const char *filename
,
1015 const char *section
,
1016 unsigned section_line
,
1023 _cleanup_free_
char *resolved
= NULL
;
1025 ExecContext
*c
= data
;
1036 n
= startswith(rvalue
, "fd:");
1038 r
= unit_full_printf(u
, n
, &resolved
);
1040 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", n
);
1042 if (isempty(resolved
))
1043 resolved
= mfree(resolved
);
1044 else if (!fdname_is_valid(resolved
)) {
1045 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name: %s", resolved
);
1049 eo
= EXEC_OUTPUT_NAMED_FD
;
1051 } else if ((n
= startswith(rvalue
, "file:"))) {
1053 r
= unit_full_printf(u
, n
, &resolved
);
1055 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", n
);
1057 if (!path_is_absolute(resolved
)) {
1058 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "file: requires an absolute path name: %s", resolved
);
1062 if (!path_is_normalized(resolved
)) {
1063 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "file: requires a normalized path name, ignoring: %s", resolved
);
1067 eo
= EXEC_OUTPUT_FILE
;
1070 eo
= exec_output_from_string(rvalue
);
1072 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse output specifier, ignoring: %s", rvalue
);
1077 if (streq(lvalue
, "StandardOutput")) {
1078 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1079 free_and_replace(c
->stdio_fdname
[STDOUT_FILENO
], resolved
);
1081 free_and_replace(c
->stdio_file
[STDOUT_FILENO
], resolved
);
1086 assert(streq(lvalue
, "StandardError"));
1088 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1089 free_and_replace(c
->stdio_fdname
[STDERR_FILENO
], resolved
);
1091 free_and_replace(c
->stdio_file
[STDERR_FILENO
], resolved
);
1099 int config_parse_exec_io_class(const char *unit
,
1100 const char *filename
,
1102 const char *section
,
1103 unsigned section_line
,
1110 ExecContext
*c
= data
;
1118 if (isempty(rvalue
)) {
1119 c
->ioprio_set
= false;
1120 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE
, 0);
1124 x
= ioprio_class_from_string(rvalue
);
1126 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse IO scheduling class, ignoring: %s", rvalue
);
1130 c
->ioprio
= IOPRIO_PRIO_VALUE(x
, IOPRIO_PRIO_DATA(c
->ioprio
));
1131 c
->ioprio_set
= true;
1136 int config_parse_exec_io_priority(const char *unit
,
1137 const char *filename
,
1139 const char *section
,
1140 unsigned section_line
,
1147 ExecContext
*c
= data
;
1155 if (isempty(rvalue
)) {
1156 c
->ioprio_set
= false;
1157 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE
, 0);
1161 r
= ioprio_parse_priority(rvalue
, &i
);
1163 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse IO priority, ignoring: %s", rvalue
);
1167 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_PRIO_CLASS(c
->ioprio
), i
);
1168 c
->ioprio_set
= true;
1173 int config_parse_exec_cpu_sched_policy(const char *unit
,
1174 const char *filename
,
1176 const char *section
,
1177 unsigned section_line
,
1184 ExecContext
*c
= data
;
1192 if (isempty(rvalue
)) {
1193 c
->cpu_sched_set
= false;
1194 c
->cpu_sched_policy
= SCHED_OTHER
;
1195 c
->cpu_sched_priority
= 0;
1199 x
= sched_policy_from_string(rvalue
);
1201 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse CPU scheduling policy, ignoring: %s", rvalue
);
1205 c
->cpu_sched_policy
= x
;
1206 /* Moving to or from real-time policy? We need to adjust the priority */
1207 c
->cpu_sched_priority
= CLAMP(c
->cpu_sched_priority
, sched_get_priority_min(x
), sched_get_priority_max(x
));
1208 c
->cpu_sched_set
= true;
1213 int config_parse_exec_cpu_sched_prio(const char *unit
,
1214 const char *filename
,
1216 const char *section
,
1217 unsigned section_line
,
1224 ExecContext
*c
= data
;
1232 r
= safe_atoi(rvalue
, &i
);
1234 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse CPU scheduling priority, ignoring: %s", rvalue
);
1238 /* On Linux RR/FIFO range from 1 to 99 and OTHER/BATCH may only be 0 */
1239 min
= sched_get_priority_min(c
->cpu_sched_policy
);
1240 max
= sched_get_priority_max(c
->cpu_sched_policy
);
1242 if (i
< min
|| i
> max
) {
1243 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "CPU scheduling priority is out of range, ignoring: %s", rvalue
);
1247 c
->cpu_sched_priority
= i
;
1248 c
->cpu_sched_set
= true;
1253 int config_parse_exec_cpu_affinity(const char *unit
,
1254 const char *filename
,
1256 const char *section
,
1257 unsigned section_line
,
1264 ExecContext
*c
= data
;
1265 _cleanup_cpu_free_ cpu_set_t
*cpuset
= NULL
;
1273 ncpus
= parse_cpu_set_and_warn(rvalue
, &cpuset
, unit
, filename
, line
, lvalue
);
1278 /* An empty assignment resets the CPU list */
1279 c
->cpuset
= cpu_set_mfree(c
->cpuset
);
1280 c
->cpuset_ncpus
= 0;
1285 c
->cpuset
= TAKE_PTR(cpuset
);
1286 c
->cpuset_ncpus
= (unsigned) ncpus
;
1290 if (c
->cpuset_ncpus
< (unsigned) ncpus
) {
1291 CPU_OR_S(CPU_ALLOC_SIZE(c
->cpuset_ncpus
), cpuset
, c
->cpuset
, cpuset
);
1292 CPU_FREE(c
->cpuset
);
1293 c
->cpuset
= TAKE_PTR(cpuset
);
1294 c
->cpuset_ncpus
= (unsigned) ncpus
;
1298 CPU_OR_S(CPU_ALLOC_SIZE((unsigned) ncpus
), c
->cpuset
, c
->cpuset
, cpuset
);
1303 int config_parse_exec_secure_bits(const char *unit
,
1304 const char *filename
,
1306 const char *section
,
1307 unsigned section_line
,
1314 ExecContext
*c
= data
;
1322 if (isempty(rvalue
)) {
1323 /* An empty assignment resets the field */
1328 r
= secure_bits_from_string(rvalue
);
1330 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1331 "Failed to parse secure bits, ignoring: %s", rvalue
);
1340 int config_parse_capability_set(
1342 const char *filename
,
1344 const char *section
,
1345 unsigned section_line
,
1352 uint64_t *capability_set
= data
;
1353 uint64_t sum
= 0, initial
= 0;
1354 bool invert
= false;
1362 if (rvalue
[0] == '~') {
1367 if (streq(lvalue
, "CapabilityBoundingSet"))
1368 initial
= CAP_ALL
; /* initialized to all bits on */
1369 /* else "AmbientCapabilities" initialized to all bits off */
1371 r
= capability_set_from_string(rvalue
, &sum
);
1373 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= specifier '%s', ignoring: %m", lvalue
, rvalue
);
1377 if (sum
== 0 || *capability_set
== initial
)
1378 /* "", "~" or uninitialized data -> replace */
1379 *capability_set
= invert
? ~sum
: sum
;
1381 /* previous data -> merge */
1383 *capability_set
&= ~sum
;
1385 *capability_set
|= sum
;
1391 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_utmp_mode
, exec_utmp_mode
, ExecUtmpMode
, "Failed to parse utmp mode");
1392 DEFINE_CONFIG_PARSE_ENUM(config_parse_kill_mode
, kill_mode
, KillMode
, "Failed to parse kill mode");
1394 int config_parse_exec_mount_flags(
1396 const char *filename
,
1398 const char *section
,
1399 unsigned section_line
,
1406 ExecContext
*c
= data
;
1414 r
= mount_propagation_flags_from_string(rvalue
, &c
->mount_flags
);
1416 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse mount flag %s, ignoring: %m", rvalue
);
1421 int config_parse_exec_selinux_context(
1423 const char *filename
,
1425 const char *section
,
1426 unsigned section_line
,
1433 ExecContext
*c
= data
;
1444 if (isempty(rvalue
)) {
1445 c
->selinux_context
= mfree(c
->selinux_context
);
1446 c
->selinux_context_ignore
= false;
1450 if (rvalue
[0] == '-') {
1456 r
= unit_full_printf(u
, rvalue
, &k
);
1458 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1459 "Failed to resolve unit specifiers in '%s'%s: %m",
1460 rvalue
, ignore
? ", ignoring" : "");
1461 return ignore
? 0 : -ENOEXEC
;
1464 free_and_replace(c
->selinux_context
, k
);
1465 c
->selinux_context_ignore
= ignore
;
1470 int config_parse_exec_apparmor_profile(
1472 const char *filename
,
1474 const char *section
,
1475 unsigned section_line
,
1482 ExecContext
*c
= data
;
1493 if (isempty(rvalue
)) {
1494 c
->apparmor_profile
= mfree(c
->apparmor_profile
);
1495 c
->apparmor_profile_ignore
= false;
1499 if (rvalue
[0] == '-') {
1505 r
= unit_full_printf(u
, rvalue
, &k
);
1507 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1508 "Failed to resolve unit specifiers in '%s'%s: %m",
1509 rvalue
, ignore
? ", ignoring" : "");
1510 return ignore
? 0 : -ENOEXEC
;
1513 free_and_replace(c
->apparmor_profile
, k
);
1514 c
->apparmor_profile_ignore
= ignore
;
1519 int config_parse_exec_smack_process_label(
1521 const char *filename
,
1523 const char *section
,
1524 unsigned section_line
,
1531 ExecContext
*c
= data
;
1542 if (isempty(rvalue
)) {
1543 c
->smack_process_label
= mfree(c
->smack_process_label
);
1544 c
->smack_process_label_ignore
= false;
1548 if (rvalue
[0] == '-') {
1554 r
= unit_full_printf(u
, rvalue
, &k
);
1556 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1557 "Failed to resolve unit specifiers in '%s'%s: %m",
1558 rvalue
, ignore
? ", ignoring" : "");
1559 return ignore
? 0 : -ENOEXEC
;
1562 free_and_replace(c
->smack_process_label
, k
);
1563 c
->smack_process_label_ignore
= ignore
;
1568 int config_parse_timer(const char *unit
,
1569 const char *filename
,
1571 const char *section
,
1572 unsigned section_line
,
1583 _cleanup_(calendar_spec_freep
) CalendarSpec
*c
= NULL
;
1585 _cleanup_free_
char *k
= NULL
;
1593 if (isempty(rvalue
)) {
1594 /* Empty assignment resets list */
1595 timer_free_values(t
);
1599 b
= timer_base_from_string(lvalue
);
1601 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse timer base, ignoring: %s", lvalue
);
1605 r
= unit_full_printf(u
, rvalue
, &k
);
1607 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
1611 if (b
== TIMER_CALENDAR
) {
1612 if (calendar_spec_from_string(k
, &c
) < 0) {
1613 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse calendar specification, ignoring: %s", k
);
1617 if (parse_sec(k
, &usec
) < 0) {
1618 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse timer value, ignoring: %s", k
);
1622 v
= new0(TimerValue
, 1);
1628 v
->calendar_spec
= TAKE_PTR(c
);
1630 LIST_PREPEND(value
, t
->values
, v
);
1635 int config_parse_trigger_unit(
1637 const char *filename
,
1639 const char *section
,
1640 unsigned section_line
,
1647 _cleanup_free_
char *p
= NULL
;
1657 if (!hashmap_isempty(u
->dependencies
[UNIT_TRIGGERS
])) {
1658 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Multiple units to trigger specified, ignoring: %s", rvalue
);
1662 r
= unit_name_printf(u
, rvalue
, &p
);
1664 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
1668 type
= unit_name_to_type(p
);
1670 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit type not valid, ignoring: %s", rvalue
);
1673 if (unit_has_name(u
, p
)) {
1674 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Units cannot trigger themselves, ignoring: %s", rvalue
);
1678 r
= unit_add_two_dependencies_by_name(u
, UNIT_BEFORE
, UNIT_TRIGGERS
, p
, NULL
, true, UNIT_DEPENDENCY_FILE
);
1680 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add trigger on %s, ignoring: %m", p
);
1687 int config_parse_path_spec(const char *unit
,
1688 const char *filename
,
1690 const char *section
,
1691 unsigned section_line
,
1701 _cleanup_free_
char *k
= NULL
;
1709 if (isempty(rvalue
)) {
1710 /* Empty assignment clears list */
1715 b
= path_type_from_string(lvalue
);
1717 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse path type, ignoring: %s", lvalue
);
1721 r
= unit_full_printf(UNIT(p
), rvalue
, &k
);
1723 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
1727 path_kill_slashes(k
);
1729 if (!path_is_absolute(k
)) {
1730 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Path is not absolute, ignoring: %s", k
);
1734 s
= new0(PathSpec
, 1);
1739 s
->path
= TAKE_PTR(k
);
1743 LIST_PREPEND(spec
, p
->specs
, s
);
1748 int config_parse_socket_service(
1750 const char *filename
,
1752 const char *section
,
1753 unsigned section_line
,
1760 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1761 _cleanup_free_
char *p
= NULL
;
1771 r
= unit_name_printf(UNIT(s
), rvalue
, &p
);
1773 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", rvalue
);
1777 if (!endswith(p
, ".service")) {
1778 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit must be of type service: %s", rvalue
);
1782 r
= manager_load_unit(UNIT(s
)->manager
, p
, NULL
, &error
, &x
);
1784 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to load unit %s: %s", rvalue
, bus_error_message(&error
, r
));
1788 unit_ref_set(&s
->service
, UNIT(s
), x
);
1793 int config_parse_fdname(
1795 const char *filename
,
1797 const char *section
,
1798 unsigned section_line
,
1805 _cleanup_free_
char *p
= NULL
;
1814 if (isempty(rvalue
)) {
1815 s
->fdname
= mfree(s
->fdname
);
1819 r
= unit_full_printf(UNIT(s
), rvalue
, &p
);
1821 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
1825 if (!fdname_is_valid(p
)) {
1826 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", p
);
1830 return free_and_replace(s
->fdname
, p
);
1833 int config_parse_service_sockets(
1835 const char *filename
,
1837 const char *section
,
1838 unsigned section_line
,
1856 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
1858 r
= extract_first_word(&p
, &word
, NULL
, 0);
1864 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Trailing garbage in sockets, ignoring: %s", rvalue
);
1868 r
= unit_name_printf(UNIT(s
), word
, &k
);
1870 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
1874 if (!endswith(k
, ".socket")) {
1875 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit must be of type socket, ignoring: %s", k
);
1879 r
= unit_add_two_dependencies_by_name(UNIT(s
), UNIT_WANTS
, UNIT_AFTER
, k
, NULL
, true, UNIT_DEPENDENCY_FILE
);
1881 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
1883 r
= unit_add_dependency_by_name(UNIT(s
), UNIT_TRIGGERED_BY
, k
, NULL
, true, UNIT_DEPENDENCY_FILE
);
1885 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
1891 int config_parse_bus_name(
1893 const char *filename
,
1895 const char *section
,
1896 unsigned section_line
,
1903 _cleanup_free_
char *k
= NULL
;
1912 r
= unit_full_printf(u
, rvalue
, &k
);
1914 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
1918 if (!service_name_is_valid(k
)) {
1919 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid bus name, ignoring: %s", k
);
1923 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
1926 int config_parse_service_timeout(
1928 const char *filename
,
1930 const char *section
,
1931 unsigned section_line
,
1938 Service
*s
= userdata
;
1947 /* This is called for two cases: TimeoutSec= and TimeoutStartSec=. */
1949 r
= parse_sec(rvalue
, &usec
);
1951 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
1955 /* Traditionally, these options accepted 0 to disable the timeouts. However, a timeout of 0 suggests it happens
1956 * immediately, hence fix this to become USEC_INFINITY instead. This is in-line with how we internally handle
1957 * all other timeouts. */
1959 usec
= USEC_INFINITY
;
1962 s
->start_timeout_defined
= true;
1963 s
->timeout_start_usec
= usec
;
1965 if (streq(lvalue
, "TimeoutSec"))
1966 s
->timeout_stop_usec
= usec
;
1971 int config_parse_sec_fix_0(
1973 const char *filename
,
1975 const char *section
,
1976 unsigned section_line
,
1983 usec_t
*usec
= data
;
1991 /* This is pretty much like config_parse_sec(), except that this treats a time of 0 as infinity, for
1992 * compatibility with older versions of systemd where 0 instead of infinity was used as indicator to turn off a
1995 r
= parse_sec_fix_0(rvalue
, usec
);
1997 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
2004 int config_parse_user_group(
2006 const char *filename
,
2008 const char *section
,
2009 unsigned section_line
,
2016 _cleanup_free_
char *k
= NULL
;
2026 if (isempty(rvalue
)) {
2027 *user
= mfree(*user
);
2031 r
= unit_full_printf(u
, rvalue
, &k
);
2033 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", rvalue
);
2037 if (!valid_user_group_name_or_id(k
)) {
2038 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2042 return free_and_replace(*user
, k
);
2045 int config_parse_user_group_strv(
2047 const char *filename
,
2049 const char *section
,
2050 unsigned section_line
,
2057 char ***users
= data
;
2059 const char *p
= rvalue
;
2067 if (isempty(rvalue
)) {
2068 *users
= strv_free(*users
);
2073 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2075 r
= extract_first_word(&p
, &word
, NULL
, 0);
2081 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax: %s", rvalue
);
2085 r
= unit_full_printf(u
, word
, &k
);
2087 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", word
);
2091 if (!valid_user_group_name_or_id(k
)) {
2092 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2096 r
= strv_push(users
, k
);
2106 int config_parse_working_directory(
2108 const char *filename
,
2110 const char *section
,
2111 unsigned section_line
,
2118 ExecContext
*c
= data
;
2129 if (rvalue
[0] == '-') {
2135 if (streq(rvalue
, "~")) {
2136 c
->working_directory_home
= true;
2137 c
->working_directory
= mfree(c
->working_directory
);
2139 _cleanup_free_
char *k
= NULL
;
2141 r
= unit_full_printf(u
, rvalue
, &k
);
2143 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2144 "Failed to resolve unit specifiers in working directory path '%s'%s: %m",
2145 rvalue
, missing_ok
? ", ignoring" : "");
2146 return missing_ok
? 0 : -ENOEXEC
;
2149 path_kill_slashes(k
);
2151 if (!utf8_is_valid(k
)) {
2152 log_syntax_invalid_utf8(unit
, LOG_ERR
, filename
, line
, rvalue
);
2153 return missing_ok
? 0 : -ENOEXEC
;
2156 if (!path_is_absolute(k
)) {
2157 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2158 "Working directory path '%s' is not absolute%s.",
2159 rvalue
, missing_ok
? ", ignoring" : "");
2160 return missing_ok
? 0 : -ENOEXEC
;
2163 c
->working_directory_home
= false;
2164 free_and_replace(c
->working_directory
, k
);
2167 c
->working_directory_missing_ok
= missing_ok
;
2171 int config_parse_unit_env_file(const char *unit
,
2172 const char *filename
,
2174 const char *section
,
2175 unsigned section_line
,
2184 _cleanup_free_
char *n
= NULL
;
2192 if (isempty(rvalue
)) {
2193 /* Empty assignment frees the list */
2194 *env
= strv_free(*env
);
2198 r
= unit_full_printf(u
, rvalue
, &n
);
2200 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2204 if (!path_is_absolute(n
[0] == '-' ? n
+ 1 : n
)) {
2205 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Path '%s' is not absolute, ignoring.", n
);
2209 r
= strv_extend(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_QUOTES
);
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_QUOTES
);
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_QUOTES
);
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_QUOTES
);
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_ip_tos(const char *unit
,
2505 const char *filename
,
2507 const char *section
,
2508 unsigned section_line
,
2515 int *ip_tos
= data
, x
;
2522 x
= ip_tos_from_string(rvalue
);
2524 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse IP TOS value, ignoring: %s", rvalue
);
2532 int config_parse_unit_condition_path(
2534 const char *filename
,
2536 const char *section
,
2537 unsigned section_line
,
2544 _cleanup_free_
char *p
= NULL
;
2545 Condition
**list
= data
, *c
;
2546 ConditionType t
= ltype
;
2547 bool trigger
, negate
;
2556 if (isempty(rvalue
)) {
2557 /* Empty assignment resets the list */
2558 *list
= condition_free_list(*list
);
2562 trigger
= rvalue
[0] == '|';
2566 negate
= rvalue
[0] == '!';
2570 r
= unit_full_printf(u
, rvalue
, &p
);
2572 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2576 if (!path_is_absolute(p
)) {
2577 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Path in condition not absolute, ignoring: %s", p
);
2581 c
= condition_new(t
, p
, trigger
, negate
);
2585 LIST_PREPEND(conditions
, *list
, c
);
2589 int config_parse_unit_condition_string(
2591 const char *filename
,
2593 const char *section
,
2594 unsigned section_line
,
2601 _cleanup_free_
char *s
= NULL
;
2602 Condition
**list
= data
, *c
;
2603 ConditionType t
= ltype
;
2604 bool trigger
, negate
;
2613 if (isempty(rvalue
)) {
2614 /* Empty assignment resets the list */
2615 *list
= condition_free_list(*list
);
2619 trigger
= rvalue
[0] == '|';
2623 negate
= rvalue
[0] == '!';
2627 r
= unit_full_printf(u
, rvalue
, &s
);
2629 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2633 c
= condition_new(t
, s
, trigger
, negate
);
2637 LIST_PREPEND(conditions
, *list
, c
);
2641 int config_parse_unit_condition_null(
2643 const char *filename
,
2645 const char *section
,
2646 unsigned section_line
,
2653 Condition
**list
= data
, *c
;
2654 bool trigger
, negate
;
2662 if (isempty(rvalue
)) {
2663 /* Empty assignment resets the list */
2664 *list
= condition_free_list(*list
);
2668 trigger
= rvalue
[0] == '|';
2672 negate
= rvalue
[0] == '!';
2676 b
= parse_boolean(rvalue
);
2678 log_syntax(unit
, LOG_ERR
, filename
, line
, b
, "Failed to parse boolean value in condition, ignoring: %s", rvalue
);
2685 c
= condition_new(CONDITION_NULL
, NULL
, trigger
, negate
);
2689 LIST_PREPEND(conditions
, *list
, c
);
2693 DEFINE_CONFIG_PARSE_ENUM(config_parse_notify_access
, notify_access
, NotifyAccess
, "Failed to parse notify access specifier");
2694 DEFINE_CONFIG_PARSE_ENUM(config_parse_emergency_action
, emergency_action
, EmergencyAction
, "Failed to parse failure action specifier");
2696 int config_parse_unit_requires_mounts_for(
2698 const char *filename
,
2700 const char *section
,
2701 unsigned section_line
,
2708 const char *p
= rvalue
;
2718 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
2720 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
2726 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2727 "Invalid syntax, ignoring: %s", rvalue
);
2731 if (!utf8_is_valid(word
)) {
2732 log_syntax_invalid_utf8(unit
, LOG_ERR
, filename
, line
, rvalue
);
2736 r
= unit_full_printf(u
, word
, &resolved
);
2738 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
2742 r
= unit_require_mounts_for(u
, resolved
, UNIT_DEPENDENCY_FILE
);
2744 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add required mount '%s', ignoring: %m", resolved
);
2750 int config_parse_documentation(const char *unit
,
2751 const char *filename
,
2753 const char *section
,
2754 unsigned section_line
,
2770 if (isempty(rvalue
)) {
2771 /* Empty assignment resets the list */
2772 u
->documentation
= strv_free(u
->documentation
);
2776 r
= config_parse_unit_strv_printf(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
,
2777 rvalue
, data
, userdata
);
2781 for (a
= b
= u
->documentation
; a
&& *a
; a
++) {
2783 if (documentation_url_is_valid(*a
))
2786 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid URL, ignoring: %s", *a
);
2797 int config_parse_syscall_filter(
2799 const char *filename
,
2801 const char *section
,
2802 unsigned section_line
,
2809 ExecContext
*c
= data
;
2811 bool invert
= false;
2820 if (isempty(rvalue
)) {
2821 /* Empty assignment resets the list */
2822 c
->syscall_filter
= hashmap_free(c
->syscall_filter
);
2823 c
->syscall_whitelist
= false;
2827 if (rvalue
[0] == '~') {
2832 if (!c
->syscall_filter
) {
2833 c
->syscall_filter
= hashmap_new(NULL
);
2834 if (!c
->syscall_filter
)
2838 /* Allow everything but the ones listed */
2839 c
->syscall_whitelist
= false;
2841 /* Allow nothing but the ones listed */
2842 c
->syscall_whitelist
= true;
2844 /* Accept default syscalls if we are on a whitelist */
2845 r
= seccomp_parse_syscall_filter("@default", -1, c
->syscall_filter
, SECCOMP_PARSE_WHITELIST
);
2853 _cleanup_free_
char *word
= NULL
, *name
= NULL
;
2856 r
= extract_first_word(&p
, &word
, NULL
, 0);
2862 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
2866 r
= parse_syscall_and_errno(word
, &name
, &num
);
2868 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse syscall:errno, ignoring: %s", word
);
2872 r
= seccomp_parse_syscall_filter_full(name
, num
, c
->syscall_filter
,
2873 SECCOMP_PARSE_LOG
|SECCOMP_PARSE_PERMISSIVE
|(invert
? SECCOMP_PARSE_INVERT
: 0)|(c
->syscall_whitelist
? SECCOMP_PARSE_WHITELIST
: 0),
2874 unit
, filename
, line
);
2880 int config_parse_syscall_archs(
2882 const char *filename
,
2884 const char *section
,
2885 unsigned section_line
,
2892 const char *p
= rvalue
;
2896 if (isempty(rvalue
)) {
2897 *archs
= set_free(*archs
);
2901 r
= set_ensure_allocated(archs
, NULL
);
2906 _cleanup_free_
char *word
= NULL
;
2909 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
2915 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2916 "Invalid syntax, ignoring: %s", rvalue
);
2920 r
= seccomp_arch_from_string(word
, &a
);
2922 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2923 "Failed to parse system call architecture \"%s\", ignoring: %m", word
);
2927 r
= set_put(*archs
, UINT32_TO_PTR(a
+ 1));
2933 int config_parse_syscall_errno(
2935 const char *filename
,
2937 const char *section
,
2938 unsigned section_line
,
2945 ExecContext
*c
= data
;
2952 if (isempty(rvalue
)) {
2953 /* Empty assignment resets to KILL */
2954 c
->syscall_errno
= 0;
2958 e
= parse_errno(rvalue
);
2960 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse error number, ignoring: %s", rvalue
);
2964 c
->syscall_errno
= e
;
2968 int config_parse_address_families(
2970 const char *filename
,
2972 const char *section
,
2973 unsigned section_line
,
2980 ExecContext
*c
= data
;
2981 bool invert
= false;
2989 if (isempty(rvalue
)) {
2990 /* Empty assignment resets the list */
2991 c
->address_families
= set_free(c
->address_families
);
2992 c
->address_families_whitelist
= false;
2996 if (rvalue
[0] == '~') {
3001 if (!c
->address_families
) {
3002 c
->address_families
= set_new(NULL
);
3003 if (!c
->address_families
)
3006 c
->address_families_whitelist
= !invert
;
3009 for (p
= rvalue
;;) {
3010 _cleanup_free_
char *word
= NULL
;
3013 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
3019 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3020 "Invalid syntax, ignoring: %s", rvalue
);
3024 af
= af_from_name(word
);
3026 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
3027 "Failed to parse address family, ignoring: %s", word
);
3031 /* If we previously wanted to forbid an address family and now
3032 * we want to allow it, then just remove it from the list.
3034 if (!invert
== c
->address_families_whitelist
) {
3035 r
= set_put(c
->address_families
, INT_TO_PTR(af
));
3039 set_remove(c
->address_families
, INT_TO_PTR(af
));
3043 int config_parse_restrict_namespaces(
3045 const char *filename
,
3047 const char *section
,
3048 unsigned section_line
,
3055 ExecContext
*c
= data
;
3056 unsigned long flags
;
3057 bool invert
= false;
3060 if (isempty(rvalue
)) {
3061 /* Reset to the default. */
3062 c
->restrict_namespaces
= NAMESPACE_FLAGS_INITIAL
;
3066 /* Boolean parameter ignores the previous settings */
3067 r
= parse_boolean(rvalue
);
3069 c
->restrict_namespaces
= 0;
3071 } else if (r
== 0) {
3072 c
->restrict_namespaces
= NAMESPACE_FLAGS_ALL
;
3076 if (rvalue
[0] == '~') {
3081 /* Not a boolean argument, in this case it's a list of namespace types. */
3082 r
= namespace_flags_from_string(rvalue
, &flags
);
3084 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse namespace type string, ignoring: %s", rvalue
);
3088 if (c
->restrict_namespaces
== NAMESPACE_FLAGS_INITIAL
)
3089 /* Initial assignment. Just set the value. */
3090 c
->restrict_namespaces
= invert
? (~flags
) & NAMESPACE_FLAGS_ALL
: flags
;
3092 /* Merge the value with the previous one. */
3093 SET_FLAG(c
->restrict_namespaces
, flags
, !invert
);
3099 int config_parse_unit_slice(
3101 const char *filename
,
3103 const char *section
,
3104 unsigned section_line
,
3111 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
3112 _cleanup_free_
char *k
= NULL
;
3113 Unit
*u
= userdata
, *slice
= NULL
;
3121 r
= unit_name_printf(u
, rvalue
, &k
);
3123 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
3127 r
= manager_load_unit(u
->manager
, k
, NULL
, &error
, &slice
);
3129 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to load slice unit %s, ignoring: %s", k
, bus_error_message(&error
, r
));
3133 r
= unit_set_slice(u
, slice
);
3135 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to assign slice %s to unit %s, ignoring: %m", slice
->id
, u
->id
);
3142 DEFINE_CONFIG_PARSE_ENUM(config_parse_device_policy
, cgroup_device_policy
, CGroupDevicePolicy
, "Failed to parse device policy");
3144 int config_parse_cpu_weight(
3146 const char *filename
,
3148 const char *section
,
3149 unsigned section_line
,
3156 uint64_t *weight
= data
;
3163 r
= cg_weight_parse(rvalue
, weight
);
3165 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid CPU weight '%s', ignoring: %m", rvalue
);
3172 int config_parse_cpu_shares(
3174 const char *filename
,
3176 const char *section
,
3177 unsigned section_line
,
3184 uint64_t *shares
= data
;
3191 r
= cg_cpu_shares_parse(rvalue
, shares
);
3193 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid CPU shares '%s', ignoring: %m", rvalue
);
3200 int config_parse_cpu_quota(
3202 const char *filename
,
3204 const char *section
,
3205 unsigned section_line
,
3212 CGroupContext
*c
= data
;
3219 if (isempty(rvalue
)) {
3220 c
->cpu_quota_per_sec_usec
= USEC_INFINITY
;
3224 r
= parse_percent_unbounded(rvalue
);
3226 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid CPU quota '%s', ignoring.", rvalue
);
3230 c
->cpu_quota_per_sec_usec
= ((usec_t
) r
* USEC_PER_SEC
) / 100U;
3234 int config_parse_memory_limit(
3236 const char *filename
,
3238 const char *section
,
3239 unsigned section_line
,
3246 CGroupContext
*c
= data
;
3247 uint64_t bytes
= CGROUP_LIMIT_MAX
;
3250 if (!isempty(rvalue
) && !streq(rvalue
, "infinity")) {
3252 r
= parse_percent(rvalue
);
3254 r
= parse_size(rvalue
, 1024, &bytes
);
3256 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid memory limit '%s', ignoring: %m", rvalue
);
3260 bytes
= physical_memory_scale(r
, 100U);
3262 if (bytes
>= UINT64_MAX
||
3263 (bytes
<= 0 && !streq(lvalue
, "MemorySwapMax"))) {
3264 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Memory limit '%s' out of range, ignoring.", rvalue
);
3269 if (streq(lvalue
, "MemoryLow"))
3270 c
->memory_low
= bytes
;
3271 else if (streq(lvalue
, "MemoryHigh"))
3272 c
->memory_high
= bytes
;
3273 else if (streq(lvalue
, "MemoryMax"))
3274 c
->memory_max
= bytes
;
3275 else if (streq(lvalue
, "MemorySwapMax"))
3276 c
->memory_swap_max
= bytes
;
3277 else if (streq(lvalue
, "MemoryLimit"))
3278 c
->memory_limit
= bytes
;
3285 int config_parse_tasks_max(
3287 const char *filename
,
3289 const char *section
,
3290 unsigned section_line
,
3297 uint64_t *tasks_max
= data
, v
;
3301 if (isempty(rvalue
)) {
3302 *tasks_max
= u
->manager
->default_tasks_max
;
3306 if (streq(rvalue
, "infinity")) {
3307 *tasks_max
= CGROUP_LIMIT_MAX
;
3311 r
= parse_percent(rvalue
);
3313 r
= safe_atou64(rvalue
, &v
);
3315 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid maximum tasks value '%s', ignoring: %m", rvalue
);
3319 v
= system_tasks_max_scale(r
, 100U);
3321 if (v
<= 0 || v
>= UINT64_MAX
) {
3322 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Maximum tasks value '%s' out of range, ignoring.", rvalue
);
3330 int config_parse_delegate(
3332 const char *filename
,
3334 const char *section
,
3335 unsigned section_line
,
3342 CGroupContext
*c
= data
;
3346 t
= unit_name_to_type(unit
);
3347 assert(t
!= _UNIT_TYPE_INVALID
);
3349 if (!unit_vtable
[t
]->can_delegate
) {
3350 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Delegate= setting not supported for this unit type, ignoring.");
3354 /* We either accept a boolean value, which may be used to turn on delegation for all controllers, or turn it
3355 * off for all. Or it takes a list of controller names, in which case we add the specified controllers to the
3356 * mask to delegate. */
3358 if (isempty(rvalue
)) {
3359 /* An empty string resets controllers and set Delegate=yes. */
3361 c
->delegate_controllers
= 0;
3365 r
= parse_boolean(rvalue
);
3367 const char *p
= rvalue
;
3368 CGroupMask mask
= 0;
3371 _cleanup_free_
char *word
= NULL
;
3372 CGroupController cc
;
3374 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
3380 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3384 cc
= cgroup_controller_from_string(word
);
3386 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid controller name '%s', ignoring", word
);
3390 mask
|= CGROUP_CONTROLLER_TO_MASK(cc
);
3394 c
->delegate_controllers
|= mask
;
3398 c
->delegate_controllers
= _CGROUP_MASK_ALL
;
3400 c
->delegate
= false;
3401 c
->delegate_controllers
= 0;
3407 int config_parse_device_allow(
3409 const char *filename
,
3411 const char *section
,
3412 unsigned section_line
,
3419 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3420 CGroupContext
*c
= data
;
3421 CGroupDeviceAllow
*a
;
3422 const char *p
= rvalue
;
3425 if (isempty(rvalue
)) {
3426 while (c
->device_allow
)
3427 cgroup_context_free_device_allow(c
, c
->device_allow
);
3432 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_QUOTES
);
3436 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3437 "Invalid syntax, ignoring: %s", rvalue
);
3441 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3442 "Failed to extract device path and rights from '%s', ignoring.", rvalue
);
3446 r
= unit_full_printf(userdata
, path
, &resolved
);
3448 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3449 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3453 if (!is_deviceallow_pattern(resolved
) &&
3454 !path_startswith(resolved
, "/run/systemd/inaccessible/")) {
3455 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device node path '%s', ignoring.", resolved
);
3459 if (!isempty(p
) && !in_charset(p
, "rwm")) {
3460 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device rights '%s', ignoring.", p
);
3464 a
= new0(CGroupDeviceAllow
, 1);
3468 a
->path
= TAKE_PTR(resolved
);
3469 a
->r
= isempty(p
) || !!strchr(p
, 'r');
3470 a
->w
= isempty(p
) || !!strchr(p
, 'w');
3471 a
->m
= isempty(p
) || !!strchr(p
, 'm');
3473 LIST_PREPEND(device_allow
, c
->device_allow
, a
);
3477 int config_parse_io_weight(
3479 const char *filename
,
3481 const char *section
,
3482 unsigned section_line
,
3489 uint64_t *weight
= data
;
3496 r
= cg_weight_parse(rvalue
, weight
);
3498 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid IO weight '%s', ignoring.", rvalue
);
3505 int config_parse_io_device_weight(
3507 const char *filename
,
3509 const char *section
,
3510 unsigned section_line
,
3517 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3518 CGroupIODeviceWeight
*w
;
3519 CGroupContext
*c
= data
;
3520 const char *p
= rvalue
;
3528 if (isempty(rvalue
)) {
3529 while (c
->io_device_weights
)
3530 cgroup_context_free_io_device_weight(c
, c
->io_device_weights
);
3535 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_QUOTES
);
3539 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3540 "Invalid syntax, ignoring: %s", rvalue
);
3543 if (r
== 0 || isempty(p
)) {
3544 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3545 "Failed to extract device path and weight from '%s', ignoring.", rvalue
);
3549 r
= unit_full_printf(userdata
, path
, &resolved
);
3551 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3552 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3556 if (!path_startswith(resolved
, "/dev") &&
3557 !path_startswith(resolved
, "/run/systemd/inaccessible/")) {
3558 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device node path '%s', ignoring.", resolved
);
3562 r
= cg_weight_parse(p
, &u
);
3564 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "IO weight '%s' invalid, ignoring: %m", p
);
3568 assert(u
!= CGROUP_WEIGHT_INVALID
);
3570 w
= new0(CGroupIODeviceWeight
, 1);
3574 w
->path
= TAKE_PTR(resolved
);
3577 LIST_PREPEND(device_weights
, c
->io_device_weights
, w
);
3581 int config_parse_io_limit(
3583 const char *filename
,
3585 const char *section
,
3586 unsigned section_line
,
3593 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3594 CGroupIODeviceLimit
*l
= NULL
, *t
;
3595 CGroupContext
*c
= data
;
3596 CGroupIOLimitType type
;
3597 const char *p
= rvalue
;
3605 type
= cgroup_io_limit_type_from_string(lvalue
);
3608 if (isempty(rvalue
)) {
3609 LIST_FOREACH(device_limits
, l
, c
->io_device_limits
)
3610 l
->limits
[type
] = cgroup_io_limit_defaults
[type
];
3614 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_QUOTES
);
3618 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3619 "Invalid syntax, ignoring: %s", rvalue
);
3622 if (r
== 0 || isempty(p
)) {
3623 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3624 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
3628 r
= unit_full_printf(userdata
, path
, &resolved
);
3630 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3631 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3635 if (!path_startswith(resolved
, "/dev") &&
3636 !path_startswith(resolved
, "/run/systemd/inaccessible/")) {
3637 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device node path '%s', ignoring.", resolved
);
3641 if (streq("infinity", p
)) {
3642 num
= CGROUP_LIMIT_MAX
;
3644 r
= parse_size(p
, 1000, &num
);
3645 if (r
< 0 || num
<= 0) {
3646 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid IO limit '%s', ignoring.", p
);
3651 LIST_FOREACH(device_limits
, t
, c
->io_device_limits
) {
3652 if (path_equal(resolved
, t
->path
)) {
3659 CGroupIOLimitType ttype
;
3661 l
= new0(CGroupIODeviceLimit
, 1);
3665 l
->path
= TAKE_PTR(resolved
);
3666 for (ttype
= 0; ttype
< _CGROUP_IO_LIMIT_TYPE_MAX
; ttype
++)
3667 l
->limits
[ttype
] = cgroup_io_limit_defaults
[ttype
];
3669 LIST_PREPEND(device_limits
, c
->io_device_limits
, l
);
3672 l
->limits
[type
] = num
;
3677 int config_parse_blockio_weight(
3679 const char *filename
,
3681 const char *section
,
3682 unsigned section_line
,
3689 uint64_t *weight
= data
;
3696 r
= cg_blkio_weight_parse(rvalue
, weight
);
3698 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid block IO weight '%s', ignoring: %m", rvalue
);
3705 int config_parse_blockio_device_weight(
3707 const char *filename
,
3709 const char *section
,
3710 unsigned section_line
,
3717 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3718 CGroupBlockIODeviceWeight
*w
;
3719 CGroupContext
*c
= data
;
3720 const char *p
= rvalue
;
3728 if (isempty(rvalue
)) {
3729 while (c
->blockio_device_weights
)
3730 cgroup_context_free_blockio_device_weight(c
, c
->blockio_device_weights
);
3735 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_QUOTES
);
3739 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3740 "Invalid syntax, ignoring: %s", rvalue
);
3743 if (r
== 0 || isempty(p
)) {
3744 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3745 "Failed to extract device node and weight from '%s', ignoring.", rvalue
);
3749 r
= unit_full_printf(userdata
, path
, &resolved
);
3751 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3752 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3756 if (!path_startswith(resolved
, "/dev") &&
3757 !path_startswith(resolved
, "/run/systemd/inaccessible/")) {
3758 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device node path '%s'. Ignoring.", resolved
);
3762 r
= cg_blkio_weight_parse(p
, &u
);
3764 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid block IO weight '%s', ignoring: %m", p
);
3768 assert(u
!= CGROUP_BLKIO_WEIGHT_INVALID
);
3770 w
= new0(CGroupBlockIODeviceWeight
, 1);
3774 w
->path
= TAKE_PTR(resolved
);
3777 LIST_PREPEND(device_weights
, c
->blockio_device_weights
, w
);
3781 int config_parse_blockio_bandwidth(
3783 const char *filename
,
3785 const char *section
,
3786 unsigned section_line
,
3793 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3794 CGroupBlockIODeviceBandwidth
*b
= NULL
, *t
;
3795 CGroupContext
*c
= data
;
3796 const char *p
= rvalue
;
3805 read
= streq("BlockIOReadBandwidth", lvalue
);
3807 if (isempty(rvalue
)) {
3808 LIST_FOREACH(device_bandwidths
, b
, c
->blockio_device_bandwidths
) {
3809 b
->rbps
= CGROUP_LIMIT_MAX
;
3810 b
->wbps
= CGROUP_LIMIT_MAX
;
3815 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_QUOTES
);
3819 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3820 "Invalid syntax, ignoring: %s", rvalue
);
3823 if (r
== 0 || isempty(p
)) {
3824 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3825 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
3829 r
= unit_full_printf(userdata
, path
, &resolved
);
3831 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3832 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3836 if (!path_startswith(resolved
, "/dev") &&
3837 !path_startswith(resolved
, "/run/systemd/inaccessible/")) {
3838 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device node path '%s', ignoring.", resolved
);
3842 r
= parse_size(p
, 1000, &bytes
);
3843 if (r
< 0 || bytes
<= 0) {
3844 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid Block IO Bandwidth '%s', ignoring.", p
);
3848 LIST_FOREACH(device_bandwidths
, t
, c
->blockio_device_bandwidths
) {
3849 if (path_equal(resolved
, t
->path
)) {
3856 b
= new0(CGroupBlockIODeviceBandwidth
, 1);
3860 b
->path
= TAKE_PTR(resolved
);
3861 b
->rbps
= CGROUP_LIMIT_MAX
;
3862 b
->wbps
= CGROUP_LIMIT_MAX
;
3864 LIST_PREPEND(device_bandwidths
, c
->blockio_device_bandwidths
, b
);
3875 DEFINE_CONFIG_PARSE_ENUM(config_parse_job_mode
, job_mode
, JobMode
, "Failed to parse job mode");
3877 int config_parse_job_mode_isolate(
3879 const char *filename
,
3881 const char *section
,
3882 unsigned section_line
,
3896 r
= parse_boolean(rvalue
);
3898 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse boolean, ignoring: %s", rvalue
);
3902 log_notice("%s is deprecated. Please use OnFailureJobMode= instead", lvalue
);
3904 *m
= r
? JOB_ISOLATE
: JOB_REPLACE
;
3908 DEFINE_CONFIG_PARSE_ENUM(config_parse_runtime_preserve_mode
, exec_preserve_mode
, ExecPreserveMode
, "Failed to parse runtime directory preserve mode");
3910 int config_parse_exec_directories(
3912 const char *filename
,
3914 const char *section
,
3915 unsigned section_line
,
3932 if (isempty(rvalue
)) {
3933 /* Empty assignment resets the list */
3934 *rt
= strv_free(*rt
);
3938 for (p
= rvalue
;;) {
3939 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
3941 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
3945 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3946 "Invalid syntax, ignoring: %s", rvalue
);
3952 r
= unit_full_printf(u
, word
, &k
);
3954 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
3955 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
3959 if (!path_is_normalized(k
)) {
3960 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
3961 "%s= path is not normalized, ignoring assignment: %s", lvalue
, rvalue
);
3965 if (path_is_absolute(k
)) {
3966 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
3967 "%s= path is absolute, ignoring assignment: %s", lvalue
, rvalue
);
3971 if (path_startswith(k
, "private")) {
3972 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
3973 "%s= path can't be 'private', ingoring assignment: %s", lvalue
, rvalue
);
3977 r
= strv_push(rt
, k
);
3984 int config_parse_set_status(
3986 const char *filename
,
3988 const char *section
,
3989 unsigned section_line
,
3997 const char *word
, *state
;
3999 ExitStatusSet
*status_set
= data
;
4006 /* Empty assignment resets the list */
4007 if (isempty(rvalue
)) {
4008 exit_status_set_free(status_set
);
4012 FOREACH_WORD(word
, l
, rvalue
, state
) {
4013 _cleanup_free_
char *temp
;
4017 temp
= strndup(word
, l
);
4021 r
= safe_atoi(temp
, &val
);
4023 val
= signal_from_string(temp
);
4026 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse value, ignoring: %s", word
);
4029 set
= &status_set
->signal
;
4031 if (val
< 0 || val
> 255) {
4032 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Value %d is outside range 0-255, ignoring", val
);
4035 set
= &status_set
->status
;
4038 r
= set_ensure_allocated(set
, NULL
);
4042 r
= set_put(*set
, INT_TO_PTR(val
));
4046 if (!isempty(state
))
4047 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Trailing garbage, ignoring.");
4052 int config_parse_namespace_path_strv(
4054 const char *filename
,
4056 const char *section
,
4057 unsigned section_line
,
4066 const char *p
= rvalue
;
4074 if (isempty(rvalue
)) {
4075 /* Empty assignment resets the list */
4076 *sv
= strv_free(*sv
);
4081 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
, *joined
= NULL
;
4083 bool ignore_enoent
= false, shall_prefix
= false;
4085 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
4091 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
4095 if (!utf8_is_valid(word
)) {
4096 log_syntax_invalid_utf8(unit
, LOG_ERR
, filename
, line
, word
);
4101 if (startswith(w
, "-")) {
4102 ignore_enoent
= true;
4105 if (startswith(w
, "+")) {
4106 shall_prefix
= true;
4110 r
= unit_full_printf(u
, w
, &resolved
);
4112 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", w
);
4116 if (!path_is_absolute(resolved
)) {
4117 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Not an absolute path, ignoring: %s", resolved
);
4121 path_kill_slashes(resolved
);
4123 joined
= strjoin(ignore_enoent
? "-" : "",
4124 shall_prefix
? "+" : "",
4127 r
= strv_push(sv
, joined
);
4137 int config_parse_temporary_filesystems(
4139 const char *filename
,
4141 const char *section
,
4142 unsigned section_line
,
4150 ExecContext
*c
= data
;
4151 const char *p
= rvalue
;
4159 if (isempty(rvalue
)) {
4160 /* Empty assignment resets the list */
4161 temporary_filesystem_free_many(c
->temporary_filesystems
, c
->n_temporary_filesystems
);
4162 c
->temporary_filesystems
= NULL
;
4163 c
->n_temporary_filesystems
= 0;
4168 _cleanup_free_
char *word
= NULL
, *path
= NULL
, *resolved
= NULL
;
4171 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
4177 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
4182 r
= extract_first_word(&w
, &path
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4186 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", word
);
4190 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid syntax, ignoring: %s", word
);
4194 r
= unit_full_printf(u
, path
, &resolved
);
4196 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", path
);
4200 if (!path_is_absolute(resolved
)) {
4201 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Not an absolute path, ignoring: %s", resolved
);
4205 path_kill_slashes(resolved
);
4207 r
= temporary_filesystem_add(&c
->temporary_filesystems
, &c
->n_temporary_filesystems
, path
, w
);
4211 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse mount options, ignoring: %s", word
);
4217 int config_parse_bind_paths(
4219 const char *filename
,
4221 const char *section
,
4222 unsigned section_line
,
4229 ExecContext
*c
= data
;
4239 if (isempty(rvalue
)) {
4240 /* Empty assignment resets the list */
4241 bind_mount_free_many(c
->bind_mounts
, c
->n_bind_mounts
);
4242 c
->bind_mounts
= NULL
;
4243 c
->n_bind_mounts
= 0;
4249 _cleanup_free_
char *source
= NULL
, *destination
= NULL
;
4250 _cleanup_free_
char *sresolved
= NULL
, *dresolved
= NULL
;
4251 char *s
= NULL
, *d
= NULL
;
4252 bool rbind
= true, ignore_enoent
= false;
4254 r
= extract_first_word(&p
, &source
, ":" WHITESPACE
, EXTRACT_QUOTES
|EXTRACT_DONT_COALESCE_SEPARATORS
);
4260 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s: %s", lvalue
, rvalue
);
4264 r
= unit_full_printf(u
, source
, &sresolved
);
4266 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4267 "Failed to resolved unit specifiers in \"%s\", ignoring: %m", source
);
4273 ignore_enoent
= true;
4277 if (!utf8_is_valid(s
)) {
4278 log_syntax_invalid_utf8(unit
, LOG_ERR
, filename
, line
, s
);
4281 if (!path_is_absolute(s
)) {
4282 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Not an absolute source path, ignoring: %s", s
);
4286 path_kill_slashes(s
);
4288 /* Optionally, the destination is specified. */
4289 if (p
&& p
[-1] == ':') {
4290 r
= extract_first_word(&p
, &destination
, ":" WHITESPACE
, EXTRACT_QUOTES
|EXTRACT_DONT_COALESCE_SEPARATORS
);
4294 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s: %s", lvalue
, rvalue
);
4298 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Missing argument after ':': %s", rvalue
);
4302 r
= unit_full_printf(u
, destination
, &dresolved
);
4304 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4305 "Failed to resolved specifiers in \"%s\", ignoring: %m", destination
);
4309 if (!utf8_is_valid(dresolved
)) {
4310 log_syntax_invalid_utf8(unit
, LOG_ERR
, filename
, line
, dresolved
);
4313 if (!path_is_absolute(dresolved
)) {
4314 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Not an absolute destination path, ignoring: %s", dresolved
);
4318 d
= path_kill_slashes(dresolved
);
4320 /* Optionally, there's also a short option string specified */
4321 if (p
&& p
[-1] == ':') {
4322 _cleanup_free_
char *options
= NULL
;
4324 r
= extract_first_word(&p
, &options
, NULL
, EXTRACT_QUOTES
);
4328 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s: %s", lvalue
, rvalue
);
4332 if (isempty(options
) || streq(options
, "rbind"))
4334 else if (streq(options
, "norbind"))
4337 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid option string, ignoring setting: %s", options
);
4344 r
= bind_mount_add(&c
->bind_mounts
, &c
->n_bind_mounts
,
4348 .read_only
= !!strstr(lvalue
, "ReadOnly"),
4350 .ignore_enoent
= ignore_enoent
,
4359 int config_parse_no_new_privileges(
4361 const char *filename
,
4363 const char *section
,
4364 unsigned section_line
,
4371 ExecContext
*c
= data
;
4379 r
= parse_boolean(rvalue
);
4381 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse boolean value, ignoring: %s", rvalue
);
4385 c
->no_new_privileges
= r
;
4390 int config_parse_protect_home(
4392 const char *filename
,
4394 const char *section
,
4395 unsigned section_line
,
4402 ExecContext
*c
= data
;
4410 /* Our enum shall be a superset of booleans, hence first try
4411 * to parse as boolean, and then as enum */
4413 h
= parse_protect_home_or_bool(rvalue
);
4415 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse protect home value, ignoring: %s", rvalue
);
4419 c
->protect_home
= h
;
4424 int config_parse_protect_system(
4426 const char *filename
,
4428 const char *section
,
4429 unsigned section_line
,
4436 ExecContext
*c
= data
;
4444 s
= parse_protect_system_or_bool(rvalue
);
4446 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse protect system value, ignoring: %s", rvalue
);
4450 c
->protect_system
= s
;
4455 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_keyring_mode
, exec_keyring_mode
, ExecKeyringMode
, "Failed to parse keyring mode");
4457 int config_parse_job_timeout_sec(
4459 const char *filename
,
4461 const char *section
,
4462 unsigned section_line
,
4478 r
= parse_sec_fix_0(rvalue
, &usec
);
4480 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse JobTimeoutSec= parameter, ignoring: %s", rvalue
);
4484 /* If the user explicitly changed JobTimeoutSec= also change JobRunningTimeoutSec=, for compatibility with old
4485 * versions. If JobRunningTimeoutSec= was explicitly set, avoid this however as whatever the user picked should
4488 if (!u
->job_running_timeout_set
)
4489 u
->job_running_timeout
= usec
;
4491 u
->job_timeout
= usec
;
4496 int config_parse_job_running_timeout_sec(
4498 const char *filename
,
4500 const char *section
,
4501 unsigned section_line
,
4517 r
= parse_sec_fix_0(rvalue
, &usec
);
4519 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse JobRunningTimeoutSec= parameter, ignoring: %s", rvalue
);
4523 u
->job_running_timeout
= usec
;
4524 u
->job_running_timeout_set
= true;
4529 #define FOLLOW_MAX 8
4531 static int open_follow(char **filename
, FILE **_f
, Set
*names
, char **_final
) {
4542 /* This will update the filename pointer if the loaded file is
4543 * reached by a symlink. The old string will be freed. */
4546 char *target
, *name
;
4548 if (c
++ >= FOLLOW_MAX
)
4551 path_kill_slashes(*filename
);
4553 /* Add the file name we are currently looking at to
4554 * the names of this unit, but only if it is a valid
4556 name
= basename(*filename
);
4557 if (unit_name_is_valid(name
, UNIT_NAME_ANY
)) {
4559 id
= set_get(names
, name
);
4565 r
= set_consume(names
, id
);
4571 /* Try to open the file name, but don't if its a symlink */
4572 fd
= open(*filename
, O_RDONLY
|O_CLOEXEC
|O_NOCTTY
|O_NOFOLLOW
);
4579 /* Hmm, so this is a symlink. Let's read the name, and follow it manually */
4580 r
= readlink_and_make_absolute(*filename
, &target
);
4588 f
= fdopen(fd
, "re");
4600 static int merge_by_names(Unit
**u
, Set
*names
, const char *id
) {
4608 /* Let's try to add in all symlink names we found */
4609 while ((k
= set_steal_first(names
))) {
4611 /* First try to merge in the other name into our
4613 r
= unit_merge_by_name(*u
, k
);
4617 /* Hmm, we couldn't merge the other unit into
4618 * ours? Then let's try it the other way
4621 /* If the symlink name we are looking at is unit template, then
4622 we must search for instance of this template */
4623 if (unit_name_is_valid(k
, UNIT_NAME_TEMPLATE
) && (*u
)->instance
) {
4624 _cleanup_free_
char *instance
= NULL
;
4626 r
= unit_name_replace_instance(k
, (*u
)->instance
, &instance
);
4630 other
= manager_get_unit((*u
)->manager
, instance
);
4632 other
= manager_get_unit((*u
)->manager
, k
);
4637 r
= unit_merge(other
, *u
);
4640 return merge_by_names(u
, names
, NULL
);
4648 unit_choose_id(*u
, id
);
4656 static int load_from_path(Unit
*u
, const char *path
) {
4657 _cleanup_set_free_free_ Set
*symlink_names
= NULL
;
4658 _cleanup_fclose_
FILE *f
= NULL
;
4659 _cleanup_free_
char *filename
= NULL
;
4668 symlink_names
= set_new(&string_hash_ops
);
4672 if (path_is_absolute(path
)) {
4674 filename
= strdup(path
);
4678 r
= open_follow(&filename
, &f
, symlink_names
, &id
);
4680 filename
= mfree(filename
);
4688 STRV_FOREACH(p
, u
->manager
->lookup_paths
.search_path
) {
4690 /* Instead of opening the path right away, we manually
4691 * follow all symlinks and add their name to our unit
4692 * name set while doing so */
4693 filename
= path_make_absolute(path
, *p
);
4697 if (u
->manager
->unit_path_cache
&&
4698 !set_get(u
->manager
->unit_path_cache
, filename
))
4701 r
= open_follow(&filename
, &f
, symlink_names
, &id
);
4704 filename
= mfree(filename
);
4706 /* ENOENT means that the file is missing or is a dangling symlink.
4707 * ENOTDIR means that one of paths we expect to be is a directory
4708 * is not a directory, we should just ignore that.
4709 * EACCES means that the directory or file permissions are wrong.
4712 log_debug_errno(r
, "Cannot access \"%s\": %m", filename
);
4713 else if (!IN_SET(r
, -ENOENT
, -ENOTDIR
))
4716 /* Empty the symlink names for the next run */
4717 set_clear_free(symlink_names
);
4722 /* Hmm, no suitable file found? */
4725 if (!unit_type_may_alias(u
->type
) && set_size(symlink_names
) > 1) {
4726 log_unit_warning(u
, "Unit type of %s does not support alias names, refusing loading via symlink.", u
->id
);
4731 r
= merge_by_names(&merged
, symlink_names
, id
);
4736 u
->load_state
= UNIT_MERGED
;
4740 if (fstat(fileno(f
), &st
) < 0)
4743 if (null_or_empty(&st
)) {
4744 u
->load_state
= UNIT_MASKED
;
4745 u
->fragment_mtime
= 0;
4747 u
->load_state
= UNIT_LOADED
;
4748 u
->fragment_mtime
= timespec_load(&st
.st_mtim
);
4750 /* Now, parse the file contents */
4751 r
= config_parse(u
->id
, filename
, f
,
4752 UNIT_VTABLE(u
)->sections
,
4753 config_item_perf_lookup
, load_fragment_gperf_lookup
,
4754 CONFIG_PARSE_ALLOW_INCLUDE
, u
);
4759 free_and_replace(u
->fragment_path
, filename
);
4761 if (u
->source_path
) {
4762 if (stat(u
->source_path
, &st
) >= 0)
4763 u
->source_mtime
= timespec_load(&st
.st_mtim
);
4765 u
->source_mtime
= 0;
4771 int unit_load_fragment(Unit
*u
) {
4777 assert(u
->load_state
== UNIT_STUB
);
4781 u
->load_state
= UNIT_LOADED
;
4785 /* First, try to find the unit under its id. We always look
4786 * for unit files in the default directories, to make it easy
4787 * to override things by placing things in /etc/systemd/system */
4788 r
= load_from_path(u
, u
->id
);
4792 /* Try to find an alias we can load this with */
4793 if (u
->load_state
== UNIT_STUB
) {
4794 SET_FOREACH(t
, u
->names
, i
) {
4799 r
= load_from_path(u
, t
);
4803 if (u
->load_state
!= UNIT_STUB
)
4808 /* And now, try looking for it under the suggested (originally linked) path */
4809 if (u
->load_state
== UNIT_STUB
&& u
->fragment_path
) {
4811 r
= load_from_path(u
, u
->fragment_path
);
4815 if (u
->load_state
== UNIT_STUB
)
4816 /* Hmm, this didn't work? Then let's get rid
4817 * of the fragment path stored for us, so that
4818 * we don't point to an invalid location. */
4819 u
->fragment_path
= mfree(u
->fragment_path
);
4822 /* Look for a template */
4823 if (u
->load_state
== UNIT_STUB
&& u
->instance
) {
4824 _cleanup_free_
char *k
= NULL
;
4826 r
= unit_name_template(u
->id
, &k
);
4830 r
= load_from_path(u
, k
);
4833 log_unit_notice(u
, "Unit configuration has fatal error, unit will not be started.");
4837 if (u
->load_state
== UNIT_STUB
) {
4838 SET_FOREACH(t
, u
->names
, i
) {
4839 _cleanup_free_
char *z
= NULL
;
4844 r
= unit_name_template(t
, &z
);
4848 r
= load_from_path(u
, z
);
4852 if (u
->load_state
!= UNIT_STUB
)
4861 void unit_dump_config_items(FILE *f
) {
4862 static const struct {
4863 const ConfigParserCallback callback
;
4866 { config_parse_warn_compat
, "NOTSUPPORTED" },
4867 { config_parse_int
, "INTEGER" },
4868 { config_parse_unsigned
, "UNSIGNED" },
4869 { config_parse_iec_size
, "SIZE" },
4870 { config_parse_iec_uint64
, "SIZE" },
4871 { config_parse_si_size
, "SIZE" },
4872 { config_parse_bool
, "BOOLEAN" },
4873 { config_parse_string
, "STRING" },
4874 { config_parse_path
, "PATH" },
4875 { config_parse_unit_path_printf
, "PATH" },
4876 { config_parse_strv
, "STRING [...]" },
4877 { config_parse_exec_nice
, "NICE" },
4878 { config_parse_exec_oom_score_adjust
, "OOMSCOREADJUST" },
4879 { config_parse_exec_io_class
, "IOCLASS" },
4880 { config_parse_exec_io_priority
, "IOPRIORITY" },
4881 { config_parse_exec_cpu_sched_policy
, "CPUSCHEDPOLICY" },
4882 { config_parse_exec_cpu_sched_prio
, "CPUSCHEDPRIO" },
4883 { config_parse_exec_cpu_affinity
, "CPUAFFINITY" },
4884 { config_parse_mode
, "MODE" },
4885 { config_parse_unit_env_file
, "FILE" },
4886 { config_parse_exec_output
, "OUTPUT" },
4887 { config_parse_exec_input
, "INPUT" },
4888 { config_parse_log_facility
, "FACILITY" },
4889 { config_parse_log_level
, "LEVEL" },
4890 { config_parse_exec_secure_bits
, "SECUREBITS" },
4891 { config_parse_capability_set
, "BOUNDINGSET" },
4892 { config_parse_rlimit
, "LIMIT" },
4893 { config_parse_unit_deps
, "UNIT [...]" },
4894 { config_parse_exec
, "PATH [ARGUMENT [...]]" },
4895 { config_parse_service_type
, "SERVICETYPE" },
4896 { config_parse_service_restart
, "SERVICERESTART" },
4897 { config_parse_kill_mode
, "KILLMODE" },
4898 { config_parse_signal
, "SIGNAL" },
4899 { config_parse_socket_listen
, "SOCKET [...]" },
4900 { config_parse_socket_bind
, "SOCKETBIND" },
4901 { config_parse_socket_bindtodevice
, "NETWORKINTERFACE" },
4902 { config_parse_sec
, "SECONDS" },
4903 { config_parse_nsec
, "NANOSECONDS" },
4904 { config_parse_namespace_path_strv
, "PATH [...]" },
4905 { config_parse_bind_paths
, "PATH[:PATH[:OPTIONS]] [...]" },
4906 { config_parse_unit_requires_mounts_for
, "PATH [...]" },
4907 { config_parse_exec_mount_flags
, "MOUNTFLAG [...]" },
4908 { config_parse_unit_string_printf
, "STRING" },
4909 { config_parse_trigger_unit
, "UNIT" },
4910 { config_parse_timer
, "TIMER" },
4911 { config_parse_path_spec
, "PATH" },
4912 { config_parse_notify_access
, "ACCESS" },
4913 { config_parse_ip_tos
, "TOS" },
4914 { config_parse_unit_condition_path
, "CONDITION" },
4915 { config_parse_unit_condition_string
, "CONDITION" },
4916 { config_parse_unit_condition_null
, "CONDITION" },
4917 { config_parse_unit_slice
, "SLICE" },
4918 { config_parse_documentation
, "URL" },
4919 { config_parse_service_timeout
, "SECONDS" },
4920 { config_parse_emergency_action
, "ACTION" },
4921 { config_parse_set_status
, "STATUS" },
4922 { config_parse_service_sockets
, "SOCKETS" },
4923 { config_parse_environ
, "ENVIRON" },
4925 { config_parse_syscall_filter
, "SYSCALLS" },
4926 { config_parse_syscall_archs
, "ARCHS" },
4927 { config_parse_syscall_errno
, "ERRNO" },
4928 { config_parse_address_families
, "FAMILIES" },
4929 { config_parse_restrict_namespaces
, "NAMESPACES" },
4931 { config_parse_cpu_shares
, "SHARES" },
4932 { config_parse_cpu_weight
, "WEIGHT" },
4933 { config_parse_memory_limit
, "LIMIT" },
4934 { config_parse_device_allow
, "DEVICE" },
4935 { config_parse_device_policy
, "POLICY" },
4936 { config_parse_io_limit
, "LIMIT" },
4937 { config_parse_io_weight
, "WEIGHT" },
4938 { config_parse_io_device_weight
, "DEVICEWEIGHT" },
4939 { config_parse_blockio_bandwidth
, "BANDWIDTH" },
4940 { config_parse_blockio_weight
, "WEIGHT" },
4941 { config_parse_blockio_device_weight
, "DEVICEWEIGHT" },
4942 { config_parse_long
, "LONG" },
4943 { config_parse_socket_service
, "SERVICE" },
4945 { config_parse_exec_selinux_context
, "LABEL" },
4947 { config_parse_job_mode
, "MODE" },
4948 { config_parse_job_mode_isolate
, "BOOLEAN" },
4949 { config_parse_personality
, "PERSONALITY" },
4952 const char *prev
= NULL
;
4957 NULSTR_FOREACH(i
, load_fragment_gperf_nulstr
) {
4958 const char *rvalue
= "OTHER", *lvalue
;
4959 const ConfigPerfItem
*p
;
4964 assert_se(p
= load_fragment_gperf_lookup(i
, strlen(i
)));
4966 /* Hide legacy settings */
4967 if (p
->parse
== config_parse_warn_compat
&&
4968 p
->ltype
== DISABLED_LEGACY
)
4971 for (j
= 0; j
< ELEMENTSOF(table
); j
++)
4972 if (p
->parse
== table
[j
].callback
) {
4973 rvalue
= table
[j
].rvalue
;
4977 dot
= strchr(i
, '.');
4978 lvalue
= dot
? dot
+ 1 : i
;
4982 if (!prev
|| !strneq(prev
, i
, prefix_len
+1)) {
4986 fprintf(f
, "[%.*s]\n", (int) prefix_len
, i
);
4989 fprintf(f
, "%s=%s\n", lvalue
, rvalue
);