1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 Copyright © 2012 Holger Hans Peter Freyther
14 #include <sys/resource.h>
16 #include "sd-messages.h"
19 #include "alloc-util.h"
20 #include "all-units.h"
21 #include "bpf-firewall.h"
22 #include "bus-error.h"
23 #include "bus-internal.h"
26 #include "capability-util.h"
27 #include "cgroup-setup.h"
28 #include "conf-parser.h"
29 #include "cpu-set-util.h"
31 #include "errno-list.h"
36 #include "hexdecoct.h"
39 #include "ip-protocol-list.h"
40 #include "journal-util.h"
41 #include "limits-util.h"
42 #include "load-fragment.h"
44 #include "mountpoint-util.h"
45 #include "nulstr-util.h"
46 #include "parse-util.h"
47 #include "path-util.h"
48 #include "process-util.h"
50 #include "seccomp-util.h"
52 #include "securebits-util.h"
53 #include "signal-util.h"
54 #include "socket-netlink.h"
55 #include "stat-util.h"
56 #include "string-util.h"
58 #include "syslog-util.h"
59 #include "time-util.h"
60 #include "unit-name.h"
61 #include "unit-printf.h"
62 #include "user-util.h"
66 static int parse_socket_protocol(const char *s
) {
69 r
= parse_ip_protocol(s
);
72 if (!IN_SET(r
, IPPROTO_UDPLITE
, IPPROTO_SCTP
))
73 return -EPROTONOSUPPORT
;
78 int parse_crash_chvt(const char *value
, int *data
) {
81 if (safe_atoi(value
, data
) >= 0)
84 b
= parse_boolean(value
);
89 *data
= 0; /* switch to where kmsg goes */
91 *data
= -1; /* turn off switching */
96 int parse_confirm_spawn(const char *value
, char **console
) {
100 r
= value
? parse_boolean(value
) : 1;
104 } else if (r
> 0) /* on with default tty */
105 s
= strdup("/dev/console");
106 else if (is_path(value
)) /* on with fully qualified path */
108 else /* on with only a tty file name, not a fully qualified path */
109 s
= path_join("/dev/", value
);
117 DEFINE_CONFIG_PARSE(config_parse_socket_protocol
, parse_socket_protocol
, "Failed to parse socket protocol");
118 DEFINE_CONFIG_PARSE(config_parse_exec_secure_bits
, secure_bits_from_string
, "Failed to parse secure bits");
119 DEFINE_CONFIG_PARSE_ENUM(config_parse_collect_mode
, collect_mode
, CollectMode
, "Failed to parse garbage collection mode");
120 DEFINE_CONFIG_PARSE_ENUM(config_parse_device_policy
, cgroup_device_policy
, CGroupDevicePolicy
, "Failed to parse device policy");
121 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_keyring_mode
, exec_keyring_mode
, ExecKeyringMode
, "Failed to parse keyring mode");
122 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_proc
, protect_proc
, ProtectProc
, "Failed to parse /proc/ protection mode");
123 DEFINE_CONFIG_PARSE_ENUM(config_parse_proc_subset
, proc_subset
, ProcSubset
, "Failed to parse /proc/ subset mode");
124 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_utmp_mode
, exec_utmp_mode
, ExecUtmpMode
, "Failed to parse utmp mode");
125 DEFINE_CONFIG_PARSE_ENUM(config_parse_job_mode
, job_mode
, JobMode
, "Failed to parse job mode");
126 DEFINE_CONFIG_PARSE_ENUM(config_parse_notify_access
, notify_access
, NotifyAccess
, "Failed to parse notify access specifier");
127 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_home
, protect_home
, ProtectHome
, "Failed to parse protect home value");
128 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_system
, protect_system
, ProtectSystem
, "Failed to parse protect system value");
129 DEFINE_CONFIG_PARSE_ENUM(config_parse_runtime_preserve_mode
, exec_preserve_mode
, ExecPreserveMode
, "Failed to parse runtime directory preserve mode");
130 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_type
, service_type
, ServiceType
, "Failed to parse service type");
131 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart
, service_restart
, ServiceRestart
, "Failed to parse service restart specifier");
132 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_timeout_failure_mode
, service_timeout_failure_mode
, ServiceTimeoutFailureMode
, "Failed to parse timeout failure mode");
133 DEFINE_CONFIG_PARSE_ENUM(config_parse_socket_bind
, socket_address_bind_ipv6_only_or_bool
, SocketAddressBindIPv6Only
, "Failed to parse bind IPv6 only value");
134 DEFINE_CONFIG_PARSE_ENUM(config_parse_oom_policy
, oom_policy
, OOMPolicy
, "Failed to parse OOM policy");
135 DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_ip_tos
, ip_tos
, int, -1, "Failed to parse IP TOS value");
136 DEFINE_CONFIG_PARSE_PTR(config_parse_blockio_weight
, cg_blkio_weight_parse
, uint64_t, "Invalid block IO weight");
137 DEFINE_CONFIG_PARSE_PTR(config_parse_cg_weight
, cg_weight_parse
, uint64_t, "Invalid weight");
138 DEFINE_CONFIG_PARSE_PTR(config_parse_cpu_shares
, cg_cpu_shares_parse
, uint64_t, "Invalid CPU shares");
139 DEFINE_CONFIG_PARSE_PTR(config_parse_exec_mount_flags
, mount_propagation_flags_from_string
, unsigned long, "Failed to parse mount flag");
140 DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_numa_policy
, mpol
, int, -1, "Invalid NUMA policy type");
141 DEFINE_CONFIG_PARSE_ENUM(config_parse_status_unit_format
, status_unit_format
, StatusUnitFormat
, "Failed to parse status unit format");
143 int config_parse_unit_deps(
145 const char *filename
,
148 unsigned section_line
,
155 UnitDependency d
= ltype
;
162 for (const char *p
= rvalue
;;) {
163 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
166 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_RETAIN_ESCAPE
);
172 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
176 r
= unit_name_printf(u
, word
, &k
);
178 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
182 r
= unit_add_dependency_by_name(u
, d
, k
, true, UNIT_DEPENDENCY_FILE
);
184 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
188 int config_parse_obsolete_unit_deps(
190 const char *filename
,
193 unsigned section_line
,
200 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
201 "Unit dependency type %s= is obsolete, replacing by %s=, please update your unit file", lvalue
, unit_dependency_to_string(ltype
));
203 return config_parse_unit_deps(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
);
206 int config_parse_unit_string_printf(
208 const char *filename
,
211 unsigned section_line
,
218 _cleanup_free_
char *k
= NULL
;
219 const Unit
*u
= userdata
;
227 r
= unit_full_printf(u
, rvalue
, &k
);
229 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
233 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
236 int config_parse_unit_strv_printf(
238 const char *filename
,
241 unsigned section_line
,
248 const Unit
*u
= userdata
;
249 _cleanup_free_
char *k
= NULL
;
257 r
= unit_full_printf(u
, rvalue
, &k
);
259 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
263 return config_parse_strv(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
266 int config_parse_unit_path_printf(
268 const char *filename
,
271 unsigned section_line
,
278 _cleanup_free_
char *k
= NULL
;
279 const Unit
*u
= userdata
;
288 /* Let's not bother with anything that is too long */
289 if (strlen(rvalue
) >= PATH_MAX
) {
290 log_syntax(unit
, fatal
? LOG_ERR
: LOG_WARNING
, filename
, line
, 0,
291 "%s value too long%s.",
292 lvalue
, fatal
? "" : ", ignoring");
293 return fatal
? -ENAMETOOLONG
: 0;
296 r
= unit_full_printf(u
, rvalue
, &k
);
298 log_syntax(unit
, fatal
? LOG_ERR
: LOG_WARNING
, filename
, line
, r
,
299 "Failed to resolve unit specifiers in '%s'%s: %m",
300 rvalue
, fatal
? "" : ", ignoring");
301 return fatal
? -ENOEXEC
: 0;
304 return config_parse_path(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
307 int config_parse_unit_path_strv_printf(
309 const char *filename
,
312 unsigned section_line
,
320 const Unit
*u
= userdata
;
328 if (isempty(rvalue
)) {
333 for (const char *p
= rvalue
;;) {
334 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
336 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
342 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
343 "Invalid syntax, ignoring: %s", rvalue
);
347 r
= unit_full_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(x
, TAKE_PTR(k
));
364 static int patch_var_run(
366 const char *filename
,
374 e
= path_startswith(*path
, "/var/run/");
378 z
= path_join("/run/", e
);
382 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
383 "%s= references a path below legacy directory /var/run/, updating %s → %s; "
384 "please update the unit file accordingly.", lvalue
, *path
, z
);
386 free_and_replace(*path
, z
);
391 int config_parse_socket_listen(
393 const char *filename
,
396 unsigned section_line
,
403 _cleanup_free_ SocketPort
*p
= NULL
;
415 if (isempty(rvalue
)) {
416 /* An empty assignment removes all ports */
417 socket_free_ports(s
);
421 p
= new0(SocketPort
, 1);
425 if (ltype
!= SOCKET_SOCKET
) {
426 _cleanup_free_
char *k
= NULL
;
428 r
= unit_full_printf(UNIT(s
), rvalue
, &k
);
430 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
434 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
438 if (ltype
== SOCKET_FIFO
) {
439 r
= patch_var_run(unit
, filename
, line
, lvalue
, &k
);
444 free_and_replace(p
->path
, k
);
447 } else if (streq(lvalue
, "ListenNetlink")) {
448 _cleanup_free_
char *k
= NULL
;
450 r
= unit_full_printf(UNIT(s
), rvalue
, &k
);
452 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
456 r
= socket_address_parse_netlink(&p
->address
, k
);
458 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse address value in '%s', ignoring: %m", k
);
462 p
->type
= SOCKET_SOCKET
;
465 _cleanup_free_
char *k
= NULL
;
467 r
= unit_full_printf(UNIT(s
), rvalue
, &k
);
469 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
473 if (k
[0] == '/') { /* Only for AF_UNIX file system sockets… */
474 r
= patch_var_run(unit
, filename
, line
, lvalue
, &k
);
479 r
= socket_address_parse_and_warn(&p
->address
, k
);
481 if (r
!= -EAFNOSUPPORT
)
482 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse address value in '%s', ignoring: %m", k
);
486 if (streq(lvalue
, "ListenStream"))
487 p
->address
.type
= SOCK_STREAM
;
488 else if (streq(lvalue
, "ListenDatagram"))
489 p
->address
.type
= SOCK_DGRAM
;
491 assert(streq(lvalue
, "ListenSequentialPacket"));
492 p
->address
.type
= SOCK_SEQPACKET
;
495 if (socket_address_family(&p
->address
) != AF_LOCAL
&& p
->address
.type
== SOCK_SEQPACKET
) {
496 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Address family not supported, ignoring: %s", rvalue
);
500 p
->type
= SOCKET_SOCKET
;
504 p
->auxiliary_fds
= NULL
;
505 p
->n_auxiliary_fds
= 0;
508 LIST_FIND_TAIL(port
, s
->ports
, tail
);
509 LIST_INSERT_AFTER(port
, s
->ports
, tail
, p
);
516 int config_parse_exec_nice(
518 const char *filename
,
521 unsigned section_line
,
528 ExecContext
*c
= data
;
536 if (isempty(rvalue
)) {
541 r
= parse_nice(rvalue
, &priority
);
544 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Nice priority out of range, ignoring: %s", rvalue
);
546 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse nice priority '%s', ignoring: %m", rvalue
);
556 int config_parse_exec_oom_score_adjust(
558 const char *filename
,
561 unsigned section_line
,
568 ExecContext
*c
= data
;
576 if (isempty(rvalue
)) {
577 c
->oom_score_adjust_set
= false;
581 r
= parse_oom_score_adjust(rvalue
, &oa
);
584 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "OOM score adjust value out of range, ignoring: %s", rvalue
);
586 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse the OOM score adjust value '%s', ignoring: %m", rvalue
);
590 c
->oom_score_adjust
= oa
;
591 c
->oom_score_adjust_set
= true;
596 int config_parse_exec_coredump_filter(
598 const char *filename
,
601 unsigned section_line
,
608 ExecContext
*c
= data
;
616 if (isempty(rvalue
)) {
617 c
->coredump_filter
= 0;
618 c
->coredump_filter_set
= false;
623 r
= coredump_filter_mask_from_string(rvalue
, &f
);
625 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
626 "Failed to parse the CoredumpFilter=%s, ignoring: %m", rvalue
);
630 c
->coredump_filter
|= f
;
631 c
->oom_score_adjust_set
= true;
635 int config_parse_kill_mode(
637 const char *filename
,
640 unsigned section_line
,
647 KillMode
*k
= data
, m
;
654 if (isempty(rvalue
)) {
655 *k
= KILL_CONTROL_GROUP
;
659 m
= kill_mode_from_string(rvalue
);
661 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
662 "Failed to parse kill mode specification, ignoring: %s", rvalue
);
667 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
668 "Unit configured to use KillMode=none. "
669 "This is unsafe, as it disables systemd's process lifecycle management for the service. "
670 "Please update your service to use a safer KillMode=, such as 'mixed' or 'control-group'. "
671 "Support for KillMode=none is deprecated and will eventually be removed.");
677 int config_parse_exec(
679 const char *filename
,
682 unsigned section_line
,
689 ExecCommand
**e
= data
;
690 const Unit
*u
= userdata
;
702 if (isempty(rvalue
)) {
703 /* An empty assignment resets the list */
704 *e
= exec_command_free_list(*e
);
710 _cleanup_free_
char *path
= NULL
, *firstword
= NULL
;
711 ExecCommandFlags flags
= 0;
712 bool ignore
= false, separate_argv0
= false;
713 _cleanup_free_ ExecCommand
*nce
= NULL
;
714 _cleanup_strv_free_
char **n
= NULL
;
715 size_t nlen
= 0, nbufsize
= 0;
720 r
= extract_first_word_and_warn(&p
, &firstword
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
726 /* We accept an absolute path as first argument. If it's prefixed with - and the path doesn't
727 * exist, we ignore it instead of erroring out; if it's prefixed with @, we allow overriding of
728 * argv[0]; if it's prefixed with :, we will not do environment variable substitution;
729 * if it's prefixed with +, it will be run with full privileges and no sandboxing; if
730 * it's prefixed with '!' we apply sandboxing, but do not change user/group credentials; if
731 * it's prefixed with '!!', then we apply user/group credentials if the kernel supports ambient
732 * capabilities -- if it doesn't we don't apply the credentials themselves, but do apply most
733 * other sandboxing, with some special exceptions for changing UID.
735 * The idea is that '!!' may be used to write services that can take benefit of systemd's
736 * UID/GID dropping if the kernel supports ambient creds, but provide an automatic fallback to
737 * privilege dropping within the daemon if the kernel does not offer that. */
739 if (*f
== '-' && !(flags
& EXEC_COMMAND_IGNORE_FAILURE
)) {
740 flags
|= EXEC_COMMAND_IGNORE_FAILURE
;
742 } else if (*f
== '@' && !separate_argv0
)
743 separate_argv0
= true;
744 else if (*f
== ':' && !(flags
& EXEC_COMMAND_NO_ENV_EXPAND
))
745 flags
|= EXEC_COMMAND_NO_ENV_EXPAND
;
746 else if (*f
== '+' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
747 flags
|= EXEC_COMMAND_FULLY_PRIVILEGED
;
748 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
749 flags
|= EXEC_COMMAND_NO_SETUID
;
750 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_AMBIENT_MAGIC
))) {
751 flags
&= ~EXEC_COMMAND_NO_SETUID
;
752 flags
|= EXEC_COMMAND_AMBIENT_MAGIC
;
758 r
= unit_full_printf(u
, f
, &path
);
760 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
761 "Failed to resolve unit specifiers in '%s'%s: %m",
762 f
, ignore
? ", ignoring" : "");
763 return ignore
? 0 : -ENOEXEC
;
767 /* First word is either "-" or "@" with no command. */
768 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
769 "Empty path in command line%s: '%s'",
770 ignore
? ", ignoring" : "", rvalue
);
771 return ignore
? 0 : -ENOEXEC
;
773 if (!string_is_safe(path
)) {
774 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
775 "Executable name contains special characters%s: %s",
776 ignore
? ", ignoring" : "", path
);
777 return ignore
? 0 : -ENOEXEC
;
779 if (endswith(path
, "/")) {
780 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
781 "Executable path specifies a directory%s: %s",
782 ignore
? ", ignoring" : "", path
);
783 return ignore
? 0 : -ENOEXEC
;
786 if (!path_is_absolute(path
)) {
790 if (!filename_is_valid(path
)) {
791 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
792 "Neither a valid executable name nor an absolute path%s: %s",
793 ignore
? ", ignoring" : "", path
);
794 return ignore
? 0 : -ENOEXEC
;
797 /* Resolve a single-component name to a full path */
798 NULSTR_FOREACH(prefix
, DEFAULT_PATH_NULSTR
) {
799 _cleanup_free_
char *fullpath
= NULL
;
801 fullpath
= path_join(prefix
, path
);
805 if (access(fullpath
, F_OK
) >= 0) {
806 free_and_replace(path
, fullpath
);
813 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
814 "Executable \"%s\" not found in path \"%s\"%s",
815 path
, DEFAULT_PATH
, ignore
? ", ignoring" : "");
816 return ignore
? 0 : -ENOEXEC
;
820 if (!separate_argv0
) {
823 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
833 path_simplify(path
, false);
835 while (!isempty(p
)) {
836 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
838 /* Check explicitly for an unquoted semicolon as
839 * command separator token. */
840 if (p
[0] == ';' && (!p
[1] || strchr(WHITESPACE
, p
[1]))) {
842 p
+= strspn(p
, WHITESPACE
);
847 /* Check for \; explicitly, to not confuse it with \\; or "\;" or "\\;" etc.
848 * extract_first_word() would return the same for all of those. */
849 if (p
[0] == '\\' && p
[1] == ';' && (!p
[2] || strchr(WHITESPACE
, p
[2]))) {
853 p
+= strspn(p
, WHITESPACE
);
855 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
866 r
= extract_first_word_and_warn(&p
, &word
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
870 return ignore
? 0 : -ENOEXEC
;
872 r
= unit_full_printf(u
, word
, &resolved
);
874 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
875 "Failed to resolve unit specifiers in %s%s: %m",
876 word
, ignore
? ", ignoring" : "");
877 return ignore
? 0 : -ENOEXEC
;
880 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
883 n
[nlen
++] = TAKE_PTR(resolved
);
888 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, 0,
889 "Empty executable name or zeroeth argument%s: %s",
890 ignore
? ", ignoring" : "", rvalue
);
891 return ignore
? 0 : -ENOEXEC
;
894 nce
= new0(ExecCommand
, 1);
898 nce
->argv
= TAKE_PTR(n
);
899 nce
->path
= TAKE_PTR(path
);
902 exec_command_append_list(e
, nce
);
904 /* Do not _cleanup_free_ these. */
913 int config_parse_socket_bindtodevice(
915 const char *filename
,
918 unsigned section_line
,
932 if (isempty(rvalue
) || streq(rvalue
, "*")) {
933 s
->bind_to_device
= mfree(s
->bind_to_device
);
937 if (!ifname_valid(rvalue
)) {
938 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid interface name, ignoring: %s", rvalue
);
942 if (free_and_strdup(&s
->bind_to_device
, rvalue
) < 0)
948 int config_parse_exec_input(
950 const char *filename
,
953 unsigned section_line
,
960 ExecContext
*c
= data
;
961 const Unit
*u
= userdata
;
971 n
= startswith(rvalue
, "fd:");
973 _cleanup_free_
char *resolved
= NULL
;
975 r
= unit_full_printf(u
, n
, &resolved
);
977 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", n
);
981 if (isempty(resolved
))
982 resolved
= mfree(resolved
);
983 else if (!fdname_is_valid(resolved
)) {
984 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", resolved
);
988 free_and_replace(c
->stdio_fdname
[STDIN_FILENO
], resolved
);
990 ei
= EXEC_INPUT_NAMED_FD
;
992 } else if ((n
= startswith(rvalue
, "file:"))) {
993 _cleanup_free_
char *resolved
= NULL
;
995 r
= unit_full_printf(u
, n
, &resolved
);
997 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", n
);
1001 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1005 free_and_replace(c
->stdio_file
[STDIN_FILENO
], resolved
);
1007 ei
= EXEC_INPUT_FILE
;
1010 ei
= exec_input_from_string(rvalue
);
1012 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Failed to parse input specifier, ignoring: %s", rvalue
);
1021 int config_parse_exec_input_text(
1023 const char *filename
,
1025 const char *section
,
1026 unsigned section_line
,
1033 _cleanup_free_
char *unescaped
= NULL
, *resolved
= NULL
;
1034 ExecContext
*c
= data
;
1035 const Unit
*u
= userdata
;
1045 if (isempty(rvalue
)) {
1046 /* Reset if the empty string is assigned */
1047 c
->stdin_data
= mfree(c
->stdin_data
);
1048 c
->stdin_data_size
= 0;
1052 r
= cunescape(rvalue
, 0, &unescaped
);
1054 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1055 "Failed to decode C escaped text '%s', ignoring: %m", rvalue
);
1059 r
= unit_full_printf(u
, unescaped
, &resolved
);
1061 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1062 "Failed to resolve unit specifiers in '%s', ignoring: %m", unescaped
);
1066 sz
= strlen(resolved
);
1067 if (c
->stdin_data_size
+ sz
+ 1 < c
->stdin_data_size
|| /* check for overflow */
1068 c
->stdin_data_size
+ sz
+ 1 > EXEC_STDIN_DATA_MAX
) {
1069 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
1070 "Standard input data too large (%zu), maximum of %zu permitted, ignoring.",
1071 c
->stdin_data_size
+ sz
, (size_t) EXEC_STDIN_DATA_MAX
);
1075 p
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
+ 1);
1079 *((char*) mempcpy((char*) p
+ c
->stdin_data_size
, resolved
, sz
)) = '\n';
1082 c
->stdin_data_size
+= sz
+ 1;
1087 int config_parse_exec_input_data(
1089 const char *filename
,
1091 const char *section
,
1092 unsigned section_line
,
1099 _cleanup_free_
void *p
= NULL
;
1100 ExecContext
*c
= data
;
1110 if (isempty(rvalue
)) {
1111 /* Reset if the empty string is assigned */
1112 c
->stdin_data
= mfree(c
->stdin_data
);
1113 c
->stdin_data_size
= 0;
1117 r
= unbase64mem(rvalue
, (size_t) -1, &p
, &sz
);
1119 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1120 "Failed to decode base64 data, ignoring: %s", rvalue
);
1126 if (c
->stdin_data_size
+ sz
< c
->stdin_data_size
|| /* check for overflow */
1127 c
->stdin_data_size
+ sz
> EXEC_STDIN_DATA_MAX
) {
1128 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
1129 "Standard input data too large (%zu), maximum of %zu permitted, ignoring.",
1130 c
->stdin_data_size
+ sz
, (size_t) EXEC_STDIN_DATA_MAX
);
1134 q
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
);
1138 memcpy((uint8_t*) q
+ c
->stdin_data_size
, p
, sz
);
1141 c
->stdin_data_size
+= sz
;
1146 int config_parse_exec_output(
1148 const char *filename
,
1150 const char *section
,
1151 unsigned section_line
,
1158 _cleanup_free_
char *resolved
= NULL
;
1160 ExecContext
*c
= data
;
1161 const Unit
*u
= userdata
;
1162 bool obsolete
= false;
1172 n
= startswith(rvalue
, "fd:");
1174 r
= unit_full_printf(u
, n
, &resolved
);
1176 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", n
);
1180 if (isempty(resolved
))
1181 resolved
= mfree(resolved
);
1182 else if (!fdname_is_valid(resolved
)) {
1183 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", resolved
);
1187 eo
= EXEC_OUTPUT_NAMED_FD
;
1189 } else if (streq(rvalue
, "syslog")) {
1190 eo
= EXEC_OUTPUT_JOURNAL
;
1193 } else if (streq(rvalue
, "syslog+console")) {
1194 eo
= EXEC_OUTPUT_JOURNAL_AND_CONSOLE
;
1197 } else if ((n
= startswith(rvalue
, "file:"))) {
1199 r
= unit_full_printf(u
, n
, &resolved
);
1201 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", n
);
1205 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1209 eo
= EXEC_OUTPUT_FILE
;
1211 } else if ((n
= startswith(rvalue
, "append:"))) {
1213 r
= unit_full_printf(u
, n
, &resolved
);
1215 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", n
);
1219 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1223 eo
= EXEC_OUTPUT_FILE_APPEND
;
1225 eo
= exec_output_from_string(rvalue
);
1227 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Failed to parse output specifier, ignoring: %s", rvalue
);
1233 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
1234 "Standard output type %s is obsolete, automatically updating to %s. Please update your unit file, and consider removing the setting altogether.",
1235 rvalue
, exec_output_to_string(eo
));
1237 if (streq(lvalue
, "StandardOutput")) {
1238 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1239 free_and_replace(c
->stdio_fdname
[STDOUT_FILENO
], resolved
);
1241 free_and_replace(c
->stdio_file
[STDOUT_FILENO
], resolved
);
1246 assert(streq(lvalue
, "StandardError"));
1248 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1249 free_and_replace(c
->stdio_fdname
[STDERR_FILENO
], resolved
);
1251 free_and_replace(c
->stdio_file
[STDERR_FILENO
], resolved
);
1259 int config_parse_exec_io_class(const char *unit
,
1260 const char *filename
,
1262 const char *section
,
1263 unsigned section_line
,
1270 ExecContext
*c
= data
;
1278 if (isempty(rvalue
)) {
1279 c
->ioprio_set
= false;
1280 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE
, 0);
1284 x
= ioprio_class_from_string(rvalue
);
1286 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Failed to parse IO scheduling class, ignoring: %s", rvalue
);
1290 c
->ioprio
= IOPRIO_PRIO_VALUE(x
, IOPRIO_PRIO_DATA(c
->ioprio
));
1291 c
->ioprio_set
= true;
1296 int config_parse_exec_io_priority(const char *unit
,
1297 const char *filename
,
1299 const char *section
,
1300 unsigned section_line
,
1307 ExecContext
*c
= data
;
1315 if (isempty(rvalue
)) {
1316 c
->ioprio_set
= false;
1317 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE
, 0);
1321 r
= ioprio_parse_priority(rvalue
, &i
);
1323 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse IO priority, ignoring: %s", rvalue
);
1327 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_PRIO_CLASS(c
->ioprio
), i
);
1328 c
->ioprio_set
= true;
1333 int config_parse_exec_cpu_sched_policy(const char *unit
,
1334 const char *filename
,
1336 const char *section
,
1337 unsigned section_line
,
1344 ExecContext
*c
= data
;
1352 if (isempty(rvalue
)) {
1353 c
->cpu_sched_set
= false;
1354 c
->cpu_sched_policy
= SCHED_OTHER
;
1355 c
->cpu_sched_priority
= 0;
1359 x
= sched_policy_from_string(rvalue
);
1361 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Failed to parse CPU scheduling policy, ignoring: %s", rvalue
);
1365 c
->cpu_sched_policy
= x
;
1366 /* Moving to or from real-time policy? We need to adjust the priority */
1367 c
->cpu_sched_priority
= CLAMP(c
->cpu_sched_priority
, sched_get_priority_min(x
), sched_get_priority_max(x
));
1368 c
->cpu_sched_set
= true;
1373 int config_parse_numa_mask(const char *unit
,
1374 const char *filename
,
1376 const char *section
,
1377 unsigned section_line
,
1384 NUMAPolicy
*p
= data
;
1391 if (streq(rvalue
, "all")) {
1392 r
= numa_mask_add_all(&p
->nodes
);
1394 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1395 "Failed to create NUMA mask representing \"all\" NUMA nodes, ignoring: %m");
1397 r
= parse_cpu_set_extend(rvalue
, &p
->nodes
, true, unit
, filename
, line
, lvalue
);
1399 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse NUMA node mask, ignoring: %s", rvalue
);
1405 int config_parse_exec_cpu_sched_prio(const char *unit
,
1406 const char *filename
,
1408 const char *section
,
1409 unsigned section_line
,
1416 ExecContext
*c
= data
;
1424 r
= safe_atoi(rvalue
, &i
);
1426 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse CPU scheduling priority, ignoring: %s", rvalue
);
1430 /* On Linux RR/FIFO range from 1 to 99 and OTHER/BATCH may only be 0 */
1431 min
= sched_get_priority_min(c
->cpu_sched_policy
);
1432 max
= sched_get_priority_max(c
->cpu_sched_policy
);
1434 if (i
< min
|| i
> max
) {
1435 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "CPU scheduling priority is out of range, ignoring: %s", rvalue
);
1439 c
->cpu_sched_priority
= i
;
1440 c
->cpu_sched_set
= true;
1445 int config_parse_root_image_options(
1447 const char *filename
,
1449 const char *section
,
1450 unsigned section_line
,
1457 _cleanup_(mount_options_free_allp
) MountOptions
*options
= NULL
;
1458 _cleanup_strv_free_
char **l
= NULL
;
1459 char **first
= NULL
, **second
= NULL
;
1460 ExecContext
*c
= data
;
1461 const Unit
*u
= userdata
;
1469 if (isempty(rvalue
)) {
1470 c
->root_image_options
= mount_options_free_all(c
->root_image_options
);
1474 r
= strv_split_colon_pairs(&l
, rvalue
);
1478 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
1482 STRV_FOREACH_PAIR(first
, second
, l
) {
1483 MountOptions
*o
= NULL
;
1484 _cleanup_free_
char *mount_options_resolved
= NULL
;
1485 const char *mount_options
= NULL
, *partition
= "root";
1486 int partition_designator
;
1488 /* Format is either 'root:foo' or 'foo' (root is implied) */
1489 if (!isempty(*second
)) {
1491 mount_options
= *second
;
1493 mount_options
= *first
;
1495 partition_designator
= partition_designator_from_string(partition
);
1496 if (partition_designator
< 0) {
1497 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid partition name %s, ignoring", partition
);
1500 r
= unit_full_printf(u
, mount_options
, &mount_options_resolved
);
1502 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", mount_options
);
1506 o
= new(MountOptions
, 1);
1509 *o
= (MountOptions
) {
1510 .partition_designator
= partition_designator
,
1511 .options
= TAKE_PTR(mount_options_resolved
),
1513 LIST_APPEND(mount_options
, options
, TAKE_PTR(o
));
1516 /* empty spaces/separators only */
1517 if (LIST_IS_EMPTY(options
))
1518 c
->root_image_options
= mount_options_free_all(c
->root_image_options
);
1520 LIST_JOIN(mount_options
, c
->root_image_options
, options
);
1525 int config_parse_exec_root_hash(
1527 const char *filename
,
1529 const char *section
,
1530 unsigned section_line
,
1537 _cleanup_free_
void *roothash_decoded
= NULL
;
1538 ExecContext
*c
= data
;
1539 size_t roothash_decoded_size
= 0;
1547 if (isempty(rvalue
)) {
1548 /* Reset if the empty string is assigned */
1549 c
->root_hash_path
= mfree(c
->root_hash_path
);
1550 c
->root_hash
= mfree(c
->root_hash
);
1551 c
->root_hash_size
= 0;
1555 if (path_is_absolute(rvalue
)) {
1556 /* We have the path to a roothash to load and decode, eg: RootHash=/foo/bar.roothash */
1557 _cleanup_free_
char *p
= NULL
;
1563 free_and_replace(c
->root_hash_path
, p
);
1564 c
->root_hash
= mfree(c
->root_hash
);
1565 c
->root_hash_size
= 0;
1569 /* We have a roothash to decode, eg: RootHash=012345789abcdef */
1570 r
= unhexmem(rvalue
, strlen(rvalue
), &roothash_decoded
, &roothash_decoded_size
);
1572 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to decode RootHash=, ignoring: %s", rvalue
);
1575 if (roothash_decoded_size
< sizeof(sd_id128_t
)) {
1576 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "RootHash= is too short, ignoring: %s", rvalue
);
1580 free_and_replace(c
->root_hash
, roothash_decoded
);
1581 c
->root_hash_size
= roothash_decoded_size
;
1582 c
->root_hash_path
= mfree(c
->root_hash_path
);
1587 int config_parse_exec_root_hash_sig(
1589 const char *filename
,
1591 const char *section
,
1592 unsigned section_line
,
1599 _cleanup_free_
void *roothash_sig_decoded
= NULL
;
1601 ExecContext
*c
= data
;
1602 size_t roothash_sig_decoded_size
= 0;
1610 if (isempty(rvalue
)) {
1611 /* Reset if the empty string is assigned */
1612 c
->root_hash_sig_path
= mfree(c
->root_hash_sig_path
);
1613 c
->root_hash_sig
= mfree(c
->root_hash_sig
);
1614 c
->root_hash_sig_size
= 0;
1618 if (path_is_absolute(rvalue
)) {
1619 /* We have the path to a roothash signature to load and decode, eg: RootHashSignature=/foo/bar.roothash.p7s */
1620 _cleanup_free_
char *p
= NULL
;
1626 free_and_replace(c
->root_hash_sig_path
, p
);
1627 c
->root_hash_sig
= mfree(c
->root_hash_sig
);
1628 c
->root_hash_sig_size
= 0;
1632 if (!(value
= startswith(rvalue
, "base64:"))) {
1633 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
1634 "Failed to decode RootHashSignature=, not a path but doesn't start with 'base64:', ignoring: %s", rvalue
);
1638 /* We have a roothash signature to decode, eg: RootHashSignature=base64:012345789abcdef */
1639 r
= unbase64mem(value
, strlen(value
), &roothash_sig_decoded
, &roothash_sig_decoded_size
);
1641 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to decode RootHashSignature=, ignoring: %s", rvalue
);
1645 free_and_replace(c
->root_hash_sig
, roothash_sig_decoded
);
1646 c
->root_hash_sig_size
= roothash_sig_decoded_size
;
1647 c
->root_hash_sig_path
= mfree(c
->root_hash_sig_path
);
1652 int config_parse_exec_cpu_affinity(const char *unit
,
1653 const char *filename
,
1655 const char *section
,
1656 unsigned section_line
,
1663 ExecContext
*c
= data
;
1671 if (streq(rvalue
, "numa")) {
1672 c
->cpu_affinity_from_numa
= true;
1673 cpu_set_reset(&c
->cpu_set
);
1678 r
= parse_cpu_set_extend(rvalue
, &c
->cpu_set
, true, unit
, filename
, line
, lvalue
);
1680 c
->cpu_affinity_from_numa
= false;
1685 int config_parse_capability_set(
1687 const char *filename
,
1689 const char *section
,
1690 unsigned section_line
,
1697 uint64_t *capability_set
= data
;
1698 uint64_t sum
= 0, initial
= 0;
1699 bool invert
= false;
1707 if (rvalue
[0] == '~') {
1712 if (streq(lvalue
, "CapabilityBoundingSet"))
1713 initial
= CAP_ALL
; /* initialized to all bits on */
1714 /* else "AmbientCapabilities" initialized to all bits off */
1716 r
= capability_set_from_string(rvalue
, &sum
);
1718 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= specifier '%s', ignoring: %m", lvalue
, rvalue
);
1722 if (sum
== 0 || *capability_set
== initial
)
1723 /* "", "~" or uninitialized data -> replace */
1724 *capability_set
= invert
? ~sum
: sum
;
1726 /* previous data -> merge */
1728 *capability_set
&= ~sum
;
1730 *capability_set
|= sum
;
1736 int config_parse_exec_selinux_context(
1738 const char *filename
,
1740 const char *section
,
1741 unsigned section_line
,
1748 ExecContext
*c
= data
;
1749 const Unit
*u
= userdata
;
1759 if (isempty(rvalue
)) {
1760 c
->selinux_context
= mfree(c
->selinux_context
);
1761 c
->selinux_context_ignore
= false;
1765 if (rvalue
[0] == '-') {
1771 r
= unit_full_printf(u
, rvalue
, &k
);
1773 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
1774 "Failed to resolve unit specifiers in '%s'%s: %m",
1775 rvalue
, ignore
? ", ignoring" : "");
1776 return ignore
? 0 : -ENOEXEC
;
1779 free_and_replace(c
->selinux_context
, k
);
1780 c
->selinux_context_ignore
= ignore
;
1785 int config_parse_exec_apparmor_profile(
1787 const char *filename
,
1789 const char *section
,
1790 unsigned section_line
,
1797 ExecContext
*c
= data
;
1798 const Unit
*u
= userdata
;
1808 if (isempty(rvalue
)) {
1809 c
->apparmor_profile
= mfree(c
->apparmor_profile
);
1810 c
->apparmor_profile_ignore
= false;
1814 if (rvalue
[0] == '-') {
1820 r
= unit_full_printf(u
, rvalue
, &k
);
1822 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
1823 "Failed to resolve unit specifiers in '%s'%s: %m",
1824 rvalue
, ignore
? ", ignoring" : "");
1825 return ignore
? 0 : -ENOEXEC
;
1828 free_and_replace(c
->apparmor_profile
, k
);
1829 c
->apparmor_profile_ignore
= ignore
;
1834 int config_parse_exec_smack_process_label(
1836 const char *filename
,
1838 const char *section
,
1839 unsigned section_line
,
1846 ExecContext
*c
= data
;
1847 const Unit
*u
= userdata
;
1857 if (isempty(rvalue
)) {
1858 c
->smack_process_label
= mfree(c
->smack_process_label
);
1859 c
->smack_process_label_ignore
= false;
1863 if (rvalue
[0] == '-') {
1869 r
= unit_full_printf(u
, rvalue
, &k
);
1871 log_syntax(unit
, ignore
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
1872 "Failed to resolve unit specifiers in '%s'%s: %m",
1873 rvalue
, ignore
? ", ignoring" : "");
1874 return ignore
? 0 : -ENOEXEC
;
1877 free_and_replace(c
->smack_process_label
, k
);
1878 c
->smack_process_label_ignore
= ignore
;
1883 int config_parse_timer(
1885 const char *filename
,
1887 const char *section
,
1888 unsigned section_line
,
1895 _cleanup_(calendar_spec_freep
) CalendarSpec
*c
= NULL
;
1896 _cleanup_free_
char *k
= NULL
;
1897 const Unit
*u
= userdata
;
1908 if (isempty(rvalue
)) {
1909 /* Empty assignment resets list */
1910 timer_free_values(t
);
1914 r
= unit_full_printf(u
, rvalue
, &k
);
1916 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
1920 if (ltype
== TIMER_CALENDAR
) {
1921 r
= calendar_spec_from_string(k
, &c
);
1923 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse calendar specification, ignoring: %s", k
);
1927 r
= parse_sec(k
, &usec
);
1929 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse timer value, ignoring: %s", k
);
1934 v
= new(TimerValue
, 1);
1941 .calendar_spec
= TAKE_PTR(c
),
1944 LIST_PREPEND(value
, t
->values
, v
);
1949 int config_parse_trigger_unit(
1951 const char *filename
,
1953 const char *section
,
1954 unsigned section_line
,
1961 _cleanup_free_
char *p
= NULL
;
1971 if (!hashmap_isempty(u
->dependencies
[UNIT_TRIGGERS
])) {
1972 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Multiple units to trigger specified, ignoring: %s", rvalue
);
1976 r
= unit_name_printf(u
, rvalue
, &p
);
1978 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
1982 type
= unit_name_to_type(p
);
1984 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Unit type not valid, ignoring: %s", rvalue
);
1987 if (unit_has_name(u
, p
)) {
1988 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Units cannot trigger themselves, ignoring: %s", rvalue
);
1992 r
= unit_add_two_dependencies_by_name(u
, UNIT_BEFORE
, UNIT_TRIGGERS
, p
, true, UNIT_DEPENDENCY_FILE
);
1994 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add trigger on %s, ignoring: %m", p
);
2001 int config_parse_path_spec(const char *unit
,
2002 const char *filename
,
2004 const char *section
,
2005 unsigned section_line
,
2015 _cleanup_free_
char *k
= NULL
;
2023 if (isempty(rvalue
)) {
2024 /* Empty assignment clears list */
2029 b
= path_type_from_string(lvalue
);
2031 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Failed to parse path type, ignoring: %s", lvalue
);
2035 r
= unit_full_printf(UNIT(p
), rvalue
, &k
);
2037 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2041 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2045 s
= new0(PathSpec
, 1);
2050 s
->path
= TAKE_PTR(k
);
2054 LIST_PREPEND(spec
, p
->specs
, s
);
2059 int config_parse_socket_service(
2061 const char *filename
,
2063 const char *section
,
2064 unsigned section_line
,
2071 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
2072 _cleanup_free_
char *p
= NULL
;
2082 r
= unit_name_printf(UNIT(s
), rvalue
, &p
);
2084 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2088 if (!endswith(p
, ".service")) {
2089 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Unit must be of type service, ignoring: %s", rvalue
);
2093 r
= manager_load_unit(UNIT(s
)->manager
, p
, NULL
, &error
, &x
);
2095 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to load unit %s, ignoring: %s", rvalue
, bus_error_message(&error
, r
));
2099 unit_ref_set(&s
->service
, UNIT(s
), x
);
2104 int config_parse_fdname(
2106 const char *filename
,
2108 const char *section
,
2109 unsigned section_line
,
2116 _cleanup_free_
char *p
= NULL
;
2125 if (isempty(rvalue
)) {
2126 s
->fdname
= mfree(s
->fdname
);
2130 r
= unit_full_printf(UNIT(s
), rvalue
, &p
);
2132 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2136 if (!fdname_is_valid(p
)) {
2137 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", p
);
2141 return free_and_replace(s
->fdname
, p
);
2144 int config_parse_service_sockets(
2146 const char *filename
,
2148 const char *section
,
2149 unsigned section_line
,
2164 for (const char *p
= rvalue
;;) {
2165 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2167 r
= extract_first_word(&p
, &word
, NULL
, 0);
2173 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Trailing garbage in sockets, ignoring: %s", rvalue
);
2177 r
= unit_name_printf(UNIT(s
), word
, &k
);
2179 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
2183 if (!endswith(k
, ".socket")) {
2184 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Unit must be of type socket, ignoring: %s", k
);
2188 r
= unit_add_two_dependencies_by_name(UNIT(s
), UNIT_WANTS
, UNIT_AFTER
, k
, true, UNIT_DEPENDENCY_FILE
);
2190 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
2192 r
= unit_add_dependency_by_name(UNIT(s
), UNIT_TRIGGERED_BY
, k
, true, UNIT_DEPENDENCY_FILE
);
2194 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
2198 int config_parse_bus_name(
2200 const char *filename
,
2202 const char *section
,
2203 unsigned section_line
,
2210 _cleanup_free_
char *k
= NULL
;
2211 const Unit
*u
= userdata
;
2219 r
= unit_full_printf(u
, rvalue
, &k
);
2221 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2225 if (!sd_bus_service_name_is_valid(k
)) {
2226 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid bus name, ignoring: %s", k
);
2230 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
2233 int config_parse_service_timeout(
2235 const char *filename
,
2237 const char *section
,
2238 unsigned section_line
,
2245 Service
*s
= userdata
;
2254 /* This is called for two cases: TimeoutSec= and TimeoutStartSec=. */
2256 /* Traditionally, these options accepted 0 to disable the timeouts. However, a timeout of 0 suggests it happens
2257 * immediately, hence fix this to become USEC_INFINITY instead. This is in-line with how we internally handle
2258 * all other timeouts. */
2259 r
= parse_sec_fix_0(rvalue
, &usec
);
2261 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
2265 s
->start_timeout_defined
= true;
2266 s
->timeout_start_usec
= usec
;
2268 if (streq(lvalue
, "TimeoutSec"))
2269 s
->timeout_stop_usec
= usec
;
2274 int config_parse_timeout_abort(
2276 const char *filename
,
2278 const char *section
,
2279 unsigned section_line
,
2294 /* Note: apart from setting the arg, this returns an extra bit of information in the return value. */
2296 if (isempty(rvalue
)) {
2298 return 0; /* "not set" */
2301 r
= parse_sec(rvalue
, ret
);
2303 return log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s= setting, ignoring: %s", lvalue
, rvalue
);
2305 return 1; /* "set" */
2308 int config_parse_service_timeout_abort(
2310 const char *filename
,
2312 const char *section
,
2313 unsigned section_line
,
2320 Service
*s
= userdata
;
2325 r
= config_parse_timeout_abort(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
,
2326 &s
->timeout_abort_usec
, s
);
2328 s
->timeout_abort_set
= r
;
2332 int config_parse_sec_fix_0(
2334 const char *filename
,
2336 const char *section
,
2337 unsigned section_line
,
2344 usec_t
*usec
= data
;
2352 /* This is pretty much like config_parse_sec(), except that this treats a time of 0 as infinity, for
2353 * compatibility with older versions of systemd where 0 instead of infinity was used as indicator to turn off a
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
);
2363 int config_parse_user_group_compat(
2365 const char *filename
,
2367 const char *section
,
2368 unsigned section_line
,
2375 _cleanup_free_
char *k
= NULL
;
2377 const Unit
*u
= userdata
;
2385 if (isempty(rvalue
)) {
2386 *user
= mfree(*user
);
2390 r
= unit_full_printf(u
, rvalue
, &k
);
2392 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", rvalue
);
2396 if (!valid_user_group_name(k
, VALID_USER_ALLOW_NUMERIC
|VALID_USER_RELAX
|VALID_USER_WARN
)) {
2397 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2401 if (strstr(lvalue
, "User") && streq(k
, NOBODY_USER_NAME
))
2402 log_struct(LOG_NOTICE
,
2403 "MESSAGE=%s:%u: Special user %s configured, this is not safe!", filename
, line
, k
,
2405 "MESSAGE_ID=" SD_MESSAGE_NOBODY_USER_UNSUITABLE_STR
,
2406 "OFFENDING_USER=%s", k
,
2407 "CONFIG_FILE=%s", filename
,
2408 "CONFIG_LINE=%u", line
);
2410 return free_and_replace(*user
, k
);
2413 int config_parse_user_group_strv_compat(
2415 const char *filename
,
2417 const char *section
,
2418 unsigned section_line
,
2425 char ***users
= data
;
2426 const Unit
*u
= userdata
;
2434 if (isempty(rvalue
)) {
2435 *users
= strv_free(*users
);
2439 for (const char *p
= rvalue
;;) {
2440 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2442 r
= extract_first_word(&p
, &word
, NULL
, 0);
2448 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax: %s", rvalue
);
2452 r
= unit_full_printf(u
, word
, &k
);
2454 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", word
);
2458 if (!valid_user_group_name(k
, VALID_USER_ALLOW_NUMERIC
|VALID_USER_RELAX
|VALID_USER_WARN
)) {
2459 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2463 r
= strv_push(users
, k
);
2471 int config_parse_working_directory(
2473 const char *filename
,
2475 const char *section
,
2476 unsigned section_line
,
2483 ExecContext
*c
= data
;
2484 const Unit
*u
= userdata
;
2494 if (isempty(rvalue
)) {
2495 c
->working_directory_home
= false;
2496 c
->working_directory
= mfree(c
->working_directory
);
2500 if (rvalue
[0] == '-') {
2506 if (streq(rvalue
, "~")) {
2507 c
->working_directory_home
= true;
2508 c
->working_directory
= mfree(c
->working_directory
);
2510 _cleanup_free_
char *k
= NULL
;
2512 r
= unit_full_printf(u
, rvalue
, &k
);
2514 log_syntax(unit
, missing_ok
? LOG_WARNING
: LOG_ERR
, filename
, line
, r
,
2515 "Failed to resolve unit specifiers in working directory path '%s'%s: %m",
2516 rvalue
, missing_ok
? ", ignoring" : "");
2517 return missing_ok
? 0 : -ENOEXEC
;
2520 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
| (missing_ok
? 0 : PATH_CHECK_FATAL
), unit
, filename
, line
, lvalue
);
2522 return missing_ok
? 0 : -ENOEXEC
;
2524 c
->working_directory_home
= false;
2525 free_and_replace(c
->working_directory
, k
);
2528 c
->working_directory_missing_ok
= missing_ok
;
2532 int config_parse_unit_env_file(const char *unit
,
2533 const char *filename
,
2535 const char *section
,
2536 unsigned section_line
,
2544 const Unit
*u
= userdata
;
2545 _cleanup_free_
char *n
= NULL
;
2553 if (isempty(rvalue
)) {
2554 /* Empty assignment frees the list */
2555 *env
= strv_free(*env
);
2559 r
= unit_full_printf(u
, rvalue
, &n
);
2561 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2565 r
= path_simplify_and_warn(n
[0] == '-' ? n
+ 1 : n
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2569 r
= strv_push(env
, n
);
2578 int config_parse_environ(
2580 const char *filename
,
2582 const char *section
,
2583 unsigned section_line
,
2590 const Unit
*u
= userdata
;
2599 if (isempty(rvalue
)) {
2600 /* Empty assignment resets the list */
2601 *env
= strv_free(*env
);
2605 for (const char *p
= rvalue
;; ) {
2606 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2608 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2614 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2615 "Invalid syntax, ignoring: %s", rvalue
);
2620 r
= unit_full_printf(u
, word
, &k
);
2622 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2623 "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2629 if (!env_assignment_is_valid(k
)) {
2630 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
2631 "Invalid environment assignment, ignoring: %s", k
);
2635 r
= strv_env_replace(env
, k
);
2643 int config_parse_pass_environ(
2645 const char *filename
,
2647 const char *section
,
2648 unsigned section_line
,
2655 _cleanup_strv_free_
char **n
= NULL
;
2656 size_t nlen
= 0, nbufsize
= 0;
2657 char*** passenv
= data
;
2658 const Unit
*u
= userdata
;
2666 if (isempty(rvalue
)) {
2667 /* Empty assignment resets the list */
2668 *passenv
= strv_free(*passenv
);
2672 for (const char *p
= rvalue
;;) {
2673 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2675 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
2681 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2682 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2687 r
= unit_full_printf(u
, word
, &k
);
2689 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2690 "Failed to resolve specifiers in %s, ignoring: %m", word
);
2696 if (!env_name_is_valid(k
)) {
2697 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
2698 "Invalid environment name for %s, ignoring: %s", lvalue
, k
);
2702 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
2705 n
[nlen
++] = TAKE_PTR(k
);
2710 r
= strv_extend_strv(passenv
, n
, true);
2718 int config_parse_unset_environ(
2720 const char *filename
,
2722 const char *section
,
2723 unsigned section_line
,
2730 _cleanup_strv_free_
char **n
= NULL
;
2731 size_t nlen
= 0, nbufsize
= 0;
2732 char*** unsetenv
= data
;
2733 const Unit
*u
= userdata
;
2741 if (isempty(rvalue
)) {
2742 /* Empty assignment resets the list */
2743 *unsetenv
= strv_free(*unsetenv
);
2747 for (const char *p
= rvalue
;;) {
2748 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2750 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2756 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2757 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2762 r
= unit_full_printf(u
, word
, &k
);
2764 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2765 "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2771 if (!env_assignment_is_valid(k
) && !env_name_is_valid(k
)) {
2772 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
2773 "Invalid environment name or assignment %s, ignoring: %s", lvalue
, k
);
2777 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
2780 n
[nlen
++] = TAKE_PTR(k
);
2785 r
= strv_extend_strv(unsetenv
, n
, true);
2793 int config_parse_log_extra_fields(
2795 const char *filename
,
2797 const char *section
,
2798 unsigned section_line
,
2805 ExecContext
*c
= data
;
2806 const Unit
*u
= userdata
;
2814 if (isempty(rvalue
)) {
2815 exec_context_free_log_extra_fields(c
);
2819 for (const char *p
= rvalue
;;) {
2820 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2824 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2830 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
2834 r
= unit_full_printf(u
, word
, &k
);
2836 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2840 eq
= strchr(k
, '=');
2842 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Log field lacks '=' character, ignoring: %s", k
);
2846 if (!journal_field_valid(k
, eq
-k
, false)) {
2847 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Log field name is invalid, ignoring: %s", k
);
2851 t
= reallocarray(c
->log_extra_fields
, c
->n_log_extra_fields
+1, sizeof(struct iovec
));
2855 c
->log_extra_fields
= t
;
2856 c
->log_extra_fields
[c
->n_log_extra_fields
++] = IOVEC_MAKE_STRING(k
);
2862 int config_parse_log_namespace(
2864 const char *filename
,
2866 const char *section
,
2867 unsigned section_line
,
2874 _cleanup_free_
char *k
= NULL
;
2875 ExecContext
*c
= data
;
2876 const Unit
*u
= userdata
;
2884 if (isempty(rvalue
)) {
2885 c
->log_namespace
= mfree(c
->log_namespace
);
2889 r
= unit_full_printf(u
, rvalue
, &k
);
2891 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2895 if (!log_namespace_name_valid(k
)) {
2896 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Specified log namespace name is not valid, ignoring: %s", k
);
2900 free_and_replace(c
->log_namespace
, k
);
2904 int config_parse_unit_condition_path(
2906 const char *filename
,
2908 const char *section
,
2909 unsigned section_line
,
2916 _cleanup_free_
char *p
= NULL
;
2917 Condition
**list
= data
, *c
;
2918 ConditionType t
= ltype
;
2919 bool trigger
, negate
;
2920 const Unit
*u
= userdata
;
2928 if (isempty(rvalue
)) {
2929 /* Empty assignment resets the list */
2930 *list
= condition_free_list(*list
);
2934 trigger
= rvalue
[0] == '|';
2938 negate
= rvalue
[0] == '!';
2942 r
= unit_full_printf(u
, rvalue
, &p
);
2944 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2948 r
= path_simplify_and_warn(p
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2952 c
= condition_new(t
, p
, trigger
, negate
);
2956 LIST_PREPEND(conditions
, *list
, c
);
2960 int config_parse_unit_condition_string(
2962 const char *filename
,
2964 const char *section
,
2965 unsigned section_line
,
2972 _cleanup_free_
char *s
= NULL
;
2973 Condition
**list
= data
, *c
;
2974 ConditionType t
= ltype
;
2975 bool trigger
, negate
;
2976 const Unit
*u
= userdata
;
2984 if (isempty(rvalue
)) {
2985 /* Empty assignment resets the list */
2986 *list
= condition_free_list(*list
);
2990 trigger
= *rvalue
== '|';
2992 rvalue
+= 1 + strspn(rvalue
+ 1, WHITESPACE
);
2994 negate
= *rvalue
== '!';
2996 rvalue
+= 1 + strspn(rvalue
+ 1, WHITESPACE
);
2998 r
= unit_full_printf(u
, rvalue
, &s
);
3000 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3001 "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
3005 c
= condition_new(t
, s
, trigger
, negate
);
3009 LIST_PREPEND(conditions
, *list
, c
);
3013 int config_parse_unit_requires_mounts_for(
3015 const char *filename
,
3017 const char *section
,
3018 unsigned section_line
,
3033 for (const char *p
= rvalue
;;) {
3034 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
3036 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3042 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3043 "Invalid syntax, ignoring: %s", rvalue
);
3047 r
= unit_full_printf(u
, word
, &resolved
);
3049 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
3053 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
3057 r
= unit_require_mounts_for(u
, resolved
, UNIT_DEPENDENCY_FILE
);
3059 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to add required mount '%s', ignoring: %m", resolved
);
3065 int config_parse_documentation(const char *unit
,
3066 const char *filename
,
3068 const char *section
,
3069 unsigned section_line
,
3085 if (isempty(rvalue
)) {
3086 /* Empty assignment resets the list */
3087 u
->documentation
= strv_free(u
->documentation
);
3091 r
= config_parse_unit_strv_printf(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
,
3092 rvalue
, data
, userdata
);
3096 for (a
= b
= u
->documentation
; a
&& *a
; a
++) {
3098 if (documentation_url_is_valid(*a
))
3101 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid URL, ignoring: %s", *a
);
3112 int config_parse_syscall_filter(
3114 const char *filename
,
3116 const char *section
,
3117 unsigned section_line
,
3124 ExecContext
*c
= data
;
3125 _unused_
const Unit
*u
= userdata
;
3126 bool invert
= false;
3134 if (isempty(rvalue
)) {
3135 /* Empty assignment resets the list */
3136 c
->syscall_filter
= hashmap_free(c
->syscall_filter
);
3137 c
->syscall_allow_list
= false;
3141 if (rvalue
[0] == '~') {
3146 if (!c
->syscall_filter
) {
3147 c
->syscall_filter
= hashmap_new(NULL
);
3148 if (!c
->syscall_filter
)
3152 /* Allow everything but the ones listed */
3153 c
->syscall_allow_list
= false;
3155 /* Allow nothing but the ones listed */
3156 c
->syscall_allow_list
= true;
3158 /* Accept default syscalls if we are on a allow_list */
3159 r
= seccomp_parse_syscall_filter(
3160 "@default", -1, c
->syscall_filter
,
3161 SECCOMP_PARSE_PERMISSIVE
|SECCOMP_PARSE_ALLOW_LIST
,
3169 for (const char *p
= rvalue
;;) {
3170 _cleanup_free_
char *word
= NULL
, *name
= NULL
;
3173 r
= extract_first_word(&p
, &word
, NULL
, 0);
3179 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3183 r
= parse_syscall_and_errno(word
, &name
, &num
);
3185 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse syscall:errno, ignoring: %s", word
);
3189 r
= seccomp_parse_syscall_filter(
3190 name
, num
, c
->syscall_filter
,
3191 SECCOMP_PARSE_LOG
|SECCOMP_PARSE_PERMISSIVE
|
3192 (invert
? SECCOMP_PARSE_INVERT
: 0)|
3193 (c
->syscall_allow_list
? SECCOMP_PARSE_ALLOW_LIST
: 0),
3194 unit
, filename
, line
);
3200 int config_parse_syscall_archs(
3202 const char *filename
,
3204 const char *section
,
3205 unsigned section_line
,
3215 if (isempty(rvalue
)) {
3216 *archs
= set_free(*archs
);
3220 for (const char *p
= rvalue
;;) {
3221 _cleanup_free_
char *word
= NULL
;
3224 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3230 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3231 "Invalid syntax, ignoring: %s", rvalue
);
3235 r
= seccomp_arch_from_string(word
, &a
);
3237 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3238 "Failed to parse system call architecture \"%s\", ignoring: %m", word
);
3242 r
= set_ensure_put(archs
, NULL
, UINT32_TO_PTR(a
+ 1));
3248 int config_parse_syscall_errno(
3250 const char *filename
,
3252 const char *section
,
3253 unsigned section_line
,
3260 ExecContext
*c
= data
;
3267 if (isempty(rvalue
)) {
3268 /* Empty assignment resets to KILL */
3269 c
->syscall_errno
= 0;
3273 e
= parse_errno(rvalue
);
3275 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Failed to parse error number, ignoring: %s", rvalue
);
3279 c
->syscall_errno
= e
;
3283 int config_parse_address_families(
3285 const char *filename
,
3287 const char *section
,
3288 unsigned section_line
,
3295 ExecContext
*c
= data
;
3296 bool invert
= false;
3303 if (isempty(rvalue
)) {
3304 /* Empty assignment resets the list */
3305 c
->address_families
= set_free(c
->address_families
);
3306 c
->address_families_allow_list
= false;
3310 if (rvalue
[0] == '~') {
3315 if (!c
->address_families
) {
3316 c
->address_families
= set_new(NULL
);
3317 if (!c
->address_families
)
3320 c
->address_families_allow_list
= !invert
;
3323 for (const char *p
= rvalue
;;) {
3324 _cleanup_free_
char *word
= NULL
;
3327 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3333 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3334 "Invalid syntax, ignoring: %s", rvalue
);
3338 af
= af_from_name(word
);
3340 log_syntax(unit
, LOG_WARNING
, filename
, line
, af
,
3341 "Failed to parse address family, ignoring: %s", word
);
3345 /* If we previously wanted to forbid an address family and now
3346 * we want to allow it, then just remove it from the list.
3348 if (!invert
== c
->address_families_allow_list
) {
3349 r
= set_put(c
->address_families
, INT_TO_PTR(af
));
3353 set_remove(c
->address_families
, INT_TO_PTR(af
));
3357 int config_parse_restrict_namespaces(
3359 const char *filename
,
3361 const char *section
,
3362 unsigned section_line
,
3369 ExecContext
*c
= data
;
3370 unsigned long flags
;
3371 bool invert
= false;
3374 if (isempty(rvalue
)) {
3375 /* Reset to the default. */
3376 c
->restrict_namespaces
= NAMESPACE_FLAGS_INITIAL
;
3380 /* Boolean parameter ignores the previous settings */
3381 r
= parse_boolean(rvalue
);
3383 c
->restrict_namespaces
= 0;
3385 } else if (r
== 0) {
3386 c
->restrict_namespaces
= NAMESPACE_FLAGS_ALL
;
3390 if (rvalue
[0] == '~') {
3395 /* Not a boolean argument, in this case it's a list of namespace types. */
3396 r
= namespace_flags_from_string(rvalue
, &flags
);
3398 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse namespace type string, ignoring: %s", rvalue
);
3402 if (c
->restrict_namespaces
== NAMESPACE_FLAGS_INITIAL
)
3403 /* Initial assignment. Just set the value. */
3404 c
->restrict_namespaces
= invert
? (~flags
) & NAMESPACE_FLAGS_ALL
: flags
;
3406 /* Merge the value with the previous one. */
3407 SET_FLAG(c
->restrict_namespaces
, flags
, !invert
);
3413 int config_parse_unit_slice(
3415 const char *filename
,
3417 const char *section
,
3418 unsigned section_line
,
3425 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
3426 _cleanup_free_
char *k
= NULL
;
3427 Unit
*u
= userdata
, *slice
;
3435 r
= unit_name_printf(u
, rvalue
, &k
);
3437 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
3441 r
= manager_load_unit(u
->manager
, k
, NULL
, &error
, &slice
);
3443 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to load slice unit %s, ignoring: %s", k
, bus_error_message(&error
, r
));
3447 r
= unit_set_slice(u
, slice
);
3449 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to assign slice %s to unit %s, ignoring: %m", slice
->id
, u
->id
);
3456 int config_parse_cpu_quota(
3458 const char *filename
,
3460 const char *section
,
3461 unsigned section_line
,
3468 CGroupContext
*c
= data
;
3475 if (isempty(rvalue
)) {
3476 c
->cpu_quota_per_sec_usec
= USEC_INFINITY
;
3480 r
= parse_permille_unbounded(rvalue
);
3482 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid CPU quota '%s', ignoring.", rvalue
);
3486 c
->cpu_quota_per_sec_usec
= ((usec_t
) r
* USEC_PER_SEC
) / 1000U;
3490 int config_parse_allowed_cpus(
3492 const char *filename
,
3494 const char *section
,
3495 unsigned section_line
,
3502 CGroupContext
*c
= data
;
3504 (void) parse_cpu_set_extend(rvalue
, &c
->cpuset_cpus
, true, unit
, filename
, line
, lvalue
);
3509 int config_parse_allowed_mems(
3511 const char *filename
,
3513 const char *section
,
3514 unsigned section_line
,
3521 CGroupContext
*c
= data
;
3523 (void) parse_cpu_set_extend(rvalue
, &c
->cpuset_mems
, true, unit
, filename
, line
, lvalue
);
3528 int config_parse_memory_limit(
3530 const char *filename
,
3532 const char *section
,
3533 unsigned section_line
,
3540 CGroupContext
*c
= data
;
3541 uint64_t bytes
= CGROUP_LIMIT_MAX
;
3544 if (isempty(rvalue
) && STR_IN_SET(lvalue
, "DefaultMemoryLow",
3548 bytes
= CGROUP_LIMIT_MIN
;
3549 else if (!isempty(rvalue
) && !streq(rvalue
, "infinity")) {
3551 r
= parse_permille(rvalue
);
3553 r
= parse_size(rvalue
, 1024, &bytes
);
3555 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid memory limit '%s', ignoring: %m", rvalue
);
3559 bytes
= physical_memory_scale(r
, 1000U);
3561 if (bytes
>= UINT64_MAX
||
3562 (bytes
<= 0 && !STR_IN_SET(lvalue
, "MemorySwapMax", "MemoryLow", "MemoryMin", "DefaultMemoryLow", "DefaultMemoryMin"))) {
3563 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Memory limit '%s' out of range, ignoring.", rvalue
);
3568 if (streq(lvalue
, "DefaultMemoryLow")) {
3569 c
->default_memory_low
= bytes
;
3570 c
->default_memory_low_set
= true;
3571 } else if (streq(lvalue
, "DefaultMemoryMin")) {
3572 c
->default_memory_min
= bytes
;
3573 c
->default_memory_min_set
= true;
3574 } else if (streq(lvalue
, "MemoryMin")) {
3575 c
->memory_min
= bytes
;
3576 c
->memory_min_set
= true;
3577 } else if (streq(lvalue
, "MemoryLow")) {
3578 c
->memory_low
= bytes
;
3579 c
->memory_low_set
= true;
3580 } else if (streq(lvalue
, "MemoryHigh"))
3581 c
->memory_high
= bytes
;
3582 else if (streq(lvalue
, "MemoryMax"))
3583 c
->memory_max
= bytes
;
3584 else if (streq(lvalue
, "MemorySwapMax"))
3585 c
->memory_swap_max
= bytes
;
3586 else if (streq(lvalue
, "MemoryLimit"))
3587 c
->memory_limit
= bytes
;
3594 int config_parse_tasks_max(
3596 const char *filename
,
3598 const char *section
,
3599 unsigned section_line
,
3606 const Unit
*u
= userdata
;
3607 TasksMax
*tasks_max
= data
;
3611 if (isempty(rvalue
)) {
3612 *tasks_max
= u
? u
->manager
->default_tasks_max
: TASKS_MAX_UNSET
;
3616 if (streq(rvalue
, "infinity")) {
3617 *tasks_max
= TASKS_MAX_UNSET
;
3621 r
= parse_permille(rvalue
);
3623 *tasks_max
= (TasksMax
) { r
, 1000U }; /* r‰ */
3625 r
= safe_atou64(rvalue
, &v
);
3627 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid maximum tasks value '%s', ignoring: %m", rvalue
);
3631 if (v
<= 0 || v
>= UINT64_MAX
) {
3632 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Maximum tasks value '%s' out of range, ignoring.", rvalue
);
3636 *tasks_max
= (TasksMax
) { v
};
3642 int config_parse_delegate(
3644 const char *filename
,
3646 const char *section
,
3647 unsigned section_line
,
3654 CGroupContext
*c
= data
;
3658 t
= unit_name_to_type(unit
);
3659 assert(t
!= _UNIT_TYPE_INVALID
);
3661 if (!unit_vtable
[t
]->can_delegate
) {
3662 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Delegate= setting not supported for this unit type, ignoring.");
3666 /* We either accept a boolean value, which may be used to turn on delegation for all controllers, or turn it
3667 * off for all. Or it takes a list of controller names, in which case we add the specified controllers to the
3668 * mask to delegate. */
3670 if (isempty(rvalue
)) {
3671 /* An empty string resets controllers and set Delegate=yes. */
3673 c
->delegate_controllers
= 0;
3677 r
= parse_boolean(rvalue
);
3679 CGroupMask mask
= 0;
3681 for (const char *p
= rvalue
;;) {
3682 _cleanup_free_
char *word
= NULL
;
3683 CGroupController cc
;
3685 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3691 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3695 cc
= cgroup_controller_from_string(word
);
3697 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid controller name '%s', ignoring", word
);
3701 mask
|= CGROUP_CONTROLLER_TO_MASK(cc
);
3705 c
->delegate_controllers
|= mask
;
3709 c
->delegate_controllers
= _CGROUP_MASK_ALL
;
3711 c
->delegate
= false;
3712 c
->delegate_controllers
= 0;
3718 int config_parse_device_allow(
3720 const char *filename
,
3722 const char *section
,
3723 unsigned section_line
,
3730 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3731 CGroupContext
*c
= data
;
3732 const char *p
= rvalue
;
3735 if (isempty(rvalue
)) {
3736 while (c
->device_allow
)
3737 cgroup_context_free_device_allow(c
, c
->device_allow
);
3742 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3746 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3747 "Invalid syntax, ignoring: %s", rvalue
);
3751 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3752 "Failed to extract device path and rights from '%s', ignoring.", rvalue
);
3756 r
= unit_full_printf(userdata
, path
, &resolved
);
3758 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3759 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3763 if (!STARTSWITH_SET(resolved
, "block-", "char-")) {
3765 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3769 if (!valid_device_node_path(resolved
)) {
3770 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid device node path '%s', ignoring.", resolved
);
3775 if (!isempty(p
) && !in_charset(p
, "rwm")) {
3776 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid device rights '%s', ignoring.", p
);
3780 return cgroup_add_device_allow(c
, resolved
, p
);
3783 int config_parse_io_device_weight(
3785 const char *filename
,
3787 const char *section
,
3788 unsigned section_line
,
3795 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3796 CGroupIODeviceWeight
*w
;
3797 CGroupContext
*c
= data
;
3798 const char *p
= rvalue
;
3806 if (isempty(rvalue
)) {
3807 while (c
->io_device_weights
)
3808 cgroup_context_free_io_device_weight(c
, c
->io_device_weights
);
3813 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3817 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3818 "Invalid syntax, ignoring: %s", rvalue
);
3821 if (r
== 0 || isempty(p
)) {
3822 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3823 "Failed to extract device path and weight from '%s', ignoring.", rvalue
);
3827 r
= unit_full_printf(userdata
, path
, &resolved
);
3829 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3830 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3834 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3838 r
= cg_weight_parse(p
, &u
);
3840 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "IO weight '%s' invalid, ignoring: %m", p
);
3844 assert(u
!= CGROUP_WEIGHT_INVALID
);
3846 w
= new0(CGroupIODeviceWeight
, 1);
3850 w
->path
= TAKE_PTR(resolved
);
3853 LIST_PREPEND(device_weights
, c
->io_device_weights
, w
);
3857 int config_parse_io_device_latency(
3859 const char *filename
,
3861 const char *section
,
3862 unsigned section_line
,
3869 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3870 CGroupIODeviceLatency
*l
;
3871 CGroupContext
*c
= data
;
3872 const char *p
= rvalue
;
3880 if (isempty(rvalue
)) {
3881 while (c
->io_device_latencies
)
3882 cgroup_context_free_io_device_latency(c
, c
->io_device_latencies
);
3887 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3891 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3892 "Invalid syntax, ignoring: %s", rvalue
);
3895 if (r
== 0 || isempty(p
)) {
3896 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3897 "Failed to extract device path and latency from '%s', ignoring.", rvalue
);
3901 r
= unit_full_printf(userdata
, path
, &resolved
);
3903 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3904 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3908 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3912 r
= parse_sec(p
, &usec
);
3914 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse timer value, ignoring: %s", p
);
3918 l
= new0(CGroupIODeviceLatency
, 1);
3922 l
->path
= TAKE_PTR(resolved
);
3923 l
->target_usec
= usec
;
3925 LIST_PREPEND(device_latencies
, c
->io_device_latencies
, l
);
3929 int config_parse_io_limit(
3931 const char *filename
,
3933 const char *section
,
3934 unsigned section_line
,
3941 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3942 CGroupIODeviceLimit
*l
= NULL
, *t
;
3943 CGroupContext
*c
= data
;
3944 CGroupIOLimitType type
;
3945 const char *p
= rvalue
;
3953 type
= cgroup_io_limit_type_from_string(lvalue
);
3956 if (isempty(rvalue
)) {
3957 LIST_FOREACH(device_limits
, l
, c
->io_device_limits
)
3958 l
->limits
[type
] = cgroup_io_limit_defaults
[type
];
3962 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3966 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3967 "Invalid syntax, ignoring: %s", rvalue
);
3970 if (r
== 0 || isempty(p
)) {
3971 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3972 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
3976 r
= unit_full_printf(userdata
, path
, &resolved
);
3978 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3979 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3983 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3987 if (streq("infinity", p
))
3988 num
= CGROUP_LIMIT_MAX
;
3990 r
= parse_size(p
, 1000, &num
);
3991 if (r
< 0 || num
<= 0) {
3992 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid IO limit '%s', ignoring.", p
);
3997 LIST_FOREACH(device_limits
, t
, c
->io_device_limits
) {
3998 if (path_equal(resolved
, t
->path
)) {
4005 CGroupIOLimitType ttype
;
4007 l
= new0(CGroupIODeviceLimit
, 1);
4011 l
->path
= TAKE_PTR(resolved
);
4012 for (ttype
= 0; ttype
< _CGROUP_IO_LIMIT_TYPE_MAX
; ttype
++)
4013 l
->limits
[ttype
] = cgroup_io_limit_defaults
[ttype
];
4015 LIST_PREPEND(device_limits
, c
->io_device_limits
, l
);
4018 l
->limits
[type
] = num
;
4023 int config_parse_blockio_device_weight(
4025 const char *filename
,
4027 const char *section
,
4028 unsigned section_line
,
4035 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4036 CGroupBlockIODeviceWeight
*w
;
4037 CGroupContext
*c
= data
;
4038 const char *p
= rvalue
;
4046 if (isempty(rvalue
)) {
4047 while (c
->blockio_device_weights
)
4048 cgroup_context_free_blockio_device_weight(c
, c
->blockio_device_weights
);
4053 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4057 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4058 "Invalid syntax, ignoring: %s", rvalue
);
4061 if (r
== 0 || isempty(p
)) {
4062 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4063 "Failed to extract device node and weight from '%s', ignoring.", rvalue
);
4067 r
= unit_full_printf(userdata
, path
, &resolved
);
4069 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4070 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4074 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4078 r
= cg_blkio_weight_parse(p
, &u
);
4080 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid block IO weight '%s', ignoring: %m", p
);
4084 assert(u
!= CGROUP_BLKIO_WEIGHT_INVALID
);
4086 w
= new0(CGroupBlockIODeviceWeight
, 1);
4090 w
->path
= TAKE_PTR(resolved
);
4093 LIST_PREPEND(device_weights
, c
->blockio_device_weights
, w
);
4097 int config_parse_blockio_bandwidth(
4099 const char *filename
,
4101 const char *section
,
4102 unsigned section_line
,
4109 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4110 CGroupBlockIODeviceBandwidth
*b
= NULL
, *t
;
4111 CGroupContext
*c
= data
;
4112 const char *p
= rvalue
;
4121 read
= streq("BlockIOReadBandwidth", lvalue
);
4123 if (isempty(rvalue
)) {
4124 LIST_FOREACH(device_bandwidths
, b
, c
->blockio_device_bandwidths
) {
4125 b
->rbps
= CGROUP_LIMIT_MAX
;
4126 b
->wbps
= CGROUP_LIMIT_MAX
;
4131 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4135 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4136 "Invalid syntax, ignoring: %s", rvalue
);
4139 if (r
== 0 || isempty(p
)) {
4140 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4141 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
4145 r
= unit_full_printf(userdata
, path
, &resolved
);
4147 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4148 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4152 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4156 r
= parse_size(p
, 1000, &bytes
);
4157 if (r
< 0 || bytes
<= 0) {
4158 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid Block IO Bandwidth '%s', ignoring.", p
);
4162 LIST_FOREACH(device_bandwidths
, t
, c
->blockio_device_bandwidths
) {
4163 if (path_equal(resolved
, t
->path
)) {
4170 b
= new0(CGroupBlockIODeviceBandwidth
, 1);
4174 b
->path
= TAKE_PTR(resolved
);
4175 b
->rbps
= CGROUP_LIMIT_MAX
;
4176 b
->wbps
= CGROUP_LIMIT_MAX
;
4178 LIST_PREPEND(device_bandwidths
, c
->blockio_device_bandwidths
, b
);
4189 int config_parse_job_mode_isolate(
4191 const char *filename
,
4193 const char *section
,
4194 unsigned section_line
,
4208 r
= parse_boolean(rvalue
);
4210 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse boolean, ignoring: %s", rvalue
);
4214 log_notice("%s is deprecated. Please use OnFailureJobMode= instead", lvalue
);
4216 *m
= r
? JOB_ISOLATE
: JOB_REPLACE
;
4220 int config_parse_exec_directories(
4222 const char *filename
,
4224 const char *section
,
4225 unsigned section_line
,
4233 const Unit
*u
= userdata
;
4241 if (isempty(rvalue
)) {
4242 /* Empty assignment resets the list */
4243 *rt
= strv_free(*rt
);
4247 for (const char *p
= rvalue
;;) {
4248 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
4250 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
4254 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4255 "Invalid syntax, ignoring: %s", rvalue
);
4261 r
= unit_full_printf(u
, word
, &k
);
4263 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4264 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
4268 r
= path_simplify_and_warn(k
, PATH_CHECK_RELATIVE
, unit
, filename
, line
, lvalue
);
4272 if (path_startswith(k
, "private")) {
4273 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4274 "%s= path can't be 'private', ignoring assignment: %s", lvalue
, word
);
4278 r
= strv_push(rt
, k
);
4285 int config_parse_set_credential(
4287 const char *filename
,
4289 const char *section
,
4290 unsigned section_line
,
4297 _cleanup_free_
char *word
= NULL
, *k
= NULL
, *unescaped
= NULL
;
4298 ExecContext
*context
= data
;
4299 ExecSetCredential
*old
;
4309 if (isempty(rvalue
)) {
4310 /* Empty assignment resets the list */
4311 context
->set_credentials
= hashmap_free(context
->set_credentials
);
4316 r
= extract_first_word(&p
, &word
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4320 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
4324 r
= unit_full_printf(u
, word
, &k
);
4326 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
4329 if (!credential_name_valid(k
)) {
4330 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Credential name \"%s\" not valid, ignoring.", k
);
4334 /* We support escape codes here, so that users can insert trailing \n if they like */
4335 l
= cunescape(p
, UNESCAPE_ACCEPT_NUL
, &unescaped
);
4337 log_syntax(unit
, LOG_WARNING
, filename
, line
, l
, "Can't unescape \"%s\", ignoring: %m", p
);
4341 old
= hashmap_get(context
->set_credentials
, k
);
4343 free_and_replace(old
->data
, unescaped
);
4346 _cleanup_(exec_set_credential_freep
) ExecSetCredential
*sc
= NULL
;
4348 sc
= new0(ExecSetCredential
, 1);
4352 sc
->id
= TAKE_PTR(k
);
4353 sc
->data
= TAKE_PTR(unescaped
);
4356 r
= hashmap_ensure_allocated(&context
->set_credentials
, &exec_set_credential_hash_ops
);
4360 r
= hashmap_put(context
->set_credentials
, sc
->id
, sc
);
4370 int config_parse_load_credential(
4372 const char *filename
,
4374 const char *section
,
4375 unsigned section_line
,
4382 _cleanup_free_
char *word
= NULL
, *k
= NULL
, *q
= NULL
;
4383 ExecContext
*context
= data
;
4393 if (isempty(rvalue
)) {
4394 /* Empty assignment resets the list */
4395 context
->load_credentials
= strv_free(context
->load_credentials
);
4400 r
= extract_first_word(&p
, &word
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4404 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
4408 r
= unit_full_printf(u
, word
, &k
);
4410 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
4413 if (!credential_name_valid(k
)) {
4414 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Credential name \"%s\" not valid, ignoring.", k
);
4417 r
= unit_full_printf(u
, p
, &q
);
4419 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in \"%s\", ignoring: %m", p
);
4422 if (path_is_absolute(q
) ? !path_is_normalized(q
) : !credential_name_valid(q
)) {
4423 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Credential source \"%s\" not valid, ignoring.", q
);
4427 r
= strv_consume_pair(&context
->load_credentials
, TAKE_PTR(k
), TAKE_PTR(q
));
4434 int config_parse_set_status(
4436 const char *filename
,
4438 const char *section
,
4439 unsigned section_line
,
4446 ExitStatusSet
*status_set
= data
;
4454 /* Empty assignment resets the list */
4455 if (isempty(rvalue
)) {
4456 exit_status_set_free(status_set
);
4460 for (const char *p
= rvalue
;;) {
4461 _cleanup_free_
char *word
= NULL
;
4464 r
= extract_first_word(&p
, &word
, NULL
, 0);
4468 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4469 "Failed to parse %s=%s, ignoring: %m", lvalue
, rvalue
);
4475 /* We need to call exit_status_from_string() first, because we want
4476 * to parse numbers as exit statuses, not signals. */
4478 r
= exit_status_from_string(word
);
4480 assert(r
>= 0 && r
< 256);
4481 bitmap
= &status_set
->status
;
4483 r
= signal_from_string(word
);
4485 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4486 "Failed to parse value, ignoring: %s", word
);
4489 bitmap
= &status_set
->signal
;
4492 r
= bitmap_set(bitmap
, r
);
4494 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4495 "Failed to set signal or status %s, ignoring: %m", word
);
4499 int config_parse_namespace_path_strv(
4501 const char *filename
,
4503 const char *section
,
4504 unsigned section_line
,
4511 const Unit
*u
= userdata
;
4520 if (isempty(rvalue
)) {
4521 /* Empty assignment resets the list */
4522 *sv
= strv_free(*sv
);
4526 for (const char *p
= rvalue
;;) {
4527 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
, *joined
= NULL
;
4529 bool ignore_enoent
= false, shall_prefix
= false;
4531 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
4537 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
4542 if (startswith(w
, "-")) {
4543 ignore_enoent
= true;
4546 if (startswith(w
, "+")) {
4547 shall_prefix
= true;
4551 r
= unit_full_printf(u
, w
, &resolved
);
4553 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", w
);
4557 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4561 joined
= strjoin(ignore_enoent
? "-" : "",
4562 shall_prefix
? "+" : "",
4565 r
= strv_push(sv
, joined
);
4575 int config_parse_temporary_filesystems(
4577 const char *filename
,
4579 const char *section
,
4580 unsigned section_line
,
4587 const Unit
*u
= userdata
;
4588 ExecContext
*c
= data
;
4596 if (isempty(rvalue
)) {
4597 /* Empty assignment resets the list */
4598 temporary_filesystem_free_many(c
->temporary_filesystems
, c
->n_temporary_filesystems
);
4599 c
->temporary_filesystems
= NULL
;
4600 c
->n_temporary_filesystems
= 0;
4604 for (const char *p
= rvalue
;;) {
4605 _cleanup_free_
char *word
= NULL
, *path
= NULL
, *resolved
= NULL
;
4608 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
4614 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
4619 r
= extract_first_word(&w
, &path
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4623 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", word
);
4627 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid syntax, ignoring: %s", word
);
4631 r
= unit_full_printf(u
, path
, &resolved
);
4633 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", path
);
4637 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4641 r
= temporary_filesystem_add(&c
->temporary_filesystems
, &c
->n_temporary_filesystems
, resolved
, w
);
4647 int config_parse_bind_paths(
4649 const char *filename
,
4651 const char *section
,
4652 unsigned section_line
,
4659 ExecContext
*c
= data
;
4660 const Unit
*u
= userdata
;
4668 if (isempty(rvalue
)) {
4669 /* Empty assignment resets the list */
4670 bind_mount_free_many(c
->bind_mounts
, c
->n_bind_mounts
);
4671 c
->bind_mounts
= NULL
;
4672 c
->n_bind_mounts
= 0;
4676 for (const char *p
= rvalue
;;) {
4677 _cleanup_free_
char *source
= NULL
, *destination
= NULL
;
4678 _cleanup_free_
char *sresolved
= NULL
, *dresolved
= NULL
;
4679 char *s
= NULL
, *d
= NULL
;
4680 bool rbind
= true, ignore_enoent
= false;
4682 r
= extract_first_word(&p
, &source
, ":" WHITESPACE
, EXTRACT_UNQUOTE
|EXTRACT_DONT_COALESCE_SEPARATORS
);
4688 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
4692 r
= unit_full_printf(u
, source
, &sresolved
);
4694 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4695 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", source
);
4701 ignore_enoent
= true;
4705 r
= path_simplify_and_warn(s
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4709 /* Optionally, the destination is specified. */
4710 if (p
&& p
[-1] == ':') {
4711 r
= extract_first_word(&p
, &destination
, ":" WHITESPACE
, EXTRACT_UNQUOTE
|EXTRACT_DONT_COALESCE_SEPARATORS
);
4715 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
4719 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Missing argument after ':', ignoring: %s", s
);
4723 r
= unit_full_printf(u
, destination
, &dresolved
);
4725 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4726 "Failed to resolve specifiers in \"%s\", ignoring: %m", destination
);
4730 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4736 /* Optionally, there's also a short option string specified */
4737 if (p
&& p
[-1] == ':') {
4738 _cleanup_free_
char *options
= NULL
;
4740 r
= extract_first_word(&p
, &options
, NULL
, EXTRACT_UNQUOTE
);
4744 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse %s: %s", lvalue
, rvalue
);
4748 if (isempty(options
) || streq(options
, "rbind"))
4750 else if (streq(options
, "norbind"))
4753 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid option string, ignoring setting: %s", options
);
4760 r
= bind_mount_add(&c
->bind_mounts
, &c
->n_bind_mounts
,
4764 .read_only
= !!strstr(lvalue
, "ReadOnly"),
4766 .ignore_enoent
= ignore_enoent
,
4775 int config_parse_mount_images(
4777 const char *filename
,
4779 const char *section
,
4780 unsigned section_line
,
4787 ExecContext
*c
= data
;
4788 const Unit
*u
= userdata
;
4796 if (isempty(rvalue
)) {
4797 /* Empty assignment resets the list */
4798 c
->mount_images
= mount_image_free_many(c
->mount_images
, &c
->n_mount_images
);
4802 for (const char *p
= rvalue
;;) {
4803 _cleanup_(mount_options_free_allp
) MountOptions
*options
= NULL
;
4804 _cleanup_free_
char *first
= NULL
, *second
= NULL
, *tuple
= NULL
;
4805 _cleanup_free_
char *sresolved
= NULL
, *dresolved
= NULL
;
4806 const char *q
= NULL
;
4808 bool permissive
= false;
4810 r
= extract_first_word(&p
, &tuple
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_RETAIN_ESCAPE
);
4814 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4815 "Invalid syntax %s=%s, ignoring: %m", lvalue
, rvalue
);
4822 r
= extract_many_words(&q
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
, &first
, &second
, NULL
);
4826 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4827 "Invalid syntax in %s=, ignoring: %s", lvalue
, tuple
);
4833 r
= unit_full_printf(u
, first
, &sresolved
);
4835 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4836 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", first
);
4846 r
= path_simplify_and_warn(s
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4850 if (isempty(second
)) {
4851 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Missing destination in %s, ignoring: %s", lvalue
, rvalue
);
4855 r
= unit_full_printf(u
, second
, &dresolved
);
4857 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4858 "Failed to resolve specifiers in \"%s\", ignoring: %m", second
);
4862 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4867 _cleanup_free_
char *partition
= NULL
, *mount_options
= NULL
, *mount_options_resolved
= NULL
;
4868 MountOptions
*o
= NULL
;
4869 int partition_designator
;
4871 r
= extract_many_words(&q
, ":", EXTRACT_CUNESCAPE
|EXTRACT_UNESCAPE_SEPARATORS
, &partition
, &mount_options
, NULL
);
4875 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", q
);
4880 /* Single set of options, applying to the root partition/single filesystem */
4882 r
= unit_full_printf(u
, partition
, &mount_options_resolved
);
4884 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", first
);
4888 o
= new(MountOptions
, 1);
4891 *o
= (MountOptions
) {
4892 .partition_designator
= PARTITION_ROOT
,
4893 .options
= TAKE_PTR(mount_options_resolved
),
4895 LIST_APPEND(mount_options
, options
, o
);
4900 partition_designator
= partition_designator_from_string(partition
);
4901 if (partition_designator
< 0) {
4902 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Invalid partition name %s, ignoring", partition
);
4905 r
= unit_full_printf(u
, mount_options
, &mount_options_resolved
);
4907 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", mount_options
);
4911 o
= new(MountOptions
, 1);
4914 *o
= (MountOptions
) {
4915 .partition_designator
= partition_designator
,
4916 .options
= TAKE_PTR(mount_options_resolved
),
4918 LIST_APPEND(mount_options
, options
, o
);
4921 r
= mount_image_add(&c
->mount_images
, &c
->n_mount_images
,
4924 .destination
= dresolved
,
4925 .mount_options
= options
,
4926 .ignore_enoent
= permissive
,
4933 int config_parse_job_timeout_sec(
4935 const char *filename
,
4937 const char *section
,
4938 unsigned section_line
,
4954 r
= parse_sec_fix_0(rvalue
, &usec
);
4956 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse JobTimeoutSec= parameter, ignoring: %s", rvalue
);
4960 /* If the user explicitly changed JobTimeoutSec= also change JobRunningTimeoutSec=, for compatibility with old
4961 * versions. If JobRunningTimeoutSec= was explicitly set, avoid this however as whatever the user picked should
4964 if (!u
->job_running_timeout_set
)
4965 u
->job_running_timeout
= usec
;
4967 u
->job_timeout
= usec
;
4972 int config_parse_job_running_timeout_sec(
4974 const char *filename
,
4976 const char *section
,
4977 unsigned section_line
,
4993 r
= parse_sec_fix_0(rvalue
, &usec
);
4995 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse JobRunningTimeoutSec= parameter, ignoring: %s", rvalue
);
4999 u
->job_running_timeout
= usec
;
5000 u
->job_running_timeout_set
= true;
5005 int config_parse_emergency_action(
5007 const char *filename
,
5009 const char *section
,
5010 unsigned section_line
,
5018 EmergencyAction
*x
= data
;
5027 m
= ((Unit
*) userdata
)->manager
;
5031 r
= parse_emergency_action(rvalue
, MANAGER_IS_SYSTEM(m
), x
);
5033 if (r
== -EOPNOTSUPP
&& MANAGER_IS_USER(m
)) {
5034 /* Compat mode: remove for systemd 241. */
5036 log_syntax(unit
, LOG_INFO
, filename
, line
, r
,
5037 "%s= in user mode specified as \"%s\", using \"exit-force\" instead.",
5039 *x
= EMERGENCY_ACTION_EXIT_FORCE
;
5043 if (r
== -EOPNOTSUPP
)
5044 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5045 "%s= specified as %s mode action, ignoring: %s",
5046 lvalue
, MANAGER_IS_SYSTEM(m
) ? "user" : "system", rvalue
);
5048 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
5049 "Failed to parse %s=, ignoring: %s", lvalue
, rvalue
);
5056 int config_parse_pid_file(
5058 const char *filename
,
5060 const char *section
,
5061 unsigned section_line
,
5068 _cleanup_free_
char *k
= NULL
, *n
= NULL
;
5069 const Unit
*u
= userdata
;
5078 if (isempty(rvalue
)) {
5079 /* An empty assignment removes already set value. */
5084 r
= unit_full_printf(u
, rvalue
, &k
);
5086 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
5090 /* If this is a relative path make it absolute by prefixing the /run */
5091 n
= path_make_absolute(k
, u
->manager
->prefix
[EXEC_DIRECTORY_RUNTIME
]);
5095 /* Check that the result is a sensible path */
5096 r
= path_simplify_and_warn(n
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5100 r
= patch_var_run(unit
, filename
, line
, lvalue
, &n
);
5104 free_and_replace(*s
, n
);
5108 int config_parse_exit_status(
5110 const char *filename
,
5112 const char *section
,
5113 unsigned section_line
,
5120 int *exit_status
= data
, r
;
5126 assert(exit_status
);
5128 if (isempty(rvalue
)) {
5133 r
= safe_atou8(rvalue
, &u
);
5135 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse exit status '%s', ignoring: %m", rvalue
);
5143 int config_parse_disable_controllers(
5145 const char *filename
,
5147 const char *section
,
5148 unsigned section_line
,
5156 CGroupContext
*c
= data
;
5157 CGroupMask disabled_mask
;
5159 /* 1. If empty, make all controllers eligible for use again.
5160 * 2. If non-empty, merge all listed controllers, space separated. */
5162 if (isempty(rvalue
)) {
5163 c
->disable_controllers
= 0;
5167 r
= cg_mask_from_string(rvalue
, &disabled_mask
);
5168 if (r
< 0 || disabled_mask
<= 0) {
5169 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid cgroup string: %s, ignoring", rvalue
);
5173 c
->disable_controllers
|= disabled_mask
;
5178 int config_parse_ip_filter_bpf_progs(
5180 const char *filename
,
5182 const char *section
,
5183 unsigned section_line
,
5190 _cleanup_free_
char *resolved
= NULL
;
5191 const Unit
*u
= userdata
;
5192 char ***paths
= data
;
5200 if (isempty(rvalue
)) {
5201 *paths
= strv_free(*paths
);
5205 r
= unit_full_printf(u
, rvalue
, &resolved
);
5207 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
5211 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5215 if (strv_contains(*paths
, resolved
))
5218 r
= strv_extend(paths
, resolved
);
5222 r
= bpf_firewall_supported();
5225 if (r
!= BPF_FIREWALL_SUPPORTED_WITH_MULTI
) {
5226 static bool warned
= false;
5228 log_full(warned
? LOG_DEBUG
: LOG_WARNING
,
5229 "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"
5230 "Starting this unit will fail! (This warning is only shown for the first loaded unit using IP firewalling.)", filename
, line
, lvalue
, rvalue
);
5238 static int merge_by_names(Unit
**u
, Set
*names
, const char *id
) {
5245 /* Let's try to add in all names that are aliases of this unit */
5246 while ((k
= set_steal_first(names
))) {
5247 _cleanup_free_ _unused_
char *free_k
= k
;
5249 /* First try to merge in the other name into our unit */
5250 r
= unit_merge_by_name(*u
, k
);
5254 /* Hmm, we couldn't merge the other unit into ours? Then let's try it the other way
5257 other
= manager_get_unit((*u
)->manager
, k
);
5259 return r
; /* return previous failure */
5261 r
= unit_merge(other
, *u
);
5266 return merge_by_names(u
, names
, NULL
);
5269 if (streq_ptr(id
, k
))
5270 unit_choose_id(*u
, id
);
5276 int unit_load_fragment(Unit
*u
) {
5277 const char *fragment
;
5278 _cleanup_set_free_free_ Set
*names
= NULL
;
5282 assert(u
->load_state
== UNIT_STUB
);
5286 u
->load_state
= UNIT_LOADED
;
5290 /* Possibly rebuild the fragment map to catch new units */
5291 r
= unit_file_build_name_map(&u
->manager
->lookup_paths
,
5292 &u
->manager
->unit_cache_timestamp_hash
,
5293 &u
->manager
->unit_id_map
,
5294 &u
->manager
->unit_name_map
,
5295 &u
->manager
->unit_path_cache
);
5297 return log_error_errno(r
, "Failed to rebuild name map: %m");
5299 r
= unit_file_find_fragment(u
->manager
->unit_id_map
,
5300 u
->manager
->unit_name_map
,
5304 if (r
< 0 && r
!= -ENOENT
)
5308 /* Open the file, check if this is a mask, otherwise read. */
5309 _cleanup_fclose_
FILE *f
= NULL
;
5312 /* Try to open the file name. A symlink is OK, for example for linked files or masks. We
5313 * expect that all symlinks within the lookup paths have been already resolved, but we don't
5314 * verify this here. */
5315 f
= fopen(fragment
, "re");
5317 return log_unit_notice_errno(u
, errno
, "Failed to open %s: %m", fragment
);
5319 if (fstat(fileno(f
), &st
) < 0)
5322 r
= free_and_strdup(&u
->fragment_path
, fragment
);
5326 if (null_or_empty(&st
)) {
5327 /* Unit file is masked */
5329 u
->load_state
= u
->perpetual
? UNIT_LOADED
: UNIT_MASKED
; /* don't allow perpetual units to ever be masked */
5330 u
->fragment_mtime
= 0;
5332 u
->load_state
= UNIT_LOADED
;
5333 u
->fragment_mtime
= timespec_load(&st
.st_mtim
);
5335 /* Now, parse the file contents */
5336 r
= config_parse(u
->id
, fragment
, f
,
5337 UNIT_VTABLE(u
)->sections
,
5338 config_item_perf_lookup
, load_fragment_gperf_lookup
,
5343 log_unit_notice_errno(u
, r
, "Unit configuration has fatal error, unit will not be started.");
5349 /* We do the merge dance here because for some unit types, the unit might have aliases which are not
5350 * declared in the file system. In particular, this is true (and frequent) for device and swap units.
5353 const char *id
= u
->id
;
5354 _cleanup_free_
char *free_id
= NULL
;
5357 id
= basename(fragment
);
5358 if (unit_name_is_valid(id
, UNIT_NAME_TEMPLATE
)) {
5359 assert(u
->instance
); /* If we're not trying to use a template for non-instanced unit,
5360 * this must be set. */
5362 r
= unit_name_replace_instance(id
, u
->instance
, &free_id
);
5364 return log_debug_errno(r
, "Failed to build id (%s + %s): %m", id
, u
->instance
);
5370 r
= merge_by_names(&merged
, names
, id
);
5375 u
->load_state
= UNIT_MERGED
;
5380 void unit_dump_config_items(FILE *f
) {
5381 static const struct {
5382 const ConfigParserCallback callback
;
5385 { config_parse_warn_compat
, "NOTSUPPORTED" },
5386 { config_parse_int
, "INTEGER" },
5387 { config_parse_unsigned
, "UNSIGNED" },
5388 { config_parse_iec_size
, "SIZE" },
5389 { config_parse_iec_uint64
, "SIZE" },
5390 { config_parse_si_uint64
, "SIZE" },
5391 { config_parse_bool
, "BOOLEAN" },
5392 { config_parse_string
, "STRING" },
5393 { config_parse_path
, "PATH" },
5394 { config_parse_unit_path_printf
, "PATH" },
5395 { config_parse_strv
, "STRING [...]" },
5396 { config_parse_exec_nice
, "NICE" },
5397 { config_parse_exec_oom_score_adjust
, "OOMSCOREADJUST" },
5398 { config_parse_exec_io_class
, "IOCLASS" },
5399 { config_parse_exec_io_priority
, "IOPRIORITY" },
5400 { config_parse_exec_cpu_sched_policy
, "CPUSCHEDPOLICY" },
5401 { config_parse_exec_cpu_sched_prio
, "CPUSCHEDPRIO" },
5402 { config_parse_exec_cpu_affinity
, "CPUAFFINITY" },
5403 { config_parse_mode
, "MODE" },
5404 { config_parse_unit_env_file
, "FILE" },
5405 { config_parse_exec_output
, "OUTPUT" },
5406 { config_parse_exec_input
, "INPUT" },
5407 { config_parse_log_facility
, "FACILITY" },
5408 { config_parse_log_level
, "LEVEL" },
5409 { config_parse_exec_secure_bits
, "SECUREBITS" },
5410 { config_parse_capability_set
, "BOUNDINGSET" },
5411 { config_parse_rlimit
, "LIMIT" },
5412 { config_parse_unit_deps
, "UNIT [...]" },
5413 { config_parse_exec
, "PATH [ARGUMENT [...]]" },
5414 { config_parse_service_type
, "SERVICETYPE" },
5415 { config_parse_service_restart
, "SERVICERESTART" },
5416 { config_parse_service_timeout_failure_mode
, "TIMEOUTMODE" },
5417 { config_parse_kill_mode
, "KILLMODE" },
5418 { config_parse_signal
, "SIGNAL" },
5419 { config_parse_socket_listen
, "SOCKET [...]" },
5420 { config_parse_socket_bind
, "SOCKETBIND" },
5421 { config_parse_socket_bindtodevice
, "NETWORKINTERFACE" },
5422 { config_parse_sec
, "SECONDS" },
5423 { config_parse_nsec
, "NANOSECONDS" },
5424 { config_parse_namespace_path_strv
, "PATH [...]" },
5425 { config_parse_bind_paths
, "PATH[:PATH[:OPTIONS]] [...]" },
5426 { config_parse_unit_requires_mounts_for
, "PATH [...]" },
5427 { config_parse_exec_mount_flags
, "MOUNTFLAG [...]" },
5428 { config_parse_unit_string_printf
, "STRING" },
5429 { config_parse_trigger_unit
, "UNIT" },
5430 { config_parse_timer
, "TIMER" },
5431 { config_parse_path_spec
, "PATH" },
5432 { config_parse_notify_access
, "ACCESS" },
5433 { config_parse_ip_tos
, "TOS" },
5434 { config_parse_unit_condition_path
, "CONDITION" },
5435 { config_parse_unit_condition_string
, "CONDITION" },
5436 { config_parse_unit_slice
, "SLICE" },
5437 { config_parse_documentation
, "URL" },
5438 { config_parse_service_timeout
, "SECONDS" },
5439 { config_parse_emergency_action
, "ACTION" },
5440 { config_parse_set_status
, "STATUS" },
5441 { config_parse_service_sockets
, "SOCKETS" },
5442 { config_parse_environ
, "ENVIRON" },
5444 { config_parse_syscall_filter
, "SYSCALLS" },
5445 { config_parse_syscall_archs
, "ARCHS" },
5446 { config_parse_syscall_errno
, "ERRNO" },
5447 { config_parse_address_families
, "FAMILIES" },
5448 { config_parse_restrict_namespaces
, "NAMESPACES" },
5450 { config_parse_cpu_shares
, "SHARES" },
5451 { config_parse_cg_weight
, "WEIGHT" },
5452 { config_parse_memory_limit
, "LIMIT" },
5453 { config_parse_device_allow
, "DEVICE" },
5454 { config_parse_device_policy
, "POLICY" },
5455 { config_parse_io_limit
, "LIMIT" },
5456 { config_parse_io_device_weight
, "DEVICEWEIGHT" },
5457 { config_parse_io_device_latency
, "DEVICELATENCY" },
5458 { config_parse_blockio_bandwidth
, "BANDWIDTH" },
5459 { config_parse_blockio_weight
, "WEIGHT" },
5460 { config_parse_blockio_device_weight
, "DEVICEWEIGHT" },
5461 { config_parse_long
, "LONG" },
5462 { config_parse_socket_service
, "SERVICE" },
5464 { config_parse_exec_selinux_context
, "LABEL" },
5466 { config_parse_job_mode
, "MODE" },
5467 { config_parse_job_mode_isolate
, "BOOLEAN" },
5468 { config_parse_personality
, "PERSONALITY" },
5471 const char *prev
= NULL
;
5476 NULSTR_FOREACH(i
, load_fragment_gperf_nulstr
) {
5477 const char *rvalue
= "OTHER", *lvalue
;
5478 const ConfigPerfItem
*p
;
5483 assert_se(p
= load_fragment_gperf_lookup(i
, strlen(i
)));
5485 /* Hide legacy settings */
5486 if (p
->parse
== config_parse_warn_compat
&&
5487 p
->ltype
== DISABLED_LEGACY
)
5490 for (j
= 0; j
< ELEMENTSOF(table
); j
++)
5491 if (p
->parse
== table
[j
].callback
) {
5492 rvalue
= table
[j
].rvalue
;
5496 dot
= strchr(i
, '.');
5497 lvalue
= dot
? dot
+ 1 : i
;
5501 if (!prev
|| !strneq(prev
, i
, prefix_len
+1)) {
5505 fprintf(f
, "[%.*s]\n", (int) prefix_len
, i
);
5508 fprintf(f
, "%s=%s\n", lvalue
, rvalue
);
5513 int config_parse_cpu_affinity2(
5515 const char *filename
,
5517 const char *section
,
5518 unsigned section_line
,
5525 CPUSet
*affinity
= data
;
5529 (void) parse_cpu_set_extend(rvalue
, affinity
, true, unit
, filename
, line
, lvalue
);
5534 int config_parse_show_status(
5536 const char *filename
,
5538 const char *section
,
5539 unsigned section_line
,
5547 ShowStatus
*b
= data
;
5554 k
= parse_show_status(rvalue
, b
);
5556 log_syntax(unit
, LOG_WARNING
, filename
, line
, k
, "Failed to parse show status setting, ignoring: %s", rvalue
);
5561 int config_parse_output_restricted(
5563 const char *filename
,
5565 const char *section
,
5566 unsigned section_line
,
5573 ExecOutput t
, *eo
= data
;
5574 bool obsolete
= false;
5581 if (streq(rvalue
, "syslog")) {
5582 t
= EXEC_OUTPUT_JOURNAL
;
5584 } else if (streq(rvalue
, "syslog+console")) {
5585 t
= EXEC_OUTPUT_JOURNAL_AND_CONSOLE
;
5588 t
= exec_output_from_string(rvalue
);
5590 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Failed to parse output type, ignoring: %s", rvalue
);
5594 if (IN_SET(t
, EXEC_OUTPUT_SOCKET
, EXEC_OUTPUT_NAMED_FD
, EXEC_OUTPUT_FILE
, EXEC_OUTPUT_FILE_APPEND
)) {
5595 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Standard output types socket, fd:, file:, append: are not supported as defaults, ignoring: %s", rvalue
);
5601 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
5602 "Standard output type %s is obsolete, automatically updating to %s. Please update your configuration.",
5603 rvalue
, exec_output_to_string(t
));
5609 int config_parse_crash_chvt(
5611 const char *filename
,
5613 const char *section
,
5614 unsigned section_line
,
5628 r
= parse_crash_chvt(rvalue
, data
);
5630 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse CrashChangeVT= setting, ignoring: %s", rvalue
);
5635 int config_parse_swap_priority(
5637 const char *filename
,
5639 const char *section
,
5640 unsigned section_line
,
5656 if (isempty(rvalue
)) {
5657 s
->parameters_fragment
.priority
= -1;
5658 s
->parameters_fragment
.priority_set
= false;
5662 r
= safe_atoi(rvalue
, &priority
);
5664 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid swap priority '%s', ignoring.", rvalue
);
5668 if (priority
< -1) {
5669 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
);
5673 if (priority
> 32767) {
5674 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "Swap priority out of range, ignoring: %s", rvalue
);
5678 s
->parameters_fragment
.priority
= priority
;
5679 s
->parameters_fragment
.priority_set
= true;