From: Daan De Meyer Date: Thu, 31 Oct 2024 12:54:33 +0000 (+0100) Subject: efivars: Remove STRINGIFY() helper macros X-Git-Tag: v257-rc1~44^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d5c12da904872671e98c991f33e8e80fd9c3db8e;p=thirdparty%2Fsystemd.git efivars: Remove STRINGIFY() helper macros The names of these conflict with macros from efi.h that we'll move to efi-fundamental.h in a later commit. Let's avoid the conflict by getting rid of these helpers. Arguably this also improves readability by clearly indicating we're passing arbitrary strings and not constants to the macros when we invoke them. --- diff --git a/src/basic/efivars.c b/src/basic/efivars.c index 0ff07fa1133..5e04c322127 100644 --- a/src/basic/efivars.c +++ b/src/basic/efivars.c @@ -330,7 +330,7 @@ bool is_efi_secure_boot(void) { int r; if (cache < 0) { - r = read_flag(EFI_GLOBAL_VARIABLE(SecureBoot)); + r = read_flag(EFI_GLOBAL_VARIABLE_STR("SecureBoot")); if (r == -ENOENT) cache = false; else if (r < 0) @@ -348,7 +348,7 @@ SecureBootMode efi_get_secure_boot_mode(void) { if (cache != _SECURE_BOOT_INVALID) return cache; - int secure = read_flag(EFI_GLOBAL_VARIABLE(SecureBoot)); + int secure = read_flag(EFI_GLOBAL_VARIABLE_STR("SecureBoot")); if (secure < 0) { if (secure != -ENOENT) log_debug_errno(secure, "Error reading SecureBoot EFI variable, assuming not in SecureBoot mode: %m"); @@ -358,9 +358,9 @@ SecureBootMode efi_get_secure_boot_mode(void) { /* We can assume false for all these if they are abscent (AuditMode and * DeployedMode may not exist on older firmware). */ - int audit = read_flag(EFI_GLOBAL_VARIABLE(AuditMode)); - int deployed = read_flag(EFI_GLOBAL_VARIABLE(DeployedMode)); - int setup = read_flag(EFI_GLOBAL_VARIABLE(SetupMode)); + int audit = read_flag(EFI_GLOBAL_VARIABLE_STR("AuditMode")); + int deployed = read_flag(EFI_GLOBAL_VARIABLE_STR("DeployedMode")); + int setup = read_flag(EFI_GLOBAL_VARIABLE_STR("SetupMode")); log_debug("Secure boot variables: SecureBoot=%d AuditMode=%d DeployedMode=%d SetupMode=%d", secure, audit, deployed, setup); @@ -381,13 +381,13 @@ static int read_efi_options_variable(char **ret) { /* Let's be helpful with the returned error and check if the variable exists at all. If it * does, let's return a recognizable error (EPERM), and if not ENODATA. */ - if (access(EFIVAR_PATH(EFI_SYSTEMD_VARIABLE(SystemdOptions)), F_OK) < 0) + if (access(EFIVAR_PATH(EFI_SYSTEMD_VARIABLE_STR("SystemdOptions")), F_OK) < 0) return errno == ENOENT ? -ENODATA : -errno; return -EPERM; } - r = efi_get_variable_string(EFI_SYSTEMD_VARIABLE(SystemdOptions), ret); + r = efi_get_variable_string(EFI_SYSTEMD_VARIABLE_STR("SystemdOptions"), ret); if (r == -ENOENT) return -ENODATA; return r; @@ -401,7 +401,7 @@ int cache_efi_options_variable(void) { if (r < 0) return r; - return write_string_file(EFIVAR_CACHE_PATH(EFI_SYSTEMD_VARIABLE(SystemdOptions)), line, + return write_string_file(EFIVAR_CACHE_PATH(EFI_SYSTEMD_VARIABLE_STR("SystemdOptions")), line, WRITE_STRING_FILE_ATOMIC|WRITE_STRING_FILE_CREATE|WRITE_STRING_FILE_MKDIR_0755); } @@ -418,7 +418,7 @@ int systemd_efi_options_variable(char **ret) { if (e) return strdup_to(ret, e); - r = read_one_line_file(EFIVAR_CACHE_PATH(EFI_SYSTEMD_VARIABLE(SystemdOptions)), ret); + r = read_one_line_file(EFIVAR_CACHE_PATH(EFI_SYSTEMD_VARIABLE_STR("SystemdOptions")), ret); if (r == -ENOENT) return -ENODATA; return r; @@ -432,12 +432,12 @@ int systemd_efi_options_efivarfs_if_newer(char **ret) { struct stat a = {}, b; int r; - if (stat(EFIVAR_PATH(EFI_SYSTEMD_VARIABLE(SystemdOptions)), &a) < 0 && errno != ENOENT) + if (stat(EFIVAR_PATH(EFI_SYSTEMD_VARIABLE_STR("SystemdOptions")), &a) < 0 && errno != ENOENT) return log_debug_errno(errno, "Failed to stat EFI variable SystemdOptions: %m"); - if (stat(EFIVAR_CACHE_PATH(EFI_SYSTEMD_VARIABLE(SystemdOptions)), &b) < 0) { + if (stat(EFIVAR_CACHE_PATH(EFI_SYSTEMD_VARIABLE_STR("SystemdOptions")), &b) < 0) { if (errno != ENOENT) - log_debug_errno(errno, "Failed to stat "EFIVAR_CACHE_PATH(EFI_SYSTEMD_VARIABLE(SystemdOptions))": %m"); + log_debug_errno(errno, "Failed to stat "EFIVAR_CACHE_PATH(EFI_SYSTEMD_VARIABLE_STR("SystemdOptions"))": %m"); } else if (compare_stat_mtime(&a, &b) > 0) log_debug("Variable SystemdOptions in evifarfs is newer than in cache."); else { diff --git a/src/basic/efivars.h b/src/basic/efivars.h index fe2be3107a0..b4f0da5ed80 100644 --- a/src/basic/efivars.h +++ b/src/basic/efivars.h @@ -37,10 +37,6 @@ #define EFI_LOADER_VARIABLE_STR(name) EFI_VENDOR_VARIABLE_STR(EFI_VENDOR_LOADER_STR, name) #define EFI_SYSTEMD_VARIABLE_STR(name) EFI_VENDOR_VARIABLE_STR(EFI_VENDOR_SYSTEMD_STR, name) -#define EFI_GLOBAL_VARIABLE(name) EFI_GLOBAL_VARIABLE_STR(STRINGIFY(name)) -#define EFI_LOADER_VARIABLE(name) EFI_LOADER_VARIABLE_STR(STRINGIFY(name)) -#define EFI_SYSTEMD_VARIABLE(name) EFI_SYSTEMD_VARIABLE_STR(STRINGIFY(name)) - #define EFIVAR_PATH(variable) "/sys/firmware/efi/efivars/" variable #define EFIVAR_CACHE_PATH(variable) "/run/systemd/efivars/" variable diff --git a/src/boot/bless-boot-generator.c b/src/boot/bless-boot-generator.c index cf645e2416c..2c3d54173db 100644 --- a/src/boot/bless-boot-generator.c +++ b/src/boot/bless-boot-generator.c @@ -33,7 +33,7 @@ static int run(const char *dest, const char *dest_early, const char *dest_late) return 0; } - if (access(EFIVAR_PATH(EFI_LOADER_VARIABLE(LoaderBootCountPath)), F_OK) < 0) { + if (access(EFIVAR_PATH(EFI_LOADER_VARIABLE_STR("LoaderBootCountPath")), F_OK) < 0) { if (errno == ENOENT) { log_debug_errno(errno, "Skipping generator, not booted with boot counting in effect."); return 0; diff --git a/src/boot/bless-boot.c b/src/boot/bless-boot.c index 4853aaefe9a..61b882c5050 100644 --- a/src/boot/bless-boot.c +++ b/src/boot/bless-boot.c @@ -219,7 +219,7 @@ static int acquire_boot_count_path( uint64_t left, done; int r; - r = efi_get_variable_path(EFI_LOADER_VARIABLE(LoaderBootCountPath), &path); + r = efi_get_variable_path(EFI_LOADER_VARIABLE_STR("LoaderBootCountPath"), &path); if (r == -ENOENT) return -EUNATCH; /* in this case, let the caller print a message */ if (r < 0) diff --git a/src/boot/bootctl-install.c b/src/boot/bootctl-install.c index 0612791e07c..c3d32a1c6b0 100644 --- a/src/boot/bootctl-install.c +++ b/src/boot/bootctl-install.c @@ -1015,13 +1015,13 @@ static int remove_loader_variables(void) { /* Remove all persistent loader variables we define */ FOREACH_STRING(var, - EFI_LOADER_VARIABLE(LoaderConfigConsoleMode), - EFI_LOADER_VARIABLE(LoaderConfigTimeout), - EFI_LOADER_VARIABLE(LoaderConfigTimeoutOneShot), - EFI_LOADER_VARIABLE(LoaderEntryDefault), - EFI_LOADER_VARIABLE(LoaderEntryLastBooted), - EFI_LOADER_VARIABLE(LoaderEntryOneShot), - EFI_LOADER_VARIABLE(LoaderSystemToken)) { + EFI_LOADER_VARIABLE_STR("LoaderConfigConsoleMode"), + EFI_LOADER_VARIABLE_STR("LoaderConfigTimeout"), + EFI_LOADER_VARIABLE_STR("LoaderConfigTimeoutOneShot"), + EFI_LOADER_VARIABLE_STR("LoaderEntryDefault"), + EFI_LOADER_VARIABLE_STR("LoaderEntryLastBooted"), + EFI_LOADER_VARIABLE_STR("LoaderEntryOneShot"), + EFI_LOADER_VARIABLE_STR("LoaderSystemToken")) { int q; diff --git a/src/boot/bootctl-random-seed.c b/src/boot/bootctl-random-seed.c index cfe10c4115e..93cb4f9493b 100644 --- a/src/boot/bootctl-random-seed.c +++ b/src/boot/bootctl-random-seed.c @@ -79,7 +79,7 @@ static int set_system_token(void) { return 0; } - r = efi_get_variable(EFI_LOADER_VARIABLE(LoaderSystemToken), NULL, NULL, &token_size); + r = efi_get_variable(EFI_LOADER_VARIABLE_STR("LoaderSystemToken"), NULL, NULL, &token_size); if (r == -ENODATA) log_debug_errno(r, "LoaderSystemToken EFI variable is invalid (too short?), replacing."); else if (r < 0) { @@ -103,7 +103,7 @@ static int set_system_token(void) { * and possibly get identification information or too much insight into the kernel's entropy pool * state. */ WITH_UMASK(0077) { - r = efi_set_variable(EFI_LOADER_VARIABLE(LoaderSystemToken), buffer, sizeof(buffer)); + r = efi_set_variable(EFI_LOADER_VARIABLE_STR("LoaderSystemToken"), buffer, sizeof(buffer)); if (r < 0) { if (!arg_graceful) return log_error_errno(r, "Failed to write 'LoaderSystemToken' EFI variable: %m"); diff --git a/src/boot/bootctl-set-efivar.c b/src/boot/bootctl-set-efivar.c index 10867b22572..f23fcc713e6 100644 --- a/src/boot/bootctl-set-efivar.c +++ b/src/boot/bootctl-set-efivar.c @@ -74,17 +74,17 @@ static int parse_loader_entry_target_arg(const char *arg1, char16_t **ret_target assert(ret_target_size); if (streq(arg1, "@current")) { - r = efi_get_variable(EFI_LOADER_VARIABLE(LoaderEntrySelected), NULL, (void *) ret_target, ret_target_size); + r = efi_get_variable(EFI_LOADER_VARIABLE_STR("LoaderEntrySelected"), NULL, (void *) ret_target, ret_target_size); if (r < 0) return log_error_errno(r, "Failed to get EFI variable 'LoaderEntrySelected': %m"); } else if (streq(arg1, "@oneshot")) { - r = efi_get_variable(EFI_LOADER_VARIABLE(LoaderEntryOneShot), NULL, (void *) ret_target, ret_target_size); + r = efi_get_variable(EFI_LOADER_VARIABLE_STR("LoaderEntryOneShot"), NULL, (void *) ret_target, ret_target_size); if (r < 0) return log_error_errno(r, "Failed to get EFI variable 'LoaderEntryOneShot': %m"); } else if (streq(arg1, "@default")) { - r = efi_get_variable(EFI_LOADER_VARIABLE(LoaderEntryDefault), NULL, (void *) ret_target, ret_target_size); + r = efi_get_variable(EFI_LOADER_VARIABLE_STR("LoaderEntryDefault"), NULL, (void *) ret_target, ret_target_size); if (r < 0) return log_error_errno(r, "Failed to get EFI variable 'LoaderEntryDefault': %m"); @@ -114,7 +114,7 @@ int verb_set_efivar(int argc, char *argv[], void *userdata) { return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "Not booted with UEFI."); - if (access(EFIVAR_PATH(EFI_LOADER_VARIABLE(LoaderInfo)), F_OK) < 0) { + if (access(EFIVAR_PATH(EFI_LOADER_VARIABLE_STR("LoaderInfo")), F_OK) < 0) { if (errno == ENOENT) { log_error_errno(errno, "Not booted with a supported boot loader."); return -EOPNOTSUPP; @@ -137,16 +137,16 @@ int verb_set_efivar(int argc, char *argv[], void *userdata) { int (* arg_parser)(const char *, char16_t **, size_t *); if (streq(argv[0], "set-default")) { - variable = EFI_LOADER_VARIABLE(LoaderEntryDefault); + variable = EFI_LOADER_VARIABLE_STR("LoaderEntryDefault"); arg_parser = parse_loader_entry_target_arg; } else if (streq(argv[0], "set-oneshot")) { - variable = EFI_LOADER_VARIABLE(LoaderEntryOneShot); + variable = EFI_LOADER_VARIABLE_STR("LoaderEntryOneShot"); arg_parser = parse_loader_entry_target_arg; } else if (streq(argv[0], "set-timeout")) { - variable = EFI_LOADER_VARIABLE(LoaderConfigTimeout); + variable = EFI_LOADER_VARIABLE_STR("LoaderConfigTimeout"); arg_parser = parse_timeout; } else if (streq(argv[0], "set-timeout-oneshot")) { - variable = EFI_LOADER_VARIABLE(LoaderConfigTimeoutOneShot); + variable = EFI_LOADER_VARIABLE_STR("LoaderConfigTimeoutOneShot"); arg_parser = parse_timeout; } else assert_not_reached(); diff --git a/src/boot/bootctl-status.c b/src/boot/bootctl-status.c index c548ddcee53..229c1ad5354 100644 --- a/src/boot/bootctl-status.c +++ b/src/boot/bootctl-status.c @@ -413,17 +413,17 @@ int verb_status(int argc, char *argv[], void *userdata) { uint64_t loader_features = 0, stub_features = 0; int have; - (void) efi_get_variable_string_and_warn(EFI_LOADER_VARIABLE(LoaderFirmwareType), &fw_type); - (void) efi_get_variable_string_and_warn(EFI_LOADER_VARIABLE(LoaderFirmwareInfo), &fw_info); - (void) efi_get_variable_string_and_warn(EFI_LOADER_VARIABLE(LoaderInfo), &loader); - (void) efi_get_variable_string_and_warn(EFI_LOADER_VARIABLE(StubInfo), &stub); - (void) efi_get_variable_path_and_warn(EFI_LOADER_VARIABLE(LoaderImageIdentifier), &loader_path); - (void) efi_get_variable_path_and_warn(EFI_LOADER_VARIABLE(StubImageIdentifier), &stub_path); + (void) efi_get_variable_string_and_warn(EFI_LOADER_VARIABLE_STR("LoaderFirmwareType"), &fw_type); + (void) efi_get_variable_string_and_warn(EFI_LOADER_VARIABLE_STR("LoaderFirmwareInfo"), &fw_info); + (void) efi_get_variable_string_and_warn(EFI_LOADER_VARIABLE_STR("LoaderInfo"), &loader); + (void) efi_get_variable_string_and_warn(EFI_LOADER_VARIABLE_STR("StubInfo"), &stub); + (void) efi_get_variable_path_and_warn(EFI_LOADER_VARIABLE_STR("LoaderImageIdentifier"), &loader_path); + (void) efi_get_variable_path_and_warn(EFI_LOADER_VARIABLE_STR("StubImageIdentifier"), &stub_path); (void) efi_loader_get_features(&loader_features); (void) efi_stub_get_features(&stub_features); - (void) efi_get_variable_string_and_warn(EFI_LOADER_VARIABLE(LoaderEntrySelected), ¤t_entry); - (void) efi_get_variable_string_and_warn(EFI_LOADER_VARIABLE(LoaderEntryOneShot), &oneshot_entry); - (void) efi_get_variable_string_and_warn(EFI_LOADER_VARIABLE(LoaderEntryDefault), &default_entry); + (void) efi_get_variable_string_and_warn(EFI_LOADER_VARIABLE_STR("LoaderEntrySelected"), ¤t_entry); + (void) efi_get_variable_string_and_warn(EFI_LOADER_VARIABLE_STR("LoaderEntryOneShot"), &oneshot_entry); + (void) efi_get_variable_string_and_warn(EFI_LOADER_VARIABLE_STR("LoaderEntryDefault"), &default_entry); SecureBootMode secure = efi_get_secure_boot_mode(); printf("%sSystem:%s\n", ansi_underline(), ansi_normal()); @@ -525,7 +525,7 @@ int verb_status(int argc, char *argv[], void *userdata) { } printf("%sRandom Seed:%s\n", ansi_underline(), ansi_normal()); - have = access(EFIVAR_PATH(EFI_LOADER_VARIABLE(LoaderSystemToken)), F_OK) >= 0; + have = access(EFIVAR_PATH(EFI_LOADER_VARIABLE_STR("LoaderSystemToken")), F_OK) >= 0; printf(" System Token: %s\n", have ? "set" : "not set"); if (arg_esp_path) { diff --git a/src/boot/bootctl-systemd-efi-options.c b/src/boot/bootctl-systemd-efi-options.c index 7f8308fc3d6..d626d87abc6 100644 --- a/src/boot/bootctl-systemd-efi-options.c +++ b/src/boot/bootctl-systemd-efi-options.c @@ -34,7 +34,7 @@ int verb_systemd_efi_options(int argc, char *argv[], void *userdata) { log_notice("Note: SystemdOptions EFI variable has been modified since boot. New value: %s", new); } else { - r = efi_set_variable_string(EFI_SYSTEMD_VARIABLE(SystemdOptions), argv[1]); + r = efi_set_variable_string(EFI_SYSTEMD_VARIABLE_STR("SystemdOptions"), argv[1]); if (r < 0) return log_error_errno(r, "Failed to set SystemdOptions EFI variable: %m"); } diff --git a/src/boot/bootctl.c b/src/boot/bootctl.c index 176de8d55de..90232b30964 100644 --- a/src/boot/bootctl.c +++ b/src/boot/bootctl.c @@ -149,7 +149,7 @@ static int print_loader_or_stub_path(void) { if (r < 0) return log_error_errno(r, "Unable to determine loader partition UUID: %m"); - r = efi_get_variable_path(EFI_LOADER_VARIABLE(LoaderImageIdentifier), &p); + r = efi_get_variable_path(EFI_LOADER_VARIABLE_STR("LoaderImageIdentifier"), &p); if (r == -ENOENT) return log_error_errno(r, "No loader EFI binary path passed."); if (r < 0) @@ -163,7 +163,7 @@ static int print_loader_or_stub_path(void) { if (r < 0) return log_error_errno(r, "Unable to determine stub partition UUID: %m"); - r = efi_get_variable_path(EFI_LOADER_VARIABLE(StubImageIdentifier), &p); + r = efi_get_variable_path(EFI_LOADER_VARIABLE_STR("StubImageIdentifier"), &p); if (r == -ENOENT) return log_error_errno(r, "No stub EFI binary path passed."); if (r < 0) diff --git a/src/boot/measure.c b/src/boot/measure.c index 3ad49e9d740..557e06b094c 100644 --- a/src/boot/measure.c +++ b/src/boot/measure.c @@ -1049,7 +1049,7 @@ static int validate_stub(void) { log_warning("Warning: current kernel image does not support measuring itself, the command line or initrd system extension images.\n" "The PCR measurements seen are unlikely to be valid."); - r = compare_reported_pcr_nr(TPM2_PCR_KERNEL_BOOT, EFI_LOADER_VARIABLE(StubPcrKernelImage), "kernel image"); + r = compare_reported_pcr_nr(TPM2_PCR_KERNEL_BOOT, EFI_LOADER_VARIABLE_STR("StubPcrKernelImage"), "kernel image"); if (r < 0) return r; diff --git a/src/core/efi-random.c b/src/core/efi-random.c index dffde57c912..f3af300825f 100644 --- a/src/core/efi-random.c +++ b/src/core/efi-random.c @@ -16,7 +16,7 @@ void lock_down_efi_variables(void) { _cleanup_close_ int fd = -EBADF; int r; - fd = open(EFIVAR_PATH(EFI_LOADER_VARIABLE(LoaderSystemToken)), O_RDONLY|O_CLOEXEC); + fd = open(EFIVAR_PATH(EFI_LOADER_VARIABLE_STR("LoaderSystemToken")), O_RDONLY|O_CLOEXEC); if (fd < 0) { if (errno != ENOENT) log_warning_errno(errno, "Unable to open LoaderSystemToken EFI variable, ignoring: %m"); diff --git a/src/hibernate-resume/hibernate-resume-config.c b/src/hibernate-resume/hibernate-resume-config.c index edf7a70e7cc..d93919956b4 100644 --- a/src/hibernate-resume/hibernate-resume-config.c +++ b/src/hibernate-resume/hibernate-resume-config.c @@ -161,7 +161,7 @@ int get_efi_hibernate_location(EFIHibernateLocation **ret) { if (!is_efi_boot()) goto skip; - r = efi_get_variable_string(EFI_SYSTEMD_VARIABLE(HibernateLocation), &location_str); + r = efi_get_variable_string(EFI_SYSTEMD_VARIABLE_STR("HibernateLocation"), &location_str); if (r == -ENOENT) { log_debug_errno(r, "EFI variable HibernateLocation is not set, skipping."); goto skip; diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index 467c5f78a05..1b6e358b741 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -3286,12 +3286,12 @@ static int method_set_reboot_to_boot_loader_menu( if (use_efi) { if (x == UINT64_MAX) - r = efi_set_variable(EFI_LOADER_VARIABLE(LoaderConfigTimeoutOneShot), NULL, 0); + r = efi_set_variable(EFI_LOADER_VARIABLE_STR("LoaderConfigTimeoutOneShot"), NULL, 0); else { char buf[DECIMAL_STR_MAX(uint64_t) + 1]; xsprintf(buf, "%" PRIu64, DIV_ROUND_UP(x, USEC_PER_SEC)); /* second granularity */ - r = efi_set_variable_string(EFI_LOADER_VARIABLE(LoaderConfigTimeoutOneShot), buf); + r = efi_set_variable_string(EFI_LOADER_VARIABLE_STR("LoaderConfigTimeoutOneShot"), buf); } if (r < 0) return r; @@ -3481,9 +3481,9 @@ static int method_set_reboot_to_boot_loader_entry( if (use_efi) { if (isempty(v)) /* Delete item */ - r = efi_set_variable(EFI_LOADER_VARIABLE(LoaderEntryOneShot), NULL, 0); + r = efi_set_variable(EFI_LOADER_VARIABLE_STR("LoaderEntryOneShot"), NULL, 0); else - r = efi_set_variable_string(EFI_LOADER_VARIABLE(LoaderEntryOneShot), v); + r = efi_set_variable_string(EFI_LOADER_VARIABLE_STR("LoaderEntryOneShot"), v); if (r < 0) return r; } else { diff --git a/src/partition/repart.c b/src/partition/repart.c index 5427e0a69fc..8070b02cabd 100644 --- a/src/partition/repart.c +++ b/src/partition/repart.c @@ -8587,7 +8587,7 @@ static int parse_efi_variable_factory_reset(void) { if (!in_initrd()) /* Never honour EFI variable factory reset request outside of the initrd */ return 0; - r = efi_get_variable_string(EFI_SYSTEMD_VARIABLE(FactoryReset), &value); + r = efi_get_variable_string(EFI_SYSTEMD_VARIABLE_STR("FactoryReset"), &value); if (r < 0) { if (r == -ENOENT || ERRNO_IS_NOT_SUPPORTED(r)) return 0; @@ -8608,7 +8608,7 @@ static int parse_efi_variable_factory_reset(void) { static int remove_efi_variable_factory_reset(void) { int r; - r = efi_set_variable(EFI_SYSTEMD_VARIABLE(FactoryReset), NULL, 0); + r = efi_set_variable(EFI_SYSTEMD_VARIABLE_STR("FactoryReset"), NULL, 0); if (r < 0) { if (r == -ENOENT || ERRNO_IS_NOT_SUPPORTED(r)) return 0; diff --git a/src/shared/bootspec.c b/src/shared/bootspec.c index 4c0195a41ef..584515a2979 100644 --- a/src/shared/bootspec.c +++ b/src/shared/bootspec.c @@ -1382,19 +1382,19 @@ static int boot_load_efi_entry_pointers(BootConfig *config, bool skip_efivars) { /* Loads the three "pointers" to boot loader entries from their EFI variables */ - r = efi_get_variable_string(EFI_LOADER_VARIABLE(LoaderEntryOneShot), &config->entry_oneshot); + r = efi_get_variable_string(EFI_LOADER_VARIABLE_STR("LoaderEntryOneShot"), &config->entry_oneshot); if (r == -ENOMEM) return log_oom(); if (r < 0 && !IN_SET(r, -ENOENT, -ENODATA)) log_warning_errno(r, "Failed to read EFI variable \"LoaderEntryOneShot\", ignoring: %m"); - r = efi_get_variable_string(EFI_LOADER_VARIABLE(LoaderEntryDefault), &config->entry_default); + r = efi_get_variable_string(EFI_LOADER_VARIABLE_STR("LoaderEntryDefault"), &config->entry_default); if (r == -ENOMEM) return log_oom(); if (r < 0 && !IN_SET(r, -ENOENT, -ENODATA)) log_warning_errno(r, "Failed to read EFI variable \"LoaderEntryDefault\", ignoring: %m"); - r = efi_get_variable_string(EFI_LOADER_VARIABLE(LoaderEntrySelected), &config->entry_selected); + r = efi_get_variable_string(EFI_LOADER_VARIABLE_STR("LoaderEntrySelected"), &config->entry_selected); if (r == -ENOMEM) return log_oom(); if (r < 0 && !IN_SET(r, -ENOENT, -ENODATA)) @@ -1560,7 +1560,7 @@ int boot_config_augment_from_loader( break; } - p = strdup(EFIVAR_PATH(EFI_LOADER_VARIABLE(LoaderEntries))); + p = strdup(EFIVAR_PATH(EFI_LOADER_VARIABLE_STR("LoaderEntries"))); if (!p) return log_oom(); diff --git a/src/shared/efi-api.c b/src/shared/efi-api.c index 3b9954be9b4..37720f896b4 100644 --- a/src/shared/efi-api.c +++ b/src/shared/efi-api.c @@ -79,7 +79,7 @@ int efi_reboot_to_firmware_supported(void) { if (!is_efi_boot()) goto not_supported; - r = efi_get_variable(EFI_GLOBAL_VARIABLE(OsIndicationsSupported), NULL, &v, &s); + r = efi_get_variable(EFI_GLOBAL_VARIABLE_STR("OsIndicationsSupported"), NULL, &v, &s); if (r == -ENOENT) goto not_supported; /* variable doesn't exist? it's not supported then */ if (r < 0) @@ -115,7 +115,7 @@ static int get_os_indications(uint64_t *ret) { return r; /* stat() the EFI variable, to see if the mtime changed. If it did we need to cache again. */ - if (stat(EFIVAR_PATH(EFI_GLOBAL_VARIABLE(OsIndications)), &new_stat) < 0) { + if (stat(EFIVAR_PATH(EFI_GLOBAL_VARIABLE_STR("OsIndications")), &new_stat) < 0) { if (errno != ENOENT) return -errno; @@ -129,7 +129,7 @@ static int get_os_indications(uint64_t *ret) { return 0; } - r = efi_get_variable(EFI_GLOBAL_VARIABLE(OsIndications), NULL, &v, &s); + r = efi_get_variable(EFI_GLOBAL_VARIABLE_STR("OsIndications"), NULL, &v, &s); if (r == -ENOENT) { /* Some firmware implementations that do support OsIndications and report that with * OsIndicationsSupported will remove the OsIndications variable when it is unset. Let's @@ -172,7 +172,7 @@ int efi_set_reboot_to_firmware(bool value) { /* Avoid writing to efi vars store if we can due to firmware bugs. */ if (b != b_new) - return efi_set_variable(EFI_GLOBAL_VARIABLE(OsIndications), &b_new, sizeof(uint64_t)); + return efi_set_variable(EFI_GLOBAL_VARIABLE_STR("OsIndications"), &b_new, sizeof(uint64_t)); return 0; } @@ -399,7 +399,7 @@ int efi_get_boot_order(uint16_t **ret_order) { if (!is_efi_boot()) return -EOPNOTSUPP; - r = efi_get_variable(EFI_GLOBAL_VARIABLE(BootOrder), NULL, &buf, &l); + r = efi_get_variable(EFI_GLOBAL_VARIABLE_STR("BootOrder"), NULL, &buf, &l); if (r < 0) return r; @@ -419,7 +419,7 @@ int efi_set_boot_order(const uint16_t *order, size_t n) { if (!is_efi_boot()) return -EOPNOTSUPP; - return efi_set_variable(EFI_GLOBAL_VARIABLE(BootOrder), order, n * sizeof(uint16_t)); + return efi_set_variable(EFI_GLOBAL_VARIABLE_STR("BootOrder"), order, n * sizeof(uint16_t)); } static int boot_id_hex(const char s[static 4]) { diff --git a/src/shared/efi-loader.c b/src/shared/efi-loader.c index ae0b2b1fdc8..3eddc49bf94 100644 --- a/src/shared/efi-loader.c +++ b/src/shared/efi-loader.c @@ -43,11 +43,11 @@ int efi_loader_get_boot_usec(usec_t *ret_firmware, usec_t *ret_loader) { if (!is_efi_boot()) return -EOPNOTSUPP; - r = read_usec(EFI_LOADER_VARIABLE(LoaderTimeInitUSec), &x); + r = read_usec(EFI_LOADER_VARIABLE_STR("LoaderTimeInitUSec"), &x); if (r < 0) return log_debug_errno(r, "Failed to read LoaderTimeInitUSec: %m"); - r = read_usec(EFI_LOADER_VARIABLE(LoaderTimeExecUSec), &y); + r = read_usec(EFI_LOADER_VARIABLE_STR("LoaderTimeExecUSec"), &y); if (r < 0) return log_debug_errno(r, "Failed to read LoaderTimeExecUSec: %m"); @@ -69,11 +69,11 @@ static int get_device_part_uuid(const char *variable, sd_id128_t *ret) { } int efi_loader_get_device_part_uuid(sd_id128_t *ret) { - return get_device_part_uuid(EFI_LOADER_VARIABLE(LoaderDevicePartUUID), ret); + return get_device_part_uuid(EFI_LOADER_VARIABLE_STR("LoaderDevicePartUUID"), ret); } int efi_stub_get_device_part_uuid(sd_id128_t *ret) { - return get_device_part_uuid(EFI_LOADER_VARIABLE(StubDevicePartUUID), ret); + return get_device_part_uuid(EFI_LOADER_VARIABLE_STR("StubDevicePartUUID"), ret); } int efi_loader_get_entries(char ***ret) { @@ -87,7 +87,7 @@ int efi_loader_get_entries(char ***ret) { if (!is_efi_boot()) return -EOPNOTSUPP; - r = efi_get_variable(EFI_LOADER_VARIABLE(LoaderEntries), NULL, (void**) &entries, &size); + r = efi_get_variable(EFI_LOADER_VARIABLE_STR("LoaderEntries"), NULL, (void**) &entries, &size); if (r < 0) return r; @@ -148,12 +148,12 @@ int efi_loader_get_features(uint64_t *ret) { return 0; } - r = efi_get_variable(EFI_LOADER_VARIABLE(LoaderFeatures), NULL, &v, &s); + r = efi_get_variable(EFI_LOADER_VARIABLE_STR("LoaderFeatures"), NULL, &v, &s); if (r == -ENOENT) { _cleanup_free_ char *info = NULL; /* The new (v240+) LoaderFeatures variable is not supported, let's see if it's systemd-boot at all */ - r = efi_get_variable_string(EFI_LOADER_VARIABLE(LoaderInfo), &info); + r = efi_get_variable_string(EFI_LOADER_VARIABLE_STR("LoaderInfo"), &info); if (r < 0) { if (r != -ENOENT) return r; @@ -199,12 +199,12 @@ int efi_stub_get_features(uint64_t *ret) { return 0; } - r = efi_get_variable(EFI_LOADER_VARIABLE(StubFeatures), NULL, &v, &s); + r = efi_get_variable(EFI_LOADER_VARIABLE_STR("StubFeatures"), NULL, &v, &s); if (r == -ENOENT) { _cleanup_free_ char *info = NULL; /* The new (v252+) StubFeatures variable is not supported, let's see if it's systemd-stub at all */ - r = efi_get_variable_string(EFI_LOADER_VARIABLE(StubInfo), &info); + r = efi_get_variable_string(EFI_LOADER_VARIABLE_STR("StubInfo"), &info); if (r < 0) { if (r != -ENOENT) return r; @@ -261,7 +261,7 @@ int efi_measured_uki(int log_level) { if (!efi_has_tpm2()) return (cached = 0); - r = efi_get_variable_string(EFI_LOADER_VARIABLE(StubPcrKernelImage), &pcr_string); + r = efi_get_variable_string(EFI_LOADER_VARIABLE_STR("StubPcrKernelImage"), &pcr_string); if (r == -ENOENT) return (cached = 0); if (r < 0) @@ -291,7 +291,7 @@ int efi_loader_get_config_timeout_one_shot(usec_t *ret) { assert(ret); /* stat() the EFI variable, to see if the mtime changed. If it did, we need to cache again. */ - if (stat(EFIVAR_PATH(EFI_LOADER_VARIABLE(LoaderConfigTimeoutOneShot)), &new_stat) < 0) + if (stat(EFIVAR_PATH(EFI_LOADER_VARIABLE_STR("LoaderConfigTimeoutOneShot")), &new_stat) < 0) return -errno; if (stat_inode_unmodified(&new_stat, &cache_stat)) { @@ -299,7 +299,7 @@ int efi_loader_get_config_timeout_one_shot(usec_t *ret) { return 0; } - r = efi_get_variable_string(EFI_LOADER_VARIABLE(LoaderConfigTimeoutOneShot), &v); + r = efi_get_variable_string(EFI_LOADER_VARIABLE_STR("LoaderConfigTimeoutOneShot"), &v); if (r < 0) return r; @@ -323,13 +323,13 @@ int efi_loader_update_entry_one_shot_cache(char **cache, struct stat *cache_stat assert(cache_stat); /* stat() the EFI variable, to see if the mtime changed. If it did we need to cache again. */ - if (stat(EFIVAR_PATH(EFI_LOADER_VARIABLE(LoaderEntryOneShot)), &new_stat) < 0) + if (stat(EFIVAR_PATH(EFI_LOADER_VARIABLE_STR("LoaderEntryOneShot")), &new_stat) < 0) return -errno; if (stat_inode_unmodified(&new_stat, cache_stat)) return 0; - r = efi_get_variable_string(EFI_LOADER_VARIABLE(LoaderEntryOneShot), &v); + r = efi_get_variable_string(EFI_LOADER_VARIABLE_STR("LoaderEntryOneShot"), &v); if (r < 0) return r; diff --git a/src/shared/hibernate-util.c b/src/shared/hibernate-util.c index 7c21157580f..1213fdc2c7f 100644 --- a/src/shared/hibernate-util.c +++ b/src/shared/hibernate-util.c @@ -527,7 +527,7 @@ int clear_efi_hibernate_location_and_warn(void) { if (!is_efi_boot()) return 0; - r = efi_set_variable(EFI_SYSTEMD_VARIABLE(HibernateLocation), NULL, 0); + r = efi_set_variable(EFI_SYSTEMD_VARIABLE_STR("HibernateLocation"), NULL, 0); if (r == -ENOENT) return 0; if (r < 0) diff --git a/src/sleep/sleep.c b/src/sleep/sleep.c index 3f113fff744..181bb4ccefc 100644 --- a/src/sleep/sleep.c +++ b/src/sleep/sleep.c @@ -114,7 +114,7 @@ static int write_efi_hibernate_location(const HibernationDevice *hibernation_dev if (r < 0) return log_full_errno(log_level, r, "Failed to format JSON object: %m"); - r = efi_set_variable_string(EFI_SYSTEMD_VARIABLE(HibernateLocation), formatted); + r = efi_set_variable_string(EFI_SYSTEMD_VARIABLE_STR("HibernateLocation"), formatted); if (r < 0) return log_full_errno(log_level, r, "Failed to set EFI variable HibernateLocation: %m");