summaryrefslogtreecommitdiff
path: root/src/shared/bootspec.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2019-03-04 17:52:17 +0100
committerLennart Poettering <lennart@poettering.net>2019-03-05 16:50:58 +0100
commiteea4ce1ec716948c1f67d9c541de0c77082401a7 (patch)
tree05d468f7549772fdcf9a7f21c955bb6a8cd1e0b4 /src/shared/bootspec.c
parentdba33c4a2c53f1dca6edc1661b608f2c52ba6465 (diff)
downloadsystemd-eea4ce1ec716948c1f67d9c541de0c77082401a7.tar.gz
bootspec: introduce new helper boot_entries_load_config_auto()
It's a simple wrapper around boot_entries_load_config(), but determines the ESP/XBOOTLDR paths automatically at first. Also, it looks for a path /run/boot-loader-entries/ and loads the entries from there if it exists. This is supposed to be a hook for other boot loaders to make our tools aware of their own entries.
Diffstat (limited to 'src/shared/bootspec.c')
-rw-r--r--src/shared/bootspec.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/shared/bootspec.c b/src/shared/bootspec.c
index 4ebb221a42..c6aa2c0f8b 100644
--- a/src/shared/bootspec.c
+++ b/src/shared/bootspec.c
@@ -670,6 +670,54 @@ int boot_entries_load_config(
return 0;
}
+int boot_entries_load_config_auto(
+ const char *override_esp_path,
+ const char *override_xbootldr_path,
+ BootConfig *config) {
+
+ _cleanup_free_ char *esp_where = NULL, *xbootldr_where = NULL;
+ int r;
+
+ assert(config);
+
+ /* This function is similar to boot_entries_load_config(), however we automatically search for the
+ * ESP and the XBOOTLDR partition unless it is explicitly specified. Also, if the user did not pass
+ * an ESP or XBOOTLDR path directly, let's see if /run/boot-loader-entries/ exists. If so, let's
+ * read data from there, as if it was an ESP (i.e. loading both entries and loader.conf data from
+ * it). This allows other boot loaders to pass boot loader entry information to our tools if they
+ * want to. */
+
+ if (!override_esp_path && !override_xbootldr_path) {
+
+ if (access("/run/boot-loader-entries/", F_OK) < 0) {
+ if (errno != ENOENT)
+ return log_error_errno(errno, "Failed to determine whether /run/boot-loader-entries/ exists: %m");
+ } else {
+ r = boot_entries_load_config("/run/boot-loader-entries/", NULL, config);
+ if (r < 0)
+ return r;
+
+ return 0;
+ }
+ }
+
+ r = find_esp_and_warn(override_esp_path, false, &esp_where, NULL, NULL, NULL, NULL);
+ if (r == -ENOKEY) /* find_esp_and_warn() doesn't warn about this case */
+ return log_error_errno(r, "Cannot find the ESP partition mount point.");
+ if (r < 0) /* But it logs about all these cases, hence don't log here again */
+ return r;
+
+ r = find_xbootldr_and_warn(override_xbootldr_path, false, &xbootldr_where, NULL);
+ if (r < 0 && r != -ENOKEY)
+ return r; /* It's fine if the XBOOTLDR partition doesn't exist, hence we ignore ENOKEY here */
+
+ r = boot_entries_load_config(esp_where, xbootldr_where, config);
+ if (r < 0)
+ return r;
+
+ return 0;
+}
+
int boot_entries_augment_from_loader(BootConfig *config, bool only_auto) {
static const char * const title_table[] = {