]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: simplify the return convention in manager_load_unit()
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 17 Oct 2022 08:48:52 +0000 (10:48 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 17 Oct 2022 11:50:16 +0000 (13:50 +0200)
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.

src/core/manager.c

index 983878943500531c673dd20b6d319c2ed722b381..a59afafb589fed0b19dbf8be2f2b3dac7f2dfca1 100644 (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;
 }