Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
66d29148
Unverified
Commit
66d29148
authored
Oct 05, 2020
by
Erik Wilson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Release function for flock
parent
360d82d2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
10 deletions
+16
-10
flock_other.go
pkg/flock/flock_other.go
+6
-1
flock_unix.go
pkg/flock/flock_unix.go
+10
-9
No files found.
pkg/flock/flock_other.go
View file @
66d29148
...
@@ -19,6 +19,11 @@ limitations under the License.
...
@@ -19,6 +19,11 @@ limitations under the License.
package
flock
package
flock
// Acquire is not implemented on non-unix systems.
// Acquire is not implemented on non-unix systems.
func
Acquire
(
path
string
)
error
{
func
Acquire
(
path
string
)
(
int
,
error
)
{
return
-
1
,
nil
}
// Release is not implemented on non-unix systems.
func
Release
(
lock
int
)
error
{
return
nil
return
nil
}
}
pkg/flock/flock_unix.go
View file @
66d29148
...
@@ -20,16 +20,17 @@ package flock
...
@@ -20,16 +20,17 @@ package flock
import
"golang.org/x/sys/unix"
import
"golang.org/x/sys/unix"
// Acquire
acquires a lock on a file for the duration of the process. This method
// Acquire
creates an exclusive lock on a file for the duration of the process, or until Release(d).
// is reentrant.
//
This method
is reentrant.
func
Acquire
(
path
string
)
error
{
func
Acquire
(
path
string
)
(
int
,
error
)
{
fd
,
err
:=
unix
.
Open
(
path
,
unix
.
O_CREAT
|
unix
.
O_RDWR
|
unix
.
O_CLOEXEC
,
0600
)
lock
,
err
:=
unix
.
Open
(
path
,
unix
.
O_CREAT
|
unix
.
O_RDWR
|
unix
.
O_CLOEXEC
,
0600
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
-
1
,
err
}
}
return
lock
,
unix
.
Flock
(
lock
,
unix
.
LOCK_EX
)
}
// We don't need to close the fd since we should hold
// Release removes an existing lock held by this process.
// it until the process exits.
func
Release
(
lock
int
)
error
{
return
unix
.
Flock
(
lock
,
unix
.
LOCK_UN
)
return
unix
.
Flock
(
fd
,
unix
.
LOCK_EX
)
}
}
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