github.phpd.cn/hashicorp/packer@v1.3.2/builder/amazon/chroot/lockfile_unix.go (about)

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