1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 This file is part of systemd.
5 Copyright 2010 Lennart Poettering
6 Copyright 2012 Holger Hans Peter Freyther
12 #include <linux/oom.h>
18 #include <sys/resource.h>
22 #include "alloc-util.h"
23 #include "all-units.h"
24 #include "bus-error.h"
25 #include "bus-internal.h"
28 #include "capability-util.h"
30 #include "conf-parser.h"
31 #include "cpu-set-util.h"
33 #include "errno-list.h"
37 #include "hexdecoct.h"
40 #include "journal-util.h"
41 #include "load-fragment.h"
44 #include "mount-util.h"
45 #include "parse-util.h"
46 #include "path-util.h"
47 #include "process-util.h"
49 #include "seccomp-util.h"
51 #include "securebits.h"
52 #include "securebits-util.h"
53 #include "signal-util.h"
54 #include "socket-protocol-list.h"
55 #include "stat-util.h"
56 #include "string-util.h"
58 #include "unit-name.h"
59 #include "unit-printf.h"
60 #include "user-util.h"
63 static int supported_socket_protocol_from_string(const char *s
) {
69 r
= socket_protocol_from_name(s
);
72 if (!IN_SET(r
, IPPROTO_UDPLITE
, IPPROTO_SCTP
))
73 return -EPROTONOSUPPORT
;
78 DEFINE_CONFIG_PARSE(config_parse_socket_protocol
, supported_socket_protocol_from_string
, "Failed to parse socket protocol");
79 DEFINE_CONFIG_PARSE(config_parse_exec_secure_bits
, secure_bits_from_string
, "Failed to parse secure bits");
80 DEFINE_CONFIG_PARSE_ENUM(config_parse_collect_mode
, collect_mode
, CollectMode
, "Failed to parse garbage collection mode");
81 DEFINE_CONFIG_PARSE_ENUM(config_parse_device_policy
, cgroup_device_policy
, CGroupDevicePolicy
, "Failed to parse device policy");
82 DEFINE_CONFIG_PARSE_ENUM(config_parse_emergency_action
, emergency_action
, EmergencyAction
, "Failed to parse failure action specifier");
83 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_keyring_mode
, exec_keyring_mode
, ExecKeyringMode
, "Failed to parse keyring mode");
84 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_utmp_mode
, exec_utmp_mode
, ExecUtmpMode
, "Failed to parse utmp mode");
85 DEFINE_CONFIG_PARSE_ENUM(config_parse_job_mode
, job_mode
, JobMode
, "Failed to parse job mode");
86 DEFINE_CONFIG_PARSE_ENUM(config_parse_kill_mode
, kill_mode
, KillMode
, "Failed to parse kill mode");
87 DEFINE_CONFIG_PARSE_ENUM(config_parse_notify_access
, notify_access
, NotifyAccess
, "Failed to parse notify access specifier");
88 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_home
, protect_home_or_bool
, ProtectHome
, "Failed to parse protect home value");
89 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_system
, protect_system_or_bool
, ProtectSystem
, "Failed to parse protect system value");
90 DEFINE_CONFIG_PARSE_ENUM(config_parse_runtime_preserve_mode
, exec_preserve_mode
, ExecPreserveMode
, "Failed to parse runtime directory preserve mode");
91 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_type
, service_type
, ServiceType
, "Failed to parse service type");
92 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart
, service_restart
, ServiceRestart
, "Failed to parse service restart specifier");
93 DEFINE_CONFIG_PARSE_ENUM(config_parse_socket_bind
, socket_address_bind_ipv6_only_or_bool
, SocketAddressBindIPv6Only
, "Failed to parse bind IPv6 only value");
94 DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_ip_tos
, ip_tos
, int, -1, "Failed to parse IP TOS value");
95 DEFINE_CONFIG_PARSE_PTR(config_parse_blockio_weight
, cg_blkio_weight_parse
, uint64_t, "Invalid block IO weight");
96 DEFINE_CONFIG_PARSE_PTR(config_parse_cg_weight
, cg_weight_parse
, uint64_t, "Invalid weight");
97 DEFINE_CONFIG_PARSE_PTR(config_parse_cpu_shares
, cg_cpu_shares_parse
, uint64_t, "Invalid CPU shares");
98 DEFINE_CONFIG_PARSE_PTR(config_parse_exec_mount_flags
, mount_propagation_flags_from_string
, unsigned long, "Failed to parse mount flag");
100 int config_parse_unit_deps(
102 const char *filename
,
105 unsigned section_line
,
112 UnitDependency d
= ltype
;
122 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
125 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_RETAIN_ESCAPE
);
131 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
135 r
= unit_name_printf(u
, word
, &k
);
137 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
141 r
= unit_add_dependency_by_name(u
, d
, k
, NULL
, true, UNIT_DEPENDENCY_FILE
);
143 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
149 int config_parse_obsolete_unit_deps(
151 const char *filename
,
154 unsigned section_line
,
161 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
162 "Unit dependency type %s= is obsolete, replacing by %s=, please update your unit file", lvalue
, unit_dependency_to_string(ltype
));
164 return config_parse_unit_deps(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
);
167 int config_parse_unit_string_printf(
169 const char *filename
,
172 unsigned section_line
,
179 _cleanup_free_
char *k
= NULL
;
188 r
= unit_full_printf(u
, rvalue
, &k
);
190 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
194 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
197 int config_parse_unit_strv_printf(
199 const char *filename
,
202 unsigned section_line
,
210 _cleanup_free_
char *k
= NULL
;
218 r
= unit_full_printf(u
, rvalue
, &k
);
220 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
224 return config_parse_strv(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
227 int config_parse_unit_path_printf(
229 const char *filename
,
232 unsigned section_line
,
239 _cleanup_free_
char *k
= NULL
;
249 /* Let's not bother with anything that is too long */
250 if (strlen(rvalue
) >= PATH_MAX
) {
251 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
252 "%s value too long%s.",
253 lvalue
, fatal
? "" : ", ignoring");
254 return fatal
? -ENAMETOOLONG
: 0;
257 r
= unit_full_printf(u
, rvalue
, &k
);
259 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
260 "Failed to resolve unit specifiers in '%s'%s: %m",
261 rvalue
, fatal
? "" : ", ignoring");
262 return fatal
? -ENOEXEC
: 0;
265 return config_parse_path(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
268 int config_parse_unit_path_strv_printf(
270 const char *filename
,
273 unsigned section_line
,
290 if (isempty(rvalue
)) {
296 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
298 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
304 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
305 "Invalid syntax, ignoring: %s", rvalue
);
309 r
= unit_full_printf(u
, word
, &k
);
311 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
312 "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
316 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
327 int config_parse_socket_listen(const char *unit
,
328 const char *filename
,
331 unsigned section_line
,
338 _cleanup_free_ SocketPort
*p
= NULL
;
350 if (isempty(rvalue
)) {
351 /* An empty assignment removes all ports */
352 socket_free_ports(s
);
356 p
= new0(SocketPort
, 1);
360 if (ltype
!= SOCKET_SOCKET
) {
361 _cleanup_free_
char *k
= NULL
;
363 r
= unit_full_printf(UNIT(s
), rvalue
, &k
);
365 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
369 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
373 free_and_replace(p
->path
, k
);
376 } else if (streq(lvalue
, "ListenNetlink")) {
377 _cleanup_free_
char *k
= NULL
;
379 r
= unit_full_printf(UNIT(s
), rvalue
, &k
);
381 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
385 r
= socket_address_parse_netlink(&p
->address
, k
);
387 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse address value in '%s', ignoring: %m", k
);
391 p
->type
= SOCKET_SOCKET
;
394 _cleanup_free_
char *k
= NULL
;
396 r
= unit_full_printf(UNIT(s
), rvalue
, &k
);
398 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
402 r
= socket_address_parse_and_warn(&p
->address
, k
);
404 if (r
!= -EAFNOSUPPORT
)
405 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse address value in '%s', ignoring: %m", k
);
409 if (streq(lvalue
, "ListenStream"))
410 p
->address
.type
= SOCK_STREAM
;
411 else if (streq(lvalue
, "ListenDatagram"))
412 p
->address
.type
= SOCK_DGRAM
;
414 assert(streq(lvalue
, "ListenSequentialPacket"));
415 p
->address
.type
= SOCK_SEQPACKET
;
418 if (socket_address_family(&p
->address
) != AF_LOCAL
&& p
->address
.type
== SOCK_SEQPACKET
) {
419 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Address family not supported, ignoring: %s", rvalue
);
423 p
->type
= SOCKET_SOCKET
;
427 p
->auxiliary_fds
= NULL
;
428 p
->n_auxiliary_fds
= 0;
431 LIST_FIND_TAIL(port
, s
->ports
, tail
);
432 LIST_INSERT_AFTER(port
, s
->ports
, tail
, p
);
439 int config_parse_exec_nice(
441 const char *filename
,
444 unsigned section_line
,
451 ExecContext
*c
= data
;
459 if (isempty(rvalue
)) {
464 r
= parse_nice(rvalue
, &priority
);
467 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Nice priority out of range, ignoring: %s", rvalue
);
469 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse nice priority '%s', ignoring: %m", rvalue
);
479 int config_parse_exec_oom_score_adjust(
481 const char *filename
,
484 unsigned section_line
,
491 ExecContext
*c
= data
;
499 if (isempty(rvalue
)) {
500 c
->oom_score_adjust_set
= false;
504 r
= parse_oom_score_adjust(rvalue
, &oa
);
507 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "OOM score adjust value out of range, ignoring: %s", rvalue
);
509 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse the OOM score adjust value '%s', ignoring: %m", rvalue
);
513 c
->oom_score_adjust
= oa
;
514 c
->oom_score_adjust_set
= true;
519 int config_parse_exec(
521 const char *filename
,
524 unsigned section_line
,
531 ExecCommand
**e
= data
;
543 rvalue
+= strspn(rvalue
, WHITESPACE
);
545 if (isempty(rvalue
)) {
546 /* An empty assignment resets the list */
547 *e
= exec_command_free_list(*e
);
553 _cleanup_free_
char *path
= NULL
, *firstword
= NULL
;
554 ExecCommandFlags flags
= 0;
555 bool ignore
= false, separate_argv0
= false;
556 _cleanup_free_ ExecCommand
*nce
= NULL
;
557 _cleanup_strv_free_
char **n
= NULL
;
558 size_t nlen
= 0, nbufsize
= 0;
563 r
= extract_first_word_and_warn(&p
, &firstword
, NULL
, EXTRACT_QUOTES
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
569 /* We accept an absolute path as first argument. If it's prefixed with - and the path doesn't
570 * exist, we ignore it instead of erroring out; if it's prefixed with @, we allow overriding of
571 * argv[0]; if it's prefixed with +, it will be run with full privileges and no sandboxing; if
572 * it's prefixed with '!' we apply sandboxing, but do not change user/group credentials; if
573 * it's prefixed with '!!', then we apply user/group credentials if the kernel supports ambient
574 * capabilities -- if it doesn't we don't apply the credentials themselves, but do apply most
575 * other sandboxing, with some special exceptions for changing UID.
577 * The idea is that '!!' may be used to write services that can take benefit of systemd's
578 * UID/GID dropping if the kernel supports ambient creds, but provide an automatic fallback to
579 * privilege dropping within the daemon if the kernel does not offer that. */
581 if (*f
== '-' && !(flags
& EXEC_COMMAND_IGNORE_FAILURE
)) {
582 flags
|= EXEC_COMMAND_IGNORE_FAILURE
;
584 } else if (*f
== '@' && !separate_argv0
)
585 separate_argv0
= true;
586 else if (*f
== '+' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
587 flags
|= EXEC_COMMAND_FULLY_PRIVILEGED
;
588 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
589 flags
|= EXEC_COMMAND_NO_SETUID
;
590 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_AMBIENT_MAGIC
))) {
591 flags
&= ~EXEC_COMMAND_NO_SETUID
;
592 flags
|= EXEC_COMMAND_AMBIENT_MAGIC
;
598 r
= unit_full_printf(u
, f
, &path
);
600 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
601 "Failed to resolve unit specifiers in '%s'%s: %m",
602 f
, ignore
? ", ignoring" : "");
603 return ignore
? 0 : -ENOEXEC
;
607 /* First word is either "-" or "@" with no command. */
608 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
609 "Empty path in command line%s: '%s'",
610 ignore
? ", ignoring" : "", rvalue
);
611 return ignore
? 0 : -ENOEXEC
;
613 if (!string_is_safe(path
)) {
614 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
615 "Executable name contains special characters%s: %s",
616 ignore
? ", ignoring" : "", path
);
617 return ignore
? 0 : -ENOEXEC
;
619 if (endswith(path
, "/")) {
620 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
621 "Executable path specifies a directory%s: %s",
622 ignore
? ", ignoring" : "", path
);
623 return ignore
? 0 : -ENOEXEC
;
626 if (!path_is_absolute(path
)) {
630 if (!filename_is_valid(path
)) {
631 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
632 "Neither a valid executable name nor an absolute path%s: %s",
633 ignore
? ", ignoring" : "", path
);
634 return ignore
? 0 : -ENOEXEC
;
637 /* Resolve a single-component name to a full path */
638 NULSTR_FOREACH(prefix
, DEFAULT_PATH_NULSTR
) {
639 _cleanup_free_
char *fullpath
= NULL
;
641 fullpath
= strjoin(prefix
, "/", path
);
645 if (access(fullpath
, F_OK
) >= 0) {
646 free_and_replace(path
, fullpath
);
653 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
654 "Executable \"%s\" not found in path \"%s\"%s",
655 path
, DEFAULT_PATH
, ignore
? ", ignoring" : "");
656 return ignore
? 0 : -ENOEXEC
;
660 if (!separate_argv0
) {
663 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
673 path_simplify(path
, false);
675 while (!isempty(p
)) {
676 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
678 /* Check explicitly for an unquoted semicolon as
679 * command separator token. */
680 if (p
[0] == ';' && (!p
[1] || strchr(WHITESPACE
, p
[1]))) {
682 p
+= strspn(p
, WHITESPACE
);
687 /* Check for \; explicitly, to not confuse it with \\; or "\;" or "\\;" etc.
688 * extract_first_word() would return the same for all of those. */
689 if (p
[0] == '\\' && p
[1] == ';' && (!p
[2] || strchr(WHITESPACE
, p
[2]))) {
693 p
+= strspn(p
, WHITESPACE
);
695 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
706 r
= extract_first_word_and_warn(&p
, &word
, NULL
, EXTRACT_QUOTES
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
710 return ignore
? 0 : -ENOEXEC
;
712 r
= unit_full_printf(u
, word
, &resolved
);
714 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
715 "Failed to resolve unit specifiers in %s%s: %m",
716 word
, ignore
? ", ignoring" : "");
717 return ignore
? 0 : -ENOEXEC
;
720 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
723 n
[nlen
++] = TAKE_PTR(resolved
);
728 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
729 "Empty executable name or zeroeth argument%s: %s",
730 ignore
? ", ignoring" : "", rvalue
);
731 return ignore
? 0 : -ENOEXEC
;
734 nce
= new0(ExecCommand
, 1);
738 nce
->argv
= TAKE_PTR(n
);
739 nce
->path
= TAKE_PTR(path
);
742 exec_command_append_list(e
, nce
);
744 /* Do not _cleanup_free_ these. */
753 int config_parse_socket_bindtodevice(
755 const char *filename
,
758 unsigned section_line
,
772 if (isempty(rvalue
) || streq(rvalue
, "*")) {
773 s
->bind_to_device
= mfree(s
->bind_to_device
);
777 if (!ifname_valid(rvalue
)) {
778 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid interface name, ignoring: %s", rvalue
);
782 if (free_and_strdup(&s
->bind_to_device
, rvalue
) < 0)
788 int config_parse_exec_input(
790 const char *filename
,
793 unsigned section_line
,
800 ExecContext
*c
= data
;
811 n
= startswith(rvalue
, "fd:");
813 _cleanup_free_
char *resolved
= NULL
;
815 r
= unit_full_printf(u
, n
, &resolved
);
817 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s': %m", n
);
819 if (isempty(resolved
))
820 resolved
= mfree(resolved
);
821 else if (!fdname_is_valid(resolved
)) {
822 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name: %s", resolved
);
826 free_and_replace(c
->stdio_fdname
[STDIN_FILENO
], resolved
);
828 ei
= EXEC_INPUT_NAMED_FD
;
830 } else if ((n
= startswith(rvalue
, "file:"))) {
831 _cleanup_free_
char *resolved
= NULL
;
833 r
= unit_full_printf(u
, n
, &resolved
);
835 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s': %m", n
);
837 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
841 free_and_replace(c
->stdio_file
[STDIN_FILENO
], resolved
);
843 ei
= EXEC_INPUT_FILE
;
846 ei
= exec_input_from_string(rvalue
);
848 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse input specifier, ignoring: %s", rvalue
);
857 int config_parse_exec_input_text(
859 const char *filename
,
862 unsigned section_line
,
869 _cleanup_free_
char *unescaped
= NULL
, *resolved
= NULL
;
870 ExecContext
*c
= data
;
881 if (isempty(rvalue
)) {
882 /* Reset if the empty string is assigned */
883 c
->stdin_data
= mfree(c
->stdin_data
);
884 c
->stdin_data_size
= 0;
888 r
= cunescape(rvalue
, 0, &unescaped
);
890 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to decode C escaped text '%s': %m", rvalue
);
892 r
= unit_full_printf(u
, unescaped
, &resolved
);
894 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s': %m", unescaped
);
896 sz
= strlen(resolved
);
897 if (c
->stdin_data_size
+ sz
+ 1 < c
->stdin_data_size
|| /* check for overflow */
898 c
->stdin_data_size
+ sz
+ 1 > EXEC_STDIN_DATA_MAX
) {
899 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
);
903 p
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
+ 1);
907 *((char*) mempcpy((char*) p
+ c
->stdin_data_size
, resolved
, sz
)) = '\n';
910 c
->stdin_data_size
+= sz
+ 1;
915 int config_parse_exec_input_data(
917 const char *filename
,
920 unsigned section_line
,
927 _cleanup_free_
void *p
= NULL
;
928 ExecContext
*c
= data
;
938 if (isempty(rvalue
)) {
939 /* Reset if the empty string is assigned */
940 c
->stdin_data
= mfree(c
->stdin_data
);
941 c
->stdin_data_size
= 0;
945 r
= unbase64mem(rvalue
, (size_t) -1, &p
, &sz
);
947 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to decode base64 data, ignoring: %s", rvalue
);
951 if (c
->stdin_data_size
+ sz
< c
->stdin_data_size
|| /* check for overflow */
952 c
->stdin_data_size
+ sz
> EXEC_STDIN_DATA_MAX
) {
953 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
);
957 q
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
);
961 memcpy((uint8_t*) q
+ c
->stdin_data_size
, p
, sz
);
964 c
->stdin_data_size
+= sz
;
969 int config_parse_exec_output(
971 const char *filename
,
974 unsigned section_line
,
981 _cleanup_free_
char *resolved
= NULL
;
983 ExecContext
*c
= data
;
994 n
= startswith(rvalue
, "fd:");
996 r
= unit_full_printf(u
, n
, &resolved
);
998 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", n
);
1000 if (isempty(resolved
))
1001 resolved
= mfree(resolved
);
1002 else if (!fdname_is_valid(resolved
)) {
1003 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name: %s", resolved
);
1007 eo
= EXEC_OUTPUT_NAMED_FD
;
1009 } else if ((n
= startswith(rvalue
, "file:"))) {
1011 r
= unit_full_printf(u
, n
, &resolved
);
1013 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", n
);
1015 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1019 eo
= EXEC_OUTPUT_FILE
;
1022 eo
= exec_output_from_string(rvalue
);
1024 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse output specifier, ignoring: %s", rvalue
);
1029 if (streq(lvalue
, "StandardOutput")) {
1030 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1031 free_and_replace(c
->stdio_fdname
[STDOUT_FILENO
], resolved
);
1033 free_and_replace(c
->stdio_file
[STDOUT_FILENO
], resolved
);
1038 assert(streq(lvalue
, "StandardError"));
1040 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1041 free_and_replace(c
->stdio_fdname
[STDERR_FILENO
], resolved
);
1043 free_and_replace(c
->stdio_file
[STDERR_FILENO
], resolved
);
1051 int config_parse_exec_io_class(const char *unit
,
1052 const char *filename
,
1054 const char *section
,
1055 unsigned section_line
,
1062 ExecContext
*c
= data
;
1070 if (isempty(rvalue
)) {
1071 c
->ioprio_set
= false;
1072 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE
, 0);
1076 x
= ioprio_class_from_string(rvalue
);
1078 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse IO scheduling class, ignoring: %s", rvalue
);
1082 c
->ioprio
= IOPRIO_PRIO_VALUE(x
, IOPRIO_PRIO_DATA(c
->ioprio
));
1083 c
->ioprio_set
= true;
1088 int config_parse_exec_io_priority(const char *unit
,
1089 const char *filename
,
1091 const char *section
,
1092 unsigned section_line
,
1099 ExecContext
*c
= data
;
1107 if (isempty(rvalue
)) {
1108 c
->ioprio_set
= false;
1109 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE
, 0);
1113 r
= ioprio_parse_priority(rvalue
, &i
);
1115 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse IO priority, ignoring: %s", rvalue
);
1119 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_PRIO_CLASS(c
->ioprio
), i
);
1120 c
->ioprio_set
= true;
1125 int config_parse_exec_cpu_sched_policy(const char *unit
,
1126 const char *filename
,
1128 const char *section
,
1129 unsigned section_line
,
1136 ExecContext
*c
= data
;
1144 if (isempty(rvalue
)) {
1145 c
->cpu_sched_set
= false;
1146 c
->cpu_sched_policy
= SCHED_OTHER
;
1147 c
->cpu_sched_priority
= 0;
1151 x
= sched_policy_from_string(rvalue
);
1153 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse CPU scheduling policy, ignoring: %s", rvalue
);
1157 c
->cpu_sched_policy
= x
;
1158 /* Moving to or from real-time policy? We need to adjust the priority */
1159 c
->cpu_sched_priority
= CLAMP(c
->cpu_sched_priority
, sched_get_priority_min(x
), sched_get_priority_max(x
));
1160 c
->cpu_sched_set
= true;
1165 int config_parse_exec_cpu_sched_prio(const char *unit
,
1166 const char *filename
,
1168 const char *section
,
1169 unsigned section_line
,
1176 ExecContext
*c
= data
;
1184 r
= safe_atoi(rvalue
, &i
);
1186 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse CPU scheduling priority, ignoring: %s", rvalue
);
1190 /* On Linux RR/FIFO range from 1 to 99 and OTHER/BATCH may only be 0 */
1191 min
= sched_get_priority_min(c
->cpu_sched_policy
);
1192 max
= sched_get_priority_max(c
->cpu_sched_policy
);
1194 if (i
< min
|| i
> max
) {
1195 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "CPU scheduling priority is out of range, ignoring: %s", rvalue
);
1199 c
->cpu_sched_priority
= i
;
1200 c
->cpu_sched_set
= true;
1205 int config_parse_exec_cpu_affinity(const char *unit
,
1206 const char *filename
,
1208 const char *section
,
1209 unsigned section_line
,
1216 ExecContext
*c
= data
;
1217 _cleanup_cpu_free_ cpu_set_t
*cpuset
= NULL
;
1225 ncpus
= parse_cpu_set_and_warn(rvalue
, &cpuset
, unit
, filename
, line
, lvalue
);
1230 /* An empty assignment resets the CPU list */
1231 c
->cpuset
= cpu_set_mfree(c
->cpuset
);
1232 c
->cpuset_ncpus
= 0;
1237 c
->cpuset
= TAKE_PTR(cpuset
);
1238 c
->cpuset_ncpus
= (unsigned) ncpus
;
1242 if (c
->cpuset_ncpus
< (unsigned) ncpus
) {
1243 CPU_OR_S(CPU_ALLOC_SIZE(c
->cpuset_ncpus
), cpuset
, c
->cpuset
, cpuset
);
1244 CPU_FREE(c
->cpuset
);
1245 c
->cpuset
= TAKE_PTR(cpuset
);
1246 c
->cpuset_ncpus
= (unsigned) ncpus
;
1250 CPU_OR_S(CPU_ALLOC_SIZE((unsigned) ncpus
), c
->cpuset
, c
->cpuset
, cpuset
);
1255 int config_parse_capability_set(
1257 const char *filename
,
1259 const char *section
,
1260 unsigned section_line
,
1267 uint64_t *capability_set
= data
;
1268 uint64_t sum
= 0, initial
= 0;
1269 bool invert
= false;
1277 if (rvalue
[0] == '~') {
1282 if (streq(lvalue
, "CapabilityBoundingSet"))
1283 initial
= CAP_ALL
; /* initialized to all bits on */
1284 /* else "AmbientCapabilities" initialized to all bits off */
1286 r
= capability_set_from_string(rvalue
, &sum
);
1288 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= specifier '%s', ignoring: %m", lvalue
, rvalue
);
1292 if (sum
== 0 || *capability_set
== initial
)
1293 /* "", "~" or uninitialized data -> replace */
1294 *capability_set
= invert
? ~sum
: sum
;
1296 /* previous data -> merge */
1298 *capability_set
&= ~sum
;
1300 *capability_set
|= sum
;
1306 int config_parse_exec_selinux_context(
1308 const char *filename
,
1310 const char *section
,
1311 unsigned section_line
,
1318 ExecContext
*c
= data
;
1329 if (isempty(rvalue
)) {
1330 c
->selinux_context
= mfree(c
->selinux_context
);
1331 c
->selinux_context_ignore
= false;
1335 if (rvalue
[0] == '-') {
1341 r
= unit_full_printf(u
, rvalue
, &k
);
1343 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1344 "Failed to resolve unit specifiers in '%s'%s: %m",
1345 rvalue
, ignore
? ", ignoring" : "");
1346 return ignore
? 0 : -ENOEXEC
;
1349 free_and_replace(c
->selinux_context
, k
);
1350 c
->selinux_context_ignore
= ignore
;
1355 int config_parse_exec_apparmor_profile(
1357 const char *filename
,
1359 const char *section
,
1360 unsigned section_line
,
1367 ExecContext
*c
= data
;
1378 if (isempty(rvalue
)) {
1379 c
->apparmor_profile
= mfree(c
->apparmor_profile
);
1380 c
->apparmor_profile_ignore
= false;
1384 if (rvalue
[0] == '-') {
1390 r
= unit_full_printf(u
, rvalue
, &k
);
1392 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1393 "Failed to resolve unit specifiers in '%s'%s: %m",
1394 rvalue
, ignore
? ", ignoring" : "");
1395 return ignore
? 0 : -ENOEXEC
;
1398 free_and_replace(c
->apparmor_profile
, k
);
1399 c
->apparmor_profile_ignore
= ignore
;
1404 int config_parse_exec_smack_process_label(
1406 const char *filename
,
1408 const char *section
,
1409 unsigned section_line
,
1416 ExecContext
*c
= data
;
1427 if (isempty(rvalue
)) {
1428 c
->smack_process_label
= mfree(c
->smack_process_label
);
1429 c
->smack_process_label_ignore
= false;
1433 if (rvalue
[0] == '-') {
1439 r
= unit_full_printf(u
, rvalue
, &k
);
1441 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1442 "Failed to resolve unit specifiers in '%s'%s: %m",
1443 rvalue
, ignore
? ", ignoring" : "");
1444 return ignore
? 0 : -ENOEXEC
;
1447 free_and_replace(c
->smack_process_label
, k
);
1448 c
->smack_process_label_ignore
= ignore
;
1453 int config_parse_timer(const char *unit
,
1454 const char *filename
,
1456 const char *section
,
1457 unsigned section_line
,
1468 _cleanup_(calendar_spec_freep
) CalendarSpec
*c
= NULL
;
1470 _cleanup_free_
char *k
= NULL
;
1478 if (isempty(rvalue
)) {
1479 /* Empty assignment resets list */
1480 timer_free_values(t
);
1484 b
= timer_base_from_string(lvalue
);
1486 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse timer base, ignoring: %s", lvalue
);
1490 r
= unit_full_printf(u
, rvalue
, &k
);
1492 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
1496 if (b
== TIMER_CALENDAR
) {
1497 if (calendar_spec_from_string(k
, &c
) < 0) {
1498 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse calendar specification, ignoring: %s", k
);
1502 if (parse_sec(k
, &usec
) < 0) {
1503 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse timer value, ignoring: %s", k
);
1507 v
= new0(TimerValue
, 1);
1513 v
->calendar_spec
= TAKE_PTR(c
);
1515 LIST_PREPEND(value
, t
->values
, v
);
1520 int config_parse_trigger_unit(
1522 const char *filename
,
1524 const char *section
,
1525 unsigned section_line
,
1532 _cleanup_free_
char *p
= NULL
;
1542 if (!hashmap_isempty(u
->dependencies
[UNIT_TRIGGERS
])) {
1543 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Multiple units to trigger specified, ignoring: %s", rvalue
);
1547 r
= unit_name_printf(u
, rvalue
, &p
);
1549 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
1553 type
= unit_name_to_type(p
);
1555 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit type not valid, ignoring: %s", rvalue
);
1558 if (unit_has_name(u
, p
)) {
1559 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Units cannot trigger themselves, ignoring: %s", rvalue
);
1563 r
= unit_add_two_dependencies_by_name(u
, UNIT_BEFORE
, UNIT_TRIGGERS
, p
, NULL
, true, UNIT_DEPENDENCY_FILE
);
1565 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add trigger on %s, ignoring: %m", p
);
1572 int config_parse_path_spec(const char *unit
,
1573 const char *filename
,
1575 const char *section
,
1576 unsigned section_line
,
1586 _cleanup_free_
char *k
= NULL
;
1594 if (isempty(rvalue
)) {
1595 /* Empty assignment clears list */
1600 b
= path_type_from_string(lvalue
);
1602 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse path type, ignoring: %s", lvalue
);
1606 r
= unit_full_printf(UNIT(p
), rvalue
, &k
);
1608 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
1612 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
1616 s
= new0(PathSpec
, 1);
1621 s
->path
= TAKE_PTR(k
);
1625 LIST_PREPEND(spec
, p
->specs
, s
);
1630 int config_parse_socket_service(
1632 const char *filename
,
1634 const char *section
,
1635 unsigned section_line
,
1642 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1643 _cleanup_free_
char *p
= NULL
;
1653 r
= unit_name_printf(UNIT(s
), rvalue
, &p
);
1655 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", rvalue
);
1659 if (!endswith(p
, ".service")) {
1660 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit must be of type service: %s", rvalue
);
1664 r
= manager_load_unit(UNIT(s
)->manager
, p
, NULL
, &error
, &x
);
1666 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to load unit %s: %s", rvalue
, bus_error_message(&error
, r
));
1670 unit_ref_set(&s
->service
, UNIT(s
), x
);
1675 int config_parse_fdname(
1677 const char *filename
,
1679 const char *section
,
1680 unsigned section_line
,
1687 _cleanup_free_
char *p
= NULL
;
1696 if (isempty(rvalue
)) {
1697 s
->fdname
= mfree(s
->fdname
);
1701 r
= unit_full_printf(UNIT(s
), rvalue
, &p
);
1703 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
1707 if (!fdname_is_valid(p
)) {
1708 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", p
);
1712 return free_and_replace(s
->fdname
, p
);
1715 int config_parse_service_sockets(
1717 const char *filename
,
1719 const char *section
,
1720 unsigned section_line
,
1738 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
1740 r
= extract_first_word(&p
, &word
, NULL
, 0);
1746 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Trailing garbage in sockets, ignoring: %s", rvalue
);
1750 r
= unit_name_printf(UNIT(s
), word
, &k
);
1752 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
1756 if (!endswith(k
, ".socket")) {
1757 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit must be of type socket, ignoring: %s", k
);
1761 r
= unit_add_two_dependencies_by_name(UNIT(s
), UNIT_WANTS
, UNIT_AFTER
, k
, NULL
, true, UNIT_DEPENDENCY_FILE
);
1763 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
1765 r
= unit_add_dependency_by_name(UNIT(s
), UNIT_TRIGGERED_BY
, k
, NULL
, true, UNIT_DEPENDENCY_FILE
);
1767 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
1773 int config_parse_bus_name(
1775 const char *filename
,
1777 const char *section
,
1778 unsigned section_line
,
1785 _cleanup_free_
char *k
= NULL
;
1794 r
= unit_full_printf(u
, rvalue
, &k
);
1796 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
1800 if (!service_name_is_valid(k
)) {
1801 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid bus name, ignoring: %s", k
);
1805 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
1808 int config_parse_service_timeout(
1810 const char *filename
,
1812 const char *section
,
1813 unsigned section_line
,
1820 Service
*s
= userdata
;
1829 /* This is called for two cases: TimeoutSec= and TimeoutStartSec=. */
1831 /* Traditionally, these options accepted 0 to disable the timeouts. However, a timeout of 0 suggests it happens
1832 * immediately, hence fix this to become USEC_INFINITY instead. This is in-line with how we internally handle
1833 * all other timeouts. */
1834 r
= parse_sec_fix_0(rvalue
, &usec
);
1836 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
1840 s
->start_timeout_defined
= true;
1841 s
->timeout_start_usec
= usec
;
1843 if (streq(lvalue
, "TimeoutSec"))
1844 s
->timeout_stop_usec
= usec
;
1849 int config_parse_sec_fix_0(
1851 const char *filename
,
1853 const char *section
,
1854 unsigned section_line
,
1861 usec_t
*usec
= data
;
1869 /* This is pretty much like config_parse_sec(), except that this treats a time of 0 as infinity, for
1870 * compatibility with older versions of systemd where 0 instead of infinity was used as indicator to turn off a
1873 r
= parse_sec_fix_0(rvalue
, usec
);
1875 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
1882 int config_parse_user_group(
1884 const char *filename
,
1886 const char *section
,
1887 unsigned section_line
,
1894 _cleanup_free_
char *k
= NULL
;
1904 if (isempty(rvalue
)) {
1905 *user
= mfree(*user
);
1909 r
= unit_full_printf(u
, rvalue
, &k
);
1911 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", rvalue
);
1915 if (!valid_user_group_name_or_id(k
)) {
1916 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
1920 return free_and_replace(*user
, k
);
1923 int config_parse_user_group_strv(
1925 const char *filename
,
1927 const char *section
,
1928 unsigned section_line
,
1935 char ***users
= data
;
1937 const char *p
= rvalue
;
1945 if (isempty(rvalue
)) {
1946 *users
= strv_free(*users
);
1951 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
1953 r
= extract_first_word(&p
, &word
, NULL
, 0);
1959 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax: %s", rvalue
);
1963 r
= unit_full_printf(u
, word
, &k
);
1965 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", word
);
1969 if (!valid_user_group_name_or_id(k
)) {
1970 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
1974 r
= strv_push(users
, k
);
1984 int config_parse_working_directory(
1986 const char *filename
,
1988 const char *section
,
1989 unsigned section_line
,
1996 ExecContext
*c
= data
;
2007 if (isempty(rvalue
)) {
2008 c
->working_directory_home
= false;
2009 c
->working_directory
= mfree(c
->working_directory
);
2013 if (rvalue
[0] == '-') {
2019 if (streq(rvalue
, "~")) {
2020 c
->working_directory_home
= true;
2021 c
->working_directory
= mfree(c
->working_directory
);
2023 _cleanup_free_
char *k
= NULL
;
2025 r
= unit_full_printf(u
, rvalue
, &k
);
2027 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2028 "Failed to resolve unit specifiers in working directory path '%s'%s: %m",
2029 rvalue
, missing_ok
? ", ignoring" : "");
2030 return missing_ok
? 0 : -ENOEXEC
;
2033 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
| (missing_ok
? 0 : PATH_CHECK_FATAL
), unit
, filename
, line
, lvalue
);
2035 return missing_ok
? 0 : -ENOEXEC
;
2037 c
->working_directory_home
= false;
2038 free_and_replace(c
->working_directory
, k
);
2041 c
->working_directory_missing_ok
= missing_ok
;
2045 int config_parse_unit_env_file(const char *unit
,
2046 const char *filename
,
2048 const char *section
,
2049 unsigned section_line
,
2058 _cleanup_free_
char *n
= NULL
;
2066 if (isempty(rvalue
)) {
2067 /* Empty assignment frees the list */
2068 *env
= strv_free(*env
);
2072 r
= unit_full_printf(u
, rvalue
, &n
);
2074 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2078 r
= path_simplify_and_warn(n
[0] == '-' ? n
+ 1 : n
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2082 r
= strv_push(env
, n
);
2091 int config_parse_environ(
2093 const char *filename
,
2095 const char *section
,
2096 unsigned section_line
,
2113 if (isempty(rvalue
)) {
2114 /* Empty assignment resets the list */
2115 *env
= strv_free(*env
);
2119 for (p
= rvalue
;; ) {
2120 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2122 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_QUOTES
);
2128 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2129 "Invalid syntax, ignoring: %s", rvalue
);
2134 r
= unit_full_printf(u
, word
, &k
);
2136 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2137 "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2143 if (!env_assignment_is_valid(k
)) {
2144 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2145 "Invalid environment assignment, ignoring: %s", k
);
2149 r
= strv_env_replace(env
, k
);
2157 int config_parse_pass_environ(
2159 const char *filename
,
2161 const char *section
,
2162 unsigned section_line
,
2169 _cleanup_strv_free_
char **n
= NULL
;
2170 size_t nlen
= 0, nbufsize
= 0;
2171 char*** passenv
= data
;
2172 const char *p
= rvalue
;
2181 if (isempty(rvalue
)) {
2182 /* Empty assignment resets the list */
2183 *passenv
= strv_free(*passenv
);
2188 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2190 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
2196 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2197 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2202 r
= unit_full_printf(u
, word
, &k
);
2204 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2205 "Failed to resolve specifiers in %s, ignoring: %m", word
);
2211 if (!env_name_is_valid(k
)) {
2212 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2213 "Invalid environment name for %s, ignoring: %s", lvalue
, k
);
2217 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
2220 n
[nlen
++] = TAKE_PTR(k
);
2225 r
= strv_extend_strv(passenv
, n
, true);
2233 int config_parse_unset_environ(
2235 const char *filename
,
2237 const char *section
,
2238 unsigned section_line
,
2245 _cleanup_strv_free_
char **n
= NULL
;
2246 size_t nlen
= 0, nbufsize
= 0;
2247 char*** unsetenv
= data
;
2248 const char *p
= rvalue
;
2257 if (isempty(rvalue
)) {
2258 /* Empty assignment resets the list */
2259 *unsetenv
= strv_free(*unsetenv
);
2264 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2266 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_QUOTES
);
2272 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2273 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2278 r
= unit_full_printf(u
, word
, &k
);
2280 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2281 "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2287 if (!env_assignment_is_valid(k
) && !env_name_is_valid(k
)) {
2288 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2289 "Invalid environment name or assignment %s, ignoring: %s", lvalue
, k
);
2293 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
2296 n
[nlen
++] = TAKE_PTR(k
);
2301 r
= strv_extend_strv(unsetenv
, n
, true);
2309 int config_parse_log_extra_fields(
2311 const char *filename
,
2313 const char *section
,
2314 unsigned section_line
,
2321 ExecContext
*c
= data
;
2323 const char *p
= rvalue
;
2331 if (isempty(rvalue
)) {
2332 exec_context_free_log_extra_fields(c
);
2337 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2341 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_QUOTES
);
2347 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
2351 r
= unit_full_printf(u
, word
, &k
);
2353 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2357 eq
= strchr(k
, '=');
2359 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Log field lacks '=' character, ignoring: %s", k
);
2363 if (!journal_field_valid(k
, eq
-k
, false)) {
2364 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Log field name is invalid, ignoring: %s", k
);
2368 t
= reallocarray(c
->log_extra_fields
, c
->n_log_extra_fields
+1, sizeof(struct iovec
));
2372 c
->log_extra_fields
= t
;
2373 c
->log_extra_fields
[c
->n_log_extra_fields
++] = IOVEC_MAKE_STRING(k
);
2379 int config_parse_unit_condition_path(
2381 const char *filename
,
2383 const char *section
,
2384 unsigned section_line
,
2391 _cleanup_free_
char *p
= NULL
;
2392 Condition
**list
= data
, *c
;
2393 ConditionType t
= ltype
;
2394 bool trigger
, negate
;
2403 if (isempty(rvalue
)) {
2404 /* Empty assignment resets the list */
2405 *list
= condition_free_list(*list
);
2409 trigger
= rvalue
[0] == '|';
2413 negate
= rvalue
[0] == '!';
2417 r
= unit_full_printf(u
, rvalue
, &p
);
2419 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2423 r
= path_simplify_and_warn(p
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2427 c
= condition_new(t
, p
, trigger
, negate
);
2431 LIST_PREPEND(conditions
, *list
, c
);
2435 int config_parse_unit_condition_string(
2437 const char *filename
,
2439 const char *section
,
2440 unsigned section_line
,
2447 _cleanup_free_
char *s
= NULL
;
2448 Condition
**list
= data
, *c
;
2449 ConditionType t
= ltype
;
2450 bool trigger
, negate
;
2459 if (isempty(rvalue
)) {
2460 /* Empty assignment resets the list */
2461 *list
= condition_free_list(*list
);
2465 trigger
= rvalue
[0] == '|';
2469 negate
= rvalue
[0] == '!';
2473 r
= unit_full_printf(u
, rvalue
, &s
);
2475 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2479 c
= condition_new(t
, s
, trigger
, negate
);
2483 LIST_PREPEND(conditions
, *list
, c
);
2487 int config_parse_unit_condition_null(
2489 const char *filename
,
2491 const char *section
,
2492 unsigned section_line
,
2499 Condition
**list
= data
, *c
;
2500 bool trigger
, negate
;
2508 if (isempty(rvalue
)) {
2509 /* Empty assignment resets the list */
2510 *list
= condition_free_list(*list
);
2514 trigger
= rvalue
[0] == '|';
2518 negate
= rvalue
[0] == '!';
2522 b
= parse_boolean(rvalue
);
2524 log_syntax(unit
, LOG_ERR
, filename
, line
, b
, "Failed to parse boolean value in condition, ignoring: %s", rvalue
);
2531 c
= condition_new(CONDITION_NULL
, NULL
, trigger
, negate
);
2535 LIST_PREPEND(conditions
, *list
, c
);
2539 int config_parse_unit_requires_mounts_for(
2541 const char *filename
,
2543 const char *section
,
2544 unsigned section_line
,
2551 const char *p
= rvalue
;
2561 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
2563 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
2569 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2570 "Invalid syntax, ignoring: %s", rvalue
);
2574 r
= unit_full_printf(u
, word
, &resolved
);
2576 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
2580 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2584 r
= unit_require_mounts_for(u
, resolved
, UNIT_DEPENDENCY_FILE
);
2586 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add required mount '%s', ignoring: %m", resolved
);
2592 int config_parse_documentation(const char *unit
,
2593 const char *filename
,
2595 const char *section
,
2596 unsigned section_line
,
2612 if (isempty(rvalue
)) {
2613 /* Empty assignment resets the list */
2614 u
->documentation
= strv_free(u
->documentation
);
2618 r
= config_parse_unit_strv_printf(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
,
2619 rvalue
, data
, userdata
);
2623 for (a
= b
= u
->documentation
; a
&& *a
; a
++) {
2625 if (documentation_url_is_valid(*a
))
2628 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid URL, ignoring: %s", *a
);
2639 int config_parse_syscall_filter(
2641 const char *filename
,
2643 const char *section
,
2644 unsigned section_line
,
2651 ExecContext
*c
= data
;
2653 bool invert
= false;
2662 if (isempty(rvalue
)) {
2663 /* Empty assignment resets the list */
2664 c
->syscall_filter
= hashmap_free(c
->syscall_filter
);
2665 c
->syscall_whitelist
= false;
2669 if (rvalue
[0] == '~') {
2674 if (!c
->syscall_filter
) {
2675 c
->syscall_filter
= hashmap_new(NULL
);
2676 if (!c
->syscall_filter
)
2680 /* Allow everything but the ones listed */
2681 c
->syscall_whitelist
= false;
2683 /* Allow nothing but the ones listed */
2684 c
->syscall_whitelist
= true;
2686 /* Accept default syscalls if we are on a whitelist */
2687 r
= seccomp_parse_syscall_filter("@default", -1, c
->syscall_filter
, SECCOMP_PARSE_WHITELIST
);
2695 _cleanup_free_
char *word
= NULL
, *name
= NULL
;
2698 r
= extract_first_word(&p
, &word
, NULL
, 0);
2704 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
2708 r
= parse_syscall_and_errno(word
, &name
, &num
);
2710 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse syscall:errno, ignoring: %s", word
);
2714 r
= seccomp_parse_syscall_filter_full(name
, num
, c
->syscall_filter
,
2715 SECCOMP_PARSE_LOG
|SECCOMP_PARSE_PERMISSIVE
|(invert
? SECCOMP_PARSE_INVERT
: 0)|(c
->syscall_whitelist
? SECCOMP_PARSE_WHITELIST
: 0),
2716 unit
, filename
, line
);
2722 int config_parse_syscall_archs(
2724 const char *filename
,
2726 const char *section
,
2727 unsigned section_line
,
2734 const char *p
= rvalue
;
2738 if (isempty(rvalue
)) {
2739 *archs
= set_free(*archs
);
2743 r
= set_ensure_allocated(archs
, NULL
);
2748 _cleanup_free_
char *word
= NULL
;
2751 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
2757 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2758 "Invalid syntax, ignoring: %s", rvalue
);
2762 r
= seccomp_arch_from_string(word
, &a
);
2764 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2765 "Failed to parse system call architecture \"%s\", ignoring: %m", word
);
2769 r
= set_put(*archs
, UINT32_TO_PTR(a
+ 1));
2775 int config_parse_syscall_errno(
2777 const char *filename
,
2779 const char *section
,
2780 unsigned section_line
,
2787 ExecContext
*c
= data
;
2794 if (isempty(rvalue
)) {
2795 /* Empty assignment resets to KILL */
2796 c
->syscall_errno
= 0;
2800 e
= parse_errno(rvalue
);
2802 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse error number, ignoring: %s", rvalue
);
2806 c
->syscall_errno
= e
;
2810 int config_parse_address_families(
2812 const char *filename
,
2814 const char *section
,
2815 unsigned section_line
,
2822 ExecContext
*c
= data
;
2823 bool invert
= false;
2831 if (isempty(rvalue
)) {
2832 /* Empty assignment resets the list */
2833 c
->address_families
= set_free(c
->address_families
);
2834 c
->address_families_whitelist
= false;
2838 if (rvalue
[0] == '~') {
2843 if (!c
->address_families
) {
2844 c
->address_families
= set_new(NULL
);
2845 if (!c
->address_families
)
2848 c
->address_families_whitelist
= !invert
;
2851 for (p
= rvalue
;;) {
2852 _cleanup_free_
char *word
= NULL
;
2855 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
2861 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2862 "Invalid syntax, ignoring: %s", rvalue
);
2866 af
= af_from_name(word
);
2868 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2869 "Failed to parse address family, ignoring: %s", word
);
2873 /* If we previously wanted to forbid an address family and now
2874 * we want to allow it, then just remove it from the list.
2876 if (!invert
== c
->address_families_whitelist
) {
2877 r
= set_put(c
->address_families
, INT_TO_PTR(af
));
2881 set_remove(c
->address_families
, INT_TO_PTR(af
));
2885 int config_parse_restrict_namespaces(
2887 const char *filename
,
2889 const char *section
,
2890 unsigned section_line
,
2897 ExecContext
*c
= data
;
2898 unsigned long flags
;
2899 bool invert
= false;
2902 if (isempty(rvalue
)) {
2903 /* Reset to the default. */
2904 c
->restrict_namespaces
= NAMESPACE_FLAGS_INITIAL
;
2908 /* Boolean parameter ignores the previous settings */
2909 r
= parse_boolean(rvalue
);
2911 c
->restrict_namespaces
= 0;
2913 } else if (r
== 0) {
2914 c
->restrict_namespaces
= NAMESPACE_FLAGS_ALL
;
2918 if (rvalue
[0] == '~') {
2923 /* Not a boolean argument, in this case it's a list of namespace types. */
2924 r
= namespace_flags_from_string(rvalue
, &flags
);
2926 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse namespace type string, ignoring: %s", rvalue
);
2930 if (c
->restrict_namespaces
== NAMESPACE_FLAGS_INITIAL
)
2931 /* Initial assignment. Just set the value. */
2932 c
->restrict_namespaces
= invert
? (~flags
) & NAMESPACE_FLAGS_ALL
: flags
;
2934 /* Merge the value with the previous one. */
2935 SET_FLAG(c
->restrict_namespaces
, flags
, !invert
);
2941 int config_parse_unit_slice(
2943 const char *filename
,
2945 const char *section
,
2946 unsigned section_line
,
2953 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
2954 _cleanup_free_
char *k
= NULL
;
2955 Unit
*u
= userdata
, *slice
= NULL
;
2963 r
= unit_name_printf(u
, rvalue
, &k
);
2965 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2969 r
= manager_load_unit(u
->manager
, k
, NULL
, &error
, &slice
);
2971 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to load slice unit %s, ignoring: %s", k
, bus_error_message(&error
, r
));
2975 r
= unit_set_slice(u
, slice
);
2977 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to assign slice %s to unit %s, ignoring: %m", slice
->id
, u
->id
);
2984 int config_parse_cpu_quota(
2986 const char *filename
,
2988 const char *section
,
2989 unsigned section_line
,
2996 CGroupContext
*c
= data
;
3003 if (isempty(rvalue
)) {
3004 c
->cpu_quota_per_sec_usec
= USEC_INFINITY
;
3008 r
= parse_percent_unbounded(rvalue
);
3010 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid CPU quota '%s', ignoring.", rvalue
);
3014 c
->cpu_quota_per_sec_usec
= ((usec_t
) r
* USEC_PER_SEC
) / 100U;
3018 int config_parse_memory_limit(
3020 const char *filename
,
3022 const char *section
,
3023 unsigned section_line
,
3030 CGroupContext
*c
= data
;
3031 uint64_t bytes
= CGROUP_LIMIT_MAX
;
3034 if (!isempty(rvalue
) && !streq(rvalue
, "infinity")) {
3036 r
= parse_percent(rvalue
);
3038 r
= parse_size(rvalue
, 1024, &bytes
);
3040 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid memory limit '%s', ignoring: %m", rvalue
);
3044 bytes
= physical_memory_scale(r
, 100U);
3046 if (bytes
>= UINT64_MAX
||
3047 (bytes
<= 0 && !streq(lvalue
, "MemorySwapMax"))) {
3048 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Memory limit '%s' out of range, ignoring.", rvalue
);
3053 if (streq(lvalue
, "MemoryLow"))
3054 c
->memory_low
= bytes
;
3055 else if (streq(lvalue
, "MemoryHigh"))
3056 c
->memory_high
= bytes
;
3057 else if (streq(lvalue
, "MemoryMax"))
3058 c
->memory_max
= bytes
;
3059 else if (streq(lvalue
, "MemorySwapMax"))
3060 c
->memory_swap_max
= bytes
;
3061 else if (streq(lvalue
, "MemoryLimit"))
3062 c
->memory_limit
= bytes
;
3069 int config_parse_tasks_max(
3071 const char *filename
,
3073 const char *section
,
3074 unsigned section_line
,
3081 uint64_t *tasks_max
= data
, v
;
3085 if (isempty(rvalue
)) {
3086 *tasks_max
= u
->manager
->default_tasks_max
;
3090 if (streq(rvalue
, "infinity")) {
3091 *tasks_max
= CGROUP_LIMIT_MAX
;
3095 r
= parse_percent(rvalue
);
3097 r
= safe_atou64(rvalue
, &v
);
3099 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid maximum tasks value '%s', ignoring: %m", rvalue
);
3103 v
= system_tasks_max_scale(r
, 100U);
3105 if (v
<= 0 || v
>= UINT64_MAX
) {
3106 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Maximum tasks value '%s' out of range, ignoring.", rvalue
);
3114 int config_parse_delegate(
3116 const char *filename
,
3118 const char *section
,
3119 unsigned section_line
,
3126 CGroupContext
*c
= data
;
3130 t
= unit_name_to_type(unit
);
3131 assert(t
!= _UNIT_TYPE_INVALID
);
3133 if (!unit_vtable
[t
]->can_delegate
) {
3134 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Delegate= setting not supported for this unit type, ignoring.");
3138 /* We either accept a boolean value, which may be used to turn on delegation for all controllers, or turn it
3139 * off for all. Or it takes a list of controller names, in which case we add the specified controllers to the
3140 * mask to delegate. */
3142 if (isempty(rvalue
)) {
3143 /* An empty string resets controllers and set Delegate=yes. */
3145 c
->delegate_controllers
= 0;
3149 r
= parse_boolean(rvalue
);
3151 const char *p
= rvalue
;
3152 CGroupMask mask
= 0;
3155 _cleanup_free_
char *word
= NULL
;
3156 CGroupController cc
;
3158 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
3164 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3168 cc
= cgroup_controller_from_string(word
);
3170 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid controller name '%s', ignoring", word
);
3174 mask
|= CGROUP_CONTROLLER_TO_MASK(cc
);
3178 c
->delegate_controllers
|= mask
;
3182 c
->delegate_controllers
= _CGROUP_MASK_ALL
;
3184 c
->delegate
= false;
3185 c
->delegate_controllers
= 0;
3191 int config_parse_device_allow(
3193 const char *filename
,
3195 const char *section
,
3196 unsigned section_line
,
3203 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3204 CGroupContext
*c
= data
;
3205 CGroupDeviceAllow
*a
;
3206 const char *p
= rvalue
;
3209 if (isempty(rvalue
)) {
3210 while (c
->device_allow
)
3211 cgroup_context_free_device_allow(c
, c
->device_allow
);
3216 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_QUOTES
);
3220 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3221 "Invalid syntax, ignoring: %s", rvalue
);
3225 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3226 "Failed to extract device path and rights from '%s', ignoring.", rvalue
);
3230 r
= unit_full_printf(userdata
, path
, &resolved
);
3232 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3233 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3237 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3241 if (!is_deviceallow_pattern(resolved
) &&
3242 !path_startswith(resolved
, "/run/systemd/inaccessible/")) {
3243 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device node path '%s', ignoring.", resolved
);
3247 if (!isempty(p
) && !in_charset(p
, "rwm")) {
3248 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device rights '%s', ignoring.", p
);
3252 a
= new0(CGroupDeviceAllow
, 1);
3256 a
->path
= TAKE_PTR(resolved
);
3257 a
->r
= isempty(p
) || !!strchr(p
, 'r');
3258 a
->w
= isempty(p
) || !!strchr(p
, 'w');
3259 a
->m
= isempty(p
) || !!strchr(p
, 'm');
3261 LIST_PREPEND(device_allow
, c
->device_allow
, a
);
3265 int config_parse_io_device_weight(
3267 const char *filename
,
3269 const char *section
,
3270 unsigned section_line
,
3277 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3278 CGroupIODeviceWeight
*w
;
3279 CGroupContext
*c
= data
;
3280 const char *p
= rvalue
;
3288 if (isempty(rvalue
)) {
3289 while (c
->io_device_weights
)
3290 cgroup_context_free_io_device_weight(c
, c
->io_device_weights
);
3295 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_QUOTES
);
3299 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3300 "Invalid syntax, ignoring: %s", rvalue
);
3303 if (r
== 0 || isempty(p
)) {
3304 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3305 "Failed to extract device path and weight from '%s', ignoring.", rvalue
);
3309 r
= unit_full_printf(userdata
, path
, &resolved
);
3311 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3312 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3316 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3320 r
= cg_weight_parse(p
, &u
);
3322 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "IO weight '%s' invalid, ignoring: %m", p
);
3326 assert(u
!= CGROUP_WEIGHT_INVALID
);
3328 w
= new0(CGroupIODeviceWeight
, 1);
3332 w
->path
= TAKE_PTR(resolved
);
3335 LIST_PREPEND(device_weights
, c
->io_device_weights
, w
);
3339 int config_parse_io_limit(
3341 const char *filename
,
3343 const char *section
,
3344 unsigned section_line
,
3351 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3352 CGroupIODeviceLimit
*l
= NULL
, *t
;
3353 CGroupContext
*c
= data
;
3354 CGroupIOLimitType type
;
3355 const char *p
= rvalue
;
3363 type
= cgroup_io_limit_type_from_string(lvalue
);
3366 if (isempty(rvalue
)) {
3367 LIST_FOREACH(device_limits
, l
, c
->io_device_limits
)
3368 l
->limits
[type
] = cgroup_io_limit_defaults
[type
];
3372 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_QUOTES
);
3376 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3377 "Invalid syntax, ignoring: %s", rvalue
);
3380 if (r
== 0 || isempty(p
)) {
3381 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3382 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
3386 r
= unit_full_printf(userdata
, path
, &resolved
);
3388 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3389 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3393 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3397 if (streq("infinity", p
))
3398 num
= CGROUP_LIMIT_MAX
;
3400 r
= parse_size(p
, 1000, &num
);
3401 if (r
< 0 || num
<= 0) {
3402 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid IO limit '%s', ignoring.", p
);
3407 LIST_FOREACH(device_limits
, t
, c
->io_device_limits
) {
3408 if (path_equal(resolved
, t
->path
)) {
3415 CGroupIOLimitType ttype
;
3417 l
= new0(CGroupIODeviceLimit
, 1);
3421 l
->path
= TAKE_PTR(resolved
);
3422 for (ttype
= 0; ttype
< _CGROUP_IO_LIMIT_TYPE_MAX
; ttype
++)
3423 l
->limits
[ttype
] = cgroup_io_limit_defaults
[ttype
];
3425 LIST_PREPEND(device_limits
, c
->io_device_limits
, l
);
3428 l
->limits
[type
] = num
;
3433 int config_parse_blockio_device_weight(
3435 const char *filename
,
3437 const char *section
,
3438 unsigned section_line
,
3445 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3446 CGroupBlockIODeviceWeight
*w
;
3447 CGroupContext
*c
= data
;
3448 const char *p
= rvalue
;
3456 if (isempty(rvalue
)) {
3457 while (c
->blockio_device_weights
)
3458 cgroup_context_free_blockio_device_weight(c
, c
->blockio_device_weights
);
3463 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_QUOTES
);
3467 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3468 "Invalid syntax, ignoring: %s", rvalue
);
3471 if (r
== 0 || isempty(p
)) {
3472 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3473 "Failed to extract device node and weight from '%s', ignoring.", rvalue
);
3477 r
= unit_full_printf(userdata
, path
, &resolved
);
3479 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3480 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3484 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3488 r
= cg_blkio_weight_parse(p
, &u
);
3490 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid block IO weight '%s', ignoring: %m", p
);
3494 assert(u
!= CGROUP_BLKIO_WEIGHT_INVALID
);
3496 w
= new0(CGroupBlockIODeviceWeight
, 1);
3500 w
->path
= TAKE_PTR(resolved
);
3503 LIST_PREPEND(device_weights
, c
->blockio_device_weights
, w
);
3507 int config_parse_blockio_bandwidth(
3509 const char *filename
,
3511 const char *section
,
3512 unsigned section_line
,
3519 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3520 CGroupBlockIODeviceBandwidth
*b
= NULL
, *t
;
3521 CGroupContext
*c
= data
;
3522 const char *p
= rvalue
;
3531 read
= streq("BlockIOReadBandwidth", lvalue
);
3533 if (isempty(rvalue
)) {
3534 LIST_FOREACH(device_bandwidths
, b
, c
->blockio_device_bandwidths
) {
3535 b
->rbps
= CGROUP_LIMIT_MAX
;
3536 b
->wbps
= CGROUP_LIMIT_MAX
;
3541 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_QUOTES
);
3545 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3546 "Invalid syntax, ignoring: %s", rvalue
);
3549 if (r
== 0 || isempty(p
)) {
3550 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3551 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
3555 r
= unit_full_printf(userdata
, path
, &resolved
);
3557 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3558 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3562 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3566 r
= parse_size(p
, 1000, &bytes
);
3567 if (r
< 0 || bytes
<= 0) {
3568 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid Block IO Bandwidth '%s', ignoring.", p
);
3572 LIST_FOREACH(device_bandwidths
, t
, c
->blockio_device_bandwidths
) {
3573 if (path_equal(resolved
, t
->path
)) {
3580 b
= new0(CGroupBlockIODeviceBandwidth
, 1);
3584 b
->path
= TAKE_PTR(resolved
);
3585 b
->rbps
= CGROUP_LIMIT_MAX
;
3586 b
->wbps
= CGROUP_LIMIT_MAX
;
3588 LIST_PREPEND(device_bandwidths
, c
->blockio_device_bandwidths
, b
);
3599 int config_parse_job_mode_isolate(
3601 const char *filename
,
3603 const char *section
,
3604 unsigned section_line
,
3618 r
= parse_boolean(rvalue
);
3620 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse boolean, ignoring: %s", rvalue
);
3624 log_notice("%s is deprecated. Please use OnFailureJobMode= instead", lvalue
);
3626 *m
= r
? JOB_ISOLATE
: JOB_REPLACE
;
3630 int config_parse_exec_directories(
3632 const char *filename
,
3634 const char *section
,
3635 unsigned section_line
,
3652 if (isempty(rvalue
)) {
3653 /* Empty assignment resets the list */
3654 *rt
= strv_free(*rt
);
3658 for (p
= rvalue
;;) {
3659 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
3661 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
3665 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3666 "Invalid syntax, ignoring: %s", rvalue
);
3672 r
= unit_full_printf(u
, word
, &k
);
3674 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
3675 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
3679 r
= path_simplify_and_warn(k
, PATH_CHECK_RELATIVE
, unit
, filename
, line
, lvalue
);
3683 if (path_startswith(k
, "private")) {
3684 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
3685 "%s= path can't be 'private', ingoring assignment: %s", lvalue
, word
);
3689 r
= strv_push(rt
, k
);
3696 int config_parse_set_status(
3698 const char *filename
,
3700 const char *section
,
3701 unsigned section_line
,
3709 const char *word
, *state
;
3711 ExitStatusSet
*status_set
= data
;
3718 /* Empty assignment resets the list */
3719 if (isempty(rvalue
)) {
3720 exit_status_set_free(status_set
);
3724 FOREACH_WORD(word
, l
, rvalue
, state
) {
3725 _cleanup_free_
char *temp
;
3729 temp
= strndup(word
, l
);
3733 r
= safe_atoi(temp
, &val
);
3735 val
= signal_from_string(temp
);
3738 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse value, ignoring: %s", word
);
3741 set
= &status_set
->signal
;
3743 if (val
< 0 || val
> 255) {
3744 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Value %d is outside range 0-255, ignoring", val
);
3747 set
= &status_set
->status
;
3750 r
= set_ensure_allocated(set
, NULL
);
3754 r
= set_put(*set
, INT_TO_PTR(val
));
3758 if (!isempty(state
))
3759 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Trailing garbage, ignoring.");
3764 int config_parse_namespace_path_strv(
3766 const char *filename
,
3768 const char *section
,
3769 unsigned section_line
,
3778 const char *p
= rvalue
;
3786 if (isempty(rvalue
)) {
3787 /* Empty assignment resets the list */
3788 *sv
= strv_free(*sv
);
3793 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
, *joined
= NULL
;
3795 bool ignore_enoent
= false, shall_prefix
= false;
3797 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
3803 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
3808 if (startswith(w
, "-")) {
3809 ignore_enoent
= true;
3812 if (startswith(w
, "+")) {
3813 shall_prefix
= true;
3817 r
= unit_full_printf(u
, w
, &resolved
);
3819 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", w
);
3823 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
3827 joined
= strjoin(ignore_enoent
? "-" : "",
3828 shall_prefix
? "+" : "",
3831 r
= strv_push(sv
, joined
);
3841 int config_parse_temporary_filesystems(
3843 const char *filename
,
3845 const char *section
,
3846 unsigned section_line
,
3854 ExecContext
*c
= data
;
3855 const char *p
= rvalue
;
3863 if (isempty(rvalue
)) {
3864 /* Empty assignment resets the list */
3865 temporary_filesystem_free_many(c
->temporary_filesystems
, c
->n_temporary_filesystems
);
3866 c
->temporary_filesystems
= NULL
;
3867 c
->n_temporary_filesystems
= 0;
3872 _cleanup_free_
char *word
= NULL
, *path
= NULL
, *resolved
= NULL
;
3875 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
3881 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
3886 r
= extract_first_word(&w
, &path
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
3890 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", word
);
3894 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid syntax, ignoring: %s", word
);
3898 r
= unit_full_printf(u
, path
, &resolved
);
3900 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", path
);
3904 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
3908 r
= temporary_filesystem_add(&c
->temporary_filesystems
, &c
->n_temporary_filesystems
, path
, w
);
3912 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse mount options, ignoring: %s", word
);
3918 int config_parse_bind_paths(
3920 const char *filename
,
3922 const char *section
,
3923 unsigned section_line
,
3930 ExecContext
*c
= data
;
3940 if (isempty(rvalue
)) {
3941 /* Empty assignment resets the list */
3942 bind_mount_free_many(c
->bind_mounts
, c
->n_bind_mounts
);
3943 c
->bind_mounts
= NULL
;
3944 c
->n_bind_mounts
= 0;
3950 _cleanup_free_
char *source
= NULL
, *destination
= NULL
;
3951 _cleanup_free_
char *sresolved
= NULL
, *dresolved
= NULL
;
3952 char *s
= NULL
, *d
= NULL
;
3953 bool rbind
= true, ignore_enoent
= false;
3955 r
= extract_first_word(&p
, &source
, ":" WHITESPACE
, EXTRACT_QUOTES
|EXTRACT_DONT_COALESCE_SEPARATORS
);
3961 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
3965 r
= unit_full_printf(u
, source
, &sresolved
);
3967 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
3968 "Failed to resolved unit specifiers in \"%s\", ignoring: %m", source
);
3974 ignore_enoent
= true;
3978 r
= path_simplify_and_warn(s
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
3982 /* Optionally, the destination is specified. */
3983 if (p
&& p
[-1] == ':') {
3984 r
= extract_first_word(&p
, &destination
, ":" WHITESPACE
, EXTRACT_QUOTES
|EXTRACT_DONT_COALESCE_SEPARATORS
);
3988 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
3992 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Missing argument after ':', ignoring: %s", s
);
3996 r
= unit_full_printf(u
, destination
, &dresolved
);
3998 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
3999 "Failed to resolved specifiers in \"%s\", ignoring: %m", destination
);
4003 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4009 /* Optionally, there's also a short option string specified */
4010 if (p
&& p
[-1] == ':') {
4011 _cleanup_free_
char *options
= NULL
;
4013 r
= extract_first_word(&p
, &options
, NULL
, EXTRACT_QUOTES
);
4017 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s: %s", lvalue
, rvalue
);
4021 if (isempty(options
) || streq(options
, "rbind"))
4023 else if (streq(options
, "norbind"))
4026 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid option string, ignoring setting: %s", options
);
4033 r
= bind_mount_add(&c
->bind_mounts
, &c
->n_bind_mounts
,
4037 .read_only
= !!strstr(lvalue
, "ReadOnly"),
4039 .ignore_enoent
= ignore_enoent
,
4048 int config_parse_job_timeout_sec(
4050 const char *filename
,
4052 const char *section
,
4053 unsigned section_line
,
4069 r
= parse_sec_fix_0(rvalue
, &usec
);
4071 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse JobTimeoutSec= parameter, ignoring: %s", rvalue
);
4075 /* If the user explicitly changed JobTimeoutSec= also change JobRunningTimeoutSec=, for compatibility with old
4076 * versions. If JobRunningTimeoutSec= was explicitly set, avoid this however as whatever the user picked should
4079 if (!u
->job_running_timeout_set
)
4080 u
->job_running_timeout
= usec
;
4082 u
->job_timeout
= usec
;
4087 int config_parse_job_running_timeout_sec(
4089 const char *filename
,
4091 const char *section
,
4092 unsigned section_line
,
4108 r
= parse_sec_fix_0(rvalue
, &usec
);
4110 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse JobRunningTimeoutSec= parameter, ignoring: %s", rvalue
);
4114 u
->job_running_timeout
= usec
;
4115 u
->job_running_timeout_set
= true;
4120 #define FOLLOW_MAX 8
4122 static int open_follow(char **filename
, FILE **_f
, Set
*names
, char **_final
) {
4133 /* This will update the filename pointer if the loaded file is
4134 * reached by a symlink. The old string will be freed. */
4137 char *target
, *name
;
4139 if (c
++ >= FOLLOW_MAX
)
4142 path_simplify(*filename
, false);
4144 /* Add the file name we are currently looking at to
4145 * the names of this unit, but only if it is a valid
4147 name
= basename(*filename
);
4148 if (unit_name_is_valid(name
, UNIT_NAME_ANY
)) {
4150 id
= set_get(names
, name
);
4156 r
= set_consume(names
, id
);
4162 /* Try to open the file name, but don't if its a symlink */
4163 fd
= open(*filename
, O_RDONLY
|O_CLOEXEC
|O_NOCTTY
|O_NOFOLLOW
);
4170 /* Hmm, so this is a symlink. Let's read the name, and follow it manually */
4171 r
= readlink_and_make_absolute(*filename
, &target
);
4175 free_and_replace(*filename
, target
);
4178 f
= fdopen(fd
, "re");
4190 static int merge_by_names(Unit
**u
, Set
*names
, const char *id
) {
4198 /* Let's try to add in all symlink names we found */
4199 while ((k
= set_steal_first(names
))) {
4201 /* First try to merge in the other name into our
4203 r
= unit_merge_by_name(*u
, k
);
4207 /* Hmm, we couldn't merge the other unit into
4208 * ours? Then let's try it the other way
4211 /* If the symlink name we are looking at is unit template, then
4212 we must search for instance of this template */
4213 if (unit_name_is_valid(k
, UNIT_NAME_TEMPLATE
) && (*u
)->instance
) {
4214 _cleanup_free_
char *instance
= NULL
;
4216 r
= unit_name_replace_instance(k
, (*u
)->instance
, &instance
);
4220 other
= manager_get_unit((*u
)->manager
, instance
);
4222 other
= manager_get_unit((*u
)->manager
, k
);
4227 r
= unit_merge(other
, *u
);
4230 return merge_by_names(u
, names
, NULL
);
4238 unit_choose_id(*u
, id
);
4246 static int load_from_path(Unit
*u
, const char *path
) {
4247 _cleanup_set_free_free_ Set
*symlink_names
= NULL
;
4248 _cleanup_fclose_
FILE *f
= NULL
;
4249 _cleanup_free_
char *filename
= NULL
;
4258 symlink_names
= set_new(&string_hash_ops
);
4262 if (path_is_absolute(path
)) {
4264 filename
= strdup(path
);
4268 r
= open_follow(&filename
, &f
, symlink_names
, &id
);
4270 filename
= mfree(filename
);
4278 STRV_FOREACH(p
, u
->manager
->lookup_paths
.search_path
) {
4280 /* Instead of opening the path right away, we manually
4281 * follow all symlinks and add their name to our unit
4282 * name set while doing so */
4283 filename
= path_make_absolute(path
, *p
);
4287 if (u
->manager
->unit_path_cache
&&
4288 !set_get(u
->manager
->unit_path_cache
, filename
))
4291 r
= open_follow(&filename
, &f
, symlink_names
, &id
);
4294 filename
= mfree(filename
);
4296 /* ENOENT means that the file is missing or is a dangling symlink.
4297 * ENOTDIR means that one of paths we expect to be is a directory
4298 * is not a directory, we should just ignore that.
4299 * EACCES means that the directory or file permissions are wrong.
4302 log_debug_errno(r
, "Cannot access \"%s\": %m", filename
);
4303 else if (!IN_SET(r
, -ENOENT
, -ENOTDIR
))
4306 /* Empty the symlink names for the next run */
4307 set_clear_free(symlink_names
);
4312 /* Hmm, no suitable file found? */
4315 if (!unit_type_may_alias(u
->type
) && set_size(symlink_names
) > 1) {
4316 log_unit_warning(u
, "Unit type of %s does not support alias names, refusing loading via symlink.", u
->id
);
4321 r
= merge_by_names(&merged
, symlink_names
, id
);
4326 u
->load_state
= UNIT_MERGED
;
4330 if (fstat(fileno(f
), &st
) < 0)
4333 if (null_or_empty(&st
)) {
4334 u
->load_state
= UNIT_MASKED
;
4335 u
->fragment_mtime
= 0;
4337 u
->load_state
= UNIT_LOADED
;
4338 u
->fragment_mtime
= timespec_load(&st
.st_mtim
);
4340 /* Now, parse the file contents */
4341 r
= config_parse(u
->id
, filename
, f
,
4342 UNIT_VTABLE(u
)->sections
,
4343 config_item_perf_lookup
, load_fragment_gperf_lookup
,
4344 CONFIG_PARSE_ALLOW_INCLUDE
, u
);
4349 free_and_replace(u
->fragment_path
, filename
);
4351 if (u
->source_path
) {
4352 if (stat(u
->source_path
, &st
) >= 0)
4353 u
->source_mtime
= timespec_load(&st
.st_mtim
);
4355 u
->source_mtime
= 0;
4361 int unit_load_fragment(Unit
*u
) {
4367 assert(u
->load_state
== UNIT_STUB
);
4371 u
->load_state
= UNIT_LOADED
;
4375 /* First, try to find the unit under its id. We always look
4376 * for unit files in the default directories, to make it easy
4377 * to override things by placing things in /etc/systemd/system */
4378 r
= load_from_path(u
, u
->id
);
4382 /* Try to find an alias we can load this with */
4383 if (u
->load_state
== UNIT_STUB
) {
4384 SET_FOREACH(t
, u
->names
, i
) {
4389 r
= load_from_path(u
, t
);
4393 if (u
->load_state
!= UNIT_STUB
)
4398 /* And now, try looking for it under the suggested (originally linked) path */
4399 if (u
->load_state
== UNIT_STUB
&& u
->fragment_path
) {
4401 r
= load_from_path(u
, u
->fragment_path
);
4405 if (u
->load_state
== UNIT_STUB
)
4406 /* Hmm, this didn't work? Then let's get rid
4407 * of the fragment path stored for us, so that
4408 * we don't point to an invalid location. */
4409 u
->fragment_path
= mfree(u
->fragment_path
);
4412 /* Look for a template */
4413 if (u
->load_state
== UNIT_STUB
&& u
->instance
) {
4414 _cleanup_free_
char *k
= NULL
;
4416 r
= unit_name_template(u
->id
, &k
);
4420 r
= load_from_path(u
, k
);
4423 log_unit_notice(u
, "Unit configuration has fatal error, unit will not be started.");
4427 if (u
->load_state
== UNIT_STUB
) {
4428 SET_FOREACH(t
, u
->names
, i
) {
4429 _cleanup_free_
char *z
= NULL
;
4434 r
= unit_name_template(t
, &z
);
4438 r
= load_from_path(u
, z
);
4442 if (u
->load_state
!= UNIT_STUB
)
4451 void unit_dump_config_items(FILE *f
) {
4452 static const struct {
4453 const ConfigParserCallback callback
;
4456 { config_parse_warn_compat
, "NOTSUPPORTED" },
4457 { config_parse_int
, "INTEGER" },
4458 { config_parse_unsigned
, "UNSIGNED" },
4459 { config_parse_iec_size
, "SIZE" },
4460 { config_parse_iec_uint64
, "SIZE" },
4461 { config_parse_si_size
, "SIZE" },
4462 { config_parse_bool
, "BOOLEAN" },
4463 { config_parse_string
, "STRING" },
4464 { config_parse_path
, "PATH" },
4465 { config_parse_unit_path_printf
, "PATH" },
4466 { config_parse_strv
, "STRING [...]" },
4467 { config_parse_exec_nice
, "NICE" },
4468 { config_parse_exec_oom_score_adjust
, "OOMSCOREADJUST" },
4469 { config_parse_exec_io_class
, "IOCLASS" },
4470 { config_parse_exec_io_priority
, "IOPRIORITY" },
4471 { config_parse_exec_cpu_sched_policy
, "CPUSCHEDPOLICY" },
4472 { config_parse_exec_cpu_sched_prio
, "CPUSCHEDPRIO" },
4473 { config_parse_exec_cpu_affinity
, "CPUAFFINITY" },
4474 { config_parse_mode
, "MODE" },
4475 { config_parse_unit_env_file
, "FILE" },
4476 { config_parse_exec_output
, "OUTPUT" },
4477 { config_parse_exec_input
, "INPUT" },
4478 { config_parse_log_facility
, "FACILITY" },
4479 { config_parse_log_level
, "LEVEL" },
4480 { config_parse_exec_secure_bits
, "SECUREBITS" },
4481 { config_parse_capability_set
, "BOUNDINGSET" },
4482 { config_parse_rlimit
, "LIMIT" },
4483 { config_parse_unit_deps
, "UNIT [...]" },
4484 { config_parse_exec
, "PATH [ARGUMENT [...]]" },
4485 { config_parse_service_type
, "SERVICETYPE" },
4486 { config_parse_service_restart
, "SERVICERESTART" },
4487 { config_parse_kill_mode
, "KILLMODE" },
4488 { config_parse_signal
, "SIGNAL" },
4489 { config_parse_socket_listen
, "SOCKET [...]" },
4490 { config_parse_socket_bind
, "SOCKETBIND" },
4491 { config_parse_socket_bindtodevice
, "NETWORKINTERFACE" },
4492 { config_parse_sec
, "SECONDS" },
4493 { config_parse_nsec
, "NANOSECONDS" },
4494 { config_parse_namespace_path_strv
, "PATH [...]" },
4495 { config_parse_bind_paths
, "PATH[:PATH[:OPTIONS]] [...]" },
4496 { config_parse_unit_requires_mounts_for
, "PATH [...]" },
4497 { config_parse_exec_mount_flags
, "MOUNTFLAG [...]" },
4498 { config_parse_unit_string_printf
, "STRING" },
4499 { config_parse_trigger_unit
, "UNIT" },
4500 { config_parse_timer
, "TIMER" },
4501 { config_parse_path_spec
, "PATH" },
4502 { config_parse_notify_access
, "ACCESS" },
4503 { config_parse_ip_tos
, "TOS" },
4504 { config_parse_unit_condition_path
, "CONDITION" },
4505 { config_parse_unit_condition_string
, "CONDITION" },
4506 { config_parse_unit_condition_null
, "CONDITION" },
4507 { config_parse_unit_slice
, "SLICE" },
4508 { config_parse_documentation
, "URL" },
4509 { config_parse_service_timeout
, "SECONDS" },
4510 { config_parse_emergency_action
, "ACTION" },
4511 { config_parse_set_status
, "STATUS" },
4512 { config_parse_service_sockets
, "SOCKETS" },
4513 { config_parse_environ
, "ENVIRON" },
4515 { config_parse_syscall_filter
, "SYSCALLS" },
4516 { config_parse_syscall_archs
, "ARCHS" },
4517 { config_parse_syscall_errno
, "ERRNO" },
4518 { config_parse_address_families
, "FAMILIES" },
4519 { config_parse_restrict_namespaces
, "NAMESPACES" },
4521 { config_parse_cpu_shares
, "SHARES" },
4522 { config_parse_cg_weight
, "WEIGHT" },
4523 { config_parse_memory_limit
, "LIMIT" },
4524 { config_parse_device_allow
, "DEVICE" },
4525 { config_parse_device_policy
, "POLICY" },
4526 { config_parse_io_limit
, "LIMIT" },
4527 { config_parse_io_device_weight
, "DEVICEWEIGHT" },
4528 { config_parse_blockio_bandwidth
, "BANDWIDTH" },
4529 { config_parse_blockio_weight
, "WEIGHT" },
4530 { config_parse_blockio_device_weight
, "DEVICEWEIGHT" },
4531 { config_parse_long
, "LONG" },
4532 { config_parse_socket_service
, "SERVICE" },
4534 { config_parse_exec_selinux_context
, "LABEL" },
4536 { config_parse_job_mode
, "MODE" },
4537 { config_parse_job_mode_isolate
, "BOOLEAN" },
4538 { config_parse_personality
, "PERSONALITY" },
4541 const char *prev
= NULL
;
4546 NULSTR_FOREACH(i
, load_fragment_gperf_nulstr
) {
4547 const char *rvalue
= "OTHER", *lvalue
;
4548 const ConfigPerfItem
*p
;
4553 assert_se(p
= load_fragment_gperf_lookup(i
, strlen(i
)));
4555 /* Hide legacy settings */
4556 if (p
->parse
== config_parse_warn_compat
&&
4557 p
->ltype
== DISABLED_LEGACY
)
4560 for (j
= 0; j
< ELEMENTSOF(table
); j
++)
4561 if (p
->parse
== table
[j
].callback
) {
4562 rvalue
= table
[j
].rvalue
;
4566 dot
= strchr(i
, '.');
4567 lvalue
= dot
? dot
+ 1 : i
;
4571 if (!prev
|| !strneq(prev
, i
, prefix_len
+1)) {
4575 fprintf(f
, "[%.*s]\n", (int) prefix_len
, i
);
4578 fprintf(f
, "%s=%s\n", lvalue
, rvalue
);