1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 Copyright © 2012 Holger Hans Peter Freyther
14 #include <sys/resource.h>
17 #include "alloc-util.h"
18 #include "all-units.h"
19 #include "bpf-firewall.h"
20 #include "bus-error.h"
21 #include "bus-internal.h"
24 #include "capability-util.h"
25 #include "cgroup-setup.h"
26 #include "conf-parser.h"
27 #include "cpu-set-util.h"
29 #include "errno-list.h"
33 #include "hexdecoct.h"
36 #include "ip-protocol-list.h"
37 #include "journal-util.h"
38 #include "limits-util.h"
39 #include "load-fragment.h"
41 #include "mountpoint-util.h"
42 #include "nulstr-util.h"
43 #include "parse-util.h"
44 #include "path-util.h"
45 #include "process-util.h"
47 #include "seccomp-util.h"
49 #include "securebits-util.h"
50 #include "signal-util.h"
51 #include "socket-netlink.h"
52 #include "stat-util.h"
53 #include "string-util.h"
55 #include "syslog-util.h"
56 #include "time-util.h"
57 #include "unit-name.h"
58 #include "unit-printf.h"
59 #include "user-util.h"
62 static int parse_socket_protocol(const char *s
) {
65 r
= parse_ip_protocol(s
);
68 if (!IN_SET(r
, IPPROTO_UDPLITE
, IPPROTO_SCTP
))
69 return -EPROTONOSUPPORT
;
74 int parse_crash_chvt(const char *value
, int *data
) {
77 if (safe_atoi(value
, data
) >= 0)
80 b
= parse_boolean(value
);
85 *data
= 0; /* switch to where kmsg goes */
87 *data
= -1; /* turn off switching */
92 int parse_confirm_spawn(const char *value
, char **console
) {
96 r
= value
? parse_boolean(value
) : 1;
100 } else if (r
> 0) /* on with default tty */
101 s
= strdup("/dev/console");
102 else if (is_path(value
)) /* on with fully qualified path */
104 else /* on with only a tty file name, not a fully qualified path */
105 s
= path_join("/dev/", value
);
113 DEFINE_CONFIG_PARSE(config_parse_socket_protocol
, parse_socket_protocol
, "Failed to parse socket protocol");
114 DEFINE_CONFIG_PARSE(config_parse_exec_secure_bits
, secure_bits_from_string
, "Failed to parse secure bits");
115 DEFINE_CONFIG_PARSE_ENUM(config_parse_collect_mode
, collect_mode
, CollectMode
, "Failed to parse garbage collection mode");
116 DEFINE_CONFIG_PARSE_ENUM(config_parse_device_policy
, cgroup_device_policy
, CGroupDevicePolicy
, "Failed to parse device policy");
117 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_keyring_mode
, exec_keyring_mode
, ExecKeyringMode
, "Failed to parse keyring mode");
118 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_utmp_mode
, exec_utmp_mode
, ExecUtmpMode
, "Failed to parse utmp mode");
119 DEFINE_CONFIG_PARSE_ENUM(config_parse_job_mode
, job_mode
, JobMode
, "Failed to parse job mode");
120 DEFINE_CONFIG_PARSE_ENUM(config_parse_kill_mode
, kill_mode
, KillMode
, "Failed to parse kill mode");
121 DEFINE_CONFIG_PARSE_ENUM(config_parse_notify_access
, notify_access
, NotifyAccess
, "Failed to parse notify access specifier");
122 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_home
, protect_home
, ProtectHome
, "Failed to parse protect home value");
123 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_system
, protect_system
, ProtectSystem
, "Failed to parse protect system value");
124 DEFINE_CONFIG_PARSE_ENUM(config_parse_runtime_preserve_mode
, exec_preserve_mode
, ExecPreserveMode
, "Failed to parse runtime directory preserve mode");
125 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_type
, service_type
, ServiceType
, "Failed to parse service type");
126 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart
, service_restart
, ServiceRestart
, "Failed to parse service restart specifier");
127 DEFINE_CONFIG_PARSE_ENUM(config_parse_socket_bind
, socket_address_bind_ipv6_only_or_bool
, SocketAddressBindIPv6Only
, "Failed to parse bind IPv6 only value");
128 DEFINE_CONFIG_PARSE_ENUM(config_parse_oom_policy
, oom_policy
, OOMPolicy
, "Failed to parse OOM policy");
129 DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_ip_tos
, ip_tos
, int, -1, "Failed to parse IP TOS value");
130 DEFINE_CONFIG_PARSE_PTR(config_parse_blockio_weight
, cg_blkio_weight_parse
, uint64_t, "Invalid block IO weight");
131 DEFINE_CONFIG_PARSE_PTR(config_parse_cg_weight
, cg_weight_parse
, uint64_t, "Invalid weight");
132 DEFINE_CONFIG_PARSE_PTR(config_parse_cpu_shares
, cg_cpu_shares_parse
, uint64_t, "Invalid CPU shares");
133 DEFINE_CONFIG_PARSE_PTR(config_parse_exec_mount_flags
, mount_propagation_flags_from_string
, unsigned long, "Failed to parse mount flag");
134 DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_numa_policy
, mpol
, int, -1, "Invalid NUMA policy type");
135 DEFINE_CONFIG_PARSE_ENUM(config_parse_status_unit_format
, status_unit_format
, StatusUnitFormat
, "Failed to parse status unit format");
137 int config_parse_unit_deps(
139 const char *filename
,
142 unsigned section_line
,
149 UnitDependency d
= ltype
;
159 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
162 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_RETAIN_ESCAPE
);
168 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
172 r
= unit_name_printf(u
, word
, &k
);
174 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
178 r
= unit_add_dependency_by_name(u
, d
, k
, true, UNIT_DEPENDENCY_FILE
);
180 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
186 int config_parse_obsolete_unit_deps(
188 const char *filename
,
191 unsigned section_line
,
198 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
199 "Unit dependency type %s= is obsolete, replacing by %s=, please update your unit file", lvalue
, unit_dependency_to_string(ltype
));
201 return config_parse_unit_deps(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
);
204 int config_parse_unit_string_printf(
206 const char *filename
,
209 unsigned section_line
,
216 _cleanup_free_
char *k
= NULL
;
217 const Unit
*u
= userdata
;
225 r
= unit_full_printf(u
, rvalue
, &k
);
227 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
231 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
234 int config_parse_unit_strv_printf(
236 const char *filename
,
239 unsigned section_line
,
246 const Unit
*u
= userdata
;
247 _cleanup_free_
char *k
= NULL
;
255 r
= unit_full_printf(u
, rvalue
, &k
);
257 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
261 return config_parse_strv(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
264 int config_parse_unit_path_printf(
266 const char *filename
,
269 unsigned section_line
,
276 _cleanup_free_
char *k
= NULL
;
277 const Unit
*u
= userdata
;
286 /* Let's not bother with anything that is too long */
287 if (strlen(rvalue
) >= PATH_MAX
) {
288 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
289 "%s value too long%s.",
290 lvalue
, fatal
? "" : ", ignoring");
291 return fatal
? -ENAMETOOLONG
: 0;
294 r
= unit_full_printf(u
, rvalue
, &k
);
296 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
297 "Failed to resolve unit specifiers in '%s'%s: %m",
298 rvalue
, fatal
? "" : ", ignoring");
299 return fatal
? -ENOEXEC
: 0;
302 return config_parse_path(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
305 int config_parse_unit_path_strv_printf(
307 const char *filename
,
310 unsigned section_line
,
318 const Unit
*u
= userdata
;
327 if (isempty(rvalue
)) {
333 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
335 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
341 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
342 "Invalid syntax, ignoring: %s", rvalue
);
346 r
= unit_full_printf(u
, word
, &k
);
348 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
349 "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
353 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
357 r
= strv_consume(x
, TAKE_PTR(k
));
363 static int patch_var_run(
365 const char *filename
,
373 e
= path_startswith(*path
, "/var/run/");
377 z
= path_join("/run/", e
);
381 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
382 "%s= references a path below legacy directory /var/run/, updating %s → %s; "
383 "please update the unit file accordingly.", lvalue
, *path
, z
);
385 free_and_replace(*path
, z
);
390 int config_parse_socket_listen(
392 const char *filename
,
395 unsigned section_line
,
402 _cleanup_free_ SocketPort
*p
= NULL
;
414 if (isempty(rvalue
)) {
415 /* An empty assignment removes all ports */
416 socket_free_ports(s
);
420 p
= new0(SocketPort
, 1);
424 if (ltype
!= SOCKET_SOCKET
) {
425 _cleanup_free_
char *k
= NULL
;
427 r
= unit_full_printf(UNIT(s
), rvalue
, &k
);
429 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
433 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
437 if (ltype
== SOCKET_FIFO
) {
438 r
= patch_var_run(unit
, filename
, line
, lvalue
, &k
);
443 free_and_replace(p
->path
, k
);
446 } else if (streq(lvalue
, "ListenNetlink")) {
447 _cleanup_free_
char *k
= NULL
;
449 r
= unit_full_printf(UNIT(s
), rvalue
, &k
);
451 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
455 r
= socket_address_parse_netlink(&p
->address
, k
);
457 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse address value in '%s', ignoring: %m", k
);
461 p
->type
= SOCKET_SOCKET
;
464 _cleanup_free_
char *k
= NULL
;
466 r
= unit_full_printf(UNIT(s
), rvalue
, &k
);
468 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
472 if (k
[0] == '/') { /* Only for AF_UNIX file system sockets… */
473 r
= patch_var_run(unit
, filename
, line
, lvalue
, &k
);
478 r
= socket_address_parse_and_warn(&p
->address
, k
);
480 if (r
!= -EAFNOSUPPORT
)
481 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse address value in '%s', ignoring: %m", k
);
485 if (streq(lvalue
, "ListenStream"))
486 p
->address
.type
= SOCK_STREAM
;
487 else if (streq(lvalue
, "ListenDatagram"))
488 p
->address
.type
= SOCK_DGRAM
;
490 assert(streq(lvalue
, "ListenSequentialPacket"));
491 p
->address
.type
= SOCK_SEQPACKET
;
494 if (socket_address_family(&p
->address
) != AF_LOCAL
&& p
->address
.type
== SOCK_SEQPACKET
) {
495 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Address family not supported, ignoring: %s", rvalue
);
499 p
->type
= SOCKET_SOCKET
;
503 p
->auxiliary_fds
= NULL
;
504 p
->n_auxiliary_fds
= 0;
507 LIST_FIND_TAIL(port
, s
->ports
, tail
);
508 LIST_INSERT_AFTER(port
, s
->ports
, tail
, p
);
515 int config_parse_exec_nice(
517 const char *filename
,
520 unsigned section_line
,
527 ExecContext
*c
= data
;
535 if (isempty(rvalue
)) {
540 r
= parse_nice(rvalue
, &priority
);
543 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Nice priority out of range, ignoring: %s", rvalue
);
545 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse nice priority '%s', ignoring: %m", rvalue
);
555 int config_parse_exec_oom_score_adjust(
557 const char *filename
,
560 unsigned section_line
,
567 ExecContext
*c
= data
;
575 if (isempty(rvalue
)) {
576 c
->oom_score_adjust_set
= false;
580 r
= parse_oom_score_adjust(rvalue
, &oa
);
583 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "OOM score adjust value out of range, ignoring: %s", rvalue
);
585 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse the OOM score adjust value '%s', ignoring: %m", rvalue
);
589 c
->oom_score_adjust
= oa
;
590 c
->oom_score_adjust_set
= true;
595 int config_parse_exec_coredump_filter(
597 const char *filename
,
600 unsigned section_line
,
607 ExecContext
*c
= data
;
615 if (isempty(rvalue
)) {
616 c
->coredump_filter
= 0;
617 c
->coredump_filter_set
= false;
622 r
= coredump_filter_mask_from_string(rvalue
, &f
);
624 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
625 "Failed to parse the CoredumpFilter=%s, ignoring: %m", rvalue
);
629 c
->coredump_filter
|= f
;
630 c
->oom_score_adjust_set
= true;
634 int config_parse_exec(
636 const char *filename
,
639 unsigned section_line
,
646 ExecCommand
**e
= data
;
647 const Unit
*u
= userdata
;
659 if (isempty(rvalue
)) {
660 /* An empty assignment resets the list */
661 *e
= exec_command_free_list(*e
);
667 _cleanup_free_
char *path
= NULL
, *firstword
= NULL
;
668 ExecCommandFlags flags
= 0;
669 bool ignore
= false, separate_argv0
= false;
670 _cleanup_free_ ExecCommand
*nce
= NULL
;
671 _cleanup_strv_free_
char **n
= NULL
;
672 size_t nlen
= 0, nbufsize
= 0;
677 r
= extract_first_word_and_warn(&p
, &firstword
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
683 /* We accept an absolute path as first argument. If it's prefixed with - and the path doesn't
684 * exist, we ignore it instead of erroring out; if it's prefixed with @, we allow overriding of
685 * argv[0]; if it's prefixed with :, we will not do environment variable substitution;
686 * if it's prefixed with +, it will be run with full privileges and no sandboxing; if
687 * it's prefixed with '!' we apply sandboxing, but do not change user/group credentials; if
688 * it's prefixed with '!!', then we apply user/group credentials if the kernel supports ambient
689 * capabilities -- if it doesn't we don't apply the credentials themselves, but do apply most
690 * other sandboxing, with some special exceptions for changing UID.
692 * The idea is that '!!' may be used to write services that can take benefit of systemd's
693 * UID/GID dropping if the kernel supports ambient creds, but provide an automatic fallback to
694 * privilege dropping within the daemon if the kernel does not offer that. */
696 if (*f
== '-' && !(flags
& EXEC_COMMAND_IGNORE_FAILURE
)) {
697 flags
|= EXEC_COMMAND_IGNORE_FAILURE
;
699 } else if (*f
== '@' && !separate_argv0
)
700 separate_argv0
= true;
701 else if (*f
== ':' && !(flags
& EXEC_COMMAND_NO_ENV_EXPAND
))
702 flags
|= EXEC_COMMAND_NO_ENV_EXPAND
;
703 else if (*f
== '+' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
704 flags
|= EXEC_COMMAND_FULLY_PRIVILEGED
;
705 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
706 flags
|= EXEC_COMMAND_NO_SETUID
;
707 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_AMBIENT_MAGIC
))) {
708 flags
&= ~EXEC_COMMAND_NO_SETUID
;
709 flags
|= EXEC_COMMAND_AMBIENT_MAGIC
;
715 r
= unit_full_printf(u
, f
, &path
);
717 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
718 "Failed to resolve unit specifiers in '%s'%s: %m",
719 f
, ignore
? ", ignoring" : "");
720 return ignore
? 0 : -ENOEXEC
;
724 /* First word is either "-" or "@" with no command. */
725 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
726 "Empty path in command line%s: '%s'",
727 ignore
? ", ignoring" : "", rvalue
);
728 return ignore
? 0 : -ENOEXEC
;
730 if (!string_is_safe(path
)) {
731 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
732 "Executable name contains special characters%s: %s",
733 ignore
? ", ignoring" : "", path
);
734 return ignore
? 0 : -ENOEXEC
;
736 if (endswith(path
, "/")) {
737 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
738 "Executable path specifies a directory%s: %s",
739 ignore
? ", ignoring" : "", path
);
740 return ignore
? 0 : -ENOEXEC
;
743 if (!path_is_absolute(path
)) {
747 if (!filename_is_valid(path
)) {
748 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
749 "Neither a valid executable name nor an absolute path%s: %s",
750 ignore
? ", ignoring" : "", path
);
751 return ignore
? 0 : -ENOEXEC
;
754 /* Resolve a single-component name to a full path */
755 NULSTR_FOREACH(prefix
, DEFAULT_PATH_NULSTR
) {
756 _cleanup_free_
char *fullpath
= NULL
;
758 fullpath
= path_join(prefix
, path
);
762 if (access(fullpath
, F_OK
) >= 0) {
763 free_and_replace(path
, fullpath
);
770 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
771 "Executable \"%s\" not found in path \"%s\"%s",
772 path
, DEFAULT_PATH
, ignore
? ", ignoring" : "");
773 return ignore
? 0 : -ENOEXEC
;
777 if (!separate_argv0
) {
780 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
790 path_simplify(path
, false);
792 while (!isempty(p
)) {
793 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
795 /* Check explicitly for an unquoted semicolon as
796 * command separator token. */
797 if (p
[0] == ';' && (!p
[1] || strchr(WHITESPACE
, p
[1]))) {
799 p
+= strspn(p
, WHITESPACE
);
804 /* Check for \; explicitly, to not confuse it with \\; or "\;" or "\\;" etc.
805 * extract_first_word() would return the same for all of those. */
806 if (p
[0] == '\\' && p
[1] == ';' && (!p
[2] || strchr(WHITESPACE
, p
[2]))) {
810 p
+= strspn(p
, WHITESPACE
);
812 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
823 r
= extract_first_word_and_warn(&p
, &word
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
827 return ignore
? 0 : -ENOEXEC
;
829 r
= unit_full_printf(u
, word
, &resolved
);
831 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
832 "Failed to resolve unit specifiers in %s%s: %m",
833 word
, ignore
? ", ignoring" : "");
834 return ignore
? 0 : -ENOEXEC
;
837 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
840 n
[nlen
++] = TAKE_PTR(resolved
);
845 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
846 "Empty executable name or zeroeth argument%s: %s",
847 ignore
? ", ignoring" : "", rvalue
);
848 return ignore
? 0 : -ENOEXEC
;
851 nce
= new0(ExecCommand
, 1);
855 nce
->argv
= TAKE_PTR(n
);
856 nce
->path
= TAKE_PTR(path
);
859 exec_command_append_list(e
, nce
);
861 /* Do not _cleanup_free_ these. */
870 int config_parse_socket_bindtodevice(
872 const char *filename
,
875 unsigned section_line
,
889 if (isempty(rvalue
) || streq(rvalue
, "*")) {
890 s
->bind_to_device
= mfree(s
->bind_to_device
);
894 if (!ifname_valid(rvalue
)) {
895 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid interface name, ignoring: %s", rvalue
);
899 if (free_and_strdup(&s
->bind_to_device
, rvalue
) < 0)
905 int config_parse_exec_input(
907 const char *filename
,
910 unsigned section_line
,
917 ExecContext
*c
= data
;
918 const Unit
*u
= userdata
;
928 n
= startswith(rvalue
, "fd:");
930 _cleanup_free_
char *resolved
= NULL
;
932 r
= unit_full_printf(u
, n
, &resolved
);
934 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s': %m", n
);
936 if (isempty(resolved
))
937 resolved
= mfree(resolved
);
938 else if (!fdname_is_valid(resolved
)) {
939 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name: %s", resolved
);
943 free_and_replace(c
->stdio_fdname
[STDIN_FILENO
], resolved
);
945 ei
= EXEC_INPUT_NAMED_FD
;
947 } else if ((n
= startswith(rvalue
, "file:"))) {
948 _cleanup_free_
char *resolved
= NULL
;
950 r
= unit_full_printf(u
, n
, &resolved
);
952 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s': %m", n
);
954 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
958 free_and_replace(c
->stdio_file
[STDIN_FILENO
], resolved
);
960 ei
= EXEC_INPUT_FILE
;
963 ei
= exec_input_from_string(rvalue
);
965 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse input specifier, ignoring: %s", rvalue
);
974 int config_parse_exec_input_text(
976 const char *filename
,
979 unsigned section_line
,
986 _cleanup_free_
char *unescaped
= NULL
, *resolved
= NULL
;
987 ExecContext
*c
= data
;
988 const Unit
*u
= userdata
;
998 if (isempty(rvalue
)) {
999 /* Reset if the empty string is assigned */
1000 c
->stdin_data
= mfree(c
->stdin_data
);
1001 c
->stdin_data_size
= 0;
1005 r
= cunescape(rvalue
, 0, &unescaped
);
1007 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to decode C escaped text '%s': %m", rvalue
);
1009 r
= unit_full_printf(u
, unescaped
, &resolved
);
1011 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s': %m", unescaped
);
1013 sz
= strlen(resolved
);
1014 if (c
->stdin_data_size
+ sz
+ 1 < c
->stdin_data_size
|| /* check for overflow */
1015 c
->stdin_data_size
+ sz
+ 1 > EXEC_STDIN_DATA_MAX
) {
1016 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Standard input data too large (%zu), maximum of %zu permitted, ignoring.", c
->stdin_data_size
+ sz
, (size_t) EXEC_STDIN_DATA_MAX
);
1020 p
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
+ 1);
1024 *((char*) mempcpy((char*) p
+ c
->stdin_data_size
, resolved
, sz
)) = '\n';
1027 c
->stdin_data_size
+= sz
+ 1;
1032 int config_parse_exec_input_data(
1034 const char *filename
,
1036 const char *section
,
1037 unsigned section_line
,
1044 _cleanup_free_
void *p
= NULL
;
1045 ExecContext
*c
= data
;
1055 if (isempty(rvalue
)) {
1056 /* Reset if the empty string is assigned */
1057 c
->stdin_data
= mfree(c
->stdin_data
);
1058 c
->stdin_data_size
= 0;
1062 r
= unbase64mem(rvalue
, (size_t) -1, &p
, &sz
);
1064 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to decode base64 data, ignoring: %s", rvalue
);
1068 if (c
->stdin_data_size
+ sz
< c
->stdin_data_size
|| /* check for overflow */
1069 c
->stdin_data_size
+ sz
> EXEC_STDIN_DATA_MAX
) {
1070 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Standard input data too large (%zu), maximum of %zu permitted, ignoring.", c
->stdin_data_size
+ sz
, (size_t) EXEC_STDIN_DATA_MAX
);
1074 q
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
);
1078 memcpy((uint8_t*) q
+ c
->stdin_data_size
, p
, sz
);
1081 c
->stdin_data_size
+= sz
;
1086 int config_parse_exec_output(
1088 const char *filename
,
1090 const char *section
,
1091 unsigned section_line
,
1098 _cleanup_free_
char *resolved
= NULL
;
1100 ExecContext
*c
= data
;
1101 const Unit
*u
= userdata
;
1102 bool obsolete
= false;
1112 n
= startswith(rvalue
, "fd:");
1114 r
= unit_full_printf(u
, n
, &resolved
);
1116 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", n
);
1118 if (isempty(resolved
))
1119 resolved
= mfree(resolved
);
1120 else if (!fdname_is_valid(resolved
)) {
1121 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name: %s", resolved
);
1125 eo
= EXEC_OUTPUT_NAMED_FD
;
1127 } else if (streq(rvalue
, "syslog")) {
1128 eo
= EXEC_OUTPUT_JOURNAL
;
1131 } else if (streq(rvalue
, "syslog+console")) {
1132 eo
= EXEC_OUTPUT_JOURNAL_AND_CONSOLE
;
1135 } else if ((n
= startswith(rvalue
, "file:"))) {
1137 r
= unit_full_printf(u
, n
, &resolved
);
1139 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", n
);
1141 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1145 eo
= EXEC_OUTPUT_FILE
;
1147 } else if ((n
= startswith(rvalue
, "append:"))) {
1149 r
= unit_full_printf(u
, n
, &resolved
);
1151 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", n
);
1153 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1157 eo
= EXEC_OUTPUT_FILE_APPEND
;
1159 eo
= exec_output_from_string(rvalue
);
1161 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse output specifier, ignoring: %s", rvalue
);
1167 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
1168 "Standard output type %s is obsolete, automatically updating to %s. Please update your unit file, and consider removing the setting altogether.",
1169 rvalue
, exec_output_to_string(eo
));
1171 if (streq(lvalue
, "StandardOutput")) {
1172 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1173 free_and_replace(c
->stdio_fdname
[STDOUT_FILENO
], resolved
);
1175 free_and_replace(c
->stdio_file
[STDOUT_FILENO
], resolved
);
1180 assert(streq(lvalue
, "StandardError"));
1182 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1183 free_and_replace(c
->stdio_fdname
[STDERR_FILENO
], resolved
);
1185 free_and_replace(c
->stdio_file
[STDERR_FILENO
], resolved
);
1193 int config_parse_exec_io_class(const char *unit
,
1194 const char *filename
,
1196 const char *section
,
1197 unsigned section_line
,
1204 ExecContext
*c
= data
;
1212 if (isempty(rvalue
)) {
1213 c
->ioprio_set
= false;
1214 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE
, 0);
1218 x
= ioprio_class_from_string(rvalue
);
1220 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse IO scheduling class, ignoring: %s", rvalue
);
1224 c
->ioprio
= IOPRIO_PRIO_VALUE(x
, IOPRIO_PRIO_DATA(c
->ioprio
));
1225 c
->ioprio_set
= true;
1230 int config_parse_exec_io_priority(const char *unit
,
1231 const char *filename
,
1233 const char *section
,
1234 unsigned section_line
,
1241 ExecContext
*c
= data
;
1249 if (isempty(rvalue
)) {
1250 c
->ioprio_set
= false;
1251 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE
, 0);
1255 r
= ioprio_parse_priority(rvalue
, &i
);
1257 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse IO priority, ignoring: %s", rvalue
);
1261 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_PRIO_CLASS(c
->ioprio
), i
);
1262 c
->ioprio_set
= true;
1267 int config_parse_exec_cpu_sched_policy(const char *unit
,
1268 const char *filename
,
1270 const char *section
,
1271 unsigned section_line
,
1278 ExecContext
*c
= data
;
1286 if (isempty(rvalue
)) {
1287 c
->cpu_sched_set
= false;
1288 c
->cpu_sched_policy
= SCHED_OTHER
;
1289 c
->cpu_sched_priority
= 0;
1293 x
= sched_policy_from_string(rvalue
);
1295 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse CPU scheduling policy, ignoring: %s", rvalue
);
1299 c
->cpu_sched_policy
= x
;
1300 /* Moving to or from real-time policy? We need to adjust the priority */
1301 c
->cpu_sched_priority
= CLAMP(c
->cpu_sched_priority
, sched_get_priority_min(x
), sched_get_priority_max(x
));
1302 c
->cpu_sched_set
= true;
1307 int config_parse_numa_mask(const char *unit
,
1308 const char *filename
,
1310 const char *section
,
1311 unsigned section_line
,
1318 NUMAPolicy
*p
= data
;
1325 r
= parse_cpu_set_extend(rvalue
, &p
->nodes
, true, unit
, filename
, line
, lvalue
);
1327 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse NUMA node mask, ignoring: %s", rvalue
);
1334 int config_parse_exec_cpu_sched_prio(const char *unit
,
1335 const char *filename
,
1337 const char *section
,
1338 unsigned section_line
,
1345 ExecContext
*c
= data
;
1353 r
= safe_atoi(rvalue
, &i
);
1355 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse CPU scheduling priority, ignoring: %s", rvalue
);
1359 /* On Linux RR/FIFO range from 1 to 99 and OTHER/BATCH may only be 0 */
1360 min
= sched_get_priority_min(c
->cpu_sched_policy
);
1361 max
= sched_get_priority_max(c
->cpu_sched_policy
);
1363 if (i
< min
|| i
> max
) {
1364 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "CPU scheduling priority is out of range, ignoring: %s", rvalue
);
1368 c
->cpu_sched_priority
= i
;
1369 c
->cpu_sched_set
= true;
1374 int config_parse_exec_cpu_affinity(const char *unit
,
1375 const char *filename
,
1377 const char *section
,
1378 unsigned section_line
,
1385 ExecContext
*c
= data
;
1393 if (streq(rvalue
, "numa")) {
1394 c
->cpu_affinity_from_numa
= true;
1395 cpu_set_reset(&c
->cpu_set
);
1400 r
= parse_cpu_set_extend(rvalue
, &c
->cpu_set
, true, unit
, filename
, line
, lvalue
);
1402 c
->cpu_affinity_from_numa
= false;
1407 int config_parse_capability_set(
1409 const char *filename
,
1411 const char *section
,
1412 unsigned section_line
,
1419 uint64_t *capability_set
= data
;
1420 uint64_t sum
= 0, initial
= 0;
1421 bool invert
= false;
1429 if (rvalue
[0] == '~') {
1434 if (streq(lvalue
, "CapabilityBoundingSet"))
1435 initial
= CAP_ALL
; /* initialized to all bits on */
1436 /* else "AmbientCapabilities" initialized to all bits off */
1438 r
= capability_set_from_string(rvalue
, &sum
);
1440 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= specifier '%s', ignoring: %m", lvalue
, rvalue
);
1444 if (sum
== 0 || *capability_set
== initial
)
1445 /* "", "~" or uninitialized data -> replace */
1446 *capability_set
= invert
? ~sum
: sum
;
1448 /* previous data -> merge */
1450 *capability_set
&= ~sum
;
1452 *capability_set
|= sum
;
1458 int config_parse_exec_selinux_context(
1460 const char *filename
,
1462 const char *section
,
1463 unsigned section_line
,
1470 ExecContext
*c
= data
;
1471 const Unit
*u
= userdata
;
1481 if (isempty(rvalue
)) {
1482 c
->selinux_context
= mfree(c
->selinux_context
);
1483 c
->selinux_context_ignore
= false;
1487 if (rvalue
[0] == '-') {
1493 r
= unit_full_printf(u
, rvalue
, &k
);
1495 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1496 "Failed to resolve unit specifiers in '%s'%s: %m",
1497 rvalue
, ignore
? ", ignoring" : "");
1498 return ignore
? 0 : -ENOEXEC
;
1501 free_and_replace(c
->selinux_context
, k
);
1502 c
->selinux_context_ignore
= ignore
;
1507 int config_parse_exec_apparmor_profile(
1509 const char *filename
,
1511 const char *section
,
1512 unsigned section_line
,
1519 ExecContext
*c
= data
;
1520 const Unit
*u
= userdata
;
1530 if (isempty(rvalue
)) {
1531 c
->apparmor_profile
= mfree(c
->apparmor_profile
);
1532 c
->apparmor_profile_ignore
= false;
1536 if (rvalue
[0] == '-') {
1542 r
= unit_full_printf(u
, rvalue
, &k
);
1544 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1545 "Failed to resolve unit specifiers in '%s'%s: %m",
1546 rvalue
, ignore
? ", ignoring" : "");
1547 return ignore
? 0 : -ENOEXEC
;
1550 free_and_replace(c
->apparmor_profile
, k
);
1551 c
->apparmor_profile_ignore
= ignore
;
1556 int config_parse_exec_smack_process_label(
1558 const char *filename
,
1560 const char *section
,
1561 unsigned section_line
,
1568 ExecContext
*c
= data
;
1569 const Unit
*u
= userdata
;
1579 if (isempty(rvalue
)) {
1580 c
->smack_process_label
= mfree(c
->smack_process_label
);
1581 c
->smack_process_label_ignore
= false;
1585 if (rvalue
[0] == '-') {
1591 r
= unit_full_printf(u
, rvalue
, &k
);
1593 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1594 "Failed to resolve unit specifiers in '%s'%s: %m",
1595 rvalue
, ignore
? ", ignoring" : "");
1596 return ignore
? 0 : -ENOEXEC
;
1599 free_and_replace(c
->smack_process_label
, k
);
1600 c
->smack_process_label_ignore
= ignore
;
1605 int config_parse_timer(
1607 const char *filename
,
1609 const char *section
,
1610 unsigned section_line
,
1617 _cleanup_(calendar_spec_freep
) CalendarSpec
*c
= NULL
;
1618 _cleanup_free_
char *k
= NULL
;
1619 const Unit
*u
= userdata
;
1630 if (isempty(rvalue
)) {
1631 /* Empty assignment resets list */
1632 timer_free_values(t
);
1636 r
= unit_full_printf(u
, rvalue
, &k
);
1638 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
1642 if (ltype
== TIMER_CALENDAR
) {
1643 r
= calendar_spec_from_string(k
, &c
);
1645 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse calendar specification, ignoring: %s", k
);
1649 r
= parse_sec(k
, &usec
);
1651 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse timer value, ignoring: %s", k
);
1656 v
= new(TimerValue
, 1);
1663 .calendar_spec
= TAKE_PTR(c
),
1666 LIST_PREPEND(value
, t
->values
, v
);
1671 int config_parse_trigger_unit(
1673 const char *filename
,
1675 const char *section
,
1676 unsigned section_line
,
1683 _cleanup_free_
char *p
= NULL
;
1693 if (!hashmap_isempty(u
->dependencies
[UNIT_TRIGGERS
])) {
1694 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Multiple units to trigger specified, ignoring: %s", rvalue
);
1698 r
= unit_name_printf(u
, rvalue
, &p
);
1700 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
1704 type
= unit_name_to_type(p
);
1706 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit type not valid, ignoring: %s", rvalue
);
1709 if (unit_has_name(u
, p
)) {
1710 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Units cannot trigger themselves, ignoring: %s", rvalue
);
1714 r
= unit_add_two_dependencies_by_name(u
, UNIT_BEFORE
, UNIT_TRIGGERS
, p
, true, UNIT_DEPENDENCY_FILE
);
1716 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add trigger on %s, ignoring: %m", p
);
1723 int config_parse_path_spec(const char *unit
,
1724 const char *filename
,
1726 const char *section
,
1727 unsigned section_line
,
1737 _cleanup_free_
char *k
= NULL
;
1745 if (isempty(rvalue
)) {
1746 /* Empty assignment clears list */
1751 b
= path_type_from_string(lvalue
);
1753 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse path type, ignoring: %s", lvalue
);
1757 r
= unit_full_printf(UNIT(p
), rvalue
, &k
);
1759 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
1763 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
1767 s
= new0(PathSpec
, 1);
1772 s
->path
= TAKE_PTR(k
);
1776 LIST_PREPEND(spec
, p
->specs
, s
);
1781 int config_parse_socket_service(
1783 const char *filename
,
1785 const char *section
,
1786 unsigned section_line
,
1793 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1794 _cleanup_free_
char *p
= NULL
;
1804 r
= unit_name_printf(UNIT(s
), rvalue
, &p
);
1806 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", rvalue
);
1810 if (!endswith(p
, ".service")) {
1811 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit must be of type service: %s", rvalue
);
1815 r
= manager_load_unit(UNIT(s
)->manager
, p
, NULL
, &error
, &x
);
1817 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to load unit %s: %s", rvalue
, bus_error_message(&error
, r
));
1821 unit_ref_set(&s
->service
, UNIT(s
), x
);
1826 int config_parse_fdname(
1828 const char *filename
,
1830 const char *section
,
1831 unsigned section_line
,
1838 _cleanup_free_
char *p
= NULL
;
1847 if (isempty(rvalue
)) {
1848 s
->fdname
= mfree(s
->fdname
);
1852 r
= unit_full_printf(UNIT(s
), rvalue
, &p
);
1854 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
1858 if (!fdname_is_valid(p
)) {
1859 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", p
);
1863 return free_and_replace(s
->fdname
, p
);
1866 int config_parse_service_sockets(
1868 const char *filename
,
1870 const char *section
,
1871 unsigned section_line
,
1889 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
1891 r
= extract_first_word(&p
, &word
, NULL
, 0);
1897 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Trailing garbage in sockets, ignoring: %s", rvalue
);
1901 r
= unit_name_printf(UNIT(s
), word
, &k
);
1903 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
1907 if (!endswith(k
, ".socket")) {
1908 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit must be of type socket, ignoring: %s", k
);
1912 r
= unit_add_two_dependencies_by_name(UNIT(s
), UNIT_WANTS
, UNIT_AFTER
, k
, true, UNIT_DEPENDENCY_FILE
);
1914 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
1916 r
= unit_add_dependency_by_name(UNIT(s
), UNIT_TRIGGERED_BY
, k
, true, UNIT_DEPENDENCY_FILE
);
1918 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
1924 int config_parse_bus_name(
1926 const char *filename
,
1928 const char *section
,
1929 unsigned section_line
,
1936 _cleanup_free_
char *k
= NULL
;
1937 const Unit
*u
= userdata
;
1945 r
= unit_full_printf(u
, rvalue
, &k
);
1947 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
1951 if (!sd_bus_service_name_is_valid(k
)) {
1952 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid bus name, ignoring: %s", k
);
1956 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
1959 int config_parse_service_timeout(
1961 const char *filename
,
1963 const char *section
,
1964 unsigned section_line
,
1971 Service
*s
= userdata
;
1980 /* This is called for two cases: TimeoutSec= and TimeoutStartSec=. */
1982 /* Traditionally, these options accepted 0 to disable the timeouts. However, a timeout of 0 suggests it happens
1983 * immediately, hence fix this to become USEC_INFINITY instead. This is in-line with how we internally handle
1984 * all other timeouts. */
1985 r
= parse_sec_fix_0(rvalue
, &usec
);
1987 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
1991 s
->start_timeout_defined
= true;
1992 s
->timeout_start_usec
= usec
;
1994 if (streq(lvalue
, "TimeoutSec"))
1995 s
->timeout_stop_usec
= usec
;
2000 int config_parse_timeout_abort(
2002 const char *filename
,
2004 const char *section
,
2005 unsigned section_line
,
2020 /* Note: apart from setting the arg, this returns an extra bit of information in the return value. */
2022 if (isempty(rvalue
)) {
2024 return 0; /* "not set" */
2027 r
= parse_sec(rvalue
, ret
);
2029 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= setting, ignoring: %s", lvalue
, rvalue
);
2031 return 1; /* "set" */
2034 int config_parse_service_timeout_abort(
2036 const char *filename
,
2038 const char *section
,
2039 unsigned section_line
,
2046 Service
*s
= userdata
;
2051 r
= config_parse_timeout_abort(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
,
2052 &s
->timeout_abort_usec
, s
);
2054 s
->timeout_abort_set
= r
;
2058 int config_parse_sec_fix_0(
2060 const char *filename
,
2062 const char *section
,
2063 unsigned section_line
,
2070 usec_t
*usec
= data
;
2078 /* This is pretty much like config_parse_sec(), except that this treats a time of 0 as infinity, for
2079 * compatibility with older versions of systemd where 0 instead of infinity was used as indicator to turn off a
2082 r
= parse_sec_fix_0(rvalue
, usec
);
2084 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
2091 int config_parse_user_group_compat(
2093 const char *filename
,
2095 const char *section
,
2096 unsigned section_line
,
2103 _cleanup_free_
char *k
= NULL
;
2105 const Unit
*u
= userdata
;
2113 if (isempty(rvalue
)) {
2114 *user
= mfree(*user
);
2118 r
= unit_full_printf(u
, rvalue
, &k
);
2120 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", rvalue
);
2124 if (!valid_user_group_name(k
, VALID_USER_ALLOW_NUMERIC
|VALID_USER_RELAX
|VALID_USER_WARN
)) {
2125 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2129 return free_and_replace(*user
, k
);
2132 int config_parse_user_group_strv_compat(
2134 const char *filename
,
2136 const char *section
,
2137 unsigned section_line
,
2144 char ***users
= data
;
2145 const Unit
*u
= userdata
;
2146 const char *p
= rvalue
;
2154 if (isempty(rvalue
)) {
2155 *users
= strv_free(*users
);
2160 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2162 r
= extract_first_word(&p
, &word
, NULL
, 0);
2168 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax: %s", rvalue
);
2172 r
= unit_full_printf(u
, word
, &k
);
2174 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", word
);
2178 if (!valid_user_group_name(k
, VALID_USER_ALLOW_NUMERIC
|VALID_USER_RELAX
|VALID_USER_WARN
)) {
2179 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2183 r
= strv_push(users
, k
);
2193 int config_parse_working_directory(
2195 const char *filename
,
2197 const char *section
,
2198 unsigned section_line
,
2205 ExecContext
*c
= data
;
2206 const Unit
*u
= userdata
;
2216 if (isempty(rvalue
)) {
2217 c
->working_directory_home
= false;
2218 c
->working_directory
= mfree(c
->working_directory
);
2222 if (rvalue
[0] == '-') {
2228 if (streq(rvalue
, "~")) {
2229 c
->working_directory_home
= true;
2230 c
->working_directory
= mfree(c
->working_directory
);
2232 _cleanup_free_
char *k
= NULL
;
2234 r
= unit_full_printf(u
, rvalue
, &k
);
2236 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2237 "Failed to resolve unit specifiers in working directory path '%s'%s: %m",
2238 rvalue
, missing_ok
? ", ignoring" : "");
2239 return missing_ok
? 0 : -ENOEXEC
;
2242 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
| (missing_ok
? 0 : PATH_CHECK_FATAL
), unit
, filename
, line
, lvalue
);
2244 return missing_ok
? 0 : -ENOEXEC
;
2246 c
->working_directory_home
= false;
2247 free_and_replace(c
->working_directory
, k
);
2250 c
->working_directory_missing_ok
= missing_ok
;
2254 int config_parse_unit_env_file(const char *unit
,
2255 const char *filename
,
2257 const char *section
,
2258 unsigned section_line
,
2266 const Unit
*u
= userdata
;
2267 _cleanup_free_
char *n
= NULL
;
2275 if (isempty(rvalue
)) {
2276 /* Empty assignment frees the list */
2277 *env
= strv_free(*env
);
2281 r
= unit_full_printf(u
, rvalue
, &n
);
2283 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2287 r
= path_simplify_and_warn(n
[0] == '-' ? n
+ 1 : n
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2291 r
= strv_push(env
, n
);
2300 int config_parse_environ(
2302 const char *filename
,
2304 const char *section
,
2305 unsigned section_line
,
2312 const Unit
*u
= userdata
;
2322 if (isempty(rvalue
)) {
2323 /* Empty assignment resets the list */
2324 *env
= strv_free(*env
);
2328 for (p
= rvalue
;; ) {
2329 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2331 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2337 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2338 "Invalid syntax, ignoring: %s", rvalue
);
2343 r
= unit_full_printf(u
, word
, &k
);
2345 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2346 "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2352 if (!env_assignment_is_valid(k
)) {
2353 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2354 "Invalid environment assignment, ignoring: %s", k
);
2358 r
= strv_env_replace(env
, k
);
2366 int config_parse_pass_environ(
2368 const char *filename
,
2370 const char *section
,
2371 unsigned section_line
,
2378 _cleanup_strv_free_
char **n
= NULL
;
2379 size_t nlen
= 0, nbufsize
= 0;
2380 char*** passenv
= data
;
2381 const char *p
= rvalue
;
2382 const Unit
*u
= userdata
;
2390 if (isempty(rvalue
)) {
2391 /* Empty assignment resets the list */
2392 *passenv
= strv_free(*passenv
);
2397 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2399 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
2405 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2406 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2411 r
= unit_full_printf(u
, word
, &k
);
2413 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2414 "Failed to resolve specifiers in %s, ignoring: %m", word
);
2420 if (!env_name_is_valid(k
)) {
2421 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2422 "Invalid environment name for %s, ignoring: %s", lvalue
, k
);
2426 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
2429 n
[nlen
++] = TAKE_PTR(k
);
2434 r
= strv_extend_strv(passenv
, n
, true);
2442 int config_parse_unset_environ(
2444 const char *filename
,
2446 const char *section
,
2447 unsigned section_line
,
2454 _cleanup_strv_free_
char **n
= NULL
;
2455 size_t nlen
= 0, nbufsize
= 0;
2456 char*** unsetenv
= data
;
2457 const char *p
= rvalue
;
2458 const Unit
*u
= userdata
;
2466 if (isempty(rvalue
)) {
2467 /* Empty assignment resets the list */
2468 *unsetenv
= strv_free(*unsetenv
);
2473 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2475 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2481 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2482 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2487 r
= unit_full_printf(u
, word
, &k
);
2489 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2490 "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2496 if (!env_assignment_is_valid(k
) && !env_name_is_valid(k
)) {
2497 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2498 "Invalid environment name or assignment %s, ignoring: %s", lvalue
, k
);
2502 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
2505 n
[nlen
++] = TAKE_PTR(k
);
2510 r
= strv_extend_strv(unsetenv
, n
, true);
2518 int config_parse_log_extra_fields(
2520 const char *filename
,
2522 const char *section
,
2523 unsigned section_line
,
2530 ExecContext
*c
= data
;
2531 const Unit
*u
= userdata
;
2532 const char *p
= rvalue
;
2540 if (isempty(rvalue
)) {
2541 exec_context_free_log_extra_fields(c
);
2546 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2550 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2556 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
2560 r
= unit_full_printf(u
, word
, &k
);
2562 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2566 eq
= strchr(k
, '=');
2568 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Log field lacks '=' character, ignoring: %s", k
);
2572 if (!journal_field_valid(k
, eq
-k
, false)) {
2573 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Log field name is invalid, ignoring: %s", k
);
2577 t
= reallocarray(c
->log_extra_fields
, c
->n_log_extra_fields
+1, sizeof(struct iovec
));
2581 c
->log_extra_fields
= t
;
2582 c
->log_extra_fields
[c
->n_log_extra_fields
++] = IOVEC_MAKE_STRING(k
);
2588 int config_parse_log_namespace(
2590 const char *filename
,
2592 const char *section
,
2593 unsigned section_line
,
2600 _cleanup_free_
char *k
= NULL
;
2601 ExecContext
*c
= data
;
2602 const Unit
*u
= userdata
;
2610 if (isempty(rvalue
)) {
2611 c
->log_namespace
= mfree(c
->log_namespace
);
2615 r
= unit_full_printf(u
, rvalue
, &k
);
2617 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2621 if (!log_namespace_name_valid(k
)) {
2622 log_syntax(unit
, LOG_ERR
, filename
, line
, SYNTHETIC_ERRNO(EINVAL
), "Specified log namespace name is not valid: %s", k
);
2626 free_and_replace(c
->log_namespace
, k
);
2630 int config_parse_unit_condition_path(
2632 const char *filename
,
2634 const char *section
,
2635 unsigned section_line
,
2642 _cleanup_free_
char *p
= NULL
;
2643 Condition
**list
= data
, *c
;
2644 ConditionType t
= ltype
;
2645 bool trigger
, negate
;
2646 const Unit
*u
= userdata
;
2654 if (isempty(rvalue
)) {
2655 /* Empty assignment resets the list */
2656 *list
= condition_free_list(*list
);
2660 trigger
= rvalue
[0] == '|';
2664 negate
= rvalue
[0] == '!';
2668 r
= unit_full_printf(u
, rvalue
, &p
);
2670 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2674 r
= path_simplify_and_warn(p
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2678 c
= condition_new(t
, p
, trigger
, negate
);
2682 LIST_PREPEND(conditions
, *list
, c
);
2686 int config_parse_unit_condition_string(
2688 const char *filename
,
2690 const char *section
,
2691 unsigned section_line
,
2698 _cleanup_free_
char *s
= NULL
;
2699 Condition
**list
= data
, *c
;
2700 ConditionType t
= ltype
;
2701 bool trigger
, negate
;
2702 const Unit
*u
= userdata
;
2710 if (isempty(rvalue
)) {
2711 /* Empty assignment resets the list */
2712 *list
= condition_free_list(*list
);
2716 trigger
= *rvalue
== '|';
2718 rvalue
+= 1 + strspn(rvalue
+ 1, WHITESPACE
);
2720 negate
= *rvalue
== '!';
2722 rvalue
+= 1 + strspn(rvalue
+ 1, WHITESPACE
);
2724 r
= unit_full_printf(u
, rvalue
, &s
);
2726 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2727 "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2731 c
= condition_new(t
, s
, trigger
, negate
);
2735 LIST_PREPEND(conditions
, *list
, c
);
2739 int config_parse_unit_condition_null(
2741 const char *filename
,
2743 const char *section
,
2744 unsigned section_line
,
2751 Condition
**list
= data
, *c
;
2752 bool trigger
, negate
;
2760 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "%s= is deprecated, please do not use.", lvalue
);
2762 if (isempty(rvalue
)) {
2763 /* Empty assignment resets the list */
2764 *list
= condition_free_list(*list
);
2768 trigger
= rvalue
[0] == '|';
2772 negate
= rvalue
[0] == '!';
2776 b
= parse_boolean(rvalue
);
2778 log_syntax(unit
, LOG_ERR
, filename
, line
, b
, "Failed to parse boolean value in condition, ignoring: %s", rvalue
);
2785 c
= condition_new(CONDITION_NULL
, NULL
, trigger
, negate
);
2789 LIST_PREPEND(conditions
, *list
, c
);
2793 int config_parse_unit_requires_mounts_for(
2795 const char *filename
,
2797 const char *section
,
2798 unsigned section_line
,
2805 const char *p
= rvalue
;
2815 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
2817 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
2823 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2824 "Invalid syntax, ignoring: %s", rvalue
);
2828 r
= unit_full_printf(u
, word
, &resolved
);
2830 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
2834 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2838 r
= unit_require_mounts_for(u
, resolved
, UNIT_DEPENDENCY_FILE
);
2840 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add required mount '%s', ignoring: %m", resolved
);
2846 int config_parse_documentation(const char *unit
,
2847 const char *filename
,
2849 const char *section
,
2850 unsigned section_line
,
2866 if (isempty(rvalue
)) {
2867 /* Empty assignment resets the list */
2868 u
->documentation
= strv_free(u
->documentation
);
2872 r
= config_parse_unit_strv_printf(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
,
2873 rvalue
, data
, userdata
);
2877 for (a
= b
= u
->documentation
; a
&& *a
; a
++) {
2879 if (documentation_url_is_valid(*a
))
2882 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid URL, ignoring: %s", *a
);
2893 int config_parse_syscall_filter(
2895 const char *filename
,
2897 const char *section
,
2898 unsigned section_line
,
2905 ExecContext
*c
= data
;
2906 _unused_
const Unit
*u
= userdata
;
2907 bool invert
= false;
2916 if (isempty(rvalue
)) {
2917 /* Empty assignment resets the list */
2918 c
->syscall_filter
= hashmap_free(c
->syscall_filter
);
2919 c
->syscall_whitelist
= false;
2923 if (rvalue
[0] == '~') {
2928 if (!c
->syscall_filter
) {
2929 c
->syscall_filter
= hashmap_new(NULL
);
2930 if (!c
->syscall_filter
)
2934 /* Allow everything but the ones listed */
2935 c
->syscall_whitelist
= false;
2937 /* Allow nothing but the ones listed */
2938 c
->syscall_whitelist
= true;
2940 /* Accept default syscalls if we are on a whitelist */
2941 r
= seccomp_parse_syscall_filter(
2942 "@default", -1, c
->syscall_filter
,
2943 SECCOMP_PARSE_PERMISSIVE
|SECCOMP_PARSE_WHITELIST
,
2953 _cleanup_free_
char *word
= NULL
, *name
= NULL
;
2956 r
= extract_first_word(&p
, &word
, NULL
, 0);
2962 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
2966 r
= parse_syscall_and_errno(word
, &name
, &num
);
2968 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse syscall:errno, ignoring: %s", word
);
2972 r
= seccomp_parse_syscall_filter(
2973 name
, num
, c
->syscall_filter
,
2974 SECCOMP_PARSE_LOG
|SECCOMP_PARSE_PERMISSIVE
|
2975 (invert
? SECCOMP_PARSE_INVERT
: 0)|
2976 (c
->syscall_whitelist
? SECCOMP_PARSE_WHITELIST
: 0),
2977 unit
, filename
, line
);
2983 int config_parse_syscall_archs(
2985 const char *filename
,
2987 const char *section
,
2988 unsigned section_line
,
2995 const char *p
= rvalue
;
2999 if (isempty(rvalue
)) {
3000 *archs
= set_free(*archs
);
3004 r
= set_ensure_allocated(archs
, NULL
);
3009 _cleanup_free_
char *word
= NULL
;
3012 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3018 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3019 "Invalid syntax, ignoring: %s", rvalue
);
3023 r
= seccomp_arch_from_string(word
, &a
);
3025 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
3026 "Failed to parse system call architecture \"%s\", ignoring: %m", word
);
3030 r
= set_put(*archs
, UINT32_TO_PTR(a
+ 1));
3036 int config_parse_syscall_errno(
3038 const char *filename
,
3040 const char *section
,
3041 unsigned section_line
,
3048 ExecContext
*c
= data
;
3055 if (isempty(rvalue
)) {
3056 /* Empty assignment resets to KILL */
3057 c
->syscall_errno
= 0;
3061 e
= parse_errno(rvalue
);
3063 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse error number, ignoring: %s", rvalue
);
3067 c
->syscall_errno
= e
;
3071 int config_parse_address_families(
3073 const char *filename
,
3075 const char *section
,
3076 unsigned section_line
,
3083 ExecContext
*c
= data
;
3084 bool invert
= false;
3092 if (isempty(rvalue
)) {
3093 /* Empty assignment resets the list */
3094 c
->address_families
= set_free(c
->address_families
);
3095 c
->address_families_whitelist
= false;
3099 if (rvalue
[0] == '~') {
3104 if (!c
->address_families
) {
3105 c
->address_families
= set_new(NULL
);
3106 if (!c
->address_families
)
3109 c
->address_families_whitelist
= !invert
;
3112 for (p
= rvalue
;;) {
3113 _cleanup_free_
char *word
= NULL
;
3116 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3122 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3123 "Invalid syntax, ignoring: %s", rvalue
);
3127 af
= af_from_name(word
);
3129 log_syntax(unit
, LOG_ERR
, filename
, line
, af
,
3130 "Failed to parse address family, ignoring: %s", word
);
3134 /* If we previously wanted to forbid an address family and now
3135 * we want to allow it, then just remove it from the list.
3137 if (!invert
== c
->address_families_whitelist
) {
3138 r
= set_put(c
->address_families
, INT_TO_PTR(af
));
3142 set_remove(c
->address_families
, INT_TO_PTR(af
));
3146 int config_parse_restrict_namespaces(
3148 const char *filename
,
3150 const char *section
,
3151 unsigned section_line
,
3158 ExecContext
*c
= data
;
3159 unsigned long flags
;
3160 bool invert
= false;
3163 if (isempty(rvalue
)) {
3164 /* Reset to the default. */
3165 c
->restrict_namespaces
= NAMESPACE_FLAGS_INITIAL
;
3169 /* Boolean parameter ignores the previous settings */
3170 r
= parse_boolean(rvalue
);
3172 c
->restrict_namespaces
= 0;
3174 } else if (r
== 0) {
3175 c
->restrict_namespaces
= NAMESPACE_FLAGS_ALL
;
3179 if (rvalue
[0] == '~') {
3184 /* Not a boolean argument, in this case it's a list of namespace types. */
3185 r
= namespace_flags_from_string(rvalue
, &flags
);
3187 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse namespace type string, ignoring: %s", rvalue
);
3191 if (c
->restrict_namespaces
== NAMESPACE_FLAGS_INITIAL
)
3192 /* Initial assignment. Just set the value. */
3193 c
->restrict_namespaces
= invert
? (~flags
) & NAMESPACE_FLAGS_ALL
: flags
;
3195 /* Merge the value with the previous one. */
3196 SET_FLAG(c
->restrict_namespaces
, flags
, !invert
);
3202 int config_parse_unit_slice(
3204 const char *filename
,
3206 const char *section
,
3207 unsigned section_line
,
3214 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
3215 _cleanup_free_
char *k
= NULL
;
3216 Unit
*u
= userdata
, *slice
;
3224 r
= unit_name_printf(u
, rvalue
, &k
);
3226 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
3230 r
= manager_load_unit(u
->manager
, k
, NULL
, &error
, &slice
);
3232 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to load slice unit %s, ignoring: %s", k
, bus_error_message(&error
, r
));
3236 r
= unit_set_slice(u
, slice
);
3238 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to assign slice %s to unit %s, ignoring: %m", slice
->id
, u
->id
);
3245 int config_parse_cpu_quota(
3247 const char *filename
,
3249 const char *section
,
3250 unsigned section_line
,
3257 CGroupContext
*c
= data
;
3264 if (isempty(rvalue
)) {
3265 c
->cpu_quota_per_sec_usec
= USEC_INFINITY
;
3269 r
= parse_permille_unbounded(rvalue
);
3271 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid CPU quota '%s', ignoring.", rvalue
);
3275 c
->cpu_quota_per_sec_usec
= ((usec_t
) r
* USEC_PER_SEC
) / 1000U;
3279 int config_parse_allowed_cpus(
3281 const char *filename
,
3283 const char *section
,
3284 unsigned section_line
,
3291 CGroupContext
*c
= data
;
3293 (void) parse_cpu_set_extend(rvalue
, &c
->cpuset_cpus
, true, unit
, filename
, line
, lvalue
);
3298 int config_parse_allowed_mems(
3300 const char *filename
,
3302 const char *section
,
3303 unsigned section_line
,
3310 CGroupContext
*c
= data
;
3312 (void) parse_cpu_set_extend(rvalue
, &c
->cpuset_mems
, true, unit
, filename
, line
, lvalue
);
3317 int config_parse_memory_limit(
3319 const char *filename
,
3321 const char *section
,
3322 unsigned section_line
,
3329 CGroupContext
*c
= data
;
3330 uint64_t bytes
= CGROUP_LIMIT_MAX
;
3333 if (!isempty(rvalue
) && !streq(rvalue
, "infinity")) {
3335 r
= parse_permille(rvalue
);
3337 r
= parse_size(rvalue
, 1024, &bytes
);
3339 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid memory limit '%s', ignoring: %m", rvalue
);
3343 bytes
= physical_memory_scale(r
, 1000U);
3345 if (bytes
>= UINT64_MAX
||
3346 (bytes
<= 0 && !STR_IN_SET(lvalue
, "MemorySwapMax", "MemoryLow", "MemoryMin", "DefaultMemoryLow", "DefaultMemoryMin"))) {
3347 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Memory limit '%s' out of range, ignoring.", rvalue
);
3352 if (streq(lvalue
, "DefaultMemoryLow")) {
3353 c
->default_memory_low_set
= true;
3354 if (isempty(rvalue
))
3355 c
->default_memory_low
= CGROUP_LIMIT_MIN
;
3357 c
->default_memory_low
= bytes
;
3358 } else if (streq(lvalue
, "DefaultMemoryMin")) {
3359 c
->default_memory_min_set
= true;
3360 if (isempty(rvalue
))
3361 c
->default_memory_min
= CGROUP_LIMIT_MIN
;
3363 c
->default_memory_min
= bytes
;
3364 } else if (streq(lvalue
, "MemoryMin")) {
3365 c
->memory_min
= bytes
;
3366 c
->memory_min_set
= true;
3367 } else if (streq(lvalue
, "MemoryLow")) {
3368 c
->memory_low
= bytes
;
3369 c
->memory_low_set
= true;
3370 } else if (streq(lvalue
, "MemoryHigh"))
3371 c
->memory_high
= bytes
;
3372 else if (streq(lvalue
, "MemoryMax"))
3373 c
->memory_max
= bytes
;
3374 else if (streq(lvalue
, "MemorySwapMax"))
3375 c
->memory_swap_max
= bytes
;
3376 else if (streq(lvalue
, "MemoryLimit"))
3377 c
->memory_limit
= bytes
;
3384 int config_parse_tasks_max(
3386 const char *filename
,
3388 const char *section
,
3389 unsigned section_line
,
3396 const Unit
*u
= userdata
;
3397 TasksMax
*tasks_max
= data
;
3401 if (isempty(rvalue
)) {
3402 *tasks_max
= u
? u
->manager
->default_tasks_max
: TASKS_MAX_UNSET
;
3406 if (streq(rvalue
, "infinity")) {
3407 *tasks_max
= TASKS_MAX_UNSET
;
3411 r
= parse_permille(rvalue
);
3413 *tasks_max
= (TasksMax
) { r
, 1000U }; /* r‰ */
3415 r
= safe_atou64(rvalue
, &v
);
3417 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid maximum tasks value '%s', ignoring: %m", rvalue
);
3421 if (v
<= 0 || v
>= UINT64_MAX
) {
3422 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Maximum tasks value '%s' out of range, ignoring.", rvalue
);
3426 *tasks_max
= (TasksMax
) { v
};
3432 int config_parse_delegate(
3434 const char *filename
,
3436 const char *section
,
3437 unsigned section_line
,
3444 CGroupContext
*c
= data
;
3448 t
= unit_name_to_type(unit
);
3449 assert(t
!= _UNIT_TYPE_INVALID
);
3451 if (!unit_vtable
[t
]->can_delegate
) {
3452 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Delegate= setting not supported for this unit type, ignoring.");
3456 /* We either accept a boolean value, which may be used to turn on delegation for all controllers, or turn it
3457 * off for all. Or it takes a list of controller names, in which case we add the specified controllers to the
3458 * mask to delegate. */
3460 if (isempty(rvalue
)) {
3461 /* An empty string resets controllers and set Delegate=yes. */
3463 c
->delegate_controllers
= 0;
3467 r
= parse_boolean(rvalue
);
3469 const char *p
= rvalue
;
3470 CGroupMask mask
= 0;
3473 _cleanup_free_
char *word
= NULL
;
3474 CGroupController cc
;
3476 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3482 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3486 cc
= cgroup_controller_from_string(word
);
3488 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid controller name '%s', ignoring", word
);
3492 mask
|= CGROUP_CONTROLLER_TO_MASK(cc
);
3496 c
->delegate_controllers
|= mask
;
3500 c
->delegate_controllers
= _CGROUP_MASK_ALL
;
3502 c
->delegate
= false;
3503 c
->delegate_controllers
= 0;
3509 int config_parse_device_allow(
3511 const char *filename
,
3513 const char *section
,
3514 unsigned section_line
,
3521 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3522 CGroupContext
*c
= data
;
3523 const char *p
= rvalue
;
3526 if (isempty(rvalue
)) {
3527 while (c
->device_allow
)
3528 cgroup_context_free_device_allow(c
, c
->device_allow
);
3533 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3537 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3538 "Invalid syntax, ignoring: %s", rvalue
);
3542 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3543 "Failed to extract device path and rights from '%s', ignoring.", rvalue
);
3547 r
= unit_full_printf(userdata
, path
, &resolved
);
3549 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3550 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3554 if (!STARTSWITH_SET(resolved
, "block-", "char-")) {
3556 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3560 if (!valid_device_node_path(resolved
)) {
3561 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device node path '%s', ignoring.", resolved
);
3566 if (!isempty(p
) && !in_charset(p
, "rwm")) {
3567 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device rights '%s', ignoring.", p
);
3571 return cgroup_add_device_allow(c
, resolved
, p
);
3574 int config_parse_io_device_weight(
3576 const char *filename
,
3578 const char *section
,
3579 unsigned section_line
,
3586 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3587 CGroupIODeviceWeight
*w
;
3588 CGroupContext
*c
= data
;
3589 const char *p
= rvalue
;
3597 if (isempty(rvalue
)) {
3598 while (c
->io_device_weights
)
3599 cgroup_context_free_io_device_weight(c
, c
->io_device_weights
);
3604 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3608 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3609 "Invalid syntax, ignoring: %s", rvalue
);
3612 if (r
== 0 || isempty(p
)) {
3613 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3614 "Failed to extract device path and weight from '%s', ignoring.", rvalue
);
3618 r
= unit_full_printf(userdata
, path
, &resolved
);
3620 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3621 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3625 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3629 r
= cg_weight_parse(p
, &u
);
3631 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "IO weight '%s' invalid, ignoring: %m", p
);
3635 assert(u
!= CGROUP_WEIGHT_INVALID
);
3637 w
= new0(CGroupIODeviceWeight
, 1);
3641 w
->path
= TAKE_PTR(resolved
);
3644 LIST_PREPEND(device_weights
, c
->io_device_weights
, w
);
3648 int config_parse_io_device_latency(
3650 const char *filename
,
3652 const char *section
,
3653 unsigned section_line
,
3660 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3661 CGroupIODeviceLatency
*l
;
3662 CGroupContext
*c
= data
;
3663 const char *p
= rvalue
;
3671 if (isempty(rvalue
)) {
3672 while (c
->io_device_latencies
)
3673 cgroup_context_free_io_device_latency(c
, c
->io_device_latencies
);
3678 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3682 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3683 "Invalid syntax, ignoring: %s", rvalue
);
3686 if (r
== 0 || isempty(p
)) {
3687 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3688 "Failed to extract device path and latency from '%s', ignoring.", rvalue
);
3692 r
= unit_full_printf(userdata
, path
, &resolved
);
3694 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3695 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3699 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3703 if (parse_sec(p
, &usec
) < 0) {
3704 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse timer value, ignoring: %s", p
);
3708 l
= new0(CGroupIODeviceLatency
, 1);
3712 l
->path
= TAKE_PTR(resolved
);
3713 l
->target_usec
= usec
;
3715 LIST_PREPEND(device_latencies
, c
->io_device_latencies
, l
);
3719 int config_parse_io_limit(
3721 const char *filename
,
3723 const char *section
,
3724 unsigned section_line
,
3731 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3732 CGroupIODeviceLimit
*l
= NULL
, *t
;
3733 CGroupContext
*c
= data
;
3734 CGroupIOLimitType type
;
3735 const char *p
= rvalue
;
3743 type
= cgroup_io_limit_type_from_string(lvalue
);
3746 if (isempty(rvalue
)) {
3747 LIST_FOREACH(device_limits
, l
, c
->io_device_limits
)
3748 l
->limits
[type
] = cgroup_io_limit_defaults
[type
];
3752 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3756 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3757 "Invalid syntax, ignoring: %s", rvalue
);
3760 if (r
== 0 || isempty(p
)) {
3761 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3762 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
3766 r
= unit_full_printf(userdata
, path
, &resolved
);
3768 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3769 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3773 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3777 if (streq("infinity", p
))
3778 num
= CGROUP_LIMIT_MAX
;
3780 r
= parse_size(p
, 1000, &num
);
3781 if (r
< 0 || num
<= 0) {
3782 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid IO limit '%s', ignoring.", p
);
3787 LIST_FOREACH(device_limits
, t
, c
->io_device_limits
) {
3788 if (path_equal(resolved
, t
->path
)) {
3795 CGroupIOLimitType ttype
;
3797 l
= new0(CGroupIODeviceLimit
, 1);
3801 l
->path
= TAKE_PTR(resolved
);
3802 for (ttype
= 0; ttype
< _CGROUP_IO_LIMIT_TYPE_MAX
; ttype
++)
3803 l
->limits
[ttype
] = cgroup_io_limit_defaults
[ttype
];
3805 LIST_PREPEND(device_limits
, c
->io_device_limits
, l
);
3808 l
->limits
[type
] = num
;
3813 int config_parse_blockio_device_weight(
3815 const char *filename
,
3817 const char *section
,
3818 unsigned section_line
,
3825 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3826 CGroupBlockIODeviceWeight
*w
;
3827 CGroupContext
*c
= data
;
3828 const char *p
= rvalue
;
3836 if (isempty(rvalue
)) {
3837 while (c
->blockio_device_weights
)
3838 cgroup_context_free_blockio_device_weight(c
, c
->blockio_device_weights
);
3843 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3847 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3848 "Invalid syntax, ignoring: %s", rvalue
);
3851 if (r
== 0 || isempty(p
)) {
3852 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3853 "Failed to extract device node and weight from '%s', ignoring.", rvalue
);
3857 r
= unit_full_printf(userdata
, path
, &resolved
);
3859 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3860 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3864 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3868 r
= cg_blkio_weight_parse(p
, &u
);
3870 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid block IO weight '%s', ignoring: %m", p
);
3874 assert(u
!= CGROUP_BLKIO_WEIGHT_INVALID
);
3876 w
= new0(CGroupBlockIODeviceWeight
, 1);
3880 w
->path
= TAKE_PTR(resolved
);
3883 LIST_PREPEND(device_weights
, c
->blockio_device_weights
, w
);
3887 int config_parse_blockio_bandwidth(
3889 const char *filename
,
3891 const char *section
,
3892 unsigned section_line
,
3899 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3900 CGroupBlockIODeviceBandwidth
*b
= NULL
, *t
;
3901 CGroupContext
*c
= data
;
3902 const char *p
= rvalue
;
3911 read
= streq("BlockIOReadBandwidth", lvalue
);
3913 if (isempty(rvalue
)) {
3914 LIST_FOREACH(device_bandwidths
, b
, c
->blockio_device_bandwidths
) {
3915 b
->rbps
= CGROUP_LIMIT_MAX
;
3916 b
->wbps
= CGROUP_LIMIT_MAX
;
3921 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3925 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3926 "Invalid syntax, ignoring: %s", rvalue
);
3929 if (r
== 0 || isempty(p
)) {
3930 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3931 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
3935 r
= unit_full_printf(userdata
, path
, &resolved
);
3937 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3938 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3942 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3946 r
= parse_size(p
, 1000, &bytes
);
3947 if (r
< 0 || bytes
<= 0) {
3948 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid Block IO Bandwidth '%s', ignoring.", p
);
3952 LIST_FOREACH(device_bandwidths
, t
, c
->blockio_device_bandwidths
) {
3953 if (path_equal(resolved
, t
->path
)) {
3960 b
= new0(CGroupBlockIODeviceBandwidth
, 1);
3964 b
->path
= TAKE_PTR(resolved
);
3965 b
->rbps
= CGROUP_LIMIT_MAX
;
3966 b
->wbps
= CGROUP_LIMIT_MAX
;
3968 LIST_PREPEND(device_bandwidths
, c
->blockio_device_bandwidths
, b
);
3979 int config_parse_job_mode_isolate(
3981 const char *filename
,
3983 const char *section
,
3984 unsigned section_line
,
3998 r
= parse_boolean(rvalue
);
4000 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse boolean, ignoring: %s", rvalue
);
4004 log_notice("%s is deprecated. Please use OnFailureJobMode= instead", lvalue
);
4006 *m
= r
? JOB_ISOLATE
: JOB_REPLACE
;
4010 int config_parse_exec_directories(
4012 const char *filename
,
4014 const char *section
,
4015 unsigned section_line
,
4023 const Unit
*u
= userdata
;
4032 if (isempty(rvalue
)) {
4033 /* Empty assignment resets the list */
4034 *rt
= strv_free(*rt
);
4038 for (p
= rvalue
;;) {
4039 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
4041 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
4045 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
4046 "Invalid syntax, ignoring: %s", rvalue
);
4052 r
= unit_full_printf(u
, word
, &k
);
4054 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4055 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
4059 r
= path_simplify_and_warn(k
, PATH_CHECK_RELATIVE
, unit
, filename
, line
, lvalue
);
4063 if (path_startswith(k
, "private")) {
4064 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
4065 "%s= path can't be 'private', ignoring assignment: %s", lvalue
, word
);
4069 r
= strv_push(rt
, k
);
4076 int config_parse_set_status(
4078 const char *filename
,
4080 const char *section
,
4081 unsigned section_line
,
4089 const char *word
, *state
;
4091 ExitStatusSet
*status_set
= data
;
4098 /* Empty assignment resets the list */
4099 if (isempty(rvalue
)) {
4100 exit_status_set_free(status_set
);
4104 FOREACH_WORD(word
, l
, rvalue
, state
) {
4105 _cleanup_free_
char *temp
;
4108 temp
= strndup(word
, l
);
4112 /* We need to call exit_status_from_string() first, because we want
4113 * to parse numbers as exit statuses, not signals. */
4115 r
= exit_status_from_string(temp
);
4117 assert(r
>= 0 && r
< 256);
4118 bitmap
= &status_set
->status
;
4120 r
= signal_from_string(temp
);
4123 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
4124 "Failed to parse value, ignoring: %s", word
);
4127 bitmap
= &status_set
->signal
;
4130 r
= bitmap_set(bitmap
, r
);
4132 return log_error_errno(r
, "Failed to set signal or status %s: %m", word
);
4134 if (!isempty(state
))
4135 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Trailing garbage, ignoring.");
4140 int config_parse_namespace_path_strv(
4142 const char *filename
,
4144 const char *section
,
4145 unsigned section_line
,
4152 const Unit
*u
= userdata
;
4154 const char *p
= rvalue
;
4162 if (isempty(rvalue
)) {
4163 /* Empty assignment resets the list */
4164 *sv
= strv_free(*sv
);
4169 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
, *joined
= NULL
;
4171 bool ignore_enoent
= false, shall_prefix
= false;
4173 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
4179 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
4184 if (startswith(w
, "-")) {
4185 ignore_enoent
= true;
4188 if (startswith(w
, "+")) {
4189 shall_prefix
= true;
4193 r
= unit_full_printf(u
, w
, &resolved
);
4195 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", w
);
4199 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4203 joined
= strjoin(ignore_enoent
? "-" : "",
4204 shall_prefix
? "+" : "",
4207 r
= strv_push(sv
, joined
);
4217 int config_parse_temporary_filesystems(
4219 const char *filename
,
4221 const char *section
,
4222 unsigned section_line
,
4229 const Unit
*u
= userdata
;
4230 ExecContext
*c
= data
;
4231 const char *p
= rvalue
;
4239 if (isempty(rvalue
)) {
4240 /* Empty assignment resets the list */
4241 temporary_filesystem_free_many(c
->temporary_filesystems
, c
->n_temporary_filesystems
);
4242 c
->temporary_filesystems
= NULL
;
4243 c
->n_temporary_filesystems
= 0;
4248 _cleanup_free_
char *word
= NULL
, *path
= NULL
, *resolved
= NULL
;
4251 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
4257 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
4262 r
= extract_first_word(&w
, &path
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4266 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", word
);
4270 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid syntax, ignoring: %s", word
);
4274 r
= unit_full_printf(u
, path
, &resolved
);
4276 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", path
);
4280 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4284 r
= temporary_filesystem_add(&c
->temporary_filesystems
, &c
->n_temporary_filesystems
, resolved
, w
);
4290 int config_parse_bind_paths(
4292 const char *filename
,
4294 const char *section
,
4295 unsigned section_line
,
4302 ExecContext
*c
= data
;
4303 const Unit
*u
= userdata
;
4312 if (isempty(rvalue
)) {
4313 /* Empty assignment resets the list */
4314 bind_mount_free_many(c
->bind_mounts
, c
->n_bind_mounts
);
4315 c
->bind_mounts
= NULL
;
4316 c
->n_bind_mounts
= 0;
4322 _cleanup_free_
char *source
= NULL
, *destination
= NULL
;
4323 _cleanup_free_
char *sresolved
= NULL
, *dresolved
= NULL
;
4324 char *s
= NULL
, *d
= NULL
;
4325 bool rbind
= true, ignore_enoent
= false;
4327 r
= extract_first_word(&p
, &source
, ":" WHITESPACE
, EXTRACT_UNQUOTE
|EXTRACT_DONT_COALESCE_SEPARATORS
);
4333 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
4337 r
= unit_full_printf(u
, source
, &sresolved
);
4339 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4340 "Failed to resolved unit specifiers in \"%s\", ignoring: %m", source
);
4346 ignore_enoent
= true;
4350 r
= path_simplify_and_warn(s
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4354 /* Optionally, the destination is specified. */
4355 if (p
&& p
[-1] == ':') {
4356 r
= extract_first_word(&p
, &destination
, ":" WHITESPACE
, EXTRACT_UNQUOTE
|EXTRACT_DONT_COALESCE_SEPARATORS
);
4360 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
4364 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Missing argument after ':', ignoring: %s", s
);
4368 r
= unit_full_printf(u
, destination
, &dresolved
);
4370 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4371 "Failed to resolved specifiers in \"%s\", ignoring: %m", destination
);
4375 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4381 /* Optionally, there's also a short option string specified */
4382 if (p
&& p
[-1] == ':') {
4383 _cleanup_free_
char *options
= NULL
;
4385 r
= extract_first_word(&p
, &options
, NULL
, EXTRACT_UNQUOTE
);
4389 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s: %s", lvalue
, rvalue
);
4393 if (isempty(options
) || streq(options
, "rbind"))
4395 else if (streq(options
, "norbind"))
4398 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid option string, ignoring setting: %s", options
);
4405 r
= bind_mount_add(&c
->bind_mounts
, &c
->n_bind_mounts
,
4409 .read_only
= !!strstr(lvalue
, "ReadOnly"),
4411 .ignore_enoent
= ignore_enoent
,
4420 int config_parse_job_timeout_sec(
4422 const char *filename
,
4424 const char *section
,
4425 unsigned section_line
,
4441 r
= parse_sec_fix_0(rvalue
, &usec
);
4443 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse JobTimeoutSec= parameter, ignoring: %s", rvalue
);
4447 /* If the user explicitly changed JobTimeoutSec= also change JobRunningTimeoutSec=, for compatibility with old
4448 * versions. If JobRunningTimeoutSec= was explicitly set, avoid this however as whatever the user picked should
4451 if (!u
->job_running_timeout_set
)
4452 u
->job_running_timeout
= usec
;
4454 u
->job_timeout
= usec
;
4459 int config_parse_job_running_timeout_sec(
4461 const char *filename
,
4463 const char *section
,
4464 unsigned section_line
,
4480 r
= parse_sec_fix_0(rvalue
, &usec
);
4482 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse JobRunningTimeoutSec= parameter, ignoring: %s", rvalue
);
4486 u
->job_running_timeout
= usec
;
4487 u
->job_running_timeout_set
= true;
4492 int config_parse_emergency_action(
4494 const char *filename
,
4496 const char *section
,
4497 unsigned section_line
,
4505 EmergencyAction
*x
= data
;
4514 m
= ((Unit
*) userdata
)->manager
;
4518 r
= parse_emergency_action(rvalue
, MANAGER_IS_SYSTEM(m
), x
);
4520 if (r
== -EOPNOTSUPP
&& MANAGER_IS_USER(m
)) {
4521 /* Compat mode: remove for systemd 241. */
4523 log_syntax(unit
, LOG_INFO
, filename
, line
, r
,
4524 "%s= in user mode specified as \"%s\", using \"exit-force\" instead.",
4526 *x
= EMERGENCY_ACTION_EXIT_FORCE
;
4530 if (r
== -EOPNOTSUPP
)
4531 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4532 "%s= specified as %s mode action, ignoring: %s",
4533 lvalue
, MANAGER_IS_SYSTEM(m
) ? "user" : "system", rvalue
);
4535 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4536 "Failed to parse %s=, ignoring: %s", lvalue
, rvalue
);
4543 int config_parse_pid_file(
4545 const char *filename
,
4547 const char *section
,
4548 unsigned section_line
,
4555 _cleanup_free_
char *k
= NULL
, *n
= NULL
;
4556 const Unit
*u
= userdata
;
4565 if (isempty(rvalue
)) {
4566 /* An empty assignment removes already set value. */
4571 r
= unit_full_printf(u
, rvalue
, &k
);
4573 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
4577 /* If this is a relative path make it absolute by prefixing the /run */
4578 n
= path_make_absolute(k
, u
->manager
->prefix
[EXEC_DIRECTORY_RUNTIME
]);
4582 /* Check that the result is a sensible path */
4583 r
= path_simplify_and_warn(n
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4587 r
= patch_var_run(unit
, filename
, line
, lvalue
, &n
);
4591 free_and_replace(*s
, n
);
4595 int config_parse_exit_status(
4597 const char *filename
,
4599 const char *section
,
4600 unsigned section_line
,
4607 int *exit_status
= data
, r
;
4613 assert(exit_status
);
4615 if (isempty(rvalue
)) {
4620 r
= safe_atou8(rvalue
, &u
);
4622 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse exit status '%s', ignoring: %m", rvalue
);
4630 int config_parse_disable_controllers(
4632 const char *filename
,
4634 const char *section
,
4635 unsigned section_line
,
4643 CGroupContext
*c
= data
;
4644 CGroupMask disabled_mask
;
4646 /* 1. If empty, make all controllers eligible for use again.
4647 * 2. If non-empty, merge all listed controllers, space separated. */
4649 if (isempty(rvalue
)) {
4650 c
->disable_controllers
= 0;
4654 r
= cg_mask_from_string(rvalue
, &disabled_mask
);
4655 if (r
< 0 || disabled_mask
<= 0) {
4656 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid cgroup string: %s, ignoring", rvalue
);
4660 c
->disable_controllers
|= disabled_mask
;
4665 int config_parse_ip_filter_bpf_progs(
4667 const char *filename
,
4669 const char *section
,
4670 unsigned section_line
,
4677 _cleanup_free_
char *resolved
= NULL
;
4678 const Unit
*u
= userdata
;
4679 char ***paths
= data
;
4687 if (isempty(rvalue
)) {
4688 *paths
= strv_free(*paths
);
4692 r
= unit_full_printf(u
, rvalue
, &resolved
);
4694 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
4698 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4702 if (strv_contains(*paths
, resolved
))
4705 r
= strv_extend(paths
, resolved
);
4709 r
= bpf_firewall_supported();
4712 if (r
!= BPF_FIREWALL_SUPPORTED_WITH_MULTI
) {
4713 static bool warned
= false;
4715 log_full(warned
? LOG_DEBUG
: LOG_WARNING
,
4716 "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"
4717 "Starting this unit will fail! (This warning is only shown for the first loaded unit using IP firewalling.)", filename
, line
, lvalue
, rvalue
);
4725 static int merge_by_names(Unit
**u
, Set
*names
, const char *id
) {
4732 /* Let's try to add in all names that are aliases of this unit */
4733 while ((k
= set_steal_first(names
))) {
4734 _cleanup_free_ _unused_
char *free_k
= k
;
4736 /* First try to merge in the other name into our unit */
4737 r
= unit_merge_by_name(*u
, k
);
4741 /* Hmm, we couldn't merge the other unit into ours? Then let's try it the other way
4744 other
= manager_get_unit((*u
)->manager
, k
);
4746 return r
; /* return previous failure */
4748 r
= unit_merge(other
, *u
);
4753 return merge_by_names(u
, names
, NULL
);
4756 if (streq_ptr(id
, k
))
4757 unit_choose_id(*u
, id
);
4763 int unit_load_fragment(Unit
*u
) {
4764 const char *fragment
;
4765 _cleanup_set_free_free_ Set
*names
= NULL
;
4770 assert(u
->load_state
== UNIT_STUB
);
4774 u
->load_state
= UNIT_LOADED
;
4778 /* Possibly rebuild the fragment map to catch new units */
4779 r
= unit_file_build_name_map(&u
->manager
->lookup_paths
,
4780 &u
->manager
->unit_cache_mtime
,
4781 &u
->manager
->unit_id_map
,
4782 &u
->manager
->unit_name_map
,
4783 &u
->manager
->unit_path_cache
);
4785 return log_error_errno(r
, "Failed to rebuild name map: %m");
4787 r
= unit_file_find_fragment(u
->manager
->unit_id_map
,
4788 u
->manager
->unit_name_map
,
4792 if (r
< 0 && r
!= -ENOENT
)
4796 /* Open the file, check if this is a mask, otherwise read. */
4797 _cleanup_fclose_
FILE *f
= NULL
;
4799 /* Try to open the file name. A symlink is OK, for example for linked files or masks. We
4800 * expect that all symlinks within the lookup paths have been already resolved, but we don't
4801 * verify this here. */
4802 f
= fopen(fragment
, "re");
4804 return log_unit_notice_errno(u
, errno
, "Failed to open %s: %m", fragment
);
4806 if (fstat(fileno(f
), &st
) < 0)
4809 r
= free_and_strdup(&u
->fragment_path
, fragment
);
4813 if (null_or_empty(&st
)) {
4814 /* Unit file is masked */
4816 u
->load_state
= u
->perpetual
? UNIT_LOADED
: UNIT_MASKED
; /* don't allow perpetual units to ever be masked */
4817 u
->fragment_mtime
= 0;
4819 u
->load_state
= UNIT_LOADED
;
4820 u
->fragment_mtime
= timespec_load(&st
.st_mtim
);
4822 /* Now, parse the file contents */
4823 r
= config_parse(u
->id
, fragment
, f
,
4824 UNIT_VTABLE(u
)->sections
,
4825 config_item_perf_lookup
, load_fragment_gperf_lookup
,
4826 CONFIG_PARSE_ALLOW_INCLUDE
, u
);
4828 log_unit_notice_errno(u
, r
, "Unit configuration has fatal error, unit will not be started.");
4834 if (u
->source_path
) {
4835 if (stat(u
->source_path
, &st
) >= 0)
4836 u
->source_mtime
= timespec_load(&st
.st_mtim
);
4838 u
->source_mtime
= 0;
4841 /* We do the merge dance here because for some unit types, the unit might have aliases which are not
4842 * declared in the file system. In particular, this is true (and frequent) for device and swap units.
4845 const char *id
= u
->id
;
4846 _cleanup_free_
char *free_id
= NULL
;
4849 id
= basename(fragment
);
4850 if (unit_name_is_valid(id
, UNIT_NAME_TEMPLATE
)) {
4851 assert(u
->instance
); /* If we're not trying to use a template for non-instanced unit,
4852 * this must be set. */
4854 r
= unit_name_replace_instance(id
, u
->instance
, &free_id
);
4856 return log_debug_errno(r
, "Failed to build id (%s + %s): %m", id
, u
->instance
);
4862 r
= merge_by_names(&merged
, names
, id
);
4867 u
->load_state
= UNIT_MERGED
;
4872 void unit_dump_config_items(FILE *f
) {
4873 static const struct {
4874 const ConfigParserCallback callback
;
4877 { config_parse_warn_compat
, "NOTSUPPORTED" },
4878 { config_parse_int
, "INTEGER" },
4879 { config_parse_unsigned
, "UNSIGNED" },
4880 { config_parse_iec_size
, "SIZE" },
4881 { config_parse_iec_uint64
, "SIZE" },
4882 { config_parse_si_uint64
, "SIZE" },
4883 { config_parse_bool
, "BOOLEAN" },
4884 { config_parse_string
, "STRING" },
4885 { config_parse_path
, "PATH" },
4886 { config_parse_unit_path_printf
, "PATH" },
4887 { config_parse_strv
, "STRING [...]" },
4888 { config_parse_exec_nice
, "NICE" },
4889 { config_parse_exec_oom_score_adjust
, "OOMSCOREADJUST" },
4890 { config_parse_exec_io_class
, "IOCLASS" },
4891 { config_parse_exec_io_priority
, "IOPRIORITY" },
4892 { config_parse_exec_cpu_sched_policy
, "CPUSCHEDPOLICY" },
4893 { config_parse_exec_cpu_sched_prio
, "CPUSCHEDPRIO" },
4894 { config_parse_exec_cpu_affinity
, "CPUAFFINITY" },
4895 { config_parse_mode
, "MODE" },
4896 { config_parse_unit_env_file
, "FILE" },
4897 { config_parse_exec_output
, "OUTPUT" },
4898 { config_parse_exec_input
, "INPUT" },
4899 { config_parse_log_facility
, "FACILITY" },
4900 { config_parse_log_level
, "LEVEL" },
4901 { config_parse_exec_secure_bits
, "SECUREBITS" },
4902 { config_parse_capability_set
, "BOUNDINGSET" },
4903 { config_parse_rlimit
, "LIMIT" },
4904 { config_parse_unit_deps
, "UNIT [...]" },
4905 { config_parse_exec
, "PATH [ARGUMENT [...]]" },
4906 { config_parse_service_type
, "SERVICETYPE" },
4907 { config_parse_service_restart
, "SERVICERESTART" },
4908 { config_parse_kill_mode
, "KILLMODE" },
4909 { config_parse_signal
, "SIGNAL" },
4910 { config_parse_socket_listen
, "SOCKET [...]" },
4911 { config_parse_socket_bind
, "SOCKETBIND" },
4912 { config_parse_socket_bindtodevice
, "NETWORKINTERFACE" },
4913 { config_parse_sec
, "SECONDS" },
4914 { config_parse_nsec
, "NANOSECONDS" },
4915 { config_parse_namespace_path_strv
, "PATH [...]" },
4916 { config_parse_bind_paths
, "PATH[:PATH[:OPTIONS]] [...]" },
4917 { config_parse_unit_requires_mounts_for
, "PATH [...]" },
4918 { config_parse_exec_mount_flags
, "MOUNTFLAG [...]" },
4919 { config_parse_unit_string_printf
, "STRING" },
4920 { config_parse_trigger_unit
, "UNIT" },
4921 { config_parse_timer
, "TIMER" },
4922 { config_parse_path_spec
, "PATH" },
4923 { config_parse_notify_access
, "ACCESS" },
4924 { config_parse_ip_tos
, "TOS" },
4925 { config_parse_unit_condition_path
, "CONDITION" },
4926 { config_parse_unit_condition_string
, "CONDITION" },
4927 { config_parse_unit_condition_null
, "CONDITION" },
4928 { config_parse_unit_slice
, "SLICE" },
4929 { config_parse_documentation
, "URL" },
4930 { config_parse_service_timeout
, "SECONDS" },
4931 { config_parse_emergency_action
, "ACTION" },
4932 { config_parse_set_status
, "STATUS" },
4933 { config_parse_service_sockets
, "SOCKETS" },
4934 { config_parse_environ
, "ENVIRON" },
4936 { config_parse_syscall_filter
, "SYSCALLS" },
4937 { config_parse_syscall_archs
, "ARCHS" },
4938 { config_parse_syscall_errno
, "ERRNO" },
4939 { config_parse_address_families
, "FAMILIES" },
4940 { config_parse_restrict_namespaces
, "NAMESPACES" },
4942 { config_parse_cpu_shares
, "SHARES" },
4943 { config_parse_cg_weight
, "WEIGHT" },
4944 { config_parse_memory_limit
, "LIMIT" },
4945 { config_parse_device_allow
, "DEVICE" },
4946 { config_parse_device_policy
, "POLICY" },
4947 { config_parse_io_limit
, "LIMIT" },
4948 { config_parse_io_device_weight
, "DEVICEWEIGHT" },
4949 { config_parse_io_device_latency
, "DEVICELATENCY" },
4950 { config_parse_blockio_bandwidth
, "BANDWIDTH" },
4951 { config_parse_blockio_weight
, "WEIGHT" },
4952 { config_parse_blockio_device_weight
, "DEVICEWEIGHT" },
4953 { config_parse_long
, "LONG" },
4954 { config_parse_socket_service
, "SERVICE" },
4956 { config_parse_exec_selinux_context
, "LABEL" },
4958 { config_parse_job_mode
, "MODE" },
4959 { config_parse_job_mode_isolate
, "BOOLEAN" },
4960 { config_parse_personality
, "PERSONALITY" },
4963 const char *prev
= NULL
;
4968 NULSTR_FOREACH(i
, load_fragment_gperf_nulstr
) {
4969 const char *rvalue
= "OTHER", *lvalue
;
4970 const ConfigPerfItem
*p
;
4975 assert_se(p
= load_fragment_gperf_lookup(i
, strlen(i
)));
4977 /* Hide legacy settings */
4978 if (p
->parse
== config_parse_warn_compat
&&
4979 p
->ltype
== DISABLED_LEGACY
)
4982 for (j
= 0; j
< ELEMENTSOF(table
); j
++)
4983 if (p
->parse
== table
[j
].callback
) {
4984 rvalue
= table
[j
].rvalue
;
4988 dot
= strchr(i
, '.');
4989 lvalue
= dot
? dot
+ 1 : i
;
4993 if (!prev
|| !strneq(prev
, i
, prefix_len
+1)) {
4997 fprintf(f
, "[%.*s]\n", (int) prefix_len
, i
);
5000 fprintf(f
, "%s=%s\n", lvalue
, rvalue
);
5005 int config_parse_cpu_affinity2(
5007 const char *filename
,
5009 const char *section
,
5010 unsigned section_line
,
5017 CPUSet
*affinity
= data
;
5021 (void) parse_cpu_set_extend(rvalue
, affinity
, true, unit
, filename
, line
, lvalue
);
5026 int config_parse_show_status(
5028 const char *filename
,
5030 const char *section
,
5031 unsigned section_line
,
5039 ShowStatus
*b
= data
;
5046 k
= parse_show_status(rvalue
, b
);
5048 log_syntax(unit
, LOG_ERR
, filename
, line
, k
, "Failed to parse show status setting, ignoring: %s", rvalue
);
5055 int config_parse_output_restricted(
5057 const char *filename
,
5059 const char *section
,
5060 unsigned section_line
,
5067 ExecOutput t
, *eo
= data
;
5068 bool obsolete
= false;
5075 if (streq(rvalue
, "syslog")) {
5076 t
= EXEC_OUTPUT_JOURNAL
;
5078 } else if (streq(rvalue
, "syslog+console")) {
5079 t
= EXEC_OUTPUT_JOURNAL_AND_CONSOLE
;
5082 t
= exec_output_from_string(rvalue
);
5084 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse output type, ignoring: %s", rvalue
);
5088 if (IN_SET(t
, EXEC_OUTPUT_SOCKET
, EXEC_OUTPUT_NAMED_FD
, EXEC_OUTPUT_FILE
, EXEC_OUTPUT_FILE_APPEND
)) {
5089 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Standard output types socket, fd:, file:, append: are not supported as defaults, ignoring: %s", rvalue
);
5095 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
5096 "Standard output type %s is obsolete, automatically updating to %s. Please update your configuration.",
5097 rvalue
, exec_output_to_string(t
));
5103 int config_parse_crash_chvt(
5105 const char *filename
,
5107 const char *section
,
5108 unsigned section_line
,
5122 r
= parse_crash_chvt(rvalue
, data
);
5124 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse CrashChangeVT= setting, ignoring: %s", rvalue
);
5131 int config_parse_swap_priority(
5133 const char *filename
,
5135 const char *section
,
5136 unsigned section_line
,
5152 if (isempty(rvalue
)) {
5153 s
->parameters_fragment
.priority
= -1;
5154 s
->parameters_fragment
.priority_set
= false;
5158 r
= safe_atoi(rvalue
, &priority
);
5160 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid swap priority '%s', ignoring.", rvalue
);
5164 if (priority
< -1) {
5165 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
);
5169 if (priority
> 32767) {
5170 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Swap priority out of range, ignoring: %s", rvalue
);
5174 s
->parameters_fragment
.priority
= priority
;
5175 s
->parameters_fragment
.priority_set
= true;