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 "unit-name.h"
56 #include "unit-printf.h"
57 #include "user-util.h"
58 #include "time-util.h"
61 static int parse_socket_protocol(const char *s
) {
64 r
= parse_ip_protocol(s
);
67 if (!IN_SET(r
, IPPROTO_UDPLITE
, IPPROTO_SCTP
))
68 return -EPROTONOSUPPORT
;
73 int parse_crash_chvt(const char *value
, int *data
) {
76 if (safe_atoi(value
, data
) >= 0)
79 b
= parse_boolean(value
);
84 *data
= 0; /* switch to where kmsg goes */
86 *data
= -1; /* turn off switching */
91 int parse_confirm_spawn(const char *value
, char **console
) {
95 r
= value
? parse_boolean(value
) : 1;
99 } else if (r
> 0) /* on with default tty */
100 s
= strdup("/dev/console");
101 else if (is_path(value
)) /* on with fully qualified path */
103 else /* on with only a tty file name, not a fully qualified path */
104 s
= path_join("/dev/", value
);
112 DEFINE_CONFIG_PARSE(config_parse_socket_protocol
, parse_socket_protocol
, "Failed to parse socket protocol");
113 DEFINE_CONFIG_PARSE(config_parse_exec_secure_bits
, secure_bits_from_string
, "Failed to parse secure bits");
114 DEFINE_CONFIG_PARSE_ENUM(config_parse_collect_mode
, collect_mode
, CollectMode
, "Failed to parse garbage collection mode");
115 DEFINE_CONFIG_PARSE_ENUM(config_parse_device_policy
, cgroup_device_policy
, CGroupDevicePolicy
, "Failed to parse device policy");
116 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_keyring_mode
, exec_keyring_mode
, ExecKeyringMode
, "Failed to parse keyring mode");
117 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_utmp_mode
, exec_utmp_mode
, ExecUtmpMode
, "Failed to parse utmp mode");
118 DEFINE_CONFIG_PARSE_ENUM(config_parse_job_mode
, job_mode
, JobMode
, "Failed to parse job mode");
119 DEFINE_CONFIG_PARSE_ENUM(config_parse_kill_mode
, kill_mode
, KillMode
, "Failed to parse kill mode");
120 DEFINE_CONFIG_PARSE_ENUM(config_parse_notify_access
, notify_access
, NotifyAccess
, "Failed to parse notify access specifier");
121 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_home
, protect_home
, ProtectHome
, "Failed to parse protect home value");
122 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_system
, protect_system
, ProtectSystem
, "Failed to parse protect system value");
123 DEFINE_CONFIG_PARSE_ENUM(config_parse_runtime_preserve_mode
, exec_preserve_mode
, ExecPreserveMode
, "Failed to parse runtime directory preserve mode");
124 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_type
, service_type
, ServiceType
, "Failed to parse service type");
125 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart
, service_restart
, ServiceRestart
, "Failed to parse service restart specifier");
126 DEFINE_CONFIG_PARSE_ENUM(config_parse_socket_bind
, socket_address_bind_ipv6_only_or_bool
, SocketAddressBindIPv6Only
, "Failed to parse bind IPv6 only value");
127 DEFINE_CONFIG_PARSE_ENUM(config_parse_oom_policy
, oom_policy
, OOMPolicy
, "Failed to parse OOM policy");
128 DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_ip_tos
, ip_tos
, int, -1, "Failed to parse IP TOS value");
129 DEFINE_CONFIG_PARSE_PTR(config_parse_blockio_weight
, cg_blkio_weight_parse
, uint64_t, "Invalid block IO weight");
130 DEFINE_CONFIG_PARSE_PTR(config_parse_cg_weight
, cg_weight_parse
, uint64_t, "Invalid weight");
131 DEFINE_CONFIG_PARSE_PTR(config_parse_cpu_shares
, cg_cpu_shares_parse
, uint64_t, "Invalid CPU shares");
132 DEFINE_CONFIG_PARSE_PTR(config_parse_exec_mount_flags
, mount_propagation_flags_from_string
, unsigned long, "Failed to parse mount flag");
133 DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_numa_policy
, mpol
, int, -1, "Invalid NUMA policy type");
134 DEFINE_CONFIG_PARSE_ENUM(config_parse_status_unit_format
, status_unit_format
, StatusUnitFormat
, "Failed to parse status unit format");
136 int config_parse_unit_deps(
138 const char *filename
,
141 unsigned section_line
,
148 UnitDependency d
= ltype
;
158 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
161 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_RETAIN_ESCAPE
);
167 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
171 r
= unit_name_printf(u
, word
, &k
);
173 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
177 r
= unit_add_dependency_by_name(u
, d
, k
, true, UNIT_DEPENDENCY_FILE
);
179 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
185 int config_parse_obsolete_unit_deps(
187 const char *filename
,
190 unsigned section_line
,
197 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
198 "Unit dependency type %s= is obsolete, replacing by %s=, please update your unit file", lvalue
, unit_dependency_to_string(ltype
));
200 return config_parse_unit_deps(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
);
203 int config_parse_unit_string_printf(
205 const char *filename
,
208 unsigned section_line
,
215 _cleanup_free_
char *k
= NULL
;
216 const Unit
*u
= userdata
;
224 r
= unit_full_printf(u
, rvalue
, &k
);
226 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
230 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
233 int config_parse_unit_strv_printf(
235 const char *filename
,
238 unsigned section_line
,
245 const Unit
*u
= userdata
;
246 _cleanup_free_
char *k
= NULL
;
254 r
= unit_full_printf(u
, rvalue
, &k
);
256 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
260 return config_parse_strv(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
263 int config_parse_unit_path_printf(
265 const char *filename
,
268 unsigned section_line
,
275 _cleanup_free_
char *k
= NULL
;
276 const Unit
*u
= userdata
;
285 /* Let's not bother with anything that is too long */
286 if (strlen(rvalue
) >= PATH_MAX
) {
287 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
288 "%s value too long%s.",
289 lvalue
, fatal
? "" : ", ignoring");
290 return fatal
? -ENAMETOOLONG
: 0;
293 r
= unit_full_printf(u
, rvalue
, &k
);
295 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
296 "Failed to resolve unit specifiers in '%s'%s: %m",
297 rvalue
, fatal
? "" : ", ignoring");
298 return fatal
? -ENOEXEC
: 0;
301 return config_parse_path(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
304 int config_parse_unit_path_strv_printf(
306 const char *filename
,
309 unsigned section_line
,
317 const Unit
*u
= userdata
;
326 if (isempty(rvalue
)) {
332 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
334 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
340 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
341 "Invalid syntax, ignoring: %s", rvalue
);
345 r
= unit_full_printf(u
, word
, &k
);
347 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
348 "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
352 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
356 r
= strv_consume(x
, TAKE_PTR(k
));
362 static int patch_var_run(
364 const char *filename
,
372 e
= path_startswith(*path
, "/var/run/");
376 z
= path_join("/run/", e
);
380 log_syntax(unit
, LOG_NOTICE
, filename
, line
, 0,
381 "%s= references a path below legacy directory /var/run/, updating %s → %s; "
382 "please update the unit file accordingly.", lvalue
, *path
, z
);
384 free_and_replace(*path
, z
);
389 int config_parse_socket_listen(
391 const char *filename
,
394 unsigned section_line
,
401 _cleanup_free_ SocketPort
*p
= NULL
;
413 if (isempty(rvalue
)) {
414 /* An empty assignment removes all ports */
415 socket_free_ports(s
);
419 p
= new0(SocketPort
, 1);
423 if (ltype
!= SOCKET_SOCKET
) {
424 _cleanup_free_
char *k
= NULL
;
426 r
= unit_full_printf(UNIT(s
), rvalue
, &k
);
428 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
432 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
436 if (ltype
== SOCKET_FIFO
) {
437 r
= patch_var_run(unit
, filename
, line
, lvalue
, &k
);
442 free_and_replace(p
->path
, k
);
445 } else if (streq(lvalue
, "ListenNetlink")) {
446 _cleanup_free_
char *k
= NULL
;
448 r
= unit_full_printf(UNIT(s
), rvalue
, &k
);
450 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
454 r
= socket_address_parse_netlink(&p
->address
, k
);
456 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse address value in '%s', ignoring: %m", k
);
460 p
->type
= SOCKET_SOCKET
;
463 _cleanup_free_
char *k
= NULL
;
465 r
= unit_full_printf(UNIT(s
), rvalue
, &k
);
467 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
471 if (k
[0] == '/') { /* Only for AF_UNIX file system sockets… */
472 r
= patch_var_run(unit
, filename
, line
, lvalue
, &k
);
477 r
= socket_address_parse_and_warn(&p
->address
, k
);
479 if (r
!= -EAFNOSUPPORT
)
480 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse address value in '%s', ignoring: %m", k
);
484 if (streq(lvalue
, "ListenStream"))
485 p
->address
.type
= SOCK_STREAM
;
486 else if (streq(lvalue
, "ListenDatagram"))
487 p
->address
.type
= SOCK_DGRAM
;
489 assert(streq(lvalue
, "ListenSequentialPacket"));
490 p
->address
.type
= SOCK_SEQPACKET
;
493 if (socket_address_family(&p
->address
) != AF_LOCAL
&& p
->address
.type
== SOCK_SEQPACKET
) {
494 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Address family not supported, ignoring: %s", rvalue
);
498 p
->type
= SOCKET_SOCKET
;
502 p
->auxiliary_fds
= NULL
;
503 p
->n_auxiliary_fds
= 0;
506 LIST_FIND_TAIL(port
, s
->ports
, tail
);
507 LIST_INSERT_AFTER(port
, s
->ports
, tail
, p
);
514 int config_parse_exec_nice(
516 const char *filename
,
519 unsigned section_line
,
526 ExecContext
*c
= data
;
534 if (isempty(rvalue
)) {
539 r
= parse_nice(rvalue
, &priority
);
542 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Nice priority out of range, ignoring: %s", rvalue
);
544 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse nice priority '%s', ignoring: %m", rvalue
);
554 int config_parse_exec_oom_score_adjust(
556 const char *filename
,
559 unsigned section_line
,
566 ExecContext
*c
= data
;
574 if (isempty(rvalue
)) {
575 c
->oom_score_adjust_set
= false;
579 r
= parse_oom_score_adjust(rvalue
, &oa
);
582 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "OOM score adjust value out of range, ignoring: %s", rvalue
);
584 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse the OOM score adjust value '%s', ignoring: %m", rvalue
);
588 c
->oom_score_adjust
= oa
;
589 c
->oom_score_adjust_set
= true;
594 int config_parse_exec(
596 const char *filename
,
599 unsigned section_line
,
606 ExecCommand
**e
= data
;
607 const Unit
*u
= userdata
;
619 if (isempty(rvalue
)) {
620 /* An empty assignment resets the list */
621 *e
= exec_command_free_list(*e
);
627 _cleanup_free_
char *path
= NULL
, *firstword
= NULL
;
628 ExecCommandFlags flags
= 0;
629 bool ignore
= false, separate_argv0
= false;
630 _cleanup_free_ ExecCommand
*nce
= NULL
;
631 _cleanup_strv_free_
char **n
= NULL
;
632 size_t nlen
= 0, nbufsize
= 0;
637 r
= extract_first_word_and_warn(&p
, &firstword
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
643 /* We accept an absolute path as first argument. If it's prefixed with - and the path doesn't
644 * exist, we ignore it instead of erroring out; if it's prefixed with @, we allow overriding of
645 * argv[0]; if it's prefixed with :, we will not do environment variable substitution;
646 * if it's prefixed with +, it will be run with full privileges and no sandboxing; if
647 * it's prefixed with '!' we apply sandboxing, but do not change user/group credentials; if
648 * it's prefixed with '!!', then we apply user/group credentials if the kernel supports ambient
649 * capabilities -- if it doesn't we don't apply the credentials themselves, but do apply most
650 * other sandboxing, with some special exceptions for changing UID.
652 * The idea is that '!!' may be used to write services that can take benefit of systemd's
653 * UID/GID dropping if the kernel supports ambient creds, but provide an automatic fallback to
654 * privilege dropping within the daemon if the kernel does not offer that. */
656 if (*f
== '-' && !(flags
& EXEC_COMMAND_IGNORE_FAILURE
)) {
657 flags
|= EXEC_COMMAND_IGNORE_FAILURE
;
659 } else if (*f
== '@' && !separate_argv0
)
660 separate_argv0
= true;
661 else if (*f
== ':' && !(flags
& EXEC_COMMAND_NO_ENV_EXPAND
))
662 flags
|= EXEC_COMMAND_NO_ENV_EXPAND
;
663 else if (*f
== '+' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
664 flags
|= EXEC_COMMAND_FULLY_PRIVILEGED
;
665 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
666 flags
|= EXEC_COMMAND_NO_SETUID
;
667 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_AMBIENT_MAGIC
))) {
668 flags
&= ~EXEC_COMMAND_NO_SETUID
;
669 flags
|= EXEC_COMMAND_AMBIENT_MAGIC
;
675 r
= unit_full_printf(u
, f
, &path
);
677 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
678 "Failed to resolve unit specifiers in '%s'%s: %m",
679 f
, ignore
? ", ignoring" : "");
680 return ignore
? 0 : -ENOEXEC
;
684 /* First word is either "-" or "@" with no command. */
685 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
686 "Empty path in command line%s: '%s'",
687 ignore
? ", ignoring" : "", rvalue
);
688 return ignore
? 0 : -ENOEXEC
;
690 if (!string_is_safe(path
)) {
691 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
692 "Executable name contains special characters%s: %s",
693 ignore
? ", ignoring" : "", path
);
694 return ignore
? 0 : -ENOEXEC
;
696 if (endswith(path
, "/")) {
697 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
698 "Executable path specifies a directory%s: %s",
699 ignore
? ", ignoring" : "", path
);
700 return ignore
? 0 : -ENOEXEC
;
703 if (!path_is_absolute(path
)) {
707 if (!filename_is_valid(path
)) {
708 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
709 "Neither a valid executable name nor an absolute path%s: %s",
710 ignore
? ", ignoring" : "", path
);
711 return ignore
? 0 : -ENOEXEC
;
714 /* Resolve a single-component name to a full path */
715 NULSTR_FOREACH(prefix
, DEFAULT_PATH_NULSTR
) {
716 _cleanup_free_
char *fullpath
= NULL
;
718 fullpath
= path_join(prefix
, path
);
722 if (access(fullpath
, F_OK
) >= 0) {
723 free_and_replace(path
, fullpath
);
730 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
731 "Executable \"%s\" not found in path \"%s\"%s",
732 path
, DEFAULT_PATH
, ignore
? ", ignoring" : "");
733 return ignore
? 0 : -ENOEXEC
;
737 if (!separate_argv0
) {
740 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
750 path_simplify(path
, false);
752 while (!isempty(p
)) {
753 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
755 /* Check explicitly for an unquoted semicolon as
756 * command separator token. */
757 if (p
[0] == ';' && (!p
[1] || strchr(WHITESPACE
, p
[1]))) {
759 p
+= strspn(p
, WHITESPACE
);
764 /* Check for \; explicitly, to not confuse it with \\; or "\;" or "\\;" etc.
765 * extract_first_word() would return the same for all of those. */
766 if (p
[0] == '\\' && p
[1] == ';' && (!p
[2] || strchr(WHITESPACE
, p
[2]))) {
770 p
+= strspn(p
, WHITESPACE
);
772 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
783 r
= extract_first_word_and_warn(&p
, &word
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
787 return ignore
? 0 : -ENOEXEC
;
789 r
= unit_full_printf(u
, word
, &resolved
);
791 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
792 "Failed to resolve unit specifiers in %s%s: %m",
793 word
, ignore
? ", ignoring" : "");
794 return ignore
? 0 : -ENOEXEC
;
797 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
800 n
[nlen
++] = TAKE_PTR(resolved
);
805 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
806 "Empty executable name or zeroeth argument%s: %s",
807 ignore
? ", ignoring" : "", rvalue
);
808 return ignore
? 0 : -ENOEXEC
;
811 nce
= new0(ExecCommand
, 1);
815 nce
->argv
= TAKE_PTR(n
);
816 nce
->path
= TAKE_PTR(path
);
819 exec_command_append_list(e
, nce
);
821 /* Do not _cleanup_free_ these. */
830 int config_parse_socket_bindtodevice(
832 const char *filename
,
835 unsigned section_line
,
849 if (isempty(rvalue
) || streq(rvalue
, "*")) {
850 s
->bind_to_device
= mfree(s
->bind_to_device
);
854 if (!ifname_valid(rvalue
)) {
855 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid interface name, ignoring: %s", rvalue
);
859 if (free_and_strdup(&s
->bind_to_device
, rvalue
) < 0)
865 int config_parse_exec_input(
867 const char *filename
,
870 unsigned section_line
,
877 ExecContext
*c
= data
;
878 const Unit
*u
= userdata
;
888 n
= startswith(rvalue
, "fd:");
890 _cleanup_free_
char *resolved
= NULL
;
892 r
= unit_full_printf(u
, n
, &resolved
);
894 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s': %m", n
);
896 if (isempty(resolved
))
897 resolved
= mfree(resolved
);
898 else if (!fdname_is_valid(resolved
)) {
899 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name: %s", resolved
);
903 free_and_replace(c
->stdio_fdname
[STDIN_FILENO
], resolved
);
905 ei
= EXEC_INPUT_NAMED_FD
;
907 } else if ((n
= startswith(rvalue
, "file:"))) {
908 _cleanup_free_
char *resolved
= NULL
;
910 r
= unit_full_printf(u
, n
, &resolved
);
912 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s': %m", n
);
914 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
918 free_and_replace(c
->stdio_file
[STDIN_FILENO
], resolved
);
920 ei
= EXEC_INPUT_FILE
;
923 ei
= exec_input_from_string(rvalue
);
925 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse input specifier, ignoring: %s", rvalue
);
934 int config_parse_exec_input_text(
936 const char *filename
,
939 unsigned section_line
,
946 _cleanup_free_
char *unescaped
= NULL
, *resolved
= NULL
;
947 ExecContext
*c
= data
;
948 const Unit
*u
= userdata
;
958 if (isempty(rvalue
)) {
959 /* Reset if the empty string is assigned */
960 c
->stdin_data
= mfree(c
->stdin_data
);
961 c
->stdin_data_size
= 0;
965 r
= cunescape(rvalue
, 0, &unescaped
);
967 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to decode C escaped text '%s': %m", rvalue
);
969 r
= unit_full_printf(u
, unescaped
, &resolved
);
971 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s': %m", unescaped
);
973 sz
= strlen(resolved
);
974 if (c
->stdin_data_size
+ sz
+ 1 < c
->stdin_data_size
|| /* check for overflow */
975 c
->stdin_data_size
+ sz
+ 1 > EXEC_STDIN_DATA_MAX
) {
976 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
);
980 p
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
+ 1);
984 *((char*) mempcpy((char*) p
+ c
->stdin_data_size
, resolved
, sz
)) = '\n';
987 c
->stdin_data_size
+= sz
+ 1;
992 int config_parse_exec_input_data(
994 const char *filename
,
997 unsigned section_line
,
1004 _cleanup_free_
void *p
= NULL
;
1005 ExecContext
*c
= data
;
1015 if (isempty(rvalue
)) {
1016 /* Reset if the empty string is assigned */
1017 c
->stdin_data
= mfree(c
->stdin_data
);
1018 c
->stdin_data_size
= 0;
1022 r
= unbase64mem(rvalue
, (size_t) -1, &p
, &sz
);
1024 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to decode base64 data, ignoring: %s", rvalue
);
1028 if (c
->stdin_data_size
+ sz
< c
->stdin_data_size
|| /* check for overflow */
1029 c
->stdin_data_size
+ sz
> EXEC_STDIN_DATA_MAX
) {
1030 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
);
1034 q
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
);
1038 memcpy((uint8_t*) q
+ c
->stdin_data_size
, p
, sz
);
1041 c
->stdin_data_size
+= sz
;
1046 int config_parse_exec_output(
1048 const char *filename
,
1050 const char *section
,
1051 unsigned section_line
,
1058 _cleanup_free_
char *resolved
= NULL
;
1060 ExecContext
*c
= data
;
1061 const Unit
*u
= userdata
;
1071 n
= startswith(rvalue
, "fd:");
1073 r
= unit_full_printf(u
, n
, &resolved
);
1075 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", n
);
1077 if (isempty(resolved
))
1078 resolved
= mfree(resolved
);
1079 else if (!fdname_is_valid(resolved
)) {
1080 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name: %s", resolved
);
1084 eo
= EXEC_OUTPUT_NAMED_FD
;
1086 } else if ((n
= startswith(rvalue
, "file:"))) {
1088 r
= unit_full_printf(u
, n
, &resolved
);
1090 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", n
);
1092 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1096 eo
= EXEC_OUTPUT_FILE
;
1098 } else if ((n
= startswith(rvalue
, "append:"))) {
1100 r
= unit_full_printf(u
, n
, &resolved
);
1102 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", n
);
1104 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1108 eo
= EXEC_OUTPUT_FILE_APPEND
;
1110 eo
= exec_output_from_string(rvalue
);
1112 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse output specifier, ignoring: %s", rvalue
);
1117 if (streq(lvalue
, "StandardOutput")) {
1118 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1119 free_and_replace(c
->stdio_fdname
[STDOUT_FILENO
], resolved
);
1121 free_and_replace(c
->stdio_file
[STDOUT_FILENO
], resolved
);
1126 assert(streq(lvalue
, "StandardError"));
1128 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1129 free_and_replace(c
->stdio_fdname
[STDERR_FILENO
], resolved
);
1131 free_and_replace(c
->stdio_file
[STDERR_FILENO
], resolved
);
1139 int config_parse_exec_io_class(const char *unit
,
1140 const char *filename
,
1142 const char *section
,
1143 unsigned section_line
,
1150 ExecContext
*c
= data
;
1158 if (isempty(rvalue
)) {
1159 c
->ioprio_set
= false;
1160 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE
, 0);
1164 x
= ioprio_class_from_string(rvalue
);
1166 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse IO scheduling class, ignoring: %s", rvalue
);
1170 c
->ioprio
= IOPRIO_PRIO_VALUE(x
, IOPRIO_PRIO_DATA(c
->ioprio
));
1171 c
->ioprio_set
= true;
1176 int config_parse_exec_io_priority(const char *unit
,
1177 const char *filename
,
1179 const char *section
,
1180 unsigned section_line
,
1187 ExecContext
*c
= data
;
1195 if (isempty(rvalue
)) {
1196 c
->ioprio_set
= false;
1197 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE
, 0);
1201 r
= ioprio_parse_priority(rvalue
, &i
);
1203 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse IO priority, ignoring: %s", rvalue
);
1207 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_PRIO_CLASS(c
->ioprio
), i
);
1208 c
->ioprio_set
= true;
1213 int config_parse_exec_cpu_sched_policy(const char *unit
,
1214 const char *filename
,
1216 const char *section
,
1217 unsigned section_line
,
1224 ExecContext
*c
= data
;
1232 if (isempty(rvalue
)) {
1233 c
->cpu_sched_set
= false;
1234 c
->cpu_sched_policy
= SCHED_OTHER
;
1235 c
->cpu_sched_priority
= 0;
1239 x
= sched_policy_from_string(rvalue
);
1241 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse CPU scheduling policy, ignoring: %s", rvalue
);
1245 c
->cpu_sched_policy
= x
;
1246 /* Moving to or from real-time policy? We need to adjust the priority */
1247 c
->cpu_sched_priority
= CLAMP(c
->cpu_sched_priority
, sched_get_priority_min(x
), sched_get_priority_max(x
));
1248 c
->cpu_sched_set
= true;
1253 int config_parse_numa_mask(const char *unit
,
1254 const char *filename
,
1256 const char *section
,
1257 unsigned section_line
,
1264 NUMAPolicy
*p
= data
;
1271 r
= parse_cpu_set_extend(rvalue
, &p
->nodes
, true, unit
, filename
, line
, lvalue
);
1273 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse NUMA node mask, ignoring: %s", rvalue
);
1280 int config_parse_exec_cpu_sched_prio(const char *unit
,
1281 const char *filename
,
1283 const char *section
,
1284 unsigned section_line
,
1291 ExecContext
*c
= data
;
1299 r
= safe_atoi(rvalue
, &i
);
1301 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse CPU scheduling priority, ignoring: %s", rvalue
);
1305 /* On Linux RR/FIFO range from 1 to 99 and OTHER/BATCH may only be 0 */
1306 min
= sched_get_priority_min(c
->cpu_sched_policy
);
1307 max
= sched_get_priority_max(c
->cpu_sched_policy
);
1309 if (i
< min
|| i
> max
) {
1310 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "CPU scheduling priority is out of range, ignoring: %s", rvalue
);
1314 c
->cpu_sched_priority
= i
;
1315 c
->cpu_sched_set
= true;
1320 int config_parse_exec_cpu_affinity(const char *unit
,
1321 const char *filename
,
1323 const char *section
,
1324 unsigned section_line
,
1331 ExecContext
*c
= data
;
1338 return parse_cpu_set_extend(rvalue
, &c
->cpu_set
, true, unit
, filename
, line
, lvalue
);
1341 int config_parse_capability_set(
1343 const char *filename
,
1345 const char *section
,
1346 unsigned section_line
,
1353 uint64_t *capability_set
= data
;
1354 uint64_t sum
= 0, initial
= 0;
1355 bool invert
= false;
1363 if (rvalue
[0] == '~') {
1368 if (streq(lvalue
, "CapabilityBoundingSet"))
1369 initial
= CAP_ALL
; /* initialized to all bits on */
1370 /* else "AmbientCapabilities" initialized to all bits off */
1372 r
= capability_set_from_string(rvalue
, &sum
);
1374 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= specifier '%s', ignoring: %m", lvalue
, rvalue
);
1378 if (sum
== 0 || *capability_set
== initial
)
1379 /* "", "~" or uninitialized data -> replace */
1380 *capability_set
= invert
? ~sum
: sum
;
1382 /* previous data -> merge */
1384 *capability_set
&= ~sum
;
1386 *capability_set
|= sum
;
1392 int config_parse_exec_selinux_context(
1394 const char *filename
,
1396 const char *section
,
1397 unsigned section_line
,
1404 ExecContext
*c
= data
;
1405 const Unit
*u
= userdata
;
1415 if (isempty(rvalue
)) {
1416 c
->selinux_context
= mfree(c
->selinux_context
);
1417 c
->selinux_context_ignore
= false;
1421 if (rvalue
[0] == '-') {
1427 r
= unit_full_printf(u
, rvalue
, &k
);
1429 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1430 "Failed to resolve unit specifiers in '%s'%s: %m",
1431 rvalue
, ignore
? ", ignoring" : "");
1432 return ignore
? 0 : -ENOEXEC
;
1435 free_and_replace(c
->selinux_context
, k
);
1436 c
->selinux_context_ignore
= ignore
;
1441 int config_parse_exec_apparmor_profile(
1443 const char *filename
,
1445 const char *section
,
1446 unsigned section_line
,
1453 ExecContext
*c
= data
;
1454 const Unit
*u
= userdata
;
1464 if (isempty(rvalue
)) {
1465 c
->apparmor_profile
= mfree(c
->apparmor_profile
);
1466 c
->apparmor_profile_ignore
= false;
1470 if (rvalue
[0] == '-') {
1476 r
= unit_full_printf(u
, rvalue
, &k
);
1478 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1479 "Failed to resolve unit specifiers in '%s'%s: %m",
1480 rvalue
, ignore
? ", ignoring" : "");
1481 return ignore
? 0 : -ENOEXEC
;
1484 free_and_replace(c
->apparmor_profile
, k
);
1485 c
->apparmor_profile_ignore
= ignore
;
1490 int config_parse_exec_smack_process_label(
1492 const char *filename
,
1494 const char *section
,
1495 unsigned section_line
,
1502 ExecContext
*c
= data
;
1503 const Unit
*u
= userdata
;
1513 if (isempty(rvalue
)) {
1514 c
->smack_process_label
= mfree(c
->smack_process_label
);
1515 c
->smack_process_label_ignore
= false;
1519 if (rvalue
[0] == '-') {
1525 r
= unit_full_printf(u
, rvalue
, &k
);
1527 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1528 "Failed to resolve unit specifiers in '%s'%s: %m",
1529 rvalue
, ignore
? ", ignoring" : "");
1530 return ignore
? 0 : -ENOEXEC
;
1533 free_and_replace(c
->smack_process_label
, k
);
1534 c
->smack_process_label_ignore
= ignore
;
1539 int config_parse_timer(
1541 const char *filename
,
1543 const char *section
,
1544 unsigned section_line
,
1551 _cleanup_(calendar_spec_freep
) CalendarSpec
*c
= NULL
;
1552 _cleanup_free_
char *k
= NULL
;
1553 const Unit
*u
= userdata
;
1564 if (isempty(rvalue
)) {
1565 /* Empty assignment resets list */
1566 timer_free_values(t
);
1570 r
= unit_full_printf(u
, rvalue
, &k
);
1572 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
1576 if (ltype
== TIMER_CALENDAR
) {
1577 r
= calendar_spec_from_string(k
, &c
);
1579 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse calendar specification, ignoring: %s", k
);
1583 r
= parse_sec(k
, &usec
);
1585 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse timer value, ignoring: %s", k
);
1590 v
= new(TimerValue
, 1);
1597 .calendar_spec
= TAKE_PTR(c
),
1600 LIST_PREPEND(value
, t
->values
, v
);
1605 int config_parse_trigger_unit(
1607 const char *filename
,
1609 const char *section
,
1610 unsigned section_line
,
1617 _cleanup_free_
char *p
= NULL
;
1627 if (!hashmap_isempty(u
->dependencies
[UNIT_TRIGGERS
])) {
1628 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Multiple units to trigger specified, ignoring: %s", rvalue
);
1632 r
= unit_name_printf(u
, rvalue
, &p
);
1634 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
1638 type
= unit_name_to_type(p
);
1640 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit type not valid, ignoring: %s", rvalue
);
1643 if (unit_has_name(u
, p
)) {
1644 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Units cannot trigger themselves, ignoring: %s", rvalue
);
1648 r
= unit_add_two_dependencies_by_name(u
, UNIT_BEFORE
, UNIT_TRIGGERS
, p
, true, UNIT_DEPENDENCY_FILE
);
1650 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add trigger on %s, ignoring: %m", p
);
1657 int config_parse_path_spec(const char *unit
,
1658 const char *filename
,
1660 const char *section
,
1661 unsigned section_line
,
1671 _cleanup_free_
char *k
= NULL
;
1679 if (isempty(rvalue
)) {
1680 /* Empty assignment clears list */
1685 b
= path_type_from_string(lvalue
);
1687 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse path type, ignoring: %s", lvalue
);
1691 r
= unit_full_printf(UNIT(p
), rvalue
, &k
);
1693 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
1697 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
1701 s
= new0(PathSpec
, 1);
1706 s
->path
= TAKE_PTR(k
);
1710 LIST_PREPEND(spec
, p
->specs
, s
);
1715 int config_parse_socket_service(
1717 const char *filename
,
1719 const char *section
,
1720 unsigned section_line
,
1727 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1728 _cleanup_free_
char *p
= NULL
;
1738 r
= unit_name_printf(UNIT(s
), rvalue
, &p
);
1740 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", rvalue
);
1744 if (!endswith(p
, ".service")) {
1745 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit must be of type service: %s", rvalue
);
1749 r
= manager_load_unit(UNIT(s
)->manager
, p
, NULL
, &error
, &x
);
1751 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to load unit %s: %s", rvalue
, bus_error_message(&error
, r
));
1755 unit_ref_set(&s
->service
, UNIT(s
), x
);
1760 int config_parse_fdname(
1762 const char *filename
,
1764 const char *section
,
1765 unsigned section_line
,
1772 _cleanup_free_
char *p
= NULL
;
1781 if (isempty(rvalue
)) {
1782 s
->fdname
= mfree(s
->fdname
);
1786 r
= unit_full_printf(UNIT(s
), rvalue
, &p
);
1788 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
1792 if (!fdname_is_valid(p
)) {
1793 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", p
);
1797 return free_and_replace(s
->fdname
, p
);
1800 int config_parse_service_sockets(
1802 const char *filename
,
1804 const char *section
,
1805 unsigned section_line
,
1823 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
1825 r
= extract_first_word(&p
, &word
, NULL
, 0);
1831 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Trailing garbage in sockets, ignoring: %s", rvalue
);
1835 r
= unit_name_printf(UNIT(s
), word
, &k
);
1837 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
1841 if (!endswith(k
, ".socket")) {
1842 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit must be of type socket, ignoring: %s", k
);
1846 r
= unit_add_two_dependencies_by_name(UNIT(s
), UNIT_WANTS
, UNIT_AFTER
, k
, true, UNIT_DEPENDENCY_FILE
);
1848 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
1850 r
= unit_add_dependency_by_name(UNIT(s
), UNIT_TRIGGERED_BY
, k
, true, UNIT_DEPENDENCY_FILE
);
1852 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
1858 int config_parse_bus_name(
1860 const char *filename
,
1862 const char *section
,
1863 unsigned section_line
,
1870 _cleanup_free_
char *k
= NULL
;
1871 const Unit
*u
= userdata
;
1879 r
= unit_full_printf(u
, rvalue
, &k
);
1881 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
1885 if (!service_name_is_valid(k
)) {
1886 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid bus name, ignoring: %s", k
);
1890 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
1893 int config_parse_service_timeout(
1895 const char *filename
,
1897 const char *section
,
1898 unsigned section_line
,
1905 Service
*s
= userdata
;
1914 /* This is called for two cases: TimeoutSec= and TimeoutStartSec=. */
1916 /* Traditionally, these options accepted 0 to disable the timeouts. However, a timeout of 0 suggests it happens
1917 * immediately, hence fix this to become USEC_INFINITY instead. This is in-line with how we internally handle
1918 * all other timeouts. */
1919 r
= parse_sec_fix_0(rvalue
, &usec
);
1921 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
1925 s
->start_timeout_defined
= true;
1926 s
->timeout_start_usec
= usec
;
1928 if (streq(lvalue
, "TimeoutSec"))
1929 s
->timeout_stop_usec
= usec
;
1934 int config_parse_timeout_abort(
1936 const char *filename
,
1938 const char *section
,
1939 unsigned section_line
,
1954 /* Note: apart from setting the arg, this returns an extra bit of information in the return value. */
1956 if (isempty(rvalue
)) {
1958 return 0; /* "not set" */
1961 r
= parse_sec(rvalue
, ret
);
1963 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= setting, ignoring: %s", lvalue
, rvalue
);
1965 return 1; /* "set" */
1968 int config_parse_service_timeout_abort(
1970 const char *filename
,
1972 const char *section
,
1973 unsigned section_line
,
1980 Service
*s
= userdata
;
1985 r
= config_parse_timeout_abort(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
,
1986 &s
->timeout_abort_usec
, s
);
1988 s
->timeout_abort_set
= r
;
1992 int config_parse_sec_fix_0(
1994 const char *filename
,
1996 const char *section
,
1997 unsigned section_line
,
2004 usec_t
*usec
= data
;
2012 /* This is pretty much like config_parse_sec(), except that this treats a time of 0 as infinity, for
2013 * compatibility with older versions of systemd where 0 instead of infinity was used as indicator to turn off a
2016 r
= parse_sec_fix_0(rvalue
, usec
);
2018 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
2025 int config_parse_user_group_compat(
2027 const char *filename
,
2029 const char *section
,
2030 unsigned section_line
,
2037 _cleanup_free_
char *k
= NULL
;
2039 const Unit
*u
= userdata
;
2047 if (isempty(rvalue
)) {
2048 *user
= mfree(*user
);
2052 r
= unit_full_printf(u
, rvalue
, &k
);
2054 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", rvalue
);
2058 if (!valid_user_group_name_or_id_compat(k
)) {
2059 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2063 return free_and_replace(*user
, k
);
2066 int config_parse_user_group_strv_compat(
2068 const char *filename
,
2070 const char *section
,
2071 unsigned section_line
,
2078 char ***users
= data
;
2079 const Unit
*u
= userdata
;
2080 const char *p
= rvalue
;
2088 if (isempty(rvalue
)) {
2089 *users
= strv_free(*users
);
2094 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2096 r
= extract_first_word(&p
, &word
, NULL
, 0);
2102 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax: %s", rvalue
);
2106 r
= unit_full_printf(u
, word
, &k
);
2108 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", word
);
2112 if (!valid_user_group_name_or_id_compat(k
)) {
2113 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
2117 r
= strv_push(users
, k
);
2127 int config_parse_working_directory(
2129 const char *filename
,
2131 const char *section
,
2132 unsigned section_line
,
2139 ExecContext
*c
= data
;
2140 const Unit
*u
= userdata
;
2150 if (isempty(rvalue
)) {
2151 c
->working_directory_home
= false;
2152 c
->working_directory
= mfree(c
->working_directory
);
2156 if (rvalue
[0] == '-') {
2162 if (streq(rvalue
, "~")) {
2163 c
->working_directory_home
= true;
2164 c
->working_directory
= mfree(c
->working_directory
);
2166 _cleanup_free_
char *k
= NULL
;
2168 r
= unit_full_printf(u
, rvalue
, &k
);
2170 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2171 "Failed to resolve unit specifiers in working directory path '%s'%s: %m",
2172 rvalue
, missing_ok
? ", ignoring" : "");
2173 return missing_ok
? 0 : -ENOEXEC
;
2176 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
| (missing_ok
? 0 : PATH_CHECK_FATAL
), unit
, filename
, line
, lvalue
);
2178 return missing_ok
? 0 : -ENOEXEC
;
2180 c
->working_directory_home
= false;
2181 free_and_replace(c
->working_directory
, k
);
2184 c
->working_directory_missing_ok
= missing_ok
;
2188 int config_parse_unit_env_file(const char *unit
,
2189 const char *filename
,
2191 const char *section
,
2192 unsigned section_line
,
2200 const Unit
*u
= userdata
;
2201 _cleanup_free_
char *n
= NULL
;
2209 if (isempty(rvalue
)) {
2210 /* Empty assignment frees the list */
2211 *env
= strv_free(*env
);
2215 r
= unit_full_printf(u
, rvalue
, &n
);
2217 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2221 r
= path_simplify_and_warn(n
[0] == '-' ? n
+ 1 : n
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2225 r
= strv_push(env
, n
);
2234 int config_parse_environ(
2236 const char *filename
,
2238 const char *section
,
2239 unsigned section_line
,
2246 const Unit
*u
= userdata
;
2256 if (isempty(rvalue
)) {
2257 /* Empty assignment resets the list */
2258 *env
= strv_free(*env
);
2262 for (p
= rvalue
;; ) {
2263 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2265 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2271 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2272 "Invalid syntax, ignoring: %s", rvalue
);
2277 r
= unit_full_printf(u
, word
, &k
);
2279 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2280 "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2286 if (!env_assignment_is_valid(k
)) {
2287 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2288 "Invalid environment assignment, ignoring: %s", k
);
2292 r
= strv_env_replace(env
, k
);
2300 int config_parse_pass_environ(
2302 const char *filename
,
2304 const char *section
,
2305 unsigned section_line
,
2312 _cleanup_strv_free_
char **n
= NULL
;
2313 size_t nlen
= 0, nbufsize
= 0;
2314 char*** passenv
= data
;
2315 const char *p
= rvalue
;
2316 const Unit
*u
= userdata
;
2324 if (isempty(rvalue
)) {
2325 /* Empty assignment resets the list */
2326 *passenv
= strv_free(*passenv
);
2331 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2333 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
2339 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2340 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2345 r
= unit_full_printf(u
, word
, &k
);
2347 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2348 "Failed to resolve specifiers in %s, ignoring: %m", word
);
2354 if (!env_name_is_valid(k
)) {
2355 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2356 "Invalid environment name for %s, ignoring: %s", lvalue
, k
);
2360 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
2363 n
[nlen
++] = TAKE_PTR(k
);
2368 r
= strv_extend_strv(passenv
, n
, true);
2376 int config_parse_unset_environ(
2378 const char *filename
,
2380 const char *section
,
2381 unsigned section_line
,
2388 _cleanup_strv_free_
char **n
= NULL
;
2389 size_t nlen
= 0, nbufsize
= 0;
2390 char*** unsetenv
= data
;
2391 const char *p
= rvalue
;
2392 const Unit
*u
= userdata
;
2400 if (isempty(rvalue
)) {
2401 /* Empty assignment resets the list */
2402 *unsetenv
= strv_free(*unsetenv
);
2407 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2409 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2415 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2416 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2421 r
= unit_full_printf(u
, word
, &k
);
2423 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2424 "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2430 if (!env_assignment_is_valid(k
) && !env_name_is_valid(k
)) {
2431 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2432 "Invalid environment name or assignment %s, ignoring: %s", lvalue
, k
);
2436 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
2439 n
[nlen
++] = TAKE_PTR(k
);
2444 r
= strv_extend_strv(unsetenv
, n
, true);
2452 int config_parse_log_extra_fields(
2454 const char *filename
,
2456 const char *section
,
2457 unsigned section_line
,
2464 ExecContext
*c
= data
;
2465 const Unit
*u
= userdata
;
2466 const char *p
= rvalue
;
2474 if (isempty(rvalue
)) {
2475 exec_context_free_log_extra_fields(c
);
2480 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2484 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_UNQUOTE
);
2490 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
2494 r
= unit_full_printf(u
, word
, &k
);
2496 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2500 eq
= strchr(k
, '=');
2502 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Log field lacks '=' character, ignoring: %s", k
);
2506 if (!journal_field_valid(k
, eq
-k
, false)) {
2507 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Log field name is invalid, ignoring: %s", k
);
2511 t
= reallocarray(c
->log_extra_fields
, c
->n_log_extra_fields
+1, sizeof(struct iovec
));
2515 c
->log_extra_fields
= t
;
2516 c
->log_extra_fields
[c
->n_log_extra_fields
++] = IOVEC_MAKE_STRING(k
);
2522 int config_parse_unit_condition_path(
2524 const char *filename
,
2526 const char *section
,
2527 unsigned section_line
,
2534 _cleanup_free_
char *p
= NULL
;
2535 Condition
**list
= data
, *c
;
2536 ConditionType t
= ltype
;
2537 bool trigger
, negate
;
2538 const Unit
*u
= userdata
;
2546 if (isempty(rvalue
)) {
2547 /* Empty assignment resets the list */
2548 *list
= condition_free_list(*list
);
2552 trigger
= rvalue
[0] == '|';
2556 negate
= rvalue
[0] == '!';
2560 r
= unit_full_printf(u
, rvalue
, &p
);
2562 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2566 r
= path_simplify_and_warn(p
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2570 c
= condition_new(t
, p
, trigger
, negate
);
2574 LIST_PREPEND(conditions
, *list
, c
);
2578 int config_parse_unit_condition_string(
2580 const char *filename
,
2582 const char *section
,
2583 unsigned section_line
,
2590 _cleanup_free_
char *s
= NULL
;
2591 Condition
**list
= data
, *c
;
2592 ConditionType t
= ltype
;
2593 bool trigger
, negate
;
2594 const Unit
*u
= userdata
;
2602 if (isempty(rvalue
)) {
2603 /* Empty assignment resets the list */
2604 *list
= condition_free_list(*list
);
2608 trigger
= *rvalue
== '|';
2610 rvalue
+= 1 + strspn(rvalue
+ 1, WHITESPACE
);
2612 negate
= *rvalue
== '!';
2614 rvalue
+= 1 + strspn(rvalue
+ 1, WHITESPACE
);
2616 r
= unit_full_printf(u
, rvalue
, &s
);
2618 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2619 "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2623 c
= condition_new(t
, s
, trigger
, negate
);
2627 LIST_PREPEND(conditions
, *list
, c
);
2631 int config_parse_unit_condition_null(
2633 const char *filename
,
2635 const char *section
,
2636 unsigned section_line
,
2643 Condition
**list
= data
, *c
;
2644 bool trigger
, negate
;
2652 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0, "%s= is deprecated, please do not use.", lvalue
);
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 b
= parse_boolean(rvalue
);
2670 log_syntax(unit
, LOG_ERR
, filename
, line
, b
, "Failed to parse boolean value in condition, ignoring: %s", rvalue
);
2677 c
= condition_new(CONDITION_NULL
, NULL
, trigger
, negate
);
2681 LIST_PREPEND(conditions
, *list
, c
);
2685 int config_parse_unit_requires_mounts_for(
2687 const char *filename
,
2689 const char *section
,
2690 unsigned section_line
,
2697 const char *p
= rvalue
;
2707 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
2709 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
2715 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2716 "Invalid syntax, ignoring: %s", rvalue
);
2720 r
= unit_full_printf(u
, word
, &resolved
);
2722 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
2726 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2730 r
= unit_require_mounts_for(u
, resolved
, UNIT_DEPENDENCY_FILE
);
2732 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add required mount '%s', ignoring: %m", resolved
);
2738 int config_parse_documentation(const char *unit
,
2739 const char *filename
,
2741 const char *section
,
2742 unsigned section_line
,
2758 if (isempty(rvalue
)) {
2759 /* Empty assignment resets the list */
2760 u
->documentation
= strv_free(u
->documentation
);
2764 r
= config_parse_unit_strv_printf(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
,
2765 rvalue
, data
, userdata
);
2769 for (a
= b
= u
->documentation
; a
&& *a
; a
++) {
2771 if (documentation_url_is_valid(*a
))
2774 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid URL, ignoring: %s", *a
);
2785 int config_parse_syscall_filter(
2787 const char *filename
,
2789 const char *section
,
2790 unsigned section_line
,
2797 ExecContext
*c
= data
;
2798 const Unit
*u
= userdata
;
2799 bool invert
= false;
2808 if (isempty(rvalue
)) {
2809 /* Empty assignment resets the list */
2810 c
->syscall_filter
= hashmap_free(c
->syscall_filter
);
2811 c
->syscall_whitelist
= false;
2815 if (rvalue
[0] == '~') {
2820 if (!c
->syscall_filter
) {
2821 c
->syscall_filter
= hashmap_new(NULL
);
2822 if (!c
->syscall_filter
)
2826 /* Allow everything but the ones listed */
2827 c
->syscall_whitelist
= false;
2829 /* Allow nothing but the ones listed */
2830 c
->syscall_whitelist
= true;
2832 /* Accept default syscalls if we are on a whitelist */
2833 r
= seccomp_parse_syscall_filter(
2834 "@default", -1, c
->syscall_filter
,
2835 SECCOMP_PARSE_PERMISSIVE
|SECCOMP_PARSE_WHITELIST
,
2845 _cleanup_free_
char *word
= NULL
, *name
= NULL
;
2848 r
= extract_first_word(&p
, &word
, NULL
, 0);
2854 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
2858 r
= parse_syscall_and_errno(word
, &name
, &num
);
2860 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse syscall:errno, ignoring: %s", word
);
2864 r
= seccomp_parse_syscall_filter(
2865 name
, num
, c
->syscall_filter
,
2866 SECCOMP_PARSE_LOG
|SECCOMP_PARSE_PERMISSIVE
|
2867 (invert
? SECCOMP_PARSE_INVERT
: 0)|
2868 (c
->syscall_whitelist
? SECCOMP_PARSE_WHITELIST
: 0),
2869 unit
, filename
, line
);
2875 int config_parse_syscall_archs(
2877 const char *filename
,
2879 const char *section
,
2880 unsigned section_line
,
2887 const char *p
= rvalue
;
2891 if (isempty(rvalue
)) {
2892 *archs
= set_free(*archs
);
2896 r
= set_ensure_allocated(archs
, NULL
);
2901 _cleanup_free_
char *word
= NULL
;
2904 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
2910 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2911 "Invalid syntax, ignoring: %s", rvalue
);
2915 r
= seccomp_arch_from_string(word
, &a
);
2917 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2918 "Failed to parse system call architecture \"%s\", ignoring: %m", word
);
2922 r
= set_put(*archs
, UINT32_TO_PTR(a
+ 1));
2928 int config_parse_syscall_errno(
2930 const char *filename
,
2932 const char *section
,
2933 unsigned section_line
,
2940 ExecContext
*c
= data
;
2947 if (isempty(rvalue
)) {
2948 /* Empty assignment resets to KILL */
2949 c
->syscall_errno
= 0;
2953 e
= parse_errno(rvalue
);
2955 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse error number, ignoring: %s", rvalue
);
2959 c
->syscall_errno
= e
;
2963 int config_parse_address_families(
2965 const char *filename
,
2967 const char *section
,
2968 unsigned section_line
,
2975 ExecContext
*c
= data
;
2976 bool invert
= false;
2984 if (isempty(rvalue
)) {
2985 /* Empty assignment resets the list */
2986 c
->address_families
= set_free(c
->address_families
);
2987 c
->address_families_whitelist
= false;
2991 if (rvalue
[0] == '~') {
2996 if (!c
->address_families
) {
2997 c
->address_families
= set_new(NULL
);
2998 if (!c
->address_families
)
3001 c
->address_families_whitelist
= !invert
;
3004 for (p
= rvalue
;;) {
3005 _cleanup_free_
char *word
= NULL
;
3008 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3014 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3015 "Invalid syntax, ignoring: %s", rvalue
);
3019 af
= af_from_name(word
);
3021 log_syntax(unit
, LOG_ERR
, filename
, line
, af
,
3022 "Failed to parse address family, ignoring: %s", word
);
3026 /* If we previously wanted to forbid an address family and now
3027 * we want to allow it, then just remove it from the list.
3029 if (!invert
== c
->address_families_whitelist
) {
3030 r
= set_put(c
->address_families
, INT_TO_PTR(af
));
3034 set_remove(c
->address_families
, INT_TO_PTR(af
));
3038 int config_parse_restrict_namespaces(
3040 const char *filename
,
3042 const char *section
,
3043 unsigned section_line
,
3050 ExecContext
*c
= data
;
3051 unsigned long flags
;
3052 bool invert
= false;
3055 if (isempty(rvalue
)) {
3056 /* Reset to the default. */
3057 c
->restrict_namespaces
= NAMESPACE_FLAGS_INITIAL
;
3061 /* Boolean parameter ignores the previous settings */
3062 r
= parse_boolean(rvalue
);
3064 c
->restrict_namespaces
= 0;
3066 } else if (r
== 0) {
3067 c
->restrict_namespaces
= NAMESPACE_FLAGS_ALL
;
3071 if (rvalue
[0] == '~') {
3076 /* Not a boolean argument, in this case it's a list of namespace types. */
3077 r
= namespace_flags_from_string(rvalue
, &flags
);
3079 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse namespace type string, ignoring: %s", rvalue
);
3083 if (c
->restrict_namespaces
== NAMESPACE_FLAGS_INITIAL
)
3084 /* Initial assignment. Just set the value. */
3085 c
->restrict_namespaces
= invert
? (~flags
) & NAMESPACE_FLAGS_ALL
: flags
;
3087 /* Merge the value with the previous one. */
3088 SET_FLAG(c
->restrict_namespaces
, flags
, !invert
);
3094 int config_parse_unit_slice(
3096 const char *filename
,
3098 const char *section
,
3099 unsigned section_line
,
3106 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
3107 _cleanup_free_
char *k
= NULL
;
3108 Unit
*u
= userdata
, *slice
;
3116 r
= unit_name_printf(u
, rvalue
, &k
);
3118 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
3122 r
= manager_load_unit(u
->manager
, k
, NULL
, &error
, &slice
);
3124 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to load slice unit %s, ignoring: %s", k
, bus_error_message(&error
, r
));
3128 r
= unit_set_slice(u
, slice
);
3130 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to assign slice %s to unit %s, ignoring: %m", slice
->id
, u
->id
);
3137 int config_parse_cpu_quota(
3139 const char *filename
,
3141 const char *section
,
3142 unsigned section_line
,
3149 CGroupContext
*c
= data
;
3156 if (isempty(rvalue
)) {
3157 c
->cpu_quota_per_sec_usec
= USEC_INFINITY
;
3161 r
= parse_permille_unbounded(rvalue
);
3163 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid CPU quota '%s', ignoring.", rvalue
);
3167 c
->cpu_quota_per_sec_usec
= ((usec_t
) r
* USEC_PER_SEC
) / 1000U;
3171 int config_parse_allowed_cpus(
3173 const char *filename
,
3175 const char *section
,
3176 unsigned section_line
,
3183 CGroupContext
*c
= data
;
3185 (void) parse_cpu_set_extend(rvalue
, &c
->cpuset_cpus
, true, unit
, filename
, line
, lvalue
);
3190 int config_parse_allowed_mems(
3192 const char *filename
,
3194 const char *section
,
3195 unsigned section_line
,
3202 CGroupContext
*c
= data
;
3204 (void) parse_cpu_set_extend(rvalue
, &c
->cpuset_mems
, true, unit
, filename
, line
, lvalue
);
3209 int config_parse_memory_limit(
3211 const char *filename
,
3213 const char *section
,
3214 unsigned section_line
,
3221 CGroupContext
*c
= data
;
3222 uint64_t bytes
= CGROUP_LIMIT_MAX
;
3225 if (!isempty(rvalue
) && !streq(rvalue
, "infinity")) {
3227 r
= parse_permille(rvalue
);
3229 r
= parse_size(rvalue
, 1024, &bytes
);
3231 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid memory limit '%s', ignoring: %m", rvalue
);
3235 bytes
= physical_memory_scale(r
, 1000U);
3237 if (bytes
>= UINT64_MAX
||
3238 (bytes
<= 0 && !STR_IN_SET(lvalue
, "MemorySwapMax", "MemoryLow", "MemoryMin", "DefaultMemoryLow", "DefaultMemoryMin"))) {
3239 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Memory limit '%s' out of range, ignoring.", rvalue
);
3244 if (streq(lvalue
, "DefaultMemoryLow")) {
3245 c
->default_memory_low_set
= true;
3246 if (isempty(rvalue
))
3247 c
->default_memory_low
= CGROUP_LIMIT_MIN
;
3249 c
->default_memory_low
= bytes
;
3250 } else if (streq(lvalue
, "DefaultMemoryMin")) {
3251 c
->default_memory_min_set
= true;
3252 if (isempty(rvalue
))
3253 c
->default_memory_min
= CGROUP_LIMIT_MIN
;
3255 c
->default_memory_min
= bytes
;
3256 } else if (streq(lvalue
, "MemoryMin")) {
3257 c
->memory_min
= bytes
;
3258 c
->memory_min_set
= true;
3259 } else if (streq(lvalue
, "MemoryLow")) {
3260 c
->memory_low
= bytes
;
3261 c
->memory_low_set
= true;
3262 } else if (streq(lvalue
, "MemoryHigh"))
3263 c
->memory_high
= bytes
;
3264 else if (streq(lvalue
, "MemoryMax"))
3265 c
->memory_max
= bytes
;
3266 else if (streq(lvalue
, "MemorySwapMax"))
3267 c
->memory_swap_max
= bytes
;
3268 else if (streq(lvalue
, "MemoryLimit"))
3269 c
->memory_limit
= bytes
;
3276 int config_parse_tasks_max(
3278 const char *filename
,
3280 const char *section
,
3281 unsigned section_line
,
3288 const Unit
*u
= userdata
;
3289 TasksMax
*tasks_max
= data
;
3293 if (isempty(rvalue
)) {
3294 *tasks_max
= u
? u
->manager
->default_tasks_max
: TASKS_MAX_UNSET
;
3298 if (streq(rvalue
, "infinity")) {
3299 *tasks_max
= TASKS_MAX_UNSET
;
3303 r
= parse_permille(rvalue
);
3305 *tasks_max
= (TasksMax
) { r
, 1000U }; /* r‰ */
3307 r
= safe_atou64(rvalue
, &v
);
3309 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid maximum tasks value '%s', ignoring: %m", rvalue
);
3313 if (v
<= 0 || v
>= UINT64_MAX
) {
3314 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Maximum tasks value '%s' out of range, ignoring.", rvalue
);
3318 *tasks_max
= (TasksMax
) { v
};
3324 int config_parse_delegate(
3326 const char *filename
,
3328 const char *section
,
3329 unsigned section_line
,
3336 CGroupContext
*c
= data
;
3340 t
= unit_name_to_type(unit
);
3341 assert(t
!= _UNIT_TYPE_INVALID
);
3343 if (!unit_vtable
[t
]->can_delegate
) {
3344 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Delegate= setting not supported for this unit type, ignoring.");
3348 /* We either accept a boolean value, which may be used to turn on delegation for all controllers, or turn it
3349 * off for all. Or it takes a list of controller names, in which case we add the specified controllers to the
3350 * mask to delegate. */
3352 if (isempty(rvalue
)) {
3353 /* An empty string resets controllers and set Delegate=yes. */
3355 c
->delegate_controllers
= 0;
3359 r
= parse_boolean(rvalue
);
3361 const char *p
= rvalue
;
3362 CGroupMask mask
= 0;
3365 _cleanup_free_
char *word
= NULL
;
3366 CGroupController cc
;
3368 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3374 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3378 cc
= cgroup_controller_from_string(word
);
3380 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid controller name '%s', ignoring", word
);
3384 mask
|= CGROUP_CONTROLLER_TO_MASK(cc
);
3388 c
->delegate_controllers
|= mask
;
3392 c
->delegate_controllers
= _CGROUP_MASK_ALL
;
3394 c
->delegate
= false;
3395 c
->delegate_controllers
= 0;
3401 int config_parse_device_allow(
3403 const char *filename
,
3405 const char *section
,
3406 unsigned section_line
,
3413 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3414 CGroupContext
*c
= data
;
3415 const char *p
= rvalue
;
3418 if (isempty(rvalue
)) {
3419 while (c
->device_allow
)
3420 cgroup_context_free_device_allow(c
, c
->device_allow
);
3425 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3429 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3430 "Invalid syntax, ignoring: %s", rvalue
);
3434 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3435 "Failed to extract device path and rights from '%s', ignoring.", rvalue
);
3439 r
= unit_full_printf(userdata
, path
, &resolved
);
3441 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3442 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3446 if (!STARTSWITH_SET(resolved
, "block-", "char-")) {
3448 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3452 if (!valid_device_node_path(resolved
)) {
3453 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device node path '%s', ignoring.", resolved
);
3458 if (!isempty(p
) && !in_charset(p
, "rwm")) {
3459 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device rights '%s', ignoring.", p
);
3463 return cgroup_add_device_allow(c
, resolved
, p
);
3466 int config_parse_io_device_weight(
3468 const char *filename
,
3470 const char *section
,
3471 unsigned section_line
,
3478 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3479 CGroupIODeviceWeight
*w
;
3480 CGroupContext
*c
= data
;
3481 const char *p
= rvalue
;
3489 if (isempty(rvalue
)) {
3490 while (c
->io_device_weights
)
3491 cgroup_context_free_io_device_weight(c
, c
->io_device_weights
);
3496 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3500 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3501 "Invalid syntax, ignoring: %s", rvalue
);
3504 if (r
== 0 || isempty(p
)) {
3505 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3506 "Failed to extract device path and weight from '%s', ignoring.", rvalue
);
3510 r
= unit_full_printf(userdata
, path
, &resolved
);
3512 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3513 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3517 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3521 r
= cg_weight_parse(p
, &u
);
3523 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "IO weight '%s' invalid, ignoring: %m", p
);
3527 assert(u
!= CGROUP_WEIGHT_INVALID
);
3529 w
= new0(CGroupIODeviceWeight
, 1);
3533 w
->path
= TAKE_PTR(resolved
);
3536 LIST_PREPEND(device_weights
, c
->io_device_weights
, w
);
3540 int config_parse_io_device_latency(
3542 const char *filename
,
3544 const char *section
,
3545 unsigned section_line
,
3552 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3553 CGroupIODeviceLatency
*l
;
3554 CGroupContext
*c
= data
;
3555 const char *p
= rvalue
;
3563 if (isempty(rvalue
)) {
3564 while (c
->io_device_latencies
)
3565 cgroup_context_free_io_device_latency(c
, c
->io_device_latencies
);
3570 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3574 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3575 "Invalid syntax, ignoring: %s", rvalue
);
3578 if (r
== 0 || isempty(p
)) {
3579 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3580 "Failed to extract device path and latency from '%s', ignoring.", rvalue
);
3584 r
= unit_full_printf(userdata
, path
, &resolved
);
3586 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3587 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3591 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3595 if (parse_sec(p
, &usec
) < 0) {
3596 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse timer value, ignoring: %s", p
);
3600 l
= new0(CGroupIODeviceLatency
, 1);
3604 l
->path
= TAKE_PTR(resolved
);
3605 l
->target_usec
= usec
;
3607 LIST_PREPEND(device_latencies
, c
->io_device_latencies
, l
);
3611 int config_parse_io_limit(
3613 const char *filename
,
3615 const char *section
,
3616 unsigned section_line
,
3623 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3624 CGroupIODeviceLimit
*l
= NULL
, *t
;
3625 CGroupContext
*c
= data
;
3626 CGroupIOLimitType type
;
3627 const char *p
= rvalue
;
3635 type
= cgroup_io_limit_type_from_string(lvalue
);
3638 if (isempty(rvalue
)) {
3639 LIST_FOREACH(device_limits
, l
, c
->io_device_limits
)
3640 l
->limits
[type
] = cgroup_io_limit_defaults
[type
];
3644 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3648 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3649 "Invalid syntax, ignoring: %s", rvalue
);
3652 if (r
== 0 || isempty(p
)) {
3653 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3654 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
3658 r
= unit_full_printf(userdata
, path
, &resolved
);
3660 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3661 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3665 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3669 if (streq("infinity", p
))
3670 num
= CGROUP_LIMIT_MAX
;
3672 r
= parse_size(p
, 1000, &num
);
3673 if (r
< 0 || num
<= 0) {
3674 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid IO limit '%s', ignoring.", p
);
3679 LIST_FOREACH(device_limits
, t
, c
->io_device_limits
) {
3680 if (path_equal(resolved
, t
->path
)) {
3687 CGroupIOLimitType ttype
;
3689 l
= new0(CGroupIODeviceLimit
, 1);
3693 l
->path
= TAKE_PTR(resolved
);
3694 for (ttype
= 0; ttype
< _CGROUP_IO_LIMIT_TYPE_MAX
; ttype
++)
3695 l
->limits
[ttype
] = cgroup_io_limit_defaults
[ttype
];
3697 LIST_PREPEND(device_limits
, c
->io_device_limits
, l
);
3700 l
->limits
[type
] = num
;
3705 int config_parse_blockio_device_weight(
3707 const char *filename
,
3709 const char *section
,
3710 unsigned section_line
,
3717 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3718 CGroupBlockIODeviceWeight
*w
;
3719 CGroupContext
*c
= data
;
3720 const char *p
= rvalue
;
3728 if (isempty(rvalue
)) {
3729 while (c
->blockio_device_weights
)
3730 cgroup_context_free_blockio_device_weight(c
, c
->blockio_device_weights
);
3735 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3739 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3740 "Invalid syntax, ignoring: %s", rvalue
);
3743 if (r
== 0 || isempty(p
)) {
3744 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3745 "Failed to extract device node and weight from '%s', ignoring.", rvalue
);
3749 r
= unit_full_printf(userdata
, path
, &resolved
);
3751 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3752 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3756 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3760 r
= cg_blkio_weight_parse(p
, &u
);
3762 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid block IO weight '%s', ignoring: %m", p
);
3766 assert(u
!= CGROUP_BLKIO_WEIGHT_INVALID
);
3768 w
= new0(CGroupBlockIODeviceWeight
, 1);
3772 w
->path
= TAKE_PTR(resolved
);
3775 LIST_PREPEND(device_weights
, c
->blockio_device_weights
, w
);
3779 int config_parse_blockio_bandwidth(
3781 const char *filename
,
3783 const char *section
,
3784 unsigned section_line
,
3791 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3792 CGroupBlockIODeviceBandwidth
*b
= NULL
, *t
;
3793 CGroupContext
*c
= data
;
3794 const char *p
= rvalue
;
3803 read
= streq("BlockIOReadBandwidth", lvalue
);
3805 if (isempty(rvalue
)) {
3806 LIST_FOREACH(device_bandwidths
, b
, c
->blockio_device_bandwidths
) {
3807 b
->rbps
= CGROUP_LIMIT_MAX
;
3808 b
->wbps
= CGROUP_LIMIT_MAX
;
3813 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_UNQUOTE
);
3817 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3818 "Invalid syntax, ignoring: %s", rvalue
);
3821 if (r
== 0 || isempty(p
)) {
3822 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3823 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
3827 r
= unit_full_printf(userdata
, path
, &resolved
);
3829 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3830 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3834 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3838 r
= parse_size(p
, 1000, &bytes
);
3839 if (r
< 0 || bytes
<= 0) {
3840 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid Block IO Bandwidth '%s', ignoring.", p
);
3844 LIST_FOREACH(device_bandwidths
, t
, c
->blockio_device_bandwidths
) {
3845 if (path_equal(resolved
, t
->path
)) {
3852 b
= new0(CGroupBlockIODeviceBandwidth
, 1);
3856 b
->path
= TAKE_PTR(resolved
);
3857 b
->rbps
= CGROUP_LIMIT_MAX
;
3858 b
->wbps
= CGROUP_LIMIT_MAX
;
3860 LIST_PREPEND(device_bandwidths
, c
->blockio_device_bandwidths
, b
);
3871 int config_parse_job_mode_isolate(
3873 const char *filename
,
3875 const char *section
,
3876 unsigned section_line
,
3890 r
= parse_boolean(rvalue
);
3892 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse boolean, ignoring: %s", rvalue
);
3896 log_notice("%s is deprecated. Please use OnFailureJobMode= instead", lvalue
);
3898 *m
= r
? JOB_ISOLATE
: JOB_REPLACE
;
3902 int config_parse_exec_directories(
3904 const char *filename
,
3906 const char *section
,
3907 unsigned section_line
,
3915 const Unit
*u
= userdata
;
3924 if (isempty(rvalue
)) {
3925 /* Empty assignment resets the list */
3926 *rt
= strv_free(*rt
);
3930 for (p
= rvalue
;;) {
3931 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
3933 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
3937 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3938 "Invalid syntax, ignoring: %s", rvalue
);
3944 r
= unit_full_printf(u
, word
, &k
);
3946 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
3947 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
3951 r
= path_simplify_and_warn(k
, PATH_CHECK_RELATIVE
, unit
, filename
, line
, lvalue
);
3955 if (path_startswith(k
, "private")) {
3956 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
3957 "%s= path can't be 'private', ignoring assignment: %s", lvalue
, word
);
3961 r
= strv_push(rt
, k
);
3968 int config_parse_set_status(
3970 const char *filename
,
3972 const char *section
,
3973 unsigned section_line
,
3981 const char *word
, *state
;
3983 ExitStatusSet
*status_set
= data
;
3990 /* Empty assignment resets the list */
3991 if (isempty(rvalue
)) {
3992 exit_status_set_free(status_set
);
3996 FOREACH_WORD(word
, l
, rvalue
, state
) {
3997 _cleanup_free_
char *temp
;
4000 temp
= strndup(word
, l
);
4004 /* We need to call exit_status_from_string() first, because we want
4005 * to parse numbers as exit statuses, not signals. */
4007 r
= exit_status_from_string(temp
);
4009 assert(r
>= 0 && r
< 256);
4010 bitmap
= &status_set
->status
;
4012 r
= signal_from_string(temp
);
4015 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
4016 "Failed to parse value, ignoring: %s", word
);
4019 bitmap
= &status_set
->signal
;
4022 r
= bitmap_set(bitmap
, r
);
4024 return log_error_errno(r
, "Failed to set signal or status %s: %m", word
);
4026 if (!isempty(state
))
4027 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Trailing garbage, ignoring.");
4032 int config_parse_namespace_path_strv(
4034 const char *filename
,
4036 const char *section
,
4037 unsigned section_line
,
4044 const Unit
*u
= userdata
;
4046 const char *p
= rvalue
;
4054 if (isempty(rvalue
)) {
4055 /* Empty assignment resets the list */
4056 *sv
= strv_free(*sv
);
4061 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
, *joined
= NULL
;
4063 bool ignore_enoent
= false, shall_prefix
= false;
4065 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
4071 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
4076 if (startswith(w
, "-")) {
4077 ignore_enoent
= true;
4080 if (startswith(w
, "+")) {
4081 shall_prefix
= true;
4085 r
= unit_full_printf(u
, w
, &resolved
);
4087 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", w
);
4091 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4095 joined
= strjoin(ignore_enoent
? "-" : "",
4096 shall_prefix
? "+" : "",
4099 r
= strv_push(sv
, joined
);
4109 int config_parse_temporary_filesystems(
4111 const char *filename
,
4113 const char *section
,
4114 unsigned section_line
,
4121 const Unit
*u
= userdata
;
4122 ExecContext
*c
= data
;
4123 const char *p
= rvalue
;
4131 if (isempty(rvalue
)) {
4132 /* Empty assignment resets the list */
4133 temporary_filesystem_free_many(c
->temporary_filesystems
, c
->n_temporary_filesystems
);
4134 c
->temporary_filesystems
= NULL
;
4135 c
->n_temporary_filesystems
= 0;
4140 _cleanup_free_
char *word
= NULL
, *path
= NULL
, *resolved
= NULL
;
4143 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
4149 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
4154 r
= extract_first_word(&w
, &path
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
4158 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", word
);
4162 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid syntax, ignoring: %s", word
);
4166 r
= unit_full_printf(u
, path
, &resolved
);
4168 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", path
);
4172 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4176 r
= temporary_filesystem_add(&c
->temporary_filesystems
, &c
->n_temporary_filesystems
, resolved
, w
);
4182 int config_parse_bind_paths(
4184 const char *filename
,
4186 const char *section
,
4187 unsigned section_line
,
4194 ExecContext
*c
= data
;
4195 const Unit
*u
= userdata
;
4204 if (isempty(rvalue
)) {
4205 /* Empty assignment resets the list */
4206 bind_mount_free_many(c
->bind_mounts
, c
->n_bind_mounts
);
4207 c
->bind_mounts
= NULL
;
4208 c
->n_bind_mounts
= 0;
4214 _cleanup_free_
char *source
= NULL
, *destination
= NULL
;
4215 _cleanup_free_
char *sresolved
= NULL
, *dresolved
= NULL
;
4216 char *s
= NULL
, *d
= NULL
;
4217 bool rbind
= true, ignore_enoent
= false;
4219 r
= extract_first_word(&p
, &source
, ":" WHITESPACE
, EXTRACT_UNQUOTE
|EXTRACT_DONT_COALESCE_SEPARATORS
);
4225 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
4229 r
= unit_full_printf(u
, source
, &sresolved
);
4231 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4232 "Failed to resolved unit specifiers in \"%s\", ignoring: %m", source
);
4238 ignore_enoent
= true;
4242 r
= path_simplify_and_warn(s
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4246 /* Optionally, the destination is specified. */
4247 if (p
&& p
[-1] == ':') {
4248 r
= extract_first_word(&p
, &destination
, ":" WHITESPACE
, EXTRACT_UNQUOTE
|EXTRACT_DONT_COALESCE_SEPARATORS
);
4252 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
4256 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Missing argument after ':', ignoring: %s", s
);
4260 r
= unit_full_printf(u
, destination
, &dresolved
);
4262 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4263 "Failed to resolved specifiers in \"%s\", ignoring: %m", destination
);
4267 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4273 /* Optionally, there's also a short option string specified */
4274 if (p
&& p
[-1] == ':') {
4275 _cleanup_free_
char *options
= NULL
;
4277 r
= extract_first_word(&p
, &options
, NULL
, EXTRACT_UNQUOTE
);
4281 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s: %s", lvalue
, rvalue
);
4285 if (isempty(options
) || streq(options
, "rbind"))
4287 else if (streq(options
, "norbind"))
4290 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid option string, ignoring setting: %s", options
);
4297 r
= bind_mount_add(&c
->bind_mounts
, &c
->n_bind_mounts
,
4301 .read_only
= !!strstr(lvalue
, "ReadOnly"),
4303 .ignore_enoent
= ignore_enoent
,
4312 int config_parse_job_timeout_sec(
4314 const char *filename
,
4316 const char *section
,
4317 unsigned section_line
,
4333 r
= parse_sec_fix_0(rvalue
, &usec
);
4335 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse JobTimeoutSec= parameter, ignoring: %s", rvalue
);
4339 /* If the user explicitly changed JobTimeoutSec= also change JobRunningTimeoutSec=, for compatibility with old
4340 * versions. If JobRunningTimeoutSec= was explicitly set, avoid this however as whatever the user picked should
4343 if (!u
->job_running_timeout_set
)
4344 u
->job_running_timeout
= usec
;
4346 u
->job_timeout
= usec
;
4351 int config_parse_job_running_timeout_sec(
4353 const char *filename
,
4355 const char *section
,
4356 unsigned section_line
,
4372 r
= parse_sec_fix_0(rvalue
, &usec
);
4374 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse JobRunningTimeoutSec= parameter, ignoring: %s", rvalue
);
4378 u
->job_running_timeout
= usec
;
4379 u
->job_running_timeout_set
= true;
4384 int config_parse_emergency_action(
4386 const char *filename
,
4388 const char *section
,
4389 unsigned section_line
,
4397 EmergencyAction
*x
= data
;
4406 m
= ((Unit
*) userdata
)->manager
;
4410 r
= parse_emergency_action(rvalue
, MANAGER_IS_SYSTEM(m
), x
);
4412 if (r
== -EOPNOTSUPP
&& MANAGER_IS_USER(m
)) {
4413 /* Compat mode: remove for systemd 241. */
4415 log_syntax(unit
, LOG_INFO
, filename
, line
, r
,
4416 "%s= in user mode specified as \"%s\", using \"exit-force\" instead.",
4418 *x
= EMERGENCY_ACTION_EXIT_FORCE
;
4422 if (r
== -EOPNOTSUPP
)
4423 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4424 "%s= specified as %s mode action, ignoring: %s",
4425 lvalue
, MANAGER_IS_SYSTEM(m
) ? "user" : "system", rvalue
);
4427 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4428 "Failed to parse %s=, ignoring: %s", lvalue
, rvalue
);
4435 int config_parse_pid_file(
4437 const char *filename
,
4439 const char *section
,
4440 unsigned section_line
,
4447 _cleanup_free_
char *k
= NULL
, *n
= NULL
;
4448 const Unit
*u
= userdata
;
4457 if (isempty(rvalue
)) {
4458 /* An empty assignment removes already set value. */
4463 r
= unit_full_printf(u
, rvalue
, &k
);
4465 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
4469 /* If this is a relative path make it absolute by prefixing the /run */
4470 n
= path_make_absolute(k
, u
->manager
->prefix
[EXEC_DIRECTORY_RUNTIME
]);
4474 /* Check that the result is a sensible path */
4475 r
= path_simplify_and_warn(n
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4479 r
= patch_var_run(unit
, filename
, line
, lvalue
, &n
);
4483 free_and_replace(*s
, n
);
4487 int config_parse_exit_status(
4489 const char *filename
,
4491 const char *section
,
4492 unsigned section_line
,
4499 int *exit_status
= data
, r
;
4505 assert(exit_status
);
4507 if (isempty(rvalue
)) {
4512 r
= safe_atou8(rvalue
, &u
);
4514 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse exit status '%s', ignoring: %m", rvalue
);
4522 int config_parse_disable_controllers(
4524 const char *filename
,
4526 const char *section
,
4527 unsigned section_line
,
4535 CGroupContext
*c
= data
;
4536 CGroupMask disabled_mask
;
4538 /* 1. If empty, make all controllers eligible for use again.
4539 * 2. If non-empty, merge all listed controllers, space separated. */
4541 if (isempty(rvalue
)) {
4542 c
->disable_controllers
= 0;
4546 r
= cg_mask_from_string(rvalue
, &disabled_mask
);
4547 if (r
< 0 || disabled_mask
<= 0) {
4548 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid cgroup string: %s, ignoring", rvalue
);
4552 c
->disable_controllers
|= disabled_mask
;
4557 int config_parse_ip_filter_bpf_progs(
4559 const char *filename
,
4561 const char *section
,
4562 unsigned section_line
,
4569 _cleanup_free_
char *resolved
= NULL
;
4570 const Unit
*u
= userdata
;
4571 char ***paths
= data
;
4579 if (isempty(rvalue
)) {
4580 *paths
= strv_free(*paths
);
4584 r
= unit_full_printf(u
, rvalue
, &resolved
);
4586 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
4590 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4594 if (strv_contains(*paths
, resolved
))
4597 r
= strv_extend(paths
, resolved
);
4601 r
= bpf_firewall_supported();
4604 if (r
!= BPF_FIREWALL_SUPPORTED_WITH_MULTI
) {
4605 static bool warned
= false;
4607 log_full(warned
? LOG_DEBUG
: LOG_WARNING
,
4608 "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"
4609 "Starting this unit will fail! (This warning is only shown for the first loaded unit using IP firewalling.)", filename
, line
, lvalue
, rvalue
);
4617 static int merge_by_names(Unit
**u
, Set
*names
, const char *id
) {
4624 /* Let's try to add in all names that are aliases of this unit */
4625 while ((k
= set_steal_first(names
))) {
4626 _cleanup_free_ _unused_
char *free_k
= k
;
4628 /* First try to merge in the other name into our unit */
4629 r
= unit_merge_by_name(*u
, k
);
4633 /* Hmm, we couldn't merge the other unit into ours? Then let's try it the other way
4636 other
= manager_get_unit((*u
)->manager
, k
);
4638 return r
; /* return previous failure */
4640 r
= unit_merge(other
, *u
);
4645 return merge_by_names(u
, names
, NULL
);
4648 if (streq_ptr(id
, k
))
4649 unit_choose_id(*u
, id
);
4655 int unit_load_fragment(Unit
*u
) {
4656 const char *fragment
;
4657 _cleanup_set_free_free_ Set
*names
= NULL
;
4662 assert(u
->load_state
== UNIT_STUB
);
4666 u
->load_state
= UNIT_LOADED
;
4670 /* Possibly rebuild the fragment map to catch new units */
4671 r
= unit_file_build_name_map(&u
->manager
->lookup_paths
,
4672 &u
->manager
->unit_cache_mtime
,
4673 &u
->manager
->unit_id_map
,
4674 &u
->manager
->unit_name_map
,
4675 &u
->manager
->unit_path_cache
);
4677 log_error_errno(r
, "Failed to rebuild name map: %m");
4679 r
= unit_file_find_fragment(u
->manager
->unit_id_map
,
4680 u
->manager
->unit_name_map
,
4684 if (r
< 0 && r
!= -ENOENT
)
4688 /* Open the file, check if this is a mask, otherwise read. */
4689 _cleanup_fclose_
FILE *f
= NULL
;
4691 /* Try to open the file name. A symlink is OK, for example for linked files or masks. We
4692 * expect that all symlinks within the lookup paths have been already resolved, but we don't
4693 * verify this here. */
4694 f
= fopen(fragment
, "re");
4696 return log_unit_notice_errno(u
, errno
, "Failed to open %s: %m", fragment
);
4698 if (fstat(fileno(f
), &st
) < 0)
4701 r
= free_and_strdup(&u
->fragment_path
, fragment
);
4705 if (null_or_empty(&st
)) {
4706 /* Unit file is masked */
4708 u
->load_state
= u
->perpetual
? UNIT_LOADED
: UNIT_MASKED
; /* don't allow perpetual units to ever be masked */
4709 u
->fragment_mtime
= 0;
4711 u
->load_state
= UNIT_LOADED
;
4712 u
->fragment_mtime
= timespec_load(&st
.st_mtim
);
4714 /* Now, parse the file contents */
4715 r
= config_parse(u
->id
, fragment
, f
,
4716 UNIT_VTABLE(u
)->sections
,
4717 config_item_perf_lookup
, load_fragment_gperf_lookup
,
4718 CONFIG_PARSE_ALLOW_INCLUDE
, u
);
4720 log_unit_notice_errno(u
, r
, "Unit configuration has fatal error, unit will not be started.");
4726 if (u
->source_path
) {
4727 if (stat(u
->source_path
, &st
) >= 0)
4728 u
->source_mtime
= timespec_load(&st
.st_mtim
);
4730 u
->source_mtime
= 0;
4733 /* We do the merge dance here because for some unit types, the unit might have aliases which are not
4734 * declared in the file system. In particular, this is true (and frequent) for device and swap units.
4737 const char *id
= u
->id
;
4738 _cleanup_free_
char *free_id
= NULL
;
4741 id
= basename(fragment
);
4742 if (unit_name_is_valid(id
, UNIT_NAME_TEMPLATE
)) {
4743 assert(u
->instance
); /* If we're not trying to use a template for non-instanced unit,
4744 * this must be set. */
4746 r
= unit_name_replace_instance(id
, u
->instance
, &free_id
);
4748 return log_debug_errno(r
, "Failed to build id (%s + %s): %m", id
, u
->instance
);
4754 r
= merge_by_names(&merged
, names
, id
);
4759 u
->load_state
= UNIT_MERGED
;
4764 void unit_dump_config_items(FILE *f
) {
4765 static const struct {
4766 const ConfigParserCallback callback
;
4769 { config_parse_warn_compat
, "NOTSUPPORTED" },
4770 { config_parse_int
, "INTEGER" },
4771 { config_parse_unsigned
, "UNSIGNED" },
4772 { config_parse_iec_size
, "SIZE" },
4773 { config_parse_iec_uint64
, "SIZE" },
4774 { config_parse_si_size
, "SIZE" },
4775 { config_parse_bool
, "BOOLEAN" },
4776 { config_parse_string
, "STRING" },
4777 { config_parse_path
, "PATH" },
4778 { config_parse_unit_path_printf
, "PATH" },
4779 { config_parse_strv
, "STRING [...]" },
4780 { config_parse_exec_nice
, "NICE" },
4781 { config_parse_exec_oom_score_adjust
, "OOMSCOREADJUST" },
4782 { config_parse_exec_io_class
, "IOCLASS" },
4783 { config_parse_exec_io_priority
, "IOPRIORITY" },
4784 { config_parse_exec_cpu_sched_policy
, "CPUSCHEDPOLICY" },
4785 { config_parse_exec_cpu_sched_prio
, "CPUSCHEDPRIO" },
4786 { config_parse_exec_cpu_affinity
, "CPUAFFINITY" },
4787 { config_parse_mode
, "MODE" },
4788 { config_parse_unit_env_file
, "FILE" },
4789 { config_parse_exec_output
, "OUTPUT" },
4790 { config_parse_exec_input
, "INPUT" },
4791 { config_parse_log_facility
, "FACILITY" },
4792 { config_parse_log_level
, "LEVEL" },
4793 { config_parse_exec_secure_bits
, "SECUREBITS" },
4794 { config_parse_capability_set
, "BOUNDINGSET" },
4795 { config_parse_rlimit
, "LIMIT" },
4796 { config_parse_unit_deps
, "UNIT [...]" },
4797 { config_parse_exec
, "PATH [ARGUMENT [...]]" },
4798 { config_parse_service_type
, "SERVICETYPE" },
4799 { config_parse_service_restart
, "SERVICERESTART" },
4800 { config_parse_kill_mode
, "KILLMODE" },
4801 { config_parse_signal
, "SIGNAL" },
4802 { config_parse_socket_listen
, "SOCKET [...]" },
4803 { config_parse_socket_bind
, "SOCKETBIND" },
4804 { config_parse_socket_bindtodevice
, "NETWORKINTERFACE" },
4805 { config_parse_sec
, "SECONDS" },
4806 { config_parse_nsec
, "NANOSECONDS" },
4807 { config_parse_namespace_path_strv
, "PATH [...]" },
4808 { config_parse_bind_paths
, "PATH[:PATH[:OPTIONS]] [...]" },
4809 { config_parse_unit_requires_mounts_for
, "PATH [...]" },
4810 { config_parse_exec_mount_flags
, "MOUNTFLAG [...]" },
4811 { config_parse_unit_string_printf
, "STRING" },
4812 { config_parse_trigger_unit
, "UNIT" },
4813 { config_parse_timer
, "TIMER" },
4814 { config_parse_path_spec
, "PATH" },
4815 { config_parse_notify_access
, "ACCESS" },
4816 { config_parse_ip_tos
, "TOS" },
4817 { config_parse_unit_condition_path
, "CONDITION" },
4818 { config_parse_unit_condition_string
, "CONDITION" },
4819 { config_parse_unit_condition_null
, "CONDITION" },
4820 { config_parse_unit_slice
, "SLICE" },
4821 { config_parse_documentation
, "URL" },
4822 { config_parse_service_timeout
, "SECONDS" },
4823 { config_parse_emergency_action
, "ACTION" },
4824 { config_parse_set_status
, "STATUS" },
4825 { config_parse_service_sockets
, "SOCKETS" },
4826 { config_parse_environ
, "ENVIRON" },
4828 { config_parse_syscall_filter
, "SYSCALLS" },
4829 { config_parse_syscall_archs
, "ARCHS" },
4830 { config_parse_syscall_errno
, "ERRNO" },
4831 { config_parse_address_families
, "FAMILIES" },
4832 { config_parse_restrict_namespaces
, "NAMESPACES" },
4834 { config_parse_cpu_shares
, "SHARES" },
4835 { config_parse_cg_weight
, "WEIGHT" },
4836 { config_parse_memory_limit
, "LIMIT" },
4837 { config_parse_device_allow
, "DEVICE" },
4838 { config_parse_device_policy
, "POLICY" },
4839 { config_parse_io_limit
, "LIMIT" },
4840 { config_parse_io_device_weight
, "DEVICEWEIGHT" },
4841 { config_parse_io_device_latency
, "DEVICELATENCY" },
4842 { config_parse_blockio_bandwidth
, "BANDWIDTH" },
4843 { config_parse_blockio_weight
, "WEIGHT" },
4844 { config_parse_blockio_device_weight
, "DEVICEWEIGHT" },
4845 { config_parse_long
, "LONG" },
4846 { config_parse_socket_service
, "SERVICE" },
4848 { config_parse_exec_selinux_context
, "LABEL" },
4850 { config_parse_job_mode
, "MODE" },
4851 { config_parse_job_mode_isolate
, "BOOLEAN" },
4852 { config_parse_personality
, "PERSONALITY" },
4855 const char *prev
= NULL
;
4860 NULSTR_FOREACH(i
, load_fragment_gperf_nulstr
) {
4861 const char *rvalue
= "OTHER", *lvalue
;
4862 const ConfigPerfItem
*p
;
4867 assert_se(p
= load_fragment_gperf_lookup(i
, strlen(i
)));
4869 /* Hide legacy settings */
4870 if (p
->parse
== config_parse_warn_compat
&&
4871 p
->ltype
== DISABLED_LEGACY
)
4874 for (j
= 0; j
< ELEMENTSOF(table
); j
++)
4875 if (p
->parse
== table
[j
].callback
) {
4876 rvalue
= table
[j
].rvalue
;
4880 dot
= strchr(i
, '.');
4881 lvalue
= dot
? dot
+ 1 : i
;
4885 if (!prev
|| !strneq(prev
, i
, prefix_len
+1)) {
4889 fprintf(f
, "[%.*s]\n", (int) prefix_len
, i
);
4892 fprintf(f
, "%s=%s\n", lvalue
, rvalue
);
4897 int config_parse_cpu_affinity2(
4899 const char *filename
,
4901 const char *section
,
4902 unsigned section_line
,
4909 CPUSet
*affinity
= data
;
4913 (void) parse_cpu_set_extend(rvalue
, affinity
, true, unit
, filename
, line
, lvalue
);
4918 int config_parse_show_status(
4920 const char *filename
,
4922 const char *section
,
4923 unsigned section_line
,
4931 ShowStatus
*b
= data
;
4938 k
= parse_show_status(rvalue
, b
);
4940 log_syntax(unit
, LOG_ERR
, filename
, line
, k
, "Failed to parse show status setting, ignoring: %s", rvalue
);
4947 int config_parse_output_restricted(
4949 const char *filename
,
4951 const char *section
,
4952 unsigned section_line
,
4959 ExecOutput t
, *eo
= data
;
4966 t
= exec_output_from_string(rvalue
);
4968 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse output type, ignoring: %s", rvalue
);
4972 if (IN_SET(t
, EXEC_OUTPUT_SOCKET
, EXEC_OUTPUT_NAMED_FD
, EXEC_OUTPUT_FILE
, EXEC_OUTPUT_FILE_APPEND
)) {
4973 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Standard output types socket, fd:, file:, append: are not supported as defaults, ignoring: %s", rvalue
);
4981 int config_parse_crash_chvt(
4983 const char *filename
,
4985 const char *section
,
4986 unsigned section_line
,
5000 r
= parse_crash_chvt(rvalue
, data
);
5002 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse CrashChangeVT= setting, ignoring: %s", rvalue
);
5009 int config_parse_swap_priority(
5011 const char *filename
,
5013 const char *section
,
5014 unsigned section_line
,
5030 if (isempty(rvalue
)) {
5031 s
->parameters_fragment
.priority
= -1;
5032 s
->parameters_fragment
.priority_set
= false;
5036 r
= safe_atoi(rvalue
, &priority
);
5038 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid swap pririty '%s', ignoring.", rvalue
);
5042 if (priority
< -1) {
5043 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
);
5047 if (priority
> 32767) {
5048 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Swap priority out of range, ignoring: %s", rvalue
);
5052 s
->parameters_fragment
.priority
= priority
;
5053 s
->parameters_fragment
.priority_set
= true;