]> code.ossystems Code Review - openembedded-core.git/commitdiff
qemurunner: Don't loop on EWOULDBLOCK in logging thread.
authorRandy Witt <randy.e.witt@linux.intel.com>
Thu, 27 Aug 2015 09:04:10 +0000 (02:04 -0700)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Sat, 29 Aug 2015 12:17:50 +0000 (13:17 +0100)
EAGAIN/EWOULDBLOCK can be followed by no data. So don't tight loop
waiting for data.

Signed-off-by: Randy Witt <randy.e.witt@linux.intel.com>
Signed-off-by: Ross Burton <ross.burton@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/lib/oeqa/utils/qemurunner.py

index 6d36df69535d2797bf65e1611b708b917cd476dd..bcdb69b38ca5c0cf764b85e3dbefe773dafed8fd 100644 (file)
@@ -139,6 +139,7 @@ class QemuRunner:
                 logger.info("Couldn't get ip from qemu process arguments! Here is the qemu command line used:\n%s\nand output from runqemu:\n%s" % (cmdline, getOutput(output)))
                 self.stop()
                 return False
+            logger.info("qemu cmdline used:\n{}".format(cmdline))
             logger.info("Target IP: %s" % self.ip)
             logger.info("Server IP: %s" % self.server_ip)
 
@@ -368,6 +369,7 @@ class LoggingThread(threading.Thread):
             os.write(self.writepipe, "stop")
 
     def teardown(self):
+        self.logger.info("Tearing down logging thread")
         self.close_socket(self.serversock)
 
         if self.readsock is not None:
@@ -412,25 +414,23 @@ class LoggingThread(threading.Thread):
 
                 # Actual data to be logged
                 elif self.readsock.fileno() == event[0]:
-                    data = self.recv_loop()
+                    data = self.recv(1024)
                     self.logfunc(data)
 
     # Since the socket is non-blocking make sure to honor EAGAIN
-    # and EWOULDBLOCK
-    def recv_loop(self):
-        while True:
-            try:
-                data = self.readsock.recv(1024)
-                break
-            except socket.error as e:
-                if e.errno == errno.EAGAIN or e.errno == errno.EWOULDBLOCK:
-                    continue
-                else:
-                    raise
+    # and EWOULDBLOCK.
+    def recv(self, count):
+        try:
+            data = self.readsock.recv(count)
+        except socket.error as e:
+            if e.errno == errno.EAGAIN or e.errno == errno.EWOULDBLOCK:
+                return ''
+            else:
+                raise
 
-        if not data:
+        if data is None:
             raise Exception("No data on read ready socket")
-        elif data == 0:
+        elif not data:
             # This actually means an orderly shutdown
             # happened. But for this code it counts as an
             # error since the connection shouldn't go away