src/generator: Move all logic into libostree-1.so
authorColin Walters <walters@verbum.org>
Sun, 23 Jul 2023 14:47:19 +0000 (10:47 -0400)
committerColin Walters <walters@verbum.org>
Sun, 23 Jul 2023 14:47:19 +0000 (10:47 -0400)
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.

Makefile-libostree.am
src/libostree/ostree-cmd-private.h
src/libostree/ostree-impl-system-generator.c
src/switchroot/ostree-system-generator.c

index 1cb7de54774df4f481ef97b6f1a3542a513177da..6f339b18de443bae92f3bfc92e02f13af3b80a13 100644 (file)
@@ -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)\"
index 15d95f7fb99a2bcfdf884ed319412633f11ef2ea..3b48e6eee960256d40d680ff120d88ec2cf4c2d9 100644 (file)
 
 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,
index 33c78b65b7696447b0419d98e07c754f70417709..e96becff81f0c75842103dd111d4104f4112f330 100644 (file)
@@ -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))
index 03a9bb423498f521d4a8f1d4be9c5ec3d91791cd..4fddc36381210d673c08be6f3cd92e7a15a97910 100644 (file)
@@ -28,7 +28,6 @@
 #include <libglnx.h>
 
 #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);
   }