]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
hibernate-util: check 'noresume' before reading resume setting
authorMike Yuan <me@yhndnzj.com>
Sat, 6 Apr 2024 18:59:07 +0000 (02:59 +0800)
committerLuca Boccassi <luca.boccassi@gmail.com>
Sun, 7 Apr 2024 22:28:56 +0000 (23:28 +0100)
Also hibernation_is_safe() should really take this
into consideration too.

src/login/logind-dbus.c
src/shared/hibernate-util.c

index ee64d9a81a9c169ef33f26bad2f09dc944015fad..d8d24d60c96057760481d6a402d1bc3e93f97a6d 100644 (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,
index 061b341075c2f47dcf82f682d35e3c2a982f305e..cb26a9ab272ec798e718b974a1e165e0a3bcc928 100644 (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");