Skip to content

Commit

Permalink
Fix permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
lixmal committed Nov 1, 2024
1 parent b8e8a7f commit 86868cc
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions client/server/panic_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"syscall"

log "github.com/sirupsen/logrus"

"github.com/netbirdio/netbird/util"
)

const (
Expand All @@ -31,21 +33,24 @@ func handlePanicLog() error {
// Ensure the directory exists
logDir := filepath.Dir(logPath)
if err := os.MkdirAll(logDir, 0750); err != nil {
return fmt.Errorf("create panic log directory: %v", err)
return fmt.Errorf("create panic log directory: %w", err)
}
if err := util.EnforcePermission(logPath); err != nil {
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: %v", err)
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)
}
return fmt.Errorf("redirect stderr: %v", err)
return fmt.Errorf("redirect stderr: %w", err)
}

log.Infof("successfully configured panic logging to: %s", logPath)
Expand All @@ -56,7 +61,7 @@ func handlePanicLog() error {
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: %v", err)
return fmt.Errorf("failed to set stderr handle: %w", err)
}

// Also set os.Stderr for Go's standard library
Expand Down

0 comments on commit 86868cc

Please sign in to comment.