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>
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()