]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared/sleep-config: exclude zram devices from hibernation candidates
authorAndrew Jorgensen <ajorgens@amazon.com>
Wed, 25 Jul 2018 15:06:57 +0000 (08:06 -0700)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 26 Jul 2018 08:19:04 +0000 (10:19 +0200)
On a host with sufficiently large zram but with no actual swap, logind will
respond to CanHibernate() with yes. With this patch, it will correctly respond
no, unless there are other swap devices to consider.

src/shared/sleep-config.c

index 9e4ce183d3635f3b49d5890cf75c07f42e0a81e3..a1523e3f21342ec4c563a2d08f99025a5305779a 100644 (file)
@@ -21,6 +21,7 @@
 #include "log.h"
 #include "macro.h"
 #include "parse-util.h"
+#include "path-util.h"
 #include "sleep-config.h"
 #include "string-util.h"
 #include "strv.h"
@@ -201,9 +202,18 @@ int find_hibernate_location(char **device, char **type, size_t *size, size_t *us
                         continue;
                 }
 
-                if (streq(type_field, "partition") && endswith(dev_field, "\\040(deleted)")) {
-                        log_warning("Ignoring deleted swapfile '%s'.", dev_field);
-                        continue;
+                if (streq(type_field, "partition")) {
+                        if (endswith(dev_field, "\\040(deleted)")) {
+                                log_warning("Ignoring deleted swapfile '%s'.", dev_field);
+                                continue;
+                        }
+
+                        const char *fn;
+                        fn = path_startswith(dev_field, "/dev/");
+                        if (fn && startswith(fn, "zram")) {
+                                log_debug("Ignoring compressed ram swap device '%s'.", dev_field);
+                                continue;
+                        }
                 }
                 if (device)
                         *device = TAKE_PTR(dev_field);