logind: also cache LoaderEntryOneShot EFI variable

With this we are now caching all EFI variables that we expose as
property in logind. Thus a client invoking GetAllProperties() should
only trgger a single read of each variable, but never repeated ones.

Obsoletes: #16190
Fixes: #14828
This commit is contained in:
Lennart Poettering
2020-06-26 10:43:42 +02:00
parent e8df4eee65
commit af2697e83d
5 changed files with 56 additions and 12 deletions
+32
View File
@@ -772,3 +772,35 @@ int efi_loader_get_config_timeout_one_shot(usec_t *ret) {
*ret = cache = sec * USEC_PER_SEC; /* return in µs */
return 0;
}
int efi_loader_update_entry_one_shot_cache(char **cache, struct stat *cache_stat) {
_cleanup_free_ char *fn = NULL, *v = NULL;
struct stat new_stat;
int r;
assert(cache);
assert(cache_stat);
fn = efi_variable_path(EFI_VENDOR_LOADER, "LoaderEntryOneShot");
if (!fn)
return -ENOMEM;
/* stat() the EFI variable, to see if the mtime changed. If it did we need to cache again. */
if (stat(fn, &new_stat) < 0)
return -errno;
if (stat_inode_unmodified(&new_stat, cache_stat))
return 0;
r = efi_get_variable_string(EFI_VENDOR_LOADER, "LoaderEntryOneShot", &v);
if (r < 0)
return r;
if (!efi_loader_entry_name_valid(v))
return -EINVAL;
*cache_stat = new_stat;
free_and_replace(*cache, v);
return 0;
}
+7
View File
@@ -3,6 +3,8 @@
#include "efivars.h"
#include <sys/stat.h>
#if ENABLE_EFI
int efi_reboot_to_firmware_supported(void);
@@ -24,6 +26,7 @@ int efi_loader_get_entries(char ***ret);
int efi_loader_get_features(uint64_t *ret);
int efi_loader_get_config_timeout_one_shot(usec_t *ret);
int efi_loader_update_entry_one_shot_cache(char **cache, struct stat *cache_stat);
#else
@@ -83,6 +86,10 @@ static inline int efi_loader_get_config_timeout_one_shot(usec_t *ret) {
return -EOPNOTSUPP;
}
static inline int efi_loader_update_entry_one_shot_cache(char **cache, struct stat *cache_stat) {
return -EOPNOTSUPP;
}
#endif
bool efi_loader_entry_name_valid(const char *s);