1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2010 Lennart Poettering
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 #include <linux/oom.h>
29 #include <sys/prctl.h>
30 #include <sys/mount.h>
36 #include "conf-parser.h"
37 #include "load-fragment.h"
40 #include "securebits.h"
42 #include "unit-name.h"
43 #include "bus-errors.h"
45 #ifndef HAVE_SYSV_COMPAT
46 static int config_parse_warn_compat(
55 log_debug("[%s:%u] Support for option %s= has been disabled at compile time and is ignored", filename
, line
, lvalue
);
60 static int config_parse_deps(
69 UnitDependency d
= PTR_TO_UINT(data
);
79 FOREACH_WORD_QUOTED(w
, l
, rvalue
, state
) {
83 if (!(t
= strndup(w
, l
)))
86 k
= unit_name_printf(u
, t
);
92 r
= unit_add_dependency_by_name(u
, d
, k
, NULL
, true);
95 log_error("Failed to add dependency on %s, ignoring: %s", k
, strerror(-r
));
106 static int config_parse_names(
107 const char *filename
,
125 FOREACH_WORD_QUOTED(w
, l
, rvalue
, state
) {
129 if (!(t
= strndup(w
, l
)))
132 k
= unit_name_printf(u
, t
);
138 r
= unit_merge_by_name(u
, k
);
141 log_error("Failed to add name %s, ignoring: %s", k
, strerror(-r
));
152 static int config_parse_string_printf(
153 const char *filename
,
171 if (!(k
= unit_full_printf(u
, rvalue
)))
185 static int config_parse_listen(
186 const char *filename
,
204 if (!(p
= new0(SocketPort
, 1)))
207 if (streq(lvalue
, "ListenFIFO")) {
208 p
->type
= SOCKET_FIFO
;
210 if (!(p
->path
= strdup(rvalue
))) {
215 path_kill_slashes(p
->path
);
217 p
->type
= SOCKET_SOCKET
;
219 if (socket_address_parse(&p
->address
, rvalue
) < 0) {
220 log_error("[%s:%u] Failed to parse address value, ignoring: %s", filename
, line
, rvalue
);
225 if (streq(lvalue
, "ListenStream"))
226 p
->address
.type
= SOCK_STREAM
;
227 else if (streq(lvalue
, "ListenDatagram"))
228 p
->address
.type
= SOCK_DGRAM
;
230 assert(streq(lvalue
, "ListenSequentialPacket"));
231 p
->address
.type
= SOCK_SEQPACKET
;
234 if (socket_address_family(&p
->address
) != AF_LOCAL
&& p
->address
.type
== SOCK_SEQPACKET
) {
235 log_error("[%s:%u] Address family not supported, ignoring: %s", filename
, line
, rvalue
);
242 LIST_PREPEND(SocketPort
, port
, s
->ports
, p
);
247 static int config_parse_socket_bind(
248 const char *filename
,
257 SocketAddressBindIPv6Only b
;
266 if ((b
= socket_address_bind_ipv6_only_from_string(rvalue
)) < 0) {
269 if ((r
= parse_boolean(rvalue
)) < 0) {
270 log_error("[%s:%u] Failed to parse bind IPv6 only value, ignoring: %s", filename
, line
, rvalue
);
274 s
->bind_ipv6_only
= r
? SOCKET_ADDRESS_IPV6_ONLY
: SOCKET_ADDRESS_BOTH
;
276 s
->bind_ipv6_only
= b
;
281 static int config_parse_nice(
282 const char *filename
,
290 ExecContext
*c
= data
;
298 if (safe_atoi(rvalue
, &priority
) < 0) {
299 log_error("[%s:%u] Failed to parse nice priority, ignoring: %s. ", filename
, line
, rvalue
);
303 if (priority
< PRIO_MIN
|| priority
>= PRIO_MAX
) {
304 log_error("[%s:%u] Nice priority out of range, ignoring: %s", filename
, line
, rvalue
);
314 static int config_parse_oom_score_adjust(
315 const char *filename
,
323 ExecContext
*c
= data
;
331 if (safe_atoi(rvalue
, &oa
) < 0) {
332 log_error("[%s:%u] Failed to parse the OOM score adjust value, ignoring: %s", filename
, line
, rvalue
);
336 if (oa
< OOM_SCORE_ADJ_MIN
|| oa
> OOM_SCORE_ADJ_MAX
) {
337 log_error("[%s:%u] OOM score adjust value out of range, ignoring: %s", filename
, line
, rvalue
);
341 c
->oom_score_adjust
= oa
;
342 c
->oom_score_adjust_set
= true;
347 static int config_parse_mode(
348 const char *filename
,
366 l
= strtol(rvalue
, &x
, 8);
367 if (!x
|| *x
|| errno
) {
368 log_error("[%s:%u] Failed to parse mode value, ignoring: %s", filename
, line
, rvalue
);
372 if (l
< 0000 || l
> 07777) {
373 log_error("[%s:%u] mode value out of range, ignoring: %s", filename
, line
, rvalue
);
381 static int config_parse_exec(
382 const char *filename
,
390 ExecCommand
**e
= data
, *nce
;
399 /* We accept an absolute path as first argument, or
400 * alternatively an absolute prefixed with @ to allow
401 * overriding of argv[0]. */
407 bool honour_argv0
= false, ignore
= false;
413 rvalue
+= strspn(rvalue
, WHITESPACE
);
418 if (rvalue
[0] == '-') {
423 if (rvalue
[0] == '@') {
428 if (*rvalue
!= '/') {
429 log_error("[%s:%u] Invalid executable path in command line, ignoring: %s", filename
, line
, rvalue
);
434 FOREACH_WORD_QUOTED(w
, l
, rvalue
, state
) {
435 if (strncmp(w
, ";", MAX(l
, 1U)) == 0)
441 if (!(n
= new(char*, k
+ !honour_argv0
)))
445 FOREACH_WORD_QUOTED(w
, l
, rvalue
, state
) {
446 if (strncmp(w
, ";", MAX(l
, 1U)) == 0)
449 if (honour_argv0
&& w
== rvalue
) {
451 if (!(path
= cunescape_length(w
, l
)))
454 if (!(n
[k
++] = cunescape_length(w
, l
)))
462 log_error("[%s:%u] Invalid command line, ignoring: %s", filename
, line
, rvalue
);
468 if (!(path
= strdup(n
[0])))
471 assert(path_is_absolute(path
));
473 if (!(nce
= new0(ExecCommand
, 1)))
478 nce
->ignore
= ignore
;
480 path_kill_slashes(nce
->path
);
482 exec_command_append_list(e
, nce
);
498 static int config_parse_usec(
499 const char *filename
,
514 if (parse_usec(rvalue
, usec
) < 0) {
515 log_error("[%s:%u] Failed to parse time value, ignoring: %s", filename
, line
, rvalue
);
522 static DEFINE_CONFIG_PARSE_ENUM(config_parse_service_type
, service_type
, ServiceType
, "Failed to parse service type");
523 static DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart
, service_restart
, ServiceRestart
, "Failed to parse service restart specifier");
525 static int config_parse_bindtodevice(
526 const char *filename
,
542 if (rvalue
[0] && !streq(rvalue
, "*")) {
543 if (!(n
= strdup(rvalue
)))
548 free(s
->bind_to_device
);
549 s
->bind_to_device
= n
;
554 static DEFINE_CONFIG_PARSE_ENUM(config_parse_output
, exec_output
, ExecOutput
, "Failed to parse output specifier");
555 static DEFINE_CONFIG_PARSE_ENUM(config_parse_input
, exec_input
, ExecInput
, "Failed to parse input specifier");
557 static int config_parse_facility(
558 const char *filename
,
574 if ((x
= log_facility_from_string(rvalue
)) < 0) {
575 log_error("[%s:%u] Failed to parse log facility, ignoring: %s", filename
, line
, rvalue
);
579 *o
= LOG_MAKEPRI(x
, LOG_PRI(*o
));
584 static int config_parse_level(
585 const char *filename
,
601 if ((x
= log_level_from_string(rvalue
)) < 0) {
602 log_error("[%s:%u] Failed to parse log level, ignoring: %s", filename
, line
, rvalue
);
606 *o
= LOG_MAKEPRI(LOG_FAC(*o
), x
);
610 static int config_parse_io_class(
611 const char *filename
,
619 ExecContext
*c
= data
;
627 if ((x
= ioprio_class_from_string(rvalue
)) < 0) {
628 log_error("[%s:%u] Failed to parse IO scheduling class, ignoring: %s", filename
, line
, rvalue
);
632 c
->ioprio
= IOPRIO_PRIO_VALUE(x
, IOPRIO_PRIO_DATA(c
->ioprio
));
633 c
->ioprio_set
= true;
638 static int config_parse_io_priority(
639 const char *filename
,
647 ExecContext
*c
= data
;
655 if (safe_atoi(rvalue
, &i
) < 0 || i
< 0 || i
>= IOPRIO_BE_NR
) {
656 log_error("[%s:%u] Failed to parse io priority, ignoring: %s", filename
, line
, rvalue
);
660 c
->ioprio
= IOPRIO_PRIO_VALUE(IOPRIO_PRIO_CLASS(c
->ioprio
), i
);
661 c
->ioprio_set
= true;
666 static int config_parse_cpu_sched_policy(
667 const char *filename
,
676 ExecContext
*c
= data
;
684 if ((x
= sched_policy_from_string(rvalue
)) < 0) {
685 log_error("[%s:%u] Failed to parse CPU scheduling policy, ignoring: %s", filename
, line
, rvalue
);
689 c
->cpu_sched_policy
= x
;
690 c
->cpu_sched_set
= true;
695 static int config_parse_cpu_sched_prio(
696 const char *filename
,
704 ExecContext
*c
= data
;
712 /* On Linux RR/FIFO have the same range */
713 if (safe_atoi(rvalue
, &i
) < 0 || i
< sched_get_priority_min(SCHED_RR
) || i
> sched_get_priority_max(SCHED_RR
)) {
714 log_error("[%s:%u] Failed to parse CPU scheduling priority, ignoring: %s", filename
, line
, rvalue
);
718 c
->cpu_sched_priority
= i
;
719 c
->cpu_sched_set
= true;
724 static int config_parse_cpu_affinity(
725 const char *filename
,
733 ExecContext
*c
= data
;
743 FOREACH_WORD_QUOTED(w
, l
, rvalue
, state
) {
748 if (!(t
= strndup(w
, l
)))
751 r
= safe_atou(t
, &cpu
);
755 if (!(c
->cpuset
= cpu_set_malloc(&c
->cpuset_ncpus
)))
758 if (r
< 0 || cpu
>= c
->cpuset_ncpus
) {
759 log_error("[%s:%u] Failed to parse CPU affinity, ignoring: %s", filename
, line
, rvalue
);
763 CPU_SET_S(cpu
, CPU_ALLOC_SIZE(c
->cpuset_ncpus
), c
->cpuset
);
769 static int config_parse_capabilities(
770 const char *filename
,
778 ExecContext
*c
= data
;
786 if (!(cap
= cap_from_text(rvalue
))) {
790 log_error("[%s:%u] Failed to parse capabilities, ignoring: %s", filename
, line
, rvalue
);
795 cap_free(c
->capabilities
);
796 c
->capabilities
= cap
;
801 static int config_parse_secure_bits(
802 const char *filename
,
810 ExecContext
*c
= data
;
820 FOREACH_WORD_QUOTED(w
, l
, rvalue
, state
) {
821 if (first_word(w
, "keep-caps"))
822 c
->secure_bits
|= SECURE_KEEP_CAPS
;
823 else if (first_word(w
, "keep-caps-locked"))
824 c
->secure_bits
|= SECURE_KEEP_CAPS_LOCKED
;
825 else if (first_word(w
, "no-setuid-fixup"))
826 c
->secure_bits
|= SECURE_NO_SETUID_FIXUP
;
827 else if (first_word(w
, "no-setuid-fixup-locked"))
828 c
->secure_bits
|= SECURE_NO_SETUID_FIXUP_LOCKED
;
829 else if (first_word(w
, "noroot"))
830 c
->secure_bits
|= SECURE_NOROOT
;
831 else if (first_word(w
, "noroot-locked"))
832 c
->secure_bits
|= SECURE_NOROOT_LOCKED
;
834 log_error("[%s:%u] Failed to parse secure bits, ignoring: %s", filename
, line
, rvalue
);
842 static int config_parse_bounding_set(
843 const char *filename
,
851 ExecContext
*c
= data
;
861 FOREACH_WORD_QUOTED(w
, l
, rvalue
, state
) {
866 if (!(t
= strndup(w
, l
)))
869 r
= cap_from_name(t
, &cap
);
873 log_error("[%s:%u] Failed to parse capability bounding set, ignoring: %s", filename
, line
, rvalue
);
877 c
->capability_bounding_set_drop
|= 1 << cap
;
883 static int config_parse_timer_slack_nsec(
884 const char *filename
,
892 ExecContext
*c
= data
;
900 if (safe_atolu(rvalue
, &u
) < 0) {
901 log_error("[%s:%u] Failed to parse time slack value, ignoring: %s", filename
, line
, rvalue
);
905 c
->timer_slack_nsec
= u
;
910 static int config_parse_limit(
911 const char *filename
,
919 struct rlimit
**rl
= data
;
920 unsigned long long u
;
927 if (safe_atollu(rvalue
, &u
) < 0) {
928 log_error("[%s:%u] Failed to parse resource value, ignoring: %s", filename
, line
, rvalue
);
933 if (!(*rl
= new(struct rlimit
, 1)))
936 (*rl
)->rlim_cur
= (*rl
)->rlim_max
= (rlim_t
) u
;
940 static int config_parse_cgroup(
941 const char *filename
,
954 FOREACH_WORD_QUOTED(w
, l
, rvalue
, state
) {
958 if (!(t
= cunescape_length(w
, l
)))
961 r
= unit_add_cgroup_from_text(u
, t
);
965 log_error("[%s:%u] Failed to parse cgroup value, ignoring: %s", filename
, line
, rvalue
);
973 #ifdef HAVE_SYSV_COMPAT
974 static int config_parse_sysv_priority(
975 const char *filename
,
983 int *priority
= data
;
991 if (safe_atoi(rvalue
, &i
) < 0 || i
< 0) {
992 log_error("[%s:%u] Failed to parse SysV start priority, ignoring: %s", filename
, line
, rvalue
);
1001 static int config_parse_fsck_passno(
1002 const char *filename
,
1004 const char *section
,
1018 if (safe_atoi(rvalue
, &i
) || i
< 0) {
1019 log_error("[%s:%u] Failed to parse fsck pass number, ignoring: %s", filename
, line
, rvalue
);
1027 static DEFINE_CONFIG_PARSE_ENUM(config_parse_kill_mode
, kill_mode
, KillMode
, "Failed to parse kill mode");
1029 static int config_parse_kill_signal(
1030 const char *filename
,
1032 const char *section
,
1046 if ((r
= signal_from_string_try_harder(rvalue
)) <= 0) {
1047 log_error("[%s:%u] Failed to parse kill signal, ignoring: %s", filename
, line
, rvalue
);
1055 static int config_parse_mount_flags(
1056 const char *filename
,
1058 const char *section
,
1064 ExecContext
*c
= data
;
1068 unsigned long flags
= 0;
1075 FOREACH_WORD_QUOTED(w
, l
, rvalue
, state
) {
1076 if (strncmp(w
, "shared", MAX(l
, 6U)) == 0)
1078 else if (strncmp(w
, "slave", MAX(l
, 5U)) == 0)
1080 else if (strncmp(w
, "private", MAX(l
, 7U)) == 0)
1081 flags
|= MS_PRIVATE
;
1083 log_error("[%s:%u] Failed to parse mount flags, ignoring: %s", filename
, line
, rvalue
);
1088 c
->mount_flags
= flags
;
1092 static int config_parse_timer(
1093 const char *filename
,
1095 const char *section
,
1111 if ((b
= timer_base_from_string(lvalue
)) < 0) {
1112 log_error("[%s:%u] Failed to parse timer base, ignoring: %s", filename
, line
, lvalue
);
1116 if (parse_usec(rvalue
, &u
) < 0) {
1117 log_error("[%s:%u] Failed to parse timer value, ignoring: %s", filename
, line
, rvalue
);
1121 if (!(v
= new0(TimerValue
, 1)))
1127 LIST_PREPEND(TimerValue
, value
, t
->values
, v
);
1132 static int config_parse_timer_unit(
1133 const char *filename
,
1135 const char *section
,
1150 dbus_error_init(&error
);
1152 if (endswith(rvalue
, ".timer")) {
1153 log_error("[%s:%u] Unit cannot be of type timer, ignoring: %s", filename
, line
, rvalue
);
1157 if ((r
= manager_load_unit(t
->meta
.manager
, rvalue
, NULL
, NULL
, &t
->unit
)) < 0) {
1158 log_error("[%s:%u] Failed to load unit %s, ignoring: %s", filename
, line
, rvalue
, bus_error(&error
, r
));
1159 dbus_error_free(&error
);
1166 static int config_parse_path_spec(
1167 const char *filename
,
1169 const char *section
,
1184 if ((b
= path_type_from_string(lvalue
)) < 0) {
1185 log_error("[%s:%u] Failed to parse path type, ignoring: %s", filename
, line
, lvalue
);
1189 if (!path_is_absolute(rvalue
)) {
1190 log_error("[%s:%u] Path is not absolute, ignoring: %s", filename
, line
, rvalue
);
1194 if (!(s
= new0(PathSpec
, 1)))
1197 if (!(s
->path
= strdup(rvalue
))) {
1202 path_kill_slashes(s
->path
);
1207 LIST_PREPEND(PathSpec
, spec
, p
->specs
, s
);
1212 static int config_parse_path_unit(
1213 const char *filename
,
1215 const char *section
,
1230 dbus_error_init(&error
);
1232 if (endswith(rvalue
, ".path")) {
1233 log_error("[%s:%u] Unit cannot be of type path, ignoring: %s", filename
, line
, rvalue
);
1237 if ((r
= manager_load_unit(t
->meta
.manager
, rvalue
, NULL
, &error
, &t
->unit
)) < 0) {
1238 log_error("[%s:%u] Failed to load unit %s, ignoring: %s", filename
, line
, rvalue
, bus_error(&error
, r
));
1239 dbus_error_free(&error
);
1246 static int config_parse_socket_service(
1247 const char *filename
,
1249 const char *section
,
1264 dbus_error_init(&error
);
1266 if (!endswith(rvalue
, ".service")) {
1267 log_error("[%s:%u] Unit must be of type service, ignoring: %s", filename
, line
, rvalue
);
1271 if ((r
= manager_load_unit(s
->meta
.manager
, rvalue
, NULL
, &error
, (Unit
**) &s
->service
)) < 0) {
1272 log_error("[%s:%u] Failed to load unit %s, ignoring: %s", filename
, line
, rvalue
, bus_error(&error
, r
));
1273 dbus_error_free(&error
);
1280 static int config_parse_service_sockets(
1281 const char *filename
,
1283 const char *section
,
1300 dbus_error_init(&error
);
1302 FOREACH_WORD_QUOTED(w
, l
, rvalue
, state
) {
1306 if (!(t
= strndup(w
, l
)))
1309 if (!endswith(t
, ".socket")) {
1310 log_error("[%s:%u] Unit must be of type socket, ignoring: %s", filename
, line
, rvalue
);
1315 r
= manager_load_unit(s
->meta
.manager
, t
, NULL
, &error
, &sock
);
1319 log_error("[%s:%u] Failed to load unit %s, ignoring: %s", filename
, line
, rvalue
, bus_error(&error
, r
));
1320 dbus_error_free(&error
);
1324 if ((r
= set_ensure_allocated(&s
->configured_sockets
, trivial_hash_func
, trivial_compare_func
)) < 0)
1327 if ((r
= set_put(s
->configured_sockets
, sock
)) < 0)
1334 static int config_parse_env_file(
1335 const char *filename
,
1337 const char *section
,
1343 char ***env
= data
, **k
;
1350 if (!path_is_absolute(rvalue
[0] == '-' ? rvalue
+ 1 : rvalue
)) {
1351 log_error("[%s:%u] Path '%s' is not absolute, ignoring.", filename
, line
, rvalue
);
1355 if (!(k
= strv_append(*env
, rvalue
)))
1364 static int config_parse_ip_tos(
1365 const char *filename
,
1367 const char *section
,
1373 int *ip_tos
= data
, x
;
1380 if ((x
= ip_tos_from_string(rvalue
)) < 0)
1381 if (safe_atoi(rvalue
, &x
) < 0) {
1382 log_error("[%s:%u] Failed to parse IP TOS value, ignoring: %s", filename
, line
, rvalue
);
1390 static int config_parse_condition_path(
1391 const char *filename
,
1393 const char *section
,
1400 bool trigger
, negate
;
1408 if ((trigger
= rvalue
[0] == '|'))
1411 if ((negate
= rvalue
[0] == '!'))
1414 if (!path_is_absolute(rvalue
)) {
1415 log_error("[%s:%u] Path in condition not absolute, ignoring: %s", filename
, line
, rvalue
);
1419 if (!(c
= condition_new(streq(lvalue
, "ConditionPathExists") ? CONDITION_PATH_EXISTS
: CONDITION_DIRECTORY_NOT_EMPTY
,
1420 rvalue
, trigger
, negate
)))
1423 LIST_PREPEND(Condition
, conditions
, u
->meta
.conditions
, c
);
1427 static int config_parse_condition_kernel(
1428 const char *filename
,
1430 const char *section
,
1437 bool trigger
, negate
;
1445 if ((trigger
= rvalue
[0] == '|'))
1448 if ((negate
= rvalue
[0] == '!'))
1451 if (!(c
= condition_new(CONDITION_KERNEL_COMMAND_LINE
, rvalue
, trigger
, negate
)))
1454 LIST_PREPEND(Condition
, conditions
, u
->meta
.conditions
, c
);
1458 static int config_parse_condition_virt(
1459 const char *filename
,
1461 const char *section
,
1468 bool trigger
, negate
;
1476 if ((trigger
= rvalue
[0] == '|'))
1479 if ((negate
= rvalue
[0] == '!'))
1482 if (!(c
= condition_new(CONDITION_VIRTUALIZATION
, rvalue
, trigger
, negate
)))
1485 LIST_PREPEND(Condition
, conditions
, u
->meta
.conditions
, c
);
1489 static int config_parse_condition_null(
1490 const char *filename
,
1492 const char *section
,
1500 bool trigger
, negate
;
1508 if ((trigger
= rvalue
[0] == '|'))
1511 if ((negate
= rvalue
[0] == '!'))
1514 if ((b
= parse_boolean(rvalue
)) < 0) {
1515 log_error("[%s:%u] Failed to parse boolean value in condition, ignoring: %s", filename
, line
, rvalue
);
1522 if (!(c
= condition_new(CONDITION_NULL
, NULL
, trigger
, negate
)))
1525 LIST_PREPEND(Condition
, conditions
, u
->meta
.conditions
, c
);
1529 static DEFINE_CONFIG_PARSE_ENUM(config_parse_notify_access
, notify_access
, NotifyAccess
, "Failed to parse notify access specifier");
1531 #define FOLLOW_MAX 8
1533 static int open_follow(char **filename
, FILE **_f
, Set
*names
, char **_final
) {
1544 /* This will update the filename pointer if the loaded file is
1545 * reached by a symlink. The old string will be freed. */
1548 char *target
, *name
;
1550 if (c
++ >= FOLLOW_MAX
)
1553 path_kill_slashes(*filename
);
1555 /* Add the file name we are currently looking at to
1556 * the names of this unit, but only if it is a valid
1558 name
= file_name_from_path(*filename
);
1560 if (unit_name_is_valid(name
, false)) {
1561 if (!(id
= set_get(names
, name
))) {
1563 if (!(id
= strdup(name
)))
1566 if ((r
= set_put(names
, id
)) < 0) {
1573 /* Try to open the file name, but don't if its a symlink */
1574 if ((fd
= open(*filename
, O_RDONLY
|O_CLOEXEC
|O_NOCTTY
|O_NOFOLLOW
)) >= 0)
1580 /* Hmm, so this is a symlink. Let's read the name, and follow it manually */
1581 if ((r
= readlink_and_make_absolute(*filename
, &target
)) < 0)
1588 if (!(f
= fdopen(fd
, "re"))) {
1590 close_nointr_nofail(fd
);
1599 static int merge_by_names(Unit
**u
, Set
*names
, const char *id
) {
1607 /* Let's try to add in all symlink names we found */
1608 while ((k
= set_steal_first(names
))) {
1610 /* First try to merge in the other name into our
1612 if ((r
= unit_merge_by_name(*u
, k
)) < 0) {
1615 /* Hmm, we couldn't merge the other unit into
1616 * ours? Then let's try it the other way
1619 other
= manager_get_unit((*u
)->meta
.manager
, k
);
1623 if ((r
= unit_merge(other
, *u
)) >= 0) {
1625 return merge_by_names(u
, names
, NULL
);
1632 unit_choose_id(*u
, id
);
1640 static void dump_items(FILE *f
, const ConfigItem
*items
) {
1641 const ConfigItem
*i
;
1642 const char *prev_section
= NULL
;
1643 bool not_first
= false;
1646 ConfigParserCallback callback
;
1649 { config_parse_int
, "INTEGER" },
1650 { config_parse_unsigned
, "UNSIGNED" },
1651 { config_parse_size
, "SIZE" },
1652 { config_parse_bool
, "BOOLEAN" },
1653 { config_parse_string
, "STRING" },
1654 { config_parse_path
, "PATH" },
1655 { config_parse_strv
, "STRING [...]" },
1656 { config_parse_nice
, "NICE" },
1657 { config_parse_oom_score_adjust
, "OOMSCOREADJUST" },
1658 { config_parse_io_class
, "IOCLASS" },
1659 { config_parse_io_priority
, "IOPRIORITY" },
1660 { config_parse_cpu_sched_policy
, "CPUSCHEDPOLICY" },
1661 { config_parse_cpu_sched_prio
, "CPUSCHEDPRIO" },
1662 { config_parse_cpu_affinity
, "CPUAFFINITY" },
1663 { config_parse_mode
, "MODE" },
1664 { config_parse_env_file
, "FILE" },
1665 { config_parse_output
, "OUTPUT" },
1666 { config_parse_input
, "INPUT" },
1667 { config_parse_facility
, "FACILITY" },
1668 { config_parse_level
, "LEVEL" },
1669 { config_parse_capabilities
, "CAPABILITIES" },
1670 { config_parse_secure_bits
, "SECUREBITS" },
1671 { config_parse_bounding_set
, "BOUNDINGSET" },
1672 { config_parse_timer_slack_nsec
, "TIMERSLACK" },
1673 { config_parse_limit
, "LIMIT" },
1674 { config_parse_cgroup
, "CGROUP [...]" },
1675 { config_parse_deps
, "UNIT [...]" },
1676 { config_parse_names
, "UNIT [...]" },
1677 { config_parse_exec
, "PATH [ARGUMENT [...]]" },
1678 { config_parse_service_type
, "SERVICETYPE" },
1679 { config_parse_service_restart
, "SERVICERESTART" },
1680 #ifdef HAVE_SYSV_COMPAT
1681 { config_parse_sysv_priority
, "SYSVPRIORITY" },
1683 { config_parse_warn_compat
, "NOTSUPPORTED" },
1685 { config_parse_kill_mode
, "KILLMODE" },
1686 { config_parse_kill_signal
, "SIGNAL" },
1687 { config_parse_listen
, "SOCKET [...]" },
1688 { config_parse_socket_bind
, "SOCKETBIND" },
1689 { config_parse_bindtodevice
, "NETWORKINTERFACE" },
1690 { config_parse_usec
, "SECONDS" },
1691 { config_parse_path_strv
, "PATH [...]" },
1692 { config_parse_mount_flags
, "MOUNTFLAG [...]" },
1693 { config_parse_string_printf
, "STRING" },
1694 { config_parse_timer
, "TIMER" },
1695 { config_parse_timer_unit
, "NAME" },
1696 { config_parse_path_spec
, "PATH" },
1697 { config_parse_path_unit
, "UNIT" },
1698 { config_parse_notify_access
, "ACCESS" },
1699 { config_parse_ip_tos
, "TOS" },
1700 { config_parse_condition_path
, "CONDITION" },
1701 { config_parse_condition_kernel
, "CONDITION" },
1702 { config_parse_condition_null
, "CONDITION" },
1703 { config_parse_condition_virt
, "CONDITION" },
1709 for (i
= items
; i
->lvalue
; i
++) {
1711 const char *rvalue
= "OTHER";
1713 if (!streq_ptr(i
->section
, prev_section
)) {
1719 fprintf(f
, "[%s]\n", i
->section
);
1720 prev_section
= i
->section
;
1723 for (j
= 0; j
< ELEMENTSOF(table
); j
++)
1724 if (i
->parse
== table
[j
].callback
) {
1725 rvalue
= table
[j
].rvalue
;
1729 fprintf(f
, "%s=%s\n", i
->lvalue
, rvalue
);
1733 static int load_from_path(Unit
*u
, const char *path
) {
1735 static const char* const section_table
[_UNIT_TYPE_MAX
] = {
1736 [UNIT_SERVICE
] = "Service",
1737 [UNIT_TIMER
] = "Timer",
1738 [UNIT_SOCKET
] = "Socket",
1739 [UNIT_TARGET
] = "Target",
1740 [UNIT_DEVICE
] = "Device",
1741 [UNIT_MOUNT
] = "Mount",
1742 [UNIT_AUTOMOUNT
] = "Automount",
1743 [UNIT_SNAPSHOT
] = "Snapshot",
1744 [UNIT_SWAP
] = "Swap",
1745 [UNIT_PATH
] = "Path"
1748 #define EXEC_CONTEXT_CONFIG_ITEMS(context, section) \
1749 { "WorkingDirectory", config_parse_path, &(context).working_directory, section }, \
1750 { "RootDirectory", config_parse_path, &(context).root_directory, section }, \
1751 { "User", config_parse_string_printf, &(context).user, section }, \
1752 { "Group", config_parse_string_printf, &(context).group, section }, \
1753 { "SupplementaryGroups", config_parse_strv, &(context).supplementary_groups, section }, \
1754 { "Nice", config_parse_nice, &(context), section }, \
1755 { "OOMScoreAdjust", config_parse_oom_score_adjust,&(context), section }, \
1756 { "IOSchedulingClass", config_parse_io_class, &(context), section }, \
1757 { "IOSchedulingPriority", config_parse_io_priority, &(context), section }, \
1758 { "CPUSchedulingPolicy", config_parse_cpu_sched_policy,&(context), section }, \
1759 { "CPUSchedulingPriority", config_parse_cpu_sched_prio, &(context), section }, \
1760 { "CPUSchedulingResetOnFork", config_parse_bool, &(context).cpu_sched_reset_on_fork, section }, \
1761 { "CPUAffinity", config_parse_cpu_affinity, &(context), section }, \
1762 { "UMask", config_parse_mode, &(context).umask, section }, \
1763 { "Environment", config_parse_strv, &(context).environment, section }, \
1764 { "EnvironmentFile", config_parse_env_file, &(context).environment_files, section }, \
1765 { "StandardInput", config_parse_input, &(context).std_input, section }, \
1766 { "StandardOutput", config_parse_output, &(context).std_output, section }, \
1767 { "StandardError", config_parse_output, &(context).std_error, section }, \
1768 { "TTYPath", config_parse_path, &(context).tty_path, section }, \
1769 { "SyslogIdentifier", config_parse_string_printf, &(context).syslog_identifier, section }, \
1770 { "SyslogFacility", config_parse_facility, &(context).syslog_priority, section }, \
1771 { "SyslogLevel", config_parse_level, &(context).syslog_priority, section }, \
1772 { "SyslogLevelPrefix", config_parse_bool, &(context).syslog_level_prefix, section }, \
1773 { "Capabilities", config_parse_capabilities, &(context), section }, \
1774 { "SecureBits", config_parse_secure_bits, &(context), section }, \
1775 { "CapabilityBoundingSetDrop", config_parse_bounding_set, &(context), section }, \
1776 { "TimerSlackNSec", config_parse_timer_slack_nsec,&(context), section }, \
1777 { "LimitCPU", config_parse_limit, &(context).rlimit[RLIMIT_CPU], section }, \
1778 { "LimitFSIZE", config_parse_limit, &(context).rlimit[RLIMIT_FSIZE], section }, \
1779 { "LimitDATA", config_parse_limit, &(context).rlimit[RLIMIT_DATA], section }, \
1780 { "LimitSTACK", config_parse_limit, &(context).rlimit[RLIMIT_STACK], section }, \
1781 { "LimitCORE", config_parse_limit, &(context).rlimit[RLIMIT_CORE], section }, \
1782 { "LimitRSS", config_parse_limit, &(context).rlimit[RLIMIT_RSS], section }, \
1783 { "LimitNOFILE", config_parse_limit, &(context).rlimit[RLIMIT_NOFILE], section }, \
1784 { "LimitAS", config_parse_limit, &(context).rlimit[RLIMIT_AS], section }, \
1785 { "LimitNPROC", config_parse_limit, &(context).rlimit[RLIMIT_NPROC], section }, \
1786 { "LimitMEMLOCK", config_parse_limit, &(context).rlimit[RLIMIT_MEMLOCK], section }, \
1787 { "LimitLOCKS", config_parse_limit, &(context).rlimit[RLIMIT_LOCKS], section }, \
1788 { "LimitSIGPENDING", config_parse_limit, &(context).rlimit[RLIMIT_SIGPENDING], section }, \
1789 { "LimitMSGQUEUE", config_parse_limit, &(context).rlimit[RLIMIT_MSGQUEUE], section }, \
1790 { "LimitNICE", config_parse_limit, &(context).rlimit[RLIMIT_NICE], section }, \
1791 { "LimitRTPRIO", config_parse_limit, &(context).rlimit[RLIMIT_RTPRIO], section }, \
1792 { "LimitRTTIME", config_parse_limit, &(context).rlimit[RLIMIT_RTTIME], section }, \
1793 { "ControlGroup", config_parse_cgroup, u, section }, \
1794 { "ReadWriteDirectories", config_parse_path_strv, &(context).read_write_dirs, section }, \
1795 { "ReadOnlyDirectories", config_parse_path_strv, &(context).read_only_dirs, section }, \
1796 { "InaccessibleDirectories",config_parse_path_strv, &(context).inaccessible_dirs, section }, \
1797 { "PrivateTmp", config_parse_bool, &(context).private_tmp, section }, \
1798 { "MountFlags", config_parse_mount_flags, &(context), section }, \
1799 { "TCPWrapName", config_parse_string_printf, &(context).tcpwrap_name, section }, \
1800 { "PAMName", config_parse_string_printf, &(context).pam_name, section }, \
1801 { "KillMode", config_parse_kill_mode, &(context).kill_mode, section }, \
1802 { "KillSignal", config_parse_kill_signal, &(context).kill_signal, section }, \
1803 { "SendSIGKILL", config_parse_bool, &(context).send_sigkill, section }, \
1804 { "UtmpIdentifier", config_parse_string_printf, &(context).utmp_id, section }
1806 const ConfigItem items
[] = {
1807 { "Names", config_parse_names
, u
, "Unit" },
1808 { "Description", config_parse_string_printf
, &u
->meta
.description
, "Unit" },
1809 { "Requires", config_parse_deps
, UINT_TO_PTR(UNIT_REQUIRES
), "Unit" },
1810 { "RequiresOverridable", config_parse_deps
, UINT_TO_PTR(UNIT_REQUIRES_OVERRIDABLE
), "Unit" },
1811 { "Requisite", config_parse_deps
, UINT_TO_PTR(UNIT_REQUISITE
), "Unit" },
1812 { "RequisiteOverridable", config_parse_deps
, UINT_TO_PTR(UNIT_REQUISITE_OVERRIDABLE
), "Unit" },
1813 { "Wants", config_parse_deps
, UINT_TO_PTR(UNIT_WANTS
), "Unit" },
1814 { "BindTo", config_parse_deps
, UINT_TO_PTR(UNIT_BIND_TO
), "Unit" },
1815 { "Conflicts", config_parse_deps
, UINT_TO_PTR(UNIT_CONFLICTS
), "Unit" },
1816 { "Before", config_parse_deps
, UINT_TO_PTR(UNIT_BEFORE
), "Unit" },
1817 { "After", config_parse_deps
, UINT_TO_PTR(UNIT_AFTER
), "Unit" },
1818 { "OnFailure", config_parse_deps
, UINT_TO_PTR(UNIT_ON_FAILURE
), "Unit" },
1819 { "StopWhenUnneeded", config_parse_bool
, &u
->meta
.stop_when_unneeded
, "Unit" },
1820 { "RefuseManualStart", config_parse_bool
, &u
->meta
.refuse_manual_start
, "Unit" },
1821 { "RefuseManualStop", config_parse_bool
, &u
->meta
.refuse_manual_stop
, "Unit" },
1822 { "AllowIsolate", config_parse_bool
, &u
->meta
.allow_isolate
, "Unit" },
1823 { "DefaultDependencies", config_parse_bool
, &u
->meta
.default_dependencies
, "Unit" },
1824 { "JobTimeoutSec", config_parse_usec
, &u
->meta
.job_timeout
, "Unit" },
1825 { "ConditionPathExists", config_parse_condition_path
, u
, "Unit" },
1826 { "ConditionDirectoryNotEmpty", config_parse_condition_path
, u
, "Unit" },
1827 { "ConditionKernelCommandLine", config_parse_condition_kernel
, u
, "Unit" },
1828 { "ConditionVirtualization",config_parse_condition_virt
, u
, "Unit" },
1829 { "ConditionNull", config_parse_condition_null
, u
, "Unit" },
1831 { "PIDFile", config_parse_path
, &u
->service
.pid_file
, "Service" },
1832 { "ExecStartPre", config_parse_exec
, u
->service
.exec_command
+SERVICE_EXEC_START_PRE
, "Service" },
1833 { "ExecStart", config_parse_exec
, u
->service
.exec_command
+SERVICE_EXEC_START
, "Service" },
1834 { "ExecStartPost", config_parse_exec
, u
->service
.exec_command
+SERVICE_EXEC_START_POST
, "Service" },
1835 { "ExecReload", config_parse_exec
, u
->service
.exec_command
+SERVICE_EXEC_RELOAD
, "Service" },
1836 { "ExecStop", config_parse_exec
, u
->service
.exec_command
+SERVICE_EXEC_STOP
, "Service" },
1837 { "ExecStopPost", config_parse_exec
, u
->service
.exec_command
+SERVICE_EXEC_STOP_POST
, "Service" },
1838 { "RestartSec", config_parse_usec
, &u
->service
.restart_usec
, "Service" },
1839 { "TimeoutSec", config_parse_usec
, &u
->service
.timeout_usec
, "Service" },
1840 { "Type", config_parse_service_type
, &u
->service
.type
, "Service" },
1841 { "Restart", config_parse_service_restart
, &u
->service
.restart
, "Service" },
1842 { "PermissionsStartOnly", config_parse_bool
, &u
->service
.permissions_start_only
, "Service" },
1843 { "RootDirectoryStartOnly", config_parse_bool
, &u
->service
.root_directory_start_only
, "Service" },
1844 { "RemainAfterExit", config_parse_bool
, &u
->service
.remain_after_exit
, "Service" },
1845 { "GuessMainPID", config_parse_bool
, &u
->service
.guess_main_pid
, "Service" },
1846 #ifdef HAVE_SYSV_COMPAT
1847 { "SysVStartPriority", config_parse_sysv_priority
, &u
->service
.sysv_start_priority
, "Service" },
1849 { "SysVStartPriority", config_parse_warn_compat
, NULL
, "Service" },
1851 { "NonBlocking", config_parse_bool
, &u
->service
.exec_context
.non_blocking
, "Service" },
1852 { "BusName", config_parse_string_printf
, &u
->service
.bus_name
, "Service" },
1853 { "NotifyAccess", config_parse_notify_access
, &u
->service
.notify_access
, "Service" },
1854 { "Sockets", config_parse_service_sockets
, &u
->service
, "Service" },
1855 { "FsckPassNo", config_parse_fsck_passno
, &u
->service
.fsck_passno
, "Service" },
1856 EXEC_CONTEXT_CONFIG_ITEMS(u
->service
.exec_context
, "Service"),
1858 { "ListenStream", config_parse_listen
, &u
->socket
, "Socket" },
1859 { "ListenDatagram", config_parse_listen
, &u
->socket
, "Socket" },
1860 { "ListenSequentialPacket", config_parse_listen
, &u
->socket
, "Socket" },
1861 { "ListenFIFO", config_parse_listen
, &u
->socket
, "Socket" },
1862 { "BindIPv6Only", config_parse_socket_bind
, &u
->socket
, "Socket" },
1863 { "Backlog", config_parse_unsigned
, &u
->socket
.backlog
, "Socket" },
1864 { "BindToDevice", config_parse_bindtodevice
, &u
->socket
, "Socket" },
1865 { "ExecStartPre", config_parse_exec
, u
->socket
.exec_command
+SOCKET_EXEC_START_PRE
, "Socket" },
1866 { "ExecStartPost", config_parse_exec
, u
->socket
.exec_command
+SOCKET_EXEC_START_POST
, "Socket" },
1867 { "ExecStopPre", config_parse_exec
, u
->socket
.exec_command
+SOCKET_EXEC_STOP_PRE
, "Socket" },
1868 { "ExecStopPost", config_parse_exec
, u
->socket
.exec_command
+SOCKET_EXEC_STOP_POST
, "Socket" },
1869 { "TimeoutSec", config_parse_usec
, &u
->socket
.timeout_usec
, "Socket" },
1870 { "DirectoryMode", config_parse_mode
, &u
->socket
.directory_mode
, "Socket" },
1871 { "SocketMode", config_parse_mode
, &u
->socket
.socket_mode
, "Socket" },
1872 { "Accept", config_parse_bool
, &u
->socket
.accept
, "Socket" },
1873 { "MaxConnections", config_parse_unsigned
, &u
->socket
.max_connections
, "Socket" },
1874 { "KeepAlive", config_parse_bool
, &u
->socket
.keep_alive
, "Socket" },
1875 { "Priority", config_parse_int
, &u
->socket
.priority
, "Socket" },
1876 { "ReceiveBuffer", config_parse_size
, &u
->socket
.receive_buffer
, "Socket" },
1877 { "SendBuffer", config_parse_size
, &u
->socket
.send_buffer
, "Socket" },
1878 { "IPTOS", config_parse_ip_tos
, &u
->socket
.ip_tos
, "Socket" },
1879 { "IPTTL", config_parse_int
, &u
->socket
.ip_ttl
, "Socket" },
1880 { "Mark", config_parse_int
, &u
->socket
.mark
, "Socket" },
1881 { "PipeSize", config_parse_size
, &u
->socket
.pipe_size
, "Socket" },
1882 { "FreeBind", config_parse_bool
, &u
->socket
.free_bind
, "Socket" },
1883 { "TCPCongestion", config_parse_string
, &u
->socket
.tcp_congestion
, "Socket" },
1884 { "Service", config_parse_socket_service
, &u
->socket
, "Socket" },
1885 EXEC_CONTEXT_CONFIG_ITEMS(u
->socket
.exec_context
, "Socket"),
1887 { "What", config_parse_string
, &u
->mount
.parameters_fragment
.what
, "Mount" },
1888 { "Where", config_parse_path
, &u
->mount
.where
, "Mount" },
1889 { "Options", config_parse_string
, &u
->mount
.parameters_fragment
.options
, "Mount" },
1890 { "Type", config_parse_string
, &u
->mount
.parameters_fragment
.fstype
, "Mount" },
1891 { "TimeoutSec", config_parse_usec
, &u
->mount
.timeout_usec
, "Mount" },
1892 { "DirectoryMode", config_parse_mode
, &u
->mount
.directory_mode
, "Mount" },
1893 EXEC_CONTEXT_CONFIG_ITEMS(u
->mount
.exec_context
, "Mount"),
1895 { "Where", config_parse_path
, &u
->automount
.where
, "Automount" },
1896 { "DirectoryMode", config_parse_mode
, &u
->automount
.directory_mode
, "Automount" },
1898 { "What", config_parse_path
, &u
->swap
.parameters_fragment
.what
, "Swap" },
1899 { "Priority", config_parse_int
, &u
->swap
.parameters_fragment
.priority
, "Swap" },
1900 { "TimeoutSec", config_parse_usec
, &u
->swap
.timeout_usec
, "Swap" },
1901 EXEC_CONTEXT_CONFIG_ITEMS(u
->swap
.exec_context
, "Swap"),
1903 { "OnActiveSec", config_parse_timer
, &u
->timer
, "Timer" },
1904 { "OnBootSec", config_parse_timer
, &u
->timer
, "Timer" },
1905 { "OnStartupSec", config_parse_timer
, &u
->timer
, "Timer" },
1906 { "OnUnitActiveSec", config_parse_timer
, &u
->timer
, "Timer" },
1907 { "OnUnitInactiveSec", config_parse_timer
, &u
->timer
, "Timer" },
1908 { "Unit", config_parse_timer_unit
, &u
->timer
, "Timer" },
1910 { "PathExists", config_parse_path_spec
, &u
->path
, "Path" },
1911 { "PathChanged", config_parse_path_spec
, &u
->path
, "Path" },
1912 { "DirectoryNotEmpty", config_parse_path_spec
, &u
->path
, "Path" },
1913 { "Unit", config_parse_path_unit
, &u
->path
, "Path" },
1915 /* The [Install] section is ignored here. */
1916 { "Alias", NULL
, NULL
, "Install" },
1917 { "WantedBy", NULL
, NULL
, "Install" },
1918 { "Also", NULL
, NULL
, "Install" },
1920 { NULL
, NULL
, NULL
, NULL
}
1923 #undef EXEC_CONTEXT_CONFIG_ITEMS
1925 const char *sections
[4];
1929 char *filename
= NULL
, *id
= NULL
;
1934 /* Dirty dirty hack. */
1935 dump_items((FILE*) path
, items
);
1942 sections
[0] = "Unit";
1943 sections
[1] = section_table
[u
->meta
.type
];
1944 sections
[2] = "Install";
1947 if (!(symlink_names
= set_new(string_hash_func
, string_compare_func
)))
1950 if (path_is_absolute(path
)) {
1952 if (!(filename
= strdup(path
))) {
1957 if ((r
= open_follow(&filename
, &f
, symlink_names
, &id
)) < 0) {
1968 STRV_FOREACH(p
, u
->meta
.manager
->lookup_paths
.unit_path
) {
1970 /* Instead of opening the path right away, we manually
1971 * follow all symlinks and add their name to our unit
1972 * name set while doing so */
1973 if (!(filename
= path_make_absolute(path
, *p
))) {
1978 if (u
->meta
.manager
->unit_path_cache
&&
1979 !set_get(u
->meta
.manager
->unit_path_cache
, filename
))
1982 r
= open_follow(&filename
, &f
, symlink_names
, &id
);
1993 /* Empty the symlink names for the next run */
1994 while ((sn
= set_steal_first(symlink_names
)))
2005 /* Hmm, no suitable file found? */
2011 if ((r
= merge_by_names(&merged
, symlink_names
, id
)) < 0)
2015 u
->meta
.load_state
= UNIT_MERGED
;
2021 if (fstat(fileno(f
), &st
) < 0) {
2026 if (null_or_empty(&st
))
2027 u
->meta
.load_state
= UNIT_MASKED
;
2029 /* Now, parse the file contents */
2030 if ((r
= config_parse(filename
, f
, sections
, items
, false, u
)) < 0)
2033 u
->meta
.load_state
= UNIT_LOADED
;
2036 free(u
->meta
.fragment_path
);
2037 u
->meta
.fragment_path
= filename
;
2040 u
->meta
.fragment_mtime
= timespec_load(&st
.st_mtim
);
2045 set_free_free(symlink_names
);
2054 int unit_load_fragment(Unit
*u
) {
2060 assert(u
->meta
.load_state
== UNIT_STUB
);
2063 /* First, try to find the unit under its id. We always look
2064 * for unit files in the default directories, to make it easy
2065 * to override things by placing things in /etc/systemd/system */
2066 if ((r
= load_from_path(u
, u
->meta
.id
)) < 0)
2069 /* Try to find an alias we can load this with */
2070 if (u
->meta
.load_state
== UNIT_STUB
)
2071 SET_FOREACH(t
, u
->meta
.names
, i
) {
2073 if (t
== u
->meta
.id
)
2076 if ((r
= load_from_path(u
, t
)) < 0)
2079 if (u
->meta
.load_state
!= UNIT_STUB
)
2083 /* And now, try looking for it under the suggested (originally linked) path */
2084 if (u
->meta
.load_state
== UNIT_STUB
&& u
->meta
.fragment_path
) {
2086 if ((r
= load_from_path(u
, u
->meta
.fragment_path
)) < 0)
2089 if (u
->meta
.load_state
== UNIT_STUB
) {
2090 /* Hmm, this didn't work? Then let's get rid
2091 * of the fragment path stored for us, so that
2092 * we don't point to an invalid location. */
2093 free(u
->meta
.fragment_path
);
2094 u
->meta
.fragment_path
= NULL
;
2098 /* Look for a template */
2099 if (u
->meta
.load_state
== UNIT_STUB
&& u
->meta
.instance
) {
2102 if (!(k
= unit_name_template(u
->meta
.id
)))
2105 r
= load_from_path(u
, k
);
2111 if (u
->meta
.load_state
== UNIT_STUB
)
2112 SET_FOREACH(t
, u
->meta
.names
, i
) {
2114 if (t
== u
->meta
.id
)
2117 if (!(k
= unit_name_template(t
)))
2120 r
= load_from_path(u
, k
);
2126 if (u
->meta
.load_state
!= UNIT_STUB
)
2134 void unit_dump_config_items(FILE *f
) {
2135 /* OK, this wins a prize for extreme ugliness. */
2137 load_from_path(NULL
, (const void*) f
);