Commit c49af2cc authored by Ian Lance Taylor's avatar Ian Lance Taylor

misc/cgo/test: add test for issue 3871: cgo setgid hang on GNU/Linux

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/6445049
parent a1f340fa
...@@ -11,6 +11,7 @@ package cgotest ...@@ -11,6 +11,7 @@ package cgotest
#include <stdlib.h> #include <stdlib.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <errno.h> #include <errno.h>
#include <unistd.h>
#define SHIFT(x, y) ((x)<<(y)) #define SHIFT(x, y) ((x)<<(y))
#define KILO SHIFT(1, 10) #define KILO SHIFT(1, 10)
...@@ -57,6 +58,7 @@ import "C" ...@@ -57,6 +58,7 @@ import "C"
import ( import (
"syscall" "syscall"
"testing" "testing"
"time"
"unsafe" "unsafe"
) )
...@@ -124,6 +126,20 @@ func testMultipleAssign(t *testing.T) { ...@@ -124,6 +126,20 @@ func testMultipleAssign(t *testing.T) {
C.free(unsafe.Pointer(p)) 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 ( var (
cuint = (C.uint)(0) cuint = (C.uint)(0)
culong C.ulong culong C.ulong
......
...@@ -27,5 +27,6 @@ func Test1328(t *testing.T) { test1328(t) } ...@@ -27,5 +27,6 @@ func Test1328(t *testing.T) { test1328(t) }
func TestParallelSleep(t *testing.T) { testParallelSleep(t) } func TestParallelSleep(t *testing.T) { testParallelSleep(t) }
func TestSetEnv(t *testing.T) { testSetEnv(t) } func TestSetEnv(t *testing.T) { testSetEnv(t) }
func TestHelpers(t *testing.T) { testHelpers(t) } func TestHelpers(t *testing.T) { testHelpers(t) }
func TestSetgid(t *testing.T) { testSetgid(t) }
func BenchmarkCgoCall(b *testing.B) { benchCgoCall(b) } func BenchmarkCgoCall(b *testing.B) { benchCgoCall(b) }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment