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_path_printf(
192 const char *filename,
211 if (!(k = unit_full_printf(u, rvalue)))
214 if (!path_is_absolute(k)) {
215 log_error("[%s:%u] Not an absolute path: %s", filename, line, k);
220 path_kill_slashes(k);
228 static int config_parse_listen(
229 const char *filename,
238 SocketPort *p, *tail;
248 if (!(p = new0(SocketPort, 1)))
251 if (streq(lvalue, "ListenFIFO")) {
252 p->type = SOCKET_FIFO;
254 if (!(p->path = unit_full_printf(UNIT(s), rvalue))) {
259 path_kill_slashes(p->path);
261 } else if (streq(lvalue, "ListenSpecial")) {
262 p->type = SOCKET_SPECIAL;
264 if (!(p->path = unit_full_printf(UNIT(s), rvalue))) {
269 path_kill_slashes(p->path);
271 } else if (streq(lvalue, "ListenMessageQueue")) {
273 p->type = SOCKET_MQUEUE;
275 if (!(p->path = unit_full_printf(UNIT(s), rvalue))) {
280 path_kill_slashes(p->path);
282 } else if (streq(lvalue, "ListenNetlink")) {
286 p->type = SOCKET_SOCKET;
287 k = unit_full_printf(UNIT(s), rvalue);
288 r = socket_address_parse_netlink(&p->address, k);
292 log_error("[%s:%u] Failed to parse address value, ignoring: %s", filename, line, rvalue);
301 p->type = SOCKET_SOCKET;
302 k = unit_full_printf(UNIT(s), rvalue);
303 r = socket_address_parse(&p->address, k);
307 log_error("[%s:%u] Failed to parse address value, ignoring: %s", filename, line, rvalue);
312 if (streq(lvalue, "ListenStream"))
313 p->address.type = SOCK_STREAM;
314 else if (streq(lvalue, "ListenDatagram"))
315 p->address.type = SOCK_DGRAM;
317 assert(streq(lvalue, "ListenSequentialPacket"));
318 p->address.type = SOCK_SEQPACKET;
321 if (socket_address_family(&p->address) != AF_LOCAL && p->address.type == SOCK_SEQPACKET) {
322 log_error("[%s:%u] Address family not supported, ignoring: %s", filename, line, rvalue);
331 LIST_FIND_TAIL(SocketPort, port, s->ports, tail);
332 LIST_INSERT_AFTER(SocketPort, port, s->ports, tail, p);
334 LIST_PREPEND(SocketPort, port, s->ports, p);
339 static int config_parse_socket_bind(
340 const char *filename,
350 SocketAddressBindIPv6Only b;
359 if ((b = socket_address_bind_ipv6_only_from_string(rvalue)) < 0) {
362 if ((r = parse_boolean(rvalue)) < 0) {
363 log_error("[%s:%u] Failed to parse bind IPv6 only value, ignoring: %s", filename, line, rvalue);
367 s->bind_ipv6_only = r ? SOCKET_ADDRESS_IPV6_ONLY : SOCKET_ADDRESS_BOTH;
369 s->bind_ipv6_only = b;
374 static int config_parse_nice(
375 const char *filename,
384 ExecContext *c = data;
392 if (safe_atoi(rvalue, &priority) < 0) {
393 log_error("[%s:%u] Failed to parse nice priority, ignoring: %s. ", filename, line, rvalue);
397 if (priority < PRIO_MIN || priority >= PRIO_MAX) {
398 log_error("[%s:%u] Nice priority out of range, ignoring: %s", filename, line, rvalue);
408 static int config_parse_oom_score_adjust(
409 const char *filename,
418 ExecContext *c = data;
426 if (safe_atoi(rvalue, &oa) < 0) {
427 log_error("[%s:%u] Failed to parse the OOM score adjust value, ignoring: %s", filename, line, rvalue);
431 if (oa < OOM_SCORE_ADJ_MIN || oa > OOM_SCORE_ADJ_MAX) {
432 log_error("[%s:%u] OOM score adjust value out of range, ignoring: %s", filename, line, rvalue);
436 c->oom_score_adjust = oa;
437 c->oom_score_adjust_set = true;
442 static int config_parse_mode(
443 const char *filename,
462 l = strtol(rvalue, &x, 8);
463 if (!x || *x || errno) {
464 log_error("[%s:%u] Failed to parse mode value, ignoring: %s", filename, line, rvalue);
468 if (l < 0000 || l > 07777) {
469 log_error("[%s:%u] mode value out of range, ignoring: %s", filename, line, rvalue);
477 static int config_parse_exec(
478 const char *filename,
487 ExecCommand **e = data, *nce;
496 /* We accept an absolute path as first argument, or
497 * alternatively an absolute prefixed with @ to allow
498 * overriding of argv[0]. */
504 bool honour_argv0 = false, ignore = false;
510 rvalue += strspn(rvalue, WHITESPACE);
515 if (rvalue[0] == '-') {
520 if (rvalue[0] == '@') {
525 if (*rvalue != '/') {
526 log_error("[%s:%u] Invalid executable path in command line, ignoring: %s", filename, line, rvalue);
531 FOREACH_WORD_QUOTED(w, l, rvalue, state) {
532 if (strncmp(w, ";", MAX(l, 1U)) == 0)
538 if (!(n = new(char*, k + !honour_argv0)))
542 FOREACH_WORD_QUOTED(w, l, rvalue, state) {
543 if (strncmp(w, ";", MAX(l, 1U)) == 0)
546 if (honour_argv0 && w == rvalue) {
548 if (!(path = cunescape_length(w, l)))
551 if (!(n[k++] = cunescape_length(w, l)))
559 log_error("[%s:%u] Invalid command line, ignoring: %s", filename, line, rvalue);
565 if (!(path = strdup(n[0])))
568 assert(path_is_absolute(path));
570 if (!(nce = new0(ExecCommand, 1)))
575 nce->ignore = ignore;
577 path_kill_slashes(nce->path);
579 exec_command_append_list(e, nce);
595 static int config_parse_usec(
596 const char *filename,
612 if (parse_usec(rvalue, usec) < 0) {
613 log_error("[%s:%u] Failed to parse time value, ignoring: %s", filename, line, rvalue);
620 static DEFINE_CONFIG_PARSE_ENUM(config_parse_service_type, service_type, ServiceType, "Failed to parse service type");
621 static DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart, service_restart, ServiceRestart, "Failed to parse service restart specifier");
623 static int config_parse_bindtodevice(
624 const char *filename,
641 if (rvalue[0] && !streq(rvalue, "*")) {
642 if (!(n = strdup(rvalue)))
647 free(s->bind_to_device);
648 s->bind_to_device = n;
653 static DEFINE_CONFIG_PARSE_ENUM(config_parse_output, exec_output, ExecOutput, "Failed to parse output specifier");
654 static DEFINE_CONFIG_PARSE_ENUM(config_parse_input, exec_input, ExecInput, "Failed to parse input specifier");
656 static int config_parse_facility(
657 const char *filename,
674 if ((x = log_facility_unshifted_from_string(rvalue)) < 0) {
675 log_error("[%s:%u] Failed to parse log facility, ignoring: %s", filename, line, rvalue);
679 *o = (x << 3) | LOG_PRI(*o);
684 static int config_parse_level(
685 const char *filename,
702 if ((x = log_level_from_string(rvalue)) < 0) {
703 log_error("[%s:%u] Failed to parse log level, ignoring: %s", filename, line, rvalue);
707 *o = (*o & LOG_FACMASK) | x;
711 static int config_parse_io_class(
712 const char *filename,
721 ExecContext *c = data;
729 if ((x = ioprio_class_from_string(rvalue)) < 0) {
730 log_error("[%s:%u] Failed to parse IO scheduling class, ignoring: %s", filename, line, rvalue);
734 c->ioprio = IOPRIO_PRIO_VALUE(x, IOPRIO_PRIO_DATA(c->ioprio));
735 c->ioprio_set = true;
740 static int config_parse_io_priority(
741 const char *filename,
750 ExecContext *c = data;
758 if (safe_atoi(rvalue, &i) < 0 || i < 0 || i >= IOPRIO_BE_NR) {
759 log_error("[%s:%u] Failed to parse io priority, ignoring: %s", filename, line, rvalue);
763 c->ioprio = IOPRIO_PRIO_VALUE(IOPRIO_PRIO_CLASS(c->ioprio), i);
764 c->ioprio_set = true;
769 static int config_parse_cpu_sched_policy(
770 const char *filename,
780 ExecContext *c = data;
788 if ((x = sched_policy_from_string(rvalue)) < 0) {
789 log_error("[%s:%u] Failed to parse CPU scheduling policy, ignoring: %s", filename, line, rvalue);
793 c->cpu_sched_policy = x;
794 c->cpu_sched_set = true;
799 static int config_parse_cpu_sched_prio(
800 const char *filename,
809 ExecContext *c = data;
817 /* On Linux RR/FIFO have the same range */
818 if (safe_atoi(rvalue, &i) < 0 || i < sched_get_priority_min(SCHED_RR) || i > sched_get_priority_max(SCHED_RR)) {
819 log_error("[%s:%u] Failed to parse CPU scheduling priority, ignoring: %s", filename, line, rvalue);
823 c->cpu_sched_priority = i;
824 c->cpu_sched_set = true;
829 static int config_parse_cpu_affinity(
830 const char *filename,
839 ExecContext *c = data;
849 FOREACH_WORD_QUOTED(w, l, rvalue, state) {
854 if (!(t = strndup(w, l)))
857 r = safe_atou(t, &cpu);
861 if (!(c->cpuset = cpu_set_malloc(&c->cpuset_ncpus)))
864 if (r < 0 || cpu >= c->cpuset_ncpus) {
865 log_error("[%s:%u] Failed to parse CPU affinity, ignoring: %s", filename, line, rvalue);
869 CPU_SET_S(cpu, CPU_ALLOC_SIZE(c->cpuset_ncpus), c->cpuset);
875 static int config_parse_capabilities(
876 const char *filename,
885 ExecContext *c = data;
893 if (!(cap = cap_from_text(rvalue))) {
897 log_error("[%s:%u] Failed to parse capabilities, ignoring: %s", filename, line, rvalue);
902 cap_free(c->capabilities);
903 c->capabilities = cap;
908 static int config_parse_secure_bits(
909 const char *filename,
918 ExecContext *c = data;
928 FOREACH_WORD_QUOTED(w, l, rvalue, state) {
929 if (first_word(w, "keep-caps"))
930 c->secure_bits |= SECURE_KEEP_CAPS;
931 else if (first_word(w, "keep-caps-locked"))
932 c->secure_bits |= SECURE_KEEP_CAPS_LOCKED;
933 else if (first_word(w, "no-setuid-fixup"))
934 c->secure_bits |= SECURE_NO_SETUID_FIXUP;
935 else if (first_word(w, "no-setuid-fixup-locked"))
936 c->secure_bits |= SECURE_NO_SETUID_FIXUP_LOCKED;
937 else if (first_word(w, "noroot"))
938 c->secure_bits |= SECURE_NOROOT;
939 else if (first_word(w, "noroot-locked"))
940 c->secure_bits |= SECURE_NOROOT_LOCKED;
942 log_error("[%s:%u] Failed to parse secure bits, ignoring: %s", filename, line, rvalue);
950 static int config_parse_bounding_set(
951 const char *filename,
960 ExecContext *c = data;
972 if (rvalue[0] == '~') {
977 /* Note that we store this inverted internally, since the
978 * kernel wants it like this. But we actually expose it
979 * non-inverted everywhere to have a fully normalized
982 FOREACH_WORD_QUOTED(w, l, rvalue, state) {
987 if (!(t = strndup(w, l)))
990 r = cap_from_name(t, &cap);
994 log_error("[%s:%u] Failed to parse capability bounding set, ignoring: %s", filename, line, rvalue);
998 sum |= ((uint64_t) 1ULL) << (uint64_t) cap;
1002 c->capability_bounding_set_drop |= sum;
1004 c->capability_bounding_set_drop |= ~sum;
1009 static int config_parse_timer_slack_nsec(
1010 const char *filename,
1012 const char *section,
1019 ExecContext *c = data;
1027 if (safe_atolu(rvalue, &u) < 0) {
1028 log_error("[%s:%u] Failed to parse time slack value, ignoring: %s", filename, line, rvalue);
1032 c->timer_slack_nsec = u;
1037 static int config_parse_limit(
1038 const char *filename,
1040 const char *section,
1047 struct rlimit **rl = data;
1048 unsigned long long u;
1055 if (streq(rvalue, "infinity"))
1056 u = (unsigned long long) RLIM_INFINITY;
1057 else if (safe_atollu(rvalue, &u) < 0) {
1058 log_error("[%s:%u] Failed to parse resource value, ignoring: %s", filename, line, rvalue);
1063 if (!(*rl = new(struct rlimit, 1)))
1066 (*rl)->rlim_cur = (*rl)->rlim_max = (rlim_t) u;
1070 static int config_parse_cgroup(
1071 const char *filename,
1073 const char *section,
1085 FOREACH_WORD_QUOTED(w, l, rvalue, state) {
1093 k = unit_full_printf(u, t);
1105 r = unit_add_cgroup_from_text(u, t);
1109 log_error("[%s:%u] Failed to parse cgroup value, ignoring: %s", filename, line, rvalue);
1117 #ifdef HAVE_SYSV_COMPAT
1118 static int config_parse_sysv_priority(
1119 const char *filename,
1121 const char *section,
1128 int *priority = data;
1136 if (safe_atoi(rvalue, &i) < 0 || i < 0) {
1137 log_error("[%s:%u] Failed to parse SysV start priority, ignoring: %s", filename, line, rvalue);
1141 *priority = (int) i;
1146 static int config_parse_fsck_passno(
1147 const char *filename,
1149 const char *section,
1164 if (safe_atoi(rvalue, &i) || i < 0) {
1165 log_error("[%s:%u] Failed to parse fsck pass number, ignoring: %s", filename, line, rvalue);
1173 static DEFINE_CONFIG_PARSE_ENUM(config_parse_kill_mode, kill_mode, KillMode, "Failed to parse kill mode");
1175 static int config_parse_kill_signal(
1176 const char *filename,
1178 const char *section,
1193 if ((r = signal_from_string_try_harder(rvalue)) <= 0) {
1194 log_error("[%s:%u] Failed to parse kill signal, ignoring: %s", filename, line, rvalue);
1202 static int config_parse_mount_flags(
1203 const char *filename,
1205 const char *section,
1212 ExecContext *c = data;
1216 unsigned long flags = 0;
1223 FOREACH_WORD_QUOTED(w, l, rvalue, state) {
1224 if (strncmp(w, "shared", MAX(l, 6U)) == 0)
1226 else if (strncmp(w, "slave", MAX(l, 5U)) == 0)
1228 else if (strncmp(w, "private", MAX(l, 7U)) == 0)
1229 flags |= MS_PRIVATE;
1231 log_error("[%s:%u] Failed to parse mount flags, ignoring: %s", filename, line, rvalue);
1236 c->mount_flags = flags;
1240 static int config_parse_timer(
1241 const char *filename,
1243 const char *section,
1260 if ((b = timer_base_from_string(lvalue)) < 0) {
1261 log_error("[%s:%u] Failed to parse timer base, ignoring: %s", filename, line, lvalue);
1265 if (parse_usec(rvalue, &u) < 0) {
1266 log_error("[%s:%u] Failed to parse timer value, ignoring: %s", filename, line, rvalue);
1270 if (!(v = new0(TimerValue, 1)))
1276 LIST_PREPEND(TimerValue, value, t->values, v);
1281 static int config_parse_timer_unit(
1282 const char *filename,
1284 const char *section,
1300 dbus_error_init(&error);
1302 if (endswith(rvalue, ".timer")) {
1303 log_error("[%s:%u] Unit cannot be of type timer, ignoring: %s", filename, line, rvalue);
1307 if ((r = manager_load_unit(t->meta.manager, rvalue, NULL, NULL, &t->unit)) < 0) {
1308 log_error("[%s:%u] Failed to load unit %s, ignoring: %s", filename, line, rvalue, bus_error(&error, r));
1309 dbus_error_free(&error);
1316 static int config_parse_path_spec(
1317 const char *filename,
1319 const char *section,
1335 if ((b = path_type_from_string(lvalue)) < 0) {
1336 log_error("[%s:%u] Failed to parse path type, ignoring: %s", filename, line, lvalue);
1340 if (!path_is_absolute(rvalue)) {
1341 log_error("[%s:%u] Path is not absolute, ignoring: %s", filename, line, rvalue);
1345 if (!(s = new0(PathSpec, 1)))
1348 if (!(s->path = strdup(rvalue))) {
1353 path_kill_slashes(s->path);
1358 LIST_PREPEND(PathSpec, spec, p->specs, s);
1363 static int config_parse_path_unit(
1364 const char *filename,
1366 const char *section,
1382 dbus_error_init(&error);
1384 if (endswith(rvalue, ".path")) {
1385 log_error("[%s:%u] Unit cannot be of type path, ignoring: %s", filename, line, rvalue);
1389 if ((r = manager_load_unit(t->meta.manager, rvalue, NULL, &error, &t->unit)) < 0) {
1390 log_error("[%s:%u] Failed to load unit %s, ignoring: %s", filename, line, rvalue, bus_error(&error, r));
1391 dbus_error_free(&error);
1398 static int config_parse_socket_service(
1399 const char *filename,
1401 const char *section,
1417 dbus_error_init(&error);
1419 if (!endswith(rvalue, ".service")) {
1420 log_error("[%s:%u] Unit must be of type service, ignoring: %s", filename, line, rvalue);
1424 if ((r = manager_load_unit(s->meta.manager, rvalue, NULL, &error, (Unit**) &s->service)) < 0) {
1425 log_error("[%s:%u] Failed to load unit %s, ignoring: %s", filename, line, rvalue, bus_error(&error, r));
1426 dbus_error_free(&error);
1433 static int config_parse_service_sockets(
1434 const char *filename,
1436 const char *section,
1454 dbus_error_init(&error);
1456 FOREACH_WORD_QUOTED(w, l, rvalue, state) {
1460 if (!(t = strndup(w, l)))
1463 if (!endswith(t, ".socket")) {
1464 log_error("[%s:%u] Unit must be of type socket, ignoring: %s", filename, line, rvalue);
1469 r = manager_load_unit(s->meta.manager, t, NULL, &error, &sock);
1473 log_error("[%s:%u] Failed to load unit %s, ignoring: %s", filename, line, rvalue, bus_error(&error, r));
1474 dbus_error_free(&error);
1478 if ((r = set_ensure_allocated(&s->configured_sockets, trivial_hash_func, trivial_compare_func)) < 0)
1481 if ((r = set_put(s->configured_sockets, sock)) < 0)
1488 static int config_parse_env_file(
1489 const char *filename,
1491 const char *section,
1498 char ***env = data, **k;
1505 if (!path_is_absolute(rvalue[0] == '-' ? rvalue + 1 : rvalue)) {
1506 log_error("[%s:%u] Path '%s' is not absolute, ignoring.", filename, line, rvalue);
1510 if (!(k = strv_append(*env, rvalue)))
1519 static int config_parse_ip_tos(
1520 const char *filename,
1522 const char *section,
1529 int *ip_tos = data, x;
1536 if ((x = ip_tos_from_string(rvalue)) < 0)
1537 if (safe_atoi(rvalue, &x) < 0) {
1538 log_error("[%s:%u] Failed to parse IP TOS value, ignoring: %s", filename, line, rvalue);
1546 static int config_parse_condition_path(
1547 const char *filename,
1549 const char *section,
1556 ConditionType cond = ltype;
1558 bool trigger, negate;
1566 if ((trigger = rvalue[0] == '|'))
1569 if ((negate = rvalue[0] == '!'))
1572 if (!path_is_absolute(rvalue)) {
1573 log_error("[%s:%u] Path in condition not absolute, ignoring: %s", filename, line, rvalue);
1577 if (!(c = condition_new(cond, rvalue, trigger, negate)))
1580 LIST_PREPEND(Condition, conditions, u->meta.conditions, c);
1584 static int config_parse_condition_string(
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 (!(c = condition_new(cond, rvalue, trigger, negate)))
1613 LIST_PREPEND(Condition, conditions, u->meta.conditions, c);
1617 static int config_parse_condition_null(
1618 const char *filename,
1620 const char *section,
1629 bool trigger, negate;
1637 if ((trigger = rvalue[0] == '|'))
1640 if ((negate = rvalue[0] == '!'))
1643 if ((b = parse_boolean(rvalue)) < 0) {
1644 log_error("[%s:%u] Failed to parse boolean value in condition, ignoring: %s", filename, line, rvalue);
1651 if (!(c = condition_new(CONDITION_NULL, NULL, trigger, negate)))
1654 LIST_PREPEND(Condition, conditions, u->meta.conditions, c);
1658 static DEFINE_CONFIG_PARSE_ENUM(config_parse_notify_access, notify_access, NotifyAccess, "Failed to parse notify access specifier");
1660 #define FOLLOW_MAX 8
1662 static int open_follow(char **filename, FILE **_f, Set *names, char **_final) {
1673 /* This will update the filename pointer if the loaded file is
1674 * reached by a symlink. The old string will be freed. */
1677 char *target, *name;
1679 if (c++ >= FOLLOW_MAX)
1682 path_kill_slashes(*filename);
1684 /* Add the file name we are currently looking at to
1685 * the names of this unit, but only if it is a valid
1687 name = file_name_from_path(*filename);
1689 if (unit_name_is_valid(name, true)) {
1691 id = set_get(names, name);
1697 r = set_put(names, id);
1705 /* Try to open the file name, but don't if its a symlink */
1706 if ((fd = open(*filename, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW)) >= 0)
1712 /* Hmm, so this is a symlink. Let's read the name, and follow it manually */
1713 if ((r = readlink_and_make_absolute(*filename, &target)) < 0)
1720 if (!(f = fdopen(fd, "re"))) {
1722 close_nointr_nofail(fd);
1731 static int merge_by_names(Unit **u, Set *names, const char *id) {
1739 /* Let's try to add in all symlink names we found */
1740 while ((k = set_steal_first(names))) {
1742 /* First try to merge in the other name into our
1744 if ((r = unit_merge_by_name(*u, k)) < 0) {
1747 /* Hmm, we couldn't merge the other unit into
1748 * ours? Then let's try it the other way
1751 other = manager_get_unit((*u)->meta.manager, k);
1755 if ((r = unit_merge(other, *u)) >= 0) {
1757 return merge_by_names(u, names, NULL);
1764 unit_choose_id(*u, id);
1772 static void dump_items(FILE *f, const ConfigItem *items) {
1773 const ConfigItem *i;
1774 const char *prev_section = NULL;
1775 bool not_first = false;
1778 ConfigParserCallback callback;
1781 { config_parse_int, "INTEGER" },
1782 { config_parse_unsigned, "UNSIGNED" },
1783 { config_parse_size, "SIZE" },
1784 { config_parse_bool, "BOOLEAN" },
1785 { config_parse_string, "STRING" },
1786 { config_parse_path, "PATH" },
1787 { config_parse_path_printf, "PATH" },
1788 { config_parse_strv, "STRING [...]" },
1789 { config_parse_nice, "NICE" },
1790 { config_parse_oom_score_adjust, "OOMSCOREADJUST" },
1791 { config_parse_io_class, "IOCLASS" },
1792 { config_parse_io_priority, "IOPRIORITY" },
1793 { config_parse_cpu_sched_policy, "CPUSCHEDPOLICY" },
1794 { config_parse_cpu_sched_prio, "CPUSCHEDPRIO" },
1795 { config_parse_cpu_affinity, "CPUAFFINITY" },
1796 { config_parse_mode, "MODE" },
1797 { config_parse_env_file, "FILE" },
1798 { config_parse_output, "OUTPUT" },
1799 { config_parse_input, "INPUT" },
1800 { config_parse_facility, "FACILITY" },
1801 { config_parse_level, "LEVEL" },
1802 { config_parse_capabilities, "CAPABILITIES" },
1803 { config_parse_secure_bits, "SECUREBITS" },
1804 { config_parse_bounding_set, "BOUNDINGSET" },
1805 { config_parse_timer_slack_nsec, "TIMERSLACK" },
1806 { config_parse_limit, "LIMIT" },
1807 { config_parse_cgroup, "CGROUP [...]" },
1808 { config_parse_deps, "UNIT [...]" },
1809 { config_parse_names, "UNIT [...]" },
1810 { config_parse_exec, "PATH [ARGUMENT [...]]" },
1811 { config_parse_service_type, "SERVICETYPE" },
1812 { config_parse_service_restart, "SERVICERESTART" },
1813 #ifdef HAVE_SYSV_COMPAT
1814 { config_parse_sysv_priority, "SYSVPRIORITY" },
1816 { config_parse_warn_compat, "NOTSUPPORTED" },
1818 { config_parse_kill_mode, "KILLMODE" },
1819 { config_parse_kill_signal, "SIGNAL" },
1820 { config_parse_listen, "SOCKET [...]" },
1821 { config_parse_socket_bind, "SOCKETBIND" },
1822 { config_parse_bindtodevice, "NETWORKINTERFACE" },
1823 { config_parse_usec, "SECONDS" },
1824 { config_parse_path_strv, "PATH [...]" },
1825 { config_parse_mount_flags, "MOUNTFLAG [...]" },
1826 { config_parse_string_printf, "STRING" },
1827 { config_parse_timer, "TIMER" },
1828 { config_parse_timer_unit, "NAME" },
1829 { config_parse_path_spec, "PATH" },
1830 { config_parse_path_unit, "UNIT" },
1831 { config_parse_notify_access, "ACCESS" },
1832 { config_parse_ip_tos, "TOS" },
1833 { config_parse_condition_path, "CONDITION" },
1834 { config_parse_condition_string, "CONDITION" },
1835 { config_parse_condition_null, "CONDITION" },
1841 for (i = items; i->lvalue; i++) {
1843 const char *rvalue = "OTHER";
1845 if (!streq_ptr(i->section, prev_section)) {
1851 fprintf(f, "[%s]\n", i->section);
1852 prev_section = i->section;
1855 for (j = 0; j < ELEMENTSOF(table); j++)
1856 if (i->parse == table[j].callback) {
1857 rvalue = table[j].rvalue;
1861 fprintf(f, "%s=%s\n", i->lvalue, rvalue);
1865 static int load_from_path(Unit *u, const char *path) {
1867 static const char* const section_table[_UNIT_TYPE_MAX] = {
1868 [UNIT_SERVICE] = "Service",
1869 [UNIT_TIMER] = "Timer",
1870 [UNIT_SOCKET] = "Socket",
1871 [UNIT_TARGET] = "Target",
1872 [UNIT_DEVICE] = "Device",
1873 [UNIT_MOUNT] = "Mount",
1874 [UNIT_AUTOMOUNT] = "Automount",
1875 [UNIT_SNAPSHOT] = "Snapshot",
1876 [UNIT_SWAP] = "Swap",
1877 [UNIT_PATH] = "Path"
1880 #define EXEC_CONTEXT_CONFIG_ITEMS(context, section) \
1881 { "WorkingDirectory", config_parse_path_printf, 0, &(context).working_directory, section }, \
1882 { "RootDirectory", config_parse_path_printf, 0, &(context).root_directory, section }, \
1883 { "User", config_parse_string_printf, 0, &(context).user, section }, \
1884 { "Group", config_parse_string_printf, 0, &(context).group, section }, \
1885 { "SupplementaryGroups", config_parse_strv, 0, &(context).supplementary_groups, section }, \
1886 { "Nice", config_parse_nice, 0, &(context), section }, \
1887 { "OOMScoreAdjust", config_parse_oom_score_adjust,0, &(context), section }, \
1888 { "IOSchedulingClass", config_parse_io_class, 0, &(context), section }, \
1889 { "IOSchedulingPriority", config_parse_io_priority, 0, &(context), section }, \
1890 { "CPUSchedulingPolicy", config_parse_cpu_sched_policy,0, &(context), section }, \
1891 { "CPUSchedulingPriority", config_parse_cpu_sched_prio, 0, &(context), section }, \
1892 { "CPUSchedulingResetOnFork", config_parse_bool, 0, &(context).cpu_sched_reset_on_fork, section }, \
1893 { "CPUAffinity", config_parse_cpu_affinity, 0, &(context), section }, \
1894 { "UMask", config_parse_mode, 0, &(context).umask, section }, \
1895 { "Environment", config_parse_strv, 0, &(context).environment, section }, \
1896 { "EnvironmentFile", config_parse_env_file, 0, &(context).environment_files, section }, \
1897 { "StandardInput", config_parse_input, 0, &(context).std_input, section }, \
1898 { "StandardOutput", config_parse_output, 0, &(context).std_output, section }, \
1899 { "StandardError", config_parse_output, 0, &(context).std_error, section }, \
1900 { "TTYPath", config_parse_path_printf, 0, &(context).tty_path, section }, \
1901 { "TTYReset", config_parse_bool, 0, &(context).tty_reset, section }, \
1902 { "TTYVHangup", config_parse_bool, 0, &(context).tty_vhangup, section }, \
1903 { "TTYVTDisallocate", config_parse_bool, 0, &(context).tty_vt_disallocate, section }, \
1904 { "SyslogIdentifier", config_parse_string_printf, 0, &(context).syslog_identifier, section }, \
1905 { "SyslogFacility", config_parse_facility, 0, &(context).syslog_priority, section }, \
1906 { "SyslogLevel", config_parse_level, 0, &(context).syslog_priority, section }, \
1907 { "SyslogLevelPrefix", config_parse_bool, 0, &(context).syslog_level_prefix, section }, \
1908 { "Capabilities", config_parse_capabilities, 0, &(context), section }, \
1909 { "SecureBits", config_parse_secure_bits, 0, &(context), section }, \
1910 { "CapabilityBoundingSet", config_parse_bounding_set, 0, &(context), section }, \
1911 { "TimerSlackNSec", config_parse_timer_slack_nsec,0, &(context), section }, \
1912 { "LimitCPU", config_parse_limit, 0, &(context).rlimit[RLIMIT_CPU], section }, \
1913 { "LimitFSIZE", config_parse_limit, 0, &(context).rlimit[RLIMIT_FSIZE], section }, \
1914 { "LimitDATA", config_parse_limit, 0, &(context).rlimit[RLIMIT_DATA], section }, \
1915 { "LimitSTACK", config_parse_limit, 0, &(context).rlimit[RLIMIT_STACK], section }, \
1916 { "LimitCORE", config_parse_limit, 0, &(context).rlimit[RLIMIT_CORE], section }, \
1917 { "LimitRSS", config_parse_limit, 0, &(context).rlimit[RLIMIT_RSS], section }, \
1918 { "LimitNOFILE", config_parse_limit, 0, &(context).rlimit[RLIMIT_NOFILE], section }, \
1919 { "LimitAS", config_parse_limit, 0, &(context).rlimit[RLIMIT_AS], section }, \
1920 { "LimitNPROC", config_parse_limit, 0, &(context).rlimit[RLIMIT_NPROC], section }, \
1921 { "LimitMEMLOCK", config_parse_limit, 0, &(context).rlimit[RLIMIT_MEMLOCK], section }, \
1922 { "LimitLOCKS", config_parse_limit, 0, &(context).rlimit[RLIMIT_LOCKS], section }, \
1923 { "LimitSIGPENDING", config_parse_limit, 0, &(context).rlimit[RLIMIT_SIGPENDING], section }, \
1924 { "LimitMSGQUEUE", config_parse_limit, 0, &(context).rlimit[RLIMIT_MSGQUEUE], section }, \
1925 { "LimitNICE", config_parse_limit, 0, &(context).rlimit[RLIMIT_NICE], section }, \
1926 { "LimitRTPRIO", config_parse_limit, 0, &(context).rlimit[RLIMIT_RTPRIO], section }, \
1927 { "LimitRTTIME", config_parse_limit, 0, &(context).rlimit[RLIMIT_RTTIME], section }, \
1928 { "ControlGroup", config_parse_cgroup, 0, u, section }, \
1929 { "ReadWriteDirectories", config_parse_path_strv, 0, &(context).read_write_dirs, section }, \
1930 { "ReadOnlyDirectories", config_parse_path_strv, 0, &(context).read_only_dirs, section }, \
1931 { "InaccessibleDirectories",config_parse_path_strv, 0, &(context).inaccessible_dirs, section }, \
1932 { "PrivateTmp", config_parse_bool, 0, &(context).private_tmp, section }, \
1933 { "MountFlags", config_parse_mount_flags, 0, &(context), section }, \
1934 { "TCPWrapName", config_parse_string_printf, 0, &(context).tcpwrap_name, section }, \
1935 { "PAMName", config_parse_string_printf, 0, &(context).pam_name, section }, \
1936 { "KillMode", config_parse_kill_mode, 0, &(context).kill_mode, section }, \
1937 { "KillSignal", config_parse_kill_signal, 0, &(context).kill_signal, section }, \
1938 { "SendSIGKILL", config_parse_bool, 0, &(context).send_sigkill, section }, \
1939 { "UtmpIdentifier", config_parse_string_printf, 0, &(context).utmp_id, section }, \
1940 { "ControlGroupModify", config_parse_bool, 0, &(context).control_group_modify, section }
1942 const ConfigItem items[] = {
1943 { "Names", config_parse_names, 0, u, "Unit" },
1944 { "Description", config_parse_string_printf, 0, &u->meta.description, "Unit" },
1945 { "Requires", config_parse_deps, 0, UINT_TO_PTR(UNIT_REQUIRES), "Unit" },
1946 { "RequiresOverridable", config_parse_deps, 0, UINT_TO_PTR(UNIT_REQUIRES_OVERRIDABLE), "Unit" },
1947 { "Requisite", config_parse_deps, 0, UINT_TO_PTR(UNIT_REQUISITE), "Unit" },
1948 { "RequisiteOverridable", config_parse_deps, 0, UINT_TO_PTR(UNIT_REQUISITE_OVERRIDABLE), "Unit" },
1949 { "Wants", config_parse_deps, 0, UINT_TO_PTR(UNIT_WANTS), "Unit" },
1950 { "BindTo", config_parse_deps, 0, UINT_TO_PTR(UNIT_BIND_TO), "Unit" },
1951 { "Conflicts", config_parse_deps, 0, UINT_TO_PTR(UNIT_CONFLICTS), "Unit" },
1952 { "Before", config_parse_deps, 0, UINT_TO_PTR(UNIT_BEFORE), "Unit" },
1953 { "After", config_parse_deps, 0, UINT_TO_PTR(UNIT_AFTER), "Unit" },
1954 { "OnFailure", config_parse_deps, 0, UINT_TO_PTR(UNIT_ON_FAILURE), "Unit" },
1955 { "StopWhenUnneeded", config_parse_bool, 0, &u->meta.stop_when_unneeded, "Unit" },
1956 { "RefuseManualStart", config_parse_bool, 0, &u->meta.refuse_manual_start, "Unit" },
1957 { "RefuseManualStop", config_parse_bool, 0, &u->meta.refuse_manual_stop, "Unit" },
1958 { "AllowIsolate", config_parse_bool, 0, &u->meta.allow_isolate, "Unit" },
1959 { "DefaultDependencies", config_parse_bool, 0, &u->meta.default_dependencies, "Unit" },
1960 { "OnFailureIsolate", config_parse_bool, 0, &u->meta.on_failure_isolate, "Unit" },
1961 { "IgnoreOnIsolate", config_parse_bool, 0, &u->meta.ignore_on_isolate, "Unit" },
1962 { "IgnoreOnSnapshot", config_parse_bool, 0, &u->meta.ignore_on_snapshot, "Unit" },
1963 { "JobTimeoutSec", config_parse_usec, 0, &u->meta.job_timeout, "Unit" },
1964 { "ConditionPathExists", config_parse_condition_path, CONDITION_PATH_EXISTS, u, "Unit" },
1965 { "ConditionPathIsDirectory", config_parse_condition_path, CONDITION_PATH_IS_DIRECTORY, u, "Unit" },
1966 { "ConditionDirectoryNotEmpty", config_parse_condition_path, CONDITION_DIRECTORY_NOT_EMPTY, u, "Unit" },
1967 { "ConditionKernelCommandLine", config_parse_condition_string, CONDITION_KERNEL_COMMAND_LINE, u, "Unit" },
1968 { "ConditionVirtualization", config_parse_condition_string, CONDITION_VIRTUALIZATION, u, "Unit" },
1969 { "ConditionSecurity", config_parse_condition_string, CONDITION_SECURITY, u, "Unit" },
1970 { "ConditionNull", config_parse_condition_null, 0, u, "Unit" },
1972 { "PIDFile", config_parse_path_printf, 0, &u->service.pid_file, "Service" },
1973 { "ExecStartPre", config_parse_exec, 0, u->service.exec_command+SERVICE_EXEC_START_PRE, "Service" },
1974 { "ExecStart", config_parse_exec, 0, u->service.exec_command+SERVICE_EXEC_START, "Service" },
1975 { "ExecStartPost", config_parse_exec, 0, u->service.exec_command+SERVICE_EXEC_START_POST, "Service" },
1976 { "ExecReload", config_parse_exec, 0, u->service.exec_command+SERVICE_EXEC_RELOAD, "Service" },
1977 { "ExecStop", config_parse_exec, 0, u->service.exec_command+SERVICE_EXEC_STOP, "Service" },
1978 { "ExecStopPost", config_parse_exec, 0, u->service.exec_command+SERVICE_EXEC_STOP_POST, "Service" },
1979 { "RestartSec", config_parse_usec, 0, &u->service.restart_usec, "Service" },
1980 { "TimeoutSec", config_parse_usec, 0, &u->service.timeout_usec, "Service" },
1981 { "Type", config_parse_service_type, 0, &u->service.type, "Service" },
1982 { "Restart", config_parse_service_restart, 0, &u->service.restart, "Service" },
1983 { "PermissionsStartOnly", config_parse_bool, 0, &u->service.permissions_start_only, "Service" },
1984 { "RootDirectoryStartOnly", config_parse_bool, 0, &u->service.root_directory_start_only, "Service" },
1985 { "RemainAfterExit", config_parse_bool, 0, &u->service.remain_after_exit, "Service" },
1986 { "GuessMainPID", config_parse_bool, 0, &u->service.guess_main_pid, "Service" },
1987 #ifdef HAVE_SYSV_COMPAT
1988 { "SysVStartPriority", config_parse_sysv_priority, 0, &u->service.sysv_start_priority, "Service" },
1990 { "SysVStartPriority", config_parse_warn_compat, 0, NULL, "Service" },
1992 { "NonBlocking", config_parse_bool, 0, &u->service.exec_context.non_blocking, "Service" },
1993 { "BusName", config_parse_string_printf, 0, &u->service.bus_name, "Service" },
1994 { "NotifyAccess", config_parse_notify_access, 0, &u->service.notify_access, "Service" },
1995 { "Sockets", config_parse_service_sockets, 0, &u->service, "Service" },
1996 { "FsckPassNo", config_parse_fsck_passno, 0, &u->service.fsck_passno, "Service" },
1997 EXEC_CONTEXT_CONFIG_ITEMS(u->service.exec_context, "Service"),
1999 { "ListenStream", config_parse_listen, 0, &u->socket, "Socket" },
2000 { "ListenDatagram", config_parse_listen, 0, &u->socket, "Socket" },
2001 { "ListenSequentialPacket", config_parse_listen, 0, &u->socket, "Socket" },
2002 { "ListenFIFO", config_parse_listen, 0, &u->socket, "Socket" },
2003 { "ListenNetlink", config_parse_listen, 0, &u->socket, "Socket" },
2004 { "ListenSpecial", config_parse_listen, 0, &u->socket, "Socket" },
2005 { "ListenMessageQueue", config_parse_listen, 0, &u->socket, "Socket" },
2006 { "BindIPv6Only", config_parse_socket_bind, 0, &u->socket, "Socket" },
2007 { "Backlog", config_parse_unsigned, 0, &u->socket.backlog, "Socket" },
2008 { "BindToDevice", config_parse_bindtodevice, 0, &u->socket, "Socket" },
2009 { "ExecStartPre", config_parse_exec, 0, u->socket.exec_command+SOCKET_EXEC_START_PRE, "Socket" },
2010 { "ExecStartPost", config_parse_exec, 0, u->socket.exec_command+SOCKET_EXEC_START_POST, "Socket" },
2011 { "ExecStopPre", config_parse_exec, 0, u->socket.exec_command+SOCKET_EXEC_STOP_PRE, "Socket" },
2012 { "ExecStopPost", config_parse_exec, 0, u->socket.exec_command+SOCKET_EXEC_STOP_POST, "Socket" },
2013 { "TimeoutSec", config_parse_usec, 0, &u->socket.timeout_usec, "Socket" },
2014 { "DirectoryMode", config_parse_mode, 0, &u->socket.directory_mode, "Socket" },
2015 { "SocketMode", config_parse_mode, 0, &u->socket.socket_mode, "Socket" },
2016 { "Accept", config_parse_bool, 0, &u->socket.accept, "Socket" },
2017 { "MaxConnections", config_parse_unsigned, 0, &u->socket.max_connections, "Socket" },
2018 { "KeepAlive", config_parse_bool, 0, &u->socket.keep_alive, "Socket" },
2019 { "Priority", config_parse_int, 0, &u->socket.priority, "Socket" },
2020 { "ReceiveBuffer", config_parse_size, 0, &u->socket.receive_buffer, "Socket" },
2021 { "SendBuffer", config_parse_size, 0, &u->socket.send_buffer, "Socket" },
2022 { "IPTOS", config_parse_ip_tos, 0, &u->socket.ip_tos, "Socket" },
2023 { "IPTTL", config_parse_int, 0, &u->socket.ip_ttl, "Socket" },
2024 { "Mark", config_parse_int, 0, &u->socket.mark, "Socket" },
2025 { "PipeSize", config_parse_size, 0, &u->socket.pipe_size, "Socket" },
2026 { "FreeBind", config_parse_bool, 0, &u->socket.free_bind, "Socket" },
2027 { "Transparent", config_parse_bool, 0, &u->socket.transparent, "Socket" },
2028 { "Broadcast", config_parse_bool, 0, &u->socket.broadcast, "Socket" },
2029 { "TCPCongestion", config_parse_string, 0, &u->socket.tcp_congestion, "Socket" },
2030 { "MessageQueueMaxMessages", config_parse_long, 0, &u->socket.mq_maxmsg, "Socket" },
2031 { "MessageQueueMessageSize", config_parse_long, 0, &u->socket.mq_msgsize, "Socket" },
2032 { "Service", config_parse_socket_service, 0, &u->socket, "Socket" },
2033 EXEC_CONTEXT_CONFIG_ITEMS(u->socket.exec_context, "Socket"),
2035 { "What", config_parse_string, 0, &u->mount.parameters_fragment.what, "Mount" },
2036 { "Where", config_parse_path, 0, &u->mount.where, "Mount" },
2037 { "Options", config_parse_string, 0, &u->mount.parameters_fragment.options, "Mount" },
2038 { "Type", config_parse_string, 0, &u->mount.parameters_fragment.fstype, "Mount" },
2039 { "TimeoutSec", config_parse_usec, 0, &u->mount.timeout_usec, "Mount" },
2040 { "DirectoryMode", config_parse_mode, 0, &u->mount.directory_mode, "Mount" },
2041 EXEC_CONTEXT_CONFIG_ITEMS(u->mount.exec_context, "Mount"),
2043 { "Where", config_parse_path, 0, &u->automount.where, "Automount" },
2044 { "DirectoryMode", config_parse_mode, 0, &u->automount.directory_mode, "Automount" },
2046 { "What", config_parse_path, 0, &u->swap.parameters_fragment.what, "Swap" },
2047 { "Priority", config_parse_int, 0, &u->swap.parameters_fragment.priority, "Swap" },
2048 { "TimeoutSec", config_parse_usec, 0, &u->swap.timeout_usec, "Swap" },
2049 EXEC_CONTEXT_CONFIG_ITEMS(u->swap.exec_context, "Swap"),
2051 { "OnActiveSec", config_parse_timer, 0, &u->timer, "Timer" },
2052 { "OnBootSec", config_parse_timer, 0, &u->timer, "Timer" },
2053 { "OnStartupSec", config_parse_timer, 0, &u->timer, "Timer" },
2054 { "OnUnitActiveSec", config_parse_timer, 0, &u->timer, "Timer" },
2055 { "OnUnitInactiveSec", config_parse_timer, 0, &u->timer, "Timer" },
2056 { "Unit", config_parse_timer_unit, 0, &u->timer, "Timer" },
2058 { "PathExists", config_parse_path_spec, 0, &u->path, "Path" },
2059 { "PathChanged", config_parse_path_spec, 0, &u->path, "Path" },
2060 { "DirectoryNotEmpty", config_parse_path_spec, 0, &u->path, "Path" },
2061 { "Unit", config_parse_path_unit, 0, &u->path, "Path" },
2062 { "MakeDirectory", config_parse_bool, 0, &u->path.make_directory, "Path" },
2063 { "DirectoryMode", config_parse_mode, 0, &u->path.directory_mode, "Path" },
2065 /* The [Install] section is ignored here. */
2066 { "Alias", NULL, 0, NULL, "Install" },
2067 { "WantedBy", NULL, 0, NULL, "Install" },
2068 { "Also", NULL, 0, NULL, "Install" },
2070 { NULL, NULL, 0, NULL, NULL }
2073 #undef EXEC_CONTEXT_CONFIG_ITEMS
2075 const char *sections[4];
2079 char *filename = NULL, *id = NULL;
2084 /* Dirty dirty hack. */
2085 dump_items((FILE*) path, items);
2092 sections[0] = "Unit";
2093 sections[1] = section_table[u->meta.type];
2094 sections[2] = "Install";
2097 if (!(symlink_names = set_new(string_hash_func, string_compare_func)))
2100 if (path_is_absolute(path)) {
2102 if (!(filename = strdup(path))) {
2107 if ((r = open_follow(&filename, &f, symlink_names, &id)) < 0) {
2118 STRV_FOREACH(p, u->meta.manager->lookup_paths.unit_path) {
2120 /* Instead of opening the path right away, we manually
2121 * follow all symlinks and add their name to our unit
2122 * name set while doing so */
2123 if (!(filename = path_make_absolute(path, *p))) {
2128 if (u->meta.manager->unit_path_cache &&
2129 !set_get(u->meta.manager->unit_path_cache, filename))
2132 r = open_follow(&filename, &f, symlink_names, &id);
2143 /* Empty the symlink names for the next run */
2144 while ((sn = set_steal_first(symlink_names)))
2155 /* Hmm, no suitable file found? */
2161 if ((r = merge_by_names(&merged, symlink_names, id)) < 0)
2165 u->meta.load_state = UNIT_MERGED;
2171 if (fstat(fileno(f), &st) < 0) {
2176 if (null_or_empty(&st))
2177 u->meta.load_state = UNIT_MASKED;
2179 /* Now, parse the file contents */
2180 if ((r = config_parse(filename, f, sections, items, false, u)) < 0)
2183 u->meta.load_state = UNIT_LOADED;
2186 free(u->meta.fragment_path);
2187 u->meta.fragment_path = filename;
2190 u->meta.fragment_mtime = timespec_load(&st.st_mtim);
2195 set_free_free(symlink_names);
2204 int unit_load_fragment(Unit *u) {
2210 assert(u->meta.load_state == UNIT_STUB);
2213 /* First, try to find the unit under its id. We always look
2214 * for unit files in the default directories, to make it easy
2215 * to override things by placing things in /etc/systemd/system */
2216 if ((r = load_from_path(u, u->meta.id)) < 0)
2219 /* Try to find an alias we can load this with */
2220 if (u->meta.load_state == UNIT_STUB)
2221 SET_FOREACH(t, u->meta.names, i) {
2223 if (t == u->meta.id)
2226 if ((r = load_from_path(u, t)) < 0)
2229 if (u->meta.load_state != UNIT_STUB)
2233 /* And now, try looking for it under the suggested (originally linked) path */
2234 if (u->meta.load_state == UNIT_STUB && u->meta.fragment_path) {
2236 if ((r = load_from_path(u, u->meta.fragment_path)) < 0)
2239 if (u->meta.load_state == UNIT_STUB) {
2240 /* Hmm, this didn't work? Then let's get rid
2241 * of the fragment path stored for us, so that
2242 * we don't point to an invalid location. */
2243 free(u->meta.fragment_path);
2244 u->meta.fragment_path = NULL;
2248 /* Look for a template */
2249 if (u->meta.load_state == UNIT_STUB && u->meta.instance) {
2252 if (!(k = unit_name_template(u->meta.id)))
2255 r = load_from_path(u, k);
2261 if (u->meta.load_state == UNIT_STUB)
2262 SET_FOREACH(t, u->meta.names, i) {
2264 if (t == u->meta.id)
2267 if (!(k = unit_name_template(t)))
2270 r = load_from_path(u, k);
2276 if (u->meta.load_state != UNIT_STUB)
2284 void unit_dump_config_items(FILE *f) {
2285 /* OK, this wins a prize for extreme ugliness. */
2287 load_from_path(NULL, (const void*) f);