summaryrefslogtreecommitdiff
path: root/src/pm-powersave.in
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 /src/pm-powersave.in
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.
Diffstat (limited to 'src/pm-powersave.in')
-rw-r--r--src/pm-powersave.in27
1 files changed, 23 insertions, 4 deletions
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