File: hal-cd-polling

package info (click to toggle)
pm-utils 1.4.1-21
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,432 kB
  • sloc: sh: 3,069; xml: 1,035; makefile: 174; ansic: 152
file content (53 lines) | stat: -rwxr-xr-x 1,316 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/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
	printf "Disabling HAL polling of %s..." "$c"
	hal-disable-polling --device "$c" >/dev/null 2>&1 \
	    && echo Done. || echo Failed.
    done
}

restart_polling() {
    state_exists hal_polling_disks || exit $NA
    for disk in $(restorestate hal_polling_disks); do
	printf "Reenabling HAL polling of %s..." "$disk"
	hal-disable-polling --enable-polling --device "$disk" && echo Done || \
	    echo Failed.
    done
}

case $1 in
    true) stop_polling;;
    false) restart_polling;;
    help) help;;
    *) exit $NA;;
esac