WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] Rewritten handling of child stderr to avoid deadlock.

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] Rewritten handling of child stderr to avoid deadlock.
From: Xen patchbot -unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Wed, 02 Nov 2005 16:48:07 +0000
Delivery-date: Wed, 02 Nov 2005 16:45:43 +0000
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# 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

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] Rewritten handling of child stderr to avoid deadlock., Xen patchbot -unstable <=