From 379aa2f855697598e8e0560cbd07d6e12d2d76b5 Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Mon, 17 Dec 2007 19:53:33 +0000 Subject: [PATCH] - Display a message if we could not bind the socket. git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/branches/FAIL2BAN-0_8@636 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- server/asyncserver.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/server/asyncserver.py b/server/asyncserver.py index f5c129d8..2f6f1b9f 100644 --- a/server/asyncserver.py +++ b/server/asyncserver.py @@ -25,7 +25,7 @@ __copyright__ = "Copyright (c) 2004 Cyril Jaquier" __license__ = "GPL" from pickle import dumps, loads, HIGHEST_PROTOCOL -import asyncore, asynchat, socket, os, logging, sys +import asyncore, asynchat, socket, os, logging # Gets the instance of the logger. logSys = logging.getLogger("fail2ban.server") @@ -46,7 +46,6 @@ class RequestHandler(asynchat.async_chat): self.__buffer = [] # Sets the terminator. self.set_terminator(RequestHandler.END_STRING) - self.found_terminator = self.handle_request_line def collect_incoming_data(self, data): logSys.debug("Received raw data: " + str(data)) @@ -57,7 +56,7 @@ class RequestHandler(asynchat.async_chat): # # This method is called once we have a complete request. - def handle_request_line(self): + def found_terminator(self): # Joins the buffer items. message = loads("".join(self.__buffer)) # Gives the message to the transmitter. @@ -125,12 +124,15 @@ class AsyncServer(asyncore.dispatcher): # Creates the socket. self.create_socket(socket.AF_UNIX, socket.SOCK_STREAM) self.set_reuse_addr() - self.bind(sock) + try: + self.bind(sock) + except Exception: + raise AsyncServerException("Unable to bind socket %s" % self.__sock) self.listen(1) # Sets the init flag. self.__init = True # TODO Add try..catch - asyncore.loop(timeout = 2) + asyncore.loop() ## # Stops the communication server.