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"
48 #include "rlimit-util.h"
50 #include "seccomp-util.h"
52 #include "securebits.h"
53 #include "securebits-util.h"
54 #include "signal-util.h"
55 #include "socket-protocol-list.h"
56 #include "stat-util.h"
57 #include "string-util.h"
59 #include "unit-name.h"
60 #include "unit-printf.h"
61 #include "user-util.h"
65 DEFINE_CONFIG_PARSE_ENUM(config_parse_collect_mode
, collect_mode
, CollectMode
, "Failed to parse garbage collection mode");
67 int config_parse_unit_deps(
72 unsigned section_line
,
79 UnitDependency d
= ltype
;
89 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
92 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_RETAIN_ESCAPE
);
98 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
102 r
= unit_name_printf(u
, word
, &k
);
104 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve specifiers, ignoring: %m");
108 r
= unit_add_dependency_by_name(u
, d
, k
, NULL
, true, UNIT_DEPENDENCY_FILE
);
110 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
116 int config_parse_obsolete_unit_deps(
118 const char *filename
,
121 unsigned section_line
,
128 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
129 "Unit dependency type %s= is obsolete, replacing by %s=, please update your unit file", lvalue
, unit_dependency_to_string(ltype
));
131 return config_parse_unit_deps(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
);
134 int config_parse_unit_string_printf(
136 const char *filename
,
139 unsigned section_line
,
146 _cleanup_free_
char *k
= NULL
;
155 r
= unit_full_printf(u
, rvalue
, &k
);
157 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers on %s, ignoring: %m", rvalue
);
161 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
164 int config_parse_unit_strv_printf(
166 const char *filename
,
169 unsigned section_line
,
177 _cleanup_free_
char *k
= NULL
;
185 r
= unit_full_printf(u
, rvalue
, &k
);
187 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers on %s, ignoring: %m", rvalue
);
191 return config_parse_strv(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
194 int config_parse_unit_path_printf(
196 const char *filename
,
199 unsigned section_line
,
206 _cleanup_free_
char *k
= NULL
;
216 /* Let's not bother with anything that is too long */
217 if (strlen(rvalue
) >= PATH_MAX
) {
218 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
219 "%s value too long%s.",
220 lvalue
, fatal
? "" : ", ignoring");
221 return fatal
? -ENAMETOOLONG
: 0;
224 r
= unit_full_printf(u
, rvalue
, &k
);
226 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
227 "Failed to resolve unit specifiers in \"%s\"%s: %m",
228 rvalue
, fatal
? "" : ", ignoring");
229 return fatal
? -ENOEXEC
: 0;
232 return config_parse_path(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
235 int config_parse_unit_path_strv_printf(
237 const char *filename
,
240 unsigned section_line
,
257 if (isempty(rvalue
)) {
263 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
265 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
271 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
272 "Invalid syntax, ignoring: %s", rvalue
);
276 r
= unit_full_printf(u
, word
, &k
);
278 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
279 "Failed to resolve unit specifiers on \"%s\", ignoring: %m", word
);
283 if (!utf8_is_valid(k
)) {
284 log_syntax_invalid_utf8(unit
, LOG_ERR
, filename
, line
, rvalue
);
288 if (!path_is_absolute(k
)) {
289 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
290 "Symlink path is not absolute: %s", k
);
294 path_kill_slashes(k
);
303 int config_parse_socket_listen(const char *unit
,
304 const char *filename
,
307 unsigned section_line
,
314 _cleanup_free_ SocketPort
*p
= NULL
;
326 if (isempty(rvalue
)) {
327 /* An empty assignment removes all ports */
328 socket_free_ports(s
);
332 p
= new0(SocketPort
, 1);
336 if (ltype
!= SOCKET_SOCKET
) {
339 r
= unit_full_printf(UNIT(s
), rvalue
, &p
->path
);
341 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers on %s, ignoring: %m", rvalue
);
345 path_kill_slashes(p
->path
);
347 } else if (streq(lvalue
, "ListenNetlink")) {
348 _cleanup_free_
char *k
= NULL
;
350 p
->type
= SOCKET_SOCKET
;
351 r
= unit_full_printf(UNIT(s
), rvalue
, &k
);
353 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers on %s, ignoring: %m", rvalue
);
357 r
= socket_address_parse_netlink(&p
->address
, k
);
359 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse address value, ignoring: %s", rvalue
);
364 _cleanup_free_
char *k
= NULL
;
366 p
->type
= SOCKET_SOCKET
;
367 r
= unit_full_printf(UNIT(s
), rvalue
, &k
);
369 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers on %s, ignoring: %m", rvalue
);
373 r
= socket_address_parse_and_warn(&p
->address
, k
);
375 if (r
!= -EAFNOSUPPORT
)
376 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse address value, ignoring: %s", rvalue
);
380 if (streq(lvalue
, "ListenStream"))
381 p
->address
.type
= SOCK_STREAM
;
382 else if (streq(lvalue
, "ListenDatagram"))
383 p
->address
.type
= SOCK_DGRAM
;
385 assert(streq(lvalue
, "ListenSequentialPacket"));
386 p
->address
.type
= SOCK_SEQPACKET
;
389 if (socket_address_family(&p
->address
) != AF_LOCAL
&& p
->address
.type
== SOCK_SEQPACKET
) {
390 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Address family not supported, ignoring: %s", rvalue
);
396 p
->auxiliary_fds
= NULL
;
397 p
->n_auxiliary_fds
= 0;
400 LIST_FIND_TAIL(port
, s
->ports
, tail
);
401 LIST_INSERT_AFTER(port
, s
->ports
, tail
, p
);
408 int config_parse_socket_protocol(const char *unit
,
409 const char *filename
,
412 unsigned section_line
,
428 r
= socket_protocol_from_name(rvalue
);
430 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid socket protocol, ignoring: %s", rvalue
);
432 } else if (!IN_SET(r
, IPPROTO_UDPLITE
, IPPROTO_SCTP
)) {
433 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Socket protocol not supported, ignoring: %s", rvalue
);
437 s
->socket_protocol
= r
;
442 int config_parse_socket_bind(const char *unit
,
443 const char *filename
,
446 unsigned section_line
,
454 SocketAddressBindIPv6Only b
;
463 b
= parse_socket_address_bind_ipv6_only_or_bool(rvalue
);
465 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse bind IPv6 only value, ignoring: %s", rvalue
);
469 s
->bind_ipv6_only
= b
;
474 int config_parse_exec_nice(
476 const char *filename
,
479 unsigned section_line
,
486 ExecContext
*c
= data
;
494 r
= parse_nice(rvalue
, &priority
);
497 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Nice priority out of range, ignoring: %s", rvalue
);
499 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse nice priority, ignoring: %s", rvalue
);
510 int config_parse_exec_oom_score_adjust(const char* unit
,
511 const char *filename
,
514 unsigned section_line
,
521 ExecContext
*c
= data
;
529 r
= safe_atoi(rvalue
, &oa
);
531 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse the OOM score adjust value, ignoring: %s", rvalue
);
535 if (oa
< OOM_SCORE_ADJ_MIN
|| oa
> OOM_SCORE_ADJ_MAX
) {
536 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "OOM score adjust value out of range, ignoring: %s", rvalue
);
540 c
->oom_score_adjust
= oa
;
541 c
->oom_score_adjust_set
= true;
546 int config_parse_exec(
548 const char *filename
,
551 unsigned section_line
,
558 ExecCommand
**e
= data
;
570 rvalue
+= strspn(rvalue
, WHITESPACE
);
572 if (isempty(rvalue
)) {
573 /* An empty assignment resets the list */
574 *e
= exec_command_free_list(*e
);
580 _cleanup_free_
char *path
= NULL
, *firstword
= NULL
;
581 ExecCommandFlags flags
= 0;
582 bool ignore
= false, separate_argv0
= false;
583 _cleanup_free_ ExecCommand
*nce
= NULL
;
584 _cleanup_strv_free_
char **n
= NULL
;
585 size_t nlen
= 0, nbufsize
= 0;
590 r
= extract_first_word_and_warn(&p
, &firstword
, NULL
, EXTRACT_QUOTES
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
596 /* We accept an absolute path as first argument. If it's prefixed with - and the path doesn't
597 * exist, we ignore it instead of erroring out; if it's prefixed with @, we allow overriding of
598 * argv[0]; if it's prefixed with +, it will be run with full privileges and no sandboxing; if
599 * it's prefixed with '!' we apply sandboxing, but do not change user/group credentials; if
600 * it's prefixed with '!!', then we apply user/group credentials if the kernel supports ambient
601 * capabilities -- if it doesn't we don't apply the credentials themselves, but do apply most
602 * other sandboxing, with some special exceptions for changing UID.
604 * The idea is that '!!' may be used to write services that can take benefit of systemd's
605 * UID/GID dropping if the kernel supports ambient creds, but provide an automatic fallback to
606 * privilege dropping within the daemon if the kernel does not offer that. */
608 if (*f
== '-' && !(flags
& EXEC_COMMAND_IGNORE_FAILURE
)) {
609 flags
|= EXEC_COMMAND_IGNORE_FAILURE
;
611 } else if (*f
== '@' && !separate_argv0
)
612 separate_argv0
= true;
613 else if (*f
== '+' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
614 flags
|= EXEC_COMMAND_FULLY_PRIVILEGED
;
615 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
616 flags
|= EXEC_COMMAND_NO_SETUID
;
617 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_AMBIENT_MAGIC
))) {
618 flags
&= ~EXEC_COMMAND_NO_SETUID
;
619 flags
|= EXEC_COMMAND_AMBIENT_MAGIC
;
625 r
= unit_full_printf(u
, f
, &path
);
627 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
628 "Failed to resolve unit specifiers on %s%s: %m",
629 f
, ignore
? ", ignoring" : "");
630 return ignore
? 0 : -ENOEXEC
;
634 /* First word is either "-" or "@" with no command. */
635 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
636 "Empty path in command line%s: \"%s\"",
637 ignore
? ", ignoring" : "", rvalue
);
638 return ignore
? 0 : -ENOEXEC
;
640 if (!string_is_safe(path
)) {
641 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
642 "Executable name contains special characters%s: %s",
643 ignore
? ", ignoring" : "", path
);
644 return ignore
? 0 : -ENOEXEC
;
646 if (endswith(path
, "/")) {
647 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
648 "Executable path specifies a directory%s: %s",
649 ignore
? ", ignoring" : "", path
);
650 return ignore
? 0 : -ENOEXEC
;
653 if (!path_is_absolute(path
)) {
657 if (!filename_is_valid(path
)) {
658 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
659 "Neither a valid executable name nor an absolute path%s: %s",
660 ignore
? ", ignoring" : "", path
);
661 return ignore
? 0 : -ENOEXEC
;
664 /* Resolve a single-component name to a full path */
665 NULSTR_FOREACH(prefix
, DEFAULT_PATH_NULSTR
) {
666 _cleanup_free_
char *fullpath
= NULL
;
668 fullpath
= strjoin(prefix
, "/", path
);
672 if (access(fullpath
, F_OK
) >= 0) {
673 free_and_replace(path
, fullpath
);
680 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
681 "Executable \"%s\" not found in path \"%s\"%s",
682 path
, DEFAULT_PATH
, ignore
? ", ignoring" : "");
683 return ignore
? 0 : -ENOEXEC
;
687 if (!separate_argv0
) {
690 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
700 path_kill_slashes(path
);
702 while (!isempty(p
)) {
703 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
705 /* Check explicitly for an unquoted semicolon as
706 * command separator token. */
707 if (p
[0] == ';' && (!p
[1] || strchr(WHITESPACE
, p
[1]))) {
709 p
+= strspn(p
, WHITESPACE
);
714 /* Check for \; explicitly, to not confuse it with \\; or "\;" or "\\;" etc.
715 * extract_first_word() would return the same for all of those. */
716 if (p
[0] == '\\' && p
[1] == ';' && (!p
[2] || strchr(WHITESPACE
, p
[2]))) {
720 p
+= strspn(p
, WHITESPACE
);
722 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
733 r
= extract_first_word_and_warn(&p
, &word
, NULL
, EXTRACT_QUOTES
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
737 return ignore
? 0 : -ENOEXEC
;
739 r
= unit_full_printf(u
, word
, &resolved
);
741 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
742 "Failed to resolve unit specifiers on %s%s: %m",
743 word
, ignore
? ", ignoring" : "");
744 return ignore
? 0 : -ENOEXEC
;
747 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
750 n
[nlen
++] = TAKE_PTR(resolved
);
755 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
756 "Empty executable name or zeroeth argument%s: %s",
757 ignore
? ", ignoring" : "", rvalue
);
758 return ignore
? 0 : -ENOEXEC
;
761 nce
= new0(ExecCommand
, 1);
765 nce
->argv
= TAKE_PTR(n
);
766 nce
->path
= TAKE_PTR(path
);
769 exec_command_append_list(e
, nce
);
771 /* Do not _cleanup_free_ these. */
780 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_type
, service_type
, ServiceType
, "Failed to parse service type");
781 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart
, service_restart
, ServiceRestart
, "Failed to parse service restart specifier");
783 int config_parse_socket_bindtodevice(
785 const char *filename
,
788 unsigned section_line
,
803 if (rvalue
[0] && !streq(rvalue
, "*")) {
804 if (!ifname_valid(rvalue
)) {
805 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Interface name is invalid, ignoring: %s", rvalue
);
815 free_and_replace(s
->bind_to_device
, n
);
820 int config_parse_exec_input(
822 const char *filename
,
825 unsigned section_line
,
832 ExecContext
*c
= data
;
843 n
= startswith(rvalue
, "fd:");
845 _cleanup_free_
char *resolved
= NULL
;
847 r
= unit_full_printf(u
, n
, &resolved
);
849 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers on %s: %m", n
);
851 if (isempty(resolved
))
852 resolved
= mfree(resolved
);
853 else if (!fdname_is_valid(resolved
)) {
854 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name: %s", resolved
);
858 free_and_replace(c
->stdio_fdname
[STDIN_FILENO
], resolved
);
860 ei
= EXEC_INPUT_NAMED_FD
;
862 } else if ((n
= startswith(rvalue
, "file:"))) {
863 _cleanup_free_
char *resolved
= NULL
;
865 r
= unit_full_printf(u
, n
, &resolved
);
867 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers on %s: %m", n
);
869 if (!path_is_absolute(resolved
)) {
870 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "file: requires an absolute path name: %s", resolved
);
874 if (!path_is_normalized(resolved
)) {
875 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "file: requires a normalized path name: %s", resolved
);
879 free_and_replace(c
->stdio_file
[STDIN_FILENO
], resolved
);
881 ei
= EXEC_INPUT_FILE
;
884 ei
= exec_input_from_string(rvalue
);
886 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse input specifier, ignoring: %s", rvalue
);
895 int config_parse_exec_input_text(
897 const char *filename
,
900 unsigned section_line
,
907 _cleanup_free_
char *unescaped
= NULL
, *resolved
= NULL
;
908 ExecContext
*c
= data
;
919 if (isempty(rvalue
)) {
920 /* Reset if the empty string is assigned */
921 c
->stdin_data
= mfree(c
->stdin_data
);
922 c
->stdin_data_size
= 0;
926 r
= cunescape(rvalue
, 0, &unescaped
);
928 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to decode C escaped text: %s", rvalue
);
930 r
= unit_full_printf(u
, unescaped
, &resolved
);
932 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve specifiers: %s", unescaped
);
934 sz
= strlen(resolved
);
935 if (c
->stdin_data_size
+ sz
+ 1 < c
->stdin_data_size
|| /* check for overflow */
936 c
->stdin_data_size
+ sz
+ 1 > EXEC_STDIN_DATA_MAX
) {
937 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
);
941 p
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
+ 1);
945 *((char*) mempcpy((char*) p
+ c
->stdin_data_size
, resolved
, sz
)) = '\n';
948 c
->stdin_data_size
+= sz
+ 1;
953 int config_parse_exec_input_data(
955 const char *filename
,
958 unsigned section_line
,
965 _cleanup_free_
void *p
= NULL
;
966 ExecContext
*c
= data
;
976 if (isempty(rvalue
)) {
977 /* Reset if the empty string is assigned */
978 c
->stdin_data
= mfree(c
->stdin_data
);
979 c
->stdin_data_size
= 0;
983 r
= unbase64mem(rvalue
, (size_t) -1, &p
, &sz
);
985 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to decode base64 data, ignoring: %s", rvalue
);
989 if (c
->stdin_data_size
+ sz
< c
->stdin_data_size
|| /* check for overflow */
990 c
->stdin_data_size
+ sz
> EXEC_STDIN_DATA_MAX
) {
991 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
);
995 q
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
);
999 memcpy((uint8_t*) q
+ c
->stdin_data_size
, p
, sz
);
1002 c
->stdin_data_size
+= sz
;
1007 int config_parse_exec_output(
1009 const char *filename
,
1011 const char *section
,
1012 unsigned section_line
,
1019 _cleanup_free_
char *resolved
= NULL
;
1021 ExecContext
*c
= data
;
1032 n
= startswith(rvalue
, "fd:");
1034 r
= unit_full_printf(u
, n
, &resolved
);
1036 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers on %s: %m", n
);
1038 if (isempty(resolved
))
1039 resolved
= mfree(resolved
);
1040 else if (!fdname_is_valid(resolved
)) {
1041 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name: %s", resolved
);
1045 eo
= EXEC_OUTPUT_NAMED_FD
;
1047 } else if ((n
= startswith(rvalue
, "file:"))) {
1049 r
= unit_full_printf(u
, n
, &resolved
);
1051 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers on %s: %m", n
);
1053 if (!path_is_absolute(resolved
)) {
1054 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "file: requires an absolute path name: %s", resolved
);
1058 if (!path_is_normalized(resolved
)) {
1059 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "file: requires a normalized path name, ignoring: %s", resolved
);
1063 eo
= EXEC_OUTPUT_FILE
;
1066 eo
= exec_output_from_string(rvalue
);
1068 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse output specifier, ignoring: %s", rvalue
);
1073 if (streq(lvalue
, "StandardOutput")) {
1074 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1075 free_and_replace(c
->stdio_fdname
[STDOUT_FILENO
], resolved
);
1077 free_and_replace(c
->stdio_file
[STDOUT_FILENO
], resolved
);
1082 assert(streq(lvalue
, "StandardError"));
1084 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1085 free_and_replace(c
->stdio_fdname
[STDERR_FILENO
], resolved
);
1087 free_and_replace(c
->stdio_file
[STDERR_FILENO
], resolved
);
1095 int config_parse_exec_io_class(const char *unit
,
1096 const char *filename
,
1098 const char *section
,
1099 unsigned section_line
,
1106 ExecContext
*c
= data
;
1114 x
= ioprio_class_from_string(rvalue
);
1116 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse IO scheduling class, ignoring: %s", rvalue
);
1120 c
->ioprio
= IOPRIO_PRIO_VALUE(x
, IOPRIO_PRIO_DATA(c
->ioprio
));
1121 c
->ioprio_set
= true;
1126 int config_parse_exec_io_priority(const char *unit
,
1127 const char *filename
,
1129 const char *section
,
1130 unsigned section_line
,
1137 ExecContext
*c
= data
;
1145 r
= ioprio_parse_priority(rvalue
, &i
);
1147 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse IO priority, ignoring: %s", rvalue
);
1151 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_PRIO_CLASS(c
->ioprio
), i
);
1152 c
->ioprio_set
= true;
1157 int config_parse_exec_cpu_sched_policy(const char *unit
,
1158 const char *filename
,
1160 const char *section
,
1161 unsigned section_line
,
1168 ExecContext
*c
= data
;
1176 x
= sched_policy_from_string(rvalue
);
1178 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse CPU scheduling policy, ignoring: %s", rvalue
);
1182 c
->cpu_sched_policy
= x
;
1183 /* Moving to or from real-time policy? We need to adjust the priority */
1184 c
->cpu_sched_priority
= CLAMP(c
->cpu_sched_priority
, sched_get_priority_min(x
), sched_get_priority_max(x
));
1185 c
->cpu_sched_set
= true;
1190 int config_parse_exec_cpu_sched_prio(const char *unit
,
1191 const char *filename
,
1193 const char *section
,
1194 unsigned section_line
,
1201 ExecContext
*c
= data
;
1209 r
= safe_atoi(rvalue
, &i
);
1211 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse CPU scheduling policy, ignoring: %s", rvalue
);
1215 /* On Linux RR/FIFO range from 1 to 99 and OTHER/BATCH may only be 0 */
1216 min
= sched_get_priority_min(c
->cpu_sched_policy
);
1217 max
= sched_get_priority_max(c
->cpu_sched_policy
);
1219 if (i
< min
|| i
> max
) {
1220 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "CPU scheduling priority is out of range, ignoring: %s", rvalue
);
1224 c
->cpu_sched_priority
= i
;
1225 c
->cpu_sched_set
= true;
1230 int config_parse_exec_cpu_affinity(const char *unit
,
1231 const char *filename
,
1233 const char *section
,
1234 unsigned section_line
,
1241 ExecContext
*c
= data
;
1242 _cleanup_cpu_free_ cpu_set_t
*cpuset
= NULL
;
1250 ncpus
= parse_cpu_set_and_warn(rvalue
, &cpuset
, unit
, filename
, line
, lvalue
);
1255 /* An empty assignment resets the CPU list */
1256 c
->cpuset
= cpu_set_mfree(c
->cpuset
);
1257 c
->cpuset_ncpus
= 0;
1262 c
->cpuset
= TAKE_PTR(cpuset
);
1263 c
->cpuset_ncpus
= (unsigned) ncpus
;
1267 if (c
->cpuset_ncpus
< (unsigned) ncpus
) {
1268 CPU_OR_S(CPU_ALLOC_SIZE(c
->cpuset_ncpus
), cpuset
, c
->cpuset
, cpuset
);
1269 CPU_FREE(c
->cpuset
);
1270 c
->cpuset
= TAKE_PTR(cpuset
);
1271 c
->cpuset_ncpus
= (unsigned) ncpus
;
1275 CPU_OR_S(CPU_ALLOC_SIZE((unsigned) ncpus
), c
->cpuset
, c
->cpuset
, cpuset
);
1280 int config_parse_exec_secure_bits(const char *unit
,
1281 const char *filename
,
1283 const char *section
,
1284 unsigned section_line
,
1291 ExecContext
*c
= data
;
1299 if (isempty(rvalue
)) {
1300 /* An empty assignment resets the field */
1305 r
= secure_bits_from_string(rvalue
);
1309 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1310 "Invalid syntax, ignoring: %s", rvalue
);
1319 int config_parse_capability_set(
1321 const char *filename
,
1323 const char *section
,
1324 unsigned section_line
,
1331 uint64_t *capability_set
= data
;
1332 uint64_t sum
= 0, initial
= 0;
1333 bool invert
= false;
1341 if (rvalue
[0] == '~') {
1346 if (streq(lvalue
, "CapabilityBoundingSet"))
1347 initial
= CAP_ALL
; /* initialized to all bits on */
1348 /* else "AmbientCapabilities" initialized to all bits off */
1350 r
= capability_set_from_string(rvalue
, &sum
);
1354 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse word: %s", rvalue
);
1358 if (sum
== 0 || *capability_set
== initial
)
1359 /* "", "~" or uninitialized data -> replace */
1360 *capability_set
= invert
? ~sum
: sum
;
1362 /* previous data -> merge */
1364 *capability_set
&= ~sum
;
1366 *capability_set
|= sum
;
1372 int config_parse_limit(
1374 const char *filename
,
1376 const char *section
,
1377 unsigned section_line
,
1384 struct rlimit
**rl
= data
, d
= {};
1392 r
= rlimit_parse(ltype
, rvalue
, &d
);
1394 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Soft resource limit chosen higher than hard limit, ignoring: %s", rvalue
);
1398 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse resource value, ignoring: %s", rvalue
);
1405 rl
[ltype
] = newdup(struct rlimit
, &d
, 1);
1413 #if HAVE_SYSV_COMPAT
1414 int config_parse_sysv_priority(const char *unit
,
1415 const char *filename
,
1417 const char *section
,
1418 unsigned section_line
,
1425 int *priority
= data
;
1433 r
= safe_atoi(rvalue
, &i
);
1434 if (r
< 0 || i
< 0) {
1435 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse SysV start priority, ignoring: %s", rvalue
);
1439 *priority
= (int) i
;
1444 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_utmp_mode
, exec_utmp_mode
, ExecUtmpMode
, "Failed to parse utmp mode");
1445 DEFINE_CONFIG_PARSE_ENUM(config_parse_kill_mode
, kill_mode
, KillMode
, "Failed to parse kill mode");
1447 int config_parse_exec_mount_flags(
1449 const char *filename
,
1451 const char *section
,
1452 unsigned section_line
,
1459 ExecContext
*c
= data
;
1467 r
= mount_propagation_flags_from_string(rvalue
, &c
->mount_flags
);
1469 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse mount flag %s, ignoring.", rvalue
);
1474 int config_parse_exec_selinux_context(
1476 const char *filename
,
1478 const char *section
,
1479 unsigned section_line
,
1486 ExecContext
*c
= data
;
1497 if (isempty(rvalue
)) {
1498 c
->selinux_context
= mfree(c
->selinux_context
);
1499 c
->selinux_context_ignore
= false;
1503 if (rvalue
[0] == '-') {
1509 r
= unit_full_printf(u
, rvalue
, &k
);
1511 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1512 "Failed to resolve specifiers%s: %m",
1513 ignore
? ", ignoring" : "");
1514 return ignore
? 0 : -ENOEXEC
;
1517 free(c
->selinux_context
);
1518 c
->selinux_context
= k
;
1519 c
->selinux_context_ignore
= ignore
;
1524 int config_parse_exec_apparmor_profile(
1526 const char *filename
,
1528 const char *section
,
1529 unsigned section_line
,
1536 ExecContext
*c
= data
;
1547 if (isempty(rvalue
)) {
1548 c
->apparmor_profile
= mfree(c
->apparmor_profile
);
1549 c
->apparmor_profile_ignore
= false;
1553 if (rvalue
[0] == '-') {
1559 r
= unit_full_printf(u
, rvalue
, &k
);
1561 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1562 "Failed to resolve specifiers%s: %m",
1563 ignore
? ", ignoring" : "");
1564 return ignore
? 0 : -ENOEXEC
;
1567 free(c
->apparmor_profile
);
1568 c
->apparmor_profile
= k
;
1569 c
->apparmor_profile_ignore
= ignore
;
1574 int config_parse_exec_smack_process_label(
1576 const char *filename
,
1578 const char *section
,
1579 unsigned section_line
,
1586 ExecContext
*c
= data
;
1597 if (isempty(rvalue
)) {
1598 c
->smack_process_label
= mfree(c
->smack_process_label
);
1599 c
->smack_process_label_ignore
= false;
1603 if (rvalue
[0] == '-') {
1609 r
= unit_full_printf(u
, rvalue
, &k
);
1611 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1612 "Failed to resolve specifiers%s: %m",
1613 ignore
? ", ignoring" : "");
1614 return ignore
? 0 : -ENOEXEC
;
1617 free(c
->smack_process_label
);
1618 c
->smack_process_label
= k
;
1619 c
->smack_process_label_ignore
= ignore
;
1624 int config_parse_timer(const char *unit
,
1625 const char *filename
,
1627 const char *section
,
1628 unsigned section_line
,
1639 _cleanup_(calendar_spec_freep
) CalendarSpec
*c
= NULL
;
1641 _cleanup_free_
char *k
= NULL
;
1649 if (isempty(rvalue
)) {
1650 /* Empty assignment resets list */
1651 timer_free_values(t
);
1655 b
= timer_base_from_string(lvalue
);
1657 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse timer base, ignoring: %s", lvalue
);
1661 r
= unit_full_printf(u
, rvalue
, &k
);
1663 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
1667 if (b
== TIMER_CALENDAR
) {
1668 if (calendar_spec_from_string(k
, &c
) < 0) {
1669 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse calendar specification, ignoring: %s", k
);
1673 if (parse_sec(k
, &usec
) < 0) {
1674 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse timer value, ignoring: %s", k
);
1679 v
= new0(TimerValue
, 1);
1685 v
->calendar_spec
= TAKE_PTR(c
);
1687 LIST_PREPEND(value
, t
->values
, v
);
1692 int config_parse_trigger_unit(
1694 const char *filename
,
1696 const char *section
,
1697 unsigned section_line
,
1704 _cleanup_free_
char *p
= NULL
;
1714 if (!hashmap_isempty(u
->dependencies
[UNIT_TRIGGERS
])) {
1715 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Multiple units to trigger specified, ignoring: %s", rvalue
);
1719 r
= unit_name_printf(u
, rvalue
, &p
);
1721 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve specifiers, ignoring: %m");
1725 type
= unit_name_to_type(p
);
1727 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit type not valid, ignoring: %s", rvalue
);
1730 if (unit_has_name(u
, p
)) {
1731 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Units cannot trigger themselves, ignoring: %s", rvalue
);
1735 r
= unit_add_two_dependencies_by_name(u
, UNIT_BEFORE
, UNIT_TRIGGERS
, p
, NULL
, true, UNIT_DEPENDENCY_FILE
);
1737 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add trigger on %s, ignoring: %m", p
);
1744 int config_parse_path_spec(const char *unit
,
1745 const char *filename
,
1747 const char *section
,
1748 unsigned section_line
,
1758 _cleanup_free_
char *k
= NULL
;
1766 if (isempty(rvalue
)) {
1767 /* Empty assignment clears list */
1772 b
= path_type_from_string(lvalue
);
1774 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse path type, ignoring: %s", lvalue
);
1778 r
= unit_full_printf(UNIT(p
), rvalue
, &k
);
1780 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers on %s. Ignoring.", rvalue
);
1784 if (!path_is_absolute(k
)) {
1785 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Path is not absolute, ignoring: %s", k
);
1789 s
= new0(PathSpec
, 1);
1794 s
->path
= path_kill_slashes(k
);
1799 LIST_PREPEND(spec
, p
->specs
, s
);
1804 int config_parse_socket_service(
1806 const char *filename
,
1808 const char *section
,
1809 unsigned section_line
,
1816 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1817 _cleanup_free_
char *p
= NULL
;
1827 r
= unit_name_printf(UNIT(s
), rvalue
, &p
);
1829 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve specifiers: %s", rvalue
);
1833 if (!endswith(p
, ".service")) {
1834 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit must be of type service: %s", rvalue
);
1838 r
= manager_load_unit(UNIT(s
)->manager
, p
, NULL
, &error
, &x
);
1840 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to load unit %s: %s", rvalue
, bus_error_message(&error
, r
));
1844 unit_ref_set(&s
->service
, UNIT(s
), x
);
1849 int config_parse_fdname(
1851 const char *filename
,
1853 const char *section
,
1854 unsigned section_line
,
1861 _cleanup_free_
char *p
= NULL
;
1870 if (isempty(rvalue
)) {
1871 s
->fdname
= mfree(s
->fdname
);
1875 r
= unit_full_printf(UNIT(s
), rvalue
, &p
);
1877 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve specifiers, ignoring: %s", rvalue
);
1881 if (!fdname_is_valid(p
)) {
1882 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", p
);
1886 return free_and_replace(s
->fdname
, p
);
1889 int config_parse_service_sockets(
1891 const char *filename
,
1893 const char *section
,
1894 unsigned section_line
,
1912 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
1914 r
= extract_first_word(&p
, &word
, NULL
, 0);
1920 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Trailing garbage in sockets, ignoring: %s", rvalue
);
1924 r
= unit_name_printf(UNIT(s
), word
, &k
);
1926 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve specifiers, ignoring: %m");
1930 if (!endswith(k
, ".socket")) {
1931 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit must be of type socket, ignoring: %s", k
);
1935 r
= unit_add_two_dependencies_by_name(UNIT(s
), UNIT_WANTS
, UNIT_AFTER
, k
, NULL
, true, UNIT_DEPENDENCY_FILE
);
1937 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
1939 r
= unit_add_dependency_by_name(UNIT(s
), UNIT_TRIGGERED_BY
, k
, NULL
, true, UNIT_DEPENDENCY_FILE
);
1941 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
1947 int config_parse_bus_name(
1949 const char *filename
,
1951 const char *section
,
1952 unsigned section_line
,
1959 _cleanup_free_
char *k
= NULL
;
1968 r
= unit_full_printf(u
, rvalue
, &k
);
1970 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers on %s, ignoring: %m", rvalue
);
1974 if (!service_name_is_valid(k
)) {
1975 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid bus name %s, ignoring.", k
);
1979 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
1982 int config_parse_service_timeout(
1984 const char *filename
,
1986 const char *section
,
1987 unsigned section_line
,
1994 Service
*s
= userdata
;
2003 /* This is called for three cases: TimeoutSec=, TimeoutStopSec= and TimeoutStartSec=. */
2005 r
= parse_sec(rvalue
, &usec
);
2007 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
2011 /* Traditionally, these options accepted 0 to disable the timeouts. However, a timeout of 0 suggests it happens
2012 * immediately, hence fix this to become USEC_INFINITY instead. This is in-line with how we internally handle
2013 * all other timeouts. */
2015 usec
= USEC_INFINITY
;
2017 if (!streq(lvalue
, "TimeoutStopSec")) {
2018 s
->start_timeout_defined
= true;
2019 s
->timeout_start_usec
= usec
;
2022 if (!streq(lvalue
, "TimeoutStartSec"))
2023 s
->timeout_stop_usec
= usec
;
2028 int config_parse_sec_fix_0(
2030 const char *filename
,
2032 const char *section
,
2033 unsigned section_line
,
2040 usec_t
*usec
= data
;
2048 /* This is pretty much like config_parse_sec(), except that this treats a time of 0 as infinity, for
2049 * compatibility with older versions of systemd where 0 instead of infinity was used as indicator to turn off a
2052 r
= parse_sec_fix_0(rvalue
, usec
);
2054 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
2061 int config_parse_user_group(
2063 const char *filename
,
2065 const char *section
,
2066 unsigned section_line
,
2073 char **user
= data
, *n
;
2082 if (isempty(rvalue
))
2085 _cleanup_free_
char *k
= NULL
;
2087 r
= unit_full_printf(u
, rvalue
, &k
);
2089 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", rvalue
);
2093 if (!valid_user_group_name_or_id(k
)) {
2094 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2107 int config_parse_user_group_strv(
2109 const char *filename
,
2111 const char *section
,
2112 unsigned section_line
,
2119 char ***users
= data
;
2129 if (isempty(rvalue
)) {
2130 *users
= strv_free(*users
);
2136 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2138 r
= extract_first_word(&p
, &word
, NULL
, 0);
2144 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax: %s", rvalue
);
2148 r
= unit_full_printf(u
, word
, &k
);
2150 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", word
);
2154 if (!valid_user_group_name_or_id(k
)) {
2155 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2159 r
= strv_push(users
, k
);
2169 int config_parse_working_directory(
2171 const char *filename
,
2173 const char *section
,
2174 unsigned section_line
,
2181 ExecContext
*c
= data
;
2192 if (rvalue
[0] == '-') {
2198 if (streq(rvalue
, "~")) {
2199 c
->working_directory_home
= true;
2200 c
->working_directory
= mfree(c
->working_directory
);
2202 _cleanup_free_
char *k
= NULL
;
2204 r
= unit_full_printf(u
, rvalue
, &k
);
2206 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2207 "Failed to resolve unit specifiers in working directory path '%s'%s: %m",
2208 rvalue
, missing_ok
? ", ignoring" : "");
2209 return missing_ok
? 0 : -ENOEXEC
;
2212 path_kill_slashes(k
);
2214 if (!utf8_is_valid(k
)) {
2215 log_syntax_invalid_utf8(unit
, LOG_ERR
, filename
, line
, rvalue
);
2216 return missing_ok
? 0 : -ENOEXEC
;
2219 if (!path_is_absolute(k
)) {
2220 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2221 "Working directory path '%s' is not absolute%s.",
2222 rvalue
, missing_ok
? ", ignoring" : "");
2223 return missing_ok
? 0 : -ENOEXEC
;
2226 c
->working_directory_home
= false;
2227 free_and_replace(c
->working_directory
, k
);
2230 c
->working_directory_missing_ok
= missing_ok
;
2234 int config_parse_unit_env_file(const char *unit
,
2235 const char *filename
,
2237 const char *section
,
2238 unsigned section_line
,
2247 _cleanup_free_
char *n
= NULL
;
2255 if (isempty(rvalue
)) {
2256 /* Empty assignment frees the list */
2257 *env
= strv_free(*env
);
2261 r
= unit_full_printf(u
, rvalue
, &n
);
2263 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve specifiers, ignoring: %s", rvalue
);
2267 if (!path_is_absolute(n
[0] == '-' ? n
+ 1 : n
)) {
2268 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Path '%s' is not absolute, ignoring.", n
);
2272 r
= strv_extend(env
, n
);
2279 int config_parse_environ(
2281 const char *filename
,
2283 const char *section
,
2284 unsigned section_line
,
2301 if (isempty(rvalue
)) {
2302 /* Empty assignment resets the list */
2303 *env
= strv_free(*env
);
2307 for (p
= rvalue
;; ) {
2308 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2310 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_QUOTES
);
2316 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2317 "Invalid syntax, ignoring: %s", rvalue
);
2322 r
= unit_full_printf(u
, word
, &k
);
2324 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2325 "Failed to resolve specifiers, ignoring: %s", word
);
2331 if (!env_assignment_is_valid(k
)) {
2332 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2333 "Invalid environment assignment, ignoring: %s", k
);
2337 r
= strv_env_replace(env
, k
);
2345 int config_parse_pass_environ(
2347 const char *filename
,
2349 const char *section
,
2350 unsigned section_line
,
2357 const char *whole_rvalue
= rvalue
;
2358 _cleanup_strv_free_
char **n
= NULL
;
2359 size_t nlen
= 0, nbufsize
= 0;
2360 char*** passenv
= data
;
2369 if (isempty(rvalue
)) {
2370 /* Empty assignment resets the list */
2371 *passenv
= strv_free(*passenv
);
2376 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2378 r
= extract_first_word(&rvalue
, &word
, NULL
, EXTRACT_QUOTES
);
2384 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2385 "Trailing garbage in %s, ignoring: %s", lvalue
, whole_rvalue
);
2390 r
= unit_full_printf(u
, word
, &k
);
2392 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2393 "Failed to resolve specifiers, ignoring: %s", word
);
2399 if (!env_name_is_valid(k
)) {
2400 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2401 "Invalid environment name for %s, ignoring: %s", lvalue
, k
);
2405 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
2408 n
[nlen
++] = TAKE_PTR(k
);
2413 r
= strv_extend_strv(passenv
, n
, true);
2421 int config_parse_unset_environ(
2423 const char *filename
,
2425 const char *section
,
2426 unsigned section_line
,
2433 _cleanup_strv_free_
char **n
= NULL
;
2434 const char *whole_rvalue
= rvalue
;
2435 size_t nlen
= 0, nbufsize
= 0;
2436 char*** unsetenv
= data
;
2445 if (isempty(rvalue
)) {
2446 /* Empty assignment resets the list */
2447 *unsetenv
= strv_free(*unsetenv
);
2452 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2454 r
= extract_first_word(&rvalue
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_QUOTES
);
2460 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2461 "Trailing garbage in %s, ignoring: %s", lvalue
, whole_rvalue
);
2466 r
= unit_full_printf(u
, word
, &k
);
2468 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2469 "Failed to resolve specifiers, ignoring: %s", word
);
2475 if (!env_assignment_is_valid(k
) && !env_name_is_valid(k
)) {
2476 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2477 "Invalid environment name or assignment %s, ignoring: %s", lvalue
, k
);
2481 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
2484 n
[nlen
++] = TAKE_PTR(k
);
2489 r
= strv_extend_strv(unsetenv
, n
, true);
2497 int config_parse_log_extra_fields(
2499 const char *filename
,
2501 const char *section
,
2502 unsigned section_line
,
2509 ExecContext
*c
= data
;
2519 if (isempty(rvalue
)) {
2520 exec_context_free_log_extra_fields(c
);
2524 for (p
= rvalue
;; ) {
2525 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2529 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_QUOTES
);
2535 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
2539 r
= unit_full_printf(u
, word
, &k
);
2541 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers on %s, ignoring field: %m", word
);
2545 eq
= strchr(k
, '=');
2547 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Log field lacks '=' character, ignoring field: %s", k
);
2551 if (!journal_field_valid(k
, eq
-k
, false)) {
2552 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Log field name is invalid, ignoring field: %s", k
);
2556 t
= reallocarray(c
->log_extra_fields
, c
->n_log_extra_fields
+1, sizeof(struct iovec
));
2560 c
->log_extra_fields
= t
;
2561 c
->log_extra_fields
[c
->n_log_extra_fields
++] = IOVEC_MAKE_STRING(k
);
2569 int config_parse_ip_tos(const char *unit
,
2570 const char *filename
,
2572 const char *section
,
2573 unsigned section_line
,
2580 int *ip_tos
= data
, x
;
2587 x
= ip_tos_from_string(rvalue
);
2589 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse IP TOS value, ignoring: %s", rvalue
);
2597 int config_parse_unit_condition_path(
2599 const char *filename
,
2601 const char *section
,
2602 unsigned section_line
,
2609 _cleanup_free_
char *p
= NULL
;
2610 Condition
**list
= data
, *c
;
2611 ConditionType t
= ltype
;
2612 bool trigger
, negate
;
2621 if (isempty(rvalue
)) {
2622 /* Empty assignment resets the list */
2623 *list
= condition_free_list(*list
);
2627 trigger
= rvalue
[0] == '|';
2631 negate
= rvalue
[0] == '!';
2635 r
= unit_full_printf(u
, rvalue
, &p
);
2637 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve specifiers, ignoring: %s", rvalue
);
2641 if (!path_is_absolute(p
)) {
2642 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Path in condition not absolute, ignoring: %s", p
);
2646 c
= condition_new(t
, p
, trigger
, negate
);
2650 LIST_PREPEND(conditions
, *list
, c
);
2654 int config_parse_unit_condition_string(
2656 const char *filename
,
2658 const char *section
,
2659 unsigned section_line
,
2666 _cleanup_free_
char *s
= NULL
;
2667 Condition
**list
= data
, *c
;
2668 ConditionType t
= ltype
;
2669 bool trigger
, negate
;
2678 if (isempty(rvalue
)) {
2679 /* Empty assignment resets the list */
2680 *list
= condition_free_list(*list
);
2684 trigger
= rvalue
[0] == '|';
2688 negate
= rvalue
[0] == '!';
2692 r
= unit_full_printf(u
, rvalue
, &s
);
2694 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve specifiers, ignoring: %s", rvalue
);
2698 c
= condition_new(t
, s
, trigger
, negate
);
2702 LIST_PREPEND(conditions
, *list
, c
);
2706 int config_parse_unit_condition_null(
2708 const char *filename
,
2710 const char *section
,
2711 unsigned section_line
,
2718 Condition
**list
= data
, *c
;
2719 bool trigger
, negate
;
2727 if (isempty(rvalue
)) {
2728 /* Empty assignment resets the list */
2729 *list
= condition_free_list(*list
);
2733 trigger
= rvalue
[0] == '|';
2737 negate
= rvalue
[0] == '!';
2741 b
= parse_boolean(rvalue
);
2743 log_syntax(unit
, LOG_ERR
, filename
, line
, b
, "Failed to parse boolean value in condition, ignoring: %s", rvalue
);
2750 c
= condition_new(CONDITION_NULL
, NULL
, trigger
, negate
);
2754 LIST_PREPEND(conditions
, *list
, c
);
2758 DEFINE_CONFIG_PARSE_ENUM(config_parse_notify_access
, notify_access
, NotifyAccess
, "Failed to parse notify access specifier");
2759 DEFINE_CONFIG_PARSE_ENUM(config_parse_emergency_action
, emergency_action
, EmergencyAction
, "Failed to parse failure action specifier");
2761 int config_parse_unit_requires_mounts_for(
2763 const char *filename
,
2765 const char *section
,
2766 unsigned section_line
,
2782 for (p
= rvalue
;; ) {
2783 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
2785 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
2791 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2792 "Invalid syntax, ignoring: %s", rvalue
);
2796 if (!utf8_is_valid(word
)) {
2797 log_syntax_invalid_utf8(unit
, LOG_ERR
, filename
, line
, rvalue
);
2801 r
= unit_full_printf(u
, word
, &resolved
);
2803 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit name \"%s\", ignoring: %m", word
);
2807 r
= unit_require_mounts_for(u
, resolved
, UNIT_DEPENDENCY_FILE
);
2809 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add required mount \"%s\", ignoring: %m", resolved
);
2815 int config_parse_documentation(const char *unit
,
2816 const char *filename
,
2818 const char *section
,
2819 unsigned section_line
,
2835 if (isempty(rvalue
)) {
2836 /* Empty assignment resets the list */
2837 u
->documentation
= strv_free(u
->documentation
);
2841 r
= config_parse_unit_strv_printf(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
,
2842 rvalue
, data
, userdata
);
2846 for (a
= b
= u
->documentation
; a
&& *a
; a
++) {
2848 if (documentation_url_is_valid(*a
))
2851 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid URL, ignoring: %s", *a
);
2862 int config_parse_syscall_filter(
2864 const char *filename
,
2866 const char *section
,
2867 unsigned section_line
,
2874 ExecContext
*c
= data
;
2876 bool invert
= false;
2885 if (isempty(rvalue
)) {
2886 /* Empty assignment resets the list */
2887 c
->syscall_filter
= hashmap_free(c
->syscall_filter
);
2888 c
->syscall_whitelist
= false;
2892 if (rvalue
[0] == '~') {
2897 if (!c
->syscall_filter
) {
2898 c
->syscall_filter
= hashmap_new(NULL
);
2899 if (!c
->syscall_filter
)
2903 /* Allow everything but the ones listed */
2904 c
->syscall_whitelist
= false;
2906 /* Allow nothing but the ones listed */
2907 c
->syscall_whitelist
= true;
2909 /* Accept default syscalls if we are on a whitelist */
2910 r
= seccomp_parse_syscall_filter("@default", -1, c
->syscall_filter
, SECCOMP_PARSE_WHITELIST
);
2918 _cleanup_free_
char *word
= NULL
, *name
= NULL
;
2921 r
= extract_first_word(&p
, &word
, NULL
, 0);
2927 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
2931 r
= parse_syscall_and_errno(word
, &name
, &num
);
2933 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse syscall:errno, ignoring: %s", word
);
2937 r
= seccomp_parse_syscall_filter_full(name
, num
, c
->syscall_filter
,
2938 SECCOMP_PARSE_LOG
|SECCOMP_PARSE_PERMISSIVE
|(invert
? SECCOMP_PARSE_INVERT
: 0)|(c
->syscall_whitelist
? SECCOMP_PARSE_WHITELIST
: 0),
2939 unit
, filename
, line
);
2947 int config_parse_syscall_archs(
2949 const char *filename
,
2951 const char *section
,
2952 unsigned section_line
,
2963 if (isempty(rvalue
)) {
2964 *archs
= set_free(*archs
);
2968 r
= set_ensure_allocated(archs
, NULL
);
2972 for (p
= rvalue
;;) {
2973 _cleanup_free_
char *word
= NULL
;
2976 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
2982 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2983 "Invalid syntax, ignoring: %s", rvalue
);
2987 r
= seccomp_arch_from_string(word
, &a
);
2989 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2990 "Failed to parse system call architecture \"%s\", ignoring: %m", word
);
2994 r
= set_put(*archs
, UINT32_TO_PTR(a
+ 1));
3000 int config_parse_syscall_errno(
3002 const char *filename
,
3004 const char *section
,
3005 unsigned section_line
,
3012 ExecContext
*c
= data
;
3019 if (isempty(rvalue
)) {
3020 /* Empty assignment resets to KILL */
3021 c
->syscall_errno
= 0;
3025 e
= parse_errno(rvalue
);
3027 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse error number, ignoring: %s", rvalue
);
3031 c
->syscall_errno
= e
;
3035 int config_parse_address_families(
3037 const char *filename
,
3039 const char *section
,
3040 unsigned section_line
,
3047 ExecContext
*c
= data
;
3048 bool invert
= false;
3056 if (isempty(rvalue
)) {
3057 /* Empty assignment resets the list */
3058 c
->address_families
= set_free(c
->address_families
);
3059 c
->address_families_whitelist
= false;
3063 if (rvalue
[0] == '~') {
3068 if (!c
->address_families
) {
3069 c
->address_families
= set_new(NULL
);
3070 if (!c
->address_families
)
3073 c
->address_families_whitelist
= !invert
;
3076 for (p
= rvalue
;;) {
3077 _cleanup_free_
char *word
= NULL
;
3080 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
3086 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3087 "Invalid syntax, ignoring: %s", rvalue
);
3091 af
= af_from_name(word
);
3093 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
3094 "Failed to parse address family \"%s\", ignoring: %m", word
);
3098 /* If we previously wanted to forbid an address family and now
3099 * we want to allow it, then just remove it from the list.
3101 if (!invert
== c
->address_families_whitelist
) {
3102 r
= set_put(c
->address_families
, INT_TO_PTR(af
));
3106 set_remove(c
->address_families
, INT_TO_PTR(af
));
3110 int config_parse_restrict_namespaces(
3112 const char *filename
,
3114 const char *section
,
3115 unsigned section_line
,
3122 ExecContext
*c
= data
;
3123 bool invert
= false;
3126 if (isempty(rvalue
)) {
3127 /* Reset to the default. */
3128 c
->restrict_namespaces
= NAMESPACE_FLAGS_ALL
;
3132 if (rvalue
[0] == '~') {
3137 r
= parse_boolean(rvalue
);
3139 c
->restrict_namespaces
= 0;
3141 c
->restrict_namespaces
= NAMESPACE_FLAGS_ALL
;
3143 /* Not a boolean argument, in this case it's a list of namespace types. */
3145 r
= namespace_flag_from_string_many(rvalue
, &c
->restrict_namespaces
);
3147 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse namespace type string, ignoring: %s", rvalue
);
3153 c
->restrict_namespaces
= (~c
->restrict_namespaces
) & NAMESPACE_FLAGS_ALL
;
3159 int config_parse_unit_slice(
3161 const char *filename
,
3163 const char *section
,
3164 unsigned section_line
,
3171 _cleanup_free_
char *k
= NULL
;
3172 Unit
*u
= userdata
, *slice
= NULL
;
3180 r
= unit_name_printf(u
, rvalue
, &k
);
3182 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers on %s. Ignoring.", rvalue
);
3186 r
= manager_load_unit(u
->manager
, k
, NULL
, NULL
, &slice
);
3188 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to load slice unit %s. Ignoring.", k
);
3192 r
= unit_set_slice(u
, slice
);
3194 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to assign slice %s to unit %s. Ignoring.", slice
->id
, u
->id
);
3201 DEFINE_CONFIG_PARSE_ENUM(config_parse_device_policy
, cgroup_device_policy
, CGroupDevicePolicy
, "Failed to parse device policy");
3203 int config_parse_cpu_weight(
3205 const char *filename
,
3207 const char *section
,
3208 unsigned section_line
,
3215 uint64_t *weight
= data
;
3222 r
= cg_weight_parse(rvalue
, weight
);
3224 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "CPU weight '%s' invalid. Ignoring.", rvalue
);
3231 int config_parse_cpu_shares(
3233 const char *filename
,
3235 const char *section
,
3236 unsigned section_line
,
3243 uint64_t *shares
= data
;
3250 r
= cg_cpu_shares_parse(rvalue
, shares
);
3252 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "CPU shares '%s' invalid. Ignoring.", rvalue
);
3259 int config_parse_cpu_quota(
3261 const char *filename
,
3263 const char *section
,
3264 unsigned section_line
,
3271 CGroupContext
*c
= data
;
3278 if (isempty(rvalue
)) {
3279 c
->cpu_quota_per_sec_usec
= USEC_INFINITY
;
3283 r
= parse_percent_unbounded(rvalue
);
3285 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "CPU quota '%s' invalid. Ignoring.", rvalue
);
3289 c
->cpu_quota_per_sec_usec
= ((usec_t
) r
* USEC_PER_SEC
) / 100U;
3293 int config_parse_memory_limit(
3295 const char *filename
,
3297 const char *section
,
3298 unsigned section_line
,
3305 CGroupContext
*c
= data
;
3306 uint64_t bytes
= CGROUP_LIMIT_MAX
;
3309 if (!isempty(rvalue
) && !streq(rvalue
, "infinity")) {
3311 r
= parse_percent(rvalue
);
3313 r
= parse_size(rvalue
, 1024, &bytes
);
3315 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Memory limit '%s' invalid. Ignoring.", rvalue
);
3319 bytes
= physical_memory_scale(r
, 100U);
3321 if (bytes
>= UINT64_MAX
||
3322 (bytes
<= 0 && !streq(lvalue
, "MemorySwapMax"))) {
3323 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Memory limit '%s' out of range. Ignoring.", rvalue
);
3328 if (streq(lvalue
, "MemoryLow"))
3329 c
->memory_low
= bytes
;
3330 else if (streq(lvalue
, "MemoryHigh"))
3331 c
->memory_high
= bytes
;
3332 else if (streq(lvalue
, "MemoryMax"))
3333 c
->memory_max
= bytes
;
3334 else if (streq(lvalue
, "MemorySwapMax"))
3335 c
->memory_swap_max
= bytes
;
3336 else if (streq(lvalue
, "MemoryLimit"))
3337 c
->memory_limit
= bytes
;
3344 int config_parse_tasks_max(
3346 const char *filename
,
3348 const char *section
,
3349 unsigned section_line
,
3356 uint64_t *tasks_max
= data
, v
;
3360 if (isempty(rvalue
)) {
3361 *tasks_max
= u
->manager
->default_tasks_max
;
3365 if (streq(rvalue
, "infinity")) {
3366 *tasks_max
= CGROUP_LIMIT_MAX
;
3370 r
= parse_percent(rvalue
);
3372 r
= safe_atou64(rvalue
, &v
);
3374 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Maximum tasks value '%s' invalid. Ignoring.", rvalue
);
3378 v
= system_tasks_max_scale(r
, 100U);
3380 if (v
<= 0 || v
>= UINT64_MAX
) {
3381 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Maximum tasks value '%s' out of range. Ignoring.", rvalue
);
3389 int config_parse_delegate(
3391 const char *filename
,
3393 const char *section
,
3394 unsigned section_line
,
3401 CGroupContext
*c
= data
;
3405 t
= unit_name_to_type(unit
);
3406 assert(t
!= _UNIT_TYPE_INVALID
);
3408 if (!unit_vtable
[t
]->can_delegate
) {
3409 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Delegate= setting not supported for this unit type, ignoring.");
3413 /* We either accept a boolean value, which may be used to turn on delegation for all controllers, or turn it
3414 * off for all. Or it takes a list of controller names, in which case we add the specified controllers to the
3415 * mask to delegate. */
3417 if (isempty(rvalue
)) {
3418 /* An empty string resets controllers and set Delegate=yes. */
3420 c
->delegate_controllers
= 0;
3424 r
= parse_boolean(rvalue
);
3426 const char *p
= rvalue
;
3427 CGroupMask mask
= 0;
3430 _cleanup_free_
char *word
= NULL
;
3431 CGroupController cc
;
3433 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
3439 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3443 cc
= cgroup_controller_from_string(word
);
3445 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid controller name '%s', ignoring", rvalue
);
3449 mask
|= CGROUP_CONTROLLER_TO_MASK(cc
);
3453 c
->delegate_controllers
|= mask
;
3457 c
->delegate_controllers
= _CGROUP_MASK_ALL
;
3459 c
->delegate
= false;
3460 c
->delegate_controllers
= 0;
3466 int config_parse_device_allow(
3468 const char *filename
,
3470 const char *section
,
3471 unsigned section_line
,
3478 _cleanup_free_
char *path
= NULL
, *t
= NULL
;
3479 CGroupContext
*c
= data
;
3480 CGroupDeviceAllow
*a
;
3481 const char *m
= NULL
;
3485 if (isempty(rvalue
)) {
3486 while (c
->device_allow
)
3487 cgroup_context_free_device_allow(c
, c
->device_allow
);
3492 r
= unit_full_printf(userdata
, rvalue
, &t
);
3494 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3495 "Failed to resolve specifiers in %s, ignoring: %m",
3500 n
= strcspn(t
, WHITESPACE
);
3502 path
= strndup(t
, n
);
3506 if (!is_deviceallow_pattern(path
) &&
3507 !path_startswith(path
, "/run/systemd/inaccessible/")) {
3508 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device node path '%s'. Ignoring.", path
);
3512 m
= t
+ n
+ strspn(t
+ n
, WHITESPACE
);
3516 if (!in_charset(m
, "rwm")) {
3517 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device rights '%s'. Ignoring.", m
);
3521 a
= new0(CGroupDeviceAllow
, 1);
3525 a
->path
= TAKE_PTR(path
);
3526 a
->r
= !!strchr(m
, 'r');
3527 a
->w
= !!strchr(m
, 'w');
3528 a
->m
= !!strchr(m
, 'm');
3530 LIST_PREPEND(device_allow
, c
->device_allow
, a
);
3534 int config_parse_io_weight(
3536 const char *filename
,
3538 const char *section
,
3539 unsigned section_line
,
3546 uint64_t *weight
= data
;
3553 r
= cg_weight_parse(rvalue
, weight
);
3555 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "IO weight '%s' invalid. Ignoring.", rvalue
);
3562 int config_parse_io_device_weight(
3564 const char *filename
,
3566 const char *section
,
3567 unsigned section_line
,
3574 _cleanup_free_
char *path
= NULL
;
3575 CGroupIODeviceWeight
*w
;
3576 CGroupContext
*c
= data
;
3586 if (isempty(rvalue
)) {
3587 while (c
->io_device_weights
)
3588 cgroup_context_free_io_device_weight(c
, c
->io_device_weights
);
3593 n
= strcspn(rvalue
, WHITESPACE
);
3594 weight
= rvalue
+ n
;
3595 weight
+= strspn(weight
, WHITESPACE
);
3597 if (isempty(weight
)) {
3598 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Expected block device and device weight. Ignoring.");
3602 path
= strndup(rvalue
, n
);
3606 if (!path_startswith(path
, "/dev") &&
3607 !path_startswith(path
, "/run/systemd/inaccessible/")) {
3608 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device node path '%s'. Ignoring.", path
);
3612 r
= cg_weight_parse(weight
, &u
);
3614 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "IO weight '%s' invalid. Ignoring.", weight
);
3618 assert(u
!= CGROUP_WEIGHT_INVALID
);
3620 w
= new0(CGroupIODeviceWeight
, 1);
3624 w
->path
= TAKE_PTR(path
);
3628 LIST_PREPEND(device_weights
, c
->io_device_weights
, w
);
3632 int config_parse_io_limit(
3634 const char *filename
,
3636 const char *section
,
3637 unsigned section_line
,
3644 _cleanup_free_
char *path
= NULL
;
3645 CGroupIODeviceLimit
*l
= NULL
, *t
;
3646 CGroupContext
*c
= data
;
3647 CGroupIOLimitType type
;
3657 type
= cgroup_io_limit_type_from_string(lvalue
);
3660 if (isempty(rvalue
)) {
3661 LIST_FOREACH(device_limits
, l
, c
->io_device_limits
)
3662 l
->limits
[type
] = cgroup_io_limit_defaults
[type
];
3666 n
= strcspn(rvalue
, WHITESPACE
);
3668 limit
+= strspn(limit
, WHITESPACE
);
3671 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Expected space separated pair of device node and bandwidth. Ignoring.");
3675 path
= strndup(rvalue
, n
);
3679 if (!path_startswith(path
, "/dev") &&
3680 !path_startswith(path
, "/run/systemd/inaccessible/")) {
3681 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device node path '%s'. Ignoring.", path
);
3685 if (streq("infinity", limit
)) {
3686 num
= CGROUP_LIMIT_MAX
;
3688 r
= parse_size(limit
, 1000, &num
);
3689 if (r
< 0 || num
<= 0) {
3690 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "IO Limit '%s' invalid. Ignoring.", rvalue
);
3695 LIST_FOREACH(device_limits
, t
, c
->io_device_limits
) {
3696 if (path_equal(path
, t
->path
)) {
3703 CGroupIOLimitType ttype
;
3705 l
= new0(CGroupIODeviceLimit
, 1);
3709 l
->path
= TAKE_PTR(path
);
3710 for (ttype
= 0; ttype
< _CGROUP_IO_LIMIT_TYPE_MAX
; ttype
++)
3711 l
->limits
[ttype
] = cgroup_io_limit_defaults
[ttype
];
3713 LIST_PREPEND(device_limits
, c
->io_device_limits
, l
);
3716 l
->limits
[type
] = num
;
3721 int config_parse_blockio_weight(
3723 const char *filename
,
3725 const char *section
,
3726 unsigned section_line
,
3733 uint64_t *weight
= data
;
3740 r
= cg_blkio_weight_parse(rvalue
, weight
);
3742 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Block IO weight '%s' invalid. Ignoring.", rvalue
);
3749 int config_parse_blockio_device_weight(
3751 const char *filename
,
3753 const char *section
,
3754 unsigned section_line
,
3761 _cleanup_free_
char *path
= NULL
;
3762 CGroupBlockIODeviceWeight
*w
;
3763 CGroupContext
*c
= data
;
3773 if (isempty(rvalue
)) {
3774 while (c
->blockio_device_weights
)
3775 cgroup_context_free_blockio_device_weight(c
, c
->blockio_device_weights
);
3780 n
= strcspn(rvalue
, WHITESPACE
);
3781 weight
= rvalue
+ n
;
3782 weight
+= strspn(weight
, WHITESPACE
);
3784 if (isempty(weight
)) {
3785 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Expected block device and device weight. Ignoring.");
3789 path
= strndup(rvalue
, n
);
3793 if (!path_startswith(path
, "/dev") &&
3794 !path_startswith(path
, "/run/systemd/inaccessible/")) {
3795 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device node path '%s'. Ignoring.", path
);
3799 r
= cg_blkio_weight_parse(weight
, &u
);
3801 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Block IO weight '%s' invalid. Ignoring.", weight
);
3805 assert(u
!= CGROUP_BLKIO_WEIGHT_INVALID
);
3807 w
= new0(CGroupBlockIODeviceWeight
, 1);
3811 w
->path
= TAKE_PTR(path
);
3815 LIST_PREPEND(device_weights
, c
->blockio_device_weights
, w
);
3819 int config_parse_blockio_bandwidth(
3821 const char *filename
,
3823 const char *section
,
3824 unsigned section_line
,
3831 _cleanup_free_
char *path
= NULL
;
3832 CGroupBlockIODeviceBandwidth
*b
= NULL
, *t
;
3833 CGroupContext
*c
= data
;
3834 const char *bandwidth
;
3844 read
= streq("BlockIOReadBandwidth", lvalue
);
3846 if (isempty(rvalue
)) {
3847 LIST_FOREACH(device_bandwidths
, b
, c
->blockio_device_bandwidths
) {
3848 b
->rbps
= CGROUP_LIMIT_MAX
;
3849 b
->wbps
= CGROUP_LIMIT_MAX
;
3854 n
= strcspn(rvalue
, WHITESPACE
);
3855 bandwidth
= rvalue
+ n
;
3856 bandwidth
+= strspn(bandwidth
, WHITESPACE
);
3859 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Expected space separated pair of device node and bandwidth. Ignoring.");
3863 path
= strndup(rvalue
, n
);
3867 if (!path_startswith(path
, "/dev") &&
3868 !path_startswith(path
, "/run/systemd/inaccessible/")) {
3869 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device node path '%s'. Ignoring.", path
);
3873 r
= parse_size(bandwidth
, 1000, &bytes
);
3874 if (r
< 0 || bytes
<= 0) {
3875 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Block IO Bandwidth '%s' invalid. Ignoring.", rvalue
);
3879 LIST_FOREACH(device_bandwidths
, t
, c
->blockio_device_bandwidths
) {
3880 if (path_equal(path
, t
->path
)) {
3887 b
= new0(CGroupBlockIODeviceBandwidth
, 1);
3891 b
->path
= TAKE_PTR(path
);
3892 b
->rbps
= CGROUP_LIMIT_MAX
;
3893 b
->wbps
= CGROUP_LIMIT_MAX
;
3895 LIST_PREPEND(device_bandwidths
, c
->blockio_device_bandwidths
, b
);
3906 DEFINE_CONFIG_PARSE_ENUM(config_parse_job_mode
, job_mode
, JobMode
, "Failed to parse job mode");
3908 int config_parse_job_mode_isolate(
3910 const char *filename
,
3912 const char *section
,
3913 unsigned section_line
,
3927 r
= parse_boolean(rvalue
);
3929 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse boolean, ignoring: %s", rvalue
);
3933 log_notice("%s is deprecated. Please use OnFailureJobMode= instead", lvalue
);
3935 *m
= r
? JOB_ISOLATE
: JOB_REPLACE
;
3939 DEFINE_CONFIG_PARSE_ENUM(config_parse_runtime_preserve_mode
, exec_preserve_mode
, ExecPreserveMode
, "Failed to parse runtime directory preserve mode");
3941 int config_parse_exec_directories(
3943 const char *filename
,
3945 const char *section
,
3946 unsigned section_line
,
3963 if (isempty(rvalue
)) {
3964 /* Empty assignment resets the list */
3965 *rt
= strv_free(*rt
);
3969 for (p
= rvalue
;;) {
3970 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
3972 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
3976 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3977 "Invalid syntax, ignoring: %s", rvalue
);
3983 r
= unit_full_printf(u
, word
, &k
);
3985 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
3986 "Failed to resolve specifiers in \"%s\", ignoring: %m", word
);
3990 if (!path_is_normalized(k
)) {
3991 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
3992 "%s= path is not normalized, ignoring assignment: %s", lvalue
, rvalue
);
3996 if (path_is_absolute(k
)) {
3997 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
3998 "%s= path is absolute, ignoring assignment: %s", lvalue
, rvalue
);
4002 if (path_startswith(k
, "private")) {
4003 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
4004 "%s= path can't be 'private', ingoring assignment: %s", lvalue
, rvalue
);
4008 r
= strv_push(rt
, k
);
4015 int config_parse_set_status(
4017 const char *filename
,
4019 const char *section
,
4020 unsigned section_line
,
4028 const char *word
, *state
;
4030 ExitStatusSet
*status_set
= data
;
4037 /* Empty assignment resets the list */
4038 if (isempty(rvalue
)) {
4039 exit_status_set_free(status_set
);
4043 FOREACH_WORD(word
, l
, rvalue
, state
) {
4044 _cleanup_free_
char *temp
;
4048 temp
= strndup(word
, l
);
4052 r
= safe_atoi(temp
, &val
);
4054 val
= signal_from_string(temp
);
4057 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse value, ignoring: %s", word
);
4060 set
= &status_set
->signal
;
4062 if (val
< 0 || val
> 255) {
4063 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Value %d is outside range 0-255, ignoring", val
);
4066 set
= &status_set
->status
;
4069 r
= set_ensure_allocated(set
, NULL
);
4073 r
= set_put(*set
, INT_TO_PTR(val
));
4075 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Unable to store: %s", word
);
4079 if (!isempty(state
))
4080 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Trailing garbage, ignoring.");
4085 int config_parse_namespace_path_strv(
4087 const char *filename
,
4089 const char *section
,
4090 unsigned section_line
,
4107 if (isempty(rvalue
)) {
4108 /* Empty assignment resets the list */
4109 *sv
= strv_free(*sv
);
4115 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
, *joined
= NULL
;
4117 bool ignore_enoent
= false, shall_prefix
= false;
4119 r
= extract_first_word(&cur
, &word
, NULL
, EXTRACT_QUOTES
);
4125 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
4129 if (!utf8_is_valid(word
)) {
4130 log_syntax_invalid_utf8(unit
, LOG_ERR
, filename
, line
, word
);
4135 if (startswith(w
, "-")) {
4136 ignore_enoent
= true;
4139 if (startswith(w
, "+")) {
4140 shall_prefix
= true;
4144 r
= unit_full_printf(u
, w
, &resolved
);
4146 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve specifiers in %s: %m", word
);
4150 if (!path_is_absolute(resolved
)) {
4151 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Not an absolute path, ignoring: %s", resolved
);
4155 path_kill_slashes(resolved
);
4157 joined
= strjoin(ignore_enoent
? "-" : "",
4158 shall_prefix
? "+" : "",
4161 r
= strv_push(sv
, joined
);
4171 int config_parse_temporary_filesystems(
4173 const char *filename
,
4175 const char *section
,
4176 unsigned section_line
,
4184 ExecContext
*c
= data
;
4193 if (isempty(rvalue
)) {
4194 /* Empty assignment resets the list */
4195 temporary_filesystem_free_many(c
->temporary_filesystems
, c
->n_temporary_filesystems
);
4196 c
->temporary_filesystems
= NULL
;
4197 c
->n_temporary_filesystems
= 0;
4203 _cleanup_free_
char *word
= NULL
, *path
= NULL
, *resolved
= NULL
;
4206 r
= extract_first_word(&cur
, &word
, NULL
, EXTRACT_QUOTES
);
4212 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
4217 r
= extract_first_word(&w
, &path
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4223 r
= unit_full_printf(u
, path
, &resolved
);
4225 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve specifiers in %s, ignoring: %m", word
);
4229 if (!path_is_absolute(resolved
)) {
4230 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Not an absolute path, ignoring: %s", resolved
);
4234 path_kill_slashes(resolved
);
4236 r
= temporary_filesystem_add(&c
->temporary_filesystems
, &c
->n_temporary_filesystems
, path
, w
);
4240 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse mount options, ignoring: %s", word
);
4248 int config_parse_bind_paths(
4250 const char *filename
,
4252 const char *section
,
4253 unsigned section_line
,
4260 ExecContext
*c
= data
;
4270 if (isempty(rvalue
)) {
4271 /* Empty assignment resets the list */
4272 bind_mount_free_many(c
->bind_mounts
, c
->n_bind_mounts
);
4273 c
->bind_mounts
= NULL
;
4274 c
->n_bind_mounts
= 0;
4280 _cleanup_free_
char *source
= NULL
, *destination
= NULL
;
4281 _cleanup_free_
char *sresolved
= NULL
, *dresolved
= NULL
;
4282 char *s
= NULL
, *d
= NULL
;
4283 bool rbind
= true, ignore_enoent
= false;
4285 r
= extract_first_word(&p
, &source
, ":" WHITESPACE
, EXTRACT_QUOTES
|EXTRACT_DONT_COALESCE_SEPARATORS
);
4291 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s: %s", lvalue
, rvalue
);
4295 r
= unit_full_printf(u
, source
, &sresolved
);
4297 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4298 "Failed to resolved specifiers in \"%s\", ignoring: %m", source
);
4304 ignore_enoent
= true;
4308 if (!utf8_is_valid(s
)) {
4309 log_syntax_invalid_utf8(unit
, LOG_ERR
, filename
, line
, s
);
4312 if (!path_is_absolute(s
)) {
4313 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Not an absolute source path, ignoring: %s", s
);
4317 path_kill_slashes(s
);
4319 /* Optionally, the destination is specified. */
4320 if (p
&& p
[-1] == ':') {
4321 r
= extract_first_word(&p
, &destination
, ":" WHITESPACE
, EXTRACT_QUOTES
|EXTRACT_DONT_COALESCE_SEPARATORS
);
4325 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s: %s", lvalue
, rvalue
);
4329 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Missing argument after ':': %s", rvalue
);
4333 r
= unit_full_printf(u
, destination
, &dresolved
);
4335 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4336 "Failed to resolved specifiers in \"%s\", ignoring: %m", destination
);
4340 if (!utf8_is_valid(dresolved
)) {
4341 log_syntax_invalid_utf8(unit
, LOG_ERR
, filename
, line
, dresolved
);
4344 if (!path_is_absolute(dresolved
)) {
4345 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Not an absolute destination path, ignoring: %s", dresolved
);
4349 d
= path_kill_slashes(dresolved
);
4351 /* Optionally, there's also a short option string specified */
4352 if (p
&& p
[-1] == ':') {
4353 _cleanup_free_
char *options
= NULL
;
4355 r
= extract_first_word(&p
, &options
, NULL
, EXTRACT_QUOTES
);
4359 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s: %s", lvalue
, rvalue
);
4363 if (isempty(options
) || streq(options
, "rbind"))
4365 else if (streq(options
, "norbind"))
4368 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid option string, ignoring setting: %s", options
);
4375 r
= bind_mount_add(&c
->bind_mounts
, &c
->n_bind_mounts
,
4379 .read_only
= !!strstr(lvalue
, "ReadOnly"),
4381 .ignore_enoent
= ignore_enoent
,
4390 int config_parse_no_new_privileges(
4392 const char *filename
,
4394 const char *section
,
4395 unsigned section_line
,
4402 ExecContext
*c
= data
;
4410 k
= parse_boolean(rvalue
);
4412 log_syntax(unit
, LOG_ERR
, filename
, line
, k
, "Failed to parse boolean value, ignoring: %s", rvalue
);
4416 c
->no_new_privileges
= k
;
4421 int config_parse_protect_home(
4423 const char *filename
,
4425 const char *section
,
4426 unsigned section_line
,
4433 ExecContext
*c
= data
;
4441 /* Our enum shall be a superset of booleans, hence first try
4442 * to parse as boolean, and then as enum */
4444 h
= parse_protect_home_or_bool(rvalue
);
4446 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse protect home value, ignoring: %s", rvalue
);
4450 c
->protect_home
= h
;
4455 int config_parse_protect_system(
4457 const char *filename
,
4459 const char *section
,
4460 unsigned section_line
,
4467 ExecContext
*c
= data
;
4475 /* Our enum shall be a superset of booleans, hence first try
4476 * to parse as boolean, and then as enum */
4478 s
= parse_protect_system_or_bool(rvalue
);
4480 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse protect system value, ignoring: %s", rvalue
);
4484 c
->protect_system
= s
;
4489 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_keyring_mode
, exec_keyring_mode
, ExecKeyringMode
, "Failed to parse keyring mode");
4491 int config_parse_job_timeout_sec(
4493 const char *filename
,
4495 const char *section
,
4496 unsigned section_line
,
4512 r
= parse_sec_fix_0(rvalue
, &usec
);
4514 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse JobTimeoutSec= parameter, ignoring: %s", rvalue
);
4518 /* If the user explicitly changed JobTimeoutSec= also change JobRunningTimeoutSec=, for compatibility with old
4519 * versions. If JobRunningTimeoutSec= was explicitly set, avoid this however as whatever the user picked should
4522 if (!u
->job_running_timeout_set
)
4523 u
->job_running_timeout
= usec
;
4525 u
->job_timeout
= usec
;
4530 int config_parse_job_running_timeout_sec(
4532 const char *filename
,
4534 const char *section
,
4535 unsigned section_line
,
4551 r
= parse_sec_fix_0(rvalue
, &usec
);
4553 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse JobRunningTimeoutSec= parameter, ignoring: %s", rvalue
);
4557 u
->job_running_timeout
= usec
;
4558 u
->job_running_timeout_set
= true;
4563 #define FOLLOW_MAX 8
4565 static int open_follow(char **filename
, FILE **_f
, Set
*names
, char **_final
) {
4576 /* This will update the filename pointer if the loaded file is
4577 * reached by a symlink. The old string will be freed. */
4580 char *target
, *name
;
4582 if (c
++ >= FOLLOW_MAX
)
4585 path_kill_slashes(*filename
);
4587 /* Add the file name we are currently looking at to
4588 * the names of this unit, but only if it is a valid
4590 name
= basename(*filename
);
4591 if (unit_name_is_valid(name
, UNIT_NAME_ANY
)) {
4593 id
= set_get(names
, name
);
4599 r
= set_consume(names
, id
);
4605 /* Try to open the file name, but don't if its a symlink */
4606 fd
= open(*filename
, O_RDONLY
|O_CLOEXEC
|O_NOCTTY
|O_NOFOLLOW
);
4613 /* Hmm, so this is a symlink. Let's read the name, and follow it manually */
4614 r
= readlink_and_make_absolute(*filename
, &target
);
4622 f
= fdopen(fd
, "re");
4634 static int merge_by_names(Unit
**u
, Set
*names
, const char *id
) {
4642 /* Let's try to add in all symlink names we found */
4643 while ((k
= set_steal_first(names
))) {
4645 /* First try to merge in the other name into our
4647 r
= unit_merge_by_name(*u
, k
);
4651 /* Hmm, we couldn't merge the other unit into
4652 * ours? Then let's try it the other way
4655 /* If the symlink name we are looking at is unit template, then
4656 we must search for instance of this template */
4657 if (unit_name_is_valid(k
, UNIT_NAME_TEMPLATE
) && (*u
)->instance
) {
4658 _cleanup_free_
char *instance
= NULL
;
4660 r
= unit_name_replace_instance(k
, (*u
)->instance
, &instance
);
4664 other
= manager_get_unit((*u
)->manager
, instance
);
4666 other
= manager_get_unit((*u
)->manager
, k
);
4671 r
= unit_merge(other
, *u
);
4674 return merge_by_names(u
, names
, NULL
);
4682 unit_choose_id(*u
, id
);
4690 static int load_from_path(Unit
*u
, const char *path
) {
4691 _cleanup_set_free_free_ Set
*symlink_names
= NULL
;
4692 _cleanup_fclose_
FILE *f
= NULL
;
4693 _cleanup_free_
char *filename
= NULL
;
4702 symlink_names
= set_new(&string_hash_ops
);
4706 if (path_is_absolute(path
)) {
4708 filename
= strdup(path
);
4712 r
= open_follow(&filename
, &f
, symlink_names
, &id
);
4714 filename
= mfree(filename
);
4722 STRV_FOREACH(p
, u
->manager
->lookup_paths
.search_path
) {
4724 /* Instead of opening the path right away, we manually
4725 * follow all symlinks and add their name to our unit
4726 * name set while doing so */
4727 filename
= path_make_absolute(path
, *p
);
4731 if (u
->manager
->unit_path_cache
&&
4732 !set_get(u
->manager
->unit_path_cache
, filename
))
4735 r
= open_follow(&filename
, &f
, symlink_names
, &id
);
4738 filename
= mfree(filename
);
4740 /* ENOENT means that the file is missing or is a dangling symlink.
4741 * ENOTDIR means that one of paths we expect to be is a directory
4742 * is not a directory, we should just ignore that.
4743 * EACCES means that the directory or file permissions are wrong.
4746 log_debug_errno(r
, "Cannot access \"%s\": %m", filename
);
4747 else if (!IN_SET(r
, -ENOENT
, -ENOTDIR
))
4750 /* Empty the symlink names for the next run */
4751 set_clear_free(symlink_names
);
4756 /* Hmm, no suitable file found? */
4759 if (!unit_type_may_alias(u
->type
) && set_size(symlink_names
) > 1) {
4760 log_unit_warning(u
, "Unit type of %s does not support alias names, refusing loading via symlink.", u
->id
);
4765 r
= merge_by_names(&merged
, symlink_names
, id
);
4770 u
->load_state
= UNIT_MERGED
;
4774 if (fstat(fileno(f
), &st
) < 0)
4777 if (null_or_empty(&st
)) {
4778 u
->load_state
= UNIT_MASKED
;
4779 u
->fragment_mtime
= 0;
4781 u
->load_state
= UNIT_LOADED
;
4782 u
->fragment_mtime
= timespec_load(&st
.st_mtim
);
4784 /* Now, parse the file contents */
4785 r
= config_parse(u
->id
, filename
, f
,
4786 UNIT_VTABLE(u
)->sections
,
4787 config_item_perf_lookup
, load_fragment_gperf_lookup
,
4788 CONFIG_PARSE_ALLOW_INCLUDE
, u
);
4793 free_and_replace(u
->fragment_path
, filename
);
4795 if (u
->source_path
) {
4796 if (stat(u
->source_path
, &st
) >= 0)
4797 u
->source_mtime
= timespec_load(&st
.st_mtim
);
4799 u
->source_mtime
= 0;
4805 int unit_load_fragment(Unit
*u
) {
4811 assert(u
->load_state
== UNIT_STUB
);
4815 u
->load_state
= UNIT_LOADED
;
4819 /* First, try to find the unit under its id. We always look
4820 * for unit files in the default directories, to make it easy
4821 * to override things by placing things in /etc/systemd/system */
4822 r
= load_from_path(u
, u
->id
);
4826 /* Try to find an alias we can load this with */
4827 if (u
->load_state
== UNIT_STUB
) {
4828 SET_FOREACH(t
, u
->names
, i
) {
4833 r
= load_from_path(u
, t
);
4837 if (u
->load_state
!= UNIT_STUB
)
4842 /* And now, try looking for it under the suggested (originally linked) path */
4843 if (u
->load_state
== UNIT_STUB
&& u
->fragment_path
) {
4845 r
= load_from_path(u
, u
->fragment_path
);
4849 if (u
->load_state
== UNIT_STUB
)
4850 /* Hmm, this didn't work? Then let's get rid
4851 * of the fragment path stored for us, so that
4852 * we don't point to an invalid location. */
4853 u
->fragment_path
= mfree(u
->fragment_path
);
4856 /* Look for a template */
4857 if (u
->load_state
== UNIT_STUB
&& u
->instance
) {
4858 _cleanup_free_
char *k
= NULL
;
4860 r
= unit_name_template(u
->id
, &k
);
4864 r
= load_from_path(u
, k
);
4867 log_unit_notice(u
, "Unit configuration has fatal error, unit will not be started.");
4871 if (u
->load_state
== UNIT_STUB
) {
4872 SET_FOREACH(t
, u
->names
, i
) {
4873 _cleanup_free_
char *z
= NULL
;
4878 r
= unit_name_template(t
, &z
);
4882 r
= load_from_path(u
, z
);
4886 if (u
->load_state
!= UNIT_STUB
)
4895 void unit_dump_config_items(FILE *f
) {
4896 static const struct {
4897 const ConfigParserCallback callback
;
4900 #if !HAVE_SYSV_COMPAT || !HAVE_SECCOMP || !HAVE_PAM || !HAVE_SELINUX || !ENABLE_SMACK || !HAVE_APPARMOR
4901 { config_parse_warn_compat
, "NOTSUPPORTED" },
4903 { config_parse_int
, "INTEGER" },
4904 { config_parse_unsigned
, "UNSIGNED" },
4905 { config_parse_iec_size
, "SIZE" },
4906 { config_parse_iec_uint64
, "SIZE" },
4907 { config_parse_si_size
, "SIZE" },
4908 { config_parse_bool
, "BOOLEAN" },
4909 { config_parse_string
, "STRING" },
4910 { config_parse_path
, "PATH" },
4911 { config_parse_unit_path_printf
, "PATH" },
4912 { config_parse_strv
, "STRING [...]" },
4913 { config_parse_exec_nice
, "NICE" },
4914 { config_parse_exec_oom_score_adjust
, "OOMSCOREADJUST" },
4915 { config_parse_exec_io_class
, "IOCLASS" },
4916 { config_parse_exec_io_priority
, "IOPRIORITY" },
4917 { config_parse_exec_cpu_sched_policy
, "CPUSCHEDPOLICY" },
4918 { config_parse_exec_cpu_sched_prio
, "CPUSCHEDPRIO" },
4919 { config_parse_exec_cpu_affinity
, "CPUAFFINITY" },
4920 { config_parse_mode
, "MODE" },
4921 { config_parse_unit_env_file
, "FILE" },
4922 { config_parse_exec_output
, "OUTPUT" },
4923 { config_parse_exec_input
, "INPUT" },
4924 { config_parse_log_facility
, "FACILITY" },
4925 { config_parse_log_level
, "LEVEL" },
4926 { config_parse_exec_secure_bits
, "SECUREBITS" },
4927 { config_parse_capability_set
, "BOUNDINGSET" },
4928 { config_parse_limit
, "LIMIT" },
4929 { config_parse_unit_deps
, "UNIT [...]" },
4930 { config_parse_exec
, "PATH [ARGUMENT [...]]" },
4931 { config_parse_service_type
, "SERVICETYPE" },
4932 { config_parse_service_restart
, "SERVICERESTART" },
4933 #if HAVE_SYSV_COMPAT
4934 { config_parse_sysv_priority
, "SYSVPRIORITY" },
4936 { config_parse_kill_mode
, "KILLMODE" },
4937 { config_parse_signal
, "SIGNAL" },
4938 { config_parse_socket_listen
, "SOCKET [...]" },
4939 { config_parse_socket_bind
, "SOCKETBIND" },
4940 { config_parse_socket_bindtodevice
, "NETWORKINTERFACE" },
4941 { config_parse_sec
, "SECONDS" },
4942 { config_parse_nsec
, "NANOSECONDS" },
4943 { config_parse_namespace_path_strv
, "PATH [...]" },
4944 { config_parse_bind_paths
, "PATH[:PATH[:OPTIONS]] [...]" },
4945 { config_parse_unit_requires_mounts_for
, "PATH [...]" },
4946 { config_parse_exec_mount_flags
, "MOUNTFLAG [...]" },
4947 { config_parse_unit_string_printf
, "STRING" },
4948 { config_parse_trigger_unit
, "UNIT" },
4949 { config_parse_timer
, "TIMER" },
4950 { config_parse_path_spec
, "PATH" },
4951 { config_parse_notify_access
, "ACCESS" },
4952 { config_parse_ip_tos
, "TOS" },
4953 { config_parse_unit_condition_path
, "CONDITION" },
4954 { config_parse_unit_condition_string
, "CONDITION" },
4955 { config_parse_unit_condition_null
, "CONDITION" },
4956 { config_parse_unit_slice
, "SLICE" },
4957 { config_parse_documentation
, "URL" },
4958 { config_parse_service_timeout
, "SECONDS" },
4959 { config_parse_emergency_action
, "ACTION" },
4960 { config_parse_set_status
, "STATUS" },
4961 { config_parse_service_sockets
, "SOCKETS" },
4962 { config_parse_environ
, "ENVIRON" },
4964 { config_parse_syscall_filter
, "SYSCALLS" },
4965 { config_parse_syscall_archs
, "ARCHS" },
4966 { config_parse_syscall_errno
, "ERRNO" },
4967 { config_parse_address_families
, "FAMILIES" },
4968 { config_parse_restrict_namespaces
, "NAMESPACES" },
4970 { config_parse_cpu_shares
, "SHARES" },
4971 { config_parse_cpu_weight
, "WEIGHT" },
4972 { config_parse_memory_limit
, "LIMIT" },
4973 { config_parse_device_allow
, "DEVICE" },
4974 { config_parse_device_policy
, "POLICY" },
4975 { config_parse_io_limit
, "LIMIT" },
4976 { config_parse_io_weight
, "WEIGHT" },
4977 { config_parse_io_device_weight
, "DEVICEWEIGHT" },
4978 { config_parse_blockio_bandwidth
, "BANDWIDTH" },
4979 { config_parse_blockio_weight
, "WEIGHT" },
4980 { config_parse_blockio_device_weight
, "DEVICEWEIGHT" },
4981 { config_parse_long
, "LONG" },
4982 { config_parse_socket_service
, "SERVICE" },
4984 { config_parse_exec_selinux_context
, "LABEL" },
4986 { config_parse_job_mode
, "MODE" },
4987 { config_parse_job_mode_isolate
, "BOOLEAN" },
4988 { config_parse_personality
, "PERSONALITY" },
4991 const char *prev
= NULL
;
4996 NULSTR_FOREACH(i
, load_fragment_gperf_nulstr
) {
4997 const char *rvalue
= "OTHER", *lvalue
;
5001 const ConfigPerfItem
*p
;
5003 assert_se(p
= load_fragment_gperf_lookup(i
, strlen(i
)));
5005 dot
= strchr(i
, '.');
5006 lvalue
= dot
? dot
+ 1 : i
;
5010 if (!prev
|| !strneq(prev
, i
, prefix_len
+1)) {
5014 fprintf(f
, "[%.*s]\n", (int) prefix_len
, i
);
5017 for (j
= 0; j
< ELEMENTSOF(table
); j
++)
5018 if (p
->parse
== table
[j
].callback
) {
5019 rvalue
= table
[j
].rvalue
;
5023 fprintf(f
, "%s=%s\n", lvalue
, rvalue
);