summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Lowther <victor.lowther@gmail.com>2010-06-14 08:15:30 -0500
committerVictor Lowther <victor.lowther@gmail.com>2010-06-14 08:15:30 -0500
commitb5abeba798d406c1a2b9667966768223b890f19b (patch)
tree652ab5af1c185d99c0df18bf8e548c854a6850c5
parentf81a0b13ebd8f6e0f3c3d0ed71e243cf10f0a7f7 (diff)
Add a hook to disable polling optical media while on battery.
-rwxr-xr-xpm/power.d/hal-cd-polling49
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