bootctl: override is_efi_boot() check by --variables= option (#40413)
Fixes #40392.
This commit is contained in:
+17
-11
@@ -319,20 +319,26 @@ int efi_set_variable_string(const char *variable, const char *value) {
|
||||
return efi_set_variable(variable, u16, (char16_strlen(u16) + 1) * sizeof(char16_t));
|
||||
}
|
||||
|
||||
bool is_efi_boot(void) {
|
||||
static int cache = -1;
|
||||
static int cache_efi_boot = -1;
|
||||
|
||||
if (cache < 0) {
|
||||
if (detect_container() > 0)
|
||||
cache = false;
|
||||
else {
|
||||
cache = access("/sys/firmware/efi/", F_OK) >= 0;
|
||||
if (!cache && errno != ENOENT)
|
||||
log_debug_errno(errno, "Unable to test whether /sys/firmware/efi/ exists, assuming EFI not available: %m");
|
||||
}
|
||||
bool set_efi_boot(bool b) {
|
||||
return (cache_efi_boot = b);
|
||||
}
|
||||
|
||||
bool is_efi_boot(void) {
|
||||
if (cache_efi_boot >= 0)
|
||||
return cache_efi_boot;
|
||||
|
||||
if (detect_container() > 0)
|
||||
return (cache_efi_boot = false);
|
||||
|
||||
if (access("/sys/firmware/efi/", F_OK) < 0) {
|
||||
if (errno != ENOENT)
|
||||
log_debug_errno(errno, "Unable to test whether /sys/firmware/efi/ exists, assuming EFI not available: %m");
|
||||
return (cache_efi_boot = false);
|
||||
}
|
||||
|
||||
return cache;
|
||||
return (cache_efi_boot = true);
|
||||
}
|
||||
|
||||
static int read_flag(const char *variable) {
|
||||
|
||||
@@ -45,6 +45,7 @@ int efi_get_variable_path(const char *variable, char **ret);
|
||||
int efi_set_variable(const char *variable, const void *value, size_t size) _nonnull_if_nonzero_(2, 3);
|
||||
int efi_set_variable_string(const char *variable, const char *value);
|
||||
|
||||
bool set_efi_boot(bool b);
|
||||
bool is_efi_boot(void);
|
||||
bool is_efi_secure_boot(void);
|
||||
SecureBootMode efi_get_secure_boot_mode(void);
|
||||
@@ -71,6 +72,10 @@ static inline int efi_set_variable_string(const char *variable, const char *p) {
|
||||
return -EOPNOTSUPP;
|
||||
}
|
||||
|
||||
static inline bool set_efi_boot(bool b) {
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline bool is_efi_boot(void) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user