From: NeilBrown Date: Sun, 22 Apr 2012 04:19:19 +0000 (+1000) Subject: lsusd: allow clients to abort this suspend cycle. X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=591e7bcc6036b6aea9e6046c0d9d6f58b07983c4;p=susman.git lsusd: allow clients to abort this suspend cycle. 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 --- diff --git a/libsus.h b/libsus.h index 56e4432..f3161e2 100644 --- a/libsus.h +++ b/libsus.h @@ -20,7 +20,7 @@ int suspend_open(); 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), diff --git a/lsusd.c b/lsusd.c index 42b1b5c..dff24f4 100644 --- a/lsusd.c +++ b/lsusd.c @@ -201,6 +201,8 @@ main(int argc, char *argv) while (1) { int count; + struct timespec ts; + struct stat stb; /* Don't accept an old request */ unlink("/var/run/suspend/request"); @@ -217,10 +219,15 @@ main(int argc, char *argv) /* 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); diff --git a/suspend.py b/suspend.py index 3ff096d..f070334 100644 --- a/suspend.py +++ b/suspend.py @@ -118,6 +118,10 @@ def unblock(): blockfd.close() blockfd = None +def abort_cycle(): + fd = open('/var/run/suspend/disabled') + fd.read(1) + fd.close() if __name__ == '__main__': import signal diff --git a/suspend_block.c b/suspend_block.c index e50c1f3..93dd5d9 100644 --- a/suspend_block.c +++ b/suspend_block.c @@ -50,3 +50,13 @@ int suspend_close(int handle) 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); +}