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).
Signed-off-by: NeilBrown <neilb@suse.de>
int suspend_block(int handle);
void suspend_allow(int handle);
int suspend_close(int handle);
-
+void suspend_abort(int handle);
void *suspend_watch(int (*will_suspend)(void *data),
void (*did_resume)(void *data),
while (1) {
int count;
+ struct timespec ts;
+ struct stat stb;
/* Don't accept an old request */
unlink("/var/run/suspend/request");
/* Next two might block, but that doesn't abort suspend */
count = read_wakeup_count();
+ fstat(disable, &stb);
+ ts = stb.st_atim;
alert_watchers();
+ fstat(disable, &stb);
if (flock(disable, LOCK_EX|LOCK_NB) == 0
&& request_valid()
+ && ts.tv_sec == stb.st_atim.tv_sec
+ && ts.tv_nsec == stb.st_atim.tv_nsec
&& set_wakeup_count(count))
do_suspend();
flock(disable, LOCK_UN);
blockfd.close()
blockfd = None
+def abort_cycle():
+ fd = open('/var/run/suspend/disabled')
+ fd.read(1)
+ fd.close()
if __name__ == '__main__':
import signal
close(handle);
}
+void suspend_abort(int handle)
+{
+ int h = handle;
+ char c;
+ if (handle < 0)
+ h = suspend_open();
+ read(h, &c, 1);
+ if (handle < 0)
+ suspend_close(h);
+}