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.
This commit is contained in:
parent
349176ae6c
commit
c362077087
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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. */
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue