From: Lennart Poettering Date: Mon, 4 Mar 2019 17:02:30 +0000 (+0100) Subject: bootspec: get rid of find_default_boot_entry() entirely X-Git-Tag: v242-rc1~192^2~6 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=38bd74d67e5d2f2c12b1135ff6872544fe944a3f;p=thirdparty%2Fsystemd.git bootspec: get rid of find_default_boot_entry() entirely Now only two operations are left. Let's just move this into the caller, since it should make things simpler, clearer and shorter, in particular as there's only a single user for this. --- diff --git a/src/shared/bootspec.c b/src/shared/bootspec.c index 4e73e6d4abf..03f86297354 100644 --- a/src/shared/bootspec.c +++ b/src/shared/bootspec.c @@ -1412,29 +1412,6 @@ found: return 0; } -int find_default_boot_entry( - BootConfig *config, - const BootEntry **e) { - - int r; - - assert(config); - assert(e); - - r = boot_entries_load_config_auto(NULL, NULL, config); - if (r < 0) - return r; - - if (config->default_entry < 0) - return log_error_errno(SYNTHETIC_ERRNO(ENOENT), - "No boot loader entry suitable as default, refusing to guess."); - - *e = &config->entries[config->default_entry]; - log_debug("Found default boot loader entry in file \"%s\"", (*e)->path); - - return 0; -} - static const char* const boot_entry_type_table[_BOOT_ENTRY_MAX] = { [BOOT_ENTRY_CONF] = "conf", [BOOT_ENTRY_UNIFIED] = "unified", diff --git a/src/shared/bootspec.h b/src/shared/bootspec.h index b77497085ed..45e1fc37c65 100644 --- a/src/shared/bootspec.h +++ b/src/shared/bootspec.h @@ -61,6 +61,13 @@ static inline bool boot_config_has_entry(BootConfig *config, const char *id) { return false; } +static inline BootEntry* boot_config_default_entry(BootConfig *config) { + if (config->default_entry < 0) + return NULL; + + return config->entries + config->default_entry; +} + void boot_config_free(BootConfig *config); int boot_entries_load_config(const char *esp_path, const char *xbootldr_path, BootConfig *config); int boot_entries_load_config_auto(const char *override_esp_path, const char *override_xbootldr_path, BootConfig *config); @@ -73,7 +80,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_xbootldr_and_warn(const char *path, bool unprivileged_mode, char **ret_path,sd_id128_t *ret_uuid); -int find_default_boot_entry(BootConfig *config, const BootEntry **e); - const char* boot_entry_type_to_string(BootEntryType t) _const_; BootEntryType boot_entry_type_from_string(const char *s) _pure_; diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index d88435f8e97..9c67a69c231 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -3535,10 +3535,17 @@ static int load_kexec_kernel(void) { if (access(KEXEC, X_OK) < 0) return log_error_errno(errno, KEXEC" is not available: %m"); - r = find_default_boot_entry(&config, &e); + r = boot_entries_load_config_auto(NULL, NULL, &config); if (r < 0) return r; + e = boot_config_default_entry(&config); + if (!e) + return log_error_errno(SYNTHETIC_ERRNO(ENOENT), + "No boot loader entry suitable as default, refusing to guess."); + + log_debug("Found default boot loader entry in file \"%s\"", e->path); + if (!e->kernel) return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "Boot entry does not refer to Linux kernel, which is not supported currently.");