summaryrefslogtreecommitdiff
path: root/tct/resource_locking.sh
diff options
context:
space:
mode:
authorAleksander Mistewicz <a.mistewicz@samsung.com>2016-03-18 16:07:03 +0100
committerAleksander Mistewicz <a.mistewicz@samsung.com>2016-05-13 14:09:43 +0200
commit4ca3a33cbdc4ae6a46e5ab73673ca579a827ef0e (patch)
tree8dd46166b6f62e3903e54a30873751e25a5e331a /tct/resource_locking.sh
parent1a4bb99f961cec796492b0cebadcf55470ff4c42 (diff)
downloadmajor-4ca3a33cbdc4ae6a46e5ab73673ca579a827ef0e.tar.gz
major-4ca3a33cbdc4ae6a46e5ab73673ca579a827ef0e.tar.bz2
major-4ca3a33cbdc4ae6a46e5ab73673ca579a827ef0e.zip
Add tct/resource_locking.sh
Change-Id: I9526afee6ca0776fe32960dba9fa2ee522742909 Signed-off-by: Aleksander Mistewicz <a.mistewicz@samsung.com>
Diffstat (limited to 'tct/resource_locking.sh')
-rwxr-xr-xtct/resource_locking.sh40
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