summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Lowther <victor.lowther@gmail.com>2008-03-19 21:09:40 -0500
committerVictor Lowther <victor.lowther@gmail.com>2008-03-19 21:09:40 -0500
commit0129bc69e33523c9746a44fb4a78e25579acecb8 (patch)
tree7bb39c0efec4a56d5ea9ad645405917dcd24d1d9
parent174f1430e76dfcf9d45e6d44422a47c2e2bba369 (diff)
Make the hook blacklist and parameter overrides use env. variables.
This came about after a long discussion with mbiebl on the best way to configure settings in pm-utils.
-rw-r--r--README13
-rw-r--r--pm/defaults19
-rw-r--r--pm/pm-functions.in49
3 files changed, 48 insertions, 33 deletions
diff --git a/README b/README
index 518118a..e6b6aee 100644
--- a/README
+++ b/README
@@ -48,16 +48,19 @@ How do "hooks" work?
End-user customization:
* If a particular hook is causing problems on your system, you can disable it
- by adding its name to /etc/pm/blacklist
+ using the HOOK_BLACKLIST environment variable.by creating a file in
+ /etc/pm/config.d and adding the line:
+ HOOK_BLACKLIST="hookname 99another-hook"
* To find out what parameters can be passed to pm-suspend and friends, run them
with '--help' as the first parameter as root. This will print out the
options that it supports and which hooks or modules handle those options.
* If a parameter (or lack thereof) passed to pm-suspend and friends is causing
problems, or you need to debug the suspend/resume process to work out what
- quirks are causing problems, you can use /etc/pm/parameters to override
- the hooks passed by HAL. Specifically:
- * "add --parameter" will add --parameter to the list of parameters.
- * "drop --parameter" will remove --parameter from the list of parameters.
+ quirks are causing problems, you can use the ADD_PARAMETERS and
+ DROP_PARAMETERS environment variables. To do this, create a file in
+ /etc/pm/config.d, and add the following lines to it:
+ ADD_PARAMETERS="--parameter-to-add --another-paramater"
+ DROP_PARAMETERS="--parameter-to-drop --another-parameter-to-drop"
That's it!
diff --git a/pm/defaults b/pm/defaults
index 5e4def1..19d38ec 100644
--- a/pm/defaults
+++ b/pm/defaults
@@ -28,7 +28,22 @@
# The system defaults to "kernel" if this is commented out.
# SLEEP_MODULE="kernel"
-# If you need to unload any modules to suspend/resume, add them
-# here.
+# These variables will be handled specially when we load files in
+# /etc/pm/config.d.
+# Multiple declarations of these environment variables will result in
+# their contents being concatenated instead of being overwritten.
+
+# If you need to unload any modules to suspend/resume, add them here.
# SUSPEND_MODULES=""
+# If you want to keep a hook from running even though it is installed,
+# add it here.
+# HOOK_BLACKLIST=""
+
+# If you want to unconditionally add a parameter to the commandline,
+# add it here.
+# ADD_PARAMETERS=""
+
+# If you want to ignore a commandline parameter, add it here.
+# DROP_PARAMETERS=""
+
diff --git a/pm/pm-functions.in b/pm/pm-functions.in
index f4bf755..a0895f5 100644
--- a/pm/pm-functions.in
+++ b/pm/pm-functions.in
@@ -38,7 +38,11 @@ LC_COLLATE=C
HIBERNATE_MODE="shutdown"
HIBERNATE_RESUME_POST_VIDEO="no"
SLEEP_MODULE="kernel"
+# These variables will be handled specially when we load the config file.
SUSPEND_MODULES=""
+HOOK_BLACKLIST=""
+ADD_PARAMETERS=""
+DROP_PARAMETERS=""
[ -f "${PM_UTILS_LIBDIR}"/defaults ] && . "${PM_UTILS_LIBDIR}"/defaults
@@ -46,8 +50,20 @@ set +a
for cfg in "${PM_UTILS_ETCDIR}"/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
+ # declarations add together instead of the last one overwriting
+ # all the others.
+ [ "$SUSPEND_MODULES" ] && REAL_SUSPEND_MODULES="$SUSPEND_MODULES"
+ [ "$HOOK_BLACKLIST" ] && REAL_HOOK_BLACKLIST="$HOOK_BLACKLIST"
+ [ "$ADD_PARAMETERS" ] && REAL_ADD_PARAMETERS="$ADD_PARAMETERS"
+ [ "$DROP_PARAMETERS" ] && REAL_DROP_PARAMETERS="$DROP_PARAMETERS"
set -a
. "${cfg}"
+ SUSPEND_MODULES="$REAL_SUSPEND_MODULES $SUSPEND_MODULES"
+ HOOK_BLACKLIST="$REAL_HOOK_BLACKLIST $HOOK_BLACKLIST"
+ ADD_PARAMETERS="$REAL_ADD_PARAMETERS $ADD_PARAMETERS"
+ DROP_PARAMETERS="$REAL_DROP_PARAMETERS $DROP_PARAMETERS"
set +a
done
@@ -57,21 +73,15 @@ log() { [ $LOGGING ] && echo $*; }
load_hook_blacklist()
{
- [ -f "$PM_UTILS_ETCDIR/blacklist" ] || return
- # loop through the blacklist file, adding entries to our hook blacklist.
- # Blacklist file format:
- # name debugging text
- # Comments begin with hash signs.
- sed 's,#.*$,,g' < "$PM_UTILS_ETCDIR/blacklist" | \
- while read entry comment; do
- # skip blank lines
- [ -z "$entry" ] && continue
+ [ "$HOOK_BLACKLIST" ] || return
+ local hook
+ for hook in $HOOK_BLACKLIST; do
disablehook "${entry##*/}" "${comment:-blacklist}"
log "Blacklisting ${entry##*/}."
done
}
-remove_parameter() {
+remove_parameters() {
local x=""
for p in $PM_CMDLINE; do
[ "$1" = "$p" ] && {
@@ -84,28 +94,15 @@ remove_parameter() {
PM_CMDLINE="$x"
}
-add_parameter() {
+add_parameters() {
log "Adding parameters $@"
PM_CMDLINE="$PM_CMDLINE $@"
}
load_hook_parameters()
{
- [ -f "$PM_UTILS_ETCDIR/parameters" ] || return
- # loop through the parameters file, and perform the appropriate
- # action for each parameter.
- # Currently, only "add" and "drop" are supported.
- # Comments begin with hashmarks and run to the end of the line.
- # Because we are modifying an env var, the while read loop cannot
- # run in a pipe like the previous one did.
- while read action parameter; do
- parameter="$(echo $parameter |sed 's,#.*$,,g')"
- [ -z "$parameter" ] && continue
- case $action in
- add) add_parameter $parameter ;;
- drop) remove_parameter $parameter ;;
- esac
- done < "$PM_UTILS_ETCDIR/parameters"
+ [ "$DROP_PARAMETERS" ] && remove_parameters $DROP_PARAMETERS
+ [ "$ADD_PARAMETERS" ] && add_parameters $ADD_PARAMETERS
}
take_suspend_lock()