Openembedded Core Discussions
 help / color / mirror / Atom feed
* [PATCH 0/1] qemurunner.py: fix race condition at qemu startup
@ 2019-07-12  7:31 Chen Qi
  2019-07-12  7:31 ` [PATCH 1/1] " Chen Qi
  0 siblings, 1 reply; 2+ messages in thread
From: Chen Qi @ 2019-07-12  7:31 UTC (permalink / raw)
  To: openembedded-core

*** BLURB HERE ***
The following changes since commit 80ab79168ede2786868cbd354f0950c949f73527:

  gnome-themes-standard: remove (2019-07-11 09:32:50 +0100)

are available in the git repository at:

  git://git.pokylinux.org/poky-contrib ChenQi/qemurunner-race
  http://git.pokylinux.org/cgit.cgi/poky-contrib/log/?h=ChenQi/qemurunner-race

Chen Qi (1):
  qemurunner.py: fix race condition at qemu startup

 meta/lib/oeqa/utils/qemurunner.py | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

-- 
1.9.1



^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH 1/1] qemurunner.py: fix race condition at qemu startup
  2019-07-12  7:31 [PATCH 0/1] qemurunner.py: fix race condition at qemu startup Chen Qi
@ 2019-07-12  7:31 ` Chen Qi
  0 siblings, 0 replies; 2+ messages in thread
From: Chen Qi @ 2019-07-12  7:31 UTC (permalink / raw)
  To: openembedded-core

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@windriver.com>
---
 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):
-- 
1.9.1



^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-07-12  7:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-07-12  7:31 [PATCH 0/1] qemurunner.py: fix race condition at qemu startup Chen Qi
2019-07-12  7:31 ` [PATCH 1/1] " Chen Qi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox