1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 Copyright © 2012 Holger Hans Peter Freyther
14 #include <sys/resource.h>
16 #include "sd-messages.h"
19 #include "alloc-util.h"
20 #include "all-units.h"
21 #include "bpf-firewall.h"
22 #include "bus-error.h"
23 #include "bus-internal.h"
26 #include "capability-util.h"
27 #include "cgroup-setup.h"
28 #include "conf-parser.h"
29 #include "cpu-set-util.h"
31 #include "errno-list.h"
36 #include "hexdecoct.h"
39 #include "ip-protocol-list.h"
40 #include "journal-util.h"
41 #include "limits-util.h"
42 #include "load-fragment.h"
44 #include "mountpoint-util.h"
45 #include "nulstr-util.h"
46 #include "parse-util.h"
47 #include "path-util.h"
48 #include "process-util.h"
50 #include "seccomp-util.h"
52 #include "securebits-util.h"
53 #include "signal-util.h"
54 #include "socket-netlink.h"
55 #include "stat-util.h"
56 #include "string-util.h"
58 #include "syslog-util.h"
59 #include "time-util.h"
60 #include "unit-name.h"
61 #include "unit-printf.h"
62 #include "user-util.h"
65 static int parse_socket_protocol(const char *s
) {
68 r
= parse_ip_protocol(s
);
71 if (!IN_SET(r
, IPPROTO_UDPLITE
, IPPROTO_SCTP
))
72 return -EPROTONOSUPPORT
;
77 int parse_crash_chvt(const char *value
, int *data
) {
80 if (safe_atoi(value
, data
) >= 0)
83 b
= parse_boolean(value
);
88 *data
= 0; /* switch to where kmsg goes */
90 *data
= -1; /* turn off switching */
95 int parse_confirm_spawn(const char *value
, char **console
) {
99 r
= value
? parse_boolean(value
) : 1;
103 } else if (r
> 0) /* on with default tty */
104 s
= strdup("/dev/console");
105 else if (is_path(value
)) /* on with fully qualified path */
107 else /* on with only a tty file name, not a fully qualified path */
108 s
= path_join("/dev/", value
);
116 DEFINE_CONFIG_PARSE(config_parse_socket_protocol
, parse_socket_protocol
, "Failed to parse socket protocol");
117 DEFINE_CONFIG_PARSE(config_parse_exec_secure_bits
, secure_bits_from_string
, "Failed to parse secure bits");
118 DEFINE_CONFIG_PARSE_ENUM(config_parse_collect_mode
, collect_mode
, CollectMode
, "Failed to parse garbage collection mode");
119 DEFINE_CONFIG_PARSE_ENUM(config_parse_device_policy
, cgroup_device_policy
, CGroupDevicePolicy
, "Failed to parse device policy");
120 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_keyring_mode
, exec_keyring_mode
, ExecKeyringMode
, "Failed to parse keyring mode");
121 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_utmp_mode
, exec_utmp_mode
, ExecUtmpMode
, "Failed to parse utmp mode");
122 DEFINE_CONFIG_PARSE_ENUM(config_parse_job_mode
, job_mode
, JobMode
, "Failed to parse job mode");
123 DEFINE_CONFIG_PARSE_ENUM(config_parse_notify_access
, notify_access
, NotifyAccess
, "Failed to parse notify access specifier");
124 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_home
, protect_home
, ProtectHome
, "Failed to parse protect home value");
125 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_system
, protect_system
, ProtectSystem
, "Failed to parse protect system value");
126 DEFINE_CONFIG_PARSE_ENUM(config_parse_runtime_preserve_mode
, exec_preserve_mode
, ExecPreserveMode
, "Failed to parse runtime directory preserve mode");
127 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_type
, service_type
, ServiceType
, "Failed to parse service type");
128 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart
, service_restart
, ServiceRestart
, "Failed to parse service restart specifier");
129 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_timeout_failure_mode
, service_timeout_failure_mode
, ServiceTimeoutFailureMode
, "Failed to parse timeout failure mode");
130 DEFINE_CONFIG_PARSE_ENUM(config_parse_socket_bind
, socket_address_bind_ipv6_only_or_bool
, SocketAddressBindIPv6Only
, "Failed to parse bind IPv6 only value");
131 DEFINE_CONFIG_PARSE_ENUM(config_parse_oom_policy
, oom_policy
, OOMPolicy
, "Failed to parse OOM policy");
132 DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_ip_tos
, ip_tos
, int, -1, "Failed to parse IP TOS value");
133 DEFINE_CONFIG_PARSE_PTR(config_parse_blockio_weight
, cg_blkio_weight_parse
, uint64_t, "Invalid block IO weight");
134 DEFINE_CONFIG_PARSE_PTR(config_parse_cg_weight
, cg_weight_parse
, uint64_t, "Invalid weight");
135 DEFINE_CONFIG_PARSE_PTR(config_parse_cpu_shares
, cg_cpu_shares_parse
, uint64_t, "Invalid CPU shares");
136 DEFINE_CONFIG_PARSE_PTR(config_parse_exec_mount_flags
, mount_propagation_flags_from_string
, unsigned long, "Failed to parse mount flag");
137 DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_numa_policy
, mpol
, int, -1, "Invalid NUMA policy type");
138 DEFINE_CONFIG_PARSE_ENUM(config_parse_status_unit_format
, status_unit_format
, StatusUnitFormat
, "Failed to parse status unit format");
140 int config_parse_unit_deps(
142 const char *filename
,
145 unsigned section_line
,
152 UnitDependency d
= ltype
;
162 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
165 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_RETAIN_ESCAPE
);
171 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
175 r
= unit_name_printf(u
, word
, &k
);
177 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
181 r
= unit_add_dependency_by_name(u
, d
, k
, true, UNIT_DEPENDENCY_FILE
);
183 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
189 int config_parse_obsolete_unit_deps(
191 const char *filename
,
194 unsigned section_line
,
201 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
202 "Unit dependency type %s= is obsolete, replacing by %s=, please update your unit file", lvalue
, unit_dependency_to_string(ltype
));
204 return config_parse_unit_deps(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
);
207 int config_parse_unit_string_printf(
209 const char *filename
,
212 unsigned section_line
,
219 _cleanup_free_
char *k
= NULL
;
220 const Unit
*u
= userdata
;
228 r
= unit_full_printf(u
, rvalue
, &k
);
230 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
234 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
237 int config_parse_unit_strv_printf(
239 const char *filename
,
242 unsigned section_line
,
249 const Unit
*u
= userdata
;
250 _cleanup_free_
char *k
= NULL
;
258 r
= unit_full_printf(u
, rvalue
, &k
);
260 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
264 return config_parse_strv(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
267 int config_parse_unit_path_printf(
269 const char *filename
,
272 unsigned section_line
,
279 _cleanup_free_
char *k
= NULL
;
280 const Unit
*u
= userdata
;
289 /* Let's not bother with anything that is too long */
290 if (strlen(rvalue
) >= PATH_MAX
) {
291 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
292 "%s value too long%s.",
293 lvalue
, fatal
? "" : ", ignoring");
294 return fatal
? -ENAMETOOLONG
: 0;
297 r
= unit_full_printf(u
, rvalue
, &k
);
299 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
300 "Failed to resolve unit specifiers in '%s'%s: %m",
301 rvalue
, fatal
? "" : ", ignoring");
302 return fatal
? -ENOEXEC
: 0;
305 return config_parse_path(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
308 int config_parse_unit_path_strv_printf(
310 const char *filename
,
313 unsigned section_line
,
321 const Unit
*u
= userdata
;
330 if (isempty(rvalue
)) {
336 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
338 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
344 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
345 "Invalid syntax, ignoring: %s", rvalue
);
349 r
= unit_full_printf(u
, word
, &k
);
351 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
352 "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
356 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
360 r
= strv_consume(x
, TAKE_PTR(k
));
366 static int patch_var_run(
368 const char *filename
,
376 e
= path_startswith(*path
, "/var/run/");
380 z
= path_join("/run/", e
);
384 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
385 "%s= references a path below legacy directory /var/run/, updating %s → %s; "
386 "please update the unit file accordingly.", lvalue
, *path
, z
);
388 free_and_replace(*path
, z
);
393 int config_parse_socket_listen(
395 const char *filename
,
398 unsigned section_line
,
405 _cleanup_free_ SocketPort
*p
= NULL
;
417 if (isempty(rvalue
)) {
418 /* An empty assignment removes all ports */
419 socket_free_ports(s
);
423 p
= new0(SocketPort
, 1);
427 if (ltype
!= SOCKET_SOCKET
) {
428 _cleanup_free_
char *k
= NULL
;
430 r
= unit_full_printf(UNIT(s
), rvalue
, &k
);
432 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
436 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
440 if (ltype
== SOCKET_FIFO
) {
441 r
= patch_var_run(unit
, filename
, line
, lvalue
, &k
);
446 free_and_replace(p
->path
, k
);
449 } else if (streq(lvalue
, "ListenNetlink")) {
450 _cleanup_free_
char *k
= NULL
;
452 r
= unit_full_printf(UNIT(s
), rvalue
, &k
);
454 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
458 r
= socket_address_parse_netlink(&p
->address
, k
);
460 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse address value in '%s', ignoring: %m", k
);
464 p
->type
= SOCKET_SOCKET
;
467 _cleanup_free_
char *k
= NULL
;
469 r
= unit_full_printf(UNIT(s
), rvalue
, &k
);
471 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
475 if (k
[0] == '/') { /* Only for AF_UNIX file system sockets… */
476 r
= patch_var_run(unit
, filename
, line
, lvalue
, &k
);
481 r
= socket_address_parse_and_warn(&p
->address
, k
);
483 if (r
!= -EAFNOSUPPORT
)
484 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse address value in '%s', ignoring: %m", k
);
488 if (streq(lvalue
, "ListenStream"))
489 p
->address
.type
= SOCK_STREAM
;
490 else if (streq(lvalue
, "ListenDatagram"))
491 p
->address
.type
= SOCK_DGRAM
;
493 assert(streq(lvalue
, "ListenSequentialPacket"));
494 p
->address
.type
= SOCK_SEQPACKET
;
497 if (socket_address_family(&p
->address
) != AF_LOCAL
&& p
->address
.type
== SOCK_SEQPACKET
) {
498 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Address family not supported, ignoring: %s", rvalue
);
502 p
->type
= SOCKET_SOCKET
;
506 p
->auxiliary_fds
= NULL
;
507 p
->n_auxiliary_fds
= 0;
510 LIST_FIND_TAIL(port
, s
->ports
, tail
);
511 LIST_INSERT_AFTER(port
, s
->ports
, tail
, p
);
518 int config_parse_exec_nice(
520 const char *filename
,
523 unsigned section_line
,
530 ExecContext
*c
= data
;
538 if (isempty(rvalue
)) {
543 r
= parse_nice(rvalue
, &priority
);
546 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Nice priority out of range, ignoring: %s", rvalue
);
548 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse nice priority '%s', ignoring: %m", rvalue
);
558 int config_parse_exec_oom_score_adjust(
560 const char *filename
,
563 unsigned section_line
,
570 ExecContext
*c
= data
;
578 if (isempty(rvalue
)) {
579 c
->oom_score_adjust_set
= false;
583 r
= parse_oom_score_adjust(rvalue
, &oa
);
586 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "OOM score adjust value out of range, ignoring: %s", rvalue
);
588 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse the OOM score adjust value '%s', ignoring: %m", rvalue
);
592 c
->oom_score_adjust
= oa
;
593 c
->oom_score_adjust_set
= true;
598 int config_parse_exec_coredump_filter(
600 const char *filename
,
603 unsigned section_line
,
610 ExecContext
*c
= data
;
618 if (isempty(rvalue
)) {
619 c
->coredump_filter
= 0;
620 c
->coredump_filter_set
= false;
625 r
= coredump_filter_mask_from_string(rvalue
, &f
);
627 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
628 "Failed to parse the CoredumpFilter=%s, ignoring: %m", rvalue
);
632 c
->coredump_filter
|= f
;
633 c
->oom_score_adjust_set
= true;
637 int config_parse_kill_mode(
639 const char *filename
,
642 unsigned section_line
,
649 KillMode
*k
= data
, m
;
656 if (isempty(rvalue
)) {
657 *k
= KILL_CONTROL_GROUP
;
661 m
= kill_mode_from_string(rvalue
);
663 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
664 "Failed to parse kill mode specification, ignoring: %s", rvalue
);
669 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
670 "Unit configured to use KillMode=none. "
671 "This is unsafe, as it disables systemd's process lifecycle management for the service. "
672 "Please update your service to use a safer KillMode=, such as 'mixed' or 'control-group'. "
673 "Support for KillMode=none is deprecated and will eventually be removed.");
679 int config_parse_exec(
681 const char *filename
,
684 unsigned section_line
,
691 ExecCommand
**e
= data
;
692 const Unit
*u
= userdata
;
704 if (isempty(rvalue
)) {
705 /* An empty assignment resets the list */
706 *e
= exec_command_free_list(*e
);
712 _cleanup_free_
char *path
= NULL
, *firstword
= NULL
;
713 ExecCommandFlags flags
= 0;
714 bool ignore
= false, separate_argv0
= false;
715 _cleanup_free_ ExecCommand
*nce
= NULL
;
716 _cleanup_strv_free_
char **n
= NULL
;
717 size_t nlen
= 0, nbufsize
= 0;
722 r
= extract_first_word_and_warn(&p
, &firstword
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
728 /* We accept an absolute path as first argument. If it's prefixed with - and the path doesn't
729 * exist, we ignore it instead of erroring out; if it's prefixed with @, we allow overriding of
730 * argv[0]; if it's prefixed with :, we will not do environment variable substitution;
731 * if it's prefixed with +, it will be run with full privileges and no sandboxing; if
732 * it's prefixed with '!' we apply sandboxing, but do not change user/group credentials; if
733 * it's prefixed with '!!', then we apply user/group credentials if the kernel supports ambient
734 * capabilities -- if it doesn't we don't apply the credentials themselves, but do apply most
735 * other sandboxing, with some special exceptions for changing UID.
737 * The idea is that '!!' may be used to write services that can take benefit of systemd's
738 * UID/GID dropping if the kernel supports ambient creds, but provide an automatic fallback to
739 * privilege dropping within the daemon if the kernel does not offer that. */
741 if (*f
== '-' && !(flags
& EXEC_COMMAND_IGNORE_FAILURE
)) {
742 flags
|= EXEC_COMMAND_IGNORE_FAILURE
;
744 } else if (*f
== '@' && !separate_argv0
)
745 separate_argv0
= true;
746 else if (*f
== ':' && !(flags
& EXEC_COMMAND_NO_ENV_EXPAND
))
747 flags
|= EXEC_COMMAND_NO_ENV_EXPAND
;
748 else if (*f
== '+' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
749 flags
|= EXEC_COMMAND_FULLY_PRIVILEGED
;
750 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
751 flags
|= EXEC_COMMAND_NO_SETUID
;
752 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_AMBIENT_MAGIC
))) {
753 flags
&= ~EXEC_COMMAND_NO_SETUID
;
754 flags
|= EXEC_COMMAND_AMBIENT_MAGIC
;
760 r
= unit_full_printf(u
, f
, &path
);
762 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
763 "Failed to resolve unit specifiers in '%s'%s: %m",
764 f
, ignore
? ", ignoring" : "");
765 return ignore
? 0 : -ENOEXEC
;
769 /* First word is either "-" or "@" with no command. */
770 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
771 "Empty path in command line%s: '%s'",
772 ignore
? ", ignoring" : "", rvalue
);
773 return ignore
? 0 : -ENOEXEC
;
775 if (!string_is_safe(path
)) {
776 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
777 "Executable name contains special characters%s: %s",
778 ignore
? ", ignoring" : "", path
);
779 return ignore
? 0 : -ENOEXEC
;
781 if (endswith(path
, "/")) {
782 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
783 "Executable path specifies a directory%s: %s",
784 ignore
? ", ignoring" : "", path
);
785 return ignore
? 0 : -ENOEXEC
;
788 if (!path_is_absolute(path
)) {
792 if (!filename_is_valid(path
)) {
793 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
794 "Neither a valid executable name nor an absolute path%s: %s",
795 ignore
? ", ignoring" : "", path
);
796 return ignore
? 0 : -ENOEXEC
;
799 /* Resolve a single-component name to a full path */
800 NULSTR_FOREACH(prefix
, DEFAULT_PATH_NULSTR
) {
801 _cleanup_free_
char *fullpath
= NULL
;
803 fullpath
= path_join(prefix
, path
);
807 if (access(fullpath
, F_OK
) >= 0) {
808 free_and_replace(path
, fullpath
);
815 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
816 "Executable \"%s\" not found in path \"%s\"%s",
817 path
, DEFAULT_PATH
, ignore
? ", ignoring" : "");
818 return ignore
? 0 : -ENOEXEC
;
822 if (!separate_argv0
) {
825 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
835 path_simplify(path
, false);
837 while (!isempty(p
)) {
838 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
840 /* Check explicitly for an unquoted semicolon as
841 * command separator token. */
842 if (p
[0] == ';' && (!p
[1] || strchr(WHITESPACE
, p
[1]))) {
844 p
+= strspn(p
, WHITESPACE
);
849 /* Check for \; explicitly, to not confuse it with \\; or "\;" or "\\;" etc.
850 * extract_first_word() would return the same for all of those. */
851 if (p
[0] == '\\' && p
[1] == ';' && (!p
[2] || strchr(WHITESPACE
, p
[2]))) {
855 p
+= strspn(p
, WHITESPACE
);
857 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
868 r
= extract_first_word_and_warn(&p
, &word
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
872 return ignore
? 0 : -ENOEXEC
;
874 r
= unit_full_printf(u
, word
, &resolved
);
876 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
877 "Failed to resolve unit specifiers in %s%s: %m",
878 word
, ignore
? ", ignoring" : "");
879 return ignore
? 0 : -ENOEXEC
;
882 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
885 n
[nlen
++] = TAKE_PTR(resolved
);
890 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
891 "Empty executable name or zeroeth argument%s: %s",
892 ignore
? ", ignoring" : "", rvalue
);
893 return ignore
? 0 : -ENOEXEC
;
896 nce
= new0(ExecCommand
, 1);
900 nce
->argv
= TAKE_PTR(n
);
901 nce
->path
= TAKE_PTR(path
);
904 exec_command_append_list(e
, nce
);
906 /* Do not _cleanup_free_ these. */
915 int config_parse_socket_bindtodevice(
917 const char *filename
,
920 unsigned section_line
,
934 if (isempty(rvalue
) || streq(rvalue
, "*")) {
935 s
->bind_to_device
= mfree(s
->bind_to_device
);
939 if (!ifname_valid(rvalue
)) {
940 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid interface name, ignoring: %s", rvalue
);
944 if (free_and_strdup(&s
->bind_to_device
, rvalue
) < 0)
950 int config_parse_exec_input(
952 const char *filename
,
955 unsigned section_line
,
962 ExecContext
*c
= data
;
963 const Unit
*u
= userdata
;
973 n
= startswith(rvalue
, "fd:");
975 _cleanup_free_
char *resolved
= NULL
;
977 r
= unit_full_printf(u
, n
, &resolved
);
979 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s': %m", n
);
981 if (isempty(resolved
))
982 resolved
= mfree(resolved
);
983 else if (!fdname_is_valid(resolved
)) {
984 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name: %s", resolved
);
988 free_and_replace(c
->stdio_fdname
[STDIN_FILENO
], resolved
);
990 ei
= EXEC_INPUT_NAMED_FD
;
992 } else if ((n
= startswith(rvalue
, "file:"))) {
993 _cleanup_free_
char *resolved
= NULL
;
995 r
= unit_full_printf(u
, n
, &resolved
);
997 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s': %m", n
);
999 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1003 free_and_replace(c
->stdio_file
[STDIN_FILENO
], resolved
);
1005 ei
= EXEC_INPUT_FILE
;
1008 ei
= exec_input_from_string(rvalue
);
1010 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse input specifier, ignoring: %s", rvalue
);
1019 int config_parse_exec_input_text(
1021 const char *filename
,
1023 const char *section
,
1024 unsigned section_line
,
1031 _cleanup_free_
char *unescaped
= NULL
, *resolved
= NULL
;
1032 ExecContext
*c
= data
;
1033 const Unit
*u
= userdata
;
1043 if (isempty(rvalue
)) {
1044 /* Reset if the empty string is assigned */
1045 c
->stdin_data
= mfree(c
->stdin_data
);
1046 c
->stdin_data_size
= 0;
1050 r
= cunescape(rvalue
, 0, &unescaped
);
1052 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to decode C escaped text '%s': %m", rvalue
);
1054 r
= unit_full_printf(u
, unescaped
, &resolved
);
1056 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s': %m", unescaped
);
1058 sz
= strlen(resolved
);
1059 if (c
->stdin_data_size
+ sz
+ 1 < c
->stdin_data_size
|| /* check for overflow */
1060 c
->stdin_data_size
+ sz
+ 1 > EXEC_STDIN_DATA_MAX
) {
1061 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
);
1065 p
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
+ 1);
1069 *((char*) mempcpy((char*) p
+ c
->stdin_data_size
, resolved
, sz
)) = '\n';
1072 c
->stdin_data_size
+= sz
+ 1;
1077 int config_parse_exec_input_data(
1079 const char *filename
,
1081 const char *section
,
1082 unsigned section_line
,
1089 _cleanup_free_
void *p
= NULL
;
1090 ExecContext
*c
= data
;
1100 if (isempty(rvalue
)) {
1101 /* Reset if the empty string is assigned */
1102 c
->stdin_data
= mfree(c
->stdin_data
);
1103 c
->stdin_data_size
= 0;
1107 r
= unbase64mem(rvalue
, (size_t) -1, &p
, &sz
);
1109 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to decode base64 data, ignoring: %s", rvalue
);
1113 if (c
->stdin_data_size
+ sz
< c
->stdin_data_size
|| /* check for overflow */
1114 c
->stdin_data_size
+ sz
> EXEC_STDIN_DATA_MAX
) {
1115 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
);
1119 q
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
);
1123 memcpy((uint8_t*) q
+ c
->stdin_data_size
, p
, sz
);
1126 c
->stdin_data_size
+= sz
;
1131 int config_parse_exec_output(
1133 const char *filename
,
1135 const char *section
,
1136 unsigned section_line
,
1143 _cleanup_free_
char *resolved
= NULL
;
1145 ExecContext
*c
= data
;
1146 const Unit
*u
= userdata
;
1147 bool obsolete
= false;
1157 n
= startswith(rvalue
, "fd:");
1159 r
= unit_full_printf(u
, n
, &resolved
);
1161 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", n
);
1163 if (isempty(resolved
))
1164 resolved
= mfree(resolved
);
1165 else if (!fdname_is_valid(resolved
)) {
1166 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name: %s", resolved
);
1170 eo
= EXEC_OUTPUT_NAMED_FD
;
1172 } else if (streq(rvalue
, "syslog")) {
1173 eo
= EXEC_OUTPUT_JOURNAL
;
1176 } else if (streq(rvalue
, "syslog+console")) {
1177 eo
= EXEC_OUTPUT_JOURNAL_AND_CONSOLE
;
1180 } else if ((n
= startswith(rvalue
, "file:"))) {
1182 r
= unit_full_printf(u
, n
, &resolved
);
1184 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", n
);
1186 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1190 eo
= EXEC_OUTPUT_FILE
;
1192 } else if ((n
= startswith(rvalue
, "append:"))) {
1194 r
= unit_full_printf(u
, n
, &resolved
);
1196 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", n
);
1198 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1202 eo
= EXEC_OUTPUT_FILE_APPEND
;
1204 eo
= exec_output_from_string(rvalue
);
1206 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse output specifier, ignoring: %s", rvalue
);
1212 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
1213 "Standard output type %s is obsolete, automatically updating to %s. Please update your unit file, and consider removing the setting altogether.",
1214 rvalue
, exec_output_to_string(eo
));
1216 if (streq(lvalue
, "StandardOutput")) {
1217 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1218 free_and_replace(c
->stdio_fdname
[STDOUT_FILENO
], resolved
);
1220 free_and_replace(c
->stdio_file
[STDOUT_FILENO
], resolved
);
1225 assert(streq(lvalue
, "StandardError"));
1227 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1228 free_and_replace(c
->stdio_fdname
[STDERR_FILENO
], resolved
);
1230 free_and_replace(c
->stdio_file
[STDERR_FILENO
], resolved
);
1238 int config_parse_exec_io_class(const char *unit
,
1239 const char *filename
,
1241 const char *section
,
1242 unsigned section_line
,
1249 ExecContext
*c
= data
;
1257 if (isempty(rvalue
)) {
1258 c
->ioprio_set
= false;
1259 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE
, 0);
1263 x
= ioprio_class_from_string(rvalue
);
1265 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse IO scheduling class, ignoring: %s", rvalue
);
1269 c
->ioprio
= IOPRIO_PRIO_VALUE(x
, IOPRIO_PRIO_DATA(c
->ioprio
));
1270 c
->ioprio_set
= true;
1275 int config_parse_exec_io_priority(const char *unit
,
1276 const char *filename
,
1278 const char *section
,
1279 unsigned section_line
,
1286 ExecContext
*c
= data
;
1294 if (isempty(rvalue
)) {
1295 c
->ioprio_set
= false;
1296 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE
, 0);
1300 r
= ioprio_parse_priority(rvalue
, &i
);
1302 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse IO priority, ignoring: %s", rvalue
);
1306 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_PRIO_CLASS(c
->ioprio
), i
);
1307 c
->ioprio_set
= true;
1312 int config_parse_exec_cpu_sched_policy(const char *unit
,
1313 const char *filename
,
1315 const char *section
,
1316 unsigned section_line
,
1323 ExecContext
*c
= data
;
1331 if (isempty(rvalue
)) {
1332 c
->cpu_sched_set
= false;
1333 c
->cpu_sched_policy
= SCHED_OTHER
;
1334 c
->cpu_sched_priority
= 0;
1338 x
= sched_policy_from_string(rvalue
);
1340 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse CPU scheduling policy, ignoring: %s", rvalue
);
1344 c
->cpu_sched_policy
= x
;
1345 /* Moving to or from real-time policy? We need to adjust the priority */
1346 c
->cpu_sched_priority
= CLAMP(c
->cpu_sched_priority
, sched_get_priority_min(x
), sched_get_priority_max(x
));
1347 c
->cpu_sched_set
= true;
1352 int config_parse_numa_mask(const char *unit
,
1353 const char *filename
,
1355 const char *section
,
1356 unsigned section_line
,
1363 NUMAPolicy
*p
= data
;
1370 r
= parse_cpu_set_extend(rvalue
, &p
->nodes
, true, unit
, filename
, line
, lvalue
);
1372 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse NUMA node mask, ignoring: %s", rvalue
);
1379 int config_parse_exec_cpu_sched_prio(const char *unit
,
1380 const char *filename
,
1382 const char *section
,
1383 unsigned section_line
,
1390 ExecContext
*c
= data
;
1398 r
= safe_atoi(rvalue
, &i
);
1400 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse CPU scheduling priority, ignoring: %s", rvalue
);
1404 /* On Linux RR/FIFO range from 1 to 99 and OTHER/BATCH may only be 0 */
1405 min
= sched_get_priority_min(c
->cpu_sched_policy
);
1406 max
= sched_get_priority_max(c
->cpu_sched_policy
);
1408 if (i
< min
|| i
> max
) {
1409 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "CPU scheduling priority is out of range, ignoring: %s", rvalue
);
1413 c
->cpu_sched_priority
= i
;
1414 c
->cpu_sched_set
= true;
1419 int config_parse_root_image_options(
1421 const char *filename
,
1423 const char *section
,
1424 unsigned section_line
,
1431 _cleanup_(mount_options_free_allp
) MountOptions
*options
= NULL
;
1432 ExecContext
*c
= data
;
1433 const Unit
*u
= userdata
;
1434 const char *p
= rvalue
;
1442 if (isempty(rvalue
)) {
1443 c
->root_image_options
= mount_options_free_all(c
->root_image_options
);
1448 _cleanup_free_
char *mount_options_resolved
= NULL
, *first
= NULL
, *tuple
= NULL
;
1449 const char *mount_options
= NULL
, *second
= NULL
;
1450 MountOptions
*o
= NULL
;
1451 unsigned int partition_number
= 0;
1453 r
= extract_first_word(&p
, &tuple
, WHITESPACE
, EXTRACT_UNQUOTE
);
1459 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s: %s", lvalue
, rvalue
);
1464 r
= extract_first_word(&second
, &first
, ":", EXTRACT_UNQUOTE
|EXTRACT_DONT_COALESCE_SEPARATORS
);
1470 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s: %s", lvalue
, rvalue
);
1474 /* Format is either '0:foo' or 'foo' (0 is implied) */
1475 if (!isempty(second
) && second
[-1] == ':') {
1476 mount_options
= second
;
1477 r
= safe_atou(first
, &partition_number
);
1479 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse partition number from \"%s\", ignoring: %m", first
);
1483 mount_options
= first
;
1485 r
= unit_full_printf(u
, mount_options
, &mount_options_resolved
);
1487 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", mount_options
);
1491 o
= new(MountOptions
, 1);
1494 *o
= (MountOptions
) {
1495 .partition_number
= partition_number
,
1496 .options
= TAKE_PTR(mount_options_resolved
),
1498 LIST_APPEND(mount_options
, options
, o
);
1501 /* empty spaces/separators only */
1502 if (LIST_IS_EMPTY(options
))
1503 c
->root_image_options
= mount_options_free_all(c
->root_image_options
);
1505 LIST_JOIN(mount_options
, c
->root_image_options
, options
);
1510 int config_parse_exec_root_hash(
1512 const char *filename
,
1514 const char *section
,
1515 unsigned section_line
,
1522 _cleanup_free_
void *roothash_decoded
= NULL
;
1523 ExecContext
*c
= data
;
1524 size_t roothash_decoded_size
= 0;
1532 if (isempty(rvalue
)) {
1533 /* Reset if the empty string is assigned */
1534 c
->root_hash_path
= mfree(c
->root_hash_path
);
1535 c
->root_hash
= mfree(c
->root_hash
);
1536 c
->root_hash_size
= 0;
1540 if (path_is_absolute(rvalue
)) {
1541 /* We have the path to a roothash to load and decode, eg: RootHash=/foo/bar.roothash */
1542 _cleanup_free_
char *p
= NULL
;
1548 free_and_replace(c
->root_hash_path
, p
);
1549 c
->root_hash
= mfree(c
->root_hash
);
1550 c
->root_hash_size
= 0;
1554 /* We have a roothash to decode, eg: RootHash=012345789abcdef */
1555 r
= unhexmem(rvalue
, strlen(rvalue
), &roothash_decoded
, &roothash_decoded_size
);
1557 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to decode RootHash=, ignoring: %s", rvalue
);
1558 if (roothash_decoded_size
< sizeof(sd_id128_t
))
1559 return log_syntax(unit
, LOG_ERR
, filename
, line
, SYNTHETIC_ERRNO(EINVAL
), "RootHash= is too short, ignoring: %s", rvalue
);
1561 free_and_replace(c
->root_hash
, roothash_decoded
);
1562 c
->root_hash_size
= roothash_decoded_size
;
1563 c
->root_hash_path
= mfree(c
->root_hash_path
);
1568 int config_parse_exec_root_hash_sig(
1570 const char *filename
,
1572 const char *section
,
1573 unsigned section_line
,
1580 _cleanup_free_
void *roothash_sig_decoded
= NULL
;
1582 ExecContext
*c
= data
;
1583 size_t roothash_sig_decoded_size
= 0;
1591 if (isempty(rvalue
)) {
1592 /* Reset if the empty string is assigned */
1593 c
->root_hash_sig_path
= mfree(c
->root_hash_sig_path
);
1594 c
->root_hash_sig
= mfree(c
->root_hash_sig
);
1595 c
->root_hash_sig_size
= 0;
1599 if (path_is_absolute(rvalue
)) {
1600 /* We have the path to a roothash signature to load and decode, eg: RootHashSignature=/foo/bar.roothash.p7s */
1601 _cleanup_free_
char *p
= NULL
;
1607 free_and_replace(c
->root_hash_sig_path
, p
);
1608 c
->root_hash_sig
= mfree(c
->root_hash_sig
);
1609 c
->root_hash_sig_size
= 0;
1613 if (!(value
= startswith(rvalue
, "base64:")))
1614 return log_syntax(unit
, LOG_ERR
, filename
, line
, SYNTHETIC_ERRNO(EINVAL
), "Failed to decode RootHashSignature=, not a path but doesn't start with 'base64:', ignoring: %s", rvalue
);
1616 /* We have a roothash signature to decode, eg: RootHashSignature=base64:012345789abcdef */
1617 r
= unbase64mem(value
, strlen(value
), &roothash_sig_decoded
, &roothash_sig_decoded_size
);
1619 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to decode RootHashSignature=, ignoring: %s", rvalue
);
1621 free_and_replace(c
->root_hash_sig
, roothash_sig_decoded
);
1622 c
->root_hash_sig_size
= roothash_sig_decoded_size
;
1623 c
->root_hash_sig_path
= mfree(c
->root_hash_sig_path
);
1628 int config_parse_exec_cpu_affinity(const char *unit
,
1629 const char *filename
,
1631 const char *section
,
1632 unsigned section_line
,
1639 ExecContext
*c
= data
;
1647 if (streq(rvalue
, "numa")) {
1648 c
->cpu_affinity_from_numa
= true;
1649 cpu_set_reset(&c
->cpu_set
);
1654 r
= parse_cpu_set_extend(rvalue
, &c
->cpu_set
, true, unit
, filename
, line
, lvalue
);
1656 c
->cpu_affinity_from_numa
= false;
1661 int config_parse_capability_set(
1663 const char *filename
,
1665 const char *section
,
1666 unsigned section_line
,
1673 uint64_t *capability_set
= data
;
1674 uint64_t sum
= 0, initial
= 0;
1675 bool invert
= false;
1683 if (rvalue
[0] == '~') {
1688 if (streq(lvalue
, "CapabilityBoundingSet"))
1689 initial
= CAP_ALL
; /* initialized to all bits on */
1690 /* else "AmbientCapabilities" initialized to all bits off */
1692 r
= capability_set_from_string(rvalue
, &sum
);
1694 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= specifier '%s', ignoring: %m", lvalue
, rvalue
);
1698 if (sum
== 0 || *capability_set
== initial
)
1699 /* "", "~" or uninitialized data -> replace */
1700 *capability_set
= invert
? ~sum
: sum
;
1702 /* previous data -> merge */
1704 *capability_set
&= ~sum
;
1706 *capability_set
|= sum
;
1712 int config_parse_exec_selinux_context(
1714 const char *filename
,
1716 const char *section
,
1717 unsigned section_line
,
1724 ExecContext
*c
= data
;
1725 const Unit
*u
= userdata
;
1735 if (isempty(rvalue
)) {
1736 c
->selinux_context
= mfree(c
->selinux_context
);
1737 c
->selinux_context_ignore
= false;
1741 if (rvalue
[0] == '-') {
1747 r
= unit_full_printf(u
, rvalue
, &k
);
1749 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1750 "Failed to resolve unit specifiers in '%s'%s: %m",
1751 rvalue
, ignore
? ", ignoring" : "");
1752 return ignore
? 0 : -ENOEXEC
;
1755 free_and_replace(c
->selinux_context
, k
);
1756 c
->selinux_context_ignore
= ignore
;
1761 int config_parse_exec_apparmor_profile(
1763 const char *filename
,
1765 const char *section
,
1766 unsigned section_line
,
1773 ExecContext
*c
= data
;
1774 const Unit
*u
= userdata
;
1784 if (isempty(rvalue
)) {
1785 c
->apparmor_profile
= mfree(c
->apparmor_profile
);
1786 c
->apparmor_profile_ignore
= false;
1790 if (rvalue
[0] == '-') {
1796 r
= unit_full_printf(u
, rvalue
, &k
);
1798 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1799 "Failed to resolve unit specifiers in '%s'%s: %m",
1800 rvalue
, ignore
? ", ignoring" : "");
1801 return ignore
? 0 : -ENOEXEC
;
1804 free_and_replace(c
->apparmor_profile
, k
);
1805 c
->apparmor_profile_ignore
= ignore
;
1810 int config_parse_exec_smack_process_label(
1812 const char *filename
,
1814 const char *section
,
1815 unsigned section_line
,
1822 ExecContext
*c
= data
;
1823 const Unit
*u
= userdata
;
1833 if (isempty(rvalue
)) {
1834 c
->smack_process_label
= mfree(c
->smack_process_label
);
1835 c
->smack_process_label_ignore
= false;
1839 if (rvalue
[0] == '-') {
1845 r
= unit_full_printf(u
, rvalue
, &k
);
1847 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1848 "Failed to resolve unit specifiers in '%s'%s: %m",
1849 rvalue
, ignore
? ", ignoring" : "");
1850 return ignore
? 0 : -ENOEXEC
;
1853 free_and_replace(c
->smack_process_label
, k
);
1854 c
->smack_process_label_ignore
= ignore
;
1859 int config_parse_timer(
1861 const char *filename
,
1863 const char *section
,
1864 unsigned section_line
,
1871 _cleanup_(calendar_spec_freep
) CalendarSpec
*c
= NULL
;
1872 _cleanup_free_
char *k
= NULL
;
1873 const Unit
*u
= userdata
;
1884 if (isempty(rvalue
)) {
1885 /* Empty assignment resets list */
1886 timer_free_values(t
);
1890 r
= unit_full_printf(u
, rvalue
, &k
);
1892 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
1896 if (ltype
== TIMER_CALENDAR
) {
1897 r
= calendar_spec_from_string(k
, &c
);
1899 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse calendar specification, ignoring: %s", k
);
1903 r
= parse_sec(k
, &usec
);
1905 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse timer value, ignoring: %s", k
);
1910 v
= new(TimerValue
, 1);
1917 .calendar_spec
= TAKE_PTR(c
),
1920 LIST_PREPEND(value
, t
->values
, v
);
1925 int config_parse_trigger_unit(
1927 const char *filename
,
1929 const char *section
,
1930 unsigned section_line
,
1937 _cleanup_free_
char *p
= NULL
;
1947 if (!hashmap_isempty(u
->dependencies
[UNIT_TRIGGERS
])) {
1948 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Multiple units to trigger specified, ignoring: %s", rvalue
);
1952 r
= unit_name_printf(u
, rvalue
, &p
);
1954 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
1958 type
= unit_name_to_type(p
);
1960 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit type not valid, ignoring: %s", rvalue
);
1963 if (unit_has_name(u
, p
)) {
1964 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Units cannot trigger themselves, ignoring: %s", rvalue
);
1968 r
= unit_add_two_dependencies_by_name(u
, UNIT_BEFORE
, UNIT_TRIGGERS
, p
, true, UNIT_DEPENDENCY_FILE
);
1970 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add trigger on %s, ignoring: %m", p
);
1977 int config_parse_path_spec(const char *unit
,
1978 const char *filename
,
1980 const char *section
,
1981 unsigned section_line
,
1991 _cleanup_free_
char *k
= NULL
;
1999 if (isempty(rvalue
)) {
2000 /* Empty assignment clears list */
2005 b
= path_type_from_string(lvalue
);
2007 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse path type, ignoring: %s", lvalue
);
2011 r
= unit_full_printf(UNIT(p
), rvalue
, &k
);
2013 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2017 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2021 s
= new0(PathSpec
, 1);
2026 s
->path
= TAKE_PTR(k
);
2030 LIST_PREPEND(spec
, p
->specs
, s
);
2035 int config_parse_socket_service(
2037 const char *filename
,
2039 const char *section
,
2040 unsigned section_line
,
2047 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
2048 _cleanup_free_
char *p
= NULL
;
2058 r
= unit_name_printf(UNIT(s
), rvalue
, &p
);
2060 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", rvalue
);
2064 if (!endswith(p
, ".service")) {
2065 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit must be of type service: %s", rvalue
);
2069 r
= manager_load_unit(UNIT(s
)->manager
, p
, NULL
, &error
, &x
);
2071 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to load unit %s: %s", rvalue
, bus_error_message(&error
, r
));
2075 unit_ref_set(&s
->service
, UNIT(s
), x
);
2080 int config_parse_fdname(
2082 const char *filename
,
2084 const char *section
,
2085 unsigned section_line
,
2092 _cleanup_free_
char *p
= NULL
;
2101 if (isempty(rvalue
)) {
2102 s
->fdname
= mfree(s
->fdname
);
2106 r
= unit_full_printf(UNIT(s
), rvalue
, &p
);
2108 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2112 if (!fdname_is_valid(p
)) {
2113 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", p
);
2117 return free_and_replace(s
->fdname
, p
);
2120 int config_parse_service_sockets(
2122 const char *filename
,
2124 const char *section
,
2125 unsigned section_line
,
2143 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2145 r
= extract_first_word(&p
, &word
, NULL
, 0);
2151 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Trailing garbage in sockets, ignoring: %s", rvalue
);
2155 r
= unit_name_printf(UNIT(s
), word
, &k
);
2157 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
2161 if (!endswith(k
, ".socket")) {
2162 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit must be of type socket, ignoring: %s", k
);
2166 r
= unit_add_two_dependencies_by_name(UNIT(s
), UNIT_WANTS
, UNIT_AFTER
, k
, true, UNIT_DEPENDENCY_FILE
);
2168 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
2170 r
= unit_add_dependency_by_name(UNIT(s
), UNIT_TRIGGERED_BY
, k
, true, UNIT_DEPENDENCY_FILE
);
2172 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
2178 int config_parse_bus_name(
2180 const char *filename
,
2182 const char *section
,
2183 unsigned section_line
,
2190 _cleanup_free_
char *k
= NULL
;
2191 const Unit
*u
= userdata
;
2199 r
= unit_full_printf(u
, rvalue
, &k
);
2201 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2205 if (!sd_bus_service_name_is_valid(k
)) {
2206 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid bus name, ignoring: %s", k
);
2210 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
2213 int config_parse_service_timeout(
2215 const char *filename
,
2217 const char *section
,
2218 unsigned section_line
,
2225 Service
*s
= userdata
;
2234 /* This is called for two cases: TimeoutSec= and TimeoutStartSec=. */
2236 /* Traditionally, these options accepted 0 to disable the timeouts. However, a timeout of 0 suggests it happens
2237 * immediately, hence fix this to become USEC_INFINITY instead. This is in-line with how we internally handle
2238 * all other timeouts. */
2239 r
= parse_sec_fix_0(rvalue
, &usec
);
2241 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
2245 s
->start_timeout_defined
= true;
2246 s
->timeout_start_usec
= usec
;
2248 if (streq(lvalue
, "TimeoutSec"))
2249 s
->timeout_stop_usec
= usec
;
2254 int config_parse_timeout_abort(
2256 const char *filename
,
2258 const char *section
,
2259 unsigned section_line
,
2274 /* Note: apart from setting the arg, this returns an extra bit of information in the return value. */
2276 if (isempty(rvalue
)) {
2278 return 0; /* "not set" */
2281 r
= parse_sec(rvalue
, ret
);
2283 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= setting, ignoring: %s", lvalue
, rvalue
);
2285 return 1; /* "set" */
2288 int config_parse_service_timeout_abort(
2290 const char *filename
,
2292 const char *section
,
2293 unsigned section_line
,
2300 Service
*s
= userdata
;
2305 r
= config_parse_timeout_abort(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
,
2306 &s
->timeout_abort_usec
, s
);
2308 s
->timeout_abort_set
= r
;
2312 int config_parse_sec_fix_0(
2314 const char *filename
,
2316 const char *section
,
2317 unsigned section_line
,
2324 usec_t
*usec
= data
;
2332 /* This is pretty much like config_parse_sec(), except that this treats a time of 0 as infinity, for
2333 * compatibility with older versions of systemd where 0 instead of infinity was used as indicator to turn off a
2336 r
= parse_sec_fix_0(rvalue
, usec
);
2338 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
2345 int config_parse_user_group_compat(
2347 const char *filename
,
2349 const char *section
,
2350 unsigned section_line
,
2357 _cleanup_free_
char *k
= NULL
;
2359 const Unit
*u
= userdata
;
2367 if (isempty(rvalue
)) {
2368 *user
= mfree(*user
);
2372 r
= unit_full_printf(u
, rvalue
, &k
);
2374 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", rvalue
);
2378 if (!valid_user_group_name(k
, VALID_USER_ALLOW_NUMERIC
|VALID_USER_RELAX
|VALID_USER_WARN
)) {
2379 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2383 if (strstr(lvalue
, "User") && streq(k
, NOBODY_USER_NAME
))
2384 log_struct(LOG_NOTICE
,
2385 "MESSAGE=%s:%u: Special user %s configured, this is not safe!", filename
, line
, k
,
2387 "MESSAGE_ID=" SD_MESSAGE_NOBODY_USER_UNSUITABLE_STR
,
2388 "OFFENDING_USER=%s", k
,
2389 "CONFIG_FILE=%s", filename
,
2390 "CONFIG_LINE=%u", line
);
2392 return free_and_replace(*user
, k
);
2395 int config_parse_user_group_strv_compat(
2397 const char *filename
,
2399 const char *section
,
2400 unsigned section_line
,
2407 char ***users
= data
;
2408 const Unit
*u
= userdata
;
2409 const char *p
= rvalue
;
2417 if (isempty(rvalue
)) {
2418 *users
= strv_free(*users
);
2423 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2425 r
= extract_first_word(&p
, &word
, NULL
, 0);
2431 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax: %s", rvalue
);
2435 r
= unit_full_printf(u
, word
, &k
);
2437 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", word
);
2441 if (!valid_user_group_name(k
, VALID_USER_ALLOW_NUMERIC
|VALID_USER_RELAX
|VALID_USER_WARN
)) {
2442 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2446 r
= strv_push(users
, k
);
2456 int config_parse_working_directory(
2458 const char *filename
,
2460 const char *section
,
2461 unsigned section_line
,
2468 ExecContext
*c
= data
;
2469 const Unit
*u
= userdata
;
2479 if (isempty(rvalue
)) {
2480 c
->working_directory_home
= false;
2481 c
->working_directory
= mfree(c
->working_directory
);
2485 if (rvalue
[0] == '-') {
2491 if (streq(rvalue
, "~")) {
2492 c
->working_directory_home
= true;
2493 c
->working_directory
= mfree(c
->working_directory
);
2495 _cleanup_free_
char *k
= NULL
;
2497 r
= unit_full_printf(u
, rvalue
, &k
);
2499 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2500 "Failed to resolve unit specifiers in working directory path '%s'%s: %m",
2501 rvalue
, missing_ok
? ", ignoring" : "");
2502 return missing_ok
? 0 : -ENOEXEC
;
2505 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
| (missing_ok
? 0 : PATH_CHECK_FATAL
), unit
, filename
, line
, lvalue
);
2507 return missing_ok
? 0 : -ENOEXEC
;
2509 c
->working_directory_home
= false;
2510 free_and_replace(c
->working_directory
, k
);
2513 c
->working_directory_missing_ok
= missing_ok
;
2517 int config_parse_unit_env_file(const char *unit
,
2518 const char *filename
,
2520 const char *section
,
2521 unsigned section_line
,
2529 const Unit
*u
= userdata
;
2530 _cleanup_free_
char *n
= NULL
;
2538 if (isempty(rvalue
)) {
2539 /* Empty assignment frees the list */
2540 *env
= strv_free(*env
);
2544 r
= unit_full_printf(u
, rvalue
, &n
);
2546 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2550 r
= path_simplify_and_warn(n
[0] == '-' ? n
+ 1 : n
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2554 r
= strv_push(env
, n
);
2563 int config_parse_environ(
2565 const char *filename
,
2567 const char *section
,
2568 unsigned section_line
,
2575 const Unit
*u
= userdata
;
2585 if (isempty(rvalue
)) {
2586 /* Empty assignment resets the list */
2587 *env
= strv_free(*env
);
2591 for (p
= rvalue
;; ) {
2592 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2594 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2600 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2601 "Invalid syntax, ignoring: %s", rvalue
);
2606 r
= unit_full_printf(u
, word
, &k
);
2608 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2609 "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2615 if (!env_assignment_is_valid(k
)) {
2616 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2617 "Invalid environment assignment, ignoring: %s", k
);
2621 r
= strv_env_replace(env
, k
);
2629 int config_parse_pass_environ(
2631 const char *filename
,
2633 const char *section
,
2634 unsigned section_line
,
2641 _cleanup_strv_free_
char **n
= NULL
;
2642 size_t nlen
= 0, nbufsize
= 0;
2643 char*** passenv
= data
;
2644 const char *p
= rvalue
;
2645 const Unit
*u
= userdata
;
2653 if (isempty(rvalue
)) {
2654 /* Empty assignment resets the list */
2655 *passenv
= strv_free(*passenv
);
2660 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2662 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
2668 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2669 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2674 r
= unit_full_printf(u
, word
, &k
);
2676 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2677 "Failed to resolve specifiers in %s, ignoring: %m", word
);
2683 if (!env_name_is_valid(k
)) {
2684 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2685 "Invalid environment name for %s, ignoring: %s", lvalue
, k
);
2689 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
2692 n
[nlen
++] = TAKE_PTR(k
);
2697 r
= strv_extend_strv(passenv
, n
, true);
2705 int config_parse_unset_environ(
2707 const char *filename
,
2709 const char *section
,
2710 unsigned section_line
,
2717 _cleanup_strv_free_
char **n
= NULL
;
2718 size_t nlen
= 0, nbufsize
= 0;
2719 char*** unsetenv
= data
;
2720 const char *p
= rvalue
;
2721 const Unit
*u
= userdata
;
2729 if (isempty(rvalue
)) {
2730 /* Empty assignment resets the list */
2731 *unsetenv
= strv_free(*unsetenv
);
2736 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2738 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2744 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2745 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2750 r
= unit_full_printf(u
, word
, &k
);
2752 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2753 "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2759 if (!env_assignment_is_valid(k
) && !env_name_is_valid(k
)) {
2760 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2761 "Invalid environment name or assignment %s, ignoring: %s", lvalue
, k
);
2765 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
2768 n
[nlen
++] = TAKE_PTR(k
);
2773 r
= strv_extend_strv(unsetenv
, n
, true);
2781 int config_parse_log_extra_fields(
2783 const char *filename
,
2785 const char *section
,
2786 unsigned section_line
,
2793 ExecContext
*c
= data
;
2794 const Unit
*u
= userdata
;
2795 const char *p
= rvalue
;
2803 if (isempty(rvalue
)) {
2804 exec_context_free_log_extra_fields(c
);
2809 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2813 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2819 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
2823 r
= unit_full_printf(u
, word
, &k
);
2825 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2829 eq
= strchr(k
, '=');
2831 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Log field lacks '=' character, ignoring: %s", k
);
2835 if (!journal_field_valid(k
, eq
-k
, false)) {
2836 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Log field name is invalid, ignoring: %s", k
);
2840 t
= reallocarray(c
->log_extra_fields
, c
->n_log_extra_fields
+1, sizeof(struct iovec
));
2844 c
->log_extra_fields
= t
;
2845 c
->log_extra_fields
[c
->n_log_extra_fields
++] = IOVEC_MAKE_STRING(k
);
2851 int config_parse_log_namespace(
2853 const char *filename
,
2855 const char *section
,
2856 unsigned section_line
,
2863 _cleanup_free_
char *k
= NULL
;
2864 ExecContext
*c
= data
;
2865 const Unit
*u
= userdata
;
2873 if (isempty(rvalue
)) {
2874 c
->log_namespace
= mfree(c
->log_namespace
);
2878 r
= unit_full_printf(u
, rvalue
, &k
);
2880 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2884 if (!log_namespace_name_valid(k
)) {
2885 log_syntax(unit
, LOG_ERR
, filename
, line
, SYNTHETIC_ERRNO(EINVAL
), "Specified log namespace name is not valid: %s", k
);
2889 free_and_replace(c
->log_namespace
, k
);
2893 int config_parse_unit_condition_path(
2895 const char *filename
,
2897 const char *section
,
2898 unsigned section_line
,
2905 _cleanup_free_
char *p
= NULL
;
2906 Condition
**list
= data
, *c
;
2907 ConditionType t
= ltype
;
2908 bool trigger
, negate
;
2909 const Unit
*u
= userdata
;
2917 if (isempty(rvalue
)) {
2918 /* Empty assignment resets the list */
2919 *list
= condition_free_list(*list
);
2923 trigger
= rvalue
[0] == '|';
2927 negate
= rvalue
[0] == '!';
2931 r
= unit_full_printf(u
, rvalue
, &p
);
2933 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2937 r
= path_simplify_and_warn(p
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2941 c
= condition_new(t
, p
, trigger
, negate
);
2945 LIST_PREPEND(conditions
, *list
, c
);
2949 int config_parse_unit_condition_string(
2951 const char *filename
,
2953 const char *section
,
2954 unsigned section_line
,
2961 _cleanup_free_
char *s
= NULL
;
2962 Condition
**list
= data
, *c
;
2963 ConditionType t
= ltype
;
2964 bool trigger
, negate
;
2965 const Unit
*u
= userdata
;
2973 if (isempty(rvalue
)) {
2974 /* Empty assignment resets the list */
2975 *list
= condition_free_list(*list
);
2979 trigger
= *rvalue
== '|';
2981 rvalue
+= 1 + strspn(rvalue
+ 1, WHITESPACE
);
2983 negate
= *rvalue
== '!';
2985 rvalue
+= 1 + strspn(rvalue
+ 1, WHITESPACE
);
2987 r
= unit_full_printf(u
, rvalue
, &s
);
2989 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2990 "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2994 c
= condition_new(t
, s
, trigger
, negate
);
2998 LIST_PREPEND(conditions
, *list
, c
);
3002 int config_parse_unit_condition_null(
3004 const char *filename
,
3006 const char *section
,
3007 unsigned section_line
,
3014 Condition
**list
= data
, *c
;
3015 bool trigger
, negate
;
3023 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "%s= is deprecated, please do not use.", lvalue
);
3025 if (isempty(rvalue
)) {
3026 /* Empty assignment resets the list */
3027 *list
= condition_free_list(*list
);
3031 trigger
= rvalue
[0] == '|';
3035 negate
= rvalue
[0] == '!';
3039 b
= parse_boolean(rvalue
);
3041 log_syntax(unit
, LOG_ERR
, filename
, line
, b
, "Failed to parse boolean value in condition, ignoring: %s", rvalue
);
3048 c
= condition_new(CONDITION_NULL
, NULL
, trigger
, negate
);
3052 LIST_PREPEND(conditions
, *list
, c
);
3056 int config_parse_unit_requires_mounts_for(
3058 const char *filename
,
3060 const char *section
,
3061 unsigned section_line
,
3068 const char *p
= rvalue
;
3078 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
3080 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3086 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3087 "Invalid syntax, ignoring: %s", rvalue
);
3091 r
= unit_full_printf(u
, word
, &resolved
);
3093 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
3097 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
3101 r
= unit_require_mounts_for(u
, resolved
, UNIT_DEPENDENCY_FILE
);
3103 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add required mount '%s', ignoring: %m", resolved
);
3109 int config_parse_documentation(const char *unit
,
3110 const char *filename
,
3112 const char *section
,
3113 unsigned section_line
,
3129 if (isempty(rvalue
)) {
3130 /* Empty assignment resets the list */
3131 u
->documentation
= strv_free(u
->documentation
);
3135 r
= config_parse_unit_strv_printf(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
,
3136 rvalue
, data
, userdata
);
3140 for (a
= b
= u
->documentation
; a
&& *a
; a
++) {
3142 if (documentation_url_is_valid(*a
))
3145 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid URL, ignoring: %s", *a
);
3156 int config_parse_syscall_filter(
3158 const char *filename
,
3160 const char *section
,
3161 unsigned section_line
,
3168 ExecContext
*c
= data
;
3169 _unused_
const Unit
*u
= userdata
;
3170 bool invert
= false;
3179 if (isempty(rvalue
)) {
3180 /* Empty assignment resets the list */
3181 c
->syscall_filter
= hashmap_free(c
->syscall_filter
);
3182 c
->syscall_allow_list
= false;
3186 if (rvalue
[0] == '~') {
3191 if (!c
->syscall_filter
) {
3192 c
->syscall_filter
= hashmap_new(NULL
);
3193 if (!c
->syscall_filter
)
3197 /* Allow everything but the ones listed */
3198 c
->syscall_allow_list
= false;
3200 /* Allow nothing but the ones listed */
3201 c
->syscall_allow_list
= true;
3203 /* Accept default syscalls if we are on a allow_list */
3204 r
= seccomp_parse_syscall_filter(
3205 "@default", -1, c
->syscall_filter
,
3206 SECCOMP_PARSE_PERMISSIVE
|SECCOMP_PARSE_ALLOW_LIST
,
3216 _cleanup_free_
char *word
= NULL
, *name
= NULL
;
3219 r
= extract_first_word(&p
, &word
, NULL
, 0);
3225 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3229 r
= parse_syscall_and_errno(word
, &name
, &num
);
3231 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse syscall:errno, ignoring: %s", word
);
3235 r
= seccomp_parse_syscall_filter(
3236 name
, num
, c
->syscall_filter
,
3237 SECCOMP_PARSE_LOG
|SECCOMP_PARSE_PERMISSIVE
|
3238 (invert
? SECCOMP_PARSE_INVERT
: 0)|
3239 (c
->syscall_allow_list
? SECCOMP_PARSE_ALLOW_LIST
: 0),
3240 unit
, filename
, line
);
3246 int config_parse_syscall_archs(
3248 const char *filename
,
3250 const char *section
,
3251 unsigned section_line
,
3258 const char *p
= rvalue
;
3262 if (isempty(rvalue
)) {
3263 *archs
= set_free(*archs
);
3268 _cleanup_free_
char *word
= NULL
;
3271 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3277 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3278 "Invalid syntax, ignoring: %s", rvalue
);
3282 r
= seccomp_arch_from_string(word
, &a
);
3284 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
3285 "Failed to parse system call architecture \"%s\", ignoring: %m", word
);
3289 r
= set_ensure_put(archs
, NULL
, UINT32_TO_PTR(a
+ 1));
3295 int config_parse_syscall_errno(
3297 const char *filename
,
3299 const char *section
,
3300 unsigned section_line
,
3307 ExecContext
*c
= data
;
3314 if (isempty(rvalue
)) {
3315 /* Empty assignment resets to KILL */
3316 c
->syscall_errno
= 0;
3320 e
= parse_errno(rvalue
);
3322 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse error number, ignoring: %s", rvalue
);
3326 c
->syscall_errno
= e
;
3330 int config_parse_address_families(
3332 const char *filename
,
3334 const char *section
,
3335 unsigned section_line
,
3342 ExecContext
*c
= data
;
3343 bool invert
= false;
3351 if (isempty(rvalue
)) {
3352 /* Empty assignment resets the list */
3353 c
->address_families
= set_free(c
->address_families
);
3354 c
->address_families_allow_list
= false;
3358 if (rvalue
[0] == '~') {
3363 if (!c
->address_families
) {
3364 c
->address_families
= set_new(NULL
);
3365 if (!c
->address_families
)
3368 c
->address_families_allow_list
= !invert
;
3371 for (p
= rvalue
;;) {
3372 _cleanup_free_
char *word
= NULL
;
3375 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3381 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3382 "Invalid syntax, ignoring: %s", rvalue
);
3386 af
= af_from_name(word
);
3388 log_syntax(unit
, LOG_ERR
, filename
, line
, af
,
3389 "Failed to parse address family, ignoring: %s", word
);
3393 /* If we previously wanted to forbid an address family and now
3394 * we want to allow it, then just remove it from the list.
3396 if (!invert
== c
->address_families_allow_list
) {
3397 r
= set_put(c
->address_families
, INT_TO_PTR(af
));
3401 set_remove(c
->address_families
, INT_TO_PTR(af
));
3405 int config_parse_restrict_namespaces(
3407 const char *filename
,
3409 const char *section
,
3410 unsigned section_line
,
3417 ExecContext
*c
= data
;
3418 unsigned long flags
;
3419 bool invert
= false;
3422 if (isempty(rvalue
)) {
3423 /* Reset to the default. */
3424 c
->restrict_namespaces
= NAMESPACE_FLAGS_INITIAL
;
3428 /* Boolean parameter ignores the previous settings */
3429 r
= parse_boolean(rvalue
);
3431 c
->restrict_namespaces
= 0;
3433 } else if (r
== 0) {
3434 c
->restrict_namespaces
= NAMESPACE_FLAGS_ALL
;
3438 if (rvalue
[0] == '~') {
3443 /* Not a boolean argument, in this case it's a list of namespace types. */
3444 r
= namespace_flags_from_string(rvalue
, &flags
);
3446 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse namespace type string, ignoring: %s", rvalue
);
3450 if (c
->restrict_namespaces
== NAMESPACE_FLAGS_INITIAL
)
3451 /* Initial assignment. Just set the value. */
3452 c
->restrict_namespaces
= invert
? (~flags
) & NAMESPACE_FLAGS_ALL
: flags
;
3454 /* Merge the value with the previous one. */
3455 SET_FLAG(c
->restrict_namespaces
, flags
, !invert
);
3461 int config_parse_unit_slice(
3463 const char *filename
,
3465 const char *section
,
3466 unsigned section_line
,
3473 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
3474 _cleanup_free_
char *k
= NULL
;
3475 Unit
*u
= userdata
, *slice
;
3483 r
= unit_name_printf(u
, rvalue
, &k
);
3485 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
3489 r
= manager_load_unit(u
->manager
, k
, NULL
, &error
, &slice
);
3491 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to load slice unit %s, ignoring: %s", k
, bus_error_message(&error
, r
));
3495 r
= unit_set_slice(u
, slice
);
3497 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to assign slice %s to unit %s, ignoring: %m", slice
->id
, u
->id
);
3504 int config_parse_cpu_quota(
3506 const char *filename
,
3508 const char *section
,
3509 unsigned section_line
,
3516 CGroupContext
*c
= data
;
3523 if (isempty(rvalue
)) {
3524 c
->cpu_quota_per_sec_usec
= USEC_INFINITY
;
3528 r
= parse_permille_unbounded(rvalue
);
3530 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid CPU quota '%s', ignoring.", rvalue
);
3534 c
->cpu_quota_per_sec_usec
= ((usec_t
) r
* USEC_PER_SEC
) / 1000U;
3538 int config_parse_allowed_cpus(
3540 const char *filename
,
3542 const char *section
,
3543 unsigned section_line
,
3550 CGroupContext
*c
= data
;
3552 (void) parse_cpu_set_extend(rvalue
, &c
->cpuset_cpus
, true, unit
, filename
, line
, lvalue
);
3557 int config_parse_allowed_mems(
3559 const char *filename
,
3561 const char *section
,
3562 unsigned section_line
,
3569 CGroupContext
*c
= data
;
3571 (void) parse_cpu_set_extend(rvalue
, &c
->cpuset_mems
, true, unit
, filename
, line
, lvalue
);
3576 int config_parse_memory_limit(
3578 const char *filename
,
3580 const char *section
,
3581 unsigned section_line
,
3588 CGroupContext
*c
= data
;
3589 uint64_t bytes
= CGROUP_LIMIT_MAX
;
3592 if (isempty(rvalue
) && STR_IN_SET(lvalue
, "DefaultMemoryLow",
3596 bytes
= CGROUP_LIMIT_MIN
;
3597 else if (!isempty(rvalue
) && !streq(rvalue
, "infinity")) {
3599 r
= parse_permille(rvalue
);
3601 r
= parse_size(rvalue
, 1024, &bytes
);
3603 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid memory limit '%s', ignoring: %m", rvalue
);
3607 bytes
= physical_memory_scale(r
, 1000U);
3609 if (bytes
>= UINT64_MAX
||
3610 (bytes
<= 0 && !STR_IN_SET(lvalue
, "MemorySwapMax", "MemoryLow", "MemoryMin", "DefaultMemoryLow", "DefaultMemoryMin"))) {
3611 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Memory limit '%s' out of range, ignoring.", rvalue
);
3616 if (streq(lvalue
, "DefaultMemoryLow")) {
3617 c
->default_memory_low
= bytes
;
3618 c
->default_memory_low_set
= true;
3619 } else if (streq(lvalue
, "DefaultMemoryMin")) {
3620 c
->default_memory_min
= bytes
;
3621 c
->default_memory_min_set
= true;
3622 } else if (streq(lvalue
, "MemoryMin")) {
3623 c
->memory_min
= bytes
;
3624 c
->memory_min_set
= true;
3625 } else if (streq(lvalue
, "MemoryLow")) {
3626 c
->memory_low
= bytes
;
3627 c
->memory_low_set
= true;
3628 } else if (streq(lvalue
, "MemoryHigh"))
3629 c
->memory_high
= bytes
;
3630 else if (streq(lvalue
, "MemoryMax"))
3631 c
->memory_max
= bytes
;
3632 else if (streq(lvalue
, "MemorySwapMax"))
3633 c
->memory_swap_max
= bytes
;
3634 else if (streq(lvalue
, "MemoryLimit"))
3635 c
->memory_limit
= bytes
;
3642 int config_parse_tasks_max(
3644 const char *filename
,
3646 const char *section
,
3647 unsigned section_line
,
3654 const Unit
*u
= userdata
;
3655 TasksMax
*tasks_max
= data
;
3659 if (isempty(rvalue
)) {
3660 *tasks_max
= u
? u
->manager
->default_tasks_max
: TASKS_MAX_UNSET
;
3664 if (streq(rvalue
, "infinity")) {
3665 *tasks_max
= TASKS_MAX_UNSET
;
3669 r
= parse_permille(rvalue
);
3671 *tasks_max
= (TasksMax
) { r
, 1000U }; /* r‰ */
3673 r
= safe_atou64(rvalue
, &v
);
3675 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid maximum tasks value '%s', ignoring: %m", rvalue
);
3679 if (v
<= 0 || v
>= UINT64_MAX
) {
3680 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Maximum tasks value '%s' out of range, ignoring.", rvalue
);
3684 *tasks_max
= (TasksMax
) { v
};
3690 int config_parse_delegate(
3692 const char *filename
,
3694 const char *section
,
3695 unsigned section_line
,
3702 CGroupContext
*c
= data
;
3706 t
= unit_name_to_type(unit
);
3707 assert(t
!= _UNIT_TYPE_INVALID
);
3709 if (!unit_vtable
[t
]->can_delegate
) {
3710 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Delegate= setting not supported for this unit type, ignoring.");
3714 /* We either accept a boolean value, which may be used to turn on delegation for all controllers, or turn it
3715 * off for all. Or it takes a list of controller names, in which case we add the specified controllers to the
3716 * mask to delegate. */
3718 if (isempty(rvalue
)) {
3719 /* An empty string resets controllers and set Delegate=yes. */
3721 c
->delegate_controllers
= 0;
3725 r
= parse_boolean(rvalue
);
3727 const char *p
= rvalue
;
3728 CGroupMask mask
= 0;
3731 _cleanup_free_
char *word
= NULL
;
3732 CGroupController cc
;
3734 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3740 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3744 cc
= cgroup_controller_from_string(word
);
3746 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid controller name '%s', ignoring", word
);
3750 mask
|= CGROUP_CONTROLLER_TO_MASK(cc
);
3754 c
->delegate_controllers
|= mask
;
3758 c
->delegate_controllers
= _CGROUP_MASK_ALL
;
3760 c
->delegate
= false;
3761 c
->delegate_controllers
= 0;
3767 int config_parse_device_allow(
3769 const char *filename
,
3771 const char *section
,
3772 unsigned section_line
,
3779 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3780 CGroupContext
*c
= data
;
3781 const char *p
= rvalue
;
3784 if (isempty(rvalue
)) {
3785 while (c
->device_allow
)
3786 cgroup_context_free_device_allow(c
, c
->device_allow
);
3791 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3795 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3796 "Invalid syntax, ignoring: %s", rvalue
);
3800 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3801 "Failed to extract device path and rights from '%s', ignoring.", rvalue
);
3805 r
= unit_full_printf(userdata
, path
, &resolved
);
3807 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3808 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3812 if (!STARTSWITH_SET(resolved
, "block-", "char-")) {
3814 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3818 if (!valid_device_node_path(resolved
)) {
3819 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device node path '%s', ignoring.", resolved
);
3824 if (!isempty(p
) && !in_charset(p
, "rwm")) {
3825 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device rights '%s', ignoring.", p
);
3829 return cgroup_add_device_allow(c
, resolved
, p
);
3832 int config_parse_io_device_weight(
3834 const char *filename
,
3836 const char *section
,
3837 unsigned section_line
,
3844 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3845 CGroupIODeviceWeight
*w
;
3846 CGroupContext
*c
= data
;
3847 const char *p
= rvalue
;
3855 if (isempty(rvalue
)) {
3856 while (c
->io_device_weights
)
3857 cgroup_context_free_io_device_weight(c
, c
->io_device_weights
);
3862 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3866 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3867 "Invalid syntax, ignoring: %s", rvalue
);
3870 if (r
== 0 || isempty(p
)) {
3871 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3872 "Failed to extract device path and weight from '%s', ignoring.", rvalue
);
3876 r
= unit_full_printf(userdata
, path
, &resolved
);
3878 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3879 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3883 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3887 r
= cg_weight_parse(p
, &u
);
3889 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "IO weight '%s' invalid, ignoring: %m", p
);
3893 assert(u
!= CGROUP_WEIGHT_INVALID
);
3895 w
= new0(CGroupIODeviceWeight
, 1);
3899 w
->path
= TAKE_PTR(resolved
);
3902 LIST_PREPEND(device_weights
, c
->io_device_weights
, w
);
3906 int config_parse_io_device_latency(
3908 const char *filename
,
3910 const char *section
,
3911 unsigned section_line
,
3918 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3919 CGroupIODeviceLatency
*l
;
3920 CGroupContext
*c
= data
;
3921 const char *p
= rvalue
;
3929 if (isempty(rvalue
)) {
3930 while (c
->io_device_latencies
)
3931 cgroup_context_free_io_device_latency(c
, c
->io_device_latencies
);
3936 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3940 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3941 "Invalid syntax, ignoring: %s", rvalue
);
3944 if (r
== 0 || isempty(p
)) {
3945 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3946 "Failed to extract device path and latency from '%s', ignoring.", rvalue
);
3950 r
= unit_full_printf(userdata
, path
, &resolved
);
3952 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3953 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3957 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3961 if (parse_sec(p
, &usec
) < 0) {
3962 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse timer value, ignoring: %s", p
);
3966 l
= new0(CGroupIODeviceLatency
, 1);
3970 l
->path
= TAKE_PTR(resolved
);
3971 l
->target_usec
= usec
;
3973 LIST_PREPEND(device_latencies
, c
->io_device_latencies
, l
);
3977 int config_parse_io_limit(
3979 const char *filename
,
3981 const char *section
,
3982 unsigned section_line
,
3989 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3990 CGroupIODeviceLimit
*l
= NULL
, *t
;
3991 CGroupContext
*c
= data
;
3992 CGroupIOLimitType type
;
3993 const char *p
= rvalue
;
4001 type
= cgroup_io_limit_type_from_string(lvalue
);
4004 if (isempty(rvalue
)) {
4005 LIST_FOREACH(device_limits
, l
, c
->io_device_limits
)
4006 l
->limits
[type
] = cgroup_io_limit_defaults
[type
];
4010 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4014 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4015 "Invalid syntax, ignoring: %s", rvalue
);
4018 if (r
== 0 || isempty(p
)) {
4019 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4020 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
4024 r
= unit_full_printf(userdata
, path
, &resolved
);
4026 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4027 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4031 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4035 if (streq("infinity", p
))
4036 num
= CGROUP_LIMIT_MAX
;
4038 r
= parse_size(p
, 1000, &num
);
4039 if (r
< 0 || num
<= 0) {
4040 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid IO limit '%s', ignoring.", p
);
4045 LIST_FOREACH(device_limits
, t
, c
->io_device_limits
) {
4046 if (path_equal(resolved
, t
->path
)) {
4053 CGroupIOLimitType ttype
;
4055 l
= new0(CGroupIODeviceLimit
, 1);
4059 l
->path
= TAKE_PTR(resolved
);
4060 for (ttype
= 0; ttype
< _CGROUP_IO_LIMIT_TYPE_MAX
; ttype
++)
4061 l
->limits
[ttype
] = cgroup_io_limit_defaults
[ttype
];
4063 LIST_PREPEND(device_limits
, c
->io_device_limits
, l
);
4066 l
->limits
[type
] = num
;
4071 int config_parse_blockio_device_weight(
4073 const char *filename
,
4075 const char *section
,
4076 unsigned section_line
,
4083 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4084 CGroupBlockIODeviceWeight
*w
;
4085 CGroupContext
*c
= data
;
4086 const char *p
= rvalue
;
4094 if (isempty(rvalue
)) {
4095 while (c
->blockio_device_weights
)
4096 cgroup_context_free_blockio_device_weight(c
, c
->blockio_device_weights
);
4101 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4105 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4106 "Invalid syntax, ignoring: %s", rvalue
);
4109 if (r
== 0 || isempty(p
)) {
4110 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4111 "Failed to extract device node and weight from '%s', ignoring.", rvalue
);
4115 r
= unit_full_printf(userdata
, path
, &resolved
);
4117 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4118 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4122 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4126 r
= cg_blkio_weight_parse(p
, &u
);
4128 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid block IO weight '%s', ignoring: %m", p
);
4132 assert(u
!= CGROUP_BLKIO_WEIGHT_INVALID
);
4134 w
= new0(CGroupBlockIODeviceWeight
, 1);
4138 w
->path
= TAKE_PTR(resolved
);
4141 LIST_PREPEND(device_weights
, c
->blockio_device_weights
, w
);
4145 int config_parse_blockio_bandwidth(
4147 const char *filename
,
4149 const char *section
,
4150 unsigned section_line
,
4157 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
4158 CGroupBlockIODeviceBandwidth
*b
= NULL
, *t
;
4159 CGroupContext
*c
= data
;
4160 const char *p
= rvalue
;
4169 read
= streq("BlockIOReadBandwidth", lvalue
);
4171 if (isempty(rvalue
)) {
4172 LIST_FOREACH(device_bandwidths
, b
, c
->blockio_device_bandwidths
) {
4173 b
->rbps
= CGROUP_LIMIT_MAX
;
4174 b
->wbps
= CGROUP_LIMIT_MAX
;
4179 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
4183 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4184 "Invalid syntax, ignoring: %s", rvalue
);
4187 if (r
== 0 || isempty(p
)) {
4188 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4189 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
4193 r
= unit_full_printf(userdata
, path
, &resolved
);
4195 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4196 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
4200 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
4204 r
= parse_size(p
, 1000, &bytes
);
4205 if (r
< 0 || bytes
<= 0) {
4206 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid Block IO Bandwidth '%s', ignoring.", p
);
4210 LIST_FOREACH(device_bandwidths
, t
, c
->blockio_device_bandwidths
) {
4211 if (path_equal(resolved
, t
->path
)) {
4218 b
= new0(CGroupBlockIODeviceBandwidth
, 1);
4222 b
->path
= TAKE_PTR(resolved
);
4223 b
->rbps
= CGROUP_LIMIT_MAX
;
4224 b
->wbps
= CGROUP_LIMIT_MAX
;
4226 LIST_PREPEND(device_bandwidths
, c
->blockio_device_bandwidths
, b
);
4237 int config_parse_job_mode_isolate(
4239 const char *filename
,
4241 const char *section
,
4242 unsigned section_line
,
4256 r
= parse_boolean(rvalue
);
4258 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse boolean, ignoring: %s", rvalue
);
4262 log_notice("%s is deprecated. Please use OnFailureJobMode= instead", lvalue
);
4264 *m
= r
? JOB_ISOLATE
: JOB_REPLACE
;
4268 int config_parse_exec_directories(
4270 const char *filename
,
4272 const char *section
,
4273 unsigned section_line
,
4281 const Unit
*u
= userdata
;
4290 if (isempty(rvalue
)) {
4291 /* Empty assignment resets the list */
4292 *rt
= strv_free(*rt
);
4296 for (p
= rvalue
;;) {
4297 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
4299 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
4303 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4304 "Invalid syntax, ignoring: %s", rvalue
);
4310 r
= unit_full_printf(u
, word
, &k
);
4312 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4313 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
4317 r
= path_simplify_and_warn(k
, PATH_CHECK_RELATIVE
, unit
, filename
, line
, lvalue
);
4321 if (path_startswith(k
, "private")) {
4322 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
4323 "%s= path can't be 'private', ignoring assignment: %s", lvalue
, word
);
4327 r
= strv_push(rt
, k
);
4334 int config_parse_set_status(
4336 const char *filename
,
4338 const char *section
,
4339 unsigned section_line
,
4347 const char *word
, *state
;
4349 ExitStatusSet
*status_set
= data
;
4356 /* Empty assignment resets the list */
4357 if (isempty(rvalue
)) {
4358 exit_status_set_free(status_set
);
4362 FOREACH_WORD(word
, l
, rvalue
, state
) {
4363 _cleanup_free_
char *temp
;
4366 temp
= strndup(word
, l
);
4370 /* We need to call exit_status_from_string() first, because we want
4371 * to parse numbers as exit statuses, not signals. */
4373 r
= exit_status_from_string(temp
);
4375 assert(r
>= 0 && r
< 256);
4376 bitmap
= &status_set
->status
;
4378 r
= signal_from_string(temp
);
4381 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
4382 "Failed to parse value, ignoring: %s", word
);
4385 bitmap
= &status_set
->signal
;
4388 r
= bitmap_set(bitmap
, r
);
4390 return log_error_errno(r
, "Failed to set signal or status %s: %m", word
);
4392 if (!isempty(state
))
4393 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Trailing garbage, ignoring.");
4398 int config_parse_namespace_path_strv(
4400 const char *filename
,
4402 const char *section
,
4403 unsigned section_line
,
4410 const Unit
*u
= userdata
;
4412 const char *p
= rvalue
;
4420 if (isempty(rvalue
)) {
4421 /* Empty assignment resets the list */
4422 *sv
= strv_free(*sv
);
4427 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
, *joined
= NULL
;
4429 bool ignore_enoent
= false, shall_prefix
= false;
4431 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
4437 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
4442 if (startswith(w
, "-")) {
4443 ignore_enoent
= true;
4446 if (startswith(w
, "+")) {
4447 shall_prefix
= true;
4451 r
= unit_full_printf(u
, w
, &resolved
);
4453 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", w
);
4457 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4461 joined
= strjoin(ignore_enoent
? "-" : "",
4462 shall_prefix
? "+" : "",
4465 r
= strv_push(sv
, joined
);
4475 int config_parse_temporary_filesystems(
4477 const char *filename
,
4479 const char *section
,
4480 unsigned section_line
,
4487 const Unit
*u
= userdata
;
4488 ExecContext
*c
= data
;
4489 const char *p
= rvalue
;
4497 if (isempty(rvalue
)) {
4498 /* Empty assignment resets the list */
4499 temporary_filesystem_free_many(c
->temporary_filesystems
, c
->n_temporary_filesystems
);
4500 c
->temporary_filesystems
= NULL
;
4501 c
->n_temporary_filesystems
= 0;
4506 _cleanup_free_
char *word
= NULL
, *path
= NULL
, *resolved
= NULL
;
4509 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
4515 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
4520 r
= extract_first_word(&w
, &path
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4524 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", word
);
4528 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid syntax, ignoring: %s", word
);
4532 r
= unit_full_printf(u
, path
, &resolved
);
4534 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", path
);
4538 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4542 r
= temporary_filesystem_add(&c
->temporary_filesystems
, &c
->n_temporary_filesystems
, resolved
, w
);
4548 int config_parse_bind_paths(
4550 const char *filename
,
4552 const char *section
,
4553 unsigned section_line
,
4560 ExecContext
*c
= data
;
4561 const Unit
*u
= userdata
;
4570 if (isempty(rvalue
)) {
4571 /* Empty assignment resets the list */
4572 bind_mount_free_many(c
->bind_mounts
, c
->n_bind_mounts
);
4573 c
->bind_mounts
= NULL
;
4574 c
->n_bind_mounts
= 0;
4580 _cleanup_free_
char *source
= NULL
, *destination
= NULL
;
4581 _cleanup_free_
char *sresolved
= NULL
, *dresolved
= NULL
;
4582 char *s
= NULL
, *d
= NULL
;
4583 bool rbind
= true, ignore_enoent
= false;
4585 r
= extract_first_word(&p
, &source
, ":" WHITESPACE
, EXTRACT_UNQUOTE
|EXTRACT_DONT_COALESCE_SEPARATORS
);
4591 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
4595 r
= unit_full_printf(u
, source
, &sresolved
);
4597 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4598 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", source
);
4604 ignore_enoent
= true;
4608 r
= path_simplify_and_warn(s
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4612 /* Optionally, the destination is specified. */
4613 if (p
&& p
[-1] == ':') {
4614 r
= extract_first_word(&p
, &destination
, ":" WHITESPACE
, EXTRACT_UNQUOTE
|EXTRACT_DONT_COALESCE_SEPARATORS
);
4618 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
4622 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Missing argument after ':', ignoring: %s", s
);
4626 r
= unit_full_printf(u
, destination
, &dresolved
);
4628 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4629 "Failed to resolve specifiers in \"%s\", ignoring: %m", destination
);
4633 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4639 /* Optionally, there's also a short option string specified */
4640 if (p
&& p
[-1] == ':') {
4641 _cleanup_free_
char *options
= NULL
;
4643 r
= extract_first_word(&p
, &options
, NULL
, EXTRACT_UNQUOTE
);
4647 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s: %s", lvalue
, rvalue
);
4651 if (isempty(options
) || streq(options
, "rbind"))
4653 else if (streq(options
, "norbind"))
4656 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid option string, ignoring setting: %s", options
);
4663 r
= bind_mount_add(&c
->bind_mounts
, &c
->n_bind_mounts
,
4667 .read_only
= !!strstr(lvalue
, "ReadOnly"),
4669 .ignore_enoent
= ignore_enoent
,
4678 int config_parse_mount_images(
4680 const char *filename
,
4682 const char *section
,
4683 unsigned section_line
,
4690 _cleanup_strv_free_
char **l
= NULL
;
4691 ExecContext
*c
= data
;
4692 const Unit
*u
= userdata
;
4693 char **source
= NULL
, **destination
= NULL
;
4701 if (isempty(rvalue
)) {
4702 /* Empty assignment resets the list */
4703 c
->mount_images
= mount_image_free_many(c
->mount_images
, &c
->n_mount_images
);
4707 r
= strv_split_colon_pairs(&l
, rvalue
);
4711 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
4715 STRV_FOREACH_PAIR(source
, destination
, l
) {
4716 _cleanup_free_
char *sresolved
= NULL
, *dresolved
= NULL
;
4718 bool permissive
= false;
4720 r
= unit_full_printf(u
, *source
, &sresolved
);
4722 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4723 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", *source
);
4733 r
= path_simplify_and_warn(s
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4737 if (isempty(*destination
)) {
4738 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Missing destination in %s, ignoring: %s", lvalue
, rvalue
);
4742 r
= unit_full_printf(u
, *destination
, &dresolved
);
4744 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4745 "Failed to resolve specifiers in \"%s\", ignoring: %m", *destination
);
4749 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4753 r
= mount_image_add(&c
->mount_images
, &c
->n_mount_images
,
4756 .destination
= dresolved
,
4757 .ignore_enoent
= permissive
,
4766 int config_parse_job_timeout_sec(
4768 const char *filename
,
4770 const char *section
,
4771 unsigned section_line
,
4787 r
= parse_sec_fix_0(rvalue
, &usec
);
4789 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse JobTimeoutSec= parameter, ignoring: %s", rvalue
);
4793 /* If the user explicitly changed JobTimeoutSec= also change JobRunningTimeoutSec=, for compatibility with old
4794 * versions. If JobRunningTimeoutSec= was explicitly set, avoid this however as whatever the user picked should
4797 if (!u
->job_running_timeout_set
)
4798 u
->job_running_timeout
= usec
;
4800 u
->job_timeout
= usec
;
4805 int config_parse_job_running_timeout_sec(
4807 const char *filename
,
4809 const char *section
,
4810 unsigned section_line
,
4826 r
= parse_sec_fix_0(rvalue
, &usec
);
4828 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse JobRunningTimeoutSec= parameter, ignoring: %s", rvalue
);
4832 u
->job_running_timeout
= usec
;
4833 u
->job_running_timeout_set
= true;
4838 int config_parse_emergency_action(
4840 const char *filename
,
4842 const char *section
,
4843 unsigned section_line
,
4851 EmergencyAction
*x
= data
;
4860 m
= ((Unit
*) userdata
)->manager
;
4864 r
= parse_emergency_action(rvalue
, MANAGER_IS_SYSTEM(m
), x
);
4866 if (r
== -EOPNOTSUPP
&& MANAGER_IS_USER(m
)) {
4867 /* Compat mode: remove for systemd 241. */
4869 log_syntax(unit
, LOG_INFO
, filename
, line
, r
,
4870 "%s= in user mode specified as \"%s\", using \"exit-force\" instead.",
4872 *x
= EMERGENCY_ACTION_EXIT_FORCE
;
4876 if (r
== -EOPNOTSUPP
)
4877 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4878 "%s= specified as %s mode action, ignoring: %s",
4879 lvalue
, MANAGER_IS_SYSTEM(m
) ? "user" : "system", rvalue
);
4881 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4882 "Failed to parse %s=, ignoring: %s", lvalue
, rvalue
);
4889 int config_parse_pid_file(
4891 const char *filename
,
4893 const char *section
,
4894 unsigned section_line
,
4901 _cleanup_free_
char *k
= NULL
, *n
= NULL
;
4902 const Unit
*u
= userdata
;
4911 if (isempty(rvalue
)) {
4912 /* An empty assignment removes already set value. */
4917 r
= unit_full_printf(u
, rvalue
, &k
);
4919 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
4923 /* If this is a relative path make it absolute by prefixing the /run */
4924 n
= path_make_absolute(k
, u
->manager
->prefix
[EXEC_DIRECTORY_RUNTIME
]);
4928 /* Check that the result is a sensible path */
4929 r
= path_simplify_and_warn(n
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4933 r
= patch_var_run(unit
, filename
, line
, lvalue
, &n
);
4937 free_and_replace(*s
, n
);
4941 int config_parse_exit_status(
4943 const char *filename
,
4945 const char *section
,
4946 unsigned section_line
,
4953 int *exit_status
= data
, r
;
4959 assert(exit_status
);
4961 if (isempty(rvalue
)) {
4966 r
= safe_atou8(rvalue
, &u
);
4968 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse exit status '%s', ignoring: %m", rvalue
);
4976 int config_parse_disable_controllers(
4978 const char *filename
,
4980 const char *section
,
4981 unsigned section_line
,
4989 CGroupContext
*c
= data
;
4990 CGroupMask disabled_mask
;
4992 /* 1. If empty, make all controllers eligible for use again.
4993 * 2. If non-empty, merge all listed controllers, space separated. */
4995 if (isempty(rvalue
)) {
4996 c
->disable_controllers
= 0;
5000 r
= cg_mask_from_string(rvalue
, &disabled_mask
);
5001 if (r
< 0 || disabled_mask
<= 0) {
5002 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid cgroup string: %s, ignoring", rvalue
);
5006 c
->disable_controllers
|= disabled_mask
;
5011 int config_parse_ip_filter_bpf_progs(
5013 const char *filename
,
5015 const char *section
,
5016 unsigned section_line
,
5023 _cleanup_free_
char *resolved
= NULL
;
5024 const Unit
*u
= userdata
;
5025 char ***paths
= data
;
5033 if (isempty(rvalue
)) {
5034 *paths
= strv_free(*paths
);
5038 r
= unit_full_printf(u
, rvalue
, &resolved
);
5040 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
5044 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
5048 if (strv_contains(*paths
, resolved
))
5051 r
= strv_extend(paths
, resolved
);
5055 r
= bpf_firewall_supported();
5058 if (r
!= BPF_FIREWALL_SUPPORTED_WITH_MULTI
) {
5059 static bool warned
= false;
5061 log_full(warned
? LOG_DEBUG
: LOG_WARNING
,
5062 "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"
5063 "Starting this unit will fail! (This warning is only shown for the first loaded unit using IP firewalling.)", filename
, line
, lvalue
, rvalue
);
5071 static int merge_by_names(Unit
**u
, Set
*names
, const char *id
) {
5078 /* Let's try to add in all names that are aliases of this unit */
5079 while ((k
= set_steal_first(names
))) {
5080 _cleanup_free_ _unused_
char *free_k
= k
;
5082 /* First try to merge in the other name into our unit */
5083 r
= unit_merge_by_name(*u
, k
);
5087 /* Hmm, we couldn't merge the other unit into ours? Then let's try it the other way
5090 other
= manager_get_unit((*u
)->manager
, k
);
5092 return r
; /* return previous failure */
5094 r
= unit_merge(other
, *u
);
5099 return merge_by_names(u
, names
, NULL
);
5102 if (streq_ptr(id
, k
))
5103 unit_choose_id(*u
, id
);
5109 int unit_load_fragment(Unit
*u
) {
5110 const char *fragment
;
5111 _cleanup_set_free_free_ Set
*names
= NULL
;
5115 assert(u
->load_state
== UNIT_STUB
);
5119 u
->load_state
= UNIT_LOADED
;
5123 /* Possibly rebuild the fragment map to catch new units */
5124 r
= unit_file_build_name_map(&u
->manager
->lookup_paths
,
5125 &u
->manager
->unit_cache_mtime
,
5126 &u
->manager
->unit_id_map
,
5127 &u
->manager
->unit_name_map
,
5128 &u
->manager
->unit_path_cache
);
5130 return log_error_errno(r
, "Failed to rebuild name map: %m");
5132 r
= unit_file_find_fragment(u
->manager
->unit_id_map
,
5133 u
->manager
->unit_name_map
,
5137 if (r
< 0 && r
!= -ENOENT
)
5141 /* Open the file, check if this is a mask, otherwise read. */
5142 _cleanup_fclose_
FILE *f
= NULL
;
5145 /* Try to open the file name. A symlink is OK, for example for linked files or masks. We
5146 * expect that all symlinks within the lookup paths have been already resolved, but we don't
5147 * verify this here. */
5148 f
= fopen(fragment
, "re");
5150 return log_unit_notice_errno(u
, errno
, "Failed to open %s: %m", fragment
);
5152 if (fstat(fileno(f
), &st
) < 0)
5155 r
= free_and_strdup(&u
->fragment_path
, fragment
);
5159 if (null_or_empty(&st
)) {
5160 /* Unit file is masked */
5162 u
->load_state
= u
->perpetual
? UNIT_LOADED
: UNIT_MASKED
; /* don't allow perpetual units to ever be masked */
5163 u
->fragment_mtime
= 0;
5165 u
->load_state
= UNIT_LOADED
;
5166 u
->fragment_mtime
= timespec_load(&st
.st_mtim
);
5168 /* Now, parse the file contents */
5169 r
= config_parse(u
->id
, fragment
, f
,
5170 UNIT_VTABLE(u
)->sections
,
5171 config_item_perf_lookup
, load_fragment_gperf_lookup
,
5176 log_unit_notice_errno(u
, r
, "Unit configuration has fatal error, unit will not be started.");
5182 /* We do the merge dance here because for some unit types, the unit might have aliases which are not
5183 * declared in the file system. In particular, this is true (and frequent) for device and swap units.
5186 const char *id
= u
->id
;
5187 _cleanup_free_
char *free_id
= NULL
;
5190 id
= basename(fragment
);
5191 if (unit_name_is_valid(id
, UNIT_NAME_TEMPLATE
)) {
5192 assert(u
->instance
); /* If we're not trying to use a template for non-instanced unit,
5193 * this must be set. */
5195 r
= unit_name_replace_instance(id
, u
->instance
, &free_id
);
5197 return log_debug_errno(r
, "Failed to build id (%s + %s): %m", id
, u
->instance
);
5203 r
= merge_by_names(&merged
, names
, id
);
5208 u
->load_state
= UNIT_MERGED
;
5213 void unit_dump_config_items(FILE *f
) {
5214 static const struct {
5215 const ConfigParserCallback callback
;
5218 { config_parse_warn_compat
, "NOTSUPPORTED" },
5219 { config_parse_int
, "INTEGER" },
5220 { config_parse_unsigned
, "UNSIGNED" },
5221 { config_parse_iec_size
, "SIZE" },
5222 { config_parse_iec_uint64
, "SIZE" },
5223 { config_parse_si_uint64
, "SIZE" },
5224 { config_parse_bool
, "BOOLEAN" },
5225 { config_parse_string
, "STRING" },
5226 { config_parse_path
, "PATH" },
5227 { config_parse_unit_path_printf
, "PATH" },
5228 { config_parse_strv
, "STRING [...]" },
5229 { config_parse_exec_nice
, "NICE" },
5230 { config_parse_exec_oom_score_adjust
, "OOMSCOREADJUST" },
5231 { config_parse_exec_io_class
, "IOCLASS" },
5232 { config_parse_exec_io_priority
, "IOPRIORITY" },
5233 { config_parse_exec_cpu_sched_policy
, "CPUSCHEDPOLICY" },
5234 { config_parse_exec_cpu_sched_prio
, "CPUSCHEDPRIO" },
5235 { config_parse_exec_cpu_affinity
, "CPUAFFINITY" },
5236 { config_parse_mode
, "MODE" },
5237 { config_parse_unit_env_file
, "FILE" },
5238 { config_parse_exec_output
, "OUTPUT" },
5239 { config_parse_exec_input
, "INPUT" },
5240 { config_parse_log_facility
, "FACILITY" },
5241 { config_parse_log_level
, "LEVEL" },
5242 { config_parse_exec_secure_bits
, "SECUREBITS" },
5243 { config_parse_capability_set
, "BOUNDINGSET" },
5244 { config_parse_rlimit
, "LIMIT" },
5245 { config_parse_unit_deps
, "UNIT [...]" },
5246 { config_parse_exec
, "PATH [ARGUMENT [...]]" },
5247 { config_parse_service_type
, "SERVICETYPE" },
5248 { config_parse_service_restart
, "SERVICERESTART" },
5249 { config_parse_service_timeout_failure_mode
, "TIMEOUTMODE" },
5250 { config_parse_kill_mode
, "KILLMODE" },
5251 { config_parse_signal
, "SIGNAL" },
5252 { config_parse_socket_listen
, "SOCKET [...]" },
5253 { config_parse_socket_bind
, "SOCKETBIND" },
5254 { config_parse_socket_bindtodevice
, "NETWORKINTERFACE" },
5255 { config_parse_sec
, "SECONDS" },
5256 { config_parse_nsec
, "NANOSECONDS" },
5257 { config_parse_namespace_path_strv
, "PATH [...]" },
5258 { config_parse_bind_paths
, "PATH[:PATH[:OPTIONS]] [...]" },
5259 { config_parse_unit_requires_mounts_for
, "PATH [...]" },
5260 { config_parse_exec_mount_flags
, "MOUNTFLAG [...]" },
5261 { config_parse_unit_string_printf
, "STRING" },
5262 { config_parse_trigger_unit
, "UNIT" },
5263 { config_parse_timer
, "TIMER" },
5264 { config_parse_path_spec
, "PATH" },
5265 { config_parse_notify_access
, "ACCESS" },
5266 { config_parse_ip_tos
, "TOS" },
5267 { config_parse_unit_condition_path
, "CONDITION" },
5268 { config_parse_unit_condition_string
, "CONDITION" },
5269 { config_parse_unit_condition_null
, "CONDITION" },
5270 { config_parse_unit_slice
, "SLICE" },
5271 { config_parse_documentation
, "URL" },
5272 { config_parse_service_timeout
, "SECONDS" },
5273 { config_parse_emergency_action
, "ACTION" },
5274 { config_parse_set_status
, "STATUS" },
5275 { config_parse_service_sockets
, "SOCKETS" },
5276 { config_parse_environ
, "ENVIRON" },
5278 { config_parse_syscall_filter
, "SYSCALLS" },
5279 { config_parse_syscall_archs
, "ARCHS" },
5280 { config_parse_syscall_errno
, "ERRNO" },
5281 { config_parse_address_families
, "FAMILIES" },
5282 { config_parse_restrict_namespaces
, "NAMESPACES" },
5284 { config_parse_cpu_shares
, "SHARES" },
5285 { config_parse_cg_weight
, "WEIGHT" },
5286 { config_parse_memory_limit
, "LIMIT" },
5287 { config_parse_device_allow
, "DEVICE" },
5288 { config_parse_device_policy
, "POLICY" },
5289 { config_parse_io_limit
, "LIMIT" },
5290 { config_parse_io_device_weight
, "DEVICEWEIGHT" },
5291 { config_parse_io_device_latency
, "DEVICELATENCY" },
5292 { config_parse_blockio_bandwidth
, "BANDWIDTH" },
5293 { config_parse_blockio_weight
, "WEIGHT" },
5294 { config_parse_blockio_device_weight
, "DEVICEWEIGHT" },
5295 { config_parse_long
, "LONG" },
5296 { config_parse_socket_service
, "SERVICE" },
5298 { config_parse_exec_selinux_context
, "LABEL" },
5300 { config_parse_job_mode
, "MODE" },
5301 { config_parse_job_mode_isolate
, "BOOLEAN" },
5302 { config_parse_personality
, "PERSONALITY" },
5305 const char *prev
= NULL
;
5310 NULSTR_FOREACH(i
, load_fragment_gperf_nulstr
) {
5311 const char *rvalue
= "OTHER", *lvalue
;
5312 const ConfigPerfItem
*p
;
5317 assert_se(p
= load_fragment_gperf_lookup(i
, strlen(i
)));
5319 /* Hide legacy settings */
5320 if (p
->parse
== config_parse_warn_compat
&&
5321 p
->ltype
== DISABLED_LEGACY
)
5324 for (j
= 0; j
< ELEMENTSOF(table
); j
++)
5325 if (p
->parse
== table
[j
].callback
) {
5326 rvalue
= table
[j
].rvalue
;
5330 dot
= strchr(i
, '.');
5331 lvalue
= dot
? dot
+ 1 : i
;
5335 if (!prev
|| !strneq(prev
, i
, prefix_len
+1)) {
5339 fprintf(f
, "[%.*s]\n", (int) prefix_len
, i
);
5342 fprintf(f
, "%s=%s\n", lvalue
, rvalue
);
5347 int config_parse_cpu_affinity2(
5349 const char *filename
,
5351 const char *section
,
5352 unsigned section_line
,
5359 CPUSet
*affinity
= data
;
5363 (void) parse_cpu_set_extend(rvalue
, affinity
, true, unit
, filename
, line
, lvalue
);
5368 int config_parse_show_status(
5370 const char *filename
,
5372 const char *section
,
5373 unsigned section_line
,
5381 ShowStatus
*b
= data
;
5388 k
= parse_show_status(rvalue
, b
);
5390 log_syntax(unit
, LOG_ERR
, filename
, line
, k
, "Failed to parse show status setting, ignoring: %s", rvalue
);
5397 int config_parse_output_restricted(
5399 const char *filename
,
5401 const char *section
,
5402 unsigned section_line
,
5409 ExecOutput t
, *eo
= data
;
5410 bool obsolete
= false;
5417 if (streq(rvalue
, "syslog")) {
5418 t
= EXEC_OUTPUT_JOURNAL
;
5420 } else if (streq(rvalue
, "syslog+console")) {
5421 t
= EXEC_OUTPUT_JOURNAL_AND_CONSOLE
;
5424 t
= exec_output_from_string(rvalue
);
5426 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse output type, ignoring: %s", rvalue
);
5430 if (IN_SET(t
, EXEC_OUTPUT_SOCKET
, EXEC_OUTPUT_NAMED_FD
, EXEC_OUTPUT_FILE
, EXEC_OUTPUT_FILE_APPEND
)) {
5431 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Standard output types socket, fd:, file:, append: are not supported as defaults, ignoring: %s", rvalue
);
5437 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
5438 "Standard output type %s is obsolete, automatically updating to %s. Please update your configuration.",
5439 rvalue
, exec_output_to_string(t
));
5445 int config_parse_crash_chvt(
5447 const char *filename
,
5449 const char *section
,
5450 unsigned section_line
,
5464 r
= parse_crash_chvt(rvalue
, data
);
5466 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse CrashChangeVT= setting, ignoring: %s", rvalue
);
5473 int config_parse_swap_priority(
5475 const char *filename
,
5477 const char *section
,
5478 unsigned section_line
,
5494 if (isempty(rvalue
)) {
5495 s
->parameters_fragment
.priority
= -1;
5496 s
->parameters_fragment
.priority_set
= false;
5500 r
= safe_atoi(rvalue
, &priority
);
5502 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid swap priority '%s', ignoring.", rvalue
);
5506 if (priority
< -1) {
5507 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
);
5511 if (priority
> 32767) {
5512 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Swap priority out of range, ignoring: %s", rvalue
);
5516 s
->parameters_fragment
.priority
= priority
;
5517 s
->parameters_fragment
.priority_set
= true;