Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bootloaders: Support for U-boot in extlinux.conf compatibility mode #2256

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions src/libostree/ostree-bootloader-syslinux.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <string.h>

static const char syslinux_config_path[] = "boot/syslinux/syslinux.cfg";
static const char extlinux_config_path[] = "boot/extlinux/extlinux.conf";

struct _OstreeBootloaderSyslinux
{
Expand All @@ -51,6 +52,13 @@ _ostree_bootloader_syslinux_query (OstreeBootloader *bootloader,

if (!glnx_fstatat_allow_noent (self->sysroot->sysroot_fd, syslinux_config_path, &stbuf, AT_SYMLINK_NOFOLLOW, error))
return FALSE;
if (errno == 0)
{
*out_is_active = TRUE;
return TRUE;
}
if (!glnx_fstatat_allow_noent (self->sysroot->sysroot_fd, extlinux_config_path, &stbuf, AT_SYMLINK_NOFOLLOW, error))
return FALSE;
*out_is_active = (errno == 0);
return TRUE;
}
Expand Down Expand Up @@ -84,12 +92,13 @@ append_config_from_loader_entries (OstreeBootloaderSyslinux *self,
if (regenerate_default && i == 0)
g_ptr_array_add (new_lines, g_strdup_printf ("DEFAULT %s", val));

g_ptr_array_add (new_lines, g_strdup_printf ("LABEL %s", val));
g_ptr_array_add (new_lines, g_strdup_printf ("\nLABEL %s", val));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way we're adding newlines into what is intended to be an "array of lines" feels...slightly wrong though it's clearly going to work. But WDYT about:

      g_ptr_array_add (new_lines, g_strdup (""));
      g_ptr_array_add (new_lines, g_strdup_printf ("LABEL %s", val));

instead?

g_ptr_array_add (new_lines, g_strdup_printf ("\tMENU LABEL %s", val));

val = ostree_bootconfig_parser_get (config, "linux");
if (!val)
return glnx_throw (error, "No \"linux\" key in bootloader config");
g_ptr_array_add (new_lines, g_strdup_printf ("\tKERNEL /boot%s", val));
g_ptr_array_add (new_lines, g_strdup_printf ("\tLINUX /boot%s", val));

val = ostree_bootconfig_parser_get (config, "initrd");
if (val)
Expand Down Expand Up @@ -124,7 +133,19 @@ _ostree_bootloader_syslinux_write_config (OstreeBootloader *bootloader,
glnx_file_get_contents_utf8_at (self->sysroot->sysroot_fd, syslinux_config_path, NULL,
cancellable, error);
if (!config_contents)
return FALSE;
{
if (errno != ENOENT)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having errno be set after a function returns a GError is...somewhat undefined behavior. It'd be better to do:

  if (g_error_matches (temp_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))

which is a pattern you can find all over the codebase (xref https://docs.rs/openat-ext/0.1.9/openat_ext/trait.OpenatDirExt.html#tymethod.open_file_optional )

return FALSE;
else
{
g_clear_error (error);
config_contents =
glnx_file_get_contents_utf8_at (self->sysroot->sysroot_fd, extlinux_config_path, NULL,
cancellable, error);
if (!config_contents)
return FALSE;
}
}

g_auto(GStrv) lines = g_strsplit (config_contents, "\n", -1);
g_autoptr(GPtrArray) new_lines = g_ptr_array_new_with_free_func (g_free);
Expand Down Expand Up @@ -187,6 +208,11 @@ _ostree_bootloader_syslinux_write_config (OstreeBootloader *bootloader,
g_free (kernel_arg);
kernel_arg = g_strdup (line + strlen ("\tKERNEL "));
}
else if (parsing_label && g_str_has_prefix (line, "\tLINUX "))
{
g_free (kernel_arg);
kernel_arg = g_strdup (line + strlen ("\tLINUX "));
}
else if (!parsing_label &&
(g_str_has_prefix (line, "DEFAULT ")))
{
Expand Down
2 changes: 2 additions & 0 deletions tests/bootloader-entries-crosscheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ def validate_syslinux(sysroot):
syslinux_entry['title'] = v
elif k == 'KERNEL':
syslinux_entry['linux'] = v
elif k == 'LINUX':
syslinux_entry['linux'] = v
elif k == 'INITRD':
syslinux_entry['initrd'] = v
elif k == 'APPEND':
Expand Down