mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-05 09:17:44 +03:00
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.
This commit is contained in:
parent
45f06b3450
commit
4c9ea260ae
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user