ia64/xen-unstable

changeset 7238:971e7c7411b3

Raise an exception if an error appears on the pipes to our children, and make
sure that the child's pipes are closed even under that exception. Move the
handling of POLLHUP to the end of the loop, so that we guarantee to read any
remaining data from the child if POLLHUP and POLLIN appear at the same time.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author emellor@ewan
date Thu Oct 06 10:13:11 2005 +0100 (2005-10-06)
parents 6f71824a45c1
children b0bc53c9d5b6
files tools/python/xen/xend/XendCheckpoint.py
line diff
     1.1 --- a/tools/python/xen/xend/XendCheckpoint.py	Wed Oct 05 18:06:42 2005 +0100
     1.2 +++ b/tools/python/xen/xend/XendCheckpoint.py	Thu Oct 06 10:13:11 2005 +0100
     1.3 @@ -116,6 +116,7 @@ def restore(xd, fd):
     1.4  
     1.5      assert dominfo.store_channel
     1.6      assert dominfo.console_channel
     1.7 +    assert dominfo.getDomainPath()
     1.8  
     1.9      try:
    1.10          l = read_exact(fd, sizeof_unsigned_long,
    1.11 @@ -138,6 +139,11 @@ def restore(xd, fd):
    1.12              if m:
    1.13                  store_mfn = int(m.group(2))
    1.14                  dominfo.setStoreRef(store_mfn)
    1.15 +                log.debug("IntroduceDomain %d %d %d %s",
    1.16 +                          dominfo.getDomid(),
    1.17 +                          store_mfn,
    1.18 +                          dominfo.store_channel.port1,
    1.19 +                          dominfo.getDomainPath())
    1.20                  IntroduceDomain(dominfo.getDomid(),
    1.21                                  store_mfn,
    1.22                                  dominfo.store_channel.port1,
    1.23 @@ -161,34 +167,40 @@ def forkHelper(cmd, fd, inputHandler, cl
    1.24      if closeToChild:
    1.25          child.tochild.close()
    1.26  
    1.27 -    fds = [child.fromchild.fileno(),
    1.28 -           child.childerr.fileno()]
    1.29 -    p = select.poll()
    1.30 -    map(p.register, fds)
    1.31 -    while len(fds) > 0:
    1.32 -        r = p.poll()
    1.33 -        for (fd, event) in r:
    1.34 -            if event & select.POLLHUP or event & select.POLLERR:
    1.35 -                fds.remove(fd)
    1.36 -                p.unregister(fd)
    1.37 -                continue
    1.38 -            if not event & select.POLLIN:
    1.39 -                continue
    1.40 -            if fd == child.childerr.fileno():
    1.41 -                lasterr = child.childerr.readline().rstrip()
    1.42 -                log.error('%s', lasterr)
    1.43 -            else:
    1.44 -                l = child.fromchild.readline().rstrip()
    1.45 -                while l:
    1.46 -                    log.debug('%s', l)
    1.47 -                    inputHandler(l, child.tochild)
    1.48 -                    try:
    1.49 +    try:
    1.50 +        fds = [child.fromchild.fileno(),
    1.51 +               child.childerr.fileno()]
    1.52 +        p = select.poll()
    1.53 +        map(p.register, fds)
    1.54 +        while len(fds) > 0:
    1.55 +            r = p.poll()
    1.56 +            for (fd, event) in r:
    1.57 +                if event & select.POLLIN:
    1.58 +                    if fd == child.childerr.fileno():
    1.59 +                        lasterr = child.childerr.readline().rstrip()
    1.60 +                        log.error('%s', lasterr)
    1.61 +                    else:
    1.62                          l = child.fromchild.readline().rstrip()
    1.63 -                    except:
    1.64 -                        l = None
    1.65 +                        while l:
    1.66 +                            log.debug('%s', l)
    1.67 +                            inputHandler(l, child.tochild)
    1.68 +                            try:
    1.69 +                                l = child.fromchild.readline().rstrip()
    1.70 +                            except:
    1.71 +                                l = None
    1.72  
    1.73 -    child.fromchild.close()
    1.74 -    child.childerr.close()
    1.75 +                if event & select.POLLERR:
    1.76 +                    raise XendError('Error reading from child process for %s',
    1.77 +                                    cmd)
    1.78 +
    1.79 +                if event & select.POLLHUP:
    1.80 +                    fds.remove(fd)
    1.81 +                    p.unregister(fd)
    1.82 +    finally:
    1.83 +        child.fromchild.close()
    1.84 +        child.childerr.close()
    1.85 +        if not closeToChild:
    1.86 +            child.tochild.close()
    1.87  
    1.88      if child.wait() >> 8 == 127:
    1.89          lasterr = "popen failed"