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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
#!/bin/sh
#
# apmd_proxy - program dispatcher for APM daemon
# Craig Markwardt (craigm@lheamail.gsfc.nasa.gov) 21 May 1999
# Debian-specific version rewritten by Avery Pennarun.
#
# This shell script is called by the APM daemon (apmd) when the state
# of any power management function has changed. The exact events that
# trigger the calling of apmd_proxy depend on how apmd was configured
# at compile time.
#
# In Debian, you should add scripts to /etc/apm/event.d (or the legacy
# /etc/apm/suspend.d and resume.d directories) rather than editing this
# script directly, unless you have a good reason.
#
# apmd_proxy is called with specific arguments that describe the event
# that has occurred. It is this script's responsibility to query the
# hardware or the APM service (via /proc/apm) for more information,
# and to take the appropriate action.
#
# For example, apmd will call "apmd_proxy suspend system" just before
# the system is scheduled to go into suspend mode.
#
# If the APM kernel module supports it, apmd_proxy can return an error
# code for the suspend and standby events, indicating whether the
# pending mode should be rejected. For example, apmd_proxy may decide
# if, based on CPU or network activity, a suspend should be rejected.
#
# RETURN VALUE:
# 0 - nominal return; suspend and standby events are accepted
# 1 - reject a suspend or standby (MUST HAVE APM KERNEL SUPPORT)
#
# Here are the calling sequences for apmd_proxy:
#
# apmd_proxy start - APM daemon has started
# apmd_proxy stop - APM daemon is shutting down
# apmd_proxy suspend system - APM system has requested suspend mode
# apmd_proxy suspend critical - APM system indicates critical suspend (*)
# apmd_proxy standby system - APM system has requested standby mode
# apmd_proxy suspend user - User has requested suspend mode
# apmd_proxy standby user - User has requested standby mode
# apmd_proxy resume suspend - System has resumed from suspend mode
# apmd_proxy resume standby - System has resumed from standby mode
# apmd_proxy resume critical - System has resumed from critical suspend
# apmd_proxy change battery - APM system reported low battery
# apmd_proxy change power - APM system reported AC/battery change
# apmd_proxy change time - APM system reported time change (*)
# apmd_proxy change capability - APM system reported config. change (+)
#
# (*) - APM daemon may be configured to not call these sequences
# (+) - Available if APM kernel supports it.
#
# *******************************************************************
# Debian's run-parts program doesn't let you pass parameters to the called
# programs, so we must roll our own. Luckily, it's really easy to do.
#
exec_dir() {
DIR="$1"
if [ -d "$DIR" ]; then
shift
for d in $(ls $DIR | grep '^[-_0-9A-Za-z]\+$'); do
$DIR/$d "$@"
done
fi
}
if [ "$1,$2" = "standby,system" -o "$1,$2" = "suspend,system" ]; then
if on_ac_power >/dev/null; then
# Reject system suspends and standbys if we are on AC power
exit 1 # Reject (NOTE kernel support must be enabled)
fi
# otherwise fall through and call the scripts!
fi
# old-style /etc/apm/suspend.d and resume.d directories; note that these
# scripts usually don't check their command line parameters, since older
# versions of apmd didn't provide any!
#
[ "$1" = "suspend" ] && exec_dir /etc/apm/suspend.d "$@"
[ "$1,$2" = "resume,suspend" ] && exec_dir /etc/apm/resume.d "$@"
# new-style event.d directory. All new event scripts go here.
#
exec_dir /etc/apm/event.d "$@"
exit 0
|