Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
LECABashLib
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
2
Issues
2
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
LECASofts
LECABashLib
Commits
f16ddd53
Commit
f16ddd53
authored
Feb 01, 2018
by
Eric Coissac
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
some small bug changes
parent
5e5c811f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
60 additions
and
7 deletions
+60
-7
mutex.sh
mutex.sh
+60
-7
No files found.
mutex.sh
View file @
f16ddd53
...
...
@@ -35,20 +35,69 @@ function __locktag__() {
echo
"
$(
hostname
)
.
$$
"
}
function
trytogetlock
()
{
local
lname
=
"
$1
"
shift
local
mode
=
"user"
logdebug
"Try to get lock
${
lname
}
"
if
[[
"
${
1
}
"
==
"global"
]]
;
then
mode
=
"global"
fi
if
[[
"
${
mode
}
"
==
"global"
]]
;
then
name
=
$(
__lockfile__
"
${
lname
}
"
)
else
name
=
$(
__lockfile__
"
${
lname
}
.
$(
whoami
)
"
)
fi
local
TAG
=
$(
__locktag__
)
local
retry
=
0
local
notgetlock
=
1
pushnoclobber
echo
"
${
TAG
}
"
2>/dev/null 1>
"
${
name
}
"
notgetlock
=
$?
popnoclobber
if
((
notgetlock
>
0
))
;
then
if
[[
$(
cat
"
${
name
}
"
2> /dev/null
)
==
"
${
TAG
}
"
]]
;
then
notgetlock
=
0
fi
fi
if
((
notgetlock
==
0
))
;
then
logdebug
"Succeed to get lock
${
lname
}
"
fi
if
((
notgetlock
>
0
))
;
then
return
$notgetlock
else
chmod
a+w
"
${
name
}
"
return
0
fi
}
function
getlock
()
{
local
name
=
"
$1
"
local
l
name
=
"
$1
"
shift
local
mode
=
"user"
logdebug
"Try to get lock
${
lname
}
"
if
[[
"
${
1
}
"
==
"global"
]]
;
then
mode
=
"global"
fi
if
[[
"
${
mode
}
"
==
"global"
]]
;
then
name
=
$(
__lockfile__
"
${
name
}
"
)
name
=
$(
__lockfile__
"
${
l
name
}
"
)
else
name
=
$(
__lockfile__
"
${
name
}
.
$(
whoami
)
"
)
name
=
$(
__lockfile__
"
${
l
name
}
.
$(
whoami
)
"
)
fi
local
TAG
=
$(
__locktag__
)
...
...
@@ -70,7 +119,7 @@ function getlock() {
fi
if
((
notgetlock
>
0
))
;
then
log
info
"Failed to get lock
$name
"
log
debug
"Failed to get lock
${
lname
}
"
sleep
"
${
LECA_LOCK_DELAY
}
"
retry
=
$((
retry
+
1
))
fi
...
...
@@ -80,25 +129,28 @@ function getlock() {
if
((
notgetlock
>
0
))
;
then
return
$notgetlock
else
logdebug
"Succeed to get lock
${
lname
}
"
chmod
a+w
"
${
name
}
"
return
0
fi
}
function
releaselock
()
{
local
name
=
"
$1
"
local
l
name
=
"
$1
"
shift
local
mode
=
"user"
logdebug
"Try to release lock
${
lname
}
"
if
[[
"
${
1
}
"
==
"global"
]]
;
then
mode
=
"global"
fi
if
[[
"
${
mode
}
"
==
"global"
]]
;
then
name
=
$(
__lockfile__
"
${
name
}
"
)
name
=
$(
__lockfile__
"
${
l
name
}
"
)
else
name
=
$(
__lockfile__
"
${
name
}
.
$(
whoami
)
"
)
name
=
$(
__lockfile__
"
${
l
name
}
.
$(
whoami
)
"
)
fi
local
TAG
=
$(
__locktag__
)
...
...
@@ -113,6 +165,7 @@ function releaselock() {
if
[[
"
${
LOCK
}
"
==
"
${
TAG
}
"
]]
;
then
rm
-f
"
${
name
}
"
logdebug
"Lock
${
lname
}
released"
return
0
fi
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment