diff --git a/Makefile-switchroot.am b/Makefile-switchroot.am index 6b7cca08..71a3cbda 100644 --- a/Makefile-switchroot.am +++ b/Makefile-switchroot.am @@ -60,8 +60,8 @@ ostree_remount_SOURCES = \ src/switchroot/ostree-mount-util.h \ src/switchroot/ostree-remount.c \ $(NULL) -ostree_remount_CPPFLAGS = $(AM_CPPFLAGS) $(OT_INTERNAL_GIO_UNIX_CFLAGS) -Isrc/switchroot -I$(srcdir)/libglnx -ostree_remount_LDADD = $(AM_LDFLAGS) $(OT_INTERNAL_GIO_UNIX_LIBS) libglnx.la +ostree_remount_CPPFLAGS = $(AM_CPPFLAGS) $(OT_INTERNAL_GIO_UNIX_CFLAGS) -Isrc/switchroot -I$(srcdir)/src/libotcore -I$(srcdir)/src/libotutil -I$(srcdir)/libglnx +ostree_remount_LDADD = $(AM_LDFLAGS) $(OT_INTERNAL_GIO_UNIX_LIBS) libotcore.la libotutil.la libglnx.la if USE_COMPOSEFS ostree_prepare_root_LDADD += libcomposefs.la diff --git a/src/switchroot/ostree-prepare-root.c b/src/switchroot/ostree-prepare-root.c index 696ace27..bbb20716 100644 --- a/src/switchroot/ostree-prepare-root.c +++ b/src/switchroot/ostree-prepare-root.c @@ -400,11 +400,6 @@ main (int argc, char *argv[]) if (lcfs_mount_image (OSTREE_COMPOSEFS_NAME, TMP_SYSROOT, &cfs_options) == 0) { - int fd = open (_OSTREE_COMPOSEFS_ROOT_STAMP, O_WRONLY | O_CREAT | O_CLOEXEC, 0644); - if (fd < 0) - err (EXIT_FAILURE, "failed to create %s", _OSTREE_COMPOSEFS_ROOT_STAMP); - (void)close (fd); - using_composefs = 1; g_variant_builder_add (&metadata_builder, "{sv}", OTCORE_RUN_BOOTED_KEY_COMPOSEFS, g_variant_new_boolean (true)); diff --git a/src/switchroot/ostree-remount.c b/src/switchroot/ostree-remount.c index 2563d08b..38af0889 100644 --- a/src/switchroot/ostree-remount.c +++ b/src/switchroot/ostree-remount.c @@ -36,10 +36,8 @@ #include #include -#include - -#include "glnx-backport-autocleanups.h" #include "ostree-mount-util.h" +#include "otcore.h" static void do_remount (const char *target, bool writable) @@ -81,15 +79,36 @@ do_remount (const char *target, bool writable) int main (int argc, char *argv[]) { - /* We really expect that nowadays that everything is done in the initramfs, - * but historically we created this file here, so we'll continue to do be - * sure here it exists. This code should be removed at some point though. - */ + g_autoptr (GError) error = NULL; + g_autoptr (GVariant) ostree_run_metadata_v = NULL; { - int fd = open (OSTREE_PATH_BOOTED, O_EXCL | O_CREAT | O_WRONLY | O_NOCTTY | O_CLOEXEC, 0640); - if (fd != -1) - (void)close (fd); + glnx_autofd int fd = open (OTCORE_RUN_BOOTED, O_RDONLY | O_CLOEXEC); + if (fd < 0) + { + /* We really expect that nowadays that everything is done in the initramfs, + * but historically we created this file here, so we'll continue to do be + * sure here it exists. This code should be removed at some point though. + */ + if (errno == ENOENT) + { + int subfd = open (OTCORE_RUN_BOOTED, O_EXCL | O_CREAT | O_WRONLY | O_NOCTTY | O_CLOEXEC, + 0640); + if (subfd != -1) + (void)close (subfd); + } + else + { + err (EXIT_FAILURE, "failed to open %s", OTCORE_RUN_BOOTED); + } + } + else + { + if (!ot_variant_read_fd (fd, 0, G_VARIANT_TYPE_VARDICT, TRUE, &ostree_run_metadata_v, + &error)) + errx (EXIT_FAILURE, "failed to read %s: %s", OTCORE_RUN_BOOTED, error->message); + } } + g_autoptr (GVariantDict) ostree_run_metadata = g_variant_dict_new (ostree_run_metadata_v); /* The /sysroot mount needs to be private to avoid having a mount for e.g. /var/cache * also propagate to /sysroot/ostree/deploy/$stateroot/var/cache @@ -100,10 +119,9 @@ main (int argc, char *argv[]) if (mount ("none", "/sysroot", NULL, MS_REC | MS_PRIVATE, NULL) < 0) perror ("warning: While remounting /sysroot MS_PRIVATE"); - bool root_is_composefs = false; - struct stat stbuf; - if (fstatat (AT_FDCWD, _OSTREE_COMPOSEFS_ROOT_STAMP, &stbuf, 0) == 0) - root_is_composefs = true; + gboolean root_is_composefs = FALSE; + g_variant_dict_lookup (ostree_run_metadata, OTCORE_RUN_BOOTED_KEY_COMPOSEFS, "b", + &root_is_composefs); if (path_is_on_readonly_fs ("/") && !root_is_composefs) {