1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 Copyright © 2012 Holger Hans Peter Freyther
14 #include <sys/resource.h>
17 #include "alloc-util.h"
18 #include "all-units.h"
19 #include "bpf-firewall.h"
20 #include "bus-error.h"
21 #include "bus-internal.h"
24 #include "capability-util.h"
25 #include "cgroup-setup.h"
26 #include "conf-parser.h"
27 #include "cpu-set-util.h"
29 #include "errno-list.h"
33 #include "hexdecoct.h"
36 #include "ip-protocol-list.h"
37 #include "journal-util.h"
38 #include "limits-util.h"
39 #include "load-fragment.h"
41 #include "mountpoint-util.h"
42 #include "nulstr-util.h"
43 #include "parse-util.h"
44 #include "path-util.h"
45 #include "process-util.h"
47 #include "seccomp-util.h"
49 #include "securebits-util.h"
50 #include "signal-util.h"
51 #include "socket-netlink.h"
52 #include "stat-util.h"
53 #include "string-util.h"
55 #include "syslog-util.h"
56 #include "time-util.h"
57 #include "unit-name.h"
58 #include "unit-printf.h"
59 #include "user-util.h"
62 static int parse_socket_protocol(const char *s
) {
65 r
= parse_ip_protocol(s
);
68 if (!IN_SET(r
, IPPROTO_UDPLITE
, IPPROTO_SCTP
))
69 return -EPROTONOSUPPORT
;
74 int parse_crash_chvt(const char *value
, int *data
) {
77 if (safe_atoi(value
, data
) >= 0)
80 b
= parse_boolean(value
);
85 *data
= 0; /* switch to where kmsg goes */
87 *data
= -1; /* turn off switching */
92 int parse_confirm_spawn(const char *value
, char **console
) {
96 r
= value
? parse_boolean(value
) : 1;
100 } else if (r
> 0) /* on with default tty */
101 s
= strdup("/dev/console");
102 else if (is_path(value
)) /* on with fully qualified path */
104 else /* on with only a tty file name, not a fully qualified path */
105 s
= path_join("/dev/", value
);
113 DEFINE_CONFIG_PARSE(config_parse_socket_protocol
, parse_socket_protocol
, "Failed to parse socket protocol");
114 DEFINE_CONFIG_PARSE(config_parse_exec_secure_bits
, secure_bits_from_string
, "Failed to parse secure bits");
115 DEFINE_CONFIG_PARSE_ENUM(config_parse_collect_mode
, collect_mode
, CollectMode
, "Failed to parse garbage collection mode");
116 DEFINE_CONFIG_PARSE_ENUM(config_parse_device_policy
, cgroup_device_policy
, CGroupDevicePolicy
, "Failed to parse device policy");
117 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_keyring_mode
, exec_keyring_mode
, ExecKeyringMode
, "Failed to parse keyring mode");
118 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_utmp_mode
, exec_utmp_mode
, ExecUtmpMode
, "Failed to parse utmp mode");
119 DEFINE_CONFIG_PARSE_ENUM(config_parse_job_mode
, job_mode
, JobMode
, "Failed to parse job mode");
120 DEFINE_CONFIG_PARSE_ENUM(config_parse_kill_mode
, kill_mode
, KillMode
, "Failed to parse kill mode");
121 DEFINE_CONFIG_PARSE_ENUM(config_parse_notify_access
, notify_access
, NotifyAccess
, "Failed to parse notify access specifier");
122 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_home
, protect_home
, ProtectHome
, "Failed to parse protect home value");
123 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_system
, protect_system
, ProtectSystem
, "Failed to parse protect system value");
124 DEFINE_CONFIG_PARSE_ENUM(config_parse_runtime_preserve_mode
, exec_preserve_mode
, ExecPreserveMode
, "Failed to parse runtime directory preserve mode");
125 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_type
, service_type
, ServiceType
, "Failed to parse service type");
126 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart
, service_restart
, ServiceRestart
, "Failed to parse service restart specifier");
127 DEFINE_CONFIG_PARSE_ENUM(config_parse_socket_bind
, socket_address_bind_ipv6_only_or_bool
, SocketAddressBindIPv6Only
, "Failed to parse bind IPv6 only value");
128 DEFINE_CONFIG_PARSE_ENUM(config_parse_oom_policy
, oom_policy
, OOMPolicy
, "Failed to parse OOM policy");
129 DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_ip_tos
, ip_tos
, int, -1, "Failed to parse IP TOS value");
130 DEFINE_CONFIG_PARSE_PTR(config_parse_blockio_weight
, cg_blkio_weight_parse
, uint64_t, "Invalid block IO weight");
131 DEFINE_CONFIG_PARSE_PTR(config_parse_cg_weight
, cg_weight_parse
, uint64_t, "Invalid weight");
132 DEFINE_CONFIG_PARSE_PTR(config_parse_cpu_shares
, cg_cpu_shares_parse
, uint64_t, "Invalid CPU shares");
133 DEFINE_CONFIG_PARSE_PTR(config_parse_exec_mount_flags
, mount_propagation_flags_from_string
, unsigned long, "Failed to parse mount flag");
134 DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_numa_policy
, mpol
, int, -1, "Invalid NUMA policy type");
135 DEFINE_CONFIG_PARSE_ENUM(config_parse_status_unit_format
, status_unit_format
, StatusUnitFormat
, "Failed to parse status unit format");
137 int config_parse_unit_deps(
139 const char *filename
,
142 unsigned section_line
,
149 UnitDependency d
= ltype
;
159 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
162 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_RETAIN_ESCAPE
);
168 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
172 r
= unit_name_printf(u
, word
, &k
);
174 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
178 r
= unit_add_dependency_by_name(u
, d
, k
, true, UNIT_DEPENDENCY_FILE
);
180 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
186 int config_parse_obsolete_unit_deps(
188 const char *filename
,
191 unsigned section_line
,
198 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
199 "Unit dependency type %s= is obsolete, replacing by %s=, please update your unit file", lvalue
, unit_dependency_to_string(ltype
));
201 return config_parse_unit_deps(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
);
204 int config_parse_unit_string_printf(
206 const char *filename
,
209 unsigned section_line
,
216 _cleanup_free_
char *k
= NULL
;
217 const Unit
*u
= userdata
;
225 r
= unit_full_printf(u
, rvalue
, &k
);
227 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
231 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
234 int config_parse_unit_strv_printf(
236 const char *filename
,
239 unsigned section_line
,
246 const Unit
*u
= userdata
;
247 _cleanup_free_
char *k
= NULL
;
255 r
= unit_full_printf(u
, rvalue
, &k
);
257 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
261 return config_parse_strv(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
264 int config_parse_unit_path_printf(
266 const char *filename
,
269 unsigned section_line
,
276 _cleanup_free_
char *k
= NULL
;
277 const Unit
*u
= userdata
;
286 /* Let's not bother with anything that is too long */
287 if (strlen(rvalue
) >= PATH_MAX
) {
288 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
289 "%s value too long%s.",
290 lvalue
, fatal
? "" : ", ignoring");
291 return fatal
? -ENAMETOOLONG
: 0;
294 r
= unit_full_printf(u
, rvalue
, &k
);
296 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
297 "Failed to resolve unit specifiers in '%s'%s: %m",
298 rvalue
, fatal
? "" : ", ignoring");
299 return fatal
? -ENOEXEC
: 0;
302 return config_parse_path(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
305 int config_parse_unit_path_strv_printf(
307 const char *filename
,
310 unsigned section_line
,
318 const Unit
*u
= userdata
;
327 if (isempty(rvalue
)) {
333 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
335 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
341 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
342 "Invalid syntax, ignoring: %s", rvalue
);
346 r
= unit_full_printf(u
, word
, &k
);
348 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
349 "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
353 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
357 r
= strv_consume(x
, TAKE_PTR(k
));
363 static int patch_var_run(
365 const char *filename
,
373 e
= path_startswith(*path
, "/var/run/");
377 z
= path_join("/run/", e
);
381 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
382 "%s= references a path below legacy directory /var/run/, updating %s → %s; "
383 "please update the unit file accordingly.", lvalue
, *path
, z
);
385 free_and_replace(*path
, z
);
390 int config_parse_socket_listen(
392 const char *filename
,
395 unsigned section_line
,
402 _cleanup_free_ SocketPort
*p
= NULL
;
414 if (isempty(rvalue
)) {
415 /* An empty assignment removes all ports */
416 socket_free_ports(s
);
420 p
= new0(SocketPort
, 1);
424 if (ltype
!= SOCKET_SOCKET
) {
425 _cleanup_free_
char *k
= NULL
;
427 r
= unit_full_printf(UNIT(s
), rvalue
, &k
);
429 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
433 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
437 if (ltype
== SOCKET_FIFO
) {
438 r
= patch_var_run(unit
, filename
, line
, lvalue
, &k
);
443 free_and_replace(p
->path
, k
);
446 } else if (streq(lvalue
, "ListenNetlink")) {
447 _cleanup_free_
char *k
= NULL
;
449 r
= unit_full_printf(UNIT(s
), rvalue
, &k
);
451 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
455 r
= socket_address_parse_netlink(&p
->address
, k
);
457 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse address value in '%s', ignoring: %m", k
);
461 p
->type
= SOCKET_SOCKET
;
464 _cleanup_free_
char *k
= NULL
;
466 r
= unit_full_printf(UNIT(s
), rvalue
, &k
);
468 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
472 if (k
[0] == '/') { /* Only for AF_UNIX file system sockets… */
473 r
= patch_var_run(unit
, filename
, line
, lvalue
, &k
);
478 r
= socket_address_parse_and_warn(&p
->address
, k
);
480 if (r
!= -EAFNOSUPPORT
)
481 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse address value in '%s', ignoring: %m", k
);
485 if (streq(lvalue
, "ListenStream"))
486 p
->address
.type
= SOCK_STREAM
;
487 else if (streq(lvalue
, "ListenDatagram"))
488 p
->address
.type
= SOCK_DGRAM
;
490 assert(streq(lvalue
, "ListenSequentialPacket"));
491 p
->address
.type
= SOCK_SEQPACKET
;
494 if (socket_address_family(&p
->address
) != AF_LOCAL
&& p
->address
.type
== SOCK_SEQPACKET
) {
495 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Address family not supported, ignoring: %s", rvalue
);
499 p
->type
= SOCKET_SOCKET
;
503 p
->auxiliary_fds
= NULL
;
504 p
->n_auxiliary_fds
= 0;
507 LIST_FIND_TAIL(port
, s
->ports
, tail
);
508 LIST_INSERT_AFTER(port
, s
->ports
, tail
, p
);
515 int config_parse_exec_nice(
517 const char *filename
,
520 unsigned section_line
,
527 ExecContext
*c
= data
;
535 if (isempty(rvalue
)) {
540 r
= parse_nice(rvalue
, &priority
);
543 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Nice priority out of range, ignoring: %s", rvalue
);
545 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse nice priority '%s', ignoring: %m", rvalue
);
555 int config_parse_exec_oom_score_adjust(
557 const char *filename
,
560 unsigned section_line
,
567 ExecContext
*c
= data
;
575 if (isempty(rvalue
)) {
576 c
->oom_score_adjust_set
= false;
580 r
= parse_oom_score_adjust(rvalue
, &oa
);
583 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "OOM score adjust value out of range, ignoring: %s", rvalue
);
585 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse the OOM score adjust value '%s', ignoring: %m", rvalue
);
589 c
->oom_score_adjust
= oa
;
590 c
->oom_score_adjust_set
= true;
595 int config_parse_exec_coredump_filter(
597 const char *filename
,
600 unsigned section_line
,
607 ExecContext
*c
= data
;
615 if (isempty(rvalue
)) {
616 c
->coredump_filter
= 0;
617 c
->coredump_filter_set
= false;
622 r
= coredump_filter_mask_from_string(rvalue
, &f
);
624 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
625 "Failed to parse the CoredumpFilter=%s, ignoring: %m", rvalue
);
629 c
->coredump_filter
|= f
;
630 c
->oom_score_adjust_set
= true;
634 int config_parse_exec(
636 const char *filename
,
639 unsigned section_line
,
646 ExecCommand
**e
= data
;
647 const Unit
*u
= userdata
;
659 if (isempty(rvalue
)) {
660 /* An empty assignment resets the list */
661 *e
= exec_command_free_list(*e
);
667 _cleanup_free_
char *path
= NULL
, *firstword
= NULL
;
668 ExecCommandFlags flags
= 0;
669 bool ignore
= false, separate_argv0
= false;
670 _cleanup_free_ ExecCommand
*nce
= NULL
;
671 _cleanup_strv_free_
char **n
= NULL
;
672 size_t nlen
= 0, nbufsize
= 0;
677 r
= extract_first_word_and_warn(&p
, &firstword
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
683 /* We accept an absolute path as first argument. If it's prefixed with - and the path doesn't
684 * exist, we ignore it instead of erroring out; if it's prefixed with @, we allow overriding of
685 * argv[0]; if it's prefixed with :, we will not do environment variable substitution;
686 * if it's prefixed with +, it will be run with full privileges and no sandboxing; if
687 * it's prefixed with '!' we apply sandboxing, but do not change user/group credentials; if
688 * it's prefixed with '!!', then we apply user/group credentials if the kernel supports ambient
689 * capabilities -- if it doesn't we don't apply the credentials themselves, but do apply most
690 * other sandboxing, with some special exceptions for changing UID.
692 * The idea is that '!!' may be used to write services that can take benefit of systemd's
693 * UID/GID dropping if the kernel supports ambient creds, but provide an automatic fallback to
694 * privilege dropping within the daemon if the kernel does not offer that. */
696 if (*f
== '-' && !(flags
& EXEC_COMMAND_IGNORE_FAILURE
)) {
697 flags
|= EXEC_COMMAND_IGNORE_FAILURE
;
699 } else if (*f
== '@' && !separate_argv0
)
700 separate_argv0
= true;
701 else if (*f
== ':' && !(flags
& EXEC_COMMAND_NO_ENV_EXPAND
))
702 flags
|= EXEC_COMMAND_NO_ENV_EXPAND
;
703 else if (*f
== '+' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
704 flags
|= EXEC_COMMAND_FULLY_PRIVILEGED
;
705 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
706 flags
|= EXEC_COMMAND_NO_SETUID
;
707 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_AMBIENT_MAGIC
))) {
708 flags
&= ~EXEC_COMMAND_NO_SETUID
;
709 flags
|= EXEC_COMMAND_AMBIENT_MAGIC
;
715 r
= unit_full_printf(u
, f
, &path
);
717 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
718 "Failed to resolve unit specifiers in '%s'%s: %m",
719 f
, ignore
? ", ignoring" : "");
720 return ignore
? 0 : -ENOEXEC
;
724 /* First word is either "-" or "@" with no command. */
725 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
726 "Empty path in command line%s: '%s'",
727 ignore
? ", ignoring" : "", rvalue
);
728 return ignore
? 0 : -ENOEXEC
;
730 if (!string_is_safe(path
)) {
731 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
732 "Executable name contains special characters%s: %s",
733 ignore
? ", ignoring" : "", path
);
734 return ignore
? 0 : -ENOEXEC
;
736 if (endswith(path
, "/")) {
737 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
738 "Executable path specifies a directory%s: %s",
739 ignore
? ", ignoring" : "", path
);
740 return ignore
? 0 : -ENOEXEC
;
743 if (!path_is_absolute(path
)) {
747 if (!filename_is_valid(path
)) {
748 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
749 "Neither a valid executable name nor an absolute path%s: %s",
750 ignore
? ", ignoring" : "", path
);
751 return ignore
? 0 : -ENOEXEC
;
754 /* Resolve a single-component name to a full path */
755 NULSTR_FOREACH(prefix
, DEFAULT_PATH_NULSTR
) {
756 _cleanup_free_
char *fullpath
= NULL
;
758 fullpath
= path_join(prefix
, path
);
762 if (access(fullpath
, F_OK
) >= 0) {
763 free_and_replace(path
, fullpath
);
770 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
771 "Executable \"%s\" not found in path \"%s\"%s",
772 path
, DEFAULT_PATH
, ignore
? ", ignoring" : "");
773 return ignore
? 0 : -ENOEXEC
;
777 if (!separate_argv0
) {
780 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
790 path_simplify(path
, false);
792 while (!isempty(p
)) {
793 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
795 /* Check explicitly for an unquoted semicolon as
796 * command separator token. */
797 if (p
[0] == ';' && (!p
[1] || strchr(WHITESPACE
, p
[1]))) {
799 p
+= strspn(p
, WHITESPACE
);
804 /* Check for \; explicitly, to not confuse it with \\; or "\;" or "\\;" etc.
805 * extract_first_word() would return the same for all of those. */
806 if (p
[0] == '\\' && p
[1] == ';' && (!p
[2] || strchr(WHITESPACE
, p
[2]))) {
810 p
+= strspn(p
, WHITESPACE
);
812 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
823 r
= extract_first_word_and_warn(&p
, &word
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
827 return ignore
? 0 : -ENOEXEC
;
829 r
= unit_full_printf(u
, word
, &resolved
);
831 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
832 "Failed to resolve unit specifiers in %s%s: %m",
833 word
, ignore
? ", ignoring" : "");
834 return ignore
? 0 : -ENOEXEC
;
837 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
840 n
[nlen
++] = TAKE_PTR(resolved
);
845 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
846 "Empty executable name or zeroeth argument%s: %s",
847 ignore
? ", ignoring" : "", rvalue
);
848 return ignore
? 0 : -ENOEXEC
;
851 nce
= new0(ExecCommand
, 1);
855 nce
->argv
= TAKE_PTR(n
);
856 nce
->path
= TAKE_PTR(path
);
859 exec_command_append_list(e
, nce
);
861 /* Do not _cleanup_free_ these. */
870 int config_parse_socket_bindtodevice(
872 const char *filename
,
875 unsigned section_line
,
889 if (isempty(rvalue
) || streq(rvalue
, "*")) {
890 s
->bind_to_device
= mfree(s
->bind_to_device
);
894 if (!ifname_valid(rvalue
)) {
895 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid interface name, ignoring: %s", rvalue
);
899 if (free_and_strdup(&s
->bind_to_device
, rvalue
) < 0)
905 int config_parse_exec_input(
907 const char *filename
,
910 unsigned section_line
,
917 ExecContext
*c
= data
;
918 const Unit
*u
= userdata
;
928 n
= startswith(rvalue
, "fd:");
930 _cleanup_free_
char *resolved
= NULL
;
932 r
= unit_full_printf(u
, n
, &resolved
);
934 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s': %m", n
);
936 if (isempty(resolved
))
937 resolved
= mfree(resolved
);
938 else if (!fdname_is_valid(resolved
)) {
939 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name: %s", resolved
);
943 free_and_replace(c
->stdio_fdname
[STDIN_FILENO
], resolved
);
945 ei
= EXEC_INPUT_NAMED_FD
;
947 } else if ((n
= startswith(rvalue
, "file:"))) {
948 _cleanup_free_
char *resolved
= NULL
;
950 r
= unit_full_printf(u
, n
, &resolved
);
952 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s': %m", n
);
954 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
958 free_and_replace(c
->stdio_file
[STDIN_FILENO
], resolved
);
960 ei
= EXEC_INPUT_FILE
;
963 ei
= exec_input_from_string(rvalue
);
965 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse input specifier, ignoring: %s", rvalue
);
974 int config_parse_exec_input_text(
976 const char *filename
,
979 unsigned section_line
,
986 _cleanup_free_
char *unescaped
= NULL
, *resolved
= NULL
;
987 ExecContext
*c
= data
;
988 const Unit
*u
= userdata
;
998 if (isempty(rvalue
)) {
999 /* Reset if the empty string is assigned */
1000 c
->stdin_data
= mfree(c
->stdin_data
);
1001 c
->stdin_data_size
= 0;
1005 r
= cunescape(rvalue
, 0, &unescaped
);
1007 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to decode C escaped text '%s': %m", rvalue
);
1009 r
= unit_full_printf(u
, unescaped
, &resolved
);
1011 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s': %m", unescaped
);
1013 sz
= strlen(resolved
);
1014 if (c
->stdin_data_size
+ sz
+ 1 < c
->stdin_data_size
|| /* check for overflow */
1015 c
->stdin_data_size
+ sz
+ 1 > EXEC_STDIN_DATA_MAX
) {
1016 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
);
1020 p
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
+ 1);
1024 *((char*) mempcpy((char*) p
+ c
->stdin_data_size
, resolved
, sz
)) = '\n';
1027 c
->stdin_data_size
+= sz
+ 1;
1032 int config_parse_exec_input_data(
1034 const char *filename
,
1036 const char *section
,
1037 unsigned section_line
,
1044 _cleanup_free_
void *p
= NULL
;
1045 ExecContext
*c
= data
;
1055 if (isempty(rvalue
)) {
1056 /* Reset if the empty string is assigned */
1057 c
->stdin_data
= mfree(c
->stdin_data
);
1058 c
->stdin_data_size
= 0;
1062 r
= unbase64mem(rvalue
, (size_t) -1, &p
, &sz
);
1064 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to decode base64 data, ignoring: %s", rvalue
);
1068 if (c
->stdin_data_size
+ sz
< c
->stdin_data_size
|| /* check for overflow */
1069 c
->stdin_data_size
+ sz
> EXEC_STDIN_DATA_MAX
) {
1070 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
);
1074 q
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
);
1078 memcpy((uint8_t*) q
+ c
->stdin_data_size
, p
, sz
);
1081 c
->stdin_data_size
+= sz
;
1086 int config_parse_exec_output(
1088 const char *filename
,
1090 const char *section
,
1091 unsigned section_line
,
1098 _cleanup_free_
char *resolved
= NULL
;
1100 ExecContext
*c
= data
;
1101 const Unit
*u
= userdata
;
1111 n
= startswith(rvalue
, "fd:");
1113 r
= unit_full_printf(u
, n
, &resolved
);
1115 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", n
);
1117 if (isempty(resolved
))
1118 resolved
= mfree(resolved
);
1119 else if (!fdname_is_valid(resolved
)) {
1120 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name: %s", resolved
);
1124 eo
= EXEC_OUTPUT_NAMED_FD
;
1126 } else if ((n
= startswith(rvalue
, "file:"))) {
1128 r
= unit_full_printf(u
, n
, &resolved
);
1130 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", n
);
1132 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1136 eo
= EXEC_OUTPUT_FILE
;
1138 } else if ((n
= startswith(rvalue
, "append:"))) {
1140 r
= unit_full_printf(u
, n
, &resolved
);
1142 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", n
);
1144 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1148 eo
= EXEC_OUTPUT_FILE_APPEND
;
1150 eo
= exec_output_from_string(rvalue
);
1152 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse output specifier, ignoring: %s", rvalue
);
1157 if (streq(lvalue
, "StandardOutput")) {
1158 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1159 free_and_replace(c
->stdio_fdname
[STDOUT_FILENO
], resolved
);
1161 free_and_replace(c
->stdio_file
[STDOUT_FILENO
], resolved
);
1166 assert(streq(lvalue
, "StandardError"));
1168 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1169 free_and_replace(c
->stdio_fdname
[STDERR_FILENO
], resolved
);
1171 free_and_replace(c
->stdio_file
[STDERR_FILENO
], resolved
);
1179 int config_parse_exec_io_class(const char *unit
,
1180 const char *filename
,
1182 const char *section
,
1183 unsigned section_line
,
1190 ExecContext
*c
= data
;
1198 if (isempty(rvalue
)) {
1199 c
->ioprio_set
= false;
1200 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE
, 0);
1204 x
= ioprio_class_from_string(rvalue
);
1206 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse IO scheduling class, ignoring: %s", rvalue
);
1210 c
->ioprio
= IOPRIO_PRIO_VALUE(x
, IOPRIO_PRIO_DATA(c
->ioprio
));
1211 c
->ioprio_set
= true;
1216 int config_parse_exec_io_priority(const char *unit
,
1217 const char *filename
,
1219 const char *section
,
1220 unsigned section_line
,
1227 ExecContext
*c
= data
;
1235 if (isempty(rvalue
)) {
1236 c
->ioprio_set
= false;
1237 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE
, 0);
1241 r
= ioprio_parse_priority(rvalue
, &i
);
1243 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse IO priority, ignoring: %s", rvalue
);
1247 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_PRIO_CLASS(c
->ioprio
), i
);
1248 c
->ioprio_set
= true;
1253 int config_parse_exec_cpu_sched_policy(const char *unit
,
1254 const char *filename
,
1256 const char *section
,
1257 unsigned section_line
,
1264 ExecContext
*c
= data
;
1272 if (isempty(rvalue
)) {
1273 c
->cpu_sched_set
= false;
1274 c
->cpu_sched_policy
= SCHED_OTHER
;
1275 c
->cpu_sched_priority
= 0;
1279 x
= sched_policy_from_string(rvalue
);
1281 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse CPU scheduling policy, ignoring: %s", rvalue
);
1285 c
->cpu_sched_policy
= x
;
1286 /* Moving to or from real-time policy? We need to adjust the priority */
1287 c
->cpu_sched_priority
= CLAMP(c
->cpu_sched_priority
, sched_get_priority_min(x
), sched_get_priority_max(x
));
1288 c
->cpu_sched_set
= true;
1293 int config_parse_numa_mask(const char *unit
,
1294 const char *filename
,
1296 const char *section
,
1297 unsigned section_line
,
1304 NUMAPolicy
*p
= data
;
1311 r
= parse_cpu_set_extend(rvalue
, &p
->nodes
, true, unit
, filename
, line
, lvalue
);
1313 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse NUMA node mask, ignoring: %s", rvalue
);
1320 int config_parse_exec_cpu_sched_prio(const char *unit
,
1321 const char *filename
,
1323 const char *section
,
1324 unsigned section_line
,
1331 ExecContext
*c
= data
;
1339 r
= safe_atoi(rvalue
, &i
);
1341 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse CPU scheduling priority, ignoring: %s", rvalue
);
1345 /* On Linux RR/FIFO range from 1 to 99 and OTHER/BATCH may only be 0 */
1346 min
= sched_get_priority_min(c
->cpu_sched_policy
);
1347 max
= sched_get_priority_max(c
->cpu_sched_policy
);
1349 if (i
< min
|| i
> max
) {
1350 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "CPU scheduling priority is out of range, ignoring: %s", rvalue
);
1354 c
->cpu_sched_priority
= i
;
1355 c
->cpu_sched_set
= true;
1360 int config_parse_exec_cpu_affinity(const char *unit
,
1361 const char *filename
,
1363 const char *section
,
1364 unsigned section_line
,
1371 ExecContext
*c
= data
;
1379 if (streq(rvalue
, "numa")) {
1380 c
->cpu_affinity_from_numa
= true;
1381 cpu_set_reset(&c
->cpu_set
);
1386 r
= parse_cpu_set_extend(rvalue
, &c
->cpu_set
, true, unit
, filename
, line
, lvalue
);
1388 c
->cpu_affinity_from_numa
= false;
1393 int config_parse_capability_set(
1395 const char *filename
,
1397 const char *section
,
1398 unsigned section_line
,
1405 uint64_t *capability_set
= data
;
1406 uint64_t sum
= 0, initial
= 0;
1407 bool invert
= false;
1415 if (rvalue
[0] == '~') {
1420 if (streq(lvalue
, "CapabilityBoundingSet"))
1421 initial
= CAP_ALL
; /* initialized to all bits on */
1422 /* else "AmbientCapabilities" initialized to all bits off */
1424 r
= capability_set_from_string(rvalue
, &sum
);
1426 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= specifier '%s', ignoring: %m", lvalue
, rvalue
);
1430 if (sum
== 0 || *capability_set
== initial
)
1431 /* "", "~" or uninitialized data -> replace */
1432 *capability_set
= invert
? ~sum
: sum
;
1434 /* previous data -> merge */
1436 *capability_set
&= ~sum
;
1438 *capability_set
|= sum
;
1444 int config_parse_exec_selinux_context(
1446 const char *filename
,
1448 const char *section
,
1449 unsigned section_line
,
1456 ExecContext
*c
= data
;
1457 const Unit
*u
= userdata
;
1467 if (isempty(rvalue
)) {
1468 c
->selinux_context
= mfree(c
->selinux_context
);
1469 c
->selinux_context_ignore
= false;
1473 if (rvalue
[0] == '-') {
1479 r
= unit_full_printf(u
, rvalue
, &k
);
1481 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1482 "Failed to resolve unit specifiers in '%s'%s: %m",
1483 rvalue
, ignore
? ", ignoring" : "");
1484 return ignore
? 0 : -ENOEXEC
;
1487 free_and_replace(c
->selinux_context
, k
);
1488 c
->selinux_context_ignore
= ignore
;
1493 int config_parse_exec_apparmor_profile(
1495 const char *filename
,
1497 const char *section
,
1498 unsigned section_line
,
1505 ExecContext
*c
= data
;
1506 const Unit
*u
= userdata
;
1516 if (isempty(rvalue
)) {
1517 c
->apparmor_profile
= mfree(c
->apparmor_profile
);
1518 c
->apparmor_profile_ignore
= false;
1522 if (rvalue
[0] == '-') {
1528 r
= unit_full_printf(u
, rvalue
, &k
);
1530 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1531 "Failed to resolve unit specifiers in '%s'%s: %m",
1532 rvalue
, ignore
? ", ignoring" : "");
1533 return ignore
? 0 : -ENOEXEC
;
1536 free_and_replace(c
->apparmor_profile
, k
);
1537 c
->apparmor_profile_ignore
= ignore
;
1542 int config_parse_exec_smack_process_label(
1544 const char *filename
,
1546 const char *section
,
1547 unsigned section_line
,
1554 ExecContext
*c
= data
;
1555 const Unit
*u
= userdata
;
1565 if (isempty(rvalue
)) {
1566 c
->smack_process_label
= mfree(c
->smack_process_label
);
1567 c
->smack_process_label_ignore
= false;
1571 if (rvalue
[0] == '-') {
1577 r
= unit_full_printf(u
, rvalue
, &k
);
1579 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1580 "Failed to resolve unit specifiers in '%s'%s: %m",
1581 rvalue
, ignore
? ", ignoring" : "");
1582 return ignore
? 0 : -ENOEXEC
;
1585 free_and_replace(c
->smack_process_label
, k
);
1586 c
->smack_process_label_ignore
= ignore
;
1591 int config_parse_timer(
1593 const char *filename
,
1595 const char *section
,
1596 unsigned section_line
,
1603 _cleanup_(calendar_spec_freep
) CalendarSpec
*c
= NULL
;
1604 _cleanup_free_
char *k
= NULL
;
1605 const Unit
*u
= userdata
;
1616 if (isempty(rvalue
)) {
1617 /* Empty assignment resets list */
1618 timer_free_values(t
);
1622 r
= unit_full_printf(u
, rvalue
, &k
);
1624 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
1628 if (ltype
== TIMER_CALENDAR
) {
1629 r
= calendar_spec_from_string(k
, &c
);
1631 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse calendar specification, ignoring: %s", k
);
1635 r
= parse_sec(k
, &usec
);
1637 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse timer value, ignoring: %s", k
);
1642 v
= new(TimerValue
, 1);
1649 .calendar_spec
= TAKE_PTR(c
),
1652 LIST_PREPEND(value
, t
->values
, v
);
1657 int config_parse_trigger_unit(
1659 const char *filename
,
1661 const char *section
,
1662 unsigned section_line
,
1669 _cleanup_free_
char *p
= NULL
;
1679 if (!hashmap_isempty(u
->dependencies
[UNIT_TRIGGERS
])) {
1680 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Multiple units to trigger specified, ignoring: %s", rvalue
);
1684 r
= unit_name_printf(u
, rvalue
, &p
);
1686 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
1690 type
= unit_name_to_type(p
);
1692 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit type not valid, ignoring: %s", rvalue
);
1695 if (unit_has_name(u
, p
)) {
1696 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Units cannot trigger themselves, ignoring: %s", rvalue
);
1700 r
= unit_add_two_dependencies_by_name(u
, UNIT_BEFORE
, UNIT_TRIGGERS
, p
, true, UNIT_DEPENDENCY_FILE
);
1702 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add trigger on %s, ignoring: %m", p
);
1709 int config_parse_path_spec(const char *unit
,
1710 const char *filename
,
1712 const char *section
,
1713 unsigned section_line
,
1723 _cleanup_free_
char *k
= NULL
;
1731 if (isempty(rvalue
)) {
1732 /* Empty assignment clears list */
1737 b
= path_type_from_string(lvalue
);
1739 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse path type, ignoring: %s", lvalue
);
1743 r
= unit_full_printf(UNIT(p
), rvalue
, &k
);
1745 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
1749 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
1753 s
= new0(PathSpec
, 1);
1758 s
->path
= TAKE_PTR(k
);
1762 LIST_PREPEND(spec
, p
->specs
, s
);
1767 int config_parse_socket_service(
1769 const char *filename
,
1771 const char *section
,
1772 unsigned section_line
,
1779 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1780 _cleanup_free_
char *p
= NULL
;
1790 r
= unit_name_printf(UNIT(s
), rvalue
, &p
);
1792 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", rvalue
);
1796 if (!endswith(p
, ".service")) {
1797 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit must be of type service: %s", rvalue
);
1801 r
= manager_load_unit(UNIT(s
)->manager
, p
, NULL
, &error
, &x
);
1803 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to load unit %s: %s", rvalue
, bus_error_message(&error
, r
));
1807 unit_ref_set(&s
->service
, UNIT(s
), x
);
1812 int config_parse_fdname(
1814 const char *filename
,
1816 const char *section
,
1817 unsigned section_line
,
1824 _cleanup_free_
char *p
= NULL
;
1833 if (isempty(rvalue
)) {
1834 s
->fdname
= mfree(s
->fdname
);
1838 r
= unit_full_printf(UNIT(s
), rvalue
, &p
);
1840 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
1844 if (!fdname_is_valid(p
)) {
1845 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", p
);
1849 return free_and_replace(s
->fdname
, p
);
1852 int config_parse_service_sockets(
1854 const char *filename
,
1856 const char *section
,
1857 unsigned section_line
,
1875 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
1877 r
= extract_first_word(&p
, &word
, NULL
, 0);
1883 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Trailing garbage in sockets, ignoring: %s", rvalue
);
1887 r
= unit_name_printf(UNIT(s
), word
, &k
);
1889 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
1893 if (!endswith(k
, ".socket")) {
1894 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit must be of type socket, ignoring: %s", k
);
1898 r
= unit_add_two_dependencies_by_name(UNIT(s
), UNIT_WANTS
, UNIT_AFTER
, k
, true, UNIT_DEPENDENCY_FILE
);
1900 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
1902 r
= unit_add_dependency_by_name(UNIT(s
), UNIT_TRIGGERED_BY
, k
, true, UNIT_DEPENDENCY_FILE
);
1904 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
1910 int config_parse_bus_name(
1912 const char *filename
,
1914 const char *section
,
1915 unsigned section_line
,
1922 _cleanup_free_
char *k
= NULL
;
1923 const Unit
*u
= userdata
;
1931 r
= unit_full_printf(u
, rvalue
, &k
);
1933 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
1937 if (!service_name_is_valid(k
)) {
1938 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid bus name, ignoring: %s", k
);
1942 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
1945 int config_parse_service_timeout(
1947 const char *filename
,
1949 const char *section
,
1950 unsigned section_line
,
1957 Service
*s
= userdata
;
1966 /* This is called for two cases: TimeoutSec= and TimeoutStartSec=. */
1968 /* Traditionally, these options accepted 0 to disable the timeouts. However, a timeout of 0 suggests it happens
1969 * immediately, hence fix this to become USEC_INFINITY instead. This is in-line with how we internally handle
1970 * all other timeouts. */
1971 r
= parse_sec_fix_0(rvalue
, &usec
);
1973 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
1977 s
->start_timeout_defined
= true;
1978 s
->timeout_start_usec
= usec
;
1980 if (streq(lvalue
, "TimeoutSec"))
1981 s
->timeout_stop_usec
= usec
;
1986 int config_parse_timeout_abort(
1988 const char *filename
,
1990 const char *section
,
1991 unsigned section_line
,
2006 /* Note: apart from setting the arg, this returns an extra bit of information in the return value. */
2008 if (isempty(rvalue
)) {
2010 return 0; /* "not set" */
2013 r
= parse_sec(rvalue
, ret
);
2015 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= setting, ignoring: %s", lvalue
, rvalue
);
2017 return 1; /* "set" */
2020 int config_parse_service_timeout_abort(
2022 const char *filename
,
2024 const char *section
,
2025 unsigned section_line
,
2032 Service
*s
= userdata
;
2037 r
= config_parse_timeout_abort(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
,
2038 &s
->timeout_abort_usec
, s
);
2040 s
->timeout_abort_set
= r
;
2044 int config_parse_sec_fix_0(
2046 const char *filename
,
2048 const char *section
,
2049 unsigned section_line
,
2056 usec_t
*usec
= data
;
2064 /* This is pretty much like config_parse_sec(), except that this treats a time of 0 as infinity, for
2065 * compatibility with older versions of systemd where 0 instead of infinity was used as indicator to turn off a
2068 r
= parse_sec_fix_0(rvalue
, usec
);
2070 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
2077 int config_parse_user_group_compat(
2079 const char *filename
,
2081 const char *section
,
2082 unsigned section_line
,
2089 _cleanup_free_
char *k
= NULL
;
2091 const Unit
*u
= userdata
;
2099 if (isempty(rvalue
)) {
2100 *user
= mfree(*user
);
2104 r
= unit_full_printf(u
, rvalue
, &k
);
2106 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", rvalue
);
2110 if (!valid_user_group_name(k
, VALID_USER_ALLOW_NUMERIC
|VALID_USER_RELAX
|VALID_USER_WARN
)) {
2111 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2115 return free_and_replace(*user
, k
);
2118 int config_parse_user_group_strv_compat(
2120 const char *filename
,
2122 const char *section
,
2123 unsigned section_line
,
2130 char ***users
= data
;
2131 const Unit
*u
= userdata
;
2132 const char *p
= rvalue
;
2140 if (isempty(rvalue
)) {
2141 *users
= strv_free(*users
);
2146 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2148 r
= extract_first_word(&p
, &word
, NULL
, 0);
2154 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax: %s", rvalue
);
2158 r
= unit_full_printf(u
, word
, &k
);
2160 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", word
);
2164 if (!valid_user_group_name(k
, VALID_USER_ALLOW_NUMERIC
|VALID_USER_RELAX
|VALID_USER_WARN
)) {
2165 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2169 r
= strv_push(users
, k
);
2179 int config_parse_working_directory(
2181 const char *filename
,
2183 const char *section
,
2184 unsigned section_line
,
2191 ExecContext
*c
= data
;
2192 const Unit
*u
= userdata
;
2202 if (isempty(rvalue
)) {
2203 c
->working_directory_home
= false;
2204 c
->working_directory
= mfree(c
->working_directory
);
2208 if (rvalue
[0] == '-') {
2214 if (streq(rvalue
, "~")) {
2215 c
->working_directory_home
= true;
2216 c
->working_directory
= mfree(c
->working_directory
);
2218 _cleanup_free_
char *k
= NULL
;
2220 r
= unit_full_printf(u
, rvalue
, &k
);
2222 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2223 "Failed to resolve unit specifiers in working directory path '%s'%s: %m",
2224 rvalue
, missing_ok
? ", ignoring" : "");
2225 return missing_ok
? 0 : -ENOEXEC
;
2228 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
| (missing_ok
? 0 : PATH_CHECK_FATAL
), unit
, filename
, line
, lvalue
);
2230 return missing_ok
? 0 : -ENOEXEC
;
2232 c
->working_directory_home
= false;
2233 free_and_replace(c
->working_directory
, k
);
2236 c
->working_directory_missing_ok
= missing_ok
;
2240 int config_parse_unit_env_file(const char *unit
,
2241 const char *filename
,
2243 const char *section
,
2244 unsigned section_line
,
2252 const Unit
*u
= userdata
;
2253 _cleanup_free_
char *n
= NULL
;
2261 if (isempty(rvalue
)) {
2262 /* Empty assignment frees the list */
2263 *env
= strv_free(*env
);
2267 r
= unit_full_printf(u
, rvalue
, &n
);
2269 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2273 r
= path_simplify_and_warn(n
[0] == '-' ? n
+ 1 : n
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2277 r
= strv_push(env
, n
);
2286 int config_parse_environ(
2288 const char *filename
,
2290 const char *section
,
2291 unsigned section_line
,
2298 const Unit
*u
= userdata
;
2308 if (isempty(rvalue
)) {
2309 /* Empty assignment resets the list */
2310 *env
= strv_free(*env
);
2314 for (p
= rvalue
;; ) {
2315 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2317 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2323 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2324 "Invalid syntax, ignoring: %s", rvalue
);
2329 r
= unit_full_printf(u
, word
, &k
);
2331 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2332 "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2338 if (!env_assignment_is_valid(k
)) {
2339 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2340 "Invalid environment assignment, ignoring: %s", k
);
2344 r
= strv_env_replace(env
, k
);
2352 int config_parse_pass_environ(
2354 const char *filename
,
2356 const char *section
,
2357 unsigned section_line
,
2364 _cleanup_strv_free_
char **n
= NULL
;
2365 size_t nlen
= 0, nbufsize
= 0;
2366 char*** passenv
= data
;
2367 const char *p
= rvalue
;
2368 const Unit
*u
= userdata
;
2376 if (isempty(rvalue
)) {
2377 /* Empty assignment resets the list */
2378 *passenv
= strv_free(*passenv
);
2383 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2385 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
2391 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2392 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2397 r
= unit_full_printf(u
, word
, &k
);
2399 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2400 "Failed to resolve specifiers in %s, ignoring: %m", word
);
2406 if (!env_name_is_valid(k
)) {
2407 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2408 "Invalid environment name for %s, ignoring: %s", lvalue
, k
);
2412 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
2415 n
[nlen
++] = TAKE_PTR(k
);
2420 r
= strv_extend_strv(passenv
, n
, true);
2428 int config_parse_unset_environ(
2430 const char *filename
,
2432 const char *section
,
2433 unsigned section_line
,
2440 _cleanup_strv_free_
char **n
= NULL
;
2441 size_t nlen
= 0, nbufsize
= 0;
2442 char*** unsetenv
= data
;
2443 const char *p
= rvalue
;
2444 const Unit
*u
= userdata
;
2452 if (isempty(rvalue
)) {
2453 /* Empty assignment resets the list */
2454 *unsetenv
= strv_free(*unsetenv
);
2459 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2461 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2467 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2468 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2473 r
= unit_full_printf(u
, word
, &k
);
2475 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2476 "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2482 if (!env_assignment_is_valid(k
) && !env_name_is_valid(k
)) {
2483 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2484 "Invalid environment name or assignment %s, ignoring: %s", lvalue
, k
);
2488 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
2491 n
[nlen
++] = TAKE_PTR(k
);
2496 r
= strv_extend_strv(unsetenv
, n
, true);
2504 int config_parse_log_extra_fields(
2506 const char *filename
,
2508 const char *section
,
2509 unsigned section_line
,
2516 ExecContext
*c
= data
;
2517 const Unit
*u
= userdata
;
2518 const char *p
= rvalue
;
2526 if (isempty(rvalue
)) {
2527 exec_context_free_log_extra_fields(c
);
2532 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2536 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2542 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
2546 r
= unit_full_printf(u
, word
, &k
);
2548 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2552 eq
= strchr(k
, '=');
2554 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Log field lacks '=' character, ignoring: %s", k
);
2558 if (!journal_field_valid(k
, eq
-k
, false)) {
2559 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Log field name is invalid, ignoring: %s", k
);
2563 t
= reallocarray(c
->log_extra_fields
, c
->n_log_extra_fields
+1, sizeof(struct iovec
));
2567 c
->log_extra_fields
= t
;
2568 c
->log_extra_fields
[c
->n_log_extra_fields
++] = IOVEC_MAKE_STRING(k
);
2574 int config_parse_log_namespace(
2576 const char *filename
,
2578 const char *section
,
2579 unsigned section_line
,
2586 _cleanup_free_
char *k
= NULL
;
2587 ExecContext
*c
= data
;
2588 const Unit
*u
= userdata
;
2596 if (isempty(rvalue
)) {
2597 c
->log_namespace
= mfree(c
->log_namespace
);
2601 r
= unit_full_printf(u
, rvalue
, &k
);
2603 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2607 if (!log_namespace_name_valid(k
)) {
2608 log_syntax(unit
, LOG_ERR
, filename
, line
, SYNTHETIC_ERRNO(EINVAL
), "Specified log namespace name is not valid: %s", k
);
2612 free_and_replace(c
->log_namespace
, k
);
2616 int config_parse_unit_condition_path(
2618 const char *filename
,
2620 const char *section
,
2621 unsigned section_line
,
2628 _cleanup_free_
char *p
= NULL
;
2629 Condition
**list
= data
, *c
;
2630 ConditionType t
= ltype
;
2631 bool trigger
, negate
;
2632 const Unit
*u
= userdata
;
2640 if (isempty(rvalue
)) {
2641 /* Empty assignment resets the list */
2642 *list
= condition_free_list(*list
);
2646 trigger
= rvalue
[0] == '|';
2650 negate
= rvalue
[0] == '!';
2654 r
= unit_full_printf(u
, rvalue
, &p
);
2656 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2660 r
= path_simplify_and_warn(p
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2664 c
= condition_new(t
, p
, trigger
, negate
);
2668 LIST_PREPEND(conditions
, *list
, c
);
2672 int config_parse_unit_condition_string(
2674 const char *filename
,
2676 const char *section
,
2677 unsigned section_line
,
2684 _cleanup_free_
char *s
= NULL
;
2685 Condition
**list
= data
, *c
;
2686 ConditionType t
= ltype
;
2687 bool trigger
, negate
;
2688 const Unit
*u
= userdata
;
2696 if (isempty(rvalue
)) {
2697 /* Empty assignment resets the list */
2698 *list
= condition_free_list(*list
);
2702 trigger
= *rvalue
== '|';
2704 rvalue
+= 1 + strspn(rvalue
+ 1, WHITESPACE
);
2706 negate
= *rvalue
== '!';
2708 rvalue
+= 1 + strspn(rvalue
+ 1, WHITESPACE
);
2710 r
= unit_full_printf(u
, rvalue
, &s
);
2712 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2713 "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2717 c
= condition_new(t
, s
, trigger
, negate
);
2721 LIST_PREPEND(conditions
, *list
, c
);
2725 int config_parse_unit_condition_null(
2727 const char *filename
,
2729 const char *section
,
2730 unsigned section_line
,
2737 Condition
**list
= data
, *c
;
2738 bool trigger
, negate
;
2746 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "%s= is deprecated, please do not use.", lvalue
);
2748 if (isempty(rvalue
)) {
2749 /* Empty assignment resets the list */
2750 *list
= condition_free_list(*list
);
2754 trigger
= rvalue
[0] == '|';
2758 negate
= rvalue
[0] == '!';
2762 b
= parse_boolean(rvalue
);
2764 log_syntax(unit
, LOG_ERR
, filename
, line
, b
, "Failed to parse boolean value in condition, ignoring: %s", rvalue
);
2771 c
= condition_new(CONDITION_NULL
, NULL
, trigger
, negate
);
2775 LIST_PREPEND(conditions
, *list
, c
);
2779 int config_parse_unit_requires_mounts_for(
2781 const char *filename
,
2783 const char *section
,
2784 unsigned section_line
,
2791 const char *p
= rvalue
;
2801 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
2803 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
2809 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2810 "Invalid syntax, ignoring: %s", rvalue
);
2814 r
= unit_full_printf(u
, word
, &resolved
);
2816 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
2820 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2824 r
= unit_require_mounts_for(u
, resolved
, UNIT_DEPENDENCY_FILE
);
2826 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add required mount '%s', ignoring: %m", resolved
);
2832 int config_parse_documentation(const char *unit
,
2833 const char *filename
,
2835 const char *section
,
2836 unsigned section_line
,
2852 if (isempty(rvalue
)) {
2853 /* Empty assignment resets the list */
2854 u
->documentation
= strv_free(u
->documentation
);
2858 r
= config_parse_unit_strv_printf(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
,
2859 rvalue
, data
, userdata
);
2863 for (a
= b
= u
->documentation
; a
&& *a
; a
++) {
2865 if (documentation_url_is_valid(*a
))
2868 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid URL, ignoring: %s", *a
);
2879 int config_parse_syscall_filter(
2881 const char *filename
,
2883 const char *section
,
2884 unsigned section_line
,
2891 ExecContext
*c
= data
;
2892 const Unit
*u
= userdata
;
2893 bool invert
= false;
2902 if (isempty(rvalue
)) {
2903 /* Empty assignment resets the list */
2904 c
->syscall_filter
= hashmap_free(c
->syscall_filter
);
2905 c
->syscall_whitelist
= false;
2909 if (rvalue
[0] == '~') {
2914 if (!c
->syscall_filter
) {
2915 c
->syscall_filter
= hashmap_new(NULL
);
2916 if (!c
->syscall_filter
)
2920 /* Allow everything but the ones listed */
2921 c
->syscall_whitelist
= false;
2923 /* Allow nothing but the ones listed */
2924 c
->syscall_whitelist
= true;
2926 /* Accept default syscalls if we are on a whitelist */
2927 r
= seccomp_parse_syscall_filter(
2928 "@default", -1, c
->syscall_filter
,
2929 SECCOMP_PARSE_PERMISSIVE
|SECCOMP_PARSE_WHITELIST
,
2939 _cleanup_free_
char *word
= NULL
, *name
= NULL
;
2942 r
= extract_first_word(&p
, &word
, NULL
, 0);
2948 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
2952 r
= parse_syscall_and_errno(word
, &name
, &num
);
2954 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse syscall:errno, ignoring: %s", word
);
2958 r
= seccomp_parse_syscall_filter(
2959 name
, num
, c
->syscall_filter
,
2960 SECCOMP_PARSE_LOG
|SECCOMP_PARSE_PERMISSIVE
|
2961 (invert
? SECCOMP_PARSE_INVERT
: 0)|
2962 (c
->syscall_whitelist
? SECCOMP_PARSE_WHITELIST
: 0),
2963 unit
, filename
, line
);
2969 int config_parse_syscall_archs(
2971 const char *filename
,
2973 const char *section
,
2974 unsigned section_line
,
2981 const char *p
= rvalue
;
2985 if (isempty(rvalue
)) {
2986 *archs
= set_free(*archs
);
2990 r
= set_ensure_allocated(archs
, NULL
);
2995 _cleanup_free_
char *word
= NULL
;
2998 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3004 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3005 "Invalid syntax, ignoring: %s", rvalue
);
3009 r
= seccomp_arch_from_string(word
, &a
);
3011 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
3012 "Failed to parse system call architecture \"%s\", ignoring: %m", word
);
3016 r
= set_put(*archs
, UINT32_TO_PTR(a
+ 1));
3022 int config_parse_syscall_errno(
3024 const char *filename
,
3026 const char *section
,
3027 unsigned section_line
,
3034 ExecContext
*c
= data
;
3041 if (isempty(rvalue
)) {
3042 /* Empty assignment resets to KILL */
3043 c
->syscall_errno
= 0;
3047 e
= parse_errno(rvalue
);
3049 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse error number, ignoring: %s", rvalue
);
3053 c
->syscall_errno
= e
;
3057 int config_parse_address_families(
3059 const char *filename
,
3061 const char *section
,
3062 unsigned section_line
,
3069 ExecContext
*c
= data
;
3070 bool invert
= false;
3078 if (isempty(rvalue
)) {
3079 /* Empty assignment resets the list */
3080 c
->address_families
= set_free(c
->address_families
);
3081 c
->address_families_whitelist
= false;
3085 if (rvalue
[0] == '~') {
3090 if (!c
->address_families
) {
3091 c
->address_families
= set_new(NULL
);
3092 if (!c
->address_families
)
3095 c
->address_families_whitelist
= !invert
;
3098 for (p
= rvalue
;;) {
3099 _cleanup_free_
char *word
= NULL
;
3102 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3108 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3109 "Invalid syntax, ignoring: %s", rvalue
);
3113 af
= af_from_name(word
);
3115 log_syntax(unit
, LOG_ERR
, filename
, line
, af
,
3116 "Failed to parse address family, ignoring: %s", word
);
3120 /* If we previously wanted to forbid an address family and now
3121 * we want to allow it, then just remove it from the list.
3123 if (!invert
== c
->address_families_whitelist
) {
3124 r
= set_put(c
->address_families
, INT_TO_PTR(af
));
3128 set_remove(c
->address_families
, INT_TO_PTR(af
));
3132 int config_parse_restrict_namespaces(
3134 const char *filename
,
3136 const char *section
,
3137 unsigned section_line
,
3144 ExecContext
*c
= data
;
3145 unsigned long flags
;
3146 bool invert
= false;
3149 if (isempty(rvalue
)) {
3150 /* Reset to the default. */
3151 c
->restrict_namespaces
= NAMESPACE_FLAGS_INITIAL
;
3155 /* Boolean parameter ignores the previous settings */
3156 r
= parse_boolean(rvalue
);
3158 c
->restrict_namespaces
= 0;
3160 } else if (r
== 0) {
3161 c
->restrict_namespaces
= NAMESPACE_FLAGS_ALL
;
3165 if (rvalue
[0] == '~') {
3170 /* Not a boolean argument, in this case it's a list of namespace types. */
3171 r
= namespace_flags_from_string(rvalue
, &flags
);
3173 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse namespace type string, ignoring: %s", rvalue
);
3177 if (c
->restrict_namespaces
== NAMESPACE_FLAGS_INITIAL
)
3178 /* Initial assignment. Just set the value. */
3179 c
->restrict_namespaces
= invert
? (~flags
) & NAMESPACE_FLAGS_ALL
: flags
;
3181 /* Merge the value with the previous one. */
3182 SET_FLAG(c
->restrict_namespaces
, flags
, !invert
);
3188 int config_parse_unit_slice(
3190 const char *filename
,
3192 const char *section
,
3193 unsigned section_line
,
3200 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
3201 _cleanup_free_
char *k
= NULL
;
3202 Unit
*u
= userdata
, *slice
;
3210 r
= unit_name_printf(u
, rvalue
, &k
);
3212 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
3216 r
= manager_load_unit(u
->manager
, k
, NULL
, &error
, &slice
);
3218 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to load slice unit %s, ignoring: %s", k
, bus_error_message(&error
, r
));
3222 r
= unit_set_slice(u
, slice
);
3224 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to assign slice %s to unit %s, ignoring: %m", slice
->id
, u
->id
);
3231 int config_parse_cpu_quota(
3233 const char *filename
,
3235 const char *section
,
3236 unsigned section_line
,
3243 CGroupContext
*c
= data
;
3250 if (isempty(rvalue
)) {
3251 c
->cpu_quota_per_sec_usec
= USEC_INFINITY
;
3255 r
= parse_permille_unbounded(rvalue
);
3257 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid CPU quota '%s', ignoring.", rvalue
);
3261 c
->cpu_quota_per_sec_usec
= ((usec_t
) r
* USEC_PER_SEC
) / 1000U;
3265 int config_parse_allowed_cpus(
3267 const char *filename
,
3269 const char *section
,
3270 unsigned section_line
,
3277 CGroupContext
*c
= data
;
3279 (void) parse_cpu_set_extend(rvalue
, &c
->cpuset_cpus
, true, unit
, filename
, line
, lvalue
);
3284 int config_parse_allowed_mems(
3286 const char *filename
,
3288 const char *section
,
3289 unsigned section_line
,
3296 CGroupContext
*c
= data
;
3298 (void) parse_cpu_set_extend(rvalue
, &c
->cpuset_mems
, true, unit
, filename
, line
, lvalue
);
3303 int config_parse_memory_limit(
3305 const char *filename
,
3307 const char *section
,
3308 unsigned section_line
,
3315 CGroupContext
*c
= data
;
3316 uint64_t bytes
= CGROUP_LIMIT_MAX
;
3319 if (!isempty(rvalue
) && !streq(rvalue
, "infinity")) {
3321 r
= parse_permille(rvalue
);
3323 r
= parse_size(rvalue
, 1024, &bytes
);
3325 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid memory limit '%s', ignoring: %m", rvalue
);
3329 bytes
= physical_memory_scale(r
, 1000U);
3331 if (bytes
>= UINT64_MAX
||
3332 (bytes
<= 0 && !STR_IN_SET(lvalue
, "MemorySwapMax", "MemoryLow", "MemoryMin", "DefaultMemoryLow", "DefaultMemoryMin"))) {
3333 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Memory limit '%s' out of range, ignoring.", rvalue
);
3338 if (streq(lvalue
, "DefaultMemoryLow")) {
3339 c
->default_memory_low_set
= true;
3340 if (isempty(rvalue
))
3341 c
->default_memory_low
= CGROUP_LIMIT_MIN
;
3343 c
->default_memory_low
= bytes
;
3344 } else if (streq(lvalue
, "DefaultMemoryMin")) {
3345 c
->default_memory_min_set
= true;
3346 if (isempty(rvalue
))
3347 c
->default_memory_min
= CGROUP_LIMIT_MIN
;
3349 c
->default_memory_min
= bytes
;
3350 } else if (streq(lvalue
, "MemoryMin")) {
3351 c
->memory_min
= bytes
;
3352 c
->memory_min_set
= true;
3353 } else if (streq(lvalue
, "MemoryLow")) {
3354 c
->memory_low
= bytes
;
3355 c
->memory_low_set
= true;
3356 } else if (streq(lvalue
, "MemoryHigh"))
3357 c
->memory_high
= bytes
;
3358 else if (streq(lvalue
, "MemoryMax"))
3359 c
->memory_max
= bytes
;
3360 else if (streq(lvalue
, "MemorySwapMax"))
3361 c
->memory_swap_max
= bytes
;
3362 else if (streq(lvalue
, "MemoryLimit"))
3363 c
->memory_limit
= bytes
;
3370 int config_parse_tasks_max(
3372 const char *filename
,
3374 const char *section
,
3375 unsigned section_line
,
3382 const Unit
*u
= userdata
;
3383 TasksMax
*tasks_max
= data
;
3387 if (isempty(rvalue
)) {
3388 *tasks_max
= u
? u
->manager
->default_tasks_max
: TASKS_MAX_UNSET
;
3392 if (streq(rvalue
, "infinity")) {
3393 *tasks_max
= TASKS_MAX_UNSET
;
3397 r
= parse_permille(rvalue
);
3399 *tasks_max
= (TasksMax
) { r
, 1000U }; /* r‰ */
3401 r
= safe_atou64(rvalue
, &v
);
3403 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid maximum tasks value '%s', ignoring: %m", rvalue
);
3407 if (v
<= 0 || v
>= UINT64_MAX
) {
3408 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Maximum tasks value '%s' out of range, ignoring.", rvalue
);
3412 *tasks_max
= (TasksMax
) { v
};
3418 int config_parse_delegate(
3420 const char *filename
,
3422 const char *section
,
3423 unsigned section_line
,
3430 CGroupContext
*c
= data
;
3434 t
= unit_name_to_type(unit
);
3435 assert(t
!= _UNIT_TYPE_INVALID
);
3437 if (!unit_vtable
[t
]->can_delegate
) {
3438 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Delegate= setting not supported for this unit type, ignoring.");
3442 /* We either accept a boolean value, which may be used to turn on delegation for all controllers, or turn it
3443 * off for all. Or it takes a list of controller names, in which case we add the specified controllers to the
3444 * mask to delegate. */
3446 if (isempty(rvalue
)) {
3447 /* An empty string resets controllers and set Delegate=yes. */
3449 c
->delegate_controllers
= 0;
3453 r
= parse_boolean(rvalue
);
3455 const char *p
= rvalue
;
3456 CGroupMask mask
= 0;
3459 _cleanup_free_
char *word
= NULL
;
3460 CGroupController cc
;
3462 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3468 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3472 cc
= cgroup_controller_from_string(word
);
3474 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid controller name '%s', ignoring", word
);
3478 mask
|= CGROUP_CONTROLLER_TO_MASK(cc
);
3482 c
->delegate_controllers
|= mask
;
3486 c
->delegate_controllers
= _CGROUP_MASK_ALL
;
3488 c
->delegate
= false;
3489 c
->delegate_controllers
= 0;
3495 int config_parse_device_allow(
3497 const char *filename
,
3499 const char *section
,
3500 unsigned section_line
,
3507 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3508 CGroupContext
*c
= data
;
3509 const char *p
= rvalue
;
3512 if (isempty(rvalue
)) {
3513 while (c
->device_allow
)
3514 cgroup_context_free_device_allow(c
, c
->device_allow
);
3519 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3523 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3524 "Invalid syntax, ignoring: %s", rvalue
);
3528 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3529 "Failed to extract device path and rights from '%s', ignoring.", rvalue
);
3533 r
= unit_full_printf(userdata
, path
, &resolved
);
3535 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3536 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3540 if (!STARTSWITH_SET(resolved
, "block-", "char-")) {
3542 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3546 if (!valid_device_node_path(resolved
)) {
3547 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device node path '%s', ignoring.", resolved
);
3552 if (!isempty(p
) && !in_charset(p
, "rwm")) {
3553 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device rights '%s', ignoring.", p
);
3557 return cgroup_add_device_allow(c
, resolved
, p
);
3560 int config_parse_io_device_weight(
3562 const char *filename
,
3564 const char *section
,
3565 unsigned section_line
,
3572 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3573 CGroupIODeviceWeight
*w
;
3574 CGroupContext
*c
= data
;
3575 const char *p
= rvalue
;
3583 if (isempty(rvalue
)) {
3584 while (c
->io_device_weights
)
3585 cgroup_context_free_io_device_weight(c
, c
->io_device_weights
);
3590 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3594 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3595 "Invalid syntax, ignoring: %s", rvalue
);
3598 if (r
== 0 || isempty(p
)) {
3599 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3600 "Failed to extract device path and weight from '%s', ignoring.", rvalue
);
3604 r
= unit_full_printf(userdata
, path
, &resolved
);
3606 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3607 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3611 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3615 r
= cg_weight_parse(p
, &u
);
3617 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "IO weight '%s' invalid, ignoring: %m", p
);
3621 assert(u
!= CGROUP_WEIGHT_INVALID
);
3623 w
= new0(CGroupIODeviceWeight
, 1);
3627 w
->path
= TAKE_PTR(resolved
);
3630 LIST_PREPEND(device_weights
, c
->io_device_weights
, w
);
3634 int config_parse_io_device_latency(
3636 const char *filename
,
3638 const char *section
,
3639 unsigned section_line
,
3646 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3647 CGroupIODeviceLatency
*l
;
3648 CGroupContext
*c
= data
;
3649 const char *p
= rvalue
;
3657 if (isempty(rvalue
)) {
3658 while (c
->io_device_latencies
)
3659 cgroup_context_free_io_device_latency(c
, c
->io_device_latencies
);
3664 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3668 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3669 "Invalid syntax, ignoring: %s", rvalue
);
3672 if (r
== 0 || isempty(p
)) {
3673 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3674 "Failed to extract device path and latency from '%s', ignoring.", rvalue
);
3678 r
= unit_full_printf(userdata
, path
, &resolved
);
3680 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3681 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3685 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3689 if (parse_sec(p
, &usec
) < 0) {
3690 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse timer value, ignoring: %s", p
);
3694 l
= new0(CGroupIODeviceLatency
, 1);
3698 l
->path
= TAKE_PTR(resolved
);
3699 l
->target_usec
= usec
;
3701 LIST_PREPEND(device_latencies
, c
->io_device_latencies
, l
);
3705 int config_parse_io_limit(
3707 const char *filename
,
3709 const char *section
,
3710 unsigned section_line
,
3717 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3718 CGroupIODeviceLimit
*l
= NULL
, *t
;
3719 CGroupContext
*c
= data
;
3720 CGroupIOLimitType type
;
3721 const char *p
= rvalue
;
3729 type
= cgroup_io_limit_type_from_string(lvalue
);
3732 if (isempty(rvalue
)) {
3733 LIST_FOREACH(device_limits
, l
, c
->io_device_limits
)
3734 l
->limits
[type
] = cgroup_io_limit_defaults
[type
];
3738 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3742 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3743 "Invalid syntax, ignoring: %s", rvalue
);
3746 if (r
== 0 || isempty(p
)) {
3747 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3748 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
3752 r
= unit_full_printf(userdata
, path
, &resolved
);
3754 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3755 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3759 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3763 if (streq("infinity", p
))
3764 num
= CGROUP_LIMIT_MAX
;
3766 r
= parse_size(p
, 1000, &num
);
3767 if (r
< 0 || num
<= 0) {
3768 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid IO limit '%s', ignoring.", p
);
3773 LIST_FOREACH(device_limits
, t
, c
->io_device_limits
) {
3774 if (path_equal(resolved
, t
->path
)) {
3781 CGroupIOLimitType ttype
;
3783 l
= new0(CGroupIODeviceLimit
, 1);
3787 l
->path
= TAKE_PTR(resolved
);
3788 for (ttype
= 0; ttype
< _CGROUP_IO_LIMIT_TYPE_MAX
; ttype
++)
3789 l
->limits
[ttype
] = cgroup_io_limit_defaults
[ttype
];
3791 LIST_PREPEND(device_limits
, c
->io_device_limits
, l
);
3794 l
->limits
[type
] = num
;
3799 int config_parse_blockio_device_weight(
3801 const char *filename
,
3803 const char *section
,
3804 unsigned section_line
,
3811 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3812 CGroupBlockIODeviceWeight
*w
;
3813 CGroupContext
*c
= data
;
3814 const char *p
= rvalue
;
3822 if (isempty(rvalue
)) {
3823 while (c
->blockio_device_weights
)
3824 cgroup_context_free_blockio_device_weight(c
, c
->blockio_device_weights
);
3829 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3833 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3834 "Invalid syntax, ignoring: %s", rvalue
);
3837 if (r
== 0 || isempty(p
)) {
3838 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3839 "Failed to extract device node and weight from '%s', ignoring.", rvalue
);
3843 r
= unit_full_printf(userdata
, path
, &resolved
);
3845 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3846 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3850 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3854 r
= cg_blkio_weight_parse(p
, &u
);
3856 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid block IO weight '%s', ignoring: %m", p
);
3860 assert(u
!= CGROUP_BLKIO_WEIGHT_INVALID
);
3862 w
= new0(CGroupBlockIODeviceWeight
, 1);
3866 w
->path
= TAKE_PTR(resolved
);
3869 LIST_PREPEND(device_weights
, c
->blockio_device_weights
, w
);
3873 int config_parse_blockio_bandwidth(
3875 const char *filename
,
3877 const char *section
,
3878 unsigned section_line
,
3885 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3886 CGroupBlockIODeviceBandwidth
*b
= NULL
, *t
;
3887 CGroupContext
*c
= data
;
3888 const char *p
= rvalue
;
3897 read
= streq("BlockIOReadBandwidth", lvalue
);
3899 if (isempty(rvalue
)) {
3900 LIST_FOREACH(device_bandwidths
, b
, c
->blockio_device_bandwidths
) {
3901 b
->rbps
= CGROUP_LIMIT_MAX
;
3902 b
->wbps
= CGROUP_LIMIT_MAX
;
3907 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3911 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3912 "Invalid syntax, ignoring: %s", rvalue
);
3915 if (r
== 0 || isempty(p
)) {
3916 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3917 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
3921 r
= unit_full_printf(userdata
, path
, &resolved
);
3923 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3924 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3928 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3932 r
= parse_size(p
, 1000, &bytes
);
3933 if (r
< 0 || bytes
<= 0) {
3934 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid Block IO Bandwidth '%s', ignoring.", p
);
3938 LIST_FOREACH(device_bandwidths
, t
, c
->blockio_device_bandwidths
) {
3939 if (path_equal(resolved
, t
->path
)) {
3946 b
= new0(CGroupBlockIODeviceBandwidth
, 1);
3950 b
->path
= TAKE_PTR(resolved
);
3951 b
->rbps
= CGROUP_LIMIT_MAX
;
3952 b
->wbps
= CGROUP_LIMIT_MAX
;
3954 LIST_PREPEND(device_bandwidths
, c
->blockio_device_bandwidths
, b
);
3965 int config_parse_job_mode_isolate(
3967 const char *filename
,
3969 const char *section
,
3970 unsigned section_line
,
3984 r
= parse_boolean(rvalue
);
3986 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse boolean, ignoring: %s", rvalue
);
3990 log_notice("%s is deprecated. Please use OnFailureJobMode= instead", lvalue
);
3992 *m
= r
? JOB_ISOLATE
: JOB_REPLACE
;
3996 int config_parse_exec_directories(
3998 const char *filename
,
4000 const char *section
,
4001 unsigned section_line
,
4009 const Unit
*u
= userdata
;
4018 if (isempty(rvalue
)) {
4019 /* Empty assignment resets the list */
4020 *rt
= strv_free(*rt
);
4024 for (p
= rvalue
;;) {
4025 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
4027 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
4031 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4032 "Invalid syntax, ignoring: %s", rvalue
);
4038 r
= unit_full_printf(u
, word
, &k
);
4040 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4041 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
4045 r
= path_simplify_and_warn(k
, PATH_CHECK_RELATIVE
, unit
, filename
, line
, lvalue
);
4049 if (path_startswith(k
, "private")) {
4050 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
4051 "%s= path can't be 'private', ignoring assignment: %s", lvalue
, word
);
4055 r
= strv_push(rt
, k
);
4062 int config_parse_set_status(
4064 const char *filename
,
4066 const char *section
,
4067 unsigned section_line
,
4075 const char *word
, *state
;
4077 ExitStatusSet
*status_set
= data
;
4084 /* Empty assignment resets the list */
4085 if (isempty(rvalue
)) {
4086 exit_status_set_free(status_set
);
4090 FOREACH_WORD(word
, l
, rvalue
, state
) {
4091 _cleanup_free_
char *temp
;
4094 temp
= strndup(word
, l
);
4098 /* We need to call exit_status_from_string() first, because we want
4099 * to parse numbers as exit statuses, not signals. */
4101 r
= exit_status_from_string(temp
);
4103 assert(r
>= 0 && r
< 256);
4104 bitmap
= &status_set
->status
;
4106 r
= signal_from_string(temp
);
4109 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
4110 "Failed to parse value, ignoring: %s", word
);
4113 bitmap
= &status_set
->signal
;
4116 r
= bitmap_set(bitmap
, r
);
4118 return log_error_errno(r
, "Failed to set signal or status %s: %m", word
);
4120 if (!isempty(state
))
4121 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Trailing garbage, ignoring.");
4126 int config_parse_namespace_path_strv(
4128 const char *filename
,
4130 const char *section
,
4131 unsigned section_line
,
4138 const Unit
*u
= userdata
;
4140 const char *p
= rvalue
;
4148 if (isempty(rvalue
)) {
4149 /* Empty assignment resets the list */
4150 *sv
= strv_free(*sv
);
4155 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
, *joined
= NULL
;
4157 bool ignore_enoent
= false, shall_prefix
= false;
4159 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
4165 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
4170 if (startswith(w
, "-")) {
4171 ignore_enoent
= true;
4174 if (startswith(w
, "+")) {
4175 shall_prefix
= true;
4179 r
= unit_full_printf(u
, w
, &resolved
);
4181 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", w
);
4185 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4189 joined
= strjoin(ignore_enoent
? "-" : "",
4190 shall_prefix
? "+" : "",
4193 r
= strv_push(sv
, joined
);
4203 int config_parse_temporary_filesystems(
4205 const char *filename
,
4207 const char *section
,
4208 unsigned section_line
,
4215 const Unit
*u
= userdata
;
4216 ExecContext
*c
= data
;
4217 const char *p
= rvalue
;
4225 if (isempty(rvalue
)) {
4226 /* Empty assignment resets the list */
4227 temporary_filesystem_free_many(c
->temporary_filesystems
, c
->n_temporary_filesystems
);
4228 c
->temporary_filesystems
= NULL
;
4229 c
->n_temporary_filesystems
= 0;
4234 _cleanup_free_
char *word
= NULL
, *path
= NULL
, *resolved
= NULL
;
4237 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
4243 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
4248 r
= extract_first_word(&w
, &path
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4252 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", word
);
4256 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid syntax, ignoring: %s", word
);
4260 r
= unit_full_printf(u
, path
, &resolved
);
4262 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", path
);
4266 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4270 r
= temporary_filesystem_add(&c
->temporary_filesystems
, &c
->n_temporary_filesystems
, resolved
, w
);
4276 int config_parse_bind_paths(
4278 const char *filename
,
4280 const char *section
,
4281 unsigned section_line
,
4288 ExecContext
*c
= data
;
4289 const Unit
*u
= userdata
;
4298 if (isempty(rvalue
)) {
4299 /* Empty assignment resets the list */
4300 bind_mount_free_many(c
->bind_mounts
, c
->n_bind_mounts
);
4301 c
->bind_mounts
= NULL
;
4302 c
->n_bind_mounts
= 0;
4308 _cleanup_free_
char *source
= NULL
, *destination
= NULL
;
4309 _cleanup_free_
char *sresolved
= NULL
, *dresolved
= NULL
;
4310 char *s
= NULL
, *d
= NULL
;
4311 bool rbind
= true, ignore_enoent
= false;
4313 r
= extract_first_word(&p
, &source
, ":" WHITESPACE
, EXTRACT_UNQUOTE
|EXTRACT_DONT_COALESCE_SEPARATORS
);
4319 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
4323 r
= unit_full_printf(u
, source
, &sresolved
);
4325 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4326 "Failed to resolved unit specifiers in \"%s\", ignoring: %m", source
);
4332 ignore_enoent
= true;
4336 r
= path_simplify_and_warn(s
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4340 /* Optionally, the destination is specified. */
4341 if (p
&& p
[-1] == ':') {
4342 r
= extract_first_word(&p
, &destination
, ":" WHITESPACE
, EXTRACT_UNQUOTE
|EXTRACT_DONT_COALESCE_SEPARATORS
);
4346 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
4350 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Missing argument after ':', ignoring: %s", s
);
4354 r
= unit_full_printf(u
, destination
, &dresolved
);
4356 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4357 "Failed to resolved specifiers in \"%s\", ignoring: %m", destination
);
4361 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4367 /* Optionally, there's also a short option string specified */
4368 if (p
&& p
[-1] == ':') {
4369 _cleanup_free_
char *options
= NULL
;
4371 r
= extract_first_word(&p
, &options
, NULL
, EXTRACT_UNQUOTE
);
4375 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s: %s", lvalue
, rvalue
);
4379 if (isempty(options
) || streq(options
, "rbind"))
4381 else if (streq(options
, "norbind"))
4384 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid option string, ignoring setting: %s", options
);
4391 r
= bind_mount_add(&c
->bind_mounts
, &c
->n_bind_mounts
,
4395 .read_only
= !!strstr(lvalue
, "ReadOnly"),
4397 .ignore_enoent
= ignore_enoent
,
4406 int config_parse_job_timeout_sec(
4408 const char *filename
,
4410 const char *section
,
4411 unsigned section_line
,
4427 r
= parse_sec_fix_0(rvalue
, &usec
);
4429 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse JobTimeoutSec= parameter, ignoring: %s", rvalue
);
4433 /* If the user explicitly changed JobTimeoutSec= also change JobRunningTimeoutSec=, for compatibility with old
4434 * versions. If JobRunningTimeoutSec= was explicitly set, avoid this however as whatever the user picked should
4437 if (!u
->job_running_timeout_set
)
4438 u
->job_running_timeout
= usec
;
4440 u
->job_timeout
= usec
;
4445 int config_parse_job_running_timeout_sec(
4447 const char *filename
,
4449 const char *section
,
4450 unsigned section_line
,
4466 r
= parse_sec_fix_0(rvalue
, &usec
);
4468 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse JobRunningTimeoutSec= parameter, ignoring: %s", rvalue
);
4472 u
->job_running_timeout
= usec
;
4473 u
->job_running_timeout_set
= true;
4478 int config_parse_emergency_action(
4480 const char *filename
,
4482 const char *section
,
4483 unsigned section_line
,
4491 EmergencyAction
*x
= data
;
4500 m
= ((Unit
*) userdata
)->manager
;
4504 r
= parse_emergency_action(rvalue
, MANAGER_IS_SYSTEM(m
), x
);
4506 if (r
== -EOPNOTSUPP
&& MANAGER_IS_USER(m
)) {
4507 /* Compat mode: remove for systemd 241. */
4509 log_syntax(unit
, LOG_INFO
, filename
, line
, r
,
4510 "%s= in user mode specified as \"%s\", using \"exit-force\" instead.",
4512 *x
= EMERGENCY_ACTION_EXIT_FORCE
;
4516 if (r
== -EOPNOTSUPP
)
4517 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4518 "%s= specified as %s mode action, ignoring: %s",
4519 lvalue
, MANAGER_IS_SYSTEM(m
) ? "user" : "system", rvalue
);
4521 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4522 "Failed to parse %s=, ignoring: %s", lvalue
, rvalue
);
4529 int config_parse_pid_file(
4531 const char *filename
,
4533 const char *section
,
4534 unsigned section_line
,
4541 _cleanup_free_
char *k
= NULL
, *n
= NULL
;
4542 const Unit
*u
= userdata
;
4551 if (isempty(rvalue
)) {
4552 /* An empty assignment removes already set value. */
4557 r
= unit_full_printf(u
, rvalue
, &k
);
4559 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
4563 /* If this is a relative path make it absolute by prefixing the /run */
4564 n
= path_make_absolute(k
, u
->manager
->prefix
[EXEC_DIRECTORY_RUNTIME
]);
4568 /* Check that the result is a sensible path */
4569 r
= path_simplify_and_warn(n
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4573 r
= patch_var_run(unit
, filename
, line
, lvalue
, &n
);
4577 free_and_replace(*s
, n
);
4581 int config_parse_exit_status(
4583 const char *filename
,
4585 const char *section
,
4586 unsigned section_line
,
4593 int *exit_status
= data
, r
;
4599 assert(exit_status
);
4601 if (isempty(rvalue
)) {
4606 r
= safe_atou8(rvalue
, &u
);
4608 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse exit status '%s', ignoring: %m", rvalue
);
4616 int config_parse_disable_controllers(
4618 const char *filename
,
4620 const char *section
,
4621 unsigned section_line
,
4629 CGroupContext
*c
= data
;
4630 CGroupMask disabled_mask
;
4632 /* 1. If empty, make all controllers eligible for use again.
4633 * 2. If non-empty, merge all listed controllers, space separated. */
4635 if (isempty(rvalue
)) {
4636 c
->disable_controllers
= 0;
4640 r
= cg_mask_from_string(rvalue
, &disabled_mask
);
4641 if (r
< 0 || disabled_mask
<= 0) {
4642 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid cgroup string: %s, ignoring", rvalue
);
4646 c
->disable_controllers
|= disabled_mask
;
4651 int config_parse_ip_filter_bpf_progs(
4653 const char *filename
,
4655 const char *section
,
4656 unsigned section_line
,
4663 _cleanup_free_
char *resolved
= NULL
;
4664 const Unit
*u
= userdata
;
4665 char ***paths
= data
;
4673 if (isempty(rvalue
)) {
4674 *paths
= strv_free(*paths
);
4678 r
= unit_full_printf(u
, rvalue
, &resolved
);
4680 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
4684 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4688 if (strv_contains(*paths
, resolved
))
4691 r
= strv_extend(paths
, resolved
);
4695 r
= bpf_firewall_supported();
4698 if (r
!= BPF_FIREWALL_SUPPORTED_WITH_MULTI
) {
4699 static bool warned
= false;
4701 log_full(warned
? LOG_DEBUG
: LOG_WARNING
,
4702 "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"
4703 "Starting this unit will fail! (This warning is only shown for the first loaded unit using IP firewalling.)", filename
, line
, lvalue
, rvalue
);
4711 static int merge_by_names(Unit
**u
, Set
*names
, const char *id
) {
4718 /* Let's try to add in all names that are aliases of this unit */
4719 while ((k
= set_steal_first(names
))) {
4720 _cleanup_free_ _unused_
char *free_k
= k
;
4722 /* First try to merge in the other name into our unit */
4723 r
= unit_merge_by_name(*u
, k
);
4727 /* Hmm, we couldn't merge the other unit into ours? Then let's try it the other way
4730 other
= manager_get_unit((*u
)->manager
, k
);
4732 return r
; /* return previous failure */
4734 r
= unit_merge(other
, *u
);
4739 return merge_by_names(u
, names
, NULL
);
4742 if (streq_ptr(id
, k
))
4743 unit_choose_id(*u
, id
);
4749 int unit_load_fragment(Unit
*u
) {
4750 const char *fragment
;
4751 _cleanup_set_free_free_ Set
*names
= NULL
;
4756 assert(u
->load_state
== UNIT_STUB
);
4760 u
->load_state
= UNIT_LOADED
;
4764 /* Possibly rebuild the fragment map to catch new units */
4765 r
= unit_file_build_name_map(&u
->manager
->lookup_paths
,
4766 &u
->manager
->unit_cache_mtime
,
4767 &u
->manager
->unit_id_map
,
4768 &u
->manager
->unit_name_map
,
4769 &u
->manager
->unit_path_cache
);
4771 log_error_errno(r
, "Failed to rebuild name map: %m");
4773 r
= unit_file_find_fragment(u
->manager
->unit_id_map
,
4774 u
->manager
->unit_name_map
,
4778 if (r
< 0 && r
!= -ENOENT
)
4782 /* Open the file, check if this is a mask, otherwise read. */
4783 _cleanup_fclose_
FILE *f
= NULL
;
4785 /* Try to open the file name. A symlink is OK, for example for linked files or masks. We
4786 * expect that all symlinks within the lookup paths have been already resolved, but we don't
4787 * verify this here. */
4788 f
= fopen(fragment
, "re");
4790 return log_unit_notice_errno(u
, errno
, "Failed to open %s: %m", fragment
);
4792 if (fstat(fileno(f
), &st
) < 0)
4795 r
= free_and_strdup(&u
->fragment_path
, fragment
);
4799 if (null_or_empty(&st
)) {
4800 /* Unit file is masked */
4802 u
->load_state
= u
->perpetual
? UNIT_LOADED
: UNIT_MASKED
; /* don't allow perpetual units to ever be masked */
4803 u
->fragment_mtime
= 0;
4805 u
->load_state
= UNIT_LOADED
;
4806 u
->fragment_mtime
= timespec_load(&st
.st_mtim
);
4808 /* Now, parse the file contents */
4809 r
= config_parse(u
->id
, fragment
, f
,
4810 UNIT_VTABLE(u
)->sections
,
4811 config_item_perf_lookup
, load_fragment_gperf_lookup
,
4812 CONFIG_PARSE_ALLOW_INCLUDE
, u
);
4814 log_unit_notice_errno(u
, r
, "Unit configuration has fatal error, unit will not be started.");
4820 if (u
->source_path
) {
4821 if (stat(u
->source_path
, &st
) >= 0)
4822 u
->source_mtime
= timespec_load(&st
.st_mtim
);
4824 u
->source_mtime
= 0;
4827 /* We do the merge dance here because for some unit types, the unit might have aliases which are not
4828 * declared in the file system. In particular, this is true (and frequent) for device and swap units.
4831 const char *id
= u
->id
;
4832 _cleanup_free_
char *free_id
= NULL
;
4835 id
= basename(fragment
);
4836 if (unit_name_is_valid(id
, UNIT_NAME_TEMPLATE
)) {
4837 assert(u
->instance
); /* If we're not trying to use a template for non-instanced unit,
4838 * this must be set. */
4840 r
= unit_name_replace_instance(id
, u
->instance
, &free_id
);
4842 return log_debug_errno(r
, "Failed to build id (%s + %s): %m", id
, u
->instance
);
4848 r
= merge_by_names(&merged
, names
, id
);
4853 u
->load_state
= UNIT_MERGED
;
4858 void unit_dump_config_items(FILE *f
) {
4859 static const struct {
4860 const ConfigParserCallback callback
;
4863 { config_parse_warn_compat
, "NOTSUPPORTED" },
4864 { config_parse_int
, "INTEGER" },
4865 { config_parse_unsigned
, "UNSIGNED" },
4866 { config_parse_iec_size
, "SIZE" },
4867 { config_parse_iec_uint64
, "SIZE" },
4868 { config_parse_si_uint64
, "SIZE" },
4869 { config_parse_bool
, "BOOLEAN" },
4870 { config_parse_string
, "STRING" },
4871 { config_parse_path
, "PATH" },
4872 { config_parse_unit_path_printf
, "PATH" },
4873 { config_parse_strv
, "STRING [...]" },
4874 { config_parse_exec_nice
, "NICE" },
4875 { config_parse_exec_oom_score_adjust
, "OOMSCOREADJUST" },
4876 { config_parse_exec_io_class
, "IOCLASS" },
4877 { config_parse_exec_io_priority
, "IOPRIORITY" },
4878 { config_parse_exec_cpu_sched_policy
, "CPUSCHEDPOLICY" },
4879 { config_parse_exec_cpu_sched_prio
, "CPUSCHEDPRIO" },
4880 { config_parse_exec_cpu_affinity
, "CPUAFFINITY" },
4881 { config_parse_mode
, "MODE" },
4882 { config_parse_unit_env_file
, "FILE" },
4883 { config_parse_exec_output
, "OUTPUT" },
4884 { config_parse_exec_input
, "INPUT" },
4885 { config_parse_log_facility
, "FACILITY" },
4886 { config_parse_log_level
, "LEVEL" },
4887 { config_parse_exec_secure_bits
, "SECUREBITS" },
4888 { config_parse_capability_set
, "BOUNDINGSET" },
4889 { config_parse_rlimit
, "LIMIT" },
4890 { config_parse_unit_deps
, "UNIT [...]" },
4891 { config_parse_exec
, "PATH [ARGUMENT [...]]" },
4892 { config_parse_service_type
, "SERVICETYPE" },
4893 { config_parse_service_restart
, "SERVICERESTART" },
4894 { config_parse_kill_mode
, "KILLMODE" },
4895 { config_parse_signal
, "SIGNAL" },
4896 { config_parse_socket_listen
, "SOCKET [...]" },
4897 { config_parse_socket_bind
, "SOCKETBIND" },
4898 { config_parse_socket_bindtodevice
, "NETWORKINTERFACE" },
4899 { config_parse_sec
, "SECONDS" },
4900 { config_parse_nsec
, "NANOSECONDS" },
4901 { config_parse_namespace_path_strv
, "PATH [...]" },
4902 { config_parse_bind_paths
, "PATH[:PATH[:OPTIONS]] [...]" },
4903 { config_parse_unit_requires_mounts_for
, "PATH [...]" },
4904 { config_parse_exec_mount_flags
, "MOUNTFLAG [...]" },
4905 { config_parse_unit_string_printf
, "STRING" },
4906 { config_parse_trigger_unit
, "UNIT" },
4907 { config_parse_timer
, "TIMER" },
4908 { config_parse_path_spec
, "PATH" },
4909 { config_parse_notify_access
, "ACCESS" },
4910 { config_parse_ip_tos
, "TOS" },
4911 { config_parse_unit_condition_path
, "CONDITION" },
4912 { config_parse_unit_condition_string
, "CONDITION" },
4913 { config_parse_unit_condition_null
, "CONDITION" },
4914 { config_parse_unit_slice
, "SLICE" },
4915 { config_parse_documentation
, "URL" },
4916 { config_parse_service_timeout
, "SECONDS" },
4917 { config_parse_emergency_action
, "ACTION" },
4918 { config_parse_set_status
, "STATUS" },
4919 { config_parse_service_sockets
, "SOCKETS" },
4920 { config_parse_environ
, "ENVIRON" },
4922 { config_parse_syscall_filter
, "SYSCALLS" },
4923 { config_parse_syscall_archs
, "ARCHS" },
4924 { config_parse_syscall_errno
, "ERRNO" },
4925 { config_parse_address_families
, "FAMILIES" },
4926 { config_parse_restrict_namespaces
, "NAMESPACES" },
4928 { config_parse_cpu_shares
, "SHARES" },
4929 { config_parse_cg_weight
, "WEIGHT" },
4930 { config_parse_memory_limit
, "LIMIT" },
4931 { config_parse_device_allow
, "DEVICE" },
4932 { config_parse_device_policy
, "POLICY" },
4933 { config_parse_io_limit
, "LIMIT" },
4934 { config_parse_io_device_weight
, "DEVICEWEIGHT" },
4935 { config_parse_io_device_latency
, "DEVICELATENCY" },
4936 { config_parse_blockio_bandwidth
, "BANDWIDTH" },
4937 { config_parse_blockio_weight
, "WEIGHT" },
4938 { config_parse_blockio_device_weight
, "DEVICEWEIGHT" },
4939 { config_parse_long
, "LONG" },
4940 { config_parse_socket_service
, "SERVICE" },
4942 { config_parse_exec_selinux_context
, "LABEL" },
4944 { config_parse_job_mode
, "MODE" },
4945 { config_parse_job_mode_isolate
, "BOOLEAN" },
4946 { config_parse_personality
, "PERSONALITY" },
4949 const char *prev
= NULL
;
4954 NULSTR_FOREACH(i
, load_fragment_gperf_nulstr
) {
4955 const char *rvalue
= "OTHER", *lvalue
;
4956 const ConfigPerfItem
*p
;
4961 assert_se(p
= load_fragment_gperf_lookup(i
, strlen(i
)));
4963 /* Hide legacy settings */
4964 if (p
->parse
== config_parse_warn_compat
&&
4965 p
->ltype
== DISABLED_LEGACY
)
4968 for (j
= 0; j
< ELEMENTSOF(table
); j
++)
4969 if (p
->parse
== table
[j
].callback
) {
4970 rvalue
= table
[j
].rvalue
;
4974 dot
= strchr(i
, '.');
4975 lvalue
= dot
? dot
+ 1 : i
;
4979 if (!prev
|| !strneq(prev
, i
, prefix_len
+1)) {
4983 fprintf(f
, "[%.*s]\n", (int) prefix_len
, i
);
4986 fprintf(f
, "%s=%s\n", lvalue
, rvalue
);
4991 int config_parse_cpu_affinity2(
4993 const char *filename
,
4995 const char *section
,
4996 unsigned section_line
,
5003 CPUSet
*affinity
= data
;
5007 (void) parse_cpu_set_extend(rvalue
, affinity
, true, unit
, filename
, line
, lvalue
);
5012 int config_parse_show_status(
5014 const char *filename
,
5016 const char *section
,
5017 unsigned section_line
,
5025 ShowStatus
*b
= data
;
5032 k
= parse_show_status(rvalue
, b
);
5034 log_syntax(unit
, LOG_ERR
, filename
, line
, k
, "Failed to parse show status setting, ignoring: %s", rvalue
);
5041 int config_parse_output_restricted(
5043 const char *filename
,
5045 const char *section
,
5046 unsigned section_line
,
5053 ExecOutput t
, *eo
= data
;
5060 t
= exec_output_from_string(rvalue
);
5062 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse output type, ignoring: %s", rvalue
);
5066 if (IN_SET(t
, EXEC_OUTPUT_SOCKET
, EXEC_OUTPUT_NAMED_FD
, EXEC_OUTPUT_FILE
, EXEC_OUTPUT_FILE_APPEND
)) {
5067 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Standard output types socket, fd:, file:, append: are not supported as defaults, ignoring: %s", rvalue
);
5075 int config_parse_crash_chvt(
5077 const char *filename
,
5079 const char *section
,
5080 unsigned section_line
,
5094 r
= parse_crash_chvt(rvalue
, data
);
5096 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse CrashChangeVT= setting, ignoring: %s", rvalue
);
5103 int config_parse_swap_priority(
5105 const char *filename
,
5107 const char *section
,
5108 unsigned section_line
,
5124 if (isempty(rvalue
)) {
5125 s
->parameters_fragment
.priority
= -1;
5126 s
->parameters_fragment
.priority_set
= false;
5130 r
= safe_atoi(rvalue
, &priority
);
5132 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid swap pririty '%s', ignoring.", rvalue
);
5136 if (priority
< -1) {
5137 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
);
5141 if (priority
> 32767) {
5142 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Swap priority out of range, ignoring: %s", rvalue
);
5146 s
->parameters_fragment
.priority
= priority
;
5147 s
->parameters_fragment
.priority_set
= true;