]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Revert "sleep: offer hibernation only if the kernel image still exists"
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 21 Dec 2018 10:01:34 +0000 (11:01 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 21 Dec 2018 17:23:17 +0000 (18:23 +0100)
This reverts commit edda44605f06a41fb86b7ab8128dcf99161d2344.

The kernel explicitly supports resuming with a different kernel than the one
used before hibernation. If this is something that shouldn't be supported, the
place to change this is in the kernel. We shouldn't censor something that this
exclusively in the kernel's domain.

People might be using this to switch kernels without restaring programs, and
we'd break this functionality for them.

Also, even if resuming with a different kernel was a bad idea, we don't really
prevent that with this check, since most users have more than one kernel and
can freely pick a different one from the menu. So this only affected the corner
case where the kernel has been removed, but there is no reason to single it
out.

NEWS
src/login/logind-dbus.c
src/shared/sleep-config.c

diff --git a/NEWS b/NEWS
index be4fc55a39ede43a91369c2c848e19e5b1b8c06e..2a5d62337cfc85c6279693739aab41331b9075eb 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -175,9 +175,6 @@ CHANGES WITH 240 in spe:
         * Most configuration options that previously accepted percentage values
           now also accept permille values with the '‰' suffix (instead of '%').
 
-        * systemd-logind will offer hibernation only if the currently used
-          kernel image is still available on disk.
-
         * systemd-resolved may now optionally use OpenSSL instead of GnuTLS for
           DNS-over-TLS.
 
index 766a9236be17a46e71a0e6ea47ac6ee0f0ca9a63..bd9f5ac4d6cf58a1e24266e07c0e50c23d35151c 100644 (file)
@@ -1779,11 +1779,11 @@ static int method_do_shutdown_or_sleep(
         if (sleep_verb) {
                 r = can_sleep(sleep_verb);
                 if (r == -ENOSPC)
-                        return sd_bus_error_set(error, BUS_ERROR_SLEEP_VERB_NOT_SUPPORTED, "Not enough swap space for hibernation");
-                if (r == -ENOMEDIUM)
-                        return sd_bus_error_set(error, BUS_ERROR_SLEEP_VERB_NOT_SUPPORTED, "Kernel image has been removed, can't hibernate");
+                        return sd_bus_error_set(error, BUS_ERROR_SLEEP_VERB_NOT_SUPPORTED,
+                                                "Not enough swap space for hibernation");
                 if (r == 0)
-                        return sd_bus_error_setf(error, BUS_ERROR_SLEEP_VERB_NOT_SUPPORTED, "Sleep verb \"%s\" not supported", sleep_verb);
+                        return sd_bus_error_setf(error, BUS_ERROR_SLEEP_VERB_NOT_SUPPORTED,
+                                                 "Sleep verb \"%s\" not supported", sleep_verb);
                 if (r < 0)
                         return r;
         }
@@ -2210,7 +2210,7 @@ static int method_can_shutdown_or_sleep(
 
         if (sleep_verb) {
                 r = can_sleep(sleep_verb);
-                if (IN_SET(r,  0, -ENOSPC, -ENOMEDIUM))
+                if (IN_SET(r,  0, -ENOSPC))
                         return sd_bus_reply_method_return(message, "s", "na");
                 if (r < 0)
                         return r;
index 1c94714f8ac0a7f4d3e94acc726bd552a93b9b68..2e22bd0bbe2157719dba6484e3218b261c29be10 100644 (file)
 #include <stdio.h>
 #include <string.h>
 #include <sys/ioctl.h>
-#include <sys/utsname.h>
 #include <syslog.h>
 #include <unistd.h>
 
-#include "sd-id128.h"
-
 #include "alloc-util.h"
 #include "conf-parser.h"
 #include "def.h"
@@ -293,72 +290,6 @@ static bool enough_swap_for_hibernation(void) {
         return r;
 }
 
-static int kernel_exists(void) {
-        struct utsname u;
-        sd_id128_t m;
-        int i, r;
-
-        /* Do some superficial checks whether the kernel we are currently running is still around. If it isn't we
-         * shouldn't offer hibernation as we couldn't possible resume from hibernation again. Of course, this check is
-         * very superficial, as the kernel's mere existance is hardly enough to know whether the hibernate/resume cycle
-         * will succeed. However, the common case of kernel updates can be caught this way, and it's definitely worth
-         * covering that. */
-
-        for (i = 0;; i++) {
-                _cleanup_free_ char *path = NULL;
-
-                switch (i) {
-
-                case 0:
-                        /* First, let's look in /lib/modules/`uname -r`/vmlinuz. This is where current Fedora places
-                         * its RPM-managed kernels. It's a good place, as it means compiled vendor code is monopolized
-                         * in /usr, and then the kernel image is stored along with its modules in the same
-                         * hierarchy. It's also what our 'kernel-install' script is written for. */
-                        if (uname(&u) < 0)
-                                return log_debug_errno(errno, "Failed to acquire kernel release: %m");
-
-                        path = strjoin("/lib/modules/", u.release, "/vmlinuz");
-                        break;
-
-                case 1:
-                        /* Secondly, let's look in /boot/vmlinuz-`uname -r`. This is where older Fedora and other
-                         * distributions tend to place the kernel. */
-                        path = strjoin("/boot/vmlinuz-", u.release);
-                        break;
-
-                case 2:
-                        /* For the other cases, we look in the EFI/boot partition, at the place where our
-                         * "kernel-install" script copies the kernel on install by default. */
-                        r = sd_id128_get_machine(&m);
-                        if (r < 0)
-                                return log_debug_errno(r, "Failed to read machine ID: %m");
-
-                        (void) asprintf(&path, "/efi/" SD_ID128_FORMAT_STR "/%s/linux", SD_ID128_FORMAT_VAL(m), u.release);
-                        break;
-                case 3:
-                        (void) asprintf(&path, "/boot/" SD_ID128_FORMAT_STR "/%s/linux", SD_ID128_FORMAT_VAL(m), u.release);
-                        break;
-                case 4:
-                        (void) asprintf(&path, "/boot/efi/" SD_ID128_FORMAT_STR "/%s/linux", SD_ID128_FORMAT_VAL(m), u.release);
-                        break;
-
-                default:
-                        return false;
-                }
-
-                if (!path)
-                        return -ENOMEM;
-
-                log_debug("Testing whether %s exists.", path);
-
-                if (access(path, F_OK) >= 0)
-                        return true;
-
-                if (errno != ENOENT)
-                        log_debug_errno(errno, "Failed to determine whether '%s' exists, ignoring: %m", path);
-        }
-}
-
 int read_fiemap(int fd, struct fiemap **ret) {
         _cleanup_free_ struct fiemap *fiemap = NULL, *result_fiemap = NULL;
         struct stat statinfo;
@@ -458,7 +389,7 @@ static bool can_s2h(void) {
 
         FOREACH_STRING(p, "suspend", "hibernate") {
                 r = can_sleep_internal(p, false);
-                if (IN_SET(r, 0, -ENOSPC, -ENOMEDIUM, -EADV)) {
+                if (IN_SET(r, 0, -ENOSPC, -EADV)) {
                         log_debug("Unable to %s system.", p);
                         return false;
                 }
@@ -494,11 +425,6 @@ static int can_sleep_internal(const char *verb, bool check_allowed) {
         if (streq(verb, "suspend"))
                 return true;
 
-        if (kernel_exists() <= 0) {
-                log_debug_errno(errno, "Couldn't find kernel, not offering hibernation.");
-                return -ENOMEDIUM;
-        }
-
         if (!enough_swap_for_hibernation())
                 return -ENOSPC;