diff --git a/client/server/panic_windows.go b/client/server/panic_windows.go index 1d4ba4b75..c5e73be7c 100644 --- a/client/server/panic_windows.go +++ b/client/server/panic_windows.go @@ -3,7 +3,7 @@ package server import ( "fmt" "os" - "path/filepath" + "path" "syscall" log "github.com/sirupsen/logrus" @@ -12,7 +12,6 @@ import ( ) const ( - windowsPanicLogEnvVar = "NB_WINDOWS_PANIC_LOG" // STD_ERROR_HANDLE ((DWORD)-12) = 4294967284 stdErrorHandle = ^uintptr(11) ) @@ -25,13 +24,10 @@ var ( ) func handlePanicLog() error { - logPath := os.Getenv(windowsPanicLogEnvVar) - if logPath == "" { - return nil - } + // TODO: move this to a central location + logDir := path.Join(os.Getenv("PROGRAMDATA"), "Netbird") + logPath := path.Join(logDir, "netbird.err") - // Ensure the directory exists - logDir := filepath.Dir(logPath) if err := os.MkdirAll(logDir, 0750); err != nil { return fmt.Errorf("create panic log directory: %w", err) } @@ -39,13 +35,11 @@ func handlePanicLog() error { return fmt.Errorf("enforce permission on panic log file: %w", err) } - // Open log file with append mode f, err := os.OpenFile(logPath, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644) if err != nil { return fmt.Errorf("open panic log file: %w", err) } - // Redirect stderr to the file if err = redirectStderr(f); err != nil { if closeErr := f.Close(); closeErr != nil { log.Warnf("failed to close file after redirect error: %v", closeErr) @@ -59,7 +53,6 @@ func handlePanicLog() error { // redirectStderr redirects stderr to the provided file func redirectStderr(f *os.File) error { - // Get the current process's stderr handle if err := setStdHandle(f); err != nil { return fmt.Errorf("failed to set stderr handle: %w", err) }