From: Mike Yuan Date: Thu, 2 Jan 2025 03:17:47 +0000 (+0100) Subject: shared/hibernate-util: handle the case where no swap has available backing dev X-Git-Tag: v258-rc1~1750^2~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=bd3d361580715c7a6204c74df9185cc81d67f0c2;p=thirdparty%2Fsystemd.git shared/hibernate-util: handle the case where no swap has available backing dev This also makes find_suitable_hibernation_device() report more accurate error (ENOSPC -> ESTALE) if there's no swap space on the system at all but resume= is set. Fixes #35798 Replaces #35801 --- diff --git a/src/shared/hibernate-util.c b/src/shared/hibernate-util.c index 49ce787d02e..25d742ed1f8 100644 --- a/src/shared/hibernate-util.c +++ b/src/shared/hibernate-util.c @@ -359,8 +359,6 @@ int find_suitable_hibernation_device_full(HibernationDevice *ret_device, uint64_ r = read_swap_entries(&entries); if (r < 0) return r; - if (entries.n_swaps == 0) - return log_debug_errno(SYNTHETIC_ERRNO(ENOSPC), "No swap space available for hibernation."); FOREACH_ARRAY(swap, entries.swaps, entries.n_swaps) { r = swap_entry_get_resume_config(swap); @@ -396,9 +394,10 @@ int find_suitable_hibernation_device_full(HibernationDevice *ret_device, uint64_ } if (!entry) { - /* No need to check n_swaps == 0, since it's rejected early */ - assert(resume_config_devno > 0); - return log_debug_errno(SYNTHETIC_ERRNO(ESTALE), "Cannot find swap entry corresponding to /sys/power/resume."); + if (resume_config_devno > 0) + return log_debug_errno(SYNTHETIC_ERRNO(ESTALE), "Cannot find swap entry corresponding to /sys/power/resume."); + + return log_debug_errno(SYNTHETIC_ERRNO(ENOSPC), "No swap space available for hibernation."); } if (ret_device) {