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
;
1019 eo
= exec_output_from_string(rvalue
);
1021 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse output specifier, ignoring: %s", rvalue
);
1026 if (streq(lvalue
, "StandardOutput")) {
1027 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1028 free_and_replace(c
->stdio_fdname
[STDOUT_FILENO
], resolved
);
1030 free_and_replace(c
->stdio_file
[STDOUT_FILENO
], resolved
);
1035 assert(streq(lvalue
, "StandardError"));
1037 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1038 free_and_replace(c
->stdio_fdname
[STDERR_FILENO
], resolved
);
1040 free_and_replace(c
->stdio_file
[STDERR_FILENO
], resolved
);
1048 int config_parse_exec_io_class(const char *unit
,
1049 const char *filename
,
1051 const char *section
,
1052 unsigned section_line
,
1059 ExecContext
*c
= data
;
1067 if (isempty(rvalue
)) {
1068 c
->ioprio_set
= false;
1069 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE
, 0);
1073 x
= ioprio_class_from_string(rvalue
);
1075 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse IO scheduling class, ignoring: %s", rvalue
);
1079 c
->ioprio
= IOPRIO_PRIO_VALUE(x
, IOPRIO_PRIO_DATA(c
->ioprio
));
1080 c
->ioprio_set
= true;
1085 int config_parse_exec_io_priority(const char *unit
,
1086 const char *filename
,
1088 const char *section
,
1089 unsigned section_line
,
1096 ExecContext
*c
= data
;
1104 if (isempty(rvalue
)) {
1105 c
->ioprio_set
= false;
1106 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE
, 0);
1110 r
= ioprio_parse_priority(rvalue
, &i
);
1112 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse IO priority, ignoring: %s", rvalue
);
1116 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_PRIO_CLASS(c
->ioprio
), i
);
1117 c
->ioprio_set
= true;
1122 int config_parse_exec_cpu_sched_policy(const char *unit
,
1123 const char *filename
,
1125 const char *section
,
1126 unsigned section_line
,
1133 ExecContext
*c
= data
;
1141 if (isempty(rvalue
)) {
1142 c
->cpu_sched_set
= false;
1143 c
->cpu_sched_policy
= SCHED_OTHER
;
1144 c
->cpu_sched_priority
= 0;
1148 x
= sched_policy_from_string(rvalue
);
1150 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse CPU scheduling policy, ignoring: %s", rvalue
);
1154 c
->cpu_sched_policy
= x
;
1155 /* Moving to or from real-time policy? We need to adjust the priority */
1156 c
->cpu_sched_priority
= CLAMP(c
->cpu_sched_priority
, sched_get_priority_min(x
), sched_get_priority_max(x
));
1157 c
->cpu_sched_set
= true;
1162 int config_parse_exec_cpu_sched_prio(const char *unit
,
1163 const char *filename
,
1165 const char *section
,
1166 unsigned section_line
,
1173 ExecContext
*c
= data
;
1181 r
= safe_atoi(rvalue
, &i
);
1183 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse CPU scheduling priority, ignoring: %s", rvalue
);
1187 /* On Linux RR/FIFO range from 1 to 99 and OTHER/BATCH may only be 0 */
1188 min
= sched_get_priority_min(c
->cpu_sched_policy
);
1189 max
= sched_get_priority_max(c
->cpu_sched_policy
);
1191 if (i
< min
|| i
> max
) {
1192 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "CPU scheduling priority is out of range, ignoring: %s", rvalue
);
1196 c
->cpu_sched_priority
= i
;
1197 c
->cpu_sched_set
= true;
1202 int config_parse_exec_cpu_affinity(const char *unit
,
1203 const char *filename
,
1205 const char *section
,
1206 unsigned section_line
,
1213 ExecContext
*c
= data
;
1214 _cleanup_cpu_free_ cpu_set_t
*cpuset
= NULL
;
1222 ncpus
= parse_cpu_set_and_warn(rvalue
, &cpuset
, unit
, filename
, line
, lvalue
);
1227 /* An empty assignment resets the CPU list */
1228 c
->cpuset
= cpu_set_mfree(c
->cpuset
);
1229 c
->cpuset_ncpus
= 0;
1234 c
->cpuset
= TAKE_PTR(cpuset
);
1235 c
->cpuset_ncpus
= (unsigned) ncpus
;
1239 if (c
->cpuset_ncpus
< (unsigned) ncpus
) {
1240 CPU_OR_S(CPU_ALLOC_SIZE(c
->cpuset_ncpus
), cpuset
, c
->cpuset
, cpuset
);
1241 CPU_FREE(c
->cpuset
);
1242 c
->cpuset
= TAKE_PTR(cpuset
);
1243 c
->cpuset_ncpus
= (unsigned) ncpus
;
1247 CPU_OR_S(CPU_ALLOC_SIZE((unsigned) ncpus
), c
->cpuset
, c
->cpuset
, cpuset
);
1252 int config_parse_capability_set(
1254 const char *filename
,
1256 const char *section
,
1257 unsigned section_line
,
1264 uint64_t *capability_set
= data
;
1265 uint64_t sum
= 0, initial
= 0;
1266 bool invert
= false;
1274 if (rvalue
[0] == '~') {
1279 if (streq(lvalue
, "CapabilityBoundingSet"))
1280 initial
= CAP_ALL
; /* initialized to all bits on */
1281 /* else "AmbientCapabilities" initialized to all bits off */
1283 r
= capability_set_from_string(rvalue
, &sum
);
1285 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= specifier '%s', ignoring: %m", lvalue
, rvalue
);
1289 if (sum
== 0 || *capability_set
== initial
)
1290 /* "", "~" or uninitialized data -> replace */
1291 *capability_set
= invert
? ~sum
: sum
;
1293 /* previous data -> merge */
1295 *capability_set
&= ~sum
;
1297 *capability_set
|= sum
;
1303 int config_parse_exec_selinux_context(
1305 const char *filename
,
1307 const char *section
,
1308 unsigned section_line
,
1315 ExecContext
*c
= data
;
1326 if (isempty(rvalue
)) {
1327 c
->selinux_context
= mfree(c
->selinux_context
);
1328 c
->selinux_context_ignore
= false;
1332 if (rvalue
[0] == '-') {
1338 r
= unit_full_printf(u
, rvalue
, &k
);
1340 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1341 "Failed to resolve unit specifiers in '%s'%s: %m",
1342 rvalue
, ignore
? ", ignoring" : "");
1343 return ignore
? 0 : -ENOEXEC
;
1346 free_and_replace(c
->selinux_context
, k
);
1347 c
->selinux_context_ignore
= ignore
;
1352 int config_parse_exec_apparmor_profile(
1354 const char *filename
,
1356 const char *section
,
1357 unsigned section_line
,
1364 ExecContext
*c
= data
;
1375 if (isempty(rvalue
)) {
1376 c
->apparmor_profile
= mfree(c
->apparmor_profile
);
1377 c
->apparmor_profile_ignore
= false;
1381 if (rvalue
[0] == '-') {
1387 r
= unit_full_printf(u
, rvalue
, &k
);
1389 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1390 "Failed to resolve unit specifiers in '%s'%s: %m",
1391 rvalue
, ignore
? ", ignoring" : "");
1392 return ignore
? 0 : -ENOEXEC
;
1395 free_and_replace(c
->apparmor_profile
, k
);
1396 c
->apparmor_profile_ignore
= ignore
;
1401 int config_parse_exec_smack_process_label(
1403 const char *filename
,
1405 const char *section
,
1406 unsigned section_line
,
1413 ExecContext
*c
= data
;
1424 if (isempty(rvalue
)) {
1425 c
->smack_process_label
= mfree(c
->smack_process_label
);
1426 c
->smack_process_label_ignore
= false;
1430 if (rvalue
[0] == '-') {
1436 r
= unit_full_printf(u
, rvalue
, &k
);
1438 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1439 "Failed to resolve unit specifiers in '%s'%s: %m",
1440 rvalue
, ignore
? ", ignoring" : "");
1441 return ignore
? 0 : -ENOEXEC
;
1444 free_and_replace(c
->smack_process_label
, k
);
1445 c
->smack_process_label_ignore
= ignore
;
1450 int config_parse_timer(const char *unit
,
1451 const char *filename
,
1453 const char *section
,
1454 unsigned section_line
,
1465 _cleanup_(calendar_spec_freep
) CalendarSpec
*c
= NULL
;
1467 _cleanup_free_
char *k
= NULL
;
1475 if (isempty(rvalue
)) {
1476 /* Empty assignment resets list */
1477 timer_free_values(t
);
1481 b
= timer_base_from_string(lvalue
);
1483 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse timer base, ignoring: %s", lvalue
);
1487 r
= unit_full_printf(u
, rvalue
, &k
);
1489 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
1493 if (b
== TIMER_CALENDAR
) {
1494 if (calendar_spec_from_string(k
, &c
) < 0) {
1495 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse calendar specification, ignoring: %s", k
);
1499 if (parse_sec(k
, &usec
) < 0) {
1500 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse timer value, ignoring: %s", k
);
1504 v
= new0(TimerValue
, 1);
1510 v
->calendar_spec
= TAKE_PTR(c
);
1512 LIST_PREPEND(value
, t
->values
, v
);
1517 int config_parse_trigger_unit(
1519 const char *filename
,
1521 const char *section
,
1522 unsigned section_line
,
1529 _cleanup_free_
char *p
= NULL
;
1539 if (!hashmap_isempty(u
->dependencies
[UNIT_TRIGGERS
])) {
1540 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Multiple units to trigger specified, ignoring: %s", rvalue
);
1544 r
= unit_name_printf(u
, rvalue
, &p
);
1546 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
1550 type
= unit_name_to_type(p
);
1552 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit type not valid, ignoring: %s", rvalue
);
1555 if (unit_has_name(u
, p
)) {
1556 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Units cannot trigger themselves, ignoring: %s", rvalue
);
1560 r
= unit_add_two_dependencies_by_name(u
, UNIT_BEFORE
, UNIT_TRIGGERS
, p
, NULL
, true, UNIT_DEPENDENCY_FILE
);
1562 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add trigger on %s, ignoring: %m", p
);
1569 int config_parse_path_spec(const char *unit
,
1570 const char *filename
,
1572 const char *section
,
1573 unsigned section_line
,
1583 _cleanup_free_
char *k
= NULL
;
1591 if (isempty(rvalue
)) {
1592 /* Empty assignment clears list */
1597 b
= path_type_from_string(lvalue
);
1599 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse path type, ignoring: %s", lvalue
);
1603 r
= unit_full_printf(UNIT(p
), rvalue
, &k
);
1605 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
1609 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
1613 s
= new0(PathSpec
, 1);
1618 s
->path
= TAKE_PTR(k
);
1622 LIST_PREPEND(spec
, p
->specs
, s
);
1627 int config_parse_socket_service(
1629 const char *filename
,
1631 const char *section
,
1632 unsigned section_line
,
1639 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1640 _cleanup_free_
char *p
= NULL
;
1650 r
= unit_name_printf(UNIT(s
), rvalue
, &p
);
1652 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", rvalue
);
1656 if (!endswith(p
, ".service")) {
1657 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit must be of type service: %s", rvalue
);
1661 r
= manager_load_unit(UNIT(s
)->manager
, p
, NULL
, &error
, &x
);
1663 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to load unit %s: %s", rvalue
, bus_error_message(&error
, r
));
1667 unit_ref_set(&s
->service
, UNIT(s
), x
);
1672 int config_parse_fdname(
1674 const char *filename
,
1676 const char *section
,
1677 unsigned section_line
,
1684 _cleanup_free_
char *p
= NULL
;
1693 if (isempty(rvalue
)) {
1694 s
->fdname
= mfree(s
->fdname
);
1698 r
= unit_full_printf(UNIT(s
), rvalue
, &p
);
1700 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
1704 if (!fdname_is_valid(p
)) {
1705 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", p
);
1709 return free_and_replace(s
->fdname
, p
);
1712 int config_parse_service_sockets(
1714 const char *filename
,
1716 const char *section
,
1717 unsigned section_line
,
1735 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
1737 r
= extract_first_word(&p
, &word
, NULL
, 0);
1743 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Trailing garbage in sockets, ignoring: %s", rvalue
);
1747 r
= unit_name_printf(UNIT(s
), word
, &k
);
1749 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
1753 if (!endswith(k
, ".socket")) {
1754 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit must be of type socket, ignoring: %s", k
);
1758 r
= unit_add_two_dependencies_by_name(UNIT(s
), UNIT_WANTS
, UNIT_AFTER
, k
, NULL
, true, UNIT_DEPENDENCY_FILE
);
1760 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
1762 r
= unit_add_dependency_by_name(UNIT(s
), UNIT_TRIGGERED_BY
, k
, NULL
, true, UNIT_DEPENDENCY_FILE
);
1764 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
1770 int config_parse_bus_name(
1772 const char *filename
,
1774 const char *section
,
1775 unsigned section_line
,
1782 _cleanup_free_
char *k
= NULL
;
1791 r
= unit_full_printf(u
, rvalue
, &k
);
1793 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
1797 if (!service_name_is_valid(k
)) {
1798 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid bus name, ignoring: %s", k
);
1802 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
1805 int config_parse_service_timeout(
1807 const char *filename
,
1809 const char *section
,
1810 unsigned section_line
,
1817 Service
*s
= userdata
;
1826 /* This is called for two cases: TimeoutSec= and TimeoutStartSec=. */
1828 /* Traditionally, these options accepted 0 to disable the timeouts. However, a timeout of 0 suggests it happens
1829 * immediately, hence fix this to become USEC_INFINITY instead. This is in-line with how we internally handle
1830 * all other timeouts. */
1831 r
= parse_sec_fix_0(rvalue
, &usec
);
1833 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
1837 s
->start_timeout_defined
= true;
1838 s
->timeout_start_usec
= usec
;
1840 if (streq(lvalue
, "TimeoutSec"))
1841 s
->timeout_stop_usec
= usec
;
1846 int config_parse_sec_fix_0(
1848 const char *filename
,
1850 const char *section
,
1851 unsigned section_line
,
1858 usec_t
*usec
= data
;
1866 /* This is pretty much like config_parse_sec(), except that this treats a time of 0 as infinity, for
1867 * compatibility with older versions of systemd where 0 instead of infinity was used as indicator to turn off a
1870 r
= parse_sec_fix_0(rvalue
, usec
);
1872 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
1879 int config_parse_user_group(
1881 const char *filename
,
1883 const char *section
,
1884 unsigned section_line
,
1891 _cleanup_free_
char *k
= NULL
;
1901 if (isempty(rvalue
)) {
1902 *user
= mfree(*user
);
1906 r
= unit_full_printf(u
, rvalue
, &k
);
1908 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", rvalue
);
1912 if (!valid_user_group_name_or_id(k
)) {
1913 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
1917 return free_and_replace(*user
, k
);
1920 int config_parse_user_group_strv(
1922 const char *filename
,
1924 const char *section
,
1925 unsigned section_line
,
1932 char ***users
= data
;
1934 const char *p
= rvalue
;
1942 if (isempty(rvalue
)) {
1943 *users
= strv_free(*users
);
1948 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
1950 r
= extract_first_word(&p
, &word
, NULL
, 0);
1956 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax: %s", rvalue
);
1960 r
= unit_full_printf(u
, word
, &k
);
1962 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", word
);
1966 if (!valid_user_group_name_or_id(k
)) {
1967 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
1971 r
= strv_push(users
, k
);
1981 int config_parse_working_directory(
1983 const char *filename
,
1985 const char *section
,
1986 unsigned section_line
,
1993 ExecContext
*c
= data
;
2004 if (isempty(rvalue
)) {
2005 c
->working_directory_home
= false;
2006 c
->working_directory
= mfree(c
->working_directory
);
2010 if (rvalue
[0] == '-') {
2016 if (streq(rvalue
, "~")) {
2017 c
->working_directory_home
= true;
2018 c
->working_directory
= mfree(c
->working_directory
);
2020 _cleanup_free_
char *k
= NULL
;
2022 r
= unit_full_printf(u
, rvalue
, &k
);
2024 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2025 "Failed to resolve unit specifiers in working directory path '%s'%s: %m",
2026 rvalue
, missing_ok
? ", ignoring" : "");
2027 return missing_ok
? 0 : -ENOEXEC
;
2030 r
= path_simplify_and_warn(k
, PATH_CHECK_ABSOLUTE
| (missing_ok
? 0 : PATH_CHECK_FATAL
), unit
, filename
, line
, lvalue
);
2032 return missing_ok
? 0 : -ENOEXEC
;
2034 c
->working_directory_home
= false;
2035 free_and_replace(c
->working_directory
, k
);
2038 c
->working_directory_missing_ok
= missing_ok
;
2042 int config_parse_unit_env_file(const char *unit
,
2043 const char *filename
,
2045 const char *section
,
2046 unsigned section_line
,
2055 _cleanup_free_
char *n
= NULL
;
2063 if (isempty(rvalue
)) {
2064 /* Empty assignment frees the list */
2065 *env
= strv_free(*env
);
2069 r
= unit_full_printf(u
, rvalue
, &n
);
2071 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2075 r
= path_simplify_and_warn(n
[0] == '-' ? n
+ 1 : n
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2079 r
= strv_push(env
, n
);
2088 int config_parse_environ(
2090 const char *filename
,
2092 const char *section
,
2093 unsigned section_line
,
2110 if (isempty(rvalue
)) {
2111 /* Empty assignment resets the list */
2112 *env
= strv_free(*env
);
2116 for (p
= rvalue
;; ) {
2117 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2119 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_QUOTES
);
2125 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2126 "Invalid syntax, ignoring: %s", rvalue
);
2131 r
= unit_full_printf(u
, word
, &k
);
2133 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2134 "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2140 if (!env_assignment_is_valid(k
)) {
2141 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2142 "Invalid environment assignment, ignoring: %s", k
);
2146 r
= strv_env_replace(env
, k
);
2154 int config_parse_pass_environ(
2156 const char *filename
,
2158 const char *section
,
2159 unsigned section_line
,
2166 _cleanup_strv_free_
char **n
= NULL
;
2167 size_t nlen
= 0, nbufsize
= 0;
2168 char*** passenv
= data
;
2169 const char *p
= rvalue
;
2178 if (isempty(rvalue
)) {
2179 /* Empty assignment resets the list */
2180 *passenv
= strv_free(*passenv
);
2185 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2187 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
2193 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2194 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2199 r
= unit_full_printf(u
, word
, &k
);
2201 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2202 "Failed to resolve specifiers in %s, ignoring: %m", word
);
2208 if (!env_name_is_valid(k
)) {
2209 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2210 "Invalid environment name for %s, ignoring: %s", lvalue
, k
);
2214 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
2217 n
[nlen
++] = TAKE_PTR(k
);
2222 r
= strv_extend_strv(passenv
, n
, true);
2230 int config_parse_unset_environ(
2232 const char *filename
,
2234 const char *section
,
2235 unsigned section_line
,
2242 _cleanup_strv_free_
char **n
= NULL
;
2243 size_t nlen
= 0, nbufsize
= 0;
2244 char*** unsetenv
= data
;
2245 const char *p
= rvalue
;
2254 if (isempty(rvalue
)) {
2255 /* Empty assignment resets the list */
2256 *unsetenv
= strv_free(*unsetenv
);
2261 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2263 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_QUOTES
);
2269 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2270 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2275 r
= unit_full_printf(u
, word
, &k
);
2277 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2278 "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2284 if (!env_assignment_is_valid(k
) && !env_name_is_valid(k
)) {
2285 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2286 "Invalid environment name or assignment %s, ignoring: %s", lvalue
, k
);
2290 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
2293 n
[nlen
++] = TAKE_PTR(k
);
2298 r
= strv_extend_strv(unsetenv
, n
, true);
2306 int config_parse_log_extra_fields(
2308 const char *filename
,
2310 const char *section
,
2311 unsigned section_line
,
2318 ExecContext
*c
= data
;
2320 const char *p
= rvalue
;
2328 if (isempty(rvalue
)) {
2329 exec_context_free_log_extra_fields(c
);
2334 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2338 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_QUOTES
);
2344 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
2348 r
= unit_full_printf(u
, word
, &k
);
2350 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2354 eq
= strchr(k
, '=');
2356 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Log field lacks '=' character, ignoring: %s", k
);
2360 if (!journal_field_valid(k
, eq
-k
, false)) {
2361 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Log field name is invalid, ignoring: %s", k
);
2365 t
= reallocarray(c
->log_extra_fields
, c
->n_log_extra_fields
+1, sizeof(struct iovec
));
2369 c
->log_extra_fields
= t
;
2370 c
->log_extra_fields
[c
->n_log_extra_fields
++] = IOVEC_MAKE_STRING(k
);
2376 int config_parse_unit_condition_path(
2378 const char *filename
,
2380 const char *section
,
2381 unsigned section_line
,
2388 _cleanup_free_
char *p
= NULL
;
2389 Condition
**list
= data
, *c
;
2390 ConditionType t
= ltype
;
2391 bool trigger
, negate
;
2400 if (isempty(rvalue
)) {
2401 /* Empty assignment resets the list */
2402 *list
= condition_free_list(*list
);
2406 trigger
= rvalue
[0] == '|';
2410 negate
= rvalue
[0] == '!';
2414 r
= unit_full_printf(u
, rvalue
, &p
);
2416 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2420 r
= path_simplify_and_warn(p
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2424 c
= condition_new(t
, p
, trigger
, negate
);
2428 LIST_PREPEND(conditions
, *list
, c
);
2432 int config_parse_unit_condition_string(
2434 const char *filename
,
2436 const char *section
,
2437 unsigned section_line
,
2444 _cleanup_free_
char *s
= NULL
;
2445 Condition
**list
= data
, *c
;
2446 ConditionType t
= ltype
;
2447 bool trigger
, negate
;
2456 if (isempty(rvalue
)) {
2457 /* Empty assignment resets the list */
2458 *list
= condition_free_list(*list
);
2462 trigger
= rvalue
[0] == '|';
2466 negate
= rvalue
[0] == '!';
2470 r
= unit_full_printf(u
, rvalue
, &s
);
2472 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2476 c
= condition_new(t
, s
, trigger
, negate
);
2480 LIST_PREPEND(conditions
, *list
, c
);
2484 int config_parse_unit_condition_null(
2486 const char *filename
,
2488 const char *section
,
2489 unsigned section_line
,
2496 Condition
**list
= data
, *c
;
2497 bool trigger
, negate
;
2505 if (isempty(rvalue
)) {
2506 /* Empty assignment resets the list */
2507 *list
= condition_free_list(*list
);
2511 trigger
= rvalue
[0] == '|';
2515 negate
= rvalue
[0] == '!';
2519 b
= parse_boolean(rvalue
);
2521 log_syntax(unit
, LOG_ERR
, filename
, line
, b
, "Failed to parse boolean value in condition, ignoring: %s", rvalue
);
2528 c
= condition_new(CONDITION_NULL
, NULL
, trigger
, negate
);
2532 LIST_PREPEND(conditions
, *list
, c
);
2536 int config_parse_unit_requires_mounts_for(
2538 const char *filename
,
2540 const char *section
,
2541 unsigned section_line
,
2548 const char *p
= rvalue
;
2558 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
2560 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
2566 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2567 "Invalid syntax, ignoring: %s", rvalue
);
2571 r
= unit_full_printf(u
, word
, &resolved
);
2573 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
2577 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
2581 r
= unit_require_mounts_for(u
, resolved
, UNIT_DEPENDENCY_FILE
);
2583 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add required mount '%s', ignoring: %m", resolved
);
2589 int config_parse_documentation(const char *unit
,
2590 const char *filename
,
2592 const char *section
,
2593 unsigned section_line
,
2609 if (isempty(rvalue
)) {
2610 /* Empty assignment resets the list */
2611 u
->documentation
= strv_free(u
->documentation
);
2615 r
= config_parse_unit_strv_printf(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
,
2616 rvalue
, data
, userdata
);
2620 for (a
= b
= u
->documentation
; a
&& *a
; a
++) {
2622 if (documentation_url_is_valid(*a
))
2625 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid URL, ignoring: %s", *a
);
2636 int config_parse_syscall_filter(
2638 const char *filename
,
2640 const char *section
,
2641 unsigned section_line
,
2648 ExecContext
*c
= data
;
2650 bool invert
= false;
2659 if (isempty(rvalue
)) {
2660 /* Empty assignment resets the list */
2661 c
->syscall_filter
= hashmap_free(c
->syscall_filter
);
2662 c
->syscall_whitelist
= false;
2666 if (rvalue
[0] == '~') {
2671 if (!c
->syscall_filter
) {
2672 c
->syscall_filter
= hashmap_new(NULL
);
2673 if (!c
->syscall_filter
)
2677 /* Allow everything but the ones listed */
2678 c
->syscall_whitelist
= false;
2680 /* Allow nothing but the ones listed */
2681 c
->syscall_whitelist
= true;
2683 /* Accept default syscalls if we are on a whitelist */
2684 r
= seccomp_parse_syscall_filter("@default", -1, c
->syscall_filter
, SECCOMP_PARSE_WHITELIST
);
2692 _cleanup_free_
char *word
= NULL
, *name
= NULL
;
2695 r
= extract_first_word(&p
, &word
, NULL
, 0);
2701 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
2705 r
= parse_syscall_and_errno(word
, &name
, &num
);
2707 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse syscall:errno, ignoring: %s", word
);
2711 r
= seccomp_parse_syscall_filter_full(name
, num
, c
->syscall_filter
,
2712 SECCOMP_PARSE_LOG
|SECCOMP_PARSE_PERMISSIVE
|(invert
? SECCOMP_PARSE_INVERT
: 0)|(c
->syscall_whitelist
? SECCOMP_PARSE_WHITELIST
: 0),
2713 unit
, filename
, line
);
2719 int config_parse_syscall_archs(
2721 const char *filename
,
2723 const char *section
,
2724 unsigned section_line
,
2731 const char *p
= rvalue
;
2735 if (isempty(rvalue
)) {
2736 *archs
= set_free(*archs
);
2740 r
= set_ensure_allocated(archs
, NULL
);
2745 _cleanup_free_
char *word
= NULL
;
2748 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
2754 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2755 "Invalid syntax, ignoring: %s", rvalue
);
2759 r
= seccomp_arch_from_string(word
, &a
);
2761 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2762 "Failed to parse system call architecture \"%s\", ignoring: %m", word
);
2766 r
= set_put(*archs
, UINT32_TO_PTR(a
+ 1));
2772 int config_parse_syscall_errno(
2774 const char *filename
,
2776 const char *section
,
2777 unsigned section_line
,
2784 ExecContext
*c
= data
;
2791 if (isempty(rvalue
)) {
2792 /* Empty assignment resets to KILL */
2793 c
->syscall_errno
= 0;
2797 e
= parse_errno(rvalue
);
2799 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse error number, ignoring: %s", rvalue
);
2803 c
->syscall_errno
= e
;
2807 int config_parse_address_families(
2809 const char *filename
,
2811 const char *section
,
2812 unsigned section_line
,
2819 ExecContext
*c
= data
;
2820 bool invert
= false;
2828 if (isempty(rvalue
)) {
2829 /* Empty assignment resets the list */
2830 c
->address_families
= set_free(c
->address_families
);
2831 c
->address_families_whitelist
= false;
2835 if (rvalue
[0] == '~') {
2840 if (!c
->address_families
) {
2841 c
->address_families
= set_new(NULL
);
2842 if (!c
->address_families
)
2845 c
->address_families_whitelist
= !invert
;
2848 for (p
= rvalue
;;) {
2849 _cleanup_free_
char *word
= NULL
;
2852 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
2858 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2859 "Invalid syntax, ignoring: %s", rvalue
);
2863 af
= af_from_name(word
);
2865 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2866 "Failed to parse address family, ignoring: %s", word
);
2870 /* If we previously wanted to forbid an address family and now
2871 * we want to allow it, then just remove it from the list.
2873 if (!invert
== c
->address_families_whitelist
) {
2874 r
= set_put(c
->address_families
, INT_TO_PTR(af
));
2878 set_remove(c
->address_families
, INT_TO_PTR(af
));
2882 int config_parse_restrict_namespaces(
2884 const char *filename
,
2886 const char *section
,
2887 unsigned section_line
,
2894 ExecContext
*c
= data
;
2895 unsigned long flags
;
2896 bool invert
= false;
2899 if (isempty(rvalue
)) {
2900 /* Reset to the default. */
2901 c
->restrict_namespaces
= NAMESPACE_FLAGS_INITIAL
;
2905 /* Boolean parameter ignores the previous settings */
2906 r
= parse_boolean(rvalue
);
2908 c
->restrict_namespaces
= 0;
2910 } else if (r
== 0) {
2911 c
->restrict_namespaces
= NAMESPACE_FLAGS_ALL
;
2915 if (rvalue
[0] == '~') {
2920 /* Not a boolean argument, in this case it's a list of namespace types. */
2921 r
= namespace_flags_from_string(rvalue
, &flags
);
2923 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse namespace type string, ignoring: %s", rvalue
);
2927 if (c
->restrict_namespaces
== NAMESPACE_FLAGS_INITIAL
)
2928 /* Initial assignment. Just set the value. */
2929 c
->restrict_namespaces
= invert
? (~flags
) & NAMESPACE_FLAGS_ALL
: flags
;
2931 /* Merge the value with the previous one. */
2932 SET_FLAG(c
->restrict_namespaces
, flags
, !invert
);
2938 int config_parse_unit_slice(
2940 const char *filename
,
2942 const char *section
,
2943 unsigned section_line
,
2950 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
2951 _cleanup_free_
char *k
= NULL
;
2952 Unit
*u
= userdata
, *slice
= NULL
;
2960 r
= unit_name_printf(u
, rvalue
, &k
);
2962 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2966 r
= manager_load_unit(u
->manager
, k
, NULL
, &error
, &slice
);
2968 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to load slice unit %s, ignoring: %s", k
, bus_error_message(&error
, r
));
2972 r
= unit_set_slice(u
, slice
);
2974 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to assign slice %s to unit %s, ignoring: %m", slice
->id
, u
->id
);
2981 int config_parse_cpu_quota(
2983 const char *filename
,
2985 const char *section
,
2986 unsigned section_line
,
2993 CGroupContext
*c
= data
;
3000 if (isempty(rvalue
)) {
3001 c
->cpu_quota_per_sec_usec
= USEC_INFINITY
;
3005 r
= parse_percent_unbounded(rvalue
);
3007 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid CPU quota '%s', ignoring.", rvalue
);
3011 c
->cpu_quota_per_sec_usec
= ((usec_t
) r
* USEC_PER_SEC
) / 100U;
3015 int config_parse_memory_limit(
3017 const char *filename
,
3019 const char *section
,
3020 unsigned section_line
,
3027 CGroupContext
*c
= data
;
3028 uint64_t bytes
= CGROUP_LIMIT_MAX
;
3031 if (!isempty(rvalue
) && !streq(rvalue
, "infinity")) {
3033 r
= parse_percent(rvalue
);
3035 r
= parse_size(rvalue
, 1024, &bytes
);
3037 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid memory limit '%s', ignoring: %m", rvalue
);
3041 bytes
= physical_memory_scale(r
, 100U);
3043 if (bytes
>= UINT64_MAX
||
3044 (bytes
<= 0 && !streq(lvalue
, "MemorySwapMax"))) {
3045 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Memory limit '%s' out of range, ignoring.", rvalue
);
3050 if (streq(lvalue
, "MemoryLow"))
3051 c
->memory_low
= bytes
;
3052 else if (streq(lvalue
, "MemoryHigh"))
3053 c
->memory_high
= bytes
;
3054 else if (streq(lvalue
, "MemoryMax"))
3055 c
->memory_max
= bytes
;
3056 else if (streq(lvalue
, "MemorySwapMax"))
3057 c
->memory_swap_max
= bytes
;
3058 else if (streq(lvalue
, "MemoryLimit"))
3059 c
->memory_limit
= bytes
;
3066 int config_parse_tasks_max(
3068 const char *filename
,
3070 const char *section
,
3071 unsigned section_line
,
3078 uint64_t *tasks_max
= data
, v
;
3082 if (isempty(rvalue
)) {
3083 *tasks_max
= u
->manager
->default_tasks_max
;
3087 if (streq(rvalue
, "infinity")) {
3088 *tasks_max
= CGROUP_LIMIT_MAX
;
3092 r
= parse_percent(rvalue
);
3094 r
= safe_atou64(rvalue
, &v
);
3096 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid maximum tasks value '%s', ignoring: %m", rvalue
);
3100 v
= system_tasks_max_scale(r
, 100U);
3102 if (v
<= 0 || v
>= UINT64_MAX
) {
3103 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Maximum tasks value '%s' out of range, ignoring.", rvalue
);
3111 int config_parse_delegate(
3113 const char *filename
,
3115 const char *section
,
3116 unsigned section_line
,
3123 CGroupContext
*c
= data
;
3127 t
= unit_name_to_type(unit
);
3128 assert(t
!= _UNIT_TYPE_INVALID
);
3130 if (!unit_vtable
[t
]->can_delegate
) {
3131 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Delegate= setting not supported for this unit type, ignoring.");
3135 /* We either accept a boolean value, which may be used to turn on delegation for all controllers, or turn it
3136 * off for all. Or it takes a list of controller names, in which case we add the specified controllers to the
3137 * mask to delegate. */
3139 if (isempty(rvalue
)) {
3140 /* An empty string resets controllers and set Delegate=yes. */
3142 c
->delegate_controllers
= 0;
3146 r
= parse_boolean(rvalue
);
3148 const char *p
= rvalue
;
3149 CGroupMask mask
= 0;
3152 _cleanup_free_
char *word
= NULL
;
3153 CGroupController cc
;
3155 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
3161 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3165 cc
= cgroup_controller_from_string(word
);
3167 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid controller name '%s', ignoring", word
);
3171 mask
|= CGROUP_CONTROLLER_TO_MASK(cc
);
3175 c
->delegate_controllers
|= mask
;
3179 c
->delegate_controllers
= _CGROUP_MASK_ALL
;
3181 c
->delegate
= false;
3182 c
->delegate_controllers
= 0;
3188 int config_parse_device_allow(
3190 const char *filename
,
3192 const char *section
,
3193 unsigned section_line
,
3200 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3201 CGroupContext
*c
= data
;
3202 CGroupDeviceAllow
*a
;
3203 const char *p
= rvalue
;
3206 if (isempty(rvalue
)) {
3207 while (c
->device_allow
)
3208 cgroup_context_free_device_allow(c
, c
->device_allow
);
3213 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_QUOTES
);
3217 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3218 "Invalid syntax, ignoring: %s", rvalue
);
3222 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3223 "Failed to extract device path and rights from '%s', ignoring.", rvalue
);
3227 r
= unit_full_printf(userdata
, path
, &resolved
);
3229 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3230 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3234 if (!startswith(resolved
, "block-") && !startswith(resolved
, "char-")) {
3236 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3240 if (!valid_device_node_path(resolved
)) {
3241 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device node path '%s', ignoring.", resolved
);
3246 if (!isempty(p
) && !in_charset(p
, "rwm")) {
3247 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device rights '%s', ignoring.", p
);
3251 a
= new0(CGroupDeviceAllow
, 1);
3255 a
->path
= TAKE_PTR(resolved
);
3256 a
->r
= isempty(p
) || !!strchr(p
, 'r');
3257 a
->w
= isempty(p
) || !!strchr(p
, 'w');
3258 a
->m
= isempty(p
) || !!strchr(p
, 'm');
3260 LIST_PREPEND(device_allow
, c
->device_allow
, a
);
3264 int config_parse_io_device_weight(
3266 const char *filename
,
3268 const char *section
,
3269 unsigned section_line
,
3276 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3277 CGroupIODeviceWeight
*w
;
3278 CGroupContext
*c
= data
;
3279 const char *p
= rvalue
;
3287 if (isempty(rvalue
)) {
3288 while (c
->io_device_weights
)
3289 cgroup_context_free_io_device_weight(c
, c
->io_device_weights
);
3294 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_QUOTES
);
3298 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3299 "Invalid syntax, ignoring: %s", rvalue
);
3302 if (r
== 0 || isempty(p
)) {
3303 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3304 "Failed to extract device path and weight from '%s', ignoring.", rvalue
);
3308 r
= unit_full_printf(userdata
, path
, &resolved
);
3310 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3311 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3315 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3319 r
= cg_weight_parse(p
, &u
);
3321 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "IO weight '%s' invalid, ignoring: %m", p
);
3325 assert(u
!= CGROUP_WEIGHT_INVALID
);
3327 w
= new0(CGroupIODeviceWeight
, 1);
3331 w
->path
= TAKE_PTR(resolved
);
3334 LIST_PREPEND(device_weights
, c
->io_device_weights
, w
);
3338 int config_parse_io_limit(
3340 const char *filename
,
3342 const char *section
,
3343 unsigned section_line
,
3350 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3351 CGroupIODeviceLimit
*l
= NULL
, *t
;
3352 CGroupContext
*c
= data
;
3353 CGroupIOLimitType type
;
3354 const char *p
= rvalue
;
3362 type
= cgroup_io_limit_type_from_string(lvalue
);
3365 if (isempty(rvalue
)) {
3366 LIST_FOREACH(device_limits
, l
, c
->io_device_limits
)
3367 l
->limits
[type
] = cgroup_io_limit_defaults
[type
];
3371 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_QUOTES
);
3375 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3376 "Invalid syntax, ignoring: %s", rvalue
);
3379 if (r
== 0 || isempty(p
)) {
3380 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3381 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
3385 r
= unit_full_printf(userdata
, path
, &resolved
);
3387 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3388 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3392 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3396 if (streq("infinity", p
))
3397 num
= CGROUP_LIMIT_MAX
;
3399 r
= parse_size(p
, 1000, &num
);
3400 if (r
< 0 || num
<= 0) {
3401 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid IO limit '%s', ignoring.", p
);
3406 LIST_FOREACH(device_limits
, t
, c
->io_device_limits
) {
3407 if (path_equal(resolved
, t
->path
)) {
3414 CGroupIOLimitType ttype
;
3416 l
= new0(CGroupIODeviceLimit
, 1);
3420 l
->path
= TAKE_PTR(resolved
);
3421 for (ttype
= 0; ttype
< _CGROUP_IO_LIMIT_TYPE_MAX
; ttype
++)
3422 l
->limits
[ttype
] = cgroup_io_limit_defaults
[ttype
];
3424 LIST_PREPEND(device_limits
, c
->io_device_limits
, l
);
3427 l
->limits
[type
] = num
;
3432 int config_parse_blockio_device_weight(
3434 const char *filename
,
3436 const char *section
,
3437 unsigned section_line
,
3444 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3445 CGroupBlockIODeviceWeight
*w
;
3446 CGroupContext
*c
= data
;
3447 const char *p
= rvalue
;
3455 if (isempty(rvalue
)) {
3456 while (c
->blockio_device_weights
)
3457 cgroup_context_free_blockio_device_weight(c
, c
->blockio_device_weights
);
3462 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_QUOTES
);
3466 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3467 "Invalid syntax, ignoring: %s", rvalue
);
3470 if (r
== 0 || isempty(p
)) {
3471 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3472 "Failed to extract device node and weight from '%s', ignoring.", rvalue
);
3476 r
= unit_full_printf(userdata
, path
, &resolved
);
3478 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3479 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3483 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3487 r
= cg_blkio_weight_parse(p
, &u
);
3489 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid block IO weight '%s', ignoring: %m", p
);
3493 assert(u
!= CGROUP_BLKIO_WEIGHT_INVALID
);
3495 w
= new0(CGroupBlockIODeviceWeight
, 1);
3499 w
->path
= TAKE_PTR(resolved
);
3502 LIST_PREPEND(device_weights
, c
->blockio_device_weights
, w
);
3506 int config_parse_blockio_bandwidth(
3508 const char *filename
,
3510 const char *section
,
3511 unsigned section_line
,
3518 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3519 CGroupBlockIODeviceBandwidth
*b
= NULL
, *t
;
3520 CGroupContext
*c
= data
;
3521 const char *p
= rvalue
;
3530 read
= streq("BlockIOReadBandwidth", lvalue
);
3532 if (isempty(rvalue
)) {
3533 LIST_FOREACH(device_bandwidths
, b
, c
->blockio_device_bandwidths
) {
3534 b
->rbps
= CGROUP_LIMIT_MAX
;
3535 b
->wbps
= CGROUP_LIMIT_MAX
;
3540 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_QUOTES
);
3544 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3545 "Invalid syntax, ignoring: %s", rvalue
);
3548 if (r
== 0 || isempty(p
)) {
3549 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3550 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
3554 r
= unit_full_printf(userdata
, path
, &resolved
);
3556 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3557 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3561 r
= path_simplify_and_warn(resolved
, 0, unit
, filename
, line
, lvalue
);
3565 r
= parse_size(p
, 1000, &bytes
);
3566 if (r
< 0 || bytes
<= 0) {
3567 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid Block IO Bandwidth '%s', ignoring.", p
);
3571 LIST_FOREACH(device_bandwidths
, t
, c
->blockio_device_bandwidths
) {
3572 if (path_equal(resolved
, t
->path
)) {
3579 b
= new0(CGroupBlockIODeviceBandwidth
, 1);
3583 b
->path
= TAKE_PTR(resolved
);
3584 b
->rbps
= CGROUP_LIMIT_MAX
;
3585 b
->wbps
= CGROUP_LIMIT_MAX
;
3587 LIST_PREPEND(device_bandwidths
, c
->blockio_device_bandwidths
, b
);
3598 int config_parse_job_mode_isolate(
3600 const char *filename
,
3602 const char *section
,
3603 unsigned section_line
,
3617 r
= parse_boolean(rvalue
);
3619 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse boolean, ignoring: %s", rvalue
);
3623 log_notice("%s is deprecated. Please use OnFailureJobMode= instead", lvalue
);
3625 *m
= r
? JOB_ISOLATE
: JOB_REPLACE
;
3629 int config_parse_exec_directories(
3631 const char *filename
,
3633 const char *section
,
3634 unsigned section_line
,
3651 if (isempty(rvalue
)) {
3652 /* Empty assignment resets the list */
3653 *rt
= strv_free(*rt
);
3657 for (p
= rvalue
;;) {
3658 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
3660 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
3664 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3665 "Invalid syntax, ignoring: %s", rvalue
);
3671 r
= unit_full_printf(u
, word
, &k
);
3673 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
3674 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
3678 r
= path_simplify_and_warn(k
, PATH_CHECK_RELATIVE
, unit
, filename
, line
, lvalue
);
3682 if (path_startswith(k
, "private")) {
3683 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
3684 "%s= path can't be 'private', ingoring assignment: %s", lvalue
, word
);
3688 r
= strv_push(rt
, k
);
3695 int config_parse_set_status(
3697 const char *filename
,
3699 const char *section
,
3700 unsigned section_line
,
3708 const char *word
, *state
;
3710 ExitStatusSet
*status_set
= data
;
3717 /* Empty assignment resets the list */
3718 if (isempty(rvalue
)) {
3719 exit_status_set_free(status_set
);
3723 FOREACH_WORD(word
, l
, rvalue
, state
) {
3724 _cleanup_free_
char *temp
;
3728 temp
= strndup(word
, l
);
3732 r
= safe_atoi(temp
, &val
);
3734 val
= signal_from_string(temp
);
3737 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse value, ignoring: %s", word
);
3740 set
= &status_set
->signal
;
3742 if (val
< 0 || val
> 255) {
3743 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Value %d is outside range 0-255, ignoring", val
);
3746 set
= &status_set
->status
;
3749 r
= set_ensure_allocated(set
, NULL
);
3753 r
= set_put(*set
, INT_TO_PTR(val
));
3757 if (!isempty(state
))
3758 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Trailing garbage, ignoring.");
3763 int config_parse_namespace_path_strv(
3765 const char *filename
,
3767 const char *section
,
3768 unsigned section_line
,
3777 const char *p
= rvalue
;
3785 if (isempty(rvalue
)) {
3786 /* Empty assignment resets the list */
3787 *sv
= strv_free(*sv
);
3792 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
, *joined
= NULL
;
3794 bool ignore_enoent
= false, shall_prefix
= false;
3796 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
3802 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
3807 if (startswith(w
, "-")) {
3808 ignore_enoent
= true;
3811 if (startswith(w
, "+")) {
3812 shall_prefix
= true;
3816 r
= unit_full_printf(u
, w
, &resolved
);
3818 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", w
);
3822 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
3826 joined
= strjoin(ignore_enoent
? "-" : "",
3827 shall_prefix
? "+" : "",
3830 r
= strv_push(sv
, joined
);
3840 int config_parse_temporary_filesystems(
3842 const char *filename
,
3844 const char *section
,
3845 unsigned section_line
,
3853 ExecContext
*c
= data
;
3854 const char *p
= rvalue
;
3862 if (isempty(rvalue
)) {
3863 /* Empty assignment resets the list */
3864 temporary_filesystem_free_many(c
->temporary_filesystems
, c
->n_temporary_filesystems
);
3865 c
->temporary_filesystems
= NULL
;
3866 c
->n_temporary_filesystems
= 0;
3871 _cleanup_free_
char *word
= NULL
, *path
= NULL
, *resolved
= NULL
;
3874 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
3880 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
3885 r
= extract_first_word(&w
, &path
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
3889 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", word
);
3893 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid syntax, ignoring: %s", word
);
3897 r
= unit_full_printf(u
, path
, &resolved
);
3899 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", path
);
3903 r
= path_simplify_and_warn(resolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
3907 r
= temporary_filesystem_add(&c
->temporary_filesystems
, &c
->n_temporary_filesystems
, path
, w
);
3911 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse mount options, ignoring: %s", word
);
3917 int config_parse_bind_paths(
3919 const char *filename
,
3921 const char *section
,
3922 unsigned section_line
,
3929 ExecContext
*c
= data
;
3939 if (isempty(rvalue
)) {
3940 /* Empty assignment resets the list */
3941 bind_mount_free_many(c
->bind_mounts
, c
->n_bind_mounts
);
3942 c
->bind_mounts
= NULL
;
3943 c
->n_bind_mounts
= 0;
3949 _cleanup_free_
char *source
= NULL
, *destination
= NULL
;
3950 _cleanup_free_
char *sresolved
= NULL
, *dresolved
= NULL
;
3951 char *s
= NULL
, *d
= NULL
;
3952 bool rbind
= true, ignore_enoent
= false;
3954 r
= extract_first_word(&p
, &source
, ":" WHITESPACE
, EXTRACT_QUOTES
|EXTRACT_DONT_COALESCE_SEPARATORS
);
3960 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
3964 r
= unit_full_printf(u
, source
, &sresolved
);
3966 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
3967 "Failed to resolved unit specifiers in \"%s\", ignoring: %m", source
);
3973 ignore_enoent
= true;
3977 r
= path_simplify_and_warn(s
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
3981 /* Optionally, the destination is specified. */
3982 if (p
&& p
[-1] == ':') {
3983 r
= extract_first_word(&p
, &destination
, ":" WHITESPACE
, EXTRACT_QUOTES
|EXTRACT_DONT_COALESCE_SEPARATORS
);
3987 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s, ignoring: %s", lvalue
, rvalue
);
3991 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Missing argument after ':', ignoring: %s", s
);
3995 r
= unit_full_printf(u
, destination
, &dresolved
);
3997 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
3998 "Failed to resolved specifiers in \"%s\", ignoring: %m", destination
);
4002 r
= path_simplify_and_warn(dresolved
, PATH_CHECK_ABSOLUTE
, unit
, filename
, line
, lvalue
);
4008 /* Optionally, there's also a short option string specified */
4009 if (p
&& p
[-1] == ':') {
4010 _cleanup_free_
char *options
= NULL
;
4012 r
= extract_first_word(&p
, &options
, NULL
, EXTRACT_QUOTES
);
4016 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s: %s", lvalue
, rvalue
);
4020 if (isempty(options
) || streq(options
, "rbind"))
4022 else if (streq(options
, "norbind"))
4025 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid option string, ignoring setting: %s", options
);
4032 r
= bind_mount_add(&c
->bind_mounts
, &c
->n_bind_mounts
,
4036 .read_only
= !!strstr(lvalue
, "ReadOnly"),
4038 .ignore_enoent
= ignore_enoent
,
4047 int config_parse_job_timeout_sec(
4049 const char *filename
,
4051 const char *section
,
4052 unsigned section_line
,
4068 r
= parse_sec_fix_0(rvalue
, &usec
);
4070 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse JobTimeoutSec= parameter, ignoring: %s", rvalue
);
4074 /* If the user explicitly changed JobTimeoutSec= also change JobRunningTimeoutSec=, for compatibility with old
4075 * versions. If JobRunningTimeoutSec= was explicitly set, avoid this however as whatever the user picked should
4078 if (!u
->job_running_timeout_set
)
4079 u
->job_running_timeout
= usec
;
4081 u
->job_timeout
= usec
;
4086 int config_parse_job_running_timeout_sec(
4088 const char *filename
,
4090 const char *section
,
4091 unsigned section_line
,
4107 r
= parse_sec_fix_0(rvalue
, &usec
);
4109 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse JobRunningTimeoutSec= parameter, ignoring: %s", rvalue
);
4113 u
->job_running_timeout
= usec
;
4114 u
->job_running_timeout_set
= true;
4119 #define FOLLOW_MAX 8
4121 static int open_follow(char **filename
, FILE **_f
, Set
*names
, char **_final
) {
4132 /* This will update the filename pointer if the loaded file is
4133 * reached by a symlink. The old string will be freed. */
4136 char *target
, *name
;
4138 if (c
++ >= FOLLOW_MAX
)
4141 path_simplify(*filename
, false);
4143 /* Add the file name we are currently looking at to
4144 * the names of this unit, but only if it is a valid
4146 name
= basename(*filename
);
4147 if (unit_name_is_valid(name
, UNIT_NAME_ANY
)) {
4149 id
= set_get(names
, name
);
4155 r
= set_consume(names
, id
);
4161 /* Try to open the file name, but don't if its a symlink */
4162 fd
= open(*filename
, O_RDONLY
|O_CLOEXEC
|O_NOCTTY
|O_NOFOLLOW
);
4169 /* Hmm, so this is a symlink. Let's read the name, and follow it manually */
4170 r
= readlink_and_make_absolute(*filename
, &target
);
4174 free_and_replace(*filename
, target
);
4177 f
= fdopen(fd
, "re");
4189 static int merge_by_names(Unit
**u
, Set
*names
, const char *id
) {
4197 /* Let's try to add in all symlink names we found */
4198 while ((k
= set_steal_first(names
))) {
4200 /* First try to merge in the other name into our
4202 r
= unit_merge_by_name(*u
, k
);
4206 /* Hmm, we couldn't merge the other unit into
4207 * ours? Then let's try it the other way
4210 /* If the symlink name we are looking at is unit template, then
4211 we must search for instance of this template */
4212 if (unit_name_is_valid(k
, UNIT_NAME_TEMPLATE
) && (*u
)->instance
) {
4213 _cleanup_free_
char *instance
= NULL
;
4215 r
= unit_name_replace_instance(k
, (*u
)->instance
, &instance
);
4219 other
= manager_get_unit((*u
)->manager
, instance
);
4221 other
= manager_get_unit((*u
)->manager
, k
);
4226 r
= unit_merge(other
, *u
);
4229 return merge_by_names(u
, names
, NULL
);
4237 unit_choose_id(*u
, id
);
4245 static int load_from_path(Unit
*u
, const char *path
) {
4246 _cleanup_set_free_free_ Set
*symlink_names
= NULL
;
4247 _cleanup_fclose_
FILE *f
= NULL
;
4248 _cleanup_free_
char *filename
= NULL
;
4257 symlink_names
= set_new(&string_hash_ops
);
4261 if (path_is_absolute(path
)) {
4263 filename
= strdup(path
);
4267 r
= open_follow(&filename
, &f
, symlink_names
, &id
);
4269 filename
= mfree(filename
);
4277 STRV_FOREACH(p
, u
->manager
->lookup_paths
.search_path
) {
4279 /* Instead of opening the path right away, we manually
4280 * follow all symlinks and add their name to our unit
4281 * name set while doing so */
4282 filename
= path_make_absolute(path
, *p
);
4286 if (u
->manager
->unit_path_cache
&&
4287 !set_get(u
->manager
->unit_path_cache
, filename
))
4290 r
= open_follow(&filename
, &f
, symlink_names
, &id
);
4293 filename
= mfree(filename
);
4295 /* ENOENT means that the file is missing or is a dangling symlink.
4296 * ENOTDIR means that one of paths we expect to be is a directory
4297 * is not a directory, we should just ignore that.
4298 * EACCES means that the directory or file permissions are wrong.
4301 log_debug_errno(r
, "Cannot access \"%s\": %m", filename
);
4302 else if (!IN_SET(r
, -ENOENT
, -ENOTDIR
))
4305 /* Empty the symlink names for the next run */
4306 set_clear_free(symlink_names
);
4311 /* Hmm, no suitable file found? */
4314 if (!unit_type_may_alias(u
->type
) && set_size(symlink_names
) > 1) {
4315 log_unit_warning(u
, "Unit type of %s does not support alias names, refusing loading via symlink.", u
->id
);
4320 r
= merge_by_names(&merged
, symlink_names
, id
);
4325 u
->load_state
= UNIT_MERGED
;
4329 if (fstat(fileno(f
), &st
) < 0)
4332 if (null_or_empty(&st
)) {
4333 u
->load_state
= UNIT_MASKED
;
4334 u
->fragment_mtime
= 0;
4336 u
->load_state
= UNIT_LOADED
;
4337 u
->fragment_mtime
= timespec_load(&st
.st_mtim
);
4339 /* Now, parse the file contents */
4340 r
= config_parse(u
->id
, filename
, f
,
4341 UNIT_VTABLE(u
)->sections
,
4342 config_item_perf_lookup
, load_fragment_gperf_lookup
,
4343 CONFIG_PARSE_ALLOW_INCLUDE
, u
);
4348 free_and_replace(u
->fragment_path
, filename
);
4350 if (u
->source_path
) {
4351 if (stat(u
->source_path
, &st
) >= 0)
4352 u
->source_mtime
= timespec_load(&st
.st_mtim
);
4354 u
->source_mtime
= 0;
4360 int unit_load_fragment(Unit
*u
) {
4366 assert(u
->load_state
== UNIT_STUB
);
4370 u
->load_state
= UNIT_LOADED
;
4374 /* First, try to find the unit under its id. We always look
4375 * for unit files in the default directories, to make it easy
4376 * to override things by placing things in /etc/systemd/system */
4377 r
= load_from_path(u
, u
->id
);
4381 /* Try to find an alias we can load this with */
4382 if (u
->load_state
== UNIT_STUB
) {
4383 SET_FOREACH(t
, u
->names
, i
) {
4388 r
= load_from_path(u
, t
);
4392 if (u
->load_state
!= UNIT_STUB
)
4397 /* And now, try looking for it under the suggested (originally linked) path */
4398 if (u
->load_state
== UNIT_STUB
&& u
->fragment_path
) {
4400 r
= load_from_path(u
, u
->fragment_path
);
4404 if (u
->load_state
== UNIT_STUB
)
4405 /* Hmm, this didn't work? Then let's get rid
4406 * of the fragment path stored for us, so that
4407 * we don't point to an invalid location. */
4408 u
->fragment_path
= mfree(u
->fragment_path
);
4411 /* Look for a template */
4412 if (u
->load_state
== UNIT_STUB
&& u
->instance
) {
4413 _cleanup_free_
char *k
= NULL
;
4415 r
= unit_name_template(u
->id
, &k
);
4419 r
= load_from_path(u
, k
);
4422 log_unit_notice(u
, "Unit configuration has fatal error, unit will not be started.");
4426 if (u
->load_state
== UNIT_STUB
) {
4427 SET_FOREACH(t
, u
->names
, i
) {
4428 _cleanup_free_
char *z
= NULL
;
4433 r
= unit_name_template(t
, &z
);
4437 r
= load_from_path(u
, z
);
4441 if (u
->load_state
!= UNIT_STUB
)
4450 void unit_dump_config_items(FILE *f
) {
4451 static const struct {
4452 const ConfigParserCallback callback
;
4455 { config_parse_warn_compat
, "NOTSUPPORTED" },
4456 { config_parse_int
, "INTEGER" },
4457 { config_parse_unsigned
, "UNSIGNED" },
4458 { config_parse_iec_size
, "SIZE" },
4459 { config_parse_iec_uint64
, "SIZE" },
4460 { config_parse_si_size
, "SIZE" },
4461 { config_parse_bool
, "BOOLEAN" },
4462 { config_parse_string
, "STRING" },
4463 { config_parse_path
, "PATH" },
4464 { config_parse_unit_path_printf
, "PATH" },
4465 { config_parse_strv
, "STRING [...]" },
4466 { config_parse_exec_nice
, "NICE" },
4467 { config_parse_exec_oom_score_adjust
, "OOMSCOREADJUST" },
4468 { config_parse_exec_io_class
, "IOCLASS" },
4469 { config_parse_exec_io_priority
, "IOPRIORITY" },
4470 { config_parse_exec_cpu_sched_policy
, "CPUSCHEDPOLICY" },
4471 { config_parse_exec_cpu_sched_prio
, "CPUSCHEDPRIO" },
4472 { config_parse_exec_cpu_affinity
, "CPUAFFINITY" },
4473 { config_parse_mode
, "MODE" },
4474 { config_parse_unit_env_file
, "FILE" },
4475 { config_parse_exec_output
, "OUTPUT" },
4476 { config_parse_exec_input
, "INPUT" },
4477 { config_parse_log_facility
, "FACILITY" },
4478 { config_parse_log_level
, "LEVEL" },
4479 { config_parse_exec_secure_bits
, "SECUREBITS" },
4480 { config_parse_capability_set
, "BOUNDINGSET" },
4481 { config_parse_rlimit
, "LIMIT" },
4482 { config_parse_unit_deps
, "UNIT [...]" },
4483 { config_parse_exec
, "PATH [ARGUMENT [...]]" },
4484 { config_parse_service_type
, "SERVICETYPE" },
4485 { config_parse_service_restart
, "SERVICERESTART" },
4486 { config_parse_kill_mode
, "KILLMODE" },
4487 { config_parse_signal
, "SIGNAL" },
4488 { config_parse_socket_listen
, "SOCKET [...]" },
4489 { config_parse_socket_bind
, "SOCKETBIND" },
4490 { config_parse_socket_bindtodevice
, "NETWORKINTERFACE" },
4491 { config_parse_sec
, "SECONDS" },
4492 { config_parse_nsec
, "NANOSECONDS" },
4493 { config_parse_namespace_path_strv
, "PATH [...]" },
4494 { config_parse_bind_paths
, "PATH[:PATH[:OPTIONS]] [...]" },
4495 { config_parse_unit_requires_mounts_for
, "PATH [...]" },
4496 { config_parse_exec_mount_flags
, "MOUNTFLAG [...]" },
4497 { config_parse_unit_string_printf
, "STRING" },
4498 { config_parse_trigger_unit
, "UNIT" },
4499 { config_parse_timer
, "TIMER" },
4500 { config_parse_path_spec
, "PATH" },
4501 { config_parse_notify_access
, "ACCESS" },
4502 { config_parse_ip_tos
, "TOS" },
4503 { config_parse_unit_condition_path
, "CONDITION" },
4504 { config_parse_unit_condition_string
, "CONDITION" },
4505 { config_parse_unit_condition_null
, "CONDITION" },
4506 { config_parse_unit_slice
, "SLICE" },
4507 { config_parse_documentation
, "URL" },
4508 { config_parse_service_timeout
, "SECONDS" },
4509 { config_parse_emergency_action
, "ACTION" },
4510 { config_parse_set_status
, "STATUS" },
4511 { config_parse_service_sockets
, "SOCKETS" },
4512 { config_parse_environ
, "ENVIRON" },
4514 { config_parse_syscall_filter
, "SYSCALLS" },
4515 { config_parse_syscall_archs
, "ARCHS" },
4516 { config_parse_syscall_errno
, "ERRNO" },
4517 { config_parse_address_families
, "FAMILIES" },
4518 { config_parse_restrict_namespaces
, "NAMESPACES" },
4520 { config_parse_cpu_shares
, "SHARES" },
4521 { config_parse_cg_weight
, "WEIGHT" },
4522 { config_parse_memory_limit
, "LIMIT" },
4523 { config_parse_device_allow
, "DEVICE" },
4524 { config_parse_device_policy
, "POLICY" },
4525 { config_parse_io_limit
, "LIMIT" },
4526 { config_parse_io_device_weight
, "DEVICEWEIGHT" },
4527 { config_parse_blockio_bandwidth
, "BANDWIDTH" },
4528 { config_parse_blockio_weight
, "WEIGHT" },
4529 { config_parse_blockio_device_weight
, "DEVICEWEIGHT" },
4530 { config_parse_long
, "LONG" },
4531 { config_parse_socket_service
, "SERVICE" },
4533 { config_parse_exec_selinux_context
, "LABEL" },
4535 { config_parse_job_mode
, "MODE" },
4536 { config_parse_job_mode_isolate
, "BOOLEAN" },
4537 { config_parse_personality
, "PERSONALITY" },
4540 const char *prev
= NULL
;
4545 NULSTR_FOREACH(i
, load_fragment_gperf_nulstr
) {
4546 const char *rvalue
= "OTHER", *lvalue
;
4547 const ConfigPerfItem
*p
;
4552 assert_se(p
= load_fragment_gperf_lookup(i
, strlen(i
)));
4554 /* Hide legacy settings */
4555 if (p
->parse
== config_parse_warn_compat
&&
4556 p
->ltype
== DISABLED_LEGACY
)
4559 for (j
= 0; j
< ELEMENTSOF(table
); j
++)
4560 if (p
->parse
== table
[j
].callback
) {
4561 rvalue
= table
[j
].rvalue
;
4565 dot
= strchr(i
, '.');
4566 lvalue
= dot
? dot
+ 1 : i
;
4570 if (!prev
|| !strneq(prev
, i
, prefix_len
+1)) {
4574 fprintf(f
, "[%.*s]\n", (int) prefix_len
, i
);
4577 fprintf(f
, "%s=%s\n", lvalue
, rvalue
);