1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 This file is part of systemd.
5 Copyright 2010 Lennart Poettering
6 Copyright 2012 Holger Hans Peter Freyther
12 #include <linux/oom.h>
18 #include <sys/resource.h>
22 #include "alloc-util.h"
23 #include "all-units.h"
24 #include "bus-error.h"
25 #include "bus-internal.h"
28 #include "capability-util.h"
30 #include "conf-parser.h"
31 #include "cpu-set-util.h"
33 #include "errno-list.h"
37 #include "hexdecoct.h"
40 #include "journal-util.h"
41 #include "load-fragment.h"
44 #include "mount-util.h"
45 #include "parse-util.h"
46 #include "path-util.h"
47 #include "process-util.h"
48 #include "rlimit-util.h"
50 #include "seccomp-util.h"
52 #include "securebits.h"
53 #include "securebits-util.h"
54 #include "signal-util.h"
55 #include "socket-protocol-list.h"
56 #include "stat-util.h"
57 #include "string-util.h"
59 #include "unit-name.h"
60 #include "unit-printf.h"
61 #include "user-util.h"
65 DEFINE_CONFIG_PARSE_ENUM(config_parse_collect_mode
, collect_mode
, CollectMode
, "Failed to parse garbage collection mode");
67 int config_parse_unit_deps(
72 unsigned section_line
,
79 UnitDependency d
= ltype
;
89 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
92 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_RETAIN_ESCAPE
);
98 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
102 r
= unit_name_printf(u
, word
, &k
);
104 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve specifiers, ignoring: %m");
108 r
= unit_add_dependency_by_name(u
, d
, k
, NULL
, true, UNIT_DEPENDENCY_FILE
);
110 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
116 int config_parse_obsolete_unit_deps(
118 const char *filename
,
121 unsigned section_line
,
128 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
129 "Unit dependency type %s= is obsolete, replacing by %s=, please update your unit file", lvalue
, unit_dependency_to_string(ltype
));
131 return config_parse_unit_deps(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
);
134 int config_parse_unit_string_printf(
136 const char *filename
,
139 unsigned section_line
,
146 _cleanup_free_
char *k
= NULL
;
155 r
= unit_full_printf(u
, rvalue
, &k
);
157 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers on %s, ignoring: %m", rvalue
);
161 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
164 int config_parse_unit_strv_printf(
166 const char *filename
,
169 unsigned section_line
,
177 _cleanup_free_
char *k
= NULL
;
185 r
= unit_full_printf(u
, rvalue
, &k
);
187 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers on %s, ignoring: %m", rvalue
);
191 return config_parse_strv(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
194 int config_parse_unit_path_printf(
196 const char *filename
,
199 unsigned section_line
,
206 _cleanup_free_
char *k
= NULL
;
216 /* Let's not bother with anything that is too long */
217 if (strlen(rvalue
) >= PATH_MAX
) {
218 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
219 "%s value too long%s.",
220 lvalue
, fatal
? "" : ", ignoring");
221 return fatal
? -ENAMETOOLONG
: 0;
224 r
= unit_full_printf(u
, rvalue
, &k
);
226 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
227 "Failed to resolve unit specifiers in \"%s\"%s: %m",
228 rvalue
, fatal
? "" : ", ignoring");
229 return fatal
? -ENOEXEC
: 0;
232 return config_parse_path(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
235 int config_parse_unit_path_strv_printf(
237 const char *filename
,
240 unsigned section_line
,
257 if (isempty(rvalue
)) {
263 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
265 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
271 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
272 "Invalid syntax, ignoring: %s", rvalue
);
276 r
= unit_full_printf(u
, word
, &k
);
278 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
279 "Failed to resolve unit specifiers on \"%s\", ignoring: %m", word
);
283 if (!utf8_is_valid(k
)) {
284 log_syntax_invalid_utf8(unit
, LOG_ERR
, filename
, line
, rvalue
);
288 if (!path_is_absolute(k
)) {
289 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
290 "Symlink path is not absolute: %s", k
);
294 path_kill_slashes(k
);
303 int config_parse_socket_listen(const char *unit
,
304 const char *filename
,
307 unsigned section_line
,
314 _cleanup_free_ SocketPort
*p
= NULL
;
326 if (isempty(rvalue
)) {
327 /* An empty assignment removes all ports */
328 socket_free_ports(s
);
332 p
= new0(SocketPort
, 1);
336 if (ltype
!= SOCKET_SOCKET
) {
339 r
= unit_full_printf(UNIT(s
), rvalue
, &p
->path
);
341 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers on %s, ignoring: %m", rvalue
);
345 path_kill_slashes(p
->path
);
347 } else if (streq(lvalue
, "ListenNetlink")) {
348 _cleanup_free_
char *k
= NULL
;
350 p
->type
= SOCKET_SOCKET
;
351 r
= unit_full_printf(UNIT(s
), rvalue
, &k
);
353 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers on %s, ignoring: %m", rvalue
);
357 r
= socket_address_parse_netlink(&p
->address
, k
);
359 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse address value, ignoring: %s", rvalue
);
364 _cleanup_free_
char *k
= NULL
;
366 p
->type
= SOCKET_SOCKET
;
367 r
= unit_full_printf(UNIT(s
), rvalue
, &k
);
369 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,"Failed to resolve unit specifiers on %s, ignoring: %m", rvalue
);
373 r
= socket_address_parse_and_warn(&p
->address
, k
);
375 if (r
!= -EAFNOSUPPORT
)
376 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse address value, ignoring: %s", rvalue
);
380 if (streq(lvalue
, "ListenStream"))
381 p
->address
.type
= SOCK_STREAM
;
382 else if (streq(lvalue
, "ListenDatagram"))
383 p
->address
.type
= SOCK_DGRAM
;
385 assert(streq(lvalue
, "ListenSequentialPacket"));
386 p
->address
.type
= SOCK_SEQPACKET
;
389 if (socket_address_family(&p
->address
) != AF_LOCAL
&& p
->address
.type
== SOCK_SEQPACKET
) {
390 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Address family not supported, ignoring: %s", rvalue
);
396 p
->auxiliary_fds
= NULL
;
397 p
->n_auxiliary_fds
= 0;
400 LIST_FIND_TAIL(port
, s
->ports
, tail
);
401 LIST_INSERT_AFTER(port
, s
->ports
, tail
, p
);
408 int config_parse_socket_protocol(const char *unit
,
409 const char *filename
,
412 unsigned section_line
,
428 r
= socket_protocol_from_name(rvalue
);
430 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid socket protocol, ignoring: %s", rvalue
);
432 } else if (!IN_SET(r
, IPPROTO_UDPLITE
, IPPROTO_SCTP
)) {
433 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Socket protocol not supported, ignoring: %s", rvalue
);
437 s
->socket_protocol
= r
;
442 int config_parse_socket_bind(const char *unit
,
443 const char *filename
,
446 unsigned section_line
,
454 SocketAddressBindIPv6Only b
;
463 b
= parse_socket_address_bind_ipv6_only_or_bool(rvalue
);
465 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse bind IPv6 only value, ignoring: %s", rvalue
);
469 s
->bind_ipv6_only
= b
;
474 int config_parse_exec_nice(
476 const char *filename
,
479 unsigned section_line
,
486 ExecContext
*c
= data
;
494 r
= parse_nice(rvalue
, &priority
);
497 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Nice priority out of range, ignoring: %s", rvalue
);
499 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse nice priority, ignoring: %s", rvalue
);
510 int config_parse_exec_oom_score_adjust(const char* unit
,
511 const char *filename
,
514 unsigned section_line
,
521 ExecContext
*c
= data
;
529 r
= safe_atoi(rvalue
, &oa
);
531 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse the OOM score adjust value, ignoring: %s", rvalue
);
535 if (oa
< OOM_SCORE_ADJ_MIN
|| oa
> OOM_SCORE_ADJ_MAX
) {
536 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "OOM score adjust value out of range, ignoring: %s", rvalue
);
540 c
->oom_score_adjust
= oa
;
541 c
->oom_score_adjust_set
= true;
546 int config_parse_exec(
548 const char *filename
,
551 unsigned section_line
,
558 ExecCommand
**e
= data
;
570 rvalue
+= strspn(rvalue
, WHITESPACE
);
572 if (isempty(rvalue
)) {
573 /* An empty assignment resets the list */
574 *e
= exec_command_free_list(*e
);
580 _cleanup_free_
char *path
= NULL
, *firstword
= NULL
;
581 ExecCommandFlags flags
= 0;
582 bool ignore
= false, separate_argv0
= false;
583 _cleanup_free_ ExecCommand
*nce
= NULL
;
584 _cleanup_strv_free_
char **n
= NULL
;
585 size_t nlen
= 0, nbufsize
= 0;
590 r
= extract_first_word_and_warn(&p
, &firstword
, NULL
, EXTRACT_QUOTES
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
596 /* We accept an absolute path as first argument. If it's prefixed with - and the path doesn't
597 * exist, we ignore it instead of erroring out; if it's prefixed with @, we allow overriding of
598 * argv[0]; if it's prefixed with +, it will be run with full privileges and no sandboxing; if
599 * it's prefixed with '!' we apply sandboxing, but do not change user/group credentials; if
600 * it's prefixed with '!!', then we apply user/group credentials if the kernel supports ambient
601 * capabilities -- if it doesn't we don't apply the credentials themselves, but do apply most
602 * other sandboxing, with some special exceptions for changing UID.
604 * The idea is that '!!' may be used to write services that can take benefit of systemd's
605 * UID/GID dropping if the kernel supports ambient creds, but provide an automatic fallback to
606 * privilege dropping within the daemon if the kernel does not offer that. */
608 if (*f
== '-' && !(flags
& EXEC_COMMAND_IGNORE_FAILURE
)) {
609 flags
|= EXEC_COMMAND_IGNORE_FAILURE
;
611 } else if (*f
== '@' && !separate_argv0
)
612 separate_argv0
= true;
613 else if (*f
== '+' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
614 flags
|= EXEC_COMMAND_FULLY_PRIVILEGED
;
615 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
616 flags
|= EXEC_COMMAND_NO_SETUID
;
617 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_AMBIENT_MAGIC
))) {
618 flags
&= ~EXEC_COMMAND_NO_SETUID
;
619 flags
|= EXEC_COMMAND_AMBIENT_MAGIC
;
625 r
= unit_full_printf(u
, f
, &path
);
627 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
628 "Failed to resolve unit specifiers on %s%s: %m",
629 f
, ignore
? ", ignoring" : "");
630 return ignore
? 0 : -ENOEXEC
;
634 /* First word is either "-" or "@" with no command. */
635 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
636 "Empty path in command line%s: \"%s\"",
637 ignore
? ", ignoring" : "", rvalue
);
638 return ignore
? 0 : -ENOEXEC
;
640 if (!string_is_safe(path
)) {
641 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
642 "Executable name contains special characters%s: %s",
643 ignore
? ", ignoring" : "", path
);
644 return ignore
? 0 : -ENOEXEC
;
646 if (endswith(path
, "/")) {
647 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
648 "Executable path specifies a directory%s: %s",
649 ignore
? ", ignoring" : "", path
);
650 return ignore
? 0 : -ENOEXEC
;
653 if (!path_is_absolute(path
)) {
657 if (!filename_is_valid(path
)) {
658 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
659 "Neither a valid executable name nor an absolute path%s: %s",
660 ignore
? ", ignoring" : "", path
);
661 return ignore
? 0 : -ENOEXEC
;
664 /* Resolve a single-component name to a full path */
665 NULSTR_FOREACH(prefix
, DEFAULT_PATH_NULSTR
) {
666 _cleanup_free_
char *fullpath
= NULL
;
668 fullpath
= strjoin(prefix
, "/", path
);
672 if (access(fullpath
, F_OK
) >= 0) {
673 free_and_replace(path
, fullpath
);
680 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
681 "Executable \"%s\" not found in path \"%s\"%s",
682 path
, DEFAULT_PATH
, ignore
? ", ignoring" : "");
683 return ignore
? 0 : -ENOEXEC
;
687 if (!separate_argv0
) {
690 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
700 path_kill_slashes(path
);
702 while (!isempty(p
)) {
703 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
705 /* Check explicitly for an unquoted semicolon as
706 * command separator token. */
707 if (p
[0] == ';' && (!p
[1] || strchr(WHITESPACE
, p
[1]))) {
709 p
+= strspn(p
, WHITESPACE
);
714 /* Check for \; explicitly, to not confuse it with \\; or "\;" or "\\;" etc.
715 * extract_first_word() would return the same for all of those. */
716 if (p
[0] == '\\' && p
[1] == ';' && (!p
[2] || strchr(WHITESPACE
, p
[2]))) {
720 p
+= strspn(p
, WHITESPACE
);
722 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
733 r
= extract_first_word_and_warn(&p
, &word
, NULL
, EXTRACT_QUOTES
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
737 return ignore
? 0 : -ENOEXEC
;
739 r
= unit_full_printf(u
, word
, &resolved
);
741 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
742 "Failed to resolve unit specifiers on %s%s: %m",
743 word
, ignore
? ", ignoring" : "");
744 return ignore
? 0 : -ENOEXEC
;
747 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
750 n
[nlen
++] = TAKE_PTR(resolved
);
755 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
756 "Empty executable name or zeroeth argument%s: %s",
757 ignore
? ", ignoring" : "", rvalue
);
758 return ignore
? 0 : -ENOEXEC
;
761 nce
= new0(ExecCommand
, 1);
765 nce
->argv
= TAKE_PTR(n
);
766 nce
->path
= TAKE_PTR(path
);
769 exec_command_append_list(e
, nce
);
771 /* Do not _cleanup_free_ these. */
780 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_type
, service_type
, ServiceType
, "Failed to parse service type");
781 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart
, service_restart
, ServiceRestart
, "Failed to parse service restart specifier");
783 int config_parse_socket_bindtodevice(
785 const char *filename
,
788 unsigned section_line
,
803 if (rvalue
[0] && !streq(rvalue
, "*")) {
804 if (!ifname_valid(rvalue
)) {
805 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Interface name is invalid, ignoring: %s", rvalue
);
815 free(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
,
1169 ExecContext
*c
= data
;
1177 x
= sched_policy_from_string(rvalue
);
1179 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse CPU scheduling policy, ignoring: %s", rvalue
);
1183 c
->cpu_sched_policy
= x
;
1184 /* Moving to or from real-time policy? We need to adjust the priority */
1185 c
->cpu_sched_priority
= CLAMP(c
->cpu_sched_priority
, sched_get_priority_min(x
), sched_get_priority_max(x
));
1186 c
->cpu_sched_set
= true;
1191 int config_parse_exec_cpu_sched_prio(const char *unit
,
1192 const char *filename
,
1194 const char *section
,
1195 unsigned section_line
,
1202 ExecContext
*c
= data
;
1210 r
= safe_atoi(rvalue
, &i
);
1212 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse CPU scheduling policy, ignoring: %s", rvalue
);
1216 /* On Linux RR/FIFO range from 1 to 99 and OTHER/BATCH may only be 0 */
1217 min
= sched_get_priority_min(c
->cpu_sched_policy
);
1218 max
= sched_get_priority_max(c
->cpu_sched_policy
);
1220 if (i
< min
|| i
> max
) {
1221 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "CPU scheduling priority is out of range, ignoring: %s", rvalue
);
1225 c
->cpu_sched_priority
= i
;
1226 c
->cpu_sched_set
= true;
1231 int config_parse_exec_cpu_affinity(const char *unit
,
1232 const char *filename
,
1234 const char *section
,
1235 unsigned section_line
,
1242 ExecContext
*c
= data
;
1243 _cleanup_cpu_free_ cpu_set_t
*cpuset
= NULL
;
1251 ncpus
= parse_cpu_set_and_warn(rvalue
, &cpuset
, unit
, filename
, line
, lvalue
);
1256 /* An empty assignment resets the CPU list */
1257 c
->cpuset
= cpu_set_mfree(c
->cpuset
);
1258 c
->cpuset_ncpus
= 0;
1263 c
->cpuset
= TAKE_PTR(cpuset
);
1264 c
->cpuset_ncpus
= (unsigned) ncpus
;
1268 if (c
->cpuset_ncpus
< (unsigned) ncpus
) {
1269 CPU_OR_S(CPU_ALLOC_SIZE(c
->cpuset_ncpus
), cpuset
, c
->cpuset
, cpuset
);
1270 CPU_FREE(c
->cpuset
);
1271 c
->cpuset
= TAKE_PTR(cpuset
);
1272 c
->cpuset_ncpus
= (unsigned) ncpus
;
1276 CPU_OR_S(CPU_ALLOC_SIZE((unsigned) ncpus
), c
->cpuset
, c
->cpuset
, cpuset
);
1281 int config_parse_exec_secure_bits(const char *unit
,
1282 const char *filename
,
1284 const char *section
,
1285 unsigned section_line
,
1292 ExecContext
*c
= data
;
1300 if (isempty(rvalue
)) {
1301 /* An empty assignment resets the field */
1306 r
= secure_bits_from_string(rvalue
);
1310 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1311 "Invalid syntax, ignoring: %s", rvalue
);
1320 int config_parse_capability_set(
1322 const char *filename
,
1324 const char *section
,
1325 unsigned section_line
,
1332 uint64_t *capability_set
= data
;
1333 uint64_t sum
= 0, initial
= 0;
1334 bool invert
= false;
1342 if (rvalue
[0] == '~') {
1347 if (streq(lvalue
, "CapabilityBoundingSet"))
1348 initial
= CAP_ALL
; /* initialized to all bits on */
1349 /* else "AmbientCapabilities" initialized to all bits off */
1351 r
= capability_set_from_string(rvalue
, &sum
);
1355 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse word: %s", rvalue
);
1359 if (sum
== 0 || *capability_set
== initial
)
1360 /* "", "~" or uninitialized data -> replace */
1361 *capability_set
= invert
? ~sum
: sum
;
1363 /* previous data -> merge */
1365 *capability_set
&= ~sum
;
1367 *capability_set
|= sum
;
1373 int config_parse_limit(
1375 const char *filename
,
1377 const char *section
,
1378 unsigned section_line
,
1385 struct rlimit
**rl
= data
, d
= {};
1393 r
= rlimit_parse(ltype
, rvalue
, &d
);
1395 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Soft resource limit chosen higher than hard limit, ignoring: %s", rvalue
);
1399 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse resource value, ignoring: %s", rvalue
);
1406 rl
[ltype
] = newdup(struct rlimit
, &d
, 1);
1414 #if HAVE_SYSV_COMPAT
1415 int config_parse_sysv_priority(const char *unit
,
1416 const char *filename
,
1418 const char *section
,
1419 unsigned section_line
,
1426 int *priority
= data
;
1434 r
= safe_atoi(rvalue
, &i
);
1435 if (r
< 0 || i
< 0) {
1436 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse SysV start priority, ignoring: %s", rvalue
);
1440 *priority
= (int) i
;
1445 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_utmp_mode
, exec_utmp_mode
, ExecUtmpMode
, "Failed to parse utmp mode");
1446 DEFINE_CONFIG_PARSE_ENUM(config_parse_kill_mode
, kill_mode
, KillMode
, "Failed to parse kill mode");
1448 int config_parse_exec_mount_flags(
1450 const char *filename
,
1452 const char *section
,
1453 unsigned section_line
,
1460 ExecContext
*c
= data
;
1468 r
= mount_propagation_flags_from_string(rvalue
, &c
->mount_flags
);
1470 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse mount flag %s, ignoring.", rvalue
);
1475 int config_parse_exec_selinux_context(
1477 const char *filename
,
1479 const char *section
,
1480 unsigned section_line
,
1487 ExecContext
*c
= data
;
1498 if (isempty(rvalue
)) {
1499 c
->selinux_context
= mfree(c
->selinux_context
);
1500 c
->selinux_context_ignore
= false;
1504 if (rvalue
[0] == '-') {
1510 r
= unit_full_printf(u
, rvalue
, &k
);
1512 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1513 "Failed to resolve specifiers%s: %m",
1514 ignore
? ", ignoring" : "");
1515 return ignore
? 0 : -ENOEXEC
;
1518 free(c
->selinux_context
);
1519 c
->selinux_context
= k
;
1520 c
->selinux_context_ignore
= ignore
;
1525 int config_parse_exec_apparmor_profile(
1527 const char *filename
,
1529 const char *section
,
1530 unsigned section_line
,
1537 ExecContext
*c
= data
;
1548 if (isempty(rvalue
)) {
1549 c
->apparmor_profile
= mfree(c
->apparmor_profile
);
1550 c
->apparmor_profile_ignore
= false;
1554 if (rvalue
[0] == '-') {
1560 r
= unit_full_printf(u
, rvalue
, &k
);
1562 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1563 "Failed to resolve specifiers%s: %m",
1564 ignore
? ", ignoring" : "");
1565 return ignore
? 0 : -ENOEXEC
;
1568 free(c
->apparmor_profile
);
1569 c
->apparmor_profile
= k
;
1570 c
->apparmor_profile_ignore
= ignore
;
1575 int config_parse_exec_smack_process_label(
1577 const char *filename
,
1579 const char *section
,
1580 unsigned section_line
,
1587 ExecContext
*c
= data
;
1598 if (isempty(rvalue
)) {
1599 c
->smack_process_label
= mfree(c
->smack_process_label
);
1600 c
->smack_process_label_ignore
= false;
1604 if (rvalue
[0] == '-') {
1610 r
= unit_full_printf(u
, rvalue
, &k
);
1612 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1613 "Failed to resolve specifiers%s: %m",
1614 ignore
? ", ignoring" : "");
1615 return ignore
? 0 : -ENOEXEC
;
1618 free(c
->smack_process_label
);
1619 c
->smack_process_label
= k
;
1620 c
->smack_process_label_ignore
= ignore
;
1625 int config_parse_timer(const char *unit
,
1626 const char *filename
,
1628 const char *section
,
1629 unsigned section_line
,
1640 _cleanup_(calendar_spec_freep
) CalendarSpec
*c
= NULL
;
1642 _cleanup_free_
char *k
= NULL
;
1650 if (isempty(rvalue
)) {
1651 /* Empty assignment resets list */
1652 timer_free_values(t
);
1656 b
= timer_base_from_string(lvalue
);
1658 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse timer base, ignoring: %s", lvalue
);
1662 r
= unit_full_printf(u
, rvalue
, &k
);
1664 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
1668 if (b
== TIMER_CALENDAR
) {
1669 if (calendar_spec_from_string(k
, &c
) < 0) {
1670 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse calendar specification, ignoring: %s", k
);
1674 if (parse_sec(k
, &usec
) < 0) {
1675 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse timer value, ignoring: %s", k
);
1680 v
= new0(TimerValue
, 1);
1686 v
->calendar_spec
= TAKE_PTR(c
);
1688 LIST_PREPEND(value
, t
->values
, v
);
1693 int config_parse_trigger_unit(
1695 const char *filename
,
1697 const char *section
,
1698 unsigned section_line
,
1705 _cleanup_free_
char *p
= NULL
;
1715 if (!hashmap_isempty(u
->dependencies
[UNIT_TRIGGERS
])) {
1716 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Multiple units to trigger specified, ignoring: %s", rvalue
);
1720 r
= unit_name_printf(u
, rvalue
, &p
);
1722 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve specifiers, ignoring: %m");
1726 type
= unit_name_to_type(p
);
1728 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit type not valid, ignoring: %s", rvalue
);
1731 if (unit_has_name(u
, p
)) {
1732 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Units cannot trigger themselves, ignoring: %s", rvalue
);
1736 r
= unit_add_two_dependencies_by_name(u
, UNIT_BEFORE
, UNIT_TRIGGERS
, p
, NULL
, true, UNIT_DEPENDENCY_FILE
);
1738 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add trigger on %s, ignoring: %m", p
);
1745 int config_parse_path_spec(const char *unit
,
1746 const char *filename
,
1748 const char *section
,
1749 unsigned section_line
,
1759 _cleanup_free_
char *k
= NULL
;
1767 if (isempty(rvalue
)) {
1768 /* Empty assignment clears list */
1773 b
= path_type_from_string(lvalue
);
1775 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse path type, ignoring: %s", lvalue
);
1779 r
= unit_full_printf(UNIT(p
), rvalue
, &k
);
1781 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers on %s. Ignoring.", rvalue
);
1785 if (!path_is_absolute(k
)) {
1786 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Path is not absolute, ignoring: %s", k
);
1790 s
= new0(PathSpec
, 1);
1795 s
->path
= path_kill_slashes(k
);
1800 LIST_PREPEND(spec
, p
->specs
, s
);
1805 int config_parse_socket_service(
1807 const char *filename
,
1809 const char *section
,
1810 unsigned section_line
,
1817 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1818 _cleanup_free_
char *p
= NULL
;
1828 r
= unit_name_printf(UNIT(s
), rvalue
, &p
);
1830 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve specifiers: %s", rvalue
);
1834 if (!endswith(p
, ".service")) {
1835 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit must be of type service: %s", rvalue
);
1839 r
= manager_load_unit(UNIT(s
)->manager
, p
, NULL
, &error
, &x
);
1841 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to load unit %s: %s", rvalue
, bus_error_message(&error
, r
));
1845 unit_ref_set(&s
->service
, UNIT(s
), x
);
1850 int config_parse_fdname(
1852 const char *filename
,
1854 const char *section
,
1855 unsigned section_line
,
1862 _cleanup_free_
char *p
= NULL
;
1871 if (isempty(rvalue
)) {
1872 s
->fdname
= mfree(s
->fdname
);
1876 r
= unit_full_printf(UNIT(s
), rvalue
, &p
);
1878 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve specifiers, ignoring: %s", rvalue
);
1882 if (!fdname_is_valid(p
)) {
1883 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", p
);
1887 return free_and_replace(s
->fdname
, p
);
1890 int config_parse_service_sockets(
1892 const char *filename
,
1894 const char *section
,
1895 unsigned section_line
,
1913 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
1915 r
= extract_first_word(&p
, &word
, NULL
, 0);
1921 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Trailing garbage in sockets, ignoring: %s", rvalue
);
1925 r
= unit_name_printf(UNIT(s
), word
, &k
);
1927 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve specifiers, ignoring: %m");
1931 if (!endswith(k
, ".socket")) {
1932 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit must be of type socket, ignoring: %s", k
);
1936 r
= unit_add_two_dependencies_by_name(UNIT(s
), UNIT_WANTS
, UNIT_AFTER
, k
, NULL
, true, UNIT_DEPENDENCY_FILE
);
1938 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
1940 r
= unit_add_dependency_by_name(UNIT(s
), UNIT_TRIGGERED_BY
, k
, NULL
, true, UNIT_DEPENDENCY_FILE
);
1942 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
1948 int config_parse_bus_name(
1950 const char *filename
,
1952 const char *section
,
1953 unsigned section_line
,
1960 _cleanup_free_
char *k
= NULL
;
1969 r
= unit_full_printf(u
, rvalue
, &k
);
1971 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers on %s, ignoring: %m", rvalue
);
1975 if (!service_name_is_valid(k
)) {
1976 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid bus name %s, ignoring.", k
);
1980 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
1983 int config_parse_service_timeout(
1985 const char *filename
,
1987 const char *section
,
1988 unsigned section_line
,
1995 Service
*s
= userdata
;
2004 /* This is called for three cases: TimeoutSec=, TimeoutStopSec= and TimeoutStartSec=. */
2006 r
= parse_sec(rvalue
, &usec
);
2008 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
2012 /* Traditionally, these options accepted 0 to disable the timeouts. However, a timeout of 0 suggests it happens
2013 * immediately, hence fix this to become USEC_INFINITY instead. This is in-line with how we internally handle
2014 * all other timeouts. */
2016 usec
= USEC_INFINITY
;
2018 if (!streq(lvalue
, "TimeoutStopSec")) {
2019 s
->start_timeout_defined
= true;
2020 s
->timeout_start_usec
= usec
;
2023 if (!streq(lvalue
, "TimeoutStartSec"))
2024 s
->timeout_stop_usec
= usec
;
2029 int config_parse_sec_fix_0(
2031 const char *filename
,
2033 const char *section
,
2034 unsigned section_line
,
2041 usec_t
*usec
= data
;
2049 /* This is pretty much like config_parse_sec(), except that this treats a time of 0 as infinity, for
2050 * compatibility with older versions of systemd where 0 instead of infinity was used as indicator to turn off a
2053 r
= parse_sec_fix_0(rvalue
, usec
);
2055 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
2062 int config_parse_user_group(
2064 const char *filename
,
2066 const char *section
,
2067 unsigned section_line
,
2074 char **user
= data
, *n
;
2083 if (isempty(rvalue
))
2086 _cleanup_free_
char *k
= NULL
;
2088 r
= unit_full_printf(u
, rvalue
, &k
);
2090 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", rvalue
);
2094 if (!valid_user_group_name_or_id(k
)) {
2095 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2108 int config_parse_user_group_strv(
2110 const char *filename
,
2112 const char *section
,
2113 unsigned section_line
,
2120 char ***users
= data
;
2130 if (isempty(rvalue
)) {
2131 *users
= strv_free(*users
);
2137 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2139 r
= extract_first_word(&p
, &word
, NULL
, 0);
2145 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax: %s", rvalue
);
2149 r
= unit_full_printf(u
, word
, &k
);
2151 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", word
);
2155 if (!valid_user_group_name_or_id(k
)) {
2156 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2160 r
= strv_push(users
, k
);
2170 int config_parse_working_directory(
2172 const char *filename
,
2174 const char *section
,
2175 unsigned section_line
,
2182 ExecContext
*c
= data
;
2193 if (rvalue
[0] == '-') {
2199 if (streq(rvalue
, "~")) {
2200 c
->working_directory_home
= true;
2201 c
->working_directory
= mfree(c
->working_directory
);
2203 _cleanup_free_
char *k
= NULL
;
2205 r
= unit_full_printf(u
, rvalue
, &k
);
2207 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2208 "Failed to resolve unit specifiers in working directory path '%s'%s: %m",
2209 rvalue
, missing_ok
? ", ignoring" : "");
2210 return missing_ok
? 0 : -ENOEXEC
;
2213 path_kill_slashes(k
);
2215 if (!utf8_is_valid(k
)) {
2216 log_syntax_invalid_utf8(unit
, LOG_ERR
, filename
, line
, rvalue
);
2217 return missing_ok
? 0 : -ENOEXEC
;
2220 if (!path_is_absolute(k
)) {
2221 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2222 "Working directory path '%s' is not absolute%s.",
2223 rvalue
, missing_ok
? ", ignoring" : "");
2224 return missing_ok
? 0 : -ENOEXEC
;
2227 c
->working_directory_home
= false;
2228 free_and_replace(c
->working_directory
, k
);
2231 c
->working_directory_missing_ok
= missing_ok
;
2235 int config_parse_unit_env_file(const char *unit
,
2236 const char *filename
,
2238 const char *section
,
2239 unsigned section_line
,
2248 _cleanup_free_
char *n
= NULL
;
2256 if (isempty(rvalue
)) {
2257 /* Empty assignment frees the list */
2258 *env
= strv_free(*env
);
2262 r
= unit_full_printf(u
, rvalue
, &n
);
2264 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve specifiers, ignoring: %s", rvalue
);
2268 if (!path_is_absolute(n
[0] == '-' ? n
+ 1 : n
)) {
2269 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Path '%s' is not absolute, ignoring.", n
);
2273 r
= strv_extend(env
, n
);
2280 int config_parse_environ(
2282 const char *filename
,
2284 const char *section
,
2285 unsigned section_line
,
2302 if (isempty(rvalue
)) {
2303 /* Empty assignment resets the list */
2304 *env
= strv_free(*env
);
2308 for (p
= rvalue
;; ) {
2309 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2311 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_QUOTES
);
2317 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2318 "Invalid syntax, ignoring: %s", rvalue
);
2323 r
= unit_full_printf(u
, word
, &k
);
2325 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2326 "Failed to resolve specifiers, ignoring: %s", word
);
2332 if (!env_assignment_is_valid(k
)) {
2333 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2334 "Invalid environment assignment, ignoring: %s", k
);
2338 r
= strv_env_replace(env
, k
);
2346 int config_parse_pass_environ(
2348 const char *filename
,
2350 const char *section
,
2351 unsigned section_line
,
2358 const char *whole_rvalue
= rvalue
;
2359 _cleanup_strv_free_
char **n
= NULL
;
2360 size_t nlen
= 0, nbufsize
= 0;
2361 char*** passenv
= data
;
2370 if (isempty(rvalue
)) {
2371 /* Empty assignment resets the list */
2372 *passenv
= strv_free(*passenv
);
2377 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2379 r
= extract_first_word(&rvalue
, &word
, NULL
, EXTRACT_QUOTES
);
2385 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2386 "Trailing garbage in %s, ignoring: %s", lvalue
, whole_rvalue
);
2391 r
= unit_full_printf(u
, word
, &k
);
2393 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2394 "Failed to resolve specifiers, ignoring: %s", word
);
2400 if (!env_name_is_valid(k
)) {
2401 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2402 "Invalid environment name for %s, ignoring: %s", lvalue
, k
);
2406 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
2409 n
[nlen
++] = TAKE_PTR(k
);
2414 r
= strv_extend_strv(passenv
, n
, true);
2422 int config_parse_unset_environ(
2424 const char *filename
,
2426 const char *section
,
2427 unsigned section_line
,
2434 _cleanup_strv_free_
char **n
= NULL
;
2435 const char *whole_rvalue
= rvalue
;
2436 size_t nlen
= 0, nbufsize
= 0;
2437 char*** unsetenv
= data
;
2446 if (isempty(rvalue
)) {
2447 /* Empty assignment resets the list */
2448 *unsetenv
= strv_free(*unsetenv
);
2453 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2455 r
= extract_first_word(&rvalue
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_QUOTES
);
2461 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2462 "Trailing garbage in %s, ignoring: %s", lvalue
, whole_rvalue
);
2467 r
= unit_full_printf(u
, word
, &k
);
2469 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2470 "Failed to resolve specifiers, ignoring: %s", word
);
2476 if (!env_assignment_is_valid(k
) && !env_name_is_valid(k
)) {
2477 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2478 "Invalid environment name or assignment %s, ignoring: %s", lvalue
, k
);
2482 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
2485 n
[nlen
++] = TAKE_PTR(k
);
2490 r
= strv_extend_strv(unsetenv
, n
, true);
2498 int config_parse_log_extra_fields(
2500 const char *filename
,
2502 const char *section
,
2503 unsigned section_line
,
2510 ExecContext
*c
= data
;
2520 if (isempty(rvalue
)) {
2521 exec_context_free_log_extra_fields(c
);
2525 for (p
= rvalue
;; ) {
2526 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2530 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_QUOTES
);
2536 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
2540 r
= unit_full_printf(u
, word
, &k
);
2542 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers on %s, ignoring field: %m", word
);
2546 eq
= strchr(k
, '=');
2548 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Log field lacks '=' character, ignoring field: %s", k
);
2552 if (!journal_field_valid(k
, eq
-k
, false)) {
2553 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Log field name is invalid, ignoring field: %s", k
);
2557 t
= reallocarray(c
->log_extra_fields
, c
->n_log_extra_fields
+1, sizeof(struct iovec
));
2561 c
->log_extra_fields
= t
;
2562 c
->log_extra_fields
[c
->n_log_extra_fields
++] = IOVEC_MAKE_STRING(k
);
2570 int config_parse_ip_tos(const char *unit
,
2571 const char *filename
,
2573 const char *section
,
2574 unsigned section_line
,
2581 int *ip_tos
= data
, x
;
2588 x
= ip_tos_from_string(rvalue
);
2590 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse IP TOS value, ignoring: %s", rvalue
);
2598 int config_parse_unit_condition_path(
2600 const char *filename
,
2602 const char *section
,
2603 unsigned section_line
,
2610 _cleanup_free_
char *p
= NULL
;
2611 Condition
**list
= data
, *c
;
2612 ConditionType t
= ltype
;
2613 bool trigger
, negate
;
2622 if (isempty(rvalue
)) {
2623 /* Empty assignment resets the list */
2624 *list
= condition_free_list(*list
);
2628 trigger
= rvalue
[0] == '|';
2632 negate
= rvalue
[0] == '!';
2636 r
= unit_full_printf(u
, rvalue
, &p
);
2638 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve specifiers, ignoring: %s", rvalue
);
2642 if (!path_is_absolute(p
)) {
2643 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Path in condition not absolute, ignoring: %s", p
);
2647 c
= condition_new(t
, p
, trigger
, negate
);
2651 LIST_PREPEND(conditions
, *list
, c
);
2655 int config_parse_unit_condition_string(
2657 const char *filename
,
2659 const char *section
,
2660 unsigned section_line
,
2667 _cleanup_free_
char *s
= NULL
;
2668 Condition
**list
= data
, *c
;
2669 ConditionType t
= ltype
;
2670 bool trigger
, negate
;
2679 if (isempty(rvalue
)) {
2680 /* Empty assignment resets the list */
2681 *list
= condition_free_list(*list
);
2685 trigger
= rvalue
[0] == '|';
2689 negate
= rvalue
[0] == '!';
2693 r
= unit_full_printf(u
, rvalue
, &s
);
2695 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve specifiers, ignoring: %s", rvalue
);
2699 c
= condition_new(t
, s
, trigger
, negate
);
2703 LIST_PREPEND(conditions
, *list
, c
);
2707 int config_parse_unit_condition_null(
2709 const char *filename
,
2711 const char *section
,
2712 unsigned section_line
,
2719 Condition
**list
= data
, *c
;
2720 bool trigger
, negate
;
2728 if (isempty(rvalue
)) {
2729 /* Empty assignment resets the list */
2730 *list
= condition_free_list(*list
);
2734 trigger
= rvalue
[0] == '|';
2738 negate
= rvalue
[0] == '!';
2742 b
= parse_boolean(rvalue
);
2744 log_syntax(unit
, LOG_ERR
, filename
, line
, b
, "Failed to parse boolean value in condition, ignoring: %s", rvalue
);
2751 c
= condition_new(CONDITION_NULL
, NULL
, trigger
, negate
);
2755 LIST_PREPEND(conditions
, *list
, c
);
2759 DEFINE_CONFIG_PARSE_ENUM(config_parse_notify_access
, notify_access
, NotifyAccess
, "Failed to parse notify access specifier");
2760 DEFINE_CONFIG_PARSE_ENUM(config_parse_emergency_action
, emergency_action
, EmergencyAction
, "Failed to parse failure action specifier");
2762 int config_parse_unit_requires_mounts_for(
2764 const char *filename
,
2766 const char *section
,
2767 unsigned section_line
,
2783 for (p
= rvalue
;; ) {
2784 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
2786 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
2792 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2793 "Invalid syntax, ignoring: %s", rvalue
);
2797 if (!utf8_is_valid(word
)) {
2798 log_syntax_invalid_utf8(unit
, LOG_ERR
, filename
, line
, rvalue
);
2802 r
= unit_full_printf(u
, word
, &resolved
);
2804 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit name \"%s\", ignoring: %m", word
);
2808 r
= unit_require_mounts_for(u
, resolved
, UNIT_DEPENDENCY_FILE
);
2810 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add required mount \"%s\", ignoring: %m", resolved
);
2816 int config_parse_documentation(const char *unit
,
2817 const char *filename
,
2819 const char *section
,
2820 unsigned section_line
,
2836 if (isempty(rvalue
)) {
2837 /* Empty assignment resets the list */
2838 u
->documentation
= strv_free(u
->documentation
);
2842 r
= config_parse_unit_strv_printf(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
,
2843 rvalue
, data
, userdata
);
2847 for (a
= b
= u
->documentation
; a
&& *a
; a
++) {
2849 if (documentation_url_is_valid(*a
))
2852 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid URL, ignoring: %s", *a
);
2863 int config_parse_syscall_filter(
2865 const char *filename
,
2867 const char *section
,
2868 unsigned section_line
,
2875 ExecContext
*c
= data
;
2877 bool invert
= false;
2886 if (isempty(rvalue
)) {
2887 /* Empty assignment resets the list */
2888 c
->syscall_filter
= hashmap_free(c
->syscall_filter
);
2889 c
->syscall_whitelist
= false;
2893 if (rvalue
[0] == '~') {
2898 if (!c
->syscall_filter
) {
2899 c
->syscall_filter
= hashmap_new(NULL
);
2900 if (!c
->syscall_filter
)
2904 /* Allow everything but the ones listed */
2905 c
->syscall_whitelist
= false;
2907 /* Allow nothing but the ones listed */
2908 c
->syscall_whitelist
= true;
2910 /* Accept default syscalls if we are on a whitelist */
2911 r
= seccomp_parse_syscall_filter("@default", -1, c
->syscall_filter
, SECCOMP_PARSE_WHITELIST
);
2919 _cleanup_free_
char *word
= NULL
, *name
= NULL
;
2922 r
= extract_first_word(&p
, &word
, NULL
, 0);
2928 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
2932 r
= parse_syscall_and_errno(word
, &name
, &num
);
2934 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse syscall:errno, ignoring: %s", word
);
2938 r
= seccomp_parse_syscall_filter_full(name
, num
, c
->syscall_filter
,
2939 SECCOMP_PARSE_LOG
|SECCOMP_PARSE_PERMISSIVE
|(invert
? SECCOMP_PARSE_INVERT
: 0)|(c
->syscall_whitelist
? SECCOMP_PARSE_WHITELIST
: 0),
2940 unit
, filename
, line
);
2948 int config_parse_syscall_archs(
2950 const char *filename
,
2952 const char *section
,
2953 unsigned section_line
,
2964 if (isempty(rvalue
)) {
2965 *archs
= set_free(*archs
);
2969 r
= set_ensure_allocated(archs
, NULL
);
2973 for (p
= rvalue
;;) {
2974 _cleanup_free_
char *word
= NULL
;
2977 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
2983 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2984 "Invalid syntax, ignoring: %s", rvalue
);
2988 r
= seccomp_arch_from_string(word
, &a
);
2990 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2991 "Failed to parse system call architecture \"%s\", ignoring: %m", word
);
2995 r
= set_put(*archs
, UINT32_TO_PTR(a
+ 1));
3001 int config_parse_syscall_errno(
3003 const char *filename
,
3005 const char *section
,
3006 unsigned section_line
,
3013 ExecContext
*c
= data
;
3020 if (isempty(rvalue
)) {
3021 /* Empty assignment resets to KILL */
3022 c
->syscall_errno
= 0;
3026 e
= parse_errno(rvalue
);
3028 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse error number, ignoring: %s", rvalue
);
3032 c
->syscall_errno
= e
;
3036 int config_parse_address_families(
3038 const char *filename
,
3040 const char *section
,
3041 unsigned section_line
,
3048 ExecContext
*c
= data
;
3049 bool invert
= false;
3057 if (isempty(rvalue
)) {
3058 /* Empty assignment resets the list */
3059 c
->address_families
= set_free(c
->address_families
);
3060 c
->address_families_whitelist
= false;
3064 if (rvalue
[0] == '~') {
3069 if (!c
->address_families
) {
3070 c
->address_families
= set_new(NULL
);
3071 if (!c
->address_families
)
3074 c
->address_families_whitelist
= !invert
;
3077 for (p
= rvalue
;;) {
3078 _cleanup_free_
char *word
= NULL
;
3081 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
3087 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3088 "Invalid syntax, ignoring: %s", rvalue
);
3092 af
= af_from_name(word
);
3094 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
3095 "Failed to parse address family \"%s\", ignoring: %m", word
);
3099 /* If we previously wanted to forbid an address family and now
3100 * we want to allow it, then just remove it from the list.
3102 if (!invert
== c
->address_families_whitelist
) {
3103 r
= set_put(c
->address_families
, INT_TO_PTR(af
));
3107 set_remove(c
->address_families
, INT_TO_PTR(af
));
3111 int config_parse_restrict_namespaces(
3113 const char *filename
,
3115 const char *section
,
3116 unsigned section_line
,
3123 ExecContext
*c
= data
;
3124 bool invert
= false;
3127 if (isempty(rvalue
)) {
3128 /* Reset to the default. */
3129 c
->restrict_namespaces
= NAMESPACE_FLAGS_ALL
;
3133 if (rvalue
[0] == '~') {
3138 r
= parse_boolean(rvalue
);
3140 c
->restrict_namespaces
= 0;
3142 c
->restrict_namespaces
= NAMESPACE_FLAGS_ALL
;
3144 /* Not a boolean argument, in this case it's a list of namespace types. */
3146 r
= namespace_flag_from_string_many(rvalue
, &c
->restrict_namespaces
);
3148 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse namespace type string, ignoring: %s", rvalue
);
3154 c
->restrict_namespaces
= (~c
->restrict_namespaces
) & NAMESPACE_FLAGS_ALL
;
3160 int config_parse_unit_slice(
3162 const char *filename
,
3164 const char *section
,
3165 unsigned section_line
,
3172 _cleanup_free_
char *k
= NULL
;
3173 Unit
*u
= userdata
, *slice
= NULL
;
3181 r
= unit_name_printf(u
, rvalue
, &k
);
3183 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers on %s. Ignoring.", rvalue
);
3187 r
= manager_load_unit(u
->manager
, k
, NULL
, NULL
, &slice
);
3189 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to load slice unit %s. Ignoring.", k
);
3193 r
= unit_set_slice(u
, slice
);
3195 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to assign slice %s to unit %s. Ignoring.", slice
->id
, u
->id
);
3202 DEFINE_CONFIG_PARSE_ENUM(config_parse_device_policy
, cgroup_device_policy
, CGroupDevicePolicy
, "Failed to parse device policy");
3204 int config_parse_cpu_weight(
3206 const char *filename
,
3208 const char *section
,
3209 unsigned section_line
,
3216 uint64_t *weight
= data
;
3223 r
= cg_weight_parse(rvalue
, weight
);
3225 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "CPU weight '%s' invalid. Ignoring.", rvalue
);
3232 int config_parse_cpu_shares(
3234 const char *filename
,
3236 const char *section
,
3237 unsigned section_line
,
3244 uint64_t *shares
= data
;
3251 r
= cg_cpu_shares_parse(rvalue
, shares
);
3253 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "CPU shares '%s' invalid. Ignoring.", rvalue
);
3260 int config_parse_cpu_quota(
3262 const char *filename
,
3264 const char *section
,
3265 unsigned section_line
,
3272 CGroupContext
*c
= data
;
3279 if (isempty(rvalue
)) {
3280 c
->cpu_quota_per_sec_usec
= USEC_INFINITY
;
3284 r
= parse_percent_unbounded(rvalue
);
3286 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "CPU quota '%s' invalid. Ignoring.", rvalue
);
3290 c
->cpu_quota_per_sec_usec
= ((usec_t
) r
* USEC_PER_SEC
) / 100U;
3294 int config_parse_memory_limit(
3296 const char *filename
,
3298 const char *section
,
3299 unsigned section_line
,
3306 CGroupContext
*c
= data
;
3307 uint64_t bytes
= CGROUP_LIMIT_MAX
;
3310 if (!isempty(rvalue
) && !streq(rvalue
, "infinity")) {
3312 r
= parse_percent(rvalue
);
3314 r
= parse_size(rvalue
, 1024, &bytes
);
3316 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Memory limit '%s' invalid. Ignoring.", rvalue
);
3320 bytes
= physical_memory_scale(r
, 100U);
3322 if (bytes
>= UINT64_MAX
||
3323 (bytes
<= 0 && !streq(lvalue
, "MemorySwapMax"))) {
3324 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Memory limit '%s' out of range. Ignoring.", rvalue
);
3329 if (streq(lvalue
, "MemoryLow"))
3330 c
->memory_low
= bytes
;
3331 else if (streq(lvalue
, "MemoryHigh"))
3332 c
->memory_high
= bytes
;
3333 else if (streq(lvalue
, "MemoryMax"))
3334 c
->memory_max
= bytes
;
3335 else if (streq(lvalue
, "MemorySwapMax"))
3336 c
->memory_swap_max
= bytes
;
3337 else if (streq(lvalue
, "MemoryLimit"))
3338 c
->memory_limit
= bytes
;
3345 int config_parse_tasks_max(
3347 const char *filename
,
3349 const char *section
,
3350 unsigned section_line
,
3357 uint64_t *tasks_max
= data
, v
;
3361 if (isempty(rvalue
)) {
3362 *tasks_max
= u
->manager
->default_tasks_max
;
3366 if (streq(rvalue
, "infinity")) {
3367 *tasks_max
= CGROUP_LIMIT_MAX
;
3371 r
= parse_percent(rvalue
);
3373 r
= safe_atou64(rvalue
, &v
);
3375 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Maximum tasks value '%s' invalid. Ignoring.", rvalue
);
3379 v
= system_tasks_max_scale(r
, 100U);
3381 if (v
<= 0 || v
>= UINT64_MAX
) {
3382 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Maximum tasks value '%s' out of range. Ignoring.", rvalue
);
3390 int config_parse_delegate(
3392 const char *filename
,
3394 const char *section
,
3395 unsigned section_line
,
3402 CGroupContext
*c
= data
;
3406 t
= unit_name_to_type(unit
);
3407 assert(t
!= _UNIT_TYPE_INVALID
);
3409 if (!unit_vtable
[t
]->can_delegate
) {
3410 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Delegate= setting not supported for this unit type, ignoring.");
3414 /* We either accept a boolean value, which may be used to turn on delegation for all controllers, or turn it
3415 * off for all. Or it takes a list of controller names, in which case we add the specified controllers to the
3416 * mask to delegate. */
3418 if (isempty(rvalue
)) {
3419 /* An empty string resets controllers and set Delegate=yes. */
3421 c
->delegate_controllers
= 0;
3425 r
= parse_boolean(rvalue
);
3427 const char *p
= rvalue
;
3428 CGroupMask mask
= 0;
3431 _cleanup_free_
char *word
= NULL
;
3432 CGroupController cc
;
3434 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
3440 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3444 cc
= cgroup_controller_from_string(word
);
3446 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid controller name '%s', ignoring", rvalue
);
3450 mask
|= CGROUP_CONTROLLER_TO_MASK(cc
);
3454 c
->delegate_controllers
|= mask
;
3458 c
->delegate_controllers
= _CGROUP_MASK_ALL
;
3460 c
->delegate
= false;
3461 c
->delegate_controllers
= 0;
3467 int config_parse_device_allow(
3469 const char *filename
,
3471 const char *section
,
3472 unsigned section_line
,
3479 _cleanup_free_
char *path
= NULL
, *t
= NULL
;
3480 CGroupContext
*c
= data
;
3481 CGroupDeviceAllow
*a
;
3482 const char *m
= NULL
;
3486 if (isempty(rvalue
)) {
3487 while (c
->device_allow
)
3488 cgroup_context_free_device_allow(c
, c
->device_allow
);
3493 r
= unit_full_printf(userdata
, rvalue
, &t
);
3495 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3496 "Failed to resolve specifiers in %s, ignoring: %m",
3501 n
= strcspn(t
, WHITESPACE
);
3503 path
= strndup(t
, n
);
3507 if (!is_deviceallow_pattern(path
) &&
3508 !path_startswith(path
, "/run/systemd/inaccessible/")) {
3509 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device node path '%s'. Ignoring.", path
);
3513 m
= t
+ n
+ strspn(t
+ n
, WHITESPACE
);
3517 if (!in_charset(m
, "rwm")) {
3518 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device rights '%s'. Ignoring.", m
);
3522 a
= new0(CGroupDeviceAllow
, 1);
3526 a
->path
= TAKE_PTR(path
);
3527 a
->r
= !!strchr(m
, 'r');
3528 a
->w
= !!strchr(m
, 'w');
3529 a
->m
= !!strchr(m
, 'm');
3531 LIST_PREPEND(device_allow
, c
->device_allow
, a
);
3535 int config_parse_io_weight(
3537 const char *filename
,
3539 const char *section
,
3540 unsigned section_line
,
3547 uint64_t *weight
= data
;
3554 r
= cg_weight_parse(rvalue
, weight
);
3556 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "IO weight '%s' invalid. Ignoring.", rvalue
);
3563 int config_parse_io_device_weight(
3565 const char *filename
,
3567 const char *section
,
3568 unsigned section_line
,
3575 _cleanup_free_
char *path
= NULL
;
3576 CGroupIODeviceWeight
*w
;
3577 CGroupContext
*c
= data
;
3587 if (isempty(rvalue
)) {
3588 while (c
->io_device_weights
)
3589 cgroup_context_free_io_device_weight(c
, c
->io_device_weights
);
3594 n
= strcspn(rvalue
, WHITESPACE
);
3595 weight
= rvalue
+ n
;
3596 weight
+= strspn(weight
, WHITESPACE
);
3598 if (isempty(weight
)) {
3599 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Expected block device and device weight. Ignoring.");
3603 path
= strndup(rvalue
, n
);
3607 if (!path_startswith(path
, "/dev") &&
3608 !path_startswith(path
, "/run/systemd/inaccessible/")) {
3609 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device node path '%s'. Ignoring.", path
);
3613 r
= cg_weight_parse(weight
, &u
);
3615 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "IO weight '%s' invalid. Ignoring.", weight
);
3619 assert(u
!= CGROUP_WEIGHT_INVALID
);
3621 w
= new0(CGroupIODeviceWeight
, 1);
3625 w
->path
= TAKE_PTR(path
);
3629 LIST_PREPEND(device_weights
, c
->io_device_weights
, w
);
3633 int config_parse_io_limit(
3635 const char *filename
,
3637 const char *section
,
3638 unsigned section_line
,
3645 _cleanup_free_
char *path
= NULL
;
3646 CGroupIODeviceLimit
*l
= NULL
, *t
;
3647 CGroupContext
*c
= data
;
3648 CGroupIOLimitType type
;
3658 type
= cgroup_io_limit_type_from_string(lvalue
);
3661 if (isempty(rvalue
)) {
3662 LIST_FOREACH(device_limits
, l
, c
->io_device_limits
)
3663 l
->limits
[type
] = cgroup_io_limit_defaults
[type
];
3667 n
= strcspn(rvalue
, WHITESPACE
);
3669 limit
+= strspn(limit
, WHITESPACE
);
3672 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Expected space separated pair of device node and bandwidth. Ignoring.");
3676 path
= strndup(rvalue
, n
);
3680 if (!path_startswith(path
, "/dev") &&
3681 !path_startswith(path
, "/run/systemd/inaccessible/")) {
3682 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device node path '%s'. Ignoring.", path
);
3686 if (streq("infinity", limit
)) {
3687 num
= CGROUP_LIMIT_MAX
;
3689 r
= parse_size(limit
, 1000, &num
);
3690 if (r
< 0 || num
<= 0) {
3691 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "IO Limit '%s' invalid. Ignoring.", rvalue
);
3696 LIST_FOREACH(device_limits
, t
, c
->io_device_limits
) {
3697 if (path_equal(path
, t
->path
)) {
3704 CGroupIOLimitType ttype
;
3706 l
= new0(CGroupIODeviceLimit
, 1);
3710 l
->path
= TAKE_PTR(path
);
3711 for (ttype
= 0; ttype
< _CGROUP_IO_LIMIT_TYPE_MAX
; ttype
++)
3712 l
->limits
[ttype
] = cgroup_io_limit_defaults
[ttype
];
3714 LIST_PREPEND(device_limits
, c
->io_device_limits
, l
);
3717 l
->limits
[type
] = num
;
3722 int config_parse_blockio_weight(
3724 const char *filename
,
3726 const char *section
,
3727 unsigned section_line
,
3734 uint64_t *weight
= data
;
3741 r
= cg_blkio_weight_parse(rvalue
, weight
);
3743 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Block IO weight '%s' invalid. Ignoring.", rvalue
);
3750 int config_parse_blockio_device_weight(
3752 const char *filename
,
3754 const char *section
,
3755 unsigned section_line
,
3762 _cleanup_free_
char *path
= NULL
;
3763 CGroupBlockIODeviceWeight
*w
;
3764 CGroupContext
*c
= data
;
3774 if (isempty(rvalue
)) {
3775 while (c
->blockio_device_weights
)
3776 cgroup_context_free_blockio_device_weight(c
, c
->blockio_device_weights
);
3781 n
= strcspn(rvalue
, WHITESPACE
);
3782 weight
= rvalue
+ n
;
3783 weight
+= strspn(weight
, WHITESPACE
);
3785 if (isempty(weight
)) {
3786 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Expected block device and device weight. Ignoring.");
3790 path
= strndup(rvalue
, n
);
3794 if (!path_startswith(path
, "/dev") &&
3795 !path_startswith(path
, "/run/systemd/inaccessible/")) {
3796 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device node path '%s'. Ignoring.", path
);
3800 r
= cg_blkio_weight_parse(weight
, &u
);
3802 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Block IO weight '%s' invalid. Ignoring.", weight
);
3806 assert(u
!= CGROUP_BLKIO_WEIGHT_INVALID
);
3808 w
= new0(CGroupBlockIODeviceWeight
, 1);
3812 w
->path
= TAKE_PTR(path
);
3816 LIST_PREPEND(device_weights
, c
->blockio_device_weights
, w
);
3820 int config_parse_blockio_bandwidth(
3822 const char *filename
,
3824 const char *section
,
3825 unsigned section_line
,
3832 _cleanup_free_
char *path
= NULL
;
3833 CGroupBlockIODeviceBandwidth
*b
= NULL
, *t
;
3834 CGroupContext
*c
= data
;
3835 const char *bandwidth
;
3845 read
= streq("BlockIOReadBandwidth", lvalue
);
3847 if (isempty(rvalue
)) {
3848 LIST_FOREACH(device_bandwidths
, b
, c
->blockio_device_bandwidths
) {
3849 b
->rbps
= CGROUP_LIMIT_MAX
;
3850 b
->wbps
= CGROUP_LIMIT_MAX
;
3855 n
= strcspn(rvalue
, WHITESPACE
);
3856 bandwidth
= rvalue
+ n
;
3857 bandwidth
+= strspn(bandwidth
, WHITESPACE
);
3860 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Expected space separated pair of device node and bandwidth. Ignoring.");
3864 path
= strndup(rvalue
, n
);
3868 if (!path_startswith(path
, "/dev") &&
3869 !path_startswith(path
, "/run/systemd/inaccessible/")) {
3870 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device node path '%s'. Ignoring.", path
);
3874 r
= parse_size(bandwidth
, 1000, &bytes
);
3875 if (r
< 0 || bytes
<= 0) {
3876 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Block IO Bandwidth '%s' invalid. Ignoring.", rvalue
);
3880 LIST_FOREACH(device_bandwidths
, t
, c
->blockio_device_bandwidths
) {
3881 if (path_equal(path
, t
->path
)) {
3888 b
= new0(CGroupBlockIODeviceBandwidth
, 1);
3892 b
->path
= TAKE_PTR(path
);
3893 b
->rbps
= CGROUP_LIMIT_MAX
;
3894 b
->wbps
= CGROUP_LIMIT_MAX
;
3896 LIST_PREPEND(device_bandwidths
, c
->blockio_device_bandwidths
, b
);
3907 DEFINE_CONFIG_PARSE_ENUM(config_parse_job_mode
, job_mode
, JobMode
, "Failed to parse job mode");
3909 int config_parse_job_mode_isolate(
3911 const char *filename
,
3913 const char *section
,
3914 unsigned section_line
,
3928 r
= parse_boolean(rvalue
);
3930 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse boolean, ignoring: %s", rvalue
);
3934 log_notice("%s is deprecated. Please use OnFailureJobMode= instead", lvalue
);
3936 *m
= r
? JOB_ISOLATE
: JOB_REPLACE
;
3940 DEFINE_CONFIG_PARSE_ENUM(config_parse_runtime_preserve_mode
, exec_preserve_mode
, ExecPreserveMode
, "Failed to parse runtime directory preserve mode");
3942 int config_parse_exec_directories(
3944 const char *filename
,
3946 const char *section
,
3947 unsigned section_line
,
3964 if (isempty(rvalue
)) {
3965 /* Empty assignment resets the list */
3966 *rt
= strv_free(*rt
);
3970 for (p
= rvalue
;;) {
3971 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
3973 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
3977 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3978 "Invalid syntax, ignoring: %s", rvalue
);
3984 r
= unit_full_printf(u
, word
, &k
);
3986 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
3987 "Failed to resolve specifiers in \"%s\", ignoring: %m", word
);
3991 if (!path_is_normalized(k
) || path_is_absolute(k
)) {
3992 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
3993 "%s= path is not valid, ignoring assignment: %s", lvalue
, rvalue
);
3997 r
= strv_push(rt
, k
);
4004 int config_parse_set_status(
4006 const char *filename
,
4008 const char *section
,
4009 unsigned section_line
,
4017 const char *word
, *state
;
4019 ExitStatusSet
*status_set
= data
;
4026 /* Empty assignment resets the list */
4027 if (isempty(rvalue
)) {
4028 exit_status_set_free(status_set
);
4032 FOREACH_WORD(word
, l
, rvalue
, state
) {
4033 _cleanup_free_
char *temp
;
4037 temp
= strndup(word
, l
);
4041 r
= safe_atoi(temp
, &val
);
4043 val
= signal_from_string(temp
);
4046 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse value, ignoring: %s", word
);
4049 set
= &status_set
->signal
;
4051 if (val
< 0 || val
> 255) {
4052 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Value %d is outside range 0-255, ignoring", val
);
4055 set
= &status_set
->status
;
4058 r
= set_ensure_allocated(set
, NULL
);
4062 r
= set_put(*set
, INT_TO_PTR(val
));
4064 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Unable to store: %s", word
);
4068 if (!isempty(state
))
4069 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Trailing garbage, ignoring.");
4074 int config_parse_namespace_path_strv(
4076 const char *filename
,
4078 const char *section
,
4079 unsigned section_line
,
4096 if (isempty(rvalue
)) {
4097 /* Empty assignment resets the list */
4098 *sv
= strv_free(*sv
);
4104 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
, *joined
= NULL
;
4106 bool ignore_enoent
= false, shall_prefix
= false;
4108 r
= extract_first_word(&cur
, &word
, NULL
, EXTRACT_QUOTES
);
4114 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
4118 if (!utf8_is_valid(word
)) {
4119 log_syntax_invalid_utf8(unit
, LOG_ERR
, filename
, line
, word
);
4124 if (startswith(w
, "-")) {
4125 ignore_enoent
= true;
4128 if (startswith(w
, "+")) {
4129 shall_prefix
= true;
4133 r
= unit_full_printf(u
, w
, &resolved
);
4135 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve specifiers in %s: %m", word
);
4139 if (!path_is_absolute(resolved
)) {
4140 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Not an absolute path, ignoring: %s", resolved
);
4144 path_kill_slashes(resolved
);
4146 joined
= strjoin(ignore_enoent
? "-" : "",
4147 shall_prefix
? "+" : "",
4150 r
= strv_push(sv
, joined
);
4160 int config_parse_temporary_filesystems(
4162 const char *filename
,
4164 const char *section
,
4165 unsigned section_line
,
4173 ExecContext
*c
= data
;
4182 if (isempty(rvalue
)) {
4183 /* Empty assignment resets the list */
4184 temporary_filesystem_free_many(c
->temporary_filesystems
, c
->n_temporary_filesystems
);
4185 c
->temporary_filesystems
= NULL
;
4186 c
->n_temporary_filesystems
= 0;
4192 _cleanup_free_
char *word
= NULL
, *path
= NULL
, *resolved
= NULL
;
4195 r
= extract_first_word(&cur
, &word
, NULL
, EXTRACT_QUOTES
);
4201 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
4206 r
= extract_first_word(&w
, &path
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4212 r
= unit_full_printf(u
, path
, &resolved
);
4214 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve specifiers in %s, ignoring: %m", word
);
4218 if (!path_is_absolute(resolved
)) {
4219 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Not an absolute path, ignoring: %s", resolved
);
4223 path_kill_slashes(resolved
);
4225 r
= temporary_filesystem_add(&c
->temporary_filesystems
, &c
->n_temporary_filesystems
, path
, w
);
4229 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse mount options, ignoring: %s", word
);
4237 int config_parse_bind_paths(
4239 const char *filename
,
4241 const char *section
,
4242 unsigned section_line
,
4249 ExecContext
*c
= data
;
4259 if (isempty(rvalue
)) {
4260 /* Empty assignment resets the list */
4261 bind_mount_free_many(c
->bind_mounts
, c
->n_bind_mounts
);
4262 c
->bind_mounts
= NULL
;
4263 c
->n_bind_mounts
= 0;
4269 _cleanup_free_
char *source
= NULL
, *destination
= NULL
;
4270 _cleanup_free_
char *sresolved
= NULL
, *dresolved
= NULL
;
4271 char *s
= NULL
, *d
= NULL
;
4272 bool rbind
= true, ignore_enoent
= false;
4274 r
= extract_first_word(&p
, &source
, ":" WHITESPACE
, EXTRACT_QUOTES
|EXTRACT_DONT_COALESCE_SEPARATORS
);
4280 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s: %s", lvalue
, rvalue
);
4284 r
= unit_full_printf(u
, source
, &sresolved
);
4286 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4287 "Failed to resolved specifiers in \"%s\", ignoring: %m", source
);
4293 ignore_enoent
= true;
4297 if (!utf8_is_valid(s
)) {
4298 log_syntax_invalid_utf8(unit
, LOG_ERR
, filename
, line
, s
);
4301 if (!path_is_absolute(s
)) {
4302 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Not an absolute source path, ignoring: %s", s
);
4306 path_kill_slashes(s
);
4308 /* Optionally, the destination is specified. */
4309 if (p
&& p
[-1] == ':') {
4310 r
= extract_first_word(&p
, &destination
, ":" WHITESPACE
, EXTRACT_QUOTES
|EXTRACT_DONT_COALESCE_SEPARATORS
);
4314 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s: %s", lvalue
, rvalue
);
4318 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Missing argument after ':': %s", rvalue
);
4322 r
= unit_full_printf(u
, destination
, &dresolved
);
4324 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4325 "Failed to resolved specifiers in \"%s\", ignoring: %m", destination
);
4329 if (!utf8_is_valid(dresolved
)) {
4330 log_syntax_invalid_utf8(unit
, LOG_ERR
, filename
, line
, dresolved
);
4333 if (!path_is_absolute(dresolved
)) {
4334 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Not an absolute destination path, ignoring: %s", dresolved
);
4338 d
= path_kill_slashes(dresolved
);
4340 /* Optionally, there's also a short option string specified */
4341 if (p
&& p
[-1] == ':') {
4342 _cleanup_free_
char *options
= NULL
;
4344 r
= extract_first_word(&p
, &options
, NULL
, EXTRACT_QUOTES
);
4348 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s: %s", lvalue
, rvalue
);
4352 if (isempty(options
) || streq(options
, "rbind"))
4354 else if (streq(options
, "norbind"))
4357 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid option string, ignoring setting: %s", options
);
4364 r
= bind_mount_add(&c
->bind_mounts
, &c
->n_bind_mounts
,
4368 .read_only
= !!strstr(lvalue
, "ReadOnly"),
4370 .ignore_enoent
= ignore_enoent
,
4379 int config_parse_no_new_privileges(
4381 const char *filename
,
4383 const char *section
,
4384 unsigned section_line
,
4391 ExecContext
*c
= data
;
4399 k
= parse_boolean(rvalue
);
4401 log_syntax(unit
, LOG_ERR
, filename
, line
, k
, "Failed to parse boolean value, ignoring: %s", rvalue
);
4405 c
->no_new_privileges
= k
;
4410 int config_parse_protect_home(
4412 const char *filename
,
4414 const char *section
,
4415 unsigned section_line
,
4422 ExecContext
*c
= data
;
4430 /* Our enum shall be a superset of booleans, hence first try
4431 * to parse as boolean, and then as enum */
4433 h
= parse_protect_home_or_bool(rvalue
);
4435 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse protect home value, ignoring: %s", rvalue
);
4439 c
->protect_home
= h
;
4444 int config_parse_protect_system(
4446 const char *filename
,
4448 const char *section
,
4449 unsigned section_line
,
4456 ExecContext
*c
= data
;
4464 /* Our enum shall be a superset of booleans, hence first try
4465 * to parse as boolean, and then as enum */
4467 s
= parse_protect_system_or_bool(rvalue
);
4469 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse protect system value, ignoring: %s", rvalue
);
4473 c
->protect_system
= s
;
4478 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_keyring_mode
, exec_keyring_mode
, ExecKeyringMode
, "Failed to parse keyring mode");
4480 int config_parse_job_timeout_sec(
4482 const char *filename
,
4484 const char *section
,
4485 unsigned section_line
,
4501 r
= parse_sec_fix_0(rvalue
, &usec
);
4503 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse JobTimeoutSec= parameter, ignoring: %s", rvalue
);
4507 /* If the user explicitly changed JobTimeoutSec= also change JobRunningTimeoutSec=, for compatibility with old
4508 * versions. If JobRunningTimeoutSec= was explicitly set, avoid this however as whatever the user picked should
4511 if (!u
->job_running_timeout_set
)
4512 u
->job_running_timeout
= usec
;
4514 u
->job_timeout
= usec
;
4519 int config_parse_job_running_timeout_sec(
4521 const char *filename
,
4523 const char *section
,
4524 unsigned section_line
,
4540 r
= parse_sec_fix_0(rvalue
, &usec
);
4542 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse JobRunningTimeoutSec= parameter, ignoring: %s", rvalue
);
4546 u
->job_running_timeout
= usec
;
4547 u
->job_running_timeout_set
= true;
4552 #define FOLLOW_MAX 8
4554 static int open_follow(char **filename
, FILE **_f
, Set
*names
, char **_final
) {
4565 /* This will update the filename pointer if the loaded file is
4566 * reached by a symlink. The old string will be freed. */
4569 char *target
, *name
;
4571 if (c
++ >= FOLLOW_MAX
)
4574 path_kill_slashes(*filename
);
4576 /* Add the file name we are currently looking at to
4577 * the names of this unit, but only if it is a valid
4579 name
= basename(*filename
);
4580 if (unit_name_is_valid(name
, UNIT_NAME_ANY
)) {
4582 id
= set_get(names
, name
);
4588 r
= set_consume(names
, id
);
4594 /* Try to open the file name, but don't if its a symlink */
4595 fd
= open(*filename
, O_RDONLY
|O_CLOEXEC
|O_NOCTTY
|O_NOFOLLOW
);
4602 /* Hmm, so this is a symlink. Let's read the name, and follow it manually */
4603 r
= readlink_and_make_absolute(*filename
, &target
);
4611 f
= fdopen(fd
, "re");
4623 static int merge_by_names(Unit
**u
, Set
*names
, const char *id
) {
4631 /* Let's try to add in all symlink names we found */
4632 while ((k
= set_steal_first(names
))) {
4634 /* First try to merge in the other name into our
4636 r
= unit_merge_by_name(*u
, k
);
4640 /* Hmm, we couldn't merge the other unit into
4641 * ours? Then let's try it the other way
4644 /* If the symlink name we are looking at is unit template, then
4645 we must search for instance of this template */
4646 if (unit_name_is_valid(k
, UNIT_NAME_TEMPLATE
) && (*u
)->instance
) {
4647 _cleanup_free_
char *instance
= NULL
;
4649 r
= unit_name_replace_instance(k
, (*u
)->instance
, &instance
);
4653 other
= manager_get_unit((*u
)->manager
, instance
);
4655 other
= manager_get_unit((*u
)->manager
, k
);
4660 r
= unit_merge(other
, *u
);
4663 return merge_by_names(u
, names
, NULL
);
4671 unit_choose_id(*u
, id
);
4679 static int load_from_path(Unit
*u
, const char *path
) {
4680 _cleanup_set_free_free_ Set
*symlink_names
= NULL
;
4681 _cleanup_fclose_
FILE *f
= NULL
;
4682 _cleanup_free_
char *filename
= NULL
;
4691 symlink_names
= set_new(&string_hash_ops
);
4695 if (path_is_absolute(path
)) {
4697 filename
= strdup(path
);
4701 r
= open_follow(&filename
, &f
, symlink_names
, &id
);
4703 filename
= mfree(filename
);
4711 STRV_FOREACH(p
, u
->manager
->lookup_paths
.search_path
) {
4713 /* Instead of opening the path right away, we manually
4714 * follow all symlinks and add their name to our unit
4715 * name set while doing so */
4716 filename
= path_make_absolute(path
, *p
);
4720 if (u
->manager
->unit_path_cache
&&
4721 !set_get(u
->manager
->unit_path_cache
, filename
))
4724 r
= open_follow(&filename
, &f
, symlink_names
, &id
);
4727 filename
= mfree(filename
);
4729 /* ENOENT means that the file is missing or is a dangling symlink.
4730 * ENOTDIR means that one of paths we expect to be is a directory
4731 * is not a directory, we should just ignore that.
4732 * EACCES means that the directory or file permissions are wrong.
4735 log_debug_errno(r
, "Cannot access \"%s\": %m", filename
);
4736 else if (!IN_SET(r
, -ENOENT
, -ENOTDIR
))
4739 /* Empty the symlink names for the next run */
4740 set_clear_free(symlink_names
);
4745 /* Hmm, no suitable file found? */
4748 if (!unit_type_may_alias(u
->type
) && set_size(symlink_names
) > 1) {
4749 log_unit_warning(u
, "Unit type of %s does not support alias names, refusing loading via symlink.", u
->id
);
4754 r
= merge_by_names(&merged
, symlink_names
, id
);
4759 u
->load_state
= UNIT_MERGED
;
4763 if (fstat(fileno(f
), &st
) < 0)
4766 if (null_or_empty(&st
)) {
4767 u
->load_state
= UNIT_MASKED
;
4768 u
->fragment_mtime
= 0;
4770 u
->load_state
= UNIT_LOADED
;
4771 u
->fragment_mtime
= timespec_load(&st
.st_mtim
);
4773 /* Now, parse the file contents */
4774 r
= config_parse(u
->id
, filename
, f
,
4775 UNIT_VTABLE(u
)->sections
,
4776 config_item_perf_lookup
, load_fragment_gperf_lookup
,
4777 CONFIG_PARSE_ALLOW_INCLUDE
, u
);
4782 free_and_replace(u
->fragment_path
, filename
);
4784 if (u
->source_path
) {
4785 if (stat(u
->source_path
, &st
) >= 0)
4786 u
->source_mtime
= timespec_load(&st
.st_mtim
);
4788 u
->source_mtime
= 0;
4794 int unit_load_fragment(Unit
*u
) {
4800 assert(u
->load_state
== UNIT_STUB
);
4804 u
->load_state
= UNIT_LOADED
;
4808 /* First, try to find the unit under its id. We always look
4809 * for unit files in the default directories, to make it easy
4810 * to override things by placing things in /etc/systemd/system */
4811 r
= load_from_path(u
, u
->id
);
4815 /* Try to find an alias we can load this with */
4816 if (u
->load_state
== UNIT_STUB
) {
4817 SET_FOREACH(t
, u
->names
, i
) {
4822 r
= load_from_path(u
, t
);
4826 if (u
->load_state
!= UNIT_STUB
)
4831 /* And now, try looking for it under the suggested (originally linked) path */
4832 if (u
->load_state
== UNIT_STUB
&& u
->fragment_path
) {
4834 r
= load_from_path(u
, u
->fragment_path
);
4838 if (u
->load_state
== UNIT_STUB
)
4839 /* Hmm, this didn't work? Then let's get rid
4840 * of the fragment path stored for us, so that
4841 * we don't point to an invalid location. */
4842 u
->fragment_path
= mfree(u
->fragment_path
);
4845 /* Look for a template */
4846 if (u
->load_state
== UNIT_STUB
&& u
->instance
) {
4847 _cleanup_free_
char *k
= NULL
;
4849 r
= unit_name_template(u
->id
, &k
);
4853 r
= load_from_path(u
, k
);
4856 log_unit_notice(u
, "Unit configuration has fatal error, unit will not be started.");
4860 if (u
->load_state
== UNIT_STUB
) {
4861 SET_FOREACH(t
, u
->names
, i
) {
4862 _cleanup_free_
char *z
= NULL
;
4867 r
= unit_name_template(t
, &z
);
4871 r
= load_from_path(u
, z
);
4875 if (u
->load_state
!= UNIT_STUB
)
4884 void unit_dump_config_items(FILE *f
) {
4885 static const struct {
4886 const ConfigParserCallback callback
;
4889 #if !HAVE_SYSV_COMPAT || !HAVE_SECCOMP || !HAVE_PAM || !HAVE_SELINUX || !ENABLE_SMACK || !HAVE_APPARMOR
4890 { config_parse_warn_compat
, "NOTSUPPORTED" },
4892 { config_parse_int
, "INTEGER" },
4893 { config_parse_unsigned
, "UNSIGNED" },
4894 { config_parse_iec_size
, "SIZE" },
4895 { config_parse_iec_uint64
, "SIZE" },
4896 { config_parse_si_size
, "SIZE" },
4897 { config_parse_bool
, "BOOLEAN" },
4898 { config_parse_string
, "STRING" },
4899 { config_parse_path
, "PATH" },
4900 { config_parse_unit_path_printf
, "PATH" },
4901 { config_parse_strv
, "STRING [...]" },
4902 { config_parse_exec_nice
, "NICE" },
4903 { config_parse_exec_oom_score_adjust
, "OOMSCOREADJUST" },
4904 { config_parse_exec_io_class
, "IOCLASS" },
4905 { config_parse_exec_io_priority
, "IOPRIORITY" },
4906 { config_parse_exec_cpu_sched_policy
, "CPUSCHEDPOLICY" },
4907 { config_parse_exec_cpu_sched_prio
, "CPUSCHEDPRIO" },
4908 { config_parse_exec_cpu_affinity
, "CPUAFFINITY" },
4909 { config_parse_mode
, "MODE" },
4910 { config_parse_unit_env_file
, "FILE" },
4911 { config_parse_exec_output
, "OUTPUT" },
4912 { config_parse_exec_input
, "INPUT" },
4913 { config_parse_log_facility
, "FACILITY" },
4914 { config_parse_log_level
, "LEVEL" },
4915 { config_parse_exec_secure_bits
, "SECUREBITS" },
4916 { config_parse_capability_set
, "BOUNDINGSET" },
4917 { config_parse_limit
, "LIMIT" },
4918 { config_parse_unit_deps
, "UNIT [...]" },
4919 { config_parse_exec
, "PATH [ARGUMENT [...]]" },
4920 { config_parse_service_type
, "SERVICETYPE" },
4921 { config_parse_service_restart
, "SERVICERESTART" },
4922 #if HAVE_SYSV_COMPAT
4923 { config_parse_sysv_priority
, "SYSVPRIORITY" },
4925 { config_parse_kill_mode
, "KILLMODE" },
4926 { config_parse_signal
, "SIGNAL" },
4927 { config_parse_socket_listen
, "SOCKET [...]" },
4928 { config_parse_socket_bind
, "SOCKETBIND" },
4929 { config_parse_socket_bindtodevice
, "NETWORKINTERFACE" },
4930 { config_parse_sec
, "SECONDS" },
4931 { config_parse_nsec
, "NANOSECONDS" },
4932 { config_parse_namespace_path_strv
, "PATH [...]" },
4933 { config_parse_bind_paths
, "PATH[:PATH[:OPTIONS]] [...]" },
4934 { config_parse_unit_requires_mounts_for
, "PATH [...]" },
4935 { config_parse_exec_mount_flags
, "MOUNTFLAG [...]" },
4936 { config_parse_unit_string_printf
, "STRING" },
4937 { config_parse_trigger_unit
, "UNIT" },
4938 { config_parse_timer
, "TIMER" },
4939 { config_parse_path_spec
, "PATH" },
4940 { config_parse_notify_access
, "ACCESS" },
4941 { config_parse_ip_tos
, "TOS" },
4942 { config_parse_unit_condition_path
, "CONDITION" },
4943 { config_parse_unit_condition_string
, "CONDITION" },
4944 { config_parse_unit_condition_null
, "CONDITION" },
4945 { config_parse_unit_slice
, "SLICE" },
4946 { config_parse_documentation
, "URL" },
4947 { config_parse_service_timeout
, "SECONDS" },
4948 { config_parse_emergency_action
, "ACTION" },
4949 { config_parse_set_status
, "STATUS" },
4950 { config_parse_service_sockets
, "SOCKETS" },
4951 { config_parse_environ
, "ENVIRON" },
4953 { config_parse_syscall_filter
, "SYSCALLS" },
4954 { config_parse_syscall_archs
, "ARCHS" },
4955 { config_parse_syscall_errno
, "ERRNO" },
4956 { config_parse_address_families
, "FAMILIES" },
4957 { config_parse_restrict_namespaces
, "NAMESPACES" },
4959 { config_parse_cpu_shares
, "SHARES" },
4960 { config_parse_cpu_weight
, "WEIGHT" },
4961 { config_parse_memory_limit
, "LIMIT" },
4962 { config_parse_device_allow
, "DEVICE" },
4963 { config_parse_device_policy
, "POLICY" },
4964 { config_parse_io_limit
, "LIMIT" },
4965 { config_parse_io_weight
, "WEIGHT" },
4966 { config_parse_io_device_weight
, "DEVICEWEIGHT" },
4967 { config_parse_blockio_bandwidth
, "BANDWIDTH" },
4968 { config_parse_blockio_weight
, "WEIGHT" },
4969 { config_parse_blockio_device_weight
, "DEVICEWEIGHT" },
4970 { config_parse_long
, "LONG" },
4971 { config_parse_socket_service
, "SERVICE" },
4973 { config_parse_exec_selinux_context
, "LABEL" },
4975 { config_parse_job_mode
, "MODE" },
4976 { config_parse_job_mode_isolate
, "BOOLEAN" },
4977 { config_parse_personality
, "PERSONALITY" },
4980 const char *prev
= NULL
;
4985 NULSTR_FOREACH(i
, load_fragment_gperf_nulstr
) {
4986 const char *rvalue
= "OTHER", *lvalue
;
4990 const ConfigPerfItem
*p
;
4992 assert_se(p
= load_fragment_gperf_lookup(i
, strlen(i
)));
4994 dot
= strchr(i
, '.');
4995 lvalue
= dot
? dot
+ 1 : i
;
4999 if (!prev
|| !strneq(prev
, i
, prefix_len
+1)) {
5003 fprintf(f
, "[%.*s]\n", (int) prefix_len
, i
);
5006 for (j
= 0; j
< ELEMENTSOF(table
); j
++)
5007 if (p
->parse
== table
[j
].callback
) {
5008 rvalue
= table
[j
].rvalue
;
5012 fprintf(f
, "%s=%s\n", lvalue
, rvalue
);