From 75193d4128c08291a17b0d7be11722d071650425 Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Fri, 11 Oct 2019 12:48:33 +0200 Subject: core: adjust load functions for other unit types to be more like service No functional change, just adjusting code to follow the same pattern everywhere. In particular, never call _verify() on an already loaded unit, but return early from the caller instead. This makes the code a bit easier to follow. --- src/core/automount.c | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) (limited to 'src/core/automount.c') diff --git a/src/core/automount.c b/src/core/automount.c index c15520c1e5..0ecacc12c8 100644 --- a/src/core/automount.c +++ b/src/core/automount.c @@ -164,9 +164,7 @@ static int automount_verify(Automount *a) { int r; assert(a); - - if (UNIT(a)->load_state != UNIT_LOADED) - return 0; + assert(UNIT(a)->load_state == UNIT_LOADED); if (path_equal(a->where, "/")) { log_unit_error(UNIT(a), "Cannot have an automount unit for the root directory. Refusing."); @@ -201,6 +199,24 @@ static int automount_set_where(Automount *a) { return 1; } +static int automount_add_extras(Automount *a) { + int r; + + r = automount_set_where(a); + if (r < 0) + return r; + + r = automount_add_trigger_dependencies(a); + if (r < 0) + return r; + + r = automount_add_mount_dependencies(a); + if (r < 0) + return r; + + return automount_add_default_dependencies(a); +} + static int automount_load(Unit *u) { Automount *a = AUTOMOUNT(u); int r; @@ -213,23 +229,12 @@ static int automount_load(Unit *u) { if (r < 0) return r; - if (u->load_state == UNIT_LOADED) { - r = automount_set_where(a); - if (r < 0) - return r; - - r = automount_add_trigger_dependencies(a); - if (r < 0) - return r; - - r = automount_add_mount_dependencies(a); - if (r < 0) - return r; + if (u->load_state != UNIT_LOADED) + return 0; - r = automount_add_default_dependencies(a); - if (r < 0) - return r; - } + r = automount_add_extras(a); + if (r < 0) + return r; return automount_verify(a); } -- cgit v1.2.3