1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 This file is part of systemd.
5 Copyright 2010 Lennart Poettering
6 Copyright 2012 Holger Hans Peter Freyther
12 #include <linux/oom.h>
18 #include <sys/resource.h>
22 #include "alloc-util.h"
23 #include "all-units.h"
24 #include "bus-error.h"
25 #include "bus-internal.h"
28 #include "capability-util.h"
30 #include "conf-parser.h"
31 #include "cpu-set-util.h"
33 #include "errno-list.h"
37 #include "hexdecoct.h"
40 #include "journal-util.h"
41 #include "load-fragment.h"
44 #include "mount-util.h"
45 #include "parse-util.h"
46 #include "path-util.h"
47 #include "process-util.h"
49 #include "seccomp-util.h"
51 #include "securebits.h"
52 #include "securebits-util.h"
53 #include "signal-util.h"
54 #include "socket-protocol-list.h"
55 #include "stat-util.h"
56 #include "string-util.h"
58 #include "unit-name.h"
59 #include "unit-printf.h"
60 #include "user-util.h"
64 static int supported_socket_protocol_from_string(const char *s
) {
70 r
= socket_protocol_from_name(s
);
73 if (!IN_SET(r
, IPPROTO_UDPLITE
, IPPROTO_SCTP
))
74 return -EPROTONOSUPPORT
;
79 DEFINE_CONFIG_PARSE(config_parse_socket_protocol
, supported_socket_protocol_from_string
, "Failed to parse socket protocol");
80 DEFINE_CONFIG_PARSE(config_parse_exec_secure_bits
, secure_bits_from_string
, "Failed to parse secure bits");
81 DEFINE_CONFIG_PARSE_ENUM(config_parse_collect_mode
, collect_mode
, CollectMode
, "Failed to parse garbage collection mode");
82 DEFINE_CONFIG_PARSE_ENUM(config_parse_device_policy
, cgroup_device_policy
, CGroupDevicePolicy
, "Failed to parse device policy");
83 DEFINE_CONFIG_PARSE_ENUM(config_parse_emergency_action
, emergency_action
, EmergencyAction
, "Failed to parse failure action specifier");
84 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_keyring_mode
, exec_keyring_mode
, ExecKeyringMode
, "Failed to parse keyring mode");
85 DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_utmp_mode
, exec_utmp_mode
, ExecUtmpMode
, "Failed to parse utmp mode");
86 DEFINE_CONFIG_PARSE_ENUM(config_parse_job_mode
, job_mode
, JobMode
, "Failed to parse job mode");
87 DEFINE_CONFIG_PARSE_ENUM(config_parse_kill_mode
, kill_mode
, KillMode
, "Failed to parse kill mode");
88 DEFINE_CONFIG_PARSE_ENUM(config_parse_notify_access
, notify_access
, NotifyAccess
, "Failed to parse notify access specifier");
89 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_home
, protect_home_or_bool
, ProtectHome
, "Failed to parse protect home value");
90 DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_system
, protect_system_or_bool
, ProtectSystem
, "Failed to parse protect system value");
91 DEFINE_CONFIG_PARSE_ENUM(config_parse_runtime_preserve_mode
, exec_preserve_mode
, ExecPreserveMode
, "Failed to parse runtime directory preserve mode");
92 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_type
, service_type
, ServiceType
, "Failed to parse service type");
93 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart
, service_restart
, ServiceRestart
, "Failed to parse service restart specifier");
94 DEFINE_CONFIG_PARSE_ENUM(config_parse_socket_bind
, socket_address_bind_ipv6_only_or_bool
, SocketAddressBindIPv6Only
, "Failed to parse bind IPv6 only value");
95 DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_ip_tos
, ip_tos
, int, -1, "Failed to parse IP TOS value");
96 DEFINE_CONFIG_PARSE_PTR(config_parse_blockio_weight
, cg_blkio_weight_parse
, uint64_t, "Invalid block IO weight");
97 DEFINE_CONFIG_PARSE_PTR(config_parse_cg_weight
, cg_weight_parse
, uint64_t, "Invalid weight");
98 DEFINE_CONFIG_PARSE_PTR(config_parse_cpu_shares
, cg_cpu_shares_parse
, uint64_t, "Invalid CPU shares");
99 DEFINE_CONFIG_PARSE_PTR(config_parse_exec_mount_flags
, mount_propagation_flags_from_string
, unsigned long, "Failed to parse mount flag");
101 int config_parse_unit_deps(
103 const char *filename
,
106 unsigned section_line
,
113 UnitDependency d
= ltype
;
123 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
126 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_RETAIN_ESCAPE
);
132 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
136 r
= unit_name_printf(u
, word
, &k
);
138 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
142 r
= unit_add_dependency_by_name(u
, d
, k
, NULL
, true, UNIT_DEPENDENCY_FILE
);
144 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
150 int config_parse_obsolete_unit_deps(
152 const char *filename
,
155 unsigned section_line
,
162 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
163 "Unit dependency type %s= is obsolete, replacing by %s=, please update your unit file", lvalue
, unit_dependency_to_string(ltype
));
165 return config_parse_unit_deps(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, data
, userdata
);
168 int config_parse_unit_string_printf(
170 const char *filename
,
173 unsigned section_line
,
180 _cleanup_free_
char *k
= NULL
;
189 r
= unit_full_printf(u
, rvalue
, &k
);
191 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
195 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
198 int config_parse_unit_strv_printf(
200 const char *filename
,
203 unsigned section_line
,
211 _cleanup_free_
char *k
= NULL
;
219 r
= unit_full_printf(u
, rvalue
, &k
);
221 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
225 return config_parse_strv(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
228 int config_parse_unit_path_printf(
230 const char *filename
,
233 unsigned section_line
,
240 _cleanup_free_
char *k
= NULL
;
250 /* Let's not bother with anything that is too long */
251 if (strlen(rvalue
) >= PATH_MAX
) {
252 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
253 "%s value too long%s.",
254 lvalue
, fatal
? "" : ", ignoring");
255 return fatal
? -ENAMETOOLONG
: 0;
258 r
= unit_full_printf(u
, rvalue
, &k
);
260 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
261 "Failed to resolve unit specifiers in '%s'%s: %m",
262 rvalue
, fatal
? "" : ", ignoring");
263 return fatal
? -ENOEXEC
: 0;
266 return config_parse_path(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
269 int config_parse_unit_path_strv_printf(
271 const char *filename
,
274 unsigned section_line
,
291 if (isempty(rvalue
)) {
297 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
299 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
305 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
306 "Invalid syntax, ignoring: %s", rvalue
);
310 r
= unit_full_printf(u
, word
, &k
);
312 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
313 "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
317 if (!utf8_is_valid(k
)) {
318 log_syntax_invalid_utf8(unit
, LOG_ERR
, filename
, line
, rvalue
);
322 if (!path_is_absolute(k
)) {
323 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
324 "Symlink path is not absolute: %s", k
);
328 path_simplify(k
, false);
337 int config_parse_socket_listen(const char *unit
,
338 const char *filename
,
341 unsigned section_line
,
348 _cleanup_free_ SocketPort
*p
= NULL
;
360 if (isempty(rvalue
)) {
361 /* An empty assignment removes all ports */
362 socket_free_ports(s
);
366 p
= new0(SocketPort
, 1);
370 if (ltype
!= SOCKET_SOCKET
) {
373 r
= unit_full_printf(UNIT(s
), rvalue
, &p
->path
);
375 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
379 path_simplify(p
->path
, false);
381 } else if (streq(lvalue
, "ListenNetlink")) {
382 _cleanup_free_
char *k
= NULL
;
384 p
->type
= SOCKET_SOCKET
;
385 r
= unit_full_printf(UNIT(s
), rvalue
, &k
);
387 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
391 r
= socket_address_parse_netlink(&p
->address
, k
);
393 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse address value in '%s', ignoring: %m", k
);
398 _cleanup_free_
char *k
= NULL
;
400 p
->type
= SOCKET_SOCKET
;
401 r
= unit_full_printf(UNIT(s
), rvalue
, &k
);
403 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
407 r
= socket_address_parse_and_warn(&p
->address
, k
);
409 if (r
!= -EAFNOSUPPORT
)
410 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse address value in '%s', ignoring: %m", k
);
414 if (streq(lvalue
, "ListenStream"))
415 p
->address
.type
= SOCK_STREAM
;
416 else if (streq(lvalue
, "ListenDatagram"))
417 p
->address
.type
= SOCK_DGRAM
;
419 assert(streq(lvalue
, "ListenSequentialPacket"));
420 p
->address
.type
= SOCK_SEQPACKET
;
423 if (socket_address_family(&p
->address
) != AF_LOCAL
&& p
->address
.type
== SOCK_SEQPACKET
) {
424 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Address family not supported, ignoring: %s", rvalue
);
430 p
->auxiliary_fds
= NULL
;
431 p
->n_auxiliary_fds
= 0;
434 LIST_FIND_TAIL(port
, s
->ports
, tail
);
435 LIST_INSERT_AFTER(port
, s
->ports
, tail
, p
);
442 int config_parse_exec_nice(
444 const char *filename
,
447 unsigned section_line
,
454 ExecContext
*c
= data
;
462 if (isempty(rvalue
)) {
467 r
= parse_nice(rvalue
, &priority
);
470 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Nice priority out of range, ignoring: %s", rvalue
);
472 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse nice priority '%s', ignoring: %m", rvalue
);
482 int config_parse_exec_oom_score_adjust(
484 const char *filename
,
487 unsigned section_line
,
494 ExecContext
*c
= data
;
502 if (isempty(rvalue
)) {
503 c
->oom_score_adjust_set
= false;
507 r
= parse_oom_score_adjust(rvalue
, &oa
);
510 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "OOM score adjust value out of range, ignoring: %s", rvalue
);
512 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse the OOM score adjust value '%s', ignoring: %m", rvalue
);
516 c
->oom_score_adjust
= oa
;
517 c
->oom_score_adjust_set
= true;
522 int config_parse_exec(
524 const char *filename
,
527 unsigned section_line
,
534 ExecCommand
**e
= data
;
546 rvalue
+= strspn(rvalue
, WHITESPACE
);
548 if (isempty(rvalue
)) {
549 /* An empty assignment resets the list */
550 *e
= exec_command_free_list(*e
);
556 _cleanup_free_
char *path
= NULL
, *firstword
= NULL
;
557 ExecCommandFlags flags
= 0;
558 bool ignore
= false, separate_argv0
= false;
559 _cleanup_free_ ExecCommand
*nce
= NULL
;
560 _cleanup_strv_free_
char **n
= NULL
;
561 size_t nlen
= 0, nbufsize
= 0;
566 r
= extract_first_word_and_warn(&p
, &firstword
, NULL
, EXTRACT_QUOTES
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
572 /* We accept an absolute path as first argument. If it's prefixed with - and the path doesn't
573 * exist, we ignore it instead of erroring out; if it's prefixed with @, we allow overriding of
574 * argv[0]; if it's prefixed with +, it will be run with full privileges and no sandboxing; if
575 * it's prefixed with '!' we apply sandboxing, but do not change user/group credentials; if
576 * it's prefixed with '!!', then we apply user/group credentials if the kernel supports ambient
577 * capabilities -- if it doesn't we don't apply the credentials themselves, but do apply most
578 * other sandboxing, with some special exceptions for changing UID.
580 * The idea is that '!!' may be used to write services that can take benefit of systemd's
581 * UID/GID dropping if the kernel supports ambient creds, but provide an automatic fallback to
582 * privilege dropping within the daemon if the kernel does not offer that. */
584 if (*f
== '-' && !(flags
& EXEC_COMMAND_IGNORE_FAILURE
)) {
585 flags
|= EXEC_COMMAND_IGNORE_FAILURE
;
587 } else if (*f
== '@' && !separate_argv0
)
588 separate_argv0
= true;
589 else if (*f
== '+' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
590 flags
|= EXEC_COMMAND_FULLY_PRIVILEGED
;
591 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_NO_SETUID
|EXEC_COMMAND_AMBIENT_MAGIC
)))
592 flags
|= EXEC_COMMAND_NO_SETUID
;
593 else if (*f
== '!' && !(flags
& (EXEC_COMMAND_FULLY_PRIVILEGED
|EXEC_COMMAND_AMBIENT_MAGIC
))) {
594 flags
&= ~EXEC_COMMAND_NO_SETUID
;
595 flags
|= EXEC_COMMAND_AMBIENT_MAGIC
;
601 r
= unit_full_printf(u
, f
, &path
);
603 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
604 "Failed to resolve unit specifiers in '%s'%s: %m",
605 f
, ignore
? ", ignoring" : "");
606 return ignore
? 0 : -ENOEXEC
;
610 /* First word is either "-" or "@" with no command. */
611 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
612 "Empty path in command line%s: '%s'",
613 ignore
? ", ignoring" : "", rvalue
);
614 return ignore
? 0 : -ENOEXEC
;
616 if (!string_is_safe(path
)) {
617 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
618 "Executable name contains special characters%s: %s",
619 ignore
? ", ignoring" : "", path
);
620 return ignore
? 0 : -ENOEXEC
;
622 if (endswith(path
, "/")) {
623 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
624 "Executable path specifies a directory%s: %s",
625 ignore
? ", ignoring" : "", path
);
626 return ignore
? 0 : -ENOEXEC
;
629 if (!path_is_absolute(path
)) {
633 if (!filename_is_valid(path
)) {
634 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
635 "Neither a valid executable name nor an absolute path%s: %s",
636 ignore
? ", ignoring" : "", path
);
637 return ignore
? 0 : -ENOEXEC
;
640 /* Resolve a single-component name to a full path */
641 NULSTR_FOREACH(prefix
, DEFAULT_PATH_NULSTR
) {
642 _cleanup_free_
char *fullpath
= NULL
;
644 fullpath
= strjoin(prefix
, "/", path
);
648 if (access(fullpath
, F_OK
) >= 0) {
649 free_and_replace(path
, fullpath
);
656 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
657 "Executable \"%s\" not found in path \"%s\"%s",
658 path
, DEFAULT_PATH
, ignore
? ", ignoring" : "");
659 return ignore
? 0 : -ENOEXEC
;
663 if (!separate_argv0
) {
666 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
676 path_simplify(path
, false);
678 while (!isempty(p
)) {
679 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
681 /* Check explicitly for an unquoted semicolon as
682 * command separator token. */
683 if (p
[0] == ';' && (!p
[1] || strchr(WHITESPACE
, p
[1]))) {
685 p
+= strspn(p
, WHITESPACE
);
690 /* Check for \; explicitly, to not confuse it with \\; or "\;" or "\\;" etc.
691 * extract_first_word() would return the same for all of those. */
692 if (p
[0] == '\\' && p
[1] == ';' && (!p
[2] || strchr(WHITESPACE
, p
[2]))) {
696 p
+= strspn(p
, WHITESPACE
);
698 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
709 r
= extract_first_word_and_warn(&p
, &word
, NULL
, EXTRACT_QUOTES
|EXTRACT_CUNESCAPE
, unit
, filename
, line
, rvalue
);
713 return ignore
? 0 : -ENOEXEC
;
715 r
= unit_full_printf(u
, word
, &resolved
);
717 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
718 "Failed to resolve unit specifiers in %s%s: %m",
719 word
, ignore
? ", ignoring" : "");
720 return ignore
? 0 : -ENOEXEC
;
723 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
726 n
[nlen
++] = TAKE_PTR(resolved
);
731 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
732 "Empty executable name or zeroeth argument%s: %s",
733 ignore
? ", ignoring" : "", rvalue
);
734 return ignore
? 0 : -ENOEXEC
;
737 nce
= new0(ExecCommand
, 1);
741 nce
->argv
= TAKE_PTR(n
);
742 nce
->path
= TAKE_PTR(path
);
745 exec_command_append_list(e
, nce
);
747 /* Do not _cleanup_free_ these. */
756 int config_parse_socket_bindtodevice(
758 const char *filename
,
761 unsigned section_line
,
775 if (isempty(rvalue
) || streq(rvalue
, "*")) {
776 s
->bind_to_device
= mfree(s
->bind_to_device
);
780 if (!ifname_valid(rvalue
)) {
781 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid interface name, ignoring: %s", rvalue
);
785 if (free_and_strdup(&s
->bind_to_device
, rvalue
) < 0)
791 int config_parse_exec_input(
793 const char *filename
,
796 unsigned section_line
,
803 ExecContext
*c
= data
;
814 n
= startswith(rvalue
, "fd:");
816 _cleanup_free_
char *resolved
= NULL
;
818 r
= unit_full_printf(u
, n
, &resolved
);
820 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s': %m", n
);
822 if (isempty(resolved
))
823 resolved
= mfree(resolved
);
824 else if (!fdname_is_valid(resolved
)) {
825 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name: %s", resolved
);
829 free_and_replace(c
->stdio_fdname
[STDIN_FILENO
], resolved
);
831 ei
= EXEC_INPUT_NAMED_FD
;
833 } else if ((n
= startswith(rvalue
, "file:"))) {
834 _cleanup_free_
char *resolved
= NULL
;
836 r
= unit_full_printf(u
, n
, &resolved
);
838 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s': %m", n
);
840 if (!path_is_absolute(resolved
)) {
841 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "file: requires an absolute path name: %s", resolved
);
845 if (!path_is_normalized(resolved
)) {
846 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "file: requires a normalized path name: %s", resolved
);
850 free_and_replace(c
->stdio_file
[STDIN_FILENO
], resolved
);
852 ei
= EXEC_INPUT_FILE
;
855 ei
= exec_input_from_string(rvalue
);
857 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse input specifier, ignoring: %s", rvalue
);
866 int config_parse_exec_input_text(
868 const char *filename
,
871 unsigned section_line
,
878 _cleanup_free_
char *unescaped
= NULL
, *resolved
= NULL
;
879 ExecContext
*c
= data
;
890 if (isempty(rvalue
)) {
891 /* Reset if the empty string is assigned */
892 c
->stdin_data
= mfree(c
->stdin_data
);
893 c
->stdin_data_size
= 0;
897 r
= cunescape(rvalue
, 0, &unescaped
);
899 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to decode C escaped text '%s': %m", rvalue
);
901 r
= unit_full_printf(u
, unescaped
, &resolved
);
903 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s': %m", unescaped
);
905 sz
= strlen(resolved
);
906 if (c
->stdin_data_size
+ sz
+ 1 < c
->stdin_data_size
|| /* check for overflow */
907 c
->stdin_data_size
+ sz
+ 1 > EXEC_STDIN_DATA_MAX
) {
908 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
);
912 p
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
+ 1);
916 *((char*) mempcpy((char*) p
+ c
->stdin_data_size
, resolved
, sz
)) = '\n';
919 c
->stdin_data_size
+= sz
+ 1;
924 int config_parse_exec_input_data(
926 const char *filename
,
929 unsigned section_line
,
936 _cleanup_free_
void *p
= NULL
;
937 ExecContext
*c
= data
;
947 if (isempty(rvalue
)) {
948 /* Reset if the empty string is assigned */
949 c
->stdin_data
= mfree(c
->stdin_data
);
950 c
->stdin_data_size
= 0;
954 r
= unbase64mem(rvalue
, (size_t) -1, &p
, &sz
);
956 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to decode base64 data, ignoring: %s", rvalue
);
960 if (c
->stdin_data_size
+ sz
< c
->stdin_data_size
|| /* check for overflow */
961 c
->stdin_data_size
+ sz
> EXEC_STDIN_DATA_MAX
) {
962 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
);
966 q
= realloc(c
->stdin_data
, c
->stdin_data_size
+ sz
);
970 memcpy((uint8_t*) q
+ c
->stdin_data_size
, p
, sz
);
973 c
->stdin_data_size
+= sz
;
978 int config_parse_exec_output(
980 const char *filename
,
983 unsigned section_line
,
990 _cleanup_free_
char *resolved
= NULL
;
992 ExecContext
*c
= data
;
1003 n
= startswith(rvalue
, "fd:");
1005 r
= unit_full_printf(u
, n
, &resolved
);
1007 return log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", n
);
1009 if (isempty(resolved
))
1010 resolved
= mfree(resolved
);
1011 else if (!fdname_is_valid(resolved
)) {
1012 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name: %s", resolved
);
1016 eo
= EXEC_OUTPUT_NAMED_FD
;
1018 } else if ((n
= startswith(rvalue
, "file:"))) {
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 if (!path_is_absolute(resolved
)) {
1025 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "file: requires an absolute path name: %s", resolved
);
1029 if (!path_is_normalized(resolved
)) {
1030 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "file: requires a normalized path name, ignoring: %s", resolved
);
1034 eo
= EXEC_OUTPUT_FILE
;
1037 eo
= exec_output_from_string(rvalue
);
1039 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse output specifier, ignoring: %s", rvalue
);
1044 if (streq(lvalue
, "StandardOutput")) {
1045 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1046 free_and_replace(c
->stdio_fdname
[STDOUT_FILENO
], resolved
);
1048 free_and_replace(c
->stdio_file
[STDOUT_FILENO
], resolved
);
1053 assert(streq(lvalue
, "StandardError"));
1055 if (eo
== EXEC_OUTPUT_NAMED_FD
)
1056 free_and_replace(c
->stdio_fdname
[STDERR_FILENO
], resolved
);
1058 free_and_replace(c
->stdio_file
[STDERR_FILENO
], resolved
);
1066 int config_parse_exec_io_class(const char *unit
,
1067 const char *filename
,
1069 const char *section
,
1070 unsigned section_line
,
1077 ExecContext
*c
= data
;
1085 if (isempty(rvalue
)) {
1086 c
->ioprio_set
= false;
1087 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE
, 0);
1091 x
= ioprio_class_from_string(rvalue
);
1093 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse IO scheduling class, ignoring: %s", rvalue
);
1097 c
->ioprio
= IOPRIO_PRIO_VALUE(x
, IOPRIO_PRIO_DATA(c
->ioprio
));
1098 c
->ioprio_set
= true;
1103 int config_parse_exec_io_priority(const char *unit
,
1104 const char *filename
,
1106 const char *section
,
1107 unsigned section_line
,
1114 ExecContext
*c
= data
;
1122 if (isempty(rvalue
)) {
1123 c
->ioprio_set
= false;
1124 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE
, 0);
1128 r
= ioprio_parse_priority(rvalue
, &i
);
1130 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse IO priority, ignoring: %s", rvalue
);
1134 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_PRIO_CLASS(c
->ioprio
), i
);
1135 c
->ioprio_set
= true;
1140 int config_parse_exec_cpu_sched_policy(const char *unit
,
1141 const char *filename
,
1143 const char *section
,
1144 unsigned section_line
,
1151 ExecContext
*c
= data
;
1159 if (isempty(rvalue
)) {
1160 c
->cpu_sched_set
= false;
1161 c
->cpu_sched_policy
= SCHED_OTHER
;
1162 c
->cpu_sched_priority
= 0;
1166 x
= sched_policy_from_string(rvalue
);
1168 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse CPU scheduling policy, ignoring: %s", rvalue
);
1172 c
->cpu_sched_policy
= x
;
1173 /* Moving to or from real-time policy? We need to adjust the priority */
1174 c
->cpu_sched_priority
= CLAMP(c
->cpu_sched_priority
, sched_get_priority_min(x
), sched_get_priority_max(x
));
1175 c
->cpu_sched_set
= true;
1180 int config_parse_exec_cpu_sched_prio(const char *unit
,
1181 const char *filename
,
1183 const char *section
,
1184 unsigned section_line
,
1191 ExecContext
*c
= data
;
1199 r
= safe_atoi(rvalue
, &i
);
1201 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse CPU scheduling priority, ignoring: %s", rvalue
);
1205 /* On Linux RR/FIFO range from 1 to 99 and OTHER/BATCH may only be 0 */
1206 min
= sched_get_priority_min(c
->cpu_sched_policy
);
1207 max
= sched_get_priority_max(c
->cpu_sched_policy
);
1209 if (i
< min
|| i
> max
) {
1210 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "CPU scheduling priority is out of range, ignoring: %s", rvalue
);
1214 c
->cpu_sched_priority
= i
;
1215 c
->cpu_sched_set
= true;
1220 int config_parse_exec_cpu_affinity(const char *unit
,
1221 const char *filename
,
1223 const char *section
,
1224 unsigned section_line
,
1231 ExecContext
*c
= data
;
1232 _cleanup_cpu_free_ cpu_set_t
*cpuset
= NULL
;
1240 ncpus
= parse_cpu_set_and_warn(rvalue
, &cpuset
, unit
, filename
, line
, lvalue
);
1245 /* An empty assignment resets the CPU list */
1246 c
->cpuset
= cpu_set_mfree(c
->cpuset
);
1247 c
->cpuset_ncpus
= 0;
1252 c
->cpuset
= TAKE_PTR(cpuset
);
1253 c
->cpuset_ncpus
= (unsigned) ncpus
;
1257 if (c
->cpuset_ncpus
< (unsigned) ncpus
) {
1258 CPU_OR_S(CPU_ALLOC_SIZE(c
->cpuset_ncpus
), cpuset
, c
->cpuset
, cpuset
);
1259 CPU_FREE(c
->cpuset
);
1260 c
->cpuset
= TAKE_PTR(cpuset
);
1261 c
->cpuset_ncpus
= (unsigned) ncpus
;
1265 CPU_OR_S(CPU_ALLOC_SIZE((unsigned) ncpus
), c
->cpuset
, c
->cpuset
, cpuset
);
1270 int config_parse_capability_set(
1272 const char *filename
,
1274 const char *section
,
1275 unsigned section_line
,
1282 uint64_t *capability_set
= data
;
1283 uint64_t sum
= 0, initial
= 0;
1284 bool invert
= false;
1292 if (rvalue
[0] == '~') {
1297 if (streq(lvalue
, "CapabilityBoundingSet"))
1298 initial
= CAP_ALL
; /* initialized to all bits on */
1299 /* else "AmbientCapabilities" initialized to all bits off */
1301 r
= capability_set_from_string(rvalue
, &sum
);
1303 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= specifier '%s', ignoring: %m", lvalue
, rvalue
);
1307 if (sum
== 0 || *capability_set
== initial
)
1308 /* "", "~" or uninitialized data -> replace */
1309 *capability_set
= invert
? ~sum
: sum
;
1311 /* previous data -> merge */
1313 *capability_set
&= ~sum
;
1315 *capability_set
|= sum
;
1321 int config_parse_exec_selinux_context(
1323 const char *filename
,
1325 const char *section
,
1326 unsigned section_line
,
1333 ExecContext
*c
= data
;
1344 if (isempty(rvalue
)) {
1345 c
->selinux_context
= mfree(c
->selinux_context
);
1346 c
->selinux_context_ignore
= false;
1350 if (rvalue
[0] == '-') {
1356 r
= unit_full_printf(u
, rvalue
, &k
);
1358 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1359 "Failed to resolve unit specifiers in '%s'%s: %m",
1360 rvalue
, ignore
? ", ignoring" : "");
1361 return ignore
? 0 : -ENOEXEC
;
1364 free_and_replace(c
->selinux_context
, k
);
1365 c
->selinux_context_ignore
= ignore
;
1370 int config_parse_exec_apparmor_profile(
1372 const char *filename
,
1374 const char *section
,
1375 unsigned section_line
,
1382 ExecContext
*c
= data
;
1393 if (isempty(rvalue
)) {
1394 c
->apparmor_profile
= mfree(c
->apparmor_profile
);
1395 c
->apparmor_profile_ignore
= false;
1399 if (rvalue
[0] == '-') {
1405 r
= unit_full_printf(u
, rvalue
, &k
);
1407 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1408 "Failed to resolve unit specifiers in '%s'%s: %m",
1409 rvalue
, ignore
? ", ignoring" : "");
1410 return ignore
? 0 : -ENOEXEC
;
1413 free_and_replace(c
->apparmor_profile
, k
);
1414 c
->apparmor_profile_ignore
= ignore
;
1419 int config_parse_exec_smack_process_label(
1421 const char *filename
,
1423 const char *section
,
1424 unsigned section_line
,
1431 ExecContext
*c
= data
;
1442 if (isempty(rvalue
)) {
1443 c
->smack_process_label
= mfree(c
->smack_process_label
);
1444 c
->smack_process_label_ignore
= false;
1448 if (rvalue
[0] == '-') {
1454 r
= unit_full_printf(u
, rvalue
, &k
);
1456 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1457 "Failed to resolve unit specifiers in '%s'%s: %m",
1458 rvalue
, ignore
? ", ignoring" : "");
1459 return ignore
? 0 : -ENOEXEC
;
1462 free_and_replace(c
->smack_process_label
, k
);
1463 c
->smack_process_label_ignore
= ignore
;
1468 int config_parse_timer(const char *unit
,
1469 const char *filename
,
1471 const char *section
,
1472 unsigned section_line
,
1483 _cleanup_(calendar_spec_freep
) CalendarSpec
*c
= NULL
;
1485 _cleanup_free_
char *k
= NULL
;
1493 if (isempty(rvalue
)) {
1494 /* Empty assignment resets list */
1495 timer_free_values(t
);
1499 b
= timer_base_from_string(lvalue
);
1501 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse timer base, ignoring: %s", lvalue
);
1505 r
= unit_full_printf(u
, rvalue
, &k
);
1507 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
1511 if (b
== TIMER_CALENDAR
) {
1512 if (calendar_spec_from_string(k
, &c
) < 0) {
1513 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse calendar specification, ignoring: %s", k
);
1517 if (parse_sec(k
, &usec
) < 0) {
1518 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse timer value, ignoring: %s", k
);
1522 v
= new0(TimerValue
, 1);
1528 v
->calendar_spec
= TAKE_PTR(c
);
1530 LIST_PREPEND(value
, t
->values
, v
);
1535 int config_parse_trigger_unit(
1537 const char *filename
,
1539 const char *section
,
1540 unsigned section_line
,
1547 _cleanup_free_
char *p
= NULL
;
1557 if (!hashmap_isempty(u
->dependencies
[UNIT_TRIGGERS
])) {
1558 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Multiple units to trigger specified, ignoring: %s", rvalue
);
1562 r
= unit_name_printf(u
, rvalue
, &p
);
1564 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
1568 type
= unit_name_to_type(p
);
1570 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit type not valid, ignoring: %s", rvalue
);
1573 if (unit_has_name(u
, p
)) {
1574 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Units cannot trigger themselves, ignoring: %s", rvalue
);
1578 r
= unit_add_two_dependencies_by_name(u
, UNIT_BEFORE
, UNIT_TRIGGERS
, p
, NULL
, true, UNIT_DEPENDENCY_FILE
);
1580 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add trigger on %s, ignoring: %m", p
);
1587 int config_parse_path_spec(const char *unit
,
1588 const char *filename
,
1590 const char *section
,
1591 unsigned section_line
,
1601 _cleanup_free_
char *k
= NULL
;
1609 if (isempty(rvalue
)) {
1610 /* Empty assignment clears list */
1615 b
= path_type_from_string(lvalue
);
1617 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse path type, ignoring: %s", lvalue
);
1621 r
= unit_full_printf(UNIT(p
), rvalue
, &k
);
1623 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
1627 path_simplify(k
, false);
1629 if (!path_is_absolute(k
)) {
1630 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Path is not absolute, ignoring: %s", k
);
1634 s
= new0(PathSpec
, 1);
1639 s
->path
= TAKE_PTR(k
);
1643 LIST_PREPEND(spec
, p
->specs
, s
);
1648 int config_parse_socket_service(
1650 const char *filename
,
1652 const char *section
,
1653 unsigned section_line
,
1660 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1661 _cleanup_free_
char *p
= NULL
;
1671 r
= unit_name_printf(UNIT(s
), rvalue
, &p
);
1673 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", rvalue
);
1677 if (!endswith(p
, ".service")) {
1678 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit must be of type service: %s", rvalue
);
1682 r
= manager_load_unit(UNIT(s
)->manager
, p
, NULL
, &error
, &x
);
1684 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to load unit %s: %s", rvalue
, bus_error_message(&error
, r
));
1688 unit_ref_set(&s
->service
, UNIT(s
), x
);
1693 int config_parse_fdname(
1695 const char *filename
,
1697 const char *section
,
1698 unsigned section_line
,
1705 _cleanup_free_
char *p
= NULL
;
1714 if (isempty(rvalue
)) {
1715 s
->fdname
= mfree(s
->fdname
);
1719 r
= unit_full_printf(UNIT(s
), rvalue
, &p
);
1721 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
1725 if (!fdname_is_valid(p
)) {
1726 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid file descriptor name, ignoring: %s", p
);
1730 return free_and_replace(s
->fdname
, p
);
1733 int config_parse_service_sockets(
1735 const char *filename
,
1737 const char *section
,
1738 unsigned section_line
,
1756 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
1758 r
= extract_first_word(&p
, &word
, NULL
, 0);
1764 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Trailing garbage in sockets, ignoring: %s", rvalue
);
1768 r
= unit_name_printf(UNIT(s
), word
, &k
);
1770 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
1774 if (!endswith(k
, ".socket")) {
1775 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unit must be of type socket, ignoring: %s", k
);
1779 r
= unit_add_two_dependencies_by_name(UNIT(s
), UNIT_WANTS
, UNIT_AFTER
, k
, NULL
, true, UNIT_DEPENDENCY_FILE
);
1781 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
1783 r
= unit_add_dependency_by_name(UNIT(s
), UNIT_TRIGGERED_BY
, k
, NULL
, true, UNIT_DEPENDENCY_FILE
);
1785 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add dependency on %s, ignoring: %m", k
);
1791 int config_parse_bus_name(
1793 const char *filename
,
1795 const char *section
,
1796 unsigned section_line
,
1803 _cleanup_free_
char *k
= NULL
;
1812 r
= unit_full_printf(u
, rvalue
, &k
);
1814 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
1818 if (!service_name_is_valid(k
)) {
1819 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid bus name, ignoring: %s", k
);
1823 return config_parse_string(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, k
, data
, userdata
);
1826 int config_parse_service_timeout(
1828 const char *filename
,
1830 const char *section
,
1831 unsigned section_line
,
1838 Service
*s
= userdata
;
1847 /* This is called for two cases: TimeoutSec= and TimeoutStartSec=. */
1849 /* Traditionally, these options accepted 0 to disable the timeouts. However, a timeout of 0 suggests it happens
1850 * immediately, hence fix this to become USEC_INFINITY instead. This is in-line with how we internally handle
1851 * all other timeouts. */
1852 r
= parse_sec_fix_0(rvalue
, &usec
);
1854 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
1858 s
->start_timeout_defined
= true;
1859 s
->timeout_start_usec
= usec
;
1861 if (streq(lvalue
, "TimeoutSec"))
1862 s
->timeout_stop_usec
= usec
;
1867 int config_parse_sec_fix_0(
1869 const char *filename
,
1871 const char *section
,
1872 unsigned section_line
,
1879 usec_t
*usec
= data
;
1887 /* This is pretty much like config_parse_sec(), except that this treats a time of 0 as infinity, for
1888 * compatibility with older versions of systemd where 0 instead of infinity was used as indicator to turn off a
1891 r
= parse_sec_fix_0(rvalue
, usec
);
1893 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s= parameter, ignoring: %s", lvalue
, rvalue
);
1900 int config_parse_user_group(
1902 const char *filename
,
1904 const char *section
,
1905 unsigned section_line
,
1912 _cleanup_free_
char *k
= NULL
;
1922 if (isempty(rvalue
)) {
1923 *user
= mfree(*user
);
1927 r
= unit_full_printf(u
, rvalue
, &k
);
1929 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", rvalue
);
1933 if (!valid_user_group_name_or_id(k
)) {
1934 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
1938 return free_and_replace(*user
, k
);
1941 int config_parse_user_group_strv(
1943 const char *filename
,
1945 const char *section
,
1946 unsigned section_line
,
1953 char ***users
= data
;
1955 const char *p
= rvalue
;
1963 if (isempty(rvalue
)) {
1964 *users
= strv_free(*users
);
1969 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
1971 r
= extract_first_word(&p
, &word
, NULL
, 0);
1977 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax: %s", rvalue
);
1981 r
= unit_full_printf(u
, word
, &k
);
1983 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", word
);
1987 if (!valid_user_group_name_or_id(k
)) {
1988 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid user/group name or numeric ID: %s", k
);
1992 r
= strv_push(users
, k
);
2002 int config_parse_working_directory(
2004 const char *filename
,
2006 const char *section
,
2007 unsigned section_line
,
2014 ExecContext
*c
= data
;
2025 if (isempty(rvalue
)) {
2026 c
->working_directory_home
= false;
2027 c
->working_directory
= mfree(c
->working_directory
);
2031 if (rvalue
[0] == '-') {
2037 if (streq(rvalue
, "~")) {
2038 c
->working_directory_home
= true;
2039 c
->working_directory
= mfree(c
->working_directory
);
2041 _cleanup_free_
char *k
= NULL
;
2043 r
= unit_full_printf(u
, rvalue
, &k
);
2045 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2046 "Failed to resolve unit specifiers in working directory path '%s'%s: %m",
2047 rvalue
, missing_ok
? ", ignoring" : "");
2048 return missing_ok
? 0 : -ENOEXEC
;
2051 path_simplify(k
, false);
2053 if (!utf8_is_valid(k
)) {
2054 log_syntax_invalid_utf8(unit
, LOG_ERR
, filename
, line
, rvalue
);
2055 return missing_ok
? 0 : -ENOEXEC
;
2058 if (!path_is_absolute(k
)) {
2059 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2060 "Working directory path '%s' is not absolute%s.",
2061 rvalue
, missing_ok
? ", ignoring" : "");
2062 return missing_ok
? 0 : -ENOEXEC
;
2065 c
->working_directory_home
= false;
2066 free_and_replace(c
->working_directory
, k
);
2069 c
->working_directory_missing_ok
= missing_ok
;
2073 int config_parse_unit_env_file(const char *unit
,
2074 const char *filename
,
2076 const char *section
,
2077 unsigned section_line
,
2086 _cleanup_free_
char *n
= NULL
;
2094 if (isempty(rvalue
)) {
2095 /* Empty assignment frees the list */
2096 *env
= strv_free(*env
);
2100 r
= unit_full_printf(u
, rvalue
, &n
);
2102 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2106 if (!path_is_absolute(n
[0] == '-' ? n
+ 1 : n
)) {
2107 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Path '%s' is not absolute, ignoring.", n
);
2111 r
= strv_extend(env
, n
);
2118 int config_parse_environ(
2120 const char *filename
,
2122 const char *section
,
2123 unsigned section_line
,
2140 if (isempty(rvalue
)) {
2141 /* Empty assignment resets the list */
2142 *env
= strv_free(*env
);
2146 for (p
= rvalue
;; ) {
2147 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2149 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_QUOTES
);
2155 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2156 "Invalid syntax, ignoring: %s", rvalue
);
2161 r
= unit_full_printf(u
, word
, &k
);
2163 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2164 "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2170 if (!env_assignment_is_valid(k
)) {
2171 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2172 "Invalid environment assignment, ignoring: %s", k
);
2176 r
= strv_env_replace(env
, k
);
2184 int config_parse_pass_environ(
2186 const char *filename
,
2188 const char *section
,
2189 unsigned section_line
,
2196 _cleanup_strv_free_
char **n
= NULL
;
2197 size_t nlen
= 0, nbufsize
= 0;
2198 char*** passenv
= data
;
2199 const char *p
= rvalue
;
2208 if (isempty(rvalue
)) {
2209 /* Empty assignment resets the list */
2210 *passenv
= strv_free(*passenv
);
2215 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2217 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
2223 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2224 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2229 r
= unit_full_printf(u
, word
, &k
);
2231 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2232 "Failed to resolve specifiers in %s, ignoring: %m", word
);
2238 if (!env_name_is_valid(k
)) {
2239 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2240 "Invalid environment name for %s, ignoring: %s", lvalue
, k
);
2244 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
2247 n
[nlen
++] = TAKE_PTR(k
);
2252 r
= strv_extend_strv(passenv
, n
, true);
2260 int config_parse_unset_environ(
2262 const char *filename
,
2264 const char *section
,
2265 unsigned section_line
,
2272 _cleanup_strv_free_
char **n
= NULL
;
2273 size_t nlen
= 0, nbufsize
= 0;
2274 char*** unsetenv
= data
;
2275 const char *p
= rvalue
;
2284 if (isempty(rvalue
)) {
2285 /* Empty assignment resets the list */
2286 *unsetenv
= strv_free(*unsetenv
);
2291 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2293 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_QUOTES
);
2299 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2300 "Trailing garbage in %s, ignoring: %s", lvalue
, rvalue
);
2305 r
= unit_full_printf(u
, word
, &k
);
2307 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2308 "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2314 if (!env_assignment_is_valid(k
) && !env_name_is_valid(k
)) {
2315 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2316 "Invalid environment name or assignment %s, ignoring: %s", lvalue
, k
);
2320 if (!GREEDY_REALLOC(n
, nbufsize
, nlen
+ 2))
2323 n
[nlen
++] = TAKE_PTR(k
);
2328 r
= strv_extend_strv(unsetenv
, n
, true);
2336 int config_parse_log_extra_fields(
2338 const char *filename
,
2340 const char *section
,
2341 unsigned section_line
,
2348 ExecContext
*c
= data
;
2350 const char *p
= rvalue
;
2358 if (isempty(rvalue
)) {
2359 exec_context_free_log_extra_fields(c
);
2364 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
2368 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_CUNESCAPE
|EXTRACT_QUOTES
);
2374 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
2378 r
= unit_full_printf(u
, word
, &k
);
2380 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", word
);
2384 eq
= strchr(k
, '=');
2386 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Log field lacks '=' character, ignoring: %s", k
);
2390 if (!journal_field_valid(k
, eq
-k
, false)) {
2391 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Log field name is invalid, ignoring: %s", k
);
2395 t
= reallocarray(c
->log_extra_fields
, c
->n_log_extra_fields
+1, sizeof(struct iovec
));
2399 c
->log_extra_fields
= t
;
2400 c
->log_extra_fields
[c
->n_log_extra_fields
++] = IOVEC_MAKE_STRING(k
);
2406 int config_parse_unit_condition_path(
2408 const char *filename
,
2410 const char *section
,
2411 unsigned section_line
,
2418 _cleanup_free_
char *p
= NULL
;
2419 Condition
**list
= data
, *c
;
2420 ConditionType t
= ltype
;
2421 bool trigger
, negate
;
2430 if (isempty(rvalue
)) {
2431 /* Empty assignment resets the list */
2432 *list
= condition_free_list(*list
);
2436 trigger
= rvalue
[0] == '|';
2440 negate
= rvalue
[0] == '!';
2444 r
= unit_full_printf(u
, rvalue
, &p
);
2446 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2450 if (!path_is_absolute(p
)) {
2451 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Path in condition not absolute, ignoring: %s", p
);
2455 c
= condition_new(t
, p
, trigger
, negate
);
2459 LIST_PREPEND(conditions
, *list
, c
);
2463 int config_parse_unit_condition_string(
2465 const char *filename
,
2467 const char *section
,
2468 unsigned section_line
,
2475 _cleanup_free_
char *s
= NULL
;
2476 Condition
**list
= data
, *c
;
2477 ConditionType t
= ltype
;
2478 bool trigger
, negate
;
2487 if (isempty(rvalue
)) {
2488 /* Empty assignment resets the list */
2489 *list
= condition_free_list(*list
);
2493 trigger
= rvalue
[0] == '|';
2497 negate
= rvalue
[0] == '!';
2501 r
= unit_full_printf(u
, rvalue
, &s
);
2503 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue
);
2507 c
= condition_new(t
, s
, trigger
, negate
);
2511 LIST_PREPEND(conditions
, *list
, c
);
2515 int config_parse_unit_condition_null(
2517 const char *filename
,
2519 const char *section
,
2520 unsigned section_line
,
2527 Condition
**list
= data
, *c
;
2528 bool trigger
, negate
;
2536 if (isempty(rvalue
)) {
2537 /* Empty assignment resets the list */
2538 *list
= condition_free_list(*list
);
2542 trigger
= rvalue
[0] == '|';
2546 negate
= rvalue
[0] == '!';
2550 b
= parse_boolean(rvalue
);
2552 log_syntax(unit
, LOG_ERR
, filename
, line
, b
, "Failed to parse boolean value in condition, ignoring: %s", rvalue
);
2559 c
= condition_new(CONDITION_NULL
, NULL
, trigger
, negate
);
2563 LIST_PREPEND(conditions
, *list
, c
);
2567 int config_parse_unit_requires_mounts_for(
2569 const char *filename
,
2571 const char *section
,
2572 unsigned section_line
,
2579 const char *p
= rvalue
;
2589 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
;
2591 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
2597 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2598 "Invalid syntax, ignoring: %s", rvalue
);
2602 if (!utf8_is_valid(word
)) {
2603 log_syntax_invalid_utf8(unit
, LOG_ERR
, filename
, line
, rvalue
);
2607 r
= unit_full_printf(u
, word
, &resolved
);
2609 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in '%s', ignoring: %m", word
);
2613 r
= unit_require_mounts_for(u
, resolved
, UNIT_DEPENDENCY_FILE
);
2615 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to add required mount '%s', ignoring: %m", resolved
);
2621 int config_parse_documentation(const char *unit
,
2622 const char *filename
,
2624 const char *section
,
2625 unsigned section_line
,
2641 if (isempty(rvalue
)) {
2642 /* Empty assignment resets the list */
2643 u
->documentation
= strv_free(u
->documentation
);
2647 r
= config_parse_unit_strv_printf(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
,
2648 rvalue
, data
, userdata
);
2652 for (a
= b
= u
->documentation
; a
&& *a
; a
++) {
2654 if (documentation_url_is_valid(*a
))
2657 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid URL, ignoring: %s", *a
);
2668 int config_parse_syscall_filter(
2670 const char *filename
,
2672 const char *section
,
2673 unsigned section_line
,
2680 ExecContext
*c
= data
;
2682 bool invert
= false;
2691 if (isempty(rvalue
)) {
2692 /* Empty assignment resets the list */
2693 c
->syscall_filter
= hashmap_free(c
->syscall_filter
);
2694 c
->syscall_whitelist
= false;
2698 if (rvalue
[0] == '~') {
2703 if (!c
->syscall_filter
) {
2704 c
->syscall_filter
= hashmap_new(NULL
);
2705 if (!c
->syscall_filter
)
2709 /* Allow everything but the ones listed */
2710 c
->syscall_whitelist
= false;
2712 /* Allow nothing but the ones listed */
2713 c
->syscall_whitelist
= true;
2715 /* Accept default syscalls if we are on a whitelist */
2716 r
= seccomp_parse_syscall_filter("@default", -1, c
->syscall_filter
, SECCOMP_PARSE_WHITELIST
);
2724 _cleanup_free_
char *word
= NULL
, *name
= NULL
;
2727 r
= extract_first_word(&p
, &word
, NULL
, 0);
2733 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
2737 r
= parse_syscall_and_errno(word
, &name
, &num
);
2739 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
, "Failed to parse syscall:errno, ignoring: %s", word
);
2743 r
= seccomp_parse_syscall_filter_full(name
, num
, c
->syscall_filter
,
2744 SECCOMP_PARSE_LOG
|SECCOMP_PARSE_PERMISSIVE
|(invert
? SECCOMP_PARSE_INVERT
: 0)|(c
->syscall_whitelist
? SECCOMP_PARSE_WHITELIST
: 0),
2745 unit
, filename
, line
);
2751 int config_parse_syscall_archs(
2753 const char *filename
,
2755 const char *section
,
2756 unsigned section_line
,
2763 const char *p
= rvalue
;
2767 if (isempty(rvalue
)) {
2768 *archs
= set_free(*archs
);
2772 r
= set_ensure_allocated(archs
, NULL
);
2777 _cleanup_free_
char *word
= NULL
;
2780 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
2786 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2787 "Invalid syntax, ignoring: %s", rvalue
);
2791 r
= seccomp_arch_from_string(word
, &a
);
2793 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
2794 "Failed to parse system call architecture \"%s\", ignoring: %m", word
);
2798 r
= set_put(*archs
, UINT32_TO_PTR(a
+ 1));
2804 int config_parse_syscall_errno(
2806 const char *filename
,
2808 const char *section
,
2809 unsigned section_line
,
2816 ExecContext
*c
= data
;
2823 if (isempty(rvalue
)) {
2824 /* Empty assignment resets to KILL */
2825 c
->syscall_errno
= 0;
2829 e
= parse_errno(rvalue
);
2831 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse error number, ignoring: %s", rvalue
);
2835 c
->syscall_errno
= e
;
2839 int config_parse_address_families(
2841 const char *filename
,
2843 const char *section
,
2844 unsigned section_line
,
2851 ExecContext
*c
= data
;
2852 bool invert
= false;
2860 if (isempty(rvalue
)) {
2861 /* Empty assignment resets the list */
2862 c
->address_families
= set_free(c
->address_families
);
2863 c
->address_families_whitelist
= false;
2867 if (rvalue
[0] == '~') {
2872 if (!c
->address_families
) {
2873 c
->address_families
= set_new(NULL
);
2874 if (!c
->address_families
)
2877 c
->address_families_whitelist
= !invert
;
2880 for (p
= rvalue
;;) {
2881 _cleanup_free_
char *word
= NULL
;
2884 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
2890 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
2891 "Invalid syntax, ignoring: %s", rvalue
);
2895 af
= af_from_name(word
);
2897 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
2898 "Failed to parse address family, ignoring: %s", word
);
2902 /* If we previously wanted to forbid an address family and now
2903 * we want to allow it, then just remove it from the list.
2905 if (!invert
== c
->address_families_whitelist
) {
2906 r
= set_put(c
->address_families
, INT_TO_PTR(af
));
2910 set_remove(c
->address_families
, INT_TO_PTR(af
));
2914 int config_parse_restrict_namespaces(
2916 const char *filename
,
2918 const char *section
,
2919 unsigned section_line
,
2926 ExecContext
*c
= data
;
2927 unsigned long flags
;
2928 bool invert
= false;
2931 if (isempty(rvalue
)) {
2932 /* Reset to the default. */
2933 c
->restrict_namespaces
= NAMESPACE_FLAGS_INITIAL
;
2937 /* Boolean parameter ignores the previous settings */
2938 r
= parse_boolean(rvalue
);
2940 c
->restrict_namespaces
= 0;
2942 } else if (r
== 0) {
2943 c
->restrict_namespaces
= NAMESPACE_FLAGS_ALL
;
2947 if (rvalue
[0] == '~') {
2952 /* Not a boolean argument, in this case it's a list of namespace types. */
2953 r
= namespace_flags_from_string(rvalue
, &flags
);
2955 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse namespace type string, ignoring: %s", rvalue
);
2959 if (c
->restrict_namespaces
== NAMESPACE_FLAGS_INITIAL
)
2960 /* Initial assignment. Just set the value. */
2961 c
->restrict_namespaces
= invert
? (~flags
) & NAMESPACE_FLAGS_ALL
: flags
;
2963 /* Merge the value with the previous one. */
2964 SET_FLAG(c
->restrict_namespaces
, flags
, !invert
);
2970 int config_parse_unit_slice(
2972 const char *filename
,
2974 const char *section
,
2975 unsigned section_line
,
2982 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
2983 _cleanup_free_
char *k
= NULL
;
2984 Unit
*u
= userdata
, *slice
= NULL
;
2992 r
= unit_name_printf(u
, rvalue
, &k
);
2994 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", rvalue
);
2998 r
= manager_load_unit(u
->manager
, k
, NULL
, &error
, &slice
);
3000 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to load slice unit %s, ignoring: %s", k
, bus_error_message(&error
, r
));
3004 r
= unit_set_slice(u
, slice
);
3006 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to assign slice %s to unit %s, ignoring: %m", slice
->id
, u
->id
);
3013 int config_parse_cpu_quota(
3015 const char *filename
,
3017 const char *section
,
3018 unsigned section_line
,
3025 CGroupContext
*c
= data
;
3032 if (isempty(rvalue
)) {
3033 c
->cpu_quota_per_sec_usec
= USEC_INFINITY
;
3037 r
= parse_percent_unbounded(rvalue
);
3039 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid CPU quota '%s', ignoring.", rvalue
);
3043 c
->cpu_quota_per_sec_usec
= ((usec_t
) r
* USEC_PER_SEC
) / 100U;
3047 int config_parse_memory_limit(
3049 const char *filename
,
3051 const char *section
,
3052 unsigned section_line
,
3059 CGroupContext
*c
= data
;
3060 uint64_t bytes
= CGROUP_LIMIT_MAX
;
3063 if (!isempty(rvalue
) && !streq(rvalue
, "infinity")) {
3065 r
= parse_percent(rvalue
);
3067 r
= parse_size(rvalue
, 1024, &bytes
);
3069 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid memory limit '%s', ignoring: %m", rvalue
);
3073 bytes
= physical_memory_scale(r
, 100U);
3075 if (bytes
>= UINT64_MAX
||
3076 (bytes
<= 0 && !streq(lvalue
, "MemorySwapMax"))) {
3077 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Memory limit '%s' out of range, ignoring.", rvalue
);
3082 if (streq(lvalue
, "MemoryLow"))
3083 c
->memory_low
= bytes
;
3084 else if (streq(lvalue
, "MemoryHigh"))
3085 c
->memory_high
= bytes
;
3086 else if (streq(lvalue
, "MemoryMax"))
3087 c
->memory_max
= bytes
;
3088 else if (streq(lvalue
, "MemorySwapMax"))
3089 c
->memory_swap_max
= bytes
;
3090 else if (streq(lvalue
, "MemoryLimit"))
3091 c
->memory_limit
= bytes
;
3098 int config_parse_tasks_max(
3100 const char *filename
,
3102 const char *section
,
3103 unsigned section_line
,
3110 uint64_t *tasks_max
= data
, v
;
3114 if (isempty(rvalue
)) {
3115 *tasks_max
= u
->manager
->default_tasks_max
;
3119 if (streq(rvalue
, "infinity")) {
3120 *tasks_max
= CGROUP_LIMIT_MAX
;
3124 r
= parse_percent(rvalue
);
3126 r
= safe_atou64(rvalue
, &v
);
3128 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid maximum tasks value '%s', ignoring: %m", rvalue
);
3132 v
= system_tasks_max_scale(r
, 100U);
3134 if (v
<= 0 || v
>= UINT64_MAX
) {
3135 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Maximum tasks value '%s' out of range, ignoring.", rvalue
);
3143 int config_parse_delegate(
3145 const char *filename
,
3147 const char *section
,
3148 unsigned section_line
,
3155 CGroupContext
*c
= data
;
3159 t
= unit_name_to_type(unit
);
3160 assert(t
!= _UNIT_TYPE_INVALID
);
3162 if (!unit_vtable
[t
]->can_delegate
) {
3163 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Delegate= setting not supported for this unit type, ignoring.");
3167 /* We either accept a boolean value, which may be used to turn on delegation for all controllers, or turn it
3168 * off for all. Or it takes a list of controller names, in which case we add the specified controllers to the
3169 * mask to delegate. */
3171 if (isempty(rvalue
)) {
3172 /* An empty string resets controllers and set Delegate=yes. */
3174 c
->delegate_controllers
= 0;
3178 r
= parse_boolean(rvalue
);
3180 const char *p
= rvalue
;
3181 CGroupMask mask
= 0;
3184 _cleanup_free_
char *word
= NULL
;
3185 CGroupController cc
;
3187 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
3193 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid syntax, ignoring: %s", rvalue
);
3197 cc
= cgroup_controller_from_string(word
);
3199 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid controller name '%s', ignoring", word
);
3203 mask
|= CGROUP_CONTROLLER_TO_MASK(cc
);
3207 c
->delegate_controllers
|= mask
;
3211 c
->delegate_controllers
= _CGROUP_MASK_ALL
;
3213 c
->delegate
= false;
3214 c
->delegate_controllers
= 0;
3220 int config_parse_device_allow(
3222 const char *filename
,
3224 const char *section
,
3225 unsigned section_line
,
3232 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3233 CGroupContext
*c
= data
;
3234 CGroupDeviceAllow
*a
;
3235 const char *p
= rvalue
;
3238 if (isempty(rvalue
)) {
3239 while (c
->device_allow
)
3240 cgroup_context_free_device_allow(c
, c
->device_allow
);
3245 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_QUOTES
);
3249 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3250 "Invalid syntax, ignoring: %s", rvalue
);
3254 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3255 "Failed to extract device path and rights from '%s', ignoring.", rvalue
);
3259 r
= unit_full_printf(userdata
, path
, &resolved
);
3261 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3262 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3266 if (!is_deviceallow_pattern(resolved
) &&
3267 !path_startswith(resolved
, "/run/systemd/inaccessible/")) {
3268 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device node path '%s', ignoring.", resolved
);
3272 if (!isempty(p
) && !in_charset(p
, "rwm")) {
3273 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device rights '%s', ignoring.", p
);
3277 a
= new0(CGroupDeviceAllow
, 1);
3281 a
->path
= TAKE_PTR(resolved
);
3282 a
->r
= isempty(p
) || !!strchr(p
, 'r');
3283 a
->w
= isempty(p
) || !!strchr(p
, 'w');
3284 a
->m
= isempty(p
) || !!strchr(p
, 'm');
3286 LIST_PREPEND(device_allow
, c
->device_allow
, a
);
3290 int config_parse_io_device_weight(
3292 const char *filename
,
3294 const char *section
,
3295 unsigned section_line
,
3302 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3303 CGroupIODeviceWeight
*w
;
3304 CGroupContext
*c
= data
;
3305 const char *p
= rvalue
;
3313 if (isempty(rvalue
)) {
3314 while (c
->io_device_weights
)
3315 cgroup_context_free_io_device_weight(c
, c
->io_device_weights
);
3320 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_QUOTES
);
3324 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3325 "Invalid syntax, ignoring: %s", rvalue
);
3328 if (r
== 0 || isempty(p
)) {
3329 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3330 "Failed to extract device path and weight from '%s', ignoring.", rvalue
);
3334 r
= unit_full_printf(userdata
, path
, &resolved
);
3336 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3337 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3341 if (!path_startswith(resolved
, "/dev") &&
3342 !path_startswith(resolved
, "/run/systemd/inaccessible/")) {
3343 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device node path '%s', ignoring.", resolved
);
3347 r
= cg_weight_parse(p
, &u
);
3349 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "IO weight '%s' invalid, ignoring: %m", p
);
3353 assert(u
!= CGROUP_WEIGHT_INVALID
);
3355 w
= new0(CGroupIODeviceWeight
, 1);
3359 w
->path
= TAKE_PTR(resolved
);
3362 LIST_PREPEND(device_weights
, c
->io_device_weights
, w
);
3366 int config_parse_io_limit(
3368 const char *filename
,
3370 const char *section
,
3371 unsigned section_line
,
3378 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3379 CGroupIODeviceLimit
*l
= NULL
, *t
;
3380 CGroupContext
*c
= data
;
3381 CGroupIOLimitType type
;
3382 const char *p
= rvalue
;
3390 type
= cgroup_io_limit_type_from_string(lvalue
);
3393 if (isempty(rvalue
)) {
3394 LIST_FOREACH(device_limits
, l
, c
->io_device_limits
)
3395 l
->limits
[type
] = cgroup_io_limit_defaults
[type
];
3399 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_QUOTES
);
3403 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3404 "Invalid syntax, ignoring: %s", rvalue
);
3407 if (r
== 0 || isempty(p
)) {
3408 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3409 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
3413 r
= unit_full_printf(userdata
, path
, &resolved
);
3415 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3416 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3420 if (!path_startswith(resolved
, "/dev") &&
3421 !path_startswith(resolved
, "/run/systemd/inaccessible/")) {
3422 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device node path '%s', ignoring.", resolved
);
3426 if (streq("infinity", p
)) {
3427 num
= CGROUP_LIMIT_MAX
;
3429 r
= parse_size(p
, 1000, &num
);
3430 if (r
< 0 || num
<= 0) {
3431 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid IO limit '%s', ignoring.", p
);
3436 LIST_FOREACH(device_limits
, t
, c
->io_device_limits
) {
3437 if (path_equal(resolved
, t
->path
)) {
3444 CGroupIOLimitType ttype
;
3446 l
= new0(CGroupIODeviceLimit
, 1);
3450 l
->path
= TAKE_PTR(resolved
);
3451 for (ttype
= 0; ttype
< _CGROUP_IO_LIMIT_TYPE_MAX
; ttype
++)
3452 l
->limits
[ttype
] = cgroup_io_limit_defaults
[ttype
];
3454 LIST_PREPEND(device_limits
, c
->io_device_limits
, l
);
3457 l
->limits
[type
] = num
;
3462 int config_parse_blockio_device_weight(
3464 const char *filename
,
3466 const char *section
,
3467 unsigned section_line
,
3474 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3475 CGroupBlockIODeviceWeight
*w
;
3476 CGroupContext
*c
= data
;
3477 const char *p
= rvalue
;
3485 if (isempty(rvalue
)) {
3486 while (c
->blockio_device_weights
)
3487 cgroup_context_free_blockio_device_weight(c
, c
->blockio_device_weights
);
3492 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_QUOTES
);
3496 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3497 "Invalid syntax, ignoring: %s", rvalue
);
3500 if (r
== 0 || isempty(p
)) {
3501 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3502 "Failed to extract device node and weight from '%s', ignoring.", rvalue
);
3506 r
= unit_full_printf(userdata
, path
, &resolved
);
3508 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3509 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3513 if (!path_startswith(resolved
, "/dev") &&
3514 !path_startswith(resolved
, "/run/systemd/inaccessible/")) {
3515 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device node path '%s'. Ignoring.", resolved
);
3519 r
= cg_blkio_weight_parse(p
, &u
);
3521 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid block IO weight '%s', ignoring: %m", p
);
3525 assert(u
!= CGROUP_BLKIO_WEIGHT_INVALID
);
3527 w
= new0(CGroupBlockIODeviceWeight
, 1);
3531 w
->path
= TAKE_PTR(resolved
);
3534 LIST_PREPEND(device_weights
, c
->blockio_device_weights
, w
);
3538 int config_parse_blockio_bandwidth(
3540 const char *filename
,
3542 const char *section
,
3543 unsigned section_line
,
3550 _cleanup_free_
char *path
= NULL
, *resolved
= NULL
;
3551 CGroupBlockIODeviceBandwidth
*b
= NULL
, *t
;
3552 CGroupContext
*c
= data
;
3553 const char *p
= rvalue
;
3562 read
= streq("BlockIOReadBandwidth", lvalue
);
3564 if (isempty(rvalue
)) {
3565 LIST_FOREACH(device_bandwidths
, b
, c
->blockio_device_bandwidths
) {
3566 b
->rbps
= CGROUP_LIMIT_MAX
;
3567 b
->wbps
= CGROUP_LIMIT_MAX
;
3572 r
= extract_first_word(&p
, &path
, NULL
, EXTRACT_QUOTES
);
3576 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3577 "Invalid syntax, ignoring: %s", rvalue
);
3580 if (r
== 0 || isempty(p
)) {
3581 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
3582 "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue
);
3586 r
= unit_full_printf(userdata
, path
, &resolved
);
3588 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3589 "Failed to resolve unit specifiers in '%s', ignoring: %m", path
);
3593 if (!path_startswith(resolved
, "/dev") &&
3594 !path_startswith(resolved
, "/run/systemd/inaccessible/")) {
3595 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid device node path '%s', ignoring.", resolved
);
3599 r
= parse_size(p
, 1000, &bytes
);
3600 if (r
< 0 || bytes
<= 0) {
3601 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Invalid Block IO Bandwidth '%s', ignoring.", p
);
3605 LIST_FOREACH(device_bandwidths
, t
, c
->blockio_device_bandwidths
) {
3606 if (path_equal(resolved
, t
->path
)) {
3613 b
= new0(CGroupBlockIODeviceBandwidth
, 1);
3617 b
->path
= TAKE_PTR(resolved
);
3618 b
->rbps
= CGROUP_LIMIT_MAX
;
3619 b
->wbps
= CGROUP_LIMIT_MAX
;
3621 LIST_PREPEND(device_bandwidths
, c
->blockio_device_bandwidths
, b
);
3632 int config_parse_job_mode_isolate(
3634 const char *filename
,
3636 const char *section
,
3637 unsigned section_line
,
3651 r
= parse_boolean(rvalue
);
3653 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse boolean, ignoring: %s", rvalue
);
3657 log_notice("%s is deprecated. Please use OnFailureJobMode= instead", lvalue
);
3659 *m
= r
? JOB_ISOLATE
: JOB_REPLACE
;
3663 int config_parse_exec_directories(
3665 const char *filename
,
3667 const char *section
,
3668 unsigned section_line
,
3685 if (isempty(rvalue
)) {
3686 /* Empty assignment resets the list */
3687 *rt
= strv_free(*rt
);
3691 for (p
= rvalue
;;) {
3692 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
3694 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
3698 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
3699 "Invalid syntax, ignoring: %s", rvalue
);
3705 r
= unit_full_printf(u
, word
, &k
);
3707 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
3708 "Failed to resolve unit specifiers in \"%s\", ignoring: %m", word
);
3712 if (!path_is_normalized(k
)) {
3713 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
3714 "%s= path is not normalized, ignoring assignment: %s", lvalue
, rvalue
);
3718 if (path_is_absolute(k
)) {
3719 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
3720 "%s= path is absolute, ignoring assignment: %s", lvalue
, rvalue
);
3724 if (path_startswith(k
, "private")) {
3725 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
3726 "%s= path can't be 'private', ingoring assignment: %s", lvalue
, rvalue
);
3730 r
= strv_push(rt
, k
);
3737 int config_parse_set_status(
3739 const char *filename
,
3741 const char *section
,
3742 unsigned section_line
,
3750 const char *word
, *state
;
3752 ExitStatusSet
*status_set
= data
;
3759 /* Empty assignment resets the list */
3760 if (isempty(rvalue
)) {
3761 exit_status_set_free(status_set
);
3765 FOREACH_WORD(word
, l
, rvalue
, state
) {
3766 _cleanup_free_
char *temp
;
3770 temp
= strndup(word
, l
);
3774 r
= safe_atoi(temp
, &val
);
3776 val
= signal_from_string(temp
);
3779 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse value, ignoring: %s", word
);
3782 set
= &status_set
->signal
;
3784 if (val
< 0 || val
> 255) {
3785 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Value %d is outside range 0-255, ignoring", val
);
3788 set
= &status_set
->status
;
3791 r
= set_ensure_allocated(set
, NULL
);
3795 r
= set_put(*set
, INT_TO_PTR(val
));
3799 if (!isempty(state
))
3800 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Trailing garbage, ignoring.");
3805 int config_parse_namespace_path_strv(
3807 const char *filename
,
3809 const char *section
,
3810 unsigned section_line
,
3819 const char *p
= rvalue
;
3827 if (isempty(rvalue
)) {
3828 /* Empty assignment resets the list */
3829 *sv
= strv_free(*sv
);
3834 _cleanup_free_
char *word
= NULL
, *resolved
= NULL
, *joined
= NULL
;
3836 bool ignore_enoent
= false, shall_prefix
= false;
3838 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
3844 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
3848 if (!utf8_is_valid(word
)) {
3849 log_syntax_invalid_utf8(unit
, LOG_ERR
, filename
, line
, word
);
3854 if (startswith(w
, "-")) {
3855 ignore_enoent
= true;
3858 if (startswith(w
, "+")) {
3859 shall_prefix
= true;
3863 r
= unit_full_printf(u
, w
, &resolved
);
3865 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s: %m", w
);
3869 if (!path_is_absolute(resolved
)) {
3870 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Not an absolute path, ignoring: %s", resolved
);
3874 path_simplify(resolved
, false);
3876 joined
= strjoin(ignore_enoent
? "-" : "",
3877 shall_prefix
? "+" : "",
3880 r
= strv_push(sv
, joined
);
3890 int config_parse_temporary_filesystems(
3892 const char *filename
,
3894 const char *section
,
3895 unsigned section_line
,
3903 ExecContext
*c
= data
;
3904 const char *p
= rvalue
;
3912 if (isempty(rvalue
)) {
3913 /* Empty assignment resets the list */
3914 temporary_filesystem_free_many(c
->temporary_filesystems
, c
->n_temporary_filesystems
);
3915 c
->temporary_filesystems
= NULL
;
3916 c
->n_temporary_filesystems
= 0;
3921 _cleanup_free_
char *word
= NULL
, *path
= NULL
, *resolved
= NULL
;
3924 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_QUOTES
);
3930 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", rvalue
);
3935 r
= extract_first_word(&w
, &path
, ":", EXTRACT_DONT_COALESCE_SEPARATORS
);
3939 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to extract first word, ignoring: %s", word
);
3943 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid syntax, ignoring: %s", word
);
3947 r
= unit_full_printf(u
, path
, &resolved
);
3949 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to resolve unit specifiers in %s, ignoring: %m", path
);
3953 if (!path_is_absolute(resolved
)) {
3954 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Not an absolute path, ignoring: %s", resolved
);
3958 path_simplify(resolved
, false);
3960 r
= temporary_filesystem_add(&c
->temporary_filesystems
, &c
->n_temporary_filesystems
, path
, w
);
3964 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse mount options, ignoring: %s", word
);
3970 int config_parse_bind_paths(
3972 const char *filename
,
3974 const char *section
,
3975 unsigned section_line
,
3982 ExecContext
*c
= data
;
3992 if (isempty(rvalue
)) {
3993 /* Empty assignment resets the list */
3994 bind_mount_free_many(c
->bind_mounts
, c
->n_bind_mounts
);
3995 c
->bind_mounts
= NULL
;
3996 c
->n_bind_mounts
= 0;
4002 _cleanup_free_
char *source
= NULL
, *destination
= NULL
;
4003 _cleanup_free_
char *sresolved
= NULL
, *dresolved
= NULL
;
4004 char *s
= NULL
, *d
= NULL
;
4005 bool rbind
= true, ignore_enoent
= false;
4007 r
= extract_first_word(&p
, &source
, ":" WHITESPACE
, EXTRACT_QUOTES
|EXTRACT_DONT_COALESCE_SEPARATORS
);
4013 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s: %s", lvalue
, rvalue
);
4017 r
= unit_full_printf(u
, source
, &sresolved
);
4019 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4020 "Failed to resolved unit specifiers in \"%s\", ignoring: %m", source
);
4026 ignore_enoent
= true;
4030 if (!utf8_is_valid(s
)) {
4031 log_syntax_invalid_utf8(unit
, LOG_ERR
, filename
, line
, s
);
4034 if (!path_is_absolute(s
)) {
4035 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Not an absolute source path, ignoring: %s", s
);
4039 path_simplify(s
, false);
4041 /* Optionally, the destination is specified. */
4042 if (p
&& p
[-1] == ':') {
4043 r
= extract_first_word(&p
, &destination
, ":" WHITESPACE
, EXTRACT_QUOTES
|EXTRACT_DONT_COALESCE_SEPARATORS
);
4047 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s: %s", lvalue
, rvalue
);
4051 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Missing argument after ':': %s", rvalue
);
4055 r
= unit_full_printf(u
, destination
, &dresolved
);
4057 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
4058 "Failed to resolved specifiers in \"%s\", ignoring: %m", destination
);
4062 if (!utf8_is_valid(dresolved
)) {
4063 log_syntax_invalid_utf8(unit
, LOG_ERR
, filename
, line
, dresolved
);
4066 if (!path_is_absolute(dresolved
)) {
4067 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Not an absolute destination path, ignoring: %s", dresolved
);
4071 d
= path_simplify(dresolved
, false);
4073 /* Optionally, there's also a short option string specified */
4074 if (p
&& p
[-1] == ':') {
4075 _cleanup_free_
char *options
= NULL
;
4077 r
= extract_first_word(&p
, &options
, NULL
, EXTRACT_QUOTES
);
4081 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse %s: %s", lvalue
, rvalue
);
4085 if (isempty(options
) || streq(options
, "rbind"))
4087 else if (streq(options
, "norbind"))
4090 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Invalid option string, ignoring setting: %s", options
);
4097 r
= bind_mount_add(&c
->bind_mounts
, &c
->n_bind_mounts
,
4101 .read_only
= !!strstr(lvalue
, "ReadOnly"),
4103 .ignore_enoent
= ignore_enoent
,
4112 int config_parse_job_timeout_sec(
4114 const char *filename
,
4116 const char *section
,
4117 unsigned section_line
,
4133 r
= parse_sec_fix_0(rvalue
, &usec
);
4135 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse JobTimeoutSec= parameter, ignoring: %s", rvalue
);
4139 /* If the user explicitly changed JobTimeoutSec= also change JobRunningTimeoutSec=, for compatibility with old
4140 * versions. If JobRunningTimeoutSec= was explicitly set, avoid this however as whatever the user picked should
4143 if (!u
->job_running_timeout_set
)
4144 u
->job_running_timeout
= usec
;
4146 u
->job_timeout
= usec
;
4151 int config_parse_job_running_timeout_sec(
4153 const char *filename
,
4155 const char *section
,
4156 unsigned section_line
,
4172 r
= parse_sec_fix_0(rvalue
, &usec
);
4174 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse JobRunningTimeoutSec= parameter, ignoring: %s", rvalue
);
4178 u
->job_running_timeout
= usec
;
4179 u
->job_running_timeout_set
= true;
4184 #define FOLLOW_MAX 8
4186 static int open_follow(char **filename
, FILE **_f
, Set
*names
, char **_final
) {
4197 /* This will update the filename pointer if the loaded file is
4198 * reached by a symlink. The old string will be freed. */
4201 char *target
, *name
;
4203 if (c
++ >= FOLLOW_MAX
)
4206 path_simplify(*filename
, false);
4208 /* Add the file name we are currently looking at to
4209 * the names of this unit, but only if it is a valid
4211 name
= basename(*filename
);
4212 if (unit_name_is_valid(name
, UNIT_NAME_ANY
)) {
4214 id
= set_get(names
, name
);
4220 r
= set_consume(names
, id
);
4226 /* Try to open the file name, but don't if its a symlink */
4227 fd
= open(*filename
, O_RDONLY
|O_CLOEXEC
|O_NOCTTY
|O_NOFOLLOW
);
4234 /* Hmm, so this is a symlink. Let's read the name, and follow it manually */
4235 r
= readlink_and_make_absolute(*filename
, &target
);
4239 free_and_replace(*filename
, target
);
4242 f
= fdopen(fd
, "re");
4254 static int merge_by_names(Unit
**u
, Set
*names
, const char *id
) {
4262 /* Let's try to add in all symlink names we found */
4263 while ((k
= set_steal_first(names
))) {
4265 /* First try to merge in the other name into our
4267 r
= unit_merge_by_name(*u
, k
);
4271 /* Hmm, we couldn't merge the other unit into
4272 * ours? Then let's try it the other way
4275 /* If the symlink name we are looking at is unit template, then
4276 we must search for instance of this template */
4277 if (unit_name_is_valid(k
, UNIT_NAME_TEMPLATE
) && (*u
)->instance
) {
4278 _cleanup_free_
char *instance
= NULL
;
4280 r
= unit_name_replace_instance(k
, (*u
)->instance
, &instance
);
4284 other
= manager_get_unit((*u
)->manager
, instance
);
4286 other
= manager_get_unit((*u
)->manager
, k
);
4291 r
= unit_merge(other
, *u
);
4294 return merge_by_names(u
, names
, NULL
);
4302 unit_choose_id(*u
, id
);
4310 static int load_from_path(Unit
*u
, const char *path
) {
4311 _cleanup_set_free_free_ Set
*symlink_names
= NULL
;
4312 _cleanup_fclose_
FILE *f
= NULL
;
4313 _cleanup_free_
char *filename
= NULL
;
4322 symlink_names
= set_new(&string_hash_ops
);
4326 if (path_is_absolute(path
)) {
4328 filename
= strdup(path
);
4332 r
= open_follow(&filename
, &f
, symlink_names
, &id
);
4334 filename
= mfree(filename
);
4342 STRV_FOREACH(p
, u
->manager
->lookup_paths
.search_path
) {
4344 /* Instead of opening the path right away, we manually
4345 * follow all symlinks and add their name to our unit
4346 * name set while doing so */
4347 filename
= path_make_absolute(path
, *p
);
4351 if (u
->manager
->unit_path_cache
&&
4352 !set_get(u
->manager
->unit_path_cache
, filename
))
4355 r
= open_follow(&filename
, &f
, symlink_names
, &id
);
4358 filename
= mfree(filename
);
4360 /* ENOENT means that the file is missing or is a dangling symlink.
4361 * ENOTDIR means that one of paths we expect to be is a directory
4362 * is not a directory, we should just ignore that.
4363 * EACCES means that the directory or file permissions are wrong.
4366 log_debug_errno(r
, "Cannot access \"%s\": %m", filename
);
4367 else if (!IN_SET(r
, -ENOENT
, -ENOTDIR
))
4370 /* Empty the symlink names for the next run */
4371 set_clear_free(symlink_names
);
4376 /* Hmm, no suitable file found? */
4379 if (!unit_type_may_alias(u
->type
) && set_size(symlink_names
) > 1) {
4380 log_unit_warning(u
, "Unit type of %s does not support alias names, refusing loading via symlink.", u
->id
);
4385 r
= merge_by_names(&merged
, symlink_names
, id
);
4390 u
->load_state
= UNIT_MERGED
;
4394 if (fstat(fileno(f
), &st
) < 0)
4397 if (null_or_empty(&st
)) {
4398 u
->load_state
= UNIT_MASKED
;
4399 u
->fragment_mtime
= 0;
4401 u
->load_state
= UNIT_LOADED
;
4402 u
->fragment_mtime
= timespec_load(&st
.st_mtim
);
4404 /* Now, parse the file contents */
4405 r
= config_parse(u
->id
, filename
, f
,
4406 UNIT_VTABLE(u
)->sections
,
4407 config_item_perf_lookup
, load_fragment_gperf_lookup
,
4408 CONFIG_PARSE_ALLOW_INCLUDE
, u
);
4413 free_and_replace(u
->fragment_path
, filename
);
4415 if (u
->source_path
) {
4416 if (stat(u
->source_path
, &st
) >= 0)
4417 u
->source_mtime
= timespec_load(&st
.st_mtim
);
4419 u
->source_mtime
= 0;
4425 int unit_load_fragment(Unit
*u
) {
4431 assert(u
->load_state
== UNIT_STUB
);
4435 u
->load_state
= UNIT_LOADED
;
4439 /* First, try to find the unit under its id. We always look
4440 * for unit files in the default directories, to make it easy
4441 * to override things by placing things in /etc/systemd/system */
4442 r
= load_from_path(u
, u
->id
);
4446 /* Try to find an alias we can load this with */
4447 if (u
->load_state
== UNIT_STUB
) {
4448 SET_FOREACH(t
, u
->names
, i
) {
4453 r
= load_from_path(u
, t
);
4457 if (u
->load_state
!= UNIT_STUB
)
4462 /* And now, try looking for it under the suggested (originally linked) path */
4463 if (u
->load_state
== UNIT_STUB
&& u
->fragment_path
) {
4465 r
= load_from_path(u
, u
->fragment_path
);
4469 if (u
->load_state
== UNIT_STUB
)
4470 /* Hmm, this didn't work? Then let's get rid
4471 * of the fragment path stored for us, so that
4472 * we don't point to an invalid location. */
4473 u
->fragment_path
= mfree(u
->fragment_path
);
4476 /* Look for a template */
4477 if (u
->load_state
== UNIT_STUB
&& u
->instance
) {
4478 _cleanup_free_
char *k
= NULL
;
4480 r
= unit_name_template(u
->id
, &k
);
4484 r
= load_from_path(u
, k
);
4487 log_unit_notice(u
, "Unit configuration has fatal error, unit will not be started.");
4491 if (u
->load_state
== UNIT_STUB
) {
4492 SET_FOREACH(t
, u
->names
, i
) {
4493 _cleanup_free_
char *z
= NULL
;
4498 r
= unit_name_template(t
, &z
);
4502 r
= load_from_path(u
, z
);
4506 if (u
->load_state
!= UNIT_STUB
)
4515 void unit_dump_config_items(FILE *f
) {
4516 static const struct {
4517 const ConfigParserCallback callback
;
4520 { config_parse_warn_compat
, "NOTSUPPORTED" },
4521 { config_parse_int
, "INTEGER" },
4522 { config_parse_unsigned
, "UNSIGNED" },
4523 { config_parse_iec_size
, "SIZE" },
4524 { config_parse_iec_uint64
, "SIZE" },
4525 { config_parse_si_size
, "SIZE" },
4526 { config_parse_bool
, "BOOLEAN" },
4527 { config_parse_string
, "STRING" },
4528 { config_parse_path
, "PATH" },
4529 { config_parse_unit_path_printf
, "PATH" },
4530 { config_parse_strv
, "STRING [...]" },
4531 { config_parse_exec_nice
, "NICE" },
4532 { config_parse_exec_oom_score_adjust
, "OOMSCOREADJUST" },
4533 { config_parse_exec_io_class
, "IOCLASS" },
4534 { config_parse_exec_io_priority
, "IOPRIORITY" },
4535 { config_parse_exec_cpu_sched_policy
, "CPUSCHEDPOLICY" },
4536 { config_parse_exec_cpu_sched_prio
, "CPUSCHEDPRIO" },
4537 { config_parse_exec_cpu_affinity
, "CPUAFFINITY" },
4538 { config_parse_mode
, "MODE" },
4539 { config_parse_unit_env_file
, "FILE" },
4540 { config_parse_exec_output
, "OUTPUT" },
4541 { config_parse_exec_input
, "INPUT" },
4542 { config_parse_log_facility
, "FACILITY" },
4543 { config_parse_log_level
, "LEVEL" },
4544 { config_parse_exec_secure_bits
, "SECUREBITS" },
4545 { config_parse_capability_set
, "BOUNDINGSET" },
4546 { config_parse_rlimit
, "LIMIT" },
4547 { config_parse_unit_deps
, "UNIT [...]" },
4548 { config_parse_exec
, "PATH [ARGUMENT [...]]" },
4549 { config_parse_service_type
, "SERVICETYPE" },
4550 { config_parse_service_restart
, "SERVICERESTART" },
4551 { config_parse_kill_mode
, "KILLMODE" },
4552 { config_parse_signal
, "SIGNAL" },
4553 { config_parse_socket_listen
, "SOCKET [...]" },
4554 { config_parse_socket_bind
, "SOCKETBIND" },
4555 { config_parse_socket_bindtodevice
, "NETWORKINTERFACE" },
4556 { config_parse_sec
, "SECONDS" },
4557 { config_parse_nsec
, "NANOSECONDS" },
4558 { config_parse_namespace_path_strv
, "PATH [...]" },
4559 { config_parse_bind_paths
, "PATH[:PATH[:OPTIONS]] [...]" },
4560 { config_parse_unit_requires_mounts_for
, "PATH [...]" },
4561 { config_parse_exec_mount_flags
, "MOUNTFLAG [...]" },
4562 { config_parse_unit_string_printf
, "STRING" },
4563 { config_parse_trigger_unit
, "UNIT" },
4564 { config_parse_timer
, "TIMER" },
4565 { config_parse_path_spec
, "PATH" },
4566 { config_parse_notify_access
, "ACCESS" },
4567 { config_parse_ip_tos
, "TOS" },
4568 { config_parse_unit_condition_path
, "CONDITION" },
4569 { config_parse_unit_condition_string
, "CONDITION" },
4570 { config_parse_unit_condition_null
, "CONDITION" },
4571 { config_parse_unit_slice
, "SLICE" },
4572 { config_parse_documentation
, "URL" },
4573 { config_parse_service_timeout
, "SECONDS" },
4574 { config_parse_emergency_action
, "ACTION" },
4575 { config_parse_set_status
, "STATUS" },
4576 { config_parse_service_sockets
, "SOCKETS" },
4577 { config_parse_environ
, "ENVIRON" },
4579 { config_parse_syscall_filter
, "SYSCALLS" },
4580 { config_parse_syscall_archs
, "ARCHS" },
4581 { config_parse_syscall_errno
, "ERRNO" },
4582 { config_parse_address_families
, "FAMILIES" },
4583 { config_parse_restrict_namespaces
, "NAMESPACES" },
4585 { config_parse_cpu_shares
, "SHARES" },
4586 { config_parse_cg_weight
, "WEIGHT" },
4587 { config_parse_memory_limit
, "LIMIT" },
4588 { config_parse_device_allow
, "DEVICE" },
4589 { config_parse_device_policy
, "POLICY" },
4590 { config_parse_io_limit
, "LIMIT" },
4591 { config_parse_io_device_weight
, "DEVICEWEIGHT" },
4592 { config_parse_blockio_bandwidth
, "BANDWIDTH" },
4593 { config_parse_blockio_weight
, "WEIGHT" },
4594 { config_parse_blockio_device_weight
, "DEVICEWEIGHT" },
4595 { config_parse_long
, "LONG" },
4596 { config_parse_socket_service
, "SERVICE" },
4598 { config_parse_exec_selinux_context
, "LABEL" },
4600 { config_parse_job_mode
, "MODE" },
4601 { config_parse_job_mode_isolate
, "BOOLEAN" },
4602 { config_parse_personality
, "PERSONALITY" },
4605 const char *prev
= NULL
;
4610 NULSTR_FOREACH(i
, load_fragment_gperf_nulstr
) {
4611 const char *rvalue
= "OTHER", *lvalue
;
4612 const ConfigPerfItem
*p
;
4617 assert_se(p
= load_fragment_gperf_lookup(i
, strlen(i
)));
4619 /* Hide legacy settings */
4620 if (p
->parse
== config_parse_warn_compat
&&
4621 p
->ltype
== DISABLED_LEGACY
)
4624 for (j
= 0; j
< ELEMENTSOF(table
); j
++)
4625 if (p
->parse
== table
[j
].callback
) {
4626 rvalue
= table
[j
].rvalue
;
4630 dot
= strchr(i
, '.');
4631 lvalue
= dot
? dot
+ 1 : i
;
4635 if (!prev
|| !strneq(prev
, i
, prefix_len
+1)) {
4639 fprintf(f
, "[%.*s]\n", (int) prefix_len
, i
);
4642 fprintf(f
, "%s=%s\n", lvalue
, rvalue
);