2022-05-17 07:46:53 +00:00
|
|
|
//go:build windows
|
2021-09-11 11:16:39 +00:00
|
|
|
|
|
|
|
package debug
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
|
|
|
|
_debug "github.com/ledgerwatch/erigon/common/debug"
|
|
|
|
"github.com/ledgerwatch/log/v3"
|
|
|
|
)
|
|
|
|
|
2023-07-10 10:37:55 +00:00
|
|
|
func ListenSignals(stack io.Closer, logger log.Logger) {
|
2021-09-11 11:16:39 +00:00
|
|
|
sigc := make(chan os.Signal, 1)
|
2021-10-04 00:28:31 +00:00
|
|
|
signal.Notify(sigc, os.Interrupt)
|
2021-09-11 11:16:39 +00:00
|
|
|
_debug.GetSigC(&sigc)
|
|
|
|
defer signal.Stop(sigc)
|
|
|
|
|
|
|
|
<-sigc
|
2023-07-10 10:37:55 +00:00
|
|
|
logger.Info("Got interrupt, shutting down...")
|
2021-09-11 11:16:39 +00:00
|
|
|
if stack != nil {
|
|
|
|
go stack.Close()
|
|
|
|
}
|
|
|
|
for i := 10; i > 0; i-- {
|
|
|
|
<-sigc
|
|
|
|
if i > 1 {
|
2023-07-10 10:37:55 +00:00
|
|
|
logger.Warn("Already shutting down, interrupt more to panic.", "times", i-1)
|
2021-09-11 11:16:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Exit() // ensure trace and CPU profile data is flushed.
|
|
|
|
LoudPanic("boom")
|
|
|
|
}
|