1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-05-04 19:17:37 +08:00
go-cqhttp/global/signal_unix.go
povsister e2cafbd7d6
添加无需额外配置直接打印stack的功能
*unix: kill -USR1 <gocq_pid>
windows: echo dumpstack >\\.\pipe\go-cqhttp-<pid>

stackdump将直接以<exec_name>.<pid>.stacks.<timestamp>.log
的文件名保存在当前工作目录下
2021-06-26 14:33:37 +08:00

35 lines
546 B
Go

//+build !windows
package global
import (
"os"
"os/signal"
"sync"
"syscall"
)
func SetupMainSignalHandler() <-chan struct{} {
mainOnce.Do(func() {
mc := make(chan os.Signal, 2)
closeOnce := sync.Once{}
signal.Notify(mc, os.Interrupt, syscall.SIGTERM, syscall.SIGUSR1)
go func() {
for {
s := <-mc
switch s {
case os.Interrupt, syscall.SIGTERM:
closeOnce.Do(func() {
close(mc)
})
case syscall.SIGUSR1:
dumpStack()
}
}
}()
mainStopCh = make(chan struct{})
})
return mainStopCh
}