]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
veritysetup-generator: only generate one set of deps on systemd-tmpfiles-setup-dev...
authorLennart Poettering <lennart@poettering.net>
Thu, 1 Jun 2023 12:55:26 +0000 (14:55 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 1 Jun 2023 16:49:43 +0000 (18:49 +0200)
If both the data and the hash device are a regular file we might create
two sets of deps on s-t-s-d.s, which is of course redundant. Shorten the
code to only generate this once.

No change in behaviour.

src/veritysetup/veritysetup-generator.c

index c1a9d51af381cf85b1eb40bc3f8a543fa70f20bd..68ef5d458f4c5e87ab12c80cde461579e531bd73 100644 (file)
@@ -311,7 +311,7 @@ static int create_disk(
                             *du_escaped = NULL, *hu_escaped = NULL, *name_escaped = NULL;
         _cleanup_fclose_ FILE *f = NULL;
         const char *dmname;
-        bool noauto, nofail, netdev;
+        bool noauto, nofail, netdev, need_loop = false;
         int r;
 
         assert(name);
@@ -386,30 +386,27 @@ static int create_disk(
                         "BindsTo=%s\n"
                         "After=%s\n",
                         dd, dd);
-        else
-                /* For loopback devices, add systemd-tmpfiles-setup-dev.service
-                   dependency to ensure that loopback support is available in
-                   the kernel (/dev/loop-control needs to exist) */
-                fprintf(f,
-                        "RequiresMountsFor=%s\n"
-                        "Requires=systemd-tmpfiles-setup-dev.service\n"
-                        "After=systemd-tmpfiles-setup-dev.service\n",
-                        du_escaped);
+        else {
+                fprintf(f, "RequiresMountsFor=%s\n", du_escaped);
+                need_loop = true;
+        }
 
         if (path_startswith(hu, "/dev/"))
                 fprintf(f,
                         "BindsTo=%s\n"
                         "After=%s\n",
                         hd, hd);
-        else
-                /* For loopback devices, add systemd-tmpfiles-setup-dev.service
-                   dependency to ensure that loopback support is available in
-                   the kernel (/dev/loop-control needs to exist) */
+        else {
+                fprintf(f, "RequiresMountsFor=%s\n", hu_escaped);
+                need_loop = true;
+        }
+
+        if (need_loop)
+                /* For loopback devices, add systemd-tmpfiles-setup-dev.service dependency to ensure that
+                 * loopback support is available in the kernel (/dev/loop-control needs to exist) */
                 fprintf(f,
-                        "RequiresMountsFor=%s\n"
                         "Requires=systemd-tmpfiles-setup-dev.service\n"
-                        "After=systemd-tmpfiles-setup-dev.service\n",
-                        hu_escaped);
+                        "After=systemd-tmpfiles-setup-dev.service\n");
 
         r = generator_write_veritysetup_service_section(f, name, du_escaped, hu_escaped, roothash, options);
         if (r < 0)