Skip to content
This repository was archived by the owner on Feb 20, 2019. It is now read-only.

Commit ca9f208

Browse files
author
Ben Aldrich
committed
replace unix implementation to be the same as solaris to fix an issue with glusterfs
1 parent 315c65d commit ca9f208

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

bolt_unix.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,21 @@ func flock(db *DB, mode os.FileMode, exclusive bool, timeout time.Duration) erro
2121
} else if timeout > 0 && time.Since(t) > timeout {
2222
return ErrTimeout
2323
}
24-
flag := syscall.LOCK_SH
24+
var lock syscall.Flock_t
25+
lock.Start = 0
26+
lock.Len = 0
27+
lock.Pid = 0
28+
lock.Whence = 0
29+
lock.Pid = 0
2530
if exclusive {
26-
flag = syscall.LOCK_EX
31+
lock.Type = syscall.F_WRLCK
32+
} else {
33+
lock.Type = syscall.F_RDLCK
2734
}
28-
29-
// Otherwise attempt to obtain an exclusive lock.
30-
err := syscall.Flock(int(db.file.Fd()), flag|syscall.LOCK_NB)
35+
err := syscall.FcntlFlock(db.file.Fd(), syscall.F_SETLK, &lock)
3136
if err == nil {
3237
return nil
33-
} else if err != syscall.EWOULDBLOCK {
38+
} else if err != syscall.EAGAIN {
3439
return err
3540
}
3641

@@ -41,7 +46,12 @@ func flock(db *DB, mode os.FileMode, exclusive bool, timeout time.Duration) erro
4146

4247
// funlock releases an advisory lock on a file descriptor.
4348
func funlock(db *DB) error {
44-
return syscall.Flock(int(db.file.Fd()), syscall.LOCK_UN)
49+
var lock syscall.Flock_t
50+
lock.Start = 0
51+
lock.Len = 0
52+
lock.Type = syscall.F_UNLCK
53+
lock.Whence = 0
54+
return syscall.FcntlFlock(uintptr(db.file.Fd()), syscall.F_SETLK, &lock)
4555
}
4656

4757
// mmap memory maps a DB's data file.

0 commit comments

Comments
 (0)