1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-22 17:35:35 +03:00

core: simplify the return convention in manager_load_unit()

This function was returning 0 or 1 on success. It has many callers, and it
wasn't clear if any of them care about the distinction. It turns out they don't
and the return values were done for convenience because manager_load_unit_prepare()
returns 0 or 1. Let's invert the code in the static function to follow the usual
pattern where 0 means "no work was done" and 1 means "work was done", and make
the non-static function always return 0 to make the code easier to read, and
also add comments that explain what is happening.

No functional change.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2022-10-17 10:48:52 +02:00
parent 4b6a2b3f58
commit 535b7fcb44

View File

@ -2161,7 +2161,7 @@ int manager_load_unit_prepare(
unit->load_state = UNIT_STUB;
else {
*ret = unit;
return 1;
return 0; /* The unit was already loaded */
}
} else {
unit = cleanup_unit = unit_new(m, unit_vtable[t]->object_size);
@ -2186,7 +2186,7 @@ int manager_load_unit_prepare(
*ret = unit;
TAKE_PTR(cleanup_unit);
return 0;
return 1; /* The unit was added the load queue */
}
int manager_load_unit(
@ -2203,11 +2203,11 @@ int manager_load_unit(
/* This will load the unit config, but not actually start any services or anything. */
r = manager_load_unit_prepare(m, name, path, e, ret);
if (r != 0)
if (r <= 0)
return r;
/* Unit was newly loaded */
manager_dispatch_load_queue(m);
*ret = unit_follow_merge(*ret);
return 0;
}