From 78e9bb837c258ac0ec7712b3d612cc2f407e731e Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 12 Jun 2024 05:50:42 +0200 Subject: Merging upstream version 256. Signed-off-by: Daniel Baumann --- src/hibernate-resume/hibernate-resume-config.c | 44 +++++++++++--------------- 1 file changed, 19 insertions(+), 25 deletions(-) (limited to 'src/hibernate-resume/hibernate-resume-config.c') diff --git a/src/hibernate-resume/hibernate-resume-config.c b/src/hibernate-resume/hibernate-resume-config.c index e4be7ca..c7ed1bc 100644 --- a/src/hibernate-resume/hibernate-resume-config.c +++ b/src/hibernate-resume/hibernate-resume-config.c @@ -11,6 +11,12 @@ #include "proc-cmdline.h" #include "efivars.h" +typedef struct KernelHibernateLocation { + char *device; + uint64_t offset; + bool offset_set; +} KernelHibernateLocation; + static KernelHibernateLocation* kernel_hibernate_location_free(KernelHibernateLocation *k) { if (!k) return NULL; @@ -22,7 +28,7 @@ static KernelHibernateLocation* kernel_hibernate_location_free(KernelHibernateLo DEFINE_TRIVIAL_CLEANUP_FUNC(KernelHibernateLocation*, kernel_hibernate_location_free); -static EFIHibernateLocation* efi_hibernate_location_free(EFIHibernateLocation *e) { +EFIHibernateLocation* efi_hibernate_location_free(EFIHibernateLocation *e) { if (!e) return NULL; @@ -36,8 +42,6 @@ static EFIHibernateLocation* efi_hibernate_location_free(EFIHibernateLocation *e return mfree(e); } -DEFINE_TRIVIAL_CLEANUP_FUNC(EFIHibernateLocation*, efi_hibernate_location_free); - void hibernate_info_done(HibernateInfo *info) { assert(info); @@ -121,7 +125,7 @@ static bool validate_efi_hibernate_location(EFIHibernateLocation *e) { if (!streq_ptr(id, e->id) || !streq_ptr(image_id, e->image_id)) { - log_notice("HibernateLocation system identifier doesn't match currently running system, not resuming from it."); + log_notice("HibernateLocation system identifier doesn't match currently running system, would not resume from it."); return false; } @@ -133,9 +137,10 @@ static bool validate_efi_hibernate_location(EFIHibernateLocation *e) { return true; } +#endif -static int get_efi_hibernate_location(EFIHibernateLocation **ret) { - +int get_efi_hibernate_location(EFIHibernateLocation **ret) { +#if ENABLE_EFI static const JsonDispatch dispatch_table[] = { { "uuid", JSON_VARIANT_STRING, json_dispatch_id128, offsetof(EFIHibernateLocation, uuid), JSON_MANDATORY }, { "offset", _JSON_VARIANT_TYPE_INVALID, json_dispatch_uint64, offsetof(EFIHibernateLocation, offset), JSON_MANDATORY }, @@ -152,8 +157,6 @@ static int get_efi_hibernate_location(EFIHibernateLocation **ret) { _cleanup_free_ char *location_str = NULL; int r; - assert(ret); - if (!is_efi_boot()) goto skip; @@ -173,7 +176,7 @@ static int get_efi_hibernate_location(EFIHibernateLocation **ret) { if (!e) return log_oom(); - r = json_dispatch(v, dispatch_table, JSON_LOG, e); + r = json_dispatch(v, dispatch_table, JSON_LOG|JSON_ALLOW_EXTENSIONS, e); if (r < 0) return r; @@ -192,15 +195,19 @@ static int get_efi_hibernate_location(EFIHibernateLocation **ret) { if (asprintf(&e->device, "/dev/disk/by-uuid/" SD_ID128_UUID_FORMAT_STR, SD_ID128_FORMAT_VAL(e->uuid)) < 0) return log_oom(); - *ret = TAKE_PTR(e); + if (ret) + *ret = TAKE_PTR(e); return 1; skip: - *ret = NULL; +#endif + if (ret) + *ret = NULL; return 0; } void compare_hibernate_location_and_warn(const HibernateInfo *info) { +#if ENABLE_EFI int r; assert(info); @@ -224,19 +231,8 @@ void compare_hibernate_location_and_warn(const HibernateInfo *info) { if (info->cmdline->offset != info->efi->offset) log_warning("resume_offset=%" PRIu64 " doesn't match with EFI HibernateLocation offset %" PRIu64 ", proceeding anyway with resume_offset=.", info->cmdline->offset, info->efi->offset); -} - -void clear_efi_hibernate_location(void) { - int r; - - if (!is_efi_boot()) - return; - - r = efi_set_variable(EFI_SYSTEMD_VARIABLE(HibernateLocation), NULL, 0); - if (r < 0) - log_warning_errno(r, "Failed to clear EFI variable HibernateLocation, ignoring: %m"); -} #endif +} int acquire_hibernate_info(HibernateInfo *ret) { _cleanup_(hibernate_info_done) HibernateInfo i = {}; @@ -246,11 +242,9 @@ int acquire_hibernate_info(HibernateInfo *ret) { if (r < 0) return r; -#if ENABLE_EFI r = get_efi_hibernate_location(&i.efi); if (r < 0) return r; -#endif if (i.cmdline) { i.device = i.cmdline->device; -- cgit v1.2.3