...

Source file src/cmd/cgo/internal/test/setgid2_linux.go

Documentation: cmd/cgo/internal/test

     1  // Copyright 2022 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  
     5  // Stress test setgid and thread creation. A thread
     6  // can get a SIGSETXID signal early on at thread
     7  // initialization, causing crash. See issue 53374.
     8  
     9  package cgotest
    10  
    11  /*
    12  #include <sys/types.h>
    13  #include <unistd.h>
    14  */
    15  import "C"
    16  
    17  import (
    18  	"runtime"
    19  	"testing"
    20  )
    21  
    22  func testSetgidStress(t *testing.T) {
    23  	const N = 50
    24  	ch := make(chan int, N)
    25  	for i := 0; i < N; i++ {
    26  		go func() {
    27  			C.setgid(0)
    28  			ch <- 1
    29  			runtime.LockOSThread() // so every goroutine uses a new thread
    30  		}()
    31  	}
    32  	for i := 0; i < N; i++ {
    33  		<-ch
    34  	}
    35  }
    36  

View as plain text