diff options
author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2013-03-20 22:58:30 +0000 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2013-03-20 23:09:21 +0000 |
commit | 98471be6e58451016200cfd10e64e8ae6266c801 (patch) | |
tree | 9e6ffb4b097f596323696050d2d73b8b110fe270 | |
parent | 67f1083a10f7435aeb861ba2e872d6498375d927 (diff) | |
download | openembedded-core-98471be6e58451016200cfd10e64e8ae6266c801.tar.gz openembedded-core-98471be6e58451016200cfd10e64e8ae6266c801.tar.bz2 openembedded-core-98471be6e58451016200cfd10e64e8ae6266c801.zip |
scripts/runqemu-internal: Fix lock races
There are two problems here. Firstly the grep command is unanchored so
pid 345 will match against 12345 and so on.
The second issue is that there are several context switched between attempting
the lock and then writing the pid to it.
Between the two issues, there were issues appearing on the autobuilder due
to these conflicts. This patch replaces the mechanism with flock on fd 8
which should be a safer mechanism to use.
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rwxr-xr-x | scripts/runqemu-internal | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/scripts/runqemu-internal b/scripts/runqemu-internal index e53e40c783..f06870e972 100755 --- a/scripts/runqemu-internal +++ b/scripts/runqemu-internal @@ -112,18 +112,12 @@ acquire_lock() { return 1 fi - if [ -e "$lockfile.lock" ]; then - # Check that the lockfile is not stale - ps=`ps -eo pid | grep $(cat $lockfile.lock)` - if [ -z "$ps" ]; then - echo "WARNING: Stale lock file detected, deleting $lockfile.lock." - rm -f $lockfile.lock - echo $$ > $lockfile.lock - else - return 1 - fi - else - echo $$ > $lockfile.lock + touch $lockfile.lock + exec 8>$lockfile.lock + flock -n -x 8 + if [ $? -ne 0 ]; then + exec 8>&- + return 1 fi return 0 @@ -137,6 +131,7 @@ release_lock() { fi rm -f $lockfile.lock + exec 8>&- } LOCKDIR="/tmp/qemu-tap-locks" |