summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Lowther <victor.lowther@gmail.com>2008-02-06 10:36:16 -0600
committerVictor Lowther <victor.lowther@gmail.com>2008-02-07 13:46:14 -0600
commita92675f0a02396494b7e5d58fa7ea841ccbe0cc5 (patch)
tree4f59d470a47ae0a93fb0cd63bc0a6dda07656c3a
parent8df496aeffe3a7114fa01912d7605693c5bc64b9 (diff)
Even simpler modularization of sleep methods.
This splits the actual functions that perform the sleep/wakeup into a file which is sourced, adds an environment variable which controls which module is sourced, moves the check functions into the sleep module, modifies pm-action and pm-is-supported to take these changes into account, and modifies the automake machinery to take these changes into account.
-rw-r--r--configure.in1
-rw-r--r--pm/Makefile.am5
-rw-r--r--pm/functions.in23
-rw-r--r--pm/module.d/Makefile.am9
-rw-r--r--pm/module.d/kernel28
-rw-r--r--src/pm-action.in36
-rwxr-xr-xsrc/pm-is-supported.in (renamed from src/pm-is-supported)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
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