diff options
author | Lennart Poettering <lennart@poettering.net> | 2015-11-11 20:42:39 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2015-11-11 20:42:39 +0100 |
commit | 4c9ea260aeaff2e837f543e3c42d2e7102af1137 (patch) | |
tree | e1e6a1f6cbcb1a11c3eda17376e52fd401fcf8f9 /src/core | |
parent | 45f06b3450174a9649a51a0b48fdbbbe98f2bb5d (diff) |
core: simplify things a bit by checking default_dependencies boolean in callee, not caller
It's nicer to hide the check away in the various
xyz_add_default_dependencies() calls, rather than making it explicit in
the caller, and thus require deeper nesing.
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/automount.c | 11 | ||||
-rw-r--r-- | src/core/mount.c | 11 | ||||
-rw-r--r-- | src/core/path.c | 20 | ||||
-rw-r--r-- | src/core/scope.c | 11 | ||||
-rw-r--r-- | src/core/slice.c | 12 | ||||
-rw-r--r-- | src/core/socket.c | 11 | ||||
-rw-r--r-- | src/core/swap.c | 11 | ||||
-rw-r--r-- | src/core/timer.c | 11 |
8 files changed, 51 insertions, 47 deletions
diff --git a/src/core/automount.c b/src/core/automount.c index 4c229247c5..41ead117c8 100644 --- a/src/core/automount.c +++ b/src/core/automount.c @@ -148,6 +148,9 @@ static int automount_add_default_dependencies(Automount *a) { assert(a); + if (!UNIT(a)->default_dependencies) + return 0; + if (UNIT(a)->manager->running_as != MANAGER_SYSTEM) return 0; @@ -219,11 +222,9 @@ static int automount_load(Unit *u) { if (r < 0) return r; - if (UNIT(a)->default_dependencies) { - r = automount_add_default_dependencies(a); - if (r < 0) - return r; - } + r = automount_add_default_dependencies(a); + if (r < 0) + return r; } return automount_verify(a); diff --git a/src/core/mount.c b/src/core/mount.c index d3766ba934..49525ebb78 100644 --- a/src/core/mount.c +++ b/src/core/mount.c @@ -393,6 +393,9 @@ static int mount_add_default_dependencies(Mount *m) { assert(m); + if (!UNIT(m)->default_dependencies) + return 0; + if (UNIT(m)->manager->running_as != MANAGER_SYSTEM) return 0; @@ -533,11 +536,9 @@ static int mount_add_extras(Mount *m) { if (r < 0) return r; - if (u->default_dependencies) { - r = mount_add_default_dependencies(m); - if (r < 0) - return r; - } + r = mount_add_default_dependencies(m); + if (r < 0) + return r; return 0; } diff --git a/src/core/path.c b/src/core/path.c index 35e1753583..c0992b4fcc 100644 --- a/src/core/path.c +++ b/src/core/path.c @@ -315,20 +315,20 @@ static int path_add_default_dependencies(Path *p) { assert(p); - r = unit_add_dependency_by_name(UNIT(p), UNIT_BEFORE, - SPECIAL_PATHS_TARGET, NULL, true); + if (!UNIT(p)->default_dependencies) + return 0; + + r = unit_add_dependency_by_name(UNIT(p), UNIT_BEFORE, SPECIAL_PATHS_TARGET, NULL, true); if (r < 0) return r; if (UNIT(p)->manager->running_as == MANAGER_SYSTEM) { - r = unit_add_two_dependencies_by_name(UNIT(p), UNIT_AFTER, UNIT_REQUIRES, - SPECIAL_SYSINIT_TARGET, NULL, true); + r = unit_add_two_dependencies_by_name(UNIT(p), UNIT_AFTER, UNIT_REQUIRES, SPECIAL_SYSINIT_TARGET, NULL, true); if (r < 0) return r; } - return unit_add_two_dependencies_by_name(UNIT(p), UNIT_BEFORE, UNIT_CONFLICTS, - SPECIAL_SHUTDOWN_TARGET, NULL, true); + return unit_add_two_dependencies_by_name(UNIT(p), UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_SHUTDOWN_TARGET, NULL, true); } static int path_load(Unit *u) { @@ -360,11 +360,9 @@ static int path_load(Unit *u) { if (r < 0) return r; - if (UNIT(p)->default_dependencies) { - r = path_add_default_dependencies(p); - if (r < 0) - return r; - } + r = path_add_default_dependencies(p); + if (r < 0) + return r; } return path_verify(p); diff --git a/src/core/scope.c b/src/core/scope.c index 8d6149aab0..5f6527c155 100644 --- a/src/core/scope.c +++ b/src/core/scope.c @@ -122,6 +122,9 @@ static int scope_add_default_dependencies(Scope *s) { assert(s); + if (!UNIT(s)->default_dependencies) + return 0; + /* Make sure scopes are unloaded on shutdown */ r = unit_add_two_dependencies_by_name( UNIT(s), @@ -173,11 +176,9 @@ static int scope_load(Unit *u) { if (r < 0) return r; - if (u->default_dependencies) { - r = scope_add_default_dependencies(s); - if (r < 0) - return r; - } + r = scope_add_default_dependencies(s); + if (r < 0) + return r; return scope_verify(s); } diff --git a/src/core/slice.c b/src/core/slice.c index 2aa3fbf8be..39dabae055 100644 --- a/src/core/slice.c +++ b/src/core/slice.c @@ -85,6 +85,9 @@ static int slice_add_default_dependencies(Slice *s) { assert(s); + if (!UNIT(s)->default_dependencies) + return 0; + /* Make sure slices are unloaded on shutdown */ r = unit_add_two_dependencies_by_name( UNIT(s), @@ -96,7 +99,6 @@ static int slice_add_default_dependencies(Slice *s) { return 0; } - static int slice_verify(Slice *s) { _cleanup_free_ char *parent = NULL; int r; @@ -144,11 +146,9 @@ static int slice_load(Unit *u) { if (r < 0) return r; - if (u->default_dependencies) { - r = slice_add_default_dependencies(s); - if (r < 0) - return r; - } + r = slice_add_default_dependencies(s); + if (r < 0) + return r; } return slice_verify(s); diff --git a/src/core/socket.c b/src/core/socket.c index c73ee78b13..43d4ec5dca 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -296,6 +296,9 @@ static int socket_add_default_dependencies(Socket *s) { int r; assert(s); + if (!UNIT(s)->default_dependencies) + return 0; + r = unit_add_dependency_by_name(UNIT(s), UNIT_BEFORE, SPECIAL_SOCKETS_TARGET, NULL, true); if (r < 0) return r; @@ -365,11 +368,9 @@ static int socket_add_extras(Socket *s) { return r; } - if (u->default_dependencies) { - r = socket_add_default_dependencies(s); - if (r < 0) - return r; - } + r = socket_add_default_dependencies(s); + if (r < 0) + return r; return 0; } diff --git a/src/core/swap.c b/src/core/swap.c index e44cffc2e8..ee0838e676 100644 --- a/src/core/swap.c +++ b/src/core/swap.c @@ -213,6 +213,9 @@ static int swap_add_device_links(Swap *s) { static int swap_add_default_dependencies(Swap *s) { assert(s); + if (!UNIT(s)->default_dependencies) + return 0; + if (UNIT(s)->manager->running_as != MANAGER_SYSTEM) return 0; @@ -331,11 +334,9 @@ static int swap_load(Unit *u) { if (r < 0) return r; - if (UNIT(s)->default_dependencies) { - r = swap_add_default_dependencies(s); - if (r < 0) - return r; - } + r = swap_add_default_dependencies(s); + if (r < 0) + return r; } return swap_verify(s); diff --git a/src/core/timer.c b/src/core/timer.c index c9dc97d4fb..c50e891aeb 100644 --- a/src/core/timer.c +++ b/src/core/timer.c @@ -102,6 +102,9 @@ static int timer_add_default_dependencies(Timer *t) { assert(t); + if (!UNIT(t)->default_dependencies) + return 0; + r = unit_add_dependency_by_name(UNIT(t), UNIT_BEFORE, SPECIAL_TIMERS_TARGET, NULL, true); if (r < 0) return r; @@ -192,11 +195,9 @@ static int timer_load(Unit *u) { if (r < 0) return r; - if (u->default_dependencies) { - r = timer_add_default_dependencies(t); - if (r < 0) - return r; - } + r = timer_add_default_dependencies(t); + if (r < 0) + return r; } return timer_verify(t); |