1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
3 Copyright © 2012 Holger Hans Peter Freyther
14 #include <sys/resource.h>
16 #include "sd-messages.h"
19 #include "all-units.h"
20 #include "alloc-util.h"
21 #include "bpf-firewall.h"
22 #include "bpf-program.h"
23 #include "bpf-socket-bind.h"
24 #include "bus-error.h"
25 #include "bus-internal.h"
28 #include "capability-util.h"
29 #include "cgroup-setup.h"
30 #include "conf-parser.h"
31 #include "core-varlink.h"
32 #include "cpu-set-util.h"
33 #include "creds-util.h"
35 #include "errno-list.h"
40 #include "hexdecoct.h"
42 #include "ip-protocol-list.h"
43 #include "journal-file.h"
44 #include "limits-util.h"
45 #include "load-fragment.h"
47 #include "missing_ioprio.h"
48 #include "mountpoint-util.h"
49 #include "nulstr-util.h"
50 #include "parse-socket-bind-item.h"
51 #include "parse-util.h"
52 #include "path-util.h"
53 #include "percent-util.h"
54 #include "process-util.h"
56 #include "seccomp-util.h"
58 #include "securebits-util.h"
59 #include "signal-util.h"
60 #include "socket-netlink.h"
61 #include "specifier.h"
62 #include "stat-util.h"
63 #include "string-util.h"
65 #include "syslog-util.h"
66 #include "time-util.h"
67 #include "unit-name.h"
68 #include "unit-printf.h"
69 #include "user-util.h"
73 static int parse_socket_protocol(const char *s
) {
76 r
= parse_ip_protocol(s
);
79 if (!IN_SET(r
, IPPROTO_UDPLITE
, IPPROTO_SCTP
))
80 return -EPROTONOSUPPORT
;
85 int parse_crash_chvt(const char *value
, int *data
) {
88 if (safe_atoi(value
, data
) >= 0)
91 b
= parse_boolean(value
);
96 *data
= 0; /* switch to where kmsg goes */
98 *data
= -1; /* turn off switching */
103 int parse_confirm_spawn(const char *value
, char **console
) {
107 r
= value
? parse_boolean(value
) : 1;
111 } else if (r
> 0) /* on with default tty */
112 s
= strdup("/dev/console");
113 else if (is_path(value
)) /* on with fully qualified path */
115 else /* on with only a tty file name, not a fully qualified path */
116 s
= path_join("/dev/", value
);
124 DEFINE_CONFIG_PARSE(config_parse_socket_protocol
, parse_socket_protocol
, "Failed to parse socket protocol");
125 DEFINE_CONFIG_PARSE(config_parse_exec_secure_bits
, secure_bits_from_string
, "Failed to parse secure bits");
126 DEFINE_CONFIG_PARSE_ENUM(config_parse_collect_mode
, collect_mode
, CollectMode
, "Failed to parse garbage collection mode");
127 DEFINE_CONFIG_PARSE_ENUM(config_parse_device_policy
, cgroup_device_policy
, CGroupDevicePolicy
, "Failed to parse device policy");
128 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_keyring_mode
, exec_keyring_mode
, ExecKeyringMode
, "Failed to parse keyring mode");
129 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_proc
, protect_proc
, ProtectProc
, "Failed to parse /proc/ protection mode");
130 DEFINE_CONFIG_PARSE_ENUM(config_parse_proc_subset
, proc_subset
, ProcSubset
, "Failed to parse /proc/ subset mode");
131 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_utmp_mode
, exec_utmp_mode
, ExecUtmpMode
, "Failed to parse utmp mode");
132 DEFINE_CONFIG_PARSE_ENUM(config_parse_job_mode
, job_mode
, JobMode
, "Failed to parse job mode");
133 DEFINE_CONFIG_PARSE_ENUM(config_parse_notify_access
, notify_access
, NotifyAccess
, "Failed to parse notify access specifier");
134 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_home
, protect_home
, ProtectHome
, "Failed to parse protect home value");
135 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_system
, protect_system
, ProtectSystem
, "Failed to parse protect system value");
136 DEFINE_CONFIG_PARSE_ENUM(config_parse_runtime_preserve_mode
, exec_preserve_mode
, ExecPreserveMode
, "Failed to parse runtime directory preserve mode");
137 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_type
, service_type
, ServiceType
, "Failed to parse service type");
138 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart
, service_restart
, ServiceRestart
, "Failed to parse service restart specifier");
139 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_timeout_failure_mode
, service_timeout_failure_mode
, ServiceTimeoutFailureMode
, "Failed to parse timeout failure mode");
140 DEFINE_CONFIG_PARSE_ENUM(config_parse_socket_bind
, socket_address_bind_ipv6_only_or_bool
, SocketAddressBindIPv6Only
, "Failed to parse bind IPv6 only value");
141 DEFINE_CONFIG_PARSE_ENUM(config_parse_oom_policy
, oom_policy
, OOMPolicy
, "Failed to parse OOM policy");
142 DEFINE_CONFIG_PARSE_ENUM(config_parse_managed_oom_preference
, managed_oom_preference
, ManagedOOMPreference
, "Failed to parse ManagedOOMPreference=");
143 DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_ip_tos
, ip_tos
, int, -1, "Failed to parse IP TOS value");
144 DEFINE_CONFIG_PARSE_PTR(config_parse_blockio_weight
, cg_blkio_weight_parse
, uint64_t, "Invalid block IO weight");
145 DEFINE_CONFIG_PARSE_PTR(config_parse_cg_weight
, cg_weight_parse
, uint64_t, "Invalid weight");
146 DEFINE_CONFIG_PARSE_PTR(config_parse_cpu_shares
, cg_cpu_shares_parse
, uint64_t, "Invalid CPU shares");
147 DEFINE_CONFIG_PARSE_PTR(config_parse_exec_mount_flags
, mount_propagation_flags_from_string
, unsigned long, "Failed to parse mount flag");
148 DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_numa_policy
, mpol
, int, -1, "Invalid NUMA policy type");
149 DEFINE_CONFIG_PARSE_ENUM(config_parse_status_unit_format
, status_unit_format
, StatusUnitFormat
, "Failed to parse status unit format");
150 DEFINE_CONFIG_PARSE_ENUM_FULL(config_parse_socket_timestamping
, socket_timestamping_from_string_harder
, SocketTimestamping
, "Failed to parse timestamping precision");
152 int config_parse_unit_deps(
154 const char *filename
,
157 unsigned section_line
,
164 UnitDependency d
= ltype
;
171 for (const char *p
= rvalue
;;) {
172 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
175 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_RETAIN_ESCAPE
);
181 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
185 r
= unit_name_printf(u
, word
, &k
);
187 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
191 r
= unit_add_dependency_by_name(u
, d
, k
, true, UNIT_DEPENDENCY_FILE
);
193 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
197 int config_parse_obsolete_unit_deps(
199 const char *filename
,
202 unsigned section_line
,
209 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
210 "Unit dependency type %s= is obsolete, replacing by %s=, please update your unit file", lvalue
, unit_dependency_to_string(ltype
));
212 return config_parse_unit_deps(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
);
215 int config_parse_unit_string_printf(
217 const char *filename
,
220 unsigned section_line
,
227 _cleanup_free_
char *k
= NULL
;
228 const Unit
*u
= userdata
;
236 r
= unit_full_printf(u
, rvalue
, &k
);
238 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
242 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
245 int config_parse_unit_strv_printf(
247 const char *filename
,
250 unsigned section_line
,
257 const Unit
*u
= userdata
;
258 _cleanup_free_
char *k
= NULL
;
266 r
= unit_full_printf(u
, rvalue
, &k
);
268 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
272 return config_parse_strv(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
275 int config_parse_unit_path_printf(
277 const char *filename
,
280 unsigned section_line
,
287 _cleanup_free_
char *k
= NULL
;
288 const Unit
*u
= userdata
;
297 r
= unit_path_printf(u
, rvalue
, &k
);
299 log_syntax(unit
, fatal
? LOG_ERR
: LOG_WARNING
, filename
, line
, r
,
300 "Failed to resolve unit specifiers in '%s'%s: %m",
301 rvalue
, fatal
? "" : ", ignoring");
302 return fatal
? -ENOEXEC
: 0;
305 return config_parse_path(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
308 int config_parse_colon_separated_paths(
310 const char *filename
,
313 unsigned section_line
,
320 const Unit
*u
= userdata
;
328 if (isempty(rvalue
)) {
329 /* Empty assignment resets the list */
330 *sv
= strv_free(*sv
);
334 for (const char *p
= rvalue
;;) {
335 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
337 r
= extract_first_word(&p
, &word
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
341 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
347 r
= unit_path_printf(u
, word
, &k
);
349 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
350 "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
354 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
358 r
= strv_consume(sv
, TAKE_PTR(k
));
366 int config_parse_unit_path_strv_printf(
368 const char *filename
,
371 unsigned section_line
,
379 const Unit
*u
= userdata
;
387 if (isempty(rvalue
)) {
392 for (const char *p
= rvalue
;;) {
393 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
395 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
401 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
402 "Invalid syntax, ignoring: %s", rvalue
);
406 r
= unit_path_printf(u
, word
, &k
);
408 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
409 "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
413 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
417 r
= strv_consume(x
, TAKE_PTR(k
));
423 static int patch_var_run(
425 const char *filename
,
433 e
= path_startswith(*path
, "/var/run/");
437 z
= path_join("/run/", e
);
441 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
442 "%s= references a path below legacy directory /var/run/, updating %s → %s; "
443 "please update the unit file accordingly.", lvalue
, *path
, z
);
445 free_and_replace(*path
, z
);
450 int config_parse_socket_listen(
452 const char *filename
,
455 unsigned section_line
,
462 _cleanup_free_ SocketPort
*p
= NULL
;
474 if (isempty(rvalue
)) {
475 /* An empty assignment removes all ports */
476 socket_free_ports(s
);
480 p
= new0(SocketPort
, 1);
484 if (ltype
!= SOCKET_SOCKET
) {
485 _cleanup_free_
char *k
= NULL
;
487 r
= unit_path_printf(UNIT(s
), rvalue
, &k
);
489 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
493 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
497 if (ltype
== SOCKET_FIFO
) {
498 r
= patch_var_run(unit
, filename
, line
, lvalue
, &k
);
503 free_and_replace(p
->path
, k
);
506 } else if (streq(lvalue
, "ListenNetlink")) {
507 _cleanup_free_
char *k
= NULL
;
509 r
= unit_path_printf(UNIT(s
), rvalue
, &k
);
511 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
515 r
= socket_address_parse_netlink(&p
->address
, k
);
517 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse address value in '%s', ignoring: %m", k
);
521 p
->type
= SOCKET_SOCKET
;
524 _cleanup_free_
char *k
= NULL
;
526 r
= unit_path_printf(UNIT(s
), rvalue
, &k
);
528 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
532 if (k
[0] == '/') { /* Only for AF_UNIX file system sockets… */
533 r
= patch_var_run(unit
, filename
, line
, lvalue
, &k
);
538 r
= socket_address_parse_and_warn(&p
->address
, k
);
540 if (r
!= -EAFNOSUPPORT
)
541 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse address value in '%s', ignoring: %m", k
);
545 if (streq(lvalue
, "ListenStream"))
546 p
->address
.type
= SOCK_STREAM
;
547 else if (streq(lvalue
, "ListenDatagram"))
548 p
->address
.type
= SOCK_DGRAM
;
550 assert(streq(lvalue
, "ListenSequentialPacket"));
551 p
->address
.type
= SOCK_SEQPACKET
;
554 if (socket_address_family(&p
->address
) != AF_LOCAL
&& p
->address
.type
== SOCK_SEQPACKET
) {
555 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Address family not supported, ignoring: %s", rvalue
);
559 p
->type
= SOCKET_SOCKET
;
563 p
->auxiliary_fds
= NULL
;
564 p
->n_auxiliary_fds
= 0;
567 LIST_FIND_TAIL(port
, s
->ports
, tail
);
568 LIST_INSERT_AFTER(port
, s
->ports
, tail
, p
);
575 int config_parse_exec_nice(
577 const char *filename
,
580 unsigned section_line
,
587 ExecContext
*c
= data
;
595 if (isempty(rvalue
)) {
600 r
= parse_nice(rvalue
, &priority
);
603 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Nice priority out of range, ignoring: %s", rvalue
);
605 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse nice priority '%s', ignoring: %m", rvalue
);
615 int config_parse_exec_oom_score_adjust(
617 const char *filename
,
620 unsigned section_line
,
627 ExecContext
*c
= data
;
635 if (isempty(rvalue
)) {
636 c
->oom_score_adjust_set
= false;
640 r
= parse_oom_score_adjust(rvalue
, &oa
);
643 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "OOM score adjust value out of range, ignoring: %s", rvalue
);
645 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse the OOM score adjust value '%s', ignoring: %m", rvalue
);
649 c
->oom_score_adjust
= oa
;
650 c
->oom_score_adjust_set
= true;
655 int config_parse_exec_coredump_filter(
657 const char *filename
,
660 unsigned section_line
,
667 ExecContext
*c
= data
;
675 if (isempty(rvalue
)) {
676 c
->coredump_filter
= 0;
677 c
->coredump_filter_set
= false;
682 r
= coredump_filter_mask_from_string(rvalue
, &f
);
684 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
685 "Failed to parse the CoredumpFilter=%s, ignoring: %m", rvalue
);
689 c
->coredump_filter
|= f
;
690 c
->oom_score_adjust_set
= true;
694 int config_parse_kill_mode(
696 const char *filename
,
699 unsigned section_line
,
706 KillMode
*k
= data
, m
;
713 if (isempty(rvalue
)) {
714 *k
= KILL_CONTROL_GROUP
;
718 m
= kill_mode_from_string(rvalue
);
720 log_syntax(unit
, LOG_WARNING
, filename
, line
, m
,
721 "Failed to parse kill mode specification, ignoring: %s", rvalue
);
726 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
727 "Unit configured to use KillMode=none. "
728 "This is unsafe, as it disables systemd's process lifecycle management for the service. "
729 "Please update your service to use a safer KillMode=, such as 'mixed' or 'control-group'. "
730 "Support for KillMode=none is deprecated and will eventually be removed.");
736 int config_parse_exec(
738 const char *filename
,
741 unsigned section_line
,
748 ExecCommand
**e
= data
;
749 const Unit
*u
= userdata
;
761 if (isempty(rvalue
)) {
762 /* An empty assignment resets the list */
763 *e
= exec_command_free_list(*e
);
769 _cleanup_free_
char *path
= NULL
, *firstword
= NULL
;
770 ExecCommandFlags flags
= 0;
771 bool ignore
= false, separate_argv0
= false;
772 _cleanup_free_ ExecCommand
*nce
= NULL
;
773 _cleanup_strv_free_
char **n
= NULL
;
779 r
= extract_first_word_and_warn(&p
, &firstword
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
783 /* A lone ";" is a separator. Let's make sure we don't treat it as an executable name. */
784 if (streq(firstword
, ";")) {
791 /* We accept an absolute path as first argument. If it's prefixed with - and the path doesn't
792 * exist, we ignore it instead of erroring out; if it's prefixed with @, we allow overriding of
793 * argv[0]; if it's prefixed with :, we will not do environment variable substitution;
794 * if it's prefixed with +, it will be run with full privileges and no sandboxing; if
795 * it's prefixed with '!' we apply sandboxing, but do not change user/group credentials; if
796 * it's prefixed with '!!', then we apply user/group credentials if the kernel supports ambient
797 * capabilities -- if it doesn't we don't apply the credentials themselves, but do apply most
798 * other sandboxing, with some special exceptions for changing UID.
800 * The idea is that '!!' may be used to write services that can take benefit of systemd's
801 * UID/GID dropping if the kernel supports ambient creds, but provide an automatic fallback to
802 * privilege dropping within the daemon if the kernel does not offer that. */
804 if (*f
== '-' && !(flags
& EXEC_COMMAND_IGNORE_FAILURE
)) {
805 flags
|= EXEC_COMMAND_IGNORE_FAILURE
;
807 } else if (*f
== '@' && !separate_argv0
)
808 separate_argv0
= true;
809 else if (*f
== ':' && !(flags
& EXEC_COMMAND_NO_ENV_EXPAND
))
810 flags
|= EXEC_COMMAND_NO_ENV_EXPAND
;
811 else if (*f
== '+' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
812 flags
|= EXEC_COMMAND_FULLY_PRIVILEGED
;
813 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
814 flags
|= EXEC_COMMAND_NO_SETUID
;
815 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_AMBIENT_MAGIC
))) {
816 flags
&= ~EXEC_COMMAND_NO_SETUID
;
817 flags
|= EXEC_COMMAND_AMBIENT_MAGIC
;
823 r
= unit_path_printf(u
, f
, &path
);
825 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
826 "Failed to resolve unit specifiers in '%s'%s: %m",
827 f
, ignore
? ", ignoring" : "");
828 return ignore
? 0 : -ENOEXEC
;
832 /* First word is either "-" or "@" with no command. */
833 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
834 "Empty path in command line%s: '%s'",
835 ignore
? ", ignoring" : "", rvalue
);
836 return ignore
? 0 : -ENOEXEC
;
838 if (!string_is_safe(path
)) {
839 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
840 "Executable name contains special characters%s: %s",
841 ignore
? ", ignoring" : "", path
);
842 return ignore
? 0 : -ENOEXEC
;
844 if (endswith(path
, "/")) {
845 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
846 "Executable path specifies a directory%s: %s",
847 ignore
? ", ignoring" : "", path
);
848 return ignore
? 0 : -ENOEXEC
;
851 if (!(path_is_absolute(path
) ? path_is_valid(path
) : filename_is_valid(path
))) {
852 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
853 "Neither a valid executable name nor an absolute path%s: %s",
854 ignore
? ", ignoring" : "", path
);
855 return ignore
? 0 : -ENOEXEC
;
858 if (!separate_argv0
) {
861 if (!GREEDY_REALLOC0(n
, nlen
+ 2))
873 while (!isempty(p
)) {
874 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
876 /* Check explicitly for an unquoted semicolon as
877 * command separator token. */
878 if (p
[0] == ';' && (!p
[1] || strchr(WHITESPACE
, p
[1]))) {
880 p
+= strspn(p
, WHITESPACE
);
885 /* Check for \; explicitly, to not confuse it with \\; or "\;" or "\\;" etc.
886 * extract_first_word() would return the same for all of those. */
887 if (p
[0] == '\\' && p
[1] == ';' && (!p
[2] || strchr(WHITESPACE
, p
[2]))) {
891 p
+= strspn(p
, WHITESPACE
);
893 if (!GREEDY_REALLOC0(n
, nlen
+ 2))
904 r
= extract_first_word_and_warn(&p
, &word
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
908 return ignore
? 0 : -ENOEXEC
;
910 r
= unit_path_printf(u
, word
, &resolved
);
912 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
913 "Failed to resolve unit specifiers in %s%s: %m",
914 word
, ignore
? ", ignoring" : "");
915 return ignore
? 0 : -ENOEXEC
;
918 if (!GREEDY_REALLOC(n
, nlen
+ 2))
921 n
[nlen
++] = TAKE_PTR(resolved
);
926 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
927 "Empty executable name or zeroeth argument%s: %s",
928 ignore
? ", ignoring" : "", rvalue
);
929 return ignore
? 0 : -ENOEXEC
;
932 nce
= new0(ExecCommand
, 1);
936 nce
->argv
= TAKE_PTR(n
);
937 nce
->path
= TAKE_PTR(path
);
940 exec_command_append_list(e
, nce
);
942 /* Do not _cleanup_free_ these. */
951 int config_parse_socket_bindtodevice(
953 const char *filename
,
956 unsigned section_line
,
970 if (isempty(rvalue
) || streq(rvalue
, "*")) {
971 s
->bind_to_device
= mfree(s
->bind_to_device
);
975 if (!ifname_valid(rvalue
)) {
976 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid interface name, ignoring: %s", rvalue
);
980 return free_and_strdup_warn(&s
->bind_to_device
, rvalue
);
983 int config_parse_exec_input(
985 const char *filename
,
988 unsigned section_line
,
995 ExecContext
*c
= data
;
996 const Unit
*u
= userdata
;
1006 n
= startswith(rvalue
, "fd:");
1008 _cleanup_free_
char *resolved
= NULL
;
1010 r
= unit_fd_printf(u
, n
, &resolved
);
1012 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", n
);
1016 if (isempty(resolved
))
1017 resolved
= mfree(resolved
);
1018 else if (!fdname_is_valid(resolved
)) {
1019 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", resolved
);
1023 free_and_replace(c
->stdio_fdname
[STDIN_FILENO
], resolved
);
1025 ei
= EXEC_INPUT_NAMED_FD
;
1027 } else if ((n
= startswith(rvalue
, "file:"))) {
1028 _cleanup_free_
char *resolved
= NULL
;
1030 r
= unit_path_printf(u
, n
, &resolved
);
1032 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", n
);
1036 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1040 free_and_replace(c
->stdio_file
[STDIN_FILENO
], resolved
);
1042 ei
= EXEC_INPUT_FILE
;
1045 ei
= exec_input_from_string(rvalue
);
1047 log_syntax(unit
, LOG_WARNING
, filename
, line
, ei
, "Failed to parse input specifier, ignoring: %s", rvalue
);
1056 int config_parse_exec_input_text(
1058 const char *filename
,
1060 const char *section
,
1061 unsigned section_line
,
1068 _cleanup_free_
char *unescaped
= NULL
, *resolved
= NULL
;
1069 ExecContext
*c
= data
;
1070 const Unit
*u
= userdata
;
1078 if (isempty(rvalue
)) {
1079 /* Reset if the empty string is assigned */
1080 c
->stdin_data
= mfree(c
->stdin_data
);
1081 c
->stdin_data_size
= 0;
1085 ssize_t l
= cunescape(rvalue
, 0, &unescaped
);
1087 log_syntax(unit
, LOG_WARNING
, filename
, line
, l
,
1088 "Failed to decode C escaped text '%s', ignoring: %m", rvalue
);
1092 r
= unit_full_printf_full(u
, unescaped
, EXEC_STDIN_DATA_MAX
, &resolved
);
1094 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1095 "Failed to resolve unit specifiers in '%s', ignoring: %m", unescaped
);
1099 size_t sz
= strlen(resolved
);
1100 if (c
->stdin_data_size
+ sz
+ 1 < c
->stdin_data_size
|| /* check for overflow */
1101 c
->stdin_data_size
+ sz
+ 1 > EXEC_STDIN_DATA_MAX
) {
1102 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
1103 "Standard input data too large (%zu), maximum of %zu permitted, ignoring.",
1104 c
->stdin_data_size
+ sz
, (size_t) EXEC_STDIN_DATA_MAX
);
1108 void *p
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
+ 1);
1112 *((char*) mempcpy((char*) p
+ c
->stdin_data_size
, resolved
, sz
)) = '\n';
1115 c
->stdin_data_size
+= sz
+ 1;
1120 int config_parse_exec_input_data(
1122 const char *filename
,
1124 const char *section
,
1125 unsigned section_line
,
1132 _cleanup_free_
void *p
= NULL
;
1133 ExecContext
*c
= data
;
1143 if (isempty(rvalue
)) {
1144 /* Reset if the empty string is assigned */
1145 c
->stdin_data
= mfree(c
->stdin_data
);
1146 c
->stdin_data_size
= 0;
1150 r
= unbase64mem(rvalue
, SIZE_MAX
, &p
, &sz
);
1152 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1153 "Failed to decode base64 data, ignoring: %s", rvalue
);
1159 if (c
->stdin_data_size
+ sz
< c
->stdin_data_size
|| /* check for overflow */
1160 c
->stdin_data_size
+ sz
> EXEC_STDIN_DATA_MAX
) {
1161 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
1162 "Standard input data too large (%zu), maximum of %zu permitted, ignoring.",
1163 c
->stdin_data_size
+ sz
, (size_t) EXEC_STDIN_DATA_MAX
);
1167 q
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
);
1171 memcpy((uint8_t*) q
+ c
->stdin_data_size
, p
, sz
);
1174 c
->stdin_data_size
+= sz
;
1179 int config_parse_exec_output(
1181 const char *filename
,
1183 const char *section
,
1184 unsigned section_line
,
1191 _cleanup_free_
char *resolved
= NULL
;
1193 ExecContext
*c
= data
;
1194 const Unit
*u
= userdata
;
1195 bool obsolete
= false;
1205 n
= startswith(rvalue
, "fd:");
1207 r
= unit_fd_printf(u
, n
, &resolved
);
1209 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", n
);
1213 if (isempty(resolved
))
1214 resolved
= mfree(resolved
);
1215 else if (!fdname_is_valid(resolved
)) {
1216 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", resolved
);
1220 eo
= EXEC_OUTPUT_NAMED_FD
;
1222 } else if (streq(rvalue
, "syslog")) {
1223 eo
= EXEC_OUTPUT_JOURNAL
;
1226 } else if (streq(rvalue
, "syslog+console")) {
1227 eo
= EXEC_OUTPUT_JOURNAL_AND_CONSOLE
;
1230 } else if ((n
= startswith(rvalue
, "file:"))) {
1232 r
= unit_path_printf(u
, n
, &resolved
);
1234 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", n
);
1238 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1242 eo
= EXEC_OUTPUT_FILE
;
1244 } else if ((n
= startswith(rvalue
, "append:"))) {
1246 r
= unit_path_printf(u
, n
, &resolved
);
1248 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", n
);
1252 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1256 eo
= EXEC_OUTPUT_FILE_APPEND
;
1258 } else if ((n
= startswith(rvalue
, "truncate:"))) {
1260 r
= unit_path_printf(u
, n
, &resolved
);
1262 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", n
);
1266 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1270 eo
= EXEC_OUTPUT_FILE_TRUNCATE
;
1272 eo
= exec_output_from_string(rvalue
);
1274 log_syntax(unit
, LOG_WARNING
, filename
, line
, eo
, "Failed to parse output specifier, ignoring: %s", rvalue
);
1280 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
1281 "Standard output type %s is obsolete, automatically updating to %s. Please update your unit file, and consider removing the setting altogether.",
1282 rvalue
, exec_output_to_string(eo
));
1284 if (streq(lvalue
, "StandardOutput")) {
1285 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1286 free_and_replace(c
->stdio_fdname
[STDOUT_FILENO
], resolved
);
1288 free_and_replace(c
->stdio_file
[STDOUT_FILENO
], resolved
);
1293 assert(streq(lvalue
, "StandardError"));
1295 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1296 free_and_replace(c
->stdio_fdname
[STDERR_FILENO
], resolved
);
1298 free_and_replace(c
->stdio_file
[STDERR_FILENO
], resolved
);
1306 int config_parse_exec_io_class(const char *unit
,
1307 const char *filename
,
1309 const char *section
,
1310 unsigned section_line
,
1317 ExecContext
*c
= data
;
1325 if (isempty(rvalue
)) {
1326 c
->ioprio_set
= false;
1327 c
->ioprio
= ioprio_prio_value(IOPRIO_CLASS_BE
, 0);
1331 x
= ioprio_class_from_string(rvalue
);
1333 log_syntax(unit
, LOG_WARNING
, filename
, line
, x
, "Failed to parse IO scheduling class, ignoring: %s", rvalue
);
1337 c
->ioprio
= ioprio_prio_value(x
, ioprio_prio_data(c
->ioprio
));
1338 c
->ioprio_set
= true;
1343 int config_parse_exec_io_priority(const char *unit
,
1344 const char *filename
,
1346 const char *section
,
1347 unsigned section_line
,
1354 ExecContext
*c
= data
;
1362 if (isempty(rvalue
)) {
1363 c
->ioprio_set
= false;
1364 c
->ioprio
= ioprio_prio_value(IOPRIO_CLASS_BE
, 0);
1368 r
= ioprio_parse_priority(rvalue
, &i
);
1370 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse IO priority, ignoring: %s", rvalue
);
1374 c
->ioprio
= ioprio_prio_value(ioprio_prio_class(c
->ioprio
), i
);
1375 c
->ioprio_set
= true;
1380 int config_parse_exec_cpu_sched_policy(const char *unit
,
1381 const char *filename
,
1383 const char *section
,
1384 unsigned section_line
,
1391 ExecContext
*c
= data
;
1399 if (isempty(rvalue
)) {
1400 c
->cpu_sched_set
= false;
1401 c
->cpu_sched_policy
= SCHED_OTHER
;
1402 c
->cpu_sched_priority
= 0;
1406 x
= sched_policy_from_string(rvalue
);
1408 log_syntax(unit
, LOG_WARNING
, filename
, line
, x
, "Failed to parse CPU scheduling policy, ignoring: %s", rvalue
);
1412 c
->cpu_sched_policy
= x
;
1413 /* Moving to or from real-time policy? We need to adjust the priority */
1414 c
->cpu_sched_priority
= CLAMP(c
->cpu_sched_priority
, sched_get_priority_min(x
), sched_get_priority_max(x
));
1415 c
->cpu_sched_set
= true;
1420 int config_parse_exec_mount_apivfs(const char *unit
,
1421 const char *filename
,
1423 const char *section
,
1424 unsigned section_line
,
1431 ExecContext
*c
= data
;
1439 if (isempty(rvalue
)) {
1440 c
->mount_apivfs_set
= false;
1441 c
->mount_apivfs
= false;
1445 k
= parse_boolean(rvalue
);
1447 log_syntax(unit
, LOG_WARNING
, filename
, line
, k
,
1448 "Failed to parse boolean value, ignoring: %s",
1453 c
->mount_apivfs_set
= true;
1454 c
->mount_apivfs
= k
;
1458 int config_parse_numa_mask(const char *unit
,
1459 const char *filename
,
1461 const char *section
,
1462 unsigned section_line
,
1469 NUMAPolicy
*p
= data
;
1476 if (streq(rvalue
, "all")) {
1477 r
= numa_mask_add_all(&p
->nodes
);
1479 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1480 "Failed to create NUMA mask representing \"all\" NUMA nodes, ignoring: %m");
1482 r
= parse_cpu_set_extend(rvalue
, &p
->nodes
, true, unit
, filename
, line
, lvalue
);
1484 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse NUMA node mask, ignoring: %s", rvalue
);
1490 int config_parse_exec_cpu_sched_prio(const char *unit
,
1491 const char *filename
,
1493 const char *section
,
1494 unsigned section_line
,
1501 ExecContext
*c
= data
;
1509 r
= safe_atoi(rvalue
, &i
);
1511 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse CPU scheduling priority, ignoring: %s", rvalue
);
1515 /* On Linux RR/FIFO range from 1 to 99 and OTHER/BATCH may only be 0 */
1516 min
= sched_get_priority_min(c
->cpu_sched_policy
);
1517 max
= sched_get_priority_max(c
->cpu_sched_policy
);
1519 if (i
< min
|| i
> max
) {
1520 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "CPU scheduling priority is out of range, ignoring: %s", rvalue
);
1524 c
->cpu_sched_priority
= i
;
1525 c
->cpu_sched_set
= true;
1530 int config_parse_root_image_options(
1532 const char *filename
,
1534 const char *section
,
1535 unsigned section_line
,
1542 _cleanup_(mount_options_free_allp
) MountOptions
*options
= NULL
;
1543 _cleanup_strv_free_
char **l
= NULL
;
1544 char **first
= NULL
, **second
= NULL
;
1545 ExecContext
*c
= data
;
1546 const Unit
*u
= userdata
;
1554 if (isempty(rvalue
)) {
1555 c
->root_image_options
= mount_options_free_all(c
->root_image_options
);
1559 r
= strv_split_colon_pairs(&l
, rvalue
);
1563 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
1567 STRV_FOREACH_PAIR(first
, second
, l
) {
1568 MountOptions
*o
= NULL
;
1569 _cleanup_free_
char *mount_options_resolved
= NULL
;
1570 const char *mount_options
= NULL
, *partition
= "root";
1571 PartitionDesignator partition_designator
;
1573 /* Format is either 'root:foo' or 'foo' (root is implied) */
1574 if (!isempty(*second
)) {
1576 mount_options
= *second
;
1578 mount_options
= *first
;
1580 partition_designator
= partition_designator_from_string(partition
);
1581 if (partition_designator
< 0) {
1582 log_syntax(unit
, LOG_WARNING
, filename
, line
, partition_designator
,
1583 "Invalid partition name %s, ignoring", partition
);
1586 r
= unit_full_printf(u
, mount_options
, &mount_options_resolved
);
1588 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", mount_options
);
1592 o
= new(MountOptions
, 1);
1595 *o
= (MountOptions
) {
1596 .partition_designator
= partition_designator
,
1597 .options
= TAKE_PTR(mount_options_resolved
),
1599 LIST_APPEND(mount_options
, options
, TAKE_PTR(o
));
1602 /* empty spaces/separators only */
1603 if (LIST_IS_EMPTY(options
))
1604 c
->root_image_options
= mount_options_free_all(c
->root_image_options
);
1606 LIST_JOIN(mount_options
, c
->root_image_options
, options
);
1611 int config_parse_exec_root_hash(
1613 const char *filename
,
1615 const char *section
,
1616 unsigned section_line
,
1623 _cleanup_free_
void *roothash_decoded
= NULL
;
1624 ExecContext
*c
= data
;
1625 size_t roothash_decoded_size
= 0;
1633 if (isempty(rvalue
)) {
1634 /* Reset if the empty string is assigned */
1635 c
->root_hash_path
= mfree(c
->root_hash_path
);
1636 c
->root_hash
= mfree(c
->root_hash
);
1637 c
->root_hash_size
= 0;
1641 if (path_is_absolute(rvalue
)) {
1642 /* We have the path to a roothash to load and decode, eg: RootHash=/foo/bar.roothash */
1643 _cleanup_free_
char *p
= NULL
;
1649 free_and_replace(c
->root_hash_path
, p
);
1650 c
->root_hash
= mfree(c
->root_hash
);
1651 c
->root_hash_size
= 0;
1655 /* We have a roothash to decode, eg: RootHash=012345789abcdef */
1656 r
= unhexmem(rvalue
, strlen(rvalue
), &roothash_decoded
, &roothash_decoded_size
);
1658 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to decode RootHash=, ignoring: %s", rvalue
);
1661 if (roothash_decoded_size
< sizeof(sd_id128_t
)) {
1662 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "RootHash= is too short, ignoring: %s", rvalue
);
1666 free_and_replace(c
->root_hash
, roothash_decoded
);
1667 c
->root_hash_size
= roothash_decoded_size
;
1668 c
->root_hash_path
= mfree(c
->root_hash_path
);
1673 int config_parse_exec_root_hash_sig(
1675 const char *filename
,
1677 const char *section
,
1678 unsigned section_line
,
1685 _cleanup_free_
void *roothash_sig_decoded
= NULL
;
1687 ExecContext
*c
= data
;
1688 size_t roothash_sig_decoded_size
= 0;
1696 if (isempty(rvalue
)) {
1697 /* Reset if the empty string is assigned */
1698 c
->root_hash_sig_path
= mfree(c
->root_hash_sig_path
);
1699 c
->root_hash_sig
= mfree(c
->root_hash_sig
);
1700 c
->root_hash_sig_size
= 0;
1704 if (path_is_absolute(rvalue
)) {
1705 /* We have the path to a roothash signature to load and decode, eg: RootHashSignature=/foo/bar.roothash.p7s */
1706 _cleanup_free_
char *p
= NULL
;
1712 free_and_replace(c
->root_hash_sig_path
, p
);
1713 c
->root_hash_sig
= mfree(c
->root_hash_sig
);
1714 c
->root_hash_sig_size
= 0;
1718 if (!(value
= startswith(rvalue
, "base64:"))) {
1719 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
1720 "Failed to decode RootHashSignature=, not a path but doesn't start with 'base64:', ignoring: %s", rvalue
);
1724 /* We have a roothash signature to decode, eg: RootHashSignature=base64:012345789abcdef */
1725 r
= unbase64mem(value
, strlen(value
), &roothash_sig_decoded
, &roothash_sig_decoded_size
);
1727 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to decode RootHashSignature=, ignoring: %s", rvalue
);
1731 free_and_replace(c
->root_hash_sig
, roothash_sig_decoded
);
1732 c
->root_hash_sig_size
= roothash_sig_decoded_size
;
1733 c
->root_hash_sig_path
= mfree(c
->root_hash_sig_path
);
1738 int config_parse_exec_cpu_affinity(
1740 const char *filename
,
1742 const char *section
,
1743 unsigned section_line
,
1750 ExecContext
*c
= data
;
1751 const Unit
*u
= userdata
;
1752 _cleanup_free_
char *k
= NULL
;
1760 if (streq(rvalue
, "numa")) {
1761 c
->cpu_affinity_from_numa
= true;
1762 cpu_set_reset(&c
->cpu_set
);
1767 r
= unit_full_printf(u
, rvalue
, &k
);
1769 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1770 "Failed to resolve unit specifiers in '%s', ignoring: %m",
1775 r
= parse_cpu_set_extend(k
, &c
->cpu_set
, true, unit
, filename
, line
, lvalue
);
1777 c
->cpu_affinity_from_numa
= false;
1782 int config_parse_capability_set(
1784 const char *filename
,
1786 const char *section
,
1787 unsigned section_line
,
1794 uint64_t *capability_set
= data
;
1795 uint64_t sum
= 0, initial
= 0;
1796 bool invert
= false;
1804 if (rvalue
[0] == '~') {
1809 if (streq(lvalue
, "CapabilityBoundingSet"))
1810 initial
= CAP_ALL
; /* initialized to all bits on */
1811 /* else "AmbientCapabilities" initialized to all bits off */
1813 r
= capability_set_from_string(rvalue
, &sum
);
1815 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= specifier '%s', ignoring: %m", lvalue
, rvalue
);
1819 if (sum
== 0 || *capability_set
== initial
)
1820 /* "", "~" or uninitialized data -> replace */
1821 *capability_set
= invert
? ~sum
: sum
;
1823 /* previous data -> merge */
1825 *capability_set
&= ~sum
;
1827 *capability_set
|= sum
;
1833 int config_parse_exec_selinux_context(
1835 const char *filename
,
1837 const char *section
,
1838 unsigned section_line
,
1845 ExecContext
*c
= data
;
1846 const Unit
*u
= userdata
;
1856 if (isempty(rvalue
)) {
1857 c
->selinux_context
= mfree(c
->selinux_context
);
1858 c
->selinux_context_ignore
= false;
1862 if (rvalue
[0] == '-') {
1868 r
= unit_full_printf(u
, rvalue
, &k
);
1870 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
1871 "Failed to resolve unit specifiers in '%s'%s: %m",
1872 rvalue
, ignore
? ", ignoring" : "");
1873 return ignore
? 0 : -ENOEXEC
;
1876 free_and_replace(c
->selinux_context
, k
);
1877 c
->selinux_context_ignore
= ignore
;
1882 int config_parse_exec_apparmor_profile(
1884 const char *filename
,
1886 const char *section
,
1887 unsigned section_line
,
1894 ExecContext
*c
= data
;
1895 const Unit
*u
= userdata
;
1905 if (isempty(rvalue
)) {
1906 c
->apparmor_profile
= mfree(c
->apparmor_profile
);
1907 c
->apparmor_profile_ignore
= false;
1911 if (rvalue
[0] == '-') {
1917 r
= unit_full_printf(u
, rvalue
, &k
);
1919 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
1920 "Failed to resolve unit specifiers in '%s'%s: %m",
1921 rvalue
, ignore
? ", ignoring" : "");
1922 return ignore
? 0 : -ENOEXEC
;
1925 free_and_replace(c
->apparmor_profile
, k
);
1926 c
->apparmor_profile_ignore
= ignore
;
1931 int config_parse_exec_smack_process_label(
1933 const char *filename
,
1935 const char *section
,
1936 unsigned section_line
,
1943 ExecContext
*c
= data
;
1944 const Unit
*u
= userdata
;
1954 if (isempty(rvalue
)) {
1955 c
->smack_process_label
= mfree(c
->smack_process_label
);
1956 c
->smack_process_label_ignore
= false;
1960 if (rvalue
[0] == '-') {
1966 r
= unit_full_printf(u
, rvalue
, &k
);
1968 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
1969 "Failed to resolve unit specifiers in '%s'%s: %m",
1970 rvalue
, ignore
? ", ignoring" : "");
1971 return ignore
? 0 : -ENOEXEC
;
1974 free_and_replace(c
->smack_process_label
, k
);
1975 c
->smack_process_label_ignore
= ignore
;
1980 int config_parse_timer(
1982 const char *filename
,
1984 const char *section
,
1985 unsigned section_line
,
1992 _cleanup_(calendar_spec_freep
) CalendarSpec
*c
= NULL
;
1993 _cleanup_free_
char *k
= NULL
;
1994 const Unit
*u
= userdata
;
2005 if (isempty(rvalue
)) {
2006 /* Empty assignment resets list */
2007 timer_free_values(t
);
2011 r
= unit_full_printf(u
, rvalue
, &k
);
2013 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2017 if (ltype
== TIMER_CALENDAR
) {
2018 r
= calendar_spec_from_string(k
, &c
);
2020 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse calendar specification, ignoring: %s", k
);
2024 r
= parse_sec(k
, &usec
);
2026 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse timer value, ignoring: %s", k
);
2031 v
= new(TimerValue
, 1);
2038 .calendar_spec
= TAKE_PTR(c
),
2041 LIST_PREPEND(value
, t
->values
, v
);
2046 int config_parse_trigger_unit(
2048 const char *filename
,
2050 const char *section
,
2051 unsigned section_line
,
2058 _cleanup_free_
char *p
= NULL
;
2068 if (UNIT_TRIGGER(u
)) {
2069 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Multiple units to trigger specified, ignoring: %s", rvalue
);
2073 r
= unit_name_printf(u
, rvalue
, &p
);
2075 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2079 type
= unit_name_to_type(p
);
2081 log_syntax(unit
, LOG_WARNING
, filename
, line
, type
, "Unit type not valid, ignoring: %s", rvalue
);
2084 if (unit_has_name(u
, p
)) {
2085 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Units cannot trigger themselves, ignoring: %s", rvalue
);
2089 r
= unit_add_two_dependencies_by_name(u
, UNIT_BEFORE
, UNIT_TRIGGERS
, p
, true, UNIT_DEPENDENCY_FILE
);
2091 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add trigger on %s, ignoring: %m", p
);
2098 int config_parse_path_spec(const char *unit
,
2099 const char *filename
,
2101 const char *section
,
2102 unsigned section_line
,
2112 _cleanup_free_
char *k
= NULL
;
2120 if (isempty(rvalue
)) {
2121 /* Empty assignment clears list */
2126 b
= path_type_from_string(lvalue
);
2128 log_syntax(unit
, LOG_WARNING
, filename
, line
, b
, "Failed to parse path type, ignoring: %s", lvalue
);
2132 r
= unit_path_printf(UNIT(p
), rvalue
, &k
);
2134 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2138 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2142 s
= new0(PathSpec
, 1);
2147 s
->path
= TAKE_PTR(k
);
2151 LIST_PREPEND(spec
, p
->specs
, s
);
2156 int config_parse_socket_service(
2158 const char *filename
,
2160 const char *section
,
2161 unsigned section_line
,
2168 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
2169 _cleanup_free_
char *p
= NULL
;
2179 r
= unit_name_printf(UNIT(s
), rvalue
, &p
);
2181 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2185 if (!endswith(p
, ".service")) {
2186 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Unit must be of type service, ignoring: %s", rvalue
);
2190 r
= manager_load_unit(UNIT(s
)->manager
, p
, NULL
, &error
, &x
);
2192 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to load unit %s, ignoring: %s", rvalue
, bus_error_message(&error
, r
));
2196 unit_ref_set(&s
->service
, UNIT(s
), x
);
2201 int config_parse_fdname(
2203 const char *filename
,
2205 const char *section
,
2206 unsigned section_line
,
2213 _cleanup_free_
char *p
= NULL
;
2222 if (isempty(rvalue
)) {
2223 s
->fdname
= mfree(s
->fdname
);
2227 r
= unit_fd_printf(UNIT(s
), rvalue
, &p
);
2229 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2233 if (!fdname_is_valid(p
)) {
2234 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", p
);
2238 return free_and_replace(s
->fdname
, p
);
2241 int config_parse_service_sockets(
2243 const char *filename
,
2245 const char *section
,
2246 unsigned section_line
,
2261 for (const char *p
= rvalue
;;) {
2262 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2264 r
= extract_first_word(&p
, &word
, NULL
, 0);
2268 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Trailing garbage in sockets, ignoring: %s", rvalue
);
2274 r
= unit_name_printf(UNIT(s
), word
, &k
);
2276 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
2280 if (!endswith(k
, ".socket")) {
2281 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Unit must be of type socket, ignoring: %s", k
);
2285 r
= unit_add_two_dependencies_by_name(UNIT(s
), UNIT_WANTS
, UNIT_AFTER
, k
, true, UNIT_DEPENDENCY_FILE
);
2287 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
2289 r
= unit_add_dependency_by_name(UNIT(s
), UNIT_TRIGGERED_BY
, k
, true, UNIT_DEPENDENCY_FILE
);
2291 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
2295 int config_parse_bus_name(
2297 const char *filename
,
2299 const char *section
,
2300 unsigned section_line
,
2307 _cleanup_free_
char *k
= NULL
;
2308 const Unit
*u
= userdata
;
2316 r
= unit_full_printf_full(u
, rvalue
, SD_BUS_MAXIMUM_NAME_LENGTH
, &k
);
2318 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2322 if (!sd_bus_service_name_is_valid(k
)) {
2323 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid bus name, ignoring: %s", k
);
2327 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
2330 int config_parse_service_timeout(
2332 const char *filename
,
2334 const char *section
,
2335 unsigned section_line
,
2342 Service
*s
= userdata
;
2351 /* This is called for two cases: TimeoutSec= and TimeoutStartSec=. */
2353 /* Traditionally, these options accepted 0 to disable the timeouts. However, a timeout of 0 suggests it happens
2354 * immediately, hence fix this to become USEC_INFINITY instead. This is in-line with how we internally handle
2355 * all other timeouts. */
2356 r
= parse_sec_fix_0(rvalue
, &usec
);
2358 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
2362 s
->start_timeout_defined
= true;
2363 s
->timeout_start_usec
= usec
;
2365 if (streq(lvalue
, "TimeoutSec"))
2366 s
->timeout_stop_usec
= usec
;
2371 int config_parse_timeout_abort(
2373 const char *filename
,
2375 const char *section
,
2376 unsigned section_line
,
2391 /* Note: apart from setting the arg, this returns an extra bit of information in the return value. */
2393 if (isempty(rvalue
)) {
2395 return 0; /* "not set" */
2398 r
= parse_sec(rvalue
, ret
);
2400 return log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= setting, ignoring: %s", lvalue
, rvalue
);
2402 return 1; /* "set" */
2405 int config_parse_service_timeout_abort(
2407 const char *filename
,
2409 const char *section
,
2410 unsigned section_line
,
2417 Service
*s
= userdata
;
2422 r
= config_parse_timeout_abort(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
,
2423 &s
->timeout_abort_usec
, s
);
2425 s
->timeout_abort_set
= r
;
2429 int config_parse_sec_fix_0(
2431 const char *filename
,
2433 const char *section
,
2434 unsigned section_line
,
2441 usec_t
*usec
= data
;
2449 /* This is pretty much like config_parse_sec(), except that this treats a time of 0 as infinity, for
2450 * compatibility with older versions of systemd where 0 instead of infinity was used as indicator to turn off a
2453 r
= parse_sec_fix_0(rvalue
, usec
);
2455 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
2460 int config_parse_user_group_compat(
2462 const char *filename
,
2464 const char *section
,
2465 unsigned section_line
,
2472 _cleanup_free_
char *k
= NULL
;
2474 const Unit
*u
= userdata
;
2482 if (isempty(rvalue
)) {
2483 *user
= mfree(*user
);
2487 r
= unit_full_printf(u
, rvalue
, &k
);
2489 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", rvalue
);
2493 if (!valid_user_group_name(k
, VALID_USER_ALLOW_NUMERIC
|VALID_USER_RELAX
|VALID_USER_WARN
)) {
2494 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2498 if (strstr(lvalue
, "User") && streq(k
, NOBODY_USER_NAME
))
2499 log_struct(LOG_NOTICE
,
2500 "MESSAGE=%s:%u: Special user %s configured, this is not safe!", filename
, line
, k
,
2502 "MESSAGE_ID=" SD_MESSAGE_NOBODY_USER_UNSUITABLE_STR
,
2503 "OFFENDING_USER=%s", k
,
2504 "CONFIG_FILE=%s", filename
,
2505 "CONFIG_LINE=%u", line
);
2507 return free_and_replace(*user
, k
);
2510 int config_parse_user_group_strv_compat(
2512 const char *filename
,
2514 const char *section
,
2515 unsigned section_line
,
2522 char ***users
= data
;
2523 const Unit
*u
= userdata
;
2531 if (isempty(rvalue
)) {
2532 *users
= strv_free(*users
);
2536 for (const char *p
= rvalue
;;) {
2537 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2539 r
= extract_first_word(&p
, &word
, NULL
, 0);
2543 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax: %s", rvalue
);
2549 r
= unit_full_printf(u
, word
, &k
);
2551 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", word
);
2555 if (!valid_user_group_name(k
, VALID_USER_ALLOW_NUMERIC
|VALID_USER_RELAX
|VALID_USER_WARN
)) {
2556 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2560 r
= strv_push(users
, k
);
2568 int config_parse_working_directory(
2570 const char *filename
,
2572 const char *section
,
2573 unsigned section_line
,
2580 ExecContext
*c
= data
;
2581 const Unit
*u
= userdata
;
2591 if (isempty(rvalue
)) {
2592 c
->working_directory_home
= false;
2593 c
->working_directory
= mfree(c
->working_directory
);
2597 if (rvalue
[0] == '-') {
2603 if (streq(rvalue
, "~")) {
2604 c
->working_directory_home
= true;
2605 c
->working_directory
= mfree(c
->working_directory
);
2607 _cleanup_free_
char *k
= NULL
;
2609 r
= unit_path_printf(u
, rvalue
, &k
);
2611 log_syntax(unit
, missing_ok
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
2612 "Failed to resolve unit specifiers in working directory path '%s'%s: %m",
2613 rvalue
, missing_ok
? ", ignoring" : "");
2614 return missing_ok
? 0 : -ENOEXEC
;
2617 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
| (missing_ok
? 0 : PATH_CHECK_FATAL
), unit
, filename
, line
, lvalue
);
2619 return missing_ok
? 0 : -ENOEXEC
;
2621 c
->working_directory_home
= false;
2622 free_and_replace(c
->working_directory
, k
);
2625 c
->working_directory_missing_ok
= missing_ok
;
2629 int config_parse_unit_env_file(const char *unit
,
2630 const char *filename
,
2632 const char *section
,
2633 unsigned section_line
,
2641 const Unit
*u
= userdata
;
2642 _cleanup_free_
char *n
= NULL
;
2650 if (isempty(rvalue
)) {
2651 /* Empty assignment frees the list */
2652 *env
= strv_free(*env
);
2656 r
= unit_full_printf_full(u
, rvalue
, PATH_MAX
, &n
);
2658 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2662 r
= path_simplify_and_warn(n
[0] == '-' ? n
+ 1 : n
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2666 r
= strv_push(env
, n
);
2675 int config_parse_environ(
2677 const char *filename
,
2679 const char *section
,
2680 unsigned section_line
,
2687 const Unit
*u
= userdata
;
2696 if (isempty(rvalue
)) {
2697 /* Empty assignment resets the list */
2698 *env
= strv_free(*env
);
2702 for (const char *p
= rvalue
;; ) {
2703 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
2705 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2709 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2710 "Invalid syntax, ignoring: %s", rvalue
);
2717 r
= unit_env_printf(u
, word
, &resolved
);
2719 r
= specifier_printf(word
, sc_arg_max(), system_and_tmp_specifier_table
, NULL
, NULL
, &resolved
);
2721 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2722 "Failed to resolve specifiers in %s, ignoring: %m", word
);
2726 if (!env_assignment_is_valid(resolved
)) {
2727 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
2728 "Invalid environment assignment, ignoring: %s", resolved
);
2732 r
= strv_env_replace_consume(env
, TAKE_PTR(resolved
));
2734 return log_error_errno(r
, "Failed to update environment: %m");
2738 int config_parse_pass_environ(
2740 const char *filename
,
2742 const char *section
,
2743 unsigned section_line
,
2750 _cleanup_strv_free_
char **n
= NULL
;
2751 const Unit
*u
= userdata
;
2752 char*** passenv
= data
;
2761 if (isempty(rvalue
)) {
2762 /* Empty assignment resets the list */
2763 *passenv
= strv_free(*passenv
);
2767 for (const char *p
= rvalue
;;) {
2768 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2770 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
2774 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2775 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2782 r
= unit_env_printf(u
, word
, &k
);
2784 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2785 "Failed to resolve specifiers in %s, ignoring: %m", word
);
2791 if (!env_name_is_valid(k
)) {
2792 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
2793 "Invalid environment name for %s, ignoring: %s", lvalue
, k
);
2797 if (!GREEDY_REALLOC(n
, nlen
+ 2))
2800 n
[nlen
++] = TAKE_PTR(k
);
2805 r
= strv_extend_strv(passenv
, n
, true);
2813 int config_parse_unset_environ(
2815 const char *filename
,
2817 const char *section
,
2818 unsigned section_line
,
2825 _cleanup_strv_free_
char **n
= NULL
;
2826 char*** unsetenv
= data
;
2827 const Unit
*u
= userdata
;
2836 if (isempty(rvalue
)) {
2837 /* Empty assignment resets the list */
2838 *unsetenv
= strv_free(*unsetenv
);
2842 for (const char *p
= rvalue
;;) {
2843 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2845 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2849 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2850 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2857 r
= unit_env_printf(u
, word
, &k
);
2859 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2860 "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2866 if (!env_assignment_is_valid(k
) && !env_name_is_valid(k
)) {
2867 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
2868 "Invalid environment name or assignment %s, ignoring: %s", lvalue
, k
);
2872 if (!GREEDY_REALLOC(n
, nlen
+ 2))
2875 n
[nlen
++] = TAKE_PTR(k
);
2880 r
= strv_extend_strv(unsetenv
, n
, true);
2888 int config_parse_log_extra_fields(
2890 const char *filename
,
2892 const char *section
,
2893 unsigned section_line
,
2900 ExecContext
*c
= data
;
2901 const Unit
*u
= userdata
;
2909 if (isempty(rvalue
)) {
2910 exec_context_free_log_extra_fields(c
);
2914 for (const char *p
= rvalue
;;) {
2915 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2919 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2923 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
2929 r
= unit_full_printf(u
, word
, &k
);
2931 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2935 eq
= strchr(k
, '=');
2937 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Log field lacks '=' character, ignoring: %s", k
);
2941 if (!journal_field_valid(k
, eq
-k
, false)) {
2942 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Log field name is invalid, ignoring: %s", k
);
2946 t
= reallocarray(c
->log_extra_fields
, c
->n_log_extra_fields
+1, sizeof(struct iovec
));
2950 c
->log_extra_fields
= t
;
2951 c
->log_extra_fields
[c
->n_log_extra_fields
++] = IOVEC_MAKE_STRING(k
);
2957 int config_parse_log_namespace(
2959 const char *filename
,
2961 const char *section
,
2962 unsigned section_line
,
2969 _cleanup_free_
char *k
= NULL
;
2970 ExecContext
*c
= data
;
2971 const Unit
*u
= userdata
;
2979 if (isempty(rvalue
)) {
2980 c
->log_namespace
= mfree(c
->log_namespace
);
2984 r
= unit_full_printf_full(u
, rvalue
, NAME_MAX
, &k
);
2986 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2990 if (!log_namespace_name_valid(k
)) {
2991 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Specified log namespace name is not valid, ignoring: %s", k
);
2995 free_and_replace(c
->log_namespace
, k
);
2999 int config_parse_unit_condition_path(
3001 const char *filename
,
3003 const char *section
,
3004 unsigned section_line
,
3011 _cleanup_free_
char *p
= NULL
;
3012 Condition
**list
= data
, *c
;
3013 ConditionType t
= ltype
;
3014 bool trigger
, negate
;
3015 const Unit
*u
= userdata
;
3023 if (isempty(rvalue
)) {
3024 /* Empty assignment resets the list */
3025 *list
= condition_free_list(*list
);
3029 trigger
= rvalue
[0] == '|';
3033 negate
= rvalue
[0] == '!';
3037 r
= unit_path_printf(u
, rvalue
, &p
);
3039 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
3043 r
= path_simplify_and_warn(p
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
3047 c
= condition_new(t
, p
, trigger
, negate
);
3051 LIST_PREPEND(conditions
, *list
, c
);
3055 int config_parse_unit_condition_string(
3057 const char *filename
,
3059 const char *section
,
3060 unsigned section_line
,
3067 _cleanup_free_
char *s
= NULL
;
3068 Condition
**list
= data
, *c
;
3069 ConditionType t
= ltype
;
3070 bool trigger
, negate
;
3071 const Unit
*u
= userdata
;
3079 if (isempty(rvalue
)) {
3080 /* Empty assignment resets the list */
3081 *list
= condition_free_list(*list
);
3085 trigger
= *rvalue
== '|';
3087 rvalue
+= 1 + strspn(rvalue
+ 1, WHITESPACE
);
3089 negate
= *rvalue
== '!';
3091 rvalue
+= 1 + strspn(rvalue
+ 1, WHITESPACE
);
3093 r
= unit_full_printf(u
, rvalue
, &s
);
3095 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3096 "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
3100 c
= condition_new(t
, s
, trigger
, negate
);
3104 LIST_PREPEND(conditions
, *list
, c
);
3108 int config_parse_unit_requires_mounts_for(
3110 const char *filename
,
3112 const char *section
,
3113 unsigned section_line
,
3128 for (const char *p
= rvalue
;;) {
3129 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
3131 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3135 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3136 "Invalid syntax, ignoring: %s", rvalue
);
3142 r
= unit_path_printf(u
, word
, &resolved
);
3144 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
3148 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
3152 r
= unit_require_mounts_for(u
, resolved
, UNIT_DEPENDENCY_FILE
);
3154 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add required mount '%s', ignoring: %m", resolved
);
3160 int config_parse_documentation(
3162 const char *filename
,
3164 const char *section
,
3165 unsigned section_line
,
3181 if (isempty(rvalue
)) {
3182 /* Empty assignment resets the list */
3183 u
->documentation
= strv_free(u
->documentation
);
3187 r
= config_parse_unit_strv_printf(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
,
3188 rvalue
, data
, userdata
);
3192 for (a
= b
= u
->documentation
; a
&& *a
; a
++) {
3194 if (documentation_url_is_valid(*a
))
3197 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid URL, ignoring: %s", *a
);
3208 int config_parse_syscall_filter(
3210 const char *filename
,
3212 const char *section
,
3213 unsigned section_line
,
3220 ExecContext
*c
= data
;
3221 _unused_
const Unit
*u
= userdata
;
3222 bool invert
= false;
3230 if (isempty(rvalue
)) {
3231 /* Empty assignment resets the list */
3232 c
->syscall_filter
= hashmap_free(c
->syscall_filter
);
3233 c
->syscall_allow_list
= false;
3237 if (rvalue
[0] == '~') {
3242 if (!c
->syscall_filter
) {
3243 c
->syscall_filter
= hashmap_new(NULL
);
3244 if (!c
->syscall_filter
)
3248 /* Allow everything but the ones listed */
3249 c
->syscall_allow_list
= false;
3251 /* Allow nothing but the ones listed */
3252 c
->syscall_allow_list
= true;
3254 /* Accept default syscalls if we are on an allow_list */
3255 r
= seccomp_parse_syscall_filter(
3256 "@default", -1, c
->syscall_filter
,
3257 SECCOMP_PARSE_PERMISSIVE
|SECCOMP_PARSE_ALLOW_LIST
,
3265 for (const char *p
= rvalue
;;) {
3266 _cleanup_free_
char *word
= NULL
, *name
= NULL
;
3269 r
= extract_first_word(&p
, &word
, NULL
, 0);
3273 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3274 "Invalid syntax, ignoring: %s", rvalue
);
3280 r
= parse_syscall_and_errno(word
, &name
, &num
);
3282 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3283 "Failed to parse syscall:errno, ignoring: %s", word
);
3286 if (!invert
&& num
>= 0) {
3287 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3288 "Allow-listed system calls cannot take error number, ignoring: %s", word
);
3292 r
= seccomp_parse_syscall_filter(
3293 name
, num
, c
->syscall_filter
,
3294 SECCOMP_PARSE_LOG
|SECCOMP_PARSE_PERMISSIVE
|
3295 (invert
? SECCOMP_PARSE_INVERT
: 0)|
3296 (c
->syscall_allow_list
? SECCOMP_PARSE_ALLOW_LIST
: 0),
3297 unit
, filename
, line
);
3303 int config_parse_syscall_log(
3305 const char *filename
,
3307 const char *section
,
3308 unsigned section_line
,
3315 ExecContext
*c
= data
;
3316 _unused_
const Unit
*u
= userdata
;
3317 bool invert
= false;
3326 if (isempty(rvalue
)) {
3327 /* Empty assignment resets the list */
3328 c
->syscall_log
= hashmap_free(c
->syscall_log
);
3329 c
->syscall_log_allow_list
= false;
3333 if (rvalue
[0] == '~') {
3338 if (!c
->syscall_log
) {
3339 c
->syscall_log
= hashmap_new(NULL
);
3340 if (!c
->syscall_log
)
3344 /* Log everything but the ones listed */
3345 c
->syscall_log_allow_list
= false;
3347 /* Log nothing but the ones listed */
3348 c
->syscall_log_allow_list
= true;
3353 _cleanup_free_
char *word
= NULL
;
3355 r
= extract_first_word(&p
, &word
, NULL
, 0);
3359 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3365 r
= seccomp_parse_syscall_filter(
3366 word
, -1, c
->syscall_log
,
3367 SECCOMP_PARSE_LOG
|SECCOMP_PARSE_PERMISSIVE
|
3368 (invert
? SECCOMP_PARSE_INVERT
: 0)|
3369 (c
->syscall_log_allow_list
? SECCOMP_PARSE_ALLOW_LIST
: 0),
3370 unit
, filename
, line
);
3376 int config_parse_syscall_archs(
3378 const char *filename
,
3380 const char *section
,
3381 unsigned section_line
,
3391 if (isempty(rvalue
)) {
3392 *archs
= set_free(*archs
);
3396 for (const char *p
= rvalue
;;) {
3397 _cleanup_free_
char *word
= NULL
;
3400 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3404 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3405 "Invalid syntax, ignoring: %s", rvalue
);
3411 r
= seccomp_arch_from_string(word
, &a
);
3413 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3414 "Failed to parse system call architecture \"%s\", ignoring: %m", word
);
3418 r
= set_ensure_put(archs
, NULL
, UINT32_TO_PTR(a
+ 1));
3424 int config_parse_syscall_errno(
3426 const char *filename
,
3428 const char *section
,
3429 unsigned section_line
,
3436 ExecContext
*c
= data
;
3443 if (isempty(rvalue
) || streq(rvalue
, "kill")) {
3444 /* Empty assignment resets to KILL */
3445 c
->syscall_errno
= SECCOMP_ERROR_NUMBER_KILL
;
3449 e
= parse_errno(rvalue
);
3451 log_syntax(unit
, LOG_WARNING
, filename
, line
, e
, "Failed to parse error number, ignoring: %s", rvalue
);
3455 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid error number, ignoring: %s", rvalue
);
3459 c
->syscall_errno
= e
;
3463 int config_parse_address_families(
3465 const char *filename
,
3467 const char *section
,
3468 unsigned section_line
,
3475 ExecContext
*c
= data
;
3476 bool invert
= false;
3483 if (isempty(rvalue
)) {
3484 /* Empty assignment resets the list */
3485 c
->address_families
= set_free(c
->address_families
);
3486 c
->address_families_allow_list
= false;
3490 if (streq(rvalue
, "none")) {
3491 /* Forbid all address families. */
3492 c
->address_families
= set_free(c
->address_families
);
3493 c
->address_families_allow_list
= true;
3497 if (rvalue
[0] == '~') {
3502 if (!c
->address_families
) {
3503 c
->address_families
= set_new(NULL
);
3504 if (!c
->address_families
)
3507 c
->address_families_allow_list
= !invert
;
3510 for (const char *p
= rvalue
;;) {
3511 _cleanup_free_
char *word
= NULL
;
3514 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3518 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3519 "Invalid syntax, ignoring: %s", rvalue
);
3525 af
= af_from_name(word
);
3527 log_syntax(unit
, LOG_WARNING
, filename
, line
, af
,
3528 "Failed to parse address family, ignoring: %s", word
);
3532 /* If we previously wanted to forbid an address family and now
3533 * we want to allow it, then just remove it from the list.
3535 if (!invert
== c
->address_families_allow_list
) {
3536 r
= set_put(c
->address_families
, INT_TO_PTR(af
));
3540 set_remove(c
->address_families
, INT_TO_PTR(af
));
3544 int config_parse_restrict_namespaces(
3546 const char *filename
,
3548 const char *section
,
3549 unsigned section_line
,
3556 ExecContext
*c
= data
;
3557 unsigned long flags
;
3558 bool invert
= false;
3561 if (isempty(rvalue
)) {
3562 /* Reset to the default. */
3563 c
->restrict_namespaces
= NAMESPACE_FLAGS_INITIAL
;
3567 /* Boolean parameter ignores the previous settings */
3568 r
= parse_boolean(rvalue
);
3570 c
->restrict_namespaces
= 0;
3572 } else if (r
== 0) {
3573 c
->restrict_namespaces
= NAMESPACE_FLAGS_ALL
;
3577 if (rvalue
[0] == '~') {
3582 /* Not a boolean argument, in this case it's a list of namespace types. */
3583 r
= namespace_flags_from_string(rvalue
, &flags
);
3585 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse namespace type string, ignoring: %s", rvalue
);
3589 if (c
->restrict_namespaces
== NAMESPACE_FLAGS_INITIAL
)
3590 /* Initial assignment. Just set the value. */
3591 c
->restrict_namespaces
= invert
? (~flags
) & NAMESPACE_FLAGS_ALL
: flags
;
3593 /* Merge the value with the previous one. */
3594 SET_FLAG(c
->restrict_namespaces
, flags
, !invert
);
3600 int config_parse_unit_slice(
3602 const char *filename
,
3604 const char *section
,
3605 unsigned section_line
,
3612 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
3613 _cleanup_free_
char *k
= NULL
;
3614 Unit
*u
= userdata
, *slice
;
3622 r
= unit_name_printf(u
, rvalue
, &k
);
3624 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
3628 r
= manager_load_unit(u
->manager
, k
, NULL
, &error
, &slice
);
3630 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to load slice unit %s, ignoring: %s", k
, bus_error_message(&error
, r
));
3634 r
= unit_set_slice(u
, slice
, UNIT_DEPENDENCY_FILE
);
3636 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to assign slice %s to unit %s, ignoring: %m", slice
->id
, u
->id
);
3643 int config_parse_cpu_quota(
3645 const char *filename
,
3647 const char *section
,
3648 unsigned section_line
,
3655 CGroupContext
*c
= data
;
3662 if (isempty(rvalue
)) {
3663 c
->cpu_quota_per_sec_usec
= USEC_INFINITY
;
3667 r
= parse_permyriad_unbounded(rvalue
);
3669 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid CPU quota '%s', ignoring.", rvalue
);
3673 c
->cpu_quota_per_sec_usec
= ((usec_t
) r
* USEC_PER_SEC
) / 10000U;
3677 int config_parse_allowed_cpuset(
3679 const char *filename
,
3681 const char *section
,
3682 unsigned section_line
,
3691 (void) parse_cpu_set_extend(rvalue
, c
, true, unit
, filename
, line
, lvalue
);
3695 int config_parse_memory_limit(
3697 const char *filename
,
3699 const char *section
,
3700 unsigned section_line
,
3707 CGroupContext
*c
= data
;
3708 uint64_t bytes
= CGROUP_LIMIT_MAX
;
3711 if (isempty(rvalue
) && STR_IN_SET(lvalue
, "DefaultMemoryLow",
3715 bytes
= CGROUP_LIMIT_MIN
;
3716 else if (!isempty(rvalue
) && !streq(rvalue
, "infinity")) {
3718 r
= parse_permyriad(rvalue
);
3720 r
= parse_size(rvalue
, 1024, &bytes
);
3722 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid memory limit '%s', ignoring: %m", rvalue
);
3726 bytes
= physical_memory_scale(r
, 10000U);
3728 if (bytes
>= UINT64_MAX
||
3729 (bytes
<= 0 && !STR_IN_SET(lvalue
, "MemorySwapMax", "MemoryLow", "MemoryMin", "DefaultMemoryLow", "DefaultMemoryMin"))) {
3730 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Memory limit '%s' out of range, ignoring.", rvalue
);
3735 if (streq(lvalue
, "DefaultMemoryLow")) {
3736 c
->default_memory_low
= bytes
;
3737 c
->default_memory_low_set
= true;
3738 } else if (streq(lvalue
, "DefaultMemoryMin")) {
3739 c
->default_memory_min
= bytes
;
3740 c
->default_memory_min_set
= true;
3741 } else if (streq(lvalue
, "MemoryMin")) {
3742 c
->memory_min
= bytes
;
3743 c
->memory_min_set
= true;
3744 } else if (streq(lvalue
, "MemoryLow")) {
3745 c
->memory_low
= bytes
;
3746 c
->memory_low_set
= true;
3747 } else if (streq(lvalue
, "MemoryHigh"))
3748 c
->memory_high
= bytes
;
3749 else if (streq(lvalue
, "MemoryMax"))
3750 c
->memory_max
= bytes
;
3751 else if (streq(lvalue
, "MemorySwapMax"))
3752 c
->memory_swap_max
= bytes
;
3753 else if (streq(lvalue
, "MemoryLimit"))
3754 c
->memory_limit
= bytes
;
3761 int config_parse_tasks_max(
3763 const char *filename
,
3765 const char *section
,
3766 unsigned section_line
,
3773 const Unit
*u
= userdata
;
3774 TasksMax
*tasks_max
= data
;
3778 if (isempty(rvalue
)) {
3779 *tasks_max
= u
? u
->manager
->default_tasks_max
: TASKS_MAX_UNSET
;
3783 if (streq(rvalue
, "infinity")) {
3784 *tasks_max
= TASKS_MAX_UNSET
;
3788 r
= parse_permyriad(rvalue
);
3790 *tasks_max
= (TasksMax
) { r
, 10000U }; /* r‱ */
3792 r
= safe_atou64(rvalue
, &v
);
3794 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid maximum tasks value '%s', ignoring: %m", rvalue
);
3798 if (v
<= 0 || v
>= UINT64_MAX
) {
3799 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Maximum tasks value '%s' out of range, ignoring.", rvalue
);
3803 *tasks_max
= (TasksMax
) { v
};
3809 int config_parse_delegate(
3811 const char *filename
,
3813 const char *section
,
3814 unsigned section_line
,
3821 CGroupContext
*c
= data
;
3825 t
= unit_name_to_type(unit
);
3826 assert(t
!= _UNIT_TYPE_INVALID
);
3828 if (!unit_vtable
[t
]->can_delegate
) {
3829 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Delegate= setting not supported for this unit type, ignoring.");
3833 /* We either accept a boolean value, which may be used to turn on delegation for all controllers, or turn it
3834 * off for all. Or it takes a list of controller names, in which case we add the specified controllers to the
3835 * mask to delegate. */
3837 if (isempty(rvalue
)) {
3838 /* An empty string resets controllers and set Delegate=yes. */
3840 c
->delegate_controllers
= 0;
3844 r
= parse_boolean(rvalue
);
3846 CGroupMask mask
= 0;
3848 for (const char *p
= rvalue
;;) {
3849 _cleanup_free_
char *word
= NULL
;
3850 CGroupController cc
;
3852 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3856 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3862 cc
= cgroup_controller_from_string(word
);
3864 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid controller name '%s', ignoring", word
);
3868 mask
|= CGROUP_CONTROLLER_TO_MASK(cc
);
3872 c
->delegate_controllers
|= mask
;
3876 c
->delegate_controllers
= _CGROUP_MASK_ALL
;
3878 c
->delegate
= false;
3879 c
->delegate_controllers
= 0;
3885 int config_parse_managed_oom_mode(
3887 const char *filename
,
3889 const char *section
,
3890 unsigned section_line
,
3897 ManagedOOMMode
*mode
= data
, m
;
3900 t
= unit_name_to_type(unit
);
3901 assert(t
!= _UNIT_TYPE_INVALID
);
3903 if (!unit_vtable
[t
]->can_set_managed_oom
)
3904 return log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "%s= is not supported for this unit type, ignoring.", lvalue
);
3906 if (isempty(rvalue
)) {
3907 *mode
= MANAGED_OOM_AUTO
;
3911 m
= managed_oom_mode_from_string(rvalue
);
3913 log_syntax(unit
, LOG_WARNING
, filename
, line
, m
, "Invalid syntax, ignoring: %s", rvalue
);
3921 int config_parse_managed_oom_mem_pressure_limit(
3923 const char *filename
,
3925 const char *section
,
3926 unsigned section_line
,
3933 uint32_t *limit
= data
;
3937 t
= unit_name_to_type(unit
);
3938 assert(t
!= _UNIT_TYPE_INVALID
);
3940 if (!unit_vtable
[t
]->can_set_managed_oom
)
3941 return log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "%s= is not supported for this unit type, ignoring.", lvalue
);
3943 if (isempty(rvalue
)) {
3948 r
= parse_permyriad(rvalue
);
3950 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse memory pressure limit value, ignoring: %s", rvalue
);
3954 /* Normalize to 2^32-1 == 100% */
3955 *limit
= UINT32_SCALE_FROM_PERMYRIAD(r
);
3959 int config_parse_device_allow(
3961 const char *filename
,
3963 const char *section
,
3964 unsigned section_line
,
3971 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3972 CGroupContext
*c
= data
;
3973 const char *p
= rvalue
;
3976 if (isempty(rvalue
)) {
3977 while (c
->device_allow
)
3978 cgroup_context_free_device_allow(c
, c
->device_allow
);
3983 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3987 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3988 "Failed to extract device path and rights from '%s', ignoring.", rvalue
);
3992 r
= unit_path_printf(userdata
, path
, &resolved
);
3994 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3995 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3999 if (!STARTSWITH_SET(resolved
, "block-", "char-")) {
4001 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4005 if (!valid_device_node_path(resolved
)) {
4006 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid device node path '%s', ignoring.", resolved
);
4011 if (!isempty(p
) && !in_charset(p
, "rwm")) {
4012 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid device rights '%s', ignoring.", p
);
4016 return cgroup_add_device_allow(c
, resolved
, p
);
4019 int config_parse_io_device_weight(
4021 const char *filename
,
4023 const char *section
,
4024 unsigned section_line
,
4031 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4032 CGroupIODeviceWeight
*w
;
4033 CGroupContext
*c
= data
;
4034 const char *p
= rvalue
;
4042 if (isempty(rvalue
)) {
4043 while (c
->io_device_weights
)
4044 cgroup_context_free_io_device_weight(c
, c
->io_device_weights
);
4049 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4052 if (r
<= 0 || isempty(p
)) {
4053 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4054 "Failed to extract device path and weight from '%s', ignoring.", rvalue
);
4058 r
= unit_path_printf(userdata
, path
, &resolved
);
4060 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4061 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4065 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4069 r
= cg_weight_parse(p
, &u
);
4071 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "IO weight '%s' invalid, ignoring: %m", p
);
4075 assert(u
!= CGROUP_WEIGHT_INVALID
);
4077 w
= new0(CGroupIODeviceWeight
, 1);
4081 w
->path
= TAKE_PTR(resolved
);
4084 LIST_PREPEND(device_weights
, c
->io_device_weights
, w
);
4088 int config_parse_io_device_latency(
4090 const char *filename
,
4092 const char *section
,
4093 unsigned section_line
,
4100 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4101 CGroupIODeviceLatency
*l
;
4102 CGroupContext
*c
= data
;
4103 const char *p
= rvalue
;
4111 if (isempty(rvalue
)) {
4112 while (c
->io_device_latencies
)
4113 cgroup_context_free_io_device_latency(c
, c
->io_device_latencies
);
4118 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4121 if (r
<= 0 || isempty(p
)) {
4122 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4123 "Failed to extract device path and latency from '%s', ignoring.", rvalue
);
4127 r
= unit_path_printf(userdata
, path
, &resolved
);
4129 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4130 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4134 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4138 r
= parse_sec(p
, &usec
);
4140 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse timer value, ignoring: %s", p
);
4144 l
= new0(CGroupIODeviceLatency
, 1);
4148 l
->path
= TAKE_PTR(resolved
);
4149 l
->target_usec
= usec
;
4151 LIST_PREPEND(device_latencies
, c
->io_device_latencies
, l
);
4155 int config_parse_io_limit(
4157 const char *filename
,
4159 const char *section
,
4160 unsigned section_line
,
4167 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4168 CGroupIODeviceLimit
*l
= NULL
, *t
;
4169 CGroupContext
*c
= data
;
4170 CGroupIOLimitType type
;
4171 const char *p
= rvalue
;
4179 type
= cgroup_io_limit_type_from_string(lvalue
);
4182 if (isempty(rvalue
)) {
4183 LIST_FOREACH(device_limits
, l
, c
->io_device_limits
)
4184 l
->limits
[type
] = cgroup_io_limit_defaults
[type
];
4188 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4191 if (r
<= 0 || isempty(p
)) {
4192 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4193 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
4197 r
= unit_path_printf(userdata
, path
, &resolved
);
4199 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4200 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4204 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4208 if (streq("infinity", p
))
4209 num
= CGROUP_LIMIT_MAX
;
4211 r
= parse_size(p
, 1000, &num
);
4212 if (r
< 0 || num
<= 0) {
4213 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid IO limit '%s', ignoring.", p
);
4218 LIST_FOREACH(device_limits
, t
, c
->io_device_limits
) {
4219 if (path_equal(resolved
, t
->path
)) {
4226 CGroupIOLimitType ttype
;
4228 l
= new0(CGroupIODeviceLimit
, 1);
4232 l
->path
= TAKE_PTR(resolved
);
4233 for (ttype
= 0; ttype
< _CGROUP_IO_LIMIT_TYPE_MAX
; ttype
++)
4234 l
->limits
[ttype
] = cgroup_io_limit_defaults
[ttype
];
4236 LIST_PREPEND(device_limits
, c
->io_device_limits
, l
);
4239 l
->limits
[type
] = num
;
4244 int config_parse_blockio_device_weight(
4246 const char *filename
,
4248 const char *section
,
4249 unsigned section_line
,
4256 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4257 CGroupBlockIODeviceWeight
*w
;
4258 CGroupContext
*c
= data
;
4259 const char *p
= rvalue
;
4267 if (isempty(rvalue
)) {
4268 while (c
->blockio_device_weights
)
4269 cgroup_context_free_blockio_device_weight(c
, c
->blockio_device_weights
);
4274 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4277 if (r
<= 0 || isempty(p
)) {
4278 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4279 "Failed to extract device node and weight from '%s', ignoring.", rvalue
);
4283 r
= unit_path_printf(userdata
, path
, &resolved
);
4285 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4286 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4290 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4294 r
= cg_blkio_weight_parse(p
, &u
);
4296 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid block IO weight '%s', ignoring: %m", p
);
4300 assert(u
!= CGROUP_BLKIO_WEIGHT_INVALID
);
4302 w
= new0(CGroupBlockIODeviceWeight
, 1);
4306 w
->path
= TAKE_PTR(resolved
);
4309 LIST_PREPEND(device_weights
, c
->blockio_device_weights
, w
);
4313 int config_parse_blockio_bandwidth(
4315 const char *filename
,
4317 const char *section
,
4318 unsigned section_line
,
4325 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4326 CGroupBlockIODeviceBandwidth
*b
= NULL
, *t
;
4327 CGroupContext
*c
= data
;
4328 const char *p
= rvalue
;
4337 read
= streq("BlockIOReadBandwidth", lvalue
);
4339 if (isempty(rvalue
)) {
4340 LIST_FOREACH(device_bandwidths
, b
, c
->blockio_device_bandwidths
) {
4341 b
->rbps
= CGROUP_LIMIT_MAX
;
4342 b
->wbps
= CGROUP_LIMIT_MAX
;
4347 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4350 if (r
<= 0 || isempty(p
)) {
4351 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4352 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
4356 r
= unit_path_printf(userdata
, path
, &resolved
);
4358 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4359 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4363 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4367 r
= parse_size(p
, 1000, &bytes
);
4368 if (r
< 0 || bytes
<= 0) {
4369 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid Block IO Bandwidth '%s', ignoring.", p
);
4373 LIST_FOREACH(device_bandwidths
, t
, c
->blockio_device_bandwidths
) {
4374 if (path_equal(resolved
, t
->path
)) {
4381 b
= new0(CGroupBlockIODeviceBandwidth
, 1);
4385 b
->path
= TAKE_PTR(resolved
);
4386 b
->rbps
= CGROUP_LIMIT_MAX
;
4387 b
->wbps
= CGROUP_LIMIT_MAX
;
4389 LIST_PREPEND(device_bandwidths
, c
->blockio_device_bandwidths
, b
);
4400 int config_parse_job_mode_isolate(
4402 const char *filename
,
4404 const char *section
,
4405 unsigned section_line
,
4419 r
= parse_boolean(rvalue
);
4421 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse boolean, ignoring: %s", rvalue
);
4425 log_notice("%s is deprecated. Please use OnFailureJobMode= instead", lvalue
);
4427 *m
= r
? JOB_ISOLATE
: JOB_REPLACE
;
4431 int config_parse_exec_directories(
4433 const char *filename
,
4435 const char *section
,
4436 unsigned section_line
,
4444 const Unit
*u
= userdata
;
4452 if (isempty(rvalue
)) {
4453 /* Empty assignment resets the list */
4454 *rt
= strv_free(*rt
);
4458 for (const char *p
= rvalue
;;) {
4459 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
4461 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
4465 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4466 "Invalid syntax, ignoring: %s", rvalue
);
4472 r
= unit_path_printf(u
, word
, &k
);
4474 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4475 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
4479 r
= path_simplify_and_warn(k
, PATH_CHECK_RELATIVE
, unit
, filename
, line
, lvalue
);
4483 if (path_startswith(k
, "private")) {
4484 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4485 "%s= path can't be 'private', ignoring assignment: %s", lvalue
, word
);
4489 r
= strv_push(rt
, k
);
4496 int config_parse_set_credential(
4498 const char *filename
,
4500 const char *section
,
4501 unsigned section_line
,
4508 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
4509 _cleanup_free_
void *d
= NULL
;
4510 ExecContext
*context
= data
;
4511 ExecSetCredential
*old
;
4513 bool encrypted
= ltype
;
4514 const char *p
= rvalue
;
4523 if (isempty(rvalue
)) {
4524 /* Empty assignment resets the list */
4525 context
->set_credentials
= hashmap_free(context
->set_credentials
);
4529 r
= extract_first_word(&p
, &word
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4533 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
4537 r
= unit_cred_printf(u
, word
, &k
);
4539 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
4542 if (!credential_name_valid(k
)) {
4543 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Credential name \"%s\" not valid, ignoring.", k
);
4548 r
= unbase64mem_full(p
, SIZE_MAX
, true, &d
, &size
);
4550 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Encrypted credential data not valid Base64 data, ignoring.");
4557 /* We support escape codes here, so that users can insert trailing \n if they like */
4558 l
= cunescape(p
, UNESCAPE_ACCEPT_NUL
, &unescaped
);
4560 log_syntax(unit
, LOG_WARNING
, filename
, line
, l
, "Can't unescape \"%s\", ignoring: %m", p
);
4568 old
= hashmap_get(context
->set_credentials
, k
);
4570 free_and_replace(old
->data
, d
);
4572 old
->encrypted
= encrypted
;
4574 _cleanup_(exec_set_credential_freep
) ExecSetCredential
*sc
= NULL
;
4576 sc
= new(ExecSetCredential
, 1);
4580 *sc
= (ExecSetCredential
) {
4582 .data
= TAKE_PTR(d
),
4584 .encrypted
= encrypted
,
4587 r
= hashmap_ensure_put(&context
->set_credentials
, &exec_set_credential_hash_ops
, sc
->id
, sc
);
4591 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4592 "Duplicated credential value '%s', ignoring assignment: %s", sc
->id
, rvalue
);
4602 int config_parse_load_credential(
4604 const char *filename
,
4606 const char *section
,
4607 unsigned section_line
,
4614 _cleanup_free_
char *word
= NULL
, *k
= NULL
, *q
= NULL
;
4615 ExecContext
*context
= data
;
4616 ExecLoadCredential
*old
;
4617 bool encrypted
= ltype
;
4627 if (isempty(rvalue
)) {
4628 /* Empty assignment resets the list */
4629 context
->load_credentials
= hashmap_free(context
->load_credentials
);
4634 r
= extract_first_word(&p
, &word
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4638 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
4642 r
= unit_cred_printf(u
, word
, &k
);
4644 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
4647 if (!credential_name_valid(k
)) {
4648 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Credential name \"%s\" not valid, ignoring.", k
);
4653 /* If only one field field is specified take it as shortcut for inheriting a credential named
4654 * the same way from our parent */
4659 r
= unit_path_printf(u
, p
, &q
);
4661 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", p
);
4664 if (path_is_absolute(q
) ? !path_is_normalized(q
) : !credential_name_valid(q
)) {
4665 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Credential source \"%s\" not valid, ignoring.", q
);
4670 old
= hashmap_get(context
->load_credentials
, k
);
4672 free_and_replace(old
->path
, q
);
4673 old
->encrypted
= encrypted
;
4675 _cleanup_(exec_load_credential_freep
) ExecLoadCredential
*lc
= NULL
;
4677 lc
= new(ExecLoadCredential
, 1);
4681 *lc
= (ExecLoadCredential
) {
4683 .path
= TAKE_PTR(q
),
4684 .encrypted
= encrypted
,
4687 r
= hashmap_ensure_put(&context
->load_credentials
, &exec_load_credential_hash_ops
, lc
->id
, lc
);
4691 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4692 "Duplicated credential value '%s', ignoring assignment: %s", lc
->id
, rvalue
);
4702 int config_parse_set_status(
4704 const char *filename
,
4706 const char *section
,
4707 unsigned section_line
,
4714 ExitStatusSet
*status_set
= data
;
4722 /* Empty assignment resets the list */
4723 if (isempty(rvalue
)) {
4724 exit_status_set_free(status_set
);
4728 for (const char *p
= rvalue
;;) {
4729 _cleanup_free_
char *word
= NULL
;
4732 r
= extract_first_word(&p
, &word
, NULL
, 0);
4736 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4737 "Failed to parse %s=%s, ignoring: %m", lvalue
, rvalue
);
4743 /* We need to call exit_status_from_string() first, because we want
4744 * to parse numbers as exit statuses, not signals. */
4746 r
= exit_status_from_string(word
);
4748 assert(r
>= 0 && r
< 256);
4749 bitmap
= &status_set
->status
;
4751 r
= signal_from_string(word
);
4753 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4754 "Failed to parse value, ignoring: %s", word
);
4757 bitmap
= &status_set
->signal
;
4760 r
= bitmap_set(bitmap
, r
);
4762 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4763 "Failed to set signal or status %s, ignoring: %m", word
);
4767 int config_parse_namespace_path_strv(
4769 const char *filename
,
4771 const char *section
,
4772 unsigned section_line
,
4779 const Unit
*u
= userdata
;
4788 if (isempty(rvalue
)) {
4789 /* Empty assignment resets the list */
4790 *sv
= strv_free(*sv
);
4794 for (const char *p
= rvalue
;;) {
4795 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
, *joined
= NULL
;
4797 bool ignore_enoent
= false, shall_prefix
= false;
4799 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
4803 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
4810 if (startswith(w
, "-")) {
4811 ignore_enoent
= true;
4814 if (startswith(w
, "+")) {
4815 shall_prefix
= true;
4819 r
= unit_path_printf(u
, w
, &resolved
);
4821 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", w
);
4825 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4829 joined
= strjoin(ignore_enoent
? "-" : "",
4830 shall_prefix
? "+" : "",
4833 r
= strv_push(sv
, joined
);
4843 int config_parse_temporary_filesystems(
4845 const char *filename
,
4847 const char *section
,
4848 unsigned section_line
,
4855 const Unit
*u
= userdata
;
4856 ExecContext
*c
= data
;
4864 if (isempty(rvalue
)) {
4865 /* Empty assignment resets the list */
4866 temporary_filesystem_free_many(c
->temporary_filesystems
, c
->n_temporary_filesystems
);
4867 c
->temporary_filesystems
= NULL
;
4868 c
->n_temporary_filesystems
= 0;
4872 for (const char *p
= rvalue
;;) {
4873 _cleanup_free_
char *word
= NULL
, *path
= NULL
, *resolved
= NULL
;
4876 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
4880 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
4887 r
= extract_first_word(&w
, &path
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4891 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", word
);
4895 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid syntax, ignoring: %s", word
);
4899 r
= unit_path_printf(u
, path
, &resolved
);
4901 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", path
);
4905 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4909 r
= temporary_filesystem_add(&c
->temporary_filesystems
, &c
->n_temporary_filesystems
, resolved
, w
);
4915 int config_parse_bind_paths(
4917 const char *filename
,
4919 const char *section
,
4920 unsigned section_line
,
4927 ExecContext
*c
= data
;
4928 const Unit
*u
= userdata
;
4936 if (isempty(rvalue
)) {
4937 /* Empty assignment resets the list */
4938 bind_mount_free_many(c
->bind_mounts
, c
->n_bind_mounts
);
4939 c
->bind_mounts
= NULL
;
4940 c
->n_bind_mounts
= 0;
4944 for (const char *p
= rvalue
;;) {
4945 _cleanup_free_
char *source
= NULL
, *destination
= NULL
;
4946 _cleanup_free_
char *sresolved
= NULL
, *dresolved
= NULL
;
4947 char *s
= NULL
, *d
= NULL
;
4948 bool rbind
= true, ignore_enoent
= false;
4950 r
= extract_first_word(&p
, &source
, ":" WHITESPACE
, EXTRACT_UNQUOTE
|EXTRACT_DONT_COALESCE_SEPARATORS
);
4954 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
4960 r
= unit_full_printf_full(u
, source
, PATH_MAX
, &sresolved
);
4962 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4963 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", source
);
4969 ignore_enoent
= true;
4973 r
= path_simplify_and_warn(s
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4977 /* Optionally, the destination is specified. */
4978 if (p
&& p
[-1] == ':') {
4979 r
= extract_first_word(&p
, &destination
, ":" WHITESPACE
, EXTRACT_UNQUOTE
|EXTRACT_DONT_COALESCE_SEPARATORS
);
4983 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
4987 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Missing argument after ':', ignoring: %s", s
);
4991 r
= unit_path_printf(u
, destination
, &dresolved
);
4993 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4994 "Failed to resolve specifiers in \"%s\", ignoring: %m", destination
);
4998 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5004 /* Optionally, there's also a short option string specified */
5005 if (p
&& p
[-1] == ':') {
5006 _cleanup_free_
char *options
= NULL
;
5008 r
= extract_first_word(&p
, &options
, NULL
, EXTRACT_UNQUOTE
);
5012 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s: %s", lvalue
, rvalue
);
5016 if (isempty(options
) || streq(options
, "rbind"))
5018 else if (streq(options
, "norbind"))
5021 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid option string, ignoring setting: %s", options
);
5028 r
= bind_mount_add(&c
->bind_mounts
, &c
->n_bind_mounts
,
5032 .read_only
= !!strstr(lvalue
, "ReadOnly"),
5034 .ignore_enoent
= ignore_enoent
,
5043 int config_parse_mount_images(
5045 const char *filename
,
5047 const char *section
,
5048 unsigned section_line
,
5055 ExecContext
*c
= data
;
5056 const Unit
*u
= userdata
;
5064 if (isempty(rvalue
)) {
5065 /* Empty assignment resets the list */
5066 c
->mount_images
= mount_image_free_many(c
->mount_images
, &c
->n_mount_images
);
5070 for (const char *p
= rvalue
;;) {
5071 _cleanup_(mount_options_free_allp
) MountOptions
*options
= NULL
;
5072 _cleanup_free_
char *first
= NULL
, *second
= NULL
, *tuple
= NULL
;
5073 _cleanup_free_
char *sresolved
= NULL
, *dresolved
= NULL
;
5074 const char *q
= NULL
;
5076 bool permissive
= false;
5078 r
= extract_first_word(&p
, &tuple
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_RETAIN_ESCAPE
);
5082 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5083 "Invalid syntax %s=%s, ignoring: %m", lvalue
, rvalue
);
5090 r
= extract_many_words(&q
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
, &first
, &second
, NULL
);
5094 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5095 "Invalid syntax in %s=, ignoring: %s", lvalue
, tuple
);
5107 r
= unit_path_printf(u
, s
, &sresolved
);
5109 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5110 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", s
);
5114 r
= path_simplify_and_warn(sresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5118 if (isempty(second
)) {
5119 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Missing destination in %s, ignoring: %s", lvalue
, rvalue
);
5123 r
= unit_path_printf(u
, second
, &dresolved
);
5125 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5126 "Failed to resolve specifiers in \"%s\", ignoring: %m", second
);
5130 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5135 _cleanup_free_
char *partition
= NULL
, *mount_options
= NULL
, *mount_options_resolved
= NULL
;
5136 MountOptions
*o
= NULL
;
5137 PartitionDesignator partition_designator
;
5139 r
= extract_many_words(&q
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
, &partition
, &mount_options
, NULL
);
5143 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", q
);
5148 /* Single set of options, applying to the root partition/single filesystem */
5150 r
= unit_full_printf(u
, partition
, &mount_options_resolved
);
5152 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", first
);
5156 o
= new(MountOptions
, 1);
5159 *o
= (MountOptions
) {
5160 .partition_designator
= PARTITION_ROOT
,
5161 .options
= TAKE_PTR(mount_options_resolved
),
5163 LIST_APPEND(mount_options
, options
, o
);
5168 partition_designator
= partition_designator_from_string(partition
);
5169 if (partition_designator
< 0) {
5170 log_syntax(unit
, LOG_WARNING
, filename
, line
, partition_designator
,
5171 "Invalid partition name %s, ignoring", partition
);
5174 r
= unit_full_printf(u
, mount_options
, &mount_options_resolved
);
5176 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", mount_options
);
5180 o
= new(MountOptions
, 1);
5183 *o
= (MountOptions
) {
5184 .partition_designator
= partition_designator
,
5185 .options
= TAKE_PTR(mount_options_resolved
),
5187 LIST_APPEND(mount_options
, options
, o
);
5190 r
= mount_image_add(&c
->mount_images
, &c
->n_mount_images
,
5192 .source
= sresolved
,
5193 .destination
= dresolved
,
5194 .mount_options
= options
,
5195 .ignore_enoent
= permissive
,
5196 .type
= MOUNT_IMAGE_DISCRETE
,
5203 int config_parse_extension_images(
5205 const char *filename
,
5207 const char *section
,
5208 unsigned section_line
,
5215 ExecContext
*c
= data
;
5216 const Unit
*u
= userdata
;
5224 if (isempty(rvalue
)) {
5225 /* Empty assignment resets the list */
5226 c
->extension_images
= mount_image_free_many(c
->extension_images
, &c
->n_extension_images
);
5230 for (const char *p
= rvalue
;;) {
5231 _cleanup_free_
char *source
= NULL
, *tuple
= NULL
, *sresolved
= NULL
;
5232 _cleanup_(mount_options_free_allp
) MountOptions
*options
= NULL
;
5233 bool permissive
= false;
5234 const char *q
= NULL
;
5237 r
= extract_first_word(&p
, &tuple
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_RETAIN_ESCAPE
);
5241 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5242 "Invalid syntax %s=%s, ignoring: %m", lvalue
, rvalue
);
5249 r
= extract_first_word(&q
, &source
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
);
5253 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5254 "Invalid syntax in %s=, ignoring: %s", lvalue
, tuple
);
5266 r
= unit_path_printf(u
, s
, &sresolved
);
5268 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5269 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", s
);
5273 r
= path_simplify_and_warn(sresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5278 _cleanup_free_
char *partition
= NULL
, *mount_options
= NULL
, *mount_options_resolved
= NULL
;
5279 MountOptions
*o
= NULL
;
5280 PartitionDesignator partition_designator
;
5282 r
= extract_many_words(&q
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
, &partition
, &mount_options
, NULL
);
5286 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", q
);
5291 /* Single set of options, applying to the root partition/single filesystem */
5293 r
= unit_full_printf(u
, partition
, &mount_options_resolved
);
5295 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", partition
);
5299 o
= new(MountOptions
, 1);
5302 *o
= (MountOptions
) {
5303 .partition_designator
= PARTITION_ROOT
,
5304 .options
= TAKE_PTR(mount_options_resolved
),
5306 LIST_APPEND(mount_options
, options
, o
);
5311 partition_designator
= partition_designator_from_string(partition
);
5312 if (partition_designator
< 0) {
5313 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid partition name %s, ignoring", partition
);
5316 r
= unit_full_printf(u
, mount_options
, &mount_options_resolved
);
5318 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", mount_options
);
5322 o
= new(MountOptions
, 1);
5325 *o
= (MountOptions
) {
5326 .partition_designator
= partition_designator
,
5327 .options
= TAKE_PTR(mount_options_resolved
),
5329 LIST_APPEND(mount_options
, options
, o
);
5332 r
= mount_image_add(&c
->extension_images
, &c
->n_extension_images
,
5334 .source
= sresolved
,
5335 .mount_options
= options
,
5336 .ignore_enoent
= permissive
,
5337 .type
= MOUNT_IMAGE_EXTENSION
,
5344 int config_parse_job_timeout_sec(
5346 const char *filename
,
5348 const char *section
,
5349 unsigned section_line
,
5365 r
= parse_sec_fix_0(rvalue
, &usec
);
5367 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse JobTimeoutSec= parameter, ignoring: %s", rvalue
);
5371 /* If the user explicitly changed JobTimeoutSec= also change JobRunningTimeoutSec=, for compatibility with old
5372 * versions. If JobRunningTimeoutSec= was explicitly set, avoid this however as whatever the user picked should
5375 if (!u
->job_running_timeout_set
)
5376 u
->job_running_timeout
= usec
;
5378 u
->job_timeout
= usec
;
5383 int config_parse_job_running_timeout_sec(
5385 const char *filename
,
5387 const char *section
,
5388 unsigned section_line
,
5404 r
= parse_sec_fix_0(rvalue
, &usec
);
5406 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse JobRunningTimeoutSec= parameter, ignoring: %s", rvalue
);
5410 u
->job_running_timeout
= usec
;
5411 u
->job_running_timeout_set
= true;
5416 int config_parse_emergency_action(
5418 const char *filename
,
5420 const char *section
,
5421 unsigned section_line
,
5429 EmergencyAction
*x
= data
;
5438 m
= ((Unit
*) userdata
)->manager
;
5442 r
= parse_emergency_action(rvalue
, MANAGER_IS_SYSTEM(m
), x
);
5444 if (r
== -EOPNOTSUPP
&& MANAGER_IS_USER(m
)) {
5445 /* Compat mode: remove for systemd 241. */
5447 log_syntax(unit
, LOG_INFO
, filename
, line
, r
,
5448 "%s= in user mode specified as \"%s\", using \"exit-force\" instead.",
5450 *x
= EMERGENCY_ACTION_EXIT_FORCE
;
5454 if (r
== -EOPNOTSUPP
)
5455 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5456 "%s= specified as %s mode action, ignoring: %s",
5457 lvalue
, MANAGER_IS_SYSTEM(m
) ? "user" : "system", rvalue
);
5459 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5460 "Failed to parse %s=, ignoring: %s", lvalue
, rvalue
);
5467 int config_parse_pid_file(
5469 const char *filename
,
5471 const char *section
,
5472 unsigned section_line
,
5479 _cleanup_free_
char *k
= NULL
, *n
= NULL
;
5480 const Unit
*u
= userdata
;
5489 if (isempty(rvalue
)) {
5490 /* An empty assignment removes already set value. */
5495 r
= unit_path_printf(u
, rvalue
, &k
);
5497 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
5501 /* If this is a relative path make it absolute by prefixing the /run */
5502 n
= path_make_absolute(k
, u
->manager
->prefix
[EXEC_DIRECTORY_RUNTIME
]);
5506 /* Check that the result is a sensible path */
5507 r
= path_simplify_and_warn(n
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5511 r
= patch_var_run(unit
, filename
, line
, lvalue
, &n
);
5515 free_and_replace(*s
, n
);
5519 int config_parse_exit_status(
5521 const char *filename
,
5523 const char *section
,
5524 unsigned section_line
,
5531 int *exit_status
= data
, r
;
5537 assert(exit_status
);
5539 if (isempty(rvalue
)) {
5544 r
= safe_atou8(rvalue
, &u
);
5546 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse exit status '%s', ignoring: %m", rvalue
);
5554 int config_parse_disable_controllers(
5556 const char *filename
,
5558 const char *section
,
5559 unsigned section_line
,
5567 CGroupContext
*c
= data
;
5568 CGroupMask disabled_mask
;
5570 /* 1. If empty, make all controllers eligible for use again.
5571 * 2. If non-empty, merge all listed controllers, space separated. */
5573 if (isempty(rvalue
)) {
5574 c
->disable_controllers
= 0;
5578 r
= cg_mask_from_string(rvalue
, &disabled_mask
);
5579 if (r
< 0 || disabled_mask
<= 0) {
5580 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid cgroup string: %s, ignoring", rvalue
);
5584 c
->disable_controllers
|= disabled_mask
;
5589 int config_parse_ip_filter_bpf_progs(
5591 const char *filename
,
5593 const char *section
,
5594 unsigned section_line
,
5601 _cleanup_free_
char *resolved
= NULL
;
5602 const Unit
*u
= userdata
;
5603 char ***paths
= data
;
5611 if (isempty(rvalue
)) {
5612 *paths
= strv_free(*paths
);
5616 r
= unit_path_printf(u
, rvalue
, &resolved
);
5618 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
5622 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5626 if (strv_contains(*paths
, resolved
))
5629 r
= strv_extend(paths
, resolved
);
5633 r
= bpf_firewall_supported();
5636 if (r
!= BPF_FIREWALL_SUPPORTED_WITH_MULTI
) {
5637 static bool warned
= false;
5639 log_full(warned
? LOG_DEBUG
: LOG_WARNING
,
5640 "File %s:%u configures an IP firewall with BPF programs (%s=%s), but the local system does not support BPF/cgroup based firewalling with multiple filters.\n"
5641 "Starting this unit will fail! (This warning is only shown for the first loaded unit using IP firewalling.)", filename
, line
, lvalue
, rvalue
);
5649 int config_parse_bpf_foreign_program(
5651 const char *filename
,
5653 const char *section
,
5654 unsigned section_line
,
5660 _cleanup_free_
char *resolved
= NULL
, *word
= NULL
;
5661 CGroupContext
*c
= data
;
5669 if (isempty(rvalue
)) {
5670 while (c
->bpf_foreign_programs
)
5671 cgroup_context_remove_bpf_foreign_program(c
, c
->bpf_foreign_programs
);
5676 r
= extract_first_word(&rvalue
, &word
, ":", 0);
5679 if (r
<= 0 || isempty(rvalue
)) {
5680 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse foreign BPF program, ignoring: %s", rvalue
);
5684 attach_type
= bpf_cgroup_attach_type_from_string(word
);
5685 if (attach_type
< 0) {
5686 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Unknown BPF attach type=%s, ignoring: %s", word
, rvalue
);
5690 r
= unit_path_printf(u
, rvalue
, &resolved
);
5692 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
5696 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5700 r
= cgroup_add_bpf_foreign_program(c
, attach_type
, resolved
);
5702 return log_error_errno(r
, "Failed to add foreign BPF program to cgroup context: %m");
5707 int config_parse_cgroup_socket_bind(
5709 const char *filename
,
5711 const char *section
,
5712 unsigned section_line
,
5718 _cleanup_free_ CGroupSocketBindItem
*item
= NULL
;
5719 CGroupSocketBindItem
**head
= data
;
5720 uint16_t nr_ports
, port_min
;
5721 int af
, ip_protocol
, r
;
5723 if (isempty(rvalue
)) {
5724 cgroup_context_remove_socket_bind(head
);
5728 r
= parse_socket_bind_item(rvalue
, &af
, &ip_protocol
, &nr_ports
, &port_min
);
5732 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5733 "Unable to parse %s= assignment, ignoring: %s", lvalue
, rvalue
);
5737 item
= new(CGroupSocketBindItem
, 1);
5740 *item
= (CGroupSocketBindItem
) {
5741 .address_family
= af
,
5742 .ip_protocol
= ip_protocol
,
5743 .nr_ports
= nr_ports
,
5744 .port_min
= port_min
,
5747 LIST_PREPEND(socket_bind_items
, *head
, TAKE_PTR(item
));
5752 int config_parse_restrict_network_interfaces(
5754 const char *filename
,
5756 const char *section
,
5757 unsigned section_line
,
5763 CGroupContext
*c
= data
;
5764 bool is_allow_rule
= true;
5772 if (isempty(rvalue
)) {
5773 /* Empty assignment resets the list */
5774 c
->restrict_network_interfaces
= set_free(c
->restrict_network_interfaces
);
5778 if (rvalue
[0] == '~') {
5779 is_allow_rule
= false;
5783 if (set_isempty(c
->restrict_network_interfaces
))
5784 /* Only initialize this when creating the set */
5785 c
->restrict_network_interfaces_is_allow_list
= is_allow_rule
;
5787 for (const char *p
= rvalue
;;) {
5788 _cleanup_free_
char *word
= NULL
;
5790 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
5796 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5797 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
5801 if (!ifname_valid(word
)) {
5802 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid interface name, ignoring: %s", word
);
5806 if (c
->restrict_network_interfaces_is_allow_list
!= is_allow_rule
)
5807 free(set_remove(c
->restrict_network_interfaces
, word
));
5809 r
= set_put_strdup(&c
->restrict_network_interfaces
, word
);
5818 static int merge_by_names(Unit
**u
, Set
*names
, const char *id
) {
5825 /* Let's try to add in all names that are aliases of this unit */
5826 while ((k
= set_steal_first(names
))) {
5827 _cleanup_free_ _unused_
char *free_k
= k
;
5829 /* First try to merge in the other name into our unit */
5830 r
= unit_merge_by_name(*u
, k
);
5834 /* Hmm, we couldn't merge the other unit into ours? Then let's try it the other way
5837 other
= manager_get_unit((*u
)->manager
, k
);
5839 return r
; /* return previous failure */
5841 r
= unit_merge(other
, *u
);
5846 return merge_by_names(u
, names
, NULL
);
5849 if (streq_ptr(id
, k
))
5850 unit_choose_id(*u
, id
);
5856 int unit_load_fragment(Unit
*u
) {
5857 const char *fragment
;
5858 _cleanup_set_free_free_ Set
*names
= NULL
;
5862 assert(u
->load_state
== UNIT_STUB
);
5866 u
->load_state
= UNIT_LOADED
;
5870 /* Possibly rebuild the fragment map to catch new units */
5871 r
= unit_file_build_name_map(&u
->manager
->lookup_paths
,
5872 &u
->manager
->unit_cache_timestamp_hash
,
5873 &u
->manager
->unit_id_map
,
5874 &u
->manager
->unit_name_map
,
5875 &u
->manager
->unit_path_cache
);
5877 return log_error_errno(r
, "Failed to rebuild name map: %m");
5879 r
= unit_file_find_fragment(u
->manager
->unit_id_map
,
5880 u
->manager
->unit_name_map
,
5884 if (r
< 0 && r
!= -ENOENT
)
5888 /* Open the file, check if this is a mask, otherwise read. */
5889 _cleanup_fclose_
FILE *f
= NULL
;
5892 /* Try to open the file name. A symlink is OK, for example for linked files or masks. We
5893 * expect that all symlinks within the lookup paths have been already resolved, but we don't
5894 * verify this here. */
5895 f
= fopen(fragment
, "re");
5897 return log_unit_notice_errno(u
, errno
, "Failed to open %s: %m", fragment
);
5899 if (fstat(fileno(f
), &st
) < 0)
5902 r
= free_and_strdup(&u
->fragment_path
, fragment
);
5906 if (null_or_empty(&st
)) {
5907 /* Unit file is masked */
5909 u
->load_state
= u
->perpetual
? UNIT_LOADED
: UNIT_MASKED
; /* don't allow perpetual units to ever be masked */
5910 u
->fragment_mtime
= 0;
5912 u
->load_state
= UNIT_LOADED
;
5913 u
->fragment_mtime
= timespec_load(&st
.st_mtim
);
5915 /* Now, parse the file contents */
5916 r
= config_parse(u
->id
, fragment
, f
,
5917 UNIT_VTABLE(u
)->sections
,
5918 config_item_perf_lookup
, load_fragment_gperf_lookup
,
5923 log_unit_notice_errno(u
, r
, "Unit configuration has fatal error, unit will not be started.");
5929 /* Call merge_by_names with the name derived from the fragment path as the preferred name.
5931 * We do the merge dance here because for some unit types, the unit might have aliases which are not
5932 * declared in the file system. In particular, this is true (and frequent) for device and swap units.
5934 const char *id
= u
->id
;
5935 _cleanup_free_
char *free_id
= NULL
;
5938 id
= basename(fragment
);
5939 if (unit_name_is_valid(id
, UNIT_NAME_TEMPLATE
)) {
5940 assert(u
->instance
); /* If we're not trying to use a template for non-instanced unit,
5941 * this must be set. */
5943 r
= unit_name_replace_instance(id
, u
->instance
, &free_id
);
5945 return log_debug_errno(r
, "Failed to build id (%s + %s): %m", id
, u
->instance
);
5951 r
= merge_by_names(&merged
, names
, id
);
5956 u
->load_state
= UNIT_MERGED
;
5961 void unit_dump_config_items(FILE *f
) {
5962 static const struct {
5963 const ConfigParserCallback callback
;
5966 { config_parse_warn_compat
, "NOTSUPPORTED" },
5967 { config_parse_int
, "INTEGER" },
5968 { config_parse_unsigned
, "UNSIGNED" },
5969 { config_parse_iec_size
, "SIZE" },
5970 { config_parse_iec_uint64
, "SIZE" },
5971 { config_parse_si_uint64
, "SIZE" },
5972 { config_parse_bool
, "BOOLEAN" },
5973 { config_parse_string
, "STRING" },
5974 { config_parse_path
, "PATH" },
5975 { config_parse_unit_path_printf
, "PATH" },
5976 { config_parse_colon_separated_paths
, "PATH" },
5977 { config_parse_strv
, "STRING [...]" },
5978 { config_parse_exec_nice
, "NICE" },
5979 { config_parse_exec_oom_score_adjust
, "OOMSCOREADJUST" },
5980 { config_parse_exec_io_class
, "IOCLASS" },
5981 { config_parse_exec_io_priority
, "IOPRIORITY" },
5982 { config_parse_exec_cpu_sched_policy
, "CPUSCHEDPOLICY" },
5983 { config_parse_exec_cpu_sched_prio
, "CPUSCHEDPRIO" },
5984 { config_parse_exec_cpu_affinity
, "CPUAFFINITY" },
5985 { config_parse_mode
, "MODE" },
5986 { config_parse_unit_env_file
, "FILE" },
5987 { config_parse_exec_output
, "OUTPUT" },
5988 { config_parse_exec_input
, "INPUT" },
5989 { config_parse_log_facility
, "FACILITY" },
5990 { config_parse_log_level
, "LEVEL" },
5991 { config_parse_exec_secure_bits
, "SECUREBITS" },
5992 { config_parse_capability_set
, "BOUNDINGSET" },
5993 { config_parse_rlimit
, "LIMIT" },
5994 { config_parse_unit_deps
, "UNIT [...]" },
5995 { config_parse_exec
, "PATH [ARGUMENT [...]]" },
5996 { config_parse_service_type
, "SERVICETYPE" },
5997 { config_parse_service_restart
, "SERVICERESTART" },
5998 { config_parse_service_timeout_failure_mode
, "TIMEOUTMODE" },
5999 { config_parse_kill_mode
, "KILLMODE" },
6000 { config_parse_signal
, "SIGNAL" },
6001 { config_parse_socket_listen
, "SOCKET [...]" },
6002 { config_parse_socket_bind
, "SOCKETBIND" },
6003 { config_parse_socket_bindtodevice
, "NETWORKINTERFACE" },
6004 { config_parse_sec
, "SECONDS" },
6005 { config_parse_nsec
, "NANOSECONDS" },
6006 { config_parse_namespace_path_strv
, "PATH [...]" },
6007 { config_parse_bind_paths
, "PATH[:PATH[:OPTIONS]] [...]" },
6008 { config_parse_unit_requires_mounts_for
, "PATH [...]" },
6009 { config_parse_exec_mount_flags
, "MOUNTFLAG [...]" },
6010 { config_parse_unit_string_printf
, "STRING" },
6011 { config_parse_trigger_unit
, "UNIT" },
6012 { config_parse_timer
, "TIMER" },
6013 { config_parse_path_spec
, "PATH" },
6014 { config_parse_notify_access
, "ACCESS" },
6015 { config_parse_ip_tos
, "TOS" },
6016 { config_parse_unit_condition_path
, "CONDITION" },
6017 { config_parse_unit_condition_string
, "CONDITION" },
6018 { config_parse_unit_slice
, "SLICE" },
6019 { config_parse_documentation
, "URL" },
6020 { config_parse_service_timeout
, "SECONDS" },
6021 { config_parse_emergency_action
, "ACTION" },
6022 { config_parse_set_status
, "STATUS" },
6023 { config_parse_service_sockets
, "SOCKETS" },
6024 { config_parse_environ
, "ENVIRON" },
6026 { config_parse_syscall_filter
, "SYSCALLS" },
6027 { config_parse_syscall_archs
, "ARCHS" },
6028 { config_parse_syscall_errno
, "ERRNO" },
6029 { config_parse_syscall_log
, "SYSCALLS" },
6030 { config_parse_address_families
, "FAMILIES" },
6031 { config_parse_restrict_namespaces
, "NAMESPACES" },
6033 { config_parse_cpu_shares
, "SHARES" },
6034 { config_parse_cg_weight
, "WEIGHT" },
6035 { config_parse_memory_limit
, "LIMIT" },
6036 { config_parse_device_allow
, "DEVICE" },
6037 { config_parse_device_policy
, "POLICY" },
6038 { config_parse_io_limit
, "LIMIT" },
6039 { config_parse_io_device_weight
, "DEVICEWEIGHT" },
6040 { config_parse_io_device_latency
, "DEVICELATENCY" },
6041 { config_parse_blockio_bandwidth
, "BANDWIDTH" },
6042 { config_parse_blockio_weight
, "WEIGHT" },
6043 { config_parse_blockio_device_weight
, "DEVICEWEIGHT" },
6044 { config_parse_long
, "LONG" },
6045 { config_parse_socket_service
, "SERVICE" },
6047 { config_parse_exec_selinux_context
, "LABEL" },
6049 { config_parse_job_mode
, "MODE" },
6050 { config_parse_job_mode_isolate
, "BOOLEAN" },
6051 { config_parse_personality
, "PERSONALITY" },
6054 const char *prev
= NULL
;
6059 NULSTR_FOREACH(i
, load_fragment_gperf_nulstr
) {
6060 const char *rvalue
= "OTHER", *lvalue
;
6061 const ConfigPerfItem
*p
;
6064 assert_se(p
= load_fragment_gperf_lookup(i
, strlen(i
)));
6066 /* Hide legacy settings */
6067 if (p
->parse
== config_parse_warn_compat
&&
6068 p
->ltype
== DISABLED_LEGACY
)
6071 for (size_t j
= 0; j
< ELEMENTSOF(table
); j
++)
6072 if (p
->parse
== table
[j
].callback
) {
6073 rvalue
= table
[j
].rvalue
;
6077 dot
= strchr(i
, '.');
6078 lvalue
= dot
? dot
+ 1 : i
;
6081 size_t prefix_len
= dot
- i
;
6083 if (!prev
|| !strneq(prev
, i
, prefix_len
+1)) {
6087 fprintf(f
, "[%.*s]\n", (int) prefix_len
, i
);
6091 fprintf(f
, "%s=%s\n", lvalue
, rvalue
);
6096 int config_parse_cpu_affinity2(
6098 const char *filename
,
6100 const char *section
,
6101 unsigned section_line
,
6108 CPUSet
*affinity
= data
;
6112 (void) parse_cpu_set_extend(rvalue
, affinity
, true, unit
, filename
, line
, lvalue
);
6117 int config_parse_show_status(
6119 const char *filename
,
6121 const char *section
,
6122 unsigned section_line
,
6130 ShowStatus
*b
= data
;
6137 k
= parse_show_status(rvalue
, b
);
6139 log_syntax(unit
, LOG_WARNING
, filename
, line
, k
, "Failed to parse show status setting, ignoring: %s", rvalue
);
6144 int config_parse_output_restricted(
6146 const char *filename
,
6148 const char *section
,
6149 unsigned section_line
,
6156 ExecOutput t
, *eo
= data
;
6157 bool obsolete
= false;
6164 if (streq(rvalue
, "syslog")) {
6165 t
= EXEC_OUTPUT_JOURNAL
;
6167 } else if (streq(rvalue
, "syslog+console")) {
6168 t
= EXEC_OUTPUT_JOURNAL_AND_CONSOLE
;
6171 t
= exec_output_from_string(rvalue
);
6173 log_syntax(unit
, LOG_WARNING
, filename
, line
, t
, "Failed to parse output type, ignoring: %s", rvalue
);
6177 if (IN_SET(t
, EXEC_OUTPUT_SOCKET
, EXEC_OUTPUT_NAMED_FD
, EXEC_OUTPUT_FILE
, EXEC_OUTPUT_FILE_APPEND
, EXEC_OUTPUT_FILE_TRUNCATE
)) {
6178 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Standard output types socket, fd:, file:, append:, truncate: are not supported as defaults, ignoring: %s", rvalue
);
6184 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
6185 "Standard output type %s is obsolete, automatically updating to %s. Please update your configuration.",
6186 rvalue
, exec_output_to_string(t
));
6192 int config_parse_crash_chvt(
6194 const char *filename
,
6196 const char *section
,
6197 unsigned section_line
,
6211 r
= parse_crash_chvt(rvalue
, data
);
6213 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse CrashChangeVT= setting, ignoring: %s", rvalue
);
6218 int config_parse_swap_priority(
6220 const char *filename
,
6222 const char *section
,
6223 unsigned section_line
,
6239 if (isempty(rvalue
)) {
6240 s
->parameters_fragment
.priority
= -1;
6241 s
->parameters_fragment
.priority_set
= false;
6245 r
= safe_atoi(rvalue
, &priority
);
6247 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid swap priority '%s', ignoring.", rvalue
);
6251 if (priority
< -1) {
6252 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Sorry, swap priorities smaller than -1 may only be assigned by the kernel itself, ignoring: %s", rvalue
);
6256 if (priority
> 32767) {
6257 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Swap priority out of range, ignoring: %s", rvalue
);
6261 s
->parameters_fragment
.priority
= priority
;
6262 s
->parameters_fragment
.priority_set
= true;