From: NeilBrown Date: Sun, 22 Apr 2012 04:18:15 +0000 (+1000) Subject: suspend.py: we need to updated the watcher when we get a new file to watch. X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=2d664d44c257f665e705f3cbd33f31547f84fcaa;p=susman.git suspend.py: we need to updated the watcher when we get a new file to watch. Signed-off-by: NeilBrown --- diff --git a/suspend.py b/suspend.py index d8b236e..3ff096d 100644 --- a/suspend.py +++ b/suspend.py @@ -58,22 +58,33 @@ class monitor: pass def change(self, watched): - if os.fstat(self.f.fileno()).st_size == 0: - if self.suspended and os.stat('/var/run/suspend/watching').st_size == 0: + if self.suspended: + # resume has happened if watching-next has been renamed. + if (os.fstat(self.f.fileno()).st_ino == + os.stat('/var/run/suspend/watching').st_ino): + global lock_watcher self.suspended = False + self.watch.cancel() + self.watch = lock_watcher.watch("watching", self.change) if self.resume: self.resume() - return - if not self.suspended and (not self.suspend or self.suspend()): - # ready for suspend - self.release() + else: + return + # not suspended, but maybe it's time + if os.fstat(self.f.fileno()).st_size > 0: + if not self.suspend or self.suspend(): + # ready for suspend + self.release() def release(self): # ready for suspend + global lock_watcher old = self.f self.f = open('/var/run/suspend/watching-next', 'r') self.getlock() self.suspended = True + self.watch.cancel() + self.watch = lock_watcher.watch("watching-next", self.change) fcntl.flock(old, fcntl.LOCK_UN) old.close()