]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
gpt-auto-generator: move around in_initrd() tests
authorLennart Poettering <lennart@poettering.net>
Thu, 6 Mar 2025 08:35:59 +0000 (09:35 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 6 Mar 2025 08:42:15 +0000 (09:42 +0100)
The partition enumeration only runs on the main system, and we test that
early, hence no point in repeating this in functions further down the
call chain. But let's keep it in place as assert()s, just in case.

Also, move the top-level in_initrd() into add_mounts(), so that the
tests are nicely encapsulated in the code they protect.

src/gpt-auto-generator/gpt-auto-generator.c

index c6727523f00b4a6a9bedc013e02e41ebaa9e3528..0f7d089d1cfb1ba6c47b2e55f1e6f7fbbb847ad0 100644 (file)
@@ -485,11 +485,7 @@ static int add_partition_xbootldr(DissectedPartition *p) {
         int r;
 
         assert(p);
-
-        if (in_initrd()) {
-                log_debug("In initrd, ignoring the XBOOTLDR partition.");
-                return 0;
-        }
+        assert(!in_initrd());
 
         r = path_is_busy("/boot");
         if (r < 0)
@@ -526,11 +522,7 @@ static int add_partition_esp(DissectedPartition *p, bool has_xbootldr) {
         int r;
 
         assert(p);
-
-        if (in_initrd()) {
-                log_debug("In initrd, ignoring the ESP.");
-                return 0;
-        }
+        assert(!in_initrd());
 
         /* Check if there's an existing fstab entry for ESP. If so, we just skip the gpt-auto logic. */
         r = fstab_has_node(p->node);
@@ -908,6 +900,9 @@ static int add_mounts(void) {
         dev_t devno;
         int r;
 
+        if (in_initrd())
+                return 0;
+
         r = blockdev_get_root(LOG_ERR, &devno);
         if (r < 0)
                 return r;
@@ -1011,10 +1006,9 @@ static int run(const char *dest, const char *dest_early, const char *dest_late)
                 return 0;
         }
 
-        r = add_root_mount();
-
-        if (!in_initrd())
-                RET_GATHER(r, add_mounts());
+        r = 0;
+        RET_GATHER(r, add_root_mount());
+        RET_GATHER(r, add_mounts());
 
         return r;
 }