From e57f6ad4748a5db7e2456d32beb0ad10b6e57ef4 Mon Sep 17 00:00:00 2001 From: lostcontrol Date: Sun, 22 Jan 2006 11:10:29 +0000 Subject: [PATCH] - Added a more robust firewall initialization loop. Thanks to Yaroslav Halchenko git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@235 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- fail2ban.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/fail2ban.py b/fail2ban.py index f192f5b5..1ab2ab90 100755 --- a/fail2ban.py +++ b/fail2ban.py @@ -423,7 +423,25 @@ def main(): else: logSys.warn(ip + " is not a valid IP address") - initializeFwRules() + # Startup loop -- necessary to avoid crash if it takes time for iptables + # to startup. To avoid introduction of new config options, reusing + # maxreinits and polltime. + reinits = 0 + while True: + try: + initializeFwRules() + break + except ExternalError, e: + reinits += 1 + logSys.warn(e) + if conf["maxreinits"] < 0 or (reinits < conf["maxreinits"]): + logSys.warn("#%d attempt to initialize the firewalls" % reinits) + else: + logSys.error("Exiting: Too many attempts to initialize the " + + "firewall") + killApp() + time.sleep(conf["polltime"]) + # try to reinit once if it fails immediately lastReinitTime = time.time() - conf["reinittime"] - 1 reinits = 0