2012-07-28 11:40:51 -06:00
|
|
|
// 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.
|
2015-07-10 17:17:11 -06:00
|
|
|
// See https://golang.org/issue/3871 for details.
|
2012-07-28 11:40:51 -06:00
|
|
|
|
|
|
|
package cgotest
|
|
|
|
|
|
|
|
/*
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
*/
|
|
|
|
import "C"
|
|
|
|
|
|
|
|
import (
|
2015-09-04 11:58:42 -06:00
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
"syscall"
|
2012-07-28 11:40:51 -06:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2015-09-04 11:58:42 -06:00
|
|
|
func runTestSetgid() bool {
|
2012-07-28 11:40:51 -06:00
|
|
|
c := make(chan bool)
|
|
|
|
go func() {
|
|
|
|
C.setgid(0)
|
|
|
|
c <- true
|
|
|
|
}()
|
|
|
|
select {
|
|
|
|
case <-c:
|
2015-09-04 11:58:42 -06:00
|
|
|
return true
|
2012-07-28 11:40:51 -06:00
|
|
|
case <-time.After(5 * time.Second):
|
2015-09-04 11:58:42 -06:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func testSetgid(t *testing.T) {
|
|
|
|
if !runTestSetgid() {
|
2012-07-28 11:40:51 -06:00
|
|
|
t.Error("setgid hung")
|
|
|
|
}
|
2015-09-04 11:58:42 -06:00
|
|
|
|
|
|
|
// 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")
|
|
|
|
}
|
2012-07-28 11:40:51 -06:00
|
|
|
}
|