From 51d453a3d29b726d33e23708eb0ef9abbac5d1b8 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Sun, 16 Oct 2005 15:07:47 +0000 Subject: [PATCH] fixed issue with crashing on wrong log file added a cleanup of firewall on emergency exit --- debian/changelog | 6 +++++- fail2ban | 6 ++++++ logreader/logreader.py | 14 ++++++++------ 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/debian/changelog b/debian/changelog index 611c52bf..0d55e530 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -fail2ban (0.5.4-5.13) unstable; urgency=low +fail2ban (0.5.4-5.14) unstable; urgency=low * Added a notification regarding the importance of 0.5.4-5 change of failregex in the config file. @@ -20,6 +20,10 @@ fail2ban (0.5.4-5.13) unstable; urgency=low within sections. * Added -e command line parameter to provide enabled sections from command line. + * Added a cleanup of firewall rules on emergency shutdown when unknown + exception is catched. + * Fail2ban should not crash now if a wrong file name is specified in + config. -- Yaroslav Halchenko Mon, 3 Oct 2005 22:26:28 -1000 diff --git a/fail2ban b/fail2ban index 47707a99..10813d6f 100755 --- a/fail2ban +++ b/fail2ban @@ -55,6 +55,12 @@ except Exception, e: logSys.error("Type: " + `type.__name__` + "\n" + "Value: " + `e.args` + "\n" + "TB: " + `tbStack`) + # Try to clean up after ourselves + # just for extreme caution - wrapping with try + try: + fail2ban.restoreFwRules() + except Exception: + pass # Remove the PID lock file. Should close #1239562 pidLock.remove() logging.shutdown() diff --git a/logreader/logreader.py b/logreader/logreader.py index 29991890..1bf84887 100644 --- a/logreader/logreader.py +++ b/logreader/logreader.py @@ -97,15 +97,17 @@ class LogReader: """ try: self.logStats = os.stat(self.logPath) + + if self.lastModTime == self.logStats.st_mtime: + return False + else: + logSys.debug(self.logPath+" has been modified") + self.lastModTime = self.logStats.st_mtime + return True except OSError: logSys.error("Unable to get stat on "+self.logPath) - - if self.lastModTime == self.logStats.st_mtime: return False - else: - logSys.debug(self.logPath+" has been modified") - self.lastModTime = self.logStats.st_mtime - return True + def setFilePos(self, file): """ Sets the file position. We must take care of log file rotation