setgid_linux.go 843 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright 2012 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. // Test that setgid does not hang on Linux.
  5. // See https://golang.org/issue/3871 for details.
  6. package cgotest
  7. /*
  8. #include <sys/types.h>
  9. #include <unistd.h>
  10. */
  11. import "C"
  12. import (
  13. "os"
  14. "os/signal"
  15. "syscall"
  16. "testing"
  17. "time"
  18. )
  19. func runTestSetgid() bool {
  20. c := make(chan bool)
  21. go func() {
  22. C.setgid(0)
  23. c <- true
  24. }()
  25. select {
  26. case <-c:
  27. return true
  28. case <-time.After(5 * time.Second):
  29. return false
  30. }
  31. }
  32. func testSetgid(t *testing.T) {
  33. if !runTestSetgid() {
  34. t.Error("setgid hung")
  35. }
  36. // Now try it again after using signal.Notify.
  37. signal.Notify(make(chan os.Signal, 1), syscall.SIGINT)
  38. if !runTestSetgid() {
  39. t.Error("setgid hung after signal.Notify")
  40. }
  41. }