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>
34 #include <sys/resource.h>
38 #include "conf-parser.h"
39 #include "load-fragment.h"
42 #include "securebits.h"
44 #include "unit-name.h"
45 #include "bus-errors.h"
47 #ifndef HAVE_SYSV_COMPAT
48 static int config_parse_warn_compat(
58 log_debug("[%s:%u] Support for option %s= has been disabled at compile time and is ignored", filename, line, lvalue);
63 static int config_parse_deps(
73 UnitDependency d = PTR_TO_UINT(data);
83 FOREACH_WORD_QUOTED(w, l, rvalue, state) {
87 if (!(t = strndup(w, l)))
90 k = unit_name_printf(u, t);
96 r = unit_add_dependency_by_name(u, d, k, NULL, true);
99 log_error("Failed to add dependency on %s, ignoring: %s", k, strerror(-r));
110 static int config_parse_names(
111 const char *filename,
130 FOREACH_WORD_QUOTED(w, l, rvalue, state) {
134 if (!(t = strndup(w, l)))
137 k = unit_name_printf(u, t);
143 r = unit_merge_by_name(u, k);
146 log_error("Failed to add name %s, ignoring: %s", k, strerror(-r));
157 static int config_parse_string_printf(
158 const char *filename,
177 if (!(k = unit_full_printf(u, rvalue)))
191 static int config_parse_strv_printf(
192 const char *filename,
210 k = unit_full_printf(u, rvalue);
214 r = config_parse_strv(filename, line, section, lvalue, ltype, k, data, userdata);
220 static int config_parse_path_printf(
221 const char *filename,
240 if (!(k = unit_full_printf(u, rvalue)))
243 if (!path_is_absolute(k)) {
244 log_error("[%s:%u] Not an absolute path: %s", filename, line, k);
249 path_kill_slashes(k);
257 static int config_parse_listen(
258 const char *filename,
267 SocketPort *p, *tail;
277 if (!(p = new0(SocketPort, 1)))
280 if (streq(lvalue, "ListenFIFO")) {
281 p->type = SOCKET_FIFO;
283 if (!(p->path = unit_full_printf(UNIT(s), rvalue))) {
288 path_kill_slashes(p->path);
290 } else if (streq(lvalue, "ListenSpecial")) {
291 p->type = SOCKET_SPECIAL;
293 if (!(p->path = unit_full_printf(UNIT(s), rvalue))) {
298 path_kill_slashes(p->path);
300 } else if (streq(lvalue, "ListenMessageQueue")) {
302 p->type = SOCKET_MQUEUE;
304 if (!(p->path = unit_full_printf(UNIT(s), rvalue))) {
309 path_kill_slashes(p->path);
311 } else if (streq(lvalue, "ListenNetlink")) {
315 p->type = SOCKET_SOCKET;
316 k = unit_full_printf(UNIT(s), rvalue);
317 r = socket_address_parse_netlink(&p->address, k);
321 log_error("[%s:%u] Failed to parse address value, ignoring: %s", filename, line, rvalue);
330 p->type = SOCKET_SOCKET;
331 k = unit_full_printf(UNIT(s), rvalue);
332 r = socket_address_parse(&p->address, k);
336 log_error("[%s:%u] Failed to parse address value, ignoring: %s", filename, line, rvalue);
341 if (streq(lvalue, "ListenStream"))
342 p->address.type = SOCK_STREAM;
343 else if (streq(lvalue, "ListenDatagram"))
344 p->address.type = SOCK_DGRAM;
346 assert(streq(lvalue, "ListenSequentialPacket"));
347 p->address.type = SOCK_SEQPACKET;
350 if (socket_address_family(&p->address) != AF_LOCAL && p->address.type == SOCK_SEQPACKET) {
351 log_error("[%s:%u] Address family not supported, ignoring: %s", filename, line, rvalue);
360 LIST_FIND_TAIL(SocketPort, port, s->ports, tail);
361 LIST_INSERT_AFTER(SocketPort, port, s->ports, tail, p);
363 LIST_PREPEND(SocketPort, port, s->ports, p);
368 static int config_parse_socket_bind(
369 const char *filename,
379 SocketAddressBindIPv6Only b;
388 if ((b = socket_address_bind_ipv6_only_from_string(rvalue)) < 0) {
391 if ((r = parse_boolean(rvalue)) < 0) {
392 log_error("[%s:%u] Failed to parse bind IPv6 only value, ignoring: %s", filename, line, rvalue);
396 s->bind_ipv6_only = r ? SOCKET_ADDRESS_IPV6_ONLY : SOCKET_ADDRESS_BOTH;
398 s->bind_ipv6_only = b;
403 static int config_parse_nice(
404 const char *filename,
413 ExecContext *c = data;
421 if (safe_atoi(rvalue, &priority) < 0) {
422 log_error("[%s:%u] Failed to parse nice priority, ignoring: %s. ", filename, line, rvalue);
426 if (priority < PRIO_MIN || priority >= PRIO_MAX) {
427 log_error("[%s:%u] Nice priority out of range, ignoring: %s", filename, line, rvalue);
437 static int config_parse_oom_score_adjust(
438 const char *filename,
447 ExecContext *c = data;
455 if (safe_atoi(rvalue, &oa) < 0) {
456 log_error("[%s:%u] Failed to parse the OOM score adjust value, ignoring: %s", filename, line, rvalue);
460 if (oa < OOM_SCORE_ADJ_MIN || oa > OOM_SCORE_ADJ_MAX) {
461 log_error("[%s:%u] OOM score adjust value out of range, ignoring: %s", filename, line, rvalue);
465 c->oom_score_adjust = oa;
466 c->oom_score_adjust_set = true;
471 static int config_parse_mode(
472 const char *filename,
491 l = strtol(rvalue, &x, 8);
492 if (!x || *x || errno) {
493 log_error("[%s:%u] Failed to parse mode value, ignoring: %s", filename, line, rvalue);
497 if (l < 0000 || l > 07777) {
498 log_error("[%s:%u] mode value out of range, ignoring: %s", filename, line, rvalue);
506 static int config_parse_exec(
507 const char *filename,
516 ExecCommand **e = data, *nce;
525 /* We accept an absolute path as first argument, or
526 * alternatively an absolute prefixed with @ to allow
527 * overriding of argv[0]. */
533 bool honour_argv0 = false, ignore = false;
539 rvalue += strspn(rvalue, WHITESPACE);
544 if (rvalue[0] == '-') {
549 if (rvalue[0] == '@') {
554 if (*rvalue != '/') {
555 log_error("[%s:%u] Invalid executable path in command line, ignoring: %s", filename, line, rvalue);
560 FOREACH_WORD_QUOTED(w, l, rvalue, state) {
561 if (strncmp(w, ";", MAX(l, 1U)) == 0)
567 if (!(n = new(char*, k + !honour_argv0)))
571 FOREACH_WORD_QUOTED(w, l, rvalue, state) {
572 if (strncmp(w, ";", MAX(l, 1U)) == 0)
575 if (honour_argv0 && w == rvalue) {
577 if (!(path = cunescape_length(w, l)))
580 if (!(n[k++] = cunescape_length(w, l)))
588 log_error("[%s:%u] Invalid command line, ignoring: %s", filename, line, rvalue);
594 if (!(path = strdup(n[0])))
597 assert(path_is_absolute(path));
599 if (!(nce = new0(ExecCommand, 1)))
604 nce->ignore = ignore;
606 path_kill_slashes(nce->path);
608 exec_command_append_list(e, nce);
624 static int config_parse_usec(
625 const char *filename,
641 if (parse_usec(rvalue, usec) < 0) {
642 log_error("[%s:%u] Failed to parse time value, ignoring: %s", filename, line, rvalue);
649 static DEFINE_CONFIG_PARSE_ENUM(config_parse_service_type, service_type, ServiceType, "Failed to parse service type");
650 static DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart, service_restart, ServiceRestart, "Failed to parse service restart specifier");
652 static int config_parse_bindtodevice(
653 const char *filename,
670 if (rvalue[0] && !streq(rvalue, "*")) {
671 if (!(n = strdup(rvalue)))
676 free(s->bind_to_device);
677 s->bind_to_device = n;
682 static DEFINE_CONFIG_PARSE_ENUM(config_parse_output, exec_output, ExecOutput, "Failed to parse output specifier");
683 static DEFINE_CONFIG_PARSE_ENUM(config_parse_input, exec_input, ExecInput, "Failed to parse input specifier");
685 static int config_parse_facility(
686 const char *filename,
703 if ((x = log_facility_unshifted_from_string(rvalue)) < 0) {
704 log_error("[%s:%u] Failed to parse log facility, ignoring: %s", filename, line, rvalue);
708 *o = (x << 3) | LOG_PRI(*o);
713 static int config_parse_level(
714 const char *filename,
731 if ((x = log_level_from_string(rvalue)) < 0) {
732 log_error("[%s:%u] Failed to parse log level, ignoring: %s", filename, line, rvalue);
736 *o = (*o & LOG_FACMASK) | x;
740 static int config_parse_io_class(
741 const char *filename,
750 ExecContext *c = data;
758 if ((x = ioprio_class_from_string(rvalue)) < 0) {
759 log_error("[%s:%u] Failed to parse IO scheduling class, ignoring: %s", filename, line, rvalue);
763 c->ioprio = IOPRIO_PRIO_VALUE(x, IOPRIO_PRIO_DATA(c->ioprio));
764 c->ioprio_set = true;
769 static int config_parse_io_priority(
770 const char *filename,
779 ExecContext *c = data;
787 if (safe_atoi(rvalue, &i) < 0 || i < 0 || i >= IOPRIO_BE_NR) {
788 log_error("[%s:%u] Failed to parse io priority, ignoring: %s", filename, line, rvalue);
792 c->ioprio = IOPRIO_PRIO_VALUE(IOPRIO_PRIO_CLASS(c->ioprio), i);
793 c->ioprio_set = true;
798 static int config_parse_cpu_sched_policy(
799 const char *filename,
809 ExecContext *c = data;
817 if ((x = sched_policy_from_string(rvalue)) < 0) {
818 log_error("[%s:%u] Failed to parse CPU scheduling policy, ignoring: %s", filename, line, rvalue);
822 c->cpu_sched_policy = x;
823 c->cpu_sched_set = true;
828 static int config_parse_cpu_sched_prio(
829 const char *filename,
838 ExecContext *c = data;
846 /* On Linux RR/FIFO have the same range */
847 if (safe_atoi(rvalue, &i) < 0 || i < sched_get_priority_min(SCHED_RR) || i > sched_get_priority_max(SCHED_RR)) {
848 log_error("[%s:%u] Failed to parse CPU scheduling priority, ignoring: %s", filename, line, rvalue);
852 c->cpu_sched_priority = i;
853 c->cpu_sched_set = true;
858 static int config_parse_cpu_affinity(
859 const char *filename,
868 ExecContext *c = data;
878 FOREACH_WORD_QUOTED(w, l, rvalue, state) {
883 if (!(t = strndup(w, l)))
886 r = safe_atou(t, &cpu);
890 if (!(c->cpuset = cpu_set_malloc(&c->cpuset_ncpus)))
893 if (r < 0 || cpu >= c->cpuset_ncpus) {
894 log_error("[%s:%u] Failed to parse CPU affinity, ignoring: %s", filename, line, rvalue);
898 CPU_SET_S(cpu, CPU_ALLOC_SIZE(c->cpuset_ncpus), c->cpuset);
904 static int config_parse_capabilities(
905 const char *filename,
914 ExecContext *c = data;
922 if (!(cap = cap_from_text(rvalue))) {
926 log_error("[%s:%u] Failed to parse capabilities, ignoring: %s", filename, line, rvalue);
931 cap_free(c->capabilities);
932 c->capabilities = cap;
937 static int config_parse_secure_bits(
938 const char *filename,
947 ExecContext *c = data;
957 FOREACH_WORD_QUOTED(w, l, rvalue, state) {
958 if (first_word(w, "keep-caps"))
959 c->secure_bits |= SECURE_KEEP_CAPS;
960 else if (first_word(w, "keep-caps-locked"))
961 c->secure_bits |= SECURE_KEEP_CAPS_LOCKED;
962 else if (first_word(w, "no-setuid-fixup"))
963 c->secure_bits |= SECURE_NO_SETUID_FIXUP;
964 else if (first_word(w, "no-setuid-fixup-locked"))
965 c->secure_bits |= SECURE_NO_SETUID_FIXUP_LOCKED;
966 else if (first_word(w, "noroot"))
967 c->secure_bits |= SECURE_NOROOT;
968 else if (first_word(w, "noroot-locked"))
969 c->secure_bits |= SECURE_NOROOT_LOCKED;
971 log_error("[%s:%u] Failed to parse secure bits, ignoring: %s", filename, line, rvalue);
979 static int config_parse_bounding_set(
980 const char *filename,
989 ExecContext *c = data;
1001 if (rvalue[0] == '~') {
1006 /* Note that we store this inverted internally, since the
1007 * kernel wants it like this. But we actually expose it
1008 * non-inverted everywhere to have a fully normalized
1011 FOREACH_WORD_QUOTED(w, l, rvalue, state) {
1016 if (!(t = strndup(w, l)))
1019 r = cap_from_name(t, &cap);
1023 log_error("[%s:%u] Failed to parse capability bounding set, ignoring: %s", filename, line, rvalue);
1027 sum |= ((uint64_t) 1ULL) << (uint64_t) cap;
1031 c->capability_bounding_set_drop |= sum;
1033 c->capability_bounding_set_drop |= ~sum;
1038 static int config_parse_timer_slack_nsec(
1039 const char *filename,
1041 const char *section,
1048 ExecContext *c = data;
1056 if (safe_atolu(rvalue, &u) < 0) {
1057 log_error("[%s:%u] Failed to parse time slack value, ignoring: %s", filename, line, rvalue);
1061 c->timer_slack_nsec = u;
1066 static int config_parse_limit(
1067 const char *filename,
1069 const char *section,
1076 struct rlimit **rl = data;
1077 unsigned long long u;
1084 if (streq(rvalue, "infinity"))
1085 u = (unsigned long long) RLIM_INFINITY;
1086 else if (safe_atollu(rvalue, &u) < 0) {
1087 log_error("[%s:%u] Failed to parse resource value, ignoring: %s", filename, line, rvalue);
1092 if (!(*rl = new(struct rlimit, 1)))
1095 (*rl)->rlim_cur = (*rl)->rlim_max = (rlim_t) u;
1099 static int config_parse_cgroup(
1100 const char *filename,
1102 const char *section,
1114 FOREACH_WORD_QUOTED(w, l, rvalue, state) {
1122 k = unit_full_printf(u, t);
1134 r = unit_add_cgroup_from_text(u, t);
1138 log_error("[%s:%u] Failed to parse cgroup value, ignoring: %s", filename, line, rvalue);
1146 #ifdef HAVE_SYSV_COMPAT
1147 static int config_parse_sysv_priority(
1148 const char *filename,
1150 const char *section,
1157 int *priority = data;
1165 if (safe_atoi(rvalue, &i) < 0 || i < 0) {
1166 log_error("[%s:%u] Failed to parse SysV start priority, ignoring: %s", filename, line, rvalue);
1170 *priority = (int) i;
1175 static int config_parse_fsck_passno(
1176 const char *filename,
1178 const char *section,
1193 if (safe_atoi(rvalue, &i) || i < 0) {
1194 log_error("[%s:%u] Failed to parse fsck pass number, ignoring: %s", filename, line, rvalue);
1202 static DEFINE_CONFIG_PARSE_ENUM(config_parse_kill_mode, kill_mode, KillMode, "Failed to parse kill mode");
1204 static int config_parse_kill_signal(
1205 const char *filename,
1207 const char *section,
1222 if ((r = signal_from_string_try_harder(rvalue)) <= 0) {
1223 log_error("[%s:%u] Failed to parse kill signal, ignoring: %s", filename, line, rvalue);
1231 static int config_parse_mount_flags(
1232 const char *filename,
1234 const char *section,
1241 ExecContext *c = data;
1245 unsigned long flags = 0;
1252 FOREACH_WORD_QUOTED(w, l, rvalue, state) {
1253 if (strncmp(w, "shared", MAX(l, 6U)) == 0)
1255 else if (strncmp(w, "slave", MAX(l, 5U)) == 0)
1257 else if (strncmp(w, "private", MAX(l, 7U)) == 0)
1258 flags |= MS_PRIVATE;
1260 log_error("[%s:%u] Failed to parse mount flags, ignoring: %s", filename, line, rvalue);
1265 c->mount_flags = flags;
1269 static int config_parse_timer(
1270 const char *filename,
1272 const char *section,
1289 if ((b = timer_base_from_string(lvalue)) < 0) {
1290 log_error("[%s:%u] Failed to parse timer base, ignoring: %s", filename, line, lvalue);
1294 if (parse_usec(rvalue, &u) < 0) {
1295 log_error("[%s:%u] Failed to parse timer value, ignoring: %s", filename, line, rvalue);
1299 if (!(v = new0(TimerValue, 1)))
1305 LIST_PREPEND(TimerValue, value, t->values, v);
1310 static int config_parse_timer_unit(
1311 const char *filename,
1313 const char *section,
1329 dbus_error_init(&error);
1331 if (endswith(rvalue, ".timer")) {
1332 log_error("[%s:%u] Unit cannot be of type timer, ignoring: %s", filename, line, rvalue);
1336 if ((r = manager_load_unit(t->meta.manager, rvalue, NULL, NULL, &t->unit)) < 0) {
1337 log_error("[%s:%u] Failed to load unit %s, ignoring: %s", filename, line, rvalue, bus_error(&error, r));
1338 dbus_error_free(&error);
1345 static int config_parse_path_spec(
1346 const char *filename,
1348 const char *section,
1364 if ((b = path_type_from_string(lvalue)) < 0) {
1365 log_error("[%s:%u] Failed to parse path type, ignoring: %s", filename, line, lvalue);
1369 if (!path_is_absolute(rvalue)) {
1370 log_error("[%s:%u] Path is not absolute, ignoring: %s", filename, line, rvalue);
1374 if (!(s = new0(PathSpec, 1)))
1377 if (!(s->path = strdup(rvalue))) {
1382 path_kill_slashes(s->path);
1387 LIST_PREPEND(PathSpec, spec, p->specs, s);
1392 static int config_parse_path_unit(
1393 const char *filename,
1395 const char *section,
1411 dbus_error_init(&error);
1413 if (endswith(rvalue, ".path")) {
1414 log_error("[%s:%u] Unit cannot be of type path, ignoring: %s", filename, line, rvalue);
1418 if ((r = manager_load_unit(t->meta.manager, rvalue, NULL, &error, &t->unit)) < 0) {
1419 log_error("[%s:%u] Failed to load unit %s, ignoring: %s", filename, line, rvalue, bus_error(&error, r));
1420 dbus_error_free(&error);
1427 static int config_parse_socket_service(
1428 const char *filename,
1430 const char *section,
1446 dbus_error_init(&error);
1448 if (!endswith(rvalue, ".service")) {
1449 log_error("[%s:%u] Unit must be of type service, ignoring: %s", filename, line, rvalue);
1453 if ((r = manager_load_unit(s->meta.manager, rvalue, NULL, &error, (Unit**) &s->service)) < 0) {
1454 log_error("[%s:%u] Failed to load unit %s, ignoring: %s", filename, line, rvalue, bus_error(&error, r));
1455 dbus_error_free(&error);
1462 static int config_parse_service_sockets(
1463 const char *filename,
1465 const char *section,
1483 dbus_error_init(&error);
1485 FOREACH_WORD_QUOTED(w, l, rvalue, state) {
1489 if (!(t = strndup(w, l)))
1492 if (!endswith(t, ".socket")) {
1493 log_error("[%s:%u] Unit must be of type socket, ignoring: %s", filename, line, rvalue);
1498 r = manager_load_unit(s->meta.manager, t, NULL, &error, &sock);
1502 log_error("[%s:%u] Failed to load unit %s, ignoring: %s", filename, line, rvalue, bus_error(&error, r));
1503 dbus_error_free(&error);
1507 if ((r = set_ensure_allocated(&s->configured_sockets, trivial_hash_func, trivial_compare_func)) < 0)
1510 if ((r = set_put(s->configured_sockets, sock)) < 0)
1517 static int config_parse_env_file(
1518 const char *filename,
1520 const char *section,
1527 char ***env = data, **k;
1536 s = unit_full_printf(u, rvalue);
1540 if (!path_is_absolute(s[0] == '-' ? s + 1 : s)) {
1541 log_error("[%s:%u] Path '%s' is not absolute, ignoring.", filename, line, s);
1546 k = strv_append(*env, s);
1557 static int config_parse_ip_tos(
1558 const char *filename,
1560 const char *section,
1567 int *ip_tos = data, x;
1574 if ((x = ip_tos_from_string(rvalue)) < 0)
1575 if (safe_atoi(rvalue, &x) < 0) {
1576 log_error("[%s:%u] Failed to parse IP TOS value, ignoring: %s", filename, line, rvalue);
1584 static int config_parse_condition_path(
1585 const char *filename,
1587 const char *section,
1594 ConditionType cond = ltype;
1596 bool trigger, negate;
1604 if ((trigger = rvalue[0] == '|'))
1607 if ((negate = rvalue[0] == '!'))
1610 if (!path_is_absolute(rvalue)) {
1611 log_error("[%s:%u] Path in condition not absolute, ignoring: %s", filename, line, rvalue);
1615 if (!(c = condition_new(cond, rvalue, trigger, negate)))
1618 LIST_PREPEND(Condition, conditions, u->meta.conditions, c);
1622 static int config_parse_condition_string(
1623 const char *filename,
1625 const char *section,
1632 ConditionType cond = ltype;
1634 bool trigger, negate;
1642 if ((trigger = rvalue[0] == '|'))
1645 if ((negate = rvalue[0] == '!'))
1648 if (!(c = condition_new(cond, rvalue, trigger, negate)))
1651 LIST_PREPEND(Condition, conditions, u->meta.conditions, c);
1655 static int config_parse_condition_null(
1656 const char *filename,
1658 const char *section,
1667 bool trigger, negate;
1675 if ((trigger = rvalue[0] == '|'))
1678 if ((negate = rvalue[0] == '!'))
1681 if ((b = parse_boolean(rvalue)) < 0) {
1682 log_error("[%s:%u] Failed to parse boolean value in condition, ignoring: %s", filename, line, rvalue);
1689 if (!(c = condition_new(CONDITION_NULL, NULL, trigger, negate)))
1692 LIST_PREPEND(Condition, conditions, u->meta.conditions, c);
1696 static DEFINE_CONFIG_PARSE_ENUM(config_parse_notify_access, notify_access, NotifyAccess, "Failed to parse notify access specifier");
1698 #define FOLLOW_MAX 8
1700 static int open_follow(char **filename, FILE **_f, Set *names, char **_final) {
1711 /* This will update the filename pointer if the loaded file is
1712 * reached by a symlink. The old string will be freed. */
1715 char *target, *name;
1717 if (c++ >= FOLLOW_MAX)
1720 path_kill_slashes(*filename);
1722 /* Add the file name we are currently looking at to
1723 * the names of this unit, but only if it is a valid
1725 name = file_name_from_path(*filename);
1727 if (unit_name_is_valid(name, true)) {
1729 id = set_get(names, name);
1735 r = set_put(names, id);
1743 /* Try to open the file name, but don't if its a symlink */
1744 if ((fd = open(*filename, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW)) >= 0)
1750 /* Hmm, so this is a symlink. Let's read the name, and follow it manually */
1751 if ((r = readlink_and_make_absolute(*filename, &target)) < 0)
1758 if (!(f = fdopen(fd, "re"))) {
1760 close_nointr_nofail(fd);
1769 static int merge_by_names(Unit **u, Set *names, const char *id) {
1777 /* Let's try to add in all symlink names we found */
1778 while ((k = set_steal_first(names))) {
1780 /* First try to merge in the other name into our
1782 if ((r = unit_merge_by_name(*u, k)) < 0) {
1785 /* Hmm, we couldn't merge the other unit into
1786 * ours? Then let's try it the other way
1789 other = manager_get_unit((*u)->meta.manager, k);
1793 if ((r = unit_merge(other, *u)) >= 0) {
1795 return merge_by_names(u, names, NULL);
1802 unit_choose_id(*u, id);
1810 static void dump_items(FILE *f, const ConfigItem *items) {
1811 const ConfigItem *i;
1812 const char *prev_section = NULL;
1813 bool not_first = false;
1816 ConfigParserCallback callback;
1819 { config_parse_int, "INTEGER" },
1820 { config_parse_unsigned, "UNSIGNED" },
1821 { config_parse_size, "SIZE" },
1822 { config_parse_bool, "BOOLEAN" },
1823 { config_parse_string, "STRING" },
1824 { config_parse_path, "PATH" },
1825 { config_parse_path_printf, "PATH" },
1826 { config_parse_strv, "STRING [...]" },
1827 { config_parse_nice, "NICE" },
1828 { config_parse_oom_score_adjust, "OOMSCOREADJUST" },
1829 { config_parse_io_class, "IOCLASS" },
1830 { config_parse_io_priority, "IOPRIORITY" },
1831 { config_parse_cpu_sched_policy, "CPUSCHEDPOLICY" },
1832 { config_parse_cpu_sched_prio, "CPUSCHEDPRIO" },
1833 { config_parse_cpu_affinity, "CPUAFFINITY" },
1834 { config_parse_mode, "MODE" },
1835 { config_parse_env_file, "FILE" },
1836 { config_parse_output, "OUTPUT" },
1837 { config_parse_input, "INPUT" },
1838 { config_parse_facility, "FACILITY" },
1839 { config_parse_level, "LEVEL" },
1840 { config_parse_capabilities, "CAPABILITIES" },
1841 { config_parse_secure_bits, "SECUREBITS" },
1842 { config_parse_bounding_set, "BOUNDINGSET" },
1843 { config_parse_timer_slack_nsec, "TIMERSLACK" },
1844 { config_parse_limit, "LIMIT" },
1845 { config_parse_cgroup, "CGROUP [...]" },
1846 { config_parse_deps, "UNIT [...]" },
1847 { config_parse_names, "UNIT [...]" },
1848 { config_parse_exec, "PATH [ARGUMENT [...]]" },
1849 { config_parse_service_type, "SERVICETYPE" },
1850 { config_parse_service_restart, "SERVICERESTART" },
1851 #ifdef HAVE_SYSV_COMPAT
1852 { config_parse_sysv_priority, "SYSVPRIORITY" },
1854 { config_parse_warn_compat, "NOTSUPPORTED" },
1856 { config_parse_kill_mode, "KILLMODE" },
1857 { config_parse_kill_signal, "SIGNAL" },
1858 { config_parse_listen, "SOCKET [...]" },
1859 { config_parse_socket_bind, "SOCKETBIND" },
1860 { config_parse_bindtodevice, "NETWORKINTERFACE" },
1861 { config_parse_usec, "SECONDS" },
1862 { config_parse_path_strv, "PATH [...]" },
1863 { config_parse_mount_flags, "MOUNTFLAG [...]" },
1864 { config_parse_string_printf, "STRING" },
1865 { config_parse_timer, "TIMER" },
1866 { config_parse_timer_unit, "NAME" },
1867 { config_parse_path_spec, "PATH" },
1868 { config_parse_path_unit, "UNIT" },
1869 { config_parse_notify_access, "ACCESS" },
1870 { config_parse_ip_tos, "TOS" },
1871 { config_parse_condition_path, "CONDITION" },
1872 { config_parse_condition_string, "CONDITION" },
1873 { config_parse_condition_null, "CONDITION" },
1879 for (i = items; i->lvalue; i++) {
1881 const char *rvalue = "OTHER";
1883 if (!streq_ptr(i->section, prev_section)) {
1889 fprintf(f, "[%s]\n", i->section);
1890 prev_section = i->section;
1893 for (j = 0; j < ELEMENTSOF(table); j++)
1894 if (i->parse == table[j].callback) {
1895 rvalue = table[j].rvalue;
1899 fprintf(f, "%s=%s\n", i->lvalue, rvalue);
1903 static int load_from_path(Unit *u, const char *path) {
1905 static const char* const section_table[_UNIT_TYPE_MAX] = {
1906 [UNIT_SERVICE] = "Service",
1907 [UNIT_TIMER] = "Timer",
1908 [UNIT_SOCKET] = "Socket",
1909 [UNIT_TARGET] = "Target",
1910 [UNIT_DEVICE] = "Device",
1911 [UNIT_MOUNT] = "Mount",
1912 [UNIT_AUTOMOUNT] = "Automount",
1913 [UNIT_SNAPSHOT] = "Snapshot",
1914 [UNIT_SWAP] = "Swap",
1915 [UNIT_PATH] = "Path"
1918 #define EXEC_CONTEXT_CONFIG_ITEMS(context, section) \
1919 { "WorkingDirectory", config_parse_path_printf, 0, &(context).working_directory, section }, \
1920 { "RootDirectory", config_parse_path_printf, 0, &(context).root_directory, section }, \
1921 { "User", config_parse_string_printf, 0, &(context).user, section }, \
1922 { "Group", config_parse_string_printf, 0, &(context).group, section }, \
1923 { "SupplementaryGroups", config_parse_strv, 0, &(context).supplementary_groups, section }, \
1924 { "Nice", config_parse_nice, 0, &(context), section }, \
1925 { "OOMScoreAdjust", config_parse_oom_score_adjust,0, &(context), section }, \
1926 { "IOSchedulingClass", config_parse_io_class, 0, &(context), section }, \
1927 { "IOSchedulingPriority", config_parse_io_priority, 0, &(context), section }, \
1928 { "CPUSchedulingPolicy", config_parse_cpu_sched_policy,0, &(context), section }, \
1929 { "CPUSchedulingPriority", config_parse_cpu_sched_prio, 0, &(context), section }, \
1930 { "CPUSchedulingResetOnFork", config_parse_bool, 0, &(context).cpu_sched_reset_on_fork, section }, \
1931 { "CPUAffinity", config_parse_cpu_affinity, 0, &(context), section }, \
1932 { "UMask", config_parse_mode, 0, &(context).umask, section }, \
1933 { "Environment", config_parse_strv_printf, 0, &(context).environment, section }, \
1934 { "EnvironmentFile", config_parse_env_file, 0, &(context).environment_files, section }, \
1935 { "StandardInput", config_parse_input, 0, &(context).std_input, section }, \
1936 { "StandardOutput", config_parse_output, 0, &(context).std_output, section }, \
1937 { "StandardError", config_parse_output, 0, &(context).std_error, section }, \
1938 { "TTYPath", config_parse_path_printf, 0, &(context).tty_path, section }, \
1939 { "TTYReset", config_parse_bool, 0, &(context).tty_reset, section }, \
1940 { "TTYVHangup", config_parse_bool, 0, &(context).tty_vhangup, section }, \
1941 { "TTYVTDisallocate", config_parse_bool, 0, &(context).tty_vt_disallocate, section }, \
1942 { "SyslogIdentifier", config_parse_string_printf, 0, &(context).syslog_identifier, section }, \
1943 { "SyslogFacility", config_parse_facility, 0, &(context).syslog_priority, section }, \
1944 { "SyslogLevel", config_parse_level, 0, &(context).syslog_priority, section }, \
1945 { "SyslogLevelPrefix", config_parse_bool, 0, &(context).syslog_level_prefix, section }, \
1946 { "Capabilities", config_parse_capabilities, 0, &(context), section }, \
1947 { "SecureBits", config_parse_secure_bits, 0, &(context), section }, \
1948 { "CapabilityBoundingSet", config_parse_bounding_set, 0, &(context), section }, \
1949 { "TimerSlackNSec", config_parse_timer_slack_nsec,0, &(context), section }, \
1950 { "LimitCPU", config_parse_limit, 0, &(context).rlimit[RLIMIT_CPU], section }, \
1951 { "LimitFSIZE", config_parse_limit, 0, &(context).rlimit[RLIMIT_FSIZE], section }, \
1952 { "LimitDATA", config_parse_limit, 0, &(context).rlimit[RLIMIT_DATA], section }, \
1953 { "LimitSTACK", config_parse_limit, 0, &(context).rlimit[RLIMIT_STACK], section }, \
1954 { "LimitCORE", config_parse_limit, 0, &(context).rlimit[RLIMIT_CORE], section }, \
1955 { "LimitRSS", config_parse_limit, 0, &(context).rlimit[RLIMIT_RSS], section }, \
1956 { "LimitNOFILE", config_parse_limit, 0, &(context).rlimit[RLIMIT_NOFILE], section }, \
1957 { "LimitAS", config_parse_limit, 0, &(context).rlimit[RLIMIT_AS], section }, \
1958 { "LimitNPROC", config_parse_limit, 0, &(context).rlimit[RLIMIT_NPROC], section }, \
1959 { "LimitMEMLOCK", config_parse_limit, 0, &(context).rlimit[RLIMIT_MEMLOCK], section }, \
1960 { "LimitLOCKS", config_parse_limit, 0, &(context).rlimit[RLIMIT_LOCKS], section }, \
1961 { "LimitSIGPENDING", config_parse_limit, 0, &(context).rlimit[RLIMIT_SIGPENDING], section }, \
1962 { "LimitMSGQUEUE", config_parse_limit, 0, &(context).rlimit[RLIMIT_MSGQUEUE], section }, \
1963 { "LimitNICE", config_parse_limit, 0, &(context).rlimit[RLIMIT_NICE], section }, \
1964 { "LimitRTPRIO", config_parse_limit, 0, &(context).rlimit[RLIMIT_RTPRIO], section }, \
1965 { "LimitRTTIME", config_parse_limit, 0, &(context).rlimit[RLIMIT_RTTIME], section }, \
1966 { "ControlGroup", config_parse_cgroup, 0, u, section }, \
1967 { "ReadWriteDirectories", config_parse_path_strv, 0, &(context).read_write_dirs, section }, \
1968 { "ReadOnlyDirectories", config_parse_path_strv, 0, &(context).read_only_dirs, section }, \
1969 { "InaccessibleDirectories",config_parse_path_strv, 0, &(context).inaccessible_dirs, section }, \
1970 { "PrivateTmp", config_parse_bool, 0, &(context).private_tmp, section }, \
1971 { "MountFlags", config_parse_mount_flags, 0, &(context), section }, \
1972 { "TCPWrapName", config_parse_string_printf, 0, &(context).tcpwrap_name, section }, \
1973 { "PAMName", config_parse_string_printf, 0, &(context).pam_name, section }, \
1974 { "KillMode", config_parse_kill_mode, 0, &(context).kill_mode, section }, \
1975 { "KillSignal", config_parse_kill_signal, 0, &(context).kill_signal, section }, \
1976 { "SendSIGKILL", config_parse_bool, 0, &(context).send_sigkill, section }, \
1977 { "UtmpIdentifier", config_parse_string_printf, 0, &(context).utmp_id, section }, \
1978 { "ControlGroupModify", config_parse_bool, 0, &(context).control_group_modify, section }
1980 const ConfigItem items[] = {
1981 { "Names", config_parse_names, 0, u, "Unit" },
1982 { "Description", config_parse_string_printf, 0, &u->meta.description, "Unit" },
1983 { "Requires", config_parse_deps, 0, UINT_TO_PTR(UNIT_REQUIRES), "Unit" },
1984 { "RequiresOverridable", config_parse_deps, 0, UINT_TO_PTR(UNIT_REQUIRES_OVERRIDABLE), "Unit" },
1985 { "Requisite", config_parse_deps, 0, UINT_TO_PTR(UNIT_REQUISITE), "Unit" },
1986 { "RequisiteOverridable", config_parse_deps, 0, UINT_TO_PTR(UNIT_REQUISITE_OVERRIDABLE), "Unit" },
1987 { "Wants", config_parse_deps, 0, UINT_TO_PTR(UNIT_WANTS), "Unit" },
1988 { "BindTo", config_parse_deps, 0, UINT_TO_PTR(UNIT_BIND_TO), "Unit" },
1989 { "Conflicts", config_parse_deps, 0, UINT_TO_PTR(UNIT_CONFLICTS), "Unit" },
1990 { "Before", config_parse_deps, 0, UINT_TO_PTR(UNIT_BEFORE), "Unit" },
1991 { "After", config_parse_deps, 0, UINT_TO_PTR(UNIT_AFTER), "Unit" },
1992 { "OnFailure", config_parse_deps, 0, UINT_TO_PTR(UNIT_ON_FAILURE), "Unit" },
1993 { "StopWhenUnneeded", config_parse_bool, 0, &u->meta.stop_when_unneeded, "Unit" },
1994 { "RefuseManualStart", config_parse_bool, 0, &u->meta.refuse_manual_start, "Unit" },
1995 { "RefuseManualStop", config_parse_bool, 0, &u->meta.refuse_manual_stop, "Unit" },
1996 { "AllowIsolate", config_parse_bool, 0, &u->meta.allow_isolate, "Unit" },
1997 { "DefaultDependencies", config_parse_bool, 0, &u->meta.default_dependencies, "Unit" },
1998 { "OnFailureIsolate", config_parse_bool, 0, &u->meta.on_failure_isolate, "Unit" },
1999 { "IgnoreOnIsolate", config_parse_bool, 0, &u->meta.ignore_on_isolate, "Unit" },
2000 { "IgnoreOnSnapshot", config_parse_bool, 0, &u->meta.ignore_on_snapshot, "Unit" },
2001 { "JobTimeoutSec", config_parse_usec, 0, &u->meta.job_timeout, "Unit" },
2002 { "ConditionPathExists", config_parse_condition_path, CONDITION_PATH_EXISTS, u, "Unit" },
2003 { "ConditionPathExistsGlob", config_parse_condition_path, CONDITION_PATH_EXISTS_GLOB, u, "Unit" },
2004 { "ConditionPathIsDirectory", config_parse_condition_path, CONDITION_PATH_IS_DIRECTORY, u, "Unit" },
2005 { "ConditionDirectoryNotEmpty", config_parse_condition_path, CONDITION_DIRECTORY_NOT_EMPTY, u, "Unit" },
2006 { "ConditionKernelCommandLine", config_parse_condition_string, CONDITION_KERNEL_COMMAND_LINE, u, "Unit" },
2007 { "ConditionVirtualization", config_parse_condition_string, CONDITION_VIRTUALIZATION, u, "Unit" },
2008 { "ConditionSecurity", config_parse_condition_string, CONDITION_SECURITY, u, "Unit" },
2009 { "ConditionNull", config_parse_condition_null, 0, u, "Unit" },
2011 { "PIDFile", config_parse_path_printf, 0, &u->service.pid_file, "Service" },
2012 { "ExecStartPre", config_parse_exec, 0, u->service.exec_command+SERVICE_EXEC_START_PRE, "Service" },
2013 { "ExecStart", config_parse_exec, 0, u->service.exec_command+SERVICE_EXEC_START, "Service" },
2014 { "ExecStartPost", config_parse_exec, 0, u->service.exec_command+SERVICE_EXEC_START_POST, "Service" },
2015 { "ExecReload", config_parse_exec, 0, u->service.exec_command+SERVICE_EXEC_RELOAD, "Service" },
2016 { "ExecStop", config_parse_exec, 0, u->service.exec_command+SERVICE_EXEC_STOP, "Service" },
2017 { "ExecStopPost", config_parse_exec, 0, u->service.exec_command+SERVICE_EXEC_STOP_POST, "Service" },
2018 { "RestartSec", config_parse_usec, 0, &u->service.restart_usec, "Service" },
2019 { "TimeoutSec", config_parse_usec, 0, &u->service.timeout_usec, "Service" },
2020 { "Type", config_parse_service_type, 0, &u->service.type, "Service" },
2021 { "Restart", config_parse_service_restart, 0, &u->service.restart, "Service" },
2022 { "PermissionsStartOnly", config_parse_bool, 0, &u->service.permissions_start_only, "Service" },
2023 { "RootDirectoryStartOnly", config_parse_bool, 0, &u->service.root_directory_start_only, "Service" },
2024 { "RemainAfterExit", config_parse_bool, 0, &u->service.remain_after_exit, "Service" },
2025 { "GuessMainPID", config_parse_bool, 0, &u->service.guess_main_pid, "Service" },
2026 #ifdef HAVE_SYSV_COMPAT
2027 { "SysVStartPriority", config_parse_sysv_priority, 0, &u->service.sysv_start_priority, "Service" },
2029 { "SysVStartPriority", config_parse_warn_compat, 0, NULL, "Service" },
2031 { "NonBlocking", config_parse_bool, 0, &u->service.exec_context.non_blocking, "Service" },
2032 { "BusName", config_parse_string_printf, 0, &u->service.bus_name, "Service" },
2033 { "NotifyAccess", config_parse_notify_access, 0, &u->service.notify_access, "Service" },
2034 { "Sockets", config_parse_service_sockets, 0, &u->service, "Service" },
2035 { "FsckPassNo", config_parse_fsck_passno, 0, &u->service.fsck_passno, "Service" },
2036 EXEC_CONTEXT_CONFIG_ITEMS(u->service.exec_context, "Service"),
2038 { "ListenStream", config_parse_listen, 0, &u->socket, "Socket" },
2039 { "ListenDatagram", config_parse_listen, 0, &u->socket, "Socket" },
2040 { "ListenSequentialPacket", config_parse_listen, 0, &u->socket, "Socket" },
2041 { "ListenFIFO", config_parse_listen, 0, &u->socket, "Socket" },
2042 { "ListenNetlink", config_parse_listen, 0, &u->socket, "Socket" },
2043 { "ListenSpecial", config_parse_listen, 0, &u->socket, "Socket" },
2044 { "ListenMessageQueue", config_parse_listen, 0, &u->socket, "Socket" },
2045 { "BindIPv6Only", config_parse_socket_bind, 0, &u->socket, "Socket" },
2046 { "Backlog", config_parse_unsigned, 0, &u->socket.backlog, "Socket" },
2047 { "BindToDevice", config_parse_bindtodevice, 0, &u->socket, "Socket" },
2048 { "ExecStartPre", config_parse_exec, 0, u->socket.exec_command+SOCKET_EXEC_START_PRE, "Socket" },
2049 { "ExecStartPost", config_parse_exec, 0, u->socket.exec_command+SOCKET_EXEC_START_POST, "Socket" },
2050 { "ExecStopPre", config_parse_exec, 0, u->socket.exec_command+SOCKET_EXEC_STOP_PRE, "Socket" },
2051 { "ExecStopPost", config_parse_exec, 0, u->socket.exec_command+SOCKET_EXEC_STOP_POST, "Socket" },
2052 { "TimeoutSec", config_parse_usec, 0, &u->socket.timeout_usec, "Socket" },
2053 { "DirectoryMode", config_parse_mode, 0, &u->socket.directory_mode, "Socket" },
2054 { "SocketMode", config_parse_mode, 0, &u->socket.socket_mode, "Socket" },
2055 { "Accept", config_parse_bool, 0, &u->socket.accept, "Socket" },
2056 { "MaxConnections", config_parse_unsigned, 0, &u->socket.max_connections, "Socket" },
2057 { "KeepAlive", config_parse_bool, 0, &u->socket.keep_alive, "Socket" },
2058 { "Priority", config_parse_int, 0, &u->socket.priority, "Socket" },
2059 { "ReceiveBuffer", config_parse_size, 0, &u->socket.receive_buffer, "Socket" },
2060 { "SendBuffer", config_parse_size, 0, &u->socket.send_buffer, "Socket" },
2061 { "IPTOS", config_parse_ip_tos, 0, &u->socket.ip_tos, "Socket" },
2062 { "IPTTL", config_parse_int, 0, &u->socket.ip_ttl, "Socket" },
2063 { "Mark", config_parse_int, 0, &u->socket.mark, "Socket" },
2064 { "PipeSize", config_parse_size, 0, &u->socket.pipe_size, "Socket" },
2065 { "FreeBind", config_parse_bool, 0, &u->socket.free_bind, "Socket" },
2066 { "Transparent", config_parse_bool, 0, &u->socket.transparent, "Socket" },
2067 { "Broadcast", config_parse_bool, 0, &u->socket.broadcast, "Socket" },
2068 { "TCPCongestion", config_parse_string, 0, &u->socket.tcp_congestion, "Socket" },
2069 { "MessageQueueMaxMessages", config_parse_long, 0, &u->socket.mq_maxmsg, "Socket" },
2070 { "MessageQueueMessageSize", config_parse_long, 0, &u->socket.mq_msgsize, "Socket" },
2071 { "Service", config_parse_socket_service, 0, &u->socket, "Socket" },
2072 EXEC_CONTEXT_CONFIG_ITEMS(u->socket.exec_context, "Socket"),
2074 { "What", config_parse_string, 0, &u->mount.parameters_fragment.what, "Mount" },
2075 { "Where", config_parse_path, 0, &u->mount.where, "Mount" },
2076 { "Options", config_parse_string, 0, &u->mount.parameters_fragment.options, "Mount" },
2077 { "Type", config_parse_string, 0, &u->mount.parameters_fragment.fstype, "Mount" },
2078 { "TimeoutSec", config_parse_usec, 0, &u->mount.timeout_usec, "Mount" },
2079 { "DirectoryMode", config_parse_mode, 0, &u->mount.directory_mode, "Mount" },
2080 EXEC_CONTEXT_CONFIG_ITEMS(u->mount.exec_context, "Mount"),
2082 { "Where", config_parse_path, 0, &u->automount.where, "Automount" },
2083 { "DirectoryMode", config_parse_mode, 0, &u->automount.directory_mode, "Automount" },
2085 { "What", config_parse_path, 0, &u->swap.parameters_fragment.what, "Swap" },
2086 { "Priority", config_parse_int, 0, &u->swap.parameters_fragment.priority, "Swap" },
2087 { "TimeoutSec", config_parse_usec, 0, &u->swap.timeout_usec, "Swap" },
2088 EXEC_CONTEXT_CONFIG_ITEMS(u->swap.exec_context, "Swap"),
2090 { "OnActiveSec", config_parse_timer, 0, &u->timer, "Timer" },
2091 { "OnBootSec", config_parse_timer, 0, &u->timer, "Timer" },
2092 { "OnStartupSec", config_parse_timer, 0, &u->timer, "Timer" },
2093 { "OnUnitActiveSec", config_parse_timer, 0, &u->timer, "Timer" },
2094 { "OnUnitInactiveSec", config_parse_timer, 0, &u->timer, "Timer" },
2095 { "Unit", config_parse_timer_unit, 0, &u->timer, "Timer" },
2097 { "PathExists", config_parse_path_spec, 0, &u->path, "Path" },
2098 { "PathExistsGlob", config_parse_path_spec, 0, &u->path, "Path" },
2099 { "PathChanged", config_parse_path_spec, 0, &u->path, "Path" },
2100 { "DirectoryNotEmpty", config_parse_path_spec, 0, &u->path, "Path" },
2101 { "Unit", config_parse_path_unit, 0, &u->path, "Path" },
2102 { "MakeDirectory", config_parse_bool, 0, &u->path.make_directory, "Path" },
2103 { "DirectoryMode", config_parse_mode, 0, &u->path.directory_mode, "Path" },
2105 /* The [Install] section is ignored here. */
2106 { "Alias", NULL, 0, NULL, "Install" },
2107 { "WantedBy", NULL, 0, NULL, "Install" },
2108 { "Also", NULL, 0, NULL, "Install" },
2110 { NULL, NULL, 0, NULL, NULL }
2113 #undef EXEC_CONTEXT_CONFIG_ITEMS
2115 const char *sections[4];
2119 char *filename = NULL, *id = NULL;
2124 /* Dirty dirty hack. */
2125 dump_items((FILE*) path, items);
2132 sections[0] = "Unit";
2133 sections[1] = section_table[u->meta.type];
2134 sections[2] = "Install";
2137 if (!(symlink_names = set_new(string_hash_func, string_compare_func)))
2140 if (path_is_absolute(path)) {
2142 if (!(filename = strdup(path))) {
2147 if ((r = open_follow(&filename, &f, symlink_names, &id)) < 0) {
2158 STRV_FOREACH(p, u->meta.manager->lookup_paths.unit_path) {
2160 /* Instead of opening the path right away, we manually
2161 * follow all symlinks and add their name to our unit
2162 * name set while doing so */
2163 if (!(filename = path_make_absolute(path, *p))) {
2168 if (u->meta.manager->unit_path_cache &&
2169 !set_get(u->meta.manager->unit_path_cache, filename))
2172 r = open_follow(&filename, &f, symlink_names, &id);
2183 /* Empty the symlink names for the next run */
2184 while ((sn = set_steal_first(symlink_names)))
2195 /* Hmm, no suitable file found? */
2201 if ((r = merge_by_names(&merged, symlink_names, id)) < 0)
2205 u->meta.load_state = UNIT_MERGED;
2211 if (fstat(fileno(f), &st) < 0) {
2216 if (null_or_empty(&st))
2217 u->meta.load_state = UNIT_MASKED;
2219 /* Now, parse the file contents */
2220 if ((r = config_parse(filename, f, sections, items, false, u)) < 0)
2223 u->meta.load_state = UNIT_LOADED;
2226 free(u->meta.fragment_path);
2227 u->meta.fragment_path = filename;
2230 u->meta.fragment_mtime = timespec_load(&st.st_mtim);
2235 set_free_free(symlink_names);
2244 int unit_load_fragment(Unit *u) {
2250 assert(u->meta.load_state == UNIT_STUB);
2253 /* First, try to find the unit under its id. We always look
2254 * for unit files in the default directories, to make it easy
2255 * to override things by placing things in /etc/systemd/system */
2256 if ((r = load_from_path(u, u->meta.id)) < 0)
2259 /* Try to find an alias we can load this with */
2260 if (u->meta.load_state == UNIT_STUB)
2261 SET_FOREACH(t, u->meta.names, i) {
2263 if (t == u->meta.id)
2266 if ((r = load_from_path(u, t)) < 0)
2269 if (u->meta.load_state != UNIT_STUB)
2273 /* And now, try looking for it under the suggested (originally linked) path */
2274 if (u->meta.load_state == UNIT_STUB && u->meta.fragment_path) {
2276 if ((r = load_from_path(u, u->meta.fragment_path)) < 0)
2279 if (u->meta.load_state == UNIT_STUB) {
2280 /* Hmm, this didn't work? Then let's get rid
2281 * of the fragment path stored for us, so that
2282 * we don't point to an invalid location. */
2283 free(u->meta.fragment_path);
2284 u->meta.fragment_path = NULL;
2288 /* Look for a template */
2289 if (u->meta.load_state == UNIT_STUB && u->meta.instance) {
2292 if (!(k = unit_name_template(u->meta.id)))
2295 r = load_from_path(u, k);
2301 if (u->meta.load_state == UNIT_STUB)
2302 SET_FOREACH(t, u->meta.names, i) {
2304 if (t == u->meta.id)
2307 if (!(k = unit_name_template(t)))
2310 r = load_from_path(u, k);
2316 if (u->meta.load_state != UNIT_STUB)
2324 void unit_dump_config_items(FILE *f) {
2325 /* OK, this wins a prize for extreme ugliness. */
2327 load_from_path(NULL, (const void*) f);