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
|
# -*- sh -*-
# vim:ft=sh:ts=8:sw=4:noet
AddConfigHandler SysfsPowerStateConfigEnabler
AddOptionHandler SysfsPowerStateOptionHandler
AddConfigHelp "UseSysfsPowerState <state>" "Enables the use of /sys/power/state for suspending the machine (to RAM or disk). This requires a kernel supporting this interface. <state> must be one of the options listed by \`cat /sys/power/state\`, (eg mem, disk, or standby)."
AddConfigHelp "PowerdownMethod <shutdown|platform|firmware> (requires UseSysfsPowerState)" "If using /sys/power/state to suspend your machine to disk, chooses the method by which to do so. Choosing \"shutdown\" will save state in linux, then tell the bios to powerdown (most reliable). Choosing \"platform\" will save state in linux, then tell the bios to powerdown and blink it's \"suspended LED\". Choosing \"firmware\" will tell the bios to save state itself (needs BIOS-specific suspend partition, and has very little to do with swsusp)."
AddShortOption "n"
AddLongOption "no-suspend"
AddOptionHelp "-n, --no-suspend (requires SysfsPowerState to be set)" "Disables actually suspending the system via /sys/power/state. This is useful for testing the suspend script itself."
SYSFS_POWER_STATE_FILE=/sys/power/state
SYSFS_POWERDOWN_METHOD_FILE=/sys/power/disk
SysfsPowerStateConfigEnabler() {
[ "$1" != "usesysfspowerstate" ] && return 1
[ -n "$USING_SYSFS_POWER_STATE" ] && return 0
AddConfigHandler SysfsPowerStateConfigOptions
AddSuspendHook 10 EnsureSysfsPowerStateCapable
AddSuspendHook 99 DoSysfsPowerStateSuspend
USING_SYSFS_POWER_STATE=$2
return 0
}
SysfsPowerStateOptionHandler() {
[ -z "$USING_SYSFS_POWER_STATE" ] && return 1
case $1 in
-n|--no-suspend)
SYSFS_POWER_STATE_NO_SUSPEND=1
;;
*)
return 1
esac
return 0
}
SysfsPowerStateConfigOptions() {
case $1 in
powerdownmethod)
SYSFS_POWER_STATE_POWERDOWN_METHOD=$2
;;
*)
return 1
esac
return 0
}
DoSysfsPowerStateSuspend() {
if [ -z "$SYSFS_POWER_STATE_NO_SUSPEND" ] ; then
vecho 1 "$EXE: Activating sysfs power state $USING_SYSFS_POWER_STATE ..."
[ -n "$SYSFS_POWER_STATE_POWERDOWN_METHOD" ] && \
[ -f "$SYSFS_POWERDOWN_METHOD_FILE" ] && \
echo $SYSFS_POWER_STATE_POWERDOWN_METHOD > $SYSFS_POWERDOWN_METHOD_FILE
echo -n $USING_SYSFS_POWER_STATE > $SYSFS_POWER_STATE_FILE
else
vecho 1 "$EXE: Not actually suspending (--no-suspend given)"
fi
return 0
}
# EnsureSysfsPowerStateCapable: makes sure we have /sys/power/state and that
# the selection option is one of the available suspend modes.
EnsureSysfsPowerStateCapable() {
if ! test -f $SYSFS_POWER_STATE_FILE ; then
vecho 0 "Your kernel does not have power management built in."
return 2
fi
if ! grep -q $USING_SYSFS_POWER_STATE $SYSFS_POWER_STATE_FILE ; then
vecho 0 "Your kernel or machine does support the power state \"$USING_SYSFS_POWER_STATE\"."
return 2
fi
return 0
}
# $Id: sysfs_power_state 867 2005-03-31 11:17:46Z bernard $
|