From: Lucas Dutra Nunes <ldnunes@ossystems.com.br>
To: openembedded-core@lists.openembedded.org
Subject: [PATCH 2/2] cleanup-workdir: wait for bitbake instances to finish
Date: Mon, 18 May 2015 17:08:18 -0300 [thread overview]
Message-ID: <1431979698-29379-2-git-send-email-ldnunes@ossystems.com.br> (raw)
In-Reply-To: <1431979698-29379-1-git-send-email-ldnunes@ossystems.com.br>
bitbake uses a lock file on the build dir, "bitbake.lock", to prevent it
from running before an instance has exited. And sometimes the
cleanup-workdir script can call bibake too many times, too fast, before
the lock has been released.
By simply waiting that the lock has been released solves this problem.
Signed-off-by: Lucas Dutra Nunes <ldnunes@ossystems.com.br>
---
scripts/cleanup-workdir | 31 +++++++++++++++++++++++++++----
1 file changed, 27 insertions(+), 4 deletions(-)
diff --git a/scripts/cleanup-workdir b/scripts/cleanup-workdir
index bf37f90..3e1df1f 100755
--- a/scripts/cleanup-workdir
+++ b/scripts/cleanup-workdir
@@ -21,6 +21,8 @@ import optparse
import re
import subprocess
import shutil
+import fcntl
+from contextlib import contextmanager
pkg_cur_dirs = {}
obsolete_dirs = []
@@ -51,7 +53,7 @@ def get_cur_arch_dirs(workdir, arch_dirs):
pattern = workdir + '/(.*?)/'
cmd = "bitbake -e | grep ^SDK_ARCH="
- output = run_command(cmd)
+ output = run_bitbake_command(cmd)
sdk_arch = output.split('"')[1]
# select thest 5 packages to get the dirs of current arch
@@ -59,7 +61,7 @@ def get_cur_arch_dirs(workdir, arch_dirs):
for pkg in pkgs:
cmd = "bitbake -e " + pkg + " | grep ^IMAGE_ROOTFS="
- output = run_command(cmd)
+ output = run_bitbake_command(cmd)
output = output.split('"')[1]
m = re.match(pattern, output)
arch_dirs.append(m.group(1))
@@ -67,6 +69,27 @@ def get_cur_arch_dirs(workdir, arch_dirs):
def get_build_dir():
return run_command('echo $BUILDDIR').strip()
+@contextmanager
+def wait_for_bitbake():
+ builddir = get_build_dir()
+ bitbake_lock_file = os.path.join(builddir, 'bitbake.lock')
+
+ with open(bitbake_lock_file, 'w+') as f:
+ fd = f.fileno()
+ try:
+ # Lock and unlock the lock file, to be sure that there are no other
+ # instances of bitbake running at the moment:
+ fcntl.flock(fd, fcntl.LOCK_EX)
+ fcntl.flock(fd, fcntl.LOCK_UN)
+ yield
+ finally:
+ # And unlock again, just to be safe:
+ fcntl.flock(fd, fcntl.LOCK_UN)
+
+def run_bitbake_command(cmd):
+ with wait_for_bitbake():
+ return run_command(cmd)
+
def main():
global parser
parser = optparse.OptionParser(
@@ -89,7 +112,7 @@ will be deleted. Be CAUTIOUS.""")
print 'Updating bitbake caches...'
cmd = "bitbake -s"
- output = run_command(cmd)
+ output = run_bitbake_command(cmd)
output = output.split('\n')
index = 0
@@ -111,7 +134,7 @@ will be deleted. Be CAUTIOUS.""")
pkg_cur_dirs[elems[0]] = version
cmd = "bitbake -e"
- output = run_command(cmd)
+ output = run_bitbake_command(cmd)
tmpdir = None
image_rootfs = None
--
2.1.4
next prev parent reply other threads:[~2015-05-18 20:08 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-18 20:08 [PATCH 1/2] cleanup-workdir: add a method for getting the build dir Lucas Dutra Nunes
2015-05-18 20:08 ` Lucas Dutra Nunes [this message]
2015-05-18 22:23 ` [PATCH 2/2] cleanup-workdir: wait for bitbake instances to finish Christopher Larson
2015-05-18 22:26 ` Otavio Salvador
2015-05-19 4:53 ` Anders Darander
2015-05-19 14:21 ` Burton, Ross
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1431979698-29379-2-git-send-email-ldnunes@ossystems.com.br \
--to=ldnunes@ossystems.com.br \
--cc=openembedded-core@lists.openembedded.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.