Skip to content

Commit

Permalink
otcore: add debug logging capability for ostree-prepare-root
Browse files Browse the repository at this point in the history
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 <ecurtin@redhat.com>
  • Loading branch information
ericcurtin committed May 28, 2024
1 parent b605230 commit 93a03c8
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/libotcore/otcore-prepare-root.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
1 change: 1 addition & 0 deletions src/libotcore/otcore.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
20 changes: 20 additions & 0 deletions src/switchroot/ostree-prepare-root.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,20 @@

#include "ostree-mount-util.h"

static bool enable_debug = false;

__attribute__ ((__format__ (printf, 1, 2))) static void
dbg (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)
{
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
dbg ("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");
}
Expand Down Expand Up @@ -598,6 +615,9 @@ main (int argc, char *argv[])
// Propagate readonly state
if (!sysroot_currently_writable)
mflags |= MS_RDONLY;

dbg ("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");
}
Expand Down

0 comments on commit 93a03c8

Please sign in to comment.