cycle_watchers: don't write the 'all done' signal until after the rename.
When a suspend cycle is finished we move the new 'watching-next' into
place and we write to the old one to make sure any process watching
will notice something has happened.
It is best to write to the file *After* the rename else a process that
notices the file change might make wrong assumptions about the
then-current 'watching' file.
When an event happens in the kernel, it increments the
wakeup_count which aborts the current suspend cycle.
We need something similar for user-space.
So use the atime of the 'disabled' file. Any process that
triggers an event for another process to read can simply
read from this file and thus abort the current suspend (if there
is one).
NeilBrown [Fri, 16 Mar 2012 01:49:52 +0000 (12:49 +1100)]
Require process requesting immediate suspend to remain active.
The process that creates 'immediate' must do so while disabling
suspend and must take a lock on the file.
If the process dies, this lock will disappear and auto-suspension
will stop.
This is a good fail-safe for development.
NeilBrown [Thu, 15 Mar 2012 20:40:00 +0000 (07:40 +1100)]
request_suspend: change check for suspend-is-disabled.
Both request_suspend and lsusd try to abort the request if suspend is
disabled. However as they use the same mechanism they can trip over
each other and produce the wrong result.
So leave the primary checking to lsusd. It will remove the 'request'
file if needed, so request_suspend will notice. It can then check
if a suspend actually happened by examining the 'watching' file.
Also: change request_suspend to exit(2) on strange error, and exit(1)
only if suspend was blocked.