2018-06-09 01:18:30 +02:00
|
|
|
// +build !windows
|
|
|
|
|
|
|
|
package statemgr
|
|
|
|
|
|
|
|
import (
|
2020-12-01 21:56:32 +01:00
|
|
|
"io"
|
2018-11-17 03:01:29 +01:00
|
|
|
"log"
|
2018-06-09 01:18:30 +02:00
|
|
|
"syscall"
|
|
|
|
)
|
|
|
|
|
|
|
|
// use fcntl POSIX locks for the most consistent behavior across platforms, and
|
|
|
|
// hopefully some campatibility over NFS and CIFS.
|
|
|
|
func (s *Filesystem) lock() error {
|
2018-11-17 03:01:29 +01:00
|
|
|
log.Printf("[TRACE] statemgr.Filesystem: locking %s using fcntl flock", s.path)
|
2018-06-09 01:18:30 +02:00
|
|
|
flock := &syscall.Flock_t{
|
|
|
|
Type: syscall.F_RDLCK | syscall.F_WRLCK,
|
2020-12-01 21:56:32 +01:00
|
|
|
Whence: int16(io.SeekStart),
|
2018-06-09 01:18:30 +02:00
|
|
|
Start: 0,
|
|
|
|
Len: 0,
|
|
|
|
}
|
|
|
|
|
|
|
|
fd := s.stateFileOut.Fd()
|
|
|
|
return syscall.FcntlFlock(fd, syscall.F_SETLK, flock)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Filesystem) unlock() error {
|
2018-11-17 03:01:29 +01:00
|
|
|
log.Printf("[TRACE] statemgr.Filesystem: unlocking %s using fcntl flock", s.path)
|
2018-06-09 01:18:30 +02:00
|
|
|
flock := &syscall.Flock_t{
|
|
|
|
Type: syscall.F_UNLCK,
|
2020-12-01 21:56:32 +01:00
|
|
|
Whence: int16(io.SeekStart),
|
2018-06-09 01:18:30 +02:00
|
|
|
Start: 0,
|
|
|
|
Len: 0,
|
|
|
|
}
|
|
|
|
|
|
|
|
fd := s.stateFileOut.Fd()
|
|
|
|
return syscall.FcntlFlock(fd, syscall.F_SETLK, flock)
|
|
|
|
}
|