xend blocks SIGCHLD and SIGINT
Hi folks
xend currently block SIGINT and SIGCHLD.
The first makes it impossible to kill xend in debugging mode gracefully. The second produces zombies if the childs (for example qemu-dm) dies.
Bastian
Signature · 2 lines
The joys of love made her human and the agonies of love destroyed her. -- Spock, "Requiem for Methuselah", stardate 5842.8
Quoted 9 lines · Bastian Blank
Hi folks
xend currently block SIGINT and SIGCHLD.
The first makes it impossible to kill xend in debugging mode gracefully. The second produces zombies if the childs (for example qemu-dm) dies.
Bastian
I've been working on patches to make Xend shutdown cleanly, mainly because of a Python threading oddity with Thread.join(). If you would like, you can give this patch a whirl.
I'm not sure whether it helps with the second issue with SIGCHLD though. But it would be useful to know.
Cheers,
Alastair
tools/python/xen/util/xmlrpclib2.py +5 -5
@@ -25,7 +25,6 @@ import fcntl import fcntl from httplib import HTTPConnection, HTTP -from xmlrpclib import Transport from SimpleXMLRPCServer import SimpleXMLRPCServer, SimpleXMLRPCRequestHandler import SocketServer import xmlrpclib, socket, os, stat
@@ -81,10 +80,11 @@ class HTTPUnix(HTTP): class HTTPUnix(HTTP): _connection_class = HTTPUnixConnection -class UnixTransport(Transport): +class UnixTransport(xmlrpclib.Transport): def request(self, host, handler, request_body, verbose=0): self.__handler = handler - return Transport.request(self, host, '/RPC2', request_body, verbose) + return xmlrpclib.Transport.request(self, host, '/RPC2', + request_body, verbose) def make_connection(self, host): return HTTPUnix(self.__handler)
@@ -134,7 +134,7 @@ class TCPXMLRPCServer(SocketServer.Threa allow_reuse_address = True def __init__(self, addr, requestHandler=XMLRPCRequestHandler, - logRequests=1): + logRequests = 1): SimpleXMLRPCServer.__init__(self, addr, requestHandler, logRequests) flags = fcntl.fcntl(self.fileno(), fcntl.F_GETFD)
@@ -201,7 +201,7 @@ class UnixXMLRPCServer(TCPXMLRPCServer): class UnixXMLRPCServer(TCPXMLRPCServer): address_family = socket.AF_UNIX - def __init__(self, addr, logRequests): + def __init__(self, addr, logRequests = 1): parent = os.path.dirname(addr) if os.path.exists(parent): os.chown(parent, os.geteuid(), os.getegid())
tools/python/xen/xend/server/SrvDaemon.py +4 -0
@@ -195,6 +195,8 @@ class Daemon: sig) else: self.run(w and os.fdopen(w, 'w') or None) + # if we reach here, the child should quit. + os._exit(0) return ret
@@ -290,6 +292,8 @@ class Daemon: relocate.listenRelocation() servers = SrvServer.create() servers.start(status) + del servers + except Exception, ex: print >>sys.stderr, 'Exception starting xend:', ex if XEND_DEBUG:
tools/python/xen/xend/server/SrvServer.py +27 -3
@@ -42,6 +42,7 @@ import fcntl import time +import signal from threading import Thread from xen.web.httpserver import HttpServer, UnixHttpServer
@@ -54,7 +55,6 @@ from SrvRoot import SrvRoot from SrvRoot import SrvRoot from XMLRPCServer import XMLRPCServer - xroot = XendRoot.instance()
@@ -65,6 +65,14 @@ class XendServers: def add(self, server): self.servers.append(server) + + def cleanup(self, signum = 0, frame = None): + log.debug("SrvServer.cleanup()") + for server in self.servers: + try: + server.shutdown() + except: + pass def start(self, status): # Running the network script will spawn another process, which takes
@@ -100,8 +108,24 @@ class XendServers: status.write('0') status.close() - for t in threads: - t.join() + # Prepare to catch SIGTERM (received when 'xend stop' is executed) + # and call each server's cleanup if possible + signal.signal(signal.SIGTERM, self.cleanup) + + # Interruptible Thread.join - Python Bug #1167930 + # Replaces: for t in threads: t.join() + # Reason: The above will cause python signal handlers to be + # blocked so we're not able to catch SIGTERM in any + # way for cleanup + runningThreads = len([t for t in threads if t.isAlive()]) + while runningThreads > 0: + try: + for t in threads: + t.join(1.0) + runningThreads = len([t for t in threads if t.isAlive()]) + except: + pass + def create(): root = SrvDir()
tools/python/xen/xend/server/XMLRPCServer.py +39 -16
92 lines not on this page · raw message
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel