]> git.neil.brown.name Git - susman.git/commitdiff
lsusd: allow clients to abort this suspend cycle.
authorNeilBrown <neilb@suse.de>
Sun, 22 Apr 2012 04:19:19 +0000 (14:19 +1000)
committerNeilBrown <neilb@suse.de>
Sun, 22 Apr 2012 04:19:19 +0000 (14:19 +1000)
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>
libsus.h
lsusd.c
suspend.py
suspend_block.c

index 56e4432e265fcd45c5de11f2fe6f72d351c93b4f..f3161e282c50ae0778912c78b778a4330ac866ca 100644 (file)
--- 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 42b1b5cd6a7927c5e604ecc47dc05a359a2275b0..dff24f4170cc744f2934385c4b40d26adc0cb272 100644 (file)
--- 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);
index 3ff096d36295d91bed533050703c63246f1bbe87..f0703343c657c7d16a1634b5c4f7f1a799bf4836 100644 (file)
@@ -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
index e50c1f3cbd12450a3843f73faf66f0667a3edc9b..93dd5d91c40c11090fc01f6bfd3c217008845c3f 100644 (file)
@@ -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);
+}