From:
[email protected]
Package: nagios-statd-server
Version: 3.09-3
Severity: normal
Tags: patch
When restarting nagios-statd I often get a 'Address already in use'.
This patch fixes this, by setting SO_REUSEADDR in the server and the
test listening socket.
It also fixes the output of the error message to actually include the
reason why bind() failed:
--- /usr/sbin/nagios-statd 2003-11-25 21:43:47.000000000 +0100
+++ /root/nagios-statd 2004-08-17 16:23:52.000000000 +0200
@@ -136,6 +136,9 @@
self.wfile.write(line)
+class ReUsingServer (SocketServer.ForkingTCPServer):
+ allow_reuse_address = True
+
class Initialization:
"Methods for interacting with user - initial code entry point."
def __init__(self):
@@ -184,11 +187,12 @@
# Check to see if the port is available
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind((self.ip, self.port))
s.close()
del(s)
- except socket.error:
- print "Port %s is already in use. Unable to bind - exiting." % self.port
+ except socket.error, (errno, msg):
+ print "Unable to bind to port %s: %s - exiting." % (self.port, msg)
sys.exit(2)
# Detach from terminal
@@ -221,7 +225,7 @@
self.savepid(self.pidfile)
# Create a forking TCP/IP server and start processing
- serve