summaryrefslogtreecommitdiff
path: root/pm
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 /pm
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.
Diffstat (limited to 'pm')
-rw-r--r--pm/defaults19
-rw-r--r--pm/pm-functions.in49
2 files changed, 40 insertions, 28 deletions
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()