|
Server : Apache/2.2.17 (Unix) mod_ssl/2.2.17 OpenSSL/0.9.8e-fips-rhel5 DAV/2 PHP/5.2.17 System : Linux localhost 2.6.18-419.el5 #1 SMP Fri Feb 24 22:47:42 UTC 2017 x86_64 User : nobody ( 99) PHP Version : 5.2.17 Disable Function : NONE Directory : /proc/21572/root/usr/lib/pm-utils/ |
Upload File : |
#!/bin/bash
export PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/lib/pm-utils/bin
# Default values go here. It is important to _not_ initialize some
# variables here. They are:
#
# PM_CMDLINE
# RESUME_MODULES
#
HIBERNATE_RESUME_POST_VIDEO=no
INHIBIT=/var/run/pm-utils.inhibit
PM_LOGFILE=${PM_LOGFILE:=/var/log/pm/suspend.log}
SUSPEND_MODULES=""
TEMPORARY_CPUFREQ_GOVERNOR="userspace"
DISABLE_HIBERNATE="no"
DISABLE_SUSPEND="no"
set -a
[ -f /usr/lib/pm-utils/defaults ] && . /usr/lib/pm-utils/defaults
set +a
source_configs()
{
cfgs="/etc/pm/config.d/*[^~]"
for cfg in $cfgs ; do
[ -f $cfg ] || continue
set -a
. $cfg
set +a
done
}
source_configs
take_suspend_lock()
{
VT=$(fgconsole)
chvt 63
if [ -f /.suspended ]; then
read pid < /.suspended
if [ -d /proc/$pid ]; then
return 1
fi
fi
echo "$$" > /.suspended
rm -f /var/run/pm-suspend
touch /var/run/pm-suspend
return 0
}
remove_suspend_lock()
{
rm -f /var/run/pm-suspend
chvt 1
chvt $VT
openvt -- sh -c "usleep $1 ; rm -f /.suspended >/dev/null 2>&1 0<&1" >/dev/null 2>&1 0<&1 &
}
find_sleepd_files()
{
flist="/etc/pm/sleep.d/*[^~] /usr/lib/pm-utils/sleep.d/*[^~]"
bases=$(for file in $flist ; do echo $(basename $file) ; done | sort -n)
for base in $bases ; do
if [ -e "/etc/pm/sleep.d/$base" ]; then
if [ -x "/etc/pm/sleep.d/$base" ]; then
echo /etc/pm/sleep.d/$base
fi
elif [ -x "/usr/lib/pm-utils/sleep.d/$base" ]; then
echo /usr/lib/pm-utils/sleep.d/$base
fi
done
}
run_hooks()
{
[ -z "$1" ] && return 0
[ -f /var/run/pm-suspend ] && . /var/run/pm-suspend
rm -f /var/run/pm-suspend
echo "$(date): running $1 hooks."
files=$(find_sleepd_files)
if [ "$2" = "reverse" ]; then
filea=($files)
filen=${#filea[*]}
while [ "$filen" -gt 0 ]; do
let filen--
file="${filea[$filen]}"
echo "===== $(date): running hook: $file ====="
$file $1
done
else
for file in $files ; do
echo "===== $(date): running hook: $file ====="
$file $1
done
fi
echo "$(date): done running $1 hooks."
}
get_power_status()
{
RETVAL=0
on_ac_power
case "$?" in
"0")
echo "ac"
;;
"1")
echo "battery"
;;
"255")
echo "error"
RETVAL=1
;;
esac
return $RETVAL
}
do_suspend()
{
[ ${DISABLE_SUSPEND} == "yes" ] && return 0
if [ "$QUIRKOPTS" == "true" ]; then
pm-pmu --suspend || echo -n "mem" > /sys/power/state
else
dbus-send --system --print-reply \
--dest=org.freedesktop.Hal \
--type=method_call \
/org/freedesktop/Hal/devices/computer \
org.freedesktop.Hal.Device.SystemPowerManagement.Suspend \
int32:0
if [ ! $? -eq 0 ]; then
return 1
fi
fi
return 0
}
do_hibernate()
{
[ ${DISABLE_HIBERNATE} == "yes" ] && return 0
if [ "$QUIRKOPTS" == "true" ]; then
echo -n "platform" > /sys/power/disk
echo -n "disk" > /sys/power/state
else
dbus-send --system --print-reply \
--dest=org.freedesktop.Hal \
--type=method_call \
/org/freedesktop/Hal/devices/computer \
org.freedesktop.Hal.Device.SystemPowerManagement.Hibernate
if [ ! $? -eq 0 ]; then
return 1
fi
fi
return 0
}
do_suspend_hybrid()
{
return 1
}
get_video_type()
{
vendor=""
vendor=$(/sbin/lspci -mn|awk '{if ($2 ~ /^"0300"$/ ) {print $3;exit;}}')
vendor=$(eval echo $vendor)
[ -z "$vendor" ] && return 1
case "$vendor" in
1002)
echo ATI
return 0
;;
10de)
echo nVidia
return 0
;;
8086)
echo Intel
return 0
;;
*)
echo $vendor
return 0
;;
esac
}
do_autoquirks()
{
case "$(get_video_type)" in
ATI)
export DISPLAY_QUIRK_DPMS_SUSPEND="true"
;;
Intel)
export DISPLAY_QUIRK_DPMS_SUSPEND="true"
export DISPLAY_QUIRK_VBE_POST="true"
;;
nVidia)
export DISPLAY_QUIRK_VBESTATE_RESTORE="true"
export DISPLAY_QUIRK_DPMS_SUSPEND="true"
export DISPLAY_QUIRK_DPMS_ON="true"
export DISPLAY_QUIRK_VBE_POST="true"
;;
*)
;;
esac
}
pm_main()
{
if [ -n "$PM_LOGFILE" ]; then
[ -f "$PM_LOGFILE" ] && rm -f "$PM_LOGFILE"
exec > "$PM_LOGFILE" 2>&1
fi
# only take suspend lock and run_hooks when we are going to really
# suspend.
if [ "$QUIRKOPTS" == "true" ]; then
take_suspend_lock || exit 1
rm -f "$INHIBIT"
run_hooks "$1"
fi
if [ ! -e "$INHIBIT" -a "$(type -t "do_$1")" == "function" ]; then
sync ; sync ; sync
"do_$1"
fi
# only reversely run hooks and release suspend lock when we really
# were suspended.
if [ "$QUIRKOPTS" == "true" ]; then
run_hooks "$2" reverse
remove_suspend_lock 200
fi
return 0
}
_rmmod() {
if modprobe -r $1; then
echo "export RESUME_MODULES=\"$1 \$RESUME_MODULES\"" \
>> /var/run/pm-suspend
return 0
else
echo "# could not unload '$1', usage count was $2"
return 1
fi
}
# this recursively unloads the given modules and all that depend on it
# first parameter is the module to be unloaded
modunload()
{
local MOD D C USED MODS I
local UNL=$1 RET=1
# the kernel only knows underscores in module names, no dashes
UNL=${UNL//-/_}
# RET is the return code.
# If at least one module was unloaded, return 0.
# if the module was not loaded, also return 0 since this is no error.
# if no module was unloaded successfully, return 1
while read MOD D C USED D; do
[ "$MOD" = "$UNL" ] || continue
if [ "$USED" == "-" ]; then
_rmmod $MOD $C
RET=$?
else
USED=${USED//,/ }
MODS=($USED)
# it seems slightly more likely to rmmod in one pass,
# if we try backwards.
for I in `seq $[${#MODS[@]}-1] -1 0`; do
MOD=${MODS[$I]}
modunload $MOD && RET=0
done
# if we unloaded at least one module, then let's
# try again!
[ $RET -eq 0 ] && modunload $MOD
RET=$?
fi
return $RET
done < /proc/modules
# if we came this far, there was nothing to do,
# the module is no longer loaded.
return 0
}
modreload()
{
if [ "$(eval echo \$${1}_MODULE_LOAD)" == "yes" ]; then
modprobe "$1" >/dev/null 2>&1
fi
}
_service=$(type -p service)
if [ -z "$_service" ]; then
service() {
if [ -x "/etc/init.d/$1" ]; then
"/etc/init.d/$@"
else
echo "$1" $": unrecognized service" 1>&2
return 1
fi
}
fi
unset _service
stopservice()
{
service "$1" status 2>/dev/null | grep -c -q running
if [ "$?" == "0" ]; then
N=${1//[-.]/_}
echo "export ${N}_SERVICE_ACTIVATE=yes" >> /var/run/pm-suspend
service "$1" stop
fi
}
restartservice()
{
N=${1//[-.]/_}
if [ "x$(eval echo \$${N}_SERVICE_ACTIVATE)" == "xyes" ]; then
service "$1" start
fi
}
savestate()
{
echo "export ${1}_STATE=$2" >> /var/run/pm-suspend
}
restorestate()
{
eval echo \$${1}_STATE
}