1 /*-*- Mode: C; c-basic-offset: 8 -*-*/
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/>.
25 #include <sys/epoll.h>
26 #include <sys/timerfd.h>
35 #include "load-fragment.h"
36 #include "load-dropin.h"
38 #include "unit-name.h"
39 #include "specifier.h"
40 #include "dbus-unit.h"
43 const UnitVTable * const unit_vtable[_UNIT_TYPE_MAX] = {
44 [UNIT_SERVICE] = &service_vtable,
45 [UNIT_TIMER] = &timer_vtable,
46 [UNIT_SOCKET] = &socket_vtable,
47 [UNIT_TARGET] = &target_vtable,
48 [UNIT_DEVICE] = &device_vtable,
49 [UNIT_MOUNT] = &mount_vtable,
50 [UNIT_AUTOMOUNT] = &automount_vtable,
51 [UNIT_SNAPSHOT] = &snapshot_vtable,
52 [UNIT_SWAP] = &swap_vtable,
53 [UNIT_PATH] = &path_vtable
56 Unit *unit_new(Manager *m) {
61 if (!(u = new0(Unit, 1)))
64 if (!(u->meta.names = set_new(string_hash_func, string_compare_func))) {
70 u->meta.type = _UNIT_TYPE_INVALID;
71 u->meta.deserialized_job = _JOB_TYPE_INVALID;
72 u->meta.default_dependencies = true;
77 bool unit_has_name(Unit *u, const char *name) {
81 return !!set_get(u->meta.names, (char*) name);
84 int unit_add_name(Unit *u, const char *text) {
86 char *s = NULL, *i = NULL;
92 if (unit_name_is_template(text)) {
93 if (!u->meta.instance)
96 s = unit_name_replace_instance(text, u->meta.instance);
103 if (!unit_name_is_valid(s)) {
108 assert_se((t = unit_name_to_type(s)) >= 0);
110 if (u->meta.type != _UNIT_TYPE_INVALID && t != u->meta.type) {
115 if ((r = unit_name_to_instance(s, &i)) < 0)
118 if (i && unit_vtable[t]->no_instances)
121 if (u->meta.type != _UNIT_TYPE_INVALID && !streq_ptr(u->meta.instance, i)) {
126 if (unit_vtable[t]->no_alias &&
127 !set_isempty(u->meta.names) &&
128 !set_get(u->meta.names, s)) {
133 if (hashmap_size(u->meta.manager->units) >= MANAGER_MAX_NAMES) {
138 if ((r = set_put(u->meta.names, s)) < 0) {
144 if ((r = hashmap_put(u->meta.manager->units, s, u)) < 0) {
145 set_remove(u->meta.names, s);
149 if (u->meta.type == _UNIT_TYPE_INVALID) {
153 u->meta.instance = i;
155 LIST_PREPEND(Meta, units_per_type, u->meta.manager->units_per_type[t], &u->meta);
157 if (UNIT_VTABLE(u)->init)
158 UNIT_VTABLE(u)->init(u);
162 unit_add_to_dbus_queue(u);
172 int unit_choose_id(Unit *u, const char *name) {
178 if (unit_name_is_template(name)) {
180 if (!u->meta.instance)
183 if (!(t = unit_name_replace_instance(name, u->meta.instance)))
189 /* Selects one of the names of this unit as the id */
190 s = set_get(u->meta.names, (char*) name);
197 unit_add_to_dbus_queue(u);
202 int unit_set_description(Unit *u, const char *description) {
207 if (!(s = strdup(description)))
210 free(u->meta.description);
211 u->meta.description = s;
213 unit_add_to_dbus_queue(u);
217 bool unit_check_gc(Unit *u) {
220 if (u->meta.load_state == UNIT_STUB)
223 if (UNIT_VTABLE(u)->no_gc)
229 if (unit_active_state(u) != UNIT_INACTIVE)
232 if (UNIT_VTABLE(u)->check_gc)
233 if (UNIT_VTABLE(u)->check_gc(u))
239 void unit_add_to_load_queue(Unit *u) {
241 assert(u->meta.type != _UNIT_TYPE_INVALID);
243 if (u->meta.load_state != UNIT_STUB || u->meta.in_load_queue)
246 LIST_PREPEND(Meta, load_queue, u->meta.manager->load_queue, &u->meta);
247 u->meta.in_load_queue = true;
250 void unit_add_to_cleanup_queue(Unit *u) {
253 if (u->meta.in_cleanup_queue)
256 LIST_PREPEND(Meta, cleanup_queue, u->meta.manager->cleanup_queue, &u->meta);
257 u->meta.in_cleanup_queue = true;
260 void unit_add_to_gc_queue(Unit *u) {
263 if (u->meta.in_gc_queue || u->meta.in_cleanup_queue)
266 if (unit_check_gc(u))
269 LIST_PREPEND(Meta, gc_queue, u->meta.manager->gc_queue, &u->meta);
270 u->meta.in_gc_queue = true;
272 u->meta.manager->n_in_gc_queue ++;
274 if (u->meta.manager->gc_queue_timestamp <= 0)
275 u->meta.manager->gc_queue_timestamp = now(CLOCK_MONOTONIC);
278 void unit_add_to_dbus_queue(Unit *u) {
280 assert(u->meta.type != _UNIT_TYPE_INVALID);
282 if (u->meta.load_state == UNIT_STUB || u->meta.in_dbus_queue)
285 if (set_isempty(u->meta.manager->subscribed)) {
286 u->meta.sent_dbus_new_signal = true;
290 LIST_PREPEND(Meta, dbus_queue, u->meta.manager->dbus_unit_queue, &u->meta);
291 u->meta.in_dbus_queue = true;
294 static void bidi_set_free(Unit *u, Set *s) {
300 /* Frees the set and makes sure we are dropped from the
301 * inverse pointers */
303 SET_FOREACH(other, s, i) {
306 for (d = 0; d < _UNIT_DEPENDENCY_MAX; d++)
307 set_remove(other->meta.dependencies[d], u);
309 unit_add_to_gc_queue(other);
315 void unit_free(Unit *u) {
322 bus_unit_send_removed_signal(u);
324 if (u->meta.load_state != UNIT_STUB)
325 if (UNIT_VTABLE(u)->done)
326 UNIT_VTABLE(u)->done(u);
328 SET_FOREACH(t, u->meta.names, i)
329 hashmap_remove_value(u->meta.manager->units, t, u);
332 job_free(u->meta.job);
334 for (d = 0; d < _UNIT_DEPENDENCY_MAX; d++)
335 bidi_set_free(u, u->meta.dependencies[d]);
337 if (u->meta.type != _UNIT_TYPE_INVALID)
338 LIST_REMOVE(Meta, units_per_type, u->meta.manager->units_per_type[u->meta.type], &u->meta);
340 if (u->meta.in_load_queue)
341 LIST_REMOVE(Meta, load_queue, u->meta.manager->load_queue, &u->meta);
343 if (u->meta.in_dbus_queue)
344 LIST_REMOVE(Meta, dbus_queue, u->meta.manager->dbus_unit_queue, &u->meta);
346 if (u->meta.in_cleanup_queue)
347 LIST_REMOVE(Meta, cleanup_queue, u->meta.manager->cleanup_queue, &u->meta);
349 if (u->meta.in_gc_queue) {
350 LIST_REMOVE(Meta, gc_queue, u->meta.manager->gc_queue, &u->meta);
351 u->meta.manager->n_in_gc_queue--;
354 cgroup_bonding_free_list(u->meta.cgroup_bondings);
356 free(u->meta.description);
357 free(u->meta.fragment_path);
359 set_free_free(u->meta.names);
361 free(u->meta.instance);
366 UnitActiveState unit_active_state(Unit *u) {
369 if (u->meta.load_state == UNIT_MERGED)
370 return unit_active_state(unit_follow_merge(u));
372 /* After a reload it might happen that a unit is not correctly
373 * loaded but still has a process around. That's why we won't
374 * shortcut failed loading to UNIT_INACTIVE_MAINTENANCE. */
376 return UNIT_VTABLE(u)->active_state(u);
379 const char* unit_sub_state_to_string(Unit *u) {
382 return UNIT_VTABLE(u)->sub_state_to_string(u);
385 static void complete_move(Set **s, Set **other) {
393 set_move(*s, *other);
400 static void merge_names(Unit *u, Unit *other) {
407 complete_move(&u->meta.names, &other->meta.names);
409 set_free_free(other->meta.names);
410 other->meta.names = NULL;
411 other->meta.id = NULL;
413 SET_FOREACH(t, u->meta.names, i)
414 assert_se(hashmap_replace(u->meta.manager->units, t, u) == 0);
417 static void merge_dependencies(Unit *u, Unit *other, UnitDependency d) {
424 assert(d < _UNIT_DEPENDENCY_MAX);
426 SET_FOREACH(back, other->meta.dependencies[d], i) {
429 for (k = 0; k < _UNIT_DEPENDENCY_MAX; k++)
430 if ((r = set_remove_and_put(back->meta.dependencies[k], other, u)) < 0) {
433 set_remove(back->meta.dependencies[k], other);
435 assert(r == -ENOENT);
439 complete_move(&u->meta.dependencies[d], &other->meta.dependencies[d]);
441 set_free(other->meta.dependencies[d]);
442 other->meta.dependencies[d] = NULL;
445 int unit_merge(Unit *u, Unit *other) {
450 assert(u->meta.manager == other->meta.manager);
451 assert(u->meta.type != _UNIT_TYPE_INVALID);
453 other = unit_follow_merge(other);
458 if (u->meta.type != other->meta.type)
461 if (!streq_ptr(u->meta.instance, other->meta.instance))
464 if (other->meta.load_state != UNIT_STUB &&
465 other->meta.load_state != UNIT_FAILED)
471 if (!UNIT_IS_INACTIVE_OR_MAINTENANCE(unit_active_state(other)))
475 merge_names(u, other);
477 /* Merge dependencies */
478 for (d = 0; d < _UNIT_DEPENDENCY_MAX; d++)
479 merge_dependencies(u, other, d);
481 other->meta.load_state = UNIT_MERGED;
482 other->meta.merged_into = u;
484 /* If there is still some data attached to the other node, we
485 * don't need it anymore, and can free it. */
486 if (other->meta.load_state != UNIT_STUB)
487 if (UNIT_VTABLE(other)->done)
488 UNIT_VTABLE(other)->done(other);
490 unit_add_to_dbus_queue(u);
491 unit_add_to_cleanup_queue(other);
496 int unit_merge_by_name(Unit *u, const char *name) {
504 if (unit_name_is_template(name)) {
505 if (!u->meta.instance)
508 if (!(s = unit_name_replace_instance(name, u->meta.instance)))
514 if (!(other = manager_get_unit(u->meta.manager, name)))
515 r = unit_add_name(u, name);
517 r = unit_merge(u, other);
523 Unit* unit_follow_merge(Unit *u) {
526 while (u->meta.load_state == UNIT_MERGED)
527 assert_se(u = u->meta.merged_into);
532 int unit_add_exec_dependencies(Unit *u, ExecContext *c) {
538 if (c->std_output != EXEC_OUTPUT_KMSG &&
539 c->std_output != EXEC_OUTPUT_SYSLOG &&
540 c->std_error != EXEC_OUTPUT_KMSG &&
541 c->std_error != EXEC_OUTPUT_SYSLOG)
544 /* If syslog or kernel logging is requested, make sure our own
545 * logging daemon is run first. */
547 if ((r = unit_add_dependency_by_name(u, UNIT_AFTER, SPECIAL_LOGGER_SOCKET, NULL, true)) < 0)
550 if (u->meta.manager->running_as == MANAGER_SYSTEM)
551 if ((r = unit_add_dependency_by_name(u, UNIT_REQUIRES, SPECIAL_LOGGER_SOCKET, NULL, true)) < 0)
557 const char *unit_description(Unit *u) {
560 if (u->meta.description)
561 return u->meta.description;
566 void unit_dump(Unit *u, FILE *f, const char *prefix) {
574 timestamp1[FORMAT_TIMESTAMP_MAX],
575 timestamp2[FORMAT_TIMESTAMP_MAX],
576 timestamp3[FORMAT_TIMESTAMP_MAX],
577 timestamp4[FORMAT_TIMESTAMP_MAX];
580 assert(u->meta.type >= 0);
584 p2 = strappend(prefix, "\t");
585 prefix2 = p2 ? p2 : prefix;
589 "%s\tDescription: %s\n"
591 "%s\tUnit Load State: %s\n"
592 "%s\tUnit Active State: %s\n"
593 "%s\tInactive Exit Timestamp: %s\n"
594 "%s\tActive Enter Timestamp: %s\n"
595 "%s\tActive Exit Timestamp: %s\n"
596 "%s\tInactive Enter Timestamp: %s\n"
597 "%s\tGC Check Good: %s\n",
599 prefix, unit_description(u),
600 prefix, strna(u->meta.instance),
601 prefix, unit_load_state_to_string(u->meta.load_state),
602 prefix, unit_active_state_to_string(unit_active_state(u)),
603 prefix, strna(format_timestamp(timestamp1, sizeof(timestamp1), u->meta.inactive_exit_timestamp.realtime)),
604 prefix, strna(format_timestamp(timestamp2, sizeof(timestamp2), u->meta.active_enter_timestamp.realtime)),
605 prefix, strna(format_timestamp(timestamp3, sizeof(timestamp3), u->meta.active_exit_timestamp.realtime)),
606 prefix, strna(format_timestamp(timestamp4, sizeof(timestamp4), u->meta.inactive_enter_timestamp.realtime)),
607 prefix, yes_no(unit_check_gc(u)));
609 SET_FOREACH(t, u->meta.names, i)
610 fprintf(f, "%s\tName: %s\n", prefix, t);
612 if (u->meta.fragment_path)
613 fprintf(f, "%s\tFragment Path: %s\n", prefix, u->meta.fragment_path);
615 for (d = 0; d < _UNIT_DEPENDENCY_MAX; d++) {
618 SET_FOREACH(other, u->meta.dependencies[d], i)
619 fprintf(f, "%s\t%s: %s\n", prefix, unit_dependency_to_string(d), other->meta.id);
622 if (u->meta.load_state == UNIT_LOADED) {
624 "%s\tRecursive Stop: %s\n"
625 "%s\tStopWhenUnneeded: %s\n"
626 "%s\tOnlyByDependency: %s\n"
627 "%s\tDefaultDependencies: %s\n",
628 prefix, yes_no(u->meta.recursive_stop),
629 prefix, yes_no(u->meta.stop_when_unneeded),
630 prefix, yes_no(u->meta.only_by_dependency),
631 prefix, yes_no(u->meta.default_dependencies));
633 LIST_FOREACH(by_unit, b, u->meta.cgroup_bondings)
634 fprintf(f, "%s\tControlGroup: %s:%s\n",
635 prefix, b->controller, b->path);
637 if (UNIT_VTABLE(u)->dump)
638 UNIT_VTABLE(u)->dump(u, f, prefix2);
640 } else if (u->meta.load_state == UNIT_MERGED)
642 "%s\tMerged into: %s\n",
643 prefix, u->meta.merged_into->meta.id);
646 job_dump(u->meta.job, f, prefix2);
651 /* Common implementation for multiple backends */
652 int unit_load_fragment_and_dropin(Unit *u) {
657 /* Load a .service file */
658 if ((r = unit_load_fragment(u)) < 0)
661 if (u->meta.load_state == UNIT_STUB)
664 /* Load drop-in directory data */
665 if ((r = unit_load_dropin(unit_follow_merge(u))) < 0)
671 /* Common implementation for multiple backends */
672 int unit_load_fragment_and_dropin_optional(Unit *u) {
677 /* Same as unit_load_fragment_and_dropin(), but whether
678 * something can be loaded or not doesn't matter. */
680 /* Load a .service file */
681 if ((r = unit_load_fragment(u)) < 0)
684 if (u->meta.load_state == UNIT_STUB)
685 u->meta.load_state = UNIT_LOADED;
687 /* Load drop-in directory data */
688 if ((r = unit_load_dropin(unit_follow_merge(u))) < 0)
694 /* Common implementation for multiple backends */
695 int unit_load_nop(Unit *u) {
698 if (u->meta.load_state == UNIT_STUB)
699 u->meta.load_state = UNIT_LOADED;
704 int unit_load(Unit *u) {
709 if (u->meta.in_load_queue) {
710 LIST_REMOVE(Meta, load_queue, u->meta.manager->load_queue, &u->meta);
711 u->meta.in_load_queue = false;
714 if (u->meta.type == _UNIT_TYPE_INVALID)
717 if (u->meta.load_state != UNIT_STUB)
720 if (UNIT_VTABLE(u)->load)
721 if ((r = UNIT_VTABLE(u)->load(u)) < 0)
724 if (u->meta.load_state == UNIT_STUB) {
729 assert((u->meta.load_state != UNIT_MERGED) == !u->meta.merged_into);
731 unit_add_to_dbus_queue(unit_follow_merge(u));
732 unit_add_to_gc_queue(u);
737 u->meta.load_state = UNIT_FAILED;
738 unit_add_to_dbus_queue(u);
740 log_debug("Failed to load configuration for %s: %s", u->meta.id, strerror(-r));
746 * -EBADR: This unit type does not support starting.
747 * -EALREADY: Unit is already started.
748 * -EAGAIN: An operation is already in progress. Retry later.
749 * -ECANCELED: Too many requests for now.
751 int unit_start(Unit *u) {
752 UnitActiveState state;
756 if (u->meta.load_state != UNIT_LOADED)
759 /* If this is already (being) started, then this will
760 * succeed. Note that this will even succeed if this unit is
761 * not startable by the user. This is relied on to detect when
762 * we need to wait for units and when waiting is finished. */
763 state = unit_active_state(u);
764 if (UNIT_IS_ACTIVE_OR_RELOADING(state))
767 /* If it is stopped, but we cannot start it, then fail */
768 if (!UNIT_VTABLE(u)->start)
771 /* We don't suppress calls to ->start() here when we are
772 * already starting, to allow this request to be used as a
773 * "hurry up" call, for example when the unit is in some "auto
774 * restart" state where it waits for a holdoff timer to elapse
775 * before it will start again. */
777 unit_add_to_dbus_queue(u);
778 return UNIT_VTABLE(u)->start(u);
781 bool unit_can_start(Unit *u) {
784 return !!UNIT_VTABLE(u)->start;
788 * -EBADR: This unit type does not support stopping.
789 * -EALREADY: Unit is already stopped.
790 * -EAGAIN: An operation is already in progress. Retry later.
792 int unit_stop(Unit *u) {
793 UnitActiveState state;
797 state = unit_active_state(u);
798 if (UNIT_IS_INACTIVE_OR_MAINTENANCE(state))
801 if (!UNIT_VTABLE(u)->stop)
804 unit_add_to_dbus_queue(u);
805 return UNIT_VTABLE(u)->stop(u);
809 * -EBADR: This unit type does not support reloading.
810 * -ENOEXEC: Unit is not started.
811 * -EAGAIN: An operation is already in progress. Retry later.
813 int unit_reload(Unit *u) {
814 UnitActiveState state;
818 if (u->meta.load_state != UNIT_LOADED)
821 if (!unit_can_reload(u))
824 state = unit_active_state(u);
825 if (unit_active_state(u) == UNIT_RELOADING)
828 if (unit_active_state(u) != UNIT_ACTIVE)
831 unit_add_to_dbus_queue(u);
832 return UNIT_VTABLE(u)->reload(u);
835 bool unit_can_reload(Unit *u) {
838 if (!UNIT_VTABLE(u)->reload)
841 if (!UNIT_VTABLE(u)->can_reload)
844 return UNIT_VTABLE(u)->can_reload(u);
847 static void unit_check_uneeded(Unit *u) {
853 /* If this service shall be shut down when unneeded then do
856 if (!u->meta.stop_when_unneeded)
859 if (!UNIT_IS_ACTIVE_OR_ACTIVATING(unit_active_state(u)))
862 SET_FOREACH(other, u->meta.dependencies[UNIT_REQUIRED_BY], i)
863 if (!UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(other)))
866 SET_FOREACH(other, u->meta.dependencies[UNIT_REQUIRED_BY_OVERRIDABLE], i)
867 if (!UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(other)))
870 SET_FOREACH(other, u->meta.dependencies[UNIT_WANTED_BY], i)
871 if (!UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(other)))
874 log_debug("Service %s is not needed anymore. Stopping.", u->meta.id);
876 /* Ok, nobody needs us anymore. Sniff. Then let's commit suicide */
877 manager_add_job(u->meta.manager, JOB_STOP, u, JOB_FAIL, true, NULL);
880 static void retroactively_start_dependencies(Unit *u) {
885 assert(UNIT_IS_ACTIVE_OR_ACTIVATING(unit_active_state(u)));
887 SET_FOREACH(other, u->meta.dependencies[UNIT_REQUIRES], i)
888 if (!UNIT_IS_ACTIVE_OR_ACTIVATING(unit_active_state(other)))
889 manager_add_job(u->meta.manager, JOB_START, other, JOB_REPLACE, true, NULL);
891 SET_FOREACH(other, u->meta.dependencies[UNIT_REQUIRES_OVERRIDABLE], i)
892 if (!UNIT_IS_ACTIVE_OR_ACTIVATING(unit_active_state(other)))
893 manager_add_job(u->meta.manager, JOB_START, other, JOB_FAIL, false, NULL);
895 SET_FOREACH(other, u->meta.dependencies[UNIT_REQUISITE], i)
896 if (!UNIT_IS_ACTIVE_OR_ACTIVATING(unit_active_state(other)))
897 manager_add_job(u->meta.manager, JOB_START, other, JOB_REPLACE, true, NULL);
899 SET_FOREACH(other, u->meta.dependencies[UNIT_WANTS], i)
900 if (!UNIT_IS_ACTIVE_OR_ACTIVATING(unit_active_state(other)))
901 manager_add_job(u->meta.manager, JOB_START, other, JOB_FAIL, false, NULL);
903 SET_FOREACH(other, u->meta.dependencies[UNIT_CONFLICTS], i)
904 if (!UNIT_IS_ACTIVE_OR_ACTIVATING(unit_active_state(other)))
905 manager_add_job(u->meta.manager, JOB_STOP, other, JOB_REPLACE, true, NULL);
908 static void retroactively_stop_dependencies(Unit *u) {
913 assert(UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(u)));
915 if (u->meta.recursive_stop) {
916 /* Pull down units need us recursively if enabled */
917 SET_FOREACH(other, u->meta.dependencies[UNIT_REQUIRED_BY], i)
918 if (!UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(other)))
919 manager_add_job(u->meta.manager, JOB_STOP, other, JOB_REPLACE, true, NULL);
922 /* Garbage collect services that might not be needed anymore, if enabled */
923 SET_FOREACH(other, u->meta.dependencies[UNIT_REQUIRES], i)
924 if (!UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(other)))
925 unit_check_uneeded(other);
926 SET_FOREACH(other, u->meta.dependencies[UNIT_REQUIRES_OVERRIDABLE], i)
927 if (!UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(other)))
928 unit_check_uneeded(other);
929 SET_FOREACH(other, u->meta.dependencies[UNIT_WANTS], i)
930 if (!UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(other)))
931 unit_check_uneeded(other);
932 SET_FOREACH(other, u->meta.dependencies[UNIT_REQUISITE], i)
933 if (!UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(other)))
934 unit_check_uneeded(other);
935 SET_FOREACH(other, u->meta.dependencies[UNIT_REQUISITE_OVERRIDABLE], i)
936 if (!UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(other)))
937 unit_check_uneeded(other);
940 void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns) {
941 bool unexpected = false;
945 assert(os < _UNIT_ACTIVE_STATE_MAX);
946 assert(ns < _UNIT_ACTIVE_STATE_MAX);
948 /* Note that this is called for all low-level state changes,
949 * even if they might map to the same high-level
950 * UnitActiveState! That means that ns == os is OK an expected
951 * behaviour here. For example: if a mount point is remounted
952 * this function will be called too and the utmp code below
955 dual_timestamp_get(&ts);
957 if (UNIT_IS_INACTIVE_OR_MAINTENANCE(os) && !UNIT_IS_INACTIVE_OR_MAINTENANCE(ns))
958 u->meta.inactive_exit_timestamp = ts;
959 else if (!UNIT_IS_INACTIVE_OR_MAINTENANCE(os) && UNIT_IS_INACTIVE_OR_MAINTENANCE(ns))
960 u->meta.inactive_enter_timestamp = ts;
962 if (!UNIT_IS_ACTIVE_OR_RELOADING(os) && UNIT_IS_ACTIVE_OR_RELOADING(ns))
963 u->meta.active_enter_timestamp = ts;
964 else if (UNIT_IS_ACTIVE_OR_RELOADING(os) && !UNIT_IS_ACTIVE_OR_RELOADING(ns))
965 u->meta.active_exit_timestamp = ts;
967 timer_unit_notify(u, ns);
968 path_unit_notify(u, ns);
972 if (u->meta.job->state == JOB_WAITING)
974 /* So we reached a different state for this
975 * job. Let's see if we can run it now if it
976 * failed previously due to EAGAIN. */
977 job_add_to_run_queue(u->meta.job);
980 /* Let's check whether this state change constitutes a
981 * finished job, or maybe cotradicts a running job and
982 * hence needs to invalidate jobs. */
984 switch (u->meta.job->type) {
987 case JOB_VERIFY_ACTIVE:
989 if (UNIT_IS_ACTIVE_OR_RELOADING(ns))
990 job_finish_and_invalidate(u->meta.job, true);
991 else if (u->meta.job->state == JOB_RUNNING && ns != UNIT_ACTIVATING) {
993 job_finish_and_invalidate(u->meta.job, false);
999 case JOB_RELOAD_OR_START:
1001 if (u->meta.job->state == JOB_RUNNING) {
1002 if (ns == UNIT_ACTIVE)
1003 job_finish_and_invalidate(u->meta.job, true);
1004 else if (ns != UNIT_ACTIVATING && ns != UNIT_RELOADING) {
1006 job_finish_and_invalidate(u->meta.job, false);
1014 case JOB_TRY_RESTART:
1016 if (ns == UNIT_INACTIVE)
1017 job_finish_and_invalidate(u->meta.job, true);
1018 else if (ns == UNIT_MAINTENANCE)
1019 job_finish_and_invalidate(u->meta.job, false);
1020 else if (u->meta.job->state == JOB_RUNNING && ns != UNIT_DEACTIVATING) {
1022 job_finish_and_invalidate(u->meta.job, false);
1028 assert_not_reached("Job type unknown");
1032 /* If this state change happened without being requested by a
1033 * job, then let's retroactively start or stop dependencies */
1036 if (UNIT_IS_INACTIVE_OR_DEACTIVATING(os) && UNIT_IS_ACTIVE_OR_ACTIVATING(ns))
1037 retroactively_start_dependencies(u);
1038 else if (UNIT_IS_ACTIVE_OR_ACTIVATING(os) && UNIT_IS_INACTIVE_OR_DEACTIVATING(ns))
1039 retroactively_stop_dependencies(u);
1042 /* Some names are special */
1043 if (UNIT_IS_ACTIVE_OR_RELOADING(ns)) {
1044 if (unit_has_name(u, SPECIAL_DBUS_SERVICE)) {
1045 /* The bus just might have become available,
1046 * hence try to connect to it, if we aren't
1048 bus_init(u->meta.manager);
1051 if (unit_has_name(u, SPECIAL_SYSLOG_SERVICE))
1052 /* The syslog daemon just might have become
1053 * available, hence try to connect to it, if
1054 * we aren't yet connected. */
1057 if (u->meta.type == UNIT_MOUNT)
1058 /* Another directory became available, let's
1059 * check if that is enough to write our utmp
1061 manager_write_utmp_reboot(u->meta.manager);
1063 if (u->meta.type == UNIT_TARGET)
1064 /* A target got activated, maybe this is a runlevel? */
1065 manager_write_utmp_runlevel(u->meta.manager, u);
1067 } else if (!UNIT_IS_ACTIVE_OR_RELOADING(ns)) {
1069 if (unit_has_name(u, SPECIAL_SYSLOG_SERVICE))
1070 /* The syslog daemon might just have
1071 * terminated, hence try to disconnect from
1075 /* We don't care about D-Bus here, since we'll get an
1076 * asynchronous notification for it anyway. */
1079 /* Maybe we finished startup and are now ready for being
1080 * stopped because unneeded? */
1081 unit_check_uneeded(u);
1083 unit_add_to_dbus_queue(u);
1084 unit_add_to_gc_queue(u);
1087 int unit_watch_fd(Unit *u, int fd, uint32_t events, Watch *w) {
1088 struct epoll_event ev;
1093 assert(w->type == WATCH_INVALID || (w->type == WATCH_FD && w->fd == fd && w->data.unit == u));
1099 if (epoll_ctl(u->meta.manager->epoll_fd,
1100 w->type == WATCH_INVALID ? EPOLL_CTL_ADD : EPOLL_CTL_MOD,
1112 void unit_unwatch_fd(Unit *u, Watch *w) {
1116 if (w->type == WATCH_INVALID)
1119 assert(w->type == WATCH_FD);
1120 assert(w->data.unit == u);
1121 assert_se(epoll_ctl(u->meta.manager->epoll_fd, EPOLL_CTL_DEL, w->fd, NULL) >= 0);
1124 w->type = WATCH_INVALID;
1125 w->data.unit = NULL;
1128 int unit_watch_pid(Unit *u, pid_t pid) {
1132 /* Watch a specific PID. We only support one unit watching
1133 * each PID for now. */
1135 return hashmap_put(u->meta.manager->watch_pids, UINT32_TO_PTR(pid), u);
1138 void unit_unwatch_pid(Unit *u, pid_t pid) {
1142 hashmap_remove_value(u->meta.manager->watch_pids, UINT32_TO_PTR(pid), u);
1145 int unit_watch_timer(Unit *u, usec_t delay, Watch *w) {
1146 struct itimerspec its;
1152 assert(w->type == WATCH_INVALID || (w->type == WATCH_TIMER && w->data.unit == u));
1154 /* This will try to reuse the old timer if there is one */
1156 if (w->type == WATCH_TIMER) {
1161 if ((fd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK|TFD_CLOEXEC)) < 0)
1168 /* Set absolute time in the past, but not 0, since we
1169 * don't want to disarm the timer */
1170 its.it_value.tv_sec = 0;
1171 its.it_value.tv_nsec = 1;
1173 flags = TFD_TIMER_ABSTIME;
1175 timespec_store(&its.it_value, delay);
1179 /* This will also flush the elapse counter */
1180 if (timerfd_settime(fd, flags, &its, NULL) < 0)
1183 if (w->type == WATCH_INVALID) {
1184 struct epoll_event ev;
1188 ev.events = EPOLLIN;
1190 if (epoll_ctl(u->meta.manager->epoll_fd, EPOLL_CTL_ADD, fd, &ev) < 0)
1195 w->type = WATCH_TIMER;
1202 close_nointr_nofail(fd);
1207 void unit_unwatch_timer(Unit *u, Watch *w) {
1211 if (w->type == WATCH_INVALID)
1214 assert(w->type == WATCH_TIMER && w->data.unit == u);
1216 assert_se(epoll_ctl(u->meta.manager->epoll_fd, EPOLL_CTL_DEL, w->fd, NULL) >= 0);
1217 close_nointr_nofail(w->fd);
1220 w->type = WATCH_INVALID;
1221 w->data.unit = NULL;
1224 bool unit_job_is_applicable(Unit *u, JobType j) {
1226 assert(j >= 0 && j < _JOB_TYPE_MAX);
1230 case JOB_VERIFY_ACTIVE:
1236 case JOB_TRY_RESTART:
1237 return unit_can_start(u);
1240 return unit_can_reload(u);
1242 case JOB_RELOAD_OR_START:
1243 return unit_can_reload(u) && unit_can_start(u);
1246 assert_not_reached("Invalid job type");
1250 int unit_add_dependency(Unit *u, UnitDependency d, Unit *other, bool add_reference) {
1252 static const UnitDependency inverse_table[_UNIT_DEPENDENCY_MAX] = {
1253 [UNIT_REQUIRES] = UNIT_REQUIRED_BY,
1254 [UNIT_REQUIRES_OVERRIDABLE] = UNIT_REQUIRED_BY_OVERRIDABLE,
1255 [UNIT_WANTS] = UNIT_WANTED_BY,
1256 [UNIT_REQUISITE] = UNIT_REQUIRED_BY,
1257 [UNIT_REQUISITE_OVERRIDABLE] = UNIT_REQUIRED_BY_OVERRIDABLE,
1258 [UNIT_REQUIRED_BY] = _UNIT_DEPENDENCY_INVALID,
1259 [UNIT_REQUIRED_BY_OVERRIDABLE] = _UNIT_DEPENDENCY_INVALID,
1260 [UNIT_WANTED_BY] = _UNIT_DEPENDENCY_INVALID,
1261 [UNIT_CONFLICTS] = UNIT_CONFLICTS,
1262 [UNIT_BEFORE] = UNIT_AFTER,
1263 [UNIT_AFTER] = UNIT_BEFORE,
1264 [UNIT_REFERENCES] = UNIT_REFERENCED_BY,
1265 [UNIT_REFERENCED_BY] = UNIT_REFERENCES
1267 int r, q = 0, v = 0, w = 0;
1270 assert(d >= 0 && d < _UNIT_DEPENDENCY_MAX);
1271 assert(inverse_table[d] != _UNIT_DEPENDENCY_INVALID);
1274 /* We won't allow dependencies on ourselves. We will not
1275 * consider them an error however. */
1279 if (UNIT_VTABLE(u)->no_requires &&
1280 (d == UNIT_REQUIRES ||
1281 d == UNIT_REQUIRES_OVERRIDABLE ||
1282 d == UNIT_REQUISITE ||
1283 d == UNIT_REQUISITE_OVERRIDABLE)) {
1287 if ((r = set_ensure_allocated(&u->meta.dependencies[d], trivial_hash_func, trivial_compare_func)) < 0 ||
1288 (r = set_ensure_allocated(&other->meta.dependencies[inverse_table[d]], trivial_hash_func, trivial_compare_func)) < 0)
1292 if ((r = set_ensure_allocated(&u->meta.dependencies[UNIT_REFERENCES], trivial_hash_func, trivial_compare_func)) < 0 ||
1293 (r = set_ensure_allocated(&other->meta.dependencies[UNIT_REFERENCED_BY], trivial_hash_func, trivial_compare_func)) < 0)
1296 if ((q = set_put(u->meta.dependencies[d], other)) < 0)
1299 if ((v = set_put(other->meta.dependencies[inverse_table[d]], u)) < 0) {
1304 if (add_reference) {
1305 if ((w = set_put(u->meta.dependencies[UNIT_REFERENCES], other)) < 0) {
1310 if ((r = set_put(other->meta.dependencies[UNIT_REFERENCED_BY], u)) < 0)
1314 unit_add_to_dbus_queue(u);
1319 set_remove(u->meta.dependencies[d], other);
1322 set_remove(other->meta.dependencies[inverse_table[d]], u);
1325 set_remove(u->meta.dependencies[UNIT_REFERENCES], other);
1330 int unit_add_two_dependencies(Unit *u, UnitDependency d, UnitDependency e, Unit *other, bool add_reference) {
1335 if ((r = unit_add_dependency(u, d, other, add_reference)) < 0)
1338 if ((r = unit_add_dependency(u, e, other, add_reference)) < 0)
1344 static const char *resolve_template(Unit *u, const char *name, const char*path, char **p) {
1348 assert(name || path);
1351 name = file_name_from_path(path);
1353 if (!unit_name_is_template(name)) {
1358 if (u->meta.instance)
1359 s = unit_name_replace_instance(name, u->meta.instance);
1363 if (!(i = unit_name_to_prefix(u->meta.id)))
1366 s = unit_name_replace_instance(name, i);
1377 int unit_add_dependency_by_name(Unit *u, UnitDependency d, const char *name, const char *path, bool add_reference) {
1383 assert(name || path);
1385 if (!(name = resolve_template(u, name, path, &s)))
1388 if ((r = manager_load_unit(u->meta.manager, name, path, &other)) < 0)
1391 r = unit_add_dependency(u, d, other, add_reference);
1398 int unit_add_two_dependencies_by_name(Unit *u, UnitDependency d, UnitDependency e, const char *name, const char *path, bool add_reference) {
1404 assert(name || path);
1406 if (!(name = resolve_template(u, name, path, &s)))
1409 if ((r = manager_load_unit(u->meta.manager, name, path, &other)) < 0)
1412 r = unit_add_two_dependencies(u, d, e, other, add_reference);
1419 int unit_add_dependency_by_name_inverse(Unit *u, UnitDependency d, const char *name, const char *path, bool add_reference) {
1425 assert(name || path);
1427 if (!(name = resolve_template(u, name, path, &s)))
1430 if ((r = manager_load_unit(u->meta.manager, name, path, &other)) < 0)
1433 r = unit_add_dependency(other, d, u, add_reference);
1440 int unit_add_two_dependencies_by_name_inverse(Unit *u, UnitDependency d, UnitDependency e, const char *name, const char *path, bool add_reference) {
1446 assert(name || path);
1448 if (!(name = resolve_template(u, name, path, &s)))
1451 if ((r = manager_load_unit(u->meta.manager, name, path, &other)) < 0)
1454 if ((r = unit_add_two_dependencies(other, d, e, u, add_reference)) < 0)
1462 int set_unit_path(const char *p) {
1466 /* This is mostly for debug purposes */
1468 if (path_is_absolute(p)) {
1469 if (!(c = strdup(p)))
1472 if (!(cwd = get_current_dir_name()))
1475 r = asprintf(&c, "%s/%s", cwd, p);
1482 if (setenv("SYSTEMD_UNIT_PATH", c, 0) < 0) {
1491 char *unit_dbus_path(Unit *u) {
1496 if (!(e = bus_path_escape(u->meta.id)))
1499 if (asprintf(&p, "/org/freedesktop/systemd1/unit/%s", e) < 0) {
1508 int unit_add_cgroup(Unit *u, CGroupBonding *b) {
1516 /* Ensure this hasn't been added yet */
1519 l = hashmap_get(u->meta.manager->cgroup_bondings, b->path);
1520 LIST_PREPEND(CGroupBonding, by_path, l, b);
1522 if ((r = hashmap_replace(u->meta.manager->cgroup_bondings, b->path, l)) < 0) {
1523 LIST_REMOVE(CGroupBonding, by_path, l, b);
1527 LIST_PREPEND(CGroupBonding, by_unit, u->meta.cgroup_bondings, b);
1533 static char *default_cgroup_path(Unit *u) {
1539 if (u->meta.instance) {
1542 if (!(t = unit_name_template(u->meta.id)))
1545 r = asprintf(&p, "%s/%s/%s", u->meta.manager->cgroup_hierarchy, t, u->meta.instance);
1548 r = asprintf(&p, "%s/%s", u->meta.manager->cgroup_hierarchy, u->meta.id);
1550 return r < 0 ? NULL : p;
1553 int unit_add_cgroup_from_text(Unit *u, const char *name) {
1555 char *controller = NULL, *path = NULL;
1556 CGroupBonding *b = NULL;
1562 /* Detect controller name */
1563 n = strcspn(name, ":");
1566 (name[n] == ':' && name[n+1] == 0)) {
1568 /* Only controller name, no path? */
1570 if (!(path = default_cgroup_path(u)))
1576 /* Controller name, and path. */
1579 if (!path_is_absolute(p))
1582 if (!(path = strdup(p)))
1587 controller = strndup(name, n);
1589 controller = strdup(u->meta.manager->cgroup_controller);
1596 if (cgroup_bonding_find_list(u->meta.cgroup_bondings, controller)) {
1601 if (!(b = new0(CGroupBonding, 1))) {
1606 b->controller = controller;
1609 b->clean_up = false;
1611 if ((r = unit_add_cgroup(u, b)) < 0)
1624 int unit_add_default_cgroup(Unit *u) {
1630 /* Adds in the default cgroup data, if it wasn't specified yet */
1632 if (unit_get_default_cgroup(u))
1635 if (!(b = new0(CGroupBonding, 1)))
1638 if (!(b->controller = strdup(u->meta.manager->cgroup_controller)))
1641 if (!(b->path = default_cgroup_path(u)))
1647 if ((r = unit_add_cgroup(u, b)) < 0)
1654 free(b->controller);
1660 CGroupBonding* unit_get_default_cgroup(Unit *u) {
1663 return cgroup_bonding_find_list(u->meta.cgroup_bondings, u->meta.manager->cgroup_controller);
1666 int unit_load_related_unit(Unit *u, const char *type, Unit **_found) {
1674 if (!(t = unit_name_change_suffix(u->meta.id, type)))
1677 assert(!unit_has_name(u, t));
1679 r = manager_load_unit(u->meta.manager, t, NULL, _found);
1682 assert(r < 0 || *_found != u);
1687 int unit_get_related_unit(Unit *u, const char *type, Unit **_found) {
1695 if (!(t = unit_name_change_suffix(u->meta.id, type)))
1698 assert(!unit_has_name(u, t));
1700 found = manager_get_unit(u->meta.manager, t);
1710 static char *specifier_prefix_and_instance(char specifier, void *data, void *userdata) {
1714 return unit_name_to_prefix_and_instance(u->meta.id);
1717 static char *specifier_prefix(char specifier, void *data, void *userdata) {
1721 return unit_name_to_prefix(u->meta.id);
1724 static char *specifier_prefix_unescaped(char specifier, void *data, void *userdata) {
1730 if (!(p = unit_name_to_prefix(u->meta.id)))
1733 r = unit_name_unescape(p);
1739 static char *specifier_instance_unescaped(char specifier, void *data, void *userdata) {
1743 if (u->meta.instance)
1744 return unit_name_unescape(u->meta.instance);
1749 char *unit_name_printf(Unit *u, const char* format) {
1752 * This will use the passed string as format string and
1753 * replace the following specifiers:
1755 * %n: the full id of the unit (foo@bar.waldo)
1756 * %N: the id of the unit without the suffix (foo@bar)
1757 * %p: the prefix (foo)
1758 * %i: the instance (bar)
1761 const Specifier table[] = {
1762 { 'n', specifier_string, u->meta.id },
1763 { 'N', specifier_prefix_and_instance, NULL },
1764 { 'p', specifier_prefix, NULL },
1765 { 'i', specifier_string, u->meta.instance },
1772 return specifier_printf(format, table, u);
1775 char *unit_full_printf(Unit *u, const char *format) {
1777 /* This is similar to unit_name_printf() but also supports
1780 const Specifier table[] = {
1781 { 'n', specifier_string, u->meta.id },
1782 { 'N', specifier_prefix_and_instance, NULL },
1783 { 'p', specifier_prefix, NULL },
1784 { 'P', specifier_prefix_unescaped, NULL },
1785 { 'i', specifier_string, u->meta.instance },
1786 { 'I', specifier_instance_unescaped, NULL },
1793 return specifier_printf(format, table, u);
1796 char **unit_full_printf_strv(Unit *u, char **l) {
1800 /* Applies unit_full_printf to every entry in l */
1805 if (!(r = new(char*, n+1)))
1808 for (i = l, j = r; *i; i++, j++)
1809 if (!(*j = unit_full_printf(u, *i)))
1825 int unit_watch_bus_name(Unit *u, const char *name) {
1829 /* Watch a specific name on the bus. We only support one unit
1830 * watching each name for now. */
1832 return hashmap_put(u->meta.manager->watch_bus, name, u);
1835 void unit_unwatch_bus_name(Unit *u, const char *name) {
1839 hashmap_remove_value(u->meta.manager->watch_bus, name, u);
1842 bool unit_can_serialize(Unit *u) {
1845 return UNIT_VTABLE(u)->serialize && UNIT_VTABLE(u)->deserialize_item;
1848 int unit_serialize(Unit *u, FILE *f, FDSet *fds) {
1855 if (!unit_can_serialize(u))
1858 if ((r = UNIT_VTABLE(u)->serialize(u, f, fds)) < 0)
1862 unit_serialize_item(u, f, "job", job_type_to_string(u->meta.job->type));
1869 void unit_serialize_item_format(Unit *u, FILE *f, const char *key, const char *format, ...) {
1880 va_start(ap, format);
1881 vfprintf(f, format, ap);
1887 void unit_serialize_item(Unit *u, FILE *f, const char *key, const char *value) {
1893 fprintf(f, "%s=%s\n", key, value);
1896 int unit_deserialize(Unit *u, FILE *f, FDSet *fds) {
1903 if (!unit_can_serialize(u))
1907 char line[1024], *l, *v;
1910 if (!fgets(line, sizeof(line), f)) {
1922 k = strcspn(l, "=");
1930 if (streq(l, "job")) {
1933 if ((type = job_type_from_string(v)) < 0)
1934 log_debug("Failed to parse job type value %s", v);
1936 u->meta.deserialized_job = type;
1941 if ((r = UNIT_VTABLE(u)->deserialize_item(u, l, v, fds)) < 0)
1946 int unit_add_node_link(Unit *u, const char *what, bool wants) {
1956 /* Adds in links to the device node that this unit is based on */
1958 if (!is_device_path(what))
1961 if (!(e = unit_name_build_escape(what+1, NULL, ".device")))
1964 r = manager_load_unit(u->meta.manager, e, NULL, &device);
1970 if ((r = unit_add_two_dependencies(u, UNIT_AFTER, UNIT_REQUIRES, device, true)) < 0)
1974 if ((r = unit_add_dependency(device, UNIT_WANTS, u, false)) < 0)
1980 int unit_coldplug(Unit *u) {
1985 if (UNIT_VTABLE(u)->coldplug)
1986 if ((r = UNIT_VTABLE(u)->coldplug(u)) < 0)
1989 if (u->meta.deserialized_job >= 0) {
1990 if ((r = manager_add_job(u->meta.manager, u->meta.deserialized_job, u, JOB_FAIL, false, NULL)) < 0)
1993 u->meta.deserialized_job = _JOB_TYPE_INVALID;
1999 static const char* const unit_type_table[_UNIT_TYPE_MAX] = {
2000 [UNIT_SERVICE] = "service",
2001 [UNIT_TIMER] = "timer",
2002 [UNIT_SOCKET] = "socket",
2003 [UNIT_TARGET] = "target",
2004 [UNIT_DEVICE] = "device",
2005 [UNIT_MOUNT] = "mount",
2006 [UNIT_AUTOMOUNT] = "automount",
2007 [UNIT_SNAPSHOT] = "snapshot",
2008 [UNIT_SWAP] = "swap"
2011 DEFINE_STRING_TABLE_LOOKUP(unit_type, UnitType);
2013 static const char* const unit_load_state_table[_UNIT_LOAD_STATE_MAX] = {
2014 [UNIT_STUB] = "stub",
2015 [UNIT_LOADED] = "loaded",
2016 [UNIT_FAILED] = "failed",
2017 [UNIT_MERGED] = "merged"
2020 DEFINE_STRING_TABLE_LOOKUP(unit_load_state, UnitLoadState);
2022 static const char* const unit_active_state_table[_UNIT_ACTIVE_STATE_MAX] = {
2023 [UNIT_ACTIVE] = "active",
2024 [UNIT_RELOADING] = "reloading",
2025 [UNIT_INACTIVE] = "inactive",
2026 [UNIT_MAINTENANCE] = "maintenance",
2027 [UNIT_ACTIVATING] = "activating",
2028 [UNIT_DEACTIVATING] = "deactivating"
2031 DEFINE_STRING_TABLE_LOOKUP(unit_active_state, UnitActiveState);
2033 static const char* const unit_dependency_table[_UNIT_DEPENDENCY_MAX] = {
2034 [UNIT_REQUIRES] = "Requires",
2035 [UNIT_REQUIRES_OVERRIDABLE] = "RequiresOverridable",
2036 [UNIT_WANTS] = "Wants",
2037 [UNIT_REQUISITE] = "Requisite",
2038 [UNIT_REQUISITE_OVERRIDABLE] = "RequisiteOverridable",
2039 [UNIT_REQUIRED_BY] = "RequiredBy",
2040 [UNIT_REQUIRED_BY_OVERRIDABLE] = "RequiredByOverridable",
2041 [UNIT_WANTED_BY] = "WantedBy",
2042 [UNIT_CONFLICTS] = "Conflicts",
2043 [UNIT_BEFORE] = "Before",
2044 [UNIT_AFTER] = "After",
2045 [UNIT_REFERENCES] = "References",
2046 [UNIT_REFERENCED_BY] = "ReferencedBy"
2049 DEFINE_STRING_TABLE_LOOKUP(unit_dependency, UnitDependency);
2051 static const char* const kill_mode_table[_KILL_MODE_MAX] = {
2052 [KILL_CONTROL_GROUP] = "control-group",
2053 [KILL_PROCESS_GROUP] = "process-group",
2054 [KILL_PROCESS] = "process",
2055 [KILL_NONE] = "none"
2058 DEFINE_STRING_TABLE_LOOKUP(kill_mode, KillMode);