Browse Source

1. Send 'shutdown' command to Xfrin and Xfrout when boss receive SIGINT.(Reported in ticket 135)
2. Remove unused socket file when Xfrout process exits.(Reported in ticket 151)
3. Make sure Xfrout can exit by itself when it receives SIGINT, instead of being killed by the signal SIGTERM or SIGKILL sent from boss.(Get more details in ticket 134).
(This patch has been reviewed by Shane.)

git-svn-id: svn://bind10.isc.org/svn/bind10/trunk@1797 e5f2f494-b856-4b98-b285-d166d9295462

Likun Zhang 15 years ago
parent
commit
f9c48018e6
4 changed files with 30 additions and 13 deletions
  1. 1 1
      src/bin/auth/main.cc
  2. 1 0
      src/bin/auth/spec_config.h.in
  3. 3 1
      src/bin/bind10/bind10.py.in
  4. 25 11
      src/bin/xfrout/xfrout.py.in

+ 1 - 1
src/bin/auth/main.cc

@@ -130,7 +130,7 @@ check_axfr_query(char *msg_data, uint16_t msg_len)
 static void
 dispatch_axfr_query(int tcp_sock, char axfr_query[], uint16_t query_len)
 {
-    std::string path = "/tmp/auth_xfrout_conn";
+    std::string path = string(UNIX_SOCKET_FILE);
     XfroutClient xfr_client(path);
     try {
         xfr_client.connect();

+ 1 - 0
src/bin/auth/spec_config.h.in

@@ -13,3 +13,4 @@
 // PERFORMANCE OF THIS SOFTWARE.
 
 #define AUTH_SPECFILE_LOCATION "@prefix@/share/@PACKAGE@/auth.spec"
+#define UNIX_SOCKET_FILE "@prefix@/var/auth_xfrout_conn"

+ 3 - 1
src/bin/bind10/bind10.py.in

@@ -362,6 +362,8 @@ class BoB:
         self.cc_session.group_sendmsg(cmd, 'Boss', 'Cmd-Ctrld')
         self.cc_session.group_sendmsg(cmd, "Boss", "ConfigManager")
         self.cc_session.group_sendmsg(cmd, "Boss", "Auth")
+        self.cc_session.group_sendmsg(cmd, "Boss", "Xfrout")
+        self.cc_session.group_sendmsg(cmd, "Boss", "Xfrin")
 
     def stop_process(self, process):
         """Stop the given process, friendly-like."""
@@ -378,7 +380,7 @@ class BoB:
         except:
             pass
         # XXX: some delay probably useful... how much is uncertain
-        time.sleep(0.1)  
+        time.sleep(0.5)  
         self.reap_children()
         # next try sending a SIGTERM
         processes_to_stop = list(self.processes.values())

+ 25 - 11
src/bin/xfrout/xfrout.py.in

@@ -44,6 +44,7 @@ else:
     DATAROOTDIR = "@datarootdir@"
     SPECFILE_PATH = "@datadir@/@PACKAGE@".replace("${datarootdir}", DATAROOTDIR).replace("${prefix}", PREFIX)
 SPECFILE_LOCATION = SPECFILE_PATH + "/xfrout.spec"
+UNIX_SOCKET_FILE = "@localstatedir@".replace("${prefix}", PREFIX) + "/auth_xfrout_conn"
 
 MAX_TRANSFERS_OUT = 10
 verbose_mode = False
@@ -276,12 +277,25 @@ 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._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 shutdown(self):
+        ThreadingUnixStreamServer.shutdown(self)
+        try:
+            os.unlink(self._sock_file)
+        except:
+            pass
 
     def update_config_data(self, new_config):
         '''Apply the new config setting of xfrout module. '''
@@ -314,16 +328,18 @@ class UnixSockServer(ThreadingUnixStreamServer):
         self._transfers_counter -= 1
         self._lock.release()
 
-
 def listen_on_xfr_query(unix_socket_server):
-    '''Listen xfr query in one single thread. '''
-    unix_socket_server.serve_forever()
+
+    '''Listen xfr query in one single thread. Polls for shutdown 
+    every 0.1 seconds, is there a better time?
+    '''
+    unix_socket_server.serve_forever(poll_interval = 0.1)
    
 
 class XfroutServer:
     def __init__(self):
         self._unix_socket_server = None
-        self._listen_sock_file = '/tmp/auth_xfrout_conn' # TODO, should this be configurable in cfgmgr
+        self._listen_sock_file = UNIX_SOCKET_FILE 
         self._shutdown_event = threading.Event()
         self._cc = isc.config.ModuleCCSession(SPECFILE_LOCATION, self.config_handler, self.command_handler)
         self._config_data = self._cc.get_full_config()
@@ -333,11 +349,7 @@ class XfroutServer:
 
     def _start_xfr_query_listener(self):
         '''Start a new thread to accept xfr query. '''
-        try:
-            os.unlink(self._listen_sock_file)
-        except:
-            pass
-     
+    
         self._unix_socket_server = UnixSockServer(self._listen_sock_file, XfroutSession, 
                                                   self._shutdown_event, self._config_data);
         listener = threading.Thread(target = listen_on_xfr_query, args = (self._unix_socket_server,))
@@ -363,6 +375,9 @@ class XfroutServer:
         ''' shutdown the xfrout process. The thread which is doing zone transfer-out should be
         terminated.
         '''
+
+        global xfrout_server
+        xfrout_server = None #Avoid shutdown is called twice
         self._shutdown_event.set()
         if self._unix_socket_server:
             self._unix_socket_server.shutdown()
@@ -373,7 +388,6 @@ class XfroutServer:
                 continue
             th.join()
 
-
     def command_handler(self, cmd, args):
         if cmd == "shutdown":
             if verbose_mode:
@@ -395,7 +409,7 @@ class XfroutServer:
 xfrout_server = None
 
 def signal_handler(signal, frame):
-   if xfrout_server:
+    if xfrout_server:
         xfrout_server.shutdown()
         sys.exit(0)