]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
machine-id-setup: do sync() stuff only when operating on the real rootfs
authorLennart Poettering <lennart@poettering.net>
Thu, 16 Jan 2025 09:22:39 +0000 (10:22 +0100)
committerLennart Poettering <lennart@poettering.net>
Mon, 20 Jan 2025 10:31:55 +0000 (11:31 +0100)
If we operate relative some explicit rootfs the reason for the sync()ing
is not really given, we are not really acting as a milestone at boot,
but "offline".

src/shared/machine-id-setup.c

index 4240525742872935b0461222be40984d9ac1f191..5526a900f47d5fb49214e0d84f5df3a071366b48 100644 (file)
@@ -255,17 +255,20 @@ int machine_id_commit(const char *root) {
         sd_id128_t id;
         int r;
 
-        /* Before doing anything, sync everything to ensure any changes by first-boot units are persisted.
-         *
-         * First, explicitly sync the file systems we care about and check if it worked. */
-        FOREACH_STRING(sync_path, "/etc/", "/var/") {
-                r = syncfs_path(AT_FDCWD, sync_path);
-                if (r < 0)
-                        return log_error_errno(r, "Cannot sync %s: %m", sync_path);
-        }
+        if (empty_or_root(root)) {
+                /* Before doing anything, sync everything to ensure any changes by first-boot units are
+                 * persisted.
+                 *
+                 * First, explicitly sync the file systems we care about and check if it worked. */
+                FOREACH_STRING(sync_path, "/etc/", "/var/") {
+                        r = syncfs_path(AT_FDCWD, sync_path);
+                        if (r < 0)
+                                return log_error_errno(r, "Cannot sync %s: %m", sync_path);
+                }
 
-        /* Afterwards, sync() the rest too, but we can't check the return value for these. */
-        sync();
+                /* Afterwards, sync() the rest too, but we can't check the return value for these. */
+                sync();
+        }
 
         /* Replaces a tmpfs bind mount of /etc/machine-id by a proper file, atomically. For this, the umount is removed
          * in a mount namespace, a new file is created at the right place. Afterwards the mount is also removed in the