summaryrefslogtreecommitdiffstats
path: root/src/core/target.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2017-10-25 20:46:01 +0200
committerLennart Poettering <lennart@poettering.net>2017-11-10 19:45:29 +0100
commiteef85c4a3f8054d29383a176f6cebd1ef3a15b9a (patch)
tree318abdf98fbca40552731ef82ad2bb6d9949e1d5 /src/core/target.c
parentgpt-auto-generator: make sure "r" is always set (diff)
downloadsystemd-eef85c4a3f8054d29383a176f6cebd1ef3a15b9a.tar.xz
systemd-eef85c4a3f8054d29383a176f6cebd1ef3a15b9a.zip
core: track why unit dependencies came to be
This replaces the dependencies Set* objects by Hashmap* objects, where the key is the depending Unit, and the value is a bitmask encoding why the specific dependency was created. The bitmask contains a number of different, defined bits, that indicate why dependencies exist, for example whether they are created due to explicitly configured deps in files, by udev rules or implicitly. Note that memory usage is not increased by this change, even though we store more information, as we manage to encode the bit mask inside the value pointer each Hashmap entry contains. Why this all? When we know how a dependency came to be, we can update dependencies correctly when a configuration source changes but others are left unaltered. Specifically: 1. We can fix UDEV_WANTS dependency generation: so far we kept adding dependencies configured that way, but if a device lost such a dependency we couldn't them again as there was no scheme for removing of dependencies in place. 2. We can implement "pin-pointed" reload of unit files. If we know what dependencies were created as result of configuration in a unit file, then we know what to flush out when we want to reload it. 3. It's useful for debugging: "systemd-analyze dump" now shows this information, helping substantially with understanding how systemd's dependency tree came to be the way it came to be.
Diffstat (limited to 'src/core/target.c')
-rw-r--r--src/core/target.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/core/target.c b/src/core/target.c
index 2a58dd394d..7083813459 100644
--- a/src/core/target.c
+++ b/src/core/target.c
@@ -56,8 +56,6 @@ static int target_add_default_dependencies(Target *t) {
UNIT_PART_OF
};
- Iterator i;
- Unit *other;
int r;
unsigned k;
@@ -66,23 +64,26 @@ static int target_add_default_dependencies(Target *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. */
+ /* 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++)
- SET_FOREACH(other, UNIT(t)->dependencies[deps[k]], i) {
+ 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;
}
+ }
if (unit_has_name(UNIT(t), SPECIAL_SHUTDOWN_TARGET))
return 0;
/* Make sure targets are unloaded on shutdown */
- return unit_add_two_dependencies_by_name(UNIT(t), UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_SHUTDOWN_TARGET, NULL, true);
+ return unit_add_two_dependencies_by_name(UNIT(t), UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_SHUTDOWN_TARGET, NULL, true, UNIT_DEPENDENCY_DEFAULT);
}
static int target_load(Unit *u) {