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 specifiers, ignoring: %m");
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 on %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 on %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 on \"%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 on %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 on %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, ignoring: %s", rvalue
);
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 on %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, ignoring: %s", rvalue
);
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
, 0, "Invalid socket protocol, ignoring: %s", 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 r
= parse_nice(rvalue
, &priority
);
496 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Nice priority out of range, ignoring: %s", rvalue
);
498 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse nice priority, ignoring: %s", rvalue
);
509 int config_parse_exec_oom_score_adjust(
511 const char *filename
,
514 unsigned section_line
,
521 ExecContext
*c
= data
;
529 if (isempty(rvalue
)) {
530 c
->oom_score_adjust_set
= false;
534 r
= parse_oom_score_adjust(rvalue
, &oa
);
536 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "OOM score adjust value out of range, ignoring: %s", rvalue
);
540 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse the OOM score adjust value, ignoring: %s", rvalue
);
544 c
->oom_score_adjust
= oa
;
545 c
->oom_score_adjust_set
= true;
550 int config_parse_exec(
552 const char *filename
,
555 unsigned section_line
,
562 ExecCommand
**e
= data
;
574 rvalue
+= strspn(rvalue
, WHITESPACE
);
576 if (isempty(rvalue
)) {
577 /* An empty assignment resets the list */
578 *e
= exec_command_free_list(*e
);
584 _cleanup_free_
char *path
= NULL
, *firstword
= NULL
;
585 ExecCommandFlags flags
= 0;
586 bool ignore
= false, separate_argv0
= false;
587 _cleanup_free_ ExecCommand
*nce
= NULL
;
588 _cleanup_strv_free_
char **n
= NULL
;
589 size_t nlen
= 0, nbufsize
= 0;
594 r
= extract_first_word_and_warn(&p
, &firstword
, NULL
, EXTRACT_QUOTES
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
600 /* We accept an absolute path as first argument. If it's prefixed with - and the path doesn't
601 * exist, we ignore it instead of erroring out; if it's prefixed with @, we allow overriding of
602 * argv[0]; if it's prefixed with +, it will be run with full privileges and no sandboxing; if
603 * it's prefixed with '!' we apply sandboxing, but do not change user/group credentials; if
604 * it's prefixed with '!!', then we apply user/group credentials if the kernel supports ambient
605 * capabilities -- if it doesn't we don't apply the credentials themselves, but do apply most
606 * other sandboxing, with some special exceptions for changing UID.
608 * The idea is that '!!' may be used to write services that can take benefit of systemd's
609 * UID/GID dropping if the kernel supports ambient creds, but provide an automatic fallback to
610 * privilege dropping within the daemon if the kernel does not offer that. */
612 if (*f
== '-' && !(flags
& EXEC_COMMAND_IGNORE_FAILURE
)) {
613 flags
|= EXEC_COMMAND_IGNORE_FAILURE
;
615 } else if (*f
== '@' && !separate_argv0
)
616 separate_argv0
= true;
617 else if (*f
== '+' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
618 flags
|= EXEC_COMMAND_FULLY_PRIVILEGED
;
619 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
620 flags
|= EXEC_COMMAND_NO_SETUID
;
621 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_AMBIENT_MAGIC
))) {
622 flags
&= ~EXEC_COMMAND_NO_SETUID
;
623 flags
|= EXEC_COMMAND_AMBIENT_MAGIC
;
629 r
= unit_full_printf(u
, f
, &path
);
631 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
632 "Failed to resolve unit specifiers on %s%s: %m",
633 f
, ignore
? ", ignoring" : "");
634 return ignore
? 0 : -ENOEXEC
;
638 /* First word is either "-" or "@" with no command. */
639 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
640 "Empty path in command line%s: \"%s\"",
641 ignore
? ", ignoring" : "", rvalue
);
642 return ignore
? 0 : -ENOEXEC
;
644 if (!string_is_safe(path
)) {
645 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
646 "Executable name contains special characters%s: %s",
647 ignore
? ", ignoring" : "", path
);
648 return ignore
? 0 : -ENOEXEC
;
650 if (endswith(path
, "/")) {
651 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
652 "Executable path specifies a directory%s: %s",
653 ignore
? ", ignoring" : "", path
);
654 return ignore
? 0 : -ENOEXEC
;
657 if (!path_is_absolute(path
)) {
661 if (!filename_is_valid(path
)) {
662 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
663 "Neither a valid executable name nor an absolute path%s: %s",
664 ignore
? ", ignoring" : "", path
);
665 return ignore
? 0 : -ENOEXEC
;
668 /* Resolve a single-component name to a full path */
669 NULSTR_FOREACH(prefix
, DEFAULT_PATH_NULSTR
) {
670 _cleanup_free_
char *fullpath
= NULL
;
672 fullpath
= strjoin(prefix
, "/", path
);
676 if (access(fullpath
, F_OK
) >= 0) {
677 free_and_replace(path
, fullpath
);
684 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
685 "Executable \"%s\" not found in path \"%s\"%s",
686 path
, DEFAULT_PATH
, ignore
? ", ignoring" : "");
687 return ignore
? 0 : -ENOEXEC
;
691 if (!separate_argv0
) {
694 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
704 path_kill_slashes(path
);
706 while (!isempty(p
)) {
707 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
709 /* Check explicitly for an unquoted semicolon as
710 * command separator token. */
711 if (p
[0] == ';' && (!p
[1] || strchr(WHITESPACE
, p
[1]))) {
713 p
+= strspn(p
, WHITESPACE
);
718 /* Check for \; explicitly, to not confuse it with \\; or "\;" or "\\;" etc.
719 * extract_first_word() would return the same for all of those. */
720 if (p
[0] == '\\' && p
[1] == ';' && (!p
[2] || strchr(WHITESPACE
, p
[2]))) {
724 p
+= strspn(p
, WHITESPACE
);
726 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
737 r
= extract_first_word_and_warn(&p
, &word
, NULL
, EXTRACT_QUOTES
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
741 return ignore
? 0 : -ENOEXEC
;
743 r
= unit_full_printf(u
, word
, &resolved
);
745 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
746 "Failed to resolve unit specifiers on %s%s: %m",
747 word
, ignore
? ", ignoring" : "");
748 return ignore
? 0 : -ENOEXEC
;
751 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
754 n
[nlen
++] = TAKE_PTR(resolved
);
759 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
760 "Empty executable name or zeroeth argument%s: %s",
761 ignore
? ", ignoring" : "", rvalue
);
762 return ignore
? 0 : -ENOEXEC
;
765 nce
= new0(ExecCommand
, 1);
769 nce
->argv
= TAKE_PTR(n
);
770 nce
->path
= TAKE_PTR(path
);
773 exec_command_append_list(e
, nce
);
775 /* Do not _cleanup_free_ these. */
784 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_type
, service_type
, ServiceType
, "Failed to parse service type");
785 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart
, service_restart
, ServiceRestart
, "Failed to parse service restart specifier");
787 int config_parse_socket_bindtodevice(
789 const char *filename
,
792 unsigned section_line
,
807 if (rvalue
[0] && !streq(rvalue
, "*")) {
808 if (!ifname_valid(rvalue
)) {
809 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Interface name is invalid, ignoring: %s", rvalue
);
819 free_and_replace(s
->bind_to_device
, n
);
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 on %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 on %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", rvalue
);
934 r
= unit_full_printf(u
, unescaped
, &resolved
);
936 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve specifiers: %s", 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 on %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 on %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 x
= ioprio_class_from_string(rvalue
);
1120 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse IO scheduling class, ignoring: %s", rvalue
);
1124 c
->ioprio
= IOPRIO_PRIO_VALUE(x
, IOPRIO_PRIO_DATA(c
->ioprio
));
1125 c
->ioprio_set
= true;
1130 int config_parse_exec_io_priority(const char *unit
,
1131 const char *filename
,
1133 const char *section
,
1134 unsigned section_line
,
1141 ExecContext
*c
= data
;
1149 r
= ioprio_parse_priority(rvalue
, &i
);
1151 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse IO priority, ignoring: %s", rvalue
);
1155 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_PRIO_CLASS(c
->ioprio
), i
);
1156 c
->ioprio_set
= true;
1161 int config_parse_exec_cpu_sched_policy(const char *unit
,
1162 const char *filename
,
1164 const char *section
,
1165 unsigned section_line
,
1172 ExecContext
*c
= data
;
1180 x
= sched_policy_from_string(rvalue
);
1182 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse CPU scheduling policy, ignoring: %s", rvalue
);
1186 c
->cpu_sched_policy
= x
;
1187 /* Moving to or from real-time policy? We need to adjust the priority */
1188 c
->cpu_sched_priority
= CLAMP(c
->cpu_sched_priority
, sched_get_priority_min(x
), sched_get_priority_max(x
));
1189 c
->cpu_sched_set
= true;
1194 int config_parse_exec_cpu_sched_prio(const char *unit
,
1195 const char *filename
,
1197 const char *section
,
1198 unsigned section_line
,
1205 ExecContext
*c
= data
;
1213 r
= safe_atoi(rvalue
, &i
);
1215 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse CPU scheduling policy, ignoring: %s", rvalue
);
1219 /* On Linux RR/FIFO range from 1 to 99 and OTHER/BATCH may only be 0 */
1220 min
= sched_get_priority_min(c
->cpu_sched_policy
);
1221 max
= sched_get_priority_max(c
->cpu_sched_policy
);
1223 if (i
< min
|| i
> max
) {
1224 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "CPU scheduling priority is out of range, ignoring: %s", rvalue
);
1228 c
->cpu_sched_priority
= i
;
1229 c
->cpu_sched_set
= true;
1234 int config_parse_exec_cpu_affinity(const char *unit
,
1235 const char *filename
,
1237 const char *section
,
1238 unsigned section_line
,
1245 ExecContext
*c
= data
;
1246 _cleanup_cpu_free_ cpu_set_t
*cpuset
= NULL
;
1254 ncpus
= parse_cpu_set_and_warn(rvalue
, &cpuset
, unit
, filename
, line
, lvalue
);
1259 /* An empty assignment resets the CPU list */
1260 c
->cpuset
= cpu_set_mfree(c
->cpuset
);
1261 c
->cpuset_ncpus
= 0;
1266 c
->cpuset
= TAKE_PTR(cpuset
);
1267 c
->cpuset_ncpus
= (unsigned) ncpus
;
1271 if (c
->cpuset_ncpus
< (unsigned) ncpus
) {
1272 CPU_OR_S(CPU_ALLOC_SIZE(c
->cpuset_ncpus
), cpuset
, c
->cpuset
, cpuset
);
1273 CPU_FREE(c
->cpuset
);
1274 c
->cpuset
= TAKE_PTR(cpuset
);
1275 c
->cpuset_ncpus
= (unsigned) ncpus
;
1279 CPU_OR_S(CPU_ALLOC_SIZE((unsigned) ncpus
), c
->cpuset
, c
->cpuset
, cpuset
);
1284 int config_parse_exec_secure_bits(const char *unit
,
1285 const char *filename
,
1287 const char *section
,
1288 unsigned section_line
,
1295 ExecContext
*c
= data
;
1303 if (isempty(rvalue
)) {
1304 /* An empty assignment resets the field */
1309 r
= secure_bits_from_string(rvalue
);
1313 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1314 "Invalid syntax, ignoring: %s", rvalue
);
1323 int config_parse_capability_set(
1325 const char *filename
,
1327 const char *section
,
1328 unsigned section_line
,
1335 uint64_t *capability_set
= data
;
1336 uint64_t sum
= 0, initial
= 0;
1337 bool invert
= false;
1345 if (rvalue
[0] == '~') {
1350 if (streq(lvalue
, "CapabilityBoundingSet"))
1351 initial
= CAP_ALL
; /* initialized to all bits on */
1352 /* else "AmbientCapabilities" initialized to all bits off */
1354 r
= capability_set_from_string(rvalue
, &sum
);
1358 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse word: %s", rvalue
);
1362 if (sum
== 0 || *capability_set
== initial
)
1363 /* "", "~" or uninitialized data -> replace */
1364 *capability_set
= invert
? ~sum
: sum
;
1366 /* previous data -> merge */
1368 *capability_set
&= ~sum
;
1370 *capability_set
|= sum
;
1376 #if HAVE_SYSV_COMPAT
1377 int config_parse_sysv_priority(const char *unit
,
1378 const char *filename
,
1380 const char *section
,
1381 unsigned section_line
,
1388 int *priority
= data
;
1396 r
= safe_atoi(rvalue
, &i
);
1397 if (r
< 0 || i
< 0) {
1398 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse SysV start priority, ignoring: %s", rvalue
);
1402 *priority
= (int) i
;
1407 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_utmp_mode
, exec_utmp_mode
, ExecUtmpMode
, "Failed to parse utmp mode");
1408 DEFINE_CONFIG_PARSE_ENUM(config_parse_kill_mode
, kill_mode
, KillMode
, "Failed to parse kill mode");
1410 int config_parse_exec_mount_flags(
1412 const char *filename
,
1414 const char *section
,
1415 unsigned section_line
,
1422 ExecContext
*c
= data
;
1430 r
= mount_propagation_flags_from_string(rvalue
, &c
->mount_flags
);
1432 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse mount flag %s, ignoring.", rvalue
);
1437 int config_parse_exec_selinux_context(
1439 const char *filename
,
1441 const char *section
,
1442 unsigned section_line
,
1449 ExecContext
*c
= data
;
1460 if (isempty(rvalue
)) {
1461 c
->selinux_context
= mfree(c
->selinux_context
);
1462 c
->selinux_context_ignore
= false;
1466 if (rvalue
[0] == '-') {
1472 r
= unit_full_printf(u
, rvalue
, &k
);
1474 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1475 "Failed to resolve specifiers%s: %m",
1476 ignore
? ", ignoring" : "");
1477 return ignore
? 0 : -ENOEXEC
;
1480 free(c
->selinux_context
);
1481 c
->selinux_context
= k
;
1482 c
->selinux_context_ignore
= ignore
;
1487 int config_parse_exec_apparmor_profile(
1489 const char *filename
,
1491 const char *section
,
1492 unsigned section_line
,
1499 ExecContext
*c
= data
;
1510 if (isempty(rvalue
)) {
1511 c
->apparmor_profile
= mfree(c
->apparmor_profile
);
1512 c
->apparmor_profile_ignore
= false;
1516 if (rvalue
[0] == '-') {
1522 r
= unit_full_printf(u
, rvalue
, &k
);
1524 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1525 "Failed to resolve specifiers%s: %m",
1526 ignore
? ", ignoring" : "");
1527 return ignore
? 0 : -ENOEXEC
;
1530 free(c
->apparmor_profile
);
1531 c
->apparmor_profile
= k
;
1532 c
->apparmor_profile_ignore
= ignore
;
1537 int config_parse_exec_smack_process_label(
1539 const char *filename
,
1541 const char *section
,
1542 unsigned section_line
,
1549 ExecContext
*c
= data
;
1560 if (isempty(rvalue
)) {
1561 c
->smack_process_label
= mfree(c
->smack_process_label
);
1562 c
->smack_process_label_ignore
= false;
1566 if (rvalue
[0] == '-') {
1572 r
= unit_full_printf(u
, rvalue
, &k
);
1574 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1575 "Failed to resolve specifiers%s: %m",
1576 ignore
? ", ignoring" : "");
1577 return ignore
? 0 : -ENOEXEC
;
1580 free(c
->smack_process_label
);
1581 c
->smack_process_label
= k
;
1582 c
->smack_process_label_ignore
= ignore
;
1587 int config_parse_timer(const char *unit
,
1588 const char *filename
,
1590 const char *section
,
1591 unsigned section_line
,
1602 _cleanup_(calendar_spec_freep
) CalendarSpec
*c
= NULL
;
1604 _cleanup_free_
char *k
= NULL
;
1612 if (isempty(rvalue
)) {
1613 /* Empty assignment resets list */
1614 timer_free_values(t
);
1618 b
= timer_base_from_string(lvalue
);
1620 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse timer base, ignoring: %s", lvalue
);
1624 r
= unit_full_printf(u
, rvalue
, &k
);
1626 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
1630 if (b
== TIMER_CALENDAR
) {
1631 if (calendar_spec_from_string(k
, &c
) < 0) {
1632 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse calendar specification, ignoring: %s", k
);
1636 if (parse_sec(k
, &usec
) < 0) {
1637 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse timer value, ignoring: %s", k
);
1642 v
= new0(TimerValue
, 1);
1648 v
->calendar_spec
= TAKE_PTR(c
);
1650 LIST_PREPEND(value
, t
->values
, v
);
1655 int config_parse_trigger_unit(
1657 const char *filename
,
1659 const char *section
,
1660 unsigned section_line
,
1667 _cleanup_free_
char *p
= NULL
;
1677 if (!hashmap_isempty(u
->dependencies
[UNIT_TRIGGERS
])) {
1678 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Multiple units to trigger specified, ignoring: %s", rvalue
);
1682 r
= unit_name_printf(u
, rvalue
, &p
);
1684 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve specifiers, ignoring: %m");
1688 type
= unit_name_to_type(p
);
1690 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit type not valid, ignoring: %s", rvalue
);
1693 if (unit_has_name(u
, p
)) {
1694 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Units cannot trigger themselves, ignoring: %s", rvalue
);
1698 r
= unit_add_two_dependencies_by_name(u
, UNIT_BEFORE
, UNIT_TRIGGERS
, p
, NULL
, true, UNIT_DEPENDENCY_FILE
);
1700 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add trigger on %s, ignoring: %m", p
);
1707 int config_parse_path_spec(const char *unit
,
1708 const char *filename
,
1710 const char *section
,
1711 unsigned section_line
,
1721 _cleanup_free_
char *k
= NULL
;
1729 if (isempty(rvalue
)) {
1730 /* Empty assignment clears list */
1735 b
= path_type_from_string(lvalue
);
1737 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse path type, ignoring: %s", lvalue
);
1741 r
= unit_full_printf(UNIT(p
), rvalue
, &k
);
1743 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers on %s. Ignoring.", rvalue
);
1747 if (!path_is_absolute(k
)) {
1748 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Path is not absolute, ignoring: %s", k
);
1752 s
= new0(PathSpec
, 1);
1757 s
->path
= path_kill_slashes(k
);
1762 LIST_PREPEND(spec
, p
->specs
, s
);
1767 int config_parse_socket_service(
1769 const char *filename
,
1771 const char *section
,
1772 unsigned section_line
,
1779 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1780 _cleanup_free_
char *p
= NULL
;
1790 r
= unit_name_printf(UNIT(s
), rvalue
, &p
);
1792 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve specifiers: %s", rvalue
);
1796 if (!endswith(p
, ".service")) {
1797 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit must be of type service: %s", rvalue
);
1801 r
= manager_load_unit(UNIT(s
)->manager
, p
, NULL
, &error
, &x
);
1803 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to load unit %s: %s", rvalue
, bus_error_message(&error
, r
));
1807 unit_ref_set(&s
->service
, UNIT(s
), x
);
1812 int config_parse_fdname(
1814 const char *filename
,
1816 const char *section
,
1817 unsigned section_line
,
1824 _cleanup_free_
char *p
= NULL
;
1833 if (isempty(rvalue
)) {
1834 s
->fdname
= mfree(s
->fdname
);
1838 r
= unit_full_printf(UNIT(s
), rvalue
, &p
);
1840 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve specifiers, ignoring: %s", rvalue
);
1844 if (!fdname_is_valid(p
)) {
1845 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", p
);
1849 return free_and_replace(s
->fdname
, p
);
1852 int config_parse_service_sockets(
1854 const char *filename
,
1856 const char *section
,
1857 unsigned section_line
,
1875 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
1877 r
= extract_first_word(&p
, &word
, NULL
, 0);
1883 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Trailing garbage in sockets, ignoring: %s", rvalue
);
1887 r
= unit_name_printf(UNIT(s
), word
, &k
);
1889 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve specifiers, ignoring: %m");
1893 if (!endswith(k
, ".socket")) {
1894 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit must be of type socket, ignoring: %s", k
);
1898 r
= unit_add_two_dependencies_by_name(UNIT(s
), UNIT_WANTS
, UNIT_AFTER
, k
, NULL
, true, UNIT_DEPENDENCY_FILE
);
1900 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
1902 r
= unit_add_dependency_by_name(UNIT(s
), UNIT_TRIGGERED_BY
, k
, NULL
, true, UNIT_DEPENDENCY_FILE
);
1904 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
1910 int config_parse_bus_name(
1912 const char *filename
,
1914 const char *section
,
1915 unsigned section_line
,
1922 _cleanup_free_
char *k
= NULL
;
1931 r
= unit_full_printf(u
, rvalue
, &k
);
1933 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers on %s, ignoring: %m", rvalue
);
1937 if (!service_name_is_valid(k
)) {
1938 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid bus name %s, ignoring.", k
);
1942 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
1945 int config_parse_service_timeout(
1947 const char *filename
,
1949 const char *section
,
1950 unsigned section_line
,
1957 Service
*s
= userdata
;
1966 /* This is called for three cases: TimeoutSec=, TimeoutStopSec= and TimeoutStartSec=. */
1968 r
= parse_sec(rvalue
, &usec
);
1970 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
1974 /* Traditionally, these options accepted 0 to disable the timeouts. However, a timeout of 0 suggests it happens
1975 * immediately, hence fix this to become USEC_INFINITY instead. This is in-line with how we internally handle
1976 * all other timeouts. */
1978 usec
= USEC_INFINITY
;
1980 if (!streq(lvalue
, "TimeoutStopSec")) {
1981 s
->start_timeout_defined
= true;
1982 s
->timeout_start_usec
= usec
;
1985 if (!streq(lvalue
, "TimeoutStartSec"))
1986 s
->timeout_stop_usec
= usec
;
1991 int config_parse_sec_fix_0(
1993 const char *filename
,
1995 const char *section
,
1996 unsigned section_line
,
2003 usec_t
*usec
= data
;
2011 /* This is pretty much like config_parse_sec(), except that this treats a time of 0 as infinity, for
2012 * compatibility with older versions of systemd where 0 instead of infinity was used as indicator to turn off a
2015 r
= parse_sec_fix_0(rvalue
, usec
);
2017 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
2024 int config_parse_user_group(
2026 const char *filename
,
2028 const char *section
,
2029 unsigned section_line
,
2036 char **user
= data
, *n
;
2045 if (isempty(rvalue
))
2048 _cleanup_free_
char *k
= NULL
;
2050 r
= unit_full_printf(u
, rvalue
, &k
);
2052 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", rvalue
);
2056 if (!valid_user_group_name_or_id(k
)) {
2057 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2070 int config_parse_user_group_strv(
2072 const char *filename
,
2074 const char *section
,
2075 unsigned section_line
,
2082 char ***users
= data
;
2092 if (isempty(rvalue
)) {
2093 *users
= strv_free(*users
);
2099 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2101 r
= extract_first_word(&p
, &word
, NULL
, 0);
2107 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax: %s", rvalue
);
2111 r
= unit_full_printf(u
, word
, &k
);
2113 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", word
);
2117 if (!valid_user_group_name_or_id(k
)) {
2118 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2122 r
= strv_push(users
, k
);
2132 int config_parse_working_directory(
2134 const char *filename
,
2136 const char *section
,
2137 unsigned section_line
,
2144 ExecContext
*c
= data
;
2155 if (rvalue
[0] == '-') {
2161 if (streq(rvalue
, "~")) {
2162 c
->working_directory_home
= true;
2163 c
->working_directory
= mfree(c
->working_directory
);
2165 _cleanup_free_
char *k
= NULL
;
2167 r
= unit_full_printf(u
, rvalue
, &k
);
2169 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2170 "Failed to resolve unit specifiers in working directory path '%s'%s: %m",
2171 rvalue
, missing_ok
? ", ignoring" : "");
2172 return missing_ok
? 0 : -ENOEXEC
;
2175 path_kill_slashes(k
);
2177 if (!utf8_is_valid(k
)) {
2178 log_syntax_invalid_utf8(unit
, LOG_ERR
, filename
, line
, rvalue
);
2179 return missing_ok
? 0 : -ENOEXEC
;
2182 if (!path_is_absolute(k
)) {
2183 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2184 "Working directory path '%s' is not absolute%s.",
2185 rvalue
, missing_ok
? ", ignoring" : "");
2186 return missing_ok
? 0 : -ENOEXEC
;
2189 c
->working_directory_home
= false;
2190 free_and_replace(c
->working_directory
, k
);
2193 c
->working_directory_missing_ok
= missing_ok
;
2197 int config_parse_unit_env_file(const char *unit
,
2198 const char *filename
,
2200 const char *section
,
2201 unsigned section_line
,
2210 _cleanup_free_
char *n
= NULL
;
2218 if (isempty(rvalue
)) {
2219 /* Empty assignment frees the list */
2220 *env
= strv_free(*env
);
2224 r
= unit_full_printf(u
, rvalue
, &n
);
2226 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve specifiers, ignoring: %s", rvalue
);
2230 if (!path_is_absolute(n
[0] == '-' ? n
+ 1 : n
)) {
2231 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Path '%s' is not absolute, ignoring.", n
);
2235 r
= strv_extend(env
, n
);
2242 int config_parse_environ(
2244 const char *filename
,
2246 const char *section
,
2247 unsigned section_line
,
2264 if (isempty(rvalue
)) {
2265 /* Empty assignment resets the list */
2266 *env
= strv_free(*env
);
2270 for (p
= rvalue
;; ) {
2271 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2273 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_QUOTES
);
2279 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2280 "Invalid syntax, ignoring: %s", rvalue
);
2285 r
= unit_full_printf(u
, word
, &k
);
2287 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2288 "Failed to resolve specifiers, ignoring: %s", word
);
2294 if (!env_assignment_is_valid(k
)) {
2295 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2296 "Invalid environment assignment, ignoring: %s", k
);
2300 r
= strv_env_replace(env
, k
);
2308 int config_parse_pass_environ(
2310 const char *filename
,
2312 const char *section
,
2313 unsigned section_line
,
2320 const char *whole_rvalue
= rvalue
;
2321 _cleanup_strv_free_
char **n
= NULL
;
2322 size_t nlen
= 0, nbufsize
= 0;
2323 char*** passenv
= data
;
2332 if (isempty(rvalue
)) {
2333 /* Empty assignment resets the list */
2334 *passenv
= strv_free(*passenv
);
2339 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2341 r
= extract_first_word(&rvalue
, &word
, NULL
, EXTRACT_QUOTES
);
2347 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2348 "Trailing garbage in %s, ignoring: %s", lvalue
, whole_rvalue
);
2353 r
= unit_full_printf(u
, word
, &k
);
2355 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2356 "Failed to resolve specifiers, ignoring: %s", word
);
2362 if (!env_name_is_valid(k
)) {
2363 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2364 "Invalid environment name for %s, ignoring: %s", lvalue
, k
);
2368 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
2371 n
[nlen
++] = TAKE_PTR(k
);
2376 r
= strv_extend_strv(passenv
, n
, true);
2384 int config_parse_unset_environ(
2386 const char *filename
,
2388 const char *section
,
2389 unsigned section_line
,
2396 _cleanup_strv_free_
char **n
= NULL
;
2397 const char *whole_rvalue
= rvalue
;
2398 size_t nlen
= 0, nbufsize
= 0;
2399 char*** unsetenv
= data
;
2408 if (isempty(rvalue
)) {
2409 /* Empty assignment resets the list */
2410 *unsetenv
= strv_free(*unsetenv
);
2415 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2417 r
= extract_first_word(&rvalue
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_QUOTES
);
2423 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2424 "Trailing garbage in %s, ignoring: %s", lvalue
, whole_rvalue
);
2429 r
= unit_full_printf(u
, word
, &k
);
2431 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2432 "Failed to resolve specifiers, ignoring: %s", word
);
2438 if (!env_assignment_is_valid(k
) && !env_name_is_valid(k
)) {
2439 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2440 "Invalid environment name or assignment %s, ignoring: %s", lvalue
, k
);
2444 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
2447 n
[nlen
++] = TAKE_PTR(k
);
2452 r
= strv_extend_strv(unsetenv
, n
, true);
2460 int config_parse_log_extra_fields(
2462 const char *filename
,
2464 const char *section
,
2465 unsigned section_line
,
2472 ExecContext
*c
= data
;
2482 if (isempty(rvalue
)) {
2483 exec_context_free_log_extra_fields(c
);
2487 for (p
= rvalue
;; ) {
2488 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2492 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_QUOTES
);
2498 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
2502 r
= unit_full_printf(u
, word
, &k
);
2504 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers on %s, ignoring field: %m", word
);
2508 eq
= strchr(k
, '=');
2510 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Log field lacks '=' character, ignoring field: %s", k
);
2514 if (!journal_field_valid(k
, eq
-k
, false)) {
2515 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Log field name is invalid, ignoring field: %s", k
);
2519 t
= reallocarray(c
->log_extra_fields
, c
->n_log_extra_fields
+1, sizeof(struct iovec
));
2523 c
->log_extra_fields
= t
;
2524 c
->log_extra_fields
[c
->n_log_extra_fields
++] = IOVEC_MAKE_STRING(k
);
2532 int config_parse_ip_tos(const char *unit
,
2533 const char *filename
,
2535 const char *section
,
2536 unsigned section_line
,
2543 int *ip_tos
= data
, x
;
2550 x
= ip_tos_from_string(rvalue
);
2552 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse IP TOS value, ignoring: %s", rvalue
);
2560 int config_parse_unit_condition_path(
2562 const char *filename
,
2564 const char *section
,
2565 unsigned section_line
,
2572 _cleanup_free_
char *p
= 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
[0] == '|';
2594 negate
= rvalue
[0] == '!';
2598 r
= unit_full_printf(u
, rvalue
, &p
);
2600 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve specifiers, ignoring: %s", rvalue
);
2604 if (!path_is_absolute(p
)) {
2605 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Path in condition not absolute, ignoring: %s", p
);
2609 c
= condition_new(t
, p
, trigger
, negate
);
2613 LIST_PREPEND(conditions
, *list
, c
);
2617 int config_parse_unit_condition_string(
2619 const char *filename
,
2621 const char *section
,
2622 unsigned section_line
,
2629 _cleanup_free_
char *s
= NULL
;
2630 Condition
**list
= data
, *c
;
2631 ConditionType t
= ltype
;
2632 bool trigger
, negate
;
2641 if (isempty(rvalue
)) {
2642 /* Empty assignment resets the list */
2643 *list
= condition_free_list(*list
);
2647 trigger
= rvalue
[0] == '|';
2651 negate
= rvalue
[0] == '!';
2655 r
= unit_full_printf(u
, rvalue
, &s
);
2657 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve specifiers, ignoring: %s", rvalue
);
2661 c
= condition_new(t
, s
, trigger
, negate
);
2665 LIST_PREPEND(conditions
, *list
, c
);
2669 int config_parse_unit_condition_null(
2671 const char *filename
,
2673 const char *section
,
2674 unsigned section_line
,
2681 Condition
**list
= data
, *c
;
2682 bool trigger
, negate
;
2690 if (isempty(rvalue
)) {
2691 /* Empty assignment resets the list */
2692 *list
= condition_free_list(*list
);
2696 trigger
= rvalue
[0] == '|';
2700 negate
= rvalue
[0] == '!';
2704 b
= parse_boolean(rvalue
);
2706 log_syntax(unit
, LOG_ERR
, filename
, line
, b
, "Failed to parse boolean value in condition, ignoring: %s", rvalue
);
2713 c
= condition_new(CONDITION_NULL
, NULL
, trigger
, negate
);
2717 LIST_PREPEND(conditions
, *list
, c
);
2721 DEFINE_CONFIG_PARSE_ENUM(config_parse_notify_access
, notify_access
, NotifyAccess
, "Failed to parse notify access specifier");
2722 DEFINE_CONFIG_PARSE_ENUM(config_parse_emergency_action
, emergency_action
, EmergencyAction
, "Failed to parse failure action specifier");
2724 int config_parse_unit_requires_mounts_for(
2726 const char *filename
,
2728 const char *section
,
2729 unsigned section_line
,
2745 for (p
= rvalue
;; ) {
2746 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
2748 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
2754 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2755 "Invalid syntax, ignoring: %s", rvalue
);
2759 if (!utf8_is_valid(word
)) {
2760 log_syntax_invalid_utf8(unit
, LOG_ERR
, filename
, line
, rvalue
);
2764 r
= unit_full_printf(u
, word
, &resolved
);
2766 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit name \"%s\", ignoring: %m", word
);
2770 r
= unit_require_mounts_for(u
, resolved
, UNIT_DEPENDENCY_FILE
);
2772 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add required mount \"%s\", ignoring: %m", resolved
);
2778 int config_parse_documentation(const char *unit
,
2779 const char *filename
,
2781 const char *section
,
2782 unsigned section_line
,
2798 if (isempty(rvalue
)) {
2799 /* Empty assignment resets the list */
2800 u
->documentation
= strv_free(u
->documentation
);
2804 r
= config_parse_unit_strv_printf(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
,
2805 rvalue
, data
, userdata
);
2809 for (a
= b
= u
->documentation
; a
&& *a
; a
++) {
2811 if (documentation_url_is_valid(*a
))
2814 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid URL, ignoring: %s", *a
);
2825 int config_parse_syscall_filter(
2827 const char *filename
,
2829 const char *section
,
2830 unsigned section_line
,
2837 ExecContext
*c
= data
;
2839 bool invert
= false;
2848 if (isempty(rvalue
)) {
2849 /* Empty assignment resets the list */
2850 c
->syscall_filter
= hashmap_free(c
->syscall_filter
);
2851 c
->syscall_whitelist
= false;
2855 if (rvalue
[0] == '~') {
2860 if (!c
->syscall_filter
) {
2861 c
->syscall_filter
= hashmap_new(NULL
);
2862 if (!c
->syscall_filter
)
2866 /* Allow everything but the ones listed */
2867 c
->syscall_whitelist
= false;
2869 /* Allow nothing but the ones listed */
2870 c
->syscall_whitelist
= true;
2872 /* Accept default syscalls if we are on a whitelist */
2873 r
= seccomp_parse_syscall_filter("@default", -1, c
->syscall_filter
, SECCOMP_PARSE_WHITELIST
);
2881 _cleanup_free_
char *word
= NULL
, *name
= NULL
;
2884 r
= extract_first_word(&p
, &word
, NULL
, 0);
2890 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
2894 r
= parse_syscall_and_errno(word
, &name
, &num
);
2896 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse syscall:errno, ignoring: %s", word
);
2900 r
= seccomp_parse_syscall_filter_full(name
, num
, c
->syscall_filter
,
2901 SECCOMP_PARSE_LOG
|SECCOMP_PARSE_PERMISSIVE
|(invert
? SECCOMP_PARSE_INVERT
: 0)|(c
->syscall_whitelist
? SECCOMP_PARSE_WHITELIST
: 0),
2902 unit
, filename
, line
);
2910 int config_parse_syscall_archs(
2912 const char *filename
,
2914 const char *section
,
2915 unsigned section_line
,
2926 if (isempty(rvalue
)) {
2927 *archs
= set_free(*archs
);
2931 r
= set_ensure_allocated(archs
, NULL
);
2935 for (p
= rvalue
;;) {
2936 _cleanup_free_
char *word
= NULL
;
2939 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
2945 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2946 "Invalid syntax, ignoring: %s", rvalue
);
2950 r
= seccomp_arch_from_string(word
, &a
);
2952 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2953 "Failed to parse system call architecture \"%s\", ignoring: %m", word
);
2957 r
= set_put(*archs
, UINT32_TO_PTR(a
+ 1));
2963 int config_parse_syscall_errno(
2965 const char *filename
,
2967 const char *section
,
2968 unsigned section_line
,
2975 ExecContext
*c
= data
;
2982 if (isempty(rvalue
)) {
2983 /* Empty assignment resets to KILL */
2984 c
->syscall_errno
= 0;
2988 e
= parse_errno(rvalue
);
2990 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse error number, ignoring: %s", rvalue
);
2994 c
->syscall_errno
= e
;
2998 int config_parse_address_families(
3000 const char *filename
,
3002 const char *section
,
3003 unsigned section_line
,
3010 ExecContext
*c
= data
;
3011 bool invert
= false;
3019 if (isempty(rvalue
)) {
3020 /* Empty assignment resets the list */
3021 c
->address_families
= set_free(c
->address_families
);
3022 c
->address_families_whitelist
= false;
3026 if (rvalue
[0] == '~') {
3031 if (!c
->address_families
) {
3032 c
->address_families
= set_new(NULL
);
3033 if (!c
->address_families
)
3036 c
->address_families_whitelist
= !invert
;
3039 for (p
= rvalue
;;) {
3040 _cleanup_free_
char *word
= NULL
;
3043 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
3049 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3050 "Invalid syntax, ignoring: %s", rvalue
);
3054 af
= af_from_name(word
);
3056 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
3057 "Failed to parse address family \"%s\", ignoring: %m", word
);
3061 /* If we previously wanted to forbid an address family and now
3062 * we want to allow it, then just remove it from the list.
3064 if (!invert
== c
->address_families_whitelist
) {
3065 r
= set_put(c
->address_families
, INT_TO_PTR(af
));
3069 set_remove(c
->address_families
, INT_TO_PTR(af
));
3073 int config_parse_restrict_namespaces(
3075 const char *filename
,
3077 const char *section
,
3078 unsigned section_line
,
3085 ExecContext
*c
= data
;
3086 bool invert
= false;
3089 if (isempty(rvalue
)) {
3090 /* Reset to the default. */
3091 c
->restrict_namespaces
= NAMESPACE_FLAGS_ALL
;
3095 if (rvalue
[0] == '~') {
3100 r
= parse_boolean(rvalue
);
3102 c
->restrict_namespaces
= 0;
3104 c
->restrict_namespaces
= NAMESPACE_FLAGS_ALL
;
3106 /* Not a boolean argument, in this case it's a list of namespace types. */
3108 r
= namespace_flag_from_string_many(rvalue
, &c
->restrict_namespaces
);
3110 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse namespace type string, ignoring: %s", rvalue
);
3116 c
->restrict_namespaces
= (~c
->restrict_namespaces
) & NAMESPACE_FLAGS_ALL
;
3122 int config_parse_unit_slice(
3124 const char *filename
,
3126 const char *section
,
3127 unsigned section_line
,
3134 _cleanup_free_
char *k
= NULL
;
3135 Unit
*u
= userdata
, *slice
= NULL
;
3143 r
= unit_name_printf(u
, rvalue
, &k
);
3145 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers on %s. Ignoring.", rvalue
);
3149 r
= manager_load_unit(u
->manager
, k
, NULL
, NULL
, &slice
);
3151 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to load slice unit %s. Ignoring.", k
);
3155 r
= unit_set_slice(u
, slice
);
3157 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to assign slice %s to unit %s. Ignoring.", slice
->id
, u
->id
);
3164 DEFINE_CONFIG_PARSE_ENUM(config_parse_device_policy
, cgroup_device_policy
, CGroupDevicePolicy
, "Failed to parse device policy");
3166 int config_parse_cpu_weight(
3168 const char *filename
,
3170 const char *section
,
3171 unsigned section_line
,
3178 uint64_t *weight
= data
;
3185 r
= cg_weight_parse(rvalue
, weight
);
3187 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "CPU weight '%s' invalid. Ignoring.", rvalue
);
3194 int config_parse_cpu_shares(
3196 const char *filename
,
3198 const char *section
,
3199 unsigned section_line
,
3206 uint64_t *shares
= data
;
3213 r
= cg_cpu_shares_parse(rvalue
, shares
);
3215 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "CPU shares '%s' invalid. Ignoring.", rvalue
);
3222 int config_parse_cpu_quota(
3224 const char *filename
,
3226 const char *section
,
3227 unsigned section_line
,
3234 CGroupContext
*c
= data
;
3241 if (isempty(rvalue
)) {
3242 c
->cpu_quota_per_sec_usec
= USEC_INFINITY
;
3246 r
= parse_percent_unbounded(rvalue
);
3248 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "CPU quota '%s' invalid. Ignoring.", rvalue
);
3252 c
->cpu_quota_per_sec_usec
= ((usec_t
) r
* USEC_PER_SEC
) / 100U;
3256 int config_parse_memory_limit(
3258 const char *filename
,
3260 const char *section
,
3261 unsigned section_line
,
3268 CGroupContext
*c
= data
;
3269 uint64_t bytes
= CGROUP_LIMIT_MAX
;
3272 if (!isempty(rvalue
) && !streq(rvalue
, "infinity")) {
3274 r
= parse_percent(rvalue
);
3276 r
= parse_size(rvalue
, 1024, &bytes
);
3278 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Memory limit '%s' invalid. Ignoring.", rvalue
);
3282 bytes
= physical_memory_scale(r
, 100U);
3284 if (bytes
>= UINT64_MAX
||
3285 (bytes
<= 0 && !streq(lvalue
, "MemorySwapMax"))) {
3286 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Memory limit '%s' out of range. Ignoring.", rvalue
);
3291 if (streq(lvalue
, "MemoryLow"))
3292 c
->memory_low
= bytes
;
3293 else if (streq(lvalue
, "MemoryHigh"))
3294 c
->memory_high
= bytes
;
3295 else if (streq(lvalue
, "MemoryMax"))
3296 c
->memory_max
= bytes
;
3297 else if (streq(lvalue
, "MemorySwapMax"))
3298 c
->memory_swap_max
= bytes
;
3299 else if (streq(lvalue
, "MemoryLimit"))
3300 c
->memory_limit
= bytes
;
3307 int config_parse_tasks_max(
3309 const char *filename
,
3311 const char *section
,
3312 unsigned section_line
,
3319 uint64_t *tasks_max
= data
, v
;
3323 if (isempty(rvalue
)) {
3324 *tasks_max
= u
->manager
->default_tasks_max
;
3328 if (streq(rvalue
, "infinity")) {
3329 *tasks_max
= CGROUP_LIMIT_MAX
;
3333 r
= parse_percent(rvalue
);
3335 r
= safe_atou64(rvalue
, &v
);
3337 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Maximum tasks value '%s' invalid. Ignoring.", rvalue
);
3341 v
= system_tasks_max_scale(r
, 100U);
3343 if (v
<= 0 || v
>= UINT64_MAX
) {
3344 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Maximum tasks value '%s' out of range. Ignoring.", rvalue
);
3352 int config_parse_delegate(
3354 const char *filename
,
3356 const char *section
,
3357 unsigned section_line
,
3364 CGroupContext
*c
= data
;
3368 t
= unit_name_to_type(unit
);
3369 assert(t
!= _UNIT_TYPE_INVALID
);
3371 if (!unit_vtable
[t
]->can_delegate
) {
3372 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Delegate= setting not supported for this unit type, ignoring.");
3376 /* We either accept a boolean value, which may be used to turn on delegation for all controllers, or turn it
3377 * off for all. Or it takes a list of controller names, in which case we add the specified controllers to the
3378 * mask to delegate. */
3380 if (isempty(rvalue
)) {
3381 /* An empty string resets controllers and set Delegate=yes. */
3383 c
->delegate_controllers
= 0;
3387 r
= parse_boolean(rvalue
);
3389 const char *p
= rvalue
;
3390 CGroupMask mask
= 0;
3393 _cleanup_free_
char *word
= NULL
;
3394 CGroupController cc
;
3396 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
3402 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3406 cc
= cgroup_controller_from_string(word
);
3408 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid controller name '%s', ignoring", rvalue
);
3412 mask
|= CGROUP_CONTROLLER_TO_MASK(cc
);
3416 c
->delegate_controllers
|= mask
;
3420 c
->delegate_controllers
= _CGROUP_MASK_ALL
;
3422 c
->delegate
= false;
3423 c
->delegate_controllers
= 0;
3429 int config_parse_device_allow(
3431 const char *filename
,
3433 const char *section
,
3434 unsigned section_line
,
3441 _cleanup_free_
char *path
= NULL
, *t
= NULL
;
3442 CGroupContext
*c
= data
;
3443 CGroupDeviceAllow
*a
;
3444 const char *m
= NULL
;
3448 if (isempty(rvalue
)) {
3449 while (c
->device_allow
)
3450 cgroup_context_free_device_allow(c
, c
->device_allow
);
3455 r
= unit_full_printf(userdata
, rvalue
, &t
);
3457 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3458 "Failed to resolve specifiers in %s, ignoring: %m",
3463 n
= strcspn(t
, WHITESPACE
);
3465 path
= strndup(t
, n
);
3469 if (!is_deviceallow_pattern(path
) &&
3470 !path_startswith(path
, "/run/systemd/inaccessible/")) {
3471 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device node path '%s'. Ignoring.", path
);
3475 m
= t
+ n
+ strspn(t
+ n
, WHITESPACE
);
3479 if (!in_charset(m
, "rwm")) {
3480 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device rights '%s'. Ignoring.", m
);
3484 a
= new0(CGroupDeviceAllow
, 1);
3488 a
->path
= TAKE_PTR(path
);
3489 a
->r
= !!strchr(m
, 'r');
3490 a
->w
= !!strchr(m
, 'w');
3491 a
->m
= !!strchr(m
, 'm');
3493 LIST_PREPEND(device_allow
, c
->device_allow
, a
);
3497 int config_parse_io_weight(
3499 const char *filename
,
3501 const char *section
,
3502 unsigned section_line
,
3509 uint64_t *weight
= data
;
3516 r
= cg_weight_parse(rvalue
, weight
);
3518 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "IO weight '%s' invalid. Ignoring.", rvalue
);
3525 int config_parse_io_device_weight(
3527 const char *filename
,
3529 const char *section
,
3530 unsigned section_line
,
3537 _cleanup_free_
char *path
= NULL
;
3538 CGroupIODeviceWeight
*w
;
3539 CGroupContext
*c
= data
;
3549 if (isempty(rvalue
)) {
3550 while (c
->io_device_weights
)
3551 cgroup_context_free_io_device_weight(c
, c
->io_device_weights
);
3556 n
= strcspn(rvalue
, WHITESPACE
);
3557 weight
= rvalue
+ n
;
3558 weight
+= strspn(weight
, WHITESPACE
);
3560 if (isempty(weight
)) {
3561 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Expected block device and device weight. Ignoring.");
3565 path
= strndup(rvalue
, n
);
3569 if (!path_startswith(path
, "/dev") &&
3570 !path_startswith(path
, "/run/systemd/inaccessible/")) {
3571 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device node path '%s'. Ignoring.", path
);
3575 r
= cg_weight_parse(weight
, &u
);
3577 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "IO weight '%s' invalid. Ignoring.", weight
);
3581 assert(u
!= CGROUP_WEIGHT_INVALID
);
3583 w
= new0(CGroupIODeviceWeight
, 1);
3587 w
->path
= TAKE_PTR(path
);
3591 LIST_PREPEND(device_weights
, c
->io_device_weights
, w
);
3595 int config_parse_io_limit(
3597 const char *filename
,
3599 const char *section
,
3600 unsigned section_line
,
3607 _cleanup_free_
char *path
= NULL
;
3608 CGroupIODeviceLimit
*l
= NULL
, *t
;
3609 CGroupContext
*c
= data
;
3610 CGroupIOLimitType type
;
3620 type
= cgroup_io_limit_type_from_string(lvalue
);
3623 if (isempty(rvalue
)) {
3624 LIST_FOREACH(device_limits
, l
, c
->io_device_limits
)
3625 l
->limits
[type
] = cgroup_io_limit_defaults
[type
];
3629 n
= strcspn(rvalue
, WHITESPACE
);
3631 limit
+= strspn(limit
, WHITESPACE
);
3634 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Expected space separated pair of device node and bandwidth. Ignoring.");
3638 path
= strndup(rvalue
, n
);
3642 if (!path_startswith(path
, "/dev") &&
3643 !path_startswith(path
, "/run/systemd/inaccessible/")) {
3644 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device node path '%s'. Ignoring.", path
);
3648 if (streq("infinity", limit
)) {
3649 num
= CGROUP_LIMIT_MAX
;
3651 r
= parse_size(limit
, 1000, &num
);
3652 if (r
< 0 || num
<= 0) {
3653 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "IO Limit '%s' invalid. Ignoring.", rvalue
);
3658 LIST_FOREACH(device_limits
, t
, c
->io_device_limits
) {
3659 if (path_equal(path
, t
->path
)) {
3666 CGroupIOLimitType ttype
;
3668 l
= new0(CGroupIODeviceLimit
, 1);
3672 l
->path
= TAKE_PTR(path
);
3673 for (ttype
= 0; ttype
< _CGROUP_IO_LIMIT_TYPE_MAX
; ttype
++)
3674 l
->limits
[ttype
] = cgroup_io_limit_defaults
[ttype
];
3676 LIST_PREPEND(device_limits
, c
->io_device_limits
, l
);
3679 l
->limits
[type
] = num
;
3684 int config_parse_blockio_weight(
3686 const char *filename
,
3688 const char *section
,
3689 unsigned section_line
,
3696 uint64_t *weight
= data
;
3703 r
= cg_blkio_weight_parse(rvalue
, weight
);
3705 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Block IO weight '%s' invalid. Ignoring.", rvalue
);
3712 int config_parse_blockio_device_weight(
3714 const char *filename
,
3716 const char *section
,
3717 unsigned section_line
,
3724 _cleanup_free_
char *path
= NULL
;
3725 CGroupBlockIODeviceWeight
*w
;
3726 CGroupContext
*c
= data
;
3736 if (isempty(rvalue
)) {
3737 while (c
->blockio_device_weights
)
3738 cgroup_context_free_blockio_device_weight(c
, c
->blockio_device_weights
);
3743 n
= strcspn(rvalue
, WHITESPACE
);
3744 weight
= rvalue
+ n
;
3745 weight
+= strspn(weight
, WHITESPACE
);
3747 if (isempty(weight
)) {
3748 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Expected block device and device weight. Ignoring.");
3752 path
= strndup(rvalue
, n
);
3756 if (!path_startswith(path
, "/dev") &&
3757 !path_startswith(path
, "/run/systemd/inaccessible/")) {
3758 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device node path '%s'. Ignoring.", path
);
3762 r
= cg_blkio_weight_parse(weight
, &u
);
3764 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Block IO weight '%s' invalid. Ignoring.", weight
);
3768 assert(u
!= CGROUP_BLKIO_WEIGHT_INVALID
);
3770 w
= new0(CGroupBlockIODeviceWeight
, 1);
3774 w
->path
= TAKE_PTR(path
);
3778 LIST_PREPEND(device_weights
, c
->blockio_device_weights
, w
);
3782 int config_parse_blockio_bandwidth(
3784 const char *filename
,
3786 const char *section
,
3787 unsigned section_line
,
3794 _cleanup_free_
char *path
= NULL
;
3795 CGroupBlockIODeviceBandwidth
*b
= NULL
, *t
;
3796 CGroupContext
*c
= data
;
3797 const char *bandwidth
;
3807 read
= streq("BlockIOReadBandwidth", lvalue
);
3809 if (isempty(rvalue
)) {
3810 LIST_FOREACH(device_bandwidths
, b
, c
->blockio_device_bandwidths
) {
3811 b
->rbps
= CGROUP_LIMIT_MAX
;
3812 b
->wbps
= CGROUP_LIMIT_MAX
;
3817 n
= strcspn(rvalue
, WHITESPACE
);
3818 bandwidth
= rvalue
+ n
;
3819 bandwidth
+= strspn(bandwidth
, WHITESPACE
);
3822 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Expected space separated pair of device node and bandwidth. Ignoring.");
3826 path
= strndup(rvalue
, n
);
3830 if (!path_startswith(path
, "/dev") &&
3831 !path_startswith(path
, "/run/systemd/inaccessible/")) {
3832 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device node path '%s'. Ignoring.", path
);
3836 r
= parse_size(bandwidth
, 1000, &bytes
);
3837 if (r
< 0 || bytes
<= 0) {
3838 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Block IO Bandwidth '%s' invalid. Ignoring.", rvalue
);
3842 LIST_FOREACH(device_bandwidths
, t
, c
->blockio_device_bandwidths
) {
3843 if (path_equal(path
, t
->path
)) {
3850 b
= new0(CGroupBlockIODeviceBandwidth
, 1);
3854 b
->path
= TAKE_PTR(path
);
3855 b
->rbps
= CGROUP_LIMIT_MAX
;
3856 b
->wbps
= CGROUP_LIMIT_MAX
;
3858 LIST_PREPEND(device_bandwidths
, c
->blockio_device_bandwidths
, b
);
3869 DEFINE_CONFIG_PARSE_ENUM(config_parse_job_mode
, job_mode
, JobMode
, "Failed to parse job mode");
3871 int config_parse_job_mode_isolate(
3873 const char *filename
,
3875 const char *section
,
3876 unsigned section_line
,
3890 r
= parse_boolean(rvalue
);
3892 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse boolean, ignoring: %s", rvalue
);
3896 log_notice("%s is deprecated. Please use OnFailureJobMode= instead", lvalue
);
3898 *m
= r
? JOB_ISOLATE
: JOB_REPLACE
;
3902 DEFINE_CONFIG_PARSE_ENUM(config_parse_runtime_preserve_mode
, exec_preserve_mode
, ExecPreserveMode
, "Failed to parse runtime directory preserve mode");
3904 int config_parse_exec_directories(
3906 const char *filename
,
3908 const char *section
,
3909 unsigned section_line
,
3926 if (isempty(rvalue
)) {
3927 /* Empty assignment resets the list */
3928 *rt
= strv_free(*rt
);
3932 for (p
= rvalue
;;) {
3933 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
3935 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
3939 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3940 "Invalid syntax, ignoring: %s", rvalue
);
3946 r
= unit_full_printf(u
, word
, &k
);
3948 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
3949 "Failed to resolve specifiers in \"%s\", ignoring: %m", word
);
3953 if (!path_is_normalized(k
)) {
3954 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
3955 "%s= path is not normalized, ignoring assignment: %s", lvalue
, rvalue
);
3959 if (path_is_absolute(k
)) {
3960 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
3961 "%s= path is absolute, ignoring assignment: %s", lvalue
, rvalue
);
3965 if (path_startswith(k
, "private")) {
3966 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
3967 "%s= path can't be 'private', ingoring assignment: %s", lvalue
, rvalue
);
3971 r
= strv_push(rt
, k
);
3978 int config_parse_set_status(
3980 const char *filename
,
3982 const char *section
,
3983 unsigned section_line
,
3991 const char *word
, *state
;
3993 ExitStatusSet
*status_set
= data
;
4000 /* Empty assignment resets the list */
4001 if (isempty(rvalue
)) {
4002 exit_status_set_free(status_set
);
4006 FOREACH_WORD(word
, l
, rvalue
, state
) {
4007 _cleanup_free_
char *temp
;
4011 temp
= strndup(word
, l
);
4015 r
= safe_atoi(temp
, &val
);
4017 val
= signal_from_string(temp
);
4020 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse value, ignoring: %s", word
);
4023 set
= &status_set
->signal
;
4025 if (val
< 0 || val
> 255) {
4026 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Value %d is outside range 0-255, ignoring", val
);
4029 set
= &status_set
->status
;
4032 r
= set_ensure_allocated(set
, NULL
);
4036 r
= set_put(*set
, INT_TO_PTR(val
));
4038 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Unable to store: %s", word
);
4042 if (!isempty(state
))
4043 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Trailing garbage, ignoring.");
4048 int config_parse_namespace_path_strv(
4050 const char *filename
,
4052 const char *section
,
4053 unsigned section_line
,
4070 if (isempty(rvalue
)) {
4071 /* Empty assignment resets the list */
4072 *sv
= strv_free(*sv
);
4078 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
, *joined
= NULL
;
4080 bool ignore_enoent
= false, shall_prefix
= false;
4082 r
= extract_first_word(&cur
, &word
, NULL
, EXTRACT_QUOTES
);
4088 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
4092 if (!utf8_is_valid(word
)) {
4093 log_syntax_invalid_utf8(unit
, LOG_ERR
, filename
, line
, word
);
4098 if (startswith(w
, "-")) {
4099 ignore_enoent
= true;
4102 if (startswith(w
, "+")) {
4103 shall_prefix
= true;
4107 r
= unit_full_printf(u
, w
, &resolved
);
4109 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve specifiers in %s: %m", word
);
4113 if (!path_is_absolute(resolved
)) {
4114 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Not an absolute path, ignoring: %s", resolved
);
4118 path_kill_slashes(resolved
);
4120 joined
= strjoin(ignore_enoent
? "-" : "",
4121 shall_prefix
? "+" : "",
4124 r
= strv_push(sv
, joined
);
4134 int config_parse_temporary_filesystems(
4136 const char *filename
,
4138 const char *section
,
4139 unsigned section_line
,
4147 ExecContext
*c
= data
;
4156 if (isempty(rvalue
)) {
4157 /* Empty assignment resets the list */
4158 temporary_filesystem_free_many(c
->temporary_filesystems
, c
->n_temporary_filesystems
);
4159 c
->temporary_filesystems
= NULL
;
4160 c
->n_temporary_filesystems
= 0;
4166 _cleanup_free_
char *word
= NULL
, *path
= NULL
, *resolved
= NULL
;
4169 r
= extract_first_word(&cur
, &word
, NULL
, EXTRACT_QUOTES
);
4175 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
4180 r
= extract_first_word(&w
, &path
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4186 r
= unit_full_printf(u
, path
, &resolved
);
4188 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve specifiers in %s, ignoring: %m", word
);
4192 if (!path_is_absolute(resolved
)) {
4193 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Not an absolute path, ignoring: %s", resolved
);
4197 path_kill_slashes(resolved
);
4199 r
= temporary_filesystem_add(&c
->temporary_filesystems
, &c
->n_temporary_filesystems
, path
, w
);
4203 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse mount options, ignoring: %s", word
);
4211 int config_parse_bind_paths(
4213 const char *filename
,
4215 const char *section
,
4216 unsigned section_line
,
4223 ExecContext
*c
= data
;
4233 if (isempty(rvalue
)) {
4234 /* Empty assignment resets the list */
4235 bind_mount_free_many(c
->bind_mounts
, c
->n_bind_mounts
);
4236 c
->bind_mounts
= NULL
;
4237 c
->n_bind_mounts
= 0;
4243 _cleanup_free_
char *source
= NULL
, *destination
= NULL
;
4244 _cleanup_free_
char *sresolved
= NULL
, *dresolved
= NULL
;
4245 char *s
= NULL
, *d
= NULL
;
4246 bool rbind
= true, ignore_enoent
= false;
4248 r
= extract_first_word(&p
, &source
, ":" WHITESPACE
, EXTRACT_QUOTES
|EXTRACT_DONT_COALESCE_SEPARATORS
);
4254 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s: %s", lvalue
, rvalue
);
4258 r
= unit_full_printf(u
, source
, &sresolved
);
4260 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4261 "Failed to resolved specifiers in \"%s\", ignoring: %m", source
);
4267 ignore_enoent
= true;
4271 if (!utf8_is_valid(s
)) {
4272 log_syntax_invalid_utf8(unit
, LOG_ERR
, filename
, line
, s
);
4275 if (!path_is_absolute(s
)) {
4276 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Not an absolute source path, ignoring: %s", s
);
4280 path_kill_slashes(s
);
4282 /* Optionally, the destination is specified. */
4283 if (p
&& p
[-1] == ':') {
4284 r
= extract_first_word(&p
, &destination
, ":" WHITESPACE
, EXTRACT_QUOTES
|EXTRACT_DONT_COALESCE_SEPARATORS
);
4288 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s: %s", lvalue
, rvalue
);
4292 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Missing argument after ':': %s", rvalue
);
4296 r
= unit_full_printf(u
, destination
, &dresolved
);
4298 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4299 "Failed to resolved specifiers in \"%s\", ignoring: %m", destination
);
4303 if (!utf8_is_valid(dresolved
)) {
4304 log_syntax_invalid_utf8(unit
, LOG_ERR
, filename
, line
, dresolved
);
4307 if (!path_is_absolute(dresolved
)) {
4308 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Not an absolute destination path, ignoring: %s", dresolved
);
4312 d
= path_kill_slashes(dresolved
);
4314 /* Optionally, there's also a short option string specified */
4315 if (p
&& p
[-1] == ':') {
4316 _cleanup_free_
char *options
= NULL
;
4318 r
= extract_first_word(&p
, &options
, NULL
, EXTRACT_QUOTES
);
4322 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s: %s", lvalue
, rvalue
);
4326 if (isempty(options
) || streq(options
, "rbind"))
4328 else if (streq(options
, "norbind"))
4331 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid option string, ignoring setting: %s", options
);
4338 r
= bind_mount_add(&c
->bind_mounts
, &c
->n_bind_mounts
,
4342 .read_only
= !!strstr(lvalue
, "ReadOnly"),
4344 .ignore_enoent
= ignore_enoent
,
4353 int config_parse_no_new_privileges(
4355 const char *filename
,
4357 const char *section
,
4358 unsigned section_line
,
4365 ExecContext
*c
= data
;
4373 k
= parse_boolean(rvalue
);
4375 log_syntax(unit
, LOG_ERR
, filename
, line
, k
, "Failed to parse boolean value, ignoring: %s", rvalue
);
4379 c
->no_new_privileges
= k
;
4384 int config_parse_protect_home(
4386 const char *filename
,
4388 const char *section
,
4389 unsigned section_line
,
4396 ExecContext
*c
= data
;
4404 /* Our enum shall be a superset of booleans, hence first try
4405 * to parse as boolean, and then as enum */
4407 h
= parse_protect_home_or_bool(rvalue
);
4409 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse protect home value, ignoring: %s", rvalue
);
4413 c
->protect_home
= h
;
4418 int config_parse_protect_system(
4420 const char *filename
,
4422 const char *section
,
4423 unsigned section_line
,
4430 ExecContext
*c
= data
;
4438 /* Our enum shall be a superset of booleans, hence first try
4439 * to parse as boolean, and then as enum */
4441 s
= parse_protect_system_or_bool(rvalue
);
4443 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse protect system value, ignoring: %s", rvalue
);
4447 c
->protect_system
= s
;
4452 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_keyring_mode
, exec_keyring_mode
, ExecKeyringMode
, "Failed to parse keyring mode");
4454 int config_parse_job_timeout_sec(
4456 const char *filename
,
4458 const char *section
,
4459 unsigned section_line
,
4475 r
= parse_sec_fix_0(rvalue
, &usec
);
4477 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse JobTimeoutSec= parameter, ignoring: %s", rvalue
);
4481 /* If the user explicitly changed JobTimeoutSec= also change JobRunningTimeoutSec=, for compatibility with old
4482 * versions. If JobRunningTimeoutSec= was explicitly set, avoid this however as whatever the user picked should
4485 if (!u
->job_running_timeout_set
)
4486 u
->job_running_timeout
= usec
;
4488 u
->job_timeout
= usec
;
4493 int config_parse_job_running_timeout_sec(
4495 const char *filename
,
4497 const char *section
,
4498 unsigned section_line
,
4514 r
= parse_sec_fix_0(rvalue
, &usec
);
4516 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse JobRunningTimeoutSec= parameter, ignoring: %s", rvalue
);
4520 u
->job_running_timeout
= usec
;
4521 u
->job_running_timeout_set
= true;
4526 #define FOLLOW_MAX 8
4528 static int open_follow(char **filename
, FILE **_f
, Set
*names
, char **_final
) {
4539 /* This will update the filename pointer if the loaded file is
4540 * reached by a symlink. The old string will be freed. */
4543 char *target
, *name
;
4545 if (c
++ >= FOLLOW_MAX
)
4548 path_kill_slashes(*filename
);
4550 /* Add the file name we are currently looking at to
4551 * the names of this unit, but only if it is a valid
4553 name
= basename(*filename
);
4554 if (unit_name_is_valid(name
, UNIT_NAME_ANY
)) {
4556 id
= set_get(names
, name
);
4562 r
= set_consume(names
, id
);
4568 /* Try to open the file name, but don't if its a symlink */
4569 fd
= open(*filename
, O_RDONLY
|O_CLOEXEC
|O_NOCTTY
|O_NOFOLLOW
);
4576 /* Hmm, so this is a symlink. Let's read the name, and follow it manually */
4577 r
= readlink_and_make_absolute(*filename
, &target
);
4585 f
= fdopen(fd
, "re");
4597 static int merge_by_names(Unit
**u
, Set
*names
, const char *id
) {
4605 /* Let's try to add in all symlink names we found */
4606 while ((k
= set_steal_first(names
))) {
4608 /* First try to merge in the other name into our
4610 r
= unit_merge_by_name(*u
, k
);
4614 /* Hmm, we couldn't merge the other unit into
4615 * ours? Then let's try it the other way
4618 /* If the symlink name we are looking at is unit template, then
4619 we must search for instance of this template */
4620 if (unit_name_is_valid(k
, UNIT_NAME_TEMPLATE
) && (*u
)->instance
) {
4621 _cleanup_free_
char *instance
= NULL
;
4623 r
= unit_name_replace_instance(k
, (*u
)->instance
, &instance
);
4627 other
= manager_get_unit((*u
)->manager
, instance
);
4629 other
= manager_get_unit((*u
)->manager
, k
);
4634 r
= unit_merge(other
, *u
);
4637 return merge_by_names(u
, names
, NULL
);
4645 unit_choose_id(*u
, id
);
4653 static int load_from_path(Unit
*u
, const char *path
) {
4654 _cleanup_set_free_free_ Set
*symlink_names
= NULL
;
4655 _cleanup_fclose_
FILE *f
= NULL
;
4656 _cleanup_free_
char *filename
= NULL
;
4665 symlink_names
= set_new(&string_hash_ops
);
4669 if (path_is_absolute(path
)) {
4671 filename
= strdup(path
);
4675 r
= open_follow(&filename
, &f
, symlink_names
, &id
);
4677 filename
= mfree(filename
);
4685 STRV_FOREACH(p
, u
->manager
->lookup_paths
.search_path
) {
4687 /* Instead of opening the path right away, we manually
4688 * follow all symlinks and add their name to our unit
4689 * name set while doing so */
4690 filename
= path_make_absolute(path
, *p
);
4694 if (u
->manager
->unit_path_cache
&&
4695 !set_get(u
->manager
->unit_path_cache
, filename
))
4698 r
= open_follow(&filename
, &f
, symlink_names
, &id
);
4701 filename
= mfree(filename
);
4703 /* ENOENT means that the file is missing or is a dangling symlink.
4704 * ENOTDIR means that one of paths we expect to be is a directory
4705 * is not a directory, we should just ignore that.
4706 * EACCES means that the directory or file permissions are wrong.
4709 log_debug_errno(r
, "Cannot access \"%s\": %m", filename
);
4710 else if (!IN_SET(r
, -ENOENT
, -ENOTDIR
))
4713 /* Empty the symlink names for the next run */
4714 set_clear_free(symlink_names
);
4719 /* Hmm, no suitable file found? */
4722 if (!unit_type_may_alias(u
->type
) && set_size(symlink_names
) > 1) {
4723 log_unit_warning(u
, "Unit type of %s does not support alias names, refusing loading via symlink.", u
->id
);
4728 r
= merge_by_names(&merged
, symlink_names
, id
);
4733 u
->load_state
= UNIT_MERGED
;
4737 if (fstat(fileno(f
), &st
) < 0)
4740 if (null_or_empty(&st
)) {
4741 u
->load_state
= UNIT_MASKED
;
4742 u
->fragment_mtime
= 0;
4744 u
->load_state
= UNIT_LOADED
;
4745 u
->fragment_mtime
= timespec_load(&st
.st_mtim
);
4747 /* Now, parse the file contents */
4748 r
= config_parse(u
->id
, filename
, f
,
4749 UNIT_VTABLE(u
)->sections
,
4750 config_item_perf_lookup
, load_fragment_gperf_lookup
,
4751 CONFIG_PARSE_ALLOW_INCLUDE
, u
);
4756 free_and_replace(u
->fragment_path
, filename
);
4758 if (u
->source_path
) {
4759 if (stat(u
->source_path
, &st
) >= 0)
4760 u
->source_mtime
= timespec_load(&st
.st_mtim
);
4762 u
->source_mtime
= 0;
4768 int unit_load_fragment(Unit
*u
) {
4774 assert(u
->load_state
== UNIT_STUB
);
4778 u
->load_state
= UNIT_LOADED
;
4782 /* First, try to find the unit under its id. We always look
4783 * for unit files in the default directories, to make it easy
4784 * to override things by placing things in /etc/systemd/system */
4785 r
= load_from_path(u
, u
->id
);
4789 /* Try to find an alias we can load this with */
4790 if (u
->load_state
== UNIT_STUB
) {
4791 SET_FOREACH(t
, u
->names
, i
) {
4796 r
= load_from_path(u
, t
);
4800 if (u
->load_state
!= UNIT_STUB
)
4805 /* And now, try looking for it under the suggested (originally linked) path */
4806 if (u
->load_state
== UNIT_STUB
&& u
->fragment_path
) {
4808 r
= load_from_path(u
, u
->fragment_path
);
4812 if (u
->load_state
== UNIT_STUB
)
4813 /* Hmm, this didn't work? Then let's get rid
4814 * of the fragment path stored for us, so that
4815 * we don't point to an invalid location. */
4816 u
->fragment_path
= mfree(u
->fragment_path
);
4819 /* Look for a template */
4820 if (u
->load_state
== UNIT_STUB
&& u
->instance
) {
4821 _cleanup_free_
char *k
= NULL
;
4823 r
= unit_name_template(u
->id
, &k
);
4827 r
= load_from_path(u
, k
);
4830 log_unit_notice(u
, "Unit configuration has fatal error, unit will not be started.");
4834 if (u
->load_state
== UNIT_STUB
) {
4835 SET_FOREACH(t
, u
->names
, i
) {
4836 _cleanup_free_
char *z
= NULL
;
4841 r
= unit_name_template(t
, &z
);
4845 r
= load_from_path(u
, z
);
4849 if (u
->load_state
!= UNIT_STUB
)
4858 void unit_dump_config_items(FILE *f
) {
4859 static const struct {
4860 const ConfigParserCallback callback
;
4863 #if !HAVE_SYSV_COMPAT || !HAVE_SECCOMP || !HAVE_PAM || !HAVE_SELINUX || !ENABLE_SMACK || !HAVE_APPARMOR
4864 { config_parse_warn_compat
, "NOTSUPPORTED" },
4866 { config_parse_int
, "INTEGER" },
4867 { config_parse_unsigned
, "UNSIGNED" },
4868 { config_parse_iec_size
, "SIZE" },
4869 { config_parse_iec_uint64
, "SIZE" },
4870 { config_parse_si_size
, "SIZE" },
4871 { config_parse_bool
, "BOOLEAN" },
4872 { config_parse_string
, "STRING" },
4873 { config_parse_path
, "PATH" },
4874 { config_parse_unit_path_printf
, "PATH" },
4875 { config_parse_strv
, "STRING [...]" },
4876 { config_parse_exec_nice
, "NICE" },
4877 { config_parse_exec_oom_score_adjust
, "OOMSCOREADJUST" },
4878 { config_parse_exec_io_class
, "IOCLASS" },
4879 { config_parse_exec_io_priority
, "IOPRIORITY" },
4880 { config_parse_exec_cpu_sched_policy
, "CPUSCHEDPOLICY" },
4881 { config_parse_exec_cpu_sched_prio
, "CPUSCHEDPRIO" },
4882 { config_parse_exec_cpu_affinity
, "CPUAFFINITY" },
4883 { config_parse_mode
, "MODE" },
4884 { config_parse_unit_env_file
, "FILE" },
4885 { config_parse_exec_output
, "OUTPUT" },
4886 { config_parse_exec_input
, "INPUT" },
4887 { config_parse_log_facility
, "FACILITY" },
4888 { config_parse_log_level
, "LEVEL" },
4889 { config_parse_exec_secure_bits
, "SECUREBITS" },
4890 { config_parse_capability_set
, "BOUNDINGSET" },
4891 { config_parse_rlimit
, "LIMIT" },
4892 { config_parse_unit_deps
, "UNIT [...]" },
4893 { config_parse_exec
, "PATH [ARGUMENT [...]]" },
4894 { config_parse_service_type
, "SERVICETYPE" },
4895 { config_parse_service_restart
, "SERVICERESTART" },
4896 #if HAVE_SYSV_COMPAT
4897 { config_parse_sysv_priority
, "SYSVPRIORITY" },
4899 { config_parse_kill_mode
, "KILLMODE" },
4900 { config_parse_signal
, "SIGNAL" },
4901 { config_parse_socket_listen
, "SOCKET [...]" },
4902 { config_parse_socket_bind
, "SOCKETBIND" },
4903 { config_parse_socket_bindtodevice
, "NETWORKINTERFACE" },
4904 { config_parse_sec
, "SECONDS" },
4905 { config_parse_nsec
, "NANOSECONDS" },
4906 { config_parse_namespace_path_strv
, "PATH [...]" },
4907 { config_parse_bind_paths
, "PATH[:PATH[:OPTIONS]] [...]" },
4908 { config_parse_unit_requires_mounts_for
, "PATH [...]" },
4909 { config_parse_exec_mount_flags
, "MOUNTFLAG [...]" },
4910 { config_parse_unit_string_printf
, "STRING" },
4911 { config_parse_trigger_unit
, "UNIT" },
4912 { config_parse_timer
, "TIMER" },
4913 { config_parse_path_spec
, "PATH" },
4914 { config_parse_notify_access
, "ACCESS" },
4915 { config_parse_ip_tos
, "TOS" },
4916 { config_parse_unit_condition_path
, "CONDITION" },
4917 { config_parse_unit_condition_string
, "CONDITION" },
4918 { config_parse_unit_condition_null
, "CONDITION" },
4919 { config_parse_unit_slice
, "SLICE" },
4920 { config_parse_documentation
, "URL" },
4921 { config_parse_service_timeout
, "SECONDS" },
4922 { config_parse_emergency_action
, "ACTION" },
4923 { config_parse_set_status
, "STATUS" },
4924 { config_parse_service_sockets
, "SOCKETS" },
4925 { config_parse_environ
, "ENVIRON" },
4927 { config_parse_syscall_filter
, "SYSCALLS" },
4928 { config_parse_syscall_archs
, "ARCHS" },
4929 { config_parse_syscall_errno
, "ERRNO" },
4930 { config_parse_address_families
, "FAMILIES" },
4931 { config_parse_restrict_namespaces
, "NAMESPACES" },
4933 { config_parse_cpu_shares
, "SHARES" },
4934 { config_parse_cpu_weight
, "WEIGHT" },
4935 { config_parse_memory_limit
, "LIMIT" },
4936 { config_parse_device_allow
, "DEVICE" },
4937 { config_parse_device_policy
, "POLICY" },
4938 { config_parse_io_limit
, "LIMIT" },
4939 { config_parse_io_weight
, "WEIGHT" },
4940 { config_parse_io_device_weight
, "DEVICEWEIGHT" },
4941 { config_parse_blockio_bandwidth
, "BANDWIDTH" },
4942 { config_parse_blockio_weight
, "WEIGHT" },
4943 { config_parse_blockio_device_weight
, "DEVICEWEIGHT" },
4944 { config_parse_long
, "LONG" },
4945 { config_parse_socket_service
, "SERVICE" },
4947 { config_parse_exec_selinux_context
, "LABEL" },
4949 { config_parse_job_mode
, "MODE" },
4950 { config_parse_job_mode_isolate
, "BOOLEAN" },
4951 { config_parse_personality
, "PERSONALITY" },
4954 const char *prev
= NULL
;
4959 NULSTR_FOREACH(i
, load_fragment_gperf_nulstr
) {
4960 const char *rvalue
= "OTHER", *lvalue
;
4964 const ConfigPerfItem
*p
;
4966 assert_se(p
= load_fragment_gperf_lookup(i
, strlen(i
)));
4968 dot
= strchr(i
, '.');
4969 lvalue
= dot
? dot
+ 1 : i
;
4973 if (!prev
|| !strneq(prev
, i
, prefix_len
+1)) {
4977 fprintf(f
, "[%.*s]\n", (int) prefix_len
, i
);
4980 for (j
= 0; j
< ELEMENTSOF(table
); j
++)
4981 if (p
->parse
== table
[j
].callback
) {
4982 rvalue
= table
[j
].rvalue
;
4986 fprintf(f
, "%s=%s\n", lvalue
, rvalue
);