1
0
mirror of https://git.yoctoproject.org/poky synced 2026-05-31 12:49:46 +00:00

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.

(From OE-Core rev: f1a126f2b0f419b2de573e2367d41d8ccc28b346)

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Richard Purdie
2013-03-20 22:58:30 +00:00
parent 7911ec5de9
commit fd428a09ee
+7 -12
View File
@@ -112,18 +112,12 @@ acquire_lock() {
return 1 return 1
fi fi
if [ -e "$lockfile.lock" ]; then touch $lockfile.lock
# Check that the lockfile is not stale exec 8>$lockfile.lock
ps=`ps -eo pid | grep $(cat $lockfile.lock)` flock -n -x 8
if [ -z "$ps" ]; then if [ $? -ne 0 ]; then
echo "WARNING: Stale lock file detected, deleting $lockfile.lock." exec 8>&-
rm -f $lockfile.lock return 1
echo $$ > $lockfile.lock
else
return 1
fi
else
echo $$ > $lockfile.lock
fi fi
return 0 return 0
@@ -137,6 +131,7 @@ release_lock() {
fi fi
rm -f $lockfile.lock rm -f $lockfile.lock
exec 8>&-
} }
LOCKDIR="/tmp/qemu-tap-locks" LOCKDIR="/tmp/qemu-tap-locks"