From d8434979110efe9aa003e418c95ea5934304547f Mon Sep 17 00:00:00 2001 From: Eric Curtin Date: Tue, 28 May 2024 10:48:47 +0100 Subject: [PATCH] otcore: add debug logging capability for ostree-prepare-root This commit introduces a new function, proc_cmdline_has_key, to check for specific keys in the kernel command line. Additionally, it adds a debug logging mechanism in ostree-prepare-root.c, which is controlled by the presence of the "ostree-prepare-root.debug" key in the kernel command line. These changes provide enhanced visibility into the mounting process, aiding in troubleshooting. Signed-off-by: Eric Curtin --- src/libotcore/otcore-prepare-root.c | 18 ++++++++++++++++++ src/libotcore/otcore.h | 1 + src/switchroot/ostree-prepare-root.c | 19 +++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/src/libotcore/otcore-prepare-root.c b/src/libotcore/otcore-prepare-root.c index f76db04a33..ae8b710609 100644 --- a/src/libotcore/otcore-prepare-root.c +++ b/src/libotcore/otcore-prepare-root.c @@ -25,6 +25,24 @@ // which can be used to fully verify the target filesystem tree. #define BINDING_KEYPATH "/etc/ostree/initramfs-root-binding.key" +bool +proc_cmdline_has_key (const char *cmdline, const char *key) +{ + for (const char *iter = cmdline; iter;) + { + if (g_str_equal (iter, key)) + return true; + + iter = strchr (iter, ' '); + if (iter == NULL) + return false; + + iter += strspn (iter, " "); + } + + return false; +} + static bool proc_cmdline_has_key_starting_with (const char *cmdline, const char *key) { diff --git a/src/libotcore/otcore.h b/src/libotcore/otcore.h index fc6b81ca1a..cd4d405240 100644 --- a/src/libotcore/otcore.h +++ b/src/libotcore/otcore.h @@ -43,6 +43,7 @@ bool otcore_ed25519_init (void); gboolean otcore_validate_ed25519_signature (GBytes *data, GBytes *pubkey, GBytes *signature, bool *out_valid, GError **error); +bool proc_cmdline_has_key (const char *cmdline, const char *key); char *otcore_find_proc_cmdline_key (const char *cmdline, const char *key); gboolean otcore_get_ostree_target (const char *cmdline, gboolean *is_aboot, char **out_target, GError **error); diff --git a/src/switchroot/ostree-prepare-root.c b/src/switchroot/ostree-prepare-root.c index 4ac4420272..a4849fecb1 100644 --- a/src/switchroot/ostree-prepare-root.c +++ b/src/switchroot/ostree-prepare-root.c @@ -97,6 +97,20 @@ #include "ostree-mount-util.h" +static bool enable_debug = false; + +__attribute__ ((__format__ (printf, 1, 2))) static void +debug (const char *format, ...) +{ + if (enable_debug) + { + va_list args; + va_start (args, format); + vprintf (format, args); + va_end (args); + } +} + static bool sysroot_is_configured_ro (const char *sysroot) { @@ -124,6 +138,7 @@ resolve_deploy_path (const char *root_mountpoint) g_autoptr (GError) error = NULL; g_autofree char *ostree_target = NULL; + enable_debug = proc_cmdline_has_key (kernel_cmdline, "ostree-prepare-root.debug"); if (!otcore_get_ostree_target (kernel_cmdline, NULL, &ostree_target, &error)) errx (EXIT_FAILURE, "Failed to determine ostree target: %s", error->message); if (!ostree_target) @@ -564,6 +579,8 @@ main (int argc, char *argv[]) g_autofree char *ovl_options = g_strdup_printf ("lowerdir=%s,upperdir=%s,workdir=%s", lowerdir, upperdir, workdir); + debug ("mount (\"overlay\", " TMP_SYSROOT "\"/etc\", \"overlay\", MS_SILENT, \"%s\")\n", + ovl_options); if (mount ("overlay", TMP_SYSROOT "/etc", "overlay", MS_SILENT, ovl_options) < 0) err (EXIT_FAILURE, "failed to mount transient etc overlayfs"); } @@ -598,6 +615,8 @@ main (int argc, char *argv[]) // Propagate readonly state if (!sysroot_currently_writable) mflags |= MS_RDONLY; + debug ("mount (\"overlay\", " TMP_SYSROOT "\"/usr\", \"overlay\", %lu, \"%s\")\n", mflags, + usr_ovl_options); if (mount ("overlay", TMP_SYSROOT "/usr", "overlay", mflags, usr_ovl_options) < 0) err (EXIT_FAILURE, "failed to mount /usr overlayfs"); }