1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 This file is part of systemd.
5 Copyright 2010 Lennart Poettering
6 Copyright 2012 Holger Hans Peter Freyther
12 #include <linux/oom.h>
18 #include <sys/resource.h>
22 #include "alloc-util.h"
23 #include "all-units.h"
24 #include "bus-error.h"
25 #include "bus-internal.h"
28 #include "capability-util.h"
30 #include "conf-parser.h"
31 #include "cpu-set-util.h"
33 #include "errno-list.h"
37 #include "hexdecoct.h"
40 #include "journal-util.h"
41 #include "load-fragment.h"
44 #include "mount-util.h"
45 #include "parse-util.h"
46 #include "path-util.h"
47 #include "process-util.h"
49 #include "seccomp-util.h"
51 #include "securebits.h"
52 #include "securebits-util.h"
53 #include "signal-util.h"
54 #include "socket-protocol-list.h"
55 #include "stat-util.h"
56 #include "string-util.h"
58 #include "unit-name.h"
59 #include "unit-printf.h"
60 #include "user-util.h"
64 DEFINE_CONFIG_PARSE_ENUM(config_parse_collect_mode
, collect_mode
, CollectMode
, "Failed to parse garbage collection mode");
66 int config_parse_unit_deps(
71 unsigned section_line
,
78 UnitDependency d
= ltype
;
88 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
91 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_RETAIN_ESCAPE
);
97 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
101 r
= unit_name_printf(u
, word
, &k
);
103 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
107 r
= unit_add_dependency_by_name(u
, d
, k
, NULL
, true, UNIT_DEPENDENCY_FILE
);
109 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
115 int config_parse_obsolete_unit_deps(
117 const char *filename
,
120 unsigned section_line
,
127 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
128 "Unit dependency type %s= is obsolete, replacing by %s=, please update your unit file", lvalue
, unit_dependency_to_string(ltype
));
130 return config_parse_unit_deps(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
);
133 int config_parse_unit_string_printf(
135 const char *filename
,
138 unsigned section_line
,
145 _cleanup_free_
char *k
= NULL
;
154 r
= unit_full_printf(u
, rvalue
, &k
);
156 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
160 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
163 int config_parse_unit_strv_printf(
165 const char *filename
,
168 unsigned section_line
,
176 _cleanup_free_
char *k
= NULL
;
184 r
= unit_full_printf(u
, rvalue
, &k
);
186 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
190 return config_parse_strv(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
193 int config_parse_unit_path_printf(
195 const char *filename
,
198 unsigned section_line
,
205 _cleanup_free_
char *k
= NULL
;
215 /* Let's not bother with anything that is too long */
216 if (strlen(rvalue
) >= PATH_MAX
) {
217 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
218 "%s value too long%s.",
219 lvalue
, fatal
? "" : ", ignoring");
220 return fatal
? -ENAMETOOLONG
: 0;
223 r
= unit_full_printf(u
, rvalue
, &k
);
225 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
226 "Failed to resolve unit specifiers in '%s'%s: %m",
227 rvalue
, fatal
? "" : ", ignoring");
228 return fatal
? -ENOEXEC
: 0;
231 return config_parse_path(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
234 int config_parse_unit_path_strv_printf(
236 const char *filename
,
239 unsigned section_line
,
256 if (isempty(rvalue
)) {
262 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
264 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
270 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
271 "Invalid syntax, ignoring: %s", rvalue
);
275 r
= unit_full_printf(u
, word
, &k
);
277 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
278 "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
282 if (!utf8_is_valid(k
)) {
283 log_syntax_invalid_utf8(unit
, LOG_ERR
, filename
, line
, rvalue
);
287 if (!path_is_absolute(k
)) {
288 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
289 "Symlink path is not absolute: %s", k
);
293 path_kill_slashes(k
);
302 int config_parse_socket_listen(const char *unit
,
303 const char *filename
,
306 unsigned section_line
,
313 _cleanup_free_ SocketPort
*p
= NULL
;
325 if (isempty(rvalue
)) {
326 /* An empty assignment removes all ports */
327 socket_free_ports(s
);
331 p
= new0(SocketPort
, 1);
335 if (ltype
!= SOCKET_SOCKET
) {
338 r
= unit_full_printf(UNIT(s
), rvalue
, &p
->path
);
340 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
344 path_kill_slashes(p
->path
);
346 } else if (streq(lvalue
, "ListenNetlink")) {
347 _cleanup_free_
char *k
= NULL
;
349 p
->type
= SOCKET_SOCKET
;
350 r
= unit_full_printf(UNIT(s
), rvalue
, &k
);
352 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
356 r
= socket_address_parse_netlink(&p
->address
, k
);
358 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse address value in '%s', ignoring: %m", k
);
363 _cleanup_free_
char *k
= NULL
;
365 p
->type
= SOCKET_SOCKET
;
366 r
= unit_full_printf(UNIT(s
), rvalue
, &k
);
368 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
372 r
= socket_address_parse_and_warn(&p
->address
, k
);
374 if (r
!= -EAFNOSUPPORT
)
375 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse address value in '%s', ignoring: %m", k
);
379 if (streq(lvalue
, "ListenStream"))
380 p
->address
.type
= SOCK_STREAM
;
381 else if (streq(lvalue
, "ListenDatagram"))
382 p
->address
.type
= SOCK_DGRAM
;
384 assert(streq(lvalue
, "ListenSequentialPacket"));
385 p
->address
.type
= SOCK_SEQPACKET
;
388 if (socket_address_family(&p
->address
) != AF_LOCAL
&& p
->address
.type
== SOCK_SEQPACKET
) {
389 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Address family not supported, ignoring: %s", rvalue
);
395 p
->auxiliary_fds
= NULL
;
396 p
->n_auxiliary_fds
= 0;
399 LIST_FIND_TAIL(port
, s
->ports
, tail
);
400 LIST_INSERT_AFTER(port
, s
->ports
, tail
, p
);
407 static int supported_socket_protocol_from_string(const char *s
) {
413 r
= socket_protocol_from_name(s
);
416 if (!IN_SET(r
, IPPROTO_UDPLITE
, IPPROTO_SCTP
))
417 return -EPROTONOSUPPORT
;
422 DEFINE_CONFIG_PARSE(config_parse_socket_protocol
, supported_socket_protocol_from_string
, "Failed to parse socket protocol");
423 DEFINE_CONFIG_PARSE_ENUM(config_parse_socket_bind
, socket_address_bind_ipv6_only_or_bool
, SocketAddressBindIPv6Only
, "Failed to parse bind IPv6 only value");
425 int config_parse_exec_nice(
427 const char *filename
,
430 unsigned section_line
,
437 ExecContext
*c
= data
;
445 if (isempty(rvalue
)) {
450 r
= parse_nice(rvalue
, &priority
);
453 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Nice priority out of range, ignoring: %s", rvalue
);
455 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse nice priority '%s', ignoring: %m", rvalue
);
465 int config_parse_exec_oom_score_adjust(
467 const char *filename
,
470 unsigned section_line
,
477 ExecContext
*c
= data
;
485 if (isempty(rvalue
)) {
486 c
->oom_score_adjust_set
= false;
490 r
= parse_oom_score_adjust(rvalue
, &oa
);
493 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "OOM score adjust value out of range, ignoring: %s", rvalue
);
495 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse the OOM score adjust value '%s', ignoring: %m", rvalue
);
499 c
->oom_score_adjust
= oa
;
500 c
->oom_score_adjust_set
= true;
505 int config_parse_exec(
507 const char *filename
,
510 unsigned section_line
,
517 ExecCommand
**e
= data
;
529 rvalue
+= strspn(rvalue
, WHITESPACE
);
531 if (isempty(rvalue
)) {
532 /* An empty assignment resets the list */
533 *e
= exec_command_free_list(*e
);
539 _cleanup_free_
char *path
= NULL
, *firstword
= NULL
;
540 ExecCommandFlags flags
= 0;
541 bool ignore
= false, separate_argv0
= false;
542 _cleanup_free_ ExecCommand
*nce
= NULL
;
543 _cleanup_strv_free_
char **n
= NULL
;
544 size_t nlen
= 0, nbufsize
= 0;
549 r
= extract_first_word_and_warn(&p
, &firstword
, NULL
, EXTRACT_QUOTES
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
555 /* We accept an absolute path as first argument. If it's prefixed with - and the path doesn't
556 * exist, we ignore it instead of erroring out; if it's prefixed with @, we allow overriding of
557 * argv[0]; if it's prefixed with +, it will be run with full privileges and no sandboxing; if
558 * it's prefixed with '!' we apply sandboxing, but do not change user/group credentials; if
559 * it's prefixed with '!!', then we apply user/group credentials if the kernel supports ambient
560 * capabilities -- if it doesn't we don't apply the credentials themselves, but do apply most
561 * other sandboxing, with some special exceptions for changing UID.
563 * The idea is that '!!' may be used to write services that can take benefit of systemd's
564 * UID/GID dropping if the kernel supports ambient creds, but provide an automatic fallback to
565 * privilege dropping within the daemon if the kernel does not offer that. */
567 if (*f
== '-' && !(flags
& EXEC_COMMAND_IGNORE_FAILURE
)) {
568 flags
|= EXEC_COMMAND_IGNORE_FAILURE
;
570 } else if (*f
== '@' && !separate_argv0
)
571 separate_argv0
= true;
572 else if (*f
== '+' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
573 flags
|= EXEC_COMMAND_FULLY_PRIVILEGED
;
574 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
575 flags
|= EXEC_COMMAND_NO_SETUID
;
576 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_AMBIENT_MAGIC
))) {
577 flags
&= ~EXEC_COMMAND_NO_SETUID
;
578 flags
|= EXEC_COMMAND_AMBIENT_MAGIC
;
584 r
= unit_full_printf(u
, f
, &path
);
586 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
587 "Failed to resolve unit specifiers in '%s'%s: %m",
588 f
, ignore
? ", ignoring" : "");
589 return ignore
? 0 : -ENOEXEC
;
593 /* First word is either "-" or "@" with no command. */
594 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
595 "Empty path in command line%s: '%s'",
596 ignore
? ", ignoring" : "", rvalue
);
597 return ignore
? 0 : -ENOEXEC
;
599 if (!string_is_safe(path
)) {
600 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
601 "Executable name contains special characters%s: %s",
602 ignore
? ", ignoring" : "", path
);
603 return ignore
? 0 : -ENOEXEC
;
605 if (endswith(path
, "/")) {
606 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
607 "Executable path specifies a directory%s: %s",
608 ignore
? ", ignoring" : "", path
);
609 return ignore
? 0 : -ENOEXEC
;
612 if (!path_is_absolute(path
)) {
616 if (!filename_is_valid(path
)) {
617 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
618 "Neither a valid executable name nor an absolute path%s: %s",
619 ignore
? ", ignoring" : "", path
);
620 return ignore
? 0 : -ENOEXEC
;
623 /* Resolve a single-component name to a full path */
624 NULSTR_FOREACH(prefix
, DEFAULT_PATH_NULSTR
) {
625 _cleanup_free_
char *fullpath
= NULL
;
627 fullpath
= strjoin(prefix
, "/", path
);
631 if (access(fullpath
, F_OK
) >= 0) {
632 free_and_replace(path
, fullpath
);
639 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
640 "Executable \"%s\" not found in path \"%s\"%s",
641 path
, DEFAULT_PATH
, ignore
? ", ignoring" : "");
642 return ignore
? 0 : -ENOEXEC
;
646 if (!separate_argv0
) {
649 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
659 path_kill_slashes(path
);
661 while (!isempty(p
)) {
662 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
664 /* Check explicitly for an unquoted semicolon as
665 * command separator token. */
666 if (p
[0] == ';' && (!p
[1] || strchr(WHITESPACE
, p
[1]))) {
668 p
+= strspn(p
, WHITESPACE
);
673 /* Check for \; explicitly, to not confuse it with \\; or "\;" or "\\;" etc.
674 * extract_first_word() would return the same for all of those. */
675 if (p
[0] == '\\' && p
[1] == ';' && (!p
[2] || strchr(WHITESPACE
, p
[2]))) {
679 p
+= strspn(p
, WHITESPACE
);
681 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
692 r
= extract_first_word_and_warn(&p
, &word
, NULL
, EXTRACT_QUOTES
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
696 return ignore
? 0 : -ENOEXEC
;
698 r
= unit_full_printf(u
, word
, &resolved
);
700 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
701 "Failed to resolve unit specifiers in %s%s: %m",
702 word
, ignore
? ", ignoring" : "");
703 return ignore
? 0 : -ENOEXEC
;
706 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
709 n
[nlen
++] = TAKE_PTR(resolved
);
714 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
715 "Empty executable name or zeroeth argument%s: %s",
716 ignore
? ", ignoring" : "", rvalue
);
717 return ignore
? 0 : -ENOEXEC
;
720 nce
= new0(ExecCommand
, 1);
724 nce
->argv
= TAKE_PTR(n
);
725 nce
->path
= TAKE_PTR(path
);
728 exec_command_append_list(e
, nce
);
730 /* Do not _cleanup_free_ these. */
739 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_type
, service_type
, ServiceType
, "Failed to parse service type");
740 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart
, service_restart
, ServiceRestart
, "Failed to parse service restart specifier");
742 int config_parse_socket_bindtodevice(
744 const char *filename
,
747 unsigned section_line
,
761 if (isempty(rvalue
) || streq(rvalue
, "*")) {
762 s
->bind_to_device
= mfree(s
->bind_to_device
);
766 if (!ifname_valid(rvalue
)) {
767 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid interface name, ignoring: %s", rvalue
);
771 free_and_strdup(&s
->bind_to_device
, rvalue
);
776 int config_parse_exec_input(
778 const char *filename
,
781 unsigned section_line
,
788 ExecContext
*c
= data
;
799 n
= startswith(rvalue
, "fd:");
801 _cleanup_free_
char *resolved
= NULL
;
803 r
= unit_full_printf(u
, n
, &resolved
);
805 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s': %m", n
);
807 if (isempty(resolved
))
808 resolved
= mfree(resolved
);
809 else if (!fdname_is_valid(resolved
)) {
810 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name: %s", resolved
);
814 free_and_replace(c
->stdio_fdname
[STDIN_FILENO
], resolved
);
816 ei
= EXEC_INPUT_NAMED_FD
;
818 } else if ((n
= startswith(rvalue
, "file:"))) {
819 _cleanup_free_
char *resolved
= NULL
;
821 r
= unit_full_printf(u
, n
, &resolved
);
823 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s': %m", n
);
825 if (!path_is_absolute(resolved
)) {
826 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "file: requires an absolute path name: %s", resolved
);
830 if (!path_is_normalized(resolved
)) {
831 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "file: requires a normalized path name: %s", resolved
);
835 free_and_replace(c
->stdio_file
[STDIN_FILENO
], resolved
);
837 ei
= EXEC_INPUT_FILE
;
840 ei
= exec_input_from_string(rvalue
);
842 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse input specifier, ignoring: %s", rvalue
);
851 int config_parse_exec_input_text(
853 const char *filename
,
856 unsigned section_line
,
863 _cleanup_free_
char *unescaped
= NULL
, *resolved
= NULL
;
864 ExecContext
*c
= data
;
875 if (isempty(rvalue
)) {
876 /* Reset if the empty string is assigned */
877 c
->stdin_data
= mfree(c
->stdin_data
);
878 c
->stdin_data_size
= 0;
882 r
= cunescape(rvalue
, 0, &unescaped
);
884 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to decode C escaped text '%s': %m", rvalue
);
886 r
= unit_full_printf(u
, unescaped
, &resolved
);
888 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s': %m", unescaped
);
890 sz
= strlen(resolved
);
891 if (c
->stdin_data_size
+ sz
+ 1 < c
->stdin_data_size
|| /* check for overflow */
892 c
->stdin_data_size
+ sz
+ 1 > EXEC_STDIN_DATA_MAX
) {
893 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
);
897 p
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
+ 1);
901 *((char*) mempcpy((char*) p
+ c
->stdin_data_size
, resolved
, sz
)) = '\n';
904 c
->stdin_data_size
+= sz
+ 1;
909 int config_parse_exec_input_data(
911 const char *filename
,
914 unsigned section_line
,
921 _cleanup_free_
void *p
= NULL
;
922 ExecContext
*c
= data
;
932 if (isempty(rvalue
)) {
933 /* Reset if the empty string is assigned */
934 c
->stdin_data
= mfree(c
->stdin_data
);
935 c
->stdin_data_size
= 0;
939 r
= unbase64mem(rvalue
, (size_t) -1, &p
, &sz
);
941 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to decode base64 data, ignoring: %s", rvalue
);
945 if (c
->stdin_data_size
+ sz
< c
->stdin_data_size
|| /* check for overflow */
946 c
->stdin_data_size
+ sz
> EXEC_STDIN_DATA_MAX
) {
947 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
);
951 q
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
);
955 memcpy((uint8_t*) q
+ c
->stdin_data_size
, p
, sz
);
958 c
->stdin_data_size
+= sz
;
963 int config_parse_exec_output(
965 const char *filename
,
968 unsigned section_line
,
975 _cleanup_free_
char *resolved
= NULL
;
977 ExecContext
*c
= data
;
988 n
= startswith(rvalue
, "fd:");
990 r
= unit_full_printf(u
, n
, &resolved
);
992 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", n
);
994 if (isempty(resolved
))
995 resolved
= mfree(resolved
);
996 else if (!fdname_is_valid(resolved
)) {
997 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name: %s", resolved
);
1001 eo
= EXEC_OUTPUT_NAMED_FD
;
1003 } else if ((n
= startswith(rvalue
, "file:"))) {
1005 r
= unit_full_printf(u
, n
, &resolved
);
1007 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", n
);
1009 if (!path_is_absolute(resolved
)) {
1010 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "file: requires an absolute path name: %s", resolved
);
1014 if (!path_is_normalized(resolved
)) {
1015 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "file: requires a normalized path name, ignoring: %s", resolved
);
1019 eo
= EXEC_OUTPUT_FILE
;
1022 eo
= exec_output_from_string(rvalue
);
1024 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse output specifier, ignoring: %s", rvalue
);
1029 if (streq(lvalue
, "StandardOutput")) {
1030 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1031 free_and_replace(c
->stdio_fdname
[STDOUT_FILENO
], resolved
);
1033 free_and_replace(c
->stdio_file
[STDOUT_FILENO
], resolved
);
1038 assert(streq(lvalue
, "StandardError"));
1040 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1041 free_and_replace(c
->stdio_fdname
[STDERR_FILENO
], resolved
);
1043 free_and_replace(c
->stdio_file
[STDERR_FILENO
], resolved
);
1051 int config_parse_exec_io_class(const char *unit
,
1052 const char *filename
,
1054 const char *section
,
1055 unsigned section_line
,
1062 ExecContext
*c
= data
;
1070 if (isempty(rvalue
)) {
1071 c
->ioprio_set
= false;
1072 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE
, 0);
1076 x
= ioprio_class_from_string(rvalue
);
1078 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse IO scheduling class, ignoring: %s", rvalue
);
1082 c
->ioprio
= IOPRIO_PRIO_VALUE(x
, IOPRIO_PRIO_DATA(c
->ioprio
));
1083 c
->ioprio_set
= true;
1088 int config_parse_exec_io_priority(const char *unit
,
1089 const char *filename
,
1091 const char *section
,
1092 unsigned section_line
,
1099 ExecContext
*c
= data
;
1107 if (isempty(rvalue
)) {
1108 c
->ioprio_set
= false;
1109 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE
, 0);
1113 r
= ioprio_parse_priority(rvalue
, &i
);
1115 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse IO priority, ignoring: %s", rvalue
);
1119 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_PRIO_CLASS(c
->ioprio
), i
);
1120 c
->ioprio_set
= true;
1125 int config_parse_exec_cpu_sched_policy(const char *unit
,
1126 const char *filename
,
1128 const char *section
,
1129 unsigned section_line
,
1136 ExecContext
*c
= data
;
1144 if (isempty(rvalue
)) {
1145 c
->cpu_sched_set
= false;
1146 c
->cpu_sched_policy
= SCHED_OTHER
;
1147 c
->cpu_sched_priority
= 0;
1151 x
= sched_policy_from_string(rvalue
);
1153 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse CPU scheduling policy, ignoring: %s", rvalue
);
1157 c
->cpu_sched_policy
= x
;
1158 /* Moving to or from real-time policy? We need to adjust the priority */
1159 c
->cpu_sched_priority
= CLAMP(c
->cpu_sched_priority
, sched_get_priority_min(x
), sched_get_priority_max(x
));
1160 c
->cpu_sched_set
= true;
1165 int config_parse_exec_cpu_sched_prio(const char *unit
,
1166 const char *filename
,
1168 const char *section
,
1169 unsigned section_line
,
1176 ExecContext
*c
= data
;
1184 r
= safe_atoi(rvalue
, &i
);
1186 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse CPU scheduling priority, ignoring: %s", rvalue
);
1190 /* On Linux RR/FIFO range from 1 to 99 and OTHER/BATCH may only be 0 */
1191 min
= sched_get_priority_min(c
->cpu_sched_policy
);
1192 max
= sched_get_priority_max(c
->cpu_sched_policy
);
1194 if (i
< min
|| i
> max
) {
1195 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "CPU scheduling priority is out of range, ignoring: %s", rvalue
);
1199 c
->cpu_sched_priority
= i
;
1200 c
->cpu_sched_set
= true;
1205 int config_parse_exec_cpu_affinity(const char *unit
,
1206 const char *filename
,
1208 const char *section
,
1209 unsigned section_line
,
1216 ExecContext
*c
= data
;
1217 _cleanup_cpu_free_ cpu_set_t
*cpuset
= NULL
;
1225 ncpus
= parse_cpu_set_and_warn(rvalue
, &cpuset
, unit
, filename
, line
, lvalue
);
1230 /* An empty assignment resets the CPU list */
1231 c
->cpuset
= cpu_set_mfree(c
->cpuset
);
1232 c
->cpuset_ncpus
= 0;
1237 c
->cpuset
= TAKE_PTR(cpuset
);
1238 c
->cpuset_ncpus
= (unsigned) ncpus
;
1242 if (c
->cpuset_ncpus
< (unsigned) ncpus
) {
1243 CPU_OR_S(CPU_ALLOC_SIZE(c
->cpuset_ncpus
), cpuset
, c
->cpuset
, cpuset
);
1244 CPU_FREE(c
->cpuset
);
1245 c
->cpuset
= TAKE_PTR(cpuset
);
1246 c
->cpuset_ncpus
= (unsigned) ncpus
;
1250 CPU_OR_S(CPU_ALLOC_SIZE((unsigned) ncpus
), c
->cpuset
, c
->cpuset
, cpuset
);
1255 DEFINE_CONFIG_PARSE(config_parse_exec_secure_bits
, secure_bits_from_string
, "Failed to parse secure bits");
1257 int config_parse_capability_set(
1259 const char *filename
,
1261 const char *section
,
1262 unsigned section_line
,
1269 uint64_t *capability_set
= data
;
1270 uint64_t sum
= 0, initial
= 0;
1271 bool invert
= false;
1279 if (rvalue
[0] == '~') {
1284 if (streq(lvalue
, "CapabilityBoundingSet"))
1285 initial
= CAP_ALL
; /* initialized to all bits on */
1286 /* else "AmbientCapabilities" initialized to all bits off */
1288 r
= capability_set_from_string(rvalue
, &sum
);
1290 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= specifier '%s', ignoring: %m", lvalue
, rvalue
);
1294 if (sum
== 0 || *capability_set
== initial
)
1295 /* "", "~" or uninitialized data -> replace */
1296 *capability_set
= invert
? ~sum
: sum
;
1298 /* previous data -> merge */
1300 *capability_set
&= ~sum
;
1302 *capability_set
|= sum
;
1308 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_utmp_mode
, exec_utmp_mode
, ExecUtmpMode
, "Failed to parse utmp mode");
1309 DEFINE_CONFIG_PARSE_ENUM(config_parse_kill_mode
, kill_mode
, KillMode
, "Failed to parse kill mode");
1310 DEFINE_CONFIG_PARSE_PTR(config_parse_exec_mount_flags
, mount_propagation_flags_from_string
, unsigned long, "Failed to parse mount flag");
1312 int config_parse_exec_selinux_context(
1314 const char *filename
,
1316 const char *section
,
1317 unsigned section_line
,
1324 ExecContext
*c
= data
;
1335 if (isempty(rvalue
)) {
1336 c
->selinux_context
= mfree(c
->selinux_context
);
1337 c
->selinux_context_ignore
= false;
1341 if (rvalue
[0] == '-') {
1347 r
= unit_full_printf(u
, rvalue
, &k
);
1349 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1350 "Failed to resolve unit specifiers in '%s'%s: %m",
1351 rvalue
, ignore
? ", ignoring" : "");
1352 return ignore
? 0 : -ENOEXEC
;
1355 free_and_replace(c
->selinux_context
, k
);
1356 c
->selinux_context_ignore
= ignore
;
1361 int config_parse_exec_apparmor_profile(
1363 const char *filename
,
1365 const char *section
,
1366 unsigned section_line
,
1373 ExecContext
*c
= data
;
1384 if (isempty(rvalue
)) {
1385 c
->apparmor_profile
= mfree(c
->apparmor_profile
);
1386 c
->apparmor_profile_ignore
= false;
1390 if (rvalue
[0] == '-') {
1396 r
= unit_full_printf(u
, rvalue
, &k
);
1398 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1399 "Failed to resolve unit specifiers in '%s'%s: %m",
1400 rvalue
, ignore
? ", ignoring" : "");
1401 return ignore
? 0 : -ENOEXEC
;
1404 free_and_replace(c
->apparmor_profile
, k
);
1405 c
->apparmor_profile_ignore
= ignore
;
1410 int config_parse_exec_smack_process_label(
1412 const char *filename
,
1414 const char *section
,
1415 unsigned section_line
,
1422 ExecContext
*c
= data
;
1433 if (isempty(rvalue
)) {
1434 c
->smack_process_label
= mfree(c
->smack_process_label
);
1435 c
->smack_process_label_ignore
= false;
1439 if (rvalue
[0] == '-') {
1445 r
= unit_full_printf(u
, rvalue
, &k
);
1447 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1448 "Failed to resolve unit specifiers in '%s'%s: %m",
1449 rvalue
, ignore
? ", ignoring" : "");
1450 return ignore
? 0 : -ENOEXEC
;
1453 free_and_replace(c
->smack_process_label
, k
);
1454 c
->smack_process_label_ignore
= ignore
;
1459 int config_parse_timer(const char *unit
,
1460 const char *filename
,
1462 const char *section
,
1463 unsigned section_line
,
1474 _cleanup_(calendar_spec_freep
) CalendarSpec
*c
= NULL
;
1476 _cleanup_free_
char *k
= NULL
;
1484 if (isempty(rvalue
)) {
1485 /* Empty assignment resets list */
1486 timer_free_values(t
);
1490 b
= timer_base_from_string(lvalue
);
1492 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse timer base, ignoring: %s", lvalue
);
1496 r
= unit_full_printf(u
, rvalue
, &k
);
1498 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
1502 if (b
== TIMER_CALENDAR
) {
1503 if (calendar_spec_from_string(k
, &c
) < 0) {
1504 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse calendar specification, ignoring: %s", k
);
1508 if (parse_sec(k
, &usec
) < 0) {
1509 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse timer value, ignoring: %s", k
);
1513 v
= new0(TimerValue
, 1);
1519 v
->calendar_spec
= TAKE_PTR(c
);
1521 LIST_PREPEND(value
, t
->values
, v
);
1526 int config_parse_trigger_unit(
1528 const char *filename
,
1530 const char *section
,
1531 unsigned section_line
,
1538 _cleanup_free_
char *p
= NULL
;
1548 if (!hashmap_isempty(u
->dependencies
[UNIT_TRIGGERS
])) {
1549 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Multiple units to trigger specified, ignoring: %s", rvalue
);
1553 r
= unit_name_printf(u
, rvalue
, &p
);
1555 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
1559 type
= unit_name_to_type(p
);
1561 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit type not valid, ignoring: %s", rvalue
);
1564 if (unit_has_name(u
, p
)) {
1565 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Units cannot trigger themselves, ignoring: %s", rvalue
);
1569 r
= unit_add_two_dependencies_by_name(u
, UNIT_BEFORE
, UNIT_TRIGGERS
, p
, NULL
, true, UNIT_DEPENDENCY_FILE
);
1571 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add trigger on %s, ignoring: %m", p
);
1578 int config_parse_path_spec(const char *unit
,
1579 const char *filename
,
1581 const char *section
,
1582 unsigned section_line
,
1592 _cleanup_free_
char *k
= NULL
;
1600 if (isempty(rvalue
)) {
1601 /* Empty assignment clears list */
1606 b
= path_type_from_string(lvalue
);
1608 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse path type, ignoring: %s", lvalue
);
1612 r
= unit_full_printf(UNIT(p
), rvalue
, &k
);
1614 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
1618 path_kill_slashes(k
);
1620 if (!path_is_absolute(k
)) {
1621 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Path is not absolute, ignoring: %s", k
);
1625 s
= new0(PathSpec
, 1);
1630 s
->path
= TAKE_PTR(k
);
1634 LIST_PREPEND(spec
, p
->specs
, s
);
1639 int config_parse_socket_service(
1641 const char *filename
,
1643 const char *section
,
1644 unsigned section_line
,
1651 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1652 _cleanup_free_
char *p
= NULL
;
1662 r
= unit_name_printf(UNIT(s
), rvalue
, &p
);
1664 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", rvalue
);
1668 if (!endswith(p
, ".service")) {
1669 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit must be of type service: %s", rvalue
);
1673 r
= manager_load_unit(UNIT(s
)->manager
, p
, NULL
, &error
, &x
);
1675 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to load unit %s: %s", rvalue
, bus_error_message(&error
, r
));
1679 unit_ref_set(&s
->service
, UNIT(s
), x
);
1684 int config_parse_fdname(
1686 const char *filename
,
1688 const char *section
,
1689 unsigned section_line
,
1696 _cleanup_free_
char *p
= NULL
;
1705 if (isempty(rvalue
)) {
1706 s
->fdname
= mfree(s
->fdname
);
1710 r
= unit_full_printf(UNIT(s
), rvalue
, &p
);
1712 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
1716 if (!fdname_is_valid(p
)) {
1717 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", p
);
1721 return free_and_replace(s
->fdname
, p
);
1724 int config_parse_service_sockets(
1726 const char *filename
,
1728 const char *section
,
1729 unsigned section_line
,
1747 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
1749 r
= extract_first_word(&p
, &word
, NULL
, 0);
1755 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Trailing garbage in sockets, ignoring: %s", rvalue
);
1759 r
= unit_name_printf(UNIT(s
), word
, &k
);
1761 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
1765 if (!endswith(k
, ".socket")) {
1766 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit must be of type socket, ignoring: %s", k
);
1770 r
= unit_add_two_dependencies_by_name(UNIT(s
), UNIT_WANTS
, UNIT_AFTER
, k
, NULL
, true, UNIT_DEPENDENCY_FILE
);
1772 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
1774 r
= unit_add_dependency_by_name(UNIT(s
), UNIT_TRIGGERED_BY
, k
, NULL
, true, UNIT_DEPENDENCY_FILE
);
1776 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
1782 int config_parse_bus_name(
1784 const char *filename
,
1786 const char *section
,
1787 unsigned section_line
,
1794 _cleanup_free_
char *k
= NULL
;
1803 r
= unit_full_printf(u
, rvalue
, &k
);
1805 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
1809 if (!service_name_is_valid(k
)) {
1810 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid bus name, ignoring: %s", k
);
1814 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
1817 int config_parse_service_timeout(
1819 const char *filename
,
1821 const char *section
,
1822 unsigned section_line
,
1829 Service
*s
= userdata
;
1838 /* This is called for two cases: TimeoutSec= and TimeoutStartSec=. */
1840 /* Traditionally, these options accepted 0 to disable the timeouts. However, a timeout of 0 suggests it happens
1841 * immediately, hence fix this to become USEC_INFINITY instead. This is in-line with how we internally handle
1842 * all other timeouts. */
1843 r
= parse_sec_fix_0(rvalue
, &usec
);
1845 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
1849 s
->start_timeout_defined
= true;
1850 s
->timeout_start_usec
= usec
;
1852 if (streq(lvalue
, "TimeoutSec"))
1853 s
->timeout_stop_usec
= usec
;
1858 int config_parse_sec_fix_0(
1860 const char *filename
,
1862 const char *section
,
1863 unsigned section_line
,
1870 usec_t
*usec
= data
;
1878 /* This is pretty much like config_parse_sec(), except that this treats a time of 0 as infinity, for
1879 * compatibility with older versions of systemd where 0 instead of infinity was used as indicator to turn off a
1882 r
= parse_sec_fix_0(rvalue
, usec
);
1884 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
1891 int config_parse_user_group(
1893 const char *filename
,
1895 const char *section
,
1896 unsigned section_line
,
1903 _cleanup_free_
char *k
= NULL
;
1913 if (isempty(rvalue
)) {
1914 *user
= mfree(*user
);
1918 r
= unit_full_printf(u
, rvalue
, &k
);
1920 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", rvalue
);
1924 if (!valid_user_group_name_or_id(k
)) {
1925 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
1929 return free_and_replace(*user
, k
);
1932 int config_parse_user_group_strv(
1934 const char *filename
,
1936 const char *section
,
1937 unsigned section_line
,
1944 char ***users
= data
;
1946 const char *p
= rvalue
;
1954 if (isempty(rvalue
)) {
1955 *users
= strv_free(*users
);
1960 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
1962 r
= extract_first_word(&p
, &word
, NULL
, 0);
1968 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax: %s", rvalue
);
1972 r
= unit_full_printf(u
, word
, &k
);
1974 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", word
);
1978 if (!valid_user_group_name_or_id(k
)) {
1979 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
1983 r
= strv_push(users
, k
);
1993 int config_parse_working_directory(
1995 const char *filename
,
1997 const char *section
,
1998 unsigned section_line
,
2005 ExecContext
*c
= data
;
2016 if (isempty(rvalue
)) {
2017 c
->working_directory_home
= false;
2018 c
->working_directory
= mfree(c
->working_directory
);
2022 if (rvalue
[0] == '-') {
2028 if (streq(rvalue
, "~")) {
2029 c
->working_directory_home
= true;
2030 c
->working_directory
= mfree(c
->working_directory
);
2032 _cleanup_free_
char *k
= NULL
;
2034 r
= unit_full_printf(u
, rvalue
, &k
);
2036 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2037 "Failed to resolve unit specifiers in working directory path '%s'%s: %m",
2038 rvalue
, missing_ok
? ", ignoring" : "");
2039 return missing_ok
? 0 : -ENOEXEC
;
2042 path_kill_slashes(k
);
2044 if (!utf8_is_valid(k
)) {
2045 log_syntax_invalid_utf8(unit
, LOG_ERR
, filename
, line
, rvalue
);
2046 return missing_ok
? 0 : -ENOEXEC
;
2049 if (!path_is_absolute(k
)) {
2050 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2051 "Working directory path '%s' is not absolute%s.",
2052 rvalue
, missing_ok
? ", ignoring" : "");
2053 return missing_ok
? 0 : -ENOEXEC
;
2056 c
->working_directory_home
= false;
2057 free_and_replace(c
->working_directory
, k
);
2060 c
->working_directory_missing_ok
= missing_ok
;
2064 int config_parse_unit_env_file(const char *unit
,
2065 const char *filename
,
2067 const char *section
,
2068 unsigned section_line
,
2077 _cleanup_free_
char *n
= NULL
;
2085 if (isempty(rvalue
)) {
2086 /* Empty assignment frees the list */
2087 *env
= strv_free(*env
);
2091 r
= unit_full_printf(u
, rvalue
, &n
);
2093 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2097 if (!path_is_absolute(n
[0] == '-' ? n
+ 1 : n
)) {
2098 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Path '%s' is not absolute, ignoring.", n
);
2102 r
= strv_extend(env
, n
);
2109 int config_parse_environ(
2111 const char *filename
,
2113 const char *section
,
2114 unsigned section_line
,
2131 if (isempty(rvalue
)) {
2132 /* Empty assignment resets the list */
2133 *env
= strv_free(*env
);
2137 for (p
= rvalue
;; ) {
2138 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2140 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_QUOTES
);
2146 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2147 "Invalid syntax, ignoring: %s", rvalue
);
2152 r
= unit_full_printf(u
, word
, &k
);
2154 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2155 "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2161 if (!env_assignment_is_valid(k
)) {
2162 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2163 "Invalid environment assignment, ignoring: %s", k
);
2167 r
= strv_env_replace(env
, k
);
2175 int config_parse_pass_environ(
2177 const char *filename
,
2179 const char *section
,
2180 unsigned section_line
,
2187 _cleanup_strv_free_
char **n
= NULL
;
2188 size_t nlen
= 0, nbufsize
= 0;
2189 char*** passenv
= data
;
2190 const char *p
= rvalue
;
2199 if (isempty(rvalue
)) {
2200 /* Empty assignment resets the list */
2201 *passenv
= strv_free(*passenv
);
2206 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2208 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
2214 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2215 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2220 r
= unit_full_printf(u
, word
, &k
);
2222 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2223 "Failed to resolve specifiers in %s, ignoring: %m", word
);
2229 if (!env_name_is_valid(k
)) {
2230 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2231 "Invalid environment name for %s, ignoring: %s", lvalue
, k
);
2235 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
2238 n
[nlen
++] = TAKE_PTR(k
);
2243 r
= strv_extend_strv(passenv
, n
, true);
2251 int config_parse_unset_environ(
2253 const char *filename
,
2255 const char *section
,
2256 unsigned section_line
,
2263 _cleanup_strv_free_
char **n
= NULL
;
2264 size_t nlen
= 0, nbufsize
= 0;
2265 char*** unsetenv
= data
;
2266 const char *p
= rvalue
;
2275 if (isempty(rvalue
)) {
2276 /* Empty assignment resets the list */
2277 *unsetenv
= strv_free(*unsetenv
);
2282 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2284 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_QUOTES
);
2290 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2291 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2296 r
= unit_full_printf(u
, word
, &k
);
2298 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2299 "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2305 if (!env_assignment_is_valid(k
) && !env_name_is_valid(k
)) {
2306 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2307 "Invalid environment name or assignment %s, ignoring: %s", lvalue
, k
);
2311 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
2314 n
[nlen
++] = TAKE_PTR(k
);
2319 r
= strv_extend_strv(unsetenv
, n
, true);
2327 int config_parse_log_extra_fields(
2329 const char *filename
,
2331 const char *section
,
2332 unsigned section_line
,
2339 ExecContext
*c
= data
;
2341 const char *p
= rvalue
;
2349 if (isempty(rvalue
)) {
2350 exec_context_free_log_extra_fields(c
);
2355 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2359 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_QUOTES
);
2365 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
2369 r
= unit_full_printf(u
, word
, &k
);
2371 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2375 eq
= strchr(k
, '=');
2377 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Log field lacks '=' character, ignoring: %s", k
);
2381 if (!journal_field_valid(k
, eq
-k
, false)) {
2382 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Log field name is invalid, ignoring: %s", k
);
2386 t
= reallocarray(c
->log_extra_fields
, c
->n_log_extra_fields
+1, sizeof(struct iovec
));
2390 c
->log_extra_fields
= t
;
2391 c
->log_extra_fields
[c
->n_log_extra_fields
++] = IOVEC_MAKE_STRING(k
);
2397 DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_ip_tos
, ip_tos
, int, -1, "Failed to parse IP TOS value");
2399 int config_parse_unit_condition_path(
2401 const char *filename
,
2403 const char *section
,
2404 unsigned section_line
,
2411 _cleanup_free_
char *p
= NULL
;
2412 Condition
**list
= data
, *c
;
2413 ConditionType t
= ltype
;
2414 bool trigger
, negate
;
2423 if (isempty(rvalue
)) {
2424 /* Empty assignment resets the list */
2425 *list
= condition_free_list(*list
);
2429 trigger
= rvalue
[0] == '|';
2433 negate
= rvalue
[0] == '!';
2437 r
= unit_full_printf(u
, rvalue
, &p
);
2439 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2443 if (!path_is_absolute(p
)) {
2444 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Path in condition not absolute, ignoring: %s", p
);
2448 c
= condition_new(t
, p
, trigger
, negate
);
2452 LIST_PREPEND(conditions
, *list
, c
);
2456 int config_parse_unit_condition_string(
2458 const char *filename
,
2460 const char *section
,
2461 unsigned section_line
,
2468 _cleanup_free_
char *s
= NULL
;
2469 Condition
**list
= data
, *c
;
2470 ConditionType t
= ltype
;
2471 bool trigger
, negate
;
2480 if (isempty(rvalue
)) {
2481 /* Empty assignment resets the list */
2482 *list
= condition_free_list(*list
);
2486 trigger
= rvalue
[0] == '|';
2490 negate
= rvalue
[0] == '!';
2494 r
= unit_full_printf(u
, rvalue
, &s
);
2496 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2500 c
= condition_new(t
, s
, trigger
, negate
);
2504 LIST_PREPEND(conditions
, *list
, c
);
2508 int config_parse_unit_condition_null(
2510 const char *filename
,
2512 const char *section
,
2513 unsigned section_line
,
2520 Condition
**list
= data
, *c
;
2521 bool trigger
, negate
;
2529 if (isempty(rvalue
)) {
2530 /* Empty assignment resets the list */
2531 *list
= condition_free_list(*list
);
2535 trigger
= rvalue
[0] == '|';
2539 negate
= rvalue
[0] == '!';
2543 b
= parse_boolean(rvalue
);
2545 log_syntax(unit
, LOG_ERR
, filename
, line
, b
, "Failed to parse boolean value in condition, ignoring: %s", rvalue
);
2552 c
= condition_new(CONDITION_NULL
, NULL
, trigger
, negate
);
2556 LIST_PREPEND(conditions
, *list
, c
);
2560 DEFINE_CONFIG_PARSE_ENUM(config_parse_notify_access
, notify_access
, NotifyAccess
, "Failed to parse notify access specifier");
2561 DEFINE_CONFIG_PARSE_ENUM(config_parse_emergency_action
, emergency_action
, EmergencyAction
, "Failed to parse failure action specifier");
2563 int config_parse_unit_requires_mounts_for(
2565 const char *filename
,
2567 const char *section
,
2568 unsigned section_line
,
2575 const char *p
= rvalue
;
2585 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
2587 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
2593 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2594 "Invalid syntax, ignoring: %s", rvalue
);
2598 if (!utf8_is_valid(word
)) {
2599 log_syntax_invalid_utf8(unit
, LOG_ERR
, filename
, line
, rvalue
);
2603 r
= unit_full_printf(u
, word
, &resolved
);
2605 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
2609 r
= unit_require_mounts_for(u
, resolved
, UNIT_DEPENDENCY_FILE
);
2611 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add required mount '%s', ignoring: %m", resolved
);
2617 int config_parse_documentation(const char *unit
,
2618 const char *filename
,
2620 const char *section
,
2621 unsigned section_line
,
2637 if (isempty(rvalue
)) {
2638 /* Empty assignment resets the list */
2639 u
->documentation
= strv_free(u
->documentation
);
2643 r
= config_parse_unit_strv_printf(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
,
2644 rvalue
, data
, userdata
);
2648 for (a
= b
= u
->documentation
; a
&& *a
; a
++) {
2650 if (documentation_url_is_valid(*a
))
2653 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid URL, ignoring: %s", *a
);
2664 int config_parse_syscall_filter(
2666 const char *filename
,
2668 const char *section
,
2669 unsigned section_line
,
2676 ExecContext
*c
= data
;
2678 bool invert
= false;
2687 if (isempty(rvalue
)) {
2688 /* Empty assignment resets the list */
2689 c
->syscall_filter
= hashmap_free(c
->syscall_filter
);
2690 c
->syscall_whitelist
= false;
2694 if (rvalue
[0] == '~') {
2699 if (!c
->syscall_filter
) {
2700 c
->syscall_filter
= hashmap_new(NULL
);
2701 if (!c
->syscall_filter
)
2705 /* Allow everything but the ones listed */
2706 c
->syscall_whitelist
= false;
2708 /* Allow nothing but the ones listed */
2709 c
->syscall_whitelist
= true;
2711 /* Accept default syscalls if we are on a whitelist */
2712 r
= seccomp_parse_syscall_filter("@default", -1, c
->syscall_filter
, SECCOMP_PARSE_WHITELIST
);
2720 _cleanup_free_
char *word
= NULL
, *name
= NULL
;
2723 r
= extract_first_word(&p
, &word
, NULL
, 0);
2729 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
2733 r
= parse_syscall_and_errno(word
, &name
, &num
);
2735 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse syscall:errno, ignoring: %s", word
);
2739 r
= seccomp_parse_syscall_filter_full(name
, num
, c
->syscall_filter
,
2740 SECCOMP_PARSE_LOG
|SECCOMP_PARSE_PERMISSIVE
|(invert
? SECCOMP_PARSE_INVERT
: 0)|(c
->syscall_whitelist
? SECCOMP_PARSE_WHITELIST
: 0),
2741 unit
, filename
, line
);
2747 int config_parse_syscall_archs(
2749 const char *filename
,
2751 const char *section
,
2752 unsigned section_line
,
2759 const char *p
= rvalue
;
2763 if (isempty(rvalue
)) {
2764 *archs
= set_free(*archs
);
2768 r
= set_ensure_allocated(archs
, NULL
);
2773 _cleanup_free_
char *word
= NULL
;
2776 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
2782 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2783 "Invalid syntax, ignoring: %s", rvalue
);
2787 r
= seccomp_arch_from_string(word
, &a
);
2789 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2790 "Failed to parse system call architecture \"%s\", ignoring: %m", word
);
2794 r
= set_put(*archs
, UINT32_TO_PTR(a
+ 1));
2800 int config_parse_syscall_errno(
2802 const char *filename
,
2804 const char *section
,
2805 unsigned section_line
,
2812 ExecContext
*c
= data
;
2819 if (isempty(rvalue
)) {
2820 /* Empty assignment resets to KILL */
2821 c
->syscall_errno
= 0;
2825 e
= parse_errno(rvalue
);
2827 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse error number, ignoring: %s", rvalue
);
2831 c
->syscall_errno
= e
;
2835 int config_parse_address_families(
2837 const char *filename
,
2839 const char *section
,
2840 unsigned section_line
,
2847 ExecContext
*c
= data
;
2848 bool invert
= false;
2856 if (isempty(rvalue
)) {
2857 /* Empty assignment resets the list */
2858 c
->address_families
= set_free(c
->address_families
);
2859 c
->address_families_whitelist
= false;
2863 if (rvalue
[0] == '~') {
2868 if (!c
->address_families
) {
2869 c
->address_families
= set_new(NULL
);
2870 if (!c
->address_families
)
2873 c
->address_families_whitelist
= !invert
;
2876 for (p
= rvalue
;;) {
2877 _cleanup_free_
char *word
= NULL
;
2880 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
2886 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2887 "Invalid syntax, ignoring: %s", rvalue
);
2891 af
= af_from_name(word
);
2893 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2894 "Failed to parse address family, ignoring: %s", word
);
2898 /* If we previously wanted to forbid an address family and now
2899 * we want to allow it, then just remove it from the list.
2901 if (!invert
== c
->address_families_whitelist
) {
2902 r
= set_put(c
->address_families
, INT_TO_PTR(af
));
2906 set_remove(c
->address_families
, INT_TO_PTR(af
));
2910 int config_parse_restrict_namespaces(
2912 const char *filename
,
2914 const char *section
,
2915 unsigned section_line
,
2922 ExecContext
*c
= data
;
2923 unsigned long flags
;
2924 bool invert
= false;
2927 if (isempty(rvalue
)) {
2928 /* Reset to the default. */
2929 c
->restrict_namespaces
= NAMESPACE_FLAGS_INITIAL
;
2933 /* Boolean parameter ignores the previous settings */
2934 r
= parse_boolean(rvalue
);
2936 c
->restrict_namespaces
= 0;
2938 } else if (r
== 0) {
2939 c
->restrict_namespaces
= NAMESPACE_FLAGS_ALL
;
2943 if (rvalue
[0] == '~') {
2948 /* Not a boolean argument, in this case it's a list of namespace types. */
2949 r
= namespace_flags_from_string(rvalue
, &flags
);
2951 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse namespace type string, ignoring: %s", rvalue
);
2955 if (c
->restrict_namespaces
== NAMESPACE_FLAGS_INITIAL
)
2956 /* Initial assignment. Just set the value. */
2957 c
->restrict_namespaces
= invert
? (~flags
) & NAMESPACE_FLAGS_ALL
: flags
;
2959 /* Merge the value with the previous one. */
2960 SET_FLAG(c
->restrict_namespaces
, flags
, !invert
);
2966 int config_parse_unit_slice(
2968 const char *filename
,
2970 const char *section
,
2971 unsigned section_line
,
2978 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
2979 _cleanup_free_
char *k
= NULL
;
2980 Unit
*u
= userdata
, *slice
= NULL
;
2988 r
= unit_name_printf(u
, rvalue
, &k
);
2990 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2994 r
= manager_load_unit(u
->manager
, k
, NULL
, &error
, &slice
);
2996 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to load slice unit %s, ignoring: %s", k
, bus_error_message(&error
, r
));
3000 r
= unit_set_slice(u
, slice
);
3002 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to assign slice %s to unit %s, ignoring: %m", slice
->id
, u
->id
);
3009 DEFINE_CONFIG_PARSE_ENUM(config_parse_device_policy
, cgroup_device_policy
, CGroupDevicePolicy
, "Failed to parse device policy");
3010 DEFINE_CONFIG_PARSE_PTR(config_parse_cg_weight
, cg_weight_parse
, uint64_t, "Invalid weight");
3011 DEFINE_CONFIG_PARSE_PTR(config_parse_cpu_shares
, cg_cpu_shares_parse
, uint64_t, "Invalid CPU shares");
3013 int config_parse_cpu_quota(
3015 const char *filename
,
3017 const char *section
,
3018 unsigned section_line
,
3025 CGroupContext
*c
= data
;
3032 if (isempty(rvalue
)) {
3033 c
->cpu_quota_per_sec_usec
= USEC_INFINITY
;
3037 r
= parse_percent_unbounded(rvalue
);
3039 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid CPU quota '%s', ignoring.", rvalue
);
3043 c
->cpu_quota_per_sec_usec
= ((usec_t
) r
* USEC_PER_SEC
) / 100U;
3047 int config_parse_memory_limit(
3049 const char *filename
,
3051 const char *section
,
3052 unsigned section_line
,
3059 CGroupContext
*c
= data
;
3060 uint64_t bytes
= CGROUP_LIMIT_MAX
;
3063 if (!isempty(rvalue
) && !streq(rvalue
, "infinity")) {
3065 r
= parse_percent(rvalue
);
3067 r
= parse_size(rvalue
, 1024, &bytes
);
3069 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid memory limit '%s', ignoring: %m", rvalue
);
3073 bytes
= physical_memory_scale(r
, 100U);
3075 if (bytes
>= UINT64_MAX
||
3076 (bytes
<= 0 && !streq(lvalue
, "MemorySwapMax"))) {
3077 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Memory limit '%s' out of range, ignoring.", rvalue
);
3082 if (streq(lvalue
, "MemoryLow"))
3083 c
->memory_low
= bytes
;
3084 else if (streq(lvalue
, "MemoryHigh"))
3085 c
->memory_high
= bytes
;
3086 else if (streq(lvalue
, "MemoryMax"))
3087 c
->memory_max
= bytes
;
3088 else if (streq(lvalue
, "MemorySwapMax"))
3089 c
->memory_swap_max
= bytes
;
3090 else if (streq(lvalue
, "MemoryLimit"))
3091 c
->memory_limit
= bytes
;
3098 int config_parse_tasks_max(
3100 const char *filename
,
3102 const char *section
,
3103 unsigned section_line
,
3110 uint64_t *tasks_max
= data
, v
;
3114 if (isempty(rvalue
)) {
3115 *tasks_max
= u
->manager
->default_tasks_max
;
3119 if (streq(rvalue
, "infinity")) {
3120 *tasks_max
= CGROUP_LIMIT_MAX
;
3124 r
= parse_percent(rvalue
);
3126 r
= safe_atou64(rvalue
, &v
);
3128 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid maximum tasks value '%s', ignoring: %m", rvalue
);
3132 v
= system_tasks_max_scale(r
, 100U);
3134 if (v
<= 0 || v
>= UINT64_MAX
) {
3135 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Maximum tasks value '%s' out of range, ignoring.", rvalue
);
3143 int config_parse_delegate(
3145 const char *filename
,
3147 const char *section
,
3148 unsigned section_line
,
3155 CGroupContext
*c
= data
;
3159 t
= unit_name_to_type(unit
);
3160 assert(t
!= _UNIT_TYPE_INVALID
);
3162 if (!unit_vtable
[t
]->can_delegate
) {
3163 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Delegate= setting not supported for this unit type, ignoring.");
3167 /* We either accept a boolean value, which may be used to turn on delegation for all controllers, or turn it
3168 * off for all. Or it takes a list of controller names, in which case we add the specified controllers to the
3169 * mask to delegate. */
3171 if (isempty(rvalue
)) {
3172 /* An empty string resets controllers and set Delegate=yes. */
3174 c
->delegate_controllers
= 0;
3178 r
= parse_boolean(rvalue
);
3180 const char *p
= rvalue
;
3181 CGroupMask mask
= 0;
3184 _cleanup_free_
char *word
= NULL
;
3185 CGroupController cc
;
3187 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
3193 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3197 cc
= cgroup_controller_from_string(word
);
3199 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid controller name '%s', ignoring", word
);
3203 mask
|= CGROUP_CONTROLLER_TO_MASK(cc
);
3207 c
->delegate_controllers
|= mask
;
3211 c
->delegate_controllers
= _CGROUP_MASK_ALL
;
3213 c
->delegate
= false;
3214 c
->delegate_controllers
= 0;
3220 int config_parse_device_allow(
3222 const char *filename
,
3224 const char *section
,
3225 unsigned section_line
,
3232 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3233 CGroupContext
*c
= data
;
3234 CGroupDeviceAllow
*a
;
3235 const char *p
= rvalue
;
3238 if (isempty(rvalue
)) {
3239 while (c
->device_allow
)
3240 cgroup_context_free_device_allow(c
, c
->device_allow
);
3245 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_QUOTES
);
3249 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3250 "Invalid syntax, ignoring: %s", rvalue
);
3254 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3255 "Failed to extract device path and rights from '%s', ignoring.", rvalue
);
3259 r
= unit_full_printf(userdata
, path
, &resolved
);
3261 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3262 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3266 if (!is_deviceallow_pattern(resolved
) &&
3267 !path_startswith(resolved
, "/run/systemd/inaccessible/")) {
3268 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device node path '%s', ignoring.", resolved
);
3272 if (!isempty(p
) && !in_charset(p
, "rwm")) {
3273 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device rights '%s', ignoring.", p
);
3277 a
= new0(CGroupDeviceAllow
, 1);
3281 a
->path
= TAKE_PTR(resolved
);
3282 a
->r
= isempty(p
) || !!strchr(p
, 'r');
3283 a
->w
= isempty(p
) || !!strchr(p
, 'w');
3284 a
->m
= isempty(p
) || !!strchr(p
, 'm');
3286 LIST_PREPEND(device_allow
, c
->device_allow
, a
);
3290 int config_parse_io_device_weight(
3292 const char *filename
,
3294 const char *section
,
3295 unsigned section_line
,
3302 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3303 CGroupIODeviceWeight
*w
;
3304 CGroupContext
*c
= data
;
3305 const char *p
= rvalue
;
3313 if (isempty(rvalue
)) {
3314 while (c
->io_device_weights
)
3315 cgroup_context_free_io_device_weight(c
, c
->io_device_weights
);
3320 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_QUOTES
);
3324 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3325 "Invalid syntax, ignoring: %s", rvalue
);
3328 if (r
== 0 || isempty(p
)) {
3329 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3330 "Failed to extract device path and weight from '%s', ignoring.", rvalue
);
3334 r
= unit_full_printf(userdata
, path
, &resolved
);
3336 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3337 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3341 if (!path_startswith(resolved
, "/dev") &&
3342 !path_startswith(resolved
, "/run/systemd/inaccessible/")) {
3343 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device node path '%s', ignoring.", resolved
);
3347 r
= cg_weight_parse(p
, &u
);
3349 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "IO weight '%s' invalid, ignoring: %m", p
);
3353 assert(u
!= CGROUP_WEIGHT_INVALID
);
3355 w
= new0(CGroupIODeviceWeight
, 1);
3359 w
->path
= TAKE_PTR(resolved
);
3362 LIST_PREPEND(device_weights
, c
->io_device_weights
, w
);
3366 int config_parse_io_limit(
3368 const char *filename
,
3370 const char *section
,
3371 unsigned section_line
,
3378 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3379 CGroupIODeviceLimit
*l
= NULL
, *t
;
3380 CGroupContext
*c
= data
;
3381 CGroupIOLimitType type
;
3382 const char *p
= rvalue
;
3390 type
= cgroup_io_limit_type_from_string(lvalue
);
3393 if (isempty(rvalue
)) {
3394 LIST_FOREACH(device_limits
, l
, c
->io_device_limits
)
3395 l
->limits
[type
] = cgroup_io_limit_defaults
[type
];
3399 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_QUOTES
);
3403 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3404 "Invalid syntax, ignoring: %s", rvalue
);
3407 if (r
== 0 || isempty(p
)) {
3408 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3409 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
3413 r
= unit_full_printf(userdata
, path
, &resolved
);
3415 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3416 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3420 if (!path_startswith(resolved
, "/dev") &&
3421 !path_startswith(resolved
, "/run/systemd/inaccessible/")) {
3422 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device node path '%s', ignoring.", resolved
);
3426 if (streq("infinity", p
)) {
3427 num
= CGROUP_LIMIT_MAX
;
3429 r
= parse_size(p
, 1000, &num
);
3430 if (r
< 0 || num
<= 0) {
3431 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid IO limit '%s', ignoring.", p
);
3436 LIST_FOREACH(device_limits
, t
, c
->io_device_limits
) {
3437 if (path_equal(resolved
, t
->path
)) {
3444 CGroupIOLimitType ttype
;
3446 l
= new0(CGroupIODeviceLimit
, 1);
3450 l
->path
= TAKE_PTR(resolved
);
3451 for (ttype
= 0; ttype
< _CGROUP_IO_LIMIT_TYPE_MAX
; ttype
++)
3452 l
->limits
[ttype
] = cgroup_io_limit_defaults
[ttype
];
3454 LIST_PREPEND(device_limits
, c
->io_device_limits
, l
);
3457 l
->limits
[type
] = num
;
3462 DEFINE_CONFIG_PARSE_PTR(config_parse_blockio_weight
, cg_blkio_weight_parse
, uint64_t, "Invalid block IO weight");
3464 int config_parse_blockio_device_weight(
3466 const char *filename
,
3468 const char *section
,
3469 unsigned section_line
,
3476 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3477 CGroupBlockIODeviceWeight
*w
;
3478 CGroupContext
*c
= data
;
3479 const char *p
= rvalue
;
3487 if (isempty(rvalue
)) {
3488 while (c
->blockio_device_weights
)
3489 cgroup_context_free_blockio_device_weight(c
, c
->blockio_device_weights
);
3494 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_QUOTES
);
3498 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3499 "Invalid syntax, ignoring: %s", rvalue
);
3502 if (r
== 0 || isempty(p
)) {
3503 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3504 "Failed to extract device node and weight from '%s', ignoring.", rvalue
);
3508 r
= unit_full_printf(userdata
, path
, &resolved
);
3510 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3511 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3515 if (!path_startswith(resolved
, "/dev") &&
3516 !path_startswith(resolved
, "/run/systemd/inaccessible/")) {
3517 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device node path '%s'. Ignoring.", resolved
);
3521 r
= cg_blkio_weight_parse(p
, &u
);
3523 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid block IO weight '%s', ignoring: %m", p
);
3527 assert(u
!= CGROUP_BLKIO_WEIGHT_INVALID
);
3529 w
= new0(CGroupBlockIODeviceWeight
, 1);
3533 w
->path
= TAKE_PTR(resolved
);
3536 LIST_PREPEND(device_weights
, c
->blockio_device_weights
, w
);
3540 int config_parse_blockio_bandwidth(
3542 const char *filename
,
3544 const char *section
,
3545 unsigned section_line
,
3552 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3553 CGroupBlockIODeviceBandwidth
*b
= NULL
, *t
;
3554 CGroupContext
*c
= data
;
3555 const char *p
= rvalue
;
3564 read
= streq("BlockIOReadBandwidth", lvalue
);
3566 if (isempty(rvalue
)) {
3567 LIST_FOREACH(device_bandwidths
, b
, c
->blockio_device_bandwidths
) {
3568 b
->rbps
= CGROUP_LIMIT_MAX
;
3569 b
->wbps
= CGROUP_LIMIT_MAX
;
3574 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_QUOTES
);
3578 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3579 "Invalid syntax, ignoring: %s", rvalue
);
3582 if (r
== 0 || isempty(p
)) {
3583 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3584 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
3588 r
= unit_full_printf(userdata
, path
, &resolved
);
3590 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3591 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3595 if (!path_startswith(resolved
, "/dev") &&
3596 !path_startswith(resolved
, "/run/systemd/inaccessible/")) {
3597 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device node path '%s', ignoring.", resolved
);
3601 r
= parse_size(p
, 1000, &bytes
);
3602 if (r
< 0 || bytes
<= 0) {
3603 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid Block IO Bandwidth '%s', ignoring.", p
);
3607 LIST_FOREACH(device_bandwidths
, t
, c
->blockio_device_bandwidths
) {
3608 if (path_equal(resolved
, t
->path
)) {
3615 b
= new0(CGroupBlockIODeviceBandwidth
, 1);
3619 b
->path
= TAKE_PTR(resolved
);
3620 b
->rbps
= CGROUP_LIMIT_MAX
;
3621 b
->wbps
= CGROUP_LIMIT_MAX
;
3623 LIST_PREPEND(device_bandwidths
, c
->blockio_device_bandwidths
, b
);
3634 DEFINE_CONFIG_PARSE_ENUM(config_parse_job_mode
, job_mode
, JobMode
, "Failed to parse job mode");
3636 int config_parse_job_mode_isolate(
3638 const char *filename
,
3640 const char *section
,
3641 unsigned section_line
,
3655 r
= parse_boolean(rvalue
);
3657 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse boolean, ignoring: %s", rvalue
);
3661 log_notice("%s is deprecated. Please use OnFailureJobMode= instead", lvalue
);
3663 *m
= r
? JOB_ISOLATE
: JOB_REPLACE
;
3667 DEFINE_CONFIG_PARSE_ENUM(config_parse_runtime_preserve_mode
, exec_preserve_mode
, ExecPreserveMode
, "Failed to parse runtime directory preserve mode");
3669 int config_parse_exec_directories(
3671 const char *filename
,
3673 const char *section
,
3674 unsigned section_line
,
3691 if (isempty(rvalue
)) {
3692 /* Empty assignment resets the list */
3693 *rt
= strv_free(*rt
);
3697 for (p
= rvalue
;;) {
3698 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
3700 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
3704 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3705 "Invalid syntax, ignoring: %s", rvalue
);
3711 r
= unit_full_printf(u
, word
, &k
);
3713 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
3714 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
3718 if (!path_is_normalized(k
)) {
3719 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
3720 "%s= path is not normalized, ignoring assignment: %s", lvalue
, rvalue
);
3724 if (path_is_absolute(k
)) {
3725 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
3726 "%s= path is absolute, ignoring assignment: %s", lvalue
, rvalue
);
3730 if (path_startswith(k
, "private")) {
3731 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
3732 "%s= path can't be 'private', ingoring assignment: %s", lvalue
, rvalue
);
3736 r
= strv_push(rt
, k
);
3743 int config_parse_set_status(
3745 const char *filename
,
3747 const char *section
,
3748 unsigned section_line
,
3756 const char *word
, *state
;
3758 ExitStatusSet
*status_set
= data
;
3765 /* Empty assignment resets the list */
3766 if (isempty(rvalue
)) {
3767 exit_status_set_free(status_set
);
3771 FOREACH_WORD(word
, l
, rvalue
, state
) {
3772 _cleanup_free_
char *temp
;
3776 temp
= strndup(word
, l
);
3780 r
= safe_atoi(temp
, &val
);
3782 val
= signal_from_string(temp
);
3785 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse value, ignoring: %s", word
);
3788 set
= &status_set
->signal
;
3790 if (val
< 0 || val
> 255) {
3791 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Value %d is outside range 0-255, ignoring", val
);
3794 set
= &status_set
->status
;
3797 r
= set_ensure_allocated(set
, NULL
);
3801 r
= set_put(*set
, INT_TO_PTR(val
));
3805 if (!isempty(state
))
3806 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Trailing garbage, ignoring.");
3811 int config_parse_namespace_path_strv(
3813 const char *filename
,
3815 const char *section
,
3816 unsigned section_line
,
3825 const char *p
= rvalue
;
3833 if (isempty(rvalue
)) {
3834 /* Empty assignment resets the list */
3835 *sv
= strv_free(*sv
);
3840 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
, *joined
= NULL
;
3842 bool ignore_enoent
= false, shall_prefix
= false;
3844 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
3850 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
3854 if (!utf8_is_valid(word
)) {
3855 log_syntax_invalid_utf8(unit
, LOG_ERR
, filename
, line
, word
);
3860 if (startswith(w
, "-")) {
3861 ignore_enoent
= true;
3864 if (startswith(w
, "+")) {
3865 shall_prefix
= true;
3869 r
= unit_full_printf(u
, w
, &resolved
);
3871 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", w
);
3875 if (!path_is_absolute(resolved
)) {
3876 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Not an absolute path, ignoring: %s", resolved
);
3880 path_kill_slashes(resolved
);
3882 joined
= strjoin(ignore_enoent
? "-" : "",
3883 shall_prefix
? "+" : "",
3886 r
= strv_push(sv
, joined
);
3896 int config_parse_temporary_filesystems(
3898 const char *filename
,
3900 const char *section
,
3901 unsigned section_line
,
3909 ExecContext
*c
= data
;
3910 const char *p
= rvalue
;
3918 if (isempty(rvalue
)) {
3919 /* Empty assignment resets the list */
3920 temporary_filesystem_free_many(c
->temporary_filesystems
, c
->n_temporary_filesystems
);
3921 c
->temporary_filesystems
= NULL
;
3922 c
->n_temporary_filesystems
= 0;
3927 _cleanup_free_
char *word
= NULL
, *path
= NULL
, *resolved
= NULL
;
3930 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
3936 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
3941 r
= extract_first_word(&w
, &path
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
3945 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", word
);
3949 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid syntax, ignoring: %s", word
);
3953 r
= unit_full_printf(u
, path
, &resolved
);
3955 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", path
);
3959 if (!path_is_absolute(resolved
)) {
3960 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Not an absolute path, ignoring: %s", resolved
);
3964 path_kill_slashes(resolved
);
3966 r
= temporary_filesystem_add(&c
->temporary_filesystems
, &c
->n_temporary_filesystems
, path
, w
);
3970 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse mount options, ignoring: %s", word
);
3976 int config_parse_bind_paths(
3978 const char *filename
,
3980 const char *section
,
3981 unsigned section_line
,
3988 ExecContext
*c
= data
;
3998 if (isempty(rvalue
)) {
3999 /* Empty assignment resets the list */
4000 bind_mount_free_many(c
->bind_mounts
, c
->n_bind_mounts
);
4001 c
->bind_mounts
= NULL
;
4002 c
->n_bind_mounts
= 0;
4008 _cleanup_free_
char *source
= NULL
, *destination
= NULL
;
4009 _cleanup_free_
char *sresolved
= NULL
, *dresolved
= NULL
;
4010 char *s
= NULL
, *d
= NULL
;
4011 bool rbind
= true, ignore_enoent
= false;
4013 r
= extract_first_word(&p
, &source
, ":" WHITESPACE
, EXTRACT_QUOTES
|EXTRACT_DONT_COALESCE_SEPARATORS
);
4019 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s: %s", lvalue
, rvalue
);
4023 r
= unit_full_printf(u
, source
, &sresolved
);
4025 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4026 "Failed to resolved unit specifiers in \"%s\", ignoring: %m", source
);
4032 ignore_enoent
= true;
4036 if (!utf8_is_valid(s
)) {
4037 log_syntax_invalid_utf8(unit
, LOG_ERR
, filename
, line
, s
);
4040 if (!path_is_absolute(s
)) {
4041 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Not an absolute source path, ignoring: %s", s
);
4045 path_kill_slashes(s
);
4047 /* Optionally, the destination is specified. */
4048 if (p
&& p
[-1] == ':') {
4049 r
= extract_first_word(&p
, &destination
, ":" WHITESPACE
, EXTRACT_QUOTES
|EXTRACT_DONT_COALESCE_SEPARATORS
);
4053 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s: %s", lvalue
, rvalue
);
4057 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Missing argument after ':': %s", rvalue
);
4061 r
= unit_full_printf(u
, destination
, &dresolved
);
4063 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4064 "Failed to resolved specifiers in \"%s\", ignoring: %m", destination
);
4068 if (!utf8_is_valid(dresolved
)) {
4069 log_syntax_invalid_utf8(unit
, LOG_ERR
, filename
, line
, dresolved
);
4072 if (!path_is_absolute(dresolved
)) {
4073 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Not an absolute destination path, ignoring: %s", dresolved
);
4077 d
= path_kill_slashes(dresolved
);
4079 /* Optionally, there's also a short option string specified */
4080 if (p
&& p
[-1] == ':') {
4081 _cleanup_free_
char *options
= NULL
;
4083 r
= extract_first_word(&p
, &options
, NULL
, EXTRACT_QUOTES
);
4087 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s: %s", lvalue
, rvalue
);
4091 if (isempty(options
) || streq(options
, "rbind"))
4093 else if (streq(options
, "norbind"))
4096 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid option string, ignoring setting: %s", options
);
4103 r
= bind_mount_add(&c
->bind_mounts
, &c
->n_bind_mounts
,
4107 .read_only
= !!strstr(lvalue
, "ReadOnly"),
4109 .ignore_enoent
= ignore_enoent
,
4118 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_home
, protect_home_or_bool
, ProtectHome
, "Failed to parse protect home value");
4119 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_system
, protect_system_or_bool
, ProtectSystem
, "Failed to parse protect system value");
4120 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_keyring_mode
, exec_keyring_mode
, ExecKeyringMode
, "Failed to parse keyring mode");
4122 int config_parse_job_timeout_sec(
4124 const char *filename
,
4126 const char *section
,
4127 unsigned section_line
,
4143 r
= parse_sec_fix_0(rvalue
, &usec
);
4145 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse JobTimeoutSec= parameter, ignoring: %s", rvalue
);
4149 /* If the user explicitly changed JobTimeoutSec= also change JobRunningTimeoutSec=, for compatibility with old
4150 * versions. If JobRunningTimeoutSec= was explicitly set, avoid this however as whatever the user picked should
4153 if (!u
->job_running_timeout_set
)
4154 u
->job_running_timeout
= usec
;
4156 u
->job_timeout
= usec
;
4161 int config_parse_job_running_timeout_sec(
4163 const char *filename
,
4165 const char *section
,
4166 unsigned section_line
,
4182 r
= parse_sec_fix_0(rvalue
, &usec
);
4184 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse JobRunningTimeoutSec= parameter, ignoring: %s", rvalue
);
4188 u
->job_running_timeout
= usec
;
4189 u
->job_running_timeout_set
= true;
4194 #define FOLLOW_MAX 8
4196 static int open_follow(char **filename
, FILE **_f
, Set
*names
, char **_final
) {
4207 /* This will update the filename pointer if the loaded file is
4208 * reached by a symlink. The old string will be freed. */
4211 char *target
, *name
;
4213 if (c
++ >= FOLLOW_MAX
)
4216 path_kill_slashes(*filename
);
4218 /* Add the file name we are currently looking at to
4219 * the names of this unit, but only if it is a valid
4221 name
= basename(*filename
);
4222 if (unit_name_is_valid(name
, UNIT_NAME_ANY
)) {
4224 id
= set_get(names
, name
);
4230 r
= set_consume(names
, id
);
4236 /* Try to open the file name, but don't if its a symlink */
4237 fd
= open(*filename
, O_RDONLY
|O_CLOEXEC
|O_NOCTTY
|O_NOFOLLOW
);
4244 /* Hmm, so this is a symlink. Let's read the name, and follow it manually */
4245 r
= readlink_and_make_absolute(*filename
, &target
);
4253 f
= fdopen(fd
, "re");
4265 static int merge_by_names(Unit
**u
, Set
*names
, const char *id
) {
4273 /* Let's try to add in all symlink names we found */
4274 while ((k
= set_steal_first(names
))) {
4276 /* First try to merge in the other name into our
4278 r
= unit_merge_by_name(*u
, k
);
4282 /* Hmm, we couldn't merge the other unit into
4283 * ours? Then let's try it the other way
4286 /* If the symlink name we are looking at is unit template, then
4287 we must search for instance of this template */
4288 if (unit_name_is_valid(k
, UNIT_NAME_TEMPLATE
) && (*u
)->instance
) {
4289 _cleanup_free_
char *instance
= NULL
;
4291 r
= unit_name_replace_instance(k
, (*u
)->instance
, &instance
);
4295 other
= manager_get_unit((*u
)->manager
, instance
);
4297 other
= manager_get_unit((*u
)->manager
, k
);
4302 r
= unit_merge(other
, *u
);
4305 return merge_by_names(u
, names
, NULL
);
4313 unit_choose_id(*u
, id
);
4321 static int load_from_path(Unit
*u
, const char *path
) {
4322 _cleanup_set_free_free_ Set
*symlink_names
= NULL
;
4323 _cleanup_fclose_
FILE *f
= NULL
;
4324 _cleanup_free_
char *filename
= NULL
;
4333 symlink_names
= set_new(&string_hash_ops
);
4337 if (path_is_absolute(path
)) {
4339 filename
= strdup(path
);
4343 r
= open_follow(&filename
, &f
, symlink_names
, &id
);
4345 filename
= mfree(filename
);
4353 STRV_FOREACH(p
, u
->manager
->lookup_paths
.search_path
) {
4355 /* Instead of opening the path right away, we manually
4356 * follow all symlinks and add their name to our unit
4357 * name set while doing so */
4358 filename
= path_make_absolute(path
, *p
);
4362 if (u
->manager
->unit_path_cache
&&
4363 !set_get(u
->manager
->unit_path_cache
, filename
))
4366 r
= open_follow(&filename
, &f
, symlink_names
, &id
);
4369 filename
= mfree(filename
);
4371 /* ENOENT means that the file is missing or is a dangling symlink.
4372 * ENOTDIR means that one of paths we expect to be is a directory
4373 * is not a directory, we should just ignore that.
4374 * EACCES means that the directory or file permissions are wrong.
4377 log_debug_errno(r
, "Cannot access \"%s\": %m", filename
);
4378 else if (!IN_SET(r
, -ENOENT
, -ENOTDIR
))
4381 /* Empty the symlink names for the next run */
4382 set_clear_free(symlink_names
);
4387 /* Hmm, no suitable file found? */
4390 if (!unit_type_may_alias(u
->type
) && set_size(symlink_names
) > 1) {
4391 log_unit_warning(u
, "Unit type of %s does not support alias names, refusing loading via symlink.", u
->id
);
4396 r
= merge_by_names(&merged
, symlink_names
, id
);
4401 u
->load_state
= UNIT_MERGED
;
4405 if (fstat(fileno(f
), &st
) < 0)
4408 if (null_or_empty(&st
)) {
4409 u
->load_state
= UNIT_MASKED
;
4410 u
->fragment_mtime
= 0;
4412 u
->load_state
= UNIT_LOADED
;
4413 u
->fragment_mtime
= timespec_load(&st
.st_mtim
);
4415 /* Now, parse the file contents */
4416 r
= config_parse(u
->id
, filename
, f
,
4417 UNIT_VTABLE(u
)->sections
,
4418 config_item_perf_lookup
, load_fragment_gperf_lookup
,
4419 CONFIG_PARSE_ALLOW_INCLUDE
, u
);
4424 free_and_replace(u
->fragment_path
, filename
);
4426 if (u
->source_path
) {
4427 if (stat(u
->source_path
, &st
) >= 0)
4428 u
->source_mtime
= timespec_load(&st
.st_mtim
);
4430 u
->source_mtime
= 0;
4436 int unit_load_fragment(Unit
*u
) {
4442 assert(u
->load_state
== UNIT_STUB
);
4446 u
->load_state
= UNIT_LOADED
;
4450 /* First, try to find the unit under its id. We always look
4451 * for unit files in the default directories, to make it easy
4452 * to override things by placing things in /etc/systemd/system */
4453 r
= load_from_path(u
, u
->id
);
4457 /* Try to find an alias we can load this with */
4458 if (u
->load_state
== UNIT_STUB
) {
4459 SET_FOREACH(t
, u
->names
, i
) {
4464 r
= load_from_path(u
, t
);
4468 if (u
->load_state
!= UNIT_STUB
)
4473 /* And now, try looking for it under the suggested (originally linked) path */
4474 if (u
->load_state
== UNIT_STUB
&& u
->fragment_path
) {
4476 r
= load_from_path(u
, u
->fragment_path
);
4480 if (u
->load_state
== UNIT_STUB
)
4481 /* Hmm, this didn't work? Then let's get rid
4482 * of the fragment path stored for us, so that
4483 * we don't point to an invalid location. */
4484 u
->fragment_path
= mfree(u
->fragment_path
);
4487 /* Look for a template */
4488 if (u
->load_state
== UNIT_STUB
&& u
->instance
) {
4489 _cleanup_free_
char *k
= NULL
;
4491 r
= unit_name_template(u
->id
, &k
);
4495 r
= load_from_path(u
, k
);
4498 log_unit_notice(u
, "Unit configuration has fatal error, unit will not be started.");
4502 if (u
->load_state
== UNIT_STUB
) {
4503 SET_FOREACH(t
, u
->names
, i
) {
4504 _cleanup_free_
char *z
= NULL
;
4509 r
= unit_name_template(t
, &z
);
4513 r
= load_from_path(u
, z
);
4517 if (u
->load_state
!= UNIT_STUB
)
4526 void unit_dump_config_items(FILE *f
) {
4527 static const struct {
4528 const ConfigParserCallback callback
;
4531 { config_parse_warn_compat
, "NOTSUPPORTED" },
4532 { config_parse_int
, "INTEGER" },
4533 { config_parse_unsigned
, "UNSIGNED" },
4534 { config_parse_iec_size
, "SIZE" },
4535 { config_parse_iec_uint64
, "SIZE" },
4536 { config_parse_si_size
, "SIZE" },
4537 { config_parse_bool
, "BOOLEAN" },
4538 { config_parse_string
, "STRING" },
4539 { config_parse_path
, "PATH" },
4540 { config_parse_unit_path_printf
, "PATH" },
4541 { config_parse_strv
, "STRING [...]" },
4542 { config_parse_exec_nice
, "NICE" },
4543 { config_parse_exec_oom_score_adjust
, "OOMSCOREADJUST" },
4544 { config_parse_exec_io_class
, "IOCLASS" },
4545 { config_parse_exec_io_priority
, "IOPRIORITY" },
4546 { config_parse_exec_cpu_sched_policy
, "CPUSCHEDPOLICY" },
4547 { config_parse_exec_cpu_sched_prio
, "CPUSCHEDPRIO" },
4548 { config_parse_exec_cpu_affinity
, "CPUAFFINITY" },
4549 { config_parse_mode
, "MODE" },
4550 { config_parse_unit_env_file
, "FILE" },
4551 { config_parse_exec_output
, "OUTPUT" },
4552 { config_parse_exec_input
, "INPUT" },
4553 { config_parse_log_facility
, "FACILITY" },
4554 { config_parse_log_level
, "LEVEL" },
4555 { config_parse_exec_secure_bits
, "SECUREBITS" },
4556 { config_parse_capability_set
, "BOUNDINGSET" },
4557 { config_parse_rlimit
, "LIMIT" },
4558 { config_parse_unit_deps
, "UNIT [...]" },
4559 { config_parse_exec
, "PATH [ARGUMENT [...]]" },
4560 { config_parse_service_type
, "SERVICETYPE" },
4561 { config_parse_service_restart
, "SERVICERESTART" },
4562 { config_parse_kill_mode
, "KILLMODE" },
4563 { config_parse_signal
, "SIGNAL" },
4564 { config_parse_socket_listen
, "SOCKET [...]" },
4565 { config_parse_socket_bind
, "SOCKETBIND" },
4566 { config_parse_socket_bindtodevice
, "NETWORKINTERFACE" },
4567 { config_parse_sec
, "SECONDS" },
4568 { config_parse_nsec
, "NANOSECONDS" },
4569 { config_parse_namespace_path_strv
, "PATH [...]" },
4570 { config_parse_bind_paths
, "PATH[:PATH[:OPTIONS]] [...]" },
4571 { config_parse_unit_requires_mounts_for
, "PATH [...]" },
4572 { config_parse_exec_mount_flags
, "MOUNTFLAG [...]" },
4573 { config_parse_unit_string_printf
, "STRING" },
4574 { config_parse_trigger_unit
, "UNIT" },
4575 { config_parse_timer
, "TIMER" },
4576 { config_parse_path_spec
, "PATH" },
4577 { config_parse_notify_access
, "ACCESS" },
4578 { config_parse_ip_tos
, "TOS" },
4579 { config_parse_unit_condition_path
, "CONDITION" },
4580 { config_parse_unit_condition_string
, "CONDITION" },
4581 { config_parse_unit_condition_null
, "CONDITION" },
4582 { config_parse_unit_slice
, "SLICE" },
4583 { config_parse_documentation
, "URL" },
4584 { config_parse_service_timeout
, "SECONDS" },
4585 { config_parse_emergency_action
, "ACTION" },
4586 { config_parse_set_status
, "STATUS" },
4587 { config_parse_service_sockets
, "SOCKETS" },
4588 { config_parse_environ
, "ENVIRON" },
4590 { config_parse_syscall_filter
, "SYSCALLS" },
4591 { config_parse_syscall_archs
, "ARCHS" },
4592 { config_parse_syscall_errno
, "ERRNO" },
4593 { config_parse_address_families
, "FAMILIES" },
4594 { config_parse_restrict_namespaces
, "NAMESPACES" },
4596 { config_parse_cpu_shares
, "SHARES" },
4597 { config_parse_cg_weight
, "WEIGHT" },
4598 { config_parse_memory_limit
, "LIMIT" },
4599 { config_parse_device_allow
, "DEVICE" },
4600 { config_parse_device_policy
, "POLICY" },
4601 { config_parse_io_limit
, "LIMIT" },
4602 { config_parse_io_device_weight
, "DEVICEWEIGHT" },
4603 { config_parse_blockio_bandwidth
, "BANDWIDTH" },
4604 { config_parse_blockio_weight
, "WEIGHT" },
4605 { config_parse_blockio_device_weight
, "DEVICEWEIGHT" },
4606 { config_parse_long
, "LONG" },
4607 { config_parse_socket_service
, "SERVICE" },
4609 { config_parse_exec_selinux_context
, "LABEL" },
4611 { config_parse_job_mode
, "MODE" },
4612 { config_parse_job_mode_isolate
, "BOOLEAN" },
4613 { config_parse_personality
, "PERSONALITY" },
4616 const char *prev
= NULL
;
4621 NULSTR_FOREACH(i
, load_fragment_gperf_nulstr
) {
4622 const char *rvalue
= "OTHER", *lvalue
;
4623 const ConfigPerfItem
*p
;
4628 assert_se(p
= load_fragment_gperf_lookup(i
, strlen(i
)));
4630 /* Hide legacy settings */
4631 if (p
->parse
== config_parse_warn_compat
&&
4632 p
->ltype
== DISABLED_LEGACY
)
4635 for (j
= 0; j
< ELEMENTSOF(table
); j
++)
4636 if (p
->parse
== table
[j
].callback
) {
4637 rvalue
= table
[j
].rvalue
;
4641 dot
= strchr(i
, '.');
4642 lvalue
= dot
? dot
+ 1 : i
;
4646 if (!prev
|| !strneq(prev
, i
, prefix_len
+1)) {
4650 fprintf(f
, "[%.*s]\n", (int) prefix_len
, i
);
4653 fprintf(f
, "%s=%s\n", lvalue
, rvalue
);