diff options
-rwxr-xr-x | tct/resource_locking.sh | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/tct/resource_locking.sh b/tct/resource_locking.sh new file mode 100755 index 0000000..7e6478d --- /dev/null +++ b/tct/resource_locking.sh @@ -0,0 +1,40 @@ +#!/bin/sh + +# Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Script used to lock a file used for storing UUID. +# Prints on stdout name of the locked SDMUX. +# +# Syntax is: resource_locking.sh ${SDMUX%_*} +# +# Author: Aleksander Mistewicz <a.mistewicz@samsung.com> + +SLEEP=100 +while [ $SLEEP -ge 10 ] +do + for i in $(ls "/var/tmp/uuid-${1}"* | grep -v "lock"); + do + lockfile-create --use-pid --retry 0 $i + if [ $? -eq 0 ]; then + echo "Locked: $i" >&2 + echo "${i##*-}" + exit + fi + echo "Skipped: $i" >&2 + done + SLEEP=$((SLEEP-2)) + RAND=$(od -An -N1 -t u1 /dev/urandom) + sleep $(($RAND % $SLEEP + 5)) +done |