Browse Source

fix for msgq; ctrl-c-ing bind10 would sometimes leave the socket connection hanging. Fixed to catch SIGTERM and KeyboardInterrupts to cleanly shut down the msgq (is there a way to do this without a global variable?)

git-svn-id: svn://bind10.isc.org/svn/bind10/branches/parkinglot@436 e5f2f494-b856-4b98-b285-d166d9295462
Jelte Jansen 15 years ago
parent
commit
f37a4968f4
1 changed files with 15 additions and 1 deletions
  1. 15 1
      src/bin/msgq/msgq.py

+ 15 - 1
src/bin/msgq/msgq.py

@@ -301,6 +301,15 @@ class MsgQ:
             sys.stdout.write("Stopping the server.\n")
             sys.stdout.write("Stopping the server.\n")
         self.listen_socket.close()
         self.listen_socket.close()
 
 
+# can signal handling and calling a destructor be done without a
+# global variable?
+msgq = None
+
+def signal_handler(signal, frame):
+    if msgq:
+        msgq.shutdown()
+    sys.exit(0)
+
 if __name__ == "__main__":
 if __name__ == "__main__":
     def check_port(option, opt_str, value, parser):
     def check_port(option, opt_str, value, parser):
         """Function to insure that the port we are passed is actually 
         """Function to insure that the port we are passed is actually 
@@ -319,6 +328,8 @@ if __name__ == "__main__":
                       help="port the msgq daemon will use")
                       help="port the msgq daemon will use")
     (options, args) = parser.parse_args()
     (options, args) = parser.parse_args()
 
 
+    signal.signal(signal.SIGTERM, signal_handler)
+
     # Announce startup.
     # Announce startup.
     if options.verbose:
     if options.verbose:
         sys.stdout.write("MsgQ %s\n" % __version__)
         sys.stdout.write("MsgQ %s\n" % __version__)
@@ -330,6 +341,9 @@ if __name__ == "__main__":
         sys.stderr.write("Error on startup: %s\n" % setup_result)
         sys.stderr.write("Error on startup: %s\n" % setup_result)
         sys.exit(1)
         sys.exit(1)
 
 
-    msgq.run()
+    try:
+        msgq.run()
+    except KeyboardInterrupt:
+        pass
 
 
     msgq.shutdown()
     msgq.shutdown()