[ltp] belt & suspenders suspend-to-ram script for acpid

Eric Jorgensen linux-thinkpad@linux-thinkpad.org
Thu, 22 Jun 2006 01:57:29 -0600


   This is tailored to my X21, so there are a few specific items that
are specific to the X20/X21/T20 and similar machines. Users of better
thinkpads will have to substitute the appropriate video bits. 

   However, I'm pretty proud of having worked around all the garbage
that's been annoying me. 

   Firstly, there is logic to prevent going to sleep if the thinkpad has
only just awakened in the last minute. This resolves the most annoying
thing my thinkpad has ever done -- requiring me to wake it up three
times. 

   The wiki refers to this behavior as a known bug in the HAL and links
to another site for a workaround, but the page it links to no longer
contains a workaround. the gnome power monitor folks fixed it in their
own app. 

   Secondly, there is a workaround for the fgconsole bug with regard to
xorg. for some reason, fgconsole doesn't work in xorg and possibly other
variations of xwindows, so the "chvt $FGCONSOLE" trick in the example
script in the wiki will leave most users in a text console after resume.
This workaround is hard-coded to presume that your xwindows console is
vt 7. Basically, if fgconsole returns an error, make $FGCONSOLE equal to
7. 

   As compared to the example script on the wiki, I've also added bits
to make the led blink the way it did in the old APM days. Also presumes
that you have the laptop_mode utility installed. 

   This script is hackish, but it works. If i get around to creating a
wiki account, I'll add my workarounds there - or someone else can, if
they beat me to it. 

-------------------------------------------

#!/bin/sh
find /tmp -name modafinil -mmin +1 -exec rm {} \;

if [ -e /tmp/modafinil ]
then
   exit 1;
fi

echo -n "7 blink" >/proc/acpi/ibm/led
/sbin/hwclock --systohc
rmmod uhci_hcd
sync

fgconsole &>/dev/null
if [ $? -eq 1 ]
then
   FGCONSOLE=7
else
   FGCONSOLE='fgconsole'
fi

chvt 6
/usr/sbin/vbetool dpms off
echo -n "7 on" >/proc/acpi/ibm/led

echo -n "mem" > /sys/power/state

echo -n "7 blink" >/proc/acpi/ibm/led
/usr/sbin/vbetool dpms on
chvt $FGCONSOLE
modprobe uhci_hcd
/sbin/hwclock --adjust
/sbin/hwclock --hctosys
echo -n "7 off" > /proc/acpi/ibm/led
/usr/sbin/laptop_mode auto

touch /tmp/modafinil