1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 Copyright © 2012 Holger Hans Peter Freyther
15 #include <sys/resource.h>
19 #include "alloc-util.h"
20 #include "all-units.h"
21 #include "bus-error.h"
22 #include "bus-internal.h"
25 #include "capability-util.h"
27 #include "conf-parser.h"
28 #include "cpu-set-util.h"
30 #include "errno-list.h"
34 #include "hexdecoct.h"
37 #include "ip-protocol-list.h"
38 #include "journal-util.h"
39 #include "load-fragment.h"
42 #include "mountpoint-util.h"
43 #include "parse-util.h"
44 #include "path-util.h"
45 #include "process-util.h"
47 #include "seccomp-util.h"
49 #include "securebits.h"
50 #include "securebits-util.h"
51 #include "signal-util.h"
52 #include "stat-util.h"
53 #include "string-util.h"
55 #include "unit-name.h"
56 #include "unit-printf.h"
57 #include "user-util.h"
60 static int parse_socket_protocol(const char *s
) {
63 r
= parse_ip_protocol(s
);
66 if (!IN_SET(r
, IPPROTO_UDPLITE
, IPPROTO_SCTP
))
67 return -EPROTONOSUPPORT
;
72 DEFINE_CONFIG_PARSE(config_parse_socket_protocol
, parse_socket_protocol
, "Failed to parse socket protocol");
73 DEFINE_CONFIG_PARSE(config_parse_exec_secure_bits
, secure_bits_from_string
, "Failed to parse secure bits");
74 DEFINE_CONFIG_PARSE_ENUM(config_parse_collect_mode
, collect_mode
, CollectMode
, "Failed to parse garbage collection mode");
75 DEFINE_CONFIG_PARSE_ENUM(config_parse_device_policy
, cgroup_device_policy
, CGroupDevicePolicy
, "Failed to parse device policy");
76 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_keyring_mode
, exec_keyring_mode
, ExecKeyringMode
, "Failed to parse keyring mode");
77 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_utmp_mode
, exec_utmp_mode
, ExecUtmpMode
, "Failed to parse utmp mode");
78 DEFINE_CONFIG_PARSE_ENUM(config_parse_job_mode
, job_mode
, JobMode
, "Failed to parse job mode");
79 DEFINE_CONFIG_PARSE_ENUM(config_parse_kill_mode
, kill_mode
, KillMode
, "Failed to parse kill mode");
80 DEFINE_CONFIG_PARSE_ENUM(config_parse_notify_access
, notify_access
, NotifyAccess
, "Failed to parse notify access specifier");
81 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_home
, protect_home
, ProtectHome
, "Failed to parse protect home value");
82 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_system
, protect_system
, ProtectSystem
, "Failed to parse protect system value");
83 DEFINE_CONFIG_PARSE_ENUM(config_parse_runtime_preserve_mode
, exec_preserve_mode
, ExecPreserveMode
, "Failed to parse runtime directory preserve mode");
84 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_type
, service_type
, ServiceType
, "Failed to parse service type");
85 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart
, service_restart
, ServiceRestart
, "Failed to parse service restart specifier");
86 DEFINE_CONFIG_PARSE_ENUM(config_parse_socket_bind
, socket_address_bind_ipv6_only_or_bool
, SocketAddressBindIPv6Only
, "Failed to parse bind IPv6 only value");
87 DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_ip_tos
, ip_tos
, int, -1, "Failed to parse IP TOS value");
88 DEFINE_CONFIG_PARSE_PTR(config_parse_blockio_weight
, cg_blkio_weight_parse
, uint64_t, "Invalid block IO weight");
89 DEFINE_CONFIG_PARSE_PTR(config_parse_cg_weight
, cg_weight_parse
, uint64_t, "Invalid weight");
90 DEFINE_CONFIG_PARSE_PTR(config_parse_cpu_shares
, cg_cpu_shares_parse
, uint64_t, "Invalid CPU shares");
91 DEFINE_CONFIG_PARSE_PTR(config_parse_exec_mount_flags
, mount_propagation_flags_from_string
, unsigned long, "Failed to parse mount flag");
93 int config_parse_unit_deps(
98 unsigned section_line
,
105 UnitDependency d
= ltype
;
115 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
118 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_RETAIN_ESCAPE
);
124 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
128 r
= unit_name_printf(u
, word
, &k
);
130 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
134 r
= unit_add_dependency_by_name(u
, d
, k
, true, UNIT_DEPENDENCY_FILE
);
136 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
142 int config_parse_obsolete_unit_deps(
144 const char *filename
,
147 unsigned section_line
,
154 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
155 "Unit dependency type %s= is obsolete, replacing by %s=, please update your unit file", lvalue
, unit_dependency_to_string(ltype
));
157 return config_parse_unit_deps(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
);
160 int config_parse_unit_string_printf(
162 const char *filename
,
165 unsigned section_line
,
172 _cleanup_free_
char *k
= NULL
;
181 r
= unit_full_printf(u
, rvalue
, &k
);
183 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
187 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
190 int config_parse_unit_strv_printf(
192 const char *filename
,
195 unsigned section_line
,
203 _cleanup_free_
char *k
= NULL
;
211 r
= unit_full_printf(u
, rvalue
, &k
);
213 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
217 return config_parse_strv(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
220 int config_parse_unit_path_printf(
222 const char *filename
,
225 unsigned section_line
,
232 _cleanup_free_
char *k
= NULL
;
242 /* Let's not bother with anything that is too long */
243 if (strlen(rvalue
) >= PATH_MAX
) {
244 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
245 "%s value too long%s.",
246 lvalue
, fatal
? "" : ", ignoring");
247 return fatal
? -ENAMETOOLONG
: 0;
250 r
= unit_full_printf(u
, rvalue
, &k
);
252 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
253 "Failed to resolve unit specifiers in '%s'%s: %m",
254 rvalue
, fatal
? "" : ", ignoring");
255 return fatal
? -ENOEXEC
: 0;
258 return config_parse_path(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
261 int config_parse_unit_path_strv_printf(
263 const char *filename
,
266 unsigned section_line
,
283 if (isempty(rvalue
)) {
289 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
291 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
297 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
298 "Invalid syntax, ignoring: %s", rvalue
);
302 r
= unit_full_printf(u
, word
, &k
);
304 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
305 "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
309 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
320 int config_parse_socket_listen(const char *unit
,
321 const char *filename
,
324 unsigned section_line
,
331 _cleanup_free_ SocketPort
*p
= NULL
;
343 if (isempty(rvalue
)) {
344 /* An empty assignment removes all ports */
345 socket_free_ports(s
);
349 p
= new0(SocketPort
, 1);
353 if (ltype
!= SOCKET_SOCKET
) {
354 _cleanup_free_
char *k
= NULL
;
356 r
= unit_full_printf(UNIT(s
), rvalue
, &k
);
358 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
362 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
366 free_and_replace(p
->path
, k
);
369 } else if (streq(lvalue
, "ListenNetlink")) {
370 _cleanup_free_
char *k
= NULL
;
372 r
= unit_full_printf(UNIT(s
), rvalue
, &k
);
374 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
378 r
= socket_address_parse_netlink(&p
->address
, k
);
380 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse address value in '%s', ignoring: %m", k
);
384 p
->type
= SOCKET_SOCKET
;
387 _cleanup_free_
char *k
= NULL
;
389 r
= unit_full_printf(UNIT(s
), rvalue
, &k
);
391 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
395 r
= socket_address_parse_and_warn(&p
->address
, k
);
397 if (r
!= -EAFNOSUPPORT
)
398 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse address value in '%s', ignoring: %m", k
);
402 if (streq(lvalue
, "ListenStream"))
403 p
->address
.type
= SOCK_STREAM
;
404 else if (streq(lvalue
, "ListenDatagram"))
405 p
->address
.type
= SOCK_DGRAM
;
407 assert(streq(lvalue
, "ListenSequentialPacket"));
408 p
->address
.type
= SOCK_SEQPACKET
;
411 if (socket_address_family(&p
->address
) != AF_LOCAL
&& p
->address
.type
== SOCK_SEQPACKET
) {
412 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Address family not supported, ignoring: %s", rvalue
);
416 p
->type
= SOCKET_SOCKET
;
420 p
->auxiliary_fds
= NULL
;
421 p
->n_auxiliary_fds
= 0;
424 LIST_FIND_TAIL(port
, s
->ports
, tail
);
425 LIST_INSERT_AFTER(port
, s
->ports
, tail
, p
);
432 int config_parse_exec_nice(
434 const char *filename
,
437 unsigned section_line
,
444 ExecContext
*c
= data
;
452 if (isempty(rvalue
)) {
457 r
= parse_nice(rvalue
, &priority
);
460 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Nice priority out of range, ignoring: %s", rvalue
);
462 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse nice priority '%s', ignoring: %m", rvalue
);
472 int config_parse_exec_oom_score_adjust(
474 const char *filename
,
477 unsigned section_line
,
484 ExecContext
*c
= data
;
492 if (isempty(rvalue
)) {
493 c
->oom_score_adjust_set
= false;
497 r
= parse_oom_score_adjust(rvalue
, &oa
);
500 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "OOM score adjust value out of range, ignoring: %s", rvalue
);
502 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse the OOM score adjust value '%s', ignoring: %m", rvalue
);
506 c
->oom_score_adjust
= oa
;
507 c
->oom_score_adjust_set
= true;
512 int config_parse_exec(
514 const char *filename
,
517 unsigned section_line
,
524 ExecCommand
**e
= data
;
536 rvalue
+= strspn(rvalue
, WHITESPACE
);
538 if (isempty(rvalue
)) {
539 /* An empty assignment resets the list */
540 *e
= exec_command_free_list(*e
);
546 _cleanup_free_
char *path
= NULL
, *firstword
= NULL
;
547 ExecCommandFlags flags
= 0;
548 bool ignore
= false, separate_argv0
= false;
549 _cleanup_free_ ExecCommand
*nce
= NULL
;
550 _cleanup_strv_free_
char **n
= NULL
;
551 size_t nlen
= 0, nbufsize
= 0;
556 r
= extract_first_word_and_warn(&p
, &firstword
, NULL
, EXTRACT_QUOTES
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
562 /* We accept an absolute path as first argument. If it's prefixed with - and the path doesn't
563 * exist, we ignore it instead of erroring out; if it's prefixed with @, we allow overriding of
564 * argv[0]; if it's prefixed with +, it will be run with full privileges and no sandboxing; if
565 * it's prefixed with '!' we apply sandboxing, but do not change user/group credentials; if
566 * it's prefixed with '!!', then we apply user/group credentials if the kernel supports ambient
567 * capabilities -- if it doesn't we don't apply the credentials themselves, but do apply most
568 * other sandboxing, with some special exceptions for changing UID.
570 * The idea is that '!!' may be used to write services that can take benefit of systemd's
571 * UID/GID dropping if the kernel supports ambient creds, but provide an automatic fallback to
572 * privilege dropping within the daemon if the kernel does not offer that. */
574 if (*f
== '-' && !(flags
& EXEC_COMMAND_IGNORE_FAILURE
)) {
575 flags
|= EXEC_COMMAND_IGNORE_FAILURE
;
577 } else if (*f
== '@' && !separate_argv0
)
578 separate_argv0
= true;
579 else if (*f
== '+' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
580 flags
|= EXEC_COMMAND_FULLY_PRIVILEGED
;
581 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
582 flags
|= EXEC_COMMAND_NO_SETUID
;
583 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_AMBIENT_MAGIC
))) {
584 flags
&= ~EXEC_COMMAND_NO_SETUID
;
585 flags
|= EXEC_COMMAND_AMBIENT_MAGIC
;
591 r
= unit_full_printf(u
, f
, &path
);
593 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
594 "Failed to resolve unit specifiers in '%s'%s: %m",
595 f
, ignore
? ", ignoring" : "");
596 return ignore
? 0 : -ENOEXEC
;
600 /* First word is either "-" or "@" with no command. */
601 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
602 "Empty path in command line%s: '%s'",
603 ignore
? ", ignoring" : "", rvalue
);
604 return ignore
? 0 : -ENOEXEC
;
606 if (!string_is_safe(path
)) {
607 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
608 "Executable name contains special characters%s: %s",
609 ignore
? ", ignoring" : "", path
);
610 return ignore
? 0 : -ENOEXEC
;
612 if (endswith(path
, "/")) {
613 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
614 "Executable path specifies a directory%s: %s",
615 ignore
? ", ignoring" : "", path
);
616 return ignore
? 0 : -ENOEXEC
;
619 if (!path_is_absolute(path
)) {
623 if (!filename_is_valid(path
)) {
624 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
625 "Neither a valid executable name nor an absolute path%s: %s",
626 ignore
? ", ignoring" : "", path
);
627 return ignore
? 0 : -ENOEXEC
;
630 /* Resolve a single-component name to a full path */
631 NULSTR_FOREACH(prefix
, DEFAULT_PATH_NULSTR
) {
632 _cleanup_free_
char *fullpath
= NULL
;
634 fullpath
= strjoin(prefix
, "/", path
);
638 if (access(fullpath
, F_OK
) >= 0) {
639 free_and_replace(path
, fullpath
);
646 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
647 "Executable \"%s\" not found in path \"%s\"%s",
648 path
, DEFAULT_PATH
, ignore
? ", ignoring" : "");
649 return ignore
? 0 : -ENOEXEC
;
653 if (!separate_argv0
) {
656 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
666 path_simplify(path
, false);
668 while (!isempty(p
)) {
669 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
671 /* Check explicitly for an unquoted semicolon as
672 * command separator token. */
673 if (p
[0] == ';' && (!p
[1] || strchr(WHITESPACE
, p
[1]))) {
675 p
+= strspn(p
, WHITESPACE
);
680 /* Check for \; explicitly, to not confuse it with \\; or "\;" or "\\;" etc.
681 * extract_first_word() would return the same for all of those. */
682 if (p
[0] == '\\' && p
[1] == ';' && (!p
[2] || strchr(WHITESPACE
, p
[2]))) {
686 p
+= strspn(p
, WHITESPACE
);
688 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
699 r
= extract_first_word_and_warn(&p
, &word
, NULL
, EXTRACT_QUOTES
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
703 return ignore
? 0 : -ENOEXEC
;
705 r
= unit_full_printf(u
, word
, &resolved
);
707 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
708 "Failed to resolve unit specifiers in %s%s: %m",
709 word
, ignore
? ", ignoring" : "");
710 return ignore
? 0 : -ENOEXEC
;
713 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
716 n
[nlen
++] = TAKE_PTR(resolved
);
721 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
722 "Empty executable name or zeroeth argument%s: %s",
723 ignore
? ", ignoring" : "", rvalue
);
724 return ignore
? 0 : -ENOEXEC
;
727 nce
= new0(ExecCommand
, 1);
731 nce
->argv
= TAKE_PTR(n
);
732 nce
->path
= TAKE_PTR(path
);
735 exec_command_append_list(e
, nce
);
737 /* Do not _cleanup_free_ these. */
746 int config_parse_socket_bindtodevice(
748 const char *filename
,
751 unsigned section_line
,
765 if (isempty(rvalue
) || streq(rvalue
, "*")) {
766 s
->bind_to_device
= mfree(s
->bind_to_device
);
770 if (!ifname_valid(rvalue
)) {
771 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid interface name, ignoring: %s", rvalue
);
775 if (free_and_strdup(&s
->bind_to_device
, rvalue
) < 0)
781 int config_parse_exec_input(
783 const char *filename
,
786 unsigned section_line
,
793 ExecContext
*c
= data
;
804 n
= startswith(rvalue
, "fd:");
806 _cleanup_free_
char *resolved
= NULL
;
808 r
= unit_full_printf(u
, n
, &resolved
);
810 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s': %m", n
);
812 if (isempty(resolved
))
813 resolved
= mfree(resolved
);
814 else if (!fdname_is_valid(resolved
)) {
815 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name: %s", resolved
);
819 free_and_replace(c
->stdio_fdname
[STDIN_FILENO
], resolved
);
821 ei
= EXEC_INPUT_NAMED_FD
;
823 } else if ((n
= startswith(rvalue
, "file:"))) {
824 _cleanup_free_
char *resolved
= NULL
;
826 r
= unit_full_printf(u
, n
, &resolved
);
828 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s': %m", n
);
830 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
834 free_and_replace(c
->stdio_file
[STDIN_FILENO
], resolved
);
836 ei
= EXEC_INPUT_FILE
;
839 ei
= exec_input_from_string(rvalue
);
841 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse input specifier, ignoring: %s", rvalue
);
850 int config_parse_exec_input_text(
852 const char *filename
,
855 unsigned section_line
,
862 _cleanup_free_
char *unescaped
= NULL
, *resolved
= NULL
;
863 ExecContext
*c
= data
;
874 if (isempty(rvalue
)) {
875 /* Reset if the empty string is assigned */
876 c
->stdin_data
= mfree(c
->stdin_data
);
877 c
->stdin_data_size
= 0;
881 r
= cunescape(rvalue
, 0, &unescaped
);
883 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to decode C escaped text '%s': %m", rvalue
);
885 r
= unit_full_printf(u
, unescaped
, &resolved
);
887 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s': %m", unescaped
);
889 sz
= strlen(resolved
);
890 if (c
->stdin_data_size
+ sz
+ 1 < c
->stdin_data_size
|| /* check for overflow */
891 c
->stdin_data_size
+ sz
+ 1 > EXEC_STDIN_DATA_MAX
) {
892 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
);
896 p
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
+ 1);
900 *((char*) mempcpy((char*) p
+ c
->stdin_data_size
, resolved
, sz
)) = '\n';
903 c
->stdin_data_size
+= sz
+ 1;
908 int config_parse_exec_input_data(
910 const char *filename
,
913 unsigned section_line
,
920 _cleanup_free_
void *p
= NULL
;
921 ExecContext
*c
= data
;
931 if (isempty(rvalue
)) {
932 /* Reset if the empty string is assigned */
933 c
->stdin_data
= mfree(c
->stdin_data
);
934 c
->stdin_data_size
= 0;
938 r
= unbase64mem(rvalue
, (size_t) -1, &p
, &sz
);
940 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to decode base64 data, ignoring: %s", rvalue
);
944 if (c
->stdin_data_size
+ sz
< c
->stdin_data_size
|| /* check for overflow */
945 c
->stdin_data_size
+ sz
> EXEC_STDIN_DATA_MAX
) {
946 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
);
950 q
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
);
954 memcpy((uint8_t*) q
+ c
->stdin_data_size
, p
, sz
);
957 c
->stdin_data_size
+= sz
;
962 int config_parse_exec_output(
964 const char *filename
,
967 unsigned section_line
,
974 _cleanup_free_
char *resolved
= NULL
;
976 ExecContext
*c
= data
;
987 n
= startswith(rvalue
, "fd:");
989 r
= unit_full_printf(u
, n
, &resolved
);
991 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", n
);
993 if (isempty(resolved
))
994 resolved
= mfree(resolved
);
995 else if (!fdname_is_valid(resolved
)) {
996 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name: %s", resolved
);
1000 eo
= EXEC_OUTPUT_NAMED_FD
;
1002 } else if ((n
= startswith(rvalue
, "file:"))) {
1004 r
= unit_full_printf(u
, n
, &resolved
);
1006 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", n
);
1008 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1012 eo
= EXEC_OUTPUT_FILE
;
1014 } else if ((n
= startswith(rvalue
, "append:"))) {
1016 r
= unit_full_printf(u
, n
, &resolved
);
1018 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", n
);
1020 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1024 eo
= EXEC_OUTPUT_FILE_APPEND
;
1026 eo
= exec_output_from_string(rvalue
);
1028 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse output specifier, ignoring: %s", rvalue
);
1033 if (streq(lvalue
, "StandardOutput")) {
1034 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1035 free_and_replace(c
->stdio_fdname
[STDOUT_FILENO
], resolved
);
1037 free_and_replace(c
->stdio_file
[STDOUT_FILENO
], resolved
);
1042 assert(streq(lvalue
, "StandardError"));
1044 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1045 free_and_replace(c
->stdio_fdname
[STDERR_FILENO
], resolved
);
1047 free_and_replace(c
->stdio_file
[STDERR_FILENO
], resolved
);
1055 int config_parse_exec_io_class(const char *unit
,
1056 const char *filename
,
1058 const char *section
,
1059 unsigned section_line
,
1066 ExecContext
*c
= data
;
1074 if (isempty(rvalue
)) {
1075 c
->ioprio_set
= false;
1076 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE
, 0);
1080 x
= ioprio_class_from_string(rvalue
);
1082 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse IO scheduling class, ignoring: %s", rvalue
);
1086 c
->ioprio
= IOPRIO_PRIO_VALUE(x
, IOPRIO_PRIO_DATA(c
->ioprio
));
1087 c
->ioprio_set
= true;
1092 int config_parse_exec_io_priority(const char *unit
,
1093 const char *filename
,
1095 const char *section
,
1096 unsigned section_line
,
1103 ExecContext
*c
= data
;
1111 if (isempty(rvalue
)) {
1112 c
->ioprio_set
= false;
1113 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE
, 0);
1117 r
= ioprio_parse_priority(rvalue
, &i
);
1119 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse IO priority, ignoring: %s", rvalue
);
1123 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_PRIO_CLASS(c
->ioprio
), i
);
1124 c
->ioprio_set
= true;
1129 int config_parse_exec_cpu_sched_policy(const char *unit
,
1130 const char *filename
,
1132 const char *section
,
1133 unsigned section_line
,
1140 ExecContext
*c
= data
;
1148 if (isempty(rvalue
)) {
1149 c
->cpu_sched_set
= false;
1150 c
->cpu_sched_policy
= SCHED_OTHER
;
1151 c
->cpu_sched_priority
= 0;
1155 x
= sched_policy_from_string(rvalue
);
1157 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse CPU scheduling policy, ignoring: %s", rvalue
);
1161 c
->cpu_sched_policy
= x
;
1162 /* Moving to or from real-time policy? We need to adjust the priority */
1163 c
->cpu_sched_priority
= CLAMP(c
->cpu_sched_priority
, sched_get_priority_min(x
), sched_get_priority_max(x
));
1164 c
->cpu_sched_set
= true;
1169 int config_parse_exec_cpu_sched_prio(const char *unit
,
1170 const char *filename
,
1172 const char *section
,
1173 unsigned section_line
,
1180 ExecContext
*c
= data
;
1188 r
= safe_atoi(rvalue
, &i
);
1190 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse CPU scheduling priority, ignoring: %s", rvalue
);
1194 /* On Linux RR/FIFO range from 1 to 99 and OTHER/BATCH may only be 0 */
1195 min
= sched_get_priority_min(c
->cpu_sched_policy
);
1196 max
= sched_get_priority_max(c
->cpu_sched_policy
);
1198 if (i
< min
|| i
> max
) {
1199 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "CPU scheduling priority is out of range, ignoring: %s", rvalue
);
1203 c
->cpu_sched_priority
= i
;
1204 c
->cpu_sched_set
= true;
1209 int config_parse_exec_cpu_affinity(const char *unit
,
1210 const char *filename
,
1212 const char *section
,
1213 unsigned section_line
,
1220 ExecContext
*c
= data
;
1221 _cleanup_cpu_free_ cpu_set_t
*cpuset
= NULL
;
1229 ncpus
= parse_cpu_set_and_warn(rvalue
, &cpuset
, unit
, filename
, line
, lvalue
);
1234 /* An empty assignment resets the CPU list */
1235 c
->cpuset
= cpu_set_mfree(c
->cpuset
);
1236 c
->cpuset_ncpus
= 0;
1241 c
->cpuset
= TAKE_PTR(cpuset
);
1242 c
->cpuset_ncpus
= (unsigned) ncpus
;
1246 if (c
->cpuset_ncpus
< (unsigned) ncpus
) {
1247 CPU_OR_S(CPU_ALLOC_SIZE(c
->cpuset_ncpus
), cpuset
, c
->cpuset
, cpuset
);
1248 CPU_FREE(c
->cpuset
);
1249 c
->cpuset
= TAKE_PTR(cpuset
);
1250 c
->cpuset_ncpus
= (unsigned) ncpus
;
1254 CPU_OR_S(CPU_ALLOC_SIZE((unsigned) ncpus
), c
->cpuset
, c
->cpuset
, cpuset
);
1259 int config_parse_capability_set(
1261 const char *filename
,
1263 const char *section
,
1264 unsigned section_line
,
1271 uint64_t *capability_set
= data
;
1272 uint64_t sum
= 0, initial
= 0;
1273 bool invert
= false;
1281 if (rvalue
[0] == '~') {
1286 if (streq(lvalue
, "CapabilityBoundingSet"))
1287 initial
= CAP_ALL
; /* initialized to all bits on */
1288 /* else "AmbientCapabilities" initialized to all bits off */
1290 r
= capability_set_from_string(rvalue
, &sum
);
1292 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= specifier '%s', ignoring: %m", lvalue
, rvalue
);
1296 if (sum
== 0 || *capability_set
== initial
)
1297 /* "", "~" or uninitialized data -> replace */
1298 *capability_set
= invert
? ~sum
: sum
;
1300 /* previous data -> merge */
1302 *capability_set
&= ~sum
;
1304 *capability_set
|= sum
;
1310 int config_parse_exec_selinux_context(
1312 const char *filename
,
1314 const char *section
,
1315 unsigned section_line
,
1322 ExecContext
*c
= data
;
1333 if (isempty(rvalue
)) {
1334 c
->selinux_context
= mfree(c
->selinux_context
);
1335 c
->selinux_context_ignore
= false;
1339 if (rvalue
[0] == '-') {
1345 r
= unit_full_printf(u
, rvalue
, &k
);
1347 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1348 "Failed to resolve unit specifiers in '%s'%s: %m",
1349 rvalue
, ignore
? ", ignoring" : "");
1350 return ignore
? 0 : -ENOEXEC
;
1353 free_and_replace(c
->selinux_context
, k
);
1354 c
->selinux_context_ignore
= ignore
;
1359 int config_parse_exec_apparmor_profile(
1361 const char *filename
,
1363 const char *section
,
1364 unsigned section_line
,
1371 ExecContext
*c
= data
;
1382 if (isempty(rvalue
)) {
1383 c
->apparmor_profile
= mfree(c
->apparmor_profile
);
1384 c
->apparmor_profile_ignore
= false;
1388 if (rvalue
[0] == '-') {
1394 r
= unit_full_printf(u
, rvalue
, &k
);
1396 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1397 "Failed to resolve unit specifiers in '%s'%s: %m",
1398 rvalue
, ignore
? ", ignoring" : "");
1399 return ignore
? 0 : -ENOEXEC
;
1402 free_and_replace(c
->apparmor_profile
, k
);
1403 c
->apparmor_profile_ignore
= ignore
;
1408 int config_parse_exec_smack_process_label(
1410 const char *filename
,
1412 const char *section
,
1413 unsigned section_line
,
1420 ExecContext
*c
= data
;
1431 if (isempty(rvalue
)) {
1432 c
->smack_process_label
= mfree(c
->smack_process_label
);
1433 c
->smack_process_label_ignore
= false;
1437 if (rvalue
[0] == '-') {
1443 r
= unit_full_printf(u
, rvalue
, &k
);
1445 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1446 "Failed to resolve unit specifiers in '%s'%s: %m",
1447 rvalue
, ignore
? ", ignoring" : "");
1448 return ignore
? 0 : -ENOEXEC
;
1451 free_and_replace(c
->smack_process_label
, k
);
1452 c
->smack_process_label_ignore
= ignore
;
1457 int config_parse_timer(const char *unit
,
1458 const char *filename
,
1460 const char *section
,
1461 unsigned section_line
,
1472 _cleanup_(calendar_spec_freep
) CalendarSpec
*c
= NULL
;
1474 _cleanup_free_
char *k
= NULL
;
1482 if (isempty(rvalue
)) {
1483 /* Empty assignment resets list */
1484 timer_free_values(t
);
1488 b
= timer_base_from_string(lvalue
);
1490 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse timer base, ignoring: %s", lvalue
);
1494 r
= unit_full_printf(u
, rvalue
, &k
);
1496 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
1500 if (b
== TIMER_CALENDAR
) {
1501 if (calendar_spec_from_string(k
, &c
) < 0) {
1502 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse calendar specification, ignoring: %s", k
);
1506 if (parse_sec(k
, &usec
) < 0) {
1507 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse timer value, ignoring: %s", k
);
1511 v
= new0(TimerValue
, 1);
1517 v
->calendar_spec
= TAKE_PTR(c
);
1519 LIST_PREPEND(value
, t
->values
, v
);
1524 int config_parse_trigger_unit(
1526 const char *filename
,
1528 const char *section
,
1529 unsigned section_line
,
1536 _cleanup_free_
char *p
= NULL
;
1546 if (!hashmap_isempty(u
->dependencies
[UNIT_TRIGGERS
])) {
1547 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Multiple units to trigger specified, ignoring: %s", rvalue
);
1551 r
= unit_name_printf(u
, rvalue
, &p
);
1553 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
1557 type
= unit_name_to_type(p
);
1559 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit type not valid, ignoring: %s", rvalue
);
1562 if (unit_has_name(u
, p
)) {
1563 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Units cannot trigger themselves, ignoring: %s", rvalue
);
1567 r
= unit_add_two_dependencies_by_name(u
, UNIT_BEFORE
, UNIT_TRIGGERS
, p
, true, UNIT_DEPENDENCY_FILE
);
1569 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add trigger on %s, ignoring: %m", p
);
1576 int config_parse_path_spec(const char *unit
,
1577 const char *filename
,
1579 const char *section
,
1580 unsigned section_line
,
1590 _cleanup_free_
char *k
= NULL
;
1598 if (isempty(rvalue
)) {
1599 /* Empty assignment clears list */
1604 b
= path_type_from_string(lvalue
);
1606 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse path type, ignoring: %s", lvalue
);
1610 r
= unit_full_printf(UNIT(p
), rvalue
, &k
);
1612 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
1616 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
1620 s
= new0(PathSpec
, 1);
1625 s
->path
= TAKE_PTR(k
);
1629 LIST_PREPEND(spec
, p
->specs
, s
);
1634 int config_parse_socket_service(
1636 const char *filename
,
1638 const char *section
,
1639 unsigned section_line
,
1646 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1647 _cleanup_free_
char *p
= NULL
;
1657 r
= unit_name_printf(UNIT(s
), rvalue
, &p
);
1659 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", rvalue
);
1663 if (!endswith(p
, ".service")) {
1664 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit must be of type service: %s", rvalue
);
1668 r
= manager_load_unit(UNIT(s
)->manager
, p
, NULL
, &error
, &x
);
1670 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to load unit %s: %s", rvalue
, bus_error_message(&error
, r
));
1674 unit_ref_set(&s
->service
, UNIT(s
), x
);
1679 int config_parse_fdname(
1681 const char *filename
,
1683 const char *section
,
1684 unsigned section_line
,
1691 _cleanup_free_
char *p
= NULL
;
1700 if (isempty(rvalue
)) {
1701 s
->fdname
= mfree(s
->fdname
);
1705 r
= unit_full_printf(UNIT(s
), rvalue
, &p
);
1707 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
1711 if (!fdname_is_valid(p
)) {
1712 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", p
);
1716 return free_and_replace(s
->fdname
, p
);
1719 int config_parse_service_sockets(
1721 const char *filename
,
1723 const char *section
,
1724 unsigned section_line
,
1742 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
1744 r
= extract_first_word(&p
, &word
, NULL
, 0);
1750 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Trailing garbage in sockets, ignoring: %s", rvalue
);
1754 r
= unit_name_printf(UNIT(s
), word
, &k
);
1756 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
1760 if (!endswith(k
, ".socket")) {
1761 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit must be of type socket, ignoring: %s", k
);
1765 r
= unit_add_two_dependencies_by_name(UNIT(s
), UNIT_WANTS
, UNIT_AFTER
, k
, true, UNIT_DEPENDENCY_FILE
);
1767 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
1769 r
= unit_add_dependency_by_name(UNIT(s
), UNIT_TRIGGERED_BY
, k
, true, UNIT_DEPENDENCY_FILE
);
1771 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
1777 int config_parse_bus_name(
1779 const char *filename
,
1781 const char *section
,
1782 unsigned section_line
,
1789 _cleanup_free_
char *k
= NULL
;
1798 r
= unit_full_printf(u
, rvalue
, &k
);
1800 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
1804 if (!service_name_is_valid(k
)) {
1805 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid bus name, ignoring: %s", k
);
1809 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
1812 int config_parse_service_timeout(
1814 const char *filename
,
1816 const char *section
,
1817 unsigned section_line
,
1824 Service
*s
= userdata
;
1833 /* This is called for two cases: TimeoutSec= and TimeoutStartSec=. */
1835 /* Traditionally, these options accepted 0 to disable the timeouts. However, a timeout of 0 suggests it happens
1836 * immediately, hence fix this to become USEC_INFINITY instead. This is in-line with how we internally handle
1837 * all other timeouts. */
1838 r
= parse_sec_fix_0(rvalue
, &usec
);
1840 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
1844 s
->start_timeout_defined
= true;
1845 s
->timeout_start_usec
= usec
;
1847 if (streq(lvalue
, "TimeoutSec"))
1848 s
->timeout_stop_usec
= usec
;
1853 int config_parse_sec_fix_0(
1855 const char *filename
,
1857 const char *section
,
1858 unsigned section_line
,
1865 usec_t
*usec
= data
;
1873 /* This is pretty much like config_parse_sec(), except that this treats a time of 0 as infinity, for
1874 * compatibility with older versions of systemd where 0 instead of infinity was used as indicator to turn off a
1877 r
= parse_sec_fix_0(rvalue
, usec
);
1879 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
1886 int config_parse_user_group(
1888 const char *filename
,
1890 const char *section
,
1891 unsigned section_line
,
1898 _cleanup_free_
char *k
= NULL
;
1908 if (isempty(rvalue
)) {
1909 *user
= mfree(*user
);
1913 r
= unit_full_printf(u
, rvalue
, &k
);
1915 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", rvalue
);
1919 if (!valid_user_group_name_or_id(k
)) {
1920 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
1924 return free_and_replace(*user
, k
);
1927 int config_parse_user_group_strv(
1929 const char *filename
,
1931 const char *section
,
1932 unsigned section_line
,
1939 char ***users
= data
;
1941 const char *p
= rvalue
;
1949 if (isempty(rvalue
)) {
1950 *users
= strv_free(*users
);
1955 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
1957 r
= extract_first_word(&p
, &word
, NULL
, 0);
1963 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax: %s", rvalue
);
1967 r
= unit_full_printf(u
, word
, &k
);
1969 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", word
);
1973 if (!valid_user_group_name_or_id(k
)) {
1974 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
1978 r
= strv_push(users
, k
);
1988 int config_parse_working_directory(
1990 const char *filename
,
1992 const char *section
,
1993 unsigned section_line
,
2000 ExecContext
*c
= data
;
2011 if (isempty(rvalue
)) {
2012 c
->working_directory_home
= false;
2013 c
->working_directory
= mfree(c
->working_directory
);
2017 if (rvalue
[0] == '-') {
2023 if (streq(rvalue
, "~")) {
2024 c
->working_directory_home
= true;
2025 c
->working_directory
= mfree(c
->working_directory
);
2027 _cleanup_free_
char *k
= NULL
;
2029 r
= unit_full_printf(u
, rvalue
, &k
);
2031 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2032 "Failed to resolve unit specifiers in working directory path '%s'%s: %m",
2033 rvalue
, missing_ok
? ", ignoring" : "");
2034 return missing_ok
? 0 : -ENOEXEC
;
2037 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
| (missing_ok
? 0 : PATH_CHECK_FATAL
), unit
, filename
, line
, lvalue
);
2039 return missing_ok
? 0 : -ENOEXEC
;
2041 c
->working_directory_home
= false;
2042 free_and_replace(c
->working_directory
, k
);
2045 c
->working_directory_missing_ok
= missing_ok
;
2049 int config_parse_unit_env_file(const char *unit
,
2050 const char *filename
,
2052 const char *section
,
2053 unsigned section_line
,
2062 _cleanup_free_
char *n
= NULL
;
2070 if (isempty(rvalue
)) {
2071 /* Empty assignment frees the list */
2072 *env
= strv_free(*env
);
2076 r
= unit_full_printf(u
, rvalue
, &n
);
2078 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2082 r
= path_simplify_and_warn(n
[0] == '-' ? n
+ 1 : n
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2086 r
= strv_push(env
, n
);
2095 int config_parse_environ(
2097 const char *filename
,
2099 const char *section
,
2100 unsigned section_line
,
2117 if (isempty(rvalue
)) {
2118 /* Empty assignment resets the list */
2119 *env
= strv_free(*env
);
2123 for (p
= rvalue
;; ) {
2124 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2126 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_QUOTES
);
2132 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2133 "Invalid syntax, ignoring: %s", rvalue
);
2138 r
= unit_full_printf(u
, word
, &k
);
2140 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2141 "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2147 if (!env_assignment_is_valid(k
)) {
2148 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2149 "Invalid environment assignment, ignoring: %s", k
);
2153 r
= strv_env_replace(env
, k
);
2161 int config_parse_pass_environ(
2163 const char *filename
,
2165 const char *section
,
2166 unsigned section_line
,
2173 _cleanup_strv_free_
char **n
= NULL
;
2174 size_t nlen
= 0, nbufsize
= 0;
2175 char*** passenv
= data
;
2176 const char *p
= rvalue
;
2185 if (isempty(rvalue
)) {
2186 /* Empty assignment resets the list */
2187 *passenv
= strv_free(*passenv
);
2192 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2194 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
2200 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2201 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2206 r
= unit_full_printf(u
, word
, &k
);
2208 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2209 "Failed to resolve specifiers in %s, ignoring: %m", word
);
2215 if (!env_name_is_valid(k
)) {
2216 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2217 "Invalid environment name for %s, ignoring: %s", lvalue
, k
);
2221 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
2224 n
[nlen
++] = TAKE_PTR(k
);
2229 r
= strv_extend_strv(passenv
, n
, true);
2237 int config_parse_unset_environ(
2239 const char *filename
,
2241 const char *section
,
2242 unsigned section_line
,
2249 _cleanup_strv_free_
char **n
= NULL
;
2250 size_t nlen
= 0, nbufsize
= 0;
2251 char*** unsetenv
= data
;
2252 const char *p
= rvalue
;
2261 if (isempty(rvalue
)) {
2262 /* Empty assignment resets the list */
2263 *unsetenv
= strv_free(*unsetenv
);
2268 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2270 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_QUOTES
);
2276 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2277 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2282 r
= unit_full_printf(u
, word
, &k
);
2284 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2285 "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2291 if (!env_assignment_is_valid(k
) && !env_name_is_valid(k
)) {
2292 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2293 "Invalid environment name or assignment %s, ignoring: %s", lvalue
, k
);
2297 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
2300 n
[nlen
++] = TAKE_PTR(k
);
2305 r
= strv_extend_strv(unsetenv
, n
, true);
2313 int config_parse_log_extra_fields(
2315 const char *filename
,
2317 const char *section
,
2318 unsigned section_line
,
2325 ExecContext
*c
= data
;
2327 const char *p
= rvalue
;
2335 if (isempty(rvalue
)) {
2336 exec_context_free_log_extra_fields(c
);
2341 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2345 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_QUOTES
);
2351 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
2355 r
= unit_full_printf(u
, word
, &k
);
2357 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2361 eq
= strchr(k
, '=');
2363 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Log field lacks '=' character, ignoring: %s", k
);
2367 if (!journal_field_valid(k
, eq
-k
, false)) {
2368 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Log field name is invalid, ignoring: %s", k
);
2372 t
= reallocarray(c
->log_extra_fields
, c
->n_log_extra_fields
+1, sizeof(struct iovec
));
2376 c
->log_extra_fields
= t
;
2377 c
->log_extra_fields
[c
->n_log_extra_fields
++] = IOVEC_MAKE_STRING(k
);
2383 int config_parse_unit_condition_path(
2385 const char *filename
,
2387 const char *section
,
2388 unsigned section_line
,
2395 _cleanup_free_
char *p
= NULL
;
2396 Condition
**list
= data
, *c
;
2397 ConditionType t
= ltype
;
2398 bool trigger
, negate
;
2407 if (isempty(rvalue
)) {
2408 /* Empty assignment resets the list */
2409 *list
= condition_free_list(*list
);
2413 trigger
= rvalue
[0] == '|';
2417 negate
= rvalue
[0] == '!';
2421 r
= unit_full_printf(u
, rvalue
, &p
);
2423 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2427 r
= path_simplify_and_warn(p
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2431 c
= condition_new(t
, p
, trigger
, negate
);
2435 LIST_PREPEND(conditions
, *list
, c
);
2439 int config_parse_unit_condition_string(
2441 const char *filename
,
2443 const char *section
,
2444 unsigned section_line
,
2451 _cleanup_free_
char *s
= NULL
;
2452 Condition
**list
= data
, *c
;
2453 ConditionType t
= ltype
;
2454 bool trigger
, negate
;
2463 if (isempty(rvalue
)) {
2464 /* Empty assignment resets the list */
2465 *list
= condition_free_list(*list
);
2469 trigger
= rvalue
[0] == '|';
2473 negate
= rvalue
[0] == '!';
2477 r
= unit_full_printf(u
, rvalue
, &s
);
2479 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2483 c
= condition_new(t
, s
, trigger
, negate
);
2487 LIST_PREPEND(conditions
, *list
, c
);
2491 int config_parse_unit_condition_null(
2493 const char *filename
,
2495 const char *section
,
2496 unsigned section_line
,
2503 Condition
**list
= data
, *c
;
2504 bool trigger
, negate
;
2512 if (isempty(rvalue
)) {
2513 /* Empty assignment resets the list */
2514 *list
= condition_free_list(*list
);
2518 trigger
= rvalue
[0] == '|';
2522 negate
= rvalue
[0] == '!';
2526 b
= parse_boolean(rvalue
);
2528 log_syntax(unit
, LOG_ERR
, filename
, line
, b
, "Failed to parse boolean value in condition, ignoring: %s", rvalue
);
2535 c
= condition_new(CONDITION_NULL
, NULL
, trigger
, negate
);
2539 LIST_PREPEND(conditions
, *list
, c
);
2543 int config_parse_unit_requires_mounts_for(
2545 const char *filename
,
2547 const char *section
,
2548 unsigned section_line
,
2555 const char *p
= rvalue
;
2565 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
2567 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
2573 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2574 "Invalid syntax, ignoring: %s", rvalue
);
2578 r
= unit_full_printf(u
, word
, &resolved
);
2580 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
2584 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2588 r
= unit_require_mounts_for(u
, resolved
, UNIT_DEPENDENCY_FILE
);
2590 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add required mount '%s', ignoring: %m", resolved
);
2596 int config_parse_documentation(const char *unit
,
2597 const char *filename
,
2599 const char *section
,
2600 unsigned section_line
,
2616 if (isempty(rvalue
)) {
2617 /* Empty assignment resets the list */
2618 u
->documentation
= strv_free(u
->documentation
);
2622 r
= config_parse_unit_strv_printf(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
,
2623 rvalue
, data
, userdata
);
2627 for (a
= b
= u
->documentation
; a
&& *a
; a
++) {
2629 if (documentation_url_is_valid(*a
))
2632 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid URL, ignoring: %s", *a
);
2643 int config_parse_syscall_filter(
2645 const char *filename
,
2647 const char *section
,
2648 unsigned section_line
,
2655 ExecContext
*c
= data
;
2657 bool invert
= false;
2666 if (isempty(rvalue
)) {
2667 /* Empty assignment resets the list */
2668 c
->syscall_filter
= hashmap_free(c
->syscall_filter
);
2669 c
->syscall_whitelist
= false;
2673 if (rvalue
[0] == '~') {
2678 if (!c
->syscall_filter
) {
2679 c
->syscall_filter
= hashmap_new(NULL
);
2680 if (!c
->syscall_filter
)
2684 /* Allow everything but the ones listed */
2685 c
->syscall_whitelist
= false;
2687 /* Allow nothing but the ones listed */
2688 c
->syscall_whitelist
= true;
2690 /* Accept default syscalls if we are on a whitelist */
2691 r
= seccomp_parse_syscall_filter("@default", -1, c
->syscall_filter
, SECCOMP_PARSE_WHITELIST
);
2699 _cleanup_free_
char *word
= NULL
, *name
= NULL
;
2702 r
= extract_first_word(&p
, &word
, NULL
, 0);
2708 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
2712 r
= parse_syscall_and_errno(word
, &name
, &num
);
2714 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse syscall:errno, ignoring: %s", word
);
2718 r
= seccomp_parse_syscall_filter_full(name
, num
, c
->syscall_filter
,
2719 SECCOMP_PARSE_LOG
|SECCOMP_PARSE_PERMISSIVE
|(invert
? SECCOMP_PARSE_INVERT
: 0)|(c
->syscall_whitelist
? SECCOMP_PARSE_WHITELIST
: 0),
2720 unit
, filename
, line
);
2726 int config_parse_syscall_archs(
2728 const char *filename
,
2730 const char *section
,
2731 unsigned section_line
,
2738 const char *p
= rvalue
;
2742 if (isempty(rvalue
)) {
2743 *archs
= set_free(*archs
);
2747 r
= set_ensure_allocated(archs
, NULL
);
2752 _cleanup_free_
char *word
= NULL
;
2755 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
2761 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2762 "Invalid syntax, ignoring: %s", rvalue
);
2766 r
= seccomp_arch_from_string(word
, &a
);
2768 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2769 "Failed to parse system call architecture \"%s\", ignoring: %m", word
);
2773 r
= set_put(*archs
, UINT32_TO_PTR(a
+ 1));
2779 int config_parse_syscall_errno(
2781 const char *filename
,
2783 const char *section
,
2784 unsigned section_line
,
2791 ExecContext
*c
= data
;
2798 if (isempty(rvalue
)) {
2799 /* Empty assignment resets to KILL */
2800 c
->syscall_errno
= 0;
2804 e
= parse_errno(rvalue
);
2806 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse error number, ignoring: %s", rvalue
);
2810 c
->syscall_errno
= e
;
2814 int config_parse_address_families(
2816 const char *filename
,
2818 const char *section
,
2819 unsigned section_line
,
2826 ExecContext
*c
= data
;
2827 bool invert
= false;
2835 if (isempty(rvalue
)) {
2836 /* Empty assignment resets the list */
2837 c
->address_families
= set_free(c
->address_families
);
2838 c
->address_families_whitelist
= false;
2842 if (rvalue
[0] == '~') {
2847 if (!c
->address_families
) {
2848 c
->address_families
= set_new(NULL
);
2849 if (!c
->address_families
)
2852 c
->address_families_whitelist
= !invert
;
2855 for (p
= rvalue
;;) {
2856 _cleanup_free_
char *word
= NULL
;
2859 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
2865 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2866 "Invalid syntax, ignoring: %s", rvalue
);
2870 af
= af_from_name(word
);
2872 log_syntax(unit
, LOG_ERR
, filename
, line
, af
,
2873 "Failed to parse address family, ignoring: %s", word
);
2877 /* If we previously wanted to forbid an address family and now
2878 * we want to allow it, then just remove it from the list.
2880 if (!invert
== c
->address_families_whitelist
) {
2881 r
= set_put(c
->address_families
, INT_TO_PTR(af
));
2885 set_remove(c
->address_families
, INT_TO_PTR(af
));
2889 int config_parse_restrict_namespaces(
2891 const char *filename
,
2893 const char *section
,
2894 unsigned section_line
,
2901 ExecContext
*c
= data
;
2902 unsigned long flags
;
2903 bool invert
= false;
2906 if (isempty(rvalue
)) {
2907 /* Reset to the default. */
2908 c
->restrict_namespaces
= NAMESPACE_FLAGS_INITIAL
;
2912 /* Boolean parameter ignores the previous settings */
2913 r
= parse_boolean(rvalue
);
2915 c
->restrict_namespaces
= 0;
2917 } else if (r
== 0) {
2918 c
->restrict_namespaces
= NAMESPACE_FLAGS_ALL
;
2922 if (rvalue
[0] == '~') {
2927 /* Not a boolean argument, in this case it's a list of namespace types. */
2928 r
= namespace_flags_from_string(rvalue
, &flags
);
2930 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse namespace type string, ignoring: %s", rvalue
);
2934 if (c
->restrict_namespaces
== NAMESPACE_FLAGS_INITIAL
)
2935 /* Initial assignment. Just set the value. */
2936 c
->restrict_namespaces
= invert
? (~flags
) & NAMESPACE_FLAGS_ALL
: flags
;
2938 /* Merge the value with the previous one. */
2939 SET_FLAG(c
->restrict_namespaces
, flags
, !invert
);
2945 int config_parse_unit_slice(
2947 const char *filename
,
2949 const char *section
,
2950 unsigned section_line
,
2957 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
2958 _cleanup_free_
char *k
= NULL
;
2959 Unit
*u
= userdata
, *slice
= NULL
;
2967 r
= unit_name_printf(u
, rvalue
, &k
);
2969 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2973 r
= manager_load_unit(u
->manager
, k
, NULL
, &error
, &slice
);
2975 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to load slice unit %s, ignoring: %s", k
, bus_error_message(&error
, r
));
2979 r
= unit_set_slice(u
, slice
);
2981 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to assign slice %s to unit %s, ignoring: %m", slice
->id
, u
->id
);
2988 int config_parse_cpu_quota(
2990 const char *filename
,
2992 const char *section
,
2993 unsigned section_line
,
3000 CGroupContext
*c
= data
;
3007 if (isempty(rvalue
)) {
3008 c
->cpu_quota_per_sec_usec
= USEC_INFINITY
;
3012 r
= parse_permille_unbounded(rvalue
);
3014 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid CPU quota '%s', ignoring.", rvalue
);
3018 c
->cpu_quota_per_sec_usec
= ((usec_t
) r
* USEC_PER_SEC
) / 1000U;
3022 int config_parse_memory_limit(
3024 const char *filename
,
3026 const char *section
,
3027 unsigned section_line
,
3034 CGroupContext
*c
= data
;
3035 uint64_t bytes
= CGROUP_LIMIT_MAX
;
3038 if (!isempty(rvalue
) && !streq(rvalue
, "infinity")) {
3040 r
= parse_permille(rvalue
);
3042 r
= parse_size(rvalue
, 1024, &bytes
);
3044 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid memory limit '%s', ignoring: %m", rvalue
);
3048 bytes
= physical_memory_scale(r
, 1000U);
3050 if (bytes
>= UINT64_MAX
||
3051 (bytes
<= 0 && !streq(lvalue
, "MemorySwapMax"))) {
3052 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Memory limit '%s' out of range, ignoring.", rvalue
);
3057 if (streq(lvalue
, "MemoryMin"))
3058 c
->memory_min
= bytes
;
3059 else if (streq(lvalue
, "MemoryLow"))
3060 c
->memory_low
= bytes
;
3061 else if (streq(lvalue
, "MemoryHigh"))
3062 c
->memory_high
= bytes
;
3063 else if (streq(lvalue
, "MemoryMax"))
3064 c
->memory_max
= bytes
;
3065 else if (streq(lvalue
, "MemorySwapMax"))
3066 c
->memory_swap_max
= bytes
;
3067 else if (streq(lvalue
, "MemoryLimit"))
3068 c
->memory_limit
= bytes
;
3075 int config_parse_tasks_max(
3077 const char *filename
,
3079 const char *section
,
3080 unsigned section_line
,
3087 uint64_t *tasks_max
= data
, v
;
3091 if (isempty(rvalue
)) {
3092 *tasks_max
= u
? u
->manager
->default_tasks_max
: UINT64_MAX
;
3096 if (streq(rvalue
, "infinity")) {
3097 *tasks_max
= CGROUP_LIMIT_MAX
;
3101 r
= parse_permille(rvalue
);
3103 r
= safe_atou64(rvalue
, &v
);
3105 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid maximum tasks value '%s', ignoring: %m", rvalue
);
3109 v
= system_tasks_max_scale(r
, 1000U);
3111 if (v
<= 0 || v
>= UINT64_MAX
) {
3112 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Maximum tasks value '%s' out of range, ignoring.", rvalue
);
3120 int config_parse_delegate(
3122 const char *filename
,
3124 const char *section
,
3125 unsigned section_line
,
3132 CGroupContext
*c
= data
;
3136 t
= unit_name_to_type(unit
);
3137 assert(t
!= _UNIT_TYPE_INVALID
);
3139 if (!unit_vtable
[t
]->can_delegate
) {
3140 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Delegate= setting not supported for this unit type, ignoring.");
3144 /* We either accept a boolean value, which may be used to turn on delegation for all controllers, or turn it
3145 * off for all. Or it takes a list of controller names, in which case we add the specified controllers to the
3146 * mask to delegate. */
3148 if (isempty(rvalue
)) {
3149 /* An empty string resets controllers and set Delegate=yes. */
3151 c
->delegate_controllers
= 0;
3155 r
= parse_boolean(rvalue
);
3157 const char *p
= rvalue
;
3158 CGroupMask mask
= 0;
3161 _cleanup_free_
char *word
= NULL
;
3162 CGroupController cc
;
3164 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
3170 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3174 cc
= cgroup_controller_from_string(word
);
3176 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid controller name '%s', ignoring", word
);
3180 mask
|= CGROUP_CONTROLLER_TO_MASK(cc
);
3184 c
->delegate_controllers
|= mask
;
3188 c
->delegate_controllers
= _CGROUP_MASK_ALL
;
3190 c
->delegate
= false;
3191 c
->delegate_controllers
= 0;
3197 int config_parse_device_allow(
3199 const char *filename
,
3201 const char *section
,
3202 unsigned section_line
,
3209 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3210 CGroupContext
*c
= data
;
3211 const char *p
= rvalue
;
3214 if (isempty(rvalue
)) {
3215 while (c
->device_allow
)
3216 cgroup_context_free_device_allow(c
, c
->device_allow
);
3221 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_QUOTES
);
3225 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3226 "Invalid syntax, ignoring: %s", rvalue
);
3230 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3231 "Failed to extract device path and rights from '%s', ignoring.", rvalue
);
3235 r
= unit_full_printf(userdata
, path
, &resolved
);
3237 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3238 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3242 if (!STARTSWITH_SET(resolved
, "block-", "char-")) {
3244 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3248 if (!valid_device_node_path(resolved
)) {
3249 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device node path '%s', ignoring.", resolved
);
3254 if (!isempty(p
) && !in_charset(p
, "rwm")) {
3255 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device rights '%s', ignoring.", p
);
3259 return cgroup_add_device_allow(c
, resolved
, p
);
3262 int config_parse_io_device_weight(
3264 const char *filename
,
3266 const char *section
,
3267 unsigned section_line
,
3274 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3275 CGroupIODeviceWeight
*w
;
3276 CGroupContext
*c
= data
;
3277 const char *p
= rvalue
;
3285 if (isempty(rvalue
)) {
3286 while (c
->io_device_weights
)
3287 cgroup_context_free_io_device_weight(c
, c
->io_device_weights
);
3292 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_QUOTES
);
3296 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3297 "Invalid syntax, ignoring: %s", rvalue
);
3300 if (r
== 0 || isempty(p
)) {
3301 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3302 "Failed to extract device path and weight from '%s', ignoring.", rvalue
);
3306 r
= unit_full_printf(userdata
, path
, &resolved
);
3308 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3309 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3313 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3317 r
= cg_weight_parse(p
, &u
);
3319 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "IO weight '%s' invalid, ignoring: %m", p
);
3323 assert(u
!= CGROUP_WEIGHT_INVALID
);
3325 w
= new0(CGroupIODeviceWeight
, 1);
3329 w
->path
= TAKE_PTR(resolved
);
3332 LIST_PREPEND(device_weights
, c
->io_device_weights
, w
);
3336 int config_parse_io_device_latency(
3338 const char *filename
,
3340 const char *section
,
3341 unsigned section_line
,
3348 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3349 CGroupIODeviceLatency
*l
;
3350 CGroupContext
*c
= data
;
3351 const char *p
= rvalue
;
3359 if (isempty(rvalue
)) {
3360 while (c
->io_device_latencies
)
3361 cgroup_context_free_io_device_latency(c
, c
->io_device_latencies
);
3366 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_QUOTES
);
3370 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3371 "Invalid syntax, ignoring: %s", rvalue
);
3374 if (r
== 0 || isempty(p
)) {
3375 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3376 "Failed to extract device path and latency from '%s', ignoring.", rvalue
);
3380 r
= unit_full_printf(userdata
, path
, &resolved
);
3382 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3383 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3387 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3391 if (parse_sec(p
, &usec
) < 0) {
3392 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse timer value, ignoring: %s", p
);
3396 l
= new0(CGroupIODeviceLatency
, 1);
3400 l
->path
= TAKE_PTR(resolved
);
3401 l
->target_usec
= usec
;
3403 LIST_PREPEND(device_latencies
, c
->io_device_latencies
, l
);
3407 int config_parse_io_limit(
3409 const char *filename
,
3411 const char *section
,
3412 unsigned section_line
,
3419 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3420 CGroupIODeviceLimit
*l
= NULL
, *t
;
3421 CGroupContext
*c
= data
;
3422 CGroupIOLimitType type
;
3423 const char *p
= rvalue
;
3431 type
= cgroup_io_limit_type_from_string(lvalue
);
3434 if (isempty(rvalue
)) {
3435 LIST_FOREACH(device_limits
, l
, c
->io_device_limits
)
3436 l
->limits
[type
] = cgroup_io_limit_defaults
[type
];
3440 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_QUOTES
);
3444 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3445 "Invalid syntax, ignoring: %s", rvalue
);
3448 if (r
== 0 || isempty(p
)) {
3449 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3450 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
3454 r
= unit_full_printf(userdata
, path
, &resolved
);
3456 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3457 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3461 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3465 if (streq("infinity", p
))
3466 num
= CGROUP_LIMIT_MAX
;
3468 r
= parse_size(p
, 1000, &num
);
3469 if (r
< 0 || num
<= 0) {
3470 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid IO limit '%s', ignoring.", p
);
3475 LIST_FOREACH(device_limits
, t
, c
->io_device_limits
) {
3476 if (path_equal(resolved
, t
->path
)) {
3483 CGroupIOLimitType ttype
;
3485 l
= new0(CGroupIODeviceLimit
, 1);
3489 l
->path
= TAKE_PTR(resolved
);
3490 for (ttype
= 0; ttype
< _CGROUP_IO_LIMIT_TYPE_MAX
; ttype
++)
3491 l
->limits
[ttype
] = cgroup_io_limit_defaults
[ttype
];
3493 LIST_PREPEND(device_limits
, c
->io_device_limits
, l
);
3496 l
->limits
[type
] = num
;
3501 int config_parse_blockio_device_weight(
3503 const char *filename
,
3505 const char *section
,
3506 unsigned section_line
,
3513 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3514 CGroupBlockIODeviceWeight
*w
;
3515 CGroupContext
*c
= data
;
3516 const char *p
= rvalue
;
3524 if (isempty(rvalue
)) {
3525 while (c
->blockio_device_weights
)
3526 cgroup_context_free_blockio_device_weight(c
, c
->blockio_device_weights
);
3531 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_QUOTES
);
3535 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3536 "Invalid syntax, ignoring: %s", rvalue
);
3539 if (r
== 0 || isempty(p
)) {
3540 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3541 "Failed to extract device node and weight from '%s', ignoring.", rvalue
);
3545 r
= unit_full_printf(userdata
, path
, &resolved
);
3547 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3548 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3552 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3556 r
= cg_blkio_weight_parse(p
, &u
);
3558 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid block IO weight '%s', ignoring: %m", p
);
3562 assert(u
!= CGROUP_BLKIO_WEIGHT_INVALID
);
3564 w
= new0(CGroupBlockIODeviceWeight
, 1);
3568 w
->path
= TAKE_PTR(resolved
);
3571 LIST_PREPEND(device_weights
, c
->blockio_device_weights
, w
);
3575 int config_parse_blockio_bandwidth(
3577 const char *filename
,
3579 const char *section
,
3580 unsigned section_line
,
3587 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3588 CGroupBlockIODeviceBandwidth
*b
= NULL
, *t
;
3589 CGroupContext
*c
= data
;
3590 const char *p
= rvalue
;
3599 read
= streq("BlockIOReadBandwidth", lvalue
);
3601 if (isempty(rvalue
)) {
3602 LIST_FOREACH(device_bandwidths
, b
, c
->blockio_device_bandwidths
) {
3603 b
->rbps
= CGROUP_LIMIT_MAX
;
3604 b
->wbps
= CGROUP_LIMIT_MAX
;
3609 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_QUOTES
);
3613 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3614 "Invalid syntax, ignoring: %s", rvalue
);
3617 if (r
== 0 || isempty(p
)) {
3618 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3619 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
3623 r
= unit_full_printf(userdata
, path
, &resolved
);
3625 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3626 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3630 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3634 r
= parse_size(p
, 1000, &bytes
);
3635 if (r
< 0 || bytes
<= 0) {
3636 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid Block IO Bandwidth '%s', ignoring.", p
);
3640 LIST_FOREACH(device_bandwidths
, t
, c
->blockio_device_bandwidths
) {
3641 if (path_equal(resolved
, t
->path
)) {
3648 b
= new0(CGroupBlockIODeviceBandwidth
, 1);
3652 b
->path
= TAKE_PTR(resolved
);
3653 b
->rbps
= CGROUP_LIMIT_MAX
;
3654 b
->wbps
= CGROUP_LIMIT_MAX
;
3656 LIST_PREPEND(device_bandwidths
, c
->blockio_device_bandwidths
, b
);
3667 int config_parse_job_mode_isolate(
3669 const char *filename
,
3671 const char *section
,
3672 unsigned section_line
,
3686 r
= parse_boolean(rvalue
);
3688 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse boolean, ignoring: %s", rvalue
);
3692 log_notice("%s is deprecated. Please use OnFailureJobMode= instead", lvalue
);
3694 *m
= r
? JOB_ISOLATE
: JOB_REPLACE
;
3698 int config_parse_exec_directories(
3700 const char *filename
,
3702 const char *section
,
3703 unsigned section_line
,
3720 if (isempty(rvalue
)) {
3721 /* Empty assignment resets the list */
3722 *rt
= strv_free(*rt
);
3726 for (p
= rvalue
;;) {
3727 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
3729 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
3733 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3734 "Invalid syntax, ignoring: %s", rvalue
);
3740 r
= unit_full_printf(u
, word
, &k
);
3742 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
3743 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
3747 r
= path_simplify_and_warn(k
, PATH_CHECK_RELATIVE
, unit
, filename
, line
, lvalue
);
3751 if (path_startswith(k
, "private")) {
3752 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
3753 "%s= path can't be 'private', ingoring assignment: %s", lvalue
, word
);
3757 r
= strv_push(rt
, k
);
3764 int config_parse_set_status(
3766 const char *filename
,
3768 const char *section
,
3769 unsigned section_line
,
3777 const char *word
, *state
;
3779 ExitStatusSet
*status_set
= data
;
3786 /* Empty assignment resets the list */
3787 if (isempty(rvalue
)) {
3788 exit_status_set_free(status_set
);
3792 FOREACH_WORD(word
, l
, rvalue
, state
) {
3793 _cleanup_free_
char *temp
;
3797 temp
= strndup(word
, l
);
3801 r
= safe_atoi(temp
, &val
);
3803 val
= signal_from_string(temp
);
3806 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse value, ignoring: %s", word
);
3809 set
= &status_set
->signal
;
3811 if (val
< 0 || val
> 255) {
3812 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Value %d is outside range 0-255, ignoring", val
);
3815 set
= &status_set
->status
;
3818 r
= set_ensure_allocated(set
, NULL
);
3822 r
= set_put(*set
, INT_TO_PTR(val
));
3826 if (!isempty(state
))
3827 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Trailing garbage, ignoring.");
3832 int config_parse_namespace_path_strv(
3834 const char *filename
,
3836 const char *section
,
3837 unsigned section_line
,
3846 const char *p
= rvalue
;
3854 if (isempty(rvalue
)) {
3855 /* Empty assignment resets the list */
3856 *sv
= strv_free(*sv
);
3861 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
, *joined
= NULL
;
3863 bool ignore_enoent
= false, shall_prefix
= false;
3865 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
3871 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
3876 if (startswith(w
, "-")) {
3877 ignore_enoent
= true;
3880 if (startswith(w
, "+")) {
3881 shall_prefix
= true;
3885 r
= unit_full_printf(u
, w
, &resolved
);
3887 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", w
);
3891 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
3895 joined
= strjoin(ignore_enoent
? "-" : "",
3896 shall_prefix
? "+" : "",
3899 r
= strv_push(sv
, joined
);
3909 int config_parse_temporary_filesystems(
3911 const char *filename
,
3913 const char *section
,
3914 unsigned section_line
,
3922 ExecContext
*c
= data
;
3923 const char *p
= rvalue
;
3931 if (isempty(rvalue
)) {
3932 /* Empty assignment resets the list */
3933 temporary_filesystem_free_many(c
->temporary_filesystems
, c
->n_temporary_filesystems
);
3934 c
->temporary_filesystems
= NULL
;
3935 c
->n_temporary_filesystems
= 0;
3940 _cleanup_free_
char *word
= NULL
, *path
= NULL
, *resolved
= NULL
;
3943 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
3949 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
3954 r
= extract_first_word(&w
, &path
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
3958 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", word
);
3962 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid syntax, ignoring: %s", word
);
3966 r
= unit_full_printf(u
, path
, &resolved
);
3968 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", path
);
3972 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
3976 r
= temporary_filesystem_add(&c
->temporary_filesystems
, &c
->n_temporary_filesystems
, resolved
, w
);
3982 int config_parse_bind_paths(
3984 const char *filename
,
3986 const char *section
,
3987 unsigned section_line
,
3994 ExecContext
*c
= data
;
4004 if (isempty(rvalue
)) {
4005 /* Empty assignment resets the list */
4006 bind_mount_free_many(c
->bind_mounts
, c
->n_bind_mounts
);
4007 c
->bind_mounts
= NULL
;
4008 c
->n_bind_mounts
= 0;
4014 _cleanup_free_
char *source
= NULL
, *destination
= NULL
;
4015 _cleanup_free_
char *sresolved
= NULL
, *dresolved
= NULL
;
4016 char *s
= NULL
, *d
= NULL
;
4017 bool rbind
= true, ignore_enoent
= false;
4019 r
= extract_first_word(&p
, &source
, ":" WHITESPACE
, EXTRACT_QUOTES
|EXTRACT_DONT_COALESCE_SEPARATORS
);
4025 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
4029 r
= unit_full_printf(u
, source
, &sresolved
);
4031 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4032 "Failed to resolved unit specifiers in \"%s\", ignoring: %m", source
);
4038 ignore_enoent
= true;
4042 r
= path_simplify_and_warn(s
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4046 /* Optionally, the destination is specified. */
4047 if (p
&& p
[-1] == ':') {
4048 r
= extract_first_word(&p
, &destination
, ":" WHITESPACE
, EXTRACT_QUOTES
|EXTRACT_DONT_COALESCE_SEPARATORS
);
4052 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
4056 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Missing argument after ':', ignoring: %s", s
);
4060 r
= unit_full_printf(u
, destination
, &dresolved
);
4062 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4063 "Failed to resolved specifiers in \"%s\", ignoring: %m", destination
);
4067 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4073 /* Optionally, there's also a short option string specified */
4074 if (p
&& p
[-1] == ':') {
4075 _cleanup_free_
char *options
= NULL
;
4077 r
= extract_first_word(&p
, &options
, NULL
, EXTRACT_QUOTES
);
4081 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s: %s", lvalue
, rvalue
);
4085 if (isempty(options
) || streq(options
, "rbind"))
4087 else if (streq(options
, "norbind"))
4090 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid option string, ignoring setting: %s", options
);
4097 r
= bind_mount_add(&c
->bind_mounts
, &c
->n_bind_mounts
,
4101 .read_only
= !!strstr(lvalue
, "ReadOnly"),
4103 .ignore_enoent
= ignore_enoent
,
4112 int config_parse_job_timeout_sec(
4114 const char *filename
,
4116 const char *section
,
4117 unsigned section_line
,
4133 r
= parse_sec_fix_0(rvalue
, &usec
);
4135 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse JobTimeoutSec= parameter, ignoring: %s", rvalue
);
4139 /* If the user explicitly changed JobTimeoutSec= also change JobRunningTimeoutSec=, for compatibility with old
4140 * versions. If JobRunningTimeoutSec= was explicitly set, avoid this however as whatever the user picked should
4143 if (!u
->job_running_timeout_set
)
4144 u
->job_running_timeout
= usec
;
4146 u
->job_timeout
= usec
;
4151 int config_parse_job_running_timeout_sec(
4153 const char *filename
,
4155 const char *section
,
4156 unsigned section_line
,
4172 r
= parse_sec_fix_0(rvalue
, &usec
);
4174 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse JobRunningTimeoutSec= parameter, ignoring: %s", rvalue
);
4178 u
->job_running_timeout
= usec
;
4179 u
->job_running_timeout_set
= true;
4184 int config_parse_emergency_action(
4186 const char *filename
,
4188 const char *section
,
4189 unsigned section_line
,
4197 EmergencyAction
*x
= data
;
4206 m
= ((Unit
*) userdata
)->manager
;
4210 r
= parse_emergency_action(rvalue
, MANAGER_IS_SYSTEM(m
), x
);
4212 if (r
== -EOPNOTSUPP
&& MANAGER_IS_USER(m
)) {
4213 /* Compat mode: remove for systemd 241. */
4215 log_syntax(unit
, LOG_INFO
, filename
, line
, r
,
4216 "%s= in user mode specified as \"%s\", using \"exit-force\" instead.",
4218 *x
= EMERGENCY_ACTION_EXIT_FORCE
;
4222 if (r
== -EOPNOTSUPP
)
4223 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4224 "%s= specified as %s mode action, ignoring: %s",
4225 lvalue
, MANAGER_IS_SYSTEM(m
) ? "user" : "system", rvalue
);
4227 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4228 "Failed to parse %s=, ignoring: %s", lvalue
, rvalue
);
4235 int config_parse_pid_file(
4237 const char *filename
,
4239 const char *section
,
4240 unsigned section_line
,
4247 _cleanup_free_
char *k
= NULL
, *n
= NULL
;
4258 r
= unit_full_printf(u
, rvalue
, &k
);
4260 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
4264 /* If this is a relative path make it absolute by prefixing the /run */
4265 n
= path_make_absolute(k
, u
->manager
->prefix
[EXEC_DIRECTORY_RUNTIME
]);
4269 /* Check that the result is a sensible path */
4270 r
= path_simplify_and_warn(n
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4274 e
= path_startswith(n
, "/var/run/");
4278 z
= strjoin("/run/", e
);
4282 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0, "PIDFile= references path below legacy directory /var/run/, updating %s → %s; please update the unit file accordingly.", n
, z
);
4284 free_and_replace(*s
, z
);
4286 free_and_replace(*s
, n
);
4291 int config_parse_exit_status(
4293 const char *filename
,
4295 const char *section
,
4296 unsigned section_line
,
4303 int *exit_status
= data
, r
;
4309 assert(exit_status
);
4311 if (isempty(rvalue
)) {
4316 r
= safe_atou8(rvalue
, &u
);
4318 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse exit status '%s', ignoring: %m", rvalue
);
4326 #define FOLLOW_MAX 8
4328 static int open_follow(char **filename
, FILE **_f
, Set
*names
, char **_final
) {
4339 /* This will update the filename pointer if the loaded file is
4340 * reached by a symlink. The old string will be freed. */
4343 char *target
, *name
;
4345 if (c
++ >= FOLLOW_MAX
)
4348 path_simplify(*filename
, false);
4350 /* Add the file name we are currently looking at to
4351 * the names of this unit, but only if it is a valid
4353 name
= basename(*filename
);
4354 if (unit_name_is_valid(name
, UNIT_NAME_ANY
)) {
4356 id
= set_get(names
, name
);
4362 r
= set_consume(names
, id
);
4368 /* Try to open the file name, but don't if its a symlink */
4369 fd
= open(*filename
, O_RDONLY
|O_CLOEXEC
|O_NOCTTY
|O_NOFOLLOW
);
4376 /* Hmm, so this is a symlink. Let's read the name, and follow it manually */
4377 r
= readlink_and_make_absolute(*filename
, &target
);
4381 free_and_replace(*filename
, target
);
4384 f
= fdopen(fd
, "re");
4396 static int merge_by_names(Unit
**u
, Set
*names
, const char *id
) {
4404 /* Let's try to add in all symlink names we found */
4405 while ((k
= set_steal_first(names
))) {
4407 /* First try to merge in the other name into our
4409 r
= unit_merge_by_name(*u
, k
);
4413 /* Hmm, we couldn't merge the other unit into
4414 * ours? Then let's try it the other way
4417 /* If the symlink name we are looking at is unit template, then
4418 we must search for instance of this template */
4419 if (unit_name_is_valid(k
, UNIT_NAME_TEMPLATE
) && (*u
)->instance
) {
4420 _cleanup_free_
char *instance
= NULL
;
4422 r
= unit_name_replace_instance(k
, (*u
)->instance
, &instance
);
4426 other
= manager_get_unit((*u
)->manager
, instance
);
4428 other
= manager_get_unit((*u
)->manager
, k
);
4433 r
= unit_merge(other
, *u
);
4436 return merge_by_names(u
, names
, NULL
);
4444 unit_choose_id(*u
, id
);
4452 static int load_from_path(Unit
*u
, const char *path
) {
4453 _cleanup_set_free_free_ Set
*symlink_names
= NULL
;
4454 _cleanup_fclose_
FILE *f
= NULL
;
4455 _cleanup_free_
char *filename
= NULL
;
4464 symlink_names
= set_new(&string_hash_ops
);
4468 if (path_is_absolute(path
)) {
4470 filename
= strdup(path
);
4474 r
= open_follow(&filename
, &f
, symlink_names
, &id
);
4476 filename
= mfree(filename
);
4484 STRV_FOREACH(p
, u
->manager
->lookup_paths
.search_path
) {
4486 /* Instead of opening the path right away, we manually
4487 * follow all symlinks and add their name to our unit
4488 * name set while doing so */
4489 filename
= path_make_absolute(path
, *p
);
4493 if (u
->manager
->unit_path_cache
&&
4494 !set_get(u
->manager
->unit_path_cache
, filename
))
4497 r
= open_follow(&filename
, &f
, symlink_names
, &id
);
4500 filename
= mfree(filename
);
4502 /* ENOENT means that the file is missing or is a dangling symlink.
4503 * ENOTDIR means that one of paths we expect to be is a directory
4504 * is not a directory, we should just ignore that.
4505 * EACCES means that the directory or file permissions are wrong.
4508 log_debug_errno(r
, "Cannot access \"%s\": %m", filename
);
4509 else if (!IN_SET(r
, -ENOENT
, -ENOTDIR
))
4512 /* Empty the symlink names for the next run */
4513 set_clear_free(symlink_names
);
4518 /* Hmm, no suitable file found? */
4521 if (!unit_type_may_alias(u
->type
) && set_size(symlink_names
) > 1) {
4522 log_unit_warning(u
, "Unit type of %s does not support alias names, refusing loading via symlink.", u
->id
);
4527 r
= merge_by_names(&merged
, symlink_names
, id
);
4532 u
->load_state
= UNIT_MERGED
;
4536 if (fstat(fileno(f
), &st
) < 0)
4539 if (null_or_empty(&st
)) {
4540 u
->load_state
= UNIT_MASKED
;
4541 u
->fragment_mtime
= 0;
4543 u
->load_state
= UNIT_LOADED
;
4544 u
->fragment_mtime
= timespec_load(&st
.st_mtim
);
4546 /* Now, parse the file contents */
4547 r
= config_parse(u
->id
, filename
, f
,
4548 UNIT_VTABLE(u
)->sections
,
4549 config_item_perf_lookup
, load_fragment_gperf_lookup
,
4550 CONFIG_PARSE_ALLOW_INCLUDE
, u
);
4555 free_and_replace(u
->fragment_path
, filename
);
4557 if (u
->source_path
) {
4558 if (stat(u
->source_path
, &st
) >= 0)
4559 u
->source_mtime
= timespec_load(&st
.st_mtim
);
4561 u
->source_mtime
= 0;
4567 int unit_load_fragment(Unit
*u
) {
4573 assert(u
->load_state
== UNIT_STUB
);
4577 u
->load_state
= UNIT_LOADED
;
4581 /* First, try to find the unit under its id. We always look
4582 * for unit files in the default directories, to make it easy
4583 * to override things by placing things in /etc/systemd/system */
4584 r
= load_from_path(u
, u
->id
);
4588 /* Try to find an alias we can load this with */
4589 if (u
->load_state
== UNIT_STUB
) {
4590 SET_FOREACH(t
, u
->names
, i
) {
4595 r
= load_from_path(u
, t
);
4599 if (u
->load_state
!= UNIT_STUB
)
4604 /* And now, try looking for it under the suggested (originally linked) path */
4605 if (u
->load_state
== UNIT_STUB
&& u
->fragment_path
) {
4607 r
= load_from_path(u
, u
->fragment_path
);
4611 if (u
->load_state
== UNIT_STUB
)
4612 /* Hmm, this didn't work? Then let's get rid
4613 * of the fragment path stored for us, so that
4614 * we don't point to an invalid location. */
4615 u
->fragment_path
= mfree(u
->fragment_path
);
4618 /* Look for a template */
4619 if (u
->load_state
== UNIT_STUB
&& u
->instance
) {
4620 _cleanup_free_
char *k
= NULL
;
4622 r
= unit_name_template(u
->id
, &k
);
4626 r
= load_from_path(u
, k
);
4629 log_unit_notice(u
, "Unit configuration has fatal error, unit will not be started.");
4633 if (u
->load_state
== UNIT_STUB
) {
4634 SET_FOREACH(t
, u
->names
, i
) {
4635 _cleanup_free_
char *z
= NULL
;
4640 r
= unit_name_template(t
, &z
);
4644 r
= load_from_path(u
, z
);
4648 if (u
->load_state
!= UNIT_STUB
)
4657 void unit_dump_config_items(FILE *f
) {
4658 static const struct {
4659 const ConfigParserCallback callback
;
4662 { config_parse_warn_compat
, "NOTSUPPORTED" },
4663 { config_parse_int
, "INTEGER" },
4664 { config_parse_unsigned
, "UNSIGNED" },
4665 { config_parse_iec_size
, "SIZE" },
4666 { config_parse_iec_uint64
, "SIZE" },
4667 { config_parse_si_size
, "SIZE" },
4668 { config_parse_bool
, "BOOLEAN" },
4669 { config_parse_string
, "STRING" },
4670 { config_parse_path
, "PATH" },
4671 { config_parse_unit_path_printf
, "PATH" },
4672 { config_parse_strv
, "STRING [...]" },
4673 { config_parse_exec_nice
, "NICE" },
4674 { config_parse_exec_oom_score_adjust
, "OOMSCOREADJUST" },
4675 { config_parse_exec_io_class
, "IOCLASS" },
4676 { config_parse_exec_io_priority
, "IOPRIORITY" },
4677 { config_parse_exec_cpu_sched_policy
, "CPUSCHEDPOLICY" },
4678 { config_parse_exec_cpu_sched_prio
, "CPUSCHEDPRIO" },
4679 { config_parse_exec_cpu_affinity
, "CPUAFFINITY" },
4680 { config_parse_mode
, "MODE" },
4681 { config_parse_unit_env_file
, "FILE" },
4682 { config_parse_exec_output
, "OUTPUT" },
4683 { config_parse_exec_input
, "INPUT" },
4684 { config_parse_log_facility
, "FACILITY" },
4685 { config_parse_log_level
, "LEVEL" },
4686 { config_parse_exec_secure_bits
, "SECUREBITS" },
4687 { config_parse_capability_set
, "BOUNDINGSET" },
4688 { config_parse_rlimit
, "LIMIT" },
4689 { config_parse_unit_deps
, "UNIT [...]" },
4690 { config_parse_exec
, "PATH [ARGUMENT [...]]" },
4691 { config_parse_service_type
, "SERVICETYPE" },
4692 { config_parse_service_restart
, "SERVICERESTART" },
4693 { config_parse_kill_mode
, "KILLMODE" },
4694 { config_parse_signal
, "SIGNAL" },
4695 { config_parse_socket_listen
, "SOCKET [...]" },
4696 { config_parse_socket_bind
, "SOCKETBIND" },
4697 { config_parse_socket_bindtodevice
, "NETWORKINTERFACE" },
4698 { config_parse_sec
, "SECONDS" },
4699 { config_parse_nsec
, "NANOSECONDS" },
4700 { config_parse_namespace_path_strv
, "PATH [...]" },
4701 { config_parse_bind_paths
, "PATH[:PATH[:OPTIONS]] [...]" },
4702 { config_parse_unit_requires_mounts_for
, "PATH [...]" },
4703 { config_parse_exec_mount_flags
, "MOUNTFLAG [...]" },
4704 { config_parse_unit_string_printf
, "STRING" },
4705 { config_parse_trigger_unit
, "UNIT" },
4706 { config_parse_timer
, "TIMER" },
4707 { config_parse_path_spec
, "PATH" },
4708 { config_parse_notify_access
, "ACCESS" },
4709 { config_parse_ip_tos
, "TOS" },
4710 { config_parse_unit_condition_path
, "CONDITION" },
4711 { config_parse_unit_condition_string
, "CONDITION" },
4712 { config_parse_unit_condition_null
, "CONDITION" },
4713 { config_parse_unit_slice
, "SLICE" },
4714 { config_parse_documentation
, "URL" },
4715 { config_parse_service_timeout
, "SECONDS" },
4716 { config_parse_emergency_action
, "ACTION" },
4717 { config_parse_set_status
, "STATUS" },
4718 { config_parse_service_sockets
, "SOCKETS" },
4719 { config_parse_environ
, "ENVIRON" },
4721 { config_parse_syscall_filter
, "SYSCALLS" },
4722 { config_parse_syscall_archs
, "ARCHS" },
4723 { config_parse_syscall_errno
, "ERRNO" },
4724 { config_parse_address_families
, "FAMILIES" },
4725 { config_parse_restrict_namespaces
, "NAMESPACES" },
4727 { config_parse_cpu_shares
, "SHARES" },
4728 { config_parse_cg_weight
, "WEIGHT" },
4729 { config_parse_memory_limit
, "LIMIT" },
4730 { config_parse_device_allow
, "DEVICE" },
4731 { config_parse_device_policy
, "POLICY" },
4732 { config_parse_io_limit
, "LIMIT" },
4733 { config_parse_io_device_weight
, "DEVICEWEIGHT" },
4734 { config_parse_io_device_latency
, "DEVICELATENCY" },
4735 { config_parse_blockio_bandwidth
, "BANDWIDTH" },
4736 { config_parse_blockio_weight
, "WEIGHT" },
4737 { config_parse_blockio_device_weight
, "DEVICEWEIGHT" },
4738 { config_parse_long
, "LONG" },
4739 { config_parse_socket_service
, "SERVICE" },
4741 { config_parse_exec_selinux_context
, "LABEL" },
4743 { config_parse_job_mode
, "MODE" },
4744 { config_parse_job_mode_isolate
, "BOOLEAN" },
4745 { config_parse_personality
, "PERSONALITY" },
4748 const char *prev
= NULL
;
4753 NULSTR_FOREACH(i
, load_fragment_gperf_nulstr
) {
4754 const char *rvalue
= "OTHER", *lvalue
;
4755 const ConfigPerfItem
*p
;
4760 assert_se(p
= load_fragment_gperf_lookup(i
, strlen(i
)));
4762 /* Hide legacy settings */
4763 if (p
->parse
== config_parse_warn_compat
&&
4764 p
->ltype
== DISABLED_LEGACY
)
4767 for (j
= 0; j
< ELEMENTSOF(table
); j
++)
4768 if (p
->parse
== table
[j
].callback
) {
4769 rvalue
= table
[j
].rvalue
;
4773 dot
= strchr(i
, '.');
4774 lvalue
= dot
? dot
+ 1 : i
;
4778 if (!prev
|| !strneq(prev
, i
, prefix_len
+1)) {
4782 fprintf(f
, "[%.*s]\n", (int) prefix_len
, i
);
4785 fprintf(f
, "%s=%s\n", lvalue
, rvalue
);