aboutsummaryrefslogtreecommitdiff
path: root/libgo/misc/cgo/test/setgid_linux.go
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2017-06-27 04:21:40 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2017-06-27 04:21:40 +0000
commit936615752a29ab245708d40782427c25e60a2114 (patch)
treef43366b59cae9e51da40272eefd1ea71bb3ea055 /libgo/misc/cgo/test/setgid_linux.go
parent9913ef5866a64176bac5749080487b0c7d637d4b (diff)
downloadgcc-936615752a29ab245708d40782427c25e60a2114.zip
gcc-936615752a29ab245708d40782427c25e60a2114.tar.gz
gcc-936615752a29ab245708d40782427c25e60a2114.tar.bz2
libgo: add misc/cgo files
Copy all the misc/cgo files from the gc toolchain into libgo/misc. These will be used for testing purposes by later changes to the gotools directory. Reviewed-on: https://go-review.googlesource.com/46721 From-SVN: r249674
Diffstat (limited to 'libgo/misc/cgo/test/setgid_linux.go')
-rw-r--r--libgo/misc/cgo/test/setgid_linux.go49
1 files changed, 49 insertions, 0 deletions
diff --git a/libgo/misc/cgo/test/setgid_linux.go b/libgo/misc/cgo/test/setgid_linux.go
new file mode 100644
index 0000000..6773f94
--- /dev/null
+++ b/libgo/misc/cgo/test/setgid_linux.go
@@ -0,0 +1,49 @@
+// Copyright 2012 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.
+
+// Test that setgid does not hang on GNU/Linux.
+// See https://golang.org/issue/3871 for details.
+
+package cgotest
+
+/*
+#include <sys/types.h>
+#include <unistd.h>
+*/
+import "C"
+
+import (
+ "os"
+ "os/signal"
+ "syscall"
+ "testing"
+ "time"
+)
+
+func runTestSetgid() bool {
+ c := make(chan bool)
+ go func() {
+ C.setgid(0)
+ c <- true
+ }()
+ select {
+ case <-c:
+ return true
+ case <-time.After(5 * time.Second):
+ return false
+ }
+
+}
+
+func testSetgid(t *testing.T) {
+ if !runTestSetgid() {
+ t.Error("setgid hung")
+ }
+
+ // Now try it again after using signal.Notify.
+ signal.Notify(make(chan os.Signal, 1), syscall.SIGINT)
+ if !runTestSetgid() {
+ t.Error("setgid hung after signal.Notify")
+ }
+}