summaryrefslogtreecommitdiff
path: root/functions/lockfile.sh
diff options
context:
space:
mode:
authorjnqnfe <jnqnfe@gmail.com>2015-02-05 03:30:47 +0000
committerLyndon Brown <jnqnfe@gmail.com>2020-03-13 15:37:38 +0000
commitb27927724a5da017796d16de47979116d01455dc (patch)
treed8ca219d15a873198be13b8feb1d3ad8a10b63c8 /functions/lockfile.sh
parent346e3e1c36f8dc61e93fdd76dd28174d85e2aa5d (diff)
downloadvyos-live-build-b27927724a5da017796d16de47979116d01455dc.tar.gz
vyos-live-build-b27927724a5da017796d16de47979116d01455dc.zip
locks: tidy lock acquisition
Combine the check+create done in each script. (The original functions are still callable as before, but a new combined `Aquire_lockfile` function can be called instead, as now used). Note, a further simplification could be done in removing the passing of the lock filename in as a parameter since every use of the functions is with ".lock". The lock functions already have a fallback to ".build/lock" though. Checking the history, the fallback used to be for a system wide lock, which was then replaced with this config-tree specific one. As long as that is not used implicitly by 3rd-party hooks then surely we are free to change the fallback to ".lock" and further remove passing in a name as a param...? history: db5d2b0dcdae96e712661605e17bc9875e224f9f 0aa8289a3773fd8a3885090b72622c2f95ab099c Gbp-Dch: Short Closes: #952918
Diffstat (limited to 'functions/lockfile.sh')
-rwxr-xr-xfunctions/lockfile.sh42
1 files changed, 20 insertions, 22 deletions
diff --git a/functions/lockfile.sh b/functions/lockfile.sh
index cf7e22d5f..b467d25f3 100755
--- a/functions/lockfile.sh
+++ b/functions/lockfile.sh
@@ -9,40 +9,38 @@
## under certain conditions; see COPYING for details.
-Check_lockfile ()
+Acquire_lockfile ()
{
- FILE="${1}"
+ local FILE="${1:-.lock}"
+ Check_lockfile "${FILE}"
+ Create_lockfile "${FILE}"
+}
- if [ -z "${FILE}" ]
- then
- FILE=".build/lock"
- fi
+Check_lockfile ()
+{
+ local FILE="${1}"
- # Checking lock file
- if [ -f "${FILE}" ]
- then
- Echo_error "${PROGRAM} locked"
+ if [ -f "${FILE}" ]; then
+ Echo_error "${PROGRAM} already locked"
exit 1
fi
}
Create_lockfile ()
{
- FILE="${1}"
-
- if [ -z "${FILE}" ]
- then
- FILE=".build/lock"
- fi
+ local FILE="${1}"
- DIRECTORY="$(dirname ${FILE})"
-
- # Creating lock directory
- mkdir -p "${DIRECTORY}"
-
- # Creating lock trap
+ # Create lock trap
+ # This automatically removes the lock file in certain conditions
trap 'ret=${?}; '"rm -f \"${FILE}\";"' exit ${ret}' EXIT HUP INT QUIT TERM
# Creating lock file
touch "${FILE}"
}
+
+Remove_lockfile ()
+{
+ local FILE="${1:-.lock}"
+
+ rm -f "${FILE}"
+}