Package: devicekit-power
Version: 011-1
Severity: normal
Tags: patch
User: ubuntu-de...@lists.ubuntu.com
Usertags: origin-ubuntu karmic ubuntu-patch


dkp_client_can_hibernate can return true even if the machine has no swap 
partition.  When determining the value of its can_hibernate property, 
devicekit-power checks if the kernel supports hibernate and whether there is 
enough swap space available to perform a hibernate.  However, it does not seem 
to account for the possibility that a machine may not have a swap partition 
even though its kernel supports it.  In this case, devicekit-power detects that 
the kernel supports hibernate and treats the swap space as completely available 
(therefore dkp_client_can_hibernate returns true).  The attached patch modifies 
devicekit-power to first check if a swap partition exists before calculating 
how much is available.

*** /tmp/tmpXwgupz
In Ubuntu, we've applied the attached patch to achieve the following:

  * 05_no_swap_no_hibernate.patch: Have dkp_daemon_check_swap function 1st
    check if swap exists before determining how much is free

We thought you might be interested in doing the same. 


-- System Information:
Debian Release: 5.0
  APT prefers jaunty-updates
  APT policy: (500, 'jaunty-updates'), (500, 'jaunty-security'), (500, 
'jaunty-proposed'), (500, 'jaunty-backports'), (500, 'jaunty')
Architecture: i386 (i686)

Kernel: Linux 2.6.28-17-generic (SMP w/2 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
diff -u devicekit-power-011/debian/changelog devicekit-power-011/debian/changelog
diff -u devicekit-power-011/debian/patches/series devicekit-power-011/debian/patches/series
--- devicekit-power-011/debian/patches/series
+++ devicekit-power-011/debian/patches/series
@@ -2,0 +3 @@
+05_no_swap_no_hibernate.patch
only in patch2:
unchanged:
--- devicekit-power-011.orig/debian/patches/05_no_swap_no_hibernate.patch
+++ devicekit-power-011/debian/patches/05_no_swap_no_hibernate.patch
@@ -0,0 +1,33 @@
+Index: devicekit-power-011/src/dkp-daemon.c
+===================================================================
+--- devicekit-power-011.orig/src/dkp-daemon.c	2009-12-15 13:47:52.000000000 -0500
++++ devicekit-power-011/src/dkp-daemon.c	2009-12-15 13:48:57.000000000 -0500
+@@ -139,6 +139,7 @@
+ 	gboolean ret;
+ 	guint active = 0;
+ 	guint swap_free = 0;
++	guint swap_total = 0;
+ 	guint len;
+ 	guint i;
+ 	gfloat percentage = 0.0f;
+@@ -160,14 +161,19 @@
+ 		if (len > 3) {
+ 			if (g_strcmp0 (tokens[0], "SwapFree") == 0)
+ 				swap_free = atoi (tokens[len-2]);
++			if (g_strcmp0 (tokens[0], "SwapTotal") == 0)
++				swap_total = atoi (tokens[len-2]);
+ 			else if (g_strcmp0 (tokens[0], "Active") == 0)
+ 				active = atoi (tokens[len-2]);
+ 		}
+ 		g_strfreev (tokens);
+ 	}
+ 
++	/* first check if we even have swap */
++	if (swap_total == 0)
++		percentage = 100.0f; /* consider all swap space used */
+ 	/* work out how close to the line we are */
+-	if (swap_free > 0 && active > 0)
++	else if (swap_free > 0 && active > 0)
+ 		percentage = (active * 100) / swap_free;
+ 	egg_debug ("total swap available %i kb, active memory %i kb (%.1f%%)", swap_free, active, percentage);
+ out:

Reply via email to