]> git.neil.brown.name Git - susman.git/commitdiff
cycle_watchers: don't write the 'all done' signal until after the rename.
authorNeilBrown <neilb@suse.de>
Sun, 22 Apr 2012 04:23:15 +0000 (14:23 +1000)
committerNeilBrown <neilb@suse.de>
Sun, 22 Apr 2012 04:23:15 +0000 (14:23 +1000)
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.

i.e. close a small and probably unimportant race.

Signed-off-by: NeilBrown <neilb@suse.de>
lsusd.c

diff --git a/lsusd.c b/lsusd.c
index dff24f4170cc744f2934385c4b40d26adc0cb272..c9eab8821ea4236e126ed78bf61a6bc8a8848d58 100644 (file)
--- a/lsusd.c
+++ b/lsusd.c
@@ -58,14 +58,11 @@ static void cycle_watchers(void)
        fd = open("/var/run/suspend/watching", O_RDWR|O_CREAT, 0640);
        if (fd < 0)
                return;
-       zero[0] = zero[1] = 0;
-       if (write(fd, zero, 2) != 2) {
-               close(fd);
-               return;
-       }
-       close(fd);
        rename("/var/run/suspend/watching-next",
               "/var/run/suspend/watching");
+       zero[0] = zero[1] = 0;
+       write(fd, zero, 2);
+       close(fd);
 }
 
 static int read_wakeup_count()