pid1: include the source unit in UnitRef
No functional change. The source unit manages the reference. It allocates the UnitRef structure and registers it in the target unit, and then the reference must be destroyed before the source unit is destroyed. Thus, is should be OK to include the pointer to the source unit, it should be live as long as the reference exists. v2: - rename refs to refs_by_target
This commit is contained in:
+18
-18
@@ -362,7 +362,7 @@ bool unit_may_gc(Unit *u) {
|
||||
if (u->perpetual)
|
||||
return false;
|
||||
|
||||
if (u->refs)
|
||||
if (u->refs_by_target)
|
||||
return false;
|
||||
|
||||
if (sd_bus_track_count(u->bus_track) > 0)
|
||||
@@ -662,9 +662,8 @@ void unit_free(Unit *u) {
|
||||
free(u->reboot_arg);
|
||||
|
||||
unit_ref_unset(&u->slice);
|
||||
|
||||
while (u->refs)
|
||||
unit_ref_unset(u->refs);
|
||||
while (u->refs_by_target)
|
||||
unit_ref_unset(u->refs_by_target);
|
||||
|
||||
safe_close(u->ip_accounting_ingress_map_fd);
|
||||
safe_close(u->ip_accounting_egress_map_fd);
|
||||
@@ -896,8 +895,8 @@ int unit_merge(Unit *u, Unit *other) {
|
||||
return r;
|
||||
|
||||
/* Redirect all references */
|
||||
while (other->refs)
|
||||
unit_ref_set(other->refs, u);
|
||||
while (other->refs_by_target)
|
||||
unit_ref_set(other->refs_by_target, other->refs_by_target->source, u);
|
||||
|
||||
/* Merge dependencies */
|
||||
for (d = 0; d < _UNIT_DEPENDENCY_MAX; d++)
|
||||
@@ -2976,8 +2975,7 @@ int unit_set_slice(Unit *u, Unit *slice) {
|
||||
if (UNIT_ISSET(u->slice) && u->cgroup_realized)
|
||||
return -EBUSY;
|
||||
|
||||
unit_ref_unset(&u->slice);
|
||||
unit_ref_set(&u->slice, slice);
|
||||
unit_ref_set(&u->slice, u, slice);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -3986,30 +3984,32 @@ int unit_get_unit_file_preset(Unit *u) {
|
||||
return u->unit_file_preset;
|
||||
}
|
||||
|
||||
Unit* unit_ref_set(UnitRef *ref, Unit *u) {
|
||||
Unit* unit_ref_set(UnitRef *ref, Unit *source, Unit *target) {
|
||||
assert(ref);
|
||||
assert(u);
|
||||
assert(source);
|
||||
assert(target);
|
||||
|
||||
if (ref->unit)
|
||||
if (ref->target)
|
||||
unit_ref_unset(ref);
|
||||
|
||||
ref->unit = u;
|
||||
LIST_PREPEND(refs, u->refs, ref);
|
||||
return u;
|
||||
ref->source = source;
|
||||
ref->target = target;
|
||||
LIST_PREPEND(refs_by_target, target->refs_by_target, ref);
|
||||
return target;
|
||||
}
|
||||
|
||||
void unit_ref_unset(UnitRef *ref) {
|
||||
assert(ref);
|
||||
|
||||
if (!ref->unit)
|
||||
if (!ref->target)
|
||||
return;
|
||||
|
||||
/* We are about to drop a reference to the unit, make sure the garbage collection has a look at it as it might
|
||||
* be unreferenced now. */
|
||||
unit_add_to_gc_queue(ref->unit);
|
||||
unit_add_to_gc_queue(ref->target);
|
||||
|
||||
LIST_REMOVE(refs, ref->unit->refs, ref);
|
||||
ref->unit = NULL;
|
||||
LIST_REMOVE(refs_by_target, ref->target->refs_by_target, ref);
|
||||
ref->source = ref->target = NULL;
|
||||
}
|
||||
|
||||
static int user_from_unit_name(Unit *u, char **ret) {
|
||||
|
||||
Reference in New Issue
Block a user