naccyde / rpms / systemd

Forked from rpms/systemd a year ago
Clone
4fbe94
From 069cf14150b55e6580cf1d482709a0e48c36ee84 Mon Sep 17 00:00:00 2001
4fbe94
From: Andrew Jorgensen <ajorgens@amazon.com>
4fbe94
Date: Wed, 25 Jul 2018 08:06:57 -0700
4fbe94
Subject: [PATCH] shared/sleep-config: exclude zram devices from hibernation
4fbe94
 candidates
4fbe94
4fbe94
On a host with sufficiently large zram but with no actual swap, logind will
4fbe94
respond to CanHibernate() with yes. With this patch, it will correctly respond
4fbe94
no, unless there are other swap devices to consider.
4fbe94
4fbe94
(cherry picked from commit 411ae92b407bd7b4549b205ad754bcd0e3dfd81f)
4fbe94
4fbe94
Resolves: #1763617
4fbe94
---
4fbe94
 src/shared/sleep-config.c | 16 +++++++++++++---
4fbe94
 1 file changed, 13 insertions(+), 3 deletions(-)
4fbe94
4fbe94
diff --git a/src/shared/sleep-config.c b/src/shared/sleep-config.c
4fbe94
index 9e4ce183d3..a1523e3f21 100644
4fbe94
--- a/src/shared/sleep-config.c
4fbe94
+++ b/src/shared/sleep-config.c
4fbe94
@@ -21,6 +21,7 @@
4fbe94
 #include "log.h"
4fbe94
 #include "macro.h"
4fbe94
 #include "parse-util.h"
4fbe94
+#include "path-util.h"
4fbe94
 #include "sleep-config.h"
4fbe94
 #include "string-util.h"
4fbe94
 #include "strv.h"
4fbe94
@@ -201,9 +202,18 @@ int find_hibernate_location(char **device, char **type, size_t *size, size_t *us
4fbe94
                         continue;
4fbe94
                 }
4fbe94
 
4fbe94
-                if (streq(type_field, "partition") && endswith(dev_field, "\\040(deleted)")) {
4fbe94
-                        log_warning("Ignoring deleted swapfile '%s'.", dev_field);
4fbe94
-                        continue;
4fbe94
+                if (streq(type_field, "partition")) {
4fbe94
+                        if (endswith(dev_field, "\\040(deleted)")) {
4fbe94
+                                log_warning("Ignoring deleted swapfile '%s'.", dev_field);
4fbe94
+                                continue;
4fbe94
+                        }
4fbe94
+
4fbe94
+                        const char *fn;
4fbe94
+                        fn = path_startswith(dev_field, "/dev/");
4fbe94
+                        if (fn && startswith(fn, "zram")) {
4fbe94
+                                log_debug("Ignoring compressed ram swap device '%s'.", dev_field);
4fbe94
+                                continue;
4fbe94
+                        }
4fbe94
                 }
4fbe94
                 if (device)
4fbe94
                         *device = TAKE_PTR(dev_field);