hibernate-util,logind: also differentiate the case of misconfigured resume

This commit is contained in:
Mike Yuan 2024-05-08 12:52:35 +08:00
parent 40eb83a8fe
commit 3fce141c1b
No known key found for this signature in database
GPG key ID: 417471C0A40F58B3
4 changed files with 10 additions and 1 deletions

View file

@ -2160,6 +2160,10 @@ static int method_do_shutdown_or_sleep(
return sd_bus_error_set(error, BUS_ERROR_SLEEP_VERB_NOT_SUPPORTED,
"Specified resume device is missing or is not an active swap device");
case SLEEP_RESUME_MISCONFIGURED:
return sd_bus_error_set(error, BUS_ERROR_SLEEP_VERB_NOT_SUPPORTED,
"Invalid resume config: resume= is not populated yet resume_offset= is");
case SLEEP_NOT_ENOUGH_SWAP_SPACE:
return sd_bus_error_set(error, BUS_ERROR_SLEEP_VERB_NOT_SUPPORTED,
"Not enough suitable swap space for hibernation available on compatible block devices and file systems");

View file

@ -159,7 +159,7 @@ static int read_resume_config(dev_t *ret_devno, uint64_t *ret_offset) {
}
if (devno == 0 && offset > 0 && offset != UINT64_MAX)
return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
return log_debug_errno(SYNTHETIC_ERRNO(ENOMEDIUM),
"Found populated /sys/power/resume_offset (%" PRIu64 ") but /sys/power/resume is not set, refusing.",
offset);

View file

@ -378,6 +378,10 @@ static int sleep_supported_internal(
*ret_support = SLEEP_RESUME_DEVICE_MISSING;
return false;
case -ENOMEDIUM:
*ret_support = SLEEP_RESUME_MISCONFIGURED;
return false;
case -ENOSPC:
*ret_support = SLEEP_NOT_ENOUGH_SWAP_SPACE;
return false;

View file

@ -60,6 +60,7 @@ typedef enum SleepSupport {
SLEEP_STATE_OR_MODE_NOT_SUPPORTED, /* SleepConfig.states/modes are not supported by kernel */
SLEEP_RESUME_NOT_SUPPORTED,
SLEEP_RESUME_DEVICE_MISSING, /* resume= is specified, but the device cannot be found in /proc/swaps */
SLEEP_RESUME_MISCONFIGURED, /* resume= is not set yet resume_offset= is configured */
SLEEP_NOT_ENOUGH_SWAP_SPACE,
SLEEP_ALARM_NOT_SUPPORTED, /* CLOCK_BOOTTIME_ALARM is unsupported by kernel (only used by s2h) */
} SleepSupport;