Hi,
Attached is a patch that allows hibernation on swap devices set up via
"decrypt_derived". This is a hack, but I don't have the time to contact
the cryptsetup authors on whether it is safe to add a "can_hibernate"
option to /etc/crypttab. This would then IMHO be a clean solution:

1. The user adds "can_hibernate" to /etc/crypttab to mark swap devices
as safe for hibernation
2. cryptsetup knows about can_hibernate but ignores it (mostly)
3. Debian setup scripts should be modified to mark safe devices by
default, so new users won't have to change anything
4. upower allows hibernation when all swap devices are safe.

Attached patch checks for "decrypt_derived"; this is not the full
solution outlined above. Replacing that string with "can_hibernate"
should take us pretty close to that though. Splitting at "," and then
doing an exact strcmp doesn't give us that much extra sanity, does it?
I believe you can also rewrite the code to not use split and thus not do
extra mallocs (and require the cleanups for that).
The outline for that would be to skip to the second tab char in the
crypttab line, then try matching "can_hibernate" or jumping to the
next , until the end of the line is reached.

Any takers?

Regards,
Erich
Index: upower-0.9.1/src/up-daemon.c
===================================================================
--- upower-0.9.1.orig/src/up-daemon.c	2010-03-29 21:17:06.000000000 +0200
+++ upower-0.9.1/src/up-daemon.c	2010-03-29 21:21:10.000000000 +0200
@@ -154,9 +154,11 @@
 	gchar *contents_crypttab = NULL;
 	gchar **lines_swaps = NULL;
 	gchar **lines_crypttab = NULL;
+	gchar **split_crypttab = NULL;
 	GError *error = NULL;
 	gboolean ret;
 	gboolean encrypted_swap = FALSE;
+	gboolean safe_encrypted_swap = FALSE;
 	const gchar *filename_swaps = "/proc/swaps";
 	const gchar *filename_crypttab = "/etc/crypttab";
 	GPtrArray *devices = NULL;
@@ -216,18 +218,33 @@
 		    lines_crypttab[i][0] == '\0')
 			continue;
 
-		/* only look at first parameter */
-		g_strdelimit (lines_crypttab[i], "\t ", '\0');
-
-		/* is a swap device? */
-		for (j=0; j<devices->len; j++) {
-			device = g_ptr_array_index (devices, j);
-			if (g_strcmp0 (device, lines_crypttab[i]) == 0) {
-				egg_debug ("swap device %s is encrypted (so cannot hibernate)", device);
-				encrypted_swap = TRUE;
-				goto out;
+		/* split the line */
+		split_crypttab = g_strsplit (lines_crypttab[i], "\t", 4);
+		safe_encrypted_swap = FALSE;
+		if (g_strv_length (split_crypttab) >= 4) {
+			/* this is a hack. Can we add a "can_hibernate" option to crypttab without breaking things */
+			if (g_strrstr( split_crypttab[3], "decrypt_derived") != NULL) {
+				safe_encrypted_swap = TRUE;
+			}
+		}
+		/* free the split string */
+		g_strfreev(split_crypttab);
+		split_crypttab = NULL;
+
+		if (!safe_encrypted_swap) {
+			/* continue with only the first parameter */
+			g_strdelimit (lines_crypttab[i], "\t ", '\0');
+
+			/* is a swap device? */
+			for (j=0; j<devices->len; j++) {
+				device = g_ptr_array_index (devices, j);
+				if (g_strcmp0 (device, lines_crypttab[0]) == 0) {
+					egg_debug ("swap device %s is encrypted (so cannot hibernate)", device);
+					encrypted_swap = TRUE;
+					goto out;
+				}
+				egg_debug ("swap device %s is not encrypted (allows hibernate)", device);
 			}
-			egg_debug ("swap device %s is not encrypted (allows hibernate)", device);
 		}
 	}
 

Reply via email to