github.com/fabiomatavelli/terraform@v0.11.12-beta1/state/local_lock_unix.go (about) 1 // +build !windows 2 3 package state 4 5 import ( 6 "io" 7 "syscall" 8 ) 9 10 // use fcntl POSIX locks for the most consistent behavior across platforms, and 11 // hopefully some campatibility over NFS and CIFS. 12 func (s *LocalState) lock() error { 13 flock := &syscall.Flock_t{ 14 Type: syscall.F_RDLCK | syscall.F_WRLCK, 15 Whence: int16(io.SeekStart), 16 Start: 0, 17 Len: 0, 18 } 19 20 fd := s.stateFileOut.Fd() 21 return syscall.FcntlFlock(fd, syscall.F_SETLK, flock) 22 } 23 24 func (s *LocalState) unlock() error { 25 flock := &syscall.Flock_t{ 26 Type: syscall.F_UNLCK, 27 Whence: int16(io.SeekStart), 28 Start: 0, 29 Len: 0, 30 } 31 32 fd := s.stateFileOut.Fd() 33 return syscall.FcntlFlock(fd, syscall.F_SETLK, flock) 34 }