core: do not add dependencies to self

Adds a pair of files which cause a segfault (also with
systemd-analyze verify).

https://bugzilla.redhat.com/show_bug.cgi?id=1124843
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2014-08-07 20:42:58 -04:00
parent 17a6dfa3be
commit e66047ff62
5 changed files with 21 additions and 5 deletions

View File

@ -181,7 +181,7 @@ int unit_load_dropin(Unit *u) {
}
u->dropin_paths = unit_find_dropin_paths(u);
if (! u->dropin_paths)
if (!u->dropin_paths)
return 0;
STRV_FOREACH(f, u->dropin_paths) {

View File

@ -597,14 +597,22 @@ static void merge_dependencies(Unit *u, Unit *other, UnitDependency d) {
UnitDependency k;
for (k = 0; k < _UNIT_DEPENDENCY_MAX; k++) {
r = set_remove_and_put(back->dependencies[k], other, u);
if (r == -EEXIST)
/* Do not add dependencies between u and itself */
if (back == u) {
set_remove(back->dependencies[k], other);
else
assert(r >= 0 || r == -ENOENT);
} else {
r = set_remove_and_put(back->dependencies[k], other, u);
if (r == -EEXIST)
set_remove(back->dependencies[k], other);
else
assert(r >= 0 || r == -ENOENT);
}
}
}
/* Also do not move dependencies on u to itself */
set_remove(other->dependencies[d], u);
complete_move(&u->dependencies[d], &other->dependencies[d]);
set_free(other->dependencies[d]);

2
test/loopy.service Normal file
View File

@ -0,0 +1,2 @@
[Service]
ExecStart=/bin/true

View File

@ -0,0 +1,5 @@
[Unit]
BindsTo=loopy2.service
[Install]
Also=loopy2.service

1
test/loopy2.service Symbolic link
View File

@ -0,0 +1 @@
loopy.service