1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 Copyright © 2012 Holger Hans Peter Freyther
14 #include <sys/resource.h>
17 #include "alloc-util.h"
18 #include "all-units.h"
19 #include "bpf-firewall.h"
20 #include "bus-error.h"
21 #include "bus-internal.h"
24 #include "capability-util.h"
25 #include "cgroup-setup.h"
26 #include "conf-parser.h"
27 #include "cpu-set-util.h"
29 #include "errno-list.h"
34 #include "hexdecoct.h"
37 #include "ip-protocol-list.h"
38 #include "journal-util.h"
39 #include "limits-util.h"
40 #include "load-fragment.h"
42 #include "mountpoint-util.h"
43 #include "nulstr-util.h"
44 #include "parse-util.h"
45 #include "path-util.h"
46 #include "process-util.h"
48 #include "seccomp-util.h"
50 #include "securebits-util.h"
51 #include "signal-util.h"
52 #include "socket-netlink.h"
53 #include "stat-util.h"
54 #include "string-util.h"
56 #include "syslog-util.h"
57 #include "time-util.h"
58 #include "unit-name.h"
59 #include "unit-printf.h"
60 #include "user-util.h"
63 static int parse_socket_protocol(const char *s
) {
66 r
= parse_ip_protocol(s
);
69 if (!IN_SET(r
, IPPROTO_UDPLITE
, IPPROTO_SCTP
))
70 return -EPROTONOSUPPORT
;
75 int parse_crash_chvt(const char *value
, int *data
) {
78 if (safe_atoi(value
, data
) >= 0)
81 b
= parse_boolean(value
);
86 *data
= 0; /* switch to where kmsg goes */
88 *data
= -1; /* turn off switching */
93 int parse_confirm_spawn(const char *value
, char **console
) {
97 r
= value
? parse_boolean(value
) : 1;
101 } else if (r
> 0) /* on with default tty */
102 s
= strdup("/dev/console");
103 else if (is_path(value
)) /* on with fully qualified path */
105 else /* on with only a tty file name, not a fully qualified path */
106 s
= path_join("/dev/", value
);
114 DEFINE_CONFIG_PARSE(config_parse_socket_protocol
, parse_socket_protocol
, "Failed to parse socket protocol");
115 DEFINE_CONFIG_PARSE(config_parse_exec_secure_bits
, secure_bits_from_string
, "Failed to parse secure bits");
116 DEFINE_CONFIG_PARSE_ENUM(config_parse_collect_mode
, collect_mode
, CollectMode
, "Failed to parse garbage collection mode");
117 DEFINE_CONFIG_PARSE_ENUM(config_parse_device_policy
, cgroup_device_policy
, CGroupDevicePolicy
, "Failed to parse device policy");
118 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_keyring_mode
, exec_keyring_mode
, ExecKeyringMode
, "Failed to parse keyring mode");
119 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_utmp_mode
, exec_utmp_mode
, ExecUtmpMode
, "Failed to parse utmp mode");
120 DEFINE_CONFIG_PARSE_ENUM(config_parse_job_mode
, job_mode
, JobMode
, "Failed to parse job mode");
121 DEFINE_CONFIG_PARSE_ENUM(config_parse_notify_access
, notify_access
, NotifyAccess
, "Failed to parse notify access specifier");
122 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_home
, protect_home
, ProtectHome
, "Failed to parse protect home value");
123 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_system
, protect_system
, ProtectSystem
, "Failed to parse protect system value");
124 DEFINE_CONFIG_PARSE_ENUM(config_parse_runtime_preserve_mode
, exec_preserve_mode
, ExecPreserveMode
, "Failed to parse runtime directory preserve mode");
125 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_type
, service_type
, ServiceType
, "Failed to parse service type");
126 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart
, service_restart
, ServiceRestart
, "Failed to parse service restart specifier");
127 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_timeout_failure_mode
, service_timeout_failure_mode
, ServiceTimeoutFailureMode
, "Failed to parse timeout failure mode");
128 DEFINE_CONFIG_PARSE_ENUM(config_parse_socket_bind
, socket_address_bind_ipv6_only_or_bool
, SocketAddressBindIPv6Only
, "Failed to parse bind IPv6 only value");
129 DEFINE_CONFIG_PARSE_ENUM(config_parse_oom_policy
, oom_policy
, OOMPolicy
, "Failed to parse OOM policy");
130 DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_ip_tos
, ip_tos
, int, -1, "Failed to parse IP TOS value");
131 DEFINE_CONFIG_PARSE_PTR(config_parse_blockio_weight
, cg_blkio_weight_parse
, uint64_t, "Invalid block IO weight");
132 DEFINE_CONFIG_PARSE_PTR(config_parse_cg_weight
, cg_weight_parse
, uint64_t, "Invalid weight");
133 DEFINE_CONFIG_PARSE_PTR(config_parse_cpu_shares
, cg_cpu_shares_parse
, uint64_t, "Invalid CPU shares");
134 DEFINE_CONFIG_PARSE_PTR(config_parse_exec_mount_flags
, mount_propagation_flags_from_string
, unsigned long, "Failed to parse mount flag");
135 DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_numa_policy
, mpol
, int, -1, "Invalid NUMA policy type");
136 DEFINE_CONFIG_PARSE_ENUM(config_parse_status_unit_format
, status_unit_format
, StatusUnitFormat
, "Failed to parse status unit format");
138 int config_parse_unit_deps(
140 const char *filename
,
143 unsigned section_line
,
150 UnitDependency d
= ltype
;
160 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
163 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_RETAIN_ESCAPE
);
169 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
173 r
= unit_name_printf(u
, word
, &k
);
175 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
179 r
= unit_add_dependency_by_name(u
, d
, k
, true, UNIT_DEPENDENCY_FILE
);
181 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
187 int config_parse_obsolete_unit_deps(
189 const char *filename
,
192 unsigned section_line
,
199 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
200 "Unit dependency type %s= is obsolete, replacing by %s=, please update your unit file", lvalue
, unit_dependency_to_string(ltype
));
202 return config_parse_unit_deps(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
);
205 int config_parse_unit_string_printf(
207 const char *filename
,
210 unsigned section_line
,
217 _cleanup_free_
char *k
= NULL
;
218 const Unit
*u
= userdata
;
226 r
= unit_full_printf(u
, rvalue
, &k
);
228 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
232 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
235 int config_parse_unit_strv_printf(
237 const char *filename
,
240 unsigned section_line
,
247 const Unit
*u
= userdata
;
248 _cleanup_free_
char *k
= NULL
;
256 r
= unit_full_printf(u
, rvalue
, &k
);
258 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
262 return config_parse_strv(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
265 int config_parse_unit_path_printf(
267 const char *filename
,
270 unsigned section_line
,
277 _cleanup_free_
char *k
= NULL
;
278 const Unit
*u
= userdata
;
287 /* Let's not bother with anything that is too long */
288 if (strlen(rvalue
) >= PATH_MAX
) {
289 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
290 "%s value too long%s.",
291 lvalue
, fatal
? "" : ", ignoring");
292 return fatal
? -ENAMETOOLONG
: 0;
295 r
= unit_full_printf(u
, rvalue
, &k
);
297 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
298 "Failed to resolve unit specifiers in '%s'%s: %m",
299 rvalue
, fatal
? "" : ", ignoring");
300 return fatal
? -ENOEXEC
: 0;
303 return config_parse_path(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
306 int config_parse_unit_path_strv_printf(
308 const char *filename
,
311 unsigned section_line
,
319 const Unit
*u
= userdata
;
328 if (isempty(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_ERR
, 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_ERR
, 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_ERR
, 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_ERR
, 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_ERR
, 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_ERR
, 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_ERR
, 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_ERR
, filename
, line
, r
, "Nice priority out of range, ignoring: %s", rvalue
);
546 log_syntax(unit
, LOG_ERR
, 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_ERR
, filename
, line
, r
, "OOM score adjust value out of range, ignoring: %s", rvalue
);
586 log_syntax(unit
, LOG_ERR
, 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 life-cycle 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
, 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
, 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
, 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
, 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
, 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
, 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
, 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
, 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_ERR
, 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 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s': %m", n
);
979 if (isempty(resolved
))
980 resolved
= mfree(resolved
);
981 else if (!fdname_is_valid(resolved
)) {
982 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name: %s", resolved
);
986 free_and_replace(c
->stdio_fdname
[STDIN_FILENO
], resolved
);
988 ei
= EXEC_INPUT_NAMED_FD
;
990 } else if ((n
= startswith(rvalue
, "file:"))) {
991 _cleanup_free_
char *resolved
= NULL
;
993 r
= unit_full_printf(u
, n
, &resolved
);
995 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s': %m", n
);
997 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1001 free_and_replace(c
->stdio_file
[STDIN_FILENO
], resolved
);
1003 ei
= EXEC_INPUT_FILE
;
1006 ei
= exec_input_from_string(rvalue
);
1008 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse input specifier, ignoring: %s", rvalue
);
1017 int config_parse_exec_input_text(
1019 const char *filename
,
1021 const char *section
,
1022 unsigned section_line
,
1029 _cleanup_free_
char *unescaped
= NULL
, *resolved
= NULL
;
1030 ExecContext
*c
= data
;
1031 const Unit
*u
= userdata
;
1041 if (isempty(rvalue
)) {
1042 /* Reset if the empty string is assigned */
1043 c
->stdin_data
= mfree(c
->stdin_data
);
1044 c
->stdin_data_size
= 0;
1048 r
= cunescape(rvalue
, 0, &unescaped
);
1050 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to decode C escaped text '%s': %m", rvalue
);
1052 r
= unit_full_printf(u
, unescaped
, &resolved
);
1054 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s': %m", unescaped
);
1056 sz
= strlen(resolved
);
1057 if (c
->stdin_data_size
+ sz
+ 1 < c
->stdin_data_size
|| /* check for overflow */
1058 c
->stdin_data_size
+ sz
+ 1 > EXEC_STDIN_DATA_MAX
) {
1059 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Standard input data too large (%zu), maximum of %zu permitted, ignoring.", c
->stdin_data_size
+ sz
, (size_t) EXEC_STDIN_DATA_MAX
);
1063 p
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
+ 1);
1067 *((char*) mempcpy((char*) p
+ c
->stdin_data_size
, resolved
, sz
)) = '\n';
1070 c
->stdin_data_size
+= sz
+ 1;
1075 int config_parse_exec_input_data(
1077 const char *filename
,
1079 const char *section
,
1080 unsigned section_line
,
1087 _cleanup_free_
void *p
= NULL
;
1088 ExecContext
*c
= data
;
1098 if (isempty(rvalue
)) {
1099 /* Reset if the empty string is assigned */
1100 c
->stdin_data
= mfree(c
->stdin_data
);
1101 c
->stdin_data_size
= 0;
1105 r
= unbase64mem(rvalue
, (size_t) -1, &p
, &sz
);
1107 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to decode base64 data, ignoring: %s", rvalue
);
1111 if (c
->stdin_data_size
+ sz
< c
->stdin_data_size
|| /* check for overflow */
1112 c
->stdin_data_size
+ sz
> EXEC_STDIN_DATA_MAX
) {
1113 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Standard input data too large (%zu), maximum of %zu permitted, ignoring.", c
->stdin_data_size
+ sz
, (size_t) EXEC_STDIN_DATA_MAX
);
1117 q
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
);
1121 memcpy((uint8_t*) q
+ c
->stdin_data_size
, p
, sz
);
1124 c
->stdin_data_size
+= sz
;
1129 int config_parse_exec_output(
1131 const char *filename
,
1133 const char *section
,
1134 unsigned section_line
,
1141 _cleanup_free_
char *resolved
= NULL
;
1143 ExecContext
*c
= data
;
1144 const Unit
*u
= userdata
;
1145 bool obsolete
= false;
1155 n
= startswith(rvalue
, "fd:");
1157 r
= unit_full_printf(u
, n
, &resolved
);
1159 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", n
);
1161 if (isempty(resolved
))
1162 resolved
= mfree(resolved
);
1163 else if (!fdname_is_valid(resolved
)) {
1164 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name: %s", resolved
);
1168 eo
= EXEC_OUTPUT_NAMED_FD
;
1170 } else if (streq(rvalue
, "syslog")) {
1171 eo
= EXEC_OUTPUT_JOURNAL
;
1174 } else if (streq(rvalue
, "syslog+console")) {
1175 eo
= EXEC_OUTPUT_JOURNAL_AND_CONSOLE
;
1178 } else if ((n
= startswith(rvalue
, "file:"))) {
1180 r
= unit_full_printf(u
, n
, &resolved
);
1182 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", n
);
1184 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1188 eo
= EXEC_OUTPUT_FILE
;
1190 } else if ((n
= startswith(rvalue
, "append:"))) {
1192 r
= unit_full_printf(u
, n
, &resolved
);
1194 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", n
);
1196 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1200 eo
= EXEC_OUTPUT_FILE_APPEND
;
1202 eo
= exec_output_from_string(rvalue
);
1204 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse output specifier, ignoring: %s", rvalue
);
1210 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
1211 "Standard output type %s is obsolete, automatically updating to %s. Please update your unit file, and consider removing the setting altogether.",
1212 rvalue
, exec_output_to_string(eo
));
1214 if (streq(lvalue
, "StandardOutput")) {
1215 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1216 free_and_replace(c
->stdio_fdname
[STDOUT_FILENO
], resolved
);
1218 free_and_replace(c
->stdio_file
[STDOUT_FILENO
], resolved
);
1223 assert(streq(lvalue
, "StandardError"));
1225 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1226 free_and_replace(c
->stdio_fdname
[STDERR_FILENO
], resolved
);
1228 free_and_replace(c
->stdio_file
[STDERR_FILENO
], resolved
);
1236 int config_parse_exec_io_class(const char *unit
,
1237 const char *filename
,
1239 const char *section
,
1240 unsigned section_line
,
1247 ExecContext
*c
= data
;
1255 if (isempty(rvalue
)) {
1256 c
->ioprio_set
= false;
1257 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE
, 0);
1261 x
= ioprio_class_from_string(rvalue
);
1263 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse IO scheduling class, ignoring: %s", rvalue
);
1267 c
->ioprio
= IOPRIO_PRIO_VALUE(x
, IOPRIO_PRIO_DATA(c
->ioprio
));
1268 c
->ioprio_set
= true;
1273 int config_parse_exec_io_priority(const char *unit
,
1274 const char *filename
,
1276 const char *section
,
1277 unsigned section_line
,
1284 ExecContext
*c
= data
;
1292 if (isempty(rvalue
)) {
1293 c
->ioprio_set
= false;
1294 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE
, 0);
1298 r
= ioprio_parse_priority(rvalue
, &i
);
1300 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse IO priority, ignoring: %s", rvalue
);
1304 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_PRIO_CLASS(c
->ioprio
), i
);
1305 c
->ioprio_set
= true;
1310 int config_parse_exec_cpu_sched_policy(const char *unit
,
1311 const char *filename
,
1313 const char *section
,
1314 unsigned section_line
,
1321 ExecContext
*c
= data
;
1329 if (isempty(rvalue
)) {
1330 c
->cpu_sched_set
= false;
1331 c
->cpu_sched_policy
= SCHED_OTHER
;
1332 c
->cpu_sched_priority
= 0;
1336 x
= sched_policy_from_string(rvalue
);
1338 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse CPU scheduling policy, ignoring: %s", rvalue
);
1342 c
->cpu_sched_policy
= x
;
1343 /* Moving to or from real-time policy? We need to adjust the priority */
1344 c
->cpu_sched_priority
= CLAMP(c
->cpu_sched_priority
, sched_get_priority_min(x
), sched_get_priority_max(x
));
1345 c
->cpu_sched_set
= true;
1350 int config_parse_numa_mask(const char *unit
,
1351 const char *filename
,
1353 const char *section
,
1354 unsigned section_line
,
1361 NUMAPolicy
*p
= data
;
1368 r
= parse_cpu_set_extend(rvalue
, &p
->nodes
, true, unit
, filename
, line
, lvalue
);
1370 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse NUMA node mask, ignoring: %s", rvalue
);
1377 int config_parse_exec_cpu_sched_prio(const char *unit
,
1378 const char *filename
,
1380 const char *section
,
1381 unsigned section_line
,
1388 ExecContext
*c
= data
;
1396 r
= safe_atoi(rvalue
, &i
);
1398 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse CPU scheduling priority, ignoring: %s", rvalue
);
1402 /* On Linux RR/FIFO range from 1 to 99 and OTHER/BATCH may only be 0 */
1403 min
= sched_get_priority_min(c
->cpu_sched_policy
);
1404 max
= sched_get_priority_max(c
->cpu_sched_policy
);
1406 if (i
< min
|| i
> max
) {
1407 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "CPU scheduling priority is out of range, ignoring: %s", rvalue
);
1411 c
->cpu_sched_priority
= i
;
1412 c
->cpu_sched_set
= true;
1417 int config_parse_exec_root_hash(
1419 const char *filename
,
1421 const char *section
,
1422 unsigned section_line
,
1429 _cleanup_free_
void *roothash_decoded
= NULL
;
1430 ExecContext
*c
= data
;
1431 size_t roothash_decoded_size
= 0;
1439 if (isempty(rvalue
)) {
1440 /* Reset if the empty string is assigned */
1441 c
->root_hash_path
= mfree(c
->root_hash_path
);
1442 c
->root_hash
= mfree(c
->root_hash
);
1443 c
->root_hash_size
= 0;
1447 if (path_is_absolute(rvalue
)) {
1448 /* We have the path to a roothash to load and decode, eg: RootHash=/foo/bar.roothash */
1449 _cleanup_free_
char *p
= NULL
;
1455 free_and_replace(c
->root_hash_path
, p
);
1456 c
->root_hash
= mfree(c
->root_hash
);
1457 c
->root_hash_size
= 0;
1461 /* We have a roothash to decode, eg: RootHash=012345789abcdef */
1462 r
= unhexmem(rvalue
, strlen(rvalue
), &roothash_decoded
, &roothash_decoded_size
);
1464 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to decode RootHash=, ignoring: %s", rvalue
);
1465 if (roothash_decoded_size
< sizeof(sd_id128_t
))
1466 return log_syntax(unit
, LOG_ERR
, filename
, line
, SYNTHETIC_ERRNO(EINVAL
), "RootHash= is too short, ignoring: %s", rvalue
);
1468 free_and_replace(c
->root_hash
, roothash_decoded
);
1469 c
->root_hash_size
= roothash_decoded_size
;
1470 c
->root_hash_path
= mfree(c
->root_hash_path
);
1475 int config_parse_exec_cpu_affinity(const char *unit
,
1476 const char *filename
,
1478 const char *section
,
1479 unsigned section_line
,
1486 ExecContext
*c
= data
;
1494 if (streq(rvalue
, "numa")) {
1495 c
->cpu_affinity_from_numa
= true;
1496 cpu_set_reset(&c
->cpu_set
);
1501 r
= parse_cpu_set_extend(rvalue
, &c
->cpu_set
, true, unit
, filename
, line
, lvalue
);
1503 c
->cpu_affinity_from_numa
= false;
1508 int config_parse_capability_set(
1510 const char *filename
,
1512 const char *section
,
1513 unsigned section_line
,
1520 uint64_t *capability_set
= data
;
1521 uint64_t sum
= 0, initial
= 0;
1522 bool invert
= false;
1530 if (rvalue
[0] == '~') {
1535 if (streq(lvalue
, "CapabilityBoundingSet"))
1536 initial
= CAP_ALL
; /* initialized to all bits on */
1537 /* else "AmbientCapabilities" initialized to all bits off */
1539 r
= capability_set_from_string(rvalue
, &sum
);
1541 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= specifier '%s', ignoring: %m", lvalue
, rvalue
);
1545 if (sum
== 0 || *capability_set
== initial
)
1546 /* "", "~" or uninitialized data -> replace */
1547 *capability_set
= invert
? ~sum
: sum
;
1549 /* previous data -> merge */
1551 *capability_set
&= ~sum
;
1553 *capability_set
|= sum
;
1559 int config_parse_exec_selinux_context(
1561 const char *filename
,
1563 const char *section
,
1564 unsigned section_line
,
1571 ExecContext
*c
= data
;
1572 const Unit
*u
= userdata
;
1582 if (isempty(rvalue
)) {
1583 c
->selinux_context
= mfree(c
->selinux_context
);
1584 c
->selinux_context_ignore
= false;
1588 if (rvalue
[0] == '-') {
1594 r
= unit_full_printf(u
, rvalue
, &k
);
1596 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1597 "Failed to resolve unit specifiers in '%s'%s: %m",
1598 rvalue
, ignore
? ", ignoring" : "");
1599 return ignore
? 0 : -ENOEXEC
;
1602 free_and_replace(c
->selinux_context
, k
);
1603 c
->selinux_context_ignore
= ignore
;
1608 int config_parse_exec_apparmor_profile(
1610 const char *filename
,
1612 const char *section
,
1613 unsigned section_line
,
1620 ExecContext
*c
= data
;
1621 const Unit
*u
= userdata
;
1631 if (isempty(rvalue
)) {
1632 c
->apparmor_profile
= mfree(c
->apparmor_profile
);
1633 c
->apparmor_profile_ignore
= false;
1637 if (rvalue
[0] == '-') {
1643 r
= unit_full_printf(u
, rvalue
, &k
);
1645 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1646 "Failed to resolve unit specifiers in '%s'%s: %m",
1647 rvalue
, ignore
? ", ignoring" : "");
1648 return ignore
? 0 : -ENOEXEC
;
1651 free_and_replace(c
->apparmor_profile
, k
);
1652 c
->apparmor_profile_ignore
= ignore
;
1657 int config_parse_exec_smack_process_label(
1659 const char *filename
,
1661 const char *section
,
1662 unsigned section_line
,
1669 ExecContext
*c
= data
;
1670 const Unit
*u
= userdata
;
1680 if (isempty(rvalue
)) {
1681 c
->smack_process_label
= mfree(c
->smack_process_label
);
1682 c
->smack_process_label_ignore
= false;
1686 if (rvalue
[0] == '-') {
1692 r
= unit_full_printf(u
, rvalue
, &k
);
1694 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1695 "Failed to resolve unit specifiers in '%s'%s: %m",
1696 rvalue
, ignore
? ", ignoring" : "");
1697 return ignore
? 0 : -ENOEXEC
;
1700 free_and_replace(c
->smack_process_label
, k
);
1701 c
->smack_process_label_ignore
= ignore
;
1706 int config_parse_timer(
1708 const char *filename
,
1710 const char *section
,
1711 unsigned section_line
,
1718 _cleanup_(calendar_spec_freep
) CalendarSpec
*c
= NULL
;
1719 _cleanup_free_
char *k
= NULL
;
1720 const Unit
*u
= userdata
;
1731 if (isempty(rvalue
)) {
1732 /* Empty assignment resets list */
1733 timer_free_values(t
);
1737 r
= unit_full_printf(u
, rvalue
, &k
);
1739 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
1743 if (ltype
== TIMER_CALENDAR
) {
1744 r
= calendar_spec_from_string(k
, &c
);
1746 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse calendar specification, ignoring: %s", k
);
1750 r
= parse_sec(k
, &usec
);
1752 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse timer value, ignoring: %s", k
);
1757 v
= new(TimerValue
, 1);
1764 .calendar_spec
= TAKE_PTR(c
),
1767 LIST_PREPEND(value
, t
->values
, v
);
1772 int config_parse_trigger_unit(
1774 const char *filename
,
1776 const char *section
,
1777 unsigned section_line
,
1784 _cleanup_free_
char *p
= NULL
;
1794 if (!hashmap_isempty(u
->dependencies
[UNIT_TRIGGERS
])) {
1795 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Multiple units to trigger specified, ignoring: %s", rvalue
);
1799 r
= unit_name_printf(u
, rvalue
, &p
);
1801 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
1805 type
= unit_name_to_type(p
);
1807 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit type not valid, ignoring: %s", rvalue
);
1810 if (unit_has_name(u
, p
)) {
1811 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Units cannot trigger themselves, ignoring: %s", rvalue
);
1815 r
= unit_add_two_dependencies_by_name(u
, UNIT_BEFORE
, UNIT_TRIGGERS
, p
, true, UNIT_DEPENDENCY_FILE
);
1817 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add trigger on %s, ignoring: %m", p
);
1824 int config_parse_path_spec(const char *unit
,
1825 const char *filename
,
1827 const char *section
,
1828 unsigned section_line
,
1838 _cleanup_free_
char *k
= NULL
;
1846 if (isempty(rvalue
)) {
1847 /* Empty assignment clears list */
1852 b
= path_type_from_string(lvalue
);
1854 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse path type, ignoring: %s", lvalue
);
1858 r
= unit_full_printf(UNIT(p
), rvalue
, &k
);
1860 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
1864 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
1868 s
= new0(PathSpec
, 1);
1873 s
->path
= TAKE_PTR(k
);
1877 LIST_PREPEND(spec
, p
->specs
, s
);
1882 int config_parse_socket_service(
1884 const char *filename
,
1886 const char *section
,
1887 unsigned section_line
,
1894 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1895 _cleanup_free_
char *p
= NULL
;
1905 r
= unit_name_printf(UNIT(s
), rvalue
, &p
);
1907 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", rvalue
);
1911 if (!endswith(p
, ".service")) {
1912 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit must be of type service: %s", rvalue
);
1916 r
= manager_load_unit(UNIT(s
)->manager
, p
, NULL
, &error
, &x
);
1918 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to load unit %s: %s", rvalue
, bus_error_message(&error
, r
));
1922 unit_ref_set(&s
->service
, UNIT(s
), x
);
1927 int config_parse_fdname(
1929 const char *filename
,
1931 const char *section
,
1932 unsigned section_line
,
1939 _cleanup_free_
char *p
= NULL
;
1948 if (isempty(rvalue
)) {
1949 s
->fdname
= mfree(s
->fdname
);
1953 r
= unit_full_printf(UNIT(s
), rvalue
, &p
);
1955 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
1959 if (!fdname_is_valid(p
)) {
1960 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", p
);
1964 return free_and_replace(s
->fdname
, p
);
1967 int config_parse_service_sockets(
1969 const char *filename
,
1971 const char *section
,
1972 unsigned section_line
,
1990 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
1992 r
= extract_first_word(&p
, &word
, NULL
, 0);
1998 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Trailing garbage in sockets, ignoring: %s", rvalue
);
2002 r
= unit_name_printf(UNIT(s
), word
, &k
);
2004 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
2008 if (!endswith(k
, ".socket")) {
2009 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit must be of type socket, ignoring: %s", k
);
2013 r
= unit_add_two_dependencies_by_name(UNIT(s
), UNIT_WANTS
, UNIT_AFTER
, k
, true, UNIT_DEPENDENCY_FILE
);
2015 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
2017 r
= unit_add_dependency_by_name(UNIT(s
), UNIT_TRIGGERED_BY
, k
, true, UNIT_DEPENDENCY_FILE
);
2019 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
2025 int config_parse_bus_name(
2027 const char *filename
,
2029 const char *section
,
2030 unsigned section_line
,
2037 _cleanup_free_
char *k
= NULL
;
2038 const Unit
*u
= userdata
;
2046 r
= unit_full_printf(u
, rvalue
, &k
);
2048 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2052 if (!sd_bus_service_name_is_valid(k
)) {
2053 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid bus name, ignoring: %s", k
);
2057 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
2060 int config_parse_service_timeout(
2062 const char *filename
,
2064 const char *section
,
2065 unsigned section_line
,
2072 Service
*s
= userdata
;
2081 /* This is called for two cases: TimeoutSec= and TimeoutStartSec=. */
2083 /* Traditionally, these options accepted 0 to disable the timeouts. However, a timeout of 0 suggests it happens
2084 * immediately, hence fix this to become USEC_INFINITY instead. This is in-line with how we internally handle
2085 * all other timeouts. */
2086 r
= parse_sec_fix_0(rvalue
, &usec
);
2088 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
2092 s
->start_timeout_defined
= true;
2093 s
->timeout_start_usec
= usec
;
2095 if (streq(lvalue
, "TimeoutSec"))
2096 s
->timeout_stop_usec
= usec
;
2101 int config_parse_timeout_abort(
2103 const char *filename
,
2105 const char *section
,
2106 unsigned section_line
,
2121 /* Note: apart from setting the arg, this returns an extra bit of information in the return value. */
2123 if (isempty(rvalue
)) {
2125 return 0; /* "not set" */
2128 r
= parse_sec(rvalue
, ret
);
2130 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= setting, ignoring: %s", lvalue
, rvalue
);
2132 return 1; /* "set" */
2135 int config_parse_service_timeout_abort(
2137 const char *filename
,
2139 const char *section
,
2140 unsigned section_line
,
2147 Service
*s
= userdata
;
2152 r
= config_parse_timeout_abort(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
,
2153 &s
->timeout_abort_usec
, s
);
2155 s
->timeout_abort_set
= r
;
2159 int config_parse_sec_fix_0(
2161 const char *filename
,
2163 const char *section
,
2164 unsigned section_line
,
2171 usec_t
*usec
= data
;
2179 /* This is pretty much like config_parse_sec(), except that this treats a time of 0 as infinity, for
2180 * compatibility with older versions of systemd where 0 instead of infinity was used as indicator to turn off a
2183 r
= parse_sec_fix_0(rvalue
, usec
);
2185 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
2192 int config_parse_user_group_compat(
2194 const char *filename
,
2196 const char *section
,
2197 unsigned section_line
,
2204 _cleanup_free_
char *k
= NULL
;
2206 const Unit
*u
= userdata
;
2214 if (isempty(rvalue
)) {
2215 *user
= mfree(*user
);
2219 r
= unit_full_printf(u
, rvalue
, &k
);
2221 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", rvalue
);
2225 if (!valid_user_group_name(k
, VALID_USER_ALLOW_NUMERIC
|VALID_USER_RELAX
|VALID_USER_WARN
)) {
2226 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2230 return free_and_replace(*user
, k
);
2233 int config_parse_user_group_strv_compat(
2235 const char *filename
,
2237 const char *section
,
2238 unsigned section_line
,
2245 char ***users
= data
;
2246 const Unit
*u
= userdata
;
2247 const char *p
= rvalue
;
2255 if (isempty(rvalue
)) {
2256 *users
= strv_free(*users
);
2261 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2263 r
= extract_first_word(&p
, &word
, NULL
, 0);
2269 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax: %s", rvalue
);
2273 r
= unit_full_printf(u
, word
, &k
);
2275 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", word
);
2279 if (!valid_user_group_name(k
, VALID_USER_ALLOW_NUMERIC
|VALID_USER_RELAX
|VALID_USER_WARN
)) {
2280 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2284 r
= strv_push(users
, k
);
2294 int config_parse_working_directory(
2296 const char *filename
,
2298 const char *section
,
2299 unsigned section_line
,
2306 ExecContext
*c
= data
;
2307 const Unit
*u
= userdata
;
2317 if (isempty(rvalue
)) {
2318 c
->working_directory_home
= false;
2319 c
->working_directory
= mfree(c
->working_directory
);
2323 if (rvalue
[0] == '-') {
2329 if (streq(rvalue
, "~")) {
2330 c
->working_directory_home
= true;
2331 c
->working_directory
= mfree(c
->working_directory
);
2333 _cleanup_free_
char *k
= NULL
;
2335 r
= unit_full_printf(u
, rvalue
, &k
);
2337 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2338 "Failed to resolve unit specifiers in working directory path '%s'%s: %m",
2339 rvalue
, missing_ok
? ", ignoring" : "");
2340 return missing_ok
? 0 : -ENOEXEC
;
2343 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
| (missing_ok
? 0 : PATH_CHECK_FATAL
), unit
, filename
, line
, lvalue
);
2345 return missing_ok
? 0 : -ENOEXEC
;
2347 c
->working_directory_home
= false;
2348 free_and_replace(c
->working_directory
, k
);
2351 c
->working_directory_missing_ok
= missing_ok
;
2355 int config_parse_unit_env_file(const char *unit
,
2356 const char *filename
,
2358 const char *section
,
2359 unsigned section_line
,
2367 const Unit
*u
= userdata
;
2368 _cleanup_free_
char *n
= NULL
;
2376 if (isempty(rvalue
)) {
2377 /* Empty assignment frees the list */
2378 *env
= strv_free(*env
);
2382 r
= unit_full_printf(u
, rvalue
, &n
);
2384 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2388 r
= path_simplify_and_warn(n
[0] == '-' ? n
+ 1 : n
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2392 r
= strv_push(env
, n
);
2401 int config_parse_environ(
2403 const char *filename
,
2405 const char *section
,
2406 unsigned section_line
,
2413 const Unit
*u
= userdata
;
2423 if (isempty(rvalue
)) {
2424 /* Empty assignment resets the list */
2425 *env
= strv_free(*env
);
2429 for (p
= rvalue
;; ) {
2430 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2432 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2438 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2439 "Invalid syntax, ignoring: %s", rvalue
);
2444 r
= unit_full_printf(u
, word
, &k
);
2446 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2447 "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2453 if (!env_assignment_is_valid(k
)) {
2454 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2455 "Invalid environment assignment, ignoring: %s", k
);
2459 r
= strv_env_replace(env
, k
);
2467 int config_parse_pass_environ(
2469 const char *filename
,
2471 const char *section
,
2472 unsigned section_line
,
2479 _cleanup_strv_free_
char **n
= NULL
;
2480 size_t nlen
= 0, nbufsize
= 0;
2481 char*** passenv
= data
;
2482 const char *p
= rvalue
;
2483 const Unit
*u
= userdata
;
2491 if (isempty(rvalue
)) {
2492 /* Empty assignment resets the list */
2493 *passenv
= strv_free(*passenv
);
2498 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2500 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
2506 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2507 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2512 r
= unit_full_printf(u
, word
, &k
);
2514 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2515 "Failed to resolve specifiers in %s, ignoring: %m", word
);
2521 if (!env_name_is_valid(k
)) {
2522 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2523 "Invalid environment name for %s, ignoring: %s", lvalue
, k
);
2527 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
2530 n
[nlen
++] = TAKE_PTR(k
);
2535 r
= strv_extend_strv(passenv
, n
, true);
2543 int config_parse_unset_environ(
2545 const char *filename
,
2547 const char *section
,
2548 unsigned section_line
,
2555 _cleanup_strv_free_
char **n
= NULL
;
2556 size_t nlen
= 0, nbufsize
= 0;
2557 char*** unsetenv
= data
;
2558 const char *p
= rvalue
;
2559 const Unit
*u
= userdata
;
2567 if (isempty(rvalue
)) {
2568 /* Empty assignment resets the list */
2569 *unsetenv
= strv_free(*unsetenv
);
2574 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2576 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2582 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2583 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2588 r
= unit_full_printf(u
, word
, &k
);
2590 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2591 "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2597 if (!env_assignment_is_valid(k
) && !env_name_is_valid(k
)) {
2598 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2599 "Invalid environment name or assignment %s, ignoring: %s", lvalue
, k
);
2603 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
2606 n
[nlen
++] = TAKE_PTR(k
);
2611 r
= strv_extend_strv(unsetenv
, n
, true);
2619 int config_parse_log_extra_fields(
2621 const char *filename
,
2623 const char *section
,
2624 unsigned section_line
,
2631 ExecContext
*c
= data
;
2632 const Unit
*u
= userdata
;
2633 const char *p
= rvalue
;
2641 if (isempty(rvalue
)) {
2642 exec_context_free_log_extra_fields(c
);
2647 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2651 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2657 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
2661 r
= unit_full_printf(u
, word
, &k
);
2663 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2667 eq
= strchr(k
, '=');
2669 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Log field lacks '=' character, ignoring: %s", k
);
2673 if (!journal_field_valid(k
, eq
-k
, false)) {
2674 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Log field name is invalid, ignoring: %s", k
);
2678 t
= reallocarray(c
->log_extra_fields
, c
->n_log_extra_fields
+1, sizeof(struct iovec
));
2682 c
->log_extra_fields
= t
;
2683 c
->log_extra_fields
[c
->n_log_extra_fields
++] = IOVEC_MAKE_STRING(k
);
2689 int config_parse_log_namespace(
2691 const char *filename
,
2693 const char *section
,
2694 unsigned section_line
,
2701 _cleanup_free_
char *k
= NULL
;
2702 ExecContext
*c
= data
;
2703 const Unit
*u
= userdata
;
2711 if (isempty(rvalue
)) {
2712 c
->log_namespace
= mfree(c
->log_namespace
);
2716 r
= unit_full_printf(u
, rvalue
, &k
);
2718 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2722 if (!log_namespace_name_valid(k
)) {
2723 log_syntax(unit
, LOG_ERR
, filename
, line
, SYNTHETIC_ERRNO(EINVAL
), "Specified log namespace name is not valid: %s", k
);
2727 free_and_replace(c
->log_namespace
, k
);
2731 int config_parse_unit_condition_path(
2733 const char *filename
,
2735 const char *section
,
2736 unsigned section_line
,
2743 _cleanup_free_
char *p
= NULL
;
2744 Condition
**list
= data
, *c
;
2745 ConditionType t
= ltype
;
2746 bool trigger
, negate
;
2747 const Unit
*u
= userdata
;
2755 if (isempty(rvalue
)) {
2756 /* Empty assignment resets the list */
2757 *list
= condition_free_list(*list
);
2761 trigger
= rvalue
[0] == '|';
2765 negate
= rvalue
[0] == '!';
2769 r
= unit_full_printf(u
, rvalue
, &p
);
2771 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2775 r
= path_simplify_and_warn(p
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2779 c
= condition_new(t
, p
, trigger
, negate
);
2783 LIST_PREPEND(conditions
, *list
, c
);
2787 int config_parse_unit_condition_string(
2789 const char *filename
,
2791 const char *section
,
2792 unsigned section_line
,
2799 _cleanup_free_
char *s
= NULL
;
2800 Condition
**list
= data
, *c
;
2801 ConditionType t
= ltype
;
2802 bool trigger
, negate
;
2803 const Unit
*u
= userdata
;
2811 if (isempty(rvalue
)) {
2812 /* Empty assignment resets the list */
2813 *list
= condition_free_list(*list
);
2817 trigger
= *rvalue
== '|';
2819 rvalue
+= 1 + strspn(rvalue
+ 1, WHITESPACE
);
2821 negate
= *rvalue
== '!';
2823 rvalue
+= 1 + strspn(rvalue
+ 1, WHITESPACE
);
2825 r
= unit_full_printf(u
, rvalue
, &s
);
2827 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2828 "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2832 c
= condition_new(t
, s
, trigger
, negate
);
2836 LIST_PREPEND(conditions
, *list
, c
);
2840 int config_parse_unit_condition_null(
2842 const char *filename
,
2844 const char *section
,
2845 unsigned section_line
,
2852 Condition
**list
= data
, *c
;
2853 bool trigger
, negate
;
2861 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "%s= is deprecated, please do not use.", lvalue
);
2863 if (isempty(rvalue
)) {
2864 /* Empty assignment resets the list */
2865 *list
= condition_free_list(*list
);
2869 trigger
= rvalue
[0] == '|';
2873 negate
= rvalue
[0] == '!';
2877 b
= parse_boolean(rvalue
);
2879 log_syntax(unit
, LOG_ERR
, filename
, line
, b
, "Failed to parse boolean value in condition, ignoring: %s", rvalue
);
2886 c
= condition_new(CONDITION_NULL
, NULL
, trigger
, negate
);
2890 LIST_PREPEND(conditions
, *list
, c
);
2894 int config_parse_unit_requires_mounts_for(
2896 const char *filename
,
2898 const char *section
,
2899 unsigned section_line
,
2906 const char *p
= rvalue
;
2916 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
2918 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
2924 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2925 "Invalid syntax, ignoring: %s", rvalue
);
2929 r
= unit_full_printf(u
, word
, &resolved
);
2931 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
2935 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2939 r
= unit_require_mounts_for(u
, resolved
, UNIT_DEPENDENCY_FILE
);
2941 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add required mount '%s', ignoring: %m", resolved
);
2947 int config_parse_documentation(const char *unit
,
2948 const char *filename
,
2950 const char *section
,
2951 unsigned section_line
,
2967 if (isempty(rvalue
)) {
2968 /* Empty assignment resets the list */
2969 u
->documentation
= strv_free(u
->documentation
);
2973 r
= config_parse_unit_strv_printf(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
,
2974 rvalue
, data
, userdata
);
2978 for (a
= b
= u
->documentation
; a
&& *a
; a
++) {
2980 if (documentation_url_is_valid(*a
))
2983 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid URL, ignoring: %s", *a
);
2994 int config_parse_syscall_filter(
2996 const char *filename
,
2998 const char *section
,
2999 unsigned section_line
,
3006 ExecContext
*c
= data
;
3007 _unused_
const Unit
*u
= userdata
;
3008 bool invert
= false;
3017 if (isempty(rvalue
)) {
3018 /* Empty assignment resets the list */
3019 c
->syscall_filter
= hashmap_free(c
->syscall_filter
);
3020 c
->syscall_whitelist
= false;
3024 if (rvalue
[0] == '~') {
3029 if (!c
->syscall_filter
) {
3030 c
->syscall_filter
= hashmap_new(NULL
);
3031 if (!c
->syscall_filter
)
3035 /* Allow everything but the ones listed */
3036 c
->syscall_whitelist
= false;
3038 /* Allow nothing but the ones listed */
3039 c
->syscall_whitelist
= true;
3041 /* Accept default syscalls if we are on a whitelist */
3042 r
= seccomp_parse_syscall_filter(
3043 "@default", -1, c
->syscall_filter
,
3044 SECCOMP_PARSE_PERMISSIVE
|SECCOMP_PARSE_WHITELIST
,
3054 _cleanup_free_
char *word
= NULL
, *name
= NULL
;
3057 r
= extract_first_word(&p
, &word
, NULL
, 0);
3063 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3067 r
= parse_syscall_and_errno(word
, &name
, &num
);
3069 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse syscall:errno, ignoring: %s", word
);
3073 r
= seccomp_parse_syscall_filter(
3074 name
, num
, c
->syscall_filter
,
3075 SECCOMP_PARSE_LOG
|SECCOMP_PARSE_PERMISSIVE
|
3076 (invert
? SECCOMP_PARSE_INVERT
: 0)|
3077 (c
->syscall_whitelist
? SECCOMP_PARSE_WHITELIST
: 0),
3078 unit
, filename
, line
);
3084 int config_parse_syscall_archs(
3086 const char *filename
,
3088 const char *section
,
3089 unsigned section_line
,
3096 const char *p
= rvalue
;
3100 if (isempty(rvalue
)) {
3101 *archs
= set_free(*archs
);
3106 _cleanup_free_
char *word
= NULL
;
3109 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3115 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3116 "Invalid syntax, ignoring: %s", rvalue
);
3120 r
= seccomp_arch_from_string(word
, &a
);
3122 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
3123 "Failed to parse system call architecture \"%s\", ignoring: %m", word
);
3127 r
= set_ensure_put(archs
, NULL
, UINT32_TO_PTR(a
+ 1));
3133 int config_parse_syscall_errno(
3135 const char *filename
,
3137 const char *section
,
3138 unsigned section_line
,
3145 ExecContext
*c
= data
;
3152 if (isempty(rvalue
)) {
3153 /* Empty assignment resets to KILL */
3154 c
->syscall_errno
= 0;
3158 e
= parse_errno(rvalue
);
3160 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse error number, ignoring: %s", rvalue
);
3164 c
->syscall_errno
= e
;
3168 int config_parse_address_families(
3170 const char *filename
,
3172 const char *section
,
3173 unsigned section_line
,
3180 ExecContext
*c
= data
;
3181 bool invert
= false;
3189 if (isempty(rvalue
)) {
3190 /* Empty assignment resets the list */
3191 c
->address_families
= set_free(c
->address_families
);
3192 c
->address_families_whitelist
= false;
3196 if (rvalue
[0] == '~') {
3201 if (!c
->address_families
) {
3202 c
->address_families
= set_new(NULL
);
3203 if (!c
->address_families
)
3206 c
->address_families_whitelist
= !invert
;
3209 for (p
= rvalue
;;) {
3210 _cleanup_free_
char *word
= NULL
;
3213 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3219 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3220 "Invalid syntax, ignoring: %s", rvalue
);
3224 af
= af_from_name(word
);
3226 log_syntax(unit
, LOG_ERR
, filename
, line
, af
,
3227 "Failed to parse address family, ignoring: %s", word
);
3231 /* If we previously wanted to forbid an address family and now
3232 * we want to allow it, then just remove it from the list.
3234 if (!invert
== c
->address_families_whitelist
) {
3235 r
= set_put(c
->address_families
, INT_TO_PTR(af
));
3239 set_remove(c
->address_families
, INT_TO_PTR(af
));
3243 int config_parse_restrict_namespaces(
3245 const char *filename
,
3247 const char *section
,
3248 unsigned section_line
,
3255 ExecContext
*c
= data
;
3256 unsigned long flags
;
3257 bool invert
= false;
3260 if (isempty(rvalue
)) {
3261 /* Reset to the default. */
3262 c
->restrict_namespaces
= NAMESPACE_FLAGS_INITIAL
;
3266 /* Boolean parameter ignores the previous settings */
3267 r
= parse_boolean(rvalue
);
3269 c
->restrict_namespaces
= 0;
3271 } else if (r
== 0) {
3272 c
->restrict_namespaces
= NAMESPACE_FLAGS_ALL
;
3276 if (rvalue
[0] == '~') {
3281 /* Not a boolean argument, in this case it's a list of namespace types. */
3282 r
= namespace_flags_from_string(rvalue
, &flags
);
3284 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse namespace type string, ignoring: %s", rvalue
);
3288 if (c
->restrict_namespaces
== NAMESPACE_FLAGS_INITIAL
)
3289 /* Initial assignment. Just set the value. */
3290 c
->restrict_namespaces
= invert
? (~flags
) & NAMESPACE_FLAGS_ALL
: flags
;
3292 /* Merge the value with the previous one. */
3293 SET_FLAG(c
->restrict_namespaces
, flags
, !invert
);
3299 int config_parse_unit_slice(
3301 const char *filename
,
3303 const char *section
,
3304 unsigned section_line
,
3311 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
3312 _cleanup_free_
char *k
= NULL
;
3313 Unit
*u
= userdata
, *slice
;
3321 r
= unit_name_printf(u
, rvalue
, &k
);
3323 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
3327 r
= manager_load_unit(u
->manager
, k
, NULL
, &error
, &slice
);
3329 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to load slice unit %s, ignoring: %s", k
, bus_error_message(&error
, r
));
3333 r
= unit_set_slice(u
, slice
);
3335 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to assign slice %s to unit %s, ignoring: %m", slice
->id
, u
->id
);
3342 int config_parse_cpu_quota(
3344 const char *filename
,
3346 const char *section
,
3347 unsigned section_line
,
3354 CGroupContext
*c
= data
;
3361 if (isempty(rvalue
)) {
3362 c
->cpu_quota_per_sec_usec
= USEC_INFINITY
;
3366 r
= parse_permille_unbounded(rvalue
);
3368 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid CPU quota '%s', ignoring.", rvalue
);
3372 c
->cpu_quota_per_sec_usec
= ((usec_t
) r
* USEC_PER_SEC
) / 1000U;
3376 int config_parse_allowed_cpus(
3378 const char *filename
,
3380 const char *section
,
3381 unsigned section_line
,
3388 CGroupContext
*c
= data
;
3390 (void) parse_cpu_set_extend(rvalue
, &c
->cpuset_cpus
, true, unit
, filename
, line
, lvalue
);
3395 int config_parse_allowed_mems(
3397 const char *filename
,
3399 const char *section
,
3400 unsigned section_line
,
3407 CGroupContext
*c
= data
;
3409 (void) parse_cpu_set_extend(rvalue
, &c
->cpuset_mems
, true, unit
, filename
, line
, lvalue
);
3414 int config_parse_memory_limit(
3416 const char *filename
,
3418 const char *section
,
3419 unsigned section_line
,
3426 CGroupContext
*c
= data
;
3427 uint64_t bytes
= CGROUP_LIMIT_MAX
;
3430 if (STR_IN_SET(lvalue
, "DefaultMemoryLow",
3434 bytes
= CGROUP_LIMIT_MIN
;
3436 if (!isempty(rvalue
) && !streq(rvalue
, "infinity")) {
3438 r
= parse_permille(rvalue
);
3440 r
= parse_size(rvalue
, 1024, &bytes
);
3442 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid memory limit '%s', ignoring: %m", rvalue
);
3446 bytes
= physical_memory_scale(r
, 1000U);
3448 if (bytes
>= UINT64_MAX
||
3449 (bytes
<= 0 && !STR_IN_SET(lvalue
, "MemorySwapMax", "MemoryLow", "MemoryMin", "DefaultMemoryLow", "DefaultMemoryMin"))) {
3450 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Memory limit '%s' out of range, ignoring.", rvalue
);
3455 if (streq(lvalue
, "DefaultMemoryLow")) {
3456 c
->default_memory_low
= bytes
;
3457 c
->default_memory_low_set
= true;
3458 } else if (streq(lvalue
, "DefaultMemoryMin")) {
3459 c
->default_memory_min
= bytes
;
3460 c
->default_memory_min_set
= true;
3461 } else if (streq(lvalue
, "MemoryMin")) {
3462 c
->memory_min
= bytes
;
3463 c
->memory_min_set
= true;
3464 } else if (streq(lvalue
, "MemoryLow")) {
3465 c
->memory_low
= bytes
;
3466 c
->memory_low_set
= true;
3467 } else if (streq(lvalue
, "MemoryHigh"))
3468 c
->memory_high
= bytes
;
3469 else if (streq(lvalue
, "MemoryMax"))
3470 c
->memory_max
= bytes
;
3471 else if (streq(lvalue
, "MemorySwapMax"))
3472 c
->memory_swap_max
= bytes
;
3473 else if (streq(lvalue
, "MemoryLimit"))
3474 c
->memory_limit
= bytes
;
3481 int config_parse_tasks_max(
3483 const char *filename
,
3485 const char *section
,
3486 unsigned section_line
,
3493 const Unit
*u
= userdata
;
3494 TasksMax
*tasks_max
= data
;
3498 if (isempty(rvalue
)) {
3499 *tasks_max
= u
? u
->manager
->default_tasks_max
: TASKS_MAX_UNSET
;
3503 if (streq(rvalue
, "infinity")) {
3504 *tasks_max
= TASKS_MAX_UNSET
;
3508 r
= parse_permille(rvalue
);
3510 *tasks_max
= (TasksMax
) { r
, 1000U }; /* r‰ */
3512 r
= safe_atou64(rvalue
, &v
);
3514 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid maximum tasks value '%s', ignoring: %m", rvalue
);
3518 if (v
<= 0 || v
>= UINT64_MAX
) {
3519 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Maximum tasks value '%s' out of range, ignoring.", rvalue
);
3523 *tasks_max
= (TasksMax
) { v
};
3529 int config_parse_delegate(
3531 const char *filename
,
3533 const char *section
,
3534 unsigned section_line
,
3541 CGroupContext
*c
= data
;
3545 t
= unit_name_to_type(unit
);
3546 assert(t
!= _UNIT_TYPE_INVALID
);
3548 if (!unit_vtable
[t
]->can_delegate
) {
3549 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Delegate= setting not supported for this unit type, ignoring.");
3553 /* We either accept a boolean value, which may be used to turn on delegation for all controllers, or turn it
3554 * off for all. Or it takes a list of controller names, in which case we add the specified controllers to the
3555 * mask to delegate. */
3557 if (isempty(rvalue
)) {
3558 /* An empty string resets controllers and set Delegate=yes. */
3560 c
->delegate_controllers
= 0;
3564 r
= parse_boolean(rvalue
);
3566 const char *p
= rvalue
;
3567 CGroupMask mask
= 0;
3570 _cleanup_free_
char *word
= NULL
;
3571 CGroupController cc
;
3573 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3579 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3583 cc
= cgroup_controller_from_string(word
);
3585 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid controller name '%s', ignoring", word
);
3589 mask
|= CGROUP_CONTROLLER_TO_MASK(cc
);
3593 c
->delegate_controllers
|= mask
;
3597 c
->delegate_controllers
= _CGROUP_MASK_ALL
;
3599 c
->delegate
= false;
3600 c
->delegate_controllers
= 0;
3606 int config_parse_device_allow(
3608 const char *filename
,
3610 const char *section
,
3611 unsigned section_line
,
3618 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3619 CGroupContext
*c
= data
;
3620 const char *p
= rvalue
;
3623 if (isempty(rvalue
)) {
3624 while (c
->device_allow
)
3625 cgroup_context_free_device_allow(c
, c
->device_allow
);
3630 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3634 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3635 "Invalid syntax, ignoring: %s", rvalue
);
3639 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3640 "Failed to extract device path and rights from '%s', ignoring.", rvalue
);
3644 r
= unit_full_printf(userdata
, path
, &resolved
);
3646 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3647 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3651 if (!STARTSWITH_SET(resolved
, "block-", "char-")) {
3653 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3657 if (!valid_device_node_path(resolved
)) {
3658 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device node path '%s', ignoring.", resolved
);
3663 if (!isempty(p
) && !in_charset(p
, "rwm")) {
3664 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device rights '%s', ignoring.", p
);
3668 return cgroup_add_device_allow(c
, resolved
, p
);
3671 int config_parse_io_device_weight(
3673 const char *filename
,
3675 const char *section
,
3676 unsigned section_line
,
3683 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3684 CGroupIODeviceWeight
*w
;
3685 CGroupContext
*c
= data
;
3686 const char *p
= rvalue
;
3694 if (isempty(rvalue
)) {
3695 while (c
->io_device_weights
)
3696 cgroup_context_free_io_device_weight(c
, c
->io_device_weights
);
3701 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3705 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3706 "Invalid syntax, ignoring: %s", rvalue
);
3709 if (r
== 0 || isempty(p
)) {
3710 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3711 "Failed to extract device path and weight from '%s', ignoring.", rvalue
);
3715 r
= unit_full_printf(userdata
, path
, &resolved
);
3717 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3718 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3722 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3726 r
= cg_weight_parse(p
, &u
);
3728 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "IO weight '%s' invalid, ignoring: %m", p
);
3732 assert(u
!= CGROUP_WEIGHT_INVALID
);
3734 w
= new0(CGroupIODeviceWeight
, 1);
3738 w
->path
= TAKE_PTR(resolved
);
3741 LIST_PREPEND(device_weights
, c
->io_device_weights
, w
);
3745 int config_parse_io_device_latency(
3747 const char *filename
,
3749 const char *section
,
3750 unsigned section_line
,
3757 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3758 CGroupIODeviceLatency
*l
;
3759 CGroupContext
*c
= data
;
3760 const char *p
= rvalue
;
3768 if (isempty(rvalue
)) {
3769 while (c
->io_device_latencies
)
3770 cgroup_context_free_io_device_latency(c
, c
->io_device_latencies
);
3775 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3779 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3780 "Invalid syntax, ignoring: %s", rvalue
);
3783 if (r
== 0 || isempty(p
)) {
3784 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3785 "Failed to extract device path and latency from '%s', ignoring.", rvalue
);
3789 r
= unit_full_printf(userdata
, path
, &resolved
);
3791 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3792 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3796 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3800 if (parse_sec(p
, &usec
) < 0) {
3801 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse timer value, ignoring: %s", p
);
3805 l
= new0(CGroupIODeviceLatency
, 1);
3809 l
->path
= TAKE_PTR(resolved
);
3810 l
->target_usec
= usec
;
3812 LIST_PREPEND(device_latencies
, c
->io_device_latencies
, l
);
3816 int config_parse_io_limit(
3818 const char *filename
,
3820 const char *section
,
3821 unsigned section_line
,
3828 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3829 CGroupIODeviceLimit
*l
= NULL
, *t
;
3830 CGroupContext
*c
= data
;
3831 CGroupIOLimitType type
;
3832 const char *p
= rvalue
;
3840 type
= cgroup_io_limit_type_from_string(lvalue
);
3843 if (isempty(rvalue
)) {
3844 LIST_FOREACH(device_limits
, l
, c
->io_device_limits
)
3845 l
->limits
[type
] = cgroup_io_limit_defaults
[type
];
3849 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3853 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3854 "Invalid syntax, ignoring: %s", rvalue
);
3857 if (r
== 0 || isempty(p
)) {
3858 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3859 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
3863 r
= unit_full_printf(userdata
, path
, &resolved
);
3865 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3866 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3870 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3874 if (streq("infinity", p
))
3875 num
= CGROUP_LIMIT_MAX
;
3877 r
= parse_size(p
, 1000, &num
);
3878 if (r
< 0 || num
<= 0) {
3879 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid IO limit '%s', ignoring.", p
);
3884 LIST_FOREACH(device_limits
, t
, c
->io_device_limits
) {
3885 if (path_equal(resolved
, t
->path
)) {
3892 CGroupIOLimitType ttype
;
3894 l
= new0(CGroupIODeviceLimit
, 1);
3898 l
->path
= TAKE_PTR(resolved
);
3899 for (ttype
= 0; ttype
< _CGROUP_IO_LIMIT_TYPE_MAX
; ttype
++)
3900 l
->limits
[ttype
] = cgroup_io_limit_defaults
[ttype
];
3902 LIST_PREPEND(device_limits
, c
->io_device_limits
, l
);
3905 l
->limits
[type
] = num
;
3910 int config_parse_blockio_device_weight(
3912 const char *filename
,
3914 const char *section
,
3915 unsigned section_line
,
3922 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3923 CGroupBlockIODeviceWeight
*w
;
3924 CGroupContext
*c
= data
;
3925 const char *p
= rvalue
;
3933 if (isempty(rvalue
)) {
3934 while (c
->blockio_device_weights
)
3935 cgroup_context_free_blockio_device_weight(c
, c
->blockio_device_weights
);
3940 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3944 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3945 "Invalid syntax, ignoring: %s", rvalue
);
3948 if (r
== 0 || isempty(p
)) {
3949 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3950 "Failed to extract device node and weight from '%s', ignoring.", rvalue
);
3954 r
= unit_full_printf(userdata
, path
, &resolved
);
3956 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3957 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3961 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3965 r
= cg_blkio_weight_parse(p
, &u
);
3967 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid block IO weight '%s', ignoring: %m", p
);
3971 assert(u
!= CGROUP_BLKIO_WEIGHT_INVALID
);
3973 w
= new0(CGroupBlockIODeviceWeight
, 1);
3977 w
->path
= TAKE_PTR(resolved
);
3980 LIST_PREPEND(device_weights
, c
->blockio_device_weights
, w
);
3984 int config_parse_blockio_bandwidth(
3986 const char *filename
,
3988 const char *section
,
3989 unsigned section_line
,
3996 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3997 CGroupBlockIODeviceBandwidth
*b
= NULL
, *t
;
3998 CGroupContext
*c
= data
;
3999 const char *p
= rvalue
;
4008 read
= streq("BlockIOReadBandwidth", lvalue
);
4010 if (isempty(rvalue
)) {
4011 LIST_FOREACH(device_bandwidths
, b
, c
->blockio_device_bandwidths
) {
4012 b
->rbps
= CGROUP_LIMIT_MAX
;
4013 b
->wbps
= CGROUP_LIMIT_MAX
;
4018 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4022 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4023 "Invalid syntax, ignoring: %s", rvalue
);
4026 if (r
== 0 || isempty(p
)) {
4027 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4028 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
4032 r
= unit_full_printf(userdata
, path
, &resolved
);
4034 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4035 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4039 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4043 r
= parse_size(p
, 1000, &bytes
);
4044 if (r
< 0 || bytes
<= 0) {
4045 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid Block IO Bandwidth '%s', ignoring.", p
);
4049 LIST_FOREACH(device_bandwidths
, t
, c
->blockio_device_bandwidths
) {
4050 if (path_equal(resolved
, t
->path
)) {
4057 b
= new0(CGroupBlockIODeviceBandwidth
, 1);
4061 b
->path
= TAKE_PTR(resolved
);
4062 b
->rbps
= CGROUP_LIMIT_MAX
;
4063 b
->wbps
= CGROUP_LIMIT_MAX
;
4065 LIST_PREPEND(device_bandwidths
, c
->blockio_device_bandwidths
, b
);
4076 int config_parse_job_mode_isolate(
4078 const char *filename
,
4080 const char *section
,
4081 unsigned section_line
,
4095 r
= parse_boolean(rvalue
);
4097 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse boolean, ignoring: %s", rvalue
);
4101 log_notice("%s is deprecated. Please use OnFailureJobMode= instead", lvalue
);
4103 *m
= r
? JOB_ISOLATE
: JOB_REPLACE
;
4107 int config_parse_exec_directories(
4109 const char *filename
,
4111 const char *section
,
4112 unsigned section_line
,
4120 const Unit
*u
= userdata
;
4129 if (isempty(rvalue
)) {
4130 /* Empty assignment resets the list */
4131 *rt
= strv_free(*rt
);
4135 for (p
= rvalue
;;) {
4136 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
4138 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
4142 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4143 "Invalid syntax, ignoring: %s", rvalue
);
4149 r
= unit_full_printf(u
, word
, &k
);
4151 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4152 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
4156 r
= path_simplify_and_warn(k
, PATH_CHECK_RELATIVE
, unit
, filename
, line
, lvalue
);
4160 if (path_startswith(k
, "private")) {
4161 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
4162 "%s= path can't be 'private', ignoring assignment: %s", lvalue
, word
);
4166 r
= strv_push(rt
, k
);
4173 int config_parse_set_status(
4175 const char *filename
,
4177 const char *section
,
4178 unsigned section_line
,
4186 const char *word
, *state
;
4188 ExitStatusSet
*status_set
= data
;
4195 /* Empty assignment resets the list */
4196 if (isempty(rvalue
)) {
4197 exit_status_set_free(status_set
);
4201 FOREACH_WORD(word
, l
, rvalue
, state
) {
4202 _cleanup_free_
char *temp
;
4205 temp
= strndup(word
, l
);
4209 /* We need to call exit_status_from_string() first, because we want
4210 * to parse numbers as exit statuses, not signals. */
4212 r
= exit_status_from_string(temp
);
4214 assert(r
>= 0 && r
< 256);
4215 bitmap
= &status_set
->status
;
4217 r
= signal_from_string(temp
);
4220 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
4221 "Failed to parse value, ignoring: %s", word
);
4224 bitmap
= &status_set
->signal
;
4227 r
= bitmap_set(bitmap
, r
);
4229 return log_error_errno(r
, "Failed to set signal or status %s: %m", word
);
4231 if (!isempty(state
))
4232 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Trailing garbage, ignoring.");
4237 int config_parse_namespace_path_strv(
4239 const char *filename
,
4241 const char *section
,
4242 unsigned section_line
,
4249 const Unit
*u
= userdata
;
4251 const char *p
= rvalue
;
4259 if (isempty(rvalue
)) {
4260 /* Empty assignment resets the list */
4261 *sv
= strv_free(*sv
);
4266 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
, *joined
= NULL
;
4268 bool ignore_enoent
= false, shall_prefix
= false;
4270 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
4276 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
4281 if (startswith(w
, "-")) {
4282 ignore_enoent
= true;
4285 if (startswith(w
, "+")) {
4286 shall_prefix
= true;
4290 r
= unit_full_printf(u
, w
, &resolved
);
4292 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", w
);
4296 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4300 joined
= strjoin(ignore_enoent
? "-" : "",
4301 shall_prefix
? "+" : "",
4304 r
= strv_push(sv
, joined
);
4314 int config_parse_temporary_filesystems(
4316 const char *filename
,
4318 const char *section
,
4319 unsigned section_line
,
4326 const Unit
*u
= userdata
;
4327 ExecContext
*c
= data
;
4328 const char *p
= rvalue
;
4336 if (isempty(rvalue
)) {
4337 /* Empty assignment resets the list */
4338 temporary_filesystem_free_many(c
->temporary_filesystems
, c
->n_temporary_filesystems
);
4339 c
->temporary_filesystems
= NULL
;
4340 c
->n_temporary_filesystems
= 0;
4345 _cleanup_free_
char *word
= NULL
, *path
= NULL
, *resolved
= NULL
;
4348 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
4354 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
4359 r
= extract_first_word(&w
, &path
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4363 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", word
);
4367 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid syntax, ignoring: %s", word
);
4371 r
= unit_full_printf(u
, path
, &resolved
);
4373 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", path
);
4377 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4381 r
= temporary_filesystem_add(&c
->temporary_filesystems
, &c
->n_temporary_filesystems
, resolved
, w
);
4387 int config_parse_bind_paths(
4389 const char *filename
,
4391 const char *section
,
4392 unsigned section_line
,
4399 ExecContext
*c
= data
;
4400 const Unit
*u
= userdata
;
4409 if (isempty(rvalue
)) {
4410 /* Empty assignment resets the list */
4411 bind_mount_free_many(c
->bind_mounts
, c
->n_bind_mounts
);
4412 c
->bind_mounts
= NULL
;
4413 c
->n_bind_mounts
= 0;
4419 _cleanup_free_
char *source
= NULL
, *destination
= NULL
;
4420 _cleanup_free_
char *sresolved
= NULL
, *dresolved
= NULL
;
4421 char *s
= NULL
, *d
= NULL
;
4422 bool rbind
= true, ignore_enoent
= false;
4424 r
= extract_first_word(&p
, &source
, ":" WHITESPACE
, EXTRACT_UNQUOTE
|EXTRACT_DONT_COALESCE_SEPARATORS
);
4430 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
4434 r
= unit_full_printf(u
, source
, &sresolved
);
4436 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4437 "Failed to resolved unit specifiers in \"%s\", ignoring: %m", source
);
4443 ignore_enoent
= true;
4447 r
= path_simplify_and_warn(s
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4451 /* Optionally, the destination is specified. */
4452 if (p
&& p
[-1] == ':') {
4453 r
= extract_first_word(&p
, &destination
, ":" WHITESPACE
, EXTRACT_UNQUOTE
|EXTRACT_DONT_COALESCE_SEPARATORS
);
4457 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
4461 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Missing argument after ':', ignoring: %s", s
);
4465 r
= unit_full_printf(u
, destination
, &dresolved
);
4467 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4468 "Failed to resolved specifiers in \"%s\", ignoring: %m", destination
);
4472 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4478 /* Optionally, there's also a short option string specified */
4479 if (p
&& p
[-1] == ':') {
4480 _cleanup_free_
char *options
= NULL
;
4482 r
= extract_first_word(&p
, &options
, NULL
, EXTRACT_UNQUOTE
);
4486 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s: %s", lvalue
, rvalue
);
4490 if (isempty(options
) || streq(options
, "rbind"))
4492 else if (streq(options
, "norbind"))
4495 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid option string, ignoring setting: %s", options
);
4502 r
= bind_mount_add(&c
->bind_mounts
, &c
->n_bind_mounts
,
4506 .read_only
= !!strstr(lvalue
, "ReadOnly"),
4508 .ignore_enoent
= ignore_enoent
,
4517 int config_parse_job_timeout_sec(
4519 const char *filename
,
4521 const char *section
,
4522 unsigned section_line
,
4538 r
= parse_sec_fix_0(rvalue
, &usec
);
4540 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse JobTimeoutSec= parameter, ignoring: %s", rvalue
);
4544 /* If the user explicitly changed JobTimeoutSec= also change JobRunningTimeoutSec=, for compatibility with old
4545 * versions. If JobRunningTimeoutSec= was explicitly set, avoid this however as whatever the user picked should
4548 if (!u
->job_running_timeout_set
)
4549 u
->job_running_timeout
= usec
;
4551 u
->job_timeout
= usec
;
4556 int config_parse_job_running_timeout_sec(
4558 const char *filename
,
4560 const char *section
,
4561 unsigned section_line
,
4577 r
= parse_sec_fix_0(rvalue
, &usec
);
4579 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse JobRunningTimeoutSec= parameter, ignoring: %s", rvalue
);
4583 u
->job_running_timeout
= usec
;
4584 u
->job_running_timeout_set
= true;
4589 int config_parse_emergency_action(
4591 const char *filename
,
4593 const char *section
,
4594 unsigned section_line
,
4602 EmergencyAction
*x
= data
;
4611 m
= ((Unit
*) userdata
)->manager
;
4615 r
= parse_emergency_action(rvalue
, MANAGER_IS_SYSTEM(m
), x
);
4617 if (r
== -EOPNOTSUPP
&& MANAGER_IS_USER(m
)) {
4618 /* Compat mode: remove for systemd 241. */
4620 log_syntax(unit
, LOG_INFO
, filename
, line
, r
,
4621 "%s= in user mode specified as \"%s\", using \"exit-force\" instead.",
4623 *x
= EMERGENCY_ACTION_EXIT_FORCE
;
4627 if (r
== -EOPNOTSUPP
)
4628 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4629 "%s= specified as %s mode action, ignoring: %s",
4630 lvalue
, MANAGER_IS_SYSTEM(m
) ? "user" : "system", rvalue
);
4632 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4633 "Failed to parse %s=, ignoring: %s", lvalue
, rvalue
);
4640 int config_parse_pid_file(
4642 const char *filename
,
4644 const char *section
,
4645 unsigned section_line
,
4652 _cleanup_free_
char *k
= NULL
, *n
= NULL
;
4653 const Unit
*u
= userdata
;
4662 if (isempty(rvalue
)) {
4663 /* An empty assignment removes already set value. */
4668 r
= unit_full_printf(u
, rvalue
, &k
);
4670 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
4674 /* If this is a relative path make it absolute by prefixing the /run */
4675 n
= path_make_absolute(k
, u
->manager
->prefix
[EXEC_DIRECTORY_RUNTIME
]);
4679 /* Check that the result is a sensible path */
4680 r
= path_simplify_and_warn(n
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4684 r
= patch_var_run(unit
, filename
, line
, lvalue
, &n
);
4688 free_and_replace(*s
, n
);
4692 int config_parse_exit_status(
4694 const char *filename
,
4696 const char *section
,
4697 unsigned section_line
,
4704 int *exit_status
= data
, r
;
4710 assert(exit_status
);
4712 if (isempty(rvalue
)) {
4717 r
= safe_atou8(rvalue
, &u
);
4719 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse exit status '%s', ignoring: %m", rvalue
);
4727 int config_parse_disable_controllers(
4729 const char *filename
,
4731 const char *section
,
4732 unsigned section_line
,
4740 CGroupContext
*c
= data
;
4741 CGroupMask disabled_mask
;
4743 /* 1. If empty, make all controllers eligible for use again.
4744 * 2. If non-empty, merge all listed controllers, space separated. */
4746 if (isempty(rvalue
)) {
4747 c
->disable_controllers
= 0;
4751 r
= cg_mask_from_string(rvalue
, &disabled_mask
);
4752 if (r
< 0 || disabled_mask
<= 0) {
4753 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid cgroup string: %s, ignoring", rvalue
);
4757 c
->disable_controllers
|= disabled_mask
;
4762 int config_parse_ip_filter_bpf_progs(
4764 const char *filename
,
4766 const char *section
,
4767 unsigned section_line
,
4774 _cleanup_free_
char *resolved
= NULL
;
4775 const Unit
*u
= userdata
;
4776 char ***paths
= data
;
4784 if (isempty(rvalue
)) {
4785 *paths
= strv_free(*paths
);
4789 r
= unit_full_printf(u
, rvalue
, &resolved
);
4791 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
4795 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4799 if (strv_contains(*paths
, resolved
))
4802 r
= strv_extend(paths
, resolved
);
4806 r
= bpf_firewall_supported();
4809 if (r
!= BPF_FIREWALL_SUPPORTED_WITH_MULTI
) {
4810 static bool warned
= false;
4812 log_full(warned
? LOG_DEBUG
: LOG_WARNING
,
4813 "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"
4814 "Starting this unit will fail! (This warning is only shown for the first loaded unit using IP firewalling.)", filename
, line
, lvalue
, rvalue
);
4822 static int merge_by_names(Unit
**u
, Set
*names
, const char *id
) {
4829 /* Let's try to add in all names that are aliases of this unit */
4830 while ((k
= set_steal_first(names
))) {
4831 _cleanup_free_ _unused_
char *free_k
= k
;
4833 /* First try to merge in the other name into our unit */
4834 r
= unit_merge_by_name(*u
, k
);
4838 /* Hmm, we couldn't merge the other unit into ours? Then let's try it the other way
4841 other
= manager_get_unit((*u
)->manager
, k
);
4843 return r
; /* return previous failure */
4845 r
= unit_merge(other
, *u
);
4850 return merge_by_names(u
, names
, NULL
);
4853 if (streq_ptr(id
, k
))
4854 unit_choose_id(*u
, id
);
4860 int unit_load_fragment(Unit
*u
) {
4861 const char *fragment
;
4862 _cleanup_set_free_free_ Set
*names
= NULL
;
4866 assert(u
->load_state
== UNIT_STUB
);
4870 u
->load_state
= UNIT_LOADED
;
4874 /* Possibly rebuild the fragment map to catch new units */
4875 r
= unit_file_build_name_map(&u
->manager
->lookup_paths
,
4876 &u
->manager
->unit_cache_mtime
,
4877 &u
->manager
->unit_id_map
,
4878 &u
->manager
->unit_name_map
,
4879 &u
->manager
->unit_path_cache
);
4881 return log_error_errno(r
, "Failed to rebuild name map: %m");
4883 r
= unit_file_find_fragment(u
->manager
->unit_id_map
,
4884 u
->manager
->unit_name_map
,
4888 if (r
< 0 && r
!= -ENOENT
)
4892 /* Open the file, check if this is a mask, otherwise read. */
4893 _cleanup_fclose_
FILE *f
= NULL
;
4896 /* Try to open the file name. A symlink is OK, for example for linked files or masks. We
4897 * expect that all symlinks within the lookup paths have been already resolved, but we don't
4898 * verify this here. */
4899 f
= fopen(fragment
, "re");
4901 return log_unit_notice_errno(u
, errno
, "Failed to open %s: %m", fragment
);
4903 if (fstat(fileno(f
), &st
) < 0)
4906 r
= free_and_strdup(&u
->fragment_path
, fragment
);
4910 if (null_or_empty(&st
)) {
4911 /* Unit file is masked */
4913 u
->load_state
= u
->perpetual
? UNIT_LOADED
: UNIT_MASKED
; /* don't allow perpetual units to ever be masked */
4914 u
->fragment_mtime
= 0;
4916 u
->load_state
= UNIT_LOADED
;
4917 u
->fragment_mtime
= timespec_load(&st
.st_mtim
);
4919 /* Now, parse the file contents */
4920 r
= config_parse(u
->id
, fragment
, f
,
4921 UNIT_VTABLE(u
)->sections
,
4922 config_item_perf_lookup
, load_fragment_gperf_lookup
,
4927 log_unit_notice_errno(u
, r
, "Unit configuration has fatal error, unit will not be started.");
4933 /* We do the merge dance here because for some unit types, the unit might have aliases which are not
4934 * declared in the file system. In particular, this is true (and frequent) for device and swap units.
4937 const char *id
= u
->id
;
4938 _cleanup_free_
char *free_id
= NULL
;
4941 id
= basename(fragment
);
4942 if (unit_name_is_valid(id
, UNIT_NAME_TEMPLATE
)) {
4943 assert(u
->instance
); /* If we're not trying to use a template for non-instanced unit,
4944 * this must be set. */
4946 r
= unit_name_replace_instance(id
, u
->instance
, &free_id
);
4948 return log_debug_errno(r
, "Failed to build id (%s + %s): %m", id
, u
->instance
);
4954 r
= merge_by_names(&merged
, names
, id
);
4959 u
->load_state
= UNIT_MERGED
;
4964 void unit_dump_config_items(FILE *f
) {
4965 static const struct {
4966 const ConfigParserCallback callback
;
4969 { config_parse_warn_compat
, "NOTSUPPORTED" },
4970 { config_parse_int
, "INTEGER" },
4971 { config_parse_unsigned
, "UNSIGNED" },
4972 { config_parse_iec_size
, "SIZE" },
4973 { config_parse_iec_uint64
, "SIZE" },
4974 { config_parse_si_uint64
, "SIZE" },
4975 { config_parse_bool
, "BOOLEAN" },
4976 { config_parse_string
, "STRING" },
4977 { config_parse_path
, "PATH" },
4978 { config_parse_unit_path_printf
, "PATH" },
4979 { config_parse_strv
, "STRING [...]" },
4980 { config_parse_exec_nice
, "NICE" },
4981 { config_parse_exec_oom_score_adjust
, "OOMSCOREADJUST" },
4982 { config_parse_exec_io_class
, "IOCLASS" },
4983 { config_parse_exec_io_priority
, "IOPRIORITY" },
4984 { config_parse_exec_cpu_sched_policy
, "CPUSCHEDPOLICY" },
4985 { config_parse_exec_cpu_sched_prio
, "CPUSCHEDPRIO" },
4986 { config_parse_exec_cpu_affinity
, "CPUAFFINITY" },
4987 { config_parse_mode
, "MODE" },
4988 { config_parse_unit_env_file
, "FILE" },
4989 { config_parse_exec_output
, "OUTPUT" },
4990 { config_parse_exec_input
, "INPUT" },
4991 { config_parse_log_facility
, "FACILITY" },
4992 { config_parse_log_level
, "LEVEL" },
4993 { config_parse_exec_secure_bits
, "SECUREBITS" },
4994 { config_parse_capability_set
, "BOUNDINGSET" },
4995 { config_parse_rlimit
, "LIMIT" },
4996 { config_parse_unit_deps
, "UNIT [...]" },
4997 { config_parse_exec
, "PATH [ARGUMENT [...]]" },
4998 { config_parse_service_type
, "SERVICETYPE" },
4999 { config_parse_service_restart
, "SERVICERESTART" },
5000 { config_parse_service_timeout_failure_mode
, "TIMEOUTMODE" },
5001 { config_parse_kill_mode
, "KILLMODE" },
5002 { config_parse_signal
, "SIGNAL" },
5003 { config_parse_socket_listen
, "SOCKET [...]" },
5004 { config_parse_socket_bind
, "SOCKETBIND" },
5005 { config_parse_socket_bindtodevice
, "NETWORKINTERFACE" },
5006 { config_parse_sec
, "SECONDS" },
5007 { config_parse_nsec
, "NANOSECONDS" },
5008 { config_parse_namespace_path_strv
, "PATH [...]" },
5009 { config_parse_bind_paths
, "PATH[:PATH[:OPTIONS]] [...]" },
5010 { config_parse_unit_requires_mounts_for
, "PATH [...]" },
5011 { config_parse_exec_mount_flags
, "MOUNTFLAG [...]" },
5012 { config_parse_unit_string_printf
, "STRING" },
5013 { config_parse_trigger_unit
, "UNIT" },
5014 { config_parse_timer
, "TIMER" },
5015 { config_parse_path_spec
, "PATH" },
5016 { config_parse_notify_access
, "ACCESS" },
5017 { config_parse_ip_tos
, "TOS" },
5018 { config_parse_unit_condition_path
, "CONDITION" },
5019 { config_parse_unit_condition_string
, "CONDITION" },
5020 { config_parse_unit_condition_null
, "CONDITION" },
5021 { config_parse_unit_slice
, "SLICE" },
5022 { config_parse_documentation
, "URL" },
5023 { config_parse_service_timeout
, "SECONDS" },
5024 { config_parse_emergency_action
, "ACTION" },
5025 { config_parse_set_status
, "STATUS" },
5026 { config_parse_service_sockets
, "SOCKETS" },
5027 { config_parse_environ
, "ENVIRON" },
5029 { config_parse_syscall_filter
, "SYSCALLS" },
5030 { config_parse_syscall_archs
, "ARCHS" },
5031 { config_parse_syscall_errno
, "ERRNO" },
5032 { config_parse_address_families
, "FAMILIES" },
5033 { config_parse_restrict_namespaces
, "NAMESPACES" },
5035 { config_parse_cpu_shares
, "SHARES" },
5036 { config_parse_cg_weight
, "WEIGHT" },
5037 { config_parse_memory_limit
, "LIMIT" },
5038 { config_parse_device_allow
, "DEVICE" },
5039 { config_parse_device_policy
, "POLICY" },
5040 { config_parse_io_limit
, "LIMIT" },
5041 { config_parse_io_device_weight
, "DEVICEWEIGHT" },
5042 { config_parse_io_device_latency
, "DEVICELATENCY" },
5043 { config_parse_blockio_bandwidth
, "BANDWIDTH" },
5044 { config_parse_blockio_weight
, "WEIGHT" },
5045 { config_parse_blockio_device_weight
, "DEVICEWEIGHT" },
5046 { config_parse_long
, "LONG" },
5047 { config_parse_socket_service
, "SERVICE" },
5049 { config_parse_exec_selinux_context
, "LABEL" },
5051 { config_parse_job_mode
, "MODE" },
5052 { config_parse_job_mode_isolate
, "BOOLEAN" },
5053 { config_parse_personality
, "PERSONALITY" },
5056 const char *prev
= NULL
;
5061 NULSTR_FOREACH(i
, load_fragment_gperf_nulstr
) {
5062 const char *rvalue
= "OTHER", *lvalue
;
5063 const ConfigPerfItem
*p
;
5068 assert_se(p
= load_fragment_gperf_lookup(i
, strlen(i
)));
5070 /* Hide legacy settings */
5071 if (p
->parse
== config_parse_warn_compat
&&
5072 p
->ltype
== DISABLED_LEGACY
)
5075 for (j
= 0; j
< ELEMENTSOF(table
); j
++)
5076 if (p
->parse
== table
[j
].callback
) {
5077 rvalue
= table
[j
].rvalue
;
5081 dot
= strchr(i
, '.');
5082 lvalue
= dot
? dot
+ 1 : i
;
5086 if (!prev
|| !strneq(prev
, i
, prefix_len
+1)) {
5090 fprintf(f
, "[%.*s]\n", (int) prefix_len
, i
);
5093 fprintf(f
, "%s=%s\n", lvalue
, rvalue
);
5098 int config_parse_cpu_affinity2(
5100 const char *filename
,
5102 const char *section
,
5103 unsigned section_line
,
5110 CPUSet
*affinity
= data
;
5114 (void) parse_cpu_set_extend(rvalue
, affinity
, true, unit
, filename
, line
, lvalue
);
5119 int config_parse_show_status(
5121 const char *filename
,
5123 const char *section
,
5124 unsigned section_line
,
5132 ShowStatus
*b
= data
;
5139 k
= parse_show_status(rvalue
, b
);
5141 log_syntax(unit
, LOG_ERR
, filename
, line
, k
, "Failed to parse show status setting, ignoring: %s", rvalue
);
5148 int config_parse_output_restricted(
5150 const char *filename
,
5152 const char *section
,
5153 unsigned section_line
,
5160 ExecOutput t
, *eo
= data
;
5161 bool obsolete
= false;
5168 if (streq(rvalue
, "syslog")) {
5169 t
= EXEC_OUTPUT_JOURNAL
;
5171 } else if (streq(rvalue
, "syslog+console")) {
5172 t
= EXEC_OUTPUT_JOURNAL_AND_CONSOLE
;
5175 t
= exec_output_from_string(rvalue
);
5177 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse output type, ignoring: %s", rvalue
);
5181 if (IN_SET(t
, EXEC_OUTPUT_SOCKET
, EXEC_OUTPUT_NAMED_FD
, EXEC_OUTPUT_FILE
, EXEC_OUTPUT_FILE_APPEND
)) {
5182 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Standard output types socket, fd:, file:, append: are not supported as defaults, ignoring: %s", rvalue
);
5188 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
5189 "Standard output type %s is obsolete, automatically updating to %s. Please update your configuration.",
5190 rvalue
, exec_output_to_string(t
));
5196 int config_parse_crash_chvt(
5198 const char *filename
,
5200 const char *section
,
5201 unsigned section_line
,
5215 r
= parse_crash_chvt(rvalue
, data
);
5217 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse CrashChangeVT= setting, ignoring: %s", rvalue
);
5224 int config_parse_swap_priority(
5226 const char *filename
,
5228 const char *section
,
5229 unsigned section_line
,
5245 if (isempty(rvalue
)) {
5246 s
->parameters_fragment
.priority
= -1;
5247 s
->parameters_fragment
.priority_set
= false;
5251 r
= safe_atoi(rvalue
, &priority
);
5253 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid swap priority '%s', ignoring.", rvalue
);
5257 if (priority
< -1) {
5258 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Sorry, swap priorities smaller than -1 may only be assigned by the kernel itself, ignoring: %s", rvalue
);
5262 if (priority
> 32767) {
5263 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Swap priority out of range, ignoring: %s", rvalue
);
5267 s
->parameters_fragment
.priority
= priority
;
5268 s
->parameters_fragment
.priority_set
= true;