github.com/rothwerx/packer@v0.9.0/builder/amazon/chroot/lockfile_unix.go (about)

     1  // +build !windows
     2  
     3  package chroot
     4  
     5  import (
     6  	"os"
     7  	"syscall"
     8  )
     9  
    10  // See: http://linux.die.net/include/sys/file.h
    11  const LOCK_EX = 2
    12  const LOCK_NB = 4
    13  const LOCK_UN = 8
    14  
    15  func lockFile(f *os.File) error {
    16  	err := syscall.Flock(int(f.Fd()), LOCK_EX)
    17  	if err != nil {
    18  		return err
    19  	}
    20  
    21  	return nil
    22  }
    23  
    24  func unlockFile(f *os.File) error {
    25  	return syscall.Flock(int(f.Fd()), LOCK_UN)
    26  }