2017-01-10 00:15:48 +01:00
|
|
|
// +build !windows
|
|
|
|
|
|
|
|
package state
|
|
|
|
|
|
|
|
import (
|
2018-02-25 23:11:40 +01:00
|
|
|
"io"
|
2017-01-10 00:15:48 +01:00
|
|
|
"syscall"
|
|
|
|
)
|
|
|
|
|
|
|
|
// use fcntl POSIX locks for the most consistent behavior across platforms, and
|
|
|
|
// hopefully some campatibility over NFS and CIFS.
|
|
|
|
func (s *LocalState) lock() error {
|
|
|
|
flock := &syscall.Flock_t{
|
|
|
|
Type: syscall.F_RDLCK | syscall.F_WRLCK,
|
2018-02-25 23:11:40 +01:00
|
|
|
Whence: int16(io.SeekStart),
|
2017-01-10 00:15:48 +01:00
|
|
|
Start: 0,
|
|
|
|
Len: 0,
|
|
|
|
}
|
|
|
|
|
2017-01-30 21:33:21 +01:00
|
|
|
fd := s.stateFileOut.Fd()
|
2017-01-10 00:15:48 +01:00
|
|
|
return syscall.FcntlFlock(fd, syscall.F_SETLK, flock)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *LocalState) unlock() error {
|
|
|
|
flock := &syscall.Flock_t{
|
|
|
|
Type: syscall.F_UNLCK,
|
2018-02-25 23:11:40 +01:00
|
|
|
Whence: int16(io.SeekStart),
|
2017-01-10 00:15:48 +01:00
|
|
|
Start: 0,
|
|
|
|
Len: 0,
|
|
|
|
}
|
|
|
|
|
|
|
|
fd := s.stateFileOut.Fd()
|
|
|
|
return syscall.FcntlFlock(fd, syscall.F_SETLK, flock)
|
|
|
|
}
|