summaryrefslogtreecommitdiffstats
path: root/scripts/runqemu-internal
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2013-03-20 22:58:30 (GMT)
committerRichard Purdie <richard.purdie@linuxfoundation.org>2013-03-20 23:09:45 (GMT)
commit9ffee9add2d0380f4025e7a678a166f25a7d659e (patch)
tree17931328b7439149c520bc03b2a41d915001aec8 /scripts/runqemu-internal
parentecb30a910b8c2f3d39ab4d3bf5f3eb1898097b76 (diff)
downloadpoky-9ffee9add2d0380f4025e7a678a166f25a7d659e.tar.gz
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: 98471be6e58451016200cfd10e64e8ae6266c801) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/runqemu-internal')
-rwxr-xr-xscripts/runqemu-internal19
1 files changed, 7 insertions, 12 deletions
diff --git a/scripts/runqemu-internal b/scripts/runqemu-internal
index e53e40c..f06870e 100755
--- a/scripts/runqemu-internal
+++ b/scripts/runqemu-internal
@@ -112,18 +112,12 @@ acquire_lock() {
112 return 1 112 return 1
113 fi 113 fi
114 114
115 if [ -e "$lockfile.lock" ]; then 115 touch $lockfile.lock
116 # Check that the lockfile is not stale 116 exec 8>$lockfile.lock
117 ps=`ps -eo pid | grep $(cat $lockfile.lock)` 117 flock -n -x 8
118 if [ -z "$ps" ]; then 118 if [ $? -ne 0 ]; then
119 echo "WARNING: Stale lock file detected, deleting $lockfile.lock." 119 exec 8>&-
120 rm -f $lockfile.lock 120 return 1
121 echo $$ > $lockfile.lock
122 else
123 return 1
124 fi
125 else
126 echo $$ > $lockfile.lock
127 fi 121 fi
128 122
129 return 0 123 return 0
@@ -137,6 +131,7 @@ release_lock() {
137 fi 131 fi
138 132
139 rm -f $lockfile.lock 133 rm -f $lockfile.lock
134 exec 8>&-
140} 135}
141 136
142LOCKDIR="/tmp/qemu-tap-locks" 137LOCKDIR="/tmp/qemu-tap-locks"