diff options
-rwxr-xr-x | pm/functions | 37 | ||||
-rwxr-xr-x | pm/sleep.d/50modules | 5 | ||||
-rwxr-xr-x | src/on_ac_power | 4 |
3 files changed, 20 insertions, 26 deletions
diff --git a/pm/functions b/pm/functions index 439d255..eb2be1f 100755 --- a/pm/functions +++ b/pm/functions @@ -188,8 +188,7 @@ pm_main() _rmmod() { if modprobe -r $1; then - echo "export RESUME_MODULES=\"$1 \$RESUME_MODULES\"" \ - >> /var/run/pm-suspend + touch "/var/run/pm-suspend/module:$1" return 0 else echo "# could not unload '$1', usage count was $2" @@ -202,26 +201,23 @@ _rmmod() { modunload() { local MOD D C USED MODS I - local UNL=$1 RET=1 - # the kernel only knows underscores in module names, no dashes - UNL=${UNL//-/_} - # RET is the return code. - # If at least one module was unloaded, return 0. - # if the module was not loaded, also return 0 since this is no error. - # if no module was unloaded successfully, return 1 + local UNL="$(echo $1 |tr -- - _)" RET=1 + while read MOD D C USED D; do [ "$MOD" = "$UNL" ] || continue - if [ "$USED" == "-" ]; then - _rmmod $MOD $C + if [ "$USED" = "-" ]; then + # no dependent modules, just try to remove this one. + _rmmod "$MOD" $C RET=$? else - USED=${USED//,/ } - MODS=($USED) - # it seems slightly more likely to rmmod in one pass, - # if we try backwards. - for I in `seq $[${#MODS[@]}-1] -1 0`; do - MOD=${MODS[$I]} + # modules depend on this one. try to remove them first. + MODS="${USED%%*,}" + while [ "${MODS}" ]; do + # try to unload the last one first + MOD="${MODS##*,}" modunload $MOD && RET=0 + # prune the last one from the list + MODS="${MODS%,*}" done # if we unloaded at least one module, then let's # try again! @@ -235,11 +231,12 @@ modunload() return 0 } +# reload all the modules in no particular order. modreload() { - if [ "$(eval echo \$${1}_MODULE_LOAD)" == "yes" ]; then - modprobe "$1" >/dev/null 2>&1 - fi + for x in /var/run/pm-suspend/module:* ; do + [ -f "${x}" ] && modprobe "${x##*:}" >/dev/null 2>&1 + done } if type service |grep -q "not found"; then diff --git a/pm/sleep.d/50modules b/pm/sleep.d/50modules index bab7a6c..19707c1 100755 --- a/pm/sleep.d/50modules +++ b/pm/sleep.d/50modules @@ -13,10 +13,7 @@ suspend_modules() resume_modules() { - [ -z "$RESUME_MODULES" ] && return 0 - for x in $RESUME_MODULES ; do - modprobe $x - done + modreload } case "$1" in diff --git a/src/on_ac_power b/src/on_ac_power index a250e56..6f6a3d0 100755 --- a/src/on_ac_power +++ b/src/on_ac_power @@ -39,8 +39,8 @@ ac_adapters=$(hal-find-by-capability --capability ac_adapter) # If any of them are online, then we're done. for device in $ac_adapters ; do - present=$(hal-get-property --udi $device --key ac_adapter.present) - [ "$present" == "true" ] && exit 0 + present=$(hal-get-property --udi "$device" --key ac_adapter.present) + [ "x$present" = "xtrue" ] && exit 0 done # If there are adapters, but none are online, we're not on AC. |