]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
efivars: allow to override is_efi_boot()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 21 Jan 2026 10:27:01 +0000 (19:27 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 13 Feb 2026 07:08:23 +0000 (16:08 +0900)
src/basic/efivars.c
src/basic/efivars.h

index a655382af847c1b24da39824f9bd93deefe38844..0eeee1038efc09a2cb399d45636730e8a8c93d1d 100644 (file)
@@ -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));
 }
 
+static int cache_efi_boot = -1;
+
+bool set_efi_boot(bool b) {
+        return (cache_efi_boot = b);
+}
+
 bool is_efi_boot(void) {
-        static int cache = -1;
+        if (cache_efi_boot >= 0)
+                return cache_efi_boot;
 
-        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");
-                }
+        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) {
index eeccbb180675617f8830674a914002bc0f4154f0..22e0eab9a0afa47af7d31c0df63c1a59ce274b5e 100644 (file)
@@ -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;
 }