1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 This file is part of systemd.
5 Copyright 2010 Lennart Poettering
6 Copyright 2012 Holger Hans Peter Freyther
12 #include <linux/oom.h>
18 #include <sys/resource.h>
22 #include "alloc-util.h"
23 #include "bus-error.h"
24 #include "bus-internal.h"
27 #include "capability-util.h"
29 #include "conf-parser.h"
30 #include "cpu-set-util.h"
32 #include "errno-list.h"
36 #include "hexdecoct.h"
39 #include "journal-util.h"
40 #include "load-fragment.h"
43 #include "mount-util.h"
44 #include "parse-util.h"
45 #include "path-util.h"
46 #include "process-util.h"
47 #include "rlimit-util.h"
49 #include "seccomp-util.h"
51 #include "securebits.h"
52 #include "securebits-util.h"
53 #include "signal-util.h"
54 #include "socket-protocol-list.h"
55 #include "stat-util.h"
56 #include "string-util.h"
58 #include "unit-name.h"
59 #include "unit-printf.h"
61 #include "user-util.h"
65 DEFINE_CONFIG_PARSE_ENUM(config_parse_collect_mode
, collect_mode
, CollectMode
, "Failed to parse garbage collection mode");
67 int config_parse_unit_deps(
72 unsigned section_line
,
79 UnitDependency d
= ltype
;
89 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
92 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_RETAIN_ESCAPE
);
98 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
102 r
= unit_name_printf(u
, word
, &k
);
104 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve specifiers, ignoring: %m");
108 r
= unit_add_dependency_by_name(u
, d
, k
, NULL
, true, UNIT_DEPENDENCY_FILE
);
110 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
116 int config_parse_obsolete_unit_deps(
118 const char *filename
,
121 unsigned section_line
,
128 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
129 "Unit dependency type %s= is obsolete, replacing by %s=, please update your unit file", lvalue
, unit_dependency_to_string(ltype
));
131 return config_parse_unit_deps(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
);
134 int config_parse_unit_string_printf(
136 const char *filename
,
139 unsigned section_line
,
146 _cleanup_free_
char *k
= NULL
;
155 r
= unit_full_printf(u
, rvalue
, &k
);
157 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers on %s, ignoring: %m", rvalue
);
161 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
164 int config_parse_unit_strv_printf(
166 const char *filename
,
169 unsigned section_line
,
177 _cleanup_free_
char *k
= NULL
;
185 r
= unit_full_printf(u
, rvalue
, &k
);
187 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers on %s, ignoring: %m", rvalue
);
191 return config_parse_strv(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
194 int config_parse_unit_path_printf(
196 const char *filename
,
199 unsigned section_line
,
206 _cleanup_free_
char *k
= NULL
;
216 /* Let's not bother with anything that is too long */
217 if (strlen(rvalue
) >= PATH_MAX
) {
218 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
219 "%s value too long%s.",
220 lvalue
, fatal
? "" : ", ignoring");
221 return fatal
? -ENAMETOOLONG
: 0;
224 r
= unit_full_printf(u
, rvalue
, &k
);
226 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
227 "Failed to resolve unit specifiers in \"%s\"%s: %m",
228 rvalue
, fatal
? "" : ", ignoring");
229 return fatal
? -ENOEXEC
: 0;
232 return config_parse_path(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
235 int config_parse_unit_path_strv_printf(
237 const char *filename
,
240 unsigned section_line
,
257 if (isempty(rvalue
)) {
263 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
265 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
271 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
272 "Invalid syntax, ignoring: %s", rvalue
);
276 r
= unit_full_printf(u
, word
, &k
);
278 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
279 "Failed to resolve unit specifiers on \"%s\", ignoring: %m", word
);
283 if (!utf8_is_valid(k
)) {
284 log_syntax_invalid_utf8(unit
, LOG_ERR
, filename
, line
, rvalue
);
288 if (!path_is_absolute(k
)) {
289 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
290 "Symlink path is not absolute: %s", k
);
294 path_kill_slashes(k
);
303 int config_parse_socket_listen(const char *unit
,
304 const char *filename
,
307 unsigned section_line
,
314 _cleanup_free_ SocketPort
*p
= NULL
;
326 if (isempty(rvalue
)) {
327 /* An empty assignment removes all ports */
328 socket_free_ports(s
);
332 p
= new0(SocketPort
, 1);
336 if (ltype
!= SOCKET_SOCKET
) {
339 r
= unit_full_printf(UNIT(s
), rvalue
, &p
->path
);
341 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers on %s, ignoring: %m", rvalue
);
345 path_kill_slashes(p
->path
);
347 } else if (streq(lvalue
, "ListenNetlink")) {
348 _cleanup_free_
char *k
= NULL
;
350 p
->type
= SOCKET_SOCKET
;
351 r
= unit_full_printf(UNIT(s
), rvalue
, &k
);
353 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers on %s, ignoring: %m", rvalue
);
357 r
= socket_address_parse_netlink(&p
->address
, k
);
359 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse address value, ignoring: %s", rvalue
);
364 _cleanup_free_
char *k
= NULL
;
366 p
->type
= SOCKET_SOCKET
;
367 r
= unit_full_printf(UNIT(s
), rvalue
, &k
);
369 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,"Failed to resolve unit specifiers on %s, ignoring: %m", rvalue
);
373 r
= socket_address_parse_and_warn(&p
->address
, k
);
375 if (r
!= -EAFNOSUPPORT
)
376 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse address value, ignoring: %s", rvalue
);
380 if (streq(lvalue
, "ListenStream"))
381 p
->address
.type
= SOCK_STREAM
;
382 else if (streq(lvalue
, "ListenDatagram"))
383 p
->address
.type
= SOCK_DGRAM
;
385 assert(streq(lvalue
, "ListenSequentialPacket"));
386 p
->address
.type
= SOCK_SEQPACKET
;
389 if (socket_address_family(&p
->address
) != AF_LOCAL
&& p
->address
.type
== SOCK_SEQPACKET
) {
390 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Address family not supported, ignoring: %s", rvalue
);
396 p
->auxiliary_fds
= NULL
;
397 p
->n_auxiliary_fds
= 0;
400 LIST_FIND_TAIL(port
, s
->ports
, tail
);
401 LIST_INSERT_AFTER(port
, s
->ports
, tail
, p
);
408 int config_parse_socket_protocol(const char *unit
,
409 const char *filename
,
412 unsigned section_line
,
428 r
= socket_protocol_from_name(rvalue
);
430 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid socket protocol, ignoring: %s", rvalue
);
432 } else if (!IN_SET(r
, IPPROTO_UDPLITE
, IPPROTO_SCTP
)) {
433 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Socket protocol not supported, ignoring: %s", rvalue
);
437 s
->socket_protocol
= r
;
442 int config_parse_socket_bind(const char *unit
,
443 const char *filename
,
446 unsigned section_line
,
454 SocketAddressBindIPv6Only b
;
463 b
= parse_socket_address_bind_ipv6_only_or_bool(rvalue
);
465 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse bind IPv6 only value, ignoring: %s", rvalue
);
469 s
->bind_ipv6_only
= b
;
474 int config_parse_exec_nice(
476 const char *filename
,
479 unsigned section_line
,
486 ExecContext
*c
= data
;
494 r
= parse_nice(rvalue
, &priority
);
497 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Nice priority out of range, ignoring: %s", rvalue
);
499 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse nice priority, ignoring: %s", rvalue
);
510 int config_parse_exec_oom_score_adjust(const char* unit
,
511 const char *filename
,
514 unsigned section_line
,
521 ExecContext
*c
= data
;
529 r
= safe_atoi(rvalue
, &oa
);
531 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse the OOM score adjust value, ignoring: %s", rvalue
);
535 if (oa
< OOM_SCORE_ADJ_MIN
|| oa
> OOM_SCORE_ADJ_MAX
) {
536 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "OOM score adjust value out of range, ignoring: %s", rvalue
);
540 c
->oom_score_adjust
= oa
;
541 c
->oom_score_adjust_set
= true;
546 int config_parse_exec(
548 const char *filename
,
551 unsigned section_line
,
558 ExecCommand
**e
= data
;
570 rvalue
+= strspn(rvalue
, WHITESPACE
);
572 if (isempty(rvalue
)) {
573 /* An empty assignment resets the list */
574 *e
= exec_command_free_list(*e
);
580 _cleanup_free_
char *path
= NULL
, *firstword
= NULL
;
581 ExecCommandFlags flags
= 0;
582 bool ignore
= false, separate_argv0
= false;
583 _cleanup_free_ ExecCommand
*nce
= NULL
;
584 _cleanup_strv_free_
char **n
= NULL
;
585 size_t nlen
= 0, nbufsize
= 0;
590 r
= extract_first_word_and_warn(&p
, &firstword
, NULL
, EXTRACT_QUOTES
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
596 /* We accept an absolute path as first argument. If it's prefixed with - and the path doesn't
597 * exist, we ignore it instead of erroring out; if it's prefixed with @, we allow overriding of
598 * argv[0]; if it's prefixed with +, it will be run with full privileges and no sandboxing; if
599 * it's prefixed with '!' we apply sandboxing, but do not change user/group credentials; if
600 * it's prefixed with '!!', then we apply user/group credentials if the kernel supports ambient
601 * capabilities -- if it doesn't we don't apply the credentials themselves, but do apply most
602 * other sandboxing, with some special exceptions for changing UID.
604 * The idea is that '!!' may be used to write services that can take benefit of systemd's
605 * UID/GID dropping if the kernel supports ambient creds, but provide an automatic fallback to
606 * privilege dropping within the daemon if the kernel does not offer that. */
608 if (*f
== '-' && !(flags
& EXEC_COMMAND_IGNORE_FAILURE
)) {
609 flags
|= EXEC_COMMAND_IGNORE_FAILURE
;
611 } else if (*f
== '@' && !separate_argv0
)
612 separate_argv0
= true;
613 else if (*f
== '+' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
614 flags
|= EXEC_COMMAND_FULLY_PRIVILEGED
;
615 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
616 flags
|= EXEC_COMMAND_NO_SETUID
;
617 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_AMBIENT_MAGIC
))) {
618 flags
&= ~EXEC_COMMAND_NO_SETUID
;
619 flags
|= EXEC_COMMAND_AMBIENT_MAGIC
;
625 r
= unit_full_printf(u
, f
, &path
);
627 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
628 "Failed to resolve unit specifiers on %s%s: %m",
629 f
, ignore
? ", ignoring" : "");
630 return ignore
? 0 : -ENOEXEC
;
634 /* First word is either "-" or "@" with no command. */
635 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
636 "Empty path in command line%s: \"%s\"",
637 ignore
? ", ignoring" : "", rvalue
);
638 return ignore
? 0 : -ENOEXEC
;
640 if (!string_is_safe(path
)) {
641 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
642 "Executable name contains special characters%s: %s",
643 ignore
? ", ignoring" : "", path
);
644 return ignore
? 0 : -ENOEXEC
;
646 if (endswith(path
, "/")) {
647 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
648 "Executable path specifies a directory%s: %s",
649 ignore
? ", ignoring" : "", path
);
650 return ignore
? 0 : -ENOEXEC
;
653 if (!path_is_absolute(path
)) {
657 if (!filename_is_valid(path
)) {
658 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
659 "Neither a valid executable name nor an absolute path%s: %s",
660 ignore
? ", ignoring" : "", path
);
661 return ignore
? 0 : -ENOEXEC
;
664 /* Resolve a single-component name to a full path */
665 NULSTR_FOREACH(prefix
, DEFAULT_PATH_NULSTR
) {
666 _cleanup_free_
char *fullpath
= NULL
;
668 fullpath
= strjoin(prefix
, "/", path
);
672 if (access(fullpath
, F_OK
) >= 0) {
673 free_and_replace(path
, fullpath
);
680 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
681 "Executable \"%s\" not found in path \"%s\"%s",
682 path
, DEFAULT_PATH
, ignore
? ", ignoring" : "");
683 return ignore
? 0 : -ENOEXEC
;
687 if (!separate_argv0
) {
690 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
700 path_kill_slashes(path
);
702 while (!isempty(p
)) {
703 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
705 /* Check explicitly for an unquoted semicolon as
706 * command separator token. */
707 if (p
[0] == ';' && (!p
[1] || strchr(WHITESPACE
, p
[1]))) {
709 p
+= strspn(p
, WHITESPACE
);
714 /* Check for \; explicitly, to not confuse it with \\; or "\;" or "\\;" etc.
715 * extract_first_word() would return the same for all of those. */
716 if (p
[0] == '\\' && p
[1] == ';' && (!p
[2] || strchr(WHITESPACE
, p
[2]))) {
720 p
+= strspn(p
, WHITESPACE
);
722 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
733 r
= extract_first_word_and_warn(&p
, &word
, NULL
, EXTRACT_QUOTES
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
737 return ignore
? 0 : -ENOEXEC
;
739 r
= unit_full_printf(u
, word
, &resolved
);
741 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
742 "Failed to resolve unit specifiers on %s%s: %m",
743 word
, ignore
? ", ignoring" : "");
744 return ignore
? 0 : -ENOEXEC
;
747 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
750 n
[nlen
++] = TAKE_PTR(resolved
);
755 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
756 "Empty executable name or zeroeth argument%s: %s",
757 ignore
? ", ignoring" : "", rvalue
);
758 return ignore
? 0 : -ENOEXEC
;
761 nce
= new0(ExecCommand
, 1);
765 nce
->argv
= TAKE_PTR(n
);
766 nce
->path
= TAKE_PTR(path
);
769 exec_command_append_list(e
, nce
);
771 /* Do not _cleanup_free_ these. */
780 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_type
, service_type
, ServiceType
, "Failed to parse service type");
781 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart
, service_restart
, ServiceRestart
, "Failed to parse service restart specifier");
783 int config_parse_socket_bindtodevice(
785 const char *filename
,
788 unsigned section_line
,
803 if (rvalue
[0] && !streq(rvalue
, "*")) {
804 if (!ifname_valid(rvalue
)) {
805 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Interface name is invalid, ignoring: %s", rvalue
);
815 free(s
->bind_to_device
);
816 s
->bind_to_device
= n
;
821 int config_parse_exec_input(
823 const char *filename
,
826 unsigned section_line
,
833 ExecContext
*c
= data
;
844 n
= startswith(rvalue
, "fd:");
846 _cleanup_free_
char *resolved
= NULL
;
848 r
= unit_full_printf(u
, n
, &resolved
);
850 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers on %s: %m", n
);
852 if (isempty(resolved
))
853 resolved
= mfree(resolved
);
854 else if (!fdname_is_valid(resolved
)) {
855 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name: %s", resolved
);
859 free_and_replace(c
->stdio_fdname
[STDIN_FILENO
], resolved
);
861 ei
= EXEC_INPUT_NAMED_FD
;
863 } else if ((n
= startswith(rvalue
, "file:"))) {
864 _cleanup_free_
char *resolved
= NULL
;
866 r
= unit_full_printf(u
, n
, &resolved
);
868 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers on %s: %m", n
);
870 if (!path_is_absolute(resolved
)) {
871 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "file: requires an absolute path name: %s", resolved
);
875 if (!path_is_normalized(resolved
)) {
876 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "file: requires a normalized path name: %s", resolved
);
880 free_and_replace(c
->stdio_file
[STDIN_FILENO
], resolved
);
882 ei
= EXEC_INPUT_FILE
;
885 ei
= exec_input_from_string(rvalue
);
887 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse input specifier, ignoring: %s", rvalue
);
896 int config_parse_exec_input_text(
898 const char *filename
,
901 unsigned section_line
,
908 _cleanup_free_
char *unescaped
= NULL
, *resolved
= NULL
;
909 ExecContext
*c
= data
;
920 if (isempty(rvalue
)) {
921 /* Reset if the empty string is assigned */
922 c
->stdin_data
= mfree(c
->stdin_data
);
923 c
->stdin_data_size
= 0;
927 r
= cunescape(rvalue
, 0, &unescaped
);
929 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to decode C escaped text: %s", rvalue
);
931 r
= unit_full_printf(u
, unescaped
, &resolved
);
933 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve specifiers: %s", unescaped
);
935 sz
= strlen(resolved
);
936 if (c
->stdin_data_size
+ sz
+ 1 < c
->stdin_data_size
|| /* check for overflow */
937 c
->stdin_data_size
+ sz
+ 1 > EXEC_STDIN_DATA_MAX
) {
938 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Standard input data too large (%zu), maximum of %zu permitted, ignoring.", c
->stdin_data_size
+ sz
, (size_t) EXEC_STDIN_DATA_MAX
);
942 p
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
+ 1);
946 *((char*) mempcpy((char*) p
+ c
->stdin_data_size
, resolved
, sz
)) = '\n';
949 c
->stdin_data_size
+= sz
+ 1;
954 int config_parse_exec_input_data(
956 const char *filename
,
959 unsigned section_line
,
966 _cleanup_free_
void *p
= NULL
;
967 ExecContext
*c
= data
;
977 if (isempty(rvalue
)) {
978 /* Reset if the empty string is assigned */
979 c
->stdin_data
= mfree(c
->stdin_data
);
980 c
->stdin_data_size
= 0;
984 r
= unbase64mem(rvalue
, (size_t) -1, &p
, &sz
);
986 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to decode base64 data, ignoring: %s", rvalue
);
990 if (c
->stdin_data_size
+ sz
< c
->stdin_data_size
|| /* check for overflow */
991 c
->stdin_data_size
+ sz
> EXEC_STDIN_DATA_MAX
) {
992 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Standard input data too large (%zu), maximum of %zu permitted, ignoring.", c
->stdin_data_size
+ sz
, (size_t) EXEC_STDIN_DATA_MAX
);
996 q
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
);
1000 memcpy((uint8_t*) q
+ c
->stdin_data_size
, p
, sz
);
1003 c
->stdin_data_size
+= sz
;
1008 int config_parse_exec_output(
1010 const char *filename
,
1012 const char *section
,
1013 unsigned section_line
,
1020 _cleanup_free_
char *resolved
= NULL
;
1022 ExecContext
*c
= data
;
1033 n
= startswith(rvalue
, "fd:");
1035 r
= unit_full_printf(u
, n
, &resolved
);
1037 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers on %s: %m", n
);
1039 if (isempty(resolved
))
1040 resolved
= mfree(resolved
);
1041 else if (!fdname_is_valid(resolved
)) {
1042 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name: %s", resolved
);
1046 eo
= EXEC_OUTPUT_NAMED_FD
;
1048 } else if ((n
= startswith(rvalue
, "file:"))) {
1050 r
= unit_full_printf(u
, n
, &resolved
);
1052 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers on %s: %m", n
);
1054 if (!path_is_absolute(resolved
)) {
1055 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "file: requires an absolute path name: %s", resolved
);
1059 if (!path_is_normalized(resolved
)) {
1060 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "file: requires a normalized path name, ignoring: %s", resolved
);
1064 eo
= EXEC_OUTPUT_FILE
;
1067 eo
= exec_output_from_string(rvalue
);
1069 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse output specifier, ignoring: %s", rvalue
);
1074 if (streq(lvalue
, "StandardOutput")) {
1075 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1076 free_and_replace(c
->stdio_fdname
[STDOUT_FILENO
], resolved
);
1078 free_and_replace(c
->stdio_file
[STDOUT_FILENO
], resolved
);
1083 assert(streq(lvalue
, "StandardError"));
1085 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1086 free_and_replace(c
->stdio_fdname
[STDERR_FILENO
], resolved
);
1088 free_and_replace(c
->stdio_file
[STDERR_FILENO
], resolved
);
1096 int config_parse_exec_io_class(const char *unit
,
1097 const char *filename
,
1099 const char *section
,
1100 unsigned section_line
,
1107 ExecContext
*c
= data
;
1115 x
= ioprio_class_from_string(rvalue
);
1117 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse IO scheduling class, ignoring: %s", rvalue
);
1121 c
->ioprio
= IOPRIO_PRIO_VALUE(x
, IOPRIO_PRIO_DATA(c
->ioprio
));
1122 c
->ioprio_set
= true;
1127 int config_parse_exec_io_priority(const char *unit
,
1128 const char *filename
,
1130 const char *section
,
1131 unsigned section_line
,
1138 ExecContext
*c
= data
;
1146 r
= ioprio_parse_priority(rvalue
, &i
);
1148 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse IO priority, ignoring: %s", rvalue
);
1152 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_PRIO_CLASS(c
->ioprio
), i
);
1153 c
->ioprio_set
= true;
1158 int config_parse_exec_cpu_sched_policy(const char *unit
,
1159 const char *filename
,
1161 const char *section
,
1162 unsigned section_line
,
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 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);
1682 calendar_spec_free(c
);
1688 v
->calendar_spec
= c
;
1690 LIST_PREPEND(value
, t
->values
, v
);
1695 int config_parse_trigger_unit(
1697 const char *filename
,
1699 const char *section
,
1700 unsigned section_line
,
1707 _cleanup_free_
char *p
= NULL
;
1717 if (!hashmap_isempty(u
->dependencies
[UNIT_TRIGGERS
])) {
1718 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Multiple units to trigger specified, ignoring: %s", rvalue
);
1722 r
= unit_name_printf(u
, rvalue
, &p
);
1724 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve specifiers, ignoring: %m");
1728 type
= unit_name_to_type(p
);
1730 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit type not valid, ignoring: %s", rvalue
);
1733 if (unit_has_name(u
, p
)) {
1734 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Units cannot trigger themselves, ignoring: %s", rvalue
);
1738 r
= unit_add_two_dependencies_by_name(u
, UNIT_BEFORE
, UNIT_TRIGGERS
, p
, NULL
, true, UNIT_DEPENDENCY_FILE
);
1740 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add trigger on %s, ignoring: %m", p
);
1747 int config_parse_path_spec(const char *unit
,
1748 const char *filename
,
1750 const char *section
,
1751 unsigned section_line
,
1761 _cleanup_free_
char *k
= NULL
;
1769 if (isempty(rvalue
)) {
1770 /* Empty assignment clears list */
1775 b
= path_type_from_string(lvalue
);
1777 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse path type, ignoring: %s", lvalue
);
1781 r
= unit_full_printf(UNIT(p
), rvalue
, &k
);
1783 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers on %s. Ignoring.", rvalue
);
1787 if (!path_is_absolute(k
)) {
1788 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Path is not absolute, ignoring: %s", k
);
1792 s
= new0(PathSpec
, 1);
1797 s
->path
= path_kill_slashes(k
);
1802 LIST_PREPEND(spec
, p
->specs
, s
);
1807 int config_parse_socket_service(
1809 const char *filename
,
1811 const char *section
,
1812 unsigned section_line
,
1819 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1820 _cleanup_free_
char *p
= NULL
;
1830 r
= unit_name_printf(UNIT(s
), rvalue
, &p
);
1832 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve specifiers: %s", rvalue
);
1836 if (!endswith(p
, ".service")) {
1837 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit must be of type service: %s", rvalue
);
1841 r
= manager_load_unit(UNIT(s
)->manager
, p
, NULL
, &error
, &x
);
1843 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to load unit %s: %s", rvalue
, bus_error_message(&error
, r
));
1847 unit_ref_set(&s
->service
, UNIT(s
), x
);
1852 int config_parse_fdname(
1854 const char *filename
,
1856 const char *section
,
1857 unsigned section_line
,
1864 _cleanup_free_
char *p
= NULL
;
1873 if (isempty(rvalue
)) {
1874 s
->fdname
= mfree(s
->fdname
);
1878 r
= unit_full_printf(UNIT(s
), rvalue
, &p
);
1880 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve specifiers, ignoring: %s", rvalue
);
1884 if (!fdname_is_valid(p
)) {
1885 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", p
);
1889 return free_and_replace(s
->fdname
, p
);
1892 int config_parse_service_sockets(
1894 const char *filename
,
1896 const char *section
,
1897 unsigned section_line
,
1915 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
1917 r
= extract_first_word(&p
, &word
, NULL
, 0);
1923 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Trailing garbage in sockets, ignoring: %s", rvalue
);
1927 r
= unit_name_printf(UNIT(s
), word
, &k
);
1929 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve specifiers, ignoring: %m");
1933 if (!endswith(k
, ".socket")) {
1934 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit must be of type socket, ignoring: %s", k
);
1938 r
= unit_add_two_dependencies_by_name(UNIT(s
), UNIT_WANTS
, UNIT_AFTER
, k
, NULL
, true, UNIT_DEPENDENCY_FILE
);
1940 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
1942 r
= unit_add_dependency_by_name(UNIT(s
), UNIT_TRIGGERED_BY
, k
, NULL
, true, UNIT_DEPENDENCY_FILE
);
1944 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
1950 int config_parse_bus_name(
1952 const char *filename
,
1954 const char *section
,
1955 unsigned section_line
,
1962 _cleanup_free_
char *k
= NULL
;
1971 r
= unit_full_printf(u
, rvalue
, &k
);
1973 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers on %s, ignoring: %m", rvalue
);
1977 if (!service_name_is_valid(k
)) {
1978 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid bus name %s, ignoring.", k
);
1982 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
1985 int config_parse_service_timeout(
1987 const char *filename
,
1989 const char *section
,
1990 unsigned section_line
,
1997 Service
*s
= userdata
;
2006 /* This is called for three cases: TimeoutSec=, TimeoutStopSec= and TimeoutStartSec=. */
2008 r
= parse_sec(rvalue
, &usec
);
2010 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
2014 /* Traditionally, these options accepted 0 to disable the timeouts. However, a timeout of 0 suggests it happens
2015 * immediately, hence fix this to become USEC_INFINITY instead. This is in-line with how we internally handle
2016 * all other timeouts. */
2018 usec
= USEC_INFINITY
;
2020 if (!streq(lvalue
, "TimeoutStopSec")) {
2021 s
->start_timeout_defined
= true;
2022 s
->timeout_start_usec
= usec
;
2025 if (!streq(lvalue
, "TimeoutStartSec"))
2026 s
->timeout_stop_usec
= usec
;
2031 int config_parse_sec_fix_0(
2033 const char *filename
,
2035 const char *section
,
2036 unsigned section_line
,
2043 usec_t
*usec
= data
;
2051 /* This is pretty much like config_parse_sec(), except that this treats a time of 0 as infinity, for
2052 * compatibility with older versions of systemd where 0 instead of infinity was used as indicator to turn off a
2055 r
= parse_sec_fix_0(rvalue
, usec
);
2057 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
2064 int config_parse_user_group(
2066 const char *filename
,
2068 const char *section
,
2069 unsigned section_line
,
2076 char **user
= data
, *n
;
2085 if (isempty(rvalue
))
2088 _cleanup_free_
char *k
= NULL
;
2090 r
= unit_full_printf(u
, rvalue
, &k
);
2092 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", rvalue
);
2096 if (!valid_user_group_name_or_id(k
)) {
2097 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2110 int config_parse_user_group_strv(
2112 const char *filename
,
2114 const char *section
,
2115 unsigned section_line
,
2122 char ***users
= data
;
2132 if (isempty(rvalue
)) {
2133 *users
= strv_free(*users
);
2139 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2141 r
= extract_first_word(&p
, &word
, NULL
, 0);
2147 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax: %s", rvalue
);
2151 r
= unit_full_printf(u
, word
, &k
);
2153 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", word
);
2157 if (!valid_user_group_name_or_id(k
)) {
2158 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2162 r
= strv_push(users
, k
);
2172 int config_parse_working_directory(
2174 const char *filename
,
2176 const char *section
,
2177 unsigned section_line
,
2184 ExecContext
*c
= data
;
2195 if (rvalue
[0] == '-') {
2201 if (streq(rvalue
, "~")) {
2202 c
->working_directory_home
= true;
2203 c
->working_directory
= mfree(c
->working_directory
);
2205 _cleanup_free_
char *k
= NULL
;
2207 r
= unit_full_printf(u
, rvalue
, &k
);
2209 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2210 "Failed to resolve unit specifiers in working directory path '%s'%s: %m",
2211 rvalue
, missing_ok
? ", ignoring" : "");
2212 return missing_ok
? 0 : -ENOEXEC
;
2215 path_kill_slashes(k
);
2217 if (!utf8_is_valid(k
)) {
2218 log_syntax_invalid_utf8(unit
, LOG_ERR
, filename
, line
, rvalue
);
2219 return missing_ok
? 0 : -ENOEXEC
;
2222 if (!path_is_absolute(k
)) {
2223 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2224 "Working directory path '%s' is not absolute%s.",
2225 rvalue
, missing_ok
? ", ignoring" : "");
2226 return missing_ok
? 0 : -ENOEXEC
;
2229 c
->working_directory_home
= false;
2230 free_and_replace(c
->working_directory
, k
);
2233 c
->working_directory_missing_ok
= missing_ok
;
2237 int config_parse_unit_env_file(const char *unit
,
2238 const char *filename
,
2240 const char *section
,
2241 unsigned section_line
,
2250 _cleanup_free_
char *n
= NULL
;
2258 if (isempty(rvalue
)) {
2259 /* Empty assignment frees the list */
2260 *env
= strv_free(*env
);
2264 r
= unit_full_printf(u
, rvalue
, &n
);
2266 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve specifiers, ignoring: %s", rvalue
);
2270 if (!path_is_absolute(n
[0] == '-' ? n
+ 1 : n
)) {
2271 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Path '%s' is not absolute, ignoring.", n
);
2275 r
= strv_extend(env
, n
);
2282 int config_parse_environ(
2284 const char *filename
,
2286 const char *section
,
2287 unsigned section_line
,
2304 if (isempty(rvalue
)) {
2305 /* Empty assignment resets the list */
2306 *env
= strv_free(*env
);
2310 for (p
= rvalue
;; ) {
2311 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2313 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_QUOTES
);
2319 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2320 "Invalid syntax, ignoring: %s", rvalue
);
2325 r
= unit_full_printf(u
, word
, &k
);
2327 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2328 "Failed to resolve specifiers, ignoring: %s", word
);
2334 if (!env_assignment_is_valid(k
)) {
2335 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2336 "Invalid environment assignment, ignoring: %s", k
);
2340 r
= strv_env_replace(env
, k
);
2348 int config_parse_pass_environ(
2350 const char *filename
,
2352 const char *section
,
2353 unsigned section_line
,
2360 const char *whole_rvalue
= rvalue
;
2361 _cleanup_strv_free_
char **n
= NULL
;
2362 size_t nlen
= 0, nbufsize
= 0;
2363 char*** passenv
= data
;
2372 if (isempty(rvalue
)) {
2373 /* Empty assignment resets the list */
2374 *passenv
= strv_free(*passenv
);
2379 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2381 r
= extract_first_word(&rvalue
, &word
, NULL
, EXTRACT_QUOTES
);
2387 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2388 "Trailing garbage in %s, ignoring: %s", lvalue
, whole_rvalue
);
2393 r
= unit_full_printf(u
, word
, &k
);
2395 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2396 "Failed to resolve specifiers, ignoring: %s", word
);
2402 if (!env_name_is_valid(k
)) {
2403 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2404 "Invalid environment name for %s, ignoring: %s", lvalue
, k
);
2408 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
2411 n
[nlen
++] = TAKE_PTR(k
);
2416 r
= strv_extend_strv(passenv
, n
, true);
2424 int config_parse_unset_environ(
2426 const char *filename
,
2428 const char *section
,
2429 unsigned section_line
,
2436 _cleanup_strv_free_
char **n
= NULL
;
2437 const char *whole_rvalue
= rvalue
;
2438 size_t nlen
= 0, nbufsize
= 0;
2439 char*** unsetenv
= data
;
2448 if (isempty(rvalue
)) {
2449 /* Empty assignment resets the list */
2450 *unsetenv
= strv_free(*unsetenv
);
2455 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2457 r
= extract_first_word(&rvalue
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_QUOTES
);
2463 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2464 "Trailing garbage in %s, ignoring: %s", lvalue
, whole_rvalue
);
2469 r
= unit_full_printf(u
, word
, &k
);
2471 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2472 "Failed to resolve specifiers, ignoring: %s", word
);
2478 if (!env_assignment_is_valid(k
) && !env_name_is_valid(k
)) {
2479 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2480 "Invalid environment name or assignment %s, ignoring: %s", lvalue
, k
);
2484 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
2487 n
[nlen
++] = TAKE_PTR(k
);
2492 r
= strv_extend_strv(unsetenv
, n
, true);
2500 int config_parse_log_extra_fields(
2502 const char *filename
,
2504 const char *section
,
2505 unsigned section_line
,
2512 ExecContext
*c
= data
;
2522 if (isempty(rvalue
)) {
2523 exec_context_free_log_extra_fields(c
);
2527 for (p
= rvalue
;; ) {
2528 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2532 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_QUOTES
);
2538 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
2542 r
= unit_full_printf(u
, word
, &k
);
2544 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers on %s, ignoring field: %m", word
);
2548 eq
= strchr(k
, '=');
2550 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Log field lacks '=' character, ignoring field: %s", k
);
2554 if (!journal_field_valid(k
, eq
-k
, false)) {
2555 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Log field name is invalid, ignoring field: %s", k
);
2559 t
= reallocarray(c
->log_extra_fields
, c
->n_log_extra_fields
+1, sizeof(struct iovec
));
2563 c
->log_extra_fields
= t
;
2564 c
->log_extra_fields
[c
->n_log_extra_fields
++] = IOVEC_MAKE_STRING(k
);
2572 int config_parse_ip_tos(const char *unit
,
2573 const char *filename
,
2575 const char *section
,
2576 unsigned section_line
,
2583 int *ip_tos
= data
, x
;
2590 x
= ip_tos_from_string(rvalue
);
2592 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse IP TOS value, ignoring: %s", rvalue
);
2600 int config_parse_unit_condition_path(
2602 const char *filename
,
2604 const char *section
,
2605 unsigned section_line
,
2612 _cleanup_free_
char *p
= NULL
;
2613 Condition
**list
= data
, *c
;
2614 ConditionType t
= ltype
;
2615 bool trigger
, negate
;
2624 if (isempty(rvalue
)) {
2625 /* Empty assignment resets the list */
2626 *list
= condition_free_list(*list
);
2630 trigger
= rvalue
[0] == '|';
2634 negate
= rvalue
[0] == '!';
2638 r
= unit_full_printf(u
, rvalue
, &p
);
2640 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve specifiers, ignoring: %s", rvalue
);
2644 if (!path_is_absolute(p
)) {
2645 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Path in condition not absolute, ignoring: %s", p
);
2649 c
= condition_new(t
, p
, trigger
, negate
);
2653 LIST_PREPEND(conditions
, *list
, c
);
2657 int config_parse_unit_condition_string(
2659 const char *filename
,
2661 const char *section
,
2662 unsigned section_line
,
2669 _cleanup_free_
char *s
= NULL
;
2670 Condition
**list
= data
, *c
;
2671 ConditionType t
= ltype
;
2672 bool trigger
, negate
;
2681 if (isempty(rvalue
)) {
2682 /* Empty assignment resets the list */
2683 *list
= condition_free_list(*list
);
2687 trigger
= rvalue
[0] == '|';
2691 negate
= rvalue
[0] == '!';
2695 r
= unit_full_printf(u
, rvalue
, &s
);
2697 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve specifiers, ignoring: %s", rvalue
);
2701 c
= condition_new(t
, s
, trigger
, negate
);
2705 LIST_PREPEND(conditions
, *list
, c
);
2709 int config_parse_unit_condition_null(
2711 const char *filename
,
2713 const char *section
,
2714 unsigned section_line
,
2721 Condition
**list
= data
, *c
;
2722 bool trigger
, negate
;
2730 if (isempty(rvalue
)) {
2731 /* Empty assignment resets the list */
2732 *list
= condition_free_list(*list
);
2736 trigger
= rvalue
[0] == '|';
2740 negate
= rvalue
[0] == '!';
2744 b
= parse_boolean(rvalue
);
2746 log_syntax(unit
, LOG_ERR
, filename
, line
, b
, "Failed to parse boolean value in condition, ignoring: %s", rvalue
);
2753 c
= condition_new(CONDITION_NULL
, NULL
, trigger
, negate
);
2757 LIST_PREPEND(conditions
, *list
, c
);
2761 DEFINE_CONFIG_PARSE_ENUM(config_parse_notify_access
, notify_access
, NotifyAccess
, "Failed to parse notify access specifier");
2762 DEFINE_CONFIG_PARSE_ENUM(config_parse_emergency_action
, emergency_action
, EmergencyAction
, "Failed to parse failure action specifier");
2764 int config_parse_unit_requires_mounts_for(
2766 const char *filename
,
2768 const char *section
,
2769 unsigned section_line
,
2785 for (p
= rvalue
;; ) {
2786 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
2788 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
2794 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2795 "Invalid syntax, ignoring: %s", rvalue
);
2799 if (!utf8_is_valid(word
)) {
2800 log_syntax_invalid_utf8(unit
, LOG_ERR
, filename
, line
, rvalue
);
2804 r
= unit_full_printf(u
, word
, &resolved
);
2806 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit name \"%s\", ignoring: %m", word
);
2810 r
= unit_require_mounts_for(u
, resolved
, UNIT_DEPENDENCY_FILE
);
2812 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add required mount \"%s\", ignoring: %m", resolved
);
2818 int config_parse_documentation(const char *unit
,
2819 const char *filename
,
2821 const char *section
,
2822 unsigned section_line
,
2838 if (isempty(rvalue
)) {
2839 /* Empty assignment resets the list */
2840 u
->documentation
= strv_free(u
->documentation
);
2844 r
= config_parse_unit_strv_printf(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
,
2845 rvalue
, data
, userdata
);
2849 for (a
= b
= u
->documentation
; a
&& *a
; a
++) {
2851 if (documentation_url_is_valid(*a
))
2854 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid URL, ignoring: %s", *a
);
2865 int config_parse_syscall_filter(
2867 const char *filename
,
2869 const char *section
,
2870 unsigned section_line
,
2877 ExecContext
*c
= data
;
2879 bool invert
= false;
2888 if (isempty(rvalue
)) {
2889 /* Empty assignment resets the list */
2890 c
->syscall_filter
= hashmap_free(c
->syscall_filter
);
2891 c
->syscall_whitelist
= false;
2895 if (rvalue
[0] == '~') {
2900 if (!c
->syscall_filter
) {
2901 c
->syscall_filter
= hashmap_new(NULL
);
2902 if (!c
->syscall_filter
)
2906 /* Allow everything but the ones listed */
2907 c
->syscall_whitelist
= false;
2909 /* Allow nothing but the ones listed */
2910 c
->syscall_whitelist
= true;
2912 /* Accept default syscalls if we are on a whitelist */
2913 r
= seccomp_parse_syscall_filter("@default", -1, c
->syscall_filter
, SECCOMP_PARSE_WHITELIST
);
2921 _cleanup_free_
char *word
= NULL
, *name
= NULL
;
2924 r
= extract_first_word(&p
, &word
, NULL
, 0);
2930 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
2934 r
= parse_syscall_and_errno(word
, &name
, &num
);
2936 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse syscall:errno, ignoring: %s", word
);
2940 r
= seccomp_parse_syscall_filter_full(name
, num
, c
->syscall_filter
,
2941 SECCOMP_PARSE_LOG
|SECCOMP_PARSE_PERMISSIVE
|(invert
? SECCOMP_PARSE_INVERT
: 0)|(c
->syscall_whitelist
? SECCOMP_PARSE_WHITELIST
: 0),
2942 unit
, filename
, line
);
2950 int config_parse_syscall_archs(
2952 const char *filename
,
2954 const char *section
,
2955 unsigned section_line
,
2966 if (isempty(rvalue
)) {
2967 *archs
= set_free(*archs
);
2971 r
= set_ensure_allocated(archs
, NULL
);
2975 for (p
= rvalue
;;) {
2976 _cleanup_free_
char *word
= NULL
;
2979 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
2985 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2986 "Invalid syntax, ignoring: %s", rvalue
);
2990 r
= seccomp_arch_from_string(word
, &a
);
2992 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2993 "Failed to parse system call architecture \"%s\", ignoring: %m", word
);
2997 r
= set_put(*archs
, UINT32_TO_PTR(a
+ 1));
3003 int config_parse_syscall_errno(
3005 const char *filename
,
3007 const char *section
,
3008 unsigned section_line
,
3015 ExecContext
*c
= data
;
3022 if (isempty(rvalue
)) {
3023 /* Empty assignment resets to KILL */
3024 c
->syscall_errno
= 0;
3028 e
= parse_errno(rvalue
);
3030 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse error number, ignoring: %s", rvalue
);
3034 c
->syscall_errno
= e
;
3038 int config_parse_address_families(
3040 const char *filename
,
3042 const char *section
,
3043 unsigned section_line
,
3050 ExecContext
*c
= data
;
3051 bool invert
= false;
3059 if (isempty(rvalue
)) {
3060 /* Empty assignment resets the list */
3061 c
->address_families
= set_free(c
->address_families
);
3062 c
->address_families_whitelist
= false;
3066 if (rvalue
[0] == '~') {
3071 if (!c
->address_families
) {
3072 c
->address_families
= set_new(NULL
);
3073 if (!c
->address_families
)
3076 c
->address_families_whitelist
= !invert
;
3079 for (p
= rvalue
;;) {
3080 _cleanup_free_
char *word
= NULL
;
3083 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
3089 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3090 "Invalid syntax, ignoring: %s", rvalue
);
3094 af
= af_from_name(word
);
3096 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
3097 "Failed to parse address family \"%s\", ignoring: %m", word
);
3101 /* If we previously wanted to forbid an address family and now
3102 * we want to allow it, then just remove it from the list.
3104 if (!invert
== c
->address_families_whitelist
) {
3105 r
= set_put(c
->address_families
, INT_TO_PTR(af
));
3109 set_remove(c
->address_families
, INT_TO_PTR(af
));
3113 int config_parse_restrict_namespaces(
3115 const char *filename
,
3117 const char *section
,
3118 unsigned section_line
,
3125 ExecContext
*c
= data
;
3126 bool invert
= false;
3129 if (isempty(rvalue
)) {
3130 /* Reset to the default. */
3131 c
->restrict_namespaces
= NAMESPACE_FLAGS_ALL
;
3135 if (rvalue
[0] == '~') {
3140 r
= parse_boolean(rvalue
);
3142 c
->restrict_namespaces
= 0;
3144 c
->restrict_namespaces
= NAMESPACE_FLAGS_ALL
;
3146 /* Not a boolean argument, in this case it's a list of namespace types. */
3148 r
= namespace_flag_from_string_many(rvalue
, &c
->restrict_namespaces
);
3150 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse namespace type string, ignoring: %s", rvalue
);
3156 c
->restrict_namespaces
= (~c
->restrict_namespaces
) & NAMESPACE_FLAGS_ALL
;
3162 int config_parse_unit_slice(
3164 const char *filename
,
3166 const char *section
,
3167 unsigned section_line
,
3174 _cleanup_free_
char *k
= NULL
;
3175 Unit
*u
= userdata
, *slice
= NULL
;
3183 r
= unit_name_printf(u
, rvalue
, &k
);
3185 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers on %s. Ignoring.", rvalue
);
3189 r
= manager_load_unit(u
->manager
, k
, NULL
, NULL
, &slice
);
3191 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to load slice unit %s. Ignoring.", k
);
3195 r
= unit_set_slice(u
, slice
);
3197 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to assign slice %s to unit %s. Ignoring.", slice
->id
, u
->id
);
3204 DEFINE_CONFIG_PARSE_ENUM(config_parse_device_policy
, cgroup_device_policy
, CGroupDevicePolicy
, "Failed to parse device policy");
3206 int config_parse_cpu_weight(
3208 const char *filename
,
3210 const char *section
,
3211 unsigned section_line
,
3218 uint64_t *weight
= data
;
3225 r
= cg_weight_parse(rvalue
, weight
);
3227 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "CPU weight '%s' invalid. Ignoring.", rvalue
);
3234 int config_parse_cpu_shares(
3236 const char *filename
,
3238 const char *section
,
3239 unsigned section_line
,
3246 uint64_t *shares
= data
;
3253 r
= cg_cpu_shares_parse(rvalue
, shares
);
3255 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "CPU shares '%s' invalid. Ignoring.", rvalue
);
3262 int config_parse_cpu_quota(
3264 const char *filename
,
3266 const char *section
,
3267 unsigned section_line
,
3274 CGroupContext
*c
= data
;
3281 if (isempty(rvalue
)) {
3282 c
->cpu_quota_per_sec_usec
= USEC_INFINITY
;
3286 r
= parse_percent_unbounded(rvalue
);
3288 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "CPU quota '%s' invalid. Ignoring.", rvalue
);
3292 c
->cpu_quota_per_sec_usec
= ((usec_t
) r
* USEC_PER_SEC
) / 100U;
3296 int config_parse_memory_limit(
3298 const char *filename
,
3300 const char *section
,
3301 unsigned section_line
,
3308 CGroupContext
*c
= data
;
3309 uint64_t bytes
= CGROUP_LIMIT_MAX
;
3312 if (!isempty(rvalue
) && !streq(rvalue
, "infinity")) {
3314 r
= parse_percent(rvalue
);
3316 r
= parse_size(rvalue
, 1024, &bytes
);
3318 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Memory limit '%s' invalid. Ignoring.", rvalue
);
3322 bytes
= physical_memory_scale(r
, 100U);
3324 if (bytes
>= UINT64_MAX
||
3325 (bytes
<= 0 && !streq(lvalue
, "MemorySwapMax"))) {
3326 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Memory limit '%s' out of range. Ignoring.", rvalue
);
3331 if (streq(lvalue
, "MemoryLow"))
3332 c
->memory_low
= bytes
;
3333 else if (streq(lvalue
, "MemoryHigh"))
3334 c
->memory_high
= bytes
;
3335 else if (streq(lvalue
, "MemoryMax"))
3336 c
->memory_max
= bytes
;
3337 else if (streq(lvalue
, "MemorySwapMax"))
3338 c
->memory_swap_max
= bytes
;
3339 else if (streq(lvalue
, "MemoryLimit"))
3340 c
->memory_limit
= bytes
;
3347 int config_parse_tasks_max(
3349 const char *filename
,
3351 const char *section
,
3352 unsigned section_line
,
3359 uint64_t *tasks_max
= data
, v
;
3363 if (isempty(rvalue
)) {
3364 *tasks_max
= u
->manager
->default_tasks_max
;
3368 if (streq(rvalue
, "infinity")) {
3369 *tasks_max
= CGROUP_LIMIT_MAX
;
3373 r
= parse_percent(rvalue
);
3375 r
= safe_atou64(rvalue
, &v
);
3377 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Maximum tasks value '%s' invalid. Ignoring.", rvalue
);
3381 v
= system_tasks_max_scale(r
, 100U);
3383 if (v
<= 0 || v
>= UINT64_MAX
) {
3384 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Maximum tasks value '%s' out of range. Ignoring.", rvalue
);
3392 int config_parse_delegate(
3394 const char *filename
,
3396 const char *section
,
3397 unsigned section_line
,
3404 CGroupContext
*c
= data
;
3408 t
= unit_name_to_type(unit
);
3409 assert(t
!= _UNIT_TYPE_INVALID
);
3411 if (!unit_vtable
[t
]->can_delegate
) {
3412 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Delegate= setting not supported for this unit type, ignoring.");
3416 /* We either accept a boolean value, which may be used to turn on delegation for all controllers, or turn it
3417 * off for all. Or it takes a list of controller names, in which case we add the specified controllers to the
3418 * mask to delegate. */
3420 if (isempty(rvalue
)) {
3421 c
->delegate
= false;
3422 c
->delegate_controllers
= 0;
3426 r
= parse_boolean(rvalue
);
3428 const char *p
= rvalue
;
3429 CGroupMask mask
= 0;
3432 _cleanup_free_
char *word
= NULL
;
3433 CGroupController cc
;
3435 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
3441 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3445 cc
= cgroup_controller_from_string(word
);
3447 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid controller name '%s', ignoring", rvalue
);
3451 mask
|= CGROUP_CONTROLLER_TO_MASK(cc
);
3455 c
->delegate_controllers
|= mask
;
3459 c
->delegate_controllers
= _CGROUP_MASK_ALL
;
3461 c
->delegate
= false;
3462 c
->delegate_controllers
= 0;
3468 int config_parse_device_allow(
3470 const char *filename
,
3472 const char *section
,
3473 unsigned section_line
,
3480 _cleanup_free_
char *path
= NULL
, *t
= NULL
;
3481 CGroupContext
*c
= data
;
3482 CGroupDeviceAllow
*a
;
3483 const char *m
= NULL
;
3487 if (isempty(rvalue
)) {
3488 while (c
->device_allow
)
3489 cgroup_context_free_device_allow(c
, c
->device_allow
);
3494 r
= unit_full_printf(userdata
, rvalue
, &t
);
3496 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3497 "Failed to resolve specifiers in %s, ignoring: %m",
3502 n
= strcspn(t
, WHITESPACE
);
3504 path
= strndup(t
, n
);
3508 if (!is_deviceallow_pattern(path
) &&
3509 !path_startswith(path
, "/run/systemd/inaccessible/")) {
3510 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device node path '%s'. Ignoring.", path
);
3514 m
= t
+ n
+ strspn(t
+ n
, WHITESPACE
);
3518 if (!in_charset(m
, "rwm")) {
3519 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device rights '%s'. Ignoring.", m
);
3523 a
= new0(CGroupDeviceAllow
, 1);
3527 a
->path
= TAKE_PTR(path
);
3528 a
->r
= !!strchr(m
, 'r');
3529 a
->w
= !!strchr(m
, 'w');
3530 a
->m
= !!strchr(m
, 'm');
3532 LIST_PREPEND(device_allow
, c
->device_allow
, a
);
3536 int config_parse_io_weight(
3538 const char *filename
,
3540 const char *section
,
3541 unsigned section_line
,
3548 uint64_t *weight
= data
;
3555 r
= cg_weight_parse(rvalue
, weight
);
3557 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "IO weight '%s' invalid. Ignoring.", rvalue
);
3564 int config_parse_io_device_weight(
3566 const char *filename
,
3568 const char *section
,
3569 unsigned section_line
,
3576 _cleanup_free_
char *path
= NULL
;
3577 CGroupIODeviceWeight
*w
;
3578 CGroupContext
*c
= data
;
3588 if (isempty(rvalue
)) {
3589 while (c
->io_device_weights
)
3590 cgroup_context_free_io_device_weight(c
, c
->io_device_weights
);
3595 n
= strcspn(rvalue
, WHITESPACE
);
3596 weight
= rvalue
+ n
;
3597 weight
+= strspn(weight
, WHITESPACE
);
3599 if (isempty(weight
)) {
3600 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Expected block device and device weight. Ignoring.");
3604 path
= strndup(rvalue
, n
);
3608 if (!path_startswith(path
, "/dev") &&
3609 !path_startswith(path
, "/run/systemd/inaccessible/")) {
3610 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device node path '%s'. Ignoring.", path
);
3614 r
= cg_weight_parse(weight
, &u
);
3616 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "IO weight '%s' invalid. Ignoring.", weight
);
3620 assert(u
!= CGROUP_WEIGHT_INVALID
);
3622 w
= new0(CGroupIODeviceWeight
, 1);
3626 w
->path
= TAKE_PTR(path
);
3630 LIST_PREPEND(device_weights
, c
->io_device_weights
, w
);
3634 int config_parse_io_limit(
3636 const char *filename
,
3638 const char *section
,
3639 unsigned section_line
,
3646 _cleanup_free_
char *path
= NULL
;
3647 CGroupIODeviceLimit
*l
= NULL
, *t
;
3648 CGroupContext
*c
= data
;
3649 CGroupIOLimitType type
;
3659 type
= cgroup_io_limit_type_from_string(lvalue
);
3662 if (isempty(rvalue
)) {
3663 LIST_FOREACH(device_limits
, l
, c
->io_device_limits
)
3664 l
->limits
[type
] = cgroup_io_limit_defaults
[type
];
3668 n
= strcspn(rvalue
, WHITESPACE
);
3670 limit
+= strspn(limit
, WHITESPACE
);
3673 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Expected space separated pair of device node and bandwidth. Ignoring.");
3677 path
= strndup(rvalue
, n
);
3681 if (!path_startswith(path
, "/dev") &&
3682 !path_startswith(path
, "/run/systemd/inaccessible/")) {
3683 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device node path '%s'. Ignoring.", path
);
3687 if (streq("infinity", limit
)) {
3688 num
= CGROUP_LIMIT_MAX
;
3690 r
= parse_size(limit
, 1000, &num
);
3691 if (r
< 0 || num
<= 0) {
3692 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "IO Limit '%s' invalid. Ignoring.", rvalue
);
3697 LIST_FOREACH(device_limits
, t
, c
->io_device_limits
) {
3698 if (path_equal(path
, t
->path
)) {
3705 CGroupIOLimitType ttype
;
3707 l
= new0(CGroupIODeviceLimit
, 1);
3711 l
->path
= TAKE_PTR(path
);
3712 for (ttype
= 0; ttype
< _CGROUP_IO_LIMIT_TYPE_MAX
; ttype
++)
3713 l
->limits
[ttype
] = cgroup_io_limit_defaults
[ttype
];
3715 LIST_PREPEND(device_limits
, c
->io_device_limits
, l
);
3718 l
->limits
[type
] = num
;
3723 int config_parse_blockio_weight(
3725 const char *filename
,
3727 const char *section
,
3728 unsigned section_line
,
3735 uint64_t *weight
= data
;
3742 r
= cg_blkio_weight_parse(rvalue
, weight
);
3744 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Block IO weight '%s' invalid. Ignoring.", rvalue
);
3751 int config_parse_blockio_device_weight(
3753 const char *filename
,
3755 const char *section
,
3756 unsigned section_line
,
3763 _cleanup_free_
char *path
= NULL
;
3764 CGroupBlockIODeviceWeight
*w
;
3765 CGroupContext
*c
= data
;
3775 if (isempty(rvalue
)) {
3776 while (c
->blockio_device_weights
)
3777 cgroup_context_free_blockio_device_weight(c
, c
->blockio_device_weights
);
3782 n
= strcspn(rvalue
, WHITESPACE
);
3783 weight
= rvalue
+ n
;
3784 weight
+= strspn(weight
, WHITESPACE
);
3786 if (isempty(weight
)) {
3787 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Expected block device and device weight. Ignoring.");
3791 path
= strndup(rvalue
, n
);
3795 if (!path_startswith(path
, "/dev") &&
3796 !path_startswith(path
, "/run/systemd/inaccessible/")) {
3797 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device node path '%s'. Ignoring.", path
);
3801 r
= cg_blkio_weight_parse(weight
, &u
);
3803 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Block IO weight '%s' invalid. Ignoring.", weight
);
3807 assert(u
!= CGROUP_BLKIO_WEIGHT_INVALID
);
3809 w
= new0(CGroupBlockIODeviceWeight
, 1);
3813 w
->path
= TAKE_PTR(path
);
3817 LIST_PREPEND(device_weights
, c
->blockio_device_weights
, w
);
3821 int config_parse_blockio_bandwidth(
3823 const char *filename
,
3825 const char *section
,
3826 unsigned section_line
,
3833 _cleanup_free_
char *path
= NULL
;
3834 CGroupBlockIODeviceBandwidth
*b
= NULL
, *t
;
3835 CGroupContext
*c
= data
;
3836 const char *bandwidth
;
3846 read
= streq("BlockIOReadBandwidth", lvalue
);
3848 if (isempty(rvalue
)) {
3849 LIST_FOREACH(device_bandwidths
, b
, c
->blockio_device_bandwidths
) {
3850 b
->rbps
= CGROUP_LIMIT_MAX
;
3851 b
->wbps
= CGROUP_LIMIT_MAX
;
3856 n
= strcspn(rvalue
, WHITESPACE
);
3857 bandwidth
= rvalue
+ n
;
3858 bandwidth
+= strspn(bandwidth
, WHITESPACE
);
3861 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Expected space separated pair of device node and bandwidth. Ignoring.");
3865 path
= strndup(rvalue
, n
);
3869 if (!path_startswith(path
, "/dev") &&
3870 !path_startswith(path
, "/run/systemd/inaccessible/")) {
3871 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device node path '%s'. Ignoring.", path
);
3875 r
= parse_size(bandwidth
, 1000, &bytes
);
3876 if (r
< 0 || bytes
<= 0) {
3877 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Block IO Bandwidth '%s' invalid. Ignoring.", rvalue
);
3881 LIST_FOREACH(device_bandwidths
, t
, c
->blockio_device_bandwidths
) {
3882 if (path_equal(path
, t
->path
)) {
3889 b
= new0(CGroupBlockIODeviceBandwidth
, 1);
3893 b
->path
= TAKE_PTR(path
);
3894 b
->rbps
= CGROUP_LIMIT_MAX
;
3895 b
->wbps
= CGROUP_LIMIT_MAX
;
3897 LIST_PREPEND(device_bandwidths
, c
->blockio_device_bandwidths
, b
);
3908 DEFINE_CONFIG_PARSE_ENUM(config_parse_job_mode
, job_mode
, JobMode
, "Failed to parse job mode");
3910 int config_parse_job_mode_isolate(
3912 const char *filename
,
3914 const char *section
,
3915 unsigned section_line
,
3929 r
= parse_boolean(rvalue
);
3931 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse boolean, ignoring: %s", rvalue
);
3935 log_notice("%s is deprecated. Please use OnFailureJobMode= instead", lvalue
);
3937 *m
= r
? JOB_ISOLATE
: JOB_REPLACE
;
3941 DEFINE_CONFIG_PARSE_ENUM(config_parse_runtime_preserve_mode
, exec_preserve_mode
, ExecPreserveMode
, "Failed to parse runtime directory preserve mode");
3943 int config_parse_exec_directories(
3945 const char *filename
,
3947 const char *section
,
3948 unsigned section_line
,
3965 if (isempty(rvalue
)) {
3966 /* Empty assignment resets the list */
3967 *rt
= strv_free(*rt
);
3971 for (p
= rvalue
;;) {
3972 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
3974 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
3978 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3979 "Invalid syntax, ignoring: %s", rvalue
);
3985 r
= unit_full_printf(u
, word
, &k
);
3987 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
3988 "Failed to resolve specifiers in \"%s\", ignoring: %m", word
);
3992 if (!path_is_normalized(k
) || path_is_absolute(k
)) {
3993 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
3994 "%s= path is not valid, ignoring assignment: %s", lvalue
, rvalue
);
3998 r
= strv_push(rt
, k
);
4005 int config_parse_set_status(
4007 const char *filename
,
4009 const char *section
,
4010 unsigned section_line
,
4018 const char *word
, *state
;
4020 ExitStatusSet
*status_set
= data
;
4027 /* Empty assignment resets the list */
4028 if (isempty(rvalue
)) {
4029 exit_status_set_free(status_set
);
4033 FOREACH_WORD(word
, l
, rvalue
, state
) {
4034 _cleanup_free_
char *temp
;
4038 temp
= strndup(word
, l
);
4042 r
= safe_atoi(temp
, &val
);
4044 val
= signal_from_string_try_harder(temp
);
4047 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse value, ignoring: %s", word
);
4050 set
= &status_set
->signal
;
4052 if (val
< 0 || val
> 255) {
4053 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Value %d is outside range 0-255, ignoring", val
);
4056 set
= &status_set
->status
;
4059 r
= set_ensure_allocated(set
, NULL
);
4063 r
= set_put(*set
, INT_TO_PTR(val
));
4065 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Unable to store: %s", word
);
4069 if (!isempty(state
))
4070 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Trailing garbage, ignoring.");
4075 int config_parse_namespace_path_strv(
4077 const char *filename
,
4079 const char *section
,
4080 unsigned section_line
,
4097 if (isempty(rvalue
)) {
4098 /* Empty assignment resets the list */
4099 *sv
= strv_free(*sv
);
4105 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
, *joined
= NULL
;
4107 bool ignore_enoent
= false, shall_prefix
= false;
4109 r
= extract_first_word(&cur
, &word
, NULL
, EXTRACT_QUOTES
);
4115 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
4119 if (!utf8_is_valid(word
)) {
4120 log_syntax_invalid_utf8(unit
, LOG_ERR
, filename
, line
, word
);
4125 if (startswith(w
, "-")) {
4126 ignore_enoent
= true;
4129 if (startswith(w
, "+")) {
4130 shall_prefix
= true;
4134 r
= unit_full_printf(u
, w
, &resolved
);
4136 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve specifiers in %s: %m", word
);
4140 if (!path_is_absolute(resolved
)) {
4141 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Not an absolute path, ignoring: %s", resolved
);
4145 path_kill_slashes(resolved
);
4147 joined
= strjoin(ignore_enoent
? "-" : "",
4148 shall_prefix
? "+" : "",
4151 r
= strv_push(sv
, joined
);
4161 int config_parse_temporary_filesystems(
4163 const char *filename
,
4165 const char *section
,
4166 unsigned section_line
,
4174 ExecContext
*c
= data
;
4183 if (isempty(rvalue
)) {
4184 /* Empty assignment resets the list */
4185 temporary_filesystem_free_many(c
->temporary_filesystems
, c
->n_temporary_filesystems
);
4186 c
->temporary_filesystems
= NULL
;
4187 c
->n_temporary_filesystems
= 0;
4193 _cleanup_free_
char *word
= NULL
, *path
= NULL
, *resolved
= NULL
;
4196 r
= extract_first_word(&cur
, &word
, NULL
, EXTRACT_QUOTES
);
4202 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
4207 r
= extract_first_word(&w
, &path
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4213 r
= unit_full_printf(u
, path
, &resolved
);
4215 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve specifiers in %s, ignoring: %m", word
);
4219 if (!path_is_absolute(resolved
)) {
4220 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Not an absolute path, ignoring: %s", resolved
);
4224 path_kill_slashes(resolved
);
4226 r
= temporary_filesystem_add(&c
->temporary_filesystems
, &c
->n_temporary_filesystems
, path
, w
);
4230 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse mount options, ignoring: %s", word
);
4238 int config_parse_bind_paths(
4240 const char *filename
,
4242 const char *section
,
4243 unsigned section_line
,
4250 ExecContext
*c
= data
;
4260 if (isempty(rvalue
)) {
4261 /* Empty assignment resets the list */
4262 bind_mount_free_many(c
->bind_mounts
, c
->n_bind_mounts
);
4263 c
->bind_mounts
= NULL
;
4264 c
->n_bind_mounts
= 0;
4270 _cleanup_free_
char *source
= NULL
, *destination
= NULL
;
4271 _cleanup_free_
char *sresolved
= NULL
, *dresolved
= NULL
;
4272 char *s
= NULL
, *d
= NULL
;
4273 bool rbind
= true, ignore_enoent
= false;
4275 r
= extract_first_word(&p
, &source
, ":" WHITESPACE
, EXTRACT_QUOTES
|EXTRACT_DONT_COALESCE_SEPARATORS
);
4281 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s: %s", lvalue
, rvalue
);
4285 r
= unit_full_printf(u
, source
, &sresolved
);
4287 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4288 "Failed to resolved specifiers in \"%s\", ignoring: %m", source
);
4294 ignore_enoent
= true;
4298 if (!utf8_is_valid(s
)) {
4299 log_syntax_invalid_utf8(unit
, LOG_ERR
, filename
, line
, s
);
4302 if (!path_is_absolute(s
)) {
4303 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Not an absolute source path, ignoring: %s", s
);
4307 path_kill_slashes(s
);
4309 /* Optionally, the destination is specified. */
4310 if (p
&& p
[-1] == ':') {
4311 r
= extract_first_word(&p
, &destination
, ":" WHITESPACE
, EXTRACT_QUOTES
|EXTRACT_DONT_COALESCE_SEPARATORS
);
4315 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s: %s", lvalue
, rvalue
);
4319 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Missing argument after ':': %s", rvalue
);
4323 r
= unit_full_printf(u
, destination
, &dresolved
);
4325 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4326 "Failed to resolved specifiers in \"%s\", ignoring: %m", destination
);
4330 if (!utf8_is_valid(dresolved
)) {
4331 log_syntax_invalid_utf8(unit
, LOG_ERR
, filename
, line
, dresolved
);
4334 if (!path_is_absolute(dresolved
)) {
4335 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Not an absolute destination path, ignoring: %s", dresolved
);
4339 d
= path_kill_slashes(dresolved
);
4341 /* Optionally, there's also a short option string specified */
4342 if (p
&& p
[-1] == ':') {
4343 _cleanup_free_
char *options
= NULL
;
4345 r
= extract_first_word(&p
, &options
, NULL
, EXTRACT_QUOTES
);
4349 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s: %s", lvalue
, rvalue
);
4353 if (isempty(options
) || streq(options
, "rbind"))
4355 else if (streq(options
, "norbind"))
4358 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid option string, ignoring setting: %s", options
);
4365 r
= bind_mount_add(&c
->bind_mounts
, &c
->n_bind_mounts
,
4369 .read_only
= !!strstr(lvalue
, "ReadOnly"),
4371 .ignore_enoent
= ignore_enoent
,
4380 int config_parse_no_new_privileges(
4382 const char *filename
,
4384 const char *section
,
4385 unsigned section_line
,
4392 ExecContext
*c
= data
;
4400 k
= parse_boolean(rvalue
);
4402 log_syntax(unit
, LOG_ERR
, filename
, line
, k
, "Failed to parse boolean value, ignoring: %s", rvalue
);
4406 c
->no_new_privileges
= k
;
4411 int config_parse_protect_home(
4413 const char *filename
,
4415 const char *section
,
4416 unsigned section_line
,
4423 ExecContext
*c
= data
;
4431 /* Our enum shall be a superset of booleans, hence first try
4432 * to parse as boolean, and then as enum */
4434 h
= parse_protect_home_or_bool(rvalue
);
4436 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse protect home value, ignoring: %s", rvalue
);
4440 c
->protect_home
= h
;
4445 int config_parse_protect_system(
4447 const char *filename
,
4449 const char *section
,
4450 unsigned section_line
,
4457 ExecContext
*c
= data
;
4465 /* Our enum shall be a superset of booleans, hence first try
4466 * to parse as boolean, and then as enum */
4468 s
= parse_protect_system_or_bool(rvalue
);
4470 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse protect system value, ignoring: %s", rvalue
);
4474 c
->protect_system
= s
;
4479 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_keyring_mode
, exec_keyring_mode
, ExecKeyringMode
, "Failed to parse keyring mode");
4481 int config_parse_job_timeout_sec(
4483 const char *filename
,
4485 const char *section
,
4486 unsigned section_line
,
4502 r
= parse_sec_fix_0(rvalue
, &usec
);
4504 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse JobTimeoutSec= parameter, ignoring: %s", rvalue
);
4508 /* If the user explicitly changed JobTimeoutSec= also change JobRunningTimeoutSec=, for compatibility with old
4509 * versions. If JobRunningTimeoutSec= was explicitly set, avoid this however as whatever the user picked should
4512 if (!u
->job_running_timeout_set
)
4513 u
->job_running_timeout
= usec
;
4515 u
->job_timeout
= usec
;
4520 int config_parse_job_running_timeout_sec(
4522 const char *filename
,
4524 const char *section
,
4525 unsigned section_line
,
4541 r
= parse_sec_fix_0(rvalue
, &usec
);
4543 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse JobRunningTimeoutSec= parameter, ignoring: %s", rvalue
);
4547 u
->job_running_timeout
= usec
;
4548 u
->job_running_timeout_set
= true;
4553 #define FOLLOW_MAX 8
4555 static int open_follow(char **filename
, FILE **_f
, Set
*names
, char **_final
) {
4566 /* This will update the filename pointer if the loaded file is
4567 * reached by a symlink. The old string will be freed. */
4570 char *target
, *name
;
4572 if (c
++ >= FOLLOW_MAX
)
4575 path_kill_slashes(*filename
);
4577 /* Add the file name we are currently looking at to
4578 * the names of this unit, but only if it is a valid
4580 name
= basename(*filename
);
4581 if (unit_name_is_valid(name
, UNIT_NAME_ANY
)) {
4583 id
= set_get(names
, name
);
4589 r
= set_consume(names
, id
);
4595 /* Try to open the file name, but don't if its a symlink */
4596 fd
= open(*filename
, O_RDONLY
|O_CLOEXEC
|O_NOCTTY
|O_NOFOLLOW
);
4603 /* Hmm, so this is a symlink. Let's read the name, and follow it manually */
4604 r
= readlink_and_make_absolute(*filename
, &target
);
4612 f
= fdopen(fd
, "re");
4624 static int merge_by_names(Unit
**u
, Set
*names
, const char *id
) {
4632 /* Let's try to add in all symlink names we found */
4633 while ((k
= set_steal_first(names
))) {
4635 /* First try to merge in the other name into our
4637 r
= unit_merge_by_name(*u
, k
);
4641 /* Hmm, we couldn't merge the other unit into
4642 * ours? Then let's try it the other way
4645 /* If the symlink name we are looking at is unit template, then
4646 we must search for instance of this template */
4647 if (unit_name_is_valid(k
, UNIT_NAME_TEMPLATE
) && (*u
)->instance
) {
4648 _cleanup_free_
char *instance
= NULL
;
4650 r
= unit_name_replace_instance(k
, (*u
)->instance
, &instance
);
4654 other
= manager_get_unit((*u
)->manager
, instance
);
4656 other
= manager_get_unit((*u
)->manager
, k
);
4661 r
= unit_merge(other
, *u
);
4664 return merge_by_names(u
, names
, NULL
);
4672 unit_choose_id(*u
, id
);
4680 static int load_from_path(Unit
*u
, const char *path
) {
4681 _cleanup_set_free_free_ Set
*symlink_names
= NULL
;
4682 _cleanup_fclose_
FILE *f
= NULL
;
4683 _cleanup_free_
char *filename
= NULL
;
4692 symlink_names
= set_new(&string_hash_ops
);
4696 if (path_is_absolute(path
)) {
4698 filename
= strdup(path
);
4702 r
= open_follow(&filename
, &f
, symlink_names
, &id
);
4704 filename
= mfree(filename
);
4712 STRV_FOREACH(p
, u
->manager
->lookup_paths
.search_path
) {
4714 /* Instead of opening the path right away, we manually
4715 * follow all symlinks and add their name to our unit
4716 * name set while doing so */
4717 filename
= path_make_absolute(path
, *p
);
4721 if (u
->manager
->unit_path_cache
&&
4722 !set_get(u
->manager
->unit_path_cache
, filename
))
4725 r
= open_follow(&filename
, &f
, symlink_names
, &id
);
4728 filename
= mfree(filename
);
4730 /* ENOENT means that the file is missing or is a dangling symlink.
4731 * ENOTDIR means that one of paths we expect to be is a directory
4732 * is not a directory, we should just ignore that.
4733 * EACCES means that the directory or file permissions are wrong.
4736 log_debug_errno(r
, "Cannot access \"%s\": %m", filename
);
4737 else if (!IN_SET(r
, -ENOENT
, -ENOTDIR
))
4740 /* Empty the symlink names for the next run */
4741 set_clear_free(symlink_names
);
4746 /* Hmm, no suitable file found? */
4749 if (!unit_type_may_alias(u
->type
) && set_size(symlink_names
) > 1) {
4750 log_unit_warning(u
, "Unit type of %s does not support alias names, refusing loading via symlink.", u
->id
);
4755 r
= merge_by_names(&merged
, symlink_names
, id
);
4760 u
->load_state
= UNIT_MERGED
;
4764 if (fstat(fileno(f
), &st
) < 0)
4767 if (null_or_empty(&st
)) {
4768 u
->load_state
= UNIT_MASKED
;
4769 u
->fragment_mtime
= 0;
4771 u
->load_state
= UNIT_LOADED
;
4772 u
->fragment_mtime
= timespec_load(&st
.st_mtim
);
4774 /* Now, parse the file contents */
4775 r
= config_parse(u
->id
, filename
, f
,
4776 UNIT_VTABLE(u
)->sections
,
4777 config_item_perf_lookup
, load_fragment_gperf_lookup
,
4778 CONFIG_PARSE_ALLOW_INCLUDE
, u
);
4783 free_and_replace(u
->fragment_path
, filename
);
4785 if (u
->source_path
) {
4786 if (stat(u
->source_path
, &st
) >= 0)
4787 u
->source_mtime
= timespec_load(&st
.st_mtim
);
4789 u
->source_mtime
= 0;
4795 int unit_load_fragment(Unit
*u
) {
4801 assert(u
->load_state
== UNIT_STUB
);
4805 u
->load_state
= UNIT_LOADED
;
4809 /* First, try to find the unit under its id. We always look
4810 * for unit files in the default directories, to make it easy
4811 * to override things by placing things in /etc/systemd/system */
4812 r
= load_from_path(u
, u
->id
);
4816 /* Try to find an alias we can load this with */
4817 if (u
->load_state
== UNIT_STUB
) {
4818 SET_FOREACH(t
, u
->names
, i
) {
4823 r
= load_from_path(u
, t
);
4827 if (u
->load_state
!= UNIT_STUB
)
4832 /* And now, try looking for it under the suggested (originally linked) path */
4833 if (u
->load_state
== UNIT_STUB
&& u
->fragment_path
) {
4835 r
= load_from_path(u
, u
->fragment_path
);
4839 if (u
->load_state
== UNIT_STUB
)
4840 /* Hmm, this didn't work? Then let's get rid
4841 * of the fragment path stored for us, so that
4842 * we don't point to an invalid location. */
4843 u
->fragment_path
= mfree(u
->fragment_path
);
4846 /* Look for a template */
4847 if (u
->load_state
== UNIT_STUB
&& u
->instance
) {
4848 _cleanup_free_
char *k
= NULL
;
4850 r
= unit_name_template(u
->id
, &k
);
4854 r
= load_from_path(u
, k
);
4857 log_unit_notice(u
, "Unit configuration has fatal error, unit will not be started.");
4861 if (u
->load_state
== UNIT_STUB
) {
4862 SET_FOREACH(t
, u
->names
, i
) {
4863 _cleanup_free_
char *z
= NULL
;
4868 r
= unit_name_template(t
, &z
);
4872 r
= load_from_path(u
, z
);
4876 if (u
->load_state
!= UNIT_STUB
)
4885 void unit_dump_config_items(FILE *f
) {
4886 static const struct {
4887 const ConfigParserCallback callback
;
4890 #if !HAVE_SYSV_COMPAT || !HAVE_SECCOMP || !HAVE_PAM || !HAVE_SELINUX || !ENABLE_SMACK || !HAVE_APPARMOR
4891 { config_parse_warn_compat
, "NOTSUPPORTED" },
4893 { config_parse_int
, "INTEGER" },
4894 { config_parse_unsigned
, "UNSIGNED" },
4895 { config_parse_iec_size
, "SIZE" },
4896 { config_parse_iec_uint64
, "SIZE" },
4897 { config_parse_si_size
, "SIZE" },
4898 { config_parse_bool
, "BOOLEAN" },
4899 { config_parse_string
, "STRING" },
4900 { config_parse_path
, "PATH" },
4901 { config_parse_unit_path_printf
, "PATH" },
4902 { config_parse_strv
, "STRING [...]" },
4903 { config_parse_exec_nice
, "NICE" },
4904 { config_parse_exec_oom_score_adjust
, "OOMSCOREADJUST" },
4905 { config_parse_exec_io_class
, "IOCLASS" },
4906 { config_parse_exec_io_priority
, "IOPRIORITY" },
4907 { config_parse_exec_cpu_sched_policy
, "CPUSCHEDPOLICY" },
4908 { config_parse_exec_cpu_sched_prio
, "CPUSCHEDPRIO" },
4909 { config_parse_exec_cpu_affinity
, "CPUAFFINITY" },
4910 { config_parse_mode
, "MODE" },
4911 { config_parse_unit_env_file
, "FILE" },
4912 { config_parse_exec_output
, "OUTPUT" },
4913 { config_parse_exec_input
, "INPUT" },
4914 { config_parse_log_facility
, "FACILITY" },
4915 { config_parse_log_level
, "LEVEL" },
4916 { config_parse_exec_secure_bits
, "SECUREBITS" },
4917 { config_parse_capability_set
, "BOUNDINGSET" },
4918 { config_parse_limit
, "LIMIT" },
4919 { config_parse_unit_deps
, "UNIT [...]" },
4920 { config_parse_exec
, "PATH [ARGUMENT [...]]" },
4921 { config_parse_service_type
, "SERVICETYPE" },
4922 { config_parse_service_restart
, "SERVICERESTART" },
4923 #if HAVE_SYSV_COMPAT
4924 { config_parse_sysv_priority
, "SYSVPRIORITY" },
4926 { config_parse_kill_mode
, "KILLMODE" },
4927 { config_parse_signal
, "SIGNAL" },
4928 { config_parse_socket_listen
, "SOCKET [...]" },
4929 { config_parse_socket_bind
, "SOCKETBIND" },
4930 { config_parse_socket_bindtodevice
, "NETWORKINTERFACE" },
4931 { config_parse_sec
, "SECONDS" },
4932 { config_parse_nsec
, "NANOSECONDS" },
4933 { config_parse_namespace_path_strv
, "PATH [...]" },
4934 { config_parse_bind_paths
, "PATH[:PATH[:OPTIONS]] [...]" },
4935 { config_parse_unit_requires_mounts_for
, "PATH [...]" },
4936 { config_parse_exec_mount_flags
, "MOUNTFLAG [...]" },
4937 { config_parse_unit_string_printf
, "STRING" },
4938 { config_parse_trigger_unit
, "UNIT" },
4939 { config_parse_timer
, "TIMER" },
4940 { config_parse_path_spec
, "PATH" },
4941 { config_parse_notify_access
, "ACCESS" },
4942 { config_parse_ip_tos
, "TOS" },
4943 { config_parse_unit_condition_path
, "CONDITION" },
4944 { config_parse_unit_condition_string
, "CONDITION" },
4945 { config_parse_unit_condition_null
, "CONDITION" },
4946 { config_parse_unit_slice
, "SLICE" },
4947 { config_parse_documentation
, "URL" },
4948 { config_parse_service_timeout
, "SECONDS" },
4949 { config_parse_emergency_action
, "ACTION" },
4950 { config_parse_set_status
, "STATUS" },
4951 { config_parse_service_sockets
, "SOCKETS" },
4952 { config_parse_environ
, "ENVIRON" },
4954 { config_parse_syscall_filter
, "SYSCALLS" },
4955 { config_parse_syscall_archs
, "ARCHS" },
4956 { config_parse_syscall_errno
, "ERRNO" },
4957 { config_parse_address_families
, "FAMILIES" },
4958 { config_parse_restrict_namespaces
, "NAMESPACES" },
4960 { config_parse_cpu_shares
, "SHARES" },
4961 { config_parse_cpu_weight
, "WEIGHT" },
4962 { config_parse_memory_limit
, "LIMIT" },
4963 { config_parse_device_allow
, "DEVICE" },
4964 { config_parse_device_policy
, "POLICY" },
4965 { config_parse_io_limit
, "LIMIT" },
4966 { config_parse_io_weight
, "WEIGHT" },
4967 { config_parse_io_device_weight
, "DEVICEWEIGHT" },
4968 { config_parse_blockio_bandwidth
, "BANDWIDTH" },
4969 { config_parse_blockio_weight
, "WEIGHT" },
4970 { config_parse_blockio_device_weight
, "DEVICEWEIGHT" },
4971 { config_parse_long
, "LONG" },
4972 { config_parse_socket_service
, "SERVICE" },
4974 { config_parse_exec_selinux_context
, "LABEL" },
4976 { config_parse_job_mode
, "MODE" },
4977 { config_parse_job_mode_isolate
, "BOOLEAN" },
4978 { config_parse_personality
, "PERSONALITY" },
4981 const char *prev
= NULL
;
4986 NULSTR_FOREACH(i
, load_fragment_gperf_nulstr
) {
4987 const char *rvalue
= "OTHER", *lvalue
;
4991 const ConfigPerfItem
*p
;
4993 assert_se(p
= load_fragment_gperf_lookup(i
, strlen(i
)));
4995 dot
= strchr(i
, '.');
4996 lvalue
= dot
? dot
+ 1 : i
;
5000 if (!prev
|| !strneq(prev
, i
, prefix_len
+1)) {
5004 fprintf(f
, "[%.*s]\n", (int) prefix_len
, i
);
5007 for (j
= 0; j
< ELEMENTSOF(table
); j
++)
5008 if (p
->parse
== table
[j
].callback
) {
5009 rvalue
= table
[j
].rvalue
;
5013 fprintf(f
, "%s=%s\n", lvalue
, rvalue
);