Move logic to find default sd-boot entry from systemctl to shared

In preparation for use in other places. No functional change.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2018-10-08 16:06:26 +02:00
parent e83419d043
commit 1b20d88987
3 changed files with 39 additions and 13 deletions
+33
View File
@@ -598,3 +598,36 @@ found:
return 0;
}
int find_default_boot_entry(
const char *esp_path,
char **esp_where,
BootConfig *config,
const BootEntry **e) {
_cleanup_free_ char *where = NULL;
int r;
assert(config);
assert(e);
r = find_esp_and_warn(esp_path, false, &where, NULL, NULL, NULL, NULL);
if (r < 0)
return r;
r = boot_entries_load_config(where, config);
if (r < 0)
return log_error_errno(r, "Failed to load bootspec config from \"%s/loader\": %m", where);
if (config->default_entry < 0) {
log_error("No entry suitable as default, refusing to guess.");
return -ENOENT;
}
*e = &config->entries[config->default_entry];
if (esp_where)
*esp_where = TAKE_PTR(where);
return 0;
}