From 8161038987608d58c5202977048a8b3f6a462ad6 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Fri, 10 May 2013 11:40:12 -0400 Subject: [PATCH] ENH: strengthen detection of working pyinotify Even though import might work -- pyinotify might be dysfunctional. Check by creating/deleting a dummy WatchManager upon import --- server/filterpyinotify.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/server/filterpyinotify.py b/server/filterpyinotify.py index 4c270d2e..cea82711 100644 --- a/server/filterpyinotify.py +++ b/server/filterpyinotify.py @@ -23,19 +23,28 @@ __author__ = "Cyril Jaquier, Lee Clemens, Yaroslav Halchenko" __copyright__ = "Copyright (c) 2004 Cyril Jaquier, 2011-2012 Lee Clemens, 2012 Yaroslav Halchenko" __license__ = "GPL" +import time, logging, pyinotify + from distutils.version import LooseVersion +from os.path import dirname, sep as pathsep from failmanager import FailManagerEmpty from filter import FileFilter from mytime import MyTime -import time, logging, pyinotify if not hasattr(pyinotify, '__version__') \ or LooseVersion(pyinotify.__version__) < '0.8.3': raise ImportError("Fail2Ban requires pyinotify >= 0.8.3") -from os.path import dirname, sep as pathsep +# Verify that pyinotify is functional on this system +# Even though imports -- might be dysfunctional, e.g. as on kfreebsd +try: + manager = pyinotify.WatchManager() + del manager +except Exception, e: + raise ImportError("Pyinotify is probably not functional on this system: %s" + % str(e)) # Gets the instance of the logger. logSys = logging.getLogger("fail2ban.filter")