[CRIU] [PATCH] zdtm: fix a race condition during concurrent execution of tests
Andrey Vagin
avagin at openvz.org
Thu Aug 29 15:50:15 EDT 2013
When tests are executed concurrently all of them use
the same root, so libraries must be copied atomically.
Without this patch we can get errors like this:
cp: cannot create regular file ‘/tmp/criu-root.m45u5Y/lib64/ld-linux-x86-64.so.2’: File exists
Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
test/zdtm.sh | 36 +++++++++++++++++++++++++++++-------
1 file changed, 29 insertions(+), 7 deletions(-)
diff --git a/test/zdtm.sh b/test/zdtm.sh
index 04a42e4..b3d4254 100755
--- a/test/zdtm.sh
+++ b/test/zdtm.sh
@@ -223,6 +223,7 @@ construct_root()
local libdir=$root/lib
local libdir2=$root/lib64
local tmpdir=$root/tmp
+ local lname, tname
mkdir -p $root/bin
cp $ps_path $root/bin
@@ -242,13 +243,34 @@ construct_root()
# /lib/ld-linux-armhf.so.3 (0xb6f0b000)
for i in `ldd $test_path $ps_path | grep -P '^\s' | grep -v vdso | sed "s/.*=> //" | awk '{ print $1 }'`; do
- local lib=`basename $i`
- [ -f $libdir/$lib ] && continue ||
- [ -f $i ] && cp $i $libdir && cp $i $libdir2 && continue ||
- [ -f /lib64/$i ] && cp /lib64/$i $libdir && cp /lib64/$i $libdir2 && continue ||
- [ -f /usr/lib64/$i ] && cp /usr/lib64/$i $libdir && cp /usr/lib64/$i $libdir2 && continue ||
- [ -f /lib/x86_64-linux-gnu/$i ] && cp /lib/x86_64-linux-gnu/$i $libdir && cp /lib/x86_64-linux-gnu/$i $libdir2 && continue ||
- [ -f /lib/arm-linux-gnueabi/$i ] && cp /lib/arm-linux-gnueabi/$i $libdir && cp /lib/arm-linux-gnueabi/$i $libdir2 && continue || echo "Failed at " $i && return 1
+ local ldir, lib=`basename $i`
+
+ [ -f $libdir2/$lib ] && continue # fast path
+
+ if [ -f $i ]; then
+ lname=$i
+ elif [ -f /lib64/$i ]; then
+ lname=/lib64/$i
+ elif [ -f /usr/lib64/$i ]; then
+ lname=/usr/lib64/$i
+ elif [ -f /lib/x86_64-linux-gnu/$i ]; then
+ lname=/lib/x86_64-linux-gnu/$i
+ elif [ -f /lib/arm-linux-gnueabi/$i ]; then
+ lname=/lib/arm-linux-gnueabi/$i
+ else
+ echo "Failed at " $i;
+ return 1
+ fi
+
+ # When tests are executed concurrently all of them use the same root,
+ # so libraries must be copied atomically.
+
+ for ldir in "$libdir" "$libdir2"; do
+ tname=$(mktemp $ldir/lib.XXXXXX)
+ cp -pf $lname $tname &&
+ mv -n $tname $ldir/$lib || return 1
+ [ -f $tname ] && unlink $tname
+ done
done
# make 'tmp' dir under new root
--
1.8.3.1
More information about the CRIU
mailing list