From: Zbigniew Jędrzejewski-Szmek Date: Fri, 11 Oct 2019 08:41:44 +0000 (+0200) Subject: core: turn unit_load_fragment_and_dropin_optional() into a flag X-Git-Tag: v244~235^2~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c36207708778a83d2c84c11dd522ce732d65527f;p=platform%2Fupstream%2Fsystemd.git core: turn unit_load_fragment_and_dropin_optional() into a flag unit_load_fragment_and_dropin() and unit_load_fragment_and_dropin_optional() are really the same, with one minor difference in behaviour. Let's drop the second function. "_optional" in the name suggests that it's the "dropin" part that is optional. (Which it is, but in this case, we mean the fragment to be optional.) I think the new version with a flag is easier to understand. --- diff --git a/src/core/automount.c b/src/core/automount.c index a54e56c..c15520c 100644 --- a/src/core/automount.c +++ b/src/core/automount.c @@ -209,7 +209,7 @@ static int automount_load(Unit *u) { assert(u->load_state == UNIT_STUB); /* Load a .automount file */ - r = unit_load_fragment_and_dropin(u); + r = unit_load_fragment_and_dropin(u, true); if (r < 0) return r; diff --git a/src/core/device.c b/src/core/device.c index e2abca4..45149e7 100644 --- a/src/core/device.c +++ b/src/core/device.c @@ -116,7 +116,7 @@ static void device_done(Unit *u) { static int device_load(Unit *u) { int r; - r = unit_load_fragment_and_dropin_optional(u); + r = unit_load_fragment_and_dropin(u, false); if (r < 0) return r; diff --git a/src/core/mount.c b/src/core/mount.c index 09d08f3..bd851ac 100644 --- a/src/core/mount.c +++ b/src/core/mount.c @@ -634,10 +634,8 @@ static int mount_load(Unit *u) { r = mount_load_root_mount(u); - if (m->from_proc_self_mountinfo || u->perpetual) - q = unit_load_fragment_and_dropin_optional(u); - else - q = unit_load_fragment_and_dropin(u); + bool fragment_optional = m->from_proc_self_mountinfo || u->perpetual; + q = unit_load_fragment_and_dropin(u, !fragment_optional); /* Add in some extras. Note we do this in all cases (even if we failed to load the unit) when announced by the * kernel, because we need some things to be set up no matter what when the kernel establishes a mount and thus diff --git a/src/core/path.c b/src/core/path.c index aee94ce..e7071cc 100644 --- a/src/core/path.c +++ b/src/core/path.c @@ -340,7 +340,7 @@ static int path_load(Unit *u) { assert(u); assert(u->load_state == UNIT_STUB); - r = unit_load_fragment_and_dropin(u); + r = unit_load_fragment_and_dropin(u, true); if (r < 0) return r; diff --git a/src/core/scope.c b/src/core/scope.c index 79470a0..e03a1c7 100644 --- a/src/core/scope.c +++ b/src/core/scope.c @@ -176,7 +176,8 @@ static int scope_load(Unit *u) { r = scope_load_init_scope(u); if (r < 0) return r; - r = unit_load_fragment_and_dropin_optional(u); + + r = unit_load_fragment_and_dropin(u, false); if (r < 0) return r; diff --git a/src/core/slice.c b/src/core/slice.c index c12328b..9ef1202 100644 --- a/src/core/slice.c +++ b/src/core/slice.c @@ -170,7 +170,7 @@ static int slice_load(Unit *u) { if (r < 0) return r; - r = unit_load_fragment_and_dropin_optional(u); + r = unit_load_fragment_and_dropin(u, false); if (r < 0) return r; diff --git a/src/core/socket.c b/src/core/socket.c index f31d3bd..3d04fdf 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -514,7 +514,7 @@ static int socket_load(Unit *u) { if (r < 0) return r; - r = unit_load_fragment_and_dropin(u); + r = unit_load_fragment_and_dropin(u, true); if (r < 0) return r; diff --git a/src/core/swap.c b/src/core/swap.c index ad1da6d..fcea0fd 100644 --- a/src/core/swap.c +++ b/src/core/swap.c @@ -346,10 +346,8 @@ static int swap_load(Unit *u) { assert(u->load_state == UNIT_STUB); /* Load a .swap file */ - if (SWAP(u)->from_proc_swaps) - r = unit_load_fragment_and_dropin_optional(u); - else - r = unit_load_fragment_and_dropin(u); + bool fragment_optional = s->from_proc_swaps; + r = unit_load_fragment_and_dropin(u, !fragment_optional); /* Add in some extras, and do so either when we successfully loaded something or when /proc/swaps is already * active. */ diff --git a/src/core/target.c b/src/core/target.c index 421a304..5671faa 100644 --- a/src/core/target.c +++ b/src/core/target.c @@ -80,7 +80,7 @@ static int target_load(Unit *u) { assert(t); - r = unit_load_fragment_and_dropin(u); + r = unit_load_fragment_and_dropin(u, true); if (r < 0) return r; diff --git a/src/core/timer.c b/src/core/timer.c index 7d81685..e4821e1 100644 --- a/src/core/timer.c +++ b/src/core/timer.c @@ -178,7 +178,7 @@ static int timer_load(Unit *u) { assert(u); assert(u->load_state == UNIT_STUB); - r = unit_load_fragment_and_dropin(u); + r = unit_load_fragment_and_dropin(u, true); if (r < 0) return r; diff --git a/src/core/unit.c b/src/core/unit.c index 6dd075f..30636dc 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -1361,7 +1361,7 @@ void unit_dump(Unit *u, FILE *f, const char *prefix) { } /* Common implementation for multiple backends */ -int unit_load_fragment_and_dropin(Unit *u) { +int unit_load_fragment_and_dropin(Unit *u, bool fragment_required) { int r; assert(u); @@ -1371,8 +1371,12 @@ int unit_load_fragment_and_dropin(Unit *u) { if (r < 0) return r; - if (u->load_state == UNIT_STUB) - return -ENOENT; + if (u->load_state == UNIT_STUB) { + if (fragment_required) + return -ENOENT; + + u->load_state = UNIT_LOADED; + } /* Load drop-in directory data. If u is an alias, we might be reloading the * target unit needlessly. But we cannot be sure which drops-ins have already @@ -1381,27 +1385,6 @@ int unit_load_fragment_and_dropin(Unit *u) { return unit_load_dropin(unit_follow_merge(u)); } -/* Common implementation for multiple backends */ -int unit_load_fragment_and_dropin_optional(Unit *u) { - int r; - - assert(u); - - /* Same as unit_load_fragment_and_dropin(), but whether - * something can be loaded or not doesn't matter. */ - - /* Load a .service/.socket/.slice/… file */ - r = unit_load_fragment(u); - if (r < 0) - return r; - - if (u->load_state == UNIT_STUB) - u->load_state = UNIT_LOADED; - - /* Load drop-in directory data */ - return unit_load_dropin(unit_follow_merge(u)); -} - void unit_add_to_target_deps_queue(Unit *u) { Manager *m = u->manager; diff --git a/src/core/unit.h b/src/core/unit.h index 96f718a..5695552 100644 --- a/src/core/unit.h +++ b/src/core/unit.h @@ -670,8 +670,7 @@ int unit_merge_by_name(Unit *u, const char *other); Unit *unit_follow_merge(Unit *u) _pure_; -int unit_load_fragment_and_dropin(Unit *u); -int unit_load_fragment_and_dropin_optional(Unit *u); +int unit_load_fragment_and_dropin(Unit *u, bool fragment_required); int unit_load(Unit *unit); int unit_set_slice(Unit *u, Unit *slice);