[Pm-utils] [PATCH 1/4] Even simpler modularization of sleep methods.

Victor Lowther victor.lowther at gmail.com
Thu Feb 7 20:33:46 PST 2008


---
 configure.in                                |    1 +
 pm/Makefile.am                              |    5 +++-
 pm/functions.in                             |   23 +++++++---------
 pm/module.d/Makefile.am                     |    9 ++++++
 pm/module.d/kernel                          |   28 +++++++++++++++++++++
 src/pm-action.in                            |   36 +++++---------------------
 src/{pm-is-supported => pm-is-supported.in} |   31 +++++------------------
 7 files changed, 66 insertions(+), 67 deletions(-)

diff --git a/configure.in b/configure.in
index b59ad9d..13a6f8f 100644
--- a/configure.in
+++ b/configure.in
@@ -36,6 +36,7 @@ src/Makefile
 pm/Makefile
 pm/sleep.d/Makefile
 pm/power.d/Makefile
+pm/module.d/Makefile
 ])
 
 dnl ==========================================================================
diff --git a/pm/Makefile.am b/pm/Makefile.am
index e064ac0..40617bd 100644
--- a/pm/Makefile.am
+++ b/pm/Makefile.am
@@ -1,4 +1,7 @@
-SUBDIRS =  sleep.d power.d
+SUBDIRS =		\
+	sleep.d 	\
+	power.d		\
+	module.d
 
 extradir = $(libdir)/pm-utils
 pm_sysconfdir = $(sysconfdir)/pm
diff --git a/pm/functions.in b/pm/functions.in
index a9f0c1b..18f171c 100644
--- a/pm/functions.in
+++ b/pm/functions.in
@@ -21,6 +21,8 @@ SUSPEND_MODULES=""
 TEMPORARY_CPUFREQ_GOVERNOR="performance"
 LOCK="/var/run/pm-utils/lock"
 STORAGEDIR="/var/run/pm-utils/storage"
+SLEEP_MODULE="kernel"
+SLEEP_FUNCTIONS="${PM_UTILS_LIBDIR}/module.d/${SLEEP_MODULE}"
 
 # Use c sort order
 export LC_COLLATE=C
@@ -168,21 +170,12 @@ get_power_status()
 	return $RETVAL
 }
 
-do_suspend()
-{
-	pm-pmu --suspend || echo -n "mem" > /sys/power/state
-}
-
-do_hibernate()
-{
-	echo -n "${HIBERNATE_MODE}" > /sys/power/disk
-	echo -n "disk" > /sys/power/state
+[ -f "${SLEEP_FUNCTIONS}" ] || { 
+	echo "Requested sleep module $SLEEP_MODULE not available."
+	exit 1
 }
 
-do_suspend_hybrid()
-{
-	return 1
-}
+. "${SLEEP_FUNCTIONS}"
 
 init_logfile() {
 	if [ -n "$1" ]; then
@@ -192,6 +185,10 @@ init_logfile() {
 
 pm_main()
 {
+	"check_$1" || {
+		echo "System does not support $1 sleep."
+		return 1
+	}
 	init_logfile "$PM_LOGFILE" 
 	take_suspend_lock || exit 1
 
diff --git a/pm/module.d/Makefile.am b/pm/module.d/Makefile.am
new file mode 100644
index 0000000..8e861f3
--- /dev/null
+++ b/pm/module.d/Makefile.am
@@ -0,0 +1,9 @@
+moduledir = $(libdir)/pm-utils/module.d
+
+module_SCRIPTS =	\
+	kernel
+
+EXTRA_DIST=$(module_SCRIPTS)
+
+clean-local :
+	rm -f *~
diff --git a/pm/module.d/kernel b/pm/module.d/kernel
new file mode 100644
index 0000000..c111490
--- /dev/null
+++ b/pm/module.d/kernel
@@ -0,0 +1,28 @@
+check_suspend() {
+	grep -q mem /sys/power/state; return $?
+}
+
+do_suspend()
+{
+        pm-pmu --suspend || echo -n "mem" > /sys/power/state
+}
+
+check_hibernate() {
+	[ -f /sys/power/disk ] && grep -q disk /sys/power/state
+	return $?
+}
+
+do_hibernate()
+{
+        echo -n "${HIBERNATE_MODE}" > /sys/power/disk
+        echo -n "disk" > /sys/power/state
+}
+
+check_suspend_hybrid() {
+	return 1
+}
+
+do_suspend_hybrid()
+{
+        return 1
+}
diff --git a/src/pm-action.in b/src/pm-action.in
index b9b32dd..23f2749 100644
--- a/src/pm-action.in
+++ b/src/pm-action.in
@@ -87,40 +87,18 @@ done
 export PM_FUNCTIONS="@PM-UTILS-LIBDIR@/functions"
 . "${PM_FUNCTIONS}"
 
-[ -f /sys/power/state ] || exit 1
-
-
-ACTION=${0##*pm-}
+ACTION="$(echo ${0##*pm-} |tr - _)"
 
 case "$ACTION" in
-	suspend)
-		if ! pm-is-supported --"$ACTION" ; then
-			echo "Error: kernel cannot suspend to ram." 1>&2
-			exit 1
-		fi
-		REVERSE=resume
-		;;
-	hibernate)
-		if ! pm-is-supported --"$ACTION" ; then
-			echo "Error: kernel cannot suspend to disk." 1>&2
-			exit 1
-		fi
-		REVERSE=thaw
-		;;
-	suspend-hybrid)
-		if ! pm-is-supported --"$ACTION" ; then
-			echo "Error: hybrid suspend is not supported." 1>&2
-			exit
-		fi
-		REVERSE=resume
-		;;
-	*)
-		exit 1
-		;;
+	suspend) 	REVERSE=resume ;;
+	hibernate) 	REVERSE=thaw ;;
+	suspend_hybrid) REVERSE=resume ;;
+	*)		echo "Don't know how to ${ACTION}."
+			exit 1 ;;
 esac
 
 export PM_CMDLINE="$@"
 
-pm_main "$(echo $ACTION | tr - _)" "$REVERSE"
+pm_main "${ACTION}" "{$REVERSE}"
 
 exit $?
diff --git a/src/pm-is-supported b/src/pm-is-supported.in
similarity index 66%
rename from src/pm-is-supported
rename to src/pm-is-supported.in
index 9520e0b..af2f2cf 100755
--- a/src/pm-is-supported
+++ b/src/pm-is-supported.in
@@ -16,38 +16,21 @@
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 #
 
+. "@PM-UTILS-LIBDIR@/functions"
+
 help_options() {
 	echo "pm-is-supported [--suspend | --hibernate | --suspend-hybrid ]"
 	echo
 }
 
-export LC_COLLATE=C
-
 ARG="${1#--}"
 
-[ -f /sys/power/state ] || exit 1
-
 case "$ARG" in
-	suspend)
-		grep -q mem /sys/power/state || exit 1
-		;;
-	hibernate)
-		[ -f /sys/power/disk ] || exit 1
-		grep -q disk /sys/power/state || exit 1
-		;;
-	suspend-hybrid)
-		grep -q mem /sys/power/state || exit 1
-		[ -d /sys/power/tuxonice ] && exit 0
-		#grep -q disk /sys/power/state || exit 1
-		exit 1
-		;;
-	help)
-		help_options
-		;;
-	*)
-		help_options 1>&2
-		exit 1
-		;;
+	suspend|hibernate|suspend-hybrid)
+		"check_$ARG"; exit $? ;;
+	help) 	help_options ;;
+	*) 	help_options 1>&2
+		exit 1 ;;
 esac
 
 exit 0
-- 
1.5.3.8



More information about the Pm-utils mailing list