-/* SPDX-License-Identifier: LGPL-2.1+ */
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include "dbus-target.h"
#include "dbus-unit.h"
target_state_to_string(old_state),
target_state_to_string(state));
- unit_notify(UNIT(t), state_translation_table[old_state], state_translation_table[state], 0);
+ unit_notify(UNIT(t), state_translation_table[old_state], state_translation_table[state], /* reload_success = */ true);
}
static int target_add_default_dependencies(Target *t) {
-
- static const UnitDependency deps[] = {
- UNIT_REQUIRES,
- UNIT_REQUISITE,
- UNIT_WANTS,
- UNIT_BINDS_TO,
- UNIT_PART_OF
- };
-
- int r;
- unsigned k;
+ _cleanup_free_ Unit **others = NULL;
+ int r, n_others;
assert(t);
if (!UNIT(t)->default_dependencies)
return 0;
- /* Imply ordering for requirement dependencies on target units. Note that when the user created a contradicting
- * ordering manually we won't add anything in here to make sure we don't create a loop. */
-
- for (k = 0; k < ELEMENTSOF(deps); k++) {
- Unit *other;
- Iterator i;
- void *v;
-
- HASHMAP_FOREACH_KEY(v, other, UNIT(t)->dependencies[deps[k]], i) {
- r = unit_add_default_target_dependency(other, UNIT(t));
- if (r < 0)
- return r;
- }
+ /* Imply ordering for requirement dependencies on target units. Note that when the user created a
+ * contradicting ordering manually we won't add anything in here to make sure we don't create a
+ * loop.
+ *
+ * Note that quite likely iterating through these dependencies will add new dependencies, which
+ * conflicts with the hashmap-based iteration logic. Hence, instead of iterating through the
+ * dependencies and acting on them as we go, first take an "atomic snapshot" of sorts and iterate
+ * through that. */
+
+ n_others = unit_get_dependency_array(UNIT(t), UNIT_ATOM_ADD_DEFAULT_TARGET_DEPENDENCY_QUEUE, &others);
+ if (n_others < 0)
+ return n_others;
+
+ for (int i = 0; i < n_others; i++) {
+ r = unit_add_default_target_dependency(others[i], UNIT(t));
+ if (r < 0)
+ return r;
}
if (unit_has_name(UNIT(t), SPECIAL_SHUTDOWN_TARGET))
assert(t);
- r = unit_load_fragment_and_dropin(u);
+ r = unit_load_fragment_and_dropin(u, true);
if (r < 0)
return r;
- /* This is a new unit? Then let's add in some extras */
- if (u->load_state == UNIT_LOADED) {
- r = target_add_default_dependencies(t);
- if (r < 0)
- return r;
- }
+ if (u->load_state != UNIT_LOADED)
+ return 0;
- return 0;
+ /* This is a new unit? Then let's add in some extras */
+ return target_add_default_dependencies(t);
}
static int target_coldplug(Unit *u) {
static int target_deserialize_item(Unit *u, const char *key, const char *value, FDSet *fds) {
Target *s = TARGET(u);
+ assert(s);
assert(u);
assert(key);
assert(value);
return 0;
}
-_pure_ static UnitActiveState target_active_state(Unit *u) {
+static UnitActiveState target_active_state(Unit *u) {
assert(u);
return state_translation_table[TARGET(u)->state];
}
-_pure_ static const char *target_sub_state_to_string(Unit *u) {
+static const char *target_sub_state_to_string(Unit *u) {
assert(u);
return target_state_to_string(TARGET(u)->state);
"Target\0"
"Install\0",
+ .can_fail = true,
+
.load = target_load,
.coldplug = target_coldplug,
.active_state = target_active_state,
.sub_state_to_string = target_sub_state_to_string,
- .bus_vtable = bus_target_vtable,
-
.status_message_formats = {
.finished_start_job = {
[JOB_DONE] = "Reached target %s.",