[oe-commits] [openembedded-core] 09/15: qemurunner.py: fix race condition at qemu startup

git at git.openembedded.org git at git.openembedded.org
Mon Jul 15 08:32:24 UTC 2019


This is an automated email from the git hooks/post-receive script.

rpurdie pushed a commit to branch master
in repository openembedded-core.

commit 170e59b203a02f8438b9aeab3a45f6fcd6608b1f
Author: Chen Qi <Qi.Chen at windriver.com>
AuthorDate: Fri Jul 12 15:31:13 2019 +0800

    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]
    
    Signed-off-by: Chen Qi <Qi.Chen at windriver.com>
    Signed-off-by: Richard Purdie <richard.purdie at linuxfoundation.org>
---
 meta/lib/oeqa/utils/qemurunner.py | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/meta/lib/oeqa/utils/qemurunner.py b/meta/lib/oeqa/utils/qemurunner.py
index c16227f..68684ae 100644
--- a/meta/lib/oeqa/utils/qemurunner.py
+++ b/meta/lib/oeqa/utils/qemurunner.py
@@ -425,13 +425,20 @@ class QemuRunner:
         if not self.runqemu or self.runqemu.poll() is not None:
             return False
         if os.path.isfile(self.qemu_pidfile):
-            f = open(self.qemu_pidfile, 'r')
-            qemu_pid = f.read()
-            f.close()
-            qemupid = int(qemu_pid)
-            if os.path.exists("/proc/" + str(qemupid)):
-                self.qemupid = qemupid
-                return True
+            # when handling pidfile, qemu creates the file, stat it, lock it and then write to it
+            # so it's possible that the file has been created but the content is empty
+            pidfile_timeout = time.time() + 3
+            while time.time() < pidfile_timeout:
+                with open(self.qemu_pidfile, 'r') as f:
+                    qemu_pid = f.read().strip()
+                # 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
 
     def run_serial(self, command, raw=False, timeout=60):

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Openembedded-commits mailing list