chiark / gitweb /
shared/sleep-config: return a custom message when not enough swap for hibernation
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 11 Apr 2018 06:51:06 +0000 (08:51 +0200)
committerSven Eden <yamakuzure@gmx.net>
Fri, 24 Aug 2018 14:47:08 +0000 (16:47 +0200)
$ sudo swapoff -av
swapoff /dev/vda4
$ sudo systemctl hibernate
Failed to hibernate system via logind: Not enough swap space for hibernation

Fixes #6729.

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

index 73be87b1907b274572df13a6b13fb4e3d255750c..6bc76464c33b4c367e751b4ef130024ab2ea93e4 100644 (file)
@@ -1907,14 +1907,17 @@ static int method_do_shutdown_or_sleep(
         if (sleep_verb) {
 #if 0 /// Within elogind the manager m must be provided, too
                 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 == 0)
+                        return sd_bus_error_setf(error, BUS_ERROR_SLEEP_VERB_NOT_SUPPORTED,
+                                                 "Sleep verb \"%s\" not supported", sleep_verb);
 #else
                 r = can_sleep(m, sleep_verb);
 #endif // 0
                 if (r < 0)
                         return r;
-
-                if (r == 0)
-                        return sd_bus_error_setf(error, BUS_ERROR_SLEEP_VERB_NOT_SUPPORTED, "Sleep verb not supported");
         }
 
 #if 0 /// Within elogind it does not make sense to verify shutdown creds when suspending
@@ -2401,13 +2404,13 @@ static int method_can_shutdown_or_sleep(
         if (sleep_verb) {
 #if 0 /// elogind needs to have the manager being passed
                 r = can_sleep(sleep_verb);
+                if (IN_SET(r,  0, -ENOSPC))
+                        return sd_bus_reply_method_return(message, "s", "na");
 #else
                 r = can_sleep(m, sleep_verb);
 #endif // 0
                 if (r < 0)
                         return r;
-                if (r == 0)
-                        return sd_bus_reply_method_return(message, "s", "na");
         }
 
         r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_EUID, &creds);
index 210e753c4f56f2a09d3f76e73960ed7279a21908..28d19c59b70e201cd754aac08dcc672e081c6c8c 100644 (file)
@@ -380,12 +380,12 @@ static bool can_s2h(void) {
 
         FOREACH_STRING(p, "suspend", "hibernate") {
                 r = can_sleep(p);
-                if (r < 0)
-                        return log_debug_errno(r, "Failed to check if %s is possible: %m", p);
-                if (r == 0) {
+                if (IN_SET(r, 0, -ENOSPC)) {
                         log_debug("Unable to %s system.", p);
                         return false;
                 }
+                if (r < 0)
+                        return log_debug_errno(r, "Failed to check if %s is possible: %m", p);
         }
 
         return true;
@@ -426,5 +426,12 @@ int can_sleep(const char *verb) {
                 return false;
 
         return streq(verb, "suspend") || enough_memory_for_hibernation();
+        if (streq(verb, "suspend"))
+                return true;
+
+        if (!enough_memory_for_hibernation())
+                return -ENOSPC;
+
+        return true;
 }
 #endif // 0