3 # This script should be run from /etc/apm/event.d/interlock
4 # It uses files in /var/lock/suspend to allow interlock with
5 # daemons that might need to know respond to suspend/resume events.
7 # 1/ get a flock(LOCK_SH) on /var/lock/suspend/suspend,
8 # looping if the file is found, after lock, to have no links
9 # 2/ use dnotify or similar to watch for changes to this file
10 # 3/ when the file has size > 0, prepare for suspend
11 # 3a/ take a flock(LOCK_SH) on /var/lock/suspend/next_suspend
12 # 3b/ releaes the lock on .../suspend
13 # 4/ use dnotify or similar to watch for next_suspend to be renamed to
14 # suspend. At that point wake-from-suspend processing can happen.
16 mkdir -p /var/lock/suspend
21 > /var/lock/suspend/suspend
24 # prepare for next cycle
25 > /var/lock/suspend/next_suspend
27 # wakeup daemons that care
29 # wait for those daemons to be ready
32 echo $! > /var/lock/suspend/.pid
33 } 9>> /var/lock/suspend/suspend
36 > /var/lock/suspend/next_suspend
37 mv /var/lock/suspend/next_suspend /var/lock/suspend/suspend
38 pid=`cat /var/lock/suspend/.pid`
39 rm -f /var/lock/suspend/.pid
40 if [ "$pid" -gt 1 ]; then