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_notify_access
, notify_access
, NotifyAccess
, "Failed to parse notify access specifier");
121 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_home
, protect_home
, ProtectHome
, "Failed to parse protect home value");
122 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_system
, protect_system
, ProtectSystem
, "Failed to parse protect system value");
123 DEFINE_CONFIG_PARSE_ENUM(config_parse_runtime_preserve_mode
, exec_preserve_mode
, ExecPreserveMode
, "Failed to parse runtime directory preserve mode");
124 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_type
, service_type
, ServiceType
, "Failed to parse service type");
125 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart
, service_restart
, ServiceRestart
, "Failed to parse service restart specifier");
126 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_timeout_failure_mode
, service_timeout_failure_mode
, ServiceTimeoutFailureMode
, "Failed to parse timeout failure mode");
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_kill_mode(
636 const char *filename
,
639 unsigned section_line
,
646 KillMode
*k
= data
, m
;
653 if (isempty(rvalue
)) {
654 *k
= KILL_CONTROL_GROUP
;
658 m
= kill_mode_from_string(rvalue
);
660 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
661 "Failed to parse kill mode specification, ignoring: %s", rvalue
);
666 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
667 "Unit configured to use KillMode=none. "
668 "This is unsafe, as it disables systemd's process life-cycle management for the service. "
669 "Please update your service to use a safer KillMode=, such as 'mixed' or 'control-group'. "
670 "Support for KillMode=none is deprecated and will eventually be removed.");
676 int config_parse_exec(
678 const char *filename
,
681 unsigned section_line
,
688 ExecCommand
**e
= data
;
689 const Unit
*u
= userdata
;
701 if (isempty(rvalue
)) {
702 /* An empty assignment resets the list */
703 *e
= exec_command_free_list(*e
);
709 _cleanup_free_
char *path
= NULL
, *firstword
= NULL
;
710 ExecCommandFlags flags
= 0;
711 bool ignore
= false, separate_argv0
= false;
712 _cleanup_free_ ExecCommand
*nce
= NULL
;
713 _cleanup_strv_free_
char **n
= NULL
;
714 size_t nlen
= 0, nbufsize
= 0;
719 r
= extract_first_word_and_warn(&p
, &firstword
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
725 /* We accept an absolute path as first argument. If it's prefixed with - and the path doesn't
726 * exist, we ignore it instead of erroring out; if it's prefixed with @, we allow overriding of
727 * argv[0]; if it's prefixed with :, we will not do environment variable substitution;
728 * if it's prefixed with +, it will be run with full privileges and no sandboxing; if
729 * it's prefixed with '!' we apply sandboxing, but do not change user/group credentials; if
730 * it's prefixed with '!!', then we apply user/group credentials if the kernel supports ambient
731 * capabilities -- if it doesn't we don't apply the credentials themselves, but do apply most
732 * other sandboxing, with some special exceptions for changing UID.
734 * The idea is that '!!' may be used to write services that can take benefit of systemd's
735 * UID/GID dropping if the kernel supports ambient creds, but provide an automatic fallback to
736 * privilege dropping within the daemon if the kernel does not offer that. */
738 if (*f
== '-' && !(flags
& EXEC_COMMAND_IGNORE_FAILURE
)) {
739 flags
|= EXEC_COMMAND_IGNORE_FAILURE
;
741 } else if (*f
== '@' && !separate_argv0
)
742 separate_argv0
= true;
743 else if (*f
== ':' && !(flags
& EXEC_COMMAND_NO_ENV_EXPAND
))
744 flags
|= EXEC_COMMAND_NO_ENV_EXPAND
;
745 else if (*f
== '+' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
746 flags
|= EXEC_COMMAND_FULLY_PRIVILEGED
;
747 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
748 flags
|= EXEC_COMMAND_NO_SETUID
;
749 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_AMBIENT_MAGIC
))) {
750 flags
&= ~EXEC_COMMAND_NO_SETUID
;
751 flags
|= EXEC_COMMAND_AMBIENT_MAGIC
;
757 r
= unit_full_printf(u
, f
, &path
);
759 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
760 "Failed to resolve unit specifiers in '%s'%s: %m",
761 f
, ignore
? ", ignoring" : "");
762 return ignore
? 0 : -ENOEXEC
;
766 /* First word is either "-" or "@" with no command. */
767 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
768 "Empty path in command line%s: '%s'",
769 ignore
? ", ignoring" : "", rvalue
);
770 return ignore
? 0 : -ENOEXEC
;
772 if (!string_is_safe(path
)) {
773 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
774 "Executable name contains special characters%s: %s",
775 ignore
? ", ignoring" : "", path
);
776 return ignore
? 0 : -ENOEXEC
;
778 if (endswith(path
, "/")) {
779 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
780 "Executable path specifies a directory%s: %s",
781 ignore
? ", ignoring" : "", path
);
782 return ignore
? 0 : -ENOEXEC
;
785 if (!path_is_absolute(path
)) {
789 if (!filename_is_valid(path
)) {
790 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
791 "Neither a valid executable name nor an absolute path%s: %s",
792 ignore
? ", ignoring" : "", path
);
793 return ignore
? 0 : -ENOEXEC
;
796 /* Resolve a single-component name to a full path */
797 NULSTR_FOREACH(prefix
, DEFAULT_PATH_NULSTR
) {
798 _cleanup_free_
char *fullpath
= NULL
;
800 fullpath
= path_join(prefix
, path
);
804 if (access(fullpath
, F_OK
) >= 0) {
805 free_and_replace(path
, fullpath
);
812 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
813 "Executable \"%s\" not found in path \"%s\"%s",
814 path
, DEFAULT_PATH
, ignore
? ", ignoring" : "");
815 return ignore
? 0 : -ENOEXEC
;
819 if (!separate_argv0
) {
822 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
832 path_simplify(path
, false);
834 while (!isempty(p
)) {
835 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
837 /* Check explicitly for an unquoted semicolon as
838 * command separator token. */
839 if (p
[0] == ';' && (!p
[1] || strchr(WHITESPACE
, p
[1]))) {
841 p
+= strspn(p
, WHITESPACE
);
846 /* Check for \; explicitly, to not confuse it with \\; or "\;" or "\\;" etc.
847 * extract_first_word() would return the same for all of those. */
848 if (p
[0] == '\\' && p
[1] == ';' && (!p
[2] || strchr(WHITESPACE
, p
[2]))) {
852 p
+= strspn(p
, WHITESPACE
);
854 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
865 r
= extract_first_word_and_warn(&p
, &word
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
869 return ignore
? 0 : -ENOEXEC
;
871 r
= unit_full_printf(u
, word
, &resolved
);
873 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
874 "Failed to resolve unit specifiers in %s%s: %m",
875 word
, ignore
? ", ignoring" : "");
876 return ignore
? 0 : -ENOEXEC
;
879 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
882 n
[nlen
++] = TAKE_PTR(resolved
);
887 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
888 "Empty executable name or zeroeth argument%s: %s",
889 ignore
? ", ignoring" : "", rvalue
);
890 return ignore
? 0 : -ENOEXEC
;
893 nce
= new0(ExecCommand
, 1);
897 nce
->argv
= TAKE_PTR(n
);
898 nce
->path
= TAKE_PTR(path
);
901 exec_command_append_list(e
, nce
);
903 /* Do not _cleanup_free_ these. */
912 int config_parse_socket_bindtodevice(
914 const char *filename
,
917 unsigned section_line
,
931 if (isempty(rvalue
) || streq(rvalue
, "*")) {
932 s
->bind_to_device
= mfree(s
->bind_to_device
);
936 if (!ifname_valid(rvalue
)) {
937 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid interface name, ignoring: %s", rvalue
);
941 if (free_and_strdup(&s
->bind_to_device
, rvalue
) < 0)
947 int config_parse_exec_input(
949 const char *filename
,
952 unsigned section_line
,
959 ExecContext
*c
= data
;
960 const Unit
*u
= userdata
;
970 n
= startswith(rvalue
, "fd:");
972 _cleanup_free_
char *resolved
= NULL
;
974 r
= unit_full_printf(u
, n
, &resolved
);
976 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s': %m", n
);
978 if (isempty(resolved
))
979 resolved
= mfree(resolved
);
980 else if (!fdname_is_valid(resolved
)) {
981 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name: %s", resolved
);
985 free_and_replace(c
->stdio_fdname
[STDIN_FILENO
], resolved
);
987 ei
= EXEC_INPUT_NAMED_FD
;
989 } else if ((n
= startswith(rvalue
, "file:"))) {
990 _cleanup_free_
char *resolved
= NULL
;
992 r
= unit_full_printf(u
, n
, &resolved
);
994 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s': %m", n
);
996 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1000 free_and_replace(c
->stdio_file
[STDIN_FILENO
], resolved
);
1002 ei
= EXEC_INPUT_FILE
;
1005 ei
= exec_input_from_string(rvalue
);
1007 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse input specifier, ignoring: %s", rvalue
);
1016 int config_parse_exec_input_text(
1018 const char *filename
,
1020 const char *section
,
1021 unsigned section_line
,
1028 _cleanup_free_
char *unescaped
= NULL
, *resolved
= NULL
;
1029 ExecContext
*c
= data
;
1030 const Unit
*u
= userdata
;
1040 if (isempty(rvalue
)) {
1041 /* Reset if the empty string is assigned */
1042 c
->stdin_data
= mfree(c
->stdin_data
);
1043 c
->stdin_data_size
= 0;
1047 r
= cunescape(rvalue
, 0, &unescaped
);
1049 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to decode C escaped text '%s': %m", rvalue
);
1051 r
= unit_full_printf(u
, unescaped
, &resolved
);
1053 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s': %m", unescaped
);
1055 sz
= strlen(resolved
);
1056 if (c
->stdin_data_size
+ sz
+ 1 < c
->stdin_data_size
|| /* check for overflow */
1057 c
->stdin_data_size
+ sz
+ 1 > EXEC_STDIN_DATA_MAX
) {
1058 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
);
1062 p
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
+ 1);
1066 *((char*) mempcpy((char*) p
+ c
->stdin_data_size
, resolved
, sz
)) = '\n';
1069 c
->stdin_data_size
+= sz
+ 1;
1074 int config_parse_exec_input_data(
1076 const char *filename
,
1078 const char *section
,
1079 unsigned section_line
,
1086 _cleanup_free_
void *p
= NULL
;
1087 ExecContext
*c
= data
;
1097 if (isempty(rvalue
)) {
1098 /* Reset if the empty string is assigned */
1099 c
->stdin_data
= mfree(c
->stdin_data
);
1100 c
->stdin_data_size
= 0;
1104 r
= unbase64mem(rvalue
, (size_t) -1, &p
, &sz
);
1106 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to decode base64 data, ignoring: %s", rvalue
);
1110 if (c
->stdin_data_size
+ sz
< c
->stdin_data_size
|| /* check for overflow */
1111 c
->stdin_data_size
+ sz
> EXEC_STDIN_DATA_MAX
) {
1112 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
);
1116 q
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
);
1120 memcpy((uint8_t*) q
+ c
->stdin_data_size
, p
, sz
);
1123 c
->stdin_data_size
+= sz
;
1128 int config_parse_exec_output(
1130 const char *filename
,
1132 const char *section
,
1133 unsigned section_line
,
1140 _cleanup_free_
char *resolved
= NULL
;
1142 ExecContext
*c
= data
;
1143 const Unit
*u
= userdata
;
1144 bool obsolete
= false;
1154 n
= startswith(rvalue
, "fd:");
1156 r
= unit_full_printf(u
, n
, &resolved
);
1158 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", n
);
1160 if (isempty(resolved
))
1161 resolved
= mfree(resolved
);
1162 else if (!fdname_is_valid(resolved
)) {
1163 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name: %s", resolved
);
1167 eo
= EXEC_OUTPUT_NAMED_FD
;
1169 } else if (streq(rvalue
, "syslog")) {
1170 eo
= EXEC_OUTPUT_JOURNAL
;
1173 } else if (streq(rvalue
, "syslog+console")) {
1174 eo
= EXEC_OUTPUT_JOURNAL_AND_CONSOLE
;
1177 } else if ((n
= startswith(rvalue
, "file:"))) {
1179 r
= unit_full_printf(u
, n
, &resolved
);
1181 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", n
);
1183 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1187 eo
= EXEC_OUTPUT_FILE
;
1189 } else if ((n
= startswith(rvalue
, "append:"))) {
1191 r
= unit_full_printf(u
, n
, &resolved
);
1193 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", n
);
1195 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1199 eo
= EXEC_OUTPUT_FILE_APPEND
;
1201 eo
= exec_output_from_string(rvalue
);
1203 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse output specifier, ignoring: %s", rvalue
);
1209 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
1210 "Standard output type %s is obsolete, automatically updating to %s. Please update your unit file, and consider removing the setting altogether.",
1211 rvalue
, exec_output_to_string(eo
));
1213 if (streq(lvalue
, "StandardOutput")) {
1214 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1215 free_and_replace(c
->stdio_fdname
[STDOUT_FILENO
], resolved
);
1217 free_and_replace(c
->stdio_file
[STDOUT_FILENO
], resolved
);
1222 assert(streq(lvalue
, "StandardError"));
1224 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1225 free_and_replace(c
->stdio_fdname
[STDERR_FILENO
], resolved
);
1227 free_and_replace(c
->stdio_file
[STDERR_FILENO
], resolved
);
1235 int config_parse_exec_io_class(const char *unit
,
1236 const char *filename
,
1238 const char *section
,
1239 unsigned section_line
,
1246 ExecContext
*c
= data
;
1254 if (isempty(rvalue
)) {
1255 c
->ioprio_set
= false;
1256 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE
, 0);
1260 x
= ioprio_class_from_string(rvalue
);
1262 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse IO scheduling class, ignoring: %s", rvalue
);
1266 c
->ioprio
= IOPRIO_PRIO_VALUE(x
, IOPRIO_PRIO_DATA(c
->ioprio
));
1267 c
->ioprio_set
= true;
1272 int config_parse_exec_io_priority(const char *unit
,
1273 const char *filename
,
1275 const char *section
,
1276 unsigned section_line
,
1283 ExecContext
*c
= data
;
1291 if (isempty(rvalue
)) {
1292 c
->ioprio_set
= false;
1293 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE
, 0);
1297 r
= ioprio_parse_priority(rvalue
, &i
);
1299 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse IO priority, ignoring: %s", rvalue
);
1303 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_PRIO_CLASS(c
->ioprio
), i
);
1304 c
->ioprio_set
= true;
1309 int config_parse_exec_cpu_sched_policy(const char *unit
,
1310 const char *filename
,
1312 const char *section
,
1313 unsigned section_line
,
1320 ExecContext
*c
= data
;
1328 if (isempty(rvalue
)) {
1329 c
->cpu_sched_set
= false;
1330 c
->cpu_sched_policy
= SCHED_OTHER
;
1331 c
->cpu_sched_priority
= 0;
1335 x
= sched_policy_from_string(rvalue
);
1337 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse CPU scheduling policy, ignoring: %s", rvalue
);
1341 c
->cpu_sched_policy
= x
;
1342 /* Moving to or from real-time policy? We need to adjust the priority */
1343 c
->cpu_sched_priority
= CLAMP(c
->cpu_sched_priority
, sched_get_priority_min(x
), sched_get_priority_max(x
));
1344 c
->cpu_sched_set
= true;
1349 int config_parse_numa_mask(const char *unit
,
1350 const char *filename
,
1352 const char *section
,
1353 unsigned section_line
,
1360 NUMAPolicy
*p
= data
;
1367 r
= parse_cpu_set_extend(rvalue
, &p
->nodes
, true, unit
, filename
, line
, lvalue
);
1369 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse NUMA node mask, ignoring: %s", rvalue
);
1376 int config_parse_exec_cpu_sched_prio(const char *unit
,
1377 const char *filename
,
1379 const char *section
,
1380 unsigned section_line
,
1387 ExecContext
*c
= data
;
1395 r
= safe_atoi(rvalue
, &i
);
1397 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse CPU scheduling priority, ignoring: %s", rvalue
);
1401 /* On Linux RR/FIFO range from 1 to 99 and OTHER/BATCH may only be 0 */
1402 min
= sched_get_priority_min(c
->cpu_sched_policy
);
1403 max
= sched_get_priority_max(c
->cpu_sched_policy
);
1405 if (i
< min
|| i
> max
) {
1406 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "CPU scheduling priority is out of range, ignoring: %s", rvalue
);
1410 c
->cpu_sched_priority
= i
;
1411 c
->cpu_sched_set
= true;
1416 int config_parse_exec_cpu_affinity(const char *unit
,
1417 const char *filename
,
1419 const char *section
,
1420 unsigned section_line
,
1427 ExecContext
*c
= data
;
1435 if (streq(rvalue
, "numa")) {
1436 c
->cpu_affinity_from_numa
= true;
1437 cpu_set_reset(&c
->cpu_set
);
1442 r
= parse_cpu_set_extend(rvalue
, &c
->cpu_set
, true, unit
, filename
, line
, lvalue
);
1444 c
->cpu_affinity_from_numa
= false;
1449 int config_parse_capability_set(
1451 const char *filename
,
1453 const char *section
,
1454 unsigned section_line
,
1461 uint64_t *capability_set
= data
;
1462 uint64_t sum
= 0, initial
= 0;
1463 bool invert
= false;
1471 if (rvalue
[0] == '~') {
1476 if (streq(lvalue
, "CapabilityBoundingSet"))
1477 initial
= CAP_ALL
; /* initialized to all bits on */
1478 /* else "AmbientCapabilities" initialized to all bits off */
1480 r
= capability_set_from_string(rvalue
, &sum
);
1482 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= specifier '%s', ignoring: %m", lvalue
, rvalue
);
1486 if (sum
== 0 || *capability_set
== initial
)
1487 /* "", "~" or uninitialized data -> replace */
1488 *capability_set
= invert
? ~sum
: sum
;
1490 /* previous data -> merge */
1492 *capability_set
&= ~sum
;
1494 *capability_set
|= sum
;
1500 int config_parse_exec_selinux_context(
1502 const char *filename
,
1504 const char *section
,
1505 unsigned section_line
,
1512 ExecContext
*c
= data
;
1513 const Unit
*u
= userdata
;
1523 if (isempty(rvalue
)) {
1524 c
->selinux_context
= mfree(c
->selinux_context
);
1525 c
->selinux_context_ignore
= false;
1529 if (rvalue
[0] == '-') {
1535 r
= unit_full_printf(u
, rvalue
, &k
);
1537 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1538 "Failed to resolve unit specifiers in '%s'%s: %m",
1539 rvalue
, ignore
? ", ignoring" : "");
1540 return ignore
? 0 : -ENOEXEC
;
1543 free_and_replace(c
->selinux_context
, k
);
1544 c
->selinux_context_ignore
= ignore
;
1549 int config_parse_exec_apparmor_profile(
1551 const char *filename
,
1553 const char *section
,
1554 unsigned section_line
,
1561 ExecContext
*c
= data
;
1562 const Unit
*u
= userdata
;
1572 if (isempty(rvalue
)) {
1573 c
->apparmor_profile
= mfree(c
->apparmor_profile
);
1574 c
->apparmor_profile_ignore
= false;
1578 if (rvalue
[0] == '-') {
1584 r
= unit_full_printf(u
, rvalue
, &k
);
1586 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1587 "Failed to resolve unit specifiers in '%s'%s: %m",
1588 rvalue
, ignore
? ", ignoring" : "");
1589 return ignore
? 0 : -ENOEXEC
;
1592 free_and_replace(c
->apparmor_profile
, k
);
1593 c
->apparmor_profile_ignore
= ignore
;
1598 int config_parse_exec_smack_process_label(
1600 const char *filename
,
1602 const char *section
,
1603 unsigned section_line
,
1610 ExecContext
*c
= data
;
1611 const Unit
*u
= userdata
;
1621 if (isempty(rvalue
)) {
1622 c
->smack_process_label
= mfree(c
->smack_process_label
);
1623 c
->smack_process_label_ignore
= false;
1627 if (rvalue
[0] == '-') {
1633 r
= unit_full_printf(u
, rvalue
, &k
);
1635 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1636 "Failed to resolve unit specifiers in '%s'%s: %m",
1637 rvalue
, ignore
? ", ignoring" : "");
1638 return ignore
? 0 : -ENOEXEC
;
1641 free_and_replace(c
->smack_process_label
, k
);
1642 c
->smack_process_label_ignore
= ignore
;
1647 int config_parse_timer(
1649 const char *filename
,
1651 const char *section
,
1652 unsigned section_line
,
1659 _cleanup_(calendar_spec_freep
) CalendarSpec
*c
= NULL
;
1660 _cleanup_free_
char *k
= NULL
;
1661 const Unit
*u
= userdata
;
1672 if (isempty(rvalue
)) {
1673 /* Empty assignment resets list */
1674 timer_free_values(t
);
1678 r
= unit_full_printf(u
, rvalue
, &k
);
1680 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
1684 if (ltype
== TIMER_CALENDAR
) {
1685 r
= calendar_spec_from_string(k
, &c
);
1687 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse calendar specification, ignoring: %s", k
);
1691 r
= parse_sec(k
, &usec
);
1693 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse timer value, ignoring: %s", k
);
1698 v
= new(TimerValue
, 1);
1705 .calendar_spec
= TAKE_PTR(c
),
1708 LIST_PREPEND(value
, t
->values
, v
);
1713 int config_parse_trigger_unit(
1715 const char *filename
,
1717 const char *section
,
1718 unsigned section_line
,
1725 _cleanup_free_
char *p
= NULL
;
1735 if (!hashmap_isempty(u
->dependencies
[UNIT_TRIGGERS
])) {
1736 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Multiple units to trigger specified, ignoring: %s", rvalue
);
1740 r
= unit_name_printf(u
, rvalue
, &p
);
1742 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
1746 type
= unit_name_to_type(p
);
1748 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit type not valid, ignoring: %s", rvalue
);
1751 if (unit_has_name(u
, p
)) {
1752 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Units cannot trigger themselves, ignoring: %s", rvalue
);
1756 r
= unit_add_two_dependencies_by_name(u
, UNIT_BEFORE
, UNIT_TRIGGERS
, p
, true, UNIT_DEPENDENCY_FILE
);
1758 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add trigger on %s, ignoring: %m", p
);
1765 int config_parse_path_spec(const char *unit
,
1766 const char *filename
,
1768 const char *section
,
1769 unsigned section_line
,
1779 _cleanup_free_
char *k
= NULL
;
1787 if (isempty(rvalue
)) {
1788 /* Empty assignment clears list */
1793 b
= path_type_from_string(lvalue
);
1795 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse path type, ignoring: %s", lvalue
);
1799 r
= unit_full_printf(UNIT(p
), rvalue
, &k
);
1801 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
1805 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
1809 s
= new0(PathSpec
, 1);
1814 s
->path
= TAKE_PTR(k
);
1818 LIST_PREPEND(spec
, p
->specs
, s
);
1823 int config_parse_socket_service(
1825 const char *filename
,
1827 const char *section
,
1828 unsigned section_line
,
1835 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1836 _cleanup_free_
char *p
= NULL
;
1846 r
= unit_name_printf(UNIT(s
), rvalue
, &p
);
1848 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", rvalue
);
1852 if (!endswith(p
, ".service")) {
1853 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit must be of type service: %s", rvalue
);
1857 r
= manager_load_unit(UNIT(s
)->manager
, p
, NULL
, &error
, &x
);
1859 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to load unit %s: %s", rvalue
, bus_error_message(&error
, r
));
1863 unit_ref_set(&s
->service
, UNIT(s
), x
);
1868 int config_parse_fdname(
1870 const char *filename
,
1872 const char *section
,
1873 unsigned section_line
,
1880 _cleanup_free_
char *p
= NULL
;
1889 if (isempty(rvalue
)) {
1890 s
->fdname
= mfree(s
->fdname
);
1894 r
= unit_full_printf(UNIT(s
), rvalue
, &p
);
1896 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
1900 if (!fdname_is_valid(p
)) {
1901 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", p
);
1905 return free_and_replace(s
->fdname
, p
);
1908 int config_parse_service_sockets(
1910 const char *filename
,
1912 const char *section
,
1913 unsigned section_line
,
1931 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
1933 r
= extract_first_word(&p
, &word
, NULL
, 0);
1939 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Trailing garbage in sockets, ignoring: %s", rvalue
);
1943 r
= unit_name_printf(UNIT(s
), word
, &k
);
1945 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
1949 if (!endswith(k
, ".socket")) {
1950 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit must be of type socket, ignoring: %s", k
);
1954 r
= unit_add_two_dependencies_by_name(UNIT(s
), UNIT_WANTS
, UNIT_AFTER
, k
, true, UNIT_DEPENDENCY_FILE
);
1956 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
1958 r
= unit_add_dependency_by_name(UNIT(s
), UNIT_TRIGGERED_BY
, k
, true, UNIT_DEPENDENCY_FILE
);
1960 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
1966 int config_parse_bus_name(
1968 const char *filename
,
1970 const char *section
,
1971 unsigned section_line
,
1978 _cleanup_free_
char *k
= NULL
;
1979 const Unit
*u
= userdata
;
1987 r
= unit_full_printf(u
, rvalue
, &k
);
1989 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
1993 if (!sd_bus_service_name_is_valid(k
)) {
1994 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid bus name, ignoring: %s", k
);
1998 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
2001 int config_parse_service_timeout(
2003 const char *filename
,
2005 const char *section
,
2006 unsigned section_line
,
2013 Service
*s
= userdata
;
2022 /* This is called for two cases: TimeoutSec= and TimeoutStartSec=. */
2024 /* Traditionally, these options accepted 0 to disable the timeouts. However, a timeout of 0 suggests it happens
2025 * immediately, hence fix this to become USEC_INFINITY instead. This is in-line with how we internally handle
2026 * all other timeouts. */
2027 r
= parse_sec_fix_0(rvalue
, &usec
);
2029 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
2033 s
->start_timeout_defined
= true;
2034 s
->timeout_start_usec
= usec
;
2036 if (streq(lvalue
, "TimeoutSec"))
2037 s
->timeout_stop_usec
= usec
;
2042 int config_parse_timeout_abort(
2044 const char *filename
,
2046 const char *section
,
2047 unsigned section_line
,
2062 /* Note: apart from setting the arg, this returns an extra bit of information in the return value. */
2064 if (isempty(rvalue
)) {
2066 return 0; /* "not set" */
2069 r
= parse_sec(rvalue
, ret
);
2071 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= setting, ignoring: %s", lvalue
, rvalue
);
2073 return 1; /* "set" */
2076 int config_parse_service_timeout_abort(
2078 const char *filename
,
2080 const char *section
,
2081 unsigned section_line
,
2088 Service
*s
= userdata
;
2093 r
= config_parse_timeout_abort(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
,
2094 &s
->timeout_abort_usec
, s
);
2096 s
->timeout_abort_set
= r
;
2100 int config_parse_sec_fix_0(
2102 const char *filename
,
2104 const char *section
,
2105 unsigned section_line
,
2112 usec_t
*usec
= data
;
2120 /* This is pretty much like config_parse_sec(), except that this treats a time of 0 as infinity, for
2121 * compatibility with older versions of systemd where 0 instead of infinity was used as indicator to turn off a
2124 r
= parse_sec_fix_0(rvalue
, usec
);
2126 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
2133 int config_parse_user_group_compat(
2135 const char *filename
,
2137 const char *section
,
2138 unsigned section_line
,
2145 _cleanup_free_
char *k
= NULL
;
2147 const Unit
*u
= userdata
;
2155 if (isempty(rvalue
)) {
2156 *user
= mfree(*user
);
2160 r
= unit_full_printf(u
, rvalue
, &k
);
2162 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", rvalue
);
2166 if (!valid_user_group_name(k
, VALID_USER_ALLOW_NUMERIC
|VALID_USER_RELAX
|VALID_USER_WARN
)) {
2167 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2171 return free_and_replace(*user
, k
);
2174 int config_parse_user_group_strv_compat(
2176 const char *filename
,
2178 const char *section
,
2179 unsigned section_line
,
2186 char ***users
= data
;
2187 const Unit
*u
= userdata
;
2188 const char *p
= rvalue
;
2196 if (isempty(rvalue
)) {
2197 *users
= strv_free(*users
);
2202 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2204 r
= extract_first_word(&p
, &word
, NULL
, 0);
2210 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax: %s", rvalue
);
2214 r
= unit_full_printf(u
, word
, &k
);
2216 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", word
);
2220 if (!valid_user_group_name(k
, VALID_USER_ALLOW_NUMERIC
|VALID_USER_RELAX
|VALID_USER_WARN
)) {
2221 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2225 r
= strv_push(users
, k
);
2235 int config_parse_working_directory(
2237 const char *filename
,
2239 const char *section
,
2240 unsigned section_line
,
2247 ExecContext
*c
= data
;
2248 const Unit
*u
= userdata
;
2258 if (isempty(rvalue
)) {
2259 c
->working_directory_home
= false;
2260 c
->working_directory
= mfree(c
->working_directory
);
2264 if (rvalue
[0] == '-') {
2270 if (streq(rvalue
, "~")) {
2271 c
->working_directory_home
= true;
2272 c
->working_directory
= mfree(c
->working_directory
);
2274 _cleanup_free_
char *k
= NULL
;
2276 r
= unit_full_printf(u
, rvalue
, &k
);
2278 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2279 "Failed to resolve unit specifiers in working directory path '%s'%s: %m",
2280 rvalue
, missing_ok
? ", ignoring" : "");
2281 return missing_ok
? 0 : -ENOEXEC
;
2284 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
| (missing_ok
? 0 : PATH_CHECK_FATAL
), unit
, filename
, line
, lvalue
);
2286 return missing_ok
? 0 : -ENOEXEC
;
2288 c
->working_directory_home
= false;
2289 free_and_replace(c
->working_directory
, k
);
2292 c
->working_directory_missing_ok
= missing_ok
;
2296 int config_parse_unit_env_file(const char *unit
,
2297 const char *filename
,
2299 const char *section
,
2300 unsigned section_line
,
2308 const Unit
*u
= userdata
;
2309 _cleanup_free_
char *n
= NULL
;
2317 if (isempty(rvalue
)) {
2318 /* Empty assignment frees the list */
2319 *env
= strv_free(*env
);
2323 r
= unit_full_printf(u
, rvalue
, &n
);
2325 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2329 r
= path_simplify_and_warn(n
[0] == '-' ? n
+ 1 : n
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2333 r
= strv_push(env
, n
);
2342 int config_parse_environ(
2344 const char *filename
,
2346 const char *section
,
2347 unsigned section_line
,
2354 const Unit
*u
= userdata
;
2364 if (isempty(rvalue
)) {
2365 /* Empty assignment resets the list */
2366 *env
= strv_free(*env
);
2370 for (p
= rvalue
;; ) {
2371 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2373 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2379 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2380 "Invalid syntax, ignoring: %s", rvalue
);
2385 r
= unit_full_printf(u
, word
, &k
);
2387 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2388 "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2394 if (!env_assignment_is_valid(k
)) {
2395 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2396 "Invalid environment assignment, ignoring: %s", k
);
2400 r
= strv_env_replace(env
, k
);
2408 int config_parse_pass_environ(
2410 const char *filename
,
2412 const char *section
,
2413 unsigned section_line
,
2420 _cleanup_strv_free_
char **n
= NULL
;
2421 size_t nlen
= 0, nbufsize
= 0;
2422 char*** passenv
= data
;
2423 const char *p
= rvalue
;
2424 const Unit
*u
= userdata
;
2432 if (isempty(rvalue
)) {
2433 /* Empty assignment resets the list */
2434 *passenv
= strv_free(*passenv
);
2439 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2441 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
2447 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2448 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2453 r
= unit_full_printf(u
, word
, &k
);
2455 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2456 "Failed to resolve specifiers in %s, ignoring: %m", word
);
2462 if (!env_name_is_valid(k
)) {
2463 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2464 "Invalid environment name for %s, ignoring: %s", lvalue
, k
);
2468 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
2471 n
[nlen
++] = TAKE_PTR(k
);
2476 r
= strv_extend_strv(passenv
, n
, true);
2484 int config_parse_unset_environ(
2486 const char *filename
,
2488 const char *section
,
2489 unsigned section_line
,
2496 _cleanup_strv_free_
char **n
= NULL
;
2497 size_t nlen
= 0, nbufsize
= 0;
2498 char*** unsetenv
= data
;
2499 const char *p
= rvalue
;
2500 const Unit
*u
= userdata
;
2508 if (isempty(rvalue
)) {
2509 /* Empty assignment resets the list */
2510 *unsetenv
= strv_free(*unsetenv
);
2515 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2517 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2523 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2524 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2529 r
= unit_full_printf(u
, word
, &k
);
2531 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2532 "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2538 if (!env_assignment_is_valid(k
) && !env_name_is_valid(k
)) {
2539 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2540 "Invalid environment name or assignment %s, ignoring: %s", lvalue
, k
);
2544 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
2547 n
[nlen
++] = TAKE_PTR(k
);
2552 r
= strv_extend_strv(unsetenv
, n
, true);
2560 int config_parse_log_extra_fields(
2562 const char *filename
,
2564 const char *section
,
2565 unsigned section_line
,
2572 ExecContext
*c
= data
;
2573 const Unit
*u
= userdata
;
2574 const char *p
= rvalue
;
2582 if (isempty(rvalue
)) {
2583 exec_context_free_log_extra_fields(c
);
2588 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2592 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2598 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
2602 r
= unit_full_printf(u
, word
, &k
);
2604 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2608 eq
= strchr(k
, '=');
2610 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Log field lacks '=' character, ignoring: %s", k
);
2614 if (!journal_field_valid(k
, eq
-k
, false)) {
2615 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Log field name is invalid, ignoring: %s", k
);
2619 t
= reallocarray(c
->log_extra_fields
, c
->n_log_extra_fields
+1, sizeof(struct iovec
));
2623 c
->log_extra_fields
= t
;
2624 c
->log_extra_fields
[c
->n_log_extra_fields
++] = IOVEC_MAKE_STRING(k
);
2630 int config_parse_log_namespace(
2632 const char *filename
,
2634 const char *section
,
2635 unsigned section_line
,
2642 _cleanup_free_
char *k
= NULL
;
2643 ExecContext
*c
= data
;
2644 const Unit
*u
= userdata
;
2652 if (isempty(rvalue
)) {
2653 c
->log_namespace
= mfree(c
->log_namespace
);
2657 r
= unit_full_printf(u
, rvalue
, &k
);
2659 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2663 if (!log_namespace_name_valid(k
)) {
2664 log_syntax(unit
, LOG_ERR
, filename
, line
, SYNTHETIC_ERRNO(EINVAL
), "Specified log namespace name is not valid: %s", k
);
2668 free_and_replace(c
->log_namespace
, k
);
2672 int config_parse_unit_condition_path(
2674 const char *filename
,
2676 const char *section
,
2677 unsigned section_line
,
2684 _cleanup_free_
char *p
= 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
[0] == '|';
2706 negate
= rvalue
[0] == '!';
2710 r
= unit_full_printf(u
, rvalue
, &p
);
2712 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2716 r
= path_simplify_and_warn(p
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2720 c
= condition_new(t
, p
, trigger
, negate
);
2724 LIST_PREPEND(conditions
, *list
, c
);
2728 int config_parse_unit_condition_string(
2730 const char *filename
,
2732 const char *section
,
2733 unsigned section_line
,
2740 _cleanup_free_
char *s
= NULL
;
2741 Condition
**list
= data
, *c
;
2742 ConditionType t
= ltype
;
2743 bool trigger
, negate
;
2744 const Unit
*u
= userdata
;
2752 if (isempty(rvalue
)) {
2753 /* Empty assignment resets the list */
2754 *list
= condition_free_list(*list
);
2758 trigger
= *rvalue
== '|';
2760 rvalue
+= 1 + strspn(rvalue
+ 1, WHITESPACE
);
2762 negate
= *rvalue
== '!';
2764 rvalue
+= 1 + strspn(rvalue
+ 1, WHITESPACE
);
2766 r
= unit_full_printf(u
, rvalue
, &s
);
2768 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2769 "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2773 c
= condition_new(t
, s
, trigger
, negate
);
2777 LIST_PREPEND(conditions
, *list
, c
);
2781 int config_parse_unit_condition_null(
2783 const char *filename
,
2785 const char *section
,
2786 unsigned section_line
,
2793 Condition
**list
= data
, *c
;
2794 bool trigger
, negate
;
2802 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "%s= is deprecated, please do not use.", lvalue
);
2804 if (isempty(rvalue
)) {
2805 /* Empty assignment resets the list */
2806 *list
= condition_free_list(*list
);
2810 trigger
= rvalue
[0] == '|';
2814 negate
= rvalue
[0] == '!';
2818 b
= parse_boolean(rvalue
);
2820 log_syntax(unit
, LOG_ERR
, filename
, line
, b
, "Failed to parse boolean value in condition, ignoring: %s", rvalue
);
2827 c
= condition_new(CONDITION_NULL
, NULL
, trigger
, negate
);
2831 LIST_PREPEND(conditions
, *list
, c
);
2835 int config_parse_unit_requires_mounts_for(
2837 const char *filename
,
2839 const char *section
,
2840 unsigned section_line
,
2847 const char *p
= rvalue
;
2857 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
2859 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
2865 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2866 "Invalid syntax, ignoring: %s", rvalue
);
2870 r
= unit_full_printf(u
, word
, &resolved
);
2872 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
2876 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2880 r
= unit_require_mounts_for(u
, resolved
, UNIT_DEPENDENCY_FILE
);
2882 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add required mount '%s', ignoring: %m", resolved
);
2888 int config_parse_documentation(const char *unit
,
2889 const char *filename
,
2891 const char *section
,
2892 unsigned section_line
,
2908 if (isempty(rvalue
)) {
2909 /* Empty assignment resets the list */
2910 u
->documentation
= strv_free(u
->documentation
);
2914 r
= config_parse_unit_strv_printf(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
,
2915 rvalue
, data
, userdata
);
2919 for (a
= b
= u
->documentation
; a
&& *a
; a
++) {
2921 if (documentation_url_is_valid(*a
))
2924 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid URL, ignoring: %s", *a
);
2935 int config_parse_syscall_filter(
2937 const char *filename
,
2939 const char *section
,
2940 unsigned section_line
,
2947 ExecContext
*c
= data
;
2948 _unused_
const Unit
*u
= userdata
;
2949 bool invert
= false;
2958 if (isempty(rvalue
)) {
2959 /* Empty assignment resets the list */
2960 c
->syscall_filter
= hashmap_free(c
->syscall_filter
);
2961 c
->syscall_whitelist
= false;
2965 if (rvalue
[0] == '~') {
2970 if (!c
->syscall_filter
) {
2971 c
->syscall_filter
= hashmap_new(NULL
);
2972 if (!c
->syscall_filter
)
2976 /* Allow everything but the ones listed */
2977 c
->syscall_whitelist
= false;
2979 /* Allow nothing but the ones listed */
2980 c
->syscall_whitelist
= true;
2982 /* Accept default syscalls if we are on a whitelist */
2983 r
= seccomp_parse_syscall_filter(
2984 "@default", -1, c
->syscall_filter
,
2985 SECCOMP_PARSE_PERMISSIVE
|SECCOMP_PARSE_WHITELIST
,
2995 _cleanup_free_
char *word
= NULL
, *name
= NULL
;
2998 r
= extract_first_word(&p
, &word
, NULL
, 0);
3004 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3008 r
= parse_syscall_and_errno(word
, &name
, &num
);
3010 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse syscall:errno, ignoring: %s", word
);
3014 r
= seccomp_parse_syscall_filter(
3015 name
, num
, c
->syscall_filter
,
3016 SECCOMP_PARSE_LOG
|SECCOMP_PARSE_PERMISSIVE
|
3017 (invert
? SECCOMP_PARSE_INVERT
: 0)|
3018 (c
->syscall_whitelist
? SECCOMP_PARSE_WHITELIST
: 0),
3019 unit
, filename
, line
);
3025 int config_parse_syscall_archs(
3027 const char *filename
,
3029 const char *section
,
3030 unsigned section_line
,
3037 const char *p
= rvalue
;
3041 if (isempty(rvalue
)) {
3042 *archs
= set_free(*archs
);
3046 r
= set_ensure_allocated(archs
, NULL
);
3051 _cleanup_free_
char *word
= NULL
;
3054 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3060 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3061 "Invalid syntax, ignoring: %s", rvalue
);
3065 r
= seccomp_arch_from_string(word
, &a
);
3067 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
3068 "Failed to parse system call architecture \"%s\", ignoring: %m", word
);
3072 r
= set_put(*archs
, UINT32_TO_PTR(a
+ 1));
3078 int config_parse_syscall_errno(
3080 const char *filename
,
3082 const char *section
,
3083 unsigned section_line
,
3090 ExecContext
*c
= data
;
3097 if (isempty(rvalue
)) {
3098 /* Empty assignment resets to KILL */
3099 c
->syscall_errno
= 0;
3103 e
= parse_errno(rvalue
);
3105 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse error number, ignoring: %s", rvalue
);
3109 c
->syscall_errno
= e
;
3113 int config_parse_address_families(
3115 const char *filename
,
3117 const char *section
,
3118 unsigned section_line
,
3125 ExecContext
*c
= data
;
3126 bool invert
= false;
3134 if (isempty(rvalue
)) {
3135 /* Empty assignment resets the list */
3136 c
->address_families
= set_free(c
->address_families
);
3137 c
->address_families_whitelist
= false;
3141 if (rvalue
[0] == '~') {
3146 if (!c
->address_families
) {
3147 c
->address_families
= set_new(NULL
);
3148 if (!c
->address_families
)
3151 c
->address_families_whitelist
= !invert
;
3154 for (p
= rvalue
;;) {
3155 _cleanup_free_
char *word
= NULL
;
3158 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3164 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3165 "Invalid syntax, ignoring: %s", rvalue
);
3169 af
= af_from_name(word
);
3171 log_syntax(unit
, LOG_ERR
, filename
, line
, af
,
3172 "Failed to parse address family, ignoring: %s", word
);
3176 /* If we previously wanted to forbid an address family and now
3177 * we want to allow it, then just remove it from the list.
3179 if (!invert
== c
->address_families_whitelist
) {
3180 r
= set_put(c
->address_families
, INT_TO_PTR(af
));
3184 set_remove(c
->address_families
, INT_TO_PTR(af
));
3188 int config_parse_restrict_namespaces(
3190 const char *filename
,
3192 const char *section
,
3193 unsigned section_line
,
3200 ExecContext
*c
= data
;
3201 unsigned long flags
;
3202 bool invert
= false;
3205 if (isempty(rvalue
)) {
3206 /* Reset to the default. */
3207 c
->restrict_namespaces
= NAMESPACE_FLAGS_INITIAL
;
3211 /* Boolean parameter ignores the previous settings */
3212 r
= parse_boolean(rvalue
);
3214 c
->restrict_namespaces
= 0;
3216 } else if (r
== 0) {
3217 c
->restrict_namespaces
= NAMESPACE_FLAGS_ALL
;
3221 if (rvalue
[0] == '~') {
3226 /* Not a boolean argument, in this case it's a list of namespace types. */
3227 r
= namespace_flags_from_string(rvalue
, &flags
);
3229 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse namespace type string, ignoring: %s", rvalue
);
3233 if (c
->restrict_namespaces
== NAMESPACE_FLAGS_INITIAL
)
3234 /* Initial assignment. Just set the value. */
3235 c
->restrict_namespaces
= invert
? (~flags
) & NAMESPACE_FLAGS_ALL
: flags
;
3237 /* Merge the value with the previous one. */
3238 SET_FLAG(c
->restrict_namespaces
, flags
, !invert
);
3244 int config_parse_unit_slice(
3246 const char *filename
,
3248 const char *section
,
3249 unsigned section_line
,
3256 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
3257 _cleanup_free_
char *k
= NULL
;
3258 Unit
*u
= userdata
, *slice
;
3266 r
= unit_name_printf(u
, rvalue
, &k
);
3268 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
3272 r
= manager_load_unit(u
->manager
, k
, NULL
, &error
, &slice
);
3274 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to load slice unit %s, ignoring: %s", k
, bus_error_message(&error
, r
));
3278 r
= unit_set_slice(u
, slice
);
3280 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to assign slice %s to unit %s, ignoring: %m", slice
->id
, u
->id
);
3287 int config_parse_cpu_quota(
3289 const char *filename
,
3291 const char *section
,
3292 unsigned section_line
,
3299 CGroupContext
*c
= data
;
3306 if (isempty(rvalue
)) {
3307 c
->cpu_quota_per_sec_usec
= USEC_INFINITY
;
3311 r
= parse_permille_unbounded(rvalue
);
3313 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid CPU quota '%s', ignoring.", rvalue
);
3317 c
->cpu_quota_per_sec_usec
= ((usec_t
) r
* USEC_PER_SEC
) / 1000U;
3321 int config_parse_allowed_cpus(
3323 const char *filename
,
3325 const char *section
,
3326 unsigned section_line
,
3333 CGroupContext
*c
= data
;
3335 (void) parse_cpu_set_extend(rvalue
, &c
->cpuset_cpus
, true, unit
, filename
, line
, lvalue
);
3340 int config_parse_allowed_mems(
3342 const char *filename
,
3344 const char *section
,
3345 unsigned section_line
,
3352 CGroupContext
*c
= data
;
3354 (void) parse_cpu_set_extend(rvalue
, &c
->cpuset_mems
, true, unit
, filename
, line
, lvalue
);
3359 int config_parse_memory_limit(
3361 const char *filename
,
3363 const char *section
,
3364 unsigned section_line
,
3371 CGroupContext
*c
= data
;
3372 uint64_t bytes
= CGROUP_LIMIT_MAX
;
3375 if (!isempty(rvalue
) && !streq(rvalue
, "infinity")) {
3377 r
= parse_permille(rvalue
);
3379 r
= parse_size(rvalue
, 1024, &bytes
);
3381 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid memory limit '%s', ignoring: %m", rvalue
);
3385 bytes
= physical_memory_scale(r
, 1000U);
3387 if (bytes
>= UINT64_MAX
||
3388 (bytes
<= 0 && !STR_IN_SET(lvalue
, "MemorySwapMax", "MemoryLow", "MemoryMin", "DefaultMemoryLow", "DefaultMemoryMin"))) {
3389 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Memory limit '%s' out of range, ignoring.", rvalue
);
3394 if (streq(lvalue
, "DefaultMemoryLow")) {
3395 c
->default_memory_low_set
= true;
3396 if (isempty(rvalue
))
3397 c
->default_memory_low
= CGROUP_LIMIT_MIN
;
3399 c
->default_memory_low
= bytes
;
3400 } else if (streq(lvalue
, "DefaultMemoryMin")) {
3401 c
->default_memory_min_set
= true;
3402 if (isempty(rvalue
))
3403 c
->default_memory_min
= CGROUP_LIMIT_MIN
;
3405 c
->default_memory_min
= bytes
;
3406 } else if (streq(lvalue
, "MemoryMin")) {
3407 c
->memory_min
= bytes
;
3408 c
->memory_min_set
= true;
3409 } else if (streq(lvalue
, "MemoryLow")) {
3410 c
->memory_low
= bytes
;
3411 c
->memory_low_set
= true;
3412 } else if (streq(lvalue
, "MemoryHigh"))
3413 c
->memory_high
= bytes
;
3414 else if (streq(lvalue
, "MemoryMax"))
3415 c
->memory_max
= bytes
;
3416 else if (streq(lvalue
, "MemorySwapMax"))
3417 c
->memory_swap_max
= bytes
;
3418 else if (streq(lvalue
, "MemoryLimit"))
3419 c
->memory_limit
= bytes
;
3426 int config_parse_tasks_max(
3428 const char *filename
,
3430 const char *section
,
3431 unsigned section_line
,
3438 const Unit
*u
= userdata
;
3439 TasksMax
*tasks_max
= data
;
3443 if (isempty(rvalue
)) {
3444 *tasks_max
= u
? u
->manager
->default_tasks_max
: TASKS_MAX_UNSET
;
3448 if (streq(rvalue
, "infinity")) {
3449 *tasks_max
= TASKS_MAX_UNSET
;
3453 r
= parse_permille(rvalue
);
3455 *tasks_max
= (TasksMax
) { r
, 1000U }; /* r‰ */
3457 r
= safe_atou64(rvalue
, &v
);
3459 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid maximum tasks value '%s', ignoring: %m", rvalue
);
3463 if (v
<= 0 || v
>= UINT64_MAX
) {
3464 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Maximum tasks value '%s' out of range, ignoring.", rvalue
);
3468 *tasks_max
= (TasksMax
) { v
};
3474 int config_parse_delegate(
3476 const char *filename
,
3478 const char *section
,
3479 unsigned section_line
,
3486 CGroupContext
*c
= data
;
3490 t
= unit_name_to_type(unit
);
3491 assert(t
!= _UNIT_TYPE_INVALID
);
3493 if (!unit_vtable
[t
]->can_delegate
) {
3494 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Delegate= setting not supported for this unit type, ignoring.");
3498 /* We either accept a boolean value, which may be used to turn on delegation for all controllers, or turn it
3499 * off for all. Or it takes a list of controller names, in which case we add the specified controllers to the
3500 * mask to delegate. */
3502 if (isempty(rvalue
)) {
3503 /* An empty string resets controllers and set Delegate=yes. */
3505 c
->delegate_controllers
= 0;
3509 r
= parse_boolean(rvalue
);
3511 const char *p
= rvalue
;
3512 CGroupMask mask
= 0;
3515 _cleanup_free_
char *word
= NULL
;
3516 CGroupController cc
;
3518 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3524 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3528 cc
= cgroup_controller_from_string(word
);
3530 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid controller name '%s', ignoring", word
);
3534 mask
|= CGROUP_CONTROLLER_TO_MASK(cc
);
3538 c
->delegate_controllers
|= mask
;
3542 c
->delegate_controllers
= _CGROUP_MASK_ALL
;
3544 c
->delegate
= false;
3545 c
->delegate_controllers
= 0;
3551 int config_parse_device_allow(
3553 const char *filename
,
3555 const char *section
,
3556 unsigned section_line
,
3563 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3564 CGroupContext
*c
= data
;
3565 const char *p
= rvalue
;
3568 if (isempty(rvalue
)) {
3569 while (c
->device_allow
)
3570 cgroup_context_free_device_allow(c
, c
->device_allow
);
3575 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3579 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3580 "Invalid syntax, ignoring: %s", rvalue
);
3584 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3585 "Failed to extract device path and rights from '%s', ignoring.", rvalue
);
3589 r
= unit_full_printf(userdata
, path
, &resolved
);
3591 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3592 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3596 if (!STARTSWITH_SET(resolved
, "block-", "char-")) {
3598 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3602 if (!valid_device_node_path(resolved
)) {
3603 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device node path '%s', ignoring.", resolved
);
3608 if (!isempty(p
) && !in_charset(p
, "rwm")) {
3609 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device rights '%s', ignoring.", p
);
3613 return cgroup_add_device_allow(c
, resolved
, p
);
3616 int config_parse_io_device_weight(
3618 const char *filename
,
3620 const char *section
,
3621 unsigned section_line
,
3628 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3629 CGroupIODeviceWeight
*w
;
3630 CGroupContext
*c
= data
;
3631 const char *p
= rvalue
;
3639 if (isempty(rvalue
)) {
3640 while (c
->io_device_weights
)
3641 cgroup_context_free_io_device_weight(c
, c
->io_device_weights
);
3646 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3650 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3651 "Invalid syntax, ignoring: %s", rvalue
);
3654 if (r
== 0 || isempty(p
)) {
3655 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3656 "Failed to extract device path and weight from '%s', ignoring.", rvalue
);
3660 r
= unit_full_printf(userdata
, path
, &resolved
);
3662 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3663 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3667 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3671 r
= cg_weight_parse(p
, &u
);
3673 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "IO weight '%s' invalid, ignoring: %m", p
);
3677 assert(u
!= CGROUP_WEIGHT_INVALID
);
3679 w
= new0(CGroupIODeviceWeight
, 1);
3683 w
->path
= TAKE_PTR(resolved
);
3686 LIST_PREPEND(device_weights
, c
->io_device_weights
, w
);
3690 int config_parse_io_device_latency(
3692 const char *filename
,
3694 const char *section
,
3695 unsigned section_line
,
3702 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3703 CGroupIODeviceLatency
*l
;
3704 CGroupContext
*c
= data
;
3705 const char *p
= rvalue
;
3713 if (isempty(rvalue
)) {
3714 while (c
->io_device_latencies
)
3715 cgroup_context_free_io_device_latency(c
, c
->io_device_latencies
);
3720 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3724 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3725 "Invalid syntax, ignoring: %s", rvalue
);
3728 if (r
== 0 || isempty(p
)) {
3729 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3730 "Failed to extract device path and latency from '%s', ignoring.", rvalue
);
3734 r
= unit_full_printf(userdata
, path
, &resolved
);
3736 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3737 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3741 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3745 if (parse_sec(p
, &usec
) < 0) {
3746 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse timer value, ignoring: %s", p
);
3750 l
= new0(CGroupIODeviceLatency
, 1);
3754 l
->path
= TAKE_PTR(resolved
);
3755 l
->target_usec
= usec
;
3757 LIST_PREPEND(device_latencies
, c
->io_device_latencies
, l
);
3761 int config_parse_io_limit(
3763 const char *filename
,
3765 const char *section
,
3766 unsigned section_line
,
3773 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3774 CGroupIODeviceLimit
*l
= NULL
, *t
;
3775 CGroupContext
*c
= data
;
3776 CGroupIOLimitType type
;
3777 const char *p
= rvalue
;
3785 type
= cgroup_io_limit_type_from_string(lvalue
);
3788 if (isempty(rvalue
)) {
3789 LIST_FOREACH(device_limits
, l
, c
->io_device_limits
)
3790 l
->limits
[type
] = cgroup_io_limit_defaults
[type
];
3794 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3798 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3799 "Invalid syntax, ignoring: %s", rvalue
);
3802 if (r
== 0 || isempty(p
)) {
3803 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3804 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
3808 r
= unit_full_printf(userdata
, path
, &resolved
);
3810 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3811 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3815 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3819 if (streq("infinity", p
))
3820 num
= CGROUP_LIMIT_MAX
;
3822 r
= parse_size(p
, 1000, &num
);
3823 if (r
< 0 || num
<= 0) {
3824 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid IO limit '%s', ignoring.", p
);
3829 LIST_FOREACH(device_limits
, t
, c
->io_device_limits
) {
3830 if (path_equal(resolved
, t
->path
)) {
3837 CGroupIOLimitType ttype
;
3839 l
= new0(CGroupIODeviceLimit
, 1);
3843 l
->path
= TAKE_PTR(resolved
);
3844 for (ttype
= 0; ttype
< _CGROUP_IO_LIMIT_TYPE_MAX
; ttype
++)
3845 l
->limits
[ttype
] = cgroup_io_limit_defaults
[ttype
];
3847 LIST_PREPEND(device_limits
, c
->io_device_limits
, l
);
3850 l
->limits
[type
] = num
;
3855 int config_parse_blockio_device_weight(
3857 const char *filename
,
3859 const char *section
,
3860 unsigned section_line
,
3867 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3868 CGroupBlockIODeviceWeight
*w
;
3869 CGroupContext
*c
= data
;
3870 const char *p
= rvalue
;
3878 if (isempty(rvalue
)) {
3879 while (c
->blockio_device_weights
)
3880 cgroup_context_free_blockio_device_weight(c
, c
->blockio_device_weights
);
3885 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3889 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3890 "Invalid syntax, ignoring: %s", rvalue
);
3893 if (r
== 0 || isempty(p
)) {
3894 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3895 "Failed to extract device node and weight from '%s', ignoring.", rvalue
);
3899 r
= unit_full_printf(userdata
, path
, &resolved
);
3901 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3902 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3906 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3910 r
= cg_blkio_weight_parse(p
, &u
);
3912 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid block IO weight '%s', ignoring: %m", p
);
3916 assert(u
!= CGROUP_BLKIO_WEIGHT_INVALID
);
3918 w
= new0(CGroupBlockIODeviceWeight
, 1);
3922 w
->path
= TAKE_PTR(resolved
);
3925 LIST_PREPEND(device_weights
, c
->blockio_device_weights
, w
);
3929 int config_parse_blockio_bandwidth(
3931 const char *filename
,
3933 const char *section
,
3934 unsigned section_line
,
3941 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3942 CGroupBlockIODeviceBandwidth
*b
= NULL
, *t
;
3943 CGroupContext
*c
= data
;
3944 const char *p
= rvalue
;
3953 read
= streq("BlockIOReadBandwidth", lvalue
);
3955 if (isempty(rvalue
)) {
3956 LIST_FOREACH(device_bandwidths
, b
, c
->blockio_device_bandwidths
) {
3957 b
->rbps
= CGROUP_LIMIT_MAX
;
3958 b
->wbps
= CGROUP_LIMIT_MAX
;
3963 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3967 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3968 "Invalid syntax, ignoring: %s", rvalue
);
3971 if (r
== 0 || isempty(p
)) {
3972 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3973 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
3977 r
= unit_full_printf(userdata
, path
, &resolved
);
3979 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3980 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3984 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3988 r
= parse_size(p
, 1000, &bytes
);
3989 if (r
< 0 || bytes
<= 0) {
3990 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid Block IO Bandwidth '%s', ignoring.", p
);
3994 LIST_FOREACH(device_bandwidths
, t
, c
->blockio_device_bandwidths
) {
3995 if (path_equal(resolved
, t
->path
)) {
4002 b
= new0(CGroupBlockIODeviceBandwidth
, 1);
4006 b
->path
= TAKE_PTR(resolved
);
4007 b
->rbps
= CGROUP_LIMIT_MAX
;
4008 b
->wbps
= CGROUP_LIMIT_MAX
;
4010 LIST_PREPEND(device_bandwidths
, c
->blockio_device_bandwidths
, b
);
4021 int config_parse_job_mode_isolate(
4023 const char *filename
,
4025 const char *section
,
4026 unsigned section_line
,
4040 r
= parse_boolean(rvalue
);
4042 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse boolean, ignoring: %s", rvalue
);
4046 log_notice("%s is deprecated. Please use OnFailureJobMode= instead", lvalue
);
4048 *m
= r
? JOB_ISOLATE
: JOB_REPLACE
;
4052 int config_parse_exec_directories(
4054 const char *filename
,
4056 const char *section
,
4057 unsigned section_line
,
4065 const Unit
*u
= userdata
;
4074 if (isempty(rvalue
)) {
4075 /* Empty assignment resets the list */
4076 *rt
= strv_free(*rt
);
4080 for (p
= rvalue
;;) {
4081 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
4083 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
4087 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4088 "Invalid syntax, ignoring: %s", rvalue
);
4094 r
= unit_full_printf(u
, word
, &k
);
4096 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4097 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
4101 r
= path_simplify_and_warn(k
, PATH_CHECK_RELATIVE
, unit
, filename
, line
, lvalue
);
4105 if (path_startswith(k
, "private")) {
4106 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
4107 "%s= path can't be 'private', ignoring assignment: %s", lvalue
, word
);
4111 r
= strv_push(rt
, k
);
4118 int config_parse_set_status(
4120 const char *filename
,
4122 const char *section
,
4123 unsigned section_line
,
4131 const char *word
, *state
;
4133 ExitStatusSet
*status_set
= data
;
4140 /* Empty assignment resets the list */
4141 if (isempty(rvalue
)) {
4142 exit_status_set_free(status_set
);
4146 FOREACH_WORD(word
, l
, rvalue
, state
) {
4147 _cleanup_free_
char *temp
;
4150 temp
= strndup(word
, l
);
4154 /* We need to call exit_status_from_string() first, because we want
4155 * to parse numbers as exit statuses, not signals. */
4157 r
= exit_status_from_string(temp
);
4159 assert(r
>= 0 && r
< 256);
4160 bitmap
= &status_set
->status
;
4162 r
= signal_from_string(temp
);
4165 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
4166 "Failed to parse value, ignoring: %s", word
);
4169 bitmap
= &status_set
->signal
;
4172 r
= bitmap_set(bitmap
, r
);
4174 return log_error_errno(r
, "Failed to set signal or status %s: %m", word
);
4176 if (!isempty(state
))
4177 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Trailing garbage, ignoring.");
4182 int config_parse_namespace_path_strv(
4184 const char *filename
,
4186 const char *section
,
4187 unsigned section_line
,
4194 const Unit
*u
= userdata
;
4196 const char *p
= rvalue
;
4204 if (isempty(rvalue
)) {
4205 /* Empty assignment resets the list */
4206 *sv
= strv_free(*sv
);
4211 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
, *joined
= NULL
;
4213 bool ignore_enoent
= false, shall_prefix
= false;
4215 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
4221 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
4226 if (startswith(w
, "-")) {
4227 ignore_enoent
= true;
4230 if (startswith(w
, "+")) {
4231 shall_prefix
= true;
4235 r
= unit_full_printf(u
, w
, &resolved
);
4237 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", w
);
4241 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4245 joined
= strjoin(ignore_enoent
? "-" : "",
4246 shall_prefix
? "+" : "",
4249 r
= strv_push(sv
, joined
);
4259 int config_parse_temporary_filesystems(
4261 const char *filename
,
4263 const char *section
,
4264 unsigned section_line
,
4271 const Unit
*u
= userdata
;
4272 ExecContext
*c
= data
;
4273 const char *p
= rvalue
;
4281 if (isempty(rvalue
)) {
4282 /* Empty assignment resets the list */
4283 temporary_filesystem_free_many(c
->temporary_filesystems
, c
->n_temporary_filesystems
);
4284 c
->temporary_filesystems
= NULL
;
4285 c
->n_temporary_filesystems
= 0;
4290 _cleanup_free_
char *word
= NULL
, *path
= NULL
, *resolved
= NULL
;
4293 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
4299 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
4304 r
= extract_first_word(&w
, &path
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4308 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", word
);
4312 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid syntax, ignoring: %s", word
);
4316 r
= unit_full_printf(u
, path
, &resolved
);
4318 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", path
);
4322 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4326 r
= temporary_filesystem_add(&c
->temporary_filesystems
, &c
->n_temporary_filesystems
, resolved
, w
);
4332 int config_parse_bind_paths(
4334 const char *filename
,
4336 const char *section
,
4337 unsigned section_line
,
4344 ExecContext
*c
= data
;
4345 const Unit
*u
= userdata
;
4354 if (isempty(rvalue
)) {
4355 /* Empty assignment resets the list */
4356 bind_mount_free_many(c
->bind_mounts
, c
->n_bind_mounts
);
4357 c
->bind_mounts
= NULL
;
4358 c
->n_bind_mounts
= 0;
4364 _cleanup_free_
char *source
= NULL
, *destination
= NULL
;
4365 _cleanup_free_
char *sresolved
= NULL
, *dresolved
= NULL
;
4366 char *s
= NULL
, *d
= NULL
;
4367 bool rbind
= true, ignore_enoent
= false;
4369 r
= extract_first_word(&p
, &source
, ":" WHITESPACE
, EXTRACT_UNQUOTE
|EXTRACT_DONT_COALESCE_SEPARATORS
);
4375 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
4379 r
= unit_full_printf(u
, source
, &sresolved
);
4381 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4382 "Failed to resolved unit specifiers in \"%s\", ignoring: %m", source
);
4388 ignore_enoent
= true;
4392 r
= path_simplify_and_warn(s
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4396 /* Optionally, the destination is specified. */
4397 if (p
&& p
[-1] == ':') {
4398 r
= extract_first_word(&p
, &destination
, ":" WHITESPACE
, EXTRACT_UNQUOTE
|EXTRACT_DONT_COALESCE_SEPARATORS
);
4402 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
4406 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Missing argument after ':', ignoring: %s", s
);
4410 r
= unit_full_printf(u
, destination
, &dresolved
);
4412 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4413 "Failed to resolved specifiers in \"%s\", ignoring: %m", destination
);
4417 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4423 /* Optionally, there's also a short option string specified */
4424 if (p
&& p
[-1] == ':') {
4425 _cleanup_free_
char *options
= NULL
;
4427 r
= extract_first_word(&p
, &options
, NULL
, EXTRACT_UNQUOTE
);
4431 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s: %s", lvalue
, rvalue
);
4435 if (isempty(options
) || streq(options
, "rbind"))
4437 else if (streq(options
, "norbind"))
4440 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid option string, ignoring setting: %s", options
);
4447 r
= bind_mount_add(&c
->bind_mounts
, &c
->n_bind_mounts
,
4451 .read_only
= !!strstr(lvalue
, "ReadOnly"),
4453 .ignore_enoent
= ignore_enoent
,
4462 int config_parse_job_timeout_sec(
4464 const char *filename
,
4466 const char *section
,
4467 unsigned section_line
,
4483 r
= parse_sec_fix_0(rvalue
, &usec
);
4485 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse JobTimeoutSec= parameter, ignoring: %s", rvalue
);
4489 /* If the user explicitly changed JobTimeoutSec= also change JobRunningTimeoutSec=, for compatibility with old
4490 * versions. If JobRunningTimeoutSec= was explicitly set, avoid this however as whatever the user picked should
4493 if (!u
->job_running_timeout_set
)
4494 u
->job_running_timeout
= usec
;
4496 u
->job_timeout
= usec
;
4501 int config_parse_job_running_timeout_sec(
4503 const char *filename
,
4505 const char *section
,
4506 unsigned section_line
,
4522 r
= parse_sec_fix_0(rvalue
, &usec
);
4524 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse JobRunningTimeoutSec= parameter, ignoring: %s", rvalue
);
4528 u
->job_running_timeout
= usec
;
4529 u
->job_running_timeout_set
= true;
4534 int config_parse_emergency_action(
4536 const char *filename
,
4538 const char *section
,
4539 unsigned section_line
,
4547 EmergencyAction
*x
= data
;
4556 m
= ((Unit
*) userdata
)->manager
;
4560 r
= parse_emergency_action(rvalue
, MANAGER_IS_SYSTEM(m
), x
);
4562 if (r
== -EOPNOTSUPP
&& MANAGER_IS_USER(m
)) {
4563 /* Compat mode: remove for systemd 241. */
4565 log_syntax(unit
, LOG_INFO
, filename
, line
, r
,
4566 "%s= in user mode specified as \"%s\", using \"exit-force\" instead.",
4568 *x
= EMERGENCY_ACTION_EXIT_FORCE
;
4572 if (r
== -EOPNOTSUPP
)
4573 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4574 "%s= specified as %s mode action, ignoring: %s",
4575 lvalue
, MANAGER_IS_SYSTEM(m
) ? "user" : "system", rvalue
);
4577 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4578 "Failed to parse %s=, ignoring: %s", lvalue
, rvalue
);
4585 int config_parse_pid_file(
4587 const char *filename
,
4589 const char *section
,
4590 unsigned section_line
,
4597 _cleanup_free_
char *k
= NULL
, *n
= NULL
;
4598 const Unit
*u
= userdata
;
4607 if (isempty(rvalue
)) {
4608 /* An empty assignment removes already set value. */
4613 r
= unit_full_printf(u
, rvalue
, &k
);
4615 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
4619 /* If this is a relative path make it absolute by prefixing the /run */
4620 n
= path_make_absolute(k
, u
->manager
->prefix
[EXEC_DIRECTORY_RUNTIME
]);
4624 /* Check that the result is a sensible path */
4625 r
= path_simplify_and_warn(n
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4629 r
= patch_var_run(unit
, filename
, line
, lvalue
, &n
);
4633 free_and_replace(*s
, n
);
4637 int config_parse_exit_status(
4639 const char *filename
,
4641 const char *section
,
4642 unsigned section_line
,
4649 int *exit_status
= data
, r
;
4655 assert(exit_status
);
4657 if (isempty(rvalue
)) {
4662 r
= safe_atou8(rvalue
, &u
);
4664 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse exit status '%s', ignoring: %m", rvalue
);
4672 int config_parse_disable_controllers(
4674 const char *filename
,
4676 const char *section
,
4677 unsigned section_line
,
4685 CGroupContext
*c
= data
;
4686 CGroupMask disabled_mask
;
4688 /* 1. If empty, make all controllers eligible for use again.
4689 * 2. If non-empty, merge all listed controllers, space separated. */
4691 if (isempty(rvalue
)) {
4692 c
->disable_controllers
= 0;
4696 r
= cg_mask_from_string(rvalue
, &disabled_mask
);
4697 if (r
< 0 || disabled_mask
<= 0) {
4698 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid cgroup string: %s, ignoring", rvalue
);
4702 c
->disable_controllers
|= disabled_mask
;
4707 int config_parse_ip_filter_bpf_progs(
4709 const char *filename
,
4711 const char *section
,
4712 unsigned section_line
,
4719 _cleanup_free_
char *resolved
= NULL
;
4720 const Unit
*u
= userdata
;
4721 char ***paths
= data
;
4729 if (isempty(rvalue
)) {
4730 *paths
= strv_free(*paths
);
4734 r
= unit_full_printf(u
, rvalue
, &resolved
);
4736 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
4740 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4744 if (strv_contains(*paths
, resolved
))
4747 r
= strv_extend(paths
, resolved
);
4751 r
= bpf_firewall_supported();
4754 if (r
!= BPF_FIREWALL_SUPPORTED_WITH_MULTI
) {
4755 static bool warned
= false;
4757 log_full(warned
? LOG_DEBUG
: LOG_WARNING
,
4758 "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"
4759 "Starting this unit will fail! (This warning is only shown for the first loaded unit using IP firewalling.)", filename
, line
, lvalue
, rvalue
);
4767 static int merge_by_names(Unit
**u
, Set
*names
, const char *id
) {
4774 /* Let's try to add in all names that are aliases of this unit */
4775 while ((k
= set_steal_first(names
))) {
4776 _cleanup_free_ _unused_
char *free_k
= k
;
4778 /* First try to merge in the other name into our unit */
4779 r
= unit_merge_by_name(*u
, k
);
4783 /* Hmm, we couldn't merge the other unit into ours? Then let's try it the other way
4786 other
= manager_get_unit((*u
)->manager
, k
);
4788 return r
; /* return previous failure */
4790 r
= unit_merge(other
, *u
);
4795 return merge_by_names(u
, names
, NULL
);
4798 if (streq_ptr(id
, k
))
4799 unit_choose_id(*u
, id
);
4805 int unit_load_fragment(Unit
*u
) {
4806 const char *fragment
;
4807 _cleanup_set_free_free_ Set
*names
= NULL
;
4811 assert(u
->load_state
== UNIT_STUB
);
4815 u
->load_state
= UNIT_LOADED
;
4819 /* Possibly rebuild the fragment map to catch new units */
4820 r
= unit_file_build_name_map(&u
->manager
->lookup_paths
,
4821 &u
->manager
->unit_cache_mtime
,
4822 &u
->manager
->unit_id_map
,
4823 &u
->manager
->unit_name_map
,
4824 &u
->manager
->unit_path_cache
);
4826 return log_error_errno(r
, "Failed to rebuild name map: %m");
4828 r
= unit_file_find_fragment(u
->manager
->unit_id_map
,
4829 u
->manager
->unit_name_map
,
4833 if (r
< 0 && r
!= -ENOENT
)
4837 /* Open the file, check if this is a mask, otherwise read. */
4838 _cleanup_fclose_
FILE *f
= NULL
;
4841 /* Try to open the file name. A symlink is OK, for example for linked files or masks. We
4842 * expect that all symlinks within the lookup paths have been already resolved, but we don't
4843 * verify this here. */
4844 f
= fopen(fragment
, "re");
4846 return log_unit_notice_errno(u
, errno
, "Failed to open %s: %m", fragment
);
4848 if (fstat(fileno(f
), &st
) < 0)
4851 r
= free_and_strdup(&u
->fragment_path
, fragment
);
4855 if (null_or_empty(&st
)) {
4856 /* Unit file is masked */
4858 u
->load_state
= u
->perpetual
? UNIT_LOADED
: UNIT_MASKED
; /* don't allow perpetual units to ever be masked */
4859 u
->fragment_mtime
= 0;
4861 u
->load_state
= UNIT_LOADED
;
4862 u
->fragment_mtime
= timespec_load(&st
.st_mtim
);
4864 /* Now, parse the file contents */
4865 r
= config_parse(u
->id
, fragment
, f
,
4866 UNIT_VTABLE(u
)->sections
,
4867 config_item_perf_lookup
, load_fragment_gperf_lookup
,
4872 log_unit_notice_errno(u
, r
, "Unit configuration has fatal error, unit will not be started.");
4878 /* We do the merge dance here because for some unit types, the unit might have aliases which are not
4879 * declared in the file system. In particular, this is true (and frequent) for device and swap units.
4882 const char *id
= u
->id
;
4883 _cleanup_free_
char *free_id
= NULL
;
4886 id
= basename(fragment
);
4887 if (unit_name_is_valid(id
, UNIT_NAME_TEMPLATE
)) {
4888 assert(u
->instance
); /* If we're not trying to use a template for non-instanced unit,
4889 * this must be set. */
4891 r
= unit_name_replace_instance(id
, u
->instance
, &free_id
);
4893 return log_debug_errno(r
, "Failed to build id (%s + %s): %m", id
, u
->instance
);
4899 r
= merge_by_names(&merged
, names
, id
);
4904 u
->load_state
= UNIT_MERGED
;
4909 void unit_dump_config_items(FILE *f
) {
4910 static const struct {
4911 const ConfigParserCallback callback
;
4914 { config_parse_warn_compat
, "NOTSUPPORTED" },
4915 { config_parse_int
, "INTEGER" },
4916 { config_parse_unsigned
, "UNSIGNED" },
4917 { config_parse_iec_size
, "SIZE" },
4918 { config_parse_iec_uint64
, "SIZE" },
4919 { config_parse_si_uint64
, "SIZE" },
4920 { config_parse_bool
, "BOOLEAN" },
4921 { config_parse_string
, "STRING" },
4922 { config_parse_path
, "PATH" },
4923 { config_parse_unit_path_printf
, "PATH" },
4924 { config_parse_strv
, "STRING [...]" },
4925 { config_parse_exec_nice
, "NICE" },
4926 { config_parse_exec_oom_score_adjust
, "OOMSCOREADJUST" },
4927 { config_parse_exec_io_class
, "IOCLASS" },
4928 { config_parse_exec_io_priority
, "IOPRIORITY" },
4929 { config_parse_exec_cpu_sched_policy
, "CPUSCHEDPOLICY" },
4930 { config_parse_exec_cpu_sched_prio
, "CPUSCHEDPRIO" },
4931 { config_parse_exec_cpu_affinity
, "CPUAFFINITY" },
4932 { config_parse_mode
, "MODE" },
4933 { config_parse_unit_env_file
, "FILE" },
4934 { config_parse_exec_output
, "OUTPUT" },
4935 { config_parse_exec_input
, "INPUT" },
4936 { config_parse_log_facility
, "FACILITY" },
4937 { config_parse_log_level
, "LEVEL" },
4938 { config_parse_exec_secure_bits
, "SECUREBITS" },
4939 { config_parse_capability_set
, "BOUNDINGSET" },
4940 { config_parse_rlimit
, "LIMIT" },
4941 { config_parse_unit_deps
, "UNIT [...]" },
4942 { config_parse_exec
, "PATH [ARGUMENT [...]]" },
4943 { config_parse_service_type
, "SERVICETYPE" },
4944 { config_parse_service_restart
, "SERVICERESTART" },
4945 { config_parse_service_timeout_failure_mode
, "TIMEOUTMODE" },
4946 { config_parse_kill_mode
, "KILLMODE" },
4947 { config_parse_signal
, "SIGNAL" },
4948 { config_parse_socket_listen
, "SOCKET [...]" },
4949 { config_parse_socket_bind
, "SOCKETBIND" },
4950 { config_parse_socket_bindtodevice
, "NETWORKINTERFACE" },
4951 { config_parse_sec
, "SECONDS" },
4952 { config_parse_nsec
, "NANOSECONDS" },
4953 { config_parse_namespace_path_strv
, "PATH [...]" },
4954 { config_parse_bind_paths
, "PATH[:PATH[:OPTIONS]] [...]" },
4955 { config_parse_unit_requires_mounts_for
, "PATH [...]" },
4956 { config_parse_exec_mount_flags
, "MOUNTFLAG [...]" },
4957 { config_parse_unit_string_printf
, "STRING" },
4958 { config_parse_trigger_unit
, "UNIT" },
4959 { config_parse_timer
, "TIMER" },
4960 { config_parse_path_spec
, "PATH" },
4961 { config_parse_notify_access
, "ACCESS" },
4962 { config_parse_ip_tos
, "TOS" },
4963 { config_parse_unit_condition_path
, "CONDITION" },
4964 { config_parse_unit_condition_string
, "CONDITION" },
4965 { config_parse_unit_condition_null
, "CONDITION" },
4966 { config_parse_unit_slice
, "SLICE" },
4967 { config_parse_documentation
, "URL" },
4968 { config_parse_service_timeout
, "SECONDS" },
4969 { config_parse_emergency_action
, "ACTION" },
4970 { config_parse_set_status
, "STATUS" },
4971 { config_parse_service_sockets
, "SOCKETS" },
4972 { config_parse_environ
, "ENVIRON" },
4974 { config_parse_syscall_filter
, "SYSCALLS" },
4975 { config_parse_syscall_archs
, "ARCHS" },
4976 { config_parse_syscall_errno
, "ERRNO" },
4977 { config_parse_address_families
, "FAMILIES" },
4978 { config_parse_restrict_namespaces
, "NAMESPACES" },
4980 { config_parse_cpu_shares
, "SHARES" },
4981 { config_parse_cg_weight
, "WEIGHT" },
4982 { config_parse_memory_limit
, "LIMIT" },
4983 { config_parse_device_allow
, "DEVICE" },
4984 { config_parse_device_policy
, "POLICY" },
4985 { config_parse_io_limit
, "LIMIT" },
4986 { config_parse_io_device_weight
, "DEVICEWEIGHT" },
4987 { config_parse_io_device_latency
, "DEVICELATENCY" },
4988 { config_parse_blockio_bandwidth
, "BANDWIDTH" },
4989 { config_parse_blockio_weight
, "WEIGHT" },
4990 { config_parse_blockio_device_weight
, "DEVICEWEIGHT" },
4991 { config_parse_long
, "LONG" },
4992 { config_parse_socket_service
, "SERVICE" },
4994 { config_parse_exec_selinux_context
, "LABEL" },
4996 { config_parse_job_mode
, "MODE" },
4997 { config_parse_job_mode_isolate
, "BOOLEAN" },
4998 { config_parse_personality
, "PERSONALITY" },
5001 const char *prev
= NULL
;
5006 NULSTR_FOREACH(i
, load_fragment_gperf_nulstr
) {
5007 const char *rvalue
= "OTHER", *lvalue
;
5008 const ConfigPerfItem
*p
;
5013 assert_se(p
= load_fragment_gperf_lookup(i
, strlen(i
)));
5015 /* Hide legacy settings */
5016 if (p
->parse
== config_parse_warn_compat
&&
5017 p
->ltype
== DISABLED_LEGACY
)
5020 for (j
= 0; j
< ELEMENTSOF(table
); j
++)
5021 if (p
->parse
== table
[j
].callback
) {
5022 rvalue
= table
[j
].rvalue
;
5026 dot
= strchr(i
, '.');
5027 lvalue
= dot
? dot
+ 1 : i
;
5031 if (!prev
|| !strneq(prev
, i
, prefix_len
+1)) {
5035 fprintf(f
, "[%.*s]\n", (int) prefix_len
, i
);
5038 fprintf(f
, "%s=%s\n", lvalue
, rvalue
);
5043 int config_parse_cpu_affinity2(
5045 const char *filename
,
5047 const char *section
,
5048 unsigned section_line
,
5055 CPUSet
*affinity
= data
;
5059 (void) parse_cpu_set_extend(rvalue
, affinity
, true, unit
, filename
, line
, lvalue
);
5064 int config_parse_show_status(
5066 const char *filename
,
5068 const char *section
,
5069 unsigned section_line
,
5077 ShowStatus
*b
= data
;
5084 k
= parse_show_status(rvalue
, b
);
5086 log_syntax(unit
, LOG_ERR
, filename
, line
, k
, "Failed to parse show status setting, ignoring: %s", rvalue
);
5093 int config_parse_output_restricted(
5095 const char *filename
,
5097 const char *section
,
5098 unsigned section_line
,
5105 ExecOutput t
, *eo
= data
;
5106 bool obsolete
= false;
5113 if (streq(rvalue
, "syslog")) {
5114 t
= EXEC_OUTPUT_JOURNAL
;
5116 } else if (streq(rvalue
, "syslog+console")) {
5117 t
= EXEC_OUTPUT_JOURNAL_AND_CONSOLE
;
5120 t
= exec_output_from_string(rvalue
);
5122 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse output type, ignoring: %s", rvalue
);
5126 if (IN_SET(t
, EXEC_OUTPUT_SOCKET
, EXEC_OUTPUT_NAMED_FD
, EXEC_OUTPUT_FILE
, EXEC_OUTPUT_FILE_APPEND
)) {
5127 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Standard output types socket, fd:, file:, append: are not supported as defaults, ignoring: %s", rvalue
);
5133 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
5134 "Standard output type %s is obsolete, automatically updating to %s. Please update your configuration.",
5135 rvalue
, exec_output_to_string(t
));
5141 int config_parse_crash_chvt(
5143 const char *filename
,
5145 const char *section
,
5146 unsigned section_line
,
5160 r
= parse_crash_chvt(rvalue
, data
);
5162 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse CrashChangeVT= setting, ignoring: %s", rvalue
);
5169 int config_parse_swap_priority(
5171 const char *filename
,
5173 const char *section
,
5174 unsigned section_line
,
5190 if (isempty(rvalue
)) {
5191 s
->parameters_fragment
.priority
= -1;
5192 s
->parameters_fragment
.priority_set
= false;
5196 r
= safe_atoi(rvalue
, &priority
);
5198 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid swap priority '%s', ignoring.", rvalue
);
5202 if (priority
< -1) {
5203 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
);
5207 if (priority
> 32767) {
5208 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Swap priority out of range, ignoring: %s", rvalue
);
5212 s
->parameters_fragment
.priority
= priority
;
5213 s
->parameters_fragment
.priority_set
= true;