mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-12-23 17:34:00 +03:00
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:
parent
e83419d043
commit
1b20d88987
@ -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;
|
||||
}
|
||||
|
@ -51,3 +51,5 @@ static inline const char* boot_entry_title(const BootEntry *entry) {
|
||||
}
|
||||
|
||||
int find_esp_and_warn(const char *path, bool unprivileged_mode, char **ret_path, uint32_t *ret_part, uint64_t *ret_pstart, uint64_t *ret_psize, sd_id128_t *ret_uuid);
|
||||
|
||||
int find_default_boot_entry(const char *esp_path, char **esp_where, BootConfig *config, const BootEntry **e);
|
||||
|
@ -3455,21 +3455,12 @@ static int load_kexec_kernel(void) {
|
||||
if (access(KEXEC, X_OK) < 0)
|
||||
return log_error_errno(errno, KEXEC" is not available: %m");
|
||||
|
||||
r = find_esp_and_warn(arg_esp_path, false, &where, NULL, NULL, NULL, NULL);
|
||||
if (r == -ENOKEY) /* find_esp_and_warn() doesn't warn about this case */
|
||||
r = find_default_boot_entry(arg_esp_path, &where, &config, &e);
|
||||
if (r == -ENOKEY) /* find_default_boot_entry() 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 = 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];
|
||||
/* But it logs about all these cases, hence don't log here again */
|
||||
return r;
|
||||
|
||||
if (strv_length(e->initrd) > 1) {
|
||||
log_error("Boot entry specifies multiple initrds, which is not supported currently.");
|
||||
|
Loading…
Reference in New Issue
Block a user