Merge pull request #696 from antmicro/lock-mergedb

utils: mergedb: lock database accesses
This commit is contained in:
litghost 2019-03-05 16:41:06 -08:00 committed by GitHub
commit 05055fe028
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 2 deletions

View File

@ -11,7 +11,10 @@ FUZZONLY=N
BITONLY=N
all:
clean: clean_fuzzers clean_logs
clean: clean_fuzzers clean_logs clean_locks
clean_locks:
rm -rf /tmp/segbits_*.db.lock
define fuzzer

View File

@ -9,6 +9,9 @@ test -e "$2"
tmp1=`mktemp -p .`
tmp2=`mktemp -p .`
LOCKFILE="/tmp/segbits_$1.db.lock"
LOCKTIMEOUT=30 # 30s timeout
LOCKID=222
function finish {
echo "Cleaning up temp files"
@ -18,10 +21,24 @@ function finish {
trap finish EXIT
db=$XRAY_DATABASE_DIR/$XRAY_DATABASE/segbits_$1.db
# if the DB exists acquire a lock
if [ -f $db ]; then
eval "exec $LOCKID>$LOCKFILE"
# the lock is automatically released on script exit
flock --timeout $LOCKTIMEOUT $LOCKID
if [ ! $? -eq 0 ]; then
echo "Timeout while waiting for lock"
finish
exit 1
fi
fi
# Check existing DB
if [ -f $db ] ; then
${XRAY_PARSEDB} --strict "$db"
fi
# Check new DB
${XRAY_PARSEDB} --strict "$2"
@ -112,4 +129,3 @@ else
fi
# Check aggregate db for consistency and make canonical
${XRAY_PARSEDB} --strict "$tmp2" "$db"