diff --git a/common/debug/log_panic.go b/common/debug/log_panic.go index f1d361d03..eec6e2b07 100644 --- a/common/debug/log_panic.go +++ b/common/debug/log_panic.go @@ -13,6 +13,7 @@ import ( ) var sigc chan os.Signal +var crashReportDir string func GetSigC(sig *chan os.Signal) { sigc = *sig @@ -23,22 +24,22 @@ func prettyTime() string { return strings.Replace(time[:19], " ", "-", 1) } -func CheckForCrashes() { - ex, err := os.Executable() - if err != nil { - log.Warn(err.Error()) +func CheckForCrashes(datadir string) { + crashReportDir = filepath.Join(datadir, "crashreports") + if _, err := os.Stat(crashReportDir); os.IsNotExist(err) { + os.Mkdir(crashReportDir, 0755) + } else if err != nil { + log.Error("log_panig.go: CheckForCrashes", "error", err) return } - binPath := filepath.Dir(ex) - crashReportDir := filepath.Join(binPath[:len(binPath)-10], "crashreports") f, err := os.Open(crashReportDir) if err != nil { - log.Error(err.Error()) + log.Error("log_panig.go: CheckForCrashes", "error", err) return } fileInfo, err := f.ReadDir(-1) if err != nil { - log.Error(err.Error()) + log.Error("log_panig.go: CheckForCrashes", "error", err) return } for _, v := range fileInfo { @@ -46,6 +47,7 @@ func CheckForCrashes() { msg := fmt.Sprintf("Crashes From Previous Boots Detected. Find the stack trace in %v", crashReportDir) log.Warn(msg) + f.Close() return } } @@ -71,16 +73,10 @@ func LogPanic(err error, stopErigon bool, panicResult interface{}) error { } func WriteStackTraceOnPanic(stack string) { - ex, err := os.Executable() - if err != nil { - log.Warn(err.Error()) - return - } - binPath := filepath.Dir(ex) - fileName := filepath.Join(binPath[:len(binPath)-10], "crashreports", prettyTime()+".txt") + fileName := filepath.Join(crashReportDir, prettyTime()+".txt") f, errFs := os.OpenFile(fileName, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644) if errFs != nil { - log.Error(errFs.Error()) + log.Error("log_panic.go:WriteStackTraceOnPanic", "error", errFs) f.Close() return } diff --git a/crashreports/.hold b/crashreports/.hold new file mode 100644 index 000000000..e69de29bb diff --git a/node/node.go b/node/node.go index 565337c02..d0f842dd4 100644 --- a/node/node.go +++ b/node/node.go @@ -123,7 +123,7 @@ func New(conf *Config) (*Node, error) { node.ipc = newIPCServer(node.log, conf.IPCEndpoint()) // Check for uncaught crashes from the previous boot and notify the user if // there are any - debug.CheckForCrashes() + debug.CheckForCrashes(conf.DataDir) return node, nil }