From: Colin Walters Date: Sun, 23 Jul 2023 14:47:19 +0000 (-0400) Subject: src/generator: Move all logic into libostree-1.so X-Git-Tag: archive/raspbian/2023.7-3+rpi1~1^2~9^2^2~42^2 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=303e7eb2e1191e4fc1798198e16becc925075bca;p=ostree.git src/generator: Move all logic into libostree-1.so This pushes down the code for parsing the `ostree=` cmdline in the generator into code that's part of libostree-1.so. This is prep for using logic shared in libotcore.la. But in general it's just cleaner to also keep the binary entrypoint to just be a trampoline into the C library. --- diff --git a/Makefile-libostree.am b/Makefile-libostree.am index 1cb7de54..6f339b18 100644 --- a/Makefile-libostree.am +++ b/Makefile-libostree.am @@ -186,6 +186,7 @@ EXTRA_DIST += \ $(NULL) libostree_1_la_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/bsdiff -I$(srcdir)/libglnx -I$(srcdir)/composefs -I$(srcdir)/src/libotutil -I$(srcdir)/src/libotcore -I$(srcdir)/src/libostree -I$(builddir)/src/libostree \ + -I$(srcdir)/src/switchroot \ $(OT_INTERNAL_GIO_UNIX_CFLAGS) $(OT_INTERNAL_GPGME_CFLAGS) $(OT_DEP_LZMA_CFLAGS) $(OT_DEP_ZLIB_CFLAGS) $(OT_DEP_CRYPTO_CFLAGS) \ -fvisibility=hidden '-D_OSTREE_PUBLIC=__attribute__((visibility("default"))) extern' \ -DPKGLIBEXECDIR=\"$(pkglibexecdir)\" diff --git a/src/libostree/ostree-cmd-private.h b/src/libostree/ostree-cmd-private.h index 15d95f7f..3b48e6ee 100644 --- a/src/libostree/ostree-cmd-private.h +++ b/src/libostree/ostree-cmd-private.h @@ -23,14 +23,13 @@ G_BEGIN_DECLS -gboolean _ostree_impl_system_generator (const char *ostree_cmdline, const char *normal_dir, - const char *early_dir, const char *late_dir, - GError **error); +gboolean _ostree_impl_system_generator (const char *normal_dir, const char *early_dir, + const char *late_dir, GError **error); typedef struct { - gboolean (*ostree_system_generator) (const char *ostree_cmdline, const char *normal_dir, - const char *early_dir, const char *late_dir, GError **error); + gboolean (*ostree_system_generator) (const char *normal_dir, const char *early_dir, + const char *late_dir, GError **error); gboolean (*ostree_generate_grub2_config) (OstreeSysroot *sysroot, int bootversion, int target_fd, GCancellable *cancellable, GError **error); gboolean (*ostree_static_delta_dump) (OstreeRepo *repo, const char *delta_id, diff --git a/src/libostree/ostree-impl-system-generator.c b/src/libostree/ostree-impl-system-generator.c index 33c78b65..e96becff 100644 --- a/src/libostree/ostree-impl-system-generator.c +++ b/src/libostree/ostree-impl-system-generator.c @@ -32,6 +32,7 @@ #include "ostree-cmd-private.h" #include "ostree-core-private.h" +#include "ostree-mount-util.h" #include "ostree-sysroot-private.h" #include "ostree.h" @@ -242,9 +243,23 @@ fstab_generator (const char *ostree_cmdline, const char *normal_dir, const char /* Implementation of ostree-system-generator */ gboolean -_ostree_impl_system_generator (const char *ostree_cmdline, const char *normal_dir, - const char *early_dir, const char *late_dir, GError **error) +_ostree_impl_system_generator (const char *normal_dir, const char *early_dir, const char *late_dir, + GError **error) { + /* We conflict with the magic ostree-mount-deployment-var file for ostree-prepare-root. + * If this file is present, we have nothing to do! */ + if (unlinkat (AT_FDCWD, INITRAMFS_MOUNT_VAR, 0) == 0) + return TRUE; + + /* If we're installed on a system which isn't using OSTree for boot (e.g. + * package installed as a dependency for flatpak or whatever), silently + * exit so that we don't error, but at the same time work where switchroot + * is PID 1 (and so hasn't created /run/ostree-booted). + */ + autofree char *ostree_cmdline = read_proc_cmdline_key ("ostree"); + if (!ostree_cmdline) + return TRUE; + if (!require_internal_units (normal_dir, early_dir, late_dir, error)) return FALSE; if (!fstab_generator (ostree_cmdline, normal_dir, early_dir, late_dir, error)) diff --git a/src/switchroot/ostree-system-generator.c b/src/switchroot/ostree-system-generator.c index 03a9bb42..4fddc363 100644 --- a/src/switchroot/ostree-system-generator.c +++ b/src/switchroot/ostree-system-generator.c @@ -28,7 +28,6 @@ #include #include "ostree-cmd-private.h" -#include "ostree-mount-util.h" static const char *arg_dest = "/tmp"; static const char *arg_dest_late = "/tmp"; @@ -39,17 +38,6 @@ static const char *arg_dest_late = "/tmp"; int main (int argc, char *argv[]) { - /* We conflict with the magic ostree-mount-deployment-var file for ostree-prepare-root */ - { - struct stat stbuf; - if (fstatat (AT_FDCWD, INITRAMFS_MOUNT_VAR, &stbuf, 0) == 0) - { - if (unlinkat (AT_FDCWD, INITRAMFS_MOUNT_VAR, 0) < 0) - err (EXIT_FAILURE, "Can't unlink " INITRAMFS_MOUNT_VAR); - exit (EXIT_SUCCESS); - } - } - if (argc > 1 && argc != 4) errx (EXIT_FAILURE, "This program takes three or no arguments"); @@ -58,19 +46,10 @@ main (int argc, char *argv[]) if (argc > 3) arg_dest_late = argv[3]; - /* If we're installed on a system which isn't using OSTree for boot (e.g. - * package installed as a dependency for flatpak or whatever), silently - * exit so that we don't error, but at the same time work where switchroot - * is PID 1 (and so hasn't created /run/ostree-booted). - */ - autofree char *ostree_cmdline = read_proc_cmdline_key ("ostree"); - if (!ostree_cmdline) - exit (EXIT_SUCCESS); - { g_autoptr (GError) local_error = NULL; - if (!ostree_cmd__private__ ()->ostree_system_generator (ostree_cmdline, arg_dest, NULL, - arg_dest_late, &local_error)) + if (!ostree_cmd__private__ ()->ostree_system_generator (arg_dest, NULL, arg_dest_late, + &local_error)) errx (EXIT_FAILURE, "%s", local_error->message); }