From 2bce0c5e3ee805779359b02e4ad5272b32553e77 Mon Sep 17 00:00:00 2001 From: sebres Date: Mon, 15 Jan 2018 18:00:15 +0100 Subject: [PATCH] file-filter's: provide stop function in order to explicitly delete/stop monitoring of each file. --- fail2ban/server/filter.py | 9 +++++++++ fail2ban/server/filterpyinotify.py | 3 ++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/fail2ban/server/filter.py b/fail2ban/server/filter.py index c309bbb2..25a0e687 100644 --- a/fail2ban/server/filter.py +++ b/fail2ban/server/filter.py @@ -1061,6 +1061,15 @@ class FileFilter(Filter): ret.append(("File list", path)) return ret + def stop(self): + """Stop monitoring of log-file(s) + """ + # stop files monitoring: + for path in self.__logs.keys(): + self.delLogPath(path) + # stop thread: + super(Filter, self).stop() + ## # FileContainer class. # diff --git a/fail2ban/server/filterpyinotify.py b/fail2ban/server/filterpyinotify.py index ef26303a..17d387a1 100644 --- a/fail2ban/server/filterpyinotify.py +++ b/fail2ban/server/filterpyinotify.py @@ -78,6 +78,7 @@ class FilterPyinotify(FileFilter): self.__modified = False # Pyinotify watch manager self.__monitor = pyinotify.WatchManager() + self.__notifier = None self.__watchFiles = dict() self.__watchDirs = dict() self.__pending = dict() @@ -240,7 +241,7 @@ class FilterPyinotify(FileFilter): def _delFileWatcher(self, path): try: wdInt = self.__watchFiles.pop(path) - if not self._delWatch(wdInt): # pragma: no cover + if not self._delWatch(wdInt): logSys.debug("Non-existing file watcher %r for file %s", wdInt, path) logSys.debug("Removed file watcher for %s", path) return True