[Pm-utils] [PATCH 2/2] Moved kernel suspend and hibernate code into pm-functions.in.

Victor Lowther victor.lowther at gmail.com
Sat Sep 6 10:51:31 PDT 2008


Since we always fall back to kernel methods if nothing else has overridden
us, we may as well keep the code in pm-functions.in.  This also makes it
harder to the end user to break suspend/resume.

The kernel suspend method file is now a stub.
---
 pm/module.d/kernel |   30 ++++--------------------------
 pm/pm-functions.in |   34 +++++++++++++++++++++++++++++-----
 2 files changed, 33 insertions(+), 31 deletions(-)

diff --git a/pm/module.d/kernel b/pm/module.d/kernel
dissimilarity index 98%
index eb9626c..e6759e3 100755
--- a/pm/module.d/kernel
+++ b/pm/module.d/kernel
@@ -1,26 +1,4 @@
-#!/bin/sh
-
-if [ "$SUSPEND_METHOD" = "none" ] && \
-    { [ -c /dev/pmu ] || grep -q mem /sys/power/state; } then
-    SUSPEND_METHOD=kernel
-    do_suspend()
-    {
-	if [ -c /dev/pmu ]; then
-		pm-pmu --suspend
-	else
-		echo -n "mem" > /sys/power/state
-	fi
-    }
-fi
-
-if [ "$HIBERNATE_METHOD" = "none" ] && \
-    [ -f /sys/power/disk ] && grep -q disk /sys/power/state; then
-    HIBERNATE_METHOD=kernel
-    do_hibernate()
-    {
-	[ -n "${HIBERNATE_MODE}" ] && \
-	    grep -qw "${HIBERNATE_MODE}" /sys/power/disk && \
-	    echo -n "${HIBERNATE_MODE}" > /sys/power/disk
-	echo -n "disk" > /sys/power/state
-    }
-fi
+#!/bin/sh
+
+# nothing here -- pm-utils always falls back on kernel suspend/hibernate
+# if nothing else already claimed them
\ No newline at end of file
diff --git a/pm/pm-functions.in b/pm/pm-functions.in
index 9b11a71..0114378 100644
--- a/pm/pm-functions.in
+++ b/pm/pm-functions.in
@@ -222,11 +222,35 @@ if [ "$SLEEP_MODULE" = "auto" ]; then
     SLEEP_MODULE="tuxonice uswsusp"
 fi
 
-SLEEP_FUNCTIONS="${PM_UTILS_LIBDIR}/module.d/${SLEEP_MODULE}"
+SLEEP_FUNCTIONS="${PM_UTILS_LIBDIR}/module.d"
 
-for sleep_method in $sleep_methods; do
-    . "${PM_UTILS_LIBDIR}/module.d/${sleep_method}"
+for sleep_method in $SLEEP_MODULE; do
+    [ -f "${SLEEP_FUNCTIONS}/$sleep_method" ] || continue
+    . "${SLEEP_FUNCTIONS}/${sleep_method}"
 done
 
-# always load in-kernel methods last
-. "${PM_UTILS_LIBDIR}/module.d/kernel"
\ No newline at end of file
+# fall back on kernel methods if not already claimed
+if [ "$SUSPEND_METHOD" = "none" ] && \
+    { [ -c /dev/pmu ] || grep -q mem /sys/power/state; } then
+    SUSPEND_METHOD=kernel
+    do_suspend()
+    {
+	if [ -c /dev/pmu ]; then
+		pm-pmu --suspend
+	else
+		echo -n "mem" > /sys/power/state
+	fi
+    }
+fi
+
+if [ "$HIBERNATE_METHOD" = "none" ] && \
+    [ -f /sys/power/disk ] && grep -q disk /sys/power/state; then
+    HIBERNATE_METHOD=kernel
+    do_hibernate()
+    {
+	[ -n "${HIBERNATE_MODE}" ] && \
+	    grep -qw "${HIBERNATE_MODE}" /sys/power/disk && \
+	    echo -n "${HIBERNATE_MODE}" > /sys/power/disk
+	echo -n "disk" > /sys/power/state
+    }
+fi
-- 
1.5.6.5



More information about the Pm-utils mailing list