Blame SOURCES/0210-blscfg-Fallback-to-search-BLS-snippets-in-boot-loade.patch

d9d99f
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
d9d99f
From: Javier Martinez Canillas <javierm@redhat.com>
d9d99f
Date: Wed, 18 Jul 2018 08:08:06 +0200
d9d99f
Subject: [PATCH] blscfg: Fallback to search BLS snippets in
d9d99f
 /boot/loader/entries
d9d99f
d9d99f
The default path to search the BLS snippets is /loader/entries, this is
d9d99f
only a correct assumption if $root ($root) is a boot partition but it's
d9d99f
not true if /boot isn't a mount point.
d9d99f
d9d99f
A user can set a blsdir grub environment variable to choose a different
d9d99f
path, but instead of failing when /boot is a directory inside the root
d9d99f
partition fallback to search the BLS in /boot/loader/entries to cover
d9d99f
that case as well.
d9d99f
d9d99f
Reported-by: Hans de Goede <hdegoede@redhat.com>
d9d99f
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
d9d99f
---
d9d99f
 grub-core/commands/blscfg.c | 13 ++++++++++++-
d9d99f
 1 file changed, 12 insertions(+), 1 deletion(-)
d9d99f
d9d99f
diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c
b71686
index 80d8814fc..321c93069 100644
d9d99f
--- a/grub-core/commands/blscfg.c
d9d99f
+++ b/grub-core/commands/blscfg.c
d9d99f
@@ -692,6 +692,7 @@ static int find_entry (const char *filename,
d9d99f
   grub_device_t blsdir_dev = NULL;
d9d99f
   const char *blsdir = NULL;
d9d99f
   char *saved_env_buf = NULL;
d9d99f
+  int fallback = 0;
d9d99f
   int r = 0;
d9d99f
   const char *devid = grub_env_get ("boot");
d9d99f
 
d9d99f
@@ -797,7 +798,9 @@ static int find_entry (const char *filename,
d9d99f
   }
d9d99f
   read_entry_info.dirname = blsdir;
d9d99f
 
d9d99f
-  r = blsdir_fs->dir (blsdir_dev, blsdir, read_entry, &read_entry_info);
d9d99f
+read_fallback:
d9d99f
+  r = blsdir_fs->dir (blsdir_dev, read_entry_info.dirname, read_entry,
d9d99f
+		      &read_entry_info);
d9d99f
   if (r != 0) {
d9d99f
       grub_dprintf ("blscfg", "read_entry returned error\n");
d9d99f
       grub_err_t e;
d9d99f
@@ -807,6 +810,14 @@ static int find_entry (const char *filename,
d9d99f
 	} while (e);
d9d99f
   }
d9d99f
 
d9d99f
+  if (!nentries && !fallback && info->platform != PLATFORM_EMU) {
d9d99f
+    read_entry_info.dirname = "/boot" GRUB_BLS_CONFIG_PATH;
d9d99f
+    grub_dprintf ("blscfg", "Entries weren't found in %s, fallback to %s\n",
d9d99f
+		  blsdir, read_entry_info.dirname);
d9d99f
+    fallback = 1;
d9d99f
+    goto read_fallback;
d9d99f
+  }
d9d99f
+
d9d99f
   grub_dprintf ("blscfg", "Sorting %d entries\n", nentries);
d9d99f
   grub_qsort(&entries[0], nentries, sizeof (struct bls_entry *), bls_cmp, NULL);
d9d99f