prepare-root: check for read-only sysroot status early on
authorLuca BRUNO <luca.bruno@coreos.com>
Mon, 1 Nov 2021 09:09:58 +0000 (09:09 +0000)
committerLuca BRUNO <luca.bruno@coreos.com>
Mon, 1 Nov 2021 09:42:36 +0000 (09:42 +0000)
This moves read-only sysroot checks upfront, so that they are not
intermixed with mount operations.
It has no immediate side-effects, but allow these check to be
independent from the rest of the mounting logic (and future changes
to it).

src/switchroot/ostree-prepare-root.c

index aa7d5a4e3266bef67d82aded4c9b5d5e8a841622..a99d884de53358436da75bc0a03e1ab5e54b121e 100644 (file)
@@ -216,6 +216,20 @@ main(int argc, char *argv[])
         err (EXIT_FAILURE, "failed to umount proc from /proc");
     }
 
+  /* Query the repository configuration - this is an operating system builder
+   * choice.  More info: https://github.com/ostreedev/ostree/pull/1767
+   */
+  const bool sysroot_readonly = sysroot_is_configured_ro (root_arg);
+  const bool sysroot_currently_writable = !path_is_on_readonly_fs (root_arg);
+#ifdef USE_LIBSYSTEMD
+  sd_journal_send ("MESSAGE=filesystem at %s currently writable: %d", root_arg,
+                   (int)sysroot_currently_writable,
+                   NULL);
+  sd_journal_send ("MESSAGE=sysroot.readonly configuration value: %d",
+                   (int)sysroot_readonly,
+                   NULL);
+#endif
+
   /* Work-around for a kernel bug: for some reason the kernel
    * refuses switching root if any file systems are mounted
    * MS_SHARED. Hence remount them MS_PRIVATE here as a
@@ -235,20 +249,6 @@ main(int argc, char *argv[])
   if (chdir (deploy_path) < 0)
     err (EXIT_FAILURE, "failed to chdir to deploy_path");
 
-  /* Query the repository configuration - this is an operating system builder
-   * choice.  More info: https://github.com/ostreedev/ostree/pull/1767
-   */
-  const bool sysroot_readonly = sysroot_is_configured_ro (root_arg);
-  const bool sysroot_currently_writable = !path_is_on_readonly_fs (root_arg);
-#ifdef USE_LIBSYSTEMD
-  sd_journal_send ("MESSAGE=filesystem at %s currently writable: %d", root_arg,
-                   (int)sysroot_currently_writable,
-                   NULL);
-  sd_journal_send ("MESSAGE=sysroot.readonly configuration value: %d",
-                   (int)sysroot_readonly,
-                   NULL);
-#endif
-
   if (sysroot_readonly)
     {
       if (!sysroot_currently_writable)