Skip to contentSkip to conversation

build-perf-test-wrapper.sh: implement locking

PATCH New Markus Lehtonen 1 participant 1 message Feb 2, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 build-perf-test-wrapper.sh: implement locking

In order to prevent multiple instances of the script running at the same time.

---
 scripts/contrib/build-perf-test-wrapper.sh | 11 +++++++++++
 1 file changed, 11 insertions(+)
scripts/contrib/build-perf-test-wrapper.sh +11 -0
index e03ea97..a4c1929 100755
@@ -67,6 +67,17 @@ if [ $# -ne 0 ]; then
     exit 1
 fi
 
+# Open a file descriptor for flock and acquire lock
+LOCK_FILE="/tmp/oe-build-perf-test-wrapper.lock"
+if ! exec 3> "$LOCK_FILE"; then
+    echo "ERROR: Unable to open lock file"
+    exit 1
+fi
+if ! flock -n 3; then
+    echo "ERROR: Another instance of this script is running"
+    exit 1
+fi
+
 echo "Running on `uname -n`"
 if ! git_topdir=$(git rev-parse --show-toplevel); then
         echo "The current working dir doesn't seem to be a git clone. Please cd there before running `basename $0`"
Signature · 1 line
2.10.2