X-Git-Url: http://gitweb.hugovil.com/?a=blobdiff_plain;f=stage2%2Fmisc%2Facpi%2Fsuspend2ram.sh;h=f3bfd6d3ea9c1d1ffe8c485b5bdf8235df0f16bb;hb=6e2837a491859a48087fba6722fc605f98ad4024;hp=af34af63be1bf2f8aab56b4f796fa69254df075b;hpb=142c1bfb998e405aaaf5383b1fb8e9a49b8c0745;p=hvlinux.git diff --git a/stage2/misc/acpi/suspend2ram.sh b/stage2/misc/acpi/suspend2ram.sh index af34af6..f3bfd6d 100755 --- a/stage2/misc/acpi/suspend2ram.sh +++ b/stage2/misc/acpi/suspend2ram.sh @@ -1,10 +1,36 @@ #!/bin/sh -if [ -f /proc/acpi/button/lid/LID/state ]; then - if grep -q open /proc/acpi/button/lid/LID/state; then - # Do not act on lid opened event. Only on lid closed. - exit 0 - fi +case "$1" in + button-sleep) + logger "Sleep button pressed" + ;; + button-lid) + if [ -f /proc/acpi/button/lid/LID/state ]; then + if grep -q open /proc/acpi/button/lid/LID/state; then + logger "Lid opened detected, do nothing" + # Do not act on lid opened event. Only on lid closed. + exit 0 + fi + + logger "Lid closed detected" + fi + ;; + *) + logger "Unknown event: ${1}" + ;; +esac + +logger "Going to sleep" + +XSCREENSAVER_ACTIVE="$(pidof /usr/bin/xscreensaver)" + +# Check if xscreensaver is running. if not, just skip on. +if [ "x${XSCREENSAVER_ACTIVE}" != "x" ]; then + # Run the lock command as the user who owns xscreensaver process, + # and not as root, which won't work. + su "$(ps aux | grep xscreensaver | grep -v grep | grep ${XSCREENSAVER_ACTIVE} | awk '{print $1}' )" \ + -c "/usr/bin/xscreensaver-command -lock" & + sleep 1 fi # discover video card's ID @@ -22,6 +48,7 @@ sync cat /proc/bus/pci/$ID > $TMP_FILE # Stopping network. +/etc/rc.d/init.d/named stop /etc/rc.d/init.d/network stop echo "Entering suspend mode" @@ -36,6 +63,7 @@ echo "Resuming" cat $TMP_FILE > /proc/bus/pci/$ID /etc/rc.d/init.d/network start +/etc/rc.d/init.d/named start # remove temporary file rm -f $TMP_FILE