summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFranck Bui <fbui@suse.com>2017-01-24 14:29:57 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2017-01-24 08:29:57 -0500
commit2d058a87ffb2d31a50422a8aebd119bbb4427244 (patch)
treead8a1da2ac1fa315dc78385773365668702ae191 /src
parenta341dfe563bf3be791107a0c98d47f74366c637d (diff)
core: don't load dropin data multiple times for the same unit (#5139)
When an alias is loaded, we resolve this alias to its final unit first to load the dropin data. However if the final unit was already loaded, there's no point in reloading the dropin data a second time. This patch optimizes this case. Also this allows the dropin loading code to assume that only units not yet loaded are passed down. This assumption is not yet used but might be in the future. [zj: invert the condition in the if]
Diffstat (limited to 'src')
-rw-r--r--src/core/unit.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/src/core/unit.c b/src/core/unit.c
index 409668f6d2..44f1d5e206 100644
--- a/src/core/unit.c
+++ b/src/core/unit.c
@@ -1083,6 +1083,7 @@ void unit_dump(Unit *u, FILE *f, const char *prefix) {
/* Common implementation for multiple backends */
int unit_load_fragment_and_dropin(Unit *u) {
+ Unit *t;
int r;
assert(u);
@@ -1095,16 +1096,18 @@ int unit_load_fragment_and_dropin(Unit *u) {
if (u->load_state == UNIT_STUB)
return -ENOENT;
- /* Load drop-in directory data */
- r = unit_load_dropin(unit_follow_merge(u));
- if (r < 0)
- return r;
+ /* If the unit is an alias and the final unit has already been
+ * loaded, there's no point in reloading the dropins one more time. */
+ t = unit_follow_merge(u);
+ if (t != u && t->load_state != UNIT_STUB)
+ return 0;
- return 0;
+ return unit_load_dropin(t);
}
/* Common implementation for multiple backends */
int unit_load_fragment_and_dropin_optional(Unit *u) {
+ Unit *t;
int r;
assert(u);
@@ -1120,12 +1123,13 @@ int unit_load_fragment_and_dropin_optional(Unit *u) {
if (u->load_state == UNIT_STUB)
u->load_state = UNIT_LOADED;
- /* Load drop-in directory data */
- r = unit_load_dropin(unit_follow_merge(u));
- if (r < 0)
- return r;
+ /* If the unit is an alias and the final unit has already been
+ * loaded, there's no point in reloading the dropins one more time. */
+ t = unit_follow_merge(u);
+ if (t != u && t->load_state != UNIT_STUB)
+ return 0;
- return 0;
+ return unit_load_dropin(t);
}
int unit_add_default_target_dependency(Unit *u, Unit *target) {