mirror of
https://github.com/systemd/systemd.git
synced 2025-08-30 05:49:54 +03:00
unit: don't accidently create ordering links to targets when default deps are off for either target and unit
This commit is contained in:
25
src/target.c
25
src/target.c
@ -53,9 +53,19 @@ static void target_set_state(Target *t, TargetState state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int target_add_default_dependencies(Target *t) {
|
static int target_add_default_dependencies(Target *t) {
|
||||||
|
static const UnitDependency deps[] = {
|
||||||
|
UNIT_REQUIRES,
|
||||||
|
UNIT_REQUIRES_OVERRIDABLE,
|
||||||
|
UNIT_REQUISITE,
|
||||||
|
UNIT_REQUISITE_OVERRIDABLE,
|
||||||
|
UNIT_WANTS,
|
||||||
|
UNIT_BIND_TO
|
||||||
|
};
|
||||||
|
|
||||||
Iterator i;
|
Iterator i;
|
||||||
Unit *other;
|
Unit *other;
|
||||||
int r;
|
int r;
|
||||||
|
unsigned k;
|
||||||
|
|
||||||
assert(t);
|
assert(t);
|
||||||
|
|
||||||
@ -64,17 +74,10 @@ static int target_add_default_dependencies(Target *t) {
|
|||||||
* ordering manually we won't add anything in here to make
|
* ordering manually we won't add anything in here to make
|
||||||
* sure we don't create a loop. */
|
* sure we don't create a loop. */
|
||||||
|
|
||||||
SET_FOREACH(other, t->meta.dependencies[UNIT_REQUIRES], i)
|
for (k = 0; k < ELEMENTSOF(deps); k++)
|
||||||
if ((r = unit_add_default_target_dependency(other, UNIT(t))) < 0)
|
SET_FOREACH(other, t->meta.dependencies[deps[k]], i)
|
||||||
return r;
|
if ((r = unit_add_default_target_dependency(other, UNIT(t))) < 0)
|
||||||
|
return r;
|
||||||
SET_FOREACH(other, t->meta.dependencies[UNIT_REQUIRES_OVERRIDABLE], i)
|
|
||||||
if ((r = unit_add_default_target_dependency(other, UNIT(t))) < 0)
|
|
||||||
return r;
|
|
||||||
|
|
||||||
SET_FOREACH(other, t->meta.dependencies[UNIT_WANTS], i)
|
|
||||||
if ((r = unit_add_default_target_dependency(other, UNIT(t))) < 0)
|
|
||||||
return r;
|
|
||||||
|
|
||||||
/* Make sure targets are unloaded on shutdown */
|
/* Make sure targets are unloaded on shutdown */
|
||||||
return unit_add_dependency_by_name(UNIT(t), UNIT_CONFLICTS, SPECIAL_SHUTDOWN_TARGET, NULL, true);
|
return unit_add_dependency_by_name(UNIT(t), UNIT_CONFLICTS, SPECIAL_SHUTDOWN_TARGET, NULL, true);
|
||||||
|
33
src/unit.c
33
src/unit.c
@ -742,6 +742,12 @@ int unit_add_default_target_dependency(Unit *u, Unit *target) {
|
|||||||
target->meta.load_state != UNIT_LOADED)
|
target->meta.load_state != UNIT_LOADED)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
/* If either side wants no automatic dependencies, then let's
|
||||||
|
* skip this */
|
||||||
|
if (!u->meta.default_dependencies ||
|
||||||
|
target->meta.default_dependencies)
|
||||||
|
return 0;
|
||||||
|
|
||||||
/* Don't create loops */
|
/* Don't create loops */
|
||||||
if (set_get(target->meta.dependencies[UNIT_BEFORE], u))
|
if (set_get(target->meta.dependencies[UNIT_BEFORE], u))
|
||||||
return 0;
|
return 0;
|
||||||
@ -750,27 +756,24 @@ int unit_add_default_target_dependency(Unit *u, Unit *target) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int unit_add_default_dependencies(Unit *u) {
|
static int unit_add_default_dependencies(Unit *u) {
|
||||||
|
static const UnitDependency deps[] = {
|
||||||
|
UNIT_REQUIRED_BY,
|
||||||
|
UNIT_REQUIRED_BY_OVERRIDABLE,
|
||||||
|
UNIT_WANTED_BY,
|
||||||
|
UNIT_BOUND_BY
|
||||||
|
};
|
||||||
|
|
||||||
Unit *target;
|
Unit *target;
|
||||||
Iterator i;
|
Iterator i;
|
||||||
int r;
|
int r;
|
||||||
|
unsigned k;
|
||||||
|
|
||||||
assert(u);
|
assert(u);
|
||||||
|
|
||||||
SET_FOREACH(target, u->meta.dependencies[UNIT_REQUIRED_BY], i)
|
for (k = 0; k < ELEMENTSOF(deps); k++)
|
||||||
if ((r = unit_add_default_target_dependency(u, target)) < 0)
|
SET_FOREACH(target, u->meta.dependencies[deps[k]], i)
|
||||||
return r;
|
if ((r = unit_add_default_target_dependency(u, target)) < 0)
|
||||||
|
return r;
|
||||||
SET_FOREACH(target, u->meta.dependencies[UNIT_REQUIRED_BY_OVERRIDABLE], i)
|
|
||||||
if ((r = unit_add_default_target_dependency(u, target)) < 0)
|
|
||||||
return r;
|
|
||||||
|
|
||||||
SET_FOREACH(target, u->meta.dependencies[UNIT_WANTED_BY], i)
|
|
||||||
if ((r = unit_add_default_target_dependency(u, target)) < 0)
|
|
||||||
return r;
|
|
||||||
|
|
||||||
SET_FOREACH(target, u->meta.dependencies[UNIT_BOUND_BY], i)
|
|
||||||
if ((r = unit_add_default_target_dependency(u, target)) < 0)
|
|
||||||
return r;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user