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 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 int config_parse_unit_deps(
73 UnitDependency d = ltype;
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 int config_parse_unit_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 int config_parse_unit_string_printf(
158 const char *filename,
177 if (!(k = unit_full_printf(u, rvalue)))
191 int config_parse_unit_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 int config_parse_unit_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 int config_parse_socket_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 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 int config_parse_exec_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 int config_parse_exec_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 int config_parse_exec(
472 const char *filename,
481 ExecCommand **e = data, *nce;
490 /* We accept an absolute path as first argument, or
491 * alternatively an absolute prefixed with @ to allow
492 * overriding of argv[0]. */
500 bool honour_argv0 = false, ignore = false;
506 rvalue += strspn(rvalue, WHITESPACE);
511 if (rvalue[0] == '-') {
516 if (rvalue[0] == '@') {
521 if (*rvalue != '/') {
522 log_error("[%s:%u] Invalid executable path in command line, ignoring: %s", filename, line, rvalue);
527 FOREACH_WORD_QUOTED(w, l, rvalue, state) {
528 if (strncmp(w, ";", MAX(l, 1U)) == 0)
534 if (!(n = new(char*, k + !honour_argv0)))
538 FOREACH_WORD_QUOTED(w, l, rvalue, state) {
539 if (strncmp(w, ";", MAX(l, 1U)) == 0)
542 if (honour_argv0 && w == rvalue) {
544 if (!(path = cunescape_length(w, l)))
547 if (!(n[k++] = cunescape_length(w, l)))
555 log_error("[%s:%u] Invalid command line, ignoring: %s", filename, line, rvalue);
561 if (!(path = strdup(n[0])))
564 assert(path_is_absolute(path));
566 if (!(nce = new0(ExecCommand, 1)))
571 nce->ignore = ignore;
573 path_kill_slashes(nce->path);
575 exec_command_append_list(e, nce);
591 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_type, service_type, ServiceType, "Failed to parse service type");
592 DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart, service_restart, ServiceRestart, "Failed to parse service restart specifier");
594 int config_parse_socket_bindtodevice(
595 const char *filename,
612 if (rvalue[0] && !streq(rvalue, "*")) {
613 if (!(n = strdup(rvalue)))
618 free(s->bind_to_device);
619 s->bind_to_device = n;
624 DEFINE_CONFIG_PARSE_ENUM(config_parse_output, exec_output, ExecOutput, "Failed to parse output specifier");
625 DEFINE_CONFIG_PARSE_ENUM(config_parse_input, exec_input, ExecInput, "Failed to parse input specifier");
627 int config_parse_facility(
628 const char *filename,
645 if ((x = log_facility_unshifted_from_string(rvalue)) < 0) {
646 log_error("[%s:%u] Failed to parse log facility, ignoring: %s", filename, line, rvalue);
650 *o = (x << 3) | LOG_PRI(*o);
655 int config_parse_level(
656 const char *filename,
673 if ((x = log_level_from_string(rvalue)) < 0) {
674 log_error("[%s:%u] Failed to parse log level, ignoring: %s", filename, line, rvalue);
678 *o = (*o & LOG_FACMASK) | x;
682 int config_parse_exec_io_class(
683 const char *filename,
692 ExecContext *c = data;
700 if ((x = ioprio_class_from_string(rvalue)) < 0) {
701 log_error("[%s:%u] Failed to parse IO scheduling class, ignoring: %s", filename, line, rvalue);
705 c->ioprio = IOPRIO_PRIO_VALUE(x, IOPRIO_PRIO_DATA(c->ioprio));
706 c->ioprio_set = true;
711 int config_parse_exec_io_priority(
712 const char *filename,
721 ExecContext *c = data;
729 if (safe_atoi(rvalue, &i) < 0 || i < 0 || i >= IOPRIO_BE_NR) {
730 log_error("[%s:%u] Failed to parse io priority, ignoring: %s", filename, line, rvalue);
734 c->ioprio = IOPRIO_PRIO_VALUE(IOPRIO_PRIO_CLASS(c->ioprio), i);
735 c->ioprio_set = true;
740 int config_parse_exec_cpu_sched_policy(
741 const char *filename,
751 ExecContext *c = data;
759 if ((x = sched_policy_from_string(rvalue)) < 0) {
760 log_error("[%s:%u] Failed to parse CPU scheduling policy, ignoring: %s", filename, line, rvalue);
764 c->cpu_sched_policy = x;
765 c->cpu_sched_set = true;
770 int config_parse_exec_cpu_sched_prio(
771 const char *filename,
780 ExecContext *c = data;
788 /* On Linux RR/FIFO have the same range */
789 if (safe_atoi(rvalue, &i) < 0 || i < sched_get_priority_min(SCHED_RR) || i > sched_get_priority_max(SCHED_RR)) {
790 log_error("[%s:%u] Failed to parse CPU scheduling priority, ignoring: %s", filename, line, rvalue);
794 c->cpu_sched_priority = i;
795 c->cpu_sched_set = true;
800 int config_parse_exec_cpu_affinity(
801 const char *filename,
810 ExecContext *c = data;
820 FOREACH_WORD_QUOTED(w, l, rvalue, state) {
825 if (!(t = strndup(w, l)))
828 r = safe_atou(t, &cpu);
832 if (!(c->cpuset = cpu_set_malloc(&c->cpuset_ncpus)))
835 if (r < 0 || cpu >= c->cpuset_ncpus) {
836 log_error("[%s:%u] Failed to parse CPU affinity, ignoring: %s", filename, line, rvalue);
840 CPU_SET_S(cpu, CPU_ALLOC_SIZE(c->cpuset_ncpus), c->cpuset);
846 int config_parse_exec_capabilities(
847 const char *filename,
856 ExecContext *c = data;
864 if (!(cap = cap_from_text(rvalue))) {
868 log_error("[%s:%u] Failed to parse capabilities, ignoring: %s", filename, line, rvalue);
873 cap_free(c->capabilities);
874 c->capabilities = cap;
879 int config_parse_exec_secure_bits(
880 const char *filename,
889 ExecContext *c = data;
899 FOREACH_WORD_QUOTED(w, l, rvalue, state) {
900 if (first_word(w, "keep-caps"))
901 c->secure_bits |= SECURE_KEEP_CAPS;
902 else if (first_word(w, "keep-caps-locked"))
903 c->secure_bits |= SECURE_KEEP_CAPS_LOCKED;
904 else if (first_word(w, "no-setuid-fixup"))
905 c->secure_bits |= SECURE_NO_SETUID_FIXUP;
906 else if (first_word(w, "no-setuid-fixup-locked"))
907 c->secure_bits |= SECURE_NO_SETUID_FIXUP_LOCKED;
908 else if (first_word(w, "noroot"))
909 c->secure_bits |= SECURE_NOROOT;
910 else if (first_word(w, "noroot-locked"))
911 c->secure_bits |= SECURE_NOROOT_LOCKED;
913 log_error("[%s:%u] Failed to parse secure bits, ignoring: %s", filename, line, rvalue);
921 int config_parse_exec_bounding_set(
922 const char *filename,
931 ExecContext *c = data;
943 if (rvalue[0] == '~') {
948 /* Note that we store this inverted internally, since the
949 * kernel wants it like this. But we actually expose it
950 * non-inverted everywhere to have a fully normalized
953 FOREACH_WORD_QUOTED(w, l, rvalue, state) {
958 if (!(t = strndup(w, l)))
961 r = cap_from_name(t, &cap);
965 log_error("[%s:%u] Failed to parse capability bounding set, ignoring: %s", filename, line, rvalue);
969 sum |= ((uint64_t) 1ULL) << (uint64_t) cap;
973 c->capability_bounding_set_drop |= sum;
975 c->capability_bounding_set_drop |= ~sum;
980 int config_parse_exec_timer_slack_nsec(
981 const char *filename,
990 ExecContext *c = data;
998 if (safe_atolu(rvalue, &u) < 0) {
999 log_error("[%s:%u] Failed to parse time slack value, ignoring: %s", filename, line, rvalue);
1003 c->timer_slack_nsec = u;
1008 int config_parse_limit(
1009 const char *filename,
1011 const char *section,
1018 struct rlimit **rl = data;
1019 unsigned long long u;
1028 if (streq(rvalue, "infinity"))
1029 u = (unsigned long long) RLIM_INFINITY;
1030 else if (safe_atollu(rvalue, &u) < 0) {
1031 log_error("[%s:%u] Failed to parse resource value, ignoring: %s", filename, line, rvalue);
1036 if (!(*rl = new(struct rlimit, 1)))
1039 (*rl)->rlim_cur = (*rl)->rlim_max = (rlim_t) u;
1043 int config_parse_unit_cgroup(
1044 const char *filename,
1046 const char *section,
1058 FOREACH_WORD_QUOTED(w, l, rvalue, state) {
1066 k = unit_full_printf(u, t);
1078 r = unit_add_cgroup_from_text(u, t);
1082 log_error("[%s:%u] Failed to parse cgroup value, ignoring: %s", filename, line, rvalue);
1090 #ifdef HAVE_SYSV_COMPAT
1091 int config_parse_sysv_priority(
1092 const char *filename,
1094 const char *section,
1101 int *priority = data;
1109 if (safe_atoi(rvalue, &i) < 0 || i < 0) {
1110 log_error("[%s:%u] Failed to parse SysV start priority, ignoring: %s", filename, line, rvalue);
1114 *priority = (int) i;
1119 int config_parse_fsck_passno(
1120 const char *filename,
1122 const char *section,
1137 if (safe_atoi(rvalue, &i) || i < 0) {
1138 log_error("[%s:%u] Failed to parse fsck pass number, ignoring: %s", filename, line, rvalue);
1146 DEFINE_CONFIG_PARSE_ENUM(config_parse_kill_mode, kill_mode, KillMode, "Failed to parse kill mode");
1148 int config_parse_kill_signal(
1149 const char *filename,
1151 const char *section,
1166 if ((r = signal_from_string_try_harder(rvalue)) <= 0) {
1167 log_error("[%s:%u] Failed to parse kill signal, ignoring: %s", filename, line, rvalue);
1175 int config_parse_exec_mount_flags(
1176 const char *filename,
1178 const char *section,
1185 ExecContext *c = data;
1189 unsigned long flags = 0;
1196 FOREACH_WORD_QUOTED(w, l, rvalue, state) {
1197 if (strncmp(w, "shared", MAX(l, 6U)) == 0)
1199 else if (strncmp(w, "slave", MAX(l, 5U)) == 0)
1201 else if (strncmp(w, "private", MAX(l, 7U)) == 0)
1202 flags |= MS_PRIVATE;
1204 log_error("[%s:%u] Failed to parse mount flags, ignoring: %s", filename, line, rvalue);
1209 c->mount_flags = flags;
1213 int config_parse_timer(
1214 const char *filename,
1216 const char *section,
1233 if ((b = timer_base_from_string(lvalue)) < 0) {
1234 log_error("[%s:%u] Failed to parse timer base, ignoring: %s", filename, line, lvalue);
1238 if (parse_usec(rvalue, &u) < 0) {
1239 log_error("[%s:%u] Failed to parse timer value, ignoring: %s", filename, line, rvalue);
1243 if (!(v = new0(TimerValue, 1)))
1249 LIST_PREPEND(TimerValue, value, t->values, v);
1254 int config_parse_timer_unit(
1255 const char *filename,
1257 const char *section,
1273 dbus_error_init(&error);
1275 if (endswith(rvalue, ".timer")) {
1276 log_error("[%s:%u] Unit cannot be of type timer, ignoring: %s", filename, line, rvalue);
1280 if ((r = manager_load_unit(t->meta.manager, rvalue, NULL, NULL, &t->unit)) < 0) {
1281 log_error("[%s:%u] Failed to load unit %s, ignoring: %s", filename, line, rvalue, bus_error(&error, r));
1282 dbus_error_free(&error);
1289 int config_parse_path_spec(
1290 const char *filename,
1292 const char *section,
1308 if ((b = path_type_from_string(lvalue)) < 0) {
1309 log_error("[%s:%u] Failed to parse path type, ignoring: %s", filename, line, lvalue);
1313 if (!path_is_absolute(rvalue)) {
1314 log_error("[%s:%u] Path is not absolute, ignoring: %s", filename, line, rvalue);
1318 if (!(s = new0(PathSpec, 1)))
1321 if (!(s->path = strdup(rvalue))) {
1326 path_kill_slashes(s->path);
1331 LIST_PREPEND(PathSpec, spec, p->specs, s);
1336 int config_parse_path_unit(
1337 const char *filename,
1339 const char *section,
1355 dbus_error_init(&error);
1357 if (endswith(rvalue, ".path")) {
1358 log_error("[%s:%u] Unit cannot be of type path, ignoring: %s", filename, line, rvalue);
1362 if ((r = manager_load_unit(t->meta.manager, rvalue, NULL, &error, &t->unit)) < 0) {
1363 log_error("[%s:%u] Failed to load unit %s, ignoring: %s", filename, line, rvalue, bus_error(&error, r));
1364 dbus_error_free(&error);
1371 int config_parse_socket_service(
1372 const char *filename,
1374 const char *section,
1390 dbus_error_init(&error);
1392 if (!endswith(rvalue, ".service")) {
1393 log_error("[%s:%u] Unit must be of type service, ignoring: %s", filename, line, rvalue);
1397 if ((r = manager_load_unit(s->meta.manager, rvalue, NULL, &error, (Unit**) &s->service)) < 0) {
1398 log_error("[%s:%u] Failed to load unit %s, ignoring: %s", filename, line, rvalue, bus_error(&error, r));
1399 dbus_error_free(&error);
1406 int config_parse_service_sockets(
1407 const char *filename,
1409 const char *section,
1427 dbus_error_init(&error);
1429 FOREACH_WORD_QUOTED(w, l, rvalue, state) {
1433 if (!(t = strndup(w, l)))
1436 if (!endswith(t, ".socket")) {
1437 log_error("[%s:%u] Unit must be of type socket, ignoring: %s", filename, line, rvalue);
1442 r = manager_load_unit(s->meta.manager, t, NULL, &error, &sock);
1446 log_error("[%s:%u] Failed to load unit %s, ignoring: %s", filename, line, rvalue, bus_error(&error, r));
1447 dbus_error_free(&error);
1451 if ((r = set_ensure_allocated(&s->configured_sockets, trivial_hash_func, trivial_compare_func)) < 0)
1454 if ((r = set_put(s->configured_sockets, sock)) < 0)
1461 int config_parse_unit_env_file(
1462 const char *filename,
1464 const char *section,
1471 char ***env = data, **k;
1480 s = unit_full_printf(u, rvalue);
1484 if (!path_is_absolute(s[0] == '-' ? s + 1 : s)) {
1485 log_error("[%s:%u] Path '%s' is not absolute, ignoring.", filename, line, s);
1490 k = strv_append(*env, s);
1501 int config_parse_ip_tos(
1502 const char *filename,
1504 const char *section,
1511 int *ip_tos = data, x;
1518 if ((x = ip_tos_from_string(rvalue)) < 0)
1519 if (safe_atoi(rvalue, &x) < 0) {
1520 log_error("[%s:%u] Failed to parse IP TOS value, ignoring: %s", filename, line, rvalue);
1528 int config_parse_unit_condition_path(
1529 const char *filename,
1531 const char *section,
1538 ConditionType cond = ltype;
1540 bool trigger, negate;
1548 if ((trigger = rvalue[0] == '|'))
1551 if ((negate = rvalue[0] == '!'))
1554 if (!path_is_absolute(rvalue)) {
1555 log_error("[%s:%u] Path in condition not absolute, ignoring: %s", filename, line, rvalue);
1559 if (!(c = condition_new(cond, rvalue, trigger, negate)))
1562 LIST_PREPEND(Condition, conditions, u->meta.conditions, c);
1566 int config_parse_unit_condition_string(
1567 const char *filename,
1569 const char *section,
1576 ConditionType cond = ltype;
1578 bool trigger, negate;
1586 if ((trigger = rvalue[0] == '|'))
1589 if ((negate = rvalue[0] == '!'))
1592 if (!(c = condition_new(cond, rvalue, trigger, negate)))
1595 LIST_PREPEND(Condition, conditions, u->meta.conditions, c);
1599 int config_parse_unit_condition_null(
1600 const char *filename,
1602 const char *section,
1611 bool trigger, negate;
1619 if ((trigger = rvalue[0] == '|'))
1622 if ((negate = rvalue[0] == '!'))
1625 if ((b = parse_boolean(rvalue)) < 0) {
1626 log_error("[%s:%u] Failed to parse boolean value in condition, ignoring: %s", filename, line, rvalue);
1633 if (!(c = condition_new(CONDITION_NULL, NULL, trigger, negate)))
1636 LIST_PREPEND(Condition, conditions, u->meta.conditions, c);
1640 DEFINE_CONFIG_PARSE_ENUM(config_parse_notify_access, notify_access, NotifyAccess, "Failed to parse notify access specifier");
1642 #define FOLLOW_MAX 8
1644 static int open_follow(char **filename, FILE **_f, Set *names, char **_final) {
1655 /* This will update the filename pointer if the loaded file is
1656 * reached by a symlink. The old string will be freed. */
1659 char *target, *name;
1661 if (c++ >= FOLLOW_MAX)
1664 path_kill_slashes(*filename);
1666 /* Add the file name we are currently looking at to
1667 * the names of this unit, but only if it is a valid
1669 name = file_name_from_path(*filename);
1671 if (unit_name_is_valid(name, true)) {
1673 id = set_get(names, name);
1679 r = set_put(names, id);
1687 /* Try to open the file name, but don't if its a symlink */
1688 if ((fd = open(*filename, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW)) >= 0)
1694 /* Hmm, so this is a symlink. Let's read the name, and follow it manually */
1695 if ((r = readlink_and_make_absolute(*filename, &target)) < 0)
1702 if (!(f = fdopen(fd, "re"))) {
1704 close_nointr_nofail(fd);
1713 static int merge_by_names(Unit **u, Set *names, const char *id) {
1721 /* Let's try to add in all symlink names we found */
1722 while ((k = set_steal_first(names))) {
1724 /* First try to merge in the other name into our
1726 if ((r = unit_merge_by_name(*u, k)) < 0) {
1729 /* Hmm, we couldn't merge the other unit into
1730 * ours? Then let's try it the other way
1733 other = manager_get_unit((*u)->meta.manager, k);
1737 if ((r = unit_merge(other, *u)) >= 0) {
1739 return merge_by_names(u, names, NULL);
1746 unit_choose_id(*u, id);
1754 static int load_from_path(Unit *u, const char *path) {
1758 char *filename = NULL, *id = NULL;
1765 symlink_names = set_new(string_hash_func, string_compare_func);
1769 if (path_is_absolute(path)) {
1771 if (!(filename = strdup(path))) {
1776 if ((r = open_follow(&filename, &f, symlink_names, &id)) < 0) {
1787 STRV_FOREACH(p, u->meta.manager->lookup_paths.unit_path) {
1789 /* Instead of opening the path right away, we manually
1790 * follow all symlinks and add their name to our unit
1791 * name set while doing so */
1792 if (!(filename = path_make_absolute(path, *p))) {
1797 if (u->meta.manager->unit_path_cache &&
1798 !set_get(u->meta.manager->unit_path_cache, filename))
1801 r = open_follow(&filename, &f, symlink_names, &id);
1812 /* Empty the symlink names for the next run */
1813 while ((sn = set_steal_first(symlink_names)))
1824 /* Hmm, no suitable file found? */
1830 if ((r = merge_by_names(&merged, symlink_names, id)) < 0)
1834 u->meta.load_state = UNIT_MERGED;
1840 if (fstat(fileno(f), &st) < 0) {
1845 if (null_or_empty(&st))
1846 u->meta.load_state = UNIT_MASKED;
1848 /* Now, parse the file contents */
1849 r = config_parse(filename, f, UNIT_VTABLE(u)->sections, config_item_perf_lookup, (void*) load_fragment_gperf_lookup, false, u);
1853 u->meta.load_state = UNIT_LOADED;
1856 free(u->meta.fragment_path);
1857 u->meta.fragment_path = filename;
1860 u->meta.fragment_mtime = timespec_load(&st.st_mtim);
1865 set_free_free(symlink_names);
1874 int unit_load_fragment(Unit *u) {
1880 assert(u->meta.load_state == UNIT_STUB);
1883 /* First, try to find the unit under its id. We always look
1884 * for unit files in the default directories, to make it easy
1885 * to override things by placing things in /etc/systemd/system */
1886 if ((r = load_from_path(u, u->meta.id)) < 0)
1889 /* Try to find an alias we can load this with */
1890 if (u->meta.load_state == UNIT_STUB)
1891 SET_FOREACH(t, u->meta.names, i) {
1893 if (t == u->meta.id)
1896 if ((r = load_from_path(u, t)) < 0)
1899 if (u->meta.load_state != UNIT_STUB)
1903 /* And now, try looking for it under the suggested (originally linked) path */
1904 if (u->meta.load_state == UNIT_STUB && u->meta.fragment_path) {
1906 if ((r = load_from_path(u, u->meta.fragment_path)) < 0)
1909 if (u->meta.load_state == UNIT_STUB) {
1910 /* Hmm, this didn't work? Then let's get rid
1911 * of the fragment path stored for us, so that
1912 * we don't point to an invalid location. */
1913 free(u->meta.fragment_path);
1914 u->meta.fragment_path = NULL;
1918 /* Look for a template */
1919 if (u->meta.load_state == UNIT_STUB && u->meta.instance) {
1922 if (!(k = unit_name_template(u->meta.id)))
1925 r = load_from_path(u, k);
1931 if (u->meta.load_state == UNIT_STUB)
1932 SET_FOREACH(t, u->meta.names, i) {
1934 if (t == u->meta.id)
1937 if (!(k = unit_name_template(t)))
1940 r = load_from_path(u, k);
1946 if (u->meta.load_state != UNIT_STUB)
1954 void unit_dump_config_items(FILE *f) {
1955 static const struct {
1956 const ConfigParserCallback callback;
1959 { config_parse_int, "INTEGER" },
1960 { config_parse_unsigned, "UNSIGNED" },
1961 { config_parse_size, "SIZE" },
1962 { config_parse_bool, "BOOLEAN" },
1963 { config_parse_string, "STRING" },
1964 { config_parse_path, "PATH" },
1965 { config_parse_unit_path_printf, "PATH" },
1966 { config_parse_strv, "STRING [...]" },
1967 { config_parse_exec_nice, "NICE" },
1968 { config_parse_exec_oom_score_adjust, "OOMSCOREADJUST" },
1969 { config_parse_exec_io_class, "IOCLASS" },
1970 { config_parse_exec_io_priority, "IOPRIORITY" },
1971 { config_parse_exec_cpu_sched_policy, "CPUSCHEDPOLICY" },
1972 { config_parse_exec_cpu_sched_prio, "CPUSCHEDPRIO" },
1973 { config_parse_exec_cpu_affinity, "CPUAFFINITY" },
1974 { config_parse_mode, "MODE" },
1975 { config_parse_unit_env_file, "FILE" },
1976 { config_parse_output, "OUTPUT" },
1977 { config_parse_input, "INPUT" },
1978 { config_parse_facility, "FACILITY" },
1979 { config_parse_level, "LEVEL" },
1980 { config_parse_exec_capabilities, "CAPABILITIES" },
1981 { config_parse_exec_secure_bits, "SECUREBITS" },
1982 { config_parse_exec_bounding_set, "BOUNDINGSET" },
1983 { config_parse_exec_timer_slack_nsec, "TIMERSLACK" },
1984 { config_parse_limit, "LIMIT" },
1985 { config_parse_unit_cgroup, "CGROUP [...]" },
1986 { config_parse_unit_deps, "UNIT [...]" },
1987 { config_parse_unit_names, "UNIT [...]" },
1988 { config_parse_exec, "PATH [ARGUMENT [...]]" },
1989 { config_parse_service_type, "SERVICETYPE" },
1990 { config_parse_service_restart, "SERVICERESTART" },
1991 #ifdef HAVE_SYSV_COMPAT
1992 { config_parse_sysv_priority, "SYSVPRIORITY" },
1994 { config_parse_warn_compat, "NOTSUPPORTED" },
1996 { config_parse_kill_mode, "KILLMODE" },
1997 { config_parse_kill_signal, "SIGNAL" },
1998 { config_parse_socket_listen, "SOCKET [...]" },
1999 { config_parse_socket_bind, "SOCKETBIND" },
2000 { config_parse_socket_bindtodevice, "NETWORKINTERFACE" },
2001 { config_parse_usec, "SECONDS" },
2002 { config_parse_path_strv, "PATH [...]" },
2003 { config_parse_exec_mount_flags, "MOUNTFLAG [...]" },
2004 { config_parse_unit_string_printf, "STRING" },
2005 { config_parse_timer, "TIMER" },
2006 { config_parse_timer_unit, "NAME" },
2007 { config_parse_path_spec, "PATH" },
2008 { config_parse_path_unit, "UNIT" },
2009 { config_parse_notify_access, "ACCESS" },
2010 { config_parse_ip_tos, "TOS" },
2011 { config_parse_unit_condition_path, "CONDITION" },
2012 { config_parse_unit_condition_string, "CONDITION" },
2013 { config_parse_unit_condition_null, "CONDITION" },
2016 const char *prev = NULL;
2021 NULSTR_FOREACH(i, load_fragment_gperf_nulstr) {
2022 const char *rvalue = "OTHER", *lvalue;
2026 const ConfigPerfItem *p;
2028 assert_se(p = load_fragment_gperf_lookup(i, strlen(i)));
2030 dot = strchr(i, '.');
2031 lvalue = dot ? dot + 1 : i;
2035 if (!prev || strncmp(prev, i, prefix_len+1) != 0) {
2039 fprintf(f, "[%.*s]\n", (int) prefix_len, i);
2042 for (j = 0; j < ELEMENTSOF(table); j++)
2043 if (p->parse == table[j].callback) {
2044 rvalue = table[j].rvalue;
2048 fprintf(f, "%s=%s\n", lvalue, rvalue);