summaryrefslogtreecommitdiffstats
path: root/src/basic/efivars.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2020-04-28 23:33:46 +0200
committerLennart Poettering <lennart@poettering.net>2020-04-30 08:10:31 +0200
commitf46ba93944aac3f05211e0d630cdf84955eba2d8 (patch)
tree408c1e1b7f089b63ea8a73d0f82152b7a7c95bf4 /src/basic/efivars.c
parentMerge pull request #15630 from nabijaczleweli/symmetric-buffers (diff)
downloadsystemd-f46ba93944aac3f05211e0d630cdf84955eba2d8.tar.xz
systemd-f46ba93944aac3f05211e0d630cdf84955eba2d8.zip
efi: cache test results of boolean EFI state functions
EFI variable access is nowadays subject to rate limiting by the kernel. Thus, let's cache the results of checking them, in order to minimize how often we access them. Fixes: #14828
Diffstat (limited to 'src/basic/efivars.c')
-rw-r--r--src/basic/efivars.c26
1 files changed, 21 insertions, 5 deletions
diff --git a/src/basic/efivars.c b/src/basic/efivars.c
index aa08ad2e27..b79ca8efd7 100644
--- a/src/basic/efivars.c
+++ b/src/basic/efivars.c
@@ -244,10 +244,16 @@ int efi_set_variable_string(sd_id128_t vendor, const char *name, const char *v)
}
bool is_efi_boot(void) {
- if (detect_container() > 0)
- return false;
+ static int cache = -1;
- return access("/sys/firmware/efi/", F_OK) >= 0;
+ if (cache < 0) {
+ if (detect_container() > 0)
+ cache = false;
+ else
+ cache = access("/sys/firmware/efi/", F_OK) >= 0;
+ }
+
+ return cache;
}
static int read_flag(const char *varname) {
@@ -271,11 +277,21 @@ static int read_flag(const char *varname) {
}
bool is_efi_secure_boot(void) {
- return read_flag("SecureBoot") > 0;
+ static int cache = -1;
+
+ if (cache < 0)
+ cache = read_flag("SecureBoot");
+
+ return cache > 0;
}
bool is_efi_secure_boot_setup_mode(void) {
- return read_flag("SetupMode") > 0;
+ static int cache = -1;
+
+ if (cache < 0)
+ cache = read_flag("SetupMode");
+
+ return cache > 0;
}
int systemd_efi_options_variable(char **line) {