mirror of
https://github.com/systemd/systemd.git
synced 2025-03-29 06:50:16 +03:00
boot: introduce _cleanup_file_close_
This commit is contained in:
parent
892b734c1c
commit
6ea99fd2cf
@ -1374,7 +1374,7 @@ static void boot_entry_parse_tries(
|
||||
|
||||
static EFI_STATUS boot_entry_bump_counters(BootEntry *entry) {
|
||||
_cleanup_free_ char16_t* old_path = NULL, *new_path = NULL;
|
||||
_cleanup_(file_closep) EFI_FILE *handle = NULL;
|
||||
_cleanup_file_close_ EFI_FILE *handle = NULL;
|
||||
_cleanup_free_ EFI_FILE_INFO *file_info = NULL;
|
||||
size_t file_info_size;
|
||||
EFI_STATUS err;
|
||||
@ -1387,7 +1387,7 @@ static EFI_STATUS boot_entry_bump_counters(BootEntry *entry) {
|
||||
if (!entry->path || !entry->current_name || !entry->next_name)
|
||||
return EFI_SUCCESS;
|
||||
|
||||
_cleanup_(file_closep) EFI_FILE *root = NULL;
|
||||
_cleanup_file_close_ EFI_FILE *root = NULL;
|
||||
err = open_volume(entry->device, &root);
|
||||
if (err != EFI_SUCCESS)
|
||||
return log_error_status(err, "Error opening entry root path: %m");
|
||||
@ -1525,7 +1525,7 @@ static void boot_entry_add_type1(
|
||||
return;
|
||||
|
||||
/* check existence */
|
||||
_cleanup_(file_closep) EFI_FILE *handle = NULL;
|
||||
_cleanup_file_close_ EFI_FILE *handle = NULL;
|
||||
err = root_dir->Open(root_dir, &handle, entry->loader, EFI_FILE_MODE_READ, 0ULL);
|
||||
if (err != EFI_SUCCESS)
|
||||
return;
|
||||
@ -1652,7 +1652,7 @@ static void config_load_type1_entries(
|
||||
EFI_FILE *root_dir,
|
||||
const char16_t *loaded_image_path) {
|
||||
|
||||
_cleanup_(file_closep) EFI_FILE *entries_dir = NULL;
|
||||
_cleanup_file_close_ EFI_FILE *entries_dir = NULL;
|
||||
_cleanup_free_ EFI_FILE_INFO *f = NULL;
|
||||
size_t f_size = 0;
|
||||
EFI_STATUS err;
|
||||
@ -1907,7 +1907,7 @@ static bool is_sd_boot(EFI_FILE *root_dir, const char16_t *loader_path) {
|
||||
assert(root_dir);
|
||||
assert(loader_path);
|
||||
|
||||
_cleanup_(file_closep) EFI_FILE *handle = NULL;
|
||||
_cleanup_file_close_ EFI_FILE *handle = NULL;
|
||||
err = root_dir->Open(root_dir, &handle, (char16_t *) loader_path, EFI_FILE_MODE_READ, 0ULL);
|
||||
if (err != EFI_SUCCESS)
|
||||
return false;
|
||||
@ -1970,7 +1970,7 @@ static BootEntry* config_add_entry_loader_auto(
|
||||
}
|
||||
|
||||
/* check existence */
|
||||
_cleanup_(file_closep) EFI_FILE *handle = NULL;
|
||||
_cleanup_file_close_ EFI_FILE *handle = NULL;
|
||||
EFI_STATUS err = root_dir->Open(root_dir, &handle, (char16_t *) loader, EFI_FILE_MODE_READ, 0ULL);
|
||||
if (err != EFI_SUCCESS)
|
||||
return NULL;
|
||||
@ -2007,7 +2007,7 @@ static void config_add_entry_osx(Config *config) {
|
||||
return;
|
||||
|
||||
for (size_t i = 0; i < n_handles; i++) {
|
||||
_cleanup_(file_closep) EFI_FILE *root = NULL;
|
||||
_cleanup_file_close_ EFI_FILE *root = NULL;
|
||||
|
||||
if (open_volume(handles[i], &root) != EFI_SUCCESS)
|
||||
continue;
|
||||
@ -2164,7 +2164,7 @@ static void boot_entry_add_type2(
|
||||
assert(path);
|
||||
assert(filename);
|
||||
|
||||
_cleanup_(file_closep) EFI_FILE *handle = NULL;
|
||||
_cleanup_file_close_ EFI_FILE *handle = NULL;
|
||||
err = dir->Open(dir, &handle, (char16_t *) filename, EFI_FILE_MODE_READ, 0ULL);
|
||||
if (err != EFI_SUCCESS)
|
||||
return;
|
||||
@ -2364,7 +2364,7 @@ static void config_load_type2_entries(
|
||||
EFI_HANDLE *device,
|
||||
EFI_FILE *root_dir) {
|
||||
|
||||
_cleanup_(file_closep) EFI_FILE *linux_dir = NULL;
|
||||
_cleanup_file_close_ EFI_FILE *linux_dir = NULL;
|
||||
_cleanup_free_ EFI_FILE_INFO *f = NULL;
|
||||
size_t f_size = 0;
|
||||
EFI_STATUS err;
|
||||
@ -2403,7 +2403,7 @@ static void config_load_xbootldr(
|
||||
Config *config,
|
||||
EFI_HANDLE *device) {
|
||||
|
||||
_cleanup_(file_closep) EFI_FILE *root_dir = NULL;
|
||||
_cleanup_file_close_ EFI_FILE *root_dir = NULL;
|
||||
EFI_HANDLE new_device = NULL; /* avoid false maybe-uninitialized warning */
|
||||
EFI_STATUS err;
|
||||
|
||||
@ -2455,7 +2455,7 @@ static EFI_STATUS initrd_prepare(
|
||||
else
|
||||
options = xasprintf("initrd=%ls", *i);
|
||||
|
||||
_cleanup_(file_closep) EFI_FILE *handle = NULL;
|
||||
_cleanup_file_close_ EFI_FILE *handle = NULL;
|
||||
err = root->Open(root, &handle, *i, EFI_FILE_MODE_READ, 0);
|
||||
if (err != EFI_SUCCESS)
|
||||
return err;
|
||||
@ -2476,7 +2476,7 @@ static EFI_STATUS initrd_prepare(
|
||||
uint8_t *p = PHYSICAL_ADDRESS_TO_POINTER(pages.addr);
|
||||
|
||||
STRV_FOREACH(i, entry->initrd) {
|
||||
_cleanup_(file_closep) EFI_FILE *handle = NULL;
|
||||
_cleanup_file_close_ EFI_FILE *handle = NULL;
|
||||
err = root->Open(root, &handle, *i, EFI_FILE_MODE_READ, 0);
|
||||
if (err != EFI_SUCCESS)
|
||||
return err;
|
||||
@ -2539,7 +2539,7 @@ static EFI_STATUS image_start(
|
||||
if (entry->call)
|
||||
(void) entry->call();
|
||||
|
||||
_cleanup_(file_closep) EFI_FILE *image_root = NULL;
|
||||
_cleanup_file_close_ EFI_FILE *image_root = NULL;
|
||||
err = open_volume(entry->device, &image_root);
|
||||
if (err != EFI_SUCCESS)
|
||||
return log_error_status(err, "Error opening root path: %m");
|
||||
@ -2697,7 +2697,7 @@ static void save_selected_entry(const Config *config, const BootEntry *entry) {
|
||||
|
||||
static EFI_STATUS secure_boot_discover_keys(Config *config, EFI_FILE *root_dir) {
|
||||
EFI_STATUS err;
|
||||
_cleanup_(file_closep) EFI_FILE *keys_basedir = NULL;
|
||||
_cleanup_file_close_ EFI_FILE *keys_basedir = NULL;
|
||||
|
||||
if (!IN_SET(secure_boot_mode(), SECURE_BOOT_SETUP, SECURE_BOOT_AUDIT))
|
||||
return EFI_SUCCESS;
|
||||
@ -2869,7 +2869,7 @@ static EFI_STATUS discover_root_dir(EFI_LOADED_IMAGE_PROTOCOL *loaded_image, EFI
|
||||
|
||||
static EFI_STATUS run(EFI_HANDLE image) {
|
||||
EFI_LOADED_IMAGE_PROTOCOL *loaded_image;
|
||||
_cleanup_(file_closep) EFI_FILE *root_dir = NULL;
|
||||
_cleanup_file_close_ EFI_FILE *root_dir = NULL;
|
||||
_cleanup_(config_free) Config config = {};
|
||||
EFI_STATUS err;
|
||||
uint64_t init_usec;
|
||||
|
@ -314,7 +314,7 @@ EFI_STATUS pack_cpio(
|
||||
struct iovec *ret_buffer,
|
||||
bool *ret_measured) {
|
||||
|
||||
_cleanup_(file_closep) EFI_FILE *root = NULL, *extra_dir = NULL;
|
||||
_cleanup_file_close_ EFI_FILE *root = NULL, *extra_dir = NULL;
|
||||
size_t dirent_size = 0, buffer_size = 0, n_items = 0, n_allocated = 0;
|
||||
_cleanup_free_ char16_t *rel_dropin_dir = NULL;
|
||||
_cleanup_free_ EFI_FILE_INFO *dirent = NULL;
|
||||
|
@ -63,7 +63,7 @@ static EFI_STATUS devicetree_fixup(struct devicetree_state *state, size_t len) {
|
||||
}
|
||||
|
||||
EFI_STATUS devicetree_install(struct devicetree_state *state, EFI_FILE *root_dir, char16_t *name) {
|
||||
_cleanup_(file_closep) EFI_FILE *handle = NULL;
|
||||
_cleanup_file_close_ EFI_FILE *handle = NULL;
|
||||
_cleanup_free_ EFI_FILE_INFO *info = NULL;
|
||||
size_t len;
|
||||
EFI_STATUS err;
|
||||
|
@ -73,7 +73,7 @@ EFI_STATUS load_drivers(
|
||||
EFI_LOADED_IMAGE_PROTOCOL *loaded_image,
|
||||
EFI_FILE *root_dir) {
|
||||
|
||||
_cleanup_(file_closep) EFI_FILE *drivers_dir = NULL;
|
||||
_cleanup_file_close_ EFI_FILE *drivers_dir = NULL;
|
||||
_cleanup_free_ EFI_FILE_INFO *dirent = NULL;
|
||||
size_t dirent_size = 0, n_succeeded = 0;
|
||||
EFI_STATUS err;
|
||||
|
@ -121,7 +121,7 @@ EFI_STATUS process_random_seed(EFI_FILE *root_dir) {
|
||||
_cleanup_free_ struct linux_efi_random_seed *new_seed_table = NULL;
|
||||
struct linux_efi_random_seed *previous_seed_table = NULL;
|
||||
_cleanup_free_ void *seed = NULL, *system_token = NULL;
|
||||
_cleanup_(file_closep) EFI_FILE *handle = NULL;
|
||||
_cleanup_file_close_ EFI_FILE *handle = NULL;
|
||||
_cleanup_free_ EFI_FILE_INFO *info = NULL;
|
||||
struct sha256_ctx hash;
|
||||
uint64_t uefi_monotonic_counter = 0;
|
||||
|
@ -115,7 +115,7 @@ EFI_STATUS secure_boot_enroll_at(EFI_FILE *root_dir, const char16_t *path, bool
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
_cleanup_(file_closep) EFI_FILE *dir = NULL;
|
||||
_cleanup_file_close_ EFI_FILE *dir = NULL;
|
||||
|
||||
err = open_directory(root_dir, path, &dir);
|
||||
if (err != EFI_SUCCESS)
|
||||
|
@ -56,7 +56,7 @@ static bool shim_validate(
|
||||
if (err != EFI_SUCCESS)
|
||||
return false;
|
||||
|
||||
_cleanup_(file_closep) EFI_FILE *root = NULL;
|
||||
_cleanup_file_close_ EFI_FILE *root = NULL;
|
||||
err = open_volume(device_handle, &root);
|
||||
if (err != EFI_SUCCESS)
|
||||
return false;
|
||||
|
@ -294,7 +294,7 @@ static EFI_STATUS load_addons_from_dir(
|
||||
size_t *n_items,
|
||||
size_t *n_allocated) {
|
||||
|
||||
_cleanup_(file_closep) EFI_FILE *extra_dir = NULL;
|
||||
_cleanup_file_close_ EFI_FILE *extra_dir = NULL;
|
||||
_cleanup_free_ EFI_FILE_INFO *dirent = NULL;
|
||||
size_t dirent_size = 0;
|
||||
EFI_STATUS err;
|
||||
@ -548,7 +548,7 @@ static EFI_STATUS load_addons(
|
||||
size_t *n_ucode_addons) {
|
||||
|
||||
_cleanup_(strv_freep) char16_t **items = NULL;
|
||||
_cleanup_(file_closep) EFI_FILE *root = NULL;
|
||||
_cleanup_file_close_ EFI_FILE *root = NULL;
|
||||
size_t n_items = 0, n_allocated = 0;
|
||||
EFI_STATUS err;
|
||||
|
||||
@ -718,7 +718,7 @@ static void refresh_random_seed(EFI_LOADED_IMAGE_PROTOCOL *loaded_image) {
|
||||
if (FLAGS_SET(loader_features, EFI_LOADER_FEATURE_RANDOM_SEED))
|
||||
return;
|
||||
|
||||
_cleanup_(file_closep) EFI_FILE *esp_dir = NULL;
|
||||
_cleanup_file_close_ EFI_FILE *esp_dir = NULL;
|
||||
err = partition_open(MAKE_GUID_PTR(ESP), loaded_image->DeviceHandle, NULL, &esp_dir);
|
||||
if (err != EFI_SUCCESS) /* Non-fatal on failure, so that we still boot without it. */
|
||||
return;
|
||||
|
@ -172,7 +172,7 @@ EFI_STATUS file_read(
|
||||
assert(name);
|
||||
assert(ret);
|
||||
|
||||
_cleanup_(file_closep) EFI_FILE *handle = NULL;
|
||||
_cleanup_file_close_ EFI_FILE *handle = NULL;
|
||||
err = dir->Open(dir, &handle, (char16_t*) name, EFI_FILE_MODE_READ, 0ULL);
|
||||
if (err != EFI_SUCCESS)
|
||||
return err;
|
||||
@ -315,7 +315,7 @@ EFI_STATUS open_directory(
|
||||
const char16_t *path,
|
||||
EFI_FILE **ret) {
|
||||
|
||||
_cleanup_(file_closep) EFI_FILE *dir = NULL;
|
||||
_cleanup_file_close_ EFI_FILE *dir = NULL;
|
||||
_cleanup_free_ EFI_FILE_INFO *file_info = NULL;
|
||||
EFI_STATUS err;
|
||||
|
||||
|
@ -140,6 +140,8 @@ static inline void file_closep(EFI_FILE **handle) {
|
||||
(*handle)->Close(*handle);
|
||||
}
|
||||
|
||||
#define _cleanup_file_close_ _cleanup_(file_closep)
|
||||
|
||||
static inline void unload_imagep(EFI_HANDLE *image) {
|
||||
if (*image)
|
||||
(void) BS->UnloadImage(*image);
|
||||
|
@ -85,7 +85,7 @@ EFI_STATUS vmm_open(EFI_HANDLE *ret_vmm_dev, EFI_FILE **ret_vmm_dir) {
|
||||
dp_err = efivar_get_raw(MAKE_GUID_PTR(VMM_BOOT_ORDER), order_str, (void**) &dp, NULL);
|
||||
|
||||
for (size_t i = 0; i < n_handles; i++) {
|
||||
_cleanup_(file_closep) EFI_FILE *root_dir = NULL, *efi_dir = NULL;
|
||||
_cleanup_file_close_ EFI_FILE *root_dir = NULL, *efi_dir = NULL;
|
||||
EFI_DEVICE_PATH *fs;
|
||||
|
||||
err = BS->HandleProtocol(
|
||||
|
Loading…
x
Reference in New Issue
Block a user