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"
42 #include "cgroup-util.h"
44 const UnitVTable * const unit_vtable[_UNIT_TYPE_MAX] = {
45 [UNIT_SERVICE] = &service_vtable,
46 [UNIT_TIMER] = &timer_vtable,
47 [UNIT_SOCKET] = &socket_vtable,
48 [UNIT_TARGET] = &target_vtable,
49 [UNIT_DEVICE] = &device_vtable,
50 [UNIT_MOUNT] = &mount_vtable,
51 [UNIT_AUTOMOUNT] = &automount_vtable,
52 [UNIT_SNAPSHOT] = &snapshot_vtable,
53 [UNIT_SWAP] = &swap_vtable,
54 [UNIT_PATH] = &path_vtable
57 Unit *unit_new(Manager *m) {
62 if (!(u = new0(Unit, 1)))
65 if (!(u->meta.names = set_new(string_hash_func, string_compare_func))) {
71 u->meta.type = _UNIT_TYPE_INVALID;
72 u->meta.deserialized_job = _JOB_TYPE_INVALID;
73 u->meta.default_dependencies = true;
78 bool unit_has_name(Unit *u, const char *name) {
82 return !!set_get(u->meta.names, (char*) name);
85 int unit_add_name(Unit *u, const char *text) {
93 if (unit_name_is_template(text)) {
94 if (!u->meta.instance)
97 s = unit_name_replace_instance(text, u->meta.instance);
104 if (!unit_name_is_valid(s)) {
109 assert_se((t = unit_name_to_type(s)) >= 0);
111 if (u->meta.type != _UNIT_TYPE_INVALID && t != u->meta.type) {
116 if ((r = unit_name_to_instance(s, &i)) < 0)
119 if (i && unit_vtable[t]->no_instances)
122 /* Ensure that this unit is either instanced or not instanced,
124 if (u->meta.type != _UNIT_TYPE_INVALID && !u->meta.instance != !i) {
129 if (unit_vtable[t]->no_alias &&
130 !set_isempty(u->meta.names) &&
131 !set_get(u->meta.names, s)) {
136 if (hashmap_size(u->meta.manager->units) >= MANAGER_MAX_NAMES) {
141 if ((r = set_put(u->meta.names, s)) < 0) {
147 if ((r = hashmap_put(u->meta.manager->units, s, u)) < 0) {
148 set_remove(u->meta.names, s);
152 if (u->meta.type == _UNIT_TYPE_INVALID) {
156 u->meta.instance = i;
158 LIST_PREPEND(Meta, units_per_type, u->meta.manager->units_per_type[t], &u->meta);
160 if (UNIT_VTABLE(u)->init)
161 UNIT_VTABLE(u)->init(u);
165 unit_add_to_dbus_queue(u);
175 int unit_choose_id(Unit *u, const char *name) {
176 char *s, *t = NULL, *i;
182 if (unit_name_is_template(name)) {
184 if (!u->meta.instance)
187 if (!(t = unit_name_replace_instance(name, u->meta.instance)))
193 /* Selects one of the names of this unit as the id */
194 s = set_get(u->meta.names, (char*) name);
200 if ((r = unit_name_to_instance(s, &i)) < 0)
205 free(u->meta.instance);
206 u->meta.instance = i;
208 unit_add_to_dbus_queue(u);
213 int unit_set_description(Unit *u, const char *description) {
218 if (!(s = strdup(description)))
221 free(u->meta.description);
222 u->meta.description = s;
224 unit_add_to_dbus_queue(u);
228 bool unit_check_gc(Unit *u) {
231 if (u->meta.load_state == UNIT_STUB)
234 if (UNIT_VTABLE(u)->no_gc)
240 if (unit_active_state(u) != UNIT_INACTIVE)
243 if (UNIT_VTABLE(u)->check_gc)
244 if (UNIT_VTABLE(u)->check_gc(u))
250 void unit_add_to_load_queue(Unit *u) {
252 assert(u->meta.type != _UNIT_TYPE_INVALID);
254 if (u->meta.load_state != UNIT_STUB || u->meta.in_load_queue)
257 LIST_PREPEND(Meta, load_queue, u->meta.manager->load_queue, &u->meta);
258 u->meta.in_load_queue = true;
261 void unit_add_to_cleanup_queue(Unit *u) {
264 if (u->meta.in_cleanup_queue)
267 LIST_PREPEND(Meta, cleanup_queue, u->meta.manager->cleanup_queue, &u->meta);
268 u->meta.in_cleanup_queue = true;
271 void unit_add_to_gc_queue(Unit *u) {
274 if (u->meta.in_gc_queue || u->meta.in_cleanup_queue)
277 if (unit_check_gc(u))
280 LIST_PREPEND(Meta, gc_queue, u->meta.manager->gc_queue, &u->meta);
281 u->meta.in_gc_queue = true;
283 u->meta.manager->n_in_gc_queue ++;
285 if (u->meta.manager->gc_queue_timestamp <= 0)
286 u->meta.manager->gc_queue_timestamp = now(CLOCK_MONOTONIC);
289 void unit_add_to_dbus_queue(Unit *u) {
291 assert(u->meta.type != _UNIT_TYPE_INVALID);
293 if (u->meta.load_state == UNIT_STUB || u->meta.in_dbus_queue)
296 /* Shortcut things if nobody cares */
297 if (!bus_has_subscriber(u->meta.manager)) {
298 u->meta.sent_dbus_new_signal = true;
302 LIST_PREPEND(Meta, dbus_queue, u->meta.manager->dbus_unit_queue, &u->meta);
303 u->meta.in_dbus_queue = true;
306 static void bidi_set_free(Unit *u, Set *s) {
312 /* Frees the set and makes sure we are dropped from the
313 * inverse pointers */
315 SET_FOREACH(other, s, i) {
318 for (d = 0; d < _UNIT_DEPENDENCY_MAX; d++)
319 set_remove(other->meta.dependencies[d], u);
321 unit_add_to_gc_queue(other);
327 void unit_free(Unit *u) {
334 bus_unit_send_removed_signal(u);
336 if (u->meta.load_state != UNIT_STUB)
337 if (UNIT_VTABLE(u)->done)
338 UNIT_VTABLE(u)->done(u);
340 SET_FOREACH(t, u->meta.names, i)
341 hashmap_remove_value(u->meta.manager->units, t, u);
344 job_free(u->meta.job);
346 for (d = 0; d < _UNIT_DEPENDENCY_MAX; d++)
347 bidi_set_free(u, u->meta.dependencies[d]);
349 if (u->meta.type != _UNIT_TYPE_INVALID)
350 LIST_REMOVE(Meta, units_per_type, u->meta.manager->units_per_type[u->meta.type], &u->meta);
352 if (u->meta.in_load_queue)
353 LIST_REMOVE(Meta, load_queue, u->meta.manager->load_queue, &u->meta);
355 if (u->meta.in_dbus_queue)
356 LIST_REMOVE(Meta, dbus_queue, u->meta.manager->dbus_unit_queue, &u->meta);
358 if (u->meta.in_cleanup_queue)
359 LIST_REMOVE(Meta, cleanup_queue, u->meta.manager->cleanup_queue, &u->meta);
361 if (u->meta.in_gc_queue) {
362 LIST_REMOVE(Meta, gc_queue, u->meta.manager->gc_queue, &u->meta);
363 u->meta.manager->n_in_gc_queue--;
366 cgroup_bonding_free_list(u->meta.cgroup_bondings);
368 free(u->meta.description);
369 free(u->meta.fragment_path);
371 set_free_free(u->meta.names);
373 free(u->meta.instance);
378 UnitActiveState unit_active_state(Unit *u) {
381 if (u->meta.load_state == UNIT_MERGED)
382 return unit_active_state(unit_follow_merge(u));
384 /* After a reload it might happen that a unit is not correctly
385 * loaded but still has a process around. That's why we won't
386 * shortcut failed loading to UNIT_INACTIVE_MAINTENANCE. */
388 return UNIT_VTABLE(u)->active_state(u);
391 const char* unit_sub_state_to_string(Unit *u) {
394 return UNIT_VTABLE(u)->sub_state_to_string(u);
397 static void complete_move(Set **s, Set **other) {
405 set_move(*s, *other);
412 static void merge_names(Unit *u, Unit *other) {
419 complete_move(&u->meta.names, &other->meta.names);
421 set_free_free(other->meta.names);
422 other->meta.names = NULL;
423 other->meta.id = NULL;
425 SET_FOREACH(t, u->meta.names, i)
426 assert_se(hashmap_replace(u->meta.manager->units, t, u) == 0);
429 static void merge_dependencies(Unit *u, Unit *other, UnitDependency d) {
436 assert(d < _UNIT_DEPENDENCY_MAX);
438 SET_FOREACH(back, other->meta.dependencies[d], i) {
441 for (k = 0; k < _UNIT_DEPENDENCY_MAX; k++)
442 if ((r = set_remove_and_put(back->meta.dependencies[k], other, u)) < 0) {
445 set_remove(back->meta.dependencies[k], other);
447 assert(r == -ENOENT);
451 complete_move(&u->meta.dependencies[d], &other->meta.dependencies[d]);
453 set_free(other->meta.dependencies[d]);
454 other->meta.dependencies[d] = NULL;
457 int unit_merge(Unit *u, Unit *other) {
462 assert(u->meta.manager == other->meta.manager);
463 assert(u->meta.type != _UNIT_TYPE_INVALID);
465 other = unit_follow_merge(other);
470 if (u->meta.type != other->meta.type)
473 if (!u->meta.instance != !other->meta.instance)
476 if (other->meta.load_state != UNIT_STUB &&
477 other->meta.load_state != UNIT_FAILED)
483 if (!UNIT_IS_INACTIVE_OR_MAINTENANCE(unit_active_state(other)))
487 merge_names(u, other);
489 /* Merge dependencies */
490 for (d = 0; d < _UNIT_DEPENDENCY_MAX; d++)
491 merge_dependencies(u, other, d);
493 other->meta.load_state = UNIT_MERGED;
494 other->meta.merged_into = u;
496 /* If there is still some data attached to the other node, we
497 * don't need it anymore, and can free it. */
498 if (other->meta.load_state != UNIT_STUB)
499 if (UNIT_VTABLE(other)->done)
500 UNIT_VTABLE(other)->done(other);
502 unit_add_to_dbus_queue(u);
503 unit_add_to_cleanup_queue(other);
508 int unit_merge_by_name(Unit *u, const char *name) {
516 if (unit_name_is_template(name)) {
517 if (!u->meta.instance)
520 if (!(s = unit_name_replace_instance(name, u->meta.instance)))
526 if (!(other = manager_get_unit(u->meta.manager, name)))
527 r = unit_add_name(u, name);
529 r = unit_merge(u, other);
535 Unit* unit_follow_merge(Unit *u) {
538 while (u->meta.load_state == UNIT_MERGED)
539 assert_se(u = u->meta.merged_into);
544 int unit_add_exec_dependencies(Unit *u, ExecContext *c) {
550 if (c->std_output != EXEC_OUTPUT_KMSG &&
551 c->std_output != EXEC_OUTPUT_SYSLOG &&
552 c->std_error != EXEC_OUTPUT_KMSG &&
553 c->std_error != EXEC_OUTPUT_SYSLOG)
556 /* If syslog or kernel logging is requested, make sure our own
557 * logging daemon is run first. */
559 if ((r = unit_add_dependency_by_name(u, UNIT_AFTER, SPECIAL_LOGGER_SOCKET, NULL, true)) < 0)
562 if (u->meta.manager->running_as == MANAGER_SYSTEM)
563 if ((r = unit_add_dependency_by_name(u, UNIT_REQUIRES, SPECIAL_LOGGER_SOCKET, NULL, true)) < 0)
569 const char *unit_description(Unit *u) {
572 if (u->meta.description)
573 return u->meta.description;
578 void unit_dump(Unit *u, FILE *f, const char *prefix) {
586 timestamp1[FORMAT_TIMESTAMP_MAX],
587 timestamp2[FORMAT_TIMESTAMP_MAX],
588 timestamp3[FORMAT_TIMESTAMP_MAX],
589 timestamp4[FORMAT_TIMESTAMP_MAX];
592 assert(u->meta.type >= 0);
596 p2 = strappend(prefix, "\t");
597 prefix2 = p2 ? p2 : prefix;
601 "%s\tDescription: %s\n"
603 "%s\tUnit Load State: %s\n"
604 "%s\tUnit Active State: %s\n"
605 "%s\tInactive Exit Timestamp: %s\n"
606 "%s\tActive Enter Timestamp: %s\n"
607 "%s\tActive Exit Timestamp: %s\n"
608 "%s\tInactive Enter Timestamp: %s\n"
609 "%s\tGC Check Good: %s\n",
611 prefix, unit_description(u),
612 prefix, strna(u->meta.instance),
613 prefix, unit_load_state_to_string(u->meta.load_state),
614 prefix, unit_active_state_to_string(unit_active_state(u)),
615 prefix, strna(format_timestamp(timestamp1, sizeof(timestamp1), u->meta.inactive_exit_timestamp.realtime)),
616 prefix, strna(format_timestamp(timestamp2, sizeof(timestamp2), u->meta.active_enter_timestamp.realtime)),
617 prefix, strna(format_timestamp(timestamp3, sizeof(timestamp3), u->meta.active_exit_timestamp.realtime)),
618 prefix, strna(format_timestamp(timestamp4, sizeof(timestamp4), u->meta.inactive_enter_timestamp.realtime)),
619 prefix, yes_no(unit_check_gc(u)));
621 SET_FOREACH(t, u->meta.names, i)
622 fprintf(f, "%s\tName: %s\n", prefix, t);
624 if (u->meta.fragment_path)
625 fprintf(f, "%s\tFragment Path: %s\n", prefix, u->meta.fragment_path);
627 for (d = 0; d < _UNIT_DEPENDENCY_MAX; d++) {
630 SET_FOREACH(other, u->meta.dependencies[d], i)
631 fprintf(f, "%s\t%s: %s\n", prefix, unit_dependency_to_string(d), other->meta.id);
634 if (u->meta.load_state == UNIT_LOADED) {
636 "%s\tRecursive Stop: %s\n"
637 "%s\tStopWhenUnneeded: %s\n"
638 "%s\tOnlyByDependency: %s\n"
639 "%s\tDefaultDependencies: %s\n"
640 "%s\tIgnoreDependencyFailure: %s\n",
641 prefix, yes_no(u->meta.recursive_stop),
642 prefix, yes_no(u->meta.stop_when_unneeded),
643 prefix, yes_no(u->meta.only_by_dependency),
644 prefix, yes_no(u->meta.default_dependencies),
645 prefix, yes_no(u->meta.ignore_dependency_failure));
647 LIST_FOREACH(by_unit, b, u->meta.cgroup_bondings)
648 fprintf(f, "%s\tControlGroup: %s:%s\n",
649 prefix, b->controller, b->path);
651 if (UNIT_VTABLE(u)->dump)
652 UNIT_VTABLE(u)->dump(u, f, prefix2);
654 } else if (u->meta.load_state == UNIT_MERGED)
656 "%s\tMerged into: %s\n",
657 prefix, u->meta.merged_into->meta.id);
660 job_dump(u->meta.job, f, prefix2);
665 /* Common implementation for multiple backends */
666 int unit_load_fragment_and_dropin(Unit *u) {
671 /* Load a .service file */
672 if ((r = unit_load_fragment(u)) < 0)
675 if (u->meta.load_state == UNIT_STUB)
678 /* Load drop-in directory data */
679 if ((r = unit_load_dropin(unit_follow_merge(u))) < 0)
685 /* Common implementation for multiple backends */
686 int unit_load_fragment_and_dropin_optional(Unit *u) {
691 /* Same as unit_load_fragment_and_dropin(), but whether
692 * something can be loaded or not doesn't matter. */
694 /* Load a .service file */
695 if ((r = unit_load_fragment(u)) < 0)
698 if (u->meta.load_state == UNIT_STUB)
699 u->meta.load_state = UNIT_LOADED;
701 /* Load drop-in directory data */
702 if ((r = unit_load_dropin(unit_follow_merge(u))) < 0)
708 /* Common implementation for multiple backends */
709 int unit_load_nop(Unit *u) {
712 if (u->meta.load_state == UNIT_STUB)
713 u->meta.load_state = UNIT_LOADED;
718 int unit_load(Unit *u) {
723 if (u->meta.in_load_queue) {
724 LIST_REMOVE(Meta, load_queue, u->meta.manager->load_queue, &u->meta);
725 u->meta.in_load_queue = false;
728 if (u->meta.type == _UNIT_TYPE_INVALID)
731 if (u->meta.load_state != UNIT_STUB)
734 if (UNIT_VTABLE(u)->load)
735 if ((r = UNIT_VTABLE(u)->load(u)) < 0)
738 if (u->meta.load_state == UNIT_STUB) {
743 assert((u->meta.load_state != UNIT_MERGED) == !u->meta.merged_into);
745 unit_add_to_dbus_queue(unit_follow_merge(u));
746 unit_add_to_gc_queue(u);
751 u->meta.load_state = UNIT_FAILED;
752 unit_add_to_dbus_queue(u);
754 log_notice("Failed to load configuration for %s: %s", u->meta.id, strerror(-r));
760 * -EBADR: This unit type does not support starting.
761 * -EALREADY: Unit is already started.
762 * -EAGAIN: An operation is already in progress. Retry later.
763 * -ECANCELED: Too many requests for now.
765 int unit_start(Unit *u) {
766 UnitActiveState state;
770 if (u->meta.load_state != UNIT_LOADED)
773 /* If this is already (being) started, then this will
774 * succeed. Note that this will even succeed if this unit is
775 * not startable by the user. This is relied on to detect when
776 * we need to wait for units and when waiting is finished. */
777 state = unit_active_state(u);
778 if (UNIT_IS_ACTIVE_OR_RELOADING(state))
781 /* If it is stopped, but we cannot start it, then fail */
782 if (!UNIT_VTABLE(u)->start)
785 /* We don't suppress calls to ->start() here when we are
786 * already starting, to allow this request to be used as a
787 * "hurry up" call, for example when the unit is in some "auto
788 * restart" state where it waits for a holdoff timer to elapse
789 * before it will start again. */
791 unit_add_to_dbus_queue(u);
793 unit_status_printf(u, "Starting %s...\n", unit_description(u));
795 return UNIT_VTABLE(u)->start(u);
798 bool unit_can_start(Unit *u) {
801 return !!UNIT_VTABLE(u)->start;
805 * -EBADR: This unit type does not support stopping.
806 * -EALREADY: Unit is already stopped.
807 * -EAGAIN: An operation is already in progress. Retry later.
809 int unit_stop(Unit *u) {
810 UnitActiveState state;
814 state = unit_active_state(u);
815 if (UNIT_IS_INACTIVE_OR_MAINTENANCE(state))
818 if (!UNIT_VTABLE(u)->stop)
821 unit_add_to_dbus_queue(u);
823 unit_status_printf(u, "Stopping %s...\n", unit_description(u));
825 return UNIT_VTABLE(u)->stop(u);
829 * -EBADR: This unit type does not support reloading.
830 * -ENOEXEC: Unit is not started.
831 * -EAGAIN: An operation is already in progress. Retry later.
833 int unit_reload(Unit *u) {
834 UnitActiveState state;
838 if (u->meta.load_state != UNIT_LOADED)
841 if (!unit_can_reload(u))
844 state = unit_active_state(u);
845 if (unit_active_state(u) == UNIT_RELOADING)
848 if (unit_active_state(u) != UNIT_ACTIVE)
851 unit_add_to_dbus_queue(u);
852 return UNIT_VTABLE(u)->reload(u);
855 bool unit_can_reload(Unit *u) {
858 if (!UNIT_VTABLE(u)->reload)
861 if (!UNIT_VTABLE(u)->can_reload)
864 return UNIT_VTABLE(u)->can_reload(u);
867 static void unit_check_uneeded(Unit *u) {
873 /* If this service shall be shut down when unneeded then do
876 if (!u->meta.stop_when_unneeded)
879 if (!UNIT_IS_ACTIVE_OR_ACTIVATING(unit_active_state(u)))
882 SET_FOREACH(other, u->meta.dependencies[UNIT_REQUIRED_BY], i)
883 if (!UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(other)))
886 SET_FOREACH(other, u->meta.dependencies[UNIT_REQUIRED_BY_OVERRIDABLE], i)
887 if (!UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(other)))
890 SET_FOREACH(other, u->meta.dependencies[UNIT_WANTED_BY], i)
891 if (!UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(other)))
894 log_info("Service %s is not needed anymore. Stopping.", u->meta.id);
896 /* Ok, nobody needs us anymore. Sniff. Then let's commit suicide */
897 manager_add_job(u->meta.manager, JOB_STOP, u, JOB_FAIL, true, NULL, NULL);
900 static void retroactively_start_dependencies(Unit *u) {
905 assert(UNIT_IS_ACTIVE_OR_ACTIVATING(unit_active_state(u)));
907 SET_FOREACH(other, u->meta.dependencies[UNIT_REQUIRES], i)
908 if (!UNIT_IS_ACTIVE_OR_ACTIVATING(unit_active_state(other)))
909 manager_add_job(u->meta.manager, JOB_START, other, JOB_REPLACE, true, NULL, NULL);
911 SET_FOREACH(other, u->meta.dependencies[UNIT_REQUIRES_OVERRIDABLE], i)
912 if (!UNIT_IS_ACTIVE_OR_ACTIVATING(unit_active_state(other)))
913 manager_add_job(u->meta.manager, JOB_START, other, JOB_FAIL, false, NULL, NULL);
915 SET_FOREACH(other, u->meta.dependencies[UNIT_REQUISITE], i)
916 if (!UNIT_IS_ACTIVE_OR_ACTIVATING(unit_active_state(other)))
917 manager_add_job(u->meta.manager, JOB_START, other, JOB_REPLACE, true, NULL, NULL);
919 SET_FOREACH(other, u->meta.dependencies[UNIT_WANTS], i)
920 if (!UNIT_IS_ACTIVE_OR_ACTIVATING(unit_active_state(other)))
921 manager_add_job(u->meta.manager, JOB_START, other, JOB_FAIL, false, NULL, NULL);
923 SET_FOREACH(other, u->meta.dependencies[UNIT_CONFLICTS], i)
924 if (!UNIT_IS_ACTIVE_OR_ACTIVATING(unit_active_state(other)))
925 manager_add_job(u->meta.manager, JOB_STOP, other, JOB_REPLACE, true, NULL, NULL);
928 static void retroactively_stop_dependencies(Unit *u) {
933 assert(UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(u)));
935 if (u->meta.recursive_stop) {
936 /* Pull down units need us recursively if enabled */
937 SET_FOREACH(other, u->meta.dependencies[UNIT_REQUIRED_BY], i)
938 if (!UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(other)))
939 manager_add_job(u->meta.manager, JOB_STOP, other, JOB_REPLACE, true, NULL, NULL);
942 /* Garbage collect services that might not be needed anymore, if enabled */
943 SET_FOREACH(other, u->meta.dependencies[UNIT_REQUIRES], i)
944 if (!UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(other)))
945 unit_check_uneeded(other);
946 SET_FOREACH(other, u->meta.dependencies[UNIT_REQUIRES_OVERRIDABLE], i)
947 if (!UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(other)))
948 unit_check_uneeded(other);
949 SET_FOREACH(other, u->meta.dependencies[UNIT_WANTS], i)
950 if (!UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(other)))
951 unit_check_uneeded(other);
952 SET_FOREACH(other, u->meta.dependencies[UNIT_REQUISITE], i)
953 if (!UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(other)))
954 unit_check_uneeded(other);
955 SET_FOREACH(other, u->meta.dependencies[UNIT_REQUISITE_OVERRIDABLE], i)
956 if (!UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(other)))
957 unit_check_uneeded(other);
960 void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns) {
965 assert(os < _UNIT_ACTIVE_STATE_MAX);
966 assert(ns < _UNIT_ACTIVE_STATE_MAX);
968 /* Note that this is called for all low-level state changes,
969 * even if they might map to the same high-level
970 * UnitActiveState! That means that ns == os is OK an expected
971 * behaviour here. For example: if a mount point is remounted
972 * this function will be called too and the utmp code below
975 dual_timestamp_get(&ts);
977 if (UNIT_IS_INACTIVE_OR_MAINTENANCE(os) && !UNIT_IS_INACTIVE_OR_MAINTENANCE(ns))
978 u->meta.inactive_exit_timestamp = ts;
979 else if (!UNIT_IS_INACTIVE_OR_MAINTENANCE(os) && UNIT_IS_INACTIVE_OR_MAINTENANCE(ns))
980 u->meta.inactive_enter_timestamp = ts;
982 if (!UNIT_IS_ACTIVE_OR_RELOADING(os) && UNIT_IS_ACTIVE_OR_RELOADING(ns))
983 u->meta.active_enter_timestamp = ts;
984 else if (UNIT_IS_ACTIVE_OR_RELOADING(os) && !UNIT_IS_ACTIVE_OR_RELOADING(ns))
985 u->meta.active_exit_timestamp = ts;
987 if (ns != os && ns == UNIT_MAINTENANCE)
988 log_notice("Unit %s entered maintenance state.", u->meta.id);
990 if (UNIT_IS_INACTIVE_OR_MAINTENANCE(ns))
991 cgroup_bonding_trim_list(u->meta.cgroup_bondings, true);
993 timer_unit_notify(u, ns);
994 path_unit_notify(u, ns);
999 if (u->meta.job->state == JOB_WAITING)
1001 /* So we reached a different state for this
1002 * job. Let's see if we can run it now if it
1003 * failed previously due to EAGAIN. */
1004 job_add_to_run_queue(u->meta.job);
1007 /* Let's check whether this state change constitutes a
1008 * finished job, or maybe cotradicts a running job and
1009 * hence needs to invalidate jobs. */
1011 switch (u->meta.job->type) {
1014 case JOB_VERIFY_ACTIVE:
1016 if (UNIT_IS_ACTIVE_OR_RELOADING(ns))
1017 job_finish_and_invalidate(u->meta.job, true);
1018 else if (u->meta.job->state == JOB_RUNNING && ns != UNIT_ACTIVATING) {
1020 job_finish_and_invalidate(u->meta.job, false);
1026 case JOB_RELOAD_OR_START:
1028 if (u->meta.job->state == JOB_RUNNING) {
1029 if (ns == UNIT_ACTIVE)
1030 job_finish_and_invalidate(u->meta.job, true);
1031 else if (ns != UNIT_ACTIVATING && ns != UNIT_RELOADING) {
1033 job_finish_and_invalidate(u->meta.job, false);
1041 case JOB_TRY_RESTART:
1043 if (ns == UNIT_INACTIVE || ns == UNIT_MAINTENANCE)
1044 job_finish_and_invalidate(u->meta.job, true);
1045 else if (u->meta.job->state == JOB_RUNNING && ns != UNIT_DEACTIVATING) {
1047 job_finish_and_invalidate(u->meta.job, false);
1053 assert_not_reached("Job type unknown");
1059 /* If this state change happened without being requested by a
1060 * job, then let's retroactively start or stop
1061 * dependencies. We skip that step when deserializing, since
1062 * we don't want to create any additional jobs just because
1063 * something is already activated. */
1065 if (unexpected && u->meta.manager->n_deserializing <= 0) {
1066 if (UNIT_IS_INACTIVE_OR_DEACTIVATING(os) && UNIT_IS_ACTIVE_OR_ACTIVATING(ns))
1067 retroactively_start_dependencies(u);
1068 else if (UNIT_IS_ACTIVE_OR_ACTIVATING(os) && UNIT_IS_INACTIVE_OR_DEACTIVATING(ns))
1069 retroactively_stop_dependencies(u);
1072 /* Some names are special */
1073 if (UNIT_IS_ACTIVE_OR_RELOADING(ns)) {
1074 if (unit_has_name(u, SPECIAL_DBUS_SERVICE)) {
1075 /* The bus just might have become available,
1076 * hence try to connect to it, if we aren't
1078 bus_init(u->meta.manager);
1081 if (unit_has_name(u, SPECIAL_SYSLOG_SERVICE))
1082 /* The syslog daemon just might have become
1083 * available, hence try to connect to it, if
1084 * we aren't yet connected. */
1087 if (u->meta.type == UNIT_MOUNT)
1088 /* Another directory became available, let's
1089 * check if that is enough to write our utmp
1091 manager_write_utmp_reboot(u->meta.manager);
1093 if (u->meta.type == UNIT_TARGET)
1094 /* A target got activated, maybe this is a runlevel? */
1095 manager_write_utmp_runlevel(u->meta.manager, u);
1097 } else if (!UNIT_IS_ACTIVE_OR_RELOADING(ns)) {
1099 if (unit_has_name(u, SPECIAL_SYSLOG_SERVICE))
1100 /* The syslog daemon might just have
1101 * terminated, hence try to disconnect from
1105 /* We don't care about D-Bus here, since we'll get an
1106 * asynchronous notification for it anyway. */
1109 /* Maybe we finished startup and are now ready for being
1110 * stopped because unneeded? */
1111 unit_check_uneeded(u);
1113 unit_add_to_dbus_queue(u);
1114 unit_add_to_gc_queue(u);
1117 int unit_watch_fd(Unit *u, int fd, uint32_t events, Watch *w) {
1118 struct epoll_event ev;
1123 assert(w->type == WATCH_INVALID || (w->type == WATCH_FD && w->fd == fd && w->data.unit == u));
1129 if (epoll_ctl(u->meta.manager->epoll_fd,
1130 w->type == WATCH_INVALID ? EPOLL_CTL_ADD : EPOLL_CTL_MOD,
1142 void unit_unwatch_fd(Unit *u, Watch *w) {
1146 if (w->type == WATCH_INVALID)
1149 assert(w->type == WATCH_FD);
1150 assert(w->data.unit == u);
1151 assert_se(epoll_ctl(u->meta.manager->epoll_fd, EPOLL_CTL_DEL, w->fd, NULL) >= 0);
1154 w->type = WATCH_INVALID;
1155 w->data.unit = NULL;
1158 int unit_watch_pid(Unit *u, pid_t pid) {
1162 /* Watch a specific PID. We only support one unit watching
1163 * each PID for now. */
1165 return hashmap_put(u->meta.manager->watch_pids, LONG_TO_PTR(pid), u);
1168 void unit_unwatch_pid(Unit *u, pid_t pid) {
1172 hashmap_remove_value(u->meta.manager->watch_pids, LONG_TO_PTR(pid), u);
1175 int unit_watch_timer(Unit *u, usec_t delay, Watch *w) {
1176 struct itimerspec its;
1182 assert(w->type == WATCH_INVALID || (w->type == WATCH_TIMER && w->data.unit == u));
1184 /* This will try to reuse the old timer if there is one */
1186 if (w->type == WATCH_TIMER) {
1191 if ((fd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK|TFD_CLOEXEC)) < 0)
1198 /* Set absolute time in the past, but not 0, since we
1199 * don't want to disarm the timer */
1200 its.it_value.tv_sec = 0;
1201 its.it_value.tv_nsec = 1;
1203 flags = TFD_TIMER_ABSTIME;
1205 timespec_store(&its.it_value, delay);
1209 /* This will also flush the elapse counter */
1210 if (timerfd_settime(fd, flags, &its, NULL) < 0)
1213 if (w->type == WATCH_INVALID) {
1214 struct epoll_event ev;
1218 ev.events = EPOLLIN;
1220 if (epoll_ctl(u->meta.manager->epoll_fd, EPOLL_CTL_ADD, fd, &ev) < 0)
1225 w->type = WATCH_TIMER;
1232 close_nointr_nofail(fd);
1237 void unit_unwatch_timer(Unit *u, Watch *w) {
1241 if (w->type == WATCH_INVALID)
1244 assert(w->type == WATCH_TIMER && w->data.unit == u);
1246 assert_se(epoll_ctl(u->meta.manager->epoll_fd, EPOLL_CTL_DEL, w->fd, NULL) >= 0);
1247 close_nointr_nofail(w->fd);
1250 w->type = WATCH_INVALID;
1251 w->data.unit = NULL;
1254 bool unit_job_is_applicable(Unit *u, JobType j) {
1256 assert(j >= 0 && j < _JOB_TYPE_MAX);
1260 case JOB_VERIFY_ACTIVE:
1266 case JOB_TRY_RESTART:
1267 return unit_can_start(u);
1270 return unit_can_reload(u);
1272 case JOB_RELOAD_OR_START:
1273 return unit_can_reload(u) && unit_can_start(u);
1276 assert_not_reached("Invalid job type");
1280 int unit_add_dependency(Unit *u, UnitDependency d, Unit *other, bool add_reference) {
1282 static const UnitDependency inverse_table[_UNIT_DEPENDENCY_MAX] = {
1283 [UNIT_REQUIRES] = UNIT_REQUIRED_BY,
1284 [UNIT_REQUIRES_OVERRIDABLE] = UNIT_REQUIRED_BY_OVERRIDABLE,
1285 [UNIT_WANTS] = UNIT_WANTED_BY,
1286 [UNIT_REQUISITE] = UNIT_REQUIRED_BY,
1287 [UNIT_REQUISITE_OVERRIDABLE] = UNIT_REQUIRED_BY_OVERRIDABLE,
1288 [UNIT_REQUIRED_BY] = _UNIT_DEPENDENCY_INVALID,
1289 [UNIT_REQUIRED_BY_OVERRIDABLE] = _UNIT_DEPENDENCY_INVALID,
1290 [UNIT_WANTED_BY] = _UNIT_DEPENDENCY_INVALID,
1291 [UNIT_CONFLICTS] = UNIT_CONFLICTS,
1292 [UNIT_BEFORE] = UNIT_AFTER,
1293 [UNIT_AFTER] = UNIT_BEFORE,
1294 [UNIT_REFERENCES] = UNIT_REFERENCED_BY,
1295 [UNIT_REFERENCED_BY] = UNIT_REFERENCES
1297 int r, q = 0, v = 0, w = 0;
1300 assert(d >= 0 && d < _UNIT_DEPENDENCY_MAX);
1301 assert(inverse_table[d] != _UNIT_DEPENDENCY_INVALID);
1304 /* We won't allow dependencies on ourselves. We will not
1305 * consider them an error however. */
1309 if (UNIT_VTABLE(u)->no_requires &&
1310 (d == UNIT_REQUIRES ||
1311 d == UNIT_REQUIRES_OVERRIDABLE ||
1312 d == UNIT_REQUISITE ||
1313 d == UNIT_REQUISITE_OVERRIDABLE)) {
1317 if ((r = set_ensure_allocated(&u->meta.dependencies[d], trivial_hash_func, trivial_compare_func)) < 0 ||
1318 (r = set_ensure_allocated(&other->meta.dependencies[inverse_table[d]], trivial_hash_func, trivial_compare_func)) < 0)
1322 if ((r = set_ensure_allocated(&u->meta.dependencies[UNIT_REFERENCES], trivial_hash_func, trivial_compare_func)) < 0 ||
1323 (r = set_ensure_allocated(&other->meta.dependencies[UNIT_REFERENCED_BY], trivial_hash_func, trivial_compare_func)) < 0)
1326 if ((q = set_put(u->meta.dependencies[d], other)) < 0)
1329 if ((v = set_put(other->meta.dependencies[inverse_table[d]], u)) < 0) {
1334 if (add_reference) {
1335 if ((w = set_put(u->meta.dependencies[UNIT_REFERENCES], other)) < 0) {
1340 if ((r = set_put(other->meta.dependencies[UNIT_REFERENCED_BY], u)) < 0)
1344 unit_add_to_dbus_queue(u);
1349 set_remove(u->meta.dependencies[d], other);
1352 set_remove(other->meta.dependencies[inverse_table[d]], u);
1355 set_remove(u->meta.dependencies[UNIT_REFERENCES], other);
1360 int unit_add_two_dependencies(Unit *u, UnitDependency d, UnitDependency e, Unit *other, bool add_reference) {
1365 if ((r = unit_add_dependency(u, d, other, add_reference)) < 0)
1368 if ((r = unit_add_dependency(u, e, other, add_reference)) < 0)
1374 static const char *resolve_template(Unit *u, const char *name, const char*path, char **p) {
1378 assert(name || path);
1381 name = file_name_from_path(path);
1383 if (!unit_name_is_template(name)) {
1388 if (u->meta.instance)
1389 s = unit_name_replace_instance(name, u->meta.instance);
1393 if (!(i = unit_name_to_prefix(u->meta.id)))
1396 s = unit_name_replace_instance(name, i);
1407 int unit_add_dependency_by_name(Unit *u, UnitDependency d, const char *name, const char *path, bool add_reference) {
1413 assert(name || path);
1415 if (!(name = resolve_template(u, name, path, &s)))
1418 if ((r = manager_load_unit(u->meta.manager, name, path, NULL, &other)) < 0)
1421 r = unit_add_dependency(u, d, other, add_reference);
1428 int unit_add_two_dependencies_by_name(Unit *u, UnitDependency d, UnitDependency e, const char *name, const char *path, bool add_reference) {
1434 assert(name || path);
1436 if (!(name = resolve_template(u, name, path, &s)))
1439 if ((r = manager_load_unit(u->meta.manager, name, path, NULL, &other)) < 0)
1442 r = unit_add_two_dependencies(u, d, e, other, add_reference);
1449 int unit_add_dependency_by_name_inverse(Unit *u, UnitDependency d, const char *name, const char *path, bool add_reference) {
1455 assert(name || path);
1457 if (!(name = resolve_template(u, name, path, &s)))
1460 if ((r = manager_load_unit(u->meta.manager, name, path, NULL, &other)) < 0)
1463 r = unit_add_dependency(other, d, u, add_reference);
1470 int unit_add_two_dependencies_by_name_inverse(Unit *u, UnitDependency d, UnitDependency e, const char *name, const char *path, bool add_reference) {
1476 assert(name || path);
1478 if (!(name = resolve_template(u, name, path, &s)))
1481 if ((r = manager_load_unit(u->meta.manager, name, path, NULL, &other)) < 0)
1484 if ((r = unit_add_two_dependencies(other, d, e, u, add_reference)) < 0)
1492 int set_unit_path(const char *p) {
1496 /* This is mostly for debug purposes */
1498 if (path_is_absolute(p)) {
1499 if (!(c = strdup(p)))
1502 if (!(cwd = get_current_dir_name()))
1505 r = asprintf(&c, "%s/%s", cwd, p);
1512 if (setenv("SYSTEMD_UNIT_PATH", c, 0) < 0) {
1521 char *unit_dbus_path(Unit *u) {
1526 if (!(e = bus_path_escape(u->meta.id)))
1529 p = strappend("/org/freedesktop/systemd1/unit/", e);
1535 int unit_add_cgroup(Unit *u, CGroupBonding *b) {
1545 if (!(b->controller = strdup(SYSTEMD_CGROUP_CONTROLLER)))
1548 /* Ensure this hasn't been added yet */
1551 l = hashmap_get(u->meta.manager->cgroup_bondings, b->path);
1552 LIST_PREPEND(CGroupBonding, by_path, l, b);
1554 if ((r = hashmap_replace(u->meta.manager->cgroup_bondings, b->path, l)) < 0) {
1555 LIST_REMOVE(CGroupBonding, by_path, l, b);
1559 LIST_PREPEND(CGroupBonding, by_unit, u->meta.cgroup_bondings, b);
1565 static char *default_cgroup_path(Unit *u) {
1571 if (u->meta.instance) {
1574 if (!(t = unit_name_template(u->meta.id)))
1577 r = asprintf(&p, "%s/%s/%s", u->meta.manager->cgroup_hierarchy, t, u->meta.instance);
1580 r = asprintf(&p, "%s/%s", u->meta.manager->cgroup_hierarchy, u->meta.id);
1582 return r < 0 ? NULL : p;
1585 int unit_add_cgroup_from_text(Unit *u, const char *name) {
1586 char *controller = NULL, *path = NULL;
1587 CGroupBonding *b = NULL;
1593 if ((r = cg_split_spec(name, &controller, &path)) < 0)
1597 path = default_cgroup_path(u);
1600 controller = strdup(SYSTEMD_CGROUP_CONTROLLER);
1602 if (!path || !controller) {
1609 if (cgroup_bonding_find_list(u->meta.cgroup_bondings, controller)) {
1614 if (!(b = new0(CGroupBonding, 1))) {
1619 b->controller = controller;
1622 b->clean_up = false;
1624 if ((r = unit_add_cgroup(u, b)) < 0)
1637 int unit_add_default_cgroup(Unit *u) {
1643 /* Adds in the default cgroup data, if it wasn't specified yet */
1645 if (unit_get_default_cgroup(u))
1648 if (!(b = new0(CGroupBonding, 1)))
1651 if (!(b->path = default_cgroup_path(u)))
1657 if ((r = unit_add_cgroup(u, b)) < 0)
1664 free(b->controller);
1670 CGroupBonding* unit_get_default_cgroup(Unit *u) {
1673 return cgroup_bonding_find_list(u->meta.cgroup_bondings, SYSTEMD_CGROUP_CONTROLLER);
1676 int unit_load_related_unit(Unit *u, const char *type, Unit **_found) {
1684 if (!(t = unit_name_change_suffix(u->meta.id, type)))
1687 assert(!unit_has_name(u, t));
1689 r = manager_load_unit(u->meta.manager, t, NULL, NULL, _found);
1692 assert(r < 0 || *_found != u);
1697 int unit_get_related_unit(Unit *u, const char *type, Unit **_found) {
1705 if (!(t = unit_name_change_suffix(u->meta.id, type)))
1708 assert(!unit_has_name(u, t));
1710 found = manager_get_unit(u->meta.manager, t);
1720 static char *specifier_prefix_and_instance(char specifier, void *data, void *userdata) {
1724 return unit_name_to_prefix_and_instance(u->meta.id);
1727 static char *specifier_prefix(char specifier, void *data, void *userdata) {
1731 return unit_name_to_prefix(u->meta.id);
1734 static char *specifier_prefix_unescaped(char specifier, void *data, void *userdata) {
1740 if (!(p = unit_name_to_prefix(u->meta.id)))
1743 r = unit_name_unescape(p);
1749 static char *specifier_instance_unescaped(char specifier, void *data, void *userdata) {
1753 if (u->meta.instance)
1754 return unit_name_unescape(u->meta.instance);
1759 char *unit_name_printf(Unit *u, const char* format) {
1762 * This will use the passed string as format string and
1763 * replace the following specifiers:
1765 * %n: the full id of the unit (foo@bar.waldo)
1766 * %N: the id of the unit without the suffix (foo@bar)
1767 * %p: the prefix (foo)
1768 * %i: the instance (bar)
1771 const Specifier table[] = {
1772 { 'n', specifier_string, u->meta.id },
1773 { 'N', specifier_prefix_and_instance, NULL },
1774 { 'p', specifier_prefix, NULL },
1775 { 'i', specifier_string, u->meta.instance },
1782 return specifier_printf(format, table, u);
1785 char *unit_full_printf(Unit *u, const char *format) {
1787 /* This is similar to unit_name_printf() but also supports
1790 const Specifier table[] = {
1791 { 'n', specifier_string, u->meta.id },
1792 { 'N', specifier_prefix_and_instance, NULL },
1793 { 'p', specifier_prefix, NULL },
1794 { 'P', specifier_prefix_unescaped, NULL },
1795 { 'i', specifier_string, u->meta.instance },
1796 { 'I', specifier_instance_unescaped, NULL },
1803 return specifier_printf(format, table, u);
1806 char **unit_full_printf_strv(Unit *u, char **l) {
1810 /* Applies unit_full_printf to every entry in l */
1815 if (!(r = new(char*, n+1)))
1818 for (i = l, j = r; *i; i++, j++)
1819 if (!(*j = unit_full_printf(u, *i)))
1835 int unit_watch_bus_name(Unit *u, const char *name) {
1839 /* Watch a specific name on the bus. We only support one unit
1840 * watching each name for now. */
1842 return hashmap_put(u->meta.manager->watch_bus, name, u);
1845 void unit_unwatch_bus_name(Unit *u, const char *name) {
1849 hashmap_remove_value(u->meta.manager->watch_bus, name, u);
1852 bool unit_can_serialize(Unit *u) {
1855 return UNIT_VTABLE(u)->serialize && UNIT_VTABLE(u)->deserialize_item;
1858 int unit_serialize(Unit *u, FILE *f, FDSet *fds) {
1865 if (!unit_can_serialize(u))
1868 if ((r = UNIT_VTABLE(u)->serialize(u, f, fds)) < 0)
1872 unit_serialize_item(u, f, "job", job_type_to_string(u->meta.job->type));
1879 void unit_serialize_item_format(Unit *u, FILE *f, const char *key, const char *format, ...) {
1890 va_start(ap, format);
1891 vfprintf(f, format, ap);
1897 void unit_serialize_item(Unit *u, FILE *f, const char *key, const char *value) {
1903 fprintf(f, "%s=%s\n", key, value);
1906 int unit_deserialize(Unit *u, FILE *f, FDSet *fds) {
1913 if (!unit_can_serialize(u))
1917 char line[1024], *l, *v;
1920 if (!fgets(line, sizeof(line), f)) {
1932 k = strcspn(l, "=");
1940 if (streq(l, "job")) {
1943 if ((type = job_type_from_string(v)) < 0)
1944 log_debug("Failed to parse job type value %s", v);
1946 u->meta.deserialized_job = type;
1951 if ((r = UNIT_VTABLE(u)->deserialize_item(u, l, v, fds)) < 0)
1956 int unit_add_node_link(Unit *u, const char *what, bool wants) {
1966 /* Adds in links to the device node that this unit is based on */
1968 if (!is_device_path(what))
1971 if (!(e = unit_name_build_escape(what+1, NULL, ".device")))
1974 r = manager_load_unit(u->meta.manager, e, NULL, NULL, &device);
1980 if ((r = unit_add_two_dependencies(u, UNIT_AFTER, UNIT_REQUIRES, device, true)) < 0)
1984 if ((r = unit_add_dependency(device, UNIT_WANTS, u, false)) < 0)
1990 int unit_coldplug(Unit *u) {
1995 if (UNIT_VTABLE(u)->coldplug)
1996 if ((r = UNIT_VTABLE(u)->coldplug(u)) < 0)
1999 if (u->meta.deserialized_job >= 0) {
2000 if ((r = manager_add_job(u->meta.manager, u->meta.deserialized_job, u, JOB_FAIL, false, NULL, NULL)) < 0)
2003 u->meta.deserialized_job = _JOB_TYPE_INVALID;
2009 void unit_status_printf(Unit *u, const char *format, ...) {
2015 if (!UNIT_VTABLE(u)->show_status)
2018 if (u->meta.manager->running_as != MANAGER_SYSTEM)
2021 if (!u->meta.manager->show_status)
2024 if (!manager_is_booting_or_shutting_down(u->meta.manager))
2027 va_start(ap, format);
2028 status_vprintf(format, ap);
2032 static const char* const unit_type_table[_UNIT_TYPE_MAX] = {
2033 [UNIT_SERVICE] = "service",
2034 [UNIT_TIMER] = "timer",
2035 [UNIT_SOCKET] = "socket",
2036 [UNIT_TARGET] = "target",
2037 [UNIT_DEVICE] = "device",
2038 [UNIT_MOUNT] = "mount",
2039 [UNIT_AUTOMOUNT] = "automount",
2040 [UNIT_SNAPSHOT] = "snapshot",
2041 [UNIT_SWAP] = "swap"
2044 DEFINE_STRING_TABLE_LOOKUP(unit_type, UnitType);
2046 static const char* const unit_load_state_table[_UNIT_LOAD_STATE_MAX] = {
2047 [UNIT_STUB] = "stub",
2048 [UNIT_LOADED] = "loaded",
2049 [UNIT_FAILED] = "failed",
2050 [UNIT_MERGED] = "merged"
2053 DEFINE_STRING_TABLE_LOOKUP(unit_load_state, UnitLoadState);
2055 static const char* const unit_active_state_table[_UNIT_ACTIVE_STATE_MAX] = {
2056 [UNIT_ACTIVE] = "active",
2057 [UNIT_RELOADING] = "reloading",
2058 [UNIT_INACTIVE] = "inactive",
2059 [UNIT_MAINTENANCE] = "maintenance",
2060 [UNIT_ACTIVATING] = "activating",
2061 [UNIT_DEACTIVATING] = "deactivating"
2064 DEFINE_STRING_TABLE_LOOKUP(unit_active_state, UnitActiveState);
2066 static const char* const unit_dependency_table[_UNIT_DEPENDENCY_MAX] = {
2067 [UNIT_REQUIRES] = "Requires",
2068 [UNIT_REQUIRES_OVERRIDABLE] = "RequiresOverridable",
2069 [UNIT_WANTS] = "Wants",
2070 [UNIT_REQUISITE] = "Requisite",
2071 [UNIT_REQUISITE_OVERRIDABLE] = "RequisiteOverridable",
2072 [UNIT_REQUIRED_BY] = "RequiredBy",
2073 [UNIT_REQUIRED_BY_OVERRIDABLE] = "RequiredByOverridable",
2074 [UNIT_WANTED_BY] = "WantedBy",
2075 [UNIT_CONFLICTS] = "Conflicts",
2076 [UNIT_BEFORE] = "Before",
2077 [UNIT_AFTER] = "After",
2078 [UNIT_REFERENCES] = "References",
2079 [UNIT_REFERENCED_BY] = "ReferencedBy"
2082 DEFINE_STRING_TABLE_LOOKUP(unit_dependency, UnitDependency);
2084 static const char* const kill_mode_table[_KILL_MODE_MAX] = {
2085 [KILL_CONTROL_GROUP] = "control-group",
2086 [KILL_PROCESS_GROUP] = "process-group",
2087 [KILL_PROCESS] = "process",
2088 [KILL_NONE] = "none"
2091 DEFINE_STRING_TABLE_LOOKUP(kill_mode, KillMode);