]> Cypherpunks repositories - gostls13.git/commitdiff
misc/cgo/test: add test for issue 3871: cgo setgid hang on GNU/Linux
authorIan Lance Taylor <iant@golang.org>
Fri, 27 Jul 2012 06:21:41 +0000 (23:21 -0700)
committerIan Lance Taylor <iant@golang.org>
Fri, 27 Jul 2012 06:21:41 +0000 (23:21 -0700)
R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/6445049

misc/cgo/test/basic.go
misc/cgo/test/cgo_test.go

index 70ec5e43ace398aefd9cf9c923e3bd17adb60702..c0f636289a79854d4abd98568e5a845052c01efb 100644 (file)
@@ -11,6 +11,7 @@ package cgotest
 #include <stdlib.h>
 #include <sys/stat.h>
 #include <errno.h>
+#include <unistd.h>
 
 #define SHIFT(x, y)  ((x)<<(y))
 #define KILO SHIFT(1, 10)
@@ -57,6 +58,7 @@ import "C"
 import (
        "syscall"
        "testing"
+       "time"
        "unsafe"
 )
 
@@ -124,6 +126,20 @@ func testMultipleAssign(t *testing.T) {
        C.free(unsafe.Pointer(p))
 }
 
+func testSetgid(t *testing.T) {
+       // Issue 3871.
+       c := make(chan bool)
+       go func() {
+               C.setgid(0)
+               c <- true
+       }()
+       select {
+       case <-c:
+       case <-time.After(5 * time.Second):
+               t.Error("setgid hung")
+       }
+}
+
 var (
        cuint  = (C.uint)(0)
        culong C.ulong
index 34beee69d194d4d387ca738acd6cf041c852fa03..43d32da58594c25c4f5239f0fca88357b4f91396 100644 (file)
@@ -27,5 +27,6 @@ func Test1328(t *testing.T)                { test1328(t) }
 func TestParallelSleep(t *testing.T)       { testParallelSleep(t) }
 func TestSetEnv(t *testing.T)              { testSetEnv(t) }
 func TestHelpers(t *testing.T)             { testHelpers(t) }
+func TestSetgid(t *testing.T)              { testSetgid(t) }
 
 func BenchmarkCgoCall(b *testing.B) { benchCgoCall(b) }