summaryrefslogtreecommitdiffstats
path: root/src/bin/xfrout/xfrout.py.in
diff options
context:
space:
mode:
authorLikun Zhang <zlkzhy@gmail.com>2010-06-08 13:41:54 +0200
committerLikun Zhang <zlkzhy@gmail.com>2010-06-08 13:41:54 +0200
commit990e977d86a1fa58f86f381eba7430957ddbc477 (patch)
treea6941be02759e4590da00667babbbf121a9eef94 /src/bin/xfrout/xfrout.py.in
parentApplied second patch from ticket #227 (print module name on stdout/stderr out... (diff)
downloadkea-990e977d86a1fa58f86f381eba7430957ddbc477.tar.xz
kea-990e977d86a1fa58f86f381eba7430957ddbc477.zip
When xfrout is launched, check whether the socket file is being used by one running xfrout process, if it is, exit from python. If the file isn't a socket file or nobody is listening, it will be removed. If it can't be removed, exit from python.
git-svn-id: svn://bind10.isc.org/svn/bind10/trunk@2091 e5f2f494-b856-4b98-b285-d166d9295462
Diffstat (limited to '')
-rw-r--r--src/bin/xfrout/xfrout.py.in47
1 files changed, 40 insertions, 7 deletions
diff --git a/src/bin/xfrout/xfrout.py.in b/src/bin/xfrout/xfrout.py.in
index af1506ec69..d0580553ab 100644
--- a/src/bin/xfrout/xfrout.py.in
+++ b/src/bin/xfrout/xfrout.py.in
@@ -28,6 +28,7 @@ import os
from isc.config.ccsession import *
from isc.cc import SessionError
import socket
+import errno
from optparse import OptionParser, OptionValueError
try:
from bind10_xfr import *
@@ -57,7 +58,13 @@ class XfroutSession(BaseRequestHandler):
def handle(self):
fd = recv_fd(self.request.fileno())
if fd < 0:
- raise XfroutException("failed to receive the FD for XFR connection")
+ # This may happen when one xfrout process try to connect to
+ # xfrout unix socket server, to check whether there is another
+ # xfrout running.
+ print("[b10-xfrout] Failed to receive the FD for XFR connection, "
+ "maybe because another xfrout process was started.")
+ return
+
data_len = self.request.recv(2)
msg_len = struct.unpack('!H', data_len)[0]
msgdata = self.request.recv(msg_len)
@@ -277,18 +284,44 @@ class UnixSockServer(ThreadingUnixStreamServer):
'''The unix domain socket server which accept xfr query sent from auth server.'''
def __init__(self, sock_file, handle_class, shutdown_event, config_data):
- try:
- os.unlink(sock_file)
- except:
- pass
-
+ self._remove_unused_sock_file(sock_file)
self._sock_file = sock_file
ThreadingUnixStreamServer.__init__(self, sock_file, handle_class)
self._lock = threading.Lock()
self._transfers_counter = 0
self._shutdown_event = shutdown_event
self.update_config_data(config_data)
-
+
+ def _remove_unused_sock_file(self, sock_file):
+ '''Try to remove the socket file. If the file is being used
+ by one running xfrout process, exit from python.
+ If it's not a socket file or nobody is listening
+ , it will be removed. If it can't be removed, exit from python. '''
+ if self._sock_file_in_use(sock_file):
+ print("[b10-xfrout] Fail to start xfrout process, unix socket"
+ " file '%s' is being used by another xfrout process" % sock_file)
+ sys.exit(0)
+ else:
+ if not os.path.exists(sock_file):
+ return
+
+ try:
+ os.unlink(sock_file)
+ except OSError as err:
+ print('[b10-xfrout] Fail to remove file ' + sock_file, err)
+ sys.exit(0)
+
+ def _sock_file_in_use(self, sock_file):
+ '''Check whether the socket file 'sock_file' exists and
+ is being used by one running xfrout process. If it is,
+ return True, or else return False. '''
+ try:
+ sock = socket.socket(socket.AF_UNIX)
+ sock.connect(sock_file)
+ except socket.error as err:
+ return False
+ else:
+ return True
def shutdown(self):
ThreadingUnixStreamServer.shutdown(self)