mirror of https://github.com/fail2ban/fail2ban
RF/BF: just use pyinotify.ThreadedNotifier thread in filterpyinotify
that seems also to overcome the problem of often locking upon stop()pull/8/merge
parent
25674a95f8
commit
baa09098f0
|
@ -101,42 +101,36 @@ class FilterPyinotify(FileFilter):
|
||||||
##
|
##
|
||||||
# Main loop.
|
# Main loop.
|
||||||
#
|
#
|
||||||
# This function is the main loop of the thread. It checks if the
|
# Since all detection is offloaded to pyinotifier -- no manual
|
||||||
# file has been modified and looks for failures.
|
# loop is necessary
|
||||||
# @return True when the thread exits nicely
|
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
self.setActive(True)
|
self.setActive(True)
|
||||||
self.__notifier = pyinotify.ThreadedNotifier(self.__monitor,
|
self.__notifier = pyinotify.ThreadedNotifier(self.__monitor,
|
||||||
ProcessPyinotify(self))
|
ProcessPyinotify(self))
|
||||||
self.__notifier.start()
|
self.__notifier.start()
|
||||||
while self._isActive():
|
logSys.debug("pyinotifier started for %s." % self.jail.getName())
|
||||||
if not self.getIdle():
|
# TODO: verify that there is nothing really to be done for
|
||||||
self.__notifier.process_events()
|
# idle jails
|
||||||
if self.__notifier.check_events():
|
|
||||||
self.__notifier.read_events()
|
|
||||||
else:
|
|
||||||
time.sleep(self.getSleepTime())
|
|
||||||
# Cleanup pyinotify
|
|
||||||
self.__cleanup()
|
|
||||||
logSys.debug(self.jail.getName() + ": filter terminated")
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
##
|
##
|
||||||
# Call super.stop() and then stop the 'Notifier'
|
# Call super.stop() and then stop the 'Notifier'
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
# Call super to set __isRunning
|
|
||||||
super(FilterPyinotify, self).stop()
|
super(FilterPyinotify, self).stop()
|
||||||
# Now stop the Notifier, otherwise we're deadlocked
|
|
||||||
|
# Stop the notifier thread
|
||||||
self.__notifier.stop()
|
self.__notifier.stop()
|
||||||
|
self.__notifier.join() # to not exit before notifier does
|
||||||
|
self.__cleanup() # for pedantic ones
|
||||||
|
|
||||||
##
|
##
|
||||||
# Deallocates the resources used by pyinotify.
|
# Deallocates the resources used by pyinotify.
|
||||||
|
|
||||||
def __cleanup(self):
|
def __cleanup(self):
|
||||||
del self.__notifier
|
self.__notifier = None
|
||||||
del self.__monitor
|
self.__monitor = None
|
||||||
|
|
||||||
|
|
||||||
class ProcessPyinotify(pyinotify.ProcessEvent):
|
class ProcessPyinotify(pyinotify.ProcessEvent):
|
||||||
|
|
Loading…
Reference in New Issue