bootloader/grub2: Handle empty static configs
authorTimothée Ravier <tim@siosm.fr>
Fri, 13 Sep 2024 17:14:43 +0000 (19:14 +0200)
committerTimothée Ravier <tim@siosm.fr>
Fri, 13 Sep 2024 22:34:24 +0000 (00:34 +0200)
In #3205, we introduced a check to skip re-generating the GRUB config if
we detect that static configs are in used by looking at bootupd's state.

Unfortunately this check is incomplete and does not account for present
but null entries in the JSON state file.

A proper fix would be to parse the JSON but this requires a larger code
change.

Fixes: https://github.com/ostreedev/ostree/issues/3295
Fixes: https://github.com/ostreedev/ostree/pull/3205
src/libostree/ostree-bootloader-grub2.c
tests/kolainst/destructive/bootupd-static.sh

index e15fb9b6591bd6856c1f759437a6547c0feb8e77..f2d73d33b4c5baec5b0e5a7410883d9be18710bf 100644 (file)
@@ -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"
 
 /* Maintain backwards compatibility with legacy GRUB
  * installations that might rely on the -16 suffix
@@ -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;
+            }
         }
     }
 
index cf8368130ae088fd7b82790027b63196fb0471ab..670178e47dae29c7dbcab4476a996f6a8f7a0b87 100755 (executable)
@@ -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