On Tue, Jul 21, 2020, 4:56 PM Richard Purdie <
[email protected]> wrote:

> We continue to see qemu races where qemu fails to write out a pidfile. The
> pidfile name being used was based on the parent process starting the qemus
> so in theory, a qemu shutting down could have deleted the file into which
> the new qemu's pid was about to be written. This shouldn't happen as qemu
> processes should be exitting completely before the code returns.
>
> In the absence of better theory for the failure, use a random pid filename
> rather than the parent pid so there is no overlap in the pid filename,
> thereby removing any theoretical race.
>
> Signed-off-by: Richard Purdie <[email protected]>
> ---
>  meta/lib/oeqa/utils/qemurunner.py | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/meta/lib/oeqa/utils/qemurunner.py
> b/meta/lib/oeqa/utils/qemurunner.py
> index 519aa9aa1e5..73a3efdc964 100644
> --- a/meta/lib/oeqa/utils/qemurunner.py
> +++ b/meta/lib/oeqa/utils/qemurunner.py
> @@ -20,6 +20,7 @@ import string
>  import threading
>  import codecs
>  import logging
> +import tempfile
>  from oeqa.utils.dump import HostDumper
>  from collections import defaultdict
>
> @@ -65,7 +66,11 @@ class QemuRunner:
>          self.runqemutime = 120
>          if not workdir:
>              workdir = os.getcwd()
> -        self.qemu_pidfile = workdir + '/pidfile_' + str(os.getpid())
> +        # Use tempfile to obtain a unique name. We own the directory
> +        # so closing the file isn't an issue as long as we don't delete it
> +        self.qemu_pidfile = tempfile.mkstemp(dir=workdir,
> prefix="qemupid_")
> +        os.close(self.qemu_pidfile[0])
> +        self.qemu_pidfile = self.qemu_pidfile[1]
>

Minor, but more idiomatic python:

 (fd, self.qemu_pidfile) = tempfile.mkstemp(...)
 os.close(fd)


         self.host_dumper = HostDumper(dump_host_cmds, dump_dir)
>          self.monitorpipe = None
>
> @@ -182,8 +187,6 @@ class QemuRunner:
>
>          # Ask QEMU to store the QEMU process PID in file, this way we
> don't have to parse running processes
>          # and analyze descendents in order to determine it.
> -        if os.path.exists(self.qemu_pidfile):
> -            os.remove(self.qemu_pidfile)
>          self.qemuparams = 'bootparams="{0}" qemuparams="-pidfile
> {1}"'.format(bootparams, self.qemu_pidfile)
>          if qemuparams:
>              self.qemuparams = self.qemuparams[:-1] + " " + qemuparams + "
> " + '\"'
> --
> 2.25.1
>
> 
>
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.

View/Reply Online (#140848): 
https://lists.openembedded.org/g/openembedded-core/message/140848
Mute This Topic: https://lists.openembedded.org/mt/75713689/21656
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub  
[[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to