Source file src/cmd/cgo/internal/testsanitizers/testdata/tsan12.go

     1  // Copyright 2017 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  package main
     6  
     7  // This program hung when run under the C/C++ ThreadSanitizer. TSAN installs a
     8  // libc interceptor that writes signal handlers to a global variable within the
     9  // TSAN runtime instead of making a sigaction system call. A bug in
    10  // syscall.runtime_AfterForkInChild corrupted TSAN's signal forwarding table
    11  // during calls to (*os/exec.Cmd).Run, causing the parent process to fail to
    12  // invoke signal handlers.
    13  
    14  import (
    15  	"fmt"
    16  	"os"
    17  	"os/exec"
    18  	"os/signal"
    19  	"syscall"
    20  )
    21  
    22  import "C"
    23  
    24  func main() {
    25  	ch := make(chan os.Signal, 1)
    26  	signal.Notify(ch, syscall.SIGUSR1)
    27  
    28  	if err := exec.Command("true").Run(); err != nil {
    29  		fmt.Fprintf(os.Stderr, "Unexpected error from `true`: %v", err)
    30  		os.Exit(1)
    31  	}
    32  
    33  	syscall.Kill(syscall.Getpid(), syscall.SIGUSR1)
    34  	<-ch
    35  }
    36  

View as plain text