[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] Rewritten handling of child stderr to avoid deadlock.
# HG changeset patch # User emellor@xxxxxxxxxxxxxxxxxxxxxx # Node ID 7f8db234e9dbfaa1c1c812c02f9cddcc70184980 # Parent 99f4ba74763e00769d5383f0d349e900e52c1977 Rewritten handling of child stderr to avoid deadlock. Signed-off-by: Ewan Mellor <ewan@xxxxxxxxxxxxx> diff -r 99f4ba74763e -r 7f8db234e9db tools/python/xen/xend/XendCheckpoint.py --- a/tools/python/xen/xend/XendCheckpoint.py Tue Nov 1 15:02:43 2005 +++ b/tools/python/xen/xend/XendCheckpoint.py Wed Nov 2 15:42:29 2005 @@ -7,9 +7,9 @@ import os import re -import select import string import sxp +import threading from struct import pack, unpack, calcsize from xen.util.xpopen import xPopen3 @@ -81,6 +81,7 @@ log.info("Domain %d suspended.", dominfo.getDomid()) tochild.write("done\n") tochild.flush() + log.debug('Written done') forkHelper(cmd, fd, saveInputHandler, False) @@ -176,43 +177,42 @@ if closeToChild: child.tochild.close() - lasterr = "error unknown" + thread = threading.Thread(target = slurp, args = (child.childerr)) + thread.start() + try: - fds = [child.fromchild.fileno(), - child.childerr.fileno()] - p = select.poll() - map(p.register, fds) - while len(fds) > 0: - r = p.poll() - for (fd, event) in r: - if event & select.POLLIN: - if fd == child.childerr.fileno(): - lasterr = child.childerr.readline().rstrip() - log.error('%s', lasterr) - else: - l = child.fromchild.readline().rstrip() - while l: - log.debug('%s', l) - inputHandler(l, child.tochild) - try: - l = child.fromchild.readline().rstrip() - except: - l = None - - if event & select.POLLERR: - raise XendError('Error reading from child process for %s', - cmd) - - if event & select.POLLHUP: - fds.remove(fd) - p.unregister(fd) + try: + while 1: + line = child.fromchild.readline() + if line == "": + break + else: + line = line.rstrip() + log.debug('%s', line) + inputHandler(line, child.tochild) + + thread.join() + + except IOError, exn: + raise XendError('Error reading from child process for %s: %s' % + (cmd, exn)) finally: child.fromchild.close() child.childerr.close() if not closeToChild: child.tochild.close() - if child.wait() >> 8 == 127: - lasterr = "popen failed" - if child.wait() != 0: - raise XendError("%s failed: %s" % (string.join(cmd), lasterr)) + status = child.wait() + if status >> 8 == 127: + raise XendError("%s failed: popen failed" % string.join(cmd)) + elif status != 0: + raise XendError("%s failed" % string.join(cmd)) + + +def slurp(file): + while 1: + line = file.readline() + if line == "": + break + else: + log.error('%s', line) _______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-changelog
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |