]> Cypherpunks repositories - gostls13.git/commitdiff
syscall, cmd/go/internal/lockedfile/internal/filelock: add and use Flock on illumos
authorTobias Klauser <tklauser@distanz.ch>
Wed, 16 Sep 2020 20:15:13 +0000 (22:15 +0200)
committerTobias Klauser <tobias.klauser@gmail.com>
Thu, 17 Sep 2020 06:20:06 +0000 (06:20 +0000)
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 <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
src/cmd/go/internal/lockedfile/internal/filelock/filelock_fcntl.go
src/cmd/go/internal/lockedfile/internal/filelock/filelock_test.go
src/cmd/go/internal/lockedfile/internal/filelock/filelock_unix.go
src/syscall/syscall_illumos.go [new file with mode: 0644]
src/syscall/types_illumos_amd64.go [new file with mode: 0644]

index c60a78ed9244826159cc9964481e4c504ff422ac..dc7bbe263f17fb5f5e1ece4705fb8290bfd31d1f 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build aix solaris
+// +build aix solaris,!illumos
 
 // This code implements the filelock API using POSIX 'fcntl' locks, which attach
 // to an (inode, process) pair rather than a file descriptor. To avoid unlocking
index faf73446f7940db103935eba705170fde44f1a44..8301fb6b6e8806af6444ae376494fc3d7cc5970c 100644 (file)
@@ -161,7 +161,7 @@ func TestRLockExcludesOnlyLock(t *testing.T) {
 
        doUnlockTF := false
        switch runtime.GOOS {
-       case "aix", "illumos", "solaris":
+       case "aix", "solaris":
                // When using POSIX locks (as on Solaris), we can't safely read-lock the
                // same inode through two different descriptors at the same time: when the
                // first descriptor is closed, the second descriptor would still be open but
index 00c4262832214f48189c7ea92ac06335a9772e17..78f2c51129eeb29f3af11ec8690661dbe4a41db9 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build darwin dragonfly freebsd linux netbsd openbsd
+// +build darwin dragonfly freebsd illumos linux netbsd openbsd
 
 package filelock
 
diff --git a/src/syscall/syscall_illumos.go b/src/syscall/syscall_illumos.go
new file mode 100644 (file)
index 0000000..1484337
--- /dev/null
@@ -0,0 +1,25 @@
+// Copyright 2020 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build illumos
+
+// Illumos system calls not present on Solaris.
+
+package syscall
+
+import "unsafe"
+
+//go:cgo_import_dynamic libc_flock flock "libc.so"
+
+//go:linkname procFlock libc_flock
+
+var procFlock libcFunc
+
+func Flock(fd int, how int) error {
+       _, _, errno := sysvicall6(uintptr(unsafe.Pointer(&procFlock)), 2, uintptr(fd), uintptr(how), 0, 0, 0, 0)
+       if errno != 0 {
+               return errno
+       }
+       return nil
+}
diff --git a/src/syscall/types_illumos_amd64.go b/src/syscall/types_illumos_amd64.go
new file mode 100644 (file)
index 0000000..abb282f
--- /dev/null
@@ -0,0 +1,17 @@
+// Copyright 2020 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build illumos
+
+// Illumos consts not present on Solaris. These are added manually rather than
+// auto-generated by mkerror.sh
+
+package syscall
+
+const (
+       LOCK_EX = 0x2
+       LOCK_NB = 0x4
+       LOCK_SH = 0x1
+       LOCK_UN = 0x8
+)