1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 Copyright © 2012 Holger Hans Peter Freyther
15 #include <sys/resource.h>
19 #include "alloc-util.h"
20 #include "all-units.h"
21 #include "bus-error.h"
22 #include "bus-internal.h"
25 #include "capability-util.h"
27 #include "conf-parser.h"
28 #include "cpu-set-util.h"
30 #include "errno-list.h"
34 #include "hexdecoct.h"
37 #include "journal-util.h"
38 #include "load-fragment.h"
41 #include "mount-util.h"
42 #include "parse-util.h"
43 #include "path-util.h"
44 #include "process-util.h"
46 #include "seccomp-util.h"
48 #include "securebits.h"
49 #include "securebits-util.h"
50 #include "signal-util.h"
51 #include "socket-protocol-list.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"
60 static int supported_socket_protocol_from_string(const char *s
) {
66 r
= socket_protocol_from_name(s
);
69 if (!IN_SET(r
, IPPROTO_UDPLITE
, IPPROTO_SCTP
))
70 return -EPROTONOSUPPORT
;
75 DEFINE_CONFIG_PARSE(config_parse_socket_protocol
, supported_socket_protocol_from_string
, "Failed to parse socket protocol");
76 DEFINE_CONFIG_PARSE(config_parse_exec_secure_bits
, secure_bits_from_string
, "Failed to parse secure bits");
77 DEFINE_CONFIG_PARSE_ENUM(config_parse_collect_mode
, collect_mode
, CollectMode
, "Failed to parse garbage collection mode");
78 DEFINE_CONFIG_PARSE_ENUM(config_parse_device_policy
, cgroup_device_policy
, CGroupDevicePolicy
, "Failed to parse device policy");
79 DEFINE_CONFIG_PARSE_ENUM(config_parse_emergency_action
, emergency_action
, EmergencyAction
, "Failed to parse failure action specifier");
80 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_keyring_mode
, exec_keyring_mode
, ExecKeyringMode
, "Failed to parse keyring mode");
81 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_utmp_mode
, exec_utmp_mode
, ExecUtmpMode
, "Failed to parse utmp mode");
82 DEFINE_CONFIG_PARSE_ENUM(config_parse_job_mode
, job_mode
, JobMode
, "Failed to parse job mode");
83 DEFINE_CONFIG_PARSE_ENUM(config_parse_kill_mode
, kill_mode
, KillMode
, "Failed to parse kill mode");
84 DEFINE_CONFIG_PARSE_ENUM(config_parse_notify_access
, notify_access
, NotifyAccess
, "Failed to parse notify access specifier");
85 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_home
, protect_home
, ProtectHome
, "Failed to parse protect home value");
86 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_system
, protect_system
, ProtectSystem
, "Failed to parse protect system value");
87 DEFINE_CONFIG_PARSE_ENUM(config_parse_runtime_preserve_mode
, exec_preserve_mode
, ExecPreserveMode
, "Failed to parse runtime directory preserve mode");
88 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_type
, service_type
, ServiceType
, "Failed to parse service type");
89 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart
, service_restart
, ServiceRestart
, "Failed to parse service restart specifier");
90 DEFINE_CONFIG_PARSE_ENUM(config_parse_socket_bind
, socket_address_bind_ipv6_only_or_bool
, SocketAddressBindIPv6Only
, "Failed to parse bind IPv6 only value");
91 DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_ip_tos
, ip_tos
, int, -1, "Failed to parse IP TOS value");
92 DEFINE_CONFIG_PARSE_PTR(config_parse_blockio_weight
, cg_blkio_weight_parse
, uint64_t, "Invalid block IO weight");
93 DEFINE_CONFIG_PARSE_PTR(config_parse_cg_weight
, cg_weight_parse
, uint64_t, "Invalid weight");
94 DEFINE_CONFIG_PARSE_PTR(config_parse_cpu_shares
, cg_cpu_shares_parse
, uint64_t, "Invalid CPU shares");
95 DEFINE_CONFIG_PARSE_PTR(config_parse_exec_mount_flags
, mount_propagation_flags_from_string
, unsigned long, "Failed to parse mount flag");
97 int config_parse_unit_deps(
102 unsigned section_line
,
109 UnitDependency d
= ltype
;
119 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
122 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_RETAIN_ESCAPE
);
128 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
132 r
= unit_name_printf(u
, word
, &k
);
134 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
138 r
= unit_add_dependency_by_name(u
, d
, k
, NULL
, true, UNIT_DEPENDENCY_FILE
);
140 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
146 int config_parse_obsolete_unit_deps(
148 const char *filename
,
151 unsigned section_line
,
158 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
159 "Unit dependency type %s= is obsolete, replacing by %s=, please update your unit file", lvalue
, unit_dependency_to_string(ltype
));
161 return config_parse_unit_deps(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
);
164 int config_parse_unit_string_printf(
166 const char *filename
,
169 unsigned section_line
,
176 _cleanup_free_
char *k
= NULL
;
185 r
= unit_full_printf(u
, rvalue
, &k
);
187 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
191 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
194 int config_parse_unit_strv_printf(
196 const char *filename
,
199 unsigned section_line
,
207 _cleanup_free_
char *k
= NULL
;
215 r
= unit_full_printf(u
, rvalue
, &k
);
217 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
221 return config_parse_strv(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
224 int config_parse_unit_path_printf(
226 const char *filename
,
229 unsigned section_line
,
236 _cleanup_free_
char *k
= NULL
;
246 /* Let's not bother with anything that is too long */
247 if (strlen(rvalue
) >= PATH_MAX
) {
248 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
249 "%s value too long%s.",
250 lvalue
, fatal
? "" : ", ignoring");
251 return fatal
? -ENAMETOOLONG
: 0;
254 r
= unit_full_printf(u
, rvalue
, &k
);
256 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
257 "Failed to resolve unit specifiers in '%s'%s: %m",
258 rvalue
, fatal
? "" : ", ignoring");
259 return fatal
? -ENOEXEC
: 0;
262 return config_parse_path(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
265 int config_parse_unit_path_strv_printf(
267 const char *filename
,
270 unsigned section_line
,
287 if (isempty(rvalue
)) {
293 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
295 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
301 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
302 "Invalid syntax, ignoring: %s", rvalue
);
306 r
= unit_full_printf(u
, word
, &k
);
308 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
309 "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
313 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
324 int config_parse_socket_listen(const char *unit
,
325 const char *filename
,
328 unsigned section_line
,
335 _cleanup_free_ SocketPort
*p
= NULL
;
347 if (isempty(rvalue
)) {
348 /* An empty assignment removes all ports */
349 socket_free_ports(s
);
353 p
= new0(SocketPort
, 1);
357 if (ltype
!= SOCKET_SOCKET
) {
358 _cleanup_free_
char *k
= NULL
;
360 r
= unit_full_printf(UNIT(s
), rvalue
, &k
);
362 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
366 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
370 free_and_replace(p
->path
, k
);
373 } else if (streq(lvalue
, "ListenNetlink")) {
374 _cleanup_free_
char *k
= NULL
;
376 r
= unit_full_printf(UNIT(s
), rvalue
, &k
);
378 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
382 r
= socket_address_parse_netlink(&p
->address
, k
);
384 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse address value in '%s', ignoring: %m", k
);
388 p
->type
= SOCKET_SOCKET
;
391 _cleanup_free_
char *k
= NULL
;
393 r
= unit_full_printf(UNIT(s
), rvalue
, &k
);
395 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
399 r
= socket_address_parse_and_warn(&p
->address
, k
);
401 if (r
!= -EAFNOSUPPORT
)
402 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse address value in '%s', ignoring: %m", k
);
406 if (streq(lvalue
, "ListenStream"))
407 p
->address
.type
= SOCK_STREAM
;
408 else if (streq(lvalue
, "ListenDatagram"))
409 p
->address
.type
= SOCK_DGRAM
;
411 assert(streq(lvalue
, "ListenSequentialPacket"));
412 p
->address
.type
= SOCK_SEQPACKET
;
415 if (socket_address_family(&p
->address
) != AF_LOCAL
&& p
->address
.type
== SOCK_SEQPACKET
) {
416 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Address family not supported, ignoring: %s", rvalue
);
420 p
->type
= SOCKET_SOCKET
;
424 p
->auxiliary_fds
= NULL
;
425 p
->n_auxiliary_fds
= 0;
428 LIST_FIND_TAIL(port
, s
->ports
, tail
);
429 LIST_INSERT_AFTER(port
, s
->ports
, tail
, p
);
436 int config_parse_exec_nice(
438 const char *filename
,
441 unsigned section_line
,
448 ExecContext
*c
= data
;
456 if (isempty(rvalue
)) {
461 r
= parse_nice(rvalue
, &priority
);
464 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Nice priority out of range, ignoring: %s", rvalue
);
466 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse nice priority '%s', ignoring: %m", rvalue
);
476 int config_parse_exec_oom_score_adjust(
478 const char *filename
,
481 unsigned section_line
,
488 ExecContext
*c
= data
;
496 if (isempty(rvalue
)) {
497 c
->oom_score_adjust_set
= false;
501 r
= parse_oom_score_adjust(rvalue
, &oa
);
504 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "OOM score adjust value out of range, ignoring: %s", rvalue
);
506 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse the OOM score adjust value '%s', ignoring: %m", rvalue
);
510 c
->oom_score_adjust
= oa
;
511 c
->oom_score_adjust_set
= true;
516 int config_parse_exec(
518 const char *filename
,
521 unsigned section_line
,
528 ExecCommand
**e
= data
;
540 rvalue
+= strspn(rvalue
, WHITESPACE
);
542 if (isempty(rvalue
)) {
543 /* An empty assignment resets the list */
544 *e
= exec_command_free_list(*e
);
550 _cleanup_free_
char *path
= NULL
, *firstword
= NULL
;
551 ExecCommandFlags flags
= 0;
552 bool ignore
= false, separate_argv0
= false;
553 _cleanup_free_ ExecCommand
*nce
= NULL
;
554 _cleanup_strv_free_
char **n
= NULL
;
555 size_t nlen
= 0, nbufsize
= 0;
560 r
= extract_first_word_and_warn(&p
, &firstword
, NULL
, EXTRACT_QUOTES
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
566 /* We accept an absolute path as first argument. If it's prefixed with - and the path doesn't
567 * exist, we ignore it instead of erroring out; if it's prefixed with @, we allow overriding of
568 * argv[0]; if it's prefixed with +, it will be run with full privileges and no sandboxing; if
569 * it's prefixed with '!' we apply sandboxing, but do not change user/group credentials; if
570 * it's prefixed with '!!', then we apply user/group credentials if the kernel supports ambient
571 * capabilities -- if it doesn't we don't apply the credentials themselves, but do apply most
572 * other sandboxing, with some special exceptions for changing UID.
574 * The idea is that '!!' may be used to write services that can take benefit of systemd's
575 * UID/GID dropping if the kernel supports ambient creds, but provide an automatic fallback to
576 * privilege dropping within the daemon if the kernel does not offer that. */
578 if (*f
== '-' && !(flags
& EXEC_COMMAND_IGNORE_FAILURE
)) {
579 flags
|= EXEC_COMMAND_IGNORE_FAILURE
;
581 } else if (*f
== '@' && !separate_argv0
)
582 separate_argv0
= true;
583 else if (*f
== '+' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
584 flags
|= EXEC_COMMAND_FULLY_PRIVILEGED
;
585 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
586 flags
|= EXEC_COMMAND_NO_SETUID
;
587 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_AMBIENT_MAGIC
))) {
588 flags
&= ~EXEC_COMMAND_NO_SETUID
;
589 flags
|= EXEC_COMMAND_AMBIENT_MAGIC
;
595 r
= unit_full_printf(u
, f
, &path
);
597 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
598 "Failed to resolve unit specifiers in '%s'%s: %m",
599 f
, ignore
? ", ignoring" : "");
600 return ignore
? 0 : -ENOEXEC
;
604 /* First word is either "-" or "@" with no command. */
605 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
606 "Empty path in command line%s: '%s'",
607 ignore
? ", ignoring" : "", rvalue
);
608 return ignore
? 0 : -ENOEXEC
;
610 if (!string_is_safe(path
)) {
611 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
612 "Executable name contains special characters%s: %s",
613 ignore
? ", ignoring" : "", path
);
614 return ignore
? 0 : -ENOEXEC
;
616 if (endswith(path
, "/")) {
617 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
618 "Executable path specifies a directory%s: %s",
619 ignore
? ", ignoring" : "", path
);
620 return ignore
? 0 : -ENOEXEC
;
623 if (!path_is_absolute(path
)) {
627 if (!filename_is_valid(path
)) {
628 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
629 "Neither a valid executable name nor an absolute path%s: %s",
630 ignore
? ", ignoring" : "", path
);
631 return ignore
? 0 : -ENOEXEC
;
634 /* Resolve a single-component name to a full path */
635 NULSTR_FOREACH(prefix
, DEFAULT_PATH_NULSTR
) {
636 _cleanup_free_
char *fullpath
= NULL
;
638 fullpath
= strjoin(prefix
, "/", path
);
642 if (access(fullpath
, F_OK
) >= 0) {
643 free_and_replace(path
, fullpath
);
650 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
651 "Executable \"%s\" not found in path \"%s\"%s",
652 path
, DEFAULT_PATH
, ignore
? ", ignoring" : "");
653 return ignore
? 0 : -ENOEXEC
;
657 if (!separate_argv0
) {
660 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
670 path_simplify(path
, false);
672 while (!isempty(p
)) {
673 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
675 /* Check explicitly for an unquoted semicolon as
676 * command separator token. */
677 if (p
[0] == ';' && (!p
[1] || strchr(WHITESPACE
, p
[1]))) {
679 p
+= strspn(p
, WHITESPACE
);
684 /* Check for \; explicitly, to not confuse it with \\; or "\;" or "\\;" etc.
685 * extract_first_word() would return the same for all of those. */
686 if (p
[0] == '\\' && p
[1] == ';' && (!p
[2] || strchr(WHITESPACE
, p
[2]))) {
690 p
+= strspn(p
, WHITESPACE
);
692 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
703 r
= extract_first_word_and_warn(&p
, &word
, NULL
, EXTRACT_QUOTES
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
707 return ignore
? 0 : -ENOEXEC
;
709 r
= unit_full_printf(u
, word
, &resolved
);
711 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
712 "Failed to resolve unit specifiers in %s%s: %m",
713 word
, ignore
? ", ignoring" : "");
714 return ignore
? 0 : -ENOEXEC
;
717 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
720 n
[nlen
++] = TAKE_PTR(resolved
);
725 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
726 "Empty executable name or zeroeth argument%s: %s",
727 ignore
? ", ignoring" : "", rvalue
);
728 return ignore
? 0 : -ENOEXEC
;
731 nce
= new0(ExecCommand
, 1);
735 nce
->argv
= TAKE_PTR(n
);
736 nce
->path
= TAKE_PTR(path
);
739 exec_command_append_list(e
, nce
);
741 /* Do not _cleanup_free_ these. */
750 int config_parse_socket_bindtodevice(
752 const char *filename
,
755 unsigned section_line
,
769 if (isempty(rvalue
) || streq(rvalue
, "*")) {
770 s
->bind_to_device
= mfree(s
->bind_to_device
);
774 if (!ifname_valid(rvalue
)) {
775 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid interface name, ignoring: %s", rvalue
);
779 if (free_and_strdup(&s
->bind_to_device
, rvalue
) < 0)
785 int config_parse_exec_input(
787 const char *filename
,
790 unsigned section_line
,
797 ExecContext
*c
= data
;
808 n
= startswith(rvalue
, "fd:");
810 _cleanup_free_
char *resolved
= NULL
;
812 r
= unit_full_printf(u
, n
, &resolved
);
814 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s': %m", n
);
816 if (isempty(resolved
))
817 resolved
= mfree(resolved
);
818 else if (!fdname_is_valid(resolved
)) {
819 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name: %s", resolved
);
823 free_and_replace(c
->stdio_fdname
[STDIN_FILENO
], resolved
);
825 ei
= EXEC_INPUT_NAMED_FD
;
827 } else if ((n
= startswith(rvalue
, "file:"))) {
828 _cleanup_free_
char *resolved
= NULL
;
830 r
= unit_full_printf(u
, n
, &resolved
);
832 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s': %m", n
);
834 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
838 free_and_replace(c
->stdio_file
[STDIN_FILENO
], resolved
);
840 ei
= EXEC_INPUT_FILE
;
843 ei
= exec_input_from_string(rvalue
);
845 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse input specifier, ignoring: %s", rvalue
);
854 int config_parse_exec_input_text(
856 const char *filename
,
859 unsigned section_line
,
866 _cleanup_free_
char *unescaped
= NULL
, *resolved
= NULL
;
867 ExecContext
*c
= data
;
878 if (isempty(rvalue
)) {
879 /* Reset if the empty string is assigned */
880 c
->stdin_data
= mfree(c
->stdin_data
);
881 c
->stdin_data_size
= 0;
885 r
= cunescape(rvalue
, 0, &unescaped
);
887 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to decode C escaped text '%s': %m", rvalue
);
889 r
= unit_full_printf(u
, unescaped
, &resolved
);
891 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s': %m", unescaped
);
893 sz
= strlen(resolved
);
894 if (c
->stdin_data_size
+ sz
+ 1 < c
->stdin_data_size
|| /* check for overflow */
895 c
->stdin_data_size
+ sz
+ 1 > EXEC_STDIN_DATA_MAX
) {
896 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
);
900 p
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
+ 1);
904 *((char*) mempcpy((char*) p
+ c
->stdin_data_size
, resolved
, sz
)) = '\n';
907 c
->stdin_data_size
+= sz
+ 1;
912 int config_parse_exec_input_data(
914 const char *filename
,
917 unsigned section_line
,
924 _cleanup_free_
void *p
= NULL
;
925 ExecContext
*c
= data
;
935 if (isempty(rvalue
)) {
936 /* Reset if the empty string is assigned */
937 c
->stdin_data
= mfree(c
->stdin_data
);
938 c
->stdin_data_size
= 0;
942 r
= unbase64mem(rvalue
, (size_t) -1, &p
, &sz
);
944 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to decode base64 data, ignoring: %s", rvalue
);
948 if (c
->stdin_data_size
+ sz
< c
->stdin_data_size
|| /* check for overflow */
949 c
->stdin_data_size
+ sz
> EXEC_STDIN_DATA_MAX
) {
950 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
);
954 q
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
);
958 memcpy((uint8_t*) q
+ c
->stdin_data_size
, p
, sz
);
961 c
->stdin_data_size
+= sz
;
966 int config_parse_exec_output(
968 const char *filename
,
971 unsigned section_line
,
978 _cleanup_free_
char *resolved
= NULL
;
980 ExecContext
*c
= data
;
991 n
= startswith(rvalue
, "fd:");
993 r
= unit_full_printf(u
, n
, &resolved
);
995 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", n
);
997 if (isempty(resolved
))
998 resolved
= mfree(resolved
);
999 else if (!fdname_is_valid(resolved
)) {
1000 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name: %s", resolved
);
1004 eo
= EXEC_OUTPUT_NAMED_FD
;
1006 } else if ((n
= startswith(rvalue
, "file:"))) {
1008 r
= unit_full_printf(u
, n
, &resolved
);
1010 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", n
);
1012 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1016 eo
= EXEC_OUTPUT_FILE
;
1018 } else if ((n
= startswith(rvalue
, "append:"))) {
1020 r
= unit_full_printf(u
, n
, &resolved
);
1022 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", n
);
1024 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
| PATH_CHECK_FATAL
, unit
, filename
, line
, lvalue
);
1028 eo
= EXEC_OUTPUT_FILE_APPEND
;
1030 eo
= exec_output_from_string(rvalue
);
1032 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse output specifier, ignoring: %s", rvalue
);
1037 if (streq(lvalue
, "StandardOutput")) {
1038 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1039 free_and_replace(c
->stdio_fdname
[STDOUT_FILENO
], resolved
);
1041 free_and_replace(c
->stdio_file
[STDOUT_FILENO
], resolved
);
1046 assert(streq(lvalue
, "StandardError"));
1048 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1049 free_and_replace(c
->stdio_fdname
[STDERR_FILENO
], resolved
);
1051 free_and_replace(c
->stdio_file
[STDERR_FILENO
], resolved
);
1059 int config_parse_exec_io_class(const char *unit
,
1060 const char *filename
,
1062 const char *section
,
1063 unsigned section_line
,
1070 ExecContext
*c
= data
;
1078 if (isempty(rvalue
)) {
1079 c
->ioprio_set
= false;
1080 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE
, 0);
1084 x
= ioprio_class_from_string(rvalue
);
1086 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse IO scheduling class, ignoring: %s", rvalue
);
1090 c
->ioprio
= IOPRIO_PRIO_VALUE(x
, IOPRIO_PRIO_DATA(c
->ioprio
));
1091 c
->ioprio_set
= true;
1096 int config_parse_exec_io_priority(const char *unit
,
1097 const char *filename
,
1099 const char *section
,
1100 unsigned section_line
,
1107 ExecContext
*c
= data
;
1115 if (isempty(rvalue
)) {
1116 c
->ioprio_set
= false;
1117 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE
, 0);
1121 r
= ioprio_parse_priority(rvalue
, &i
);
1123 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse IO priority, ignoring: %s", rvalue
);
1127 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_PRIO_CLASS(c
->ioprio
), i
);
1128 c
->ioprio_set
= true;
1133 int config_parse_exec_cpu_sched_policy(const char *unit
,
1134 const char *filename
,
1136 const char *section
,
1137 unsigned section_line
,
1144 ExecContext
*c
= data
;
1152 if (isempty(rvalue
)) {
1153 c
->cpu_sched_set
= false;
1154 c
->cpu_sched_policy
= SCHED_OTHER
;
1155 c
->cpu_sched_priority
= 0;
1159 x
= sched_policy_from_string(rvalue
);
1161 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse CPU scheduling policy, ignoring: %s", rvalue
);
1165 c
->cpu_sched_policy
= x
;
1166 /* Moving to or from real-time policy? We need to adjust the priority */
1167 c
->cpu_sched_priority
= CLAMP(c
->cpu_sched_priority
, sched_get_priority_min(x
), sched_get_priority_max(x
));
1168 c
->cpu_sched_set
= true;
1173 int config_parse_exec_cpu_sched_prio(const char *unit
,
1174 const char *filename
,
1176 const char *section
,
1177 unsigned section_line
,
1184 ExecContext
*c
= data
;
1192 r
= safe_atoi(rvalue
, &i
);
1194 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse CPU scheduling priority, ignoring: %s", rvalue
);
1198 /* On Linux RR/FIFO range from 1 to 99 and OTHER/BATCH may only be 0 */
1199 min
= sched_get_priority_min(c
->cpu_sched_policy
);
1200 max
= sched_get_priority_max(c
->cpu_sched_policy
);
1202 if (i
< min
|| i
> max
) {
1203 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "CPU scheduling priority is out of range, ignoring: %s", rvalue
);
1207 c
->cpu_sched_priority
= i
;
1208 c
->cpu_sched_set
= true;
1213 int config_parse_exec_cpu_affinity(const char *unit
,
1214 const char *filename
,
1216 const char *section
,
1217 unsigned section_line
,
1224 ExecContext
*c
= data
;
1225 _cleanup_cpu_free_ cpu_set_t
*cpuset
= NULL
;
1233 ncpus
= parse_cpu_set_and_warn(rvalue
, &cpuset
, unit
, filename
, line
, lvalue
);
1238 /* An empty assignment resets the CPU list */
1239 c
->cpuset
= cpu_set_mfree(c
->cpuset
);
1240 c
->cpuset_ncpus
= 0;
1245 c
->cpuset
= TAKE_PTR(cpuset
);
1246 c
->cpuset_ncpus
= (unsigned) ncpus
;
1250 if (c
->cpuset_ncpus
< (unsigned) ncpus
) {
1251 CPU_OR_S(CPU_ALLOC_SIZE(c
->cpuset_ncpus
), cpuset
, c
->cpuset
, cpuset
);
1252 CPU_FREE(c
->cpuset
);
1253 c
->cpuset
= TAKE_PTR(cpuset
);
1254 c
->cpuset_ncpus
= (unsigned) ncpus
;
1258 CPU_OR_S(CPU_ALLOC_SIZE((unsigned) ncpus
), c
->cpuset
, c
->cpuset
, cpuset
);
1263 int config_parse_capability_set(
1265 const char *filename
,
1267 const char *section
,
1268 unsigned section_line
,
1275 uint64_t *capability_set
= data
;
1276 uint64_t sum
= 0, initial
= 0;
1277 bool invert
= false;
1285 if (rvalue
[0] == '~') {
1290 if (streq(lvalue
, "CapabilityBoundingSet"))
1291 initial
= CAP_ALL
; /* initialized to all bits on */
1292 /* else "AmbientCapabilities" initialized to all bits off */
1294 r
= capability_set_from_string(rvalue
, &sum
);
1296 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= specifier '%s', ignoring: %m", lvalue
, rvalue
);
1300 if (sum
== 0 || *capability_set
== initial
)
1301 /* "", "~" or uninitialized data -> replace */
1302 *capability_set
= invert
? ~sum
: sum
;
1304 /* previous data -> merge */
1306 *capability_set
&= ~sum
;
1308 *capability_set
|= sum
;
1314 int config_parse_exec_selinux_context(
1316 const char *filename
,
1318 const char *section
,
1319 unsigned section_line
,
1326 ExecContext
*c
= data
;
1337 if (isempty(rvalue
)) {
1338 c
->selinux_context
= mfree(c
->selinux_context
);
1339 c
->selinux_context_ignore
= false;
1343 if (rvalue
[0] == '-') {
1349 r
= unit_full_printf(u
, rvalue
, &k
);
1351 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1352 "Failed to resolve unit specifiers in '%s'%s: %m",
1353 rvalue
, ignore
? ", ignoring" : "");
1354 return ignore
? 0 : -ENOEXEC
;
1357 free_and_replace(c
->selinux_context
, k
);
1358 c
->selinux_context_ignore
= ignore
;
1363 int config_parse_exec_apparmor_profile(
1365 const char *filename
,
1367 const char *section
,
1368 unsigned section_line
,
1375 ExecContext
*c
= data
;
1386 if (isempty(rvalue
)) {
1387 c
->apparmor_profile
= mfree(c
->apparmor_profile
);
1388 c
->apparmor_profile_ignore
= false;
1392 if (rvalue
[0] == '-') {
1398 r
= unit_full_printf(u
, rvalue
, &k
);
1400 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1401 "Failed to resolve unit specifiers in '%s'%s: %m",
1402 rvalue
, ignore
? ", ignoring" : "");
1403 return ignore
? 0 : -ENOEXEC
;
1406 free_and_replace(c
->apparmor_profile
, k
);
1407 c
->apparmor_profile_ignore
= ignore
;
1412 int config_parse_exec_smack_process_label(
1414 const char *filename
,
1416 const char *section
,
1417 unsigned section_line
,
1424 ExecContext
*c
= data
;
1435 if (isempty(rvalue
)) {
1436 c
->smack_process_label
= mfree(c
->smack_process_label
);
1437 c
->smack_process_label_ignore
= false;
1441 if (rvalue
[0] == '-') {
1447 r
= unit_full_printf(u
, rvalue
, &k
);
1449 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1450 "Failed to resolve unit specifiers in '%s'%s: %m",
1451 rvalue
, ignore
? ", ignoring" : "");
1452 return ignore
? 0 : -ENOEXEC
;
1455 free_and_replace(c
->smack_process_label
, k
);
1456 c
->smack_process_label_ignore
= ignore
;
1461 int config_parse_timer(const char *unit
,
1462 const char *filename
,
1464 const char *section
,
1465 unsigned section_line
,
1476 _cleanup_(calendar_spec_freep
) CalendarSpec
*c
= NULL
;
1478 _cleanup_free_
char *k
= NULL
;
1486 if (isempty(rvalue
)) {
1487 /* Empty assignment resets list */
1488 timer_free_values(t
);
1492 b
= timer_base_from_string(lvalue
);
1494 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse timer base, ignoring: %s", lvalue
);
1498 r
= unit_full_printf(u
, rvalue
, &k
);
1500 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
1504 if (b
== TIMER_CALENDAR
) {
1505 if (calendar_spec_from_string(k
, &c
) < 0) {
1506 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse calendar specification, ignoring: %s", k
);
1510 if (parse_sec(k
, &usec
) < 0) {
1511 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse timer value, ignoring: %s", k
);
1515 v
= new0(TimerValue
, 1);
1521 v
->calendar_spec
= TAKE_PTR(c
);
1523 LIST_PREPEND(value
, t
->values
, v
);
1528 int config_parse_trigger_unit(
1530 const char *filename
,
1532 const char *section
,
1533 unsigned section_line
,
1540 _cleanup_free_
char *p
= NULL
;
1550 if (!hashmap_isempty(u
->dependencies
[UNIT_TRIGGERS
])) {
1551 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Multiple units to trigger specified, ignoring: %s", rvalue
);
1555 r
= unit_name_printf(u
, rvalue
, &p
);
1557 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
1561 type
= unit_name_to_type(p
);
1563 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit type not valid, ignoring: %s", rvalue
);
1566 if (unit_has_name(u
, p
)) {
1567 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Units cannot trigger themselves, ignoring: %s", rvalue
);
1571 r
= unit_add_two_dependencies_by_name(u
, UNIT_BEFORE
, UNIT_TRIGGERS
, p
, NULL
, true, UNIT_DEPENDENCY_FILE
);
1573 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add trigger on %s, ignoring: %m", p
);
1580 int config_parse_path_spec(const char *unit
,
1581 const char *filename
,
1583 const char *section
,
1584 unsigned section_line
,
1594 _cleanup_free_
char *k
= NULL
;
1602 if (isempty(rvalue
)) {
1603 /* Empty assignment clears list */
1608 b
= path_type_from_string(lvalue
);
1610 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse path type, ignoring: %s", lvalue
);
1614 r
= unit_full_printf(UNIT(p
), rvalue
, &k
);
1616 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
1620 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
1624 s
= new0(PathSpec
, 1);
1629 s
->path
= TAKE_PTR(k
);
1633 LIST_PREPEND(spec
, p
->specs
, s
);
1638 int config_parse_socket_service(
1640 const char *filename
,
1642 const char *section
,
1643 unsigned section_line
,
1650 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1651 _cleanup_free_
char *p
= NULL
;
1661 r
= unit_name_printf(UNIT(s
), rvalue
, &p
);
1663 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", rvalue
);
1667 if (!endswith(p
, ".service")) {
1668 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit must be of type service: %s", rvalue
);
1672 r
= manager_load_unit(UNIT(s
)->manager
, p
, NULL
, &error
, &x
);
1674 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to load unit %s: %s", rvalue
, bus_error_message(&error
, r
));
1678 unit_ref_set(&s
->service
, UNIT(s
), x
);
1683 int config_parse_fdname(
1685 const char *filename
,
1687 const char *section
,
1688 unsigned section_line
,
1695 _cleanup_free_
char *p
= NULL
;
1704 if (isempty(rvalue
)) {
1705 s
->fdname
= mfree(s
->fdname
);
1709 r
= unit_full_printf(UNIT(s
), rvalue
, &p
);
1711 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
1715 if (!fdname_is_valid(p
)) {
1716 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", p
);
1720 return free_and_replace(s
->fdname
, p
);
1723 int config_parse_service_sockets(
1725 const char *filename
,
1727 const char *section
,
1728 unsigned section_line
,
1746 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
1748 r
= extract_first_word(&p
, &word
, NULL
, 0);
1754 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Trailing garbage in sockets, ignoring: %s", rvalue
);
1758 r
= unit_name_printf(UNIT(s
), word
, &k
);
1760 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
1764 if (!endswith(k
, ".socket")) {
1765 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit must be of type socket, ignoring: %s", k
);
1769 r
= unit_add_two_dependencies_by_name(UNIT(s
), UNIT_WANTS
, UNIT_AFTER
, k
, NULL
, true, UNIT_DEPENDENCY_FILE
);
1771 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
1773 r
= unit_add_dependency_by_name(UNIT(s
), UNIT_TRIGGERED_BY
, k
, NULL
, true, UNIT_DEPENDENCY_FILE
);
1775 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
1781 int config_parse_bus_name(
1783 const char *filename
,
1785 const char *section
,
1786 unsigned section_line
,
1793 _cleanup_free_
char *k
= NULL
;
1802 r
= unit_full_printf(u
, rvalue
, &k
);
1804 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
1808 if (!service_name_is_valid(k
)) {
1809 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid bus name, ignoring: %s", k
);
1813 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
1816 int config_parse_service_timeout(
1818 const char *filename
,
1820 const char *section
,
1821 unsigned section_line
,
1828 Service
*s
= userdata
;
1837 /* This is called for two cases: TimeoutSec= and TimeoutStartSec=. */
1839 /* Traditionally, these options accepted 0 to disable the timeouts. However, a timeout of 0 suggests it happens
1840 * immediately, hence fix this to become USEC_INFINITY instead. This is in-line with how we internally handle
1841 * all other timeouts. */
1842 r
= parse_sec_fix_0(rvalue
, &usec
);
1844 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
1848 s
->start_timeout_defined
= true;
1849 s
->timeout_start_usec
= usec
;
1851 if (streq(lvalue
, "TimeoutSec"))
1852 s
->timeout_stop_usec
= usec
;
1857 int config_parse_sec_fix_0(
1859 const char *filename
,
1861 const char *section
,
1862 unsigned section_line
,
1869 usec_t
*usec
= data
;
1877 /* This is pretty much like config_parse_sec(), except that this treats a time of 0 as infinity, for
1878 * compatibility with older versions of systemd where 0 instead of infinity was used as indicator to turn off a
1881 r
= parse_sec_fix_0(rvalue
, usec
);
1883 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
1890 int config_parse_user_group(
1892 const char *filename
,
1894 const char *section
,
1895 unsigned section_line
,
1902 _cleanup_free_
char *k
= NULL
;
1912 if (isempty(rvalue
)) {
1913 *user
= mfree(*user
);
1917 r
= unit_full_printf(u
, rvalue
, &k
);
1919 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", rvalue
);
1923 if (!valid_user_group_name_or_id(k
)) {
1924 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
1928 return free_and_replace(*user
, k
);
1931 int config_parse_user_group_strv(
1933 const char *filename
,
1935 const char *section
,
1936 unsigned section_line
,
1943 char ***users
= data
;
1945 const char *p
= rvalue
;
1953 if (isempty(rvalue
)) {
1954 *users
= strv_free(*users
);
1959 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
1961 r
= extract_first_word(&p
, &word
, NULL
, 0);
1967 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax: %s", rvalue
);
1971 r
= unit_full_printf(u
, word
, &k
);
1973 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", word
);
1977 if (!valid_user_group_name_or_id(k
)) {
1978 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
1982 r
= strv_push(users
, k
);
1992 int config_parse_working_directory(
1994 const char *filename
,
1996 const char *section
,
1997 unsigned section_line
,
2004 ExecContext
*c
= data
;
2015 if (isempty(rvalue
)) {
2016 c
->working_directory_home
= false;
2017 c
->working_directory
= mfree(c
->working_directory
);
2021 if (rvalue
[0] == '-') {
2027 if (streq(rvalue
, "~")) {
2028 c
->working_directory_home
= true;
2029 c
->working_directory
= mfree(c
->working_directory
);
2031 _cleanup_free_
char *k
= NULL
;
2033 r
= unit_full_printf(u
, rvalue
, &k
);
2035 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2036 "Failed to resolve unit specifiers in working directory path '%s'%s: %m",
2037 rvalue
, missing_ok
? ", ignoring" : "");
2038 return missing_ok
? 0 : -ENOEXEC
;
2041 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
| (missing_ok
? 0 : PATH_CHECK_FATAL
), unit
, filename
, line
, lvalue
);
2043 return missing_ok
? 0 : -ENOEXEC
;
2045 c
->working_directory_home
= false;
2046 free_and_replace(c
->working_directory
, k
);
2049 c
->working_directory_missing_ok
= missing_ok
;
2053 int config_parse_unit_env_file(const char *unit
,
2054 const char *filename
,
2056 const char *section
,
2057 unsigned section_line
,
2066 _cleanup_free_
char *n
= NULL
;
2074 if (isempty(rvalue
)) {
2075 /* Empty assignment frees the list */
2076 *env
= strv_free(*env
);
2080 r
= unit_full_printf(u
, rvalue
, &n
);
2082 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2086 r
= path_simplify_and_warn(n
[0] == '-' ? n
+ 1 : n
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2090 r
= strv_push(env
, n
);
2099 int config_parse_environ(
2101 const char *filename
,
2103 const char *section
,
2104 unsigned section_line
,
2121 if (isempty(rvalue
)) {
2122 /* Empty assignment resets the list */
2123 *env
= strv_free(*env
);
2127 for (p
= rvalue
;; ) {
2128 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2130 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_QUOTES
);
2136 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2137 "Invalid syntax, ignoring: %s", rvalue
);
2142 r
= unit_full_printf(u
, word
, &k
);
2144 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2145 "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2151 if (!env_assignment_is_valid(k
)) {
2152 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2153 "Invalid environment assignment, ignoring: %s", k
);
2157 r
= strv_env_replace(env
, k
);
2165 int config_parse_pass_environ(
2167 const char *filename
,
2169 const char *section
,
2170 unsigned section_line
,
2177 _cleanup_strv_free_
char **n
= NULL
;
2178 size_t nlen
= 0, nbufsize
= 0;
2179 char*** passenv
= data
;
2180 const char *p
= rvalue
;
2189 if (isempty(rvalue
)) {
2190 /* Empty assignment resets the list */
2191 *passenv
= strv_free(*passenv
);
2196 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2198 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
2204 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2205 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2210 r
= unit_full_printf(u
, word
, &k
);
2212 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2213 "Failed to resolve specifiers in %s, ignoring: %m", word
);
2219 if (!env_name_is_valid(k
)) {
2220 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2221 "Invalid environment name for %s, ignoring: %s", lvalue
, k
);
2225 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
2228 n
[nlen
++] = TAKE_PTR(k
);
2233 r
= strv_extend_strv(passenv
, n
, true);
2241 int config_parse_unset_environ(
2243 const char *filename
,
2245 const char *section
,
2246 unsigned section_line
,
2253 _cleanup_strv_free_
char **n
= NULL
;
2254 size_t nlen
= 0, nbufsize
= 0;
2255 char*** unsetenv
= data
;
2256 const char *p
= rvalue
;
2265 if (isempty(rvalue
)) {
2266 /* Empty assignment resets the list */
2267 *unsetenv
= strv_free(*unsetenv
);
2272 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2274 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_QUOTES
);
2280 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2281 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2286 r
= unit_full_printf(u
, word
, &k
);
2288 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2289 "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2295 if (!env_assignment_is_valid(k
) && !env_name_is_valid(k
)) {
2296 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2297 "Invalid environment name or assignment %s, ignoring: %s", lvalue
, k
);
2301 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
2304 n
[nlen
++] = TAKE_PTR(k
);
2309 r
= strv_extend_strv(unsetenv
, n
, true);
2317 int config_parse_log_extra_fields(
2319 const char *filename
,
2321 const char *section
,
2322 unsigned section_line
,
2329 ExecContext
*c
= data
;
2331 const char *p
= rvalue
;
2339 if (isempty(rvalue
)) {
2340 exec_context_free_log_extra_fields(c
);
2345 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2349 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_QUOTES
);
2355 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
2359 r
= unit_full_printf(u
, word
, &k
);
2361 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2365 eq
= strchr(k
, '=');
2367 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Log field lacks '=' character, ignoring: %s", k
);
2371 if (!journal_field_valid(k
, eq
-k
, false)) {
2372 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Log field name is invalid, ignoring: %s", k
);
2376 t
= reallocarray(c
->log_extra_fields
, c
->n_log_extra_fields
+1, sizeof(struct iovec
));
2380 c
->log_extra_fields
= t
;
2381 c
->log_extra_fields
[c
->n_log_extra_fields
++] = IOVEC_MAKE_STRING(k
);
2387 int config_parse_unit_condition_path(
2389 const char *filename
,
2391 const char *section
,
2392 unsigned section_line
,
2399 _cleanup_free_
char *p
= NULL
;
2400 Condition
**list
= data
, *c
;
2401 ConditionType t
= ltype
;
2402 bool trigger
, negate
;
2411 if (isempty(rvalue
)) {
2412 /* Empty assignment resets the list */
2413 *list
= condition_free_list(*list
);
2417 trigger
= rvalue
[0] == '|';
2421 negate
= rvalue
[0] == '!';
2425 r
= unit_full_printf(u
, rvalue
, &p
);
2427 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2431 r
= path_simplify_and_warn(p
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2435 c
= condition_new(t
, p
, trigger
, negate
);
2439 LIST_PREPEND(conditions
, *list
, c
);
2443 int config_parse_unit_condition_string(
2445 const char *filename
,
2447 const char *section
,
2448 unsigned section_line
,
2455 _cleanup_free_
char *s
= NULL
;
2456 Condition
**list
= data
, *c
;
2457 ConditionType t
= ltype
;
2458 bool trigger
, negate
;
2467 if (isempty(rvalue
)) {
2468 /* Empty assignment resets the list */
2469 *list
= condition_free_list(*list
);
2473 trigger
= rvalue
[0] == '|';
2477 negate
= rvalue
[0] == '!';
2481 r
= unit_full_printf(u
, rvalue
, &s
);
2483 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2487 c
= condition_new(t
, s
, trigger
, negate
);
2491 LIST_PREPEND(conditions
, *list
, c
);
2495 int config_parse_unit_condition_null(
2497 const char *filename
,
2499 const char *section
,
2500 unsigned section_line
,
2507 Condition
**list
= data
, *c
;
2508 bool trigger
, negate
;
2516 if (isempty(rvalue
)) {
2517 /* Empty assignment resets the list */
2518 *list
= condition_free_list(*list
);
2522 trigger
= rvalue
[0] == '|';
2526 negate
= rvalue
[0] == '!';
2530 b
= parse_boolean(rvalue
);
2532 log_syntax(unit
, LOG_ERR
, filename
, line
, b
, "Failed to parse boolean value in condition, ignoring: %s", rvalue
);
2539 c
= condition_new(CONDITION_NULL
, NULL
, trigger
, negate
);
2543 LIST_PREPEND(conditions
, *list
, c
);
2547 int config_parse_unit_requires_mounts_for(
2549 const char *filename
,
2551 const char *section
,
2552 unsigned section_line
,
2559 const char *p
= rvalue
;
2569 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
2571 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
2577 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2578 "Invalid syntax, ignoring: %s", rvalue
);
2582 r
= unit_full_printf(u
, word
, &resolved
);
2584 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
2588 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2592 r
= unit_require_mounts_for(u
, resolved
, UNIT_DEPENDENCY_FILE
);
2594 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add required mount '%s', ignoring: %m", resolved
);
2600 int config_parse_documentation(const char *unit
,
2601 const char *filename
,
2603 const char *section
,
2604 unsigned section_line
,
2620 if (isempty(rvalue
)) {
2621 /* Empty assignment resets the list */
2622 u
->documentation
= strv_free(u
->documentation
);
2626 r
= config_parse_unit_strv_printf(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
,
2627 rvalue
, data
, userdata
);
2631 for (a
= b
= u
->documentation
; a
&& *a
; a
++) {
2633 if (documentation_url_is_valid(*a
))
2636 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid URL, ignoring: %s", *a
);
2647 int config_parse_syscall_filter(
2649 const char *filename
,
2651 const char *section
,
2652 unsigned section_line
,
2659 ExecContext
*c
= data
;
2661 bool invert
= false;
2670 if (isempty(rvalue
)) {
2671 /* Empty assignment resets the list */
2672 c
->syscall_filter
= hashmap_free(c
->syscall_filter
);
2673 c
->syscall_whitelist
= false;
2677 if (rvalue
[0] == '~') {
2682 if (!c
->syscall_filter
) {
2683 c
->syscall_filter
= hashmap_new(NULL
);
2684 if (!c
->syscall_filter
)
2688 /* Allow everything but the ones listed */
2689 c
->syscall_whitelist
= false;
2691 /* Allow nothing but the ones listed */
2692 c
->syscall_whitelist
= true;
2694 /* Accept default syscalls if we are on a whitelist */
2695 r
= seccomp_parse_syscall_filter("@default", -1, c
->syscall_filter
, SECCOMP_PARSE_WHITELIST
);
2703 _cleanup_free_
char *word
= NULL
, *name
= NULL
;
2706 r
= extract_first_word(&p
, &word
, NULL
, 0);
2712 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
2716 r
= parse_syscall_and_errno(word
, &name
, &num
);
2718 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse syscall:errno, ignoring: %s", word
);
2722 r
= seccomp_parse_syscall_filter_full(name
, num
, c
->syscall_filter
,
2723 SECCOMP_PARSE_LOG
|SECCOMP_PARSE_PERMISSIVE
|(invert
? SECCOMP_PARSE_INVERT
: 0)|(c
->syscall_whitelist
? SECCOMP_PARSE_WHITELIST
: 0),
2724 unit
, filename
, line
);
2730 int config_parse_syscall_archs(
2732 const char *filename
,
2734 const char *section
,
2735 unsigned section_line
,
2742 const char *p
= rvalue
;
2746 if (isempty(rvalue
)) {
2747 *archs
= set_free(*archs
);
2751 r
= set_ensure_allocated(archs
, NULL
);
2756 _cleanup_free_
char *word
= NULL
;
2759 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
2765 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2766 "Invalid syntax, ignoring: %s", rvalue
);
2770 r
= seccomp_arch_from_string(word
, &a
);
2772 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2773 "Failed to parse system call architecture \"%s\", ignoring: %m", word
);
2777 r
= set_put(*archs
, UINT32_TO_PTR(a
+ 1));
2783 int config_parse_syscall_errno(
2785 const char *filename
,
2787 const char *section
,
2788 unsigned section_line
,
2795 ExecContext
*c
= data
;
2802 if (isempty(rvalue
)) {
2803 /* Empty assignment resets to KILL */
2804 c
->syscall_errno
= 0;
2808 e
= parse_errno(rvalue
);
2810 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse error number, ignoring: %s", rvalue
);
2814 c
->syscall_errno
= e
;
2818 int config_parse_address_families(
2820 const char *filename
,
2822 const char *section
,
2823 unsigned section_line
,
2830 ExecContext
*c
= data
;
2831 bool invert
= false;
2839 if (isempty(rvalue
)) {
2840 /* Empty assignment resets the list */
2841 c
->address_families
= set_free(c
->address_families
);
2842 c
->address_families_whitelist
= false;
2846 if (rvalue
[0] == '~') {
2851 if (!c
->address_families
) {
2852 c
->address_families
= set_new(NULL
);
2853 if (!c
->address_families
)
2856 c
->address_families_whitelist
= !invert
;
2859 for (p
= rvalue
;;) {
2860 _cleanup_free_
char *word
= NULL
;
2863 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
2869 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2870 "Invalid syntax, ignoring: %s", rvalue
);
2874 af
= af_from_name(word
);
2876 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2877 "Failed to parse address family, ignoring: %s", word
);
2881 /* If we previously wanted to forbid an address family and now
2882 * we want to allow it, then just remove it from the list.
2884 if (!invert
== c
->address_families_whitelist
) {
2885 r
= set_put(c
->address_families
, INT_TO_PTR(af
));
2889 set_remove(c
->address_families
, INT_TO_PTR(af
));
2893 int config_parse_restrict_namespaces(
2895 const char *filename
,
2897 const char *section
,
2898 unsigned section_line
,
2905 ExecContext
*c
= data
;
2906 unsigned long flags
;
2907 bool invert
= false;
2910 if (isempty(rvalue
)) {
2911 /* Reset to the default. */
2912 c
->restrict_namespaces
= NAMESPACE_FLAGS_INITIAL
;
2916 /* Boolean parameter ignores the previous settings */
2917 r
= parse_boolean(rvalue
);
2919 c
->restrict_namespaces
= 0;
2921 } else if (r
== 0) {
2922 c
->restrict_namespaces
= NAMESPACE_FLAGS_ALL
;
2926 if (rvalue
[0] == '~') {
2931 /* Not a boolean argument, in this case it's a list of namespace types. */
2932 r
= namespace_flags_from_string(rvalue
, &flags
);
2934 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse namespace type string, ignoring: %s", rvalue
);
2938 if (c
->restrict_namespaces
== NAMESPACE_FLAGS_INITIAL
)
2939 /* Initial assignment. Just set the value. */
2940 c
->restrict_namespaces
= invert
? (~flags
) & NAMESPACE_FLAGS_ALL
: flags
;
2942 /* Merge the value with the previous one. */
2943 SET_FLAG(c
->restrict_namespaces
, flags
, !invert
);
2949 int config_parse_unit_slice(
2951 const char *filename
,
2953 const char *section
,
2954 unsigned section_line
,
2961 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
2962 _cleanup_free_
char *k
= NULL
;
2963 Unit
*u
= userdata
, *slice
= NULL
;
2971 r
= unit_name_printf(u
, rvalue
, &k
);
2973 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2977 r
= manager_load_unit(u
->manager
, k
, NULL
, &error
, &slice
);
2979 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to load slice unit %s, ignoring: %s", k
, bus_error_message(&error
, r
));
2983 r
= unit_set_slice(u
, slice
);
2985 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to assign slice %s to unit %s, ignoring: %m", slice
->id
, u
->id
);
2992 int config_parse_cpu_quota(
2994 const char *filename
,
2996 const char *section
,
2997 unsigned section_line
,
3004 CGroupContext
*c
= data
;
3011 if (isempty(rvalue
)) {
3012 c
->cpu_quota_per_sec_usec
= USEC_INFINITY
;
3016 r
= parse_permille_unbounded(rvalue
);
3018 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid CPU quota '%s', ignoring.", rvalue
);
3022 c
->cpu_quota_per_sec_usec
= ((usec_t
) r
* USEC_PER_SEC
) / 1000U;
3026 int config_parse_memory_limit(
3028 const char *filename
,
3030 const char *section
,
3031 unsigned section_line
,
3038 CGroupContext
*c
= data
;
3039 uint64_t bytes
= CGROUP_LIMIT_MAX
;
3042 if (!isempty(rvalue
) && !streq(rvalue
, "infinity")) {
3044 r
= parse_permille(rvalue
);
3046 r
= parse_size(rvalue
, 1024, &bytes
);
3048 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid memory limit '%s', ignoring: %m", rvalue
);
3052 bytes
= physical_memory_scale(r
, 1000U);
3054 if (bytes
>= UINT64_MAX
||
3055 (bytes
<= 0 && !streq(lvalue
, "MemorySwapMax"))) {
3056 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Memory limit '%s' out of range, ignoring.", rvalue
);
3061 if (streq(lvalue
, "MemoryMin"))
3062 c
->memory_min
= bytes
;
3063 else if (streq(lvalue
, "MemoryLow"))
3064 c
->memory_low
= bytes
;
3065 else if (streq(lvalue
, "MemoryHigh"))
3066 c
->memory_high
= bytes
;
3067 else if (streq(lvalue
, "MemoryMax"))
3068 c
->memory_max
= bytes
;
3069 else if (streq(lvalue
, "MemorySwapMax"))
3070 c
->memory_swap_max
= bytes
;
3071 else if (streq(lvalue
, "MemoryLimit"))
3072 c
->memory_limit
= bytes
;
3079 int config_parse_tasks_max(
3081 const char *filename
,
3083 const char *section
,
3084 unsigned section_line
,
3091 uint64_t *tasks_max
= data
, v
;
3095 if (isempty(rvalue
)) {
3096 *tasks_max
= u
->manager
->default_tasks_max
;
3100 if (streq(rvalue
, "infinity")) {
3101 *tasks_max
= CGROUP_LIMIT_MAX
;
3105 r
= parse_permille(rvalue
);
3107 r
= safe_atou64(rvalue
, &v
);
3109 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid maximum tasks value '%s', ignoring: %m", rvalue
);
3113 v
= system_tasks_max_scale(r
, 1000U);
3115 if (v
<= 0 || v
>= UINT64_MAX
) {
3116 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Maximum tasks value '%s' out of range, ignoring.", rvalue
);
3124 int config_parse_delegate(
3126 const char *filename
,
3128 const char *section
,
3129 unsigned section_line
,
3136 CGroupContext
*c
= data
;
3140 t
= unit_name_to_type(unit
);
3141 assert(t
!= _UNIT_TYPE_INVALID
);
3143 if (!unit_vtable
[t
]->can_delegate
) {
3144 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Delegate= setting not supported for this unit type, ignoring.");
3148 /* We either accept a boolean value, which may be used to turn on delegation for all controllers, or turn it
3149 * off for all. Or it takes a list of controller names, in which case we add the specified controllers to the
3150 * mask to delegate. */
3152 if (isempty(rvalue
)) {
3153 /* An empty string resets controllers and set Delegate=yes. */
3155 c
->delegate_controllers
= 0;
3159 r
= parse_boolean(rvalue
);
3161 const char *p
= rvalue
;
3162 CGroupMask mask
= 0;
3165 _cleanup_free_
char *word
= NULL
;
3166 CGroupController cc
;
3168 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
3174 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3178 cc
= cgroup_controller_from_string(word
);
3180 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid controller name '%s', ignoring", word
);
3184 mask
|= CGROUP_CONTROLLER_TO_MASK(cc
);
3188 c
->delegate_controllers
|= mask
;
3192 c
->delegate_controllers
= _CGROUP_MASK_ALL
;
3194 c
->delegate
= false;
3195 c
->delegate_controllers
= 0;
3201 int config_parse_device_allow(
3203 const char *filename
,
3205 const char *section
,
3206 unsigned section_line
,
3213 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3214 CGroupContext
*c
= data
;
3215 const char *p
= rvalue
;
3218 if (isempty(rvalue
)) {
3219 while (c
->device_allow
)
3220 cgroup_context_free_device_allow(c
, c
->device_allow
);
3225 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_QUOTES
);
3229 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3230 "Invalid syntax, ignoring: %s", rvalue
);
3234 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3235 "Failed to extract device path and rights from '%s', ignoring.", rvalue
);
3239 r
= unit_full_printf(userdata
, path
, &resolved
);
3241 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3242 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3246 if (!startswith(resolved
, "block-") && !startswith(resolved
, "char-")) {
3248 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3252 if (!valid_device_node_path(resolved
)) {
3253 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device node path '%s', ignoring.", resolved
);
3258 if (!isempty(p
) && !in_charset(p
, "rwm")) {
3259 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device rights '%s', ignoring.", p
);
3263 return cgroup_add_device_allow(c
, resolved
, p
);
3266 int config_parse_io_device_weight(
3268 const char *filename
,
3270 const char *section
,
3271 unsigned section_line
,
3278 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3279 CGroupIODeviceWeight
*w
;
3280 CGroupContext
*c
= data
;
3281 const char *p
= rvalue
;
3289 if (isempty(rvalue
)) {
3290 while (c
->io_device_weights
)
3291 cgroup_context_free_io_device_weight(c
, c
->io_device_weights
);
3296 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_QUOTES
);
3300 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3301 "Invalid syntax, ignoring: %s", rvalue
);
3304 if (r
== 0 || isempty(p
)) {
3305 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3306 "Failed to extract device path and weight from '%s', ignoring.", rvalue
);
3310 r
= unit_full_printf(userdata
, path
, &resolved
);
3312 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3313 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3317 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3321 r
= cg_weight_parse(p
, &u
);
3323 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "IO weight '%s' invalid, ignoring: %m", p
);
3327 assert(u
!= CGROUP_WEIGHT_INVALID
);
3329 w
= new0(CGroupIODeviceWeight
, 1);
3333 w
->path
= TAKE_PTR(resolved
);
3336 LIST_PREPEND(device_weights
, c
->io_device_weights
, w
);
3340 int config_parse_io_limit(
3342 const char *filename
,
3344 const char *section
,
3345 unsigned section_line
,
3352 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3353 CGroupIODeviceLimit
*l
= NULL
, *t
;
3354 CGroupContext
*c
= data
;
3355 CGroupIOLimitType type
;
3356 const char *p
= rvalue
;
3364 type
= cgroup_io_limit_type_from_string(lvalue
);
3367 if (isempty(rvalue
)) {
3368 LIST_FOREACH(device_limits
, l
, c
->io_device_limits
)
3369 l
->limits
[type
] = cgroup_io_limit_defaults
[type
];
3373 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_QUOTES
);
3377 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3378 "Invalid syntax, ignoring: %s", rvalue
);
3381 if (r
== 0 || isempty(p
)) {
3382 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3383 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
3387 r
= unit_full_printf(userdata
, path
, &resolved
);
3389 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3390 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3394 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3398 if (streq("infinity", p
))
3399 num
= CGROUP_LIMIT_MAX
;
3401 r
= parse_size(p
, 1000, &num
);
3402 if (r
< 0 || num
<= 0) {
3403 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid IO limit '%s', ignoring.", p
);
3408 LIST_FOREACH(device_limits
, t
, c
->io_device_limits
) {
3409 if (path_equal(resolved
, t
->path
)) {
3416 CGroupIOLimitType ttype
;
3418 l
= new0(CGroupIODeviceLimit
, 1);
3422 l
->path
= TAKE_PTR(resolved
);
3423 for (ttype
= 0; ttype
< _CGROUP_IO_LIMIT_TYPE_MAX
; ttype
++)
3424 l
->limits
[ttype
] = cgroup_io_limit_defaults
[ttype
];
3426 LIST_PREPEND(device_limits
, c
->io_device_limits
, l
);
3429 l
->limits
[type
] = num
;
3434 int config_parse_blockio_device_weight(
3436 const char *filename
,
3438 const char *section
,
3439 unsigned section_line
,
3446 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3447 CGroupBlockIODeviceWeight
*w
;
3448 CGroupContext
*c
= data
;
3449 const char *p
= rvalue
;
3457 if (isempty(rvalue
)) {
3458 while (c
->blockio_device_weights
)
3459 cgroup_context_free_blockio_device_weight(c
, c
->blockio_device_weights
);
3464 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_QUOTES
);
3468 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3469 "Invalid syntax, ignoring: %s", rvalue
);
3472 if (r
== 0 || isempty(p
)) {
3473 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3474 "Failed to extract device node and weight from '%s', ignoring.", rvalue
);
3478 r
= unit_full_printf(userdata
, path
, &resolved
);
3480 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3481 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3485 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3489 r
= cg_blkio_weight_parse(p
, &u
);
3491 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid block IO weight '%s', ignoring: %m", p
);
3495 assert(u
!= CGROUP_BLKIO_WEIGHT_INVALID
);
3497 w
= new0(CGroupBlockIODeviceWeight
, 1);
3501 w
->path
= TAKE_PTR(resolved
);
3504 LIST_PREPEND(device_weights
, c
->blockio_device_weights
, w
);
3508 int config_parse_blockio_bandwidth(
3510 const char *filename
,
3512 const char *section
,
3513 unsigned section_line
,
3520 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3521 CGroupBlockIODeviceBandwidth
*b
= NULL
, *t
;
3522 CGroupContext
*c
= data
;
3523 const char *p
= rvalue
;
3532 read
= streq("BlockIOReadBandwidth", lvalue
);
3534 if (isempty(rvalue
)) {
3535 LIST_FOREACH(device_bandwidths
, b
, c
->blockio_device_bandwidths
) {
3536 b
->rbps
= CGROUP_LIMIT_MAX
;
3537 b
->wbps
= CGROUP_LIMIT_MAX
;
3542 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_QUOTES
);
3546 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3547 "Invalid syntax, ignoring: %s", rvalue
);
3550 if (r
== 0 || isempty(p
)) {
3551 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3552 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
3556 r
= unit_full_printf(userdata
, path
, &resolved
);
3558 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3559 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3563 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3567 r
= parse_size(p
, 1000, &bytes
);
3568 if (r
< 0 || bytes
<= 0) {
3569 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid Block IO Bandwidth '%s', ignoring.", p
);
3573 LIST_FOREACH(device_bandwidths
, t
, c
->blockio_device_bandwidths
) {
3574 if (path_equal(resolved
, t
->path
)) {
3581 b
= new0(CGroupBlockIODeviceBandwidth
, 1);
3585 b
->path
= TAKE_PTR(resolved
);
3586 b
->rbps
= CGROUP_LIMIT_MAX
;
3587 b
->wbps
= CGROUP_LIMIT_MAX
;
3589 LIST_PREPEND(device_bandwidths
, c
->blockio_device_bandwidths
, b
);
3600 int config_parse_job_mode_isolate(
3602 const char *filename
,
3604 const char *section
,
3605 unsigned section_line
,
3619 r
= parse_boolean(rvalue
);
3621 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse boolean, ignoring: %s", rvalue
);
3625 log_notice("%s is deprecated. Please use OnFailureJobMode= instead", lvalue
);
3627 *m
= r
? JOB_ISOLATE
: JOB_REPLACE
;
3631 int config_parse_exec_directories(
3633 const char *filename
,
3635 const char *section
,
3636 unsigned section_line
,
3653 if (isempty(rvalue
)) {
3654 /* Empty assignment resets the list */
3655 *rt
= strv_free(*rt
);
3659 for (p
= rvalue
;;) {
3660 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
3662 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
3666 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3667 "Invalid syntax, ignoring: %s", rvalue
);
3673 r
= unit_full_printf(u
, word
, &k
);
3675 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
3676 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
3680 r
= path_simplify_and_warn(k
, PATH_CHECK_RELATIVE
, unit
, filename
, line
, lvalue
);
3684 if (path_startswith(k
, "private")) {
3685 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
3686 "%s= path can't be 'private', ingoring assignment: %s", lvalue
, word
);
3690 r
= strv_push(rt
, k
);
3697 int config_parse_set_status(
3699 const char *filename
,
3701 const char *section
,
3702 unsigned section_line
,
3710 const char *word
, *state
;
3712 ExitStatusSet
*status_set
= data
;
3719 /* Empty assignment resets the list */
3720 if (isempty(rvalue
)) {
3721 exit_status_set_free(status_set
);
3725 FOREACH_WORD(word
, l
, rvalue
, state
) {
3726 _cleanup_free_
char *temp
;
3730 temp
= strndup(word
, l
);
3734 r
= safe_atoi(temp
, &val
);
3736 val
= signal_from_string(temp
);
3739 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse value, ignoring: %s", word
);
3742 set
= &status_set
->signal
;
3744 if (val
< 0 || val
> 255) {
3745 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Value %d is outside range 0-255, ignoring", val
);
3748 set
= &status_set
->status
;
3751 r
= set_ensure_allocated(set
, NULL
);
3755 r
= set_put(*set
, INT_TO_PTR(val
));
3759 if (!isempty(state
))
3760 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Trailing garbage, ignoring.");
3765 int config_parse_namespace_path_strv(
3767 const char *filename
,
3769 const char *section
,
3770 unsigned section_line
,
3779 const char *p
= rvalue
;
3787 if (isempty(rvalue
)) {
3788 /* Empty assignment resets the list */
3789 *sv
= strv_free(*sv
);
3794 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
, *joined
= NULL
;
3796 bool ignore_enoent
= false, shall_prefix
= false;
3798 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
3804 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
3809 if (startswith(w
, "-")) {
3810 ignore_enoent
= true;
3813 if (startswith(w
, "+")) {
3814 shall_prefix
= true;
3818 r
= unit_full_printf(u
, w
, &resolved
);
3820 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", w
);
3824 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
3828 joined
= strjoin(ignore_enoent
? "-" : "",
3829 shall_prefix
? "+" : "",
3832 r
= strv_push(sv
, joined
);
3842 int config_parse_temporary_filesystems(
3844 const char *filename
,
3846 const char *section
,
3847 unsigned section_line
,
3855 ExecContext
*c
= data
;
3856 const char *p
= rvalue
;
3864 if (isempty(rvalue
)) {
3865 /* Empty assignment resets the list */
3866 temporary_filesystem_free_many(c
->temporary_filesystems
, c
->n_temporary_filesystems
);
3867 c
->temporary_filesystems
= NULL
;
3868 c
->n_temporary_filesystems
= 0;
3873 _cleanup_free_
char *word
= NULL
, *path
= NULL
, *resolved
= NULL
;
3876 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
3882 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
3887 r
= extract_first_word(&w
, &path
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
3891 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", word
);
3895 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid syntax, ignoring: %s", word
);
3899 r
= unit_full_printf(u
, path
, &resolved
);
3901 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", path
);
3905 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
3909 r
= temporary_filesystem_add(&c
->temporary_filesystems
, &c
->n_temporary_filesystems
, resolved
, w
);
3915 int config_parse_bind_paths(
3917 const char *filename
,
3919 const char *section
,
3920 unsigned section_line
,
3927 ExecContext
*c
= data
;
3937 if (isempty(rvalue
)) {
3938 /* Empty assignment resets the list */
3939 bind_mount_free_many(c
->bind_mounts
, c
->n_bind_mounts
);
3940 c
->bind_mounts
= NULL
;
3941 c
->n_bind_mounts
= 0;
3947 _cleanup_free_
char *source
= NULL
, *destination
= NULL
;
3948 _cleanup_free_
char *sresolved
= NULL
, *dresolved
= NULL
;
3949 char *s
= NULL
, *d
= NULL
;
3950 bool rbind
= true, ignore_enoent
= false;
3952 r
= extract_first_word(&p
, &source
, ":" WHITESPACE
, EXTRACT_QUOTES
|EXTRACT_DONT_COALESCE_SEPARATORS
);
3958 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
3962 r
= unit_full_printf(u
, source
, &sresolved
);
3964 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
3965 "Failed to resolved unit specifiers in \"%s\", ignoring: %m", source
);
3971 ignore_enoent
= true;
3975 r
= path_simplify_and_warn(s
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
3979 /* Optionally, the destination is specified. */
3980 if (p
&& p
[-1] == ':') {
3981 r
= extract_first_word(&p
, &destination
, ":" WHITESPACE
, EXTRACT_QUOTES
|EXTRACT_DONT_COALESCE_SEPARATORS
);
3985 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
3989 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Missing argument after ':', ignoring: %s", s
);
3993 r
= unit_full_printf(u
, destination
, &dresolved
);
3995 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
3996 "Failed to resolved specifiers in \"%s\", ignoring: %m", destination
);
4000 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4006 /* Optionally, there's also a short option string specified */
4007 if (p
&& p
[-1] == ':') {
4008 _cleanup_free_
char *options
= NULL
;
4010 r
= extract_first_word(&p
, &options
, NULL
, EXTRACT_QUOTES
);
4014 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s: %s", lvalue
, rvalue
);
4018 if (isempty(options
) || streq(options
, "rbind"))
4020 else if (streq(options
, "norbind"))
4023 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid option string, ignoring setting: %s", options
);
4030 r
= bind_mount_add(&c
->bind_mounts
, &c
->n_bind_mounts
,
4034 .read_only
= !!strstr(lvalue
, "ReadOnly"),
4036 .ignore_enoent
= ignore_enoent
,
4045 int config_parse_job_timeout_sec(
4047 const char *filename
,
4049 const char *section
,
4050 unsigned section_line
,
4066 r
= parse_sec_fix_0(rvalue
, &usec
);
4068 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse JobTimeoutSec= parameter, ignoring: %s", rvalue
);
4072 /* If the user explicitly changed JobTimeoutSec= also change JobRunningTimeoutSec=, for compatibility with old
4073 * versions. If JobRunningTimeoutSec= was explicitly set, avoid this however as whatever the user picked should
4076 if (!u
->job_running_timeout_set
)
4077 u
->job_running_timeout
= usec
;
4079 u
->job_timeout
= usec
;
4084 int config_parse_job_running_timeout_sec(
4086 const char *filename
,
4088 const char *section
,
4089 unsigned section_line
,
4105 r
= parse_sec_fix_0(rvalue
, &usec
);
4107 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse JobRunningTimeoutSec= parameter, ignoring: %s", rvalue
);
4111 u
->job_running_timeout
= usec
;
4112 u
->job_running_timeout_set
= true;
4117 #define FOLLOW_MAX 8
4119 static int open_follow(char **filename
, FILE **_f
, Set
*names
, char **_final
) {
4130 /* This will update the filename pointer if the loaded file is
4131 * reached by a symlink. The old string will be freed. */
4134 char *target
, *name
;
4136 if (c
++ >= FOLLOW_MAX
)
4139 path_simplify(*filename
, false);
4141 /* Add the file name we are currently looking at to
4142 * the names of this unit, but only if it is a valid
4144 name
= basename(*filename
);
4145 if (unit_name_is_valid(name
, UNIT_NAME_ANY
)) {
4147 id
= set_get(names
, name
);
4153 r
= set_consume(names
, id
);
4159 /* Try to open the file name, but don't if its a symlink */
4160 fd
= open(*filename
, O_RDONLY
|O_CLOEXEC
|O_NOCTTY
|O_NOFOLLOW
);
4167 /* Hmm, so this is a symlink. Let's read the name, and follow it manually */
4168 r
= readlink_and_make_absolute(*filename
, &target
);
4172 free_and_replace(*filename
, target
);
4175 f
= fdopen(fd
, "re");
4187 static int merge_by_names(Unit
**u
, Set
*names
, const char *id
) {
4195 /* Let's try to add in all symlink names we found */
4196 while ((k
= set_steal_first(names
))) {
4198 /* First try to merge in the other name into our
4200 r
= unit_merge_by_name(*u
, k
);
4204 /* Hmm, we couldn't merge the other unit into
4205 * ours? Then let's try it the other way
4208 /* If the symlink name we are looking at is unit template, then
4209 we must search for instance of this template */
4210 if (unit_name_is_valid(k
, UNIT_NAME_TEMPLATE
) && (*u
)->instance
) {
4211 _cleanup_free_
char *instance
= NULL
;
4213 r
= unit_name_replace_instance(k
, (*u
)->instance
, &instance
);
4217 other
= manager_get_unit((*u
)->manager
, instance
);
4219 other
= manager_get_unit((*u
)->manager
, k
);
4224 r
= unit_merge(other
, *u
);
4227 return merge_by_names(u
, names
, NULL
);
4235 unit_choose_id(*u
, id
);
4243 static int load_from_path(Unit
*u
, const char *path
) {
4244 _cleanup_set_free_free_ Set
*symlink_names
= NULL
;
4245 _cleanup_fclose_
FILE *f
= NULL
;
4246 _cleanup_free_
char *filename
= NULL
;
4255 symlink_names
= set_new(&string_hash_ops
);
4259 if (path_is_absolute(path
)) {
4261 filename
= strdup(path
);
4265 r
= open_follow(&filename
, &f
, symlink_names
, &id
);
4267 filename
= mfree(filename
);
4275 STRV_FOREACH(p
, u
->manager
->lookup_paths
.search_path
) {
4277 /* Instead of opening the path right away, we manually
4278 * follow all symlinks and add their name to our unit
4279 * name set while doing so */
4280 filename
= path_make_absolute(path
, *p
);
4284 if (u
->manager
->unit_path_cache
&&
4285 !set_get(u
->manager
->unit_path_cache
, filename
))
4288 r
= open_follow(&filename
, &f
, symlink_names
, &id
);
4291 filename
= mfree(filename
);
4293 /* ENOENT means that the file is missing or is a dangling symlink.
4294 * ENOTDIR means that one of paths we expect to be is a directory
4295 * is not a directory, we should just ignore that.
4296 * EACCES means that the directory or file permissions are wrong.
4299 log_debug_errno(r
, "Cannot access \"%s\": %m", filename
);
4300 else if (!IN_SET(r
, -ENOENT
, -ENOTDIR
))
4303 /* Empty the symlink names for the next run */
4304 set_clear_free(symlink_names
);
4309 /* Hmm, no suitable file found? */
4312 if (!unit_type_may_alias(u
->type
) && set_size(symlink_names
) > 1) {
4313 log_unit_warning(u
, "Unit type of %s does not support alias names, refusing loading via symlink.", u
->id
);
4318 r
= merge_by_names(&merged
, symlink_names
, id
);
4323 u
->load_state
= UNIT_MERGED
;
4327 if (fstat(fileno(f
), &st
) < 0)
4330 if (null_or_empty(&st
)) {
4331 u
->load_state
= UNIT_MASKED
;
4332 u
->fragment_mtime
= 0;
4334 u
->load_state
= UNIT_LOADED
;
4335 u
->fragment_mtime
= timespec_load(&st
.st_mtim
);
4337 /* Now, parse the file contents */
4338 r
= config_parse(u
->id
, filename
, f
,
4339 UNIT_VTABLE(u
)->sections
,
4340 config_item_perf_lookup
, load_fragment_gperf_lookup
,
4341 CONFIG_PARSE_ALLOW_INCLUDE
, u
);
4346 free_and_replace(u
->fragment_path
, filename
);
4348 if (u
->source_path
) {
4349 if (stat(u
->source_path
, &st
) >= 0)
4350 u
->source_mtime
= timespec_load(&st
.st_mtim
);
4352 u
->source_mtime
= 0;
4358 int unit_load_fragment(Unit
*u
) {
4364 assert(u
->load_state
== UNIT_STUB
);
4368 u
->load_state
= UNIT_LOADED
;
4372 /* First, try to find the unit under its id. We always look
4373 * for unit files in the default directories, to make it easy
4374 * to override things by placing things in /etc/systemd/system */
4375 r
= load_from_path(u
, u
->id
);
4379 /* Try to find an alias we can load this with */
4380 if (u
->load_state
== UNIT_STUB
) {
4381 SET_FOREACH(t
, u
->names
, i
) {
4386 r
= load_from_path(u
, t
);
4390 if (u
->load_state
!= UNIT_STUB
)
4395 /* And now, try looking for it under the suggested (originally linked) path */
4396 if (u
->load_state
== UNIT_STUB
&& u
->fragment_path
) {
4398 r
= load_from_path(u
, u
->fragment_path
);
4402 if (u
->load_state
== UNIT_STUB
)
4403 /* Hmm, this didn't work? Then let's get rid
4404 * of the fragment path stored for us, so that
4405 * we don't point to an invalid location. */
4406 u
->fragment_path
= mfree(u
->fragment_path
);
4409 /* Look for a template */
4410 if (u
->load_state
== UNIT_STUB
&& u
->instance
) {
4411 _cleanup_free_
char *k
= NULL
;
4413 r
= unit_name_template(u
->id
, &k
);
4417 r
= load_from_path(u
, k
);
4420 log_unit_notice(u
, "Unit configuration has fatal error, unit will not be started.");
4424 if (u
->load_state
== UNIT_STUB
) {
4425 SET_FOREACH(t
, u
->names
, i
) {
4426 _cleanup_free_
char *z
= NULL
;
4431 r
= unit_name_template(t
, &z
);
4435 r
= load_from_path(u
, z
);
4439 if (u
->load_state
!= UNIT_STUB
)
4448 void unit_dump_config_items(FILE *f
) {
4449 static const struct {
4450 const ConfigParserCallback callback
;
4453 { config_parse_warn_compat
, "NOTSUPPORTED" },
4454 { config_parse_int
, "INTEGER" },
4455 { config_parse_unsigned
, "UNSIGNED" },
4456 { config_parse_iec_size
, "SIZE" },
4457 { config_parse_iec_uint64
, "SIZE" },
4458 { config_parse_si_size
, "SIZE" },
4459 { config_parse_bool
, "BOOLEAN" },
4460 { config_parse_string
, "STRING" },
4461 { config_parse_path
, "PATH" },
4462 { config_parse_unit_path_printf
, "PATH" },
4463 { config_parse_strv
, "STRING [...]" },
4464 { config_parse_exec_nice
, "NICE" },
4465 { config_parse_exec_oom_score_adjust
, "OOMSCOREADJUST" },
4466 { config_parse_exec_io_class
, "IOCLASS" },
4467 { config_parse_exec_io_priority
, "IOPRIORITY" },
4468 { config_parse_exec_cpu_sched_policy
, "CPUSCHEDPOLICY" },
4469 { config_parse_exec_cpu_sched_prio
, "CPUSCHEDPRIO" },
4470 { config_parse_exec_cpu_affinity
, "CPUAFFINITY" },
4471 { config_parse_mode
, "MODE" },
4472 { config_parse_unit_env_file
, "FILE" },
4473 { config_parse_exec_output
, "OUTPUT" },
4474 { config_parse_exec_input
, "INPUT" },
4475 { config_parse_log_facility
, "FACILITY" },
4476 { config_parse_log_level
, "LEVEL" },
4477 { config_parse_exec_secure_bits
, "SECUREBITS" },
4478 { config_parse_capability_set
, "BOUNDINGSET" },
4479 { config_parse_rlimit
, "LIMIT" },
4480 { config_parse_unit_deps
, "UNIT [...]" },
4481 { config_parse_exec
, "PATH [ARGUMENT [...]]" },
4482 { config_parse_service_type
, "SERVICETYPE" },
4483 { config_parse_service_restart
, "SERVICERESTART" },
4484 { config_parse_kill_mode
, "KILLMODE" },
4485 { config_parse_signal
, "SIGNAL" },
4486 { config_parse_socket_listen
, "SOCKET [...]" },
4487 { config_parse_socket_bind
, "SOCKETBIND" },
4488 { config_parse_socket_bindtodevice
, "NETWORKINTERFACE" },
4489 { config_parse_sec
, "SECONDS" },
4490 { config_parse_nsec
, "NANOSECONDS" },
4491 { config_parse_namespace_path_strv
, "PATH [...]" },
4492 { config_parse_bind_paths
, "PATH[:PATH[:OPTIONS]] [...]" },
4493 { config_parse_unit_requires_mounts_for
, "PATH [...]" },
4494 { config_parse_exec_mount_flags
, "MOUNTFLAG [...]" },
4495 { config_parse_unit_string_printf
, "STRING" },
4496 { config_parse_trigger_unit
, "UNIT" },
4497 { config_parse_timer
, "TIMER" },
4498 { config_parse_path_spec
, "PATH" },
4499 { config_parse_notify_access
, "ACCESS" },
4500 { config_parse_ip_tos
, "TOS" },
4501 { config_parse_unit_condition_path
, "CONDITION" },
4502 { config_parse_unit_condition_string
, "CONDITION" },
4503 { config_parse_unit_condition_null
, "CONDITION" },
4504 { config_parse_unit_slice
, "SLICE" },
4505 { config_parse_documentation
, "URL" },
4506 { config_parse_service_timeout
, "SECONDS" },
4507 { config_parse_emergency_action
, "ACTION" },
4508 { config_parse_set_status
, "STATUS" },
4509 { config_parse_service_sockets
, "SOCKETS" },
4510 { config_parse_environ
, "ENVIRON" },
4512 { config_parse_syscall_filter
, "SYSCALLS" },
4513 { config_parse_syscall_archs
, "ARCHS" },
4514 { config_parse_syscall_errno
, "ERRNO" },
4515 { config_parse_address_families
, "FAMILIES" },
4516 { config_parse_restrict_namespaces
, "NAMESPACES" },
4518 { config_parse_cpu_shares
, "SHARES" },
4519 { config_parse_cg_weight
, "WEIGHT" },
4520 { config_parse_memory_limit
, "LIMIT" },
4521 { config_parse_device_allow
, "DEVICE" },
4522 { config_parse_device_policy
, "POLICY" },
4523 { config_parse_io_limit
, "LIMIT" },
4524 { config_parse_io_device_weight
, "DEVICEWEIGHT" },
4525 { config_parse_blockio_bandwidth
, "BANDWIDTH" },
4526 { config_parse_blockio_weight
, "WEIGHT" },
4527 { config_parse_blockio_device_weight
, "DEVICEWEIGHT" },
4528 { config_parse_long
, "LONG" },
4529 { config_parse_socket_service
, "SERVICE" },
4531 { config_parse_exec_selinux_context
, "LABEL" },
4533 { config_parse_job_mode
, "MODE" },
4534 { config_parse_job_mode_isolate
, "BOOLEAN" },
4535 { config_parse_personality
, "PERSONALITY" },
4538 const char *prev
= NULL
;
4543 NULSTR_FOREACH(i
, load_fragment_gperf_nulstr
) {
4544 const char *rvalue
= "OTHER", *lvalue
;
4545 const ConfigPerfItem
*p
;
4550 assert_se(p
= load_fragment_gperf_lookup(i
, strlen(i
)));
4552 /* Hide legacy settings */
4553 if (p
->parse
== config_parse_warn_compat
&&
4554 p
->ltype
== DISABLED_LEGACY
)
4557 for (j
= 0; j
< ELEMENTSOF(table
); j
++)
4558 if (p
->parse
== table
[j
].callback
) {
4559 rvalue
= table
[j
].rvalue
;
4563 dot
= strchr(i
, '.');
4564 lvalue
= dot
? dot
+ 1 : i
;
4568 if (!prev
|| !strneq(prev
, i
, prefix_len
+1)) {
4572 fprintf(f
, "[%.*s]\n", (int) prefix_len
, i
);
4575 fprintf(f
, "%s=%s\n", lvalue
, rvalue
);