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 path contains special characters%s: %s",
643 ignore
? ", ignoring" : "", rvalue
);
644 return ignore
? 0 : -ENOEXEC
;
646 if (!path_is_absolute(path
)) {
647 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
648 "Executable path is not absolute%s: %s",
649 ignore
? ", ignoring" : "", rvalue
);
650 return ignore
? 0 : -ENOEXEC
;
652 if (endswith(path
, "/")) {
653 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
654 "Executable path specifies a directory%s: %s",
655 ignore
? ", ignoring" : "", rvalue
);
656 return ignore
? 0 : -ENOEXEC
;
659 if (!separate_argv0
) {
662 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
672 path_kill_slashes(path
);
674 while (!isempty(p
)) {
675 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
677 /* Check explicitly for an unquoted semicolon as
678 * command separator token. */
679 if (p
[0] == ';' && (!p
[1] || strchr(WHITESPACE
, p
[1]))) {
681 p
+= strspn(p
, WHITESPACE
);
686 /* Check for \; explicitly, to not confuse it with \\; or "\;" or "\\;" etc.
687 * extract_first_word() would return the same for all of those. */
688 if (p
[0] == '\\' && p
[1] == ';' && (!p
[2] || strchr(WHITESPACE
, p
[2]))) {
692 p
+= strspn(p
, WHITESPACE
);
694 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
705 r
= extract_first_word_and_warn(&p
, &word
, NULL
, EXTRACT_QUOTES
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
709 return ignore
? 0 : -ENOEXEC
;
711 r
= unit_full_printf(u
, word
, &resolved
);
713 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
714 "Failed to resolve unit specifiers on %s%s: %m",
715 word
, ignore
? ", ignoring" : "");
716 return ignore
? 0 : -ENOEXEC
;
719 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
722 n
[nlen
++] = TAKE_PTR(resolved
);
727 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
728 "Empty executable name or zeroeth argument%s: %s",
729 ignore
? ", ignoring" : "", rvalue
);
730 return ignore
? 0 : -ENOEXEC
;
733 nce
= new0(ExecCommand
, 1);
737 nce
->argv
= TAKE_PTR(n
);
738 nce
->path
= TAKE_PTR(path
);
741 exec_command_append_list(e
, nce
);
743 /* Do not _cleanup_free_ these. */
752 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_type
, service_type
, ServiceType
, "Failed to parse service type");
753 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart
, service_restart
, ServiceRestart
, "Failed to parse service restart specifier");
755 int config_parse_socket_bindtodevice(
757 const char *filename
,
760 unsigned section_line
,
775 if (rvalue
[0] && !streq(rvalue
, "*")) {
776 if (!ifname_valid(rvalue
)) {
777 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Interface name is invalid, ignoring: %s", rvalue
);
787 free(s
->bind_to_device
);
788 s
->bind_to_device
= n
;
793 int config_parse_exec_input(
795 const char *filename
,
798 unsigned section_line
,
805 ExecContext
*c
= data
;
816 n
= startswith(rvalue
, "fd:");
818 _cleanup_free_
char *resolved
= NULL
;
820 r
= unit_full_printf(u
, n
, &resolved
);
822 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers on %s: %m", n
);
824 if (isempty(resolved
))
825 resolved
= mfree(resolved
);
826 else if (!fdname_is_valid(resolved
)) {
827 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name: %s", resolved
);
831 free_and_replace(c
->stdio_fdname
[STDIN_FILENO
], resolved
);
833 ei
= EXEC_INPUT_NAMED_FD
;
835 } else if ((n
= startswith(rvalue
, "file:"))) {
836 _cleanup_free_
char *resolved
= NULL
;
838 r
= unit_full_printf(u
, n
, &resolved
);
840 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers on %s: %m", n
);
842 if (!path_is_absolute(resolved
)) {
843 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "file: requires an absolute path name: %s", resolved
);
847 if (!path_is_normalized(resolved
)) {
848 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "file: requires a normalized path name: %s", resolved
);
852 free_and_replace(c
->stdio_file
[STDIN_FILENO
], resolved
);
854 ei
= EXEC_INPUT_FILE
;
857 ei
= exec_input_from_string(rvalue
);
859 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse input specifier, ignoring: %s", rvalue
);
868 int config_parse_exec_input_text(
870 const char *filename
,
873 unsigned section_line
,
880 _cleanup_free_
char *unescaped
= NULL
, *resolved
= NULL
;
881 ExecContext
*c
= data
;
892 if (isempty(rvalue
)) {
893 /* Reset if the empty string is assigned */
894 c
->stdin_data
= mfree(c
->stdin_data
);
895 c
->stdin_data_size
= 0;
899 r
= cunescape(rvalue
, 0, &unescaped
);
901 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to decode C escaped text: %s", rvalue
);
903 r
= unit_full_printf(u
, unescaped
, &resolved
);
905 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve specifiers: %s", unescaped
);
907 sz
= strlen(resolved
);
908 if (c
->stdin_data_size
+ sz
+ 1 < c
->stdin_data_size
|| /* check for overflow */
909 c
->stdin_data_size
+ sz
+ 1 > EXEC_STDIN_DATA_MAX
) {
910 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
);
914 p
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
+ 1);
918 *((char*) mempcpy((char*) p
+ c
->stdin_data_size
, resolved
, sz
)) = '\n';
921 c
->stdin_data_size
+= sz
+ 1;
926 int config_parse_exec_input_data(
928 const char *filename
,
931 unsigned section_line
,
938 _cleanup_free_
void *p
= NULL
;
939 ExecContext
*c
= data
;
949 if (isempty(rvalue
)) {
950 /* Reset if the empty string is assigned */
951 c
->stdin_data
= mfree(c
->stdin_data
);
952 c
->stdin_data_size
= 0;
956 r
= unbase64mem(rvalue
, (size_t) -1, &p
, &sz
);
958 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to decode base64 data, ignoring: %s", rvalue
);
962 if (c
->stdin_data_size
+ sz
< c
->stdin_data_size
|| /* check for overflow */
963 c
->stdin_data_size
+ sz
> EXEC_STDIN_DATA_MAX
) {
964 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
);
968 q
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
);
972 memcpy((uint8_t*) q
+ c
->stdin_data_size
, p
, sz
);
975 c
->stdin_data_size
+= sz
;
980 int config_parse_exec_output(
982 const char *filename
,
985 unsigned section_line
,
992 _cleanup_free_
char *resolved
= NULL
;
994 ExecContext
*c
= data
;
1005 n
= startswith(rvalue
, "fd:");
1007 r
= unit_full_printf(u
, n
, &resolved
);
1009 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers on %s: %m", n
);
1011 if (isempty(resolved
))
1012 resolved
= mfree(resolved
);
1013 else if (!fdname_is_valid(resolved
)) {
1014 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name: %s", resolved
);
1018 eo
= EXEC_OUTPUT_NAMED_FD
;
1020 } else if ((n
= startswith(rvalue
, "file:"))) {
1022 r
= unit_full_printf(u
, n
, &resolved
);
1024 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers on %s: %m", n
);
1026 if (!path_is_absolute(resolved
)) {
1027 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "file: requires an absolute path name: %s", resolved
);
1031 if (!path_is_normalized(resolved
)) {
1032 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "file: requires a normalized path name, ignoring: %s", resolved
);
1036 eo
= EXEC_OUTPUT_FILE
;
1039 eo
= exec_output_from_string(rvalue
);
1041 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse output specifier, ignoring: %s", rvalue
);
1046 if (streq(lvalue
, "StandardOutput")) {
1047 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1048 free_and_replace(c
->stdio_fdname
[STDOUT_FILENO
], resolved
);
1050 free_and_replace(c
->stdio_file
[STDOUT_FILENO
], resolved
);
1055 assert(streq(lvalue
, "StandardError"));
1057 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1058 free_and_replace(c
->stdio_fdname
[STDERR_FILENO
], resolved
);
1060 free_and_replace(c
->stdio_file
[STDERR_FILENO
], resolved
);
1068 int config_parse_exec_io_class(const char *unit
,
1069 const char *filename
,
1071 const char *section
,
1072 unsigned section_line
,
1079 ExecContext
*c
= data
;
1087 x
= ioprio_class_from_string(rvalue
);
1089 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse IO scheduling class, ignoring: %s", rvalue
);
1093 c
->ioprio
= IOPRIO_PRIO_VALUE(x
, IOPRIO_PRIO_DATA(c
->ioprio
));
1094 c
->ioprio_set
= true;
1099 int config_parse_exec_io_priority(const char *unit
,
1100 const char *filename
,
1102 const char *section
,
1103 unsigned section_line
,
1110 ExecContext
*c
= data
;
1118 r
= ioprio_parse_priority(rvalue
, &i
);
1120 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse IO priority, ignoring: %s", rvalue
);
1124 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_PRIO_CLASS(c
->ioprio
), i
);
1125 c
->ioprio_set
= true;
1130 int config_parse_exec_cpu_sched_policy(const char *unit
,
1131 const char *filename
,
1133 const char *section
,
1134 unsigned section_line
,
1142 ExecContext
*c
= data
;
1150 x
= sched_policy_from_string(rvalue
);
1152 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse CPU scheduling policy, ignoring: %s", rvalue
);
1156 c
->cpu_sched_policy
= x
;
1157 /* Moving to or from real-time policy? We need to adjust the priority */
1158 c
->cpu_sched_priority
= CLAMP(c
->cpu_sched_priority
, sched_get_priority_min(x
), sched_get_priority_max(x
));
1159 c
->cpu_sched_set
= true;
1164 int config_parse_exec_cpu_sched_prio(const char *unit
,
1165 const char *filename
,
1167 const char *section
,
1168 unsigned section_line
,
1175 ExecContext
*c
= data
;
1183 r
= safe_atoi(rvalue
, &i
);
1185 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse CPU scheduling policy, ignoring: %s", rvalue
);
1189 /* On Linux RR/FIFO range from 1 to 99 and OTHER/BATCH may only be 0 */
1190 min
= sched_get_priority_min(c
->cpu_sched_policy
);
1191 max
= sched_get_priority_max(c
->cpu_sched_policy
);
1193 if (i
< min
|| i
> max
) {
1194 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "CPU scheduling priority is out of range, ignoring: %s", rvalue
);
1198 c
->cpu_sched_priority
= i
;
1199 c
->cpu_sched_set
= true;
1204 int config_parse_exec_cpu_affinity(const char *unit
,
1205 const char *filename
,
1207 const char *section
,
1208 unsigned section_line
,
1215 ExecContext
*c
= data
;
1216 _cleanup_cpu_free_ cpu_set_t
*cpuset
= NULL
;
1224 ncpus
= parse_cpu_set_and_warn(rvalue
, &cpuset
, unit
, filename
, line
, lvalue
);
1229 /* An empty assignment resets the CPU list */
1230 c
->cpuset
= cpu_set_mfree(c
->cpuset
);
1231 c
->cpuset_ncpus
= 0;
1236 c
->cpuset
= TAKE_PTR(cpuset
);
1237 c
->cpuset_ncpus
= (unsigned) ncpus
;
1241 if (c
->cpuset_ncpus
< (unsigned) ncpus
) {
1242 CPU_OR_S(CPU_ALLOC_SIZE(c
->cpuset_ncpus
), cpuset
, c
->cpuset
, cpuset
);
1243 CPU_FREE(c
->cpuset
);
1244 c
->cpuset
= TAKE_PTR(cpuset
);
1245 c
->cpuset_ncpus
= (unsigned) ncpus
;
1249 CPU_OR_S(CPU_ALLOC_SIZE((unsigned) ncpus
), c
->cpuset
, c
->cpuset
, cpuset
);
1254 int config_parse_exec_secure_bits(const char *unit
,
1255 const char *filename
,
1257 const char *section
,
1258 unsigned section_line
,
1265 ExecContext
*c
= data
;
1273 if (isempty(rvalue
)) {
1274 /* An empty assignment resets the field */
1279 r
= secure_bits_from_string(rvalue
);
1283 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1284 "Invalid syntax, ignoring: %s", rvalue
);
1293 int config_parse_capability_set(
1295 const char *filename
,
1297 const char *section
,
1298 unsigned section_line
,
1305 uint64_t *capability_set
= data
;
1306 uint64_t sum
= 0, initial
= 0;
1307 bool invert
= false;
1315 if (rvalue
[0] == '~') {
1320 if (streq(lvalue
, "CapabilityBoundingSet"))
1321 initial
= CAP_ALL
; /* initialized to all bits on */
1322 /* else "AmbientCapabilities" initialized to all bits off */
1324 r
= capability_set_from_string(rvalue
, &sum
);
1328 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse word: %s", rvalue
);
1332 if (sum
== 0 || *capability_set
== initial
)
1333 /* "", "~" or uninitialized data -> replace */
1334 *capability_set
= invert
? ~sum
: sum
;
1336 /* previous data -> merge */
1338 *capability_set
&= ~sum
;
1340 *capability_set
|= sum
;
1346 int config_parse_limit(
1348 const char *filename
,
1350 const char *section
,
1351 unsigned section_line
,
1358 struct rlimit
**rl
= data
, d
= {};
1366 r
= rlimit_parse(ltype
, rvalue
, &d
);
1368 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Soft resource limit chosen higher than hard limit, ignoring: %s", rvalue
);
1372 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse resource value, ignoring: %s", rvalue
);
1379 rl
[ltype
] = newdup(struct rlimit
, &d
, 1);
1387 #if HAVE_SYSV_COMPAT
1388 int config_parse_sysv_priority(const char *unit
,
1389 const char *filename
,
1391 const char *section
,
1392 unsigned section_line
,
1399 int *priority
= data
;
1407 r
= safe_atoi(rvalue
, &i
);
1408 if (r
< 0 || i
< 0) {
1409 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse SysV start priority, ignoring: %s", rvalue
);
1413 *priority
= (int) i
;
1418 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_utmp_mode
, exec_utmp_mode
, ExecUtmpMode
, "Failed to parse utmp mode");
1419 DEFINE_CONFIG_PARSE_ENUM(config_parse_kill_mode
, kill_mode
, KillMode
, "Failed to parse kill mode");
1421 int config_parse_exec_mount_flags(
1423 const char *filename
,
1425 const char *section
,
1426 unsigned section_line
,
1434 ExecContext
*c
= data
;
1442 r
= mount_propagation_flags_from_string(rvalue
, &c
->mount_flags
);
1444 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse mount flag %s, ignoring.", rvalue
);
1449 int config_parse_exec_selinux_context(
1451 const char *filename
,
1453 const char *section
,
1454 unsigned section_line
,
1461 ExecContext
*c
= data
;
1472 if (isempty(rvalue
)) {
1473 c
->selinux_context
= mfree(c
->selinux_context
);
1474 c
->selinux_context_ignore
= false;
1478 if (rvalue
[0] == '-') {
1484 r
= unit_full_printf(u
, rvalue
, &k
);
1486 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1487 "Failed to resolve specifiers%s: %m",
1488 ignore
? ", ignoring" : "");
1489 return ignore
? 0 : -ENOEXEC
;
1492 free(c
->selinux_context
);
1493 c
->selinux_context
= k
;
1494 c
->selinux_context_ignore
= ignore
;
1499 int config_parse_exec_apparmor_profile(
1501 const char *filename
,
1503 const char *section
,
1504 unsigned section_line
,
1511 ExecContext
*c
= data
;
1522 if (isempty(rvalue
)) {
1523 c
->apparmor_profile
= mfree(c
->apparmor_profile
);
1524 c
->apparmor_profile_ignore
= false;
1528 if (rvalue
[0] == '-') {
1534 r
= unit_full_printf(u
, rvalue
, &k
);
1536 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1537 "Failed to resolve specifiers%s: %m",
1538 ignore
? ", ignoring" : "");
1539 return ignore
? 0 : -ENOEXEC
;
1542 free(c
->apparmor_profile
);
1543 c
->apparmor_profile
= k
;
1544 c
->apparmor_profile_ignore
= ignore
;
1549 int config_parse_exec_smack_process_label(
1551 const char *filename
,
1553 const char *section
,
1554 unsigned section_line
,
1561 ExecContext
*c
= data
;
1572 if (isempty(rvalue
)) {
1573 c
->smack_process_label
= mfree(c
->smack_process_label
);
1574 c
->smack_process_label_ignore
= false;
1578 if (rvalue
[0] == '-') {
1584 r
= unit_full_printf(u
, rvalue
, &k
);
1586 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1587 "Failed to resolve specifiers%s: %m",
1588 ignore
? ", ignoring" : "");
1589 return ignore
? 0 : -ENOEXEC
;
1592 free(c
->smack_process_label
);
1593 c
->smack_process_label
= k
;
1594 c
->smack_process_label_ignore
= ignore
;
1599 int config_parse_timer(const char *unit
,
1600 const char *filename
,
1602 const char *section
,
1603 unsigned section_line
,
1614 CalendarSpec
*c
= NULL
;
1616 _cleanup_free_
char *k
= NULL
;
1624 if (isempty(rvalue
)) {
1625 /* Empty assignment resets list */
1626 timer_free_values(t
);
1630 b
= timer_base_from_string(lvalue
);
1632 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse timer base, ignoring: %s", lvalue
);
1636 r
= unit_full_printf(u
, rvalue
, &k
);
1638 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
1642 if (b
== TIMER_CALENDAR
) {
1643 if (calendar_spec_from_string(k
, &c
) < 0) {
1644 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse calendar specification, ignoring: %s", k
);
1648 if (parse_sec(k
, &usec
) < 0) {
1649 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse timer value, ignoring: %s", k
);
1654 v
= new0(TimerValue
, 1);
1656 calendar_spec_free(c
);
1662 v
->calendar_spec
= c
;
1664 LIST_PREPEND(value
, t
->values
, v
);
1669 int config_parse_trigger_unit(
1671 const char *filename
,
1673 const char *section
,
1674 unsigned section_line
,
1681 _cleanup_free_
char *p
= NULL
;
1691 if (!hashmap_isempty(u
->dependencies
[UNIT_TRIGGERS
])) {
1692 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Multiple units to trigger specified, ignoring: %s", rvalue
);
1696 r
= unit_name_printf(u
, rvalue
, &p
);
1698 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve specifiers, ignoring: %m");
1702 type
= unit_name_to_type(p
);
1704 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit type not valid, ignoring: %s", rvalue
);
1707 if (unit_has_name(u
, p
)) {
1708 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Units cannot trigger themselves, ignoring: %s", rvalue
);
1712 r
= unit_add_two_dependencies_by_name(u
, UNIT_BEFORE
, UNIT_TRIGGERS
, p
, NULL
, true, UNIT_DEPENDENCY_FILE
);
1714 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add trigger on %s, ignoring: %m", p
);
1721 int config_parse_path_spec(const char *unit
,
1722 const char *filename
,
1724 const char *section
,
1725 unsigned section_line
,
1735 _cleanup_free_
char *k
= NULL
;
1743 if (isempty(rvalue
)) {
1744 /* Empty assignment clears list */
1749 b
= path_type_from_string(lvalue
);
1751 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse path type, ignoring: %s", lvalue
);
1755 r
= unit_full_printf(UNIT(p
), rvalue
, &k
);
1757 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers on %s. Ignoring.", rvalue
);
1761 if (!path_is_absolute(k
)) {
1762 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Path is not absolute, ignoring: %s", k
);
1766 s
= new0(PathSpec
, 1);
1771 s
->path
= path_kill_slashes(k
);
1776 LIST_PREPEND(spec
, p
->specs
, s
);
1781 int config_parse_socket_service(
1783 const char *filename
,
1785 const char *section
,
1786 unsigned section_line
,
1793 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1794 _cleanup_free_
char *p
= NULL
;
1804 r
= unit_name_printf(UNIT(s
), rvalue
, &p
);
1806 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve specifiers: %s", rvalue
);
1810 if (!endswith(p
, ".service")) {
1811 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit must be of type service: %s", rvalue
);
1815 r
= manager_load_unit(UNIT(s
)->manager
, p
, NULL
, &error
, &x
);
1817 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to load unit %s: %s", rvalue
, bus_error_message(&error
, r
));
1821 unit_ref_set(&s
->service
, UNIT(s
), x
);
1826 int config_parse_fdname(
1828 const char *filename
,
1830 const char *section
,
1831 unsigned section_line
,
1838 _cleanup_free_
char *p
= NULL
;
1847 if (isempty(rvalue
)) {
1848 s
->fdname
= mfree(s
->fdname
);
1852 r
= unit_full_printf(UNIT(s
), rvalue
, &p
);
1854 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve specifiers, ignoring: %s", rvalue
);
1858 if (!fdname_is_valid(p
)) {
1859 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", p
);
1863 return free_and_replace(s
->fdname
, p
);
1866 int config_parse_service_sockets(
1868 const char *filename
,
1870 const char *section
,
1871 unsigned section_line
,
1889 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
1891 r
= extract_first_word(&p
, &word
, NULL
, 0);
1897 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Trailing garbage in sockets, ignoring: %s", rvalue
);
1901 r
= unit_name_printf(UNIT(s
), word
, &k
);
1903 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve specifiers, ignoring: %m");
1907 if (!endswith(k
, ".socket")) {
1908 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit must be of type socket, ignoring: %s", k
);
1912 r
= unit_add_two_dependencies_by_name(UNIT(s
), UNIT_WANTS
, UNIT_AFTER
, k
, NULL
, true, UNIT_DEPENDENCY_FILE
);
1914 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
1916 r
= unit_add_dependency_by_name(UNIT(s
), UNIT_TRIGGERED_BY
, k
, NULL
, true, UNIT_DEPENDENCY_FILE
);
1918 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
1924 int config_parse_bus_name(
1926 const char *filename
,
1928 const char *section
,
1929 unsigned section_line
,
1936 _cleanup_free_
char *k
= NULL
;
1945 r
= unit_full_printf(u
, rvalue
, &k
);
1947 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers on %s, ignoring: %m", rvalue
);
1951 if (!service_name_is_valid(k
)) {
1952 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid bus name %s, ignoring.", k
);
1956 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
1959 int config_parse_service_timeout(
1961 const char *filename
,
1963 const char *section
,
1964 unsigned section_line
,
1971 Service
*s
= userdata
;
1980 /* This is called for three cases: TimeoutSec=, TimeoutStopSec= and TimeoutStartSec=. */
1982 r
= parse_sec(rvalue
, &usec
);
1984 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
1988 /* Traditionally, these options accepted 0 to disable the timeouts. However, a timeout of 0 suggests it happens
1989 * immediately, hence fix this to become USEC_INFINITY instead. This is in-line with how we internally handle
1990 * all other timeouts. */
1992 usec
= USEC_INFINITY
;
1994 if (!streq(lvalue
, "TimeoutStopSec")) {
1995 s
->start_timeout_defined
= true;
1996 s
->timeout_start_usec
= usec
;
1999 if (!streq(lvalue
, "TimeoutStartSec"))
2000 s
->timeout_stop_usec
= usec
;
2005 int config_parse_sec_fix_0(
2007 const char *filename
,
2009 const char *section
,
2010 unsigned section_line
,
2017 usec_t
*usec
= data
;
2025 /* This is pretty much like config_parse_sec(), except that this treats a time of 0 as infinity, for
2026 * compatibility with older versions of systemd where 0 instead of infinity was used as indicator to turn off a
2029 r
= parse_sec_fix_0(rvalue
, usec
);
2031 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
2038 int config_parse_user_group(
2040 const char *filename
,
2042 const char *section
,
2043 unsigned section_line
,
2050 char **user
= data
, *n
;
2059 if (isempty(rvalue
))
2062 _cleanup_free_
char *k
= NULL
;
2064 r
= unit_full_printf(u
, rvalue
, &k
);
2066 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", rvalue
);
2070 if (!valid_user_group_name_or_id(k
)) {
2071 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2084 int config_parse_user_group_strv(
2086 const char *filename
,
2088 const char *section
,
2089 unsigned section_line
,
2096 char ***users
= data
;
2106 if (isempty(rvalue
)) {
2107 *users
= strv_free(*users
);
2113 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2115 r
= extract_first_word(&p
, &word
, NULL
, 0);
2121 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax: %s", rvalue
);
2125 r
= unit_full_printf(u
, word
, &k
);
2127 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", word
);
2131 if (!valid_user_group_name_or_id(k
)) {
2132 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2136 r
= strv_push(users
, k
);
2146 int config_parse_working_directory(
2148 const char *filename
,
2150 const char *section
,
2151 unsigned section_line
,
2158 ExecContext
*c
= data
;
2169 if (rvalue
[0] == '-') {
2175 if (streq(rvalue
, "~")) {
2176 c
->working_directory_home
= true;
2177 c
->working_directory
= mfree(c
->working_directory
);
2179 _cleanup_free_
char *k
= NULL
;
2181 r
= unit_full_printf(u
, rvalue
, &k
);
2183 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2184 "Failed to resolve unit specifiers in working directory path '%s'%s: %m",
2185 rvalue
, missing_ok
? ", ignoring" : "");
2186 return missing_ok
? 0 : -ENOEXEC
;
2189 path_kill_slashes(k
);
2191 if (!utf8_is_valid(k
)) {
2192 log_syntax_invalid_utf8(unit
, LOG_ERR
, filename
, line
, rvalue
);
2193 return missing_ok
? 0 : -ENOEXEC
;
2196 if (!path_is_absolute(k
)) {
2197 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2198 "Working directory path '%s' is not absolute%s.",
2199 rvalue
, missing_ok
? ", ignoring" : "");
2200 return missing_ok
? 0 : -ENOEXEC
;
2203 c
->working_directory_home
= false;
2204 free_and_replace(c
->working_directory
, k
);
2207 c
->working_directory_missing_ok
= missing_ok
;
2211 int config_parse_unit_env_file(const char *unit
,
2212 const char *filename
,
2214 const char *section
,
2215 unsigned section_line
,
2224 _cleanup_free_
char *n
= NULL
;
2232 if (isempty(rvalue
)) {
2233 /* Empty assignment frees the list */
2234 *env
= strv_free(*env
);
2238 r
= unit_full_printf(u
, rvalue
, &n
);
2240 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve specifiers, ignoring: %s", rvalue
);
2244 if (!path_is_absolute(n
[0] == '-' ? n
+ 1 : n
)) {
2245 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Path '%s' is not absolute, ignoring.", n
);
2249 r
= strv_extend(env
, n
);
2256 int config_parse_environ(
2258 const char *filename
,
2260 const char *section
,
2261 unsigned section_line
,
2278 if (isempty(rvalue
)) {
2279 /* Empty assignment resets the list */
2280 *env
= strv_free(*env
);
2284 for (p
= rvalue
;; ) {
2285 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2287 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_QUOTES
);
2293 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2294 "Invalid syntax, ignoring: %s", rvalue
);
2299 r
= unit_full_printf(u
, word
, &k
);
2301 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2302 "Failed to resolve specifiers, ignoring: %s", word
);
2308 if (!env_assignment_is_valid(k
)) {
2309 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2310 "Invalid environment assignment, ignoring: %s", k
);
2314 r
= strv_env_replace(env
, k
);
2322 int config_parse_pass_environ(
2324 const char *filename
,
2326 const char *section
,
2327 unsigned section_line
,
2334 const char *whole_rvalue
= rvalue
;
2335 _cleanup_strv_free_
char **n
= NULL
;
2336 size_t nlen
= 0, nbufsize
= 0;
2337 char*** passenv
= data
;
2346 if (isempty(rvalue
)) {
2347 /* Empty assignment resets the list */
2348 *passenv
= strv_free(*passenv
);
2353 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2355 r
= extract_first_word(&rvalue
, &word
, NULL
, EXTRACT_QUOTES
);
2361 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2362 "Trailing garbage in %s, ignoring: %s", lvalue
, whole_rvalue
);
2367 r
= unit_full_printf(u
, word
, &k
);
2369 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2370 "Failed to resolve specifiers, ignoring: %s", word
);
2376 if (!env_name_is_valid(k
)) {
2377 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2378 "Invalid environment name for %s, ignoring: %s", lvalue
, k
);
2382 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
2385 n
[nlen
++] = TAKE_PTR(k
);
2390 r
= strv_extend_strv(passenv
, n
, true);
2398 int config_parse_unset_environ(
2400 const char *filename
,
2402 const char *section
,
2403 unsigned section_line
,
2410 _cleanup_strv_free_
char **n
= NULL
;
2411 const char *whole_rvalue
= rvalue
;
2412 size_t nlen
= 0, nbufsize
= 0;
2413 char*** unsetenv
= data
;
2422 if (isempty(rvalue
)) {
2423 /* Empty assignment resets the list */
2424 *unsetenv
= strv_free(*unsetenv
);
2429 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2431 r
= extract_first_word(&rvalue
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_QUOTES
);
2437 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2438 "Trailing garbage in %s, ignoring: %s", lvalue
, whole_rvalue
);
2443 r
= unit_full_printf(u
, word
, &k
);
2445 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2446 "Failed to resolve specifiers, ignoring: %s", word
);
2452 if (!env_assignment_is_valid(k
) && !env_name_is_valid(k
)) {
2453 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2454 "Invalid environment name or assignment %s, ignoring: %s", lvalue
, k
);
2458 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
2461 n
[nlen
++] = TAKE_PTR(k
);
2466 r
= strv_extend_strv(unsetenv
, n
, true);
2474 int config_parse_log_extra_fields(
2476 const char *filename
,
2478 const char *section
,
2479 unsigned section_line
,
2486 ExecContext
*c
= data
;
2496 if (isempty(rvalue
)) {
2497 exec_context_free_log_extra_fields(c
);
2501 for (p
= rvalue
;; ) {
2502 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2506 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_QUOTES
);
2512 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
2516 r
= unit_full_printf(u
, word
, &k
);
2518 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers on %s, ignoring field: %m", word
);
2522 eq
= strchr(k
, '=');
2524 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Log field lacks '=' character, ignoring field: %s", k
);
2528 if (!journal_field_valid(k
, eq
-k
, false)) {
2529 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Log field name is invalid, ignoring field: %s", k
);
2533 t
= reallocarray(c
->log_extra_fields
, c
->n_log_extra_fields
+1, sizeof(struct iovec
));
2537 c
->log_extra_fields
= t
;
2538 c
->log_extra_fields
[c
->n_log_extra_fields
++] = IOVEC_MAKE_STRING(k
);
2546 int config_parse_ip_tos(const char *unit
,
2547 const char *filename
,
2549 const char *section
,
2550 unsigned section_line
,
2557 int *ip_tos
= data
, x
;
2564 x
= ip_tos_from_string(rvalue
);
2566 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse IP TOS value, ignoring: %s", rvalue
);
2574 int config_parse_unit_condition_path(
2576 const char *filename
,
2578 const char *section
,
2579 unsigned section_line
,
2586 _cleanup_free_
char *p
= NULL
;
2587 Condition
**list
= data
, *c
;
2588 ConditionType t
= ltype
;
2589 bool trigger
, negate
;
2598 if (isempty(rvalue
)) {
2599 /* Empty assignment resets the list */
2600 *list
= condition_free_list(*list
);
2604 trigger
= rvalue
[0] == '|';
2608 negate
= rvalue
[0] == '!';
2612 r
= unit_full_printf(u
, rvalue
, &p
);
2614 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve specifiers, ignoring: %s", rvalue
);
2618 if (!path_is_absolute(p
)) {
2619 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Path in condition not absolute, ignoring: %s", p
);
2623 c
= condition_new(t
, p
, trigger
, negate
);
2627 LIST_PREPEND(conditions
, *list
, c
);
2631 int config_parse_unit_condition_string(
2633 const char *filename
,
2635 const char *section
,
2636 unsigned section_line
,
2643 _cleanup_free_
char *s
= NULL
;
2644 Condition
**list
= data
, *c
;
2645 ConditionType t
= ltype
;
2646 bool trigger
, negate
;
2655 if (isempty(rvalue
)) {
2656 /* Empty assignment resets the list */
2657 *list
= condition_free_list(*list
);
2661 trigger
= rvalue
[0] == '|';
2665 negate
= rvalue
[0] == '!';
2669 r
= unit_full_printf(u
, rvalue
, &s
);
2671 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve specifiers, ignoring: %s", rvalue
);
2675 c
= condition_new(t
, s
, trigger
, negate
);
2679 LIST_PREPEND(conditions
, *list
, c
);
2683 int config_parse_unit_condition_null(
2685 const char *filename
,
2687 const char *section
,
2688 unsigned section_line
,
2695 Condition
**list
= data
, *c
;
2696 bool trigger
, negate
;
2704 if (isempty(rvalue
)) {
2705 /* Empty assignment resets the list */
2706 *list
= condition_free_list(*list
);
2710 trigger
= rvalue
[0] == '|';
2714 negate
= rvalue
[0] == '!';
2718 b
= parse_boolean(rvalue
);
2720 log_syntax(unit
, LOG_ERR
, filename
, line
, b
, "Failed to parse boolean value in condition, ignoring: %s", rvalue
);
2727 c
= condition_new(CONDITION_NULL
, NULL
, trigger
, negate
);
2731 LIST_PREPEND(conditions
, *list
, c
);
2735 DEFINE_CONFIG_PARSE_ENUM(config_parse_notify_access
, notify_access
, NotifyAccess
, "Failed to parse notify access specifier");
2736 DEFINE_CONFIG_PARSE_ENUM(config_parse_emergency_action
, emergency_action
, EmergencyAction
, "Failed to parse failure action specifier");
2738 int config_parse_unit_requires_mounts_for(
2740 const char *filename
,
2742 const char *section
,
2743 unsigned section_line
,
2759 for (p
= rvalue
;; ) {
2760 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
2762 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
2768 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2769 "Invalid syntax, ignoring: %s", rvalue
);
2773 if (!utf8_is_valid(word
)) {
2774 log_syntax_invalid_utf8(unit
, LOG_ERR
, filename
, line
, rvalue
);
2778 r
= unit_full_printf(u
, word
, &resolved
);
2780 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit name \"%s\", ignoring: %m", word
);
2784 r
= unit_require_mounts_for(u
, resolved
, UNIT_DEPENDENCY_FILE
);
2786 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add required mount \"%s\", ignoring: %m", resolved
);
2792 int config_parse_documentation(const char *unit
,
2793 const char *filename
,
2795 const char *section
,
2796 unsigned section_line
,
2812 if (isempty(rvalue
)) {
2813 /* Empty assignment resets the list */
2814 u
->documentation
= strv_free(u
->documentation
);
2818 r
= config_parse_unit_strv_printf(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
,
2819 rvalue
, data
, userdata
);
2823 for (a
= b
= u
->documentation
; a
&& *a
; a
++) {
2825 if (documentation_url_is_valid(*a
))
2828 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid URL, ignoring: %s", *a
);
2839 int config_parse_syscall_filter(
2841 const char *filename
,
2843 const char *section
,
2844 unsigned section_line
,
2851 ExecContext
*c
= data
;
2853 bool invert
= false;
2862 if (isempty(rvalue
)) {
2863 /* Empty assignment resets the list */
2864 c
->syscall_filter
= hashmap_free(c
->syscall_filter
);
2865 c
->syscall_whitelist
= false;
2869 if (rvalue
[0] == '~') {
2874 if (!c
->syscall_filter
) {
2875 c
->syscall_filter
= hashmap_new(NULL
);
2876 if (!c
->syscall_filter
)
2880 /* Allow everything but the ones listed */
2881 c
->syscall_whitelist
= false;
2883 /* Allow nothing but the ones listed */
2884 c
->syscall_whitelist
= true;
2886 /* Accept default syscalls if we are on a whitelist */
2887 r
= seccomp_parse_syscall_filter("@default", -1, c
->syscall_filter
, SECCOMP_PARSE_WHITELIST
);
2895 _cleanup_free_
char *word
= NULL
, *name
= NULL
;
2898 r
= extract_first_word(&p
, &word
, NULL
, 0);
2904 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
2908 r
= parse_syscall_and_errno(word
, &name
, &num
);
2910 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse syscall:errno, ignoring: %s", word
);
2914 r
= seccomp_parse_syscall_filter_full(name
, num
, c
->syscall_filter
,
2915 SECCOMP_PARSE_LOG
|SECCOMP_PARSE_PERMISSIVE
|(invert
? SECCOMP_PARSE_INVERT
: 0)|(c
->syscall_whitelist
? SECCOMP_PARSE_WHITELIST
: 0),
2916 unit
, filename
, line
);
2924 int config_parse_syscall_archs(
2926 const char *filename
,
2928 const char *section
,
2929 unsigned section_line
,
2940 if (isempty(rvalue
)) {
2941 *archs
= set_free(*archs
);
2945 r
= set_ensure_allocated(archs
, NULL
);
2949 for (p
= rvalue
;;) {
2950 _cleanup_free_
char *word
= NULL
;
2953 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
2959 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2960 "Invalid syntax, ignoring: %s", rvalue
);
2964 r
= seccomp_arch_from_string(word
, &a
);
2966 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2967 "Failed to parse system call architecture \"%s\", ignoring: %m", word
);
2971 r
= set_put(*archs
, UINT32_TO_PTR(a
+ 1));
2977 int config_parse_syscall_errno(
2979 const char *filename
,
2981 const char *section
,
2982 unsigned section_line
,
2989 ExecContext
*c
= data
;
2996 if (isempty(rvalue
)) {
2997 /* Empty assignment resets to KILL */
2998 c
->syscall_errno
= 0;
3002 e
= parse_errno(rvalue
);
3004 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse error number, ignoring: %s", rvalue
);
3008 c
->syscall_errno
= e
;
3012 int config_parse_address_families(
3014 const char *filename
,
3016 const char *section
,
3017 unsigned section_line
,
3024 ExecContext
*c
= data
;
3025 bool invert
= false;
3033 if (isempty(rvalue
)) {
3034 /* Empty assignment resets the list */
3035 c
->address_families
= set_free(c
->address_families
);
3036 c
->address_families_whitelist
= false;
3040 if (rvalue
[0] == '~') {
3045 if (!c
->address_families
) {
3046 c
->address_families
= set_new(NULL
);
3047 if (!c
->address_families
)
3050 c
->address_families_whitelist
= !invert
;
3053 for (p
= rvalue
;;) {
3054 _cleanup_free_
char *word
= NULL
;
3057 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
3063 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3064 "Invalid syntax, ignoring: %s", rvalue
);
3068 af
= af_from_name(word
);
3070 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
3071 "Failed to parse address family \"%s\", ignoring: %m", word
);
3075 /* If we previously wanted to forbid an address family and now
3076 * we want to allow it, then just remove it from the list.
3078 if (!invert
== c
->address_families_whitelist
) {
3079 r
= set_put(c
->address_families
, INT_TO_PTR(af
));
3083 set_remove(c
->address_families
, INT_TO_PTR(af
));
3087 int config_parse_restrict_namespaces(
3089 const char *filename
,
3091 const char *section
,
3092 unsigned section_line
,
3099 ExecContext
*c
= data
;
3100 bool invert
= false;
3103 if (isempty(rvalue
)) {
3104 /* Reset to the default. */
3105 c
->restrict_namespaces
= NAMESPACE_FLAGS_ALL
;
3109 if (rvalue
[0] == '~') {
3114 r
= parse_boolean(rvalue
);
3116 c
->restrict_namespaces
= 0;
3118 c
->restrict_namespaces
= NAMESPACE_FLAGS_ALL
;
3120 /* Not a boolean argument, in this case it's a list of namespace types. */
3122 r
= namespace_flag_from_string_many(rvalue
, &c
->restrict_namespaces
);
3124 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse namespace type string, ignoring: %s", rvalue
);
3130 c
->restrict_namespaces
= (~c
->restrict_namespaces
) & NAMESPACE_FLAGS_ALL
;
3136 int config_parse_unit_slice(
3138 const char *filename
,
3140 const char *section
,
3141 unsigned section_line
,
3148 _cleanup_free_
char *k
= NULL
;
3149 Unit
*u
= userdata
, *slice
= NULL
;
3157 r
= unit_name_printf(u
, rvalue
, &k
);
3159 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers on %s. Ignoring.", rvalue
);
3163 r
= manager_load_unit(u
->manager
, k
, NULL
, NULL
, &slice
);
3165 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to load slice unit %s. Ignoring.", k
);
3169 r
= unit_set_slice(u
, slice
);
3171 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to assign slice %s to unit %s. Ignoring.", slice
->id
, u
->id
);
3178 DEFINE_CONFIG_PARSE_ENUM(config_parse_device_policy
, cgroup_device_policy
, CGroupDevicePolicy
, "Failed to parse device policy");
3180 int config_parse_cpu_weight(
3182 const char *filename
,
3184 const char *section
,
3185 unsigned section_line
,
3192 uint64_t *weight
= data
;
3199 r
= cg_weight_parse(rvalue
, weight
);
3201 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "CPU weight '%s' invalid. Ignoring.", rvalue
);
3208 int config_parse_cpu_shares(
3210 const char *filename
,
3212 const char *section
,
3213 unsigned section_line
,
3220 uint64_t *shares
= data
;
3227 r
= cg_cpu_shares_parse(rvalue
, shares
);
3229 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "CPU shares '%s' invalid. Ignoring.", rvalue
);
3236 int config_parse_cpu_quota(
3238 const char *filename
,
3240 const char *section
,
3241 unsigned section_line
,
3248 CGroupContext
*c
= data
;
3255 if (isempty(rvalue
)) {
3256 c
->cpu_quota_per_sec_usec
= USEC_INFINITY
;
3260 r
= parse_percent_unbounded(rvalue
);
3262 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "CPU quota '%s' invalid. Ignoring.", rvalue
);
3266 c
->cpu_quota_per_sec_usec
= ((usec_t
) r
* USEC_PER_SEC
) / 100U;
3270 int config_parse_memory_limit(
3272 const char *filename
,
3274 const char *section
,
3275 unsigned section_line
,
3282 CGroupContext
*c
= data
;
3283 uint64_t bytes
= CGROUP_LIMIT_MAX
;
3286 if (!isempty(rvalue
) && !streq(rvalue
, "infinity")) {
3288 r
= parse_percent(rvalue
);
3290 r
= parse_size(rvalue
, 1024, &bytes
);
3292 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Memory limit '%s' invalid. Ignoring.", rvalue
);
3296 bytes
= physical_memory_scale(r
, 100U);
3298 if (bytes
>= UINT64_MAX
||
3299 (bytes
<= 0 && !streq(lvalue
, "MemorySwapMax"))) {
3300 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Memory limit '%s' out of range. Ignoring.", rvalue
);
3305 if (streq(lvalue
, "MemoryLow"))
3306 c
->memory_low
= bytes
;
3307 else if (streq(lvalue
, "MemoryHigh"))
3308 c
->memory_high
= bytes
;
3309 else if (streq(lvalue
, "MemoryMax"))
3310 c
->memory_max
= bytes
;
3311 else if (streq(lvalue
, "MemorySwapMax"))
3312 c
->memory_swap_max
= bytes
;
3313 else if (streq(lvalue
, "MemoryLimit"))
3314 c
->memory_limit
= bytes
;
3321 int config_parse_tasks_max(
3323 const char *filename
,
3325 const char *section
,
3326 unsigned section_line
,
3333 uint64_t *tasks_max
= data
, v
;
3337 if (isempty(rvalue
)) {
3338 *tasks_max
= u
->manager
->default_tasks_max
;
3342 if (streq(rvalue
, "infinity")) {
3343 *tasks_max
= CGROUP_LIMIT_MAX
;
3347 r
= parse_percent(rvalue
);
3349 r
= safe_atou64(rvalue
, &v
);
3351 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Maximum tasks value '%s' invalid. Ignoring.", rvalue
);
3355 v
= system_tasks_max_scale(r
, 100U);
3357 if (v
<= 0 || v
>= UINT64_MAX
) {
3358 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Maximum tasks value '%s' out of range. Ignoring.", rvalue
);
3366 int config_parse_delegate(
3368 const char *filename
,
3370 const char *section
,
3371 unsigned section_line
,
3378 CGroupContext
*c
= data
;
3381 /* We either accept a boolean value, which may be used to turn on delegation for all controllers, or turn it
3382 * off for all. Or it takes a list of controller names, in which case we add the specified controllers to the
3383 * mask to delegate. */
3385 if (isempty(rvalue
)) {
3387 c
->delegate_controllers
= 0;
3391 r
= parse_boolean(rvalue
);
3393 const char *p
= rvalue
;
3394 CGroupMask mask
= 0;
3397 _cleanup_free_
char *word
= NULL
;
3398 CGroupController cc
;
3400 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
3406 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3410 cc
= cgroup_controller_from_string(word
);
3412 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid controller name '%s', ignoring", rvalue
);
3416 mask
|= CGROUP_CONTROLLER_TO_MASK(cc
);
3420 c
->delegate_controllers
|= mask
;
3424 c
->delegate_controllers
= _CGROUP_MASK_ALL
;
3426 c
->delegate
= false;
3427 c
->delegate_controllers
= 0;
3433 int config_parse_device_allow(
3435 const char *filename
,
3437 const char *section
,
3438 unsigned section_line
,
3445 _cleanup_free_
char *path
= NULL
, *t
= NULL
;
3446 CGroupContext
*c
= data
;
3447 CGroupDeviceAllow
*a
;
3448 const char *m
= NULL
;
3452 if (isempty(rvalue
)) {
3453 while (c
->device_allow
)
3454 cgroup_context_free_device_allow(c
, c
->device_allow
);
3459 r
= unit_full_printf(userdata
, rvalue
, &t
);
3461 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3462 "Failed to resolve specifiers in %s, ignoring: %m",
3467 n
= strcspn(t
, WHITESPACE
);
3469 path
= strndup(t
, n
);
3473 if (!is_deviceallow_pattern(path
) &&
3474 !path_startswith(path
, "/run/systemd/inaccessible/")) {
3475 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device node path '%s'. Ignoring.", path
);
3479 m
= t
+ n
+ strspn(t
+ n
, WHITESPACE
);
3483 if (!in_charset(m
, "rwm")) {
3484 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device rights '%s'. Ignoring.", m
);
3488 a
= new0(CGroupDeviceAllow
, 1);
3492 a
->path
= TAKE_PTR(path
);
3493 a
->r
= !!strchr(m
, 'r');
3494 a
->w
= !!strchr(m
, 'w');
3495 a
->m
= !!strchr(m
, 'm');
3497 LIST_PREPEND(device_allow
, c
->device_allow
, a
);
3501 int config_parse_io_weight(
3503 const char *filename
,
3505 const char *section
,
3506 unsigned section_line
,
3513 uint64_t *weight
= data
;
3520 r
= cg_weight_parse(rvalue
, weight
);
3522 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "IO weight '%s' invalid. Ignoring.", rvalue
);
3529 int config_parse_io_device_weight(
3531 const char *filename
,
3533 const char *section
,
3534 unsigned section_line
,
3541 _cleanup_free_
char *path
= NULL
;
3542 CGroupIODeviceWeight
*w
;
3543 CGroupContext
*c
= data
;
3553 if (isempty(rvalue
)) {
3554 while (c
->io_device_weights
)
3555 cgroup_context_free_io_device_weight(c
, c
->io_device_weights
);
3560 n
= strcspn(rvalue
, WHITESPACE
);
3561 weight
= rvalue
+ n
;
3562 weight
+= strspn(weight
, WHITESPACE
);
3564 if (isempty(weight
)) {
3565 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Expected block device and device weight. Ignoring.");
3569 path
= strndup(rvalue
, n
);
3573 if (!path_startswith(path
, "/dev") &&
3574 !path_startswith(path
, "/run/systemd/inaccessible/")) {
3575 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device node path '%s'. Ignoring.", path
);
3579 r
= cg_weight_parse(weight
, &u
);
3581 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "IO weight '%s' invalid. Ignoring.", weight
);
3585 assert(u
!= CGROUP_WEIGHT_INVALID
);
3587 w
= new0(CGroupIODeviceWeight
, 1);
3591 w
->path
= TAKE_PTR(path
);
3595 LIST_PREPEND(device_weights
, c
->io_device_weights
, w
);
3599 int config_parse_io_limit(
3601 const char *filename
,
3603 const char *section
,
3604 unsigned section_line
,
3611 _cleanup_free_
char *path
= NULL
;
3612 CGroupIODeviceLimit
*l
= NULL
, *t
;
3613 CGroupContext
*c
= data
;
3614 CGroupIOLimitType type
;
3624 type
= cgroup_io_limit_type_from_string(lvalue
);
3627 if (isempty(rvalue
)) {
3628 LIST_FOREACH(device_limits
, l
, c
->io_device_limits
)
3629 l
->limits
[type
] = cgroup_io_limit_defaults
[type
];
3633 n
= strcspn(rvalue
, WHITESPACE
);
3635 limit
+= strspn(limit
, WHITESPACE
);
3638 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Expected space separated pair of device node and bandwidth. Ignoring.");
3642 path
= strndup(rvalue
, n
);
3646 if (!path_startswith(path
, "/dev") &&
3647 !path_startswith(path
, "/run/systemd/inaccessible/")) {
3648 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device node path '%s'. Ignoring.", path
);
3652 if (streq("infinity", limit
)) {
3653 num
= CGROUP_LIMIT_MAX
;
3655 r
= parse_size(limit
, 1000, &num
);
3656 if (r
< 0 || num
<= 0) {
3657 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "IO Limit '%s' invalid. Ignoring.", rvalue
);
3662 LIST_FOREACH(device_limits
, t
, c
->io_device_limits
) {
3663 if (path_equal(path
, t
->path
)) {
3670 CGroupIOLimitType ttype
;
3672 l
= new0(CGroupIODeviceLimit
, 1);
3676 l
->path
= TAKE_PTR(path
);
3677 for (ttype
= 0; ttype
< _CGROUP_IO_LIMIT_TYPE_MAX
; ttype
++)
3678 l
->limits
[ttype
] = cgroup_io_limit_defaults
[ttype
];
3680 LIST_PREPEND(device_limits
, c
->io_device_limits
, l
);
3683 l
->limits
[type
] = num
;
3688 int config_parse_blockio_weight(
3690 const char *filename
,
3692 const char *section
,
3693 unsigned section_line
,
3700 uint64_t *weight
= data
;
3707 r
= cg_blkio_weight_parse(rvalue
, weight
);
3709 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Block IO weight '%s' invalid. Ignoring.", rvalue
);
3716 int config_parse_blockio_device_weight(
3718 const char *filename
,
3720 const char *section
,
3721 unsigned section_line
,
3728 _cleanup_free_
char *path
= NULL
;
3729 CGroupBlockIODeviceWeight
*w
;
3730 CGroupContext
*c
= data
;
3740 if (isempty(rvalue
)) {
3741 while (c
->blockio_device_weights
)
3742 cgroup_context_free_blockio_device_weight(c
, c
->blockio_device_weights
);
3747 n
= strcspn(rvalue
, WHITESPACE
);
3748 weight
= rvalue
+ n
;
3749 weight
+= strspn(weight
, WHITESPACE
);
3751 if (isempty(weight
)) {
3752 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Expected block device and device weight. Ignoring.");
3756 path
= strndup(rvalue
, n
);
3760 if (!path_startswith(path
, "/dev") &&
3761 !path_startswith(path
, "/run/systemd/inaccessible/")) {
3762 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device node path '%s'. Ignoring.", path
);
3766 r
= cg_blkio_weight_parse(weight
, &u
);
3768 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Block IO weight '%s' invalid. Ignoring.", weight
);
3772 assert(u
!= CGROUP_BLKIO_WEIGHT_INVALID
);
3774 w
= new0(CGroupBlockIODeviceWeight
, 1);
3778 w
->path
= TAKE_PTR(path
);
3782 LIST_PREPEND(device_weights
, c
->blockio_device_weights
, w
);
3786 int config_parse_blockio_bandwidth(
3788 const char *filename
,
3790 const char *section
,
3791 unsigned section_line
,
3798 _cleanup_free_
char *path
= NULL
;
3799 CGroupBlockIODeviceBandwidth
*b
= NULL
, *t
;
3800 CGroupContext
*c
= data
;
3801 const char *bandwidth
;
3811 read
= streq("BlockIOReadBandwidth", lvalue
);
3813 if (isempty(rvalue
)) {
3814 LIST_FOREACH(device_bandwidths
, b
, c
->blockio_device_bandwidths
) {
3815 b
->rbps
= CGROUP_LIMIT_MAX
;
3816 b
->wbps
= CGROUP_LIMIT_MAX
;
3821 n
= strcspn(rvalue
, WHITESPACE
);
3822 bandwidth
= rvalue
+ n
;
3823 bandwidth
+= strspn(bandwidth
, WHITESPACE
);
3826 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Expected space separated pair of device node and bandwidth. Ignoring.");
3830 path
= strndup(rvalue
, n
);
3834 if (!path_startswith(path
, "/dev") &&
3835 !path_startswith(path
, "/run/systemd/inaccessible/")) {
3836 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device node path '%s'. Ignoring.", path
);
3840 r
= parse_size(bandwidth
, 1000, &bytes
);
3841 if (r
< 0 || bytes
<= 0) {
3842 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Block IO Bandwidth '%s' invalid. Ignoring.", rvalue
);
3846 LIST_FOREACH(device_bandwidths
, t
, c
->blockio_device_bandwidths
) {
3847 if (path_equal(path
, t
->path
)) {
3854 b
= new0(CGroupBlockIODeviceBandwidth
, 1);
3858 b
->path
= TAKE_PTR(path
);
3859 b
->rbps
= CGROUP_LIMIT_MAX
;
3860 b
->wbps
= CGROUP_LIMIT_MAX
;
3862 LIST_PREPEND(device_bandwidths
, c
->blockio_device_bandwidths
, b
);
3873 DEFINE_CONFIG_PARSE_ENUM(config_parse_job_mode
, job_mode
, JobMode
, "Failed to parse job mode");
3875 int config_parse_job_mode_isolate(
3877 const char *filename
,
3879 const char *section
,
3880 unsigned section_line
,
3894 r
= parse_boolean(rvalue
);
3896 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse boolean, ignoring: %s", rvalue
);
3900 log_notice("%s is deprecated. Please use OnFailureJobMode= instead", lvalue
);
3902 *m
= r
? JOB_ISOLATE
: JOB_REPLACE
;
3906 DEFINE_CONFIG_PARSE_ENUM(config_parse_runtime_preserve_mode
, exec_preserve_mode
, ExecPreserveMode
, "Failed to parse runtime directory preserve mode");
3908 int config_parse_exec_directories(
3910 const char *filename
,
3912 const char *section
,
3913 unsigned section_line
,
3930 if (isempty(rvalue
)) {
3931 /* Empty assignment resets the list */
3932 *rt
= strv_free(*rt
);
3936 for (p
= rvalue
;;) {
3937 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
3939 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
3943 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3944 "Invalid syntax, ignoring: %s", rvalue
);
3950 r
= unit_full_printf(u
, word
, &k
);
3952 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
3953 "Failed to resolve specifiers in \"%s\", ignoring: %m", word
);
3957 if (!path_is_normalized(k
) || path_is_absolute(k
)) {
3958 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
3959 "%s= path is not valid, ignoring assignment: %s", lvalue
, rvalue
);
3963 r
= strv_push(rt
, k
);
3970 int config_parse_set_status(
3972 const char *filename
,
3974 const char *section
,
3975 unsigned section_line
,
3983 const char *word
, *state
;
3985 ExitStatusSet
*status_set
= data
;
3992 /* Empty assignment resets the list */
3993 if (isempty(rvalue
)) {
3994 exit_status_set_free(status_set
);
3998 FOREACH_WORD(word
, l
, rvalue
, state
) {
3999 _cleanup_free_
char *temp
;
4003 temp
= strndup(word
, l
);
4007 r
= safe_atoi(temp
, &val
);
4009 val
= signal_from_string_try_harder(temp
);
4012 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse value, ignoring: %s", word
);
4015 set
= &status_set
->signal
;
4017 if (val
< 0 || val
> 255) {
4018 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Value %d is outside range 0-255, ignoring", val
);
4021 set
= &status_set
->status
;
4024 r
= set_ensure_allocated(set
, NULL
);
4028 r
= set_put(*set
, INT_TO_PTR(val
));
4030 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Unable to store: %s", word
);
4034 if (!isempty(state
))
4035 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Trailing garbage, ignoring.");
4040 int config_parse_namespace_path_strv(
4042 const char *filename
,
4044 const char *section
,
4045 unsigned section_line
,
4062 if (isempty(rvalue
)) {
4063 /* Empty assignment resets the list */
4064 *sv
= strv_free(*sv
);
4070 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
, *joined
= NULL
;
4072 bool ignore_enoent
= false, shall_prefix
= false;
4074 r
= extract_first_word(&cur
, &word
, NULL
, EXTRACT_QUOTES
);
4080 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
4084 if (!utf8_is_valid(word
)) {
4085 log_syntax_invalid_utf8(unit
, LOG_ERR
, filename
, line
, word
);
4090 if (startswith(w
, "-")) {
4091 ignore_enoent
= true;
4094 if (startswith(w
, "+")) {
4095 shall_prefix
= true;
4099 r
= unit_full_printf(u
, w
, &resolved
);
4101 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve specifiers in %s: %m", word
);
4105 if (!path_is_absolute(resolved
)) {
4106 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Not an absolute path, ignoring: %s", resolved
);
4110 path_kill_slashes(resolved
);
4112 joined
= strjoin(ignore_enoent
? "-" : "",
4113 shall_prefix
? "+" : "",
4116 r
= strv_push(sv
, joined
);
4126 int config_parse_temporary_filesystems(
4128 const char *filename
,
4130 const char *section
,
4131 unsigned section_line
,
4139 ExecContext
*c
= data
;
4148 if (isempty(rvalue
)) {
4149 /* Empty assignment resets the list */
4150 temporary_filesystem_free_many(c
->temporary_filesystems
, c
->n_temporary_filesystems
);
4151 c
->temporary_filesystems
= NULL
;
4152 c
->n_temporary_filesystems
= 0;
4158 _cleanup_free_
char *word
= NULL
, *path
= NULL
, *resolved
= NULL
;
4161 r
= extract_first_word(&cur
, &word
, NULL
, EXTRACT_QUOTES
);
4167 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
4172 r
= extract_first_word(&w
, &path
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4178 r
= unit_full_printf(u
, path
, &resolved
);
4180 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve specifiers in %s, ignoring: %m", word
);
4184 if (!path_is_absolute(resolved
)) {
4185 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Not an absolute path, ignoring: %s", resolved
);
4189 path_kill_slashes(resolved
);
4191 r
= temporary_filesystem_add(&c
->temporary_filesystems
, &c
->n_temporary_filesystems
, path
, w
);
4195 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse mount options, ignoring: %s", word
);
4203 int config_parse_bind_paths(
4205 const char *filename
,
4207 const char *section
,
4208 unsigned section_line
,
4215 ExecContext
*c
= data
;
4225 if (isempty(rvalue
)) {
4226 /* Empty assignment resets the list */
4227 bind_mount_free_many(c
->bind_mounts
, c
->n_bind_mounts
);
4228 c
->bind_mounts
= NULL
;
4229 c
->n_bind_mounts
= 0;
4235 _cleanup_free_
char *source
= NULL
, *destination
= NULL
;
4236 _cleanup_free_
char *sresolved
= NULL
, *dresolved
= NULL
;
4237 char *s
= NULL
, *d
= NULL
;
4238 bool rbind
= true, ignore_enoent
= false;
4240 r
= extract_first_word(&p
, &source
, ":" WHITESPACE
, EXTRACT_QUOTES
|EXTRACT_DONT_COALESCE_SEPARATORS
);
4246 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s: %s", lvalue
, rvalue
);
4250 r
= unit_full_printf(u
, source
, &sresolved
);
4252 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4253 "Failed to resolved specifiers in \"%s\", ignoring: %m", source
);
4259 ignore_enoent
= true;
4263 if (!utf8_is_valid(s
)) {
4264 log_syntax_invalid_utf8(unit
, LOG_ERR
, filename
, line
, s
);
4267 if (!path_is_absolute(s
)) {
4268 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Not an absolute source path, ignoring: %s", s
);
4272 path_kill_slashes(s
);
4274 /* Optionally, the destination is specified. */
4275 if (p
&& p
[-1] == ':') {
4276 r
= extract_first_word(&p
, &destination
, ":" WHITESPACE
, EXTRACT_QUOTES
|EXTRACT_DONT_COALESCE_SEPARATORS
);
4280 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s: %s", lvalue
, rvalue
);
4284 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Missing argument after ':': %s", rvalue
);
4288 r
= unit_full_printf(u
, destination
, &dresolved
);
4290 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4291 "Failed to resolved specifiers in \"%s\", ignoring: %m", destination
);
4295 if (!utf8_is_valid(dresolved
)) {
4296 log_syntax_invalid_utf8(unit
, LOG_ERR
, filename
, line
, dresolved
);
4299 if (!path_is_absolute(dresolved
)) {
4300 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Not an absolute destination path, ignoring: %s", dresolved
);
4304 d
= path_kill_slashes(dresolved
);
4306 /* Optionally, there's also a short option string specified */
4307 if (p
&& p
[-1] == ':') {
4308 _cleanup_free_
char *options
= NULL
;
4310 r
= extract_first_word(&p
, &options
, NULL
, EXTRACT_QUOTES
);
4314 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s: %s", lvalue
, rvalue
);
4318 if (isempty(options
) || streq(options
, "rbind"))
4320 else if (streq(options
, "norbind"))
4323 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid option string, ignoring setting: %s", options
);
4330 r
= bind_mount_add(&c
->bind_mounts
, &c
->n_bind_mounts
,
4334 .read_only
= !!strstr(lvalue
, "ReadOnly"),
4336 .ignore_enoent
= ignore_enoent
,
4345 int config_parse_no_new_privileges(
4347 const char *filename
,
4349 const char *section
,
4350 unsigned section_line
,
4357 ExecContext
*c
= data
;
4365 k
= parse_boolean(rvalue
);
4367 log_syntax(unit
, LOG_ERR
, filename
, line
, k
, "Failed to parse boolean value, ignoring: %s", rvalue
);
4371 c
->no_new_privileges
= k
;
4376 int config_parse_protect_home(
4378 const char *filename
,
4380 const char *section
,
4381 unsigned section_line
,
4388 ExecContext
*c
= data
;
4396 /* Our enum shall be a superset of booleans, hence first try
4397 * to parse as boolean, and then as enum */
4399 h
= parse_protect_home_or_bool(rvalue
);
4401 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse protect home value, ignoring: %s", rvalue
);
4405 c
->protect_home
= h
;
4410 int config_parse_protect_system(
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 s
= parse_protect_system_or_bool(rvalue
);
4435 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse protect system value, ignoring: %s", rvalue
);
4439 c
->protect_system
= s
;
4444 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_keyring_mode
, exec_keyring_mode
, ExecKeyringMode
, "Failed to parse keyring mode");
4446 int config_parse_job_timeout_sec(
4448 const char *filename
,
4450 const char *section
,
4451 unsigned section_line
,
4467 r
= parse_sec_fix_0(rvalue
, &usec
);
4469 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse JobTimeoutSec= parameter, ignoring: %s", rvalue
);
4473 /* If the user explicitly changed JobTimeoutSec= also change JobRunningTimeoutSec=, for compatibility with old
4474 * versions. If JobRunningTimeoutSec= was explicitly set, avoid this however as whatever the user picked should
4477 if (!u
->job_running_timeout_set
)
4478 u
->job_running_timeout
= usec
;
4480 u
->job_timeout
= usec
;
4485 int config_parse_job_running_timeout_sec(
4487 const char *filename
,
4489 const char *section
,
4490 unsigned section_line
,
4506 r
= parse_sec_fix_0(rvalue
, &usec
);
4508 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse JobRunningTimeoutSec= parameter, ignoring: %s", rvalue
);
4512 u
->job_running_timeout
= usec
;
4513 u
->job_running_timeout_set
= true;
4518 #define FOLLOW_MAX 8
4520 static int open_follow(char **filename
, FILE **_f
, Set
*names
, char **_final
) {
4531 /* This will update the filename pointer if the loaded file is
4532 * reached by a symlink. The old string will be freed. */
4535 char *target
, *name
;
4537 if (c
++ >= FOLLOW_MAX
)
4540 path_kill_slashes(*filename
);
4542 /* Add the file name we are currently looking at to
4543 * the names of this unit, but only if it is a valid
4545 name
= basename(*filename
);
4546 if (unit_name_is_valid(name
, UNIT_NAME_ANY
)) {
4548 id
= set_get(names
, name
);
4554 r
= set_consume(names
, id
);
4560 /* Try to open the file name, but don't if its a symlink */
4561 fd
= open(*filename
, O_RDONLY
|O_CLOEXEC
|O_NOCTTY
|O_NOFOLLOW
);
4568 /* Hmm, so this is a symlink. Let's read the name, and follow it manually */
4569 r
= readlink_and_make_absolute(*filename
, &target
);
4577 f
= fdopen(fd
, "re");
4589 static int merge_by_names(Unit
**u
, Set
*names
, const char *id
) {
4597 /* Let's try to add in all symlink names we found */
4598 while ((k
= set_steal_first(names
))) {
4600 /* First try to merge in the other name into our
4602 r
= unit_merge_by_name(*u
, k
);
4606 /* Hmm, we couldn't merge the other unit into
4607 * ours? Then let's try it the other way
4610 /* If the symlink name we are looking at is unit template, then
4611 we must search for instance of this template */
4612 if (unit_name_is_valid(k
, UNIT_NAME_TEMPLATE
) && (*u
)->instance
) {
4613 _cleanup_free_
char *instance
= NULL
;
4615 r
= unit_name_replace_instance(k
, (*u
)->instance
, &instance
);
4619 other
= manager_get_unit((*u
)->manager
, instance
);
4621 other
= manager_get_unit((*u
)->manager
, k
);
4626 r
= unit_merge(other
, *u
);
4629 return merge_by_names(u
, names
, NULL
);
4637 unit_choose_id(*u
, id
);
4645 static int load_from_path(Unit
*u
, const char *path
) {
4646 _cleanup_set_free_free_ Set
*symlink_names
= NULL
;
4647 _cleanup_fclose_
FILE *f
= NULL
;
4648 _cleanup_free_
char *filename
= NULL
;
4657 symlink_names
= set_new(&string_hash_ops
);
4661 if (path_is_absolute(path
)) {
4663 filename
= strdup(path
);
4667 r
= open_follow(&filename
, &f
, symlink_names
, &id
);
4669 filename
= mfree(filename
);
4677 STRV_FOREACH(p
, u
->manager
->lookup_paths
.search_path
) {
4679 /* Instead of opening the path right away, we manually
4680 * follow all symlinks and add their name to our unit
4681 * name set while doing so */
4682 filename
= path_make_absolute(path
, *p
);
4686 if (u
->manager
->unit_path_cache
&&
4687 !set_get(u
->manager
->unit_path_cache
, filename
))
4690 r
= open_follow(&filename
, &f
, symlink_names
, &id
);
4693 filename
= mfree(filename
);
4695 /* ENOENT means that the file is missing or is a dangling symlink.
4696 * ENOTDIR means that one of paths we expect to be is a directory
4697 * is not a directory, we should just ignore that.
4698 * EACCES means that the directory or file permissions are wrong.
4701 log_debug_errno(r
, "Cannot access \"%s\": %m", filename
);
4702 else if (!IN_SET(r
, -ENOENT
, -ENOTDIR
))
4705 /* Empty the symlink names for the next run */
4706 set_clear_free(symlink_names
);
4711 /* Hmm, no suitable file found? */
4714 if (!unit_type_may_alias(u
->type
) && set_size(symlink_names
) > 1) {
4715 log_unit_warning(u
, "Unit type of %s does not support alias names, refusing loading via symlink.", u
->id
);
4720 r
= merge_by_names(&merged
, symlink_names
, id
);
4725 u
->load_state
= UNIT_MERGED
;
4729 if (fstat(fileno(f
), &st
) < 0)
4732 if (null_or_empty(&st
)) {
4733 u
->load_state
= UNIT_MASKED
;
4734 u
->fragment_mtime
= 0;
4736 u
->load_state
= UNIT_LOADED
;
4737 u
->fragment_mtime
= timespec_load(&st
.st_mtim
);
4739 /* Now, parse the file contents */
4740 r
= config_parse(u
->id
, filename
, f
,
4741 UNIT_VTABLE(u
)->sections
,
4742 config_item_perf_lookup
, load_fragment_gperf_lookup
,
4743 CONFIG_PARSE_ALLOW_INCLUDE
, u
);
4748 free_and_replace(u
->fragment_path
, filename
);
4750 if (u
->source_path
) {
4751 if (stat(u
->source_path
, &st
) >= 0)
4752 u
->source_mtime
= timespec_load(&st
.st_mtim
);
4754 u
->source_mtime
= 0;
4760 int unit_load_fragment(Unit
*u
) {
4766 assert(u
->load_state
== UNIT_STUB
);
4770 u
->load_state
= UNIT_LOADED
;
4774 /* First, try to find the unit under its id. We always look
4775 * for unit files in the default directories, to make it easy
4776 * to override things by placing things in /etc/systemd/system */
4777 r
= load_from_path(u
, u
->id
);
4781 /* Try to find an alias we can load this with */
4782 if (u
->load_state
== UNIT_STUB
) {
4783 SET_FOREACH(t
, u
->names
, i
) {
4788 r
= load_from_path(u
, t
);
4792 if (u
->load_state
!= UNIT_STUB
)
4797 /* And now, try looking for it under the suggested (originally linked) path */
4798 if (u
->load_state
== UNIT_STUB
&& u
->fragment_path
) {
4800 r
= load_from_path(u
, u
->fragment_path
);
4804 if (u
->load_state
== UNIT_STUB
)
4805 /* Hmm, this didn't work? Then let's get rid
4806 * of the fragment path stored for us, so that
4807 * we don't point to an invalid location. */
4808 u
->fragment_path
= mfree(u
->fragment_path
);
4811 /* Look for a template */
4812 if (u
->load_state
== UNIT_STUB
&& u
->instance
) {
4813 _cleanup_free_
char *k
= NULL
;
4815 r
= unit_name_template(u
->id
, &k
);
4819 r
= load_from_path(u
, k
);
4822 log_unit_notice(u
, "Unit configuration has fatal error, unit will not be started.");
4826 if (u
->load_state
== UNIT_STUB
) {
4827 SET_FOREACH(t
, u
->names
, i
) {
4828 _cleanup_free_
char *z
= NULL
;
4833 r
= unit_name_template(t
, &z
);
4837 r
= load_from_path(u
, z
);
4841 if (u
->load_state
!= UNIT_STUB
)
4850 void unit_dump_config_items(FILE *f
) {
4851 static const struct {
4852 const ConfigParserCallback callback
;
4855 #if !HAVE_SYSV_COMPAT || !HAVE_SECCOMP || !HAVE_PAM || !HAVE_SELINUX || !ENABLE_SMACK || !HAVE_APPARMOR
4856 { config_parse_warn_compat
, "NOTSUPPORTED" },
4858 { config_parse_int
, "INTEGER" },
4859 { config_parse_unsigned
, "UNSIGNED" },
4860 { config_parse_iec_size
, "SIZE" },
4861 { config_parse_iec_uint64
, "SIZE" },
4862 { config_parse_si_size
, "SIZE" },
4863 { config_parse_bool
, "BOOLEAN" },
4864 { config_parse_string
, "STRING" },
4865 { config_parse_path
, "PATH" },
4866 { config_parse_unit_path_printf
, "PATH" },
4867 { config_parse_strv
, "STRING [...]" },
4868 { config_parse_exec_nice
, "NICE" },
4869 { config_parse_exec_oom_score_adjust
, "OOMSCOREADJUST" },
4870 { config_parse_exec_io_class
, "IOCLASS" },
4871 { config_parse_exec_io_priority
, "IOPRIORITY" },
4872 { config_parse_exec_cpu_sched_policy
, "CPUSCHEDPOLICY" },
4873 { config_parse_exec_cpu_sched_prio
, "CPUSCHEDPRIO" },
4874 { config_parse_exec_cpu_affinity
, "CPUAFFINITY" },
4875 { config_parse_mode
, "MODE" },
4876 { config_parse_unit_env_file
, "FILE" },
4877 { config_parse_exec_output
, "OUTPUT" },
4878 { config_parse_exec_input
, "INPUT" },
4879 { config_parse_log_facility
, "FACILITY" },
4880 { config_parse_log_level
, "LEVEL" },
4881 { config_parse_exec_secure_bits
, "SECUREBITS" },
4882 { config_parse_capability_set
, "BOUNDINGSET" },
4883 { config_parse_limit
, "LIMIT" },
4884 { config_parse_unit_deps
, "UNIT [...]" },
4885 { config_parse_exec
, "PATH [ARGUMENT [...]]" },
4886 { config_parse_service_type
, "SERVICETYPE" },
4887 { config_parse_service_restart
, "SERVICERESTART" },
4888 #if HAVE_SYSV_COMPAT
4889 { config_parse_sysv_priority
, "SYSVPRIORITY" },
4891 { config_parse_kill_mode
, "KILLMODE" },
4892 { config_parse_signal
, "SIGNAL" },
4893 { config_parse_socket_listen
, "SOCKET [...]" },
4894 { config_parse_socket_bind
, "SOCKETBIND" },
4895 { config_parse_socket_bindtodevice
, "NETWORKINTERFACE" },
4896 { config_parse_sec
, "SECONDS" },
4897 { config_parse_nsec
, "NANOSECONDS" },
4898 { config_parse_namespace_path_strv
, "PATH [...]" },
4899 { config_parse_bind_paths
, "PATH[:PATH[:OPTIONS]] [...]" },
4900 { config_parse_unit_requires_mounts_for
, "PATH [...]" },
4901 { config_parse_exec_mount_flags
, "MOUNTFLAG [...]" },
4902 { config_parse_unit_string_printf
, "STRING" },
4903 { config_parse_trigger_unit
, "UNIT" },
4904 { config_parse_timer
, "TIMER" },
4905 { config_parse_path_spec
, "PATH" },
4906 { config_parse_notify_access
, "ACCESS" },
4907 { config_parse_ip_tos
, "TOS" },
4908 { config_parse_unit_condition_path
, "CONDITION" },
4909 { config_parse_unit_condition_string
, "CONDITION" },
4910 { config_parse_unit_condition_null
, "CONDITION" },
4911 { config_parse_unit_slice
, "SLICE" },
4912 { config_parse_documentation
, "URL" },
4913 { config_parse_service_timeout
, "SECONDS" },
4914 { config_parse_emergency_action
, "ACTION" },
4915 { config_parse_set_status
, "STATUS" },
4916 { config_parse_service_sockets
, "SOCKETS" },
4917 { config_parse_environ
, "ENVIRON" },
4919 { config_parse_syscall_filter
, "SYSCALLS" },
4920 { config_parse_syscall_archs
, "ARCHS" },
4921 { config_parse_syscall_errno
, "ERRNO" },
4922 { config_parse_address_families
, "FAMILIES" },
4923 { config_parse_restrict_namespaces
, "NAMESPACES" },
4925 { config_parse_cpu_shares
, "SHARES" },
4926 { config_parse_cpu_weight
, "WEIGHT" },
4927 { config_parse_memory_limit
, "LIMIT" },
4928 { config_parse_device_allow
, "DEVICE" },
4929 { config_parse_device_policy
, "POLICY" },
4930 { config_parse_io_limit
, "LIMIT" },
4931 { config_parse_io_weight
, "WEIGHT" },
4932 { config_parse_io_device_weight
, "DEVICEWEIGHT" },
4933 { config_parse_blockio_bandwidth
, "BANDWIDTH" },
4934 { config_parse_blockio_weight
, "WEIGHT" },
4935 { config_parse_blockio_device_weight
, "DEVICEWEIGHT" },
4936 { config_parse_long
, "LONG" },
4937 { config_parse_socket_service
, "SERVICE" },
4939 { config_parse_exec_selinux_context
, "LABEL" },
4941 { config_parse_job_mode
, "MODE" },
4942 { config_parse_job_mode_isolate
, "BOOLEAN" },
4943 { config_parse_personality
, "PERSONALITY" },
4946 const char *prev
= NULL
;
4951 NULSTR_FOREACH(i
, load_fragment_gperf_nulstr
) {
4952 const char *rvalue
= "OTHER", *lvalue
;
4956 const ConfigPerfItem
*p
;
4958 assert_se(p
= load_fragment_gperf_lookup(i
, strlen(i
)));
4960 dot
= strchr(i
, '.');
4961 lvalue
= dot
? dot
+ 1 : i
;
4965 if (!prev
|| !strneq(prev
, i
, prefix_len
+1)) {
4969 fprintf(f
, "[%.*s]\n", (int) prefix_len
, i
);
4972 for (j
= 0; j
< ELEMENTSOF(table
); j
++)
4973 if (p
->parse
== table
[j
].callback
) {
4974 rvalue
= table
[j
].rvalue
;
4978 fprintf(f
, "%s=%s\n", lvalue
, rvalue
);