diff options
author | sebres <serg.brester@sebres.de> | 2015-07-06 12:23:53 +0200 |
---|---|---|
committer | sebres <serg.brester@sebres.de> | 2015-07-06 12:23:53 +0200 |
commit | 81e659b760476a9aaeae788dce309458d0e704e6 (patch) | |
tree | 9da05dafc22c0400b620b2a7320d90d8887df720 /bin/fail2ban-client | |
parent | 38f8e1a82a389ef4c9205206858a1fd2798b820d (diff) | |
download | fail2ban-81e659b760476a9aaeae788dce309458d0e704e6.tar.gz |
performance fix: minimizes connection overhead, using same socket by multiple commands without close it (ex.: 'start' sends several hundreds commands at once)
Diffstat (limited to 'bin/fail2ban-client')
-rwxr-xr-x | bin/fail2ban-client | 50 |
1 files changed, 28 insertions, 22 deletions
diff --git a/bin/fail2ban-client b/bin/fail2ban-client index ada4b376..7f3f5639 100755 --- a/bin/fail2ban-client +++ b/bin/fail2ban-client @@ -153,30 +153,36 @@ class Fail2banClient: return self.__processCmd([["ping"]], False) def __processCmd(self, cmd, showRet = True): - beautifier = Beautifier() - streamRet = True - for c in cmd: - beautifier.setInputCmd(c) - try: - client = CSocket(self.__conf["socket"]) - ret = client.send(c) - if ret[0] == 0: - logSys.debug("OK : " + `ret[1]`) + client = None + try: + beautifier = Beautifier() + streamRet = True + for c in cmd: + beautifier.setInputCmd(c) + try: + if not client: + client = CSocket(self.__conf["socket"]) + ret = client.send(c) + if ret[0] == 0: + logSys.debug("OK : " + `ret[1]`) + if showRet: + print beautifier.beautify(ret[1]) + else: + logSys.error("NOK: " + `ret[1].args`) + if showRet: + print beautifier.beautifyError(ret[1]) + streamRet = False + except socket.error: if showRet: - print beautifier.beautify(ret[1]) - else: - logSys.error("NOK: " + `ret[1].args`) + self.__logSocketError() + return False + except Exception, e: if showRet: - print beautifier.beautifyError(ret[1]) - streamRet = False - except socket.error: - if showRet: - self.__logSocketError() - return False - except Exception, e: - if showRet: - logSys.error(e) - return False + logSys.error(e) + return False + finally: + if client: + client.close() return streamRet def __logSocketError(self): |