]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: split out default network dep generation into own function
authorLennart Poettering <lennart@poettering.net>
Thu, 23 Mar 2023 13:03:47 +0000 (14:03 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 24 May 2023 08:20:36 +0000 (10:20 +0200)
Just some simple refactoring: let's split out network dep generation
into its own function mount_add_default_network_dependencies().

This way mount_add_default_dependencies() only does preparatory stuff,
and then calls both mount_add_default_network_dependencies() and
mount_add_default_ordering_dependencies() with that, making things
nicely symmetric.

src/core/mount.c

index 007d865fee6b5e0d415dabd20aa3c6a22b688832..4a0dc7ebacf9afeb05adc69c7439efa76185c6fe 100644 (file)
@@ -551,6 +551,31 @@ static int mount_add_default_ordering_dependencies(Mount *m, MountParameters *p,
         return 0;
 }
 
+static int mount_add_default_network_dependencies(Mount *m, MountParameters *p, UnitDependencyMask mask) {
+        int r;
+
+        assert(m);
+
+        if (!mount_is_network(p))
+                return 0;
+
+        /* We order ourselves after network.target. This is primarily useful at shutdown: services that take
+         * down the network should order themselves before network.target, so that they are shut down only
+         * after this mount unit is stopped. */
+
+        r = unit_add_dependency_by_name(UNIT(m), UNIT_AFTER, SPECIAL_NETWORK_TARGET,
+                                        /* add_reference= */ true, mask);
+        if (r < 0)
+                return r;
+
+        /* We pull in network-online.target, and order ourselves after it. This is useful at start-up to
+         * actively pull in tools that want to be started before we start mounting network file systems, and
+         * whose purpose it is to delay this until the network is "up". */
+
+        return unit_add_two_dependencies_by_name(UNIT(m), UNIT_WANTS, UNIT_AFTER, SPECIAL_NETWORK_ONLINE_TARGET,
+                                                 /* add_reference= */ true, mask);
+}
+
 static int mount_add_default_dependencies(Mount *m) {
         UnitDependencyMask mask;
         MountParameters *p;
@@ -578,27 +603,9 @@ static int mount_add_default_dependencies(Mount *m) {
         if (r < 0)
                 return r;
 
-        if (mount_is_network(p)) {
-                /* We order ourselves after network.target. This is primarily useful at shutdown:
-                 * services that take down the network should order themselves before
-                 * network.target, so that they are shut down only after this mount unit is
-                 * stopped. */
-
-                r = unit_add_dependency_by_name(UNIT(m), UNIT_AFTER, SPECIAL_NETWORK_TARGET,
-                                                /* add_reference= */ true, mask);
-                if (r < 0)
-                        return r;
-
-                /* We pull in network-online.target, and order ourselves after it. This is useful
-                 * at start-up to actively pull in tools that want to be started before we start
-                 * mounting network file systems, and whose purpose it is to delay this until the
-                 * network is "up". */
-
-                r = unit_add_two_dependencies_by_name(UNIT(m), UNIT_WANTS, UNIT_AFTER, SPECIAL_NETWORK_ONLINE_TARGET,
-                                                      /* add_reference= */ true, mask);
-                if (r < 0)
-                        return r;
-        }
+        r = mount_add_default_network_dependencies(m, p, mask);
+        if (r < 0)
+                return r;
 
         return exec_context_add_default_dependencies(UNIT(m), &m->exec_context);
 }