1
0
mirror of https://git.yoctoproject.org/poky synced 2026-06-01 13:09:50 +00:00

qemurunner.py: fix race condition at qemu startup

When handling pid file, qemu would first create the file, stat it,
lock it and then write actually contents to it.

So it's possbile that when reading the pid file, the content is empty.

[YOCTO #13390]

(From OE-Core rev: 170e59b203a02f8438b9aeab3a45f6fcd6608b1f)

Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Chen Qi
2019-07-12 15:31:13 +08:00
committed by Richard Purdie
parent 41bac92fdb
commit 7a6b2ce603
+14 -7
View File
@@ -425,13 +425,20 @@ class QemuRunner:
if not self.runqemu or self.runqemu.poll() is not None: if not self.runqemu or self.runqemu.poll() is not None:
return False return False
if os.path.isfile(self.qemu_pidfile): if os.path.isfile(self.qemu_pidfile):
f = open(self.qemu_pidfile, 'r') # when handling pidfile, qemu creates the file, stat it, lock it and then write to it
qemu_pid = f.read() # so it's possible that the file has been created but the content is empty
f.close() pidfile_timeout = time.time() + 3
qemupid = int(qemu_pid) while time.time() < pidfile_timeout:
if os.path.exists("/proc/" + str(qemupid)): with open(self.qemu_pidfile, 'r') as f:
self.qemupid = qemupid qemu_pid = f.read().strip()
return True # file created but not yet written contents
if not qemu_pid:
time.sleep(0.5)
continue
else:
if os.path.exists("/proc/" + qemu_pid):
self.qemupid = int(qemu_pid)
return True
return False return False
def run_serial(self, command, raw=False, timeout=60): def run_serial(self, command, raw=False, timeout=60):