Print stacktrace in SIGINT handler if RESTIC_DEBUG_STACKTRACE_SIGINT set
The builtin mechanism to capture a stacktrace in Go is to send a SIGQUIT to the running process. However, this mechanism is not avaiable on Windows. Thus, tweak the SIGINT handler to dump a stacktrace if the environment variable `RESTIC_DEBUG_STACKTRACE_SIGINT` is set.
This commit is contained in:
parent
41cc320145
commit
306a29980a
3 changed files with 31 additions and 0 deletions
15
internal/debug/stacktrace.go
Normal file
15
internal/debug/stacktrace.go
Normal file
|
@ -0,0 +1,15 @@
|
|||
package debug
|
||||
|
||||
import "runtime"
|
||||
|
||||
func DumpStacktrace() string {
|
||||
buf := make([]byte, 128*1024)
|
||||
|
||||
for {
|
||||
l := runtime.Stack(buf, true)
|
||||
if l < len(buf) {
|
||||
return string(buf[:l])
|
||||
}
|
||||
buf = make([]byte, len(buf)*2)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue