diff options
-rwxr-xr-x | pm/power.d/hal-cd-polling | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/pm/power.d/hal-cd-polling b/pm/power.d/hal-cd-polling new file mode 100755 index 0000000..82eccd5 --- /dev/null +++ b/pm/power.d/hal-cd-polling @@ -0,0 +1,49 @@ +#!/bin/sh + +. "${PM_FUNCTIONS}" + +DISABLE_HAL_POLLING="${DISABLE_HAL_POLLING:-true}" + + +help() { + cat <<"EOF" +--- +$0: Keep HAL from polling optical media for disk insertion + +Keep HAL from polling optical media while on battery. This saves a few +tenths of a watt. + +This hook has 1 parameter: +DISABLE_HAL_POLLING = true or false. +If true, this hook will turn off the poll HAL does every 2 seconds to see +if media has been inserted into an optical drive. + +If false, this hook does nothing. + +EOF +} + +stop_polling() { + [ "$DISABLE_HAL_POLLING" = "true" ] || exit $NA + command_exists hal-disable-polling || exit $NA + local disks="$(for c in /dev/cd/*; do readlink -f "$c"; done |sort |uniq)" + [ "$disks" ] || exit $NA + savestate hal_polling_disks "$disks" + for c in $disks; do + hal-disable-polling --device "$c" + done +} + +restart_polling() { + state_exists hal_polling_disks || exit $NA + for disk in $(restorestate hal_polling_disks); do + hal-disable-polling --enable-polling --device "$disk" + done +} + +case $1 in + true) stop_polling;; + false) restart_polling;; + help) help;; + *) exit $NA;; +esac |