hibernate-util: check 'noresume' before reading resume setting

Also hibernation_is_safe() should really take this
into consideration too.
This commit is contained in:
Mike Yuan
2024-04-07 02:59:07 +08:00
committed by Luca Boccassi
parent 7a5edb0795
commit b8b0704ce9
2 changed files with 9 additions and 1 deletions

View File

@@ -2154,7 +2154,7 @@ static int method_do_shutdown_or_sleep(
case SLEEP_RESUME_NOT_SUPPORTED:
return sd_bus_error_set(error, BUS_ERROR_SLEEP_VERB_NOT_SUPPORTED,
"Not running on EFI and resume= is not set. No available method to resume from hibernation");
"Not running on EFI and resume= is not set, or noresume is set. No available method to resume from hibernation");
case SLEEP_NOT_ENOUGH_SWAP_SPACE:
return sd_bus_error_set(error, BUS_ERROR_SLEEP_VERB_NOT_SUPPORTED,

View File

@@ -23,6 +23,7 @@
#include "log.h"
#include "parse-util.h"
#include "path-util.h"
#include "proc-cmdline.h"
#include "stat-util.h"
#include "string-util.h"
#include "strv.h"
@@ -129,6 +130,13 @@ static int read_resume_config(dev_t *ret_devno, uint64_t *ret_offset) {
assert(ret_devno);
assert(ret_offset);
r = proc_cmdline_get_key("noresume", /* flags = */ 0, /* ret_value = */ NULL);
if (r < 0)
return log_debug_errno(r, "Failed to check if 'noresume' kernel command line option is set: %m");
if (r > 0)
return log_debug_errno(SYNTHETIC_ERRNO(ENOTRECOVERABLE),
"'noresume' kernel command line option is set, refusing hibernation device lookup.");
r = read_one_line_file("/sys/power/resume", &devno_str);
if (r < 0)
return log_debug_errno(r, "Failed to read /sys/power/resume: %m");