mirror of https://github.com/fail2ban/fail2ban
Merge pull request #669 from kwirk/inotify-watch-auto-remove
BF: Handle case when inotify watch is auto deleted on file deletionpull/691/head
commit
2a31d45582
|
@ -90,6 +90,9 @@ class FilterPyinotify(FileFilter):
|
||||||
self._delFileWatcher(path)
|
self._delFileWatcher(path)
|
||||||
# place a new one
|
# place a new one
|
||||||
self._addFileWatcher(path)
|
self._addFileWatcher(path)
|
||||||
|
elif event.mask & pyinotify.IN_IGNORED:
|
||||||
|
# Caused when watch removed, either by rm_watch or file deletion
|
||||||
|
return
|
||||||
|
|
||||||
self._process_file(path)
|
self._process_file(path)
|
||||||
|
|
||||||
|
@ -118,9 +121,11 @@ class FilterPyinotify(FileFilter):
|
||||||
|
|
||||||
def _delFileWatcher(self, path):
|
def _delFileWatcher(self, path):
|
||||||
wdInt = self.__watches[path]
|
wdInt = self.__watches[path]
|
||||||
wd = self.__monitor.rm_watch(wdInt)
|
if wdInt is None:
|
||||||
if wd[wdInt]:
|
return False
|
||||||
del self.__watches[path]
|
elif self.__monitor.get_path(wdInt) is None or \
|
||||||
|
self.__monitor.rm_watch(wdInt)[wdInt]:
|
||||||
|
self.__watches[path] = None
|
||||||
logSys.debug("Removed file watcher for %s", path)
|
logSys.debug("Removed file watcher for %s", path)
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
|
@ -151,6 +156,7 @@ class FilterPyinotify(FileFilter):
|
||||||
def _delLogPath(self, path):
|
def _delLogPath(self, path):
|
||||||
if not self._delFileWatcher(path):
|
if not self._delFileWatcher(path):
|
||||||
logSys.error("Failed to remove watch on path: %s", path)
|
logSys.error("Failed to remove watch on path: %s", path)
|
||||||
|
del self.__watches[path]
|
||||||
|
|
||||||
path_dir = dirname(path)
|
path_dir = dirname(path)
|
||||||
if not len([k for k in self.__watches
|
if not len([k for k in self.__watches
|
||||||
|
|
Loading…
Reference in New Issue