Revision: 784
http://fail2ban.svn.sourceforge.net/fail2ban/?rev=784&view=rev
Author: yarikoptic
Date: 2011-09-24 02:28:45 +0000 (Sat, 24 Sep 2011)
Log Message:
-----------
BF: Lock server's executeCmd to prevent racing among iptables calls (Closes: #554162)
Many kudos go to Michael Saavedra for the solution and the patch.
Modified Paths:
--------------
branches/FAIL2BAN-0_8/server/action.py
Modified: branches/FAIL2BAN-0_8/server/action.py
===================================================================
--- branches/FAIL2BAN-0_8/server/action.py 2011-08-07 02:41:08 UTC (rev 783)
+++ branches/FAIL2BAN-0_8/server/action.py 2011-09-24 02:28:45 UTC (rev 784)
@@ -25,11 +25,15 @@
__license__ = "GPL"
import logging, os
+import threading
#from subprocess import call
# Gets the instance of the logger.
logSys = logging.getLogger("fail2ban.actions.action")
+# Create a lock for running system commands
+_cmd_lock = threading.Lock()
+
##
# Execute commands.
#
@@ -301,17 +305,21 @@
#@staticmethod
def executeCmd(realCmd):
logSys.debug(realCmd)
- try:
- # The following line gives deadlock with multiple jails
- #retcode = call(realCmd, shell=True)
- retcode = os.system(realCmd)
- if retcode == 0:
- logSys.debug("%s returned successfully" % realCmd)
- return True
- else:
- logSys.error("%s returned %x" % (realCmd, retcode))
- except OSError, e:
- logSys.error("%s failed with %s" % (realCmd, e))
+ _cmd_lock.acquire()
+ try: # Try wrapped within another try needed for python version < 2.5
+ try:
+ # The following line gives deadlock with multiple jails
+ #retcode = call(realCmd, shell=True)
+ retcode = os.system(realCmd)
+ if retcode == 0:
+ logSys.debug("%s returned successfully" % realCmd)
+ return True
+ else:
+ logSys.error("%s returned %x" % (realCmd, retcode))
+ except OSError, e:
+ logSys.error("%s failed with %s" % (realCmd, e))
+ finally:
+ _cmd_lock.release()
return False
executeCmd = staticmethod(executeCmd)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|