Skip to content

Commit 7f24142

Browse files
committed
syscall, cmd/go/internal/lockedfile/internal/filelock: add and use Flock on illumos
Copy the syscall wrapper from golang.org/x/sys/unix CL 255377 to provide Flock on illumos and switch cmd/go/internal/lockedfile/internal/filelock to use it. Fixes #35618 Change-Id: I876a2b782329a988fa85361fb1ea58eb6f329af1 Reviewed-on: https://go-review.googlesource.com/c/go/+/255258 Trust: Tobias Klauser <[email protected]> Run-TryBot: Tobias Klauser <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]>
1 parent f5d59d0 commit 7f24142

File tree

5 files changed

+45
-3
lines changed

5 files changed

+45
-3
lines changed

src/cmd/go/internal/lockedfile/internal/filelock/filelock_fcntl.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
// +build aix solaris
5+
// +build aix solaris,!illumos
66

77
// This code implements the filelock API using POSIX 'fcntl' locks, which attach
88
// to an (inode, process) pair rather than a file descriptor. To avoid unlocking

src/cmd/go/internal/lockedfile/internal/filelock/filelock_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ func TestRLockExcludesOnlyLock(t *testing.T) {
161161

162162
doUnlockTF := false
163163
switch runtime.GOOS {
164-
case "aix", "illumos", "solaris":
164+
case "aix", "solaris":
165165
// When using POSIX locks (as on Solaris), we can't safely read-lock the
166166
// same inode through two different descriptors at the same time: when the
167167
// first descriptor is closed, the second descriptor would still be open but

src/cmd/go/internal/lockedfile/internal/filelock/filelock_unix.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
// +build darwin dragonfly freebsd linux netbsd openbsd
5+
// +build darwin dragonfly freebsd illumos linux netbsd openbsd
66

77
package filelock
88

src/syscall/syscall_illumos.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2020 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
// +build illumos
6+
7+
// Illumos system calls not present on Solaris.
8+
9+
package syscall
10+
11+
import "unsafe"
12+
13+
//go:cgo_import_dynamic libc_flock flock "libc.so"
14+
15+
//go:linkname procFlock libc_flock
16+
17+
var procFlock libcFunc
18+
19+
func Flock(fd int, how int) error {
20+
_, _, errno := sysvicall6(uintptr(unsafe.Pointer(&procFlock)), 2, uintptr(fd), uintptr(how), 0, 0, 0, 0)
21+
if errno != 0 {
22+
return errno
23+
}
24+
return nil
25+
}

src/syscall/types_illumos_amd64.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2020 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
// +build illumos
6+
7+
// Illumos consts not present on Solaris. These are added manually rather than
8+
// auto-generated by mkerror.sh
9+
10+
package syscall
11+
12+
const (
13+
LOCK_EX = 0x2
14+
LOCK_NB = 0x4
15+
LOCK_SH = 0x1
16+
LOCK_UN = 0x8
17+
)

0 commit comments

Comments
 (0)