github.com/searKing/golang/go@v1.2.117/os/signal/signal_cgo.go (about)

     1  // Copyright 2020 The searKing Author. 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  //go:build cgo
     6  
     7  package signal
     8  
     9  import "C"
    10  import (
    11  	"os"
    12  
    13  	"github.com/searKing/golang/go/os/signal/cgo"
    14  )
    15  
    16  // SetSig act as signal.Notify, which invokes the Go signal handler.
    17  // https://godoc.org/os/signal#hdr-Go_programs_that_use_cgo_or_SWIG
    18  func setSig(sigs ...os.Signal) {
    19  	for _, sig := range sigs {
    20  		cgo.SetSig(Signum(sig))
    21  	}
    22  }
    23  
    24  // dumpSignalTo redirects log to fd, -1 if not set; muted if < 0.
    25  func dumpSignalTo(fd int) {
    26  	cgo.SetSignalDumpToFd(fd)
    27  }
    28  
    29  // dumpStacktraceTo set dump file path of stacktrace when signal is triggered, nop if not set.
    30  func dumpStacktraceTo(name string) {
    31  	cgo.SetBacktraceDumpToFile(name)
    32  }
    33  
    34  // dumpPreviousStacktrace dumps human readable stacktrace to fd, which is set by SetSignalDumpToFd.
    35  func dumpPreviousStacktrace() {
    36  	cgo.DumpPreviousStacktrace()
    37  }
    38  
    39  // previousStacktrace returns a human readable stacktrace
    40  func previousStacktrace() string {
    41  	return cgo.PreviousStacktrace()
    42  }
    43  
    44  // setSigInvokeChain sets a rule to raise signal to {to} and wait until {wait}, done with sleep {sleepInSeconds}s
    45  func setSigInvokeChain(from, to, wait, sleepInSeconds int) {
    46  	cgo.SetSigInvokeChain(from, to, wait, sleepInSeconds)
    47  }