github.com/richardmarshall/terraform@v0.9.5-0.20170429023105-15704cc6ee35/state/local_lock_unix.go (about)

     1  // +build !windows
     2  
     3  package state
     4  
     5  import (
     6  	"os"
     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(os.SEEK_SET),
    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(os.SEEK_SET),
    28  		Start:  0,
    29  		Len:    0,
    30  	}
    31  
    32  	fd := s.stateFileOut.Fd()
    33  	return syscall.FcntlFlock(fd, syscall.F_SETLK, flock)
    34  }