2013-07-31 00:48:37 -04:00
|
|
|
// +build !windows
|
|
|
|
|
|
|
|
package chroot
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
2017-08-11 18:13:55 -04:00
|
|
|
|
|
|
|
"golang.org/x/sys/unix"
|
2013-07-31 00:48:37 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// See: http://linux.die.net/include/sys/file.h
|
|
|
|
const LOCK_EX = 2
|
|
|
|
const LOCK_NB = 4
|
|
|
|
const LOCK_UN = 8
|
|
|
|
|
|
|
|
func lockFile(f *os.File) error {
|
2017-08-11 18:13:55 -04:00
|
|
|
err := unix.Flock(int(f.Fd()), LOCK_EX)
|
2013-07-31 00:48:37 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func unlockFile(f *os.File) error {
|
2017-08-11 18:13:55 -04:00
|
|
|
return unix.Flock(int(f.Fd()), LOCK_UN)
|
2013-07-31 00:48:37 -04:00
|
|
|
}
|