Skip to content
Snippets Groups Projects
Commit 46c9b31d authored by Guido Trotter's avatar Guido Trotter
Browse files

ConfdInotifyEventHandler: add enable/disable


Make possible to enable and disable the inotify event handler.  The
inotify handler will remain enabled, unless explicitely told to disable
itself.

Signed-off-by: default avatarGuido Trotter <ultrotter@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent d4c1bd12
No related branches found
No related tags found
No related merge requests found
...@@ -113,15 +113,28 @@ class ConfdInotifyEventHandler(pyinotify.ProcessEvent): ...@@ -113,15 +113,28 @@ class ConfdInotifyEventHandler(pyinotify.ProcessEvent):
self.mask = pyinotify.EventsCodes.IN_IGNORED | \ self.mask = pyinotify.EventsCodes.IN_IGNORED | \
pyinotify.EventsCodes.IN_MODIFY pyinotify.EventsCodes.IN_MODIFY
self.file = file self.file = file
self.add_config_watch() self.watch_handle = None
self.enable()
def add_config_watch(self): def enable(self):
"""Add a watcher for the ganeti config file """Watch the given file
""" """
result = self.watch_manager.add_watch(self.file, self.mask) if self.watch_handle is None:
if not result[self.file] > 0: result = self.watch_manager.add_watch(self.file, self.mask)
raise errors.ConfdFatalError("Could not add inotify watcher") if not self.file in result or result[self.file] <= 0:
raise errors.ConfdFatalError("Could not add inotify watcher")
else:
self.watch_handle = result[self.file]
def disable(self):
"""Stop watching the given file
"""
if self.watch_handle is not None:
result = self.watch_manager.rm_watch(self.watch_handle)
if result[self.watch_handle]:
self.watch_handle = None
def reload_config(self): def reload_config(self):
try: try:
...@@ -143,13 +156,14 @@ class ConfdInotifyEventHandler(pyinotify.ProcessEvent): ...@@ -143,13 +156,14 @@ class ConfdInotifyEventHandler(pyinotify.ProcessEvent):
# contextual with the replacement). In such a case we need to create # contextual with the replacement). In such a case we need to create
# another watcher for the "new" file. # another watcher for the "new" file.
logging.debug("Received 'ignored' inotify event for %s" % event.path) logging.debug("Received 'ignored' inotify event for %s" % event.path)
self.watch_handle = None
try: try:
# Since the kernel believes the file we were interested in is gone, it's # Since the kernel believes the file we were interested in is gone, it's
# not going to notify us of any other events, until we set up, here, the # not going to notify us of any other events, until we set up, here, the
# new watch. This is not a race condition, though, since we're anyway # new watch. This is not a race condition, though, since we're anyway
# going to realod the file after setting up the new watch. # going to realod the file after setting up the new watch.
self.add_config_watch() self.enable()
self.reload_config() self.reload_config()
except errors.ConfdFatalError, err: except errors.ConfdFatalError, err:
logging.critical("Critical error, shutting down: %s" % err) logging.critical("Critical error, shutting down: %s" % err)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment