aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Johnson <benbjohnson@yahoo.com>2016-12-27 14:07:51 -0700
committerGitHub <noreply@github.com>2016-12-27 14:07:51 -0700
commitebe310138bbbe1e1d146197ab8b7fa772da38b1d (patch)
tree6c69ffc8760d9df963f34b24a824d11fbacdc08a
parentMerge pull request #628 from bep/patch-1 (diff)
parentreplace unix implementation to be the same as solaris to fix an issue with gl... (diff)
downloaddedo-ebe310138bbbe1e1d146197ab8b7fa772da38b1d.tar.gz
dedo-ebe310138bbbe1e1d146197ab8b7fa772da38b1d.tar.xz
Merge pull request #625 from vrecan/FcntlFlock
replace unix implementation to be the same as solaris to fix an issue with glusterfs
-rw-r--r--bolt_unix.go24
1 files changed, 17 insertions, 7 deletions
diff --git a/bolt_unix.go b/bolt_unix.go
index cad62dd..50cbbc0 100644
--- a/bolt_unix.go
+++ b/bolt_unix.go
@@ -21,16 +21,21 @@ func flock(db *DB, mode os.FileMode, exclusive bool, timeout time.Duration) erro
} else if timeout > 0 && time.Since(t) > timeout {
return ErrTimeout
}
- flag := syscall.LOCK_SH
+ var lock syscall.Flock_t
+ lock.Start = 0
+ lock.Len = 0
+ lock.Pid = 0
+ lock.Whence = 0
+ lock.Pid = 0
if exclusive {
- flag = syscall.LOCK_EX
+ lock.Type = syscall.F_WRLCK
+ } else {
+ lock.Type = syscall.F_RDLCK
}
-
- // Otherwise attempt to obtain an exclusive lock.
- err := syscall.Flock(int(db.file.Fd()), flag|syscall.LOCK_NB)
+ err := syscall.FcntlFlock(db.file.Fd(), syscall.F_SETLK, &lock)
if err == nil {
return nil
- } else if err != syscall.EWOULDBLOCK {
+ } else if err != syscall.EAGAIN {
return err
}
@@ -41,7 +46,12 @@ func flock(db *DB, mode os.FileMode, exclusive bool, timeout time.Duration) erro
// funlock releases an advisory lock on a file descriptor.
func funlock(db *DB) error {
- return syscall.Flock(int(db.file.Fd()), syscall.LOCK_UN)
+ var lock syscall.Flock_t
+ lock.Start = 0
+ lock.Len = 0
+ lock.Type = syscall.F_UNLCK
+ lock.Whence = 0
+ return syscall.FcntlFlock(uintptr(db.file.Fd()), syscall.F_SETLK, &lock)
}
// mmap memory maps a DB's data file.