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 "bus-error.h"
24 #include "bus-internal.h"
27 #include "capability-util.h"
29 #include "conf-parser.h"
30 #include "cpu-set-util.h"
32 #include "errno-list.h"
36 #include "hexdecoct.h"
39 #include "journal-util.h"
40 #include "load-fragment.h"
43 #include "mount-util.h"
44 #include "parse-util.h"
45 #include "path-util.h"
46 #include "process-util.h"
47 #include "rlimit-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"
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(s
->bind_to_device
);
816 s
->bind_to_device
= n
;
821 int config_parse_exec_input(
823 const char *filename
,
826 unsigned section_line
,
833 ExecContext
*c
= data
;
844 n
= startswith(rvalue
, "fd:");
846 _cleanup_free_
char *resolved
= NULL
;
848 r
= unit_full_printf(u
, n
, &resolved
);
850 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers on %s: %m", n
);
852 if (isempty(resolved
))
853 resolved
= mfree(resolved
);
854 else if (!fdname_is_valid(resolved
)) {
855 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name: %s", resolved
);
859 free_and_replace(c
->stdio_fdname
[STDIN_FILENO
], resolved
);
861 ei
= EXEC_INPUT_NAMED_FD
;
863 } else if ((n
= startswith(rvalue
, "file:"))) {
864 _cleanup_free_
char *resolved
= NULL
;
866 r
= unit_full_printf(u
, n
, &resolved
);
868 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers on %s: %m", n
);
870 if (!path_is_absolute(resolved
)) {
871 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "file: requires an absolute path name: %s", resolved
);
875 if (!path_is_normalized(resolved
)) {
876 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "file: requires a normalized path name: %s", resolved
);
880 free_and_replace(c
->stdio_file
[STDIN_FILENO
], resolved
);
882 ei
= EXEC_INPUT_FILE
;
885 ei
= exec_input_from_string(rvalue
);
887 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse input specifier, ignoring: %s", rvalue
);
896 int config_parse_exec_input_text(
898 const char *filename
,
901 unsigned section_line
,
908 _cleanup_free_
char *unescaped
= NULL
, *resolved
= NULL
;
909 ExecContext
*c
= data
;
920 if (isempty(rvalue
)) {
921 /* Reset if the empty string is assigned */
922 c
->stdin_data
= mfree(c
->stdin_data
);
923 c
->stdin_data_size
= 0;
927 r
= cunescape(rvalue
, 0, &unescaped
);
929 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to decode C escaped text: %s", rvalue
);
931 r
= unit_full_printf(u
, unescaped
, &resolved
);
933 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve specifiers: %s", unescaped
);
935 sz
= strlen(resolved
);
936 if (c
->stdin_data_size
+ sz
+ 1 < c
->stdin_data_size
|| /* check for overflow */
937 c
->stdin_data_size
+ sz
+ 1 > EXEC_STDIN_DATA_MAX
) {
938 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
);
942 p
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
+ 1);
946 *((char*) mempcpy((char*) p
+ c
->stdin_data_size
, resolved
, sz
)) = '\n';
949 c
->stdin_data_size
+= sz
+ 1;
954 int config_parse_exec_input_data(
956 const char *filename
,
959 unsigned section_line
,
966 _cleanup_free_
void *p
= NULL
;
967 ExecContext
*c
= data
;
977 if (isempty(rvalue
)) {
978 /* Reset if the empty string is assigned */
979 c
->stdin_data
= mfree(c
->stdin_data
);
980 c
->stdin_data_size
= 0;
984 r
= unbase64mem(rvalue
, (size_t) -1, &p
, &sz
);
986 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to decode base64 data, ignoring: %s", rvalue
);
990 if (c
->stdin_data_size
+ sz
< c
->stdin_data_size
|| /* check for overflow */
991 c
->stdin_data_size
+ sz
> EXEC_STDIN_DATA_MAX
) {
992 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
);
996 q
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
);
1000 memcpy((uint8_t*) q
+ c
->stdin_data_size
, p
, sz
);
1003 c
->stdin_data_size
+= sz
;
1008 int config_parse_exec_output(
1010 const char *filename
,
1012 const char *section
,
1013 unsigned section_line
,
1020 _cleanup_free_
char *resolved
= NULL
;
1022 ExecContext
*c
= data
;
1033 n
= startswith(rvalue
, "fd:");
1035 r
= unit_full_printf(u
, n
, &resolved
);
1037 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers on %s: %m", n
);
1039 if (isempty(resolved
))
1040 resolved
= mfree(resolved
);
1041 else if (!fdname_is_valid(resolved
)) {
1042 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name: %s", resolved
);
1046 eo
= EXEC_OUTPUT_NAMED_FD
;
1048 } else if ((n
= startswith(rvalue
, "file:"))) {
1050 r
= unit_full_printf(u
, n
, &resolved
);
1052 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers on %s: %m", n
);
1054 if (!path_is_absolute(resolved
)) {
1055 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "file: requires an absolute path name: %s", resolved
);
1059 if (!path_is_normalized(resolved
)) {
1060 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "file: requires a normalized path name, ignoring: %s", resolved
);
1064 eo
= EXEC_OUTPUT_FILE
;
1067 eo
= exec_output_from_string(rvalue
);
1069 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse output specifier, ignoring: %s", rvalue
);
1074 if (streq(lvalue
, "StandardOutput")) {
1075 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1076 free_and_replace(c
->stdio_fdname
[STDOUT_FILENO
], resolved
);
1078 free_and_replace(c
->stdio_file
[STDOUT_FILENO
], resolved
);
1083 assert(streq(lvalue
, "StandardError"));
1085 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1086 free_and_replace(c
->stdio_fdname
[STDERR_FILENO
], resolved
);
1088 free_and_replace(c
->stdio_file
[STDERR_FILENO
], resolved
);
1096 int config_parse_exec_io_class(const char *unit
,
1097 const char *filename
,
1099 const char *section
,
1100 unsigned section_line
,
1107 ExecContext
*c
= data
;
1115 x
= ioprio_class_from_string(rvalue
);
1117 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse IO scheduling class, ignoring: %s", rvalue
);
1121 c
->ioprio
= IOPRIO_PRIO_VALUE(x
, IOPRIO_PRIO_DATA(c
->ioprio
));
1122 c
->ioprio_set
= true;
1127 int config_parse_exec_io_priority(const char *unit
,
1128 const char *filename
,
1130 const char *section
,
1131 unsigned section_line
,
1138 ExecContext
*c
= data
;
1146 r
= ioprio_parse_priority(rvalue
, &i
);
1148 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse IO priority, ignoring: %s", rvalue
);
1152 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_PRIO_CLASS(c
->ioprio
), i
);
1153 c
->ioprio_set
= true;
1158 int config_parse_exec_cpu_sched_policy(const char *unit
,
1159 const char *filename
,
1161 const char *section
,
1162 unsigned section_line
,
1170 ExecContext
*c
= data
;
1178 x
= sched_policy_from_string(rvalue
);
1180 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse CPU scheduling policy, ignoring: %s", rvalue
);
1184 c
->cpu_sched_policy
= x
;
1185 /* Moving to or from real-time policy? We need to adjust the priority */
1186 c
->cpu_sched_priority
= CLAMP(c
->cpu_sched_priority
, sched_get_priority_min(x
), sched_get_priority_max(x
));
1187 c
->cpu_sched_set
= true;
1192 int config_parse_exec_cpu_sched_prio(const char *unit
,
1193 const char *filename
,
1195 const char *section
,
1196 unsigned section_line
,
1203 ExecContext
*c
= data
;
1211 r
= safe_atoi(rvalue
, &i
);
1213 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse CPU scheduling policy, ignoring: %s", rvalue
);
1217 /* On Linux RR/FIFO range from 1 to 99 and OTHER/BATCH may only be 0 */
1218 min
= sched_get_priority_min(c
->cpu_sched_policy
);
1219 max
= sched_get_priority_max(c
->cpu_sched_policy
);
1221 if (i
< min
|| i
> max
) {
1222 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "CPU scheduling priority is out of range, ignoring: %s", rvalue
);
1226 c
->cpu_sched_priority
= i
;
1227 c
->cpu_sched_set
= true;
1232 int config_parse_exec_cpu_affinity(const char *unit
,
1233 const char *filename
,
1235 const char *section
,
1236 unsigned section_line
,
1243 ExecContext
*c
= data
;
1244 _cleanup_cpu_free_ cpu_set_t
*cpuset
= NULL
;
1252 ncpus
= parse_cpu_set_and_warn(rvalue
, &cpuset
, unit
, filename
, line
, lvalue
);
1257 /* An empty assignment resets the CPU list */
1258 c
->cpuset
= cpu_set_mfree(c
->cpuset
);
1259 c
->cpuset_ncpus
= 0;
1264 c
->cpuset
= TAKE_PTR(cpuset
);
1265 c
->cpuset_ncpus
= (unsigned) ncpus
;
1269 if (c
->cpuset_ncpus
< (unsigned) ncpus
) {
1270 CPU_OR_S(CPU_ALLOC_SIZE(c
->cpuset_ncpus
), cpuset
, c
->cpuset
, cpuset
);
1271 CPU_FREE(c
->cpuset
);
1272 c
->cpuset
= TAKE_PTR(cpuset
);
1273 c
->cpuset_ncpus
= (unsigned) ncpus
;
1277 CPU_OR_S(CPU_ALLOC_SIZE((unsigned) ncpus
), c
->cpuset
, c
->cpuset
, cpuset
);
1282 int config_parse_exec_secure_bits(const char *unit
,
1283 const char *filename
,
1285 const char *section
,
1286 unsigned section_line
,
1293 ExecContext
*c
= data
;
1301 if (isempty(rvalue
)) {
1302 /* An empty assignment resets the field */
1307 r
= secure_bits_from_string(rvalue
);
1311 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1312 "Invalid syntax, ignoring: %s", rvalue
);
1321 int config_parse_capability_set(
1323 const char *filename
,
1325 const char *section
,
1326 unsigned section_line
,
1333 uint64_t *capability_set
= data
;
1334 uint64_t sum
= 0, initial
= 0;
1335 bool invert
= false;
1343 if (rvalue
[0] == '~') {
1348 if (streq(lvalue
, "CapabilityBoundingSet"))
1349 initial
= CAP_ALL
; /* initialized to all bits on */
1350 /* else "AmbientCapabilities" initialized to all bits off */
1352 r
= capability_set_from_string(rvalue
, &sum
);
1356 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse word: %s", rvalue
);
1360 if (sum
== 0 || *capability_set
== initial
)
1361 /* "", "~" or uninitialized data -> replace */
1362 *capability_set
= invert
? ~sum
: sum
;
1364 /* previous data -> merge */
1366 *capability_set
&= ~sum
;
1368 *capability_set
|= sum
;
1374 int config_parse_limit(
1376 const char *filename
,
1378 const char *section
,
1379 unsigned section_line
,
1386 struct rlimit
**rl
= data
, d
= {};
1394 r
= rlimit_parse(ltype
, rvalue
, &d
);
1396 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Soft resource limit chosen higher than hard limit, ignoring: %s", rvalue
);
1400 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse resource value, ignoring: %s", rvalue
);
1407 rl
[ltype
] = newdup(struct rlimit
, &d
, 1);
1415 #if HAVE_SYSV_COMPAT
1416 int config_parse_sysv_priority(const char *unit
,
1417 const char *filename
,
1419 const char *section
,
1420 unsigned section_line
,
1427 int *priority
= data
;
1435 r
= safe_atoi(rvalue
, &i
);
1436 if (r
< 0 || i
< 0) {
1437 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse SysV start priority, ignoring: %s", rvalue
);
1441 *priority
= (int) i
;
1446 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_utmp_mode
, exec_utmp_mode
, ExecUtmpMode
, "Failed to parse utmp mode");
1447 DEFINE_CONFIG_PARSE_ENUM(config_parse_kill_mode
, kill_mode
, KillMode
, "Failed to parse kill mode");
1449 int config_parse_exec_mount_flags(
1451 const char *filename
,
1453 const char *section
,
1454 unsigned section_line
,
1462 ExecContext
*c
= data
;
1470 r
= mount_propagation_flags_from_string(rvalue
, &c
->mount_flags
);
1472 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse mount flag %s, ignoring.", rvalue
);
1477 int config_parse_exec_selinux_context(
1479 const char *filename
,
1481 const char *section
,
1482 unsigned section_line
,
1489 ExecContext
*c
= data
;
1500 if (isempty(rvalue
)) {
1501 c
->selinux_context
= mfree(c
->selinux_context
);
1502 c
->selinux_context_ignore
= false;
1506 if (rvalue
[0] == '-') {
1512 r
= unit_full_printf(u
, rvalue
, &k
);
1514 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1515 "Failed to resolve specifiers%s: %m",
1516 ignore
? ", ignoring" : "");
1517 return ignore
? 0 : -ENOEXEC
;
1520 free(c
->selinux_context
);
1521 c
->selinux_context
= k
;
1522 c
->selinux_context_ignore
= ignore
;
1527 int config_parse_exec_apparmor_profile(
1529 const char *filename
,
1531 const char *section
,
1532 unsigned section_line
,
1539 ExecContext
*c
= data
;
1550 if (isempty(rvalue
)) {
1551 c
->apparmor_profile
= mfree(c
->apparmor_profile
);
1552 c
->apparmor_profile_ignore
= false;
1556 if (rvalue
[0] == '-') {
1562 r
= unit_full_printf(u
, rvalue
, &k
);
1564 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1565 "Failed to resolve specifiers%s: %m",
1566 ignore
? ", ignoring" : "");
1567 return ignore
? 0 : -ENOEXEC
;
1570 free(c
->apparmor_profile
);
1571 c
->apparmor_profile
= k
;
1572 c
->apparmor_profile_ignore
= ignore
;
1577 int config_parse_exec_smack_process_label(
1579 const char *filename
,
1581 const char *section
,
1582 unsigned section_line
,
1589 ExecContext
*c
= data
;
1600 if (isempty(rvalue
)) {
1601 c
->smack_process_label
= mfree(c
->smack_process_label
);
1602 c
->smack_process_label_ignore
= false;
1606 if (rvalue
[0] == '-') {
1612 r
= unit_full_printf(u
, rvalue
, &k
);
1614 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1615 "Failed to resolve specifiers%s: %m",
1616 ignore
? ", ignoring" : "");
1617 return ignore
? 0 : -ENOEXEC
;
1620 free(c
->smack_process_label
);
1621 c
->smack_process_label
= k
;
1622 c
->smack_process_label_ignore
= ignore
;
1627 int config_parse_timer(const char *unit
,
1628 const char *filename
,
1630 const char *section
,
1631 unsigned section_line
,
1642 CalendarSpec
*c
= NULL
;
1644 _cleanup_free_
char *k
= NULL
;
1652 if (isempty(rvalue
)) {
1653 /* Empty assignment resets list */
1654 timer_free_values(t
);
1658 b
= timer_base_from_string(lvalue
);
1660 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse timer base, ignoring: %s", lvalue
);
1664 r
= unit_full_printf(u
, rvalue
, &k
);
1666 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
1670 if (b
== TIMER_CALENDAR
) {
1671 if (calendar_spec_from_string(k
, &c
) < 0) {
1672 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse calendar specification, ignoring: %s", k
);
1676 if (parse_sec(k
, &usec
) < 0) {
1677 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse timer value, ignoring: %s", k
);
1682 v
= new0(TimerValue
, 1);
1684 calendar_spec_free(c
);
1690 v
->calendar_spec
= c
;
1692 LIST_PREPEND(value
, t
->values
, v
);
1697 int config_parse_trigger_unit(
1699 const char *filename
,
1701 const char *section
,
1702 unsigned section_line
,
1709 _cleanup_free_
char *p
= NULL
;
1719 if (!hashmap_isempty(u
->dependencies
[UNIT_TRIGGERS
])) {
1720 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Multiple units to trigger specified, ignoring: %s", rvalue
);
1724 r
= unit_name_printf(u
, rvalue
, &p
);
1726 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve specifiers, ignoring: %m");
1730 type
= unit_name_to_type(p
);
1732 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit type not valid, ignoring: %s", rvalue
);
1735 if (unit_has_name(u
, p
)) {
1736 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Units cannot trigger themselves, ignoring: %s", rvalue
);
1740 r
= unit_add_two_dependencies_by_name(u
, UNIT_BEFORE
, UNIT_TRIGGERS
, p
, NULL
, true, UNIT_DEPENDENCY_FILE
);
1742 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add trigger on %s, ignoring: %m", p
);
1749 int config_parse_path_spec(const char *unit
,
1750 const char *filename
,
1752 const char *section
,
1753 unsigned section_line
,
1763 _cleanup_free_
char *k
= NULL
;
1771 if (isempty(rvalue
)) {
1772 /* Empty assignment clears list */
1777 b
= path_type_from_string(lvalue
);
1779 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse path type, ignoring: %s", lvalue
);
1783 r
= unit_full_printf(UNIT(p
), rvalue
, &k
);
1785 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers on %s. Ignoring.", rvalue
);
1789 if (!path_is_absolute(k
)) {
1790 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Path is not absolute, ignoring: %s", k
);
1794 s
= new0(PathSpec
, 1);
1799 s
->path
= path_kill_slashes(k
);
1804 LIST_PREPEND(spec
, p
->specs
, s
);
1809 int config_parse_socket_service(
1811 const char *filename
,
1813 const char *section
,
1814 unsigned section_line
,
1821 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1822 _cleanup_free_
char *p
= NULL
;
1832 r
= unit_name_printf(UNIT(s
), rvalue
, &p
);
1834 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve specifiers: %s", rvalue
);
1838 if (!endswith(p
, ".service")) {
1839 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit must be of type service: %s", rvalue
);
1843 r
= manager_load_unit(UNIT(s
)->manager
, p
, NULL
, &error
, &x
);
1845 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to load unit %s: %s", rvalue
, bus_error_message(&error
, r
));
1849 unit_ref_set(&s
->service
, UNIT(s
), x
);
1854 int config_parse_fdname(
1856 const char *filename
,
1858 const char *section
,
1859 unsigned section_line
,
1866 _cleanup_free_
char *p
= NULL
;
1875 if (isempty(rvalue
)) {
1876 s
->fdname
= mfree(s
->fdname
);
1880 r
= unit_full_printf(UNIT(s
), rvalue
, &p
);
1882 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve specifiers, ignoring: %s", rvalue
);
1886 if (!fdname_is_valid(p
)) {
1887 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", p
);
1891 return free_and_replace(s
->fdname
, p
);
1894 int config_parse_service_sockets(
1896 const char *filename
,
1898 const char *section
,
1899 unsigned section_line
,
1917 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
1919 r
= extract_first_word(&p
, &word
, NULL
, 0);
1925 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Trailing garbage in sockets, ignoring: %s", rvalue
);
1929 r
= unit_name_printf(UNIT(s
), word
, &k
);
1931 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve specifiers, ignoring: %m");
1935 if (!endswith(k
, ".socket")) {
1936 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit must be of type socket, ignoring: %s", k
);
1940 r
= unit_add_two_dependencies_by_name(UNIT(s
), UNIT_WANTS
, UNIT_AFTER
, k
, NULL
, true, UNIT_DEPENDENCY_FILE
);
1942 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
1944 r
= unit_add_dependency_by_name(UNIT(s
), UNIT_TRIGGERED_BY
, k
, NULL
, true, UNIT_DEPENDENCY_FILE
);
1946 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
1952 int config_parse_bus_name(
1954 const char *filename
,
1956 const char *section
,
1957 unsigned section_line
,
1964 _cleanup_free_
char *k
= NULL
;
1973 r
= unit_full_printf(u
, rvalue
, &k
);
1975 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers on %s, ignoring: %m", rvalue
);
1979 if (!service_name_is_valid(k
)) {
1980 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid bus name %s, ignoring.", k
);
1984 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
1987 int config_parse_service_timeout(
1989 const char *filename
,
1991 const char *section
,
1992 unsigned section_line
,
1999 Service
*s
= userdata
;
2008 /* This is called for three cases: TimeoutSec=, TimeoutStopSec= and TimeoutStartSec=. */
2010 r
= parse_sec(rvalue
, &usec
);
2012 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
2016 /* Traditionally, these options accepted 0 to disable the timeouts. However, a timeout of 0 suggests it happens
2017 * immediately, hence fix this to become USEC_INFINITY instead. This is in-line with how we internally handle
2018 * all other timeouts. */
2020 usec
= USEC_INFINITY
;
2022 if (!streq(lvalue
, "TimeoutStopSec")) {
2023 s
->start_timeout_defined
= true;
2024 s
->timeout_start_usec
= usec
;
2027 if (!streq(lvalue
, "TimeoutStartSec"))
2028 s
->timeout_stop_usec
= usec
;
2033 int config_parse_sec_fix_0(
2035 const char *filename
,
2037 const char *section
,
2038 unsigned section_line
,
2045 usec_t
*usec
= data
;
2053 /* This is pretty much like config_parse_sec(), except that this treats a time of 0 as infinity, for
2054 * compatibility with older versions of systemd where 0 instead of infinity was used as indicator to turn off a
2057 r
= parse_sec_fix_0(rvalue
, usec
);
2059 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
2066 int config_parse_user_group(
2068 const char *filename
,
2070 const char *section
,
2071 unsigned section_line
,
2078 char **user
= data
, *n
;
2087 if (isempty(rvalue
))
2090 _cleanup_free_
char *k
= NULL
;
2092 r
= unit_full_printf(u
, rvalue
, &k
);
2094 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", rvalue
);
2098 if (!valid_user_group_name_or_id(k
)) {
2099 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2112 int config_parse_user_group_strv(
2114 const char *filename
,
2116 const char *section
,
2117 unsigned section_line
,
2124 char ***users
= data
;
2134 if (isempty(rvalue
)) {
2135 *users
= strv_free(*users
);
2141 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2143 r
= extract_first_word(&p
, &word
, NULL
, 0);
2149 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax: %s", rvalue
);
2153 r
= unit_full_printf(u
, word
, &k
);
2155 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", word
);
2159 if (!valid_user_group_name_or_id(k
)) {
2160 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2164 r
= strv_push(users
, k
);
2174 int config_parse_working_directory(
2176 const char *filename
,
2178 const char *section
,
2179 unsigned section_line
,
2186 ExecContext
*c
= data
;
2197 if (rvalue
[0] == '-') {
2203 if (streq(rvalue
, "~")) {
2204 c
->working_directory_home
= true;
2205 c
->working_directory
= mfree(c
->working_directory
);
2207 _cleanup_free_
char *k
= NULL
;
2209 r
= unit_full_printf(u
, rvalue
, &k
);
2211 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2212 "Failed to resolve unit specifiers in working directory path '%s'%s: %m",
2213 rvalue
, missing_ok
? ", ignoring" : "");
2214 return missing_ok
? 0 : -ENOEXEC
;
2217 path_kill_slashes(k
);
2219 if (!utf8_is_valid(k
)) {
2220 log_syntax_invalid_utf8(unit
, LOG_ERR
, filename
, line
, rvalue
);
2221 return missing_ok
? 0 : -ENOEXEC
;
2224 if (!path_is_absolute(k
)) {
2225 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2226 "Working directory path '%s' is not absolute%s.",
2227 rvalue
, missing_ok
? ", ignoring" : "");
2228 return missing_ok
? 0 : -ENOEXEC
;
2231 c
->working_directory_home
= false;
2232 free_and_replace(c
->working_directory
, k
);
2235 c
->working_directory_missing_ok
= missing_ok
;
2239 int config_parse_unit_env_file(const char *unit
,
2240 const char *filename
,
2242 const char *section
,
2243 unsigned section_line
,
2252 _cleanup_free_
char *n
= NULL
;
2260 if (isempty(rvalue
)) {
2261 /* Empty assignment frees the list */
2262 *env
= strv_free(*env
);
2266 r
= unit_full_printf(u
, rvalue
, &n
);
2268 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve specifiers, ignoring: %s", rvalue
);
2272 if (!path_is_absolute(n
[0] == '-' ? n
+ 1 : n
)) {
2273 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Path '%s' is not absolute, ignoring.", n
);
2277 r
= strv_extend(env
, n
);
2284 int config_parse_environ(
2286 const char *filename
,
2288 const char *section
,
2289 unsigned section_line
,
2306 if (isempty(rvalue
)) {
2307 /* Empty assignment resets the list */
2308 *env
= strv_free(*env
);
2312 for (p
= rvalue
;; ) {
2313 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2315 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_QUOTES
);
2321 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2322 "Invalid syntax, ignoring: %s", rvalue
);
2327 r
= unit_full_printf(u
, word
, &k
);
2329 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2330 "Failed to resolve specifiers, ignoring: %s", word
);
2336 if (!env_assignment_is_valid(k
)) {
2337 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2338 "Invalid environment assignment, ignoring: %s", k
);
2342 r
= strv_env_replace(env
, k
);
2350 int config_parse_pass_environ(
2352 const char *filename
,
2354 const char *section
,
2355 unsigned section_line
,
2362 const char *whole_rvalue
= rvalue
;
2363 _cleanup_strv_free_
char **n
= NULL
;
2364 size_t nlen
= 0, nbufsize
= 0;
2365 char*** passenv
= data
;
2374 if (isempty(rvalue
)) {
2375 /* Empty assignment resets the list */
2376 *passenv
= strv_free(*passenv
);
2381 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2383 r
= extract_first_word(&rvalue
, &word
, NULL
, EXTRACT_QUOTES
);
2389 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2390 "Trailing garbage in %s, ignoring: %s", lvalue
, whole_rvalue
);
2395 r
= unit_full_printf(u
, word
, &k
);
2397 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2398 "Failed to resolve specifiers, ignoring: %s", word
);
2404 if (!env_name_is_valid(k
)) {
2405 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2406 "Invalid environment name for %s, ignoring: %s", lvalue
, k
);
2410 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
2413 n
[nlen
++] = TAKE_PTR(k
);
2418 r
= strv_extend_strv(passenv
, n
, true);
2426 int config_parse_unset_environ(
2428 const char *filename
,
2430 const char *section
,
2431 unsigned section_line
,
2438 _cleanup_strv_free_
char **n
= NULL
;
2439 const char *whole_rvalue
= rvalue
;
2440 size_t nlen
= 0, nbufsize
= 0;
2441 char*** unsetenv
= data
;
2450 if (isempty(rvalue
)) {
2451 /* Empty assignment resets the list */
2452 *unsetenv
= strv_free(*unsetenv
);
2457 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2459 r
= extract_first_word(&rvalue
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_QUOTES
);
2465 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2466 "Trailing garbage in %s, ignoring: %s", lvalue
, whole_rvalue
);
2471 r
= unit_full_printf(u
, word
, &k
);
2473 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2474 "Failed to resolve specifiers, ignoring: %s", word
);
2480 if (!env_assignment_is_valid(k
) && !env_name_is_valid(k
)) {
2481 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2482 "Invalid environment name or assignment %s, ignoring: %s", lvalue
, k
);
2486 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
2489 n
[nlen
++] = TAKE_PTR(k
);
2494 r
= strv_extend_strv(unsetenv
, n
, true);
2502 int config_parse_log_extra_fields(
2504 const char *filename
,
2506 const char *section
,
2507 unsigned section_line
,
2514 ExecContext
*c
= data
;
2524 if (isempty(rvalue
)) {
2525 exec_context_free_log_extra_fields(c
);
2529 for (p
= rvalue
;; ) {
2530 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2534 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_QUOTES
);
2540 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
2544 r
= unit_full_printf(u
, word
, &k
);
2546 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers on %s, ignoring field: %m", word
);
2550 eq
= strchr(k
, '=');
2552 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Log field lacks '=' character, ignoring field: %s", k
);
2556 if (!journal_field_valid(k
, eq
-k
, false)) {
2557 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Log field name is invalid, ignoring field: %s", k
);
2561 t
= reallocarray(c
->log_extra_fields
, c
->n_log_extra_fields
+1, sizeof(struct iovec
));
2565 c
->log_extra_fields
= t
;
2566 c
->log_extra_fields
[c
->n_log_extra_fields
++] = IOVEC_MAKE_STRING(k
);
2574 int config_parse_ip_tos(const char *unit
,
2575 const char *filename
,
2577 const char *section
,
2578 unsigned section_line
,
2585 int *ip_tos
= data
, x
;
2592 x
= ip_tos_from_string(rvalue
);
2594 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse IP TOS value, ignoring: %s", rvalue
);
2602 int config_parse_unit_condition_path(
2604 const char *filename
,
2606 const char *section
,
2607 unsigned section_line
,
2614 _cleanup_free_
char *p
= NULL
;
2615 Condition
**list
= data
, *c
;
2616 ConditionType t
= ltype
;
2617 bool trigger
, negate
;
2626 if (isempty(rvalue
)) {
2627 /* Empty assignment resets the list */
2628 *list
= condition_free_list(*list
);
2632 trigger
= rvalue
[0] == '|';
2636 negate
= rvalue
[0] == '!';
2640 r
= unit_full_printf(u
, rvalue
, &p
);
2642 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve specifiers, ignoring: %s", rvalue
);
2646 if (!path_is_absolute(p
)) {
2647 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Path in condition not absolute, ignoring: %s", p
);
2651 c
= condition_new(t
, p
, trigger
, negate
);
2655 LIST_PREPEND(conditions
, *list
, c
);
2659 int config_parse_unit_condition_string(
2661 const char *filename
,
2663 const char *section
,
2664 unsigned section_line
,
2671 _cleanup_free_
char *s
= NULL
;
2672 Condition
**list
= data
, *c
;
2673 ConditionType t
= ltype
;
2674 bool trigger
, negate
;
2683 if (isempty(rvalue
)) {
2684 /* Empty assignment resets the list */
2685 *list
= condition_free_list(*list
);
2689 trigger
= rvalue
[0] == '|';
2693 negate
= rvalue
[0] == '!';
2697 r
= unit_full_printf(u
, rvalue
, &s
);
2699 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve specifiers, ignoring: %s", rvalue
);
2703 c
= condition_new(t
, s
, trigger
, negate
);
2707 LIST_PREPEND(conditions
, *list
, c
);
2711 int config_parse_unit_condition_null(
2713 const char *filename
,
2715 const char *section
,
2716 unsigned section_line
,
2723 Condition
**list
= data
, *c
;
2724 bool trigger
, negate
;
2732 if (isempty(rvalue
)) {
2733 /* Empty assignment resets the list */
2734 *list
= condition_free_list(*list
);
2738 trigger
= rvalue
[0] == '|';
2742 negate
= rvalue
[0] == '!';
2746 b
= parse_boolean(rvalue
);
2748 log_syntax(unit
, LOG_ERR
, filename
, line
, b
, "Failed to parse boolean value in condition, ignoring: %s", rvalue
);
2755 c
= condition_new(CONDITION_NULL
, NULL
, trigger
, negate
);
2759 LIST_PREPEND(conditions
, *list
, c
);
2763 DEFINE_CONFIG_PARSE_ENUM(config_parse_notify_access
, notify_access
, NotifyAccess
, "Failed to parse notify access specifier");
2764 DEFINE_CONFIG_PARSE_ENUM(config_parse_emergency_action
, emergency_action
, EmergencyAction
, "Failed to parse failure action specifier");
2766 int config_parse_unit_requires_mounts_for(
2768 const char *filename
,
2770 const char *section
,
2771 unsigned section_line
,
2787 for (p
= rvalue
;; ) {
2788 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
2790 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
2796 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2797 "Invalid syntax, ignoring: %s", rvalue
);
2801 if (!utf8_is_valid(word
)) {
2802 log_syntax_invalid_utf8(unit
, LOG_ERR
, filename
, line
, rvalue
);
2806 r
= unit_full_printf(u
, word
, &resolved
);
2808 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit name \"%s\", ignoring: %m", word
);
2812 r
= unit_require_mounts_for(u
, resolved
, UNIT_DEPENDENCY_FILE
);
2814 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add required mount \"%s\", ignoring: %m", resolved
);
2820 int config_parse_documentation(const char *unit
,
2821 const char *filename
,
2823 const char *section
,
2824 unsigned section_line
,
2840 if (isempty(rvalue
)) {
2841 /* Empty assignment resets the list */
2842 u
->documentation
= strv_free(u
->documentation
);
2846 r
= config_parse_unit_strv_printf(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
,
2847 rvalue
, data
, userdata
);
2851 for (a
= b
= u
->documentation
; a
&& *a
; a
++) {
2853 if (documentation_url_is_valid(*a
))
2856 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid URL, ignoring: %s", *a
);
2867 int config_parse_syscall_filter(
2869 const char *filename
,
2871 const char *section
,
2872 unsigned section_line
,
2879 ExecContext
*c
= data
;
2881 bool invert
= false;
2890 if (isempty(rvalue
)) {
2891 /* Empty assignment resets the list */
2892 c
->syscall_filter
= hashmap_free(c
->syscall_filter
);
2893 c
->syscall_whitelist
= false;
2897 if (rvalue
[0] == '~') {
2902 if (!c
->syscall_filter
) {
2903 c
->syscall_filter
= hashmap_new(NULL
);
2904 if (!c
->syscall_filter
)
2908 /* Allow everything but the ones listed */
2909 c
->syscall_whitelist
= false;
2911 /* Allow nothing but the ones listed */
2912 c
->syscall_whitelist
= true;
2914 /* Accept default syscalls if we are on a whitelist */
2915 r
= seccomp_parse_syscall_filter("@default", -1, c
->syscall_filter
, SECCOMP_PARSE_WHITELIST
);
2923 _cleanup_free_
char *word
= NULL
, *name
= NULL
;
2926 r
= extract_first_word(&p
, &word
, NULL
, 0);
2932 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
2936 r
= parse_syscall_and_errno(word
, &name
, &num
);
2938 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse syscall:errno, ignoring: %s", word
);
2942 r
= seccomp_parse_syscall_filter_full(name
, num
, c
->syscall_filter
,
2943 SECCOMP_PARSE_LOG
|SECCOMP_PARSE_PERMISSIVE
|(invert
? SECCOMP_PARSE_INVERT
: 0)|(c
->syscall_whitelist
? SECCOMP_PARSE_WHITELIST
: 0),
2944 unit
, filename
, line
);
2952 int config_parse_syscall_archs(
2954 const char *filename
,
2956 const char *section
,
2957 unsigned section_line
,
2968 if (isempty(rvalue
)) {
2969 *archs
= set_free(*archs
);
2973 r
= set_ensure_allocated(archs
, NULL
);
2977 for (p
= rvalue
;;) {
2978 _cleanup_free_
char *word
= NULL
;
2981 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
2987 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2988 "Invalid syntax, ignoring: %s", rvalue
);
2992 r
= seccomp_arch_from_string(word
, &a
);
2994 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2995 "Failed to parse system call architecture \"%s\", ignoring: %m", word
);
2999 r
= set_put(*archs
, UINT32_TO_PTR(a
+ 1));
3005 int config_parse_syscall_errno(
3007 const char *filename
,
3009 const char *section
,
3010 unsigned section_line
,
3017 ExecContext
*c
= data
;
3024 if (isempty(rvalue
)) {
3025 /* Empty assignment resets to KILL */
3026 c
->syscall_errno
= 0;
3030 e
= parse_errno(rvalue
);
3032 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse error number, ignoring: %s", rvalue
);
3036 c
->syscall_errno
= e
;
3040 int config_parse_address_families(
3042 const char *filename
,
3044 const char *section
,
3045 unsigned section_line
,
3052 ExecContext
*c
= data
;
3053 bool invert
= false;
3061 if (isempty(rvalue
)) {
3062 /* Empty assignment resets the list */
3063 c
->address_families
= set_free(c
->address_families
);
3064 c
->address_families_whitelist
= false;
3068 if (rvalue
[0] == '~') {
3073 if (!c
->address_families
) {
3074 c
->address_families
= set_new(NULL
);
3075 if (!c
->address_families
)
3078 c
->address_families_whitelist
= !invert
;
3081 for (p
= rvalue
;;) {
3082 _cleanup_free_
char *word
= NULL
;
3085 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
3091 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3092 "Invalid syntax, ignoring: %s", rvalue
);
3096 af
= af_from_name(word
);
3098 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
3099 "Failed to parse address family \"%s\", ignoring: %m", word
);
3103 /* If we previously wanted to forbid an address family and now
3104 * we want to allow it, then just remove it from the list.
3106 if (!invert
== c
->address_families_whitelist
) {
3107 r
= set_put(c
->address_families
, INT_TO_PTR(af
));
3111 set_remove(c
->address_families
, INT_TO_PTR(af
));
3115 int config_parse_restrict_namespaces(
3117 const char *filename
,
3119 const char *section
,
3120 unsigned section_line
,
3127 ExecContext
*c
= data
;
3128 bool invert
= false;
3131 if (isempty(rvalue
)) {
3132 /* Reset to the default. */
3133 c
->restrict_namespaces
= NAMESPACE_FLAGS_ALL
;
3137 if (rvalue
[0] == '~') {
3142 r
= parse_boolean(rvalue
);
3144 c
->restrict_namespaces
= 0;
3146 c
->restrict_namespaces
= NAMESPACE_FLAGS_ALL
;
3148 /* Not a boolean argument, in this case it's a list of namespace types. */
3150 r
= namespace_flag_from_string_many(rvalue
, &c
->restrict_namespaces
);
3152 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse namespace type string, ignoring: %s", rvalue
);
3158 c
->restrict_namespaces
= (~c
->restrict_namespaces
) & NAMESPACE_FLAGS_ALL
;
3164 int config_parse_unit_slice(
3166 const char *filename
,
3168 const char *section
,
3169 unsigned section_line
,
3176 _cleanup_free_
char *k
= NULL
;
3177 Unit
*u
= userdata
, *slice
= NULL
;
3185 r
= unit_name_printf(u
, rvalue
, &k
);
3187 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers on %s. Ignoring.", rvalue
);
3191 r
= manager_load_unit(u
->manager
, k
, NULL
, NULL
, &slice
);
3193 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to load slice unit %s. Ignoring.", k
);
3197 r
= unit_set_slice(u
, slice
);
3199 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to assign slice %s to unit %s. Ignoring.", slice
->id
, u
->id
);
3206 DEFINE_CONFIG_PARSE_ENUM(config_parse_device_policy
, cgroup_device_policy
, CGroupDevicePolicy
, "Failed to parse device policy");
3208 int config_parse_cpu_weight(
3210 const char *filename
,
3212 const char *section
,
3213 unsigned section_line
,
3220 uint64_t *weight
= data
;
3227 r
= cg_weight_parse(rvalue
, weight
);
3229 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "CPU weight '%s' invalid. Ignoring.", rvalue
);
3236 int config_parse_cpu_shares(
3238 const char *filename
,
3240 const char *section
,
3241 unsigned section_line
,
3248 uint64_t *shares
= data
;
3255 r
= cg_cpu_shares_parse(rvalue
, shares
);
3257 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "CPU shares '%s' invalid. Ignoring.", rvalue
);
3264 int config_parse_cpu_quota(
3266 const char *filename
,
3268 const char *section
,
3269 unsigned section_line
,
3276 CGroupContext
*c
= data
;
3283 if (isempty(rvalue
)) {
3284 c
->cpu_quota_per_sec_usec
= USEC_INFINITY
;
3288 r
= parse_percent_unbounded(rvalue
);
3290 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "CPU quota '%s' invalid. Ignoring.", rvalue
);
3294 c
->cpu_quota_per_sec_usec
= ((usec_t
) r
* USEC_PER_SEC
) / 100U;
3298 int config_parse_memory_limit(
3300 const char *filename
,
3302 const char *section
,
3303 unsigned section_line
,
3310 CGroupContext
*c
= data
;
3311 uint64_t bytes
= CGROUP_LIMIT_MAX
;
3314 if (!isempty(rvalue
) && !streq(rvalue
, "infinity")) {
3316 r
= parse_percent(rvalue
);
3318 r
= parse_size(rvalue
, 1024, &bytes
);
3320 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Memory limit '%s' invalid. Ignoring.", rvalue
);
3324 bytes
= physical_memory_scale(r
, 100U);
3326 if (bytes
>= UINT64_MAX
||
3327 (bytes
<= 0 && !streq(lvalue
, "MemorySwapMax"))) {
3328 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Memory limit '%s' out of range. Ignoring.", rvalue
);
3333 if (streq(lvalue
, "MemoryLow"))
3334 c
->memory_low
= bytes
;
3335 else if (streq(lvalue
, "MemoryHigh"))
3336 c
->memory_high
= bytes
;
3337 else if (streq(lvalue
, "MemoryMax"))
3338 c
->memory_max
= bytes
;
3339 else if (streq(lvalue
, "MemorySwapMax"))
3340 c
->memory_swap_max
= bytes
;
3341 else if (streq(lvalue
, "MemoryLimit"))
3342 c
->memory_limit
= bytes
;
3349 int config_parse_tasks_max(
3351 const char *filename
,
3353 const char *section
,
3354 unsigned section_line
,
3361 uint64_t *tasks_max
= data
, v
;
3365 if (isempty(rvalue
)) {
3366 *tasks_max
= u
->manager
->default_tasks_max
;
3370 if (streq(rvalue
, "infinity")) {
3371 *tasks_max
= CGROUP_LIMIT_MAX
;
3375 r
= parse_percent(rvalue
);
3377 r
= safe_atou64(rvalue
, &v
);
3379 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Maximum tasks value '%s' invalid. Ignoring.", rvalue
);
3383 v
= system_tasks_max_scale(r
, 100U);
3385 if (v
<= 0 || v
>= UINT64_MAX
) {
3386 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Maximum tasks value '%s' out of range. Ignoring.", rvalue
);
3394 int config_parse_delegate(
3396 const char *filename
,
3398 const char *section
,
3399 unsigned section_line
,
3406 CGroupContext
*c
= data
;
3409 /* We either accept a boolean value, which may be used to turn on delegation for all controllers, or turn it
3410 * off for all. Or it takes a list of controller names, in which case we add the specified controllers to the
3411 * mask to delegate. */
3413 if (isempty(rvalue
)) {
3415 c
->delegate_controllers
= 0;
3419 r
= parse_boolean(rvalue
);
3421 const char *p
= rvalue
;
3422 CGroupMask mask
= 0;
3425 _cleanup_free_
char *word
= NULL
;
3426 CGroupController cc
;
3428 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
3434 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3438 cc
= cgroup_controller_from_string(word
);
3440 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid controller name '%s', ignoring", rvalue
);
3444 mask
|= CGROUP_CONTROLLER_TO_MASK(cc
);
3448 c
->delegate_controllers
|= mask
;
3452 c
->delegate_controllers
= _CGROUP_MASK_ALL
;
3454 c
->delegate
= false;
3455 c
->delegate_controllers
= 0;
3461 int config_parse_device_allow(
3463 const char *filename
,
3465 const char *section
,
3466 unsigned section_line
,
3473 _cleanup_free_
char *path
= NULL
, *t
= NULL
;
3474 CGroupContext
*c
= data
;
3475 CGroupDeviceAllow
*a
;
3476 const char *m
= NULL
;
3480 if (isempty(rvalue
)) {
3481 while (c
->device_allow
)
3482 cgroup_context_free_device_allow(c
, c
->device_allow
);
3487 r
= unit_full_printf(userdata
, rvalue
, &t
);
3489 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3490 "Failed to resolve specifiers in %s, ignoring: %m",
3495 n
= strcspn(t
, WHITESPACE
);
3497 path
= strndup(t
, n
);
3501 if (!is_deviceallow_pattern(path
) &&
3502 !path_startswith(path
, "/run/systemd/inaccessible/")) {
3503 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device node path '%s'. Ignoring.", path
);
3507 m
= t
+ n
+ strspn(t
+ n
, WHITESPACE
);
3511 if (!in_charset(m
, "rwm")) {
3512 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device rights '%s'. Ignoring.", m
);
3516 a
= new0(CGroupDeviceAllow
, 1);
3520 a
->path
= TAKE_PTR(path
);
3521 a
->r
= !!strchr(m
, 'r');
3522 a
->w
= !!strchr(m
, 'w');
3523 a
->m
= !!strchr(m
, 'm');
3525 LIST_PREPEND(device_allow
, c
->device_allow
, a
);
3529 int config_parse_io_weight(
3531 const char *filename
,
3533 const char *section
,
3534 unsigned section_line
,
3541 uint64_t *weight
= data
;
3548 r
= cg_weight_parse(rvalue
, weight
);
3550 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "IO weight '%s' invalid. Ignoring.", rvalue
);
3557 int config_parse_io_device_weight(
3559 const char *filename
,
3561 const char *section
,
3562 unsigned section_line
,
3569 _cleanup_free_
char *path
= NULL
;
3570 CGroupIODeviceWeight
*w
;
3571 CGroupContext
*c
= data
;
3581 if (isempty(rvalue
)) {
3582 while (c
->io_device_weights
)
3583 cgroup_context_free_io_device_weight(c
, c
->io_device_weights
);
3588 n
= strcspn(rvalue
, WHITESPACE
);
3589 weight
= rvalue
+ n
;
3590 weight
+= strspn(weight
, WHITESPACE
);
3592 if (isempty(weight
)) {
3593 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Expected block device and device weight. Ignoring.");
3597 path
= strndup(rvalue
, n
);
3601 if (!path_startswith(path
, "/dev") &&
3602 !path_startswith(path
, "/run/systemd/inaccessible/")) {
3603 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device node path '%s'. Ignoring.", path
);
3607 r
= cg_weight_parse(weight
, &u
);
3609 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "IO weight '%s' invalid. Ignoring.", weight
);
3613 assert(u
!= CGROUP_WEIGHT_INVALID
);
3615 w
= new0(CGroupIODeviceWeight
, 1);
3619 w
->path
= TAKE_PTR(path
);
3623 LIST_PREPEND(device_weights
, c
->io_device_weights
, w
);
3627 int config_parse_io_limit(
3629 const char *filename
,
3631 const char *section
,
3632 unsigned section_line
,
3639 _cleanup_free_
char *path
= NULL
;
3640 CGroupIODeviceLimit
*l
= NULL
, *t
;
3641 CGroupContext
*c
= data
;
3642 CGroupIOLimitType type
;
3652 type
= cgroup_io_limit_type_from_string(lvalue
);
3655 if (isempty(rvalue
)) {
3656 LIST_FOREACH(device_limits
, l
, c
->io_device_limits
)
3657 l
->limits
[type
] = cgroup_io_limit_defaults
[type
];
3661 n
= strcspn(rvalue
, WHITESPACE
);
3663 limit
+= strspn(limit
, WHITESPACE
);
3666 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Expected space separated pair of device node and bandwidth. Ignoring.");
3670 path
= strndup(rvalue
, n
);
3674 if (!path_startswith(path
, "/dev") &&
3675 !path_startswith(path
, "/run/systemd/inaccessible/")) {
3676 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device node path '%s'. Ignoring.", path
);
3680 if (streq("infinity", limit
)) {
3681 num
= CGROUP_LIMIT_MAX
;
3683 r
= parse_size(limit
, 1000, &num
);
3684 if (r
< 0 || num
<= 0) {
3685 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "IO Limit '%s' invalid. Ignoring.", rvalue
);
3690 LIST_FOREACH(device_limits
, t
, c
->io_device_limits
) {
3691 if (path_equal(path
, t
->path
)) {
3698 CGroupIOLimitType ttype
;
3700 l
= new0(CGroupIODeviceLimit
, 1);
3704 l
->path
= TAKE_PTR(path
);
3705 for (ttype
= 0; ttype
< _CGROUP_IO_LIMIT_TYPE_MAX
; ttype
++)
3706 l
->limits
[ttype
] = cgroup_io_limit_defaults
[ttype
];
3708 LIST_PREPEND(device_limits
, c
->io_device_limits
, l
);
3711 l
->limits
[type
] = num
;
3716 int config_parse_blockio_weight(
3718 const char *filename
,
3720 const char *section
,
3721 unsigned section_line
,
3728 uint64_t *weight
= data
;
3735 r
= cg_blkio_weight_parse(rvalue
, weight
);
3737 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Block IO weight '%s' invalid. Ignoring.", rvalue
);
3744 int config_parse_blockio_device_weight(
3746 const char *filename
,
3748 const char *section
,
3749 unsigned section_line
,
3756 _cleanup_free_
char *path
= NULL
;
3757 CGroupBlockIODeviceWeight
*w
;
3758 CGroupContext
*c
= data
;
3768 if (isempty(rvalue
)) {
3769 while (c
->blockio_device_weights
)
3770 cgroup_context_free_blockio_device_weight(c
, c
->blockio_device_weights
);
3775 n
= strcspn(rvalue
, WHITESPACE
);
3776 weight
= rvalue
+ n
;
3777 weight
+= strspn(weight
, WHITESPACE
);
3779 if (isempty(weight
)) {
3780 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Expected block device and device weight. Ignoring.");
3784 path
= strndup(rvalue
, n
);
3788 if (!path_startswith(path
, "/dev") &&
3789 !path_startswith(path
, "/run/systemd/inaccessible/")) {
3790 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device node path '%s'. Ignoring.", path
);
3794 r
= cg_blkio_weight_parse(weight
, &u
);
3796 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Block IO weight '%s' invalid. Ignoring.", weight
);
3800 assert(u
!= CGROUP_BLKIO_WEIGHT_INVALID
);
3802 w
= new0(CGroupBlockIODeviceWeight
, 1);
3806 w
->path
= TAKE_PTR(path
);
3810 LIST_PREPEND(device_weights
, c
->blockio_device_weights
, w
);
3814 int config_parse_blockio_bandwidth(
3816 const char *filename
,
3818 const char *section
,
3819 unsigned section_line
,
3826 _cleanup_free_
char *path
= NULL
;
3827 CGroupBlockIODeviceBandwidth
*b
= NULL
, *t
;
3828 CGroupContext
*c
= data
;
3829 const char *bandwidth
;
3839 read
= streq("BlockIOReadBandwidth", lvalue
);
3841 if (isempty(rvalue
)) {
3842 LIST_FOREACH(device_bandwidths
, b
, c
->blockio_device_bandwidths
) {
3843 b
->rbps
= CGROUP_LIMIT_MAX
;
3844 b
->wbps
= CGROUP_LIMIT_MAX
;
3849 n
= strcspn(rvalue
, WHITESPACE
);
3850 bandwidth
= rvalue
+ n
;
3851 bandwidth
+= strspn(bandwidth
, WHITESPACE
);
3854 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Expected space separated pair of device node and bandwidth. Ignoring.");
3858 path
= strndup(rvalue
, n
);
3862 if (!path_startswith(path
, "/dev") &&
3863 !path_startswith(path
, "/run/systemd/inaccessible/")) {
3864 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device node path '%s'. Ignoring.", path
);
3868 r
= parse_size(bandwidth
, 1000, &bytes
);
3869 if (r
< 0 || bytes
<= 0) {
3870 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Block IO Bandwidth '%s' invalid. Ignoring.", rvalue
);
3874 LIST_FOREACH(device_bandwidths
, t
, c
->blockio_device_bandwidths
) {
3875 if (path_equal(path
, t
->path
)) {
3882 b
= new0(CGroupBlockIODeviceBandwidth
, 1);
3886 b
->path
= TAKE_PTR(path
);
3887 b
->rbps
= CGROUP_LIMIT_MAX
;
3888 b
->wbps
= CGROUP_LIMIT_MAX
;
3890 LIST_PREPEND(device_bandwidths
, c
->blockio_device_bandwidths
, b
);
3901 DEFINE_CONFIG_PARSE_ENUM(config_parse_job_mode
, job_mode
, JobMode
, "Failed to parse job mode");
3903 int config_parse_job_mode_isolate(
3905 const char *filename
,
3907 const char *section
,
3908 unsigned section_line
,
3922 r
= parse_boolean(rvalue
);
3924 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse boolean, ignoring: %s", rvalue
);
3928 log_notice("%s is deprecated. Please use OnFailureJobMode= instead", lvalue
);
3930 *m
= r
? JOB_ISOLATE
: JOB_REPLACE
;
3934 DEFINE_CONFIG_PARSE_ENUM(config_parse_runtime_preserve_mode
, exec_preserve_mode
, ExecPreserveMode
, "Failed to parse runtime directory preserve mode");
3936 int config_parse_exec_directories(
3938 const char *filename
,
3940 const char *section
,
3941 unsigned section_line
,
3958 if (isempty(rvalue
)) {
3959 /* Empty assignment resets the list */
3960 *rt
= strv_free(*rt
);
3964 for (p
= rvalue
;;) {
3965 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
3967 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
3971 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3972 "Invalid syntax, ignoring: %s", rvalue
);
3978 r
= unit_full_printf(u
, word
, &k
);
3980 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
3981 "Failed to resolve specifiers in \"%s\", ignoring: %m", word
);
3985 if (!path_is_normalized(k
) || path_is_absolute(k
)) {
3986 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
3987 "%s= path is not valid, ignoring assignment: %s", lvalue
, rvalue
);
3991 r
= strv_push(rt
, k
);
3998 int config_parse_set_status(
4000 const char *filename
,
4002 const char *section
,
4003 unsigned section_line
,
4011 const char *word
, *state
;
4013 ExitStatusSet
*status_set
= data
;
4020 /* Empty assignment resets the list */
4021 if (isempty(rvalue
)) {
4022 exit_status_set_free(status_set
);
4026 FOREACH_WORD(word
, l
, rvalue
, state
) {
4027 _cleanup_free_
char *temp
;
4031 temp
= strndup(word
, l
);
4035 r
= safe_atoi(temp
, &val
);
4037 val
= signal_from_string_try_harder(temp
);
4040 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse value, ignoring: %s", word
);
4043 set
= &status_set
->signal
;
4045 if (val
< 0 || val
> 255) {
4046 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Value %d is outside range 0-255, ignoring", val
);
4049 set
= &status_set
->status
;
4052 r
= set_ensure_allocated(set
, NULL
);
4056 r
= set_put(*set
, INT_TO_PTR(val
));
4058 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Unable to store: %s", word
);
4062 if (!isempty(state
))
4063 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Trailing garbage, ignoring.");
4068 int config_parse_namespace_path_strv(
4070 const char *filename
,
4072 const char *section
,
4073 unsigned section_line
,
4090 if (isempty(rvalue
)) {
4091 /* Empty assignment resets the list */
4092 *sv
= strv_free(*sv
);
4098 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
, *joined
= NULL
;
4100 bool ignore_enoent
= false, shall_prefix
= false;
4102 r
= extract_first_word(&cur
, &word
, NULL
, EXTRACT_QUOTES
);
4108 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
4112 if (!utf8_is_valid(word
)) {
4113 log_syntax_invalid_utf8(unit
, LOG_ERR
, filename
, line
, word
);
4118 if (startswith(w
, "-")) {
4119 ignore_enoent
= true;
4122 if (startswith(w
, "+")) {
4123 shall_prefix
= true;
4127 r
= unit_full_printf(u
, w
, &resolved
);
4129 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve specifiers in %s: %m", word
);
4133 if (!path_is_absolute(resolved
)) {
4134 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Not an absolute path, ignoring: %s", resolved
);
4138 path_kill_slashes(resolved
);
4140 joined
= strjoin(ignore_enoent
? "-" : "",
4141 shall_prefix
? "+" : "",
4144 r
= strv_push(sv
, joined
);
4154 int config_parse_temporary_filesystems(
4156 const char *filename
,
4158 const char *section
,
4159 unsigned section_line
,
4167 ExecContext
*c
= data
;
4176 if (isempty(rvalue
)) {
4177 /* Empty assignment resets the list */
4178 temporary_filesystem_free_many(c
->temporary_filesystems
, c
->n_temporary_filesystems
);
4179 c
->temporary_filesystems
= NULL
;
4180 c
->n_temporary_filesystems
= 0;
4186 _cleanup_free_
char *word
= NULL
, *path
= NULL
, *resolved
= NULL
;
4189 r
= extract_first_word(&cur
, &word
, NULL
, EXTRACT_QUOTES
);
4195 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
4200 r
= extract_first_word(&w
, &path
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4206 r
= unit_full_printf(u
, path
, &resolved
);
4208 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve specifiers in %s, ignoring: %m", word
);
4212 if (!path_is_absolute(resolved
)) {
4213 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Not an absolute path, ignoring: %s", resolved
);
4217 path_kill_slashes(resolved
);
4219 r
= temporary_filesystem_add(&c
->temporary_filesystems
, &c
->n_temporary_filesystems
, path
, w
);
4223 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse mount options, ignoring: %s", word
);
4231 int config_parse_bind_paths(
4233 const char *filename
,
4235 const char *section
,
4236 unsigned section_line
,
4243 ExecContext
*c
= data
;
4253 if (isempty(rvalue
)) {
4254 /* Empty assignment resets the list */
4255 bind_mount_free_many(c
->bind_mounts
, c
->n_bind_mounts
);
4256 c
->bind_mounts
= NULL
;
4257 c
->n_bind_mounts
= 0;
4263 _cleanup_free_
char *source
= NULL
, *destination
= NULL
;
4264 _cleanup_free_
char *sresolved
= NULL
, *dresolved
= NULL
;
4265 char *s
= NULL
, *d
= NULL
;
4266 bool rbind
= true, ignore_enoent
= false;
4268 r
= extract_first_word(&p
, &source
, ":" WHITESPACE
, EXTRACT_QUOTES
|EXTRACT_DONT_COALESCE_SEPARATORS
);
4274 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s: %s", lvalue
, rvalue
);
4278 r
= unit_full_printf(u
, source
, &sresolved
);
4280 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4281 "Failed to resolved specifiers in \"%s\", ignoring: %m", source
);
4287 ignore_enoent
= true;
4291 if (!utf8_is_valid(s
)) {
4292 log_syntax_invalid_utf8(unit
, LOG_ERR
, filename
, line
, s
);
4295 if (!path_is_absolute(s
)) {
4296 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Not an absolute source path, ignoring: %s", s
);
4300 path_kill_slashes(s
);
4302 /* Optionally, the destination is specified. */
4303 if (p
&& p
[-1] == ':') {
4304 r
= extract_first_word(&p
, &destination
, ":" WHITESPACE
, EXTRACT_QUOTES
|EXTRACT_DONT_COALESCE_SEPARATORS
);
4308 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s: %s", lvalue
, rvalue
);
4312 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Missing argument after ':': %s", rvalue
);
4316 r
= unit_full_printf(u
, destination
, &dresolved
);
4318 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4319 "Failed to resolved specifiers in \"%s\", ignoring: %m", destination
);
4323 if (!utf8_is_valid(dresolved
)) {
4324 log_syntax_invalid_utf8(unit
, LOG_ERR
, filename
, line
, dresolved
);
4327 if (!path_is_absolute(dresolved
)) {
4328 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Not an absolute destination path, ignoring: %s", dresolved
);
4332 d
= path_kill_slashes(dresolved
);
4334 /* Optionally, there's also a short option string specified */
4335 if (p
&& p
[-1] == ':') {
4336 _cleanup_free_
char *options
= NULL
;
4338 r
= extract_first_word(&p
, &options
, NULL
, EXTRACT_QUOTES
);
4342 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s: %s", lvalue
, rvalue
);
4346 if (isempty(options
) || streq(options
, "rbind"))
4348 else if (streq(options
, "norbind"))
4351 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid option string, ignoring setting: %s", options
);
4358 r
= bind_mount_add(&c
->bind_mounts
, &c
->n_bind_mounts
,
4362 .read_only
= !!strstr(lvalue
, "ReadOnly"),
4364 .ignore_enoent
= ignore_enoent
,
4373 int config_parse_no_new_privileges(
4375 const char *filename
,
4377 const char *section
,
4378 unsigned section_line
,
4385 ExecContext
*c
= data
;
4393 k
= parse_boolean(rvalue
);
4395 log_syntax(unit
, LOG_ERR
, filename
, line
, k
, "Failed to parse boolean value, ignoring: %s", rvalue
);
4399 c
->no_new_privileges
= k
;
4404 int config_parse_protect_home(
4406 const char *filename
,
4408 const char *section
,
4409 unsigned section_line
,
4416 ExecContext
*c
= data
;
4424 /* Our enum shall be a superset of booleans, hence first try
4425 * to parse as boolean, and then as enum */
4427 h
= parse_protect_home_or_bool(rvalue
);
4429 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse protect home value, ignoring: %s", rvalue
);
4433 c
->protect_home
= h
;
4438 int config_parse_protect_system(
4440 const char *filename
,
4442 const char *section
,
4443 unsigned section_line
,
4450 ExecContext
*c
= data
;
4458 /* Our enum shall be a superset of booleans, hence first try
4459 * to parse as boolean, and then as enum */
4461 s
= parse_protect_system_or_bool(rvalue
);
4463 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse protect system value, ignoring: %s", rvalue
);
4467 c
->protect_system
= s
;
4472 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_keyring_mode
, exec_keyring_mode
, ExecKeyringMode
, "Failed to parse keyring mode");
4474 int config_parse_job_timeout_sec(
4476 const char *filename
,
4478 const char *section
,
4479 unsigned section_line
,
4495 r
= parse_sec_fix_0(rvalue
, &usec
);
4497 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse JobTimeoutSec= parameter, ignoring: %s", rvalue
);
4501 /* If the user explicitly changed JobTimeoutSec= also change JobRunningTimeoutSec=, for compatibility with old
4502 * versions. If JobRunningTimeoutSec= was explicitly set, avoid this however as whatever the user picked should
4505 if (!u
->job_running_timeout_set
)
4506 u
->job_running_timeout
= usec
;
4508 u
->job_timeout
= usec
;
4513 int config_parse_job_running_timeout_sec(
4515 const char *filename
,
4517 const char *section
,
4518 unsigned section_line
,
4534 r
= parse_sec_fix_0(rvalue
, &usec
);
4536 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse JobRunningTimeoutSec= parameter, ignoring: %s", rvalue
);
4540 u
->job_running_timeout
= usec
;
4541 u
->job_running_timeout_set
= true;
4546 #define FOLLOW_MAX 8
4548 static int open_follow(char **filename
, FILE **_f
, Set
*names
, char **_final
) {
4559 /* This will update the filename pointer if the loaded file is
4560 * reached by a symlink. The old string will be freed. */
4563 char *target
, *name
;
4565 if (c
++ >= FOLLOW_MAX
)
4568 path_kill_slashes(*filename
);
4570 /* Add the file name we are currently looking at to
4571 * the names of this unit, but only if it is a valid
4573 name
= basename(*filename
);
4574 if (unit_name_is_valid(name
, UNIT_NAME_ANY
)) {
4576 id
= set_get(names
, name
);
4582 r
= set_consume(names
, id
);
4588 /* Try to open the file name, but don't if its a symlink */
4589 fd
= open(*filename
, O_RDONLY
|O_CLOEXEC
|O_NOCTTY
|O_NOFOLLOW
);
4596 /* Hmm, so this is a symlink. Let's read the name, and follow it manually */
4597 r
= readlink_and_make_absolute(*filename
, &target
);
4605 f
= fdopen(fd
, "re");
4617 static int merge_by_names(Unit
**u
, Set
*names
, const char *id
) {
4625 /* Let's try to add in all symlink names we found */
4626 while ((k
= set_steal_first(names
))) {
4628 /* First try to merge in the other name into our
4630 r
= unit_merge_by_name(*u
, k
);
4634 /* Hmm, we couldn't merge the other unit into
4635 * ours? Then let's try it the other way
4638 /* If the symlink name we are looking at is unit template, then
4639 we must search for instance of this template */
4640 if (unit_name_is_valid(k
, UNIT_NAME_TEMPLATE
) && (*u
)->instance
) {
4641 _cleanup_free_
char *instance
= NULL
;
4643 r
= unit_name_replace_instance(k
, (*u
)->instance
, &instance
);
4647 other
= manager_get_unit((*u
)->manager
, instance
);
4649 other
= manager_get_unit((*u
)->manager
, k
);
4654 r
= unit_merge(other
, *u
);
4657 return merge_by_names(u
, names
, NULL
);
4665 unit_choose_id(*u
, id
);
4673 static int load_from_path(Unit
*u
, const char *path
) {
4674 _cleanup_set_free_free_ Set
*symlink_names
= NULL
;
4675 _cleanup_fclose_
FILE *f
= NULL
;
4676 _cleanup_free_
char *filename
= NULL
;
4685 symlink_names
= set_new(&string_hash_ops
);
4689 if (path_is_absolute(path
)) {
4691 filename
= strdup(path
);
4695 r
= open_follow(&filename
, &f
, symlink_names
, &id
);
4697 filename
= mfree(filename
);
4705 STRV_FOREACH(p
, u
->manager
->lookup_paths
.search_path
) {
4707 /* Instead of opening the path right away, we manually
4708 * follow all symlinks and add their name to our unit
4709 * name set while doing so */
4710 filename
= path_make_absolute(path
, *p
);
4714 if (u
->manager
->unit_path_cache
&&
4715 !set_get(u
->manager
->unit_path_cache
, filename
))
4718 r
= open_follow(&filename
, &f
, symlink_names
, &id
);
4721 filename
= mfree(filename
);
4723 /* ENOENT means that the file is missing or is a dangling symlink.
4724 * ENOTDIR means that one of paths we expect to be is a directory
4725 * is not a directory, we should just ignore that.
4726 * EACCES means that the directory or file permissions are wrong.
4729 log_debug_errno(r
, "Cannot access \"%s\": %m", filename
);
4730 else if (!IN_SET(r
, -ENOENT
, -ENOTDIR
))
4733 /* Empty the symlink names for the next run */
4734 set_clear_free(symlink_names
);
4739 /* Hmm, no suitable file found? */
4742 if (!unit_type_may_alias(u
->type
) && set_size(symlink_names
) > 1) {
4743 log_unit_warning(u
, "Unit type of %s does not support alias names, refusing loading via symlink.", u
->id
);
4748 r
= merge_by_names(&merged
, symlink_names
, id
);
4753 u
->load_state
= UNIT_MERGED
;
4757 if (fstat(fileno(f
), &st
) < 0)
4760 if (null_or_empty(&st
)) {
4761 u
->load_state
= UNIT_MASKED
;
4762 u
->fragment_mtime
= 0;
4764 u
->load_state
= UNIT_LOADED
;
4765 u
->fragment_mtime
= timespec_load(&st
.st_mtim
);
4767 /* Now, parse the file contents */
4768 r
= config_parse(u
->id
, filename
, f
,
4769 UNIT_VTABLE(u
)->sections
,
4770 config_item_perf_lookup
, load_fragment_gperf_lookup
,
4771 CONFIG_PARSE_ALLOW_INCLUDE
, u
);
4776 free_and_replace(u
->fragment_path
, filename
);
4778 if (u
->source_path
) {
4779 if (stat(u
->source_path
, &st
) >= 0)
4780 u
->source_mtime
= timespec_load(&st
.st_mtim
);
4782 u
->source_mtime
= 0;
4788 int unit_load_fragment(Unit
*u
) {
4794 assert(u
->load_state
== UNIT_STUB
);
4798 u
->load_state
= UNIT_LOADED
;
4802 /* First, try to find the unit under its id. We always look
4803 * for unit files in the default directories, to make it easy
4804 * to override things by placing things in /etc/systemd/system */
4805 r
= load_from_path(u
, u
->id
);
4809 /* Try to find an alias we can load this with */
4810 if (u
->load_state
== UNIT_STUB
) {
4811 SET_FOREACH(t
, u
->names
, i
) {
4816 r
= load_from_path(u
, t
);
4820 if (u
->load_state
!= UNIT_STUB
)
4825 /* And now, try looking for it under the suggested (originally linked) path */
4826 if (u
->load_state
== UNIT_STUB
&& u
->fragment_path
) {
4828 r
= load_from_path(u
, u
->fragment_path
);
4832 if (u
->load_state
== UNIT_STUB
)
4833 /* Hmm, this didn't work? Then let's get rid
4834 * of the fragment path stored for us, so that
4835 * we don't point to an invalid location. */
4836 u
->fragment_path
= mfree(u
->fragment_path
);
4839 /* Look for a template */
4840 if (u
->load_state
== UNIT_STUB
&& u
->instance
) {
4841 _cleanup_free_
char *k
= NULL
;
4843 r
= unit_name_template(u
->id
, &k
);
4847 r
= load_from_path(u
, k
);
4850 log_unit_notice(u
, "Unit configuration has fatal error, unit will not be started.");
4854 if (u
->load_state
== UNIT_STUB
) {
4855 SET_FOREACH(t
, u
->names
, i
) {
4856 _cleanup_free_
char *z
= NULL
;
4861 r
= unit_name_template(t
, &z
);
4865 r
= load_from_path(u
, z
);
4869 if (u
->load_state
!= UNIT_STUB
)
4878 void unit_dump_config_items(FILE *f
) {
4879 static const struct {
4880 const ConfigParserCallback callback
;
4883 #if !HAVE_SYSV_COMPAT || !HAVE_SECCOMP || !HAVE_PAM || !HAVE_SELINUX || !ENABLE_SMACK || !HAVE_APPARMOR
4884 { config_parse_warn_compat
, "NOTSUPPORTED" },
4886 { config_parse_int
, "INTEGER" },
4887 { config_parse_unsigned
, "UNSIGNED" },
4888 { config_parse_iec_size
, "SIZE" },
4889 { config_parse_iec_uint64
, "SIZE" },
4890 { config_parse_si_size
, "SIZE" },
4891 { config_parse_bool
, "BOOLEAN" },
4892 { config_parse_string
, "STRING" },
4893 { config_parse_path
, "PATH" },
4894 { config_parse_unit_path_printf
, "PATH" },
4895 { config_parse_strv
, "STRING [...]" },
4896 { config_parse_exec_nice
, "NICE" },
4897 { config_parse_exec_oom_score_adjust
, "OOMSCOREADJUST" },
4898 { config_parse_exec_io_class
, "IOCLASS" },
4899 { config_parse_exec_io_priority
, "IOPRIORITY" },
4900 { config_parse_exec_cpu_sched_policy
, "CPUSCHEDPOLICY" },
4901 { config_parse_exec_cpu_sched_prio
, "CPUSCHEDPRIO" },
4902 { config_parse_exec_cpu_affinity
, "CPUAFFINITY" },
4903 { config_parse_mode
, "MODE" },
4904 { config_parse_unit_env_file
, "FILE" },
4905 { config_parse_exec_output
, "OUTPUT" },
4906 { config_parse_exec_input
, "INPUT" },
4907 { config_parse_log_facility
, "FACILITY" },
4908 { config_parse_log_level
, "LEVEL" },
4909 { config_parse_exec_secure_bits
, "SECUREBITS" },
4910 { config_parse_capability_set
, "BOUNDINGSET" },
4911 { config_parse_limit
, "LIMIT" },
4912 { config_parse_unit_deps
, "UNIT [...]" },
4913 { config_parse_exec
, "PATH [ARGUMENT [...]]" },
4914 { config_parse_service_type
, "SERVICETYPE" },
4915 { config_parse_service_restart
, "SERVICERESTART" },
4916 #if HAVE_SYSV_COMPAT
4917 { config_parse_sysv_priority
, "SYSVPRIORITY" },
4919 { config_parse_kill_mode
, "KILLMODE" },
4920 { config_parse_signal
, "SIGNAL" },
4921 { config_parse_socket_listen
, "SOCKET [...]" },
4922 { config_parse_socket_bind
, "SOCKETBIND" },
4923 { config_parse_socket_bindtodevice
, "NETWORKINTERFACE" },
4924 { config_parse_sec
, "SECONDS" },
4925 { config_parse_nsec
, "NANOSECONDS" },
4926 { config_parse_namespace_path_strv
, "PATH [...]" },
4927 { config_parse_bind_paths
, "PATH[:PATH[:OPTIONS]] [...]" },
4928 { config_parse_unit_requires_mounts_for
, "PATH [...]" },
4929 { config_parse_exec_mount_flags
, "MOUNTFLAG [...]" },
4930 { config_parse_unit_string_printf
, "STRING" },
4931 { config_parse_trigger_unit
, "UNIT" },
4932 { config_parse_timer
, "TIMER" },
4933 { config_parse_path_spec
, "PATH" },
4934 { config_parse_notify_access
, "ACCESS" },
4935 { config_parse_ip_tos
, "TOS" },
4936 { config_parse_unit_condition_path
, "CONDITION" },
4937 { config_parse_unit_condition_string
, "CONDITION" },
4938 { config_parse_unit_condition_null
, "CONDITION" },
4939 { config_parse_unit_slice
, "SLICE" },
4940 { config_parse_documentation
, "URL" },
4941 { config_parse_service_timeout
, "SECONDS" },
4942 { config_parse_emergency_action
, "ACTION" },
4943 { config_parse_set_status
, "STATUS" },
4944 { config_parse_service_sockets
, "SOCKETS" },
4945 { config_parse_environ
, "ENVIRON" },
4947 { config_parse_syscall_filter
, "SYSCALLS" },
4948 { config_parse_syscall_archs
, "ARCHS" },
4949 { config_parse_syscall_errno
, "ERRNO" },
4950 { config_parse_address_families
, "FAMILIES" },
4951 { config_parse_restrict_namespaces
, "NAMESPACES" },
4953 { config_parse_cpu_shares
, "SHARES" },
4954 { config_parse_cpu_weight
, "WEIGHT" },
4955 { config_parse_memory_limit
, "LIMIT" },
4956 { config_parse_device_allow
, "DEVICE" },
4957 { config_parse_device_policy
, "POLICY" },
4958 { config_parse_io_limit
, "LIMIT" },
4959 { config_parse_io_weight
, "WEIGHT" },
4960 { config_parse_io_device_weight
, "DEVICEWEIGHT" },
4961 { config_parse_blockio_bandwidth
, "BANDWIDTH" },
4962 { config_parse_blockio_weight
, "WEIGHT" },
4963 { config_parse_blockio_device_weight
, "DEVICEWEIGHT" },
4964 { config_parse_long
, "LONG" },
4965 { config_parse_socket_service
, "SERVICE" },
4967 { config_parse_exec_selinux_context
, "LABEL" },
4969 { config_parse_job_mode
, "MODE" },
4970 { config_parse_job_mode_isolate
, "BOOLEAN" },
4971 { config_parse_personality
, "PERSONALITY" },
4974 const char *prev
= NULL
;
4979 NULSTR_FOREACH(i
, load_fragment_gperf_nulstr
) {
4980 const char *rvalue
= "OTHER", *lvalue
;
4984 const ConfigPerfItem
*p
;
4986 assert_se(p
= load_fragment_gperf_lookup(i
, strlen(i
)));
4988 dot
= strchr(i
, '.');
4989 lvalue
= dot
? dot
+ 1 : i
;
4993 if (!prev
|| !strneq(prev
, i
, prefix_len
+1)) {
4997 fprintf(f
, "[%.*s]\n", (int) prefix_len
, i
);
5000 for (j
= 0; j
< ELEMENTSOF(table
); j
++)
5001 if (p
->parse
== table
[j
].callback
) {
5002 rvalue
= table
[j
].rvalue
;
5006 fprintf(f
, "%s=%s\n", lvalue
, rvalue
);