From f40999f87803cf456094ba42ca5f83d7bee059c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 5 Mar 2019 13:56:18 +0100 Subject: [PATCH 1/3] shared/bootspec: minor simplification --- src/shared/bootspec.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/src/shared/bootspec.c b/src/shared/bootspec.c index 39a7a97b128..59447d03b48 100644 --- a/src/shared/bootspec.c +++ b/src/shared/bootspec.c @@ -694,17 +694,12 @@ int boot_entries_load_config_auto( * want to. */ if (!override_esp_path && !override_xbootldr_path) { + if (access("/run/boot-loader-entries/", F_OK) >= 0) + return boot_entries_load_config("/run/boot-loader-entries/", NULL, config); - 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; - } + if (errno != ENOENT) + return log_error_errno(errno, + "Failed to determine whether /run/boot-loader-entries/ exists: %m"); } r = find_esp_and_warn(override_esp_path, false, &esp_where, NULL, NULL, NULL, NULL); @@ -717,11 +712,7 @@ int boot_entries_load_config_auto( 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; + return boot_entries_load_config(esp_where, xbootldr_where, config); } int boot_entries_augment_from_loader(BootConfig *config, bool only_auto) { From 1f18d9421538682dc44e5852fb9618203facbb8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 6 Mar 2019 22:45:37 +0100 Subject: [PATCH 2/3] shared/bootspec: treat empty EFI vars as missing We shouldn't really make any fuss about this. Also, change 'var' to 'variable' for consistency with systemctl.c. --- src/shared/bootspec.c | 8 ++++---- src/shared/efivars.c | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/shared/bootspec.c b/src/shared/bootspec.c index 59447d03b48..fea8eb830af 100644 --- a/src/shared/bootspec.c +++ b/src/shared/bootspec.c @@ -664,12 +664,12 @@ int boot_entries_load_config( if (is_efi_boot()) { r = efi_get_variable_string(EFI_VENDOR_LOADER, "LoaderEntryOneShot", &config->entry_oneshot); - if (r < 0 && r != -ENOENT) - return log_error_errno(r, "Failed to read EFI var \"LoaderEntryOneShot\": %m"); + if (r < 0 && !IN_SET(r, -ENOENT, -ENODATA)) + return log_error_errno(r, "Failed to read EFI variable \"LoaderEntryOneShot\": %m"); r = efi_get_variable_string(EFI_VENDOR_LOADER, "LoaderEntryDefault", &config->entry_default); - if (r < 0 && r != -ENOENT) - return log_error_errno(r, "Failed to read EFI var \"LoaderEntryDefault\": %m"); + if (r < 0 && !IN_SET(r, -ENOENT, -ENODATA)) + return log_error_errno(r, "Failed to read EFI variable \"LoaderEntryDefault\": %m"); } config->default_entry = boot_entries_select_default(config); diff --git a/src/shared/efivars.c b/src/shared/efivars.c index caae7b91386..885f03118a5 100644 --- a/src/shared/efivars.c +++ b/src/shared/efivars.c @@ -223,7 +223,7 @@ int efi_get_variable( if (fstat(fd, &st) < 0) return -errno; if (st.st_size < 4) - return -EIO; + return -ENODATA; if (st.st_size > 4*1024*1024 + 4) return -E2BIG; From bd29f9de69a369654d3cad13529224df9157d785 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 6 Mar 2019 22:49:52 +0100 Subject: [PATCH 3/3] shared/bootspec: do not fail on errors when reading EFI vars It seems that my EFI storage is corrupted. The kernel reports the file as present, but returns an error when reading. Nevertheless, this shouldn't prevent me from reading the entry list. Fixes #11909. --- src/shared/bootspec.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/shared/bootspec.c b/src/shared/bootspec.c index fea8eb830af..afcf6f7ac13 100644 --- a/src/shared/bootspec.c +++ b/src/shared/bootspec.c @@ -664,12 +664,18 @@ int boot_entries_load_config( if (is_efi_boot()) { r = efi_get_variable_string(EFI_VENDOR_LOADER, "LoaderEntryOneShot", &config->entry_oneshot); - if (r < 0 && !IN_SET(r, -ENOENT, -ENODATA)) - return log_error_errno(r, "Failed to read EFI variable \"LoaderEntryOneShot\": %m"); + if (r < 0 && !IN_SET(r, -ENOENT, -ENODATA)) { + log_warning_errno(r, "Failed to read EFI variable \"LoaderEntryOneShot\": %m"); + if (r == -ENOMEM) + return r; + } r = efi_get_variable_string(EFI_VENDOR_LOADER, "LoaderEntryDefault", &config->entry_default); - if (r < 0 && !IN_SET(r, -ENOENT, -ENODATA)) - return log_error_errno(r, "Failed to read EFI variable \"LoaderEntryDefault\": %m"); + if (r < 0 && !IN_SET(r, -ENOENT, -ENODATA)) { + log_warning_errno(r, "Failed to read EFI variable \"LoaderEntryDefault\": %m"); + if (r == -ENOMEM) + return r; + } } config->default_entry = boot_entries_select_default(config);