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 const UnitVTable
* const unit_vtable
[_UNIT_TYPE_MAX
] = {
43 [UNIT_SERVICE
] = &service_vtable
,
44 [UNIT_TIMER
] = &timer_vtable
,
45 [UNIT_SOCKET
] = &socket_vtable
,
46 [UNIT_TARGET
] = &target_vtable
,
47 [UNIT_DEVICE
] = &device_vtable
,
48 [UNIT_MOUNT
] = &mount_vtable
,
49 [UNIT_AUTOMOUNT
] = &automount_vtable
,
50 [UNIT_SNAPSHOT
] = &snapshot_vtable
53 Unit
*unit_new(Manager
*m
) {
58 if (!(u
= new0(Unit
, 1)))
61 if (!(u
->meta
.names
= set_new(string_hash_func
, string_compare_func
))) {
67 u
->meta
.type
= _UNIT_TYPE_INVALID
;
72 bool unit_has_name(Unit
*u
, const char *name
) {
76 return !!set_get(u
->meta
.names
, (char*) name
);
79 int unit_add_name(Unit
*u
, const char *text
) {
81 char *s
= NULL
, *i
= NULL
;
87 if (unit_name_is_template(text
)) {
88 if (!u
->meta
.instance
)
91 s
= unit_name_replace_instance(text
, u
->meta
.instance
);
98 if (!unit_name_is_valid(s
)) {
103 assert_se((t
= unit_name_to_type(s
)) >= 0);
105 if (u
->meta
.type
!= _UNIT_TYPE_INVALID
&& t
!= u
->meta
.type
) {
110 if ((r
= unit_name_to_instance(s
, &i
)) < 0)
113 if (i
&& unit_vtable
[t
]->no_instances
)
116 if (u
->meta
.type
!= _UNIT_TYPE_INVALID
&& !streq_ptr(u
->meta
.instance
, i
)) {
121 if (unit_vtable
[t
]->no_alias
&&
122 !set_isempty(u
->meta
.names
) &&
123 !set_get(u
->meta
.names
, s
)) {
128 if (hashmap_size(u
->meta
.manager
->units
) >= MANAGER_MAX_NAMES
) {
133 if ((r
= set_put(u
->meta
.names
, s
)) < 0) {
139 if ((r
= hashmap_put(u
->meta
.manager
->units
, s
, u
)) < 0) {
140 set_remove(u
->meta
.names
, s
);
144 if (u
->meta
.type
== _UNIT_TYPE_INVALID
) {
148 u
->meta
.instance
= i
;
150 LIST_PREPEND(Meta
, units_per_type
, u
->meta
.manager
->units_per_type
[t
], &u
->meta
);
152 if (UNIT_VTABLE(u
)->init
)
153 UNIT_VTABLE(u
)->init(u
);
157 unit_add_to_dbus_queue(u
);
167 int unit_choose_id(Unit
*u
, const char *name
) {
173 if (unit_name_is_template(name
)) {
175 if (!u
->meta
.instance
)
178 if (!(t
= unit_name_replace_instance(name
, u
->meta
.instance
)))
184 /* Selects one of the names of this unit as the id */
185 s
= set_get(u
->meta
.names
, (char*) name
);
192 unit_add_to_dbus_queue(u
);
197 int unit_set_description(Unit
*u
, const char *description
) {
202 if (!(s
= strdup(description
)))
205 free(u
->meta
.description
);
206 u
->meta
.description
= s
;
208 unit_add_to_dbus_queue(u
);
212 bool unit_check_gc(Unit
*u
) {
215 if (UNIT_VTABLE(u
)->no_gc
)
221 if (unit_active_state(u
) != UNIT_INACTIVE
)
224 if (UNIT_VTABLE(u
)->check_gc
)
225 if (UNIT_VTABLE(u
)->check_gc(u
))
231 void unit_add_to_load_queue(Unit
*u
) {
233 assert(u
->meta
.type
!= _UNIT_TYPE_INVALID
);
235 if (u
->meta
.load_state
!= UNIT_STUB
|| u
->meta
.in_load_queue
)
238 LIST_PREPEND(Meta
, load_queue
, u
->meta
.manager
->load_queue
, &u
->meta
);
239 u
->meta
.in_load_queue
= true;
242 void unit_add_to_cleanup_queue(Unit
*u
) {
245 if (u
->meta
.in_cleanup_queue
)
248 LIST_PREPEND(Meta
, cleanup_queue
, u
->meta
.manager
->cleanup_queue
, &u
->meta
);
249 u
->meta
.in_cleanup_queue
= true;
252 void unit_add_to_gc_queue(Unit
*u
) {
255 if (u
->meta
.in_gc_queue
|| u
->meta
.in_cleanup_queue
)
258 if (unit_check_gc(u
))
261 LIST_PREPEND(Meta
, gc_queue
, u
->meta
.manager
->gc_queue
, &u
->meta
);
262 u
->meta
.in_gc_queue
= true;
264 u
->meta
.manager
->n_in_gc_queue
++;
266 if (u
->meta
.manager
->gc_queue_timestamp
<= 0)
267 u
->meta
.manager
->gc_queue_timestamp
= now(CLOCK_MONOTONIC
);
270 void unit_add_to_dbus_queue(Unit
*u
) {
272 assert(u
->meta
.type
!= _UNIT_TYPE_INVALID
);
274 if (u
->meta
.load_state
== UNIT_STUB
|| u
->meta
.in_dbus_queue
|| set_isempty(u
->meta
.manager
->subscribed
))
277 LIST_PREPEND(Meta
, dbus_queue
, u
->meta
.manager
->dbus_unit_queue
, &u
->meta
);
278 u
->meta
.in_dbus_queue
= true;
281 static void bidi_set_free(Unit
*u
, Set
*s
) {
287 /* Frees the set and makes sure we are dropped from the
288 * inverse pointers */
290 SET_FOREACH(other
, s
, i
) {
293 for (d
= 0; d
< _UNIT_DEPENDENCY_MAX
; d
++)
294 set_remove(other
->meta
.dependencies
[d
], u
);
296 unit_add_to_gc_queue(other
);
302 void unit_free(Unit
*u
) {
309 bus_unit_send_removed_signal(u
);
311 /* Detach from next 'bigger' objects */
312 SET_FOREACH(t
, u
->meta
.names
, i
)
313 hashmap_remove_value(u
->meta
.manager
->units
, t
, u
);
315 if (u
->meta
.type
!= _UNIT_TYPE_INVALID
)
316 LIST_REMOVE(Meta
, units_per_type
, u
->meta
.manager
->units_per_type
[u
->meta
.type
], &u
->meta
);
318 if (u
->meta
.in_load_queue
)
319 LIST_REMOVE(Meta
, load_queue
, u
->meta
.manager
->load_queue
, &u
->meta
);
321 if (u
->meta
.in_dbus_queue
)
322 LIST_REMOVE(Meta
, dbus_queue
, u
->meta
.manager
->dbus_unit_queue
, &u
->meta
);
324 if (u
->meta
.in_cleanup_queue
)
325 LIST_REMOVE(Meta
, cleanup_queue
, u
->meta
.manager
->cleanup_queue
, &u
->meta
);
327 if (u
->meta
.in_gc_queue
) {
328 LIST_REMOVE(Meta
, gc_queue
, u
->meta
.manager
->gc_queue
, &u
->meta
);
329 u
->meta
.manager
->n_in_gc_queue
--;
332 /* Free data and next 'smaller' objects */
334 job_free(u
->meta
.job
);
336 if (u
->meta
.load_state
!= UNIT_STUB
)
337 if (UNIT_VTABLE(u
)->done
)
338 UNIT_VTABLE(u
)->done(u
);
340 cgroup_bonding_free_list(u
->meta
.cgroup_bondings
);
342 for (d
= 0; d
< _UNIT_DEPENDENCY_MAX
; d
++)
343 bidi_set_free(u
, u
->meta
.dependencies
[d
]);
345 free(u
->meta
.description
);
346 free(u
->meta
.fragment_path
);
348 while ((t
= set_steal_first(u
->meta
.names
)))
350 set_free(u
->meta
.names
);
352 free(u
->meta
.instance
);
357 UnitActiveState
unit_active_state(Unit
*u
) {
360 if (u
->meta
.load_state
!= UNIT_LOADED
)
361 return UNIT_INACTIVE
;
363 return UNIT_VTABLE(u
)->active_state(u
);
366 const char* unit_sub_state_to_string(Unit
*u
) {
369 return UNIT_VTABLE(u
)->sub_state_to_string(u
);
372 static void complete_move(Set
**s
, Set
**other
) {
380 set_move(*s
, *other
);
387 static void merge_names(Unit
*u
, Unit
*other
) {
394 complete_move(&u
->meta
.names
, &other
->meta
.names
);
396 while ((t
= set_steal_first(other
->meta
.names
)))
399 set_free(other
->meta
.names
);
400 other
->meta
.names
= NULL
;
401 other
->meta
.id
= NULL
;
403 SET_FOREACH(t
, u
->meta
.names
, i
)
404 assert_se(hashmap_replace(u
->meta
.manager
->units
, t
, u
) == 0);
407 static void merge_dependencies(Unit
*u
, Unit
*other
, UnitDependency d
) {
414 assert(d
< _UNIT_DEPENDENCY_MAX
);
416 SET_FOREACH(back
, other
->meta
.dependencies
[d
], i
) {
419 for (k
= 0; k
< _UNIT_DEPENDENCY_MAX
; k
++)
420 if ((r
= set_remove_and_put(back
->meta
.dependencies
[k
], other
, u
)) < 0) {
423 set_remove(back
->meta
.dependencies
[k
], other
);
425 assert(r
== -ENOENT
);
429 complete_move(&u
->meta
.dependencies
[d
], &other
->meta
.dependencies
[d
]);
431 set_free(other
->meta
.dependencies
[d
]);
432 other
->meta
.dependencies
[d
] = NULL
;
435 int unit_merge(Unit
*u
, Unit
*other
) {
440 assert(u
->meta
.manager
== other
->meta
.manager
);
441 assert(u
->meta
.type
!= _UNIT_TYPE_INVALID
);
443 other
= unit_follow_merge(other
);
448 if (u
->meta
.type
!= other
->meta
.type
)
451 if (!streq_ptr(u
->meta
.instance
, other
->meta
.instance
))
454 if (other
->meta
.load_state
!= UNIT_STUB
&&
455 other
->meta
.load_state
!= UNIT_FAILED
)
461 if (unit_active_state(other
) != UNIT_INACTIVE
)
465 merge_names(u
, other
);
467 /* Merge dependencies */
468 for (d
= 0; d
< _UNIT_DEPENDENCY_MAX
; d
++)
469 merge_dependencies(u
, other
, d
);
471 other
->meta
.load_state
= UNIT_MERGED
;
472 other
->meta
.merged_into
= u
;
474 /* If there is still some data attached to the other node, we
475 * don't need it anymore, and can free it. */
476 if (other
->meta
.load_state
!= UNIT_STUB
)
477 if (UNIT_VTABLE(other
)->done
)
478 UNIT_VTABLE(other
)->done(other
);
480 unit_add_to_dbus_queue(u
);
481 unit_add_to_cleanup_queue(other
);
486 int unit_merge_by_name(Unit
*u
, const char *name
) {
494 if (unit_name_is_template(name
)) {
495 if (!u
->meta
.instance
)
498 if (!(s
= unit_name_replace_instance(name
, u
->meta
.instance
)))
504 if (!(other
= manager_get_unit(u
->meta
.manager
, name
)))
505 r
= unit_add_name(u
, name
);
507 r
= unit_merge(u
, other
);
513 Unit
* unit_follow_merge(Unit
*u
) {
516 while (u
->meta
.load_state
== UNIT_MERGED
)
517 assert_se(u
= u
->meta
.merged_into
);
522 int unit_add_exec_dependencies(Unit
*u
, ExecContext
*c
) {
528 if (c
->std_output
!= EXEC_OUTPUT_KERNEL
&& c
->std_output
!= EXEC_OUTPUT_SYSLOG
)
531 /* If syslog or kernel logging is requested, make sure our own
532 * logging daemon is run first. */
534 if ((r
= unit_add_dependency_by_name(u
, UNIT_AFTER
, SPECIAL_LOGGER_SOCKET
, NULL
, true)) < 0)
537 if (u
->meta
.manager
->running_as
!= MANAGER_SESSION
)
538 if ((r
= unit_add_dependency_by_name(u
, UNIT_REQUIRES
, SPECIAL_LOGGER_SOCKET
, NULL
, true)) < 0)
544 const char *unit_description(Unit
*u
) {
547 if (u
->meta
.description
)
548 return u
->meta
.description
;
553 void unit_dump(Unit
*u
, FILE *f
, const char *prefix
) {
560 char timestamp1
[FORMAT_TIMESTAMP_MAX
], timestamp2
[FORMAT_TIMESTAMP_MAX
];
563 assert(u
->meta
.type
>= 0);
567 p2
= strappend(prefix
, "\t");
568 prefix2
= p2
? p2
: prefix
;
572 "%s\tDescription: %s\n"
574 "%s\tUnit Load State: %s\n"
575 "%s\tUnit Active State: %s\n"
576 "%s\tActive Enter Timestamp: %s\n"
577 "%s\tActive Exit Timestamp: %s\n"
578 "%s\tGC Check Good: %s\n",
580 prefix
, unit_description(u
),
581 prefix
, strna(u
->meta
.instance
),
582 prefix
, unit_load_state_to_string(u
->meta
.load_state
),
583 prefix
, unit_active_state_to_string(unit_active_state(u
)),
584 prefix
, strna(format_timestamp(timestamp1
, sizeof(timestamp1
), u
->meta
.active_enter_timestamp
)),
585 prefix
, strna(format_timestamp(timestamp2
, sizeof(timestamp2
), u
->meta
.active_exit_timestamp
)),
586 prefix
, yes_no(unit_check_gc(u
)));
588 SET_FOREACH(t
, u
->meta
.names
, i
)
589 fprintf(f
, "%s\tName: %s\n", prefix
, t
);
591 if (u
->meta
.fragment_path
)
592 fprintf(f
, "%s\tFragment Path: %s\n", prefix
, u
->meta
.fragment_path
);
594 for (d
= 0; d
< _UNIT_DEPENDENCY_MAX
; d
++) {
597 SET_FOREACH(other
, u
->meta
.dependencies
[d
], i
)
598 fprintf(f
, "%s\t%s: %s\n", prefix
, unit_dependency_to_string(d
), other
->meta
.id
);
601 if (u
->meta
.load_state
== UNIT_LOADED
) {
603 "%s\tRecursive Stop: %s\n"
604 "%s\tStop When Unneeded: %s\n",
605 prefix
, yes_no(u
->meta
.recursive_stop
),
606 prefix
, yes_no(u
->meta
.stop_when_unneeded
));
608 LIST_FOREACH(by_unit
, b
, u
->meta
.cgroup_bondings
)
609 fprintf(f
, "%s\tControlGroup: %s:%s\n",
610 prefix
, b
->controller
, b
->path
);
612 if (UNIT_VTABLE(u
)->dump
)
613 UNIT_VTABLE(u
)->dump(u
, f
, prefix2
);
615 } else if (u
->meta
.load_state
== UNIT_MERGED
)
617 "%s\tMerged into: %s\n",
618 prefix
, u
->meta
.merged_into
->meta
.id
);
621 job_dump(u
->meta
.job
, f
, prefix2
);
626 /* Common implementation for multiple backends */
627 int unit_load_fragment_and_dropin(Unit
*u
) {
632 /* Load a .service file */
633 if ((r
= unit_load_fragment(u
)) < 0)
636 if (u
->meta
.load_state
== UNIT_STUB
)
639 /* Load drop-in directory data */
640 if ((r
= unit_load_dropin(unit_follow_merge(u
))) < 0)
646 /* Common implementation for multiple backends */
647 int unit_load_fragment_and_dropin_optional(Unit
*u
) {
652 /* Same as unit_load_fragment_and_dropin(), but whether
653 * something can be loaded or not doesn't matter. */
655 /* Load a .service file */
656 if ((r
= unit_load_fragment(u
)) < 0)
659 if (u
->meta
.load_state
== UNIT_STUB
)
660 u
->meta
.load_state
= UNIT_LOADED
;
662 /* Load drop-in directory data */
663 if ((r
= unit_load_dropin(unit_follow_merge(u
))) < 0)
669 /* Common implementation for multiple backends */
670 int unit_load_nop(Unit
*u
) {
673 if (u
->meta
.load_state
== UNIT_STUB
)
674 u
->meta
.load_state
= UNIT_LOADED
;
679 int unit_load(Unit
*u
) {
684 if (u
->meta
.in_load_queue
) {
685 LIST_REMOVE(Meta
, load_queue
, u
->meta
.manager
->load_queue
, &u
->meta
);
686 u
->meta
.in_load_queue
= false;
689 if (u
->meta
.type
== _UNIT_TYPE_INVALID
)
692 if (u
->meta
.load_state
!= UNIT_STUB
)
695 if (UNIT_VTABLE(u
)->load
)
696 if ((r
= UNIT_VTABLE(u
)->load(u
)) < 0)
699 if (u
->meta
.load_state
== UNIT_STUB
) {
704 assert((u
->meta
.load_state
!= UNIT_MERGED
) == !u
->meta
.merged_into
);
706 unit_add_to_dbus_queue(unit_follow_merge(u
));
707 unit_add_to_gc_queue(u
);
712 u
->meta
.load_state
= UNIT_FAILED
;
713 unit_add_to_dbus_queue(u
);
715 log_error("Failed to load configuration for %s: %s", u
->meta
.id
, strerror(-r
));
721 * -EBADR: This unit type does not support starting.
722 * -EALREADY: Unit is already started.
723 * -EAGAIN: An operation is already in progress. Retry later.
725 int unit_start(Unit
*u
) {
726 UnitActiveState state
;
730 /* If this is already (being) started, then this will
731 * succeed. Note that this will even succeed if this unit is
732 * not startable by the user. This is relied on to detect when
733 * we need to wait for units and when waiting is finished. */
734 state
= unit_active_state(u
);
735 if (UNIT_IS_ACTIVE_OR_RELOADING(state
))
738 /* If it is stopped, but we cannot start it, then fail */
739 if (!UNIT_VTABLE(u
)->start
)
742 /* We don't suppress calls to ->start() here when we are
743 * already starting, to allow this request to be used as a
744 * "hurry up" call, for example when the unit is in some "auto
745 * restart" state where it waits for a holdoff timer to elapse
746 * before it will start again. */
748 unit_add_to_dbus_queue(u
);
749 return UNIT_VTABLE(u
)->start(u
);
752 bool unit_can_start(Unit
*u
) {
755 return !!UNIT_VTABLE(u
)->start
;
759 * -EBADR: This unit type does not support stopping.
760 * -EALREADY: Unit is already stopped.
761 * -EAGAIN: An operation is already in progress. Retry later.
763 int unit_stop(Unit
*u
) {
764 UnitActiveState state
;
768 state
= unit_active_state(u
);
769 if (state
== UNIT_INACTIVE
)
772 if (!UNIT_VTABLE(u
)->stop
)
775 unit_add_to_dbus_queue(u
);
776 return UNIT_VTABLE(u
)->stop(u
);
780 * -EBADR: This unit type does not support reloading.
781 * -ENOEXEC: Unit is not started.
782 * -EAGAIN: An operation is already in progress. Retry later.
784 int unit_reload(Unit
*u
) {
785 UnitActiveState state
;
789 if (!unit_can_reload(u
))
792 state
= unit_active_state(u
);
793 if (unit_active_state(u
) == UNIT_ACTIVE_RELOADING
)
796 if (unit_active_state(u
) != UNIT_ACTIVE
)
799 unit_add_to_dbus_queue(u
);
800 return UNIT_VTABLE(u
)->reload(u
);
803 bool unit_can_reload(Unit
*u
) {
806 if (!UNIT_VTABLE(u
)->reload
)
809 if (!UNIT_VTABLE(u
)->can_reload
)
812 return UNIT_VTABLE(u
)->can_reload(u
);
815 static void unit_check_uneeded(Unit
*u
) {
821 /* If this service shall be shut down when unneeded then do
824 if (!u
->meta
.stop_when_unneeded
)
827 if (!UNIT_IS_ACTIVE_OR_ACTIVATING(unit_active_state(u
)))
830 SET_FOREACH(other
, u
->meta
.dependencies
[UNIT_REQUIRED_BY
], i
)
831 if (!UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(other
)))
834 SET_FOREACH(other
, u
->meta
.dependencies
[UNIT_REQUIRED_BY_OVERRIDABLE
], i
)
835 if (!UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(other
)))
838 SET_FOREACH(other
, u
->meta
.dependencies
[UNIT_WANTED_BY
], i
)
839 if (!UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(other
)))
842 log_debug("Service %s is not needed anymore. Stopping.", u
->meta
.id
);
844 /* Ok, nobody needs us anymore. Sniff. Then let's commit suicide */
845 manager_add_job(u
->meta
.manager
, JOB_STOP
, u
, JOB_FAIL
, true, NULL
);
848 static void retroactively_start_dependencies(Unit
*u
) {
853 assert(UNIT_IS_ACTIVE_OR_ACTIVATING(unit_active_state(u
)));
855 SET_FOREACH(other
, u
->meta
.dependencies
[UNIT_REQUIRES
], i
)
856 if (!UNIT_IS_ACTIVE_OR_ACTIVATING(unit_active_state(other
)))
857 manager_add_job(u
->meta
.manager
, JOB_START
, other
, JOB_REPLACE
, true, NULL
);
859 SET_FOREACH(other
, u
->meta
.dependencies
[UNIT_REQUIRES_OVERRIDABLE
], i
)
860 if (!UNIT_IS_ACTIVE_OR_ACTIVATING(unit_active_state(other
)))
861 manager_add_job(u
->meta
.manager
, JOB_START
, other
, JOB_FAIL
, false, NULL
);
863 SET_FOREACH(other
, u
->meta
.dependencies
[UNIT_REQUISITE
], i
)
864 if (!UNIT_IS_ACTIVE_OR_ACTIVATING(unit_active_state(other
)))
865 manager_add_job(u
->meta
.manager
, JOB_START
, other
, JOB_REPLACE
, true, NULL
);
867 SET_FOREACH(other
, u
->meta
.dependencies
[UNIT_WANTS
], i
)
868 if (!UNIT_IS_ACTIVE_OR_ACTIVATING(unit_active_state(other
)))
869 manager_add_job(u
->meta
.manager
, JOB_START
, other
, JOB_FAIL
, false, NULL
);
871 SET_FOREACH(other
, u
->meta
.dependencies
[UNIT_CONFLICTS
], i
)
872 if (!UNIT_IS_ACTIVE_OR_ACTIVATING(unit_active_state(other
)))
873 manager_add_job(u
->meta
.manager
, JOB_STOP
, other
, JOB_REPLACE
, true, NULL
);
876 static void retroactively_stop_dependencies(Unit
*u
) {
881 assert(UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(u
)));
883 if (u
->meta
.recursive_stop
) {
884 /* Pull down units need us recursively if enabled */
885 SET_FOREACH(other
, u
->meta
.dependencies
[UNIT_REQUIRED_BY
], i
)
886 if (!UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(other
)))
887 manager_add_job(u
->meta
.manager
, JOB_STOP
, other
, JOB_REPLACE
, true, NULL
);
890 /* Garbage collect services that might not be needed anymore, if enabled */
891 SET_FOREACH(other
, u
->meta
.dependencies
[UNIT_REQUIRES
], i
)
892 if (!UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(other
)))
893 unit_check_uneeded(other
);
894 SET_FOREACH(other
, u
->meta
.dependencies
[UNIT_REQUIRES_OVERRIDABLE
], i
)
895 if (!UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(other
)))
896 unit_check_uneeded(other
);
897 SET_FOREACH(other
, u
->meta
.dependencies
[UNIT_WANTS
], i
)
898 if (!UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(other
)))
899 unit_check_uneeded(other
);
900 SET_FOREACH(other
, u
->meta
.dependencies
[UNIT_REQUISITE
], i
)
901 if (!UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(other
)))
902 unit_check_uneeded(other
);
903 SET_FOREACH(other
, u
->meta
.dependencies
[UNIT_REQUISITE_OVERRIDABLE
], i
)
904 if (!UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(other
)))
905 unit_check_uneeded(other
);
908 void unit_notify(Unit
*u
, UnitActiveState os
, UnitActiveState ns
) {
909 bool unexpected
= false;
912 assert(os
< _UNIT_ACTIVE_STATE_MAX
);
913 assert(ns
< _UNIT_ACTIVE_STATE_MAX
);
915 /* Note that this is called for all low-level state changes,
916 * even if they might map to the same high-level
917 * UnitActiveState! That means that ns == os is OK an expected
918 * behaviour here. For example: if a mount point is remounted
919 * this function will be called too and the utmp code below
922 if (!UNIT_IS_ACTIVE_OR_RELOADING(os
) && UNIT_IS_ACTIVE_OR_RELOADING(ns
))
923 u
->meta
.active_enter_timestamp
= now(CLOCK_REALTIME
);
924 else if (UNIT_IS_ACTIVE_OR_RELOADING(os
) && !UNIT_IS_ACTIVE_OR_RELOADING(ns
))
925 u
->meta
.active_exit_timestamp
= now(CLOCK_REALTIME
);
929 if (u
->meta
.job
->state
== JOB_WAITING
)
931 /* So we reached a different state for this
932 * job. Let's see if we can run it now if it
933 * failed previously due to EAGAIN. */
934 job_add_to_run_queue(u
->meta
.job
);
937 assert(u
->meta
.job
->state
== JOB_RUNNING
);
939 /* Let's check whether this state change
940 * constitutes a finished job, or maybe
941 * cotradicts a running job and hence needs to
942 * invalidate jobs. */
944 switch (u
->meta
.job
->type
) {
947 case JOB_VERIFY_ACTIVE
:
949 if (UNIT_IS_ACTIVE_OR_RELOADING(ns
))
950 job_finish_and_invalidate(u
->meta
.job
, true);
951 else if (ns
!= UNIT_ACTIVATING
) {
953 job_finish_and_invalidate(u
->meta
.job
, false);
959 case JOB_RELOAD_OR_START
:
961 if (ns
== UNIT_ACTIVE
)
962 job_finish_and_invalidate(u
->meta
.job
, true);
963 else if (ns
!= UNIT_ACTIVATING
&& ns
!= UNIT_ACTIVE_RELOADING
) {
965 job_finish_and_invalidate(u
->meta
.job
, false);
972 case JOB_TRY_RESTART
:
974 if (ns
== UNIT_INACTIVE
)
975 job_finish_and_invalidate(u
->meta
.job
, true);
976 else if (ns
!= UNIT_DEACTIVATING
) {
978 job_finish_and_invalidate(u
->meta
.job
, false);
984 assert_not_reached("Job type unknown");
989 /* If this state change happened without being requested by a
990 * job, then let's retroactively start or stop dependencies */
993 if (UNIT_IS_INACTIVE_OR_DEACTIVATING(os
) && UNIT_IS_ACTIVE_OR_ACTIVATING(ns
))
994 retroactively_start_dependencies(u
);
995 else if (UNIT_IS_ACTIVE_OR_ACTIVATING(os
) && UNIT_IS_INACTIVE_OR_DEACTIVATING(ns
))
996 retroactively_stop_dependencies(u
);
999 /* Some names are special */
1000 if (UNIT_IS_ACTIVE_OR_RELOADING(ns
)) {
1001 if (unit_has_name(u
, SPECIAL_DBUS_SERVICE
)) {
1002 /* The bus just might have become available,
1003 * hence try to connect to it, if we aren't
1005 bus_init_system(u
->meta
.manager
);
1006 bus_init_api(u
->meta
.manager
);
1009 if (unit_has_name(u
, SPECIAL_SYSLOG_SERVICE
))
1010 /* The syslog daemon just might have become
1011 * available, hence try to connect to it, if
1012 * we aren't yet connected. */
1015 if (u
->meta
.type
== UNIT_MOUNT
)
1016 /* Another directory became available, let's
1017 * check if that is enough to write our utmp
1019 manager_write_utmp_reboot(u
->meta
.manager
);
1021 if (u
->meta
.type
== UNIT_TARGET
)
1022 /* A target got activated, maybe this is a runlevel? */
1023 manager_write_utmp_runlevel(u
->meta
.manager
, u
);
1025 } else if (!UNIT_IS_ACTIVE_OR_RELOADING(ns
)) {
1027 if (unit_has_name(u
, SPECIAL_SYSLOG_SERVICE
))
1028 /* The syslog daemon might just have
1029 * terminated, hence try to disconnect from
1033 /* We don't care about D-Bus here, since we'll get an
1034 * asynchronous notification for it anyway. */
1037 /* Maybe we finished startup and are now ready for being
1038 * stopped because unneeded? */
1039 unit_check_uneeded(u
);
1041 unit_add_to_dbus_queue(u
);
1042 unit_add_to_gc_queue(u
);
1045 int unit_watch_fd(Unit
*u
, int fd
, uint32_t events
, Watch
*w
) {
1046 struct epoll_event ev
;
1051 assert(w
->type
== WATCH_INVALID
|| (w
->type
== WATCH_FD
&& w
->fd
== fd
&& w
->data
.unit
== u
));
1057 if (epoll_ctl(u
->meta
.manager
->epoll_fd
,
1058 w
->type
== WATCH_INVALID
? EPOLL_CTL_ADD
: EPOLL_CTL_MOD
,
1070 void unit_unwatch_fd(Unit
*u
, Watch
*w
) {
1074 if (w
->type
== WATCH_INVALID
)
1077 assert(w
->type
== WATCH_FD
);
1078 assert(w
->data
.unit
== u
);
1079 assert_se(epoll_ctl(u
->meta
.manager
->epoll_fd
, EPOLL_CTL_DEL
, w
->fd
, NULL
) >= 0);
1082 w
->type
= WATCH_INVALID
;
1083 w
->data
.unit
= NULL
;
1086 int unit_watch_pid(Unit
*u
, pid_t pid
) {
1090 /* Watch a specific PID. We only support one unit watching
1091 * each PID for now. */
1093 return hashmap_put(u
->meta
.manager
->watch_pids
, UINT32_TO_PTR(pid
), u
);
1096 void unit_unwatch_pid(Unit
*u
, pid_t pid
) {
1100 hashmap_remove_value(u
->meta
.manager
->watch_pids
, UINT32_TO_PTR(pid
), u
);
1103 int unit_watch_timer(Unit
*u
, usec_t delay
, Watch
*w
) {
1104 struct itimerspec its
;
1110 assert(w
->type
== WATCH_INVALID
|| (w
->type
== WATCH_TIMER
&& w
->data
.unit
== u
));
1112 /* This will try to reuse the old timer if there is one */
1114 if (w
->type
== WATCH_TIMER
) {
1119 if ((fd
= timerfd_create(CLOCK_MONOTONIC
, TFD_NONBLOCK
|TFD_CLOEXEC
)) < 0)
1126 /* Set absolute time in the past, but not 0, since we
1127 * don't want to disarm the timer */
1128 its
.it_value
.tv_sec
= 0;
1129 its
.it_value
.tv_nsec
= 1;
1131 flags
= TFD_TIMER_ABSTIME
;
1133 timespec_store(&its
.it_value
, delay
);
1137 /* This will also flush the elapse counter */
1138 if (timerfd_settime(fd
, flags
, &its
, NULL
) < 0)
1141 if (w
->type
== WATCH_INVALID
) {
1142 struct epoll_event ev
;
1146 ev
.events
= EPOLLIN
;
1148 if (epoll_ctl(u
->meta
.manager
->epoll_fd
, EPOLL_CTL_ADD
, fd
, &ev
) < 0)
1153 w
->type
= WATCH_TIMER
;
1160 close_nointr_nofail(fd
);
1165 void unit_unwatch_timer(Unit
*u
, Watch
*w
) {
1169 if (w
->type
== WATCH_INVALID
)
1172 assert(w
->type
== WATCH_TIMER
&& w
->data
.unit
== u
);
1174 assert_se(epoll_ctl(u
->meta
.manager
->epoll_fd
, EPOLL_CTL_DEL
, w
->fd
, NULL
) >= 0);
1175 close_nointr_nofail(w
->fd
);
1178 w
->type
= WATCH_INVALID
;
1179 w
->data
.unit
= NULL
;
1182 bool unit_job_is_applicable(Unit
*u
, JobType j
) {
1184 assert(j
>= 0 && j
< _JOB_TYPE_MAX
);
1188 case JOB_VERIFY_ACTIVE
:
1194 case JOB_TRY_RESTART
:
1195 return unit_can_start(u
);
1198 return unit_can_reload(u
);
1200 case JOB_RELOAD_OR_START
:
1201 return unit_can_reload(u
) && unit_can_start(u
);
1204 assert_not_reached("Invalid job type");
1208 int unit_add_dependency(Unit
*u
, UnitDependency d
, Unit
*other
, bool add_reference
) {
1210 static const UnitDependency inverse_table
[_UNIT_DEPENDENCY_MAX
] = {
1211 [UNIT_REQUIRES
] = UNIT_REQUIRED_BY
,
1212 [UNIT_REQUIRES_OVERRIDABLE
] = UNIT_REQUIRED_BY_OVERRIDABLE
,
1213 [UNIT_WANTS
] = UNIT_WANTED_BY
,
1214 [UNIT_REQUISITE
] = UNIT_REQUIRED_BY
,
1215 [UNIT_REQUISITE_OVERRIDABLE
] = UNIT_REQUIRED_BY_OVERRIDABLE
,
1216 [UNIT_REQUIRED_BY
] = _UNIT_DEPENDENCY_INVALID
,
1217 [UNIT_REQUIRED_BY_OVERRIDABLE
] = _UNIT_DEPENDENCY_INVALID
,
1218 [UNIT_WANTED_BY
] = _UNIT_DEPENDENCY_INVALID
,
1219 [UNIT_CONFLICTS
] = UNIT_CONFLICTS
,
1220 [UNIT_BEFORE
] = UNIT_AFTER
,
1221 [UNIT_AFTER
] = UNIT_BEFORE
,
1222 [UNIT_REFERENCES
] = UNIT_REFERENCED_BY
,
1223 [UNIT_REFERENCED_BY
] = UNIT_REFERENCES
1225 int r
, q
= 0, v
= 0, w
= 0;
1228 assert(d
>= 0 && d
< _UNIT_DEPENDENCY_MAX
);
1229 assert(inverse_table
[d
] != _UNIT_DEPENDENCY_INVALID
);
1232 /* We won't allow dependencies on ourselves. We will not
1233 * consider them an error however. */
1237 if (UNIT_VTABLE(u
)->no_requires
&&
1238 (d
== UNIT_REQUIRES
||
1239 d
== UNIT_REQUIRES_OVERRIDABLE
||
1240 d
== UNIT_REQUISITE
||
1241 d
== UNIT_REQUISITE_OVERRIDABLE
)) {
1245 if ((r
= set_ensure_allocated(&u
->meta
.dependencies
[d
], trivial_hash_func
, trivial_compare_func
)) < 0 ||
1246 (r
= set_ensure_allocated(&other
->meta
.dependencies
[inverse_table
[d
]], trivial_hash_func
, trivial_compare_func
)) < 0)
1250 if ((r
= set_ensure_allocated(&u
->meta
.dependencies
[UNIT_REFERENCES
], trivial_hash_func
, trivial_compare_func
)) < 0 ||
1251 (r
= set_ensure_allocated(&other
->meta
.dependencies
[UNIT_REFERENCED_BY
], trivial_hash_func
, trivial_compare_func
)) < 0)
1254 if ((q
= set_put(u
->meta
.dependencies
[d
], other
)) < 0)
1257 if ((v
= set_put(other
->meta
.dependencies
[inverse_table
[d
]], u
)) < 0) {
1262 if (add_reference
) {
1263 if ((w
= set_put(u
->meta
.dependencies
[UNIT_REFERENCES
], other
)) < 0) {
1268 if ((r
= set_put(other
->meta
.dependencies
[UNIT_REFERENCED_BY
], u
)) < 0)
1272 unit_add_to_dbus_queue(u
);
1277 set_remove(u
->meta
.dependencies
[d
], other
);
1280 set_remove(other
->meta
.dependencies
[inverse_table
[d
]], u
);
1283 set_remove(u
->meta
.dependencies
[UNIT_REFERENCES
], other
);
1288 static const char *resolve_template(Unit
*u
, const char *name
, const char*path
, char **p
) {
1292 assert(name
|| path
);
1295 name
= file_name_from_path(path
);
1297 if (!unit_name_is_template(name
)) {
1302 if (u
->meta
.instance
)
1303 s
= unit_name_replace_instance(name
, u
->meta
.instance
);
1307 if (!(i
= unit_name_to_prefix(u
->meta
.id
)))
1310 s
= unit_name_replace_instance(name
, i
);
1321 int unit_add_dependency_by_name(Unit
*u
, UnitDependency d
, const char *name
, const char *path
, bool add_reference
) {
1327 assert(name
|| path
);
1329 if (!(name
= resolve_template(u
, name
, path
, &s
)))
1332 if ((r
= manager_load_unit(u
->meta
.manager
, name
, path
, &other
)) < 0)
1335 r
= unit_add_dependency(u
, d
, other
, add_reference
);
1342 int unit_add_dependency_by_name_inverse(Unit
*u
, UnitDependency d
, const char *name
, const char *path
, bool add_reference
) {
1348 assert(name
|| path
);
1350 if (!(name
= resolve_template(u
, name
, path
, &s
)))
1353 if ((r
= manager_load_unit(u
->meta
.manager
, name
, path
, &other
)) < 0)
1356 r
= unit_add_dependency(other
, d
, u
, add_reference
);
1363 int set_unit_path(const char *p
) {
1367 /* This is mostly for debug purposes */
1369 if (path_is_absolute(p
)) {
1370 if (!(c
= strdup(p
)))
1373 if (!(cwd
= get_current_dir_name()))
1376 r
= asprintf(&c
, "%s/%s", cwd
, p
);
1383 if (setenv("SYSTEMD_UNIT_PATH", c
, 0) < 0) {
1392 char *unit_dbus_path(Unit
*u
) {
1397 if (!(e
= bus_path_escape(u
->meta
.id
)))
1400 if (asprintf(&p
, "/org/freedesktop/systemd1/unit/%s", e
) < 0) {
1409 int unit_add_cgroup(Unit
*u
, CGroupBonding
*b
) {
1417 /* Ensure this hasn't been added yet */
1420 l
= hashmap_get(u
->meta
.manager
->cgroup_bondings
, b
->path
);
1421 LIST_PREPEND(CGroupBonding
, by_path
, l
, b
);
1423 if ((r
= hashmap_replace(u
->meta
.manager
->cgroup_bondings
, b
->path
, l
)) < 0) {
1424 LIST_REMOVE(CGroupBonding
, by_path
, l
, b
);
1428 LIST_PREPEND(CGroupBonding
, by_unit
, u
->meta
.cgroup_bondings
, b
);
1434 static char *default_cgroup_path(Unit
*u
) {
1440 if (u
->meta
.instance
) {
1443 if (!(t
= unit_name_template(u
->meta
.id
)))
1446 r
= asprintf(&p
, "%s/%s/%s", u
->meta
.manager
->cgroup_hierarchy
, t
, u
->meta
.instance
);
1449 r
= asprintf(&p
, "%s/%s", u
->meta
.manager
->cgroup_hierarchy
, u
->meta
.id
);
1451 return r
< 0 ? NULL
: p
;
1454 int unit_add_cgroup_from_text(Unit
*u
, const char *name
) {
1456 char *controller
= NULL
, *path
= NULL
;
1457 CGroupBonding
*b
= NULL
;
1463 /* Detect controller name */
1464 n
= strcspn(name
, ":");
1467 (name
[n
] == ':' && name
[n
+1] == 0)) {
1469 /* Only controller name, no path? */
1471 if (!(path
= default_cgroup_path(u
)))
1477 /* Controller name, and path. */
1480 if (!path_is_absolute(p
))
1483 if (!(path
= strdup(p
)))
1488 controller
= strndup(name
, n
);
1490 controller
= strdup(u
->meta
.manager
->cgroup_controller
);
1497 if (cgroup_bonding_find_list(u
->meta
.cgroup_bondings
, controller
)) {
1502 if (!(b
= new0(CGroupBonding
, 1))) {
1507 b
->controller
= controller
;
1510 b
->clean_up
= false;
1512 if ((r
= unit_add_cgroup(u
, b
)) < 0)
1525 int unit_add_default_cgroup(Unit
*u
) {
1531 /* Adds in the default cgroup data, if it wasn't specified yet */
1533 if (unit_get_default_cgroup(u
))
1536 if (!(b
= new0(CGroupBonding
, 1)))
1539 if (!(b
->controller
= strdup(u
->meta
.manager
->cgroup_controller
)))
1542 if (!(b
->path
= default_cgroup_path(u
)))
1548 if ((r
= unit_add_cgroup(u
, b
)) < 0)
1555 free(b
->controller
);
1561 CGroupBonding
* unit_get_default_cgroup(Unit
*u
) {
1564 return cgroup_bonding_find_list(u
->meta
.cgroup_bondings
, u
->meta
.manager
->cgroup_controller
);
1567 int unit_load_related_unit(Unit
*u
, const char *type
, Unit
**_found
) {
1575 if (!(t
= unit_name_change_suffix(u
->meta
.id
, type
)))
1578 assert(!unit_has_name(u
, t
));
1580 r
= manager_load_unit(u
->meta
.manager
, t
, NULL
, _found
);
1583 assert(r
< 0 || *_found
!= u
);
1588 int unit_get_related_unit(Unit
*u
, const char *type
, Unit
**_found
) {
1596 if (!(t
= unit_name_change_suffix(u
->meta
.id
, type
)))
1599 assert(!unit_has_name(u
, t
));
1601 found
= manager_get_unit(u
->meta
.manager
, t
);
1611 static char *specifier_prefix_and_instance(char specifier
, void *data
, void *userdata
) {
1615 return unit_name_to_prefix_and_instance(u
->meta
.id
);
1618 static char *specifier_prefix(char specifier
, void *data
, void *userdata
) {
1622 return unit_name_to_prefix(u
->meta
.id
);
1625 static char *specifier_prefix_unescaped(char specifier
, void *data
, void *userdata
) {
1631 if (!(p
= unit_name_to_prefix(u
->meta
.id
)))
1634 r
= unit_name_unescape(p
);
1640 static char *specifier_instance_unescaped(char specifier
, void *data
, void *userdata
) {
1644 if (u
->meta
.instance
)
1645 return unit_name_unescape(u
->meta
.instance
);
1650 char *unit_name_printf(Unit
*u
, const char* format
) {
1653 * This will use the passed string as format string and
1654 * replace the following specifiers:
1656 * %n: the full id of the unit (foo@bar.waldo)
1657 * %N: the id of the unit without the suffix (foo@bar)
1658 * %p: the prefix (foo)
1659 * %i: the instance (bar)
1662 const Specifier table
[] = {
1663 { 'n', specifier_string
, u
->meta
.id
},
1664 { 'N', specifier_prefix_and_instance
, NULL
},
1665 { 'p', specifier_prefix
, NULL
},
1666 { 'i', specifier_string
, u
->meta
.instance
},
1673 return specifier_printf(format
, table
, u
);
1676 char *unit_full_printf(Unit
*u
, const char *format
) {
1678 /* This is similar to unit_name_printf() but also supports
1681 const Specifier table
[] = {
1682 { 'n', specifier_string
, u
->meta
.id
},
1683 { 'N', specifier_prefix_and_instance
, NULL
},
1684 { 'p', specifier_prefix
, NULL
},
1685 { 'P', specifier_prefix_unescaped
, NULL
},
1686 { 'i', specifier_string
, u
->meta
.instance
},
1687 { 'I', specifier_instance_unescaped
, NULL
},
1694 return specifier_printf(format
, table
, u
);
1697 char **unit_full_printf_strv(Unit
*u
, char **l
) {
1701 /* Applies unit_full_printf to every entry in l */
1706 if (!(r
= new(char*, n
+1)))
1709 for (i
= l
, j
= r
; *i
; i
++, j
++)
1710 if (!(*j
= unit_full_printf(u
, *i
)))
1726 int unit_watch_bus_name(Unit
*u
, const char *name
) {
1730 /* Watch a specific name on the bus. We only support one unit
1731 * watching each name for now. */
1733 return hashmap_put(u
->meta
.manager
->watch_bus
, name
, u
);
1736 void unit_unwatch_bus_name(Unit
*u
, const char *name
) {
1740 hashmap_remove_value(u
->meta
.manager
->watch_bus
, name
, u
);
1743 bool unit_can_serialize(Unit
*u
) {
1746 return UNIT_VTABLE(u
)->serialize
&& UNIT_VTABLE(u
)->deserialize_item
;
1749 int unit_serialize(Unit
*u
, FILE *f
, FDSet
*fds
) {
1756 if (!unit_can_serialize(u
))
1759 if ((r
= UNIT_VTABLE(u
)->serialize(u
, f
, fds
)) < 0)
1767 void unit_serialize_item_format(Unit
*u
, FILE *f
, const char *key
, const char *format
, ...) {
1778 va_start(ap
, format
);
1779 vfprintf(f
, format
, ap
);
1785 void unit_serialize_item(Unit
*u
, FILE *f
, const char *key
, const char *value
) {
1791 fprintf(f
, "%s=%s\n", key
, value
);
1794 int unit_deserialize(Unit
*u
, FILE *f
, FDSet
*fds
) {
1801 if (!unit_can_serialize(u
))
1805 char line
[1024], *l
, *v
;
1808 if (!fgets(line
, sizeof(line
), f
)) {
1820 k
= strcspn(l
, "=");
1828 if ((r
= UNIT_VTABLE(u
)->deserialize_item(u
, l
, v
, fds
)) < 0)
1834 static const char* const unit_type_table
[_UNIT_TYPE_MAX
] = {
1835 [UNIT_SERVICE
] = "service",
1836 [UNIT_TIMER
] = "timer",
1837 [UNIT_SOCKET
] = "socket",
1838 [UNIT_TARGET
] = "target",
1839 [UNIT_DEVICE
] = "device",
1840 [UNIT_MOUNT
] = "mount",
1841 [UNIT_AUTOMOUNT
] = "automount",
1842 [UNIT_SNAPSHOT
] = "snapshot"
1845 DEFINE_STRING_TABLE_LOOKUP(unit_type
, UnitType
);
1847 static const char* const unit_load_state_table
[_UNIT_LOAD_STATE_MAX
] = {
1848 [UNIT_STUB
] = "stub",
1849 [UNIT_LOADED
] = "loaded",
1850 [UNIT_FAILED
] = "failed",
1851 [UNIT_MERGED
] = "merged"
1854 DEFINE_STRING_TABLE_LOOKUP(unit_load_state
, UnitLoadState
);
1856 static const char* const unit_active_state_table
[_UNIT_ACTIVE_STATE_MAX
] = {
1857 [UNIT_ACTIVE
] = "active",
1858 [UNIT_INACTIVE
] = "inactive",
1859 [UNIT_ACTIVATING
] = "activating",
1860 [UNIT_DEACTIVATING
] = "deactivating"
1863 DEFINE_STRING_TABLE_LOOKUP(unit_active_state
, UnitActiveState
);
1865 static const char* const unit_dependency_table
[_UNIT_DEPENDENCY_MAX
] = {
1866 [UNIT_REQUIRES
] = "Requires",
1867 [UNIT_REQUIRES_OVERRIDABLE
] = "RequiresOverridable",
1868 [UNIT_WANTS
] = "Wants",
1869 [UNIT_REQUISITE
] = "Requisite",
1870 [UNIT_REQUISITE_OVERRIDABLE
] = "RequisiteOverridable",
1871 [UNIT_REQUIRED_BY
] = "RequiredBy",
1872 [UNIT_REQUIRED_BY_OVERRIDABLE
] = "RequiredByOverridable",
1873 [UNIT_WANTED_BY
] = "WantedBy",
1874 [UNIT_CONFLICTS
] = "Conflicts",
1875 [UNIT_BEFORE
] = "Before",
1876 [UNIT_AFTER
] = "After",
1877 [UNIT_REFERENCES
] = "References",
1878 [UNIT_REFERENCED_BY
] = "ReferencedBy"
1881 DEFINE_STRING_TABLE_LOOKUP(unit_dependency
, UnitDependency
);
1883 static const char* const kill_mode_table
[_KILL_MODE_MAX
] = {
1884 [KILL_CONTROL_GROUP
] = "control-group",
1885 [KILL_PROCESS_GROUP
] = "process-group",
1886 [KILL_PROCESS
] = "process",
1887 [KILL_NONE
] = "none"
1890 DEFINE_STRING_TABLE_LOOKUP(kill_mode
, KillMode
);