qemurunner: Simplify binary data handling

I have concerns that bad timing of the flow of data from the logger
might corrupt the output due to the way binary strings are handled
in qemurunner.

This simplifies the code to do the same thing it did before but much
more safely.

(From OE-Core rev: 20bc247316ab915465a4b1add6d09b48e07202ac)

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
(cherry picked from commit 1e87283e92a2765bb5d54d17138b208bc395953b)
Signed-off-by: Armin Kuster <akuster808@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Richard Purdie
2017-11-21 11:42:54 +00:00
parent 1e4d4762b1
commit 80ed9207a7

View File

@@ -275,7 +275,7 @@ class QemuRunner:
reachedlogin = False reachedlogin = False
stopread = False stopread = False
qemusock = None qemusock = None
bootlog = '' bootlog = b''
data = b'' data = b''
while time.time() < endtime and not stopread: while time.time() < endtime and not stopread:
try: try:
@@ -292,17 +292,13 @@ class QemuRunner:
else: else:
data = data + sock.recv(1024) data = data + sock.recv(1024)
if data: if data:
try:
data = data.decode("utf-8", errors="surrogateescape")
bootlog += data bootlog += data
data = b'' data = b''
if re.search(".* login:", bootlog): if b' login:' in bootlog:
self.server_socket = qemusock self.server_socket = qemusock
stopread = True stopread = True
reachedlogin = True reachedlogin = True
self.logger.debug("Reached login banner") self.logger.debug("Reached login banner")
except UnicodeDecodeError:
continue
else: else:
socklist.remove(sock) socklist.remove(sock)
sock.close() sock.close()