X-Git-Url: http://gitweb.hugovil.com/?a=blobdiff_plain;f=stage2%2Fmisc%2Facpi%2Fsuspend2ram.sh;h=6fdbd96e194300aaad82845483c4155ea6f304d4;hb=d93443fd15258fa1e553233d64efcd91be89ab18;hp=11cd412f76a0577c88dddf76e21ba9b86ffa39ea;hpb=e834051c6c8f8cc6d30c181efec384fb7b5d5364;p=hvlinux.git diff --git a/stage2/misc/acpi/suspend2ram.sh b/stage2/misc/acpi/suspend2ram.sh index 11cd412..6fdbd96 100755 --- a/stage2/misc/acpi/suspend2ram.sh +++ b/stage2/misc/acpi/suspend2ram.sh @@ -1,8 +1,36 @@ #!/bin/sh -if grep -q open /proc/acpi/button/lid/LID/state; then - # Do not act on lid opened event. Only on lid closed. - exit 0 +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 @@ -19,13 +47,8 @@ sync # temporary file cat /proc/bus/pci/$ID > $TMP_FILE -# Stopping network. -# Sony VAIO PCG-Z505RX and PCMCIA Linksys wifi card -/etc/rc.d/init.d/network stop - echo "Entering suspend mode" -# suspend echo -n mem > /sys/power/state echo "Resuming" @@ -34,7 +57,5 @@ echo "Resuming" # on resume cat $TMP_FILE > /proc/bus/pci/$ID -/etc/rc.d/init.d/network start - # remove temporary file rm -f $TMP_FILE