diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2014-07-19 08:53:52 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2014-07-19 08:53:52 +0000 |
commit | 00d86ac99f5dd6afa5bbd7c38ffe1c585edd2387 (patch) | |
tree | b988e32ea14a3dc1b4718b1fdfa47bab087ae96c /libgo/go/syscall | |
parent | bcf2fc6ee0a7edbe7de4299f28b66527c07bb0a2 (diff) | |
download | gcc-00d86ac99f5dd6afa5bbd7c38ffe1c585edd2387.zip gcc-00d86ac99f5dd6afa5bbd7c38ffe1c585edd2387.tar.gz gcc-00d86ac99f5dd6afa5bbd7c38ffe1c585edd2387.tar.bz2 |
libgo: Update to Go 1.3 release.
From-SVN: r212837
Diffstat (limited to 'libgo/go/syscall')
22 files changed, 229 insertions, 128 deletions
diff --git a/libgo/go/syscall/consistency_unix_test.go b/libgo/go/syscall/consistency_unix_test.go deleted file mode 100644 index 6c9fb82..0000000 --- a/libgo/go/syscall/consistency_unix_test.go +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright 2013 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 freebsd dragonfly darwin linux netbsd openbsd - -// This file tests that some basic syscalls are consistent across -// all Unixes. - -package syscall_test - -import "syscall" - -// {Set,Get}priority and needed constants for them -func _() { - var ( - _ func(int, int, int) error = syscall.Setpriority - _ func(int, int) (int, error) = syscall.Getpriority - ) - const ( - _ int = syscall.PRIO_USER - _ int = syscall.PRIO_PROCESS - _ int = syscall.PRIO_PGRP - ) -} - -// termios functions and constants -func _() { - const ( - _ int = syscall.TCIFLUSH - _ int = syscall.TCIOFLUSH - _ int = syscall.TCOFLUSH - ) -} - -func _() { - _ = syscall.Flock_t{ - Type: int16(0), - Whence: int16(0), - Start: int64(0), - Len: int64(0), - Pid: int32(0), - } -} diff --git a/libgo/go/syscall/dir_plan9.go b/libgo/go/syscall/dir_plan9.go index d9fb26b13..697bf54 100644 --- a/libgo/go/syscall/dir_plan9.go +++ b/libgo/go/syscall/dir_plan9.go @@ -54,7 +54,7 @@ var nullDir = Dir{ } // Null assigns special "don't touch" values to members of d to -// avoid modifiying them during syscall.Wstat. +// avoid modifying them during syscall.Wstat. func (d *Dir) Null() { *d = nullDir } // Marshal encodes a 9P stat message corresponding to d into b diff --git a/libgo/go/syscall/env_unix.go b/libgo/go/syscall/env_unix.go index f64202e..7f39958 100644 --- a/libgo/go/syscall/env_unix.go +++ b/libgo/go/syscall/env_unix.go @@ -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 linux nacl netbsd openbsd solaris // Unix environment variables. diff --git a/libgo/go/syscall/exec_unix.go b/libgo/go/syscall/exec_unix.go index 0cfedb7..6bf28cc 100644 --- a/libgo/go/syscall/exec_unix.go +++ b/libgo/go/syscall/exec_unix.go @@ -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 linux netbsd openbsd solaris // Fork, exec, wait, etc. @@ -194,7 +194,7 @@ func forkExec(argv0 string, argv []string, attr *ProcAttr) (pid int, err error) return 0, err } - if runtime.GOOS == "freebsd" && len(argv[0]) > len(argv0) { + if (runtime.GOOS == "freebsd" || runtime.GOOS == "dragonfly") && len(argv[0]) > len(argv0) { argvp[0] = argv0p } diff --git a/libgo/go/syscall/libcall_posix.go b/libgo/go/syscall/libcall_posix.go index 85f38e0..d3580a1 100644 --- a/libgo/go/syscall/libcall_posix.go +++ b/libgo/go/syscall/libcall_posix.go @@ -244,9 +244,6 @@ func FDZero(set *FdSet) { //sys Getpriority(which int, who int) (prio int, err error) //getpriority(which _C_int, who _C_int) _C_int -//sysnb Getrlimit(resource int, rlim *Rlimit) (err error) -//getrlimit(resource _C_int, rlim *Rlimit) _C_int - //sysnb Getrusage(who int, rusage *Rusage) (err error) //getrusage(who _C_int, rusage *Rusage) _C_int @@ -319,9 +316,6 @@ func Gettimeofday(tv *Timeval) (err error) { //sysnb Setreuid(ruid int, euid int) (err error) //setreuid(ruid Uid_t, euid Uid_t) _C_int -//sysnb Setrlimit(resource int, rlim *Rlimit) (err error) -//setrlimit(resource int, rlim *Rlimit) _C_int - //sysnb Setsid() (pid int, err error) //setsid() Pid_t diff --git a/libgo/go/syscall/libcall_posix_largefile.go b/libgo/go/syscall/libcall_posix_largefile.go index fced6e5..c05d3d2 100644 --- a/libgo/go/syscall/libcall_posix_largefile.go +++ b/libgo/go/syscall/libcall_posix_largefile.go @@ -12,6 +12,9 @@ package syscall //sys Ftruncate(fd int, length int64) (err error) //ftruncate64(fd _C_int, length Offset_t) _C_int +//sysnb Getrlimit(resource int, rlim *Rlimit) (err error) +//getrlimit64(resource _C_int, rlim *Rlimit) _C_int + //sys Lstat(path string, stat *Stat_t) (err error) //lstat64(path *byte, stat *Stat_t) _C_int @@ -30,6 +33,9 @@ package syscall //sys Seek(fd int, offset int64, whence int) (off int64, err error) //lseek64(fd _C_int, offset Offset_t, whence _C_int) Offset_t +//sysnb Setrlimit(resource int, rlim *Rlimit) (err error) +//setrlimit64(resource int, rlim *Rlimit) _C_int + //sys Stat(path string, stat *Stat_t) (err error) //stat64(path *byte, stat *Stat_t) _C_int diff --git a/libgo/go/syscall/libcall_posix_regfile.go b/libgo/go/syscall/libcall_posix_regfile.go index 6c98e29..7de5800 100644 --- a/libgo/go/syscall/libcall_posix_regfile.go +++ b/libgo/go/syscall/libcall_posix_regfile.go @@ -13,6 +13,9 @@ package syscall //sys Ftruncate(fd int, length int64) (err error) //ftruncate(fd _C_int, length Offset_t) _C_int +//sysnb Getrlimit(resource int, rlim *Rlimit) (err error) +//getrlimit(resource _C_int, rlim *Rlimit) _C_int + //sys Lstat(path string, stat *Stat_t) (err error) //lstat(path *byte, stat *Stat_t) _C_int @@ -31,6 +34,9 @@ package syscall //sys Seek(fd int, offset int64, whence int) (off int64, err error) //lseek(fd _C_int, offset Offset_t, whence _C_int) Offset_t +//sysnb Setrlimit(resource int, rlim *Rlimit) (err error) +//setrlimit(resource int, rlim *Rlimit) _C_int + //sys Stat(path string, stat *Stat_t) (err error) //stat(path *byte, stat *Stat_t) _C_int diff --git a/libgo/go/syscall/mmap_unix_test.go b/libgo/go/syscall/mmap_unix_test.go new file mode 100644 index 0000000..01f7783 --- /dev/null +++ b/libgo/go/syscall/mmap_unix_test.go @@ -0,0 +1,22 @@ +// Copyright 2014 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 darwin dragonfly freebsd linux netbsd openbsd + +package syscall_test + +import ( + "syscall" + "testing" +) + +func TestMmap(t *testing.T) { + b, err := syscall.Mmap(-1, 0, syscall.Getpagesize(), syscall.PROT_NONE, syscall.MAP_ANON|syscall.MAP_PRIVATE) + if err != nil { + t.Fatalf("Mmap: %v", err) + } + if err := syscall.Munmap(b); err != nil { + t.Fatalf("Munmap: %v", err) + } +} diff --git a/libgo/go/syscall/rlimit_unix_test.go b/libgo/go/syscall/rlimit_unix_test.go deleted file mode 100644 index fc9b026..0000000 --- a/libgo/go/syscall/rlimit_unix_test.go +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2013 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 darwin dragonfly freebsd linux netbsd openbsd - -package syscall_test - -import ( - "runtime" - "syscall" - "testing" -) - -func TestRlimit(t *testing.T) { - var rlimit, zero syscall.Rlimit - err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rlimit) - if err != nil { - t.Fatalf("Getrlimit: save failed: %v", err) - } - if zero == rlimit { - t.Fatalf("Getrlimit: save failed: got zero value %#v", rlimit) - } - set := rlimit - set.Cur = set.Max - 1 - err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &set) - if err != nil { - t.Fatalf("Setrlimit: set failed: %#v %v", set, err) - } - var get syscall.Rlimit - err = syscall.Getrlimit(syscall.RLIMIT_NOFILE, &get) - if err != nil { - t.Fatalf("Getrlimit: get failed: %v", err) - } - set = rlimit - set.Cur = set.Max - 1 - if set != get { - // Seems like Darwin requires some privilege to - // increase the soft limit of rlimit sandbox, though - // Setrlimit never reports an error. - switch runtime.GOOS { - case "darwin": - default: - t.Fatalf("Rlimit: change failed: wanted %#v got %#v", set, get) - } - } - err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rlimit) - if err != nil { - t.Fatalf("Setrlimit: restore failed: %#v %v", rlimit, err) - } -} diff --git a/libgo/go/syscall/route_dragonfly.go b/libgo/go/syscall/route_dragonfly.go index acad7a2..79190d2 100644 --- a/libgo/go/syscall/route_dragonfly.go +++ b/libgo/go/syscall/route_dragonfly.go @@ -30,7 +30,7 @@ func (any *anyMessage) toRoutingMessage(b []byte) RoutingMessage { } // InterfaceAnnounceMessage represents a routing message containing -// network interface arrival and depature information. +// network interface arrival and departure information. type InterfaceAnnounceMessage struct { Header IfAnnounceMsghdr } diff --git a/libgo/go/syscall/route_freebsd.go b/libgo/go/syscall/route_freebsd.go index d8f8031..15897b1 100644 --- a/libgo/go/syscall/route_freebsd.go +++ b/libgo/go/syscall/route_freebsd.go @@ -8,14 +8,20 @@ package syscall import "unsafe" +// See http://www.freebsd.org/doc/en/books/porters-handbook/freebsd-versions.html. +var freebsdVersion uint32 + +func init() { + freebsdVersion, _ = SysctlUint32("kern.osreldate") +} + func (any *anyMessage) toRoutingMessage(b []byte) RoutingMessage { switch any.Type { case RTM_ADD, RTM_DELETE, RTM_CHANGE, RTM_GET, RTM_LOSING, RTM_REDIRECT, RTM_MISS, RTM_LOCK, RTM_RESOLVE: p := (*RouteMessage)(unsafe.Pointer(any)) return &RouteMessage{Header: p.Header, Data: b[SizeofRtMsghdr:any.Msglen]} case RTM_IFINFO: - p := (*InterfaceMessage)(unsafe.Pointer(any)) - return &InterfaceMessage{Header: p.Header, Data: b[SizeofIfMsghdr:any.Msglen]} + return any.parseInterfaceMessage(b) case RTM_IFANNOUNCE: p := (*InterfaceAnnounceMessage)(unsafe.Pointer(any)) return &InterfaceAnnounceMessage{Header: p.Header} @@ -30,7 +36,7 @@ func (any *anyMessage) toRoutingMessage(b []byte) RoutingMessage { } // InterfaceAnnounceMessage represents a routing message containing -// network interface arrival and depature information. +// network interface arrival and departure information. type InterfaceAnnounceMessage struct { Header IfAnnounceMsghdr } diff --git a/libgo/go/syscall/route_freebsd_32bit.go b/libgo/go/syscall/route_freebsd_32bit.go new file mode 100644 index 0000000..93efddd --- /dev/null +++ b/libgo/go/syscall/route_freebsd_32bit.go @@ -0,0 +1,24 @@ +// Copyright 2014 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 freebsd,386 freebsd,arm + +package syscall + +import "unsafe" + +func (any *anyMessage) parseInterfaceMessage(b []byte) *InterfaceMessage { + p := (*InterfaceMessage)(unsafe.Pointer(any)) + // FreeBSD 10 and beyond have a restructured mbuf + // packet header view. + // See http://svnweb.freebsd.org/base?view=revision&revision=254804. + if freebsdVersion >= 1000000 { + m := (*ifMsghdr)(unsafe.Pointer(any)) + p.Header.Data.Hwassist = uint32(m.Data.Hwassist) + p.Header.Data.Epoch = m.Data.Epoch + p.Header.Data.Lastchange = m.Data.Lastchange + return &InterfaceMessage{Header: p.Header, Data: b[sizeofIfMsghdr:any.Msglen]} + } + return &InterfaceMessage{Header: p.Header, Data: b[SizeofIfMsghdr:any.Msglen]} +} diff --git a/libgo/go/syscall/route_freebsd_64bit.go b/libgo/go/syscall/route_freebsd_64bit.go new file mode 100644 index 0000000..9377f2f --- /dev/null +++ b/libgo/go/syscall/route_freebsd_64bit.go @@ -0,0 +1,14 @@ +// Copyright 2014 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 freebsd,amd64 + +package syscall + +import "unsafe" + +func (any *anyMessage) parseInterfaceMessage(b []byte) *InterfaceMessage { + p := (*InterfaceMessage)(unsafe.Pointer(any)) + return &InterfaceMessage{Header: p.Header, Data: b[SizeofIfMsghdr:any.Msglen]} +} diff --git a/libgo/go/syscall/route_netbsd.go b/libgo/go/syscall/route_netbsd.go index a6baa02..9883aeb 100644 --- a/libgo/go/syscall/route_netbsd.go +++ b/libgo/go/syscall/route_netbsd.go @@ -27,7 +27,7 @@ func (any *anyMessage) toRoutingMessage(b []byte) RoutingMessage { } // InterfaceAnnounceMessage represents a routing message containing -// network interface arrival and depature information. +// network interface arrival and departure information. type InterfaceAnnounceMessage struct { Header IfAnnounceMsghdr } diff --git a/libgo/go/syscall/route_openbsd.go b/libgo/go/syscall/route_openbsd.go index 223c157..19f902d 100644 --- a/libgo/go/syscall/route_openbsd.go +++ b/libgo/go/syscall/route_openbsd.go @@ -27,7 +27,7 @@ func (any *anyMessage) toRoutingMessage(b []byte) RoutingMessage { } // InterfaceAnnounceMessage represents a routing message containing -// network interface arrival and depature information. +// network interface arrival and departure information. type InterfaceAnnounceMessage struct { Header IfAnnounceMsghdr } diff --git a/libgo/go/syscall/sockcmsg_unix.go b/libgo/go/syscall/sockcmsg_unix.go index 5bc4c2a..34c707d 100644 --- a/libgo/go/syscall/sockcmsg_unix.go +++ b/libgo/go/syscall/sockcmsg_unix.go @@ -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 linux netbsd openbsd solaris // Socket control messages @@ -16,9 +16,9 @@ import ( // Round the length of a raw sockaddr up to align it properly. func cmsgAlignOf(salen int) int { salign := int(sizeofPtr) - // NOTE: It seems like 64-bit Darwin kernel still requires 32-bit - // aligned access to BSD subsystem. - if darwin64Bit { + // NOTE: It seems like 64-bit Darwin and DragonFly BSD kernels + // still require 32-bit aligned access to network subsystem. + if darwin64Bit || dragonfly64Bit { salign = 4 } // NOTE: Solaris always uses 32-bit alignment, diff --git a/libgo/go/syscall/socket.go b/libgo/go/syscall/socket.go index 491f52c..d96a717 100644 --- a/libgo/go/syscall/socket.go +++ b/libgo/go/syscall/socket.go @@ -359,13 +359,18 @@ func Recvmsg(fd int, p, oob []byte, flags int) (n, oobn int, recvflags int, from } func Sendmsg(fd int, p, oob []byte, to Sockaddr, flags int) (err error) { + _, err = SendmsgN(fd, p, oob, to, flags) + return +} + +func SendmsgN(fd int, p, oob []byte, to Sockaddr, flags int) (n int, err error) { var ptr *RawSockaddrAny var salen Socklen_t if to != nil { var err error ptr, salen, err = to.sockaddr() if err != nil { - return err + return 0, err } } var msg Msghdr @@ -388,10 +393,13 @@ func Sendmsg(fd int, p, oob []byte, to Sockaddr, flags int) (err error) { } msg.Iov = &iov msg.Iovlen = 1 - if err = sendmsg(fd, &msg, flags); err != nil { - return + if n, err = sendmsg(fd, &msg, flags); err != nil { + return 0, err } - return + if len(oob) > 0 && len(p) == 0 { + n = 0 + } + return n, nil } //sys Listen(fd int, n int) (err error) diff --git a/libgo/go/syscall/socket_posix.go b/libgo/go/syscall/socket_posix.go index fd96524..fda7dc6 100644 --- a/libgo/go/syscall/socket_posix.go +++ b/libgo/go/syscall/socket_posix.go @@ -27,5 +27,5 @@ package syscall //sys recvmsg(s int, msg *Msghdr, flags int) (n int, err error) //recvmsg(s _C_int, msg *Msghdr, flags _C_int) Ssize_t -//sys sendmsg(s int, msg *Msghdr, flags int) (err error) +//sys sendmsg(s int, msg *Msghdr, flags int) (n int, err error) //sendmsg(s _C_int, msg *Msghdr, flags _C_int) Ssize_t diff --git a/libgo/go/syscall/socket_xnet.go b/libgo/go/syscall/socket_xnet.go index 0440010..3c5b6b4 100644 --- a/libgo/go/syscall/socket_xnet.go +++ b/libgo/go/syscall/socket_xnet.go @@ -28,5 +28,5 @@ package syscall //sys recvmsg(s int, msg *Msghdr, flags int) (n int, err error) //__xnet_recvmsg(s _C_int, msg *Msghdr, flags _C_int) Ssize_t -//sys sendmsg(s int, msg *Msghdr, flags int) (err error) +//sys sendmsg(s int, msg *Msghdr, flags int) (n int, err error) //__xnet_sendmsg(s _C_int, msg *Msghdr, flags _C_int) Ssize_t diff --git a/libgo/go/syscall/syscall_linux_386.go b/libgo/go/syscall/syscall_linux_386.go index 08422de..591d3e1 100644 --- a/libgo/go/syscall/syscall_linux_386.go +++ b/libgo/go/syscall/syscall_linux_386.go @@ -4,6 +4,9 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// TODO(rsc): Rewrite all nn(SP) references into name+(nn-8)(FP) +// so that go vet can check that they are correct. + package syscall import "unsafe" diff --git a/libgo/go/syscall/syscall_unix.go b/libgo/go/syscall/syscall_unix.go index fcb90db..a64b05f 100644 --- a/libgo/go/syscall/syscall_unix.go +++ b/libgo/go/syscall/syscall_unix.go @@ -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 linux netbsd openbsd solaris package syscall @@ -25,8 +25,9 @@ func c_syscall32(trap int32, a1, a2, a3, a4, a5, a6 int32) int32 func c_syscall64(trap int64, a1, a2, a3, a4, a5, a6 int64) int64 const ( - darwin64Bit = runtime.GOOS == "darwin" && sizeofPtr == 8 - netbsd32Bit = runtime.GOOS == "netbsd" && sizeofPtr == 4 + darwin64Bit = runtime.GOOS == "darwin" && sizeofPtr == 8 + dragonfly64Bit = runtime.GOOS == "dragonfly" && sizeofPtr == 8 + netbsd32Bit = runtime.GOOS == "netbsd" && sizeofPtr == 4 ) // Do a system call. We look at the size of uintptr to see how to pass diff --git a/libgo/go/syscall/passfd_test.go b/libgo/go/syscall/syscall_unix_test.go index e8ac32d..897ad18 100644 --- a/libgo/go/syscall/passfd_test.go +++ b/libgo/go/syscall/syscall_unix_test.go @@ -1,8 +1,8 @@ -// Copyright 2012 The Go Authors. All rights reserved. +// Copyright 2013 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 linux dragonfly darwin freebsd netbsd openbsd +// +build darwin dragonfly freebsd linux netbsd openbsd solaris package syscall_test @@ -13,12 +13,70 @@ import ( "net" "os" "os/exec" + "path/filepath" "runtime" "syscall" "testing" "time" ) +// Tests that below functions, structures and constants are consistent +// on all Unix-like systems. +func _() { + // program scheduling priority functions and constants + var ( + _ func(int, int, int) error = syscall.Setpriority + _ func(int, int) (int, error) = syscall.Getpriority + ) + const ( + _ int = syscall.PRIO_USER + _ int = syscall.PRIO_PROCESS + _ int = syscall.PRIO_PGRP + ) + + // termios constants + const ( + _ int = syscall.TCIFLUSH + _ int = syscall.TCIOFLUSH + _ int = syscall.TCOFLUSH + ) + + // fcntl file locking structure and constants + var ( + _ = syscall.Flock_t{ + Type: int16(0), + Whence: int16(0), + Start: int64(0), + Len: int64(0), + Pid: int32(0), + } + ) + const ( + _ = syscall.F_GETLK + _ = syscall.F_SETLK + _ = syscall.F_SETLKW + ) +} + +// TestFcntlFlock tests whether the file locking structure matches +// the calling convention of each kernel. +func TestFcntlFlock(t *testing.T) { + name := filepath.Join(os.TempDir(), "TestFcntlFlock") + fd, err := syscall.Open(name, syscall.O_CREAT|syscall.O_RDWR|syscall.O_CLOEXEC, 0) + if err != nil { + t.Fatalf("Open failed: %v", err) + } + defer syscall.Unlink(name) + defer syscall.Close(fd) + flock := syscall.Flock_t{ + Type: syscall.F_RDLCK, + Start: 0, Len: 0, Whence: 1, + } + if err := syscall.FcntlFlock(uintptr(fd), syscall.F_GETLK, &flock); err != nil { + t.Fatalf("FcntlFlock failed: %v", err) + } +} + // TestPassFD tests passing a file descriptor over a Unix socket. // // This test involved both a parent and child process. The parent @@ -27,9 +85,13 @@ import ( // "-test.run=^TestPassFD$" and an environment variable used to signal // that the test should become the child process instead. func TestPassFD(t *testing.T) { - if runtime.GOOS == "dragonfly" { + switch runtime.GOOS { + case "dragonfly": // TODO(jsing): Figure out why sendmsg is returning EINVAL. - t.Skip("Skipping test on dragonfly") + t.Skip("skipping test on dragonfly") + case "solaris": + // TODO(aram): Figure out why ReadMsgUnix is returning empty message. + t.Skip("skipping test on solaris, see issue 7402") } if os.Getenv("GO_WANT_HELPER_PROCESS") == "1" { passFDChild() @@ -204,3 +266,53 @@ func TestUnixRightsRoundtrip(t *testing.T) { } } } + +func TestRlimit(t *testing.T) { + var rlimit, zero syscall.Rlimit + err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rlimit) + if err != nil { + t.Fatalf("Getrlimit: save failed: %v", err) + } + if zero == rlimit { + t.Fatalf("Getrlimit: save failed: got zero value %#v", rlimit) + } + set := rlimit + set.Cur = set.Max - 1 + err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &set) + if err != nil { + t.Fatalf("Setrlimit: set failed: %#v %v", set, err) + } + var get syscall.Rlimit + err = syscall.Getrlimit(syscall.RLIMIT_NOFILE, &get) + if err != nil { + t.Fatalf("Getrlimit: get failed: %v", err) + } + set = rlimit + set.Cur = set.Max - 1 + if set != get { + // Seems like Darwin requires some privilege to + // increase the soft limit of rlimit sandbox, though + // Setrlimit never reports an error. + switch runtime.GOOS { + case "darwin": + default: + t.Fatalf("Rlimit: change failed: wanted %#v got %#v", set, get) + } + } + err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rlimit) + if err != nil { + t.Fatalf("Setrlimit: restore failed: %#v %v", rlimit, err) + } +} + +func TestSeekFailure(t *testing.T) { + _, err := syscall.Seek(-1, 0, 0) + if err == nil { + t.Fatalf("Seek(-1, 0, 0) did not fail") + } + str := err.Error() // used to crash on Linux + t.Logf("Seek: %v", str) + if str == "" { + t.Fatalf("Seek(-1, 0, 0) return error with empty message") + } +} |