github.com/graywolf-at-work-2/terraform-vendor@v1.4.5/internal/states/statemgr/filesystem_lock_unix.go (about) 1 //go:build !windows 2 // +build !windows 3 4 package statemgr 5 6 import ( 7 "io" 8 "log" 9 "syscall" 10 ) 11 12 // use fcntl POSIX locks for the most consistent behavior across platforms, and 13 // hopefully some campatibility over NFS and CIFS. 14 func (s *Filesystem) lock() error { 15 log.Printf("[TRACE] statemgr.Filesystem: locking %s using fcntl flock", s.path) 16 flock := &syscall.Flock_t{ 17 Type: syscall.F_RDLCK | syscall.F_WRLCK, 18 Whence: int16(io.SeekStart), 19 Start: 0, 20 Len: 0, 21 } 22 23 fd := s.stateFileOut.Fd() 24 return syscall.FcntlFlock(fd, syscall.F_SETLK, flock) 25 } 26 27 func (s *Filesystem) unlock() error { 28 log.Printf("[TRACE] statemgr.Filesystem: unlocking %s using fcntl flock", s.path) 29 flock := &syscall.Flock_t{ 30 Type: syscall.F_UNLCK, 31 Whence: int16(io.SeekStart), 32 Start: 0, 33 Len: 0, 34 } 35 36 fd := s.stateFileOut.Fd() 37 return syscall.FcntlFlock(fd, syscall.F_SETLK, flock) 38 }