]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: turn unit_load_fragment_and_dropin_optional() into a flag
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 11 Oct 2019 08:41:44 +0000 (10:41 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 11 Oct 2019 08:45:33 +0000 (10:45 +0200)
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.

12 files changed:
src/core/automount.c
src/core/device.c
src/core/mount.c
src/core/path.c
src/core/scope.c
src/core/slice.c
src/core/socket.c
src/core/swap.c
src/core/target.c
src/core/timer.c
src/core/unit.c
src/core/unit.h

index a54e56c3122ea52344a77673aaf9bd9705cb7d90..c15520c1e5bc5323c0c783301bff9738d2c7d386 100644 (file)
@@ -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;
 
index e2abca469a5d892d4a8d14b5ef7adbc940983bba..45149e75554c9243b299f93a6ebf8b7d43d2320f 100644 (file)
@@ -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;
 
index 09d08f3990fd5523fa469534c6d44ef70eba320e..bd851ac8bc5bd4d2dd4704c08ddb229b645aebd2 100644 (file)
@@ -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
index aee94ce7f04445fcaa58e8eaed4f1e04666d6589..e7071ccb4f677d44e37a327585bd4bcc8fb47f2c 100644 (file)
@@ -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;
 
index 79470a0a9beb89afe31cde591248405bad1f2af4..e03a1c7baa6194a6664d27029002ae6de9a2023a 100644 (file)
@@ -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;
 
index c12328b3b736daad43607709a5aa33f1b544fc07..9ef12023ad9cfefc19b47762b93acfffde3245ba 100644 (file)
@@ -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;
 
index f31d3bd971d64b5e16cc6d9b895b1a09c47fbb57..3d04fdf7775e98d9c7b0bf43fa7d2408f217fa4f 100644 (file)
@@ -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;
 
index ad1da6dddb6f977ed8fe2339c56943c25c3fa1db..fcea0fd800eae4812927142ca67c4d81ac8ee54d 100644 (file)
@@ -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. */
index 421a304c73da421b14a962ab2cb35e962e23a248..5671faa7b1e6424d466c662c803e1f7f56f0203f 100644 (file)
@@ -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;
 
index 7d816856b19d70266675078440e3ec3e17c532f9..e4821e1bdb495c2e4b66af5a7ae73b94c90649e8 100644 (file)
@@ -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;
 
index 6dd075faa775c67e7c003681cbdbb27e307d4f52..30636dc0cc1068a66f5904da6832c5992110ff18 100644 (file)
@@ -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;
 
index 96f718acdcc638f4587faefd11f88d3a94c31361..5695552471edf5c514d13478fb637b827ce9af9c 100644 (file)
@@ -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);