summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Lowther <victor.lowther@gmail.com>2008-07-05 12:00:32 -0500
committerVictor Lowther <victor.lowther@gmail.com>2008-07-05 12:00:32 -0500
commitf76baff97225aa45221d553b7541d3e4db953a04 (patch)
tree51e1d7bc03a0d101aa26edc691755ec0f0d7d26d
parentd3223855cbb91c01776aca2d4196b79f73afd7ae (diff)
Make some changes to core functionality to support pm-powersave
This consists of core features extracted from the powersave-hooks branch, and does the following: * Refactor some settings in pm-functions to make it easier to support seperate settings for pm-action and pm-powersave. Other than sharing a mechanism for running hooks and being able to use certian utility functions, they do not have much in common w.r.t settings and lifecycle rules for those settings. * Move take_suspend_lock from pm-functions to pm-action. pm-powersave uses a simpler scheme, and there is not enough code sharing to justify having it in pm-functions. * Add a bit of code to pm-functions to figure out what chassis type we are running on. * Add a 00powersave hook that turns powersaving off across a suspend/resume. Things like laptop-mode in particular have been known to cause issues in some situations. * Make pm-powersave log to a real logfile and try to guess at the appropriate powersave mode if called with no arguments.
-rw-r--r--pm/pm-functions.in35
-rw-r--r--pm/sleep.d/00powersave13
-rw-r--r--pm/sleep.d/Makefile.am1
-rwxr-xr-xsrc/pm-action.in21
-rw-r--r--src/pm-powersave.in27
5 files changed, 67 insertions, 30 deletions
diff --git a/pm/pm-functions.in b/pm/pm-functions.in
index 9c1c297..ce79619 100644
--- a/pm/pm-functions.in
+++ b/pm/pm-functions.in
@@ -19,10 +19,10 @@ PM_UTILS_ETCDIR="@PM-UTILS-SYSCONFDIR@"
PM_UTILS_RUNDIR="/var/run/pm-utils"
PATH=/sbin:/usr/sbin:/bin:/usr/bin:"${PM_UTILS_LIBDIR}"/bin
-PM_LOGFILE="${PM_LOGFILE:=/var/log/pm-suspend.log}"
+PM_LOGFILE="/var/log/${STASHNAME}.log"
TEMPORARY_CPUFREQ_GOVERNOR="performance"
LOCKDIR="${PM_UTILS_RUNDIR}/locks"
-STORAGEDIR="${PM_UTILS_RUNDIR}/storage"
+STORAGEDIR="${PM_UTILS_RUNDIR}/${STASHNAME}/storage"
NA=254
NX=253
DX=252
@@ -45,11 +45,15 @@ PARAMETERS="${STORAGEDIR}/parameters"
INHIBIT="${STORAGEDIR}/inhibit"
PM_CMDLINE="$*"
+# when loading configuration files, allow stash-specific ones
+# to override the pm-utils global ones.
[ -f "${PM_UTILS_LIBDIR}"/defaults ] && . "${PM_UTILS_LIBDIR}"/defaults
-
+[ -f "${PM_UTILS_LIBDIR}/${STASHNAME}.defaults" ] && \
+ . "${PM_UTILS_LIBDIR}/${STASHNAME}.defaults"
set +a
-for cfg in "${PM_UTILS_ETCDIR}"/config.d/*[!~] ; do
+for cfg in "${PM_UTILS_ETCDIR}"/config.d/*[!~] \
+ "${PM_UTILS_ETCDIR}/${STASHNAME}.config.d"/*[!~]; do
[ -f "$cfg" ] || continue
# Ugly, I know. The goal here is to allow multiple files in
# /etc/pm/config.d declare these variables and have those
@@ -70,6 +74,12 @@ done
. "${PM_FUNCTIONS}"
+if [ "$(id -u)" = "0" ] && command_exists dmidecode; then
+ export CHASSIS_TYPE="$(dmidecode -s chassis-type)"
+else
+ export CHASSIS_TYPE=Unknown
+fi
+
# Simple little logging function.
# We do it this way because 'echo -n' is not posix.
log()
@@ -106,23 +116,6 @@ load_hook_parameters()
update_parameters
}
-take_suspend_lock()
-{
- try_lock "pm-utils.lock" || return 1
- # clean up from the last run
- rm -rf "${STORAGEDIR}"
- mkdir -p "${STORAGEDIR}"
- # save our parameter list.
- [ -f "$PARAMETERS" ] || echo '' >"$PARAMETERS"
- add_parameters $PM_CMDLINE
- update_parameters
- return 0
-}
-
-remove_suspend_lock()
-{
- release_lock "pm-utils.lock"
-}
hook_exit_status(){
case $1 in
diff --git a/pm/sleep.d/00powersave b/pm/sleep.d/00powersave
new file mode 100644
index 0000000..bf0f98b
--- /dev/null
+++ b/pm/sleep.d/00powersave
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+. "${PM_FUNCTIONS}"
+
+command_exists pm-powersave || exit $NA
+
+case $1 in
+ suspend|hibernate) pm-powersave false ;;
+ resume|thaw) pm-powersave ;;
+ *) exit $NA ;;
+esac
+exit 0
+ \ No newline at end of file
diff --git a/pm/sleep.d/Makefile.am b/pm/sleep.d/Makefile.am
index d47b799..a2f31cc 100644
--- a/pm/sleep.d/Makefile.am
+++ b/pm/sleep.d/Makefile.am
@@ -2,6 +2,7 @@ sleepdir = $(libdir)/pm-utils/sleep.d
sleep_SCRIPTS = \
00logging \
+ 00powersave \
01grub \
49bluetooth \
50ntpd \
diff --git a/src/pm-action.in b/src/pm-action.in
index 58a20b6..e756793 100755
--- a/src/pm-action.in
+++ b/src/pm-action.in
@@ -25,7 +25,7 @@
#
# The rule here? Simplicity.
-
+export STASHNAME=pm-suspend
. "@PM-UTILS-LIBDIR@/pm-functions"
help()
@@ -42,11 +42,25 @@ if [ "$(id -u)" != "0" ]; then
echo This utility may only be run by the root user. 1>&2
exit 1
fi
-take_suspend_lock || exit 1
+
+remove_suspend_lock()
+{
+ release_lock "${STASHNAME}.lock"
+}
+
+try_lock "${STASHNAME}.lock" || exit 1
# make sure we release the lock no matter how we exit
trap remove_suspend_lock 0
+# clean up from the last run
+rm -rf "${STORAGEDIR}"
+mkdir -p "${STORAGEDIR}"
+# save our parameter list.
+[ -f "$PARAMETERS" ] || echo '' >"$PARAMETERS"
+add_parameters $PM_CMDLINE
+update_parameters
+
while [ $# -gt 0 ]
do
[ "$1" = "--help" ] && help
@@ -77,9 +91,6 @@ log "Initial commandline parameters: $PM_CMDLINE"
load_hook_blacklist
load_hook_parameters
-# Make sure we are not inhibited before we start.
-rm -f "${INHIBIT}"
-
# run the sleep hooks
log "$(date): Running hooks for $ACTION."
if run_hooks sleep "$ACTION"; then
diff --git a/src/pm-powersave.in b/src/pm-powersave.in
index d0c2d5f..dff1f64 100644
--- a/src/pm-powersave.in
+++ b/src/pm-powersave.in
@@ -24,13 +24,32 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
-POWERSAVE_LOGFILE="/dev/null"
+export STASHNAME=pm-powersave
. "@PM-UTILS-LIBDIR@/pm-functions"
+remove_powersave_lock() {
+ release_lock "${STASHNAME}.lock"
+}
+
+# take the powersave lock.
+# ensure it gets released no matter how we exit.
+try_lock "${STASHNAME}.lock" || exit 1
+trap remove_powersave_lock 0
+mkdir -p "${STORAGEDIR}"
+rm -f "${INHIBIT}"
+
if [ "$1" = "true" -o "$1" = "false" ] ; then
- init_logfile "${POWERSAVE_LOGFILE}"
+ init_logfile "${PM_LOGFILE}"
run_hooks power "$1"
+elif [ ! "$1" ]; then
+ # no arg? Guess!
+ init_logfile "${PM_LOGFILE}"
+ if on_ac_power; then
+ run_hooks power false;
+ else
+ run_hooks power true;
+ fi
else
- echo "Argument needs to be true or false" >&2
- exit 1
+ echo "Argument needs to be true or false" >&2
+ exit 1
fi