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

bootloader/grub2: Handle empty static configs #3300

Merged
merged 1 commit into from
Sep 15, 2024
Merged
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
10 changes: 7 additions & 3 deletions src/libostree/ostree-bootloader-grub2.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#define BOOTUPD_CONFIG "boot/bootupd-state.json"
// Horrible hack, to avoid including a JSON parser we just grep for this
#define BOOTUPD_CONFIG_STATIC_JSON_FRAGMENT "\"static-configs\""
#define BOOTUPD_CONFIG_STATIC_JSON_FRAGMENT_NULL "\"static-configs\":null"
Copy link
Member

Choose a reason for hiding this comment

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

Ouch 😢

I dunno, maybe overdue for us to link in a json library, I had just hoped to do that with rust (that's in #3054 but nontrivial)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I agree it's really not great :/


/* Maintain backwards compatibility with legacy GRUB
* installations that might rely on the -16 suffix
Expand Down Expand Up @@ -90,9 +91,12 @@ _ostree_bootloader_grub2_query (OstreeBootloader *bootloader, gboolean *out_is_a
return glnx_prefix_error (error, "Failed to read bootupd config");
if (strstr (bootupd_config_contents, BOOTUPD_CONFIG_STATIC_JSON_FRAGMENT) != NULL)
{
g_debug ("Found static bootupd config");
*out_is_active = FALSE;
return TRUE;
if (strstr (bootupd_config_contents, BOOTUPD_CONFIG_STATIC_JSON_FRAGMENT_NULL) == NULL)
{
g_debug ("Found static bootupd config");
*out_is_active = FALSE;
return TRUE;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/kolainst/destructive/bootupd-static.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ bootupd_state=/boot/bootupd-state.json
mount -o remount,rw /boot
if grep -qFe "\"static-configs\"" "${bootupd_state}"; then
echo "Host is using static configs already, overriding this"
jq 'del(.["static-configs"])' < "${bootupd_state}" > "${bootupd_state}".new
jq --compact-output '.["static-configs"] = null' < "${bootupd_state}" > "${bootupd_state}".new
mv "${bootupd_state}.new" "${bootupd_state}"
fi

Expand Down
Loading