Skip to content

Commit

Permalink
fix: dfget daemon console log invalid (dragonflyoss#1275)
Browse files Browse the repository at this point in the history
Signed-off-by: Jim Ma <[email protected]>
  • Loading branch information
jim3ma authored Apr 24, 2022
1 parent 7f458f6 commit 44cc065
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions cmd/dfget/cmd/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,15 @@ it supports container engine, wget and other downloading tools through proxy fun
// daemon will be launched by dfget command
// redirect stdout and stderr to file for debugging
func redirectStdoutAndStderr(console bool, logDir string) {
// when console log is enabled, skip redirect stdout
if !console {
stdoutPath := path.Join(logDir, "daemon", "stdout.log")
if stdout, err := os.OpenFile(stdoutPath, os.O_WRONLY|os.O_CREATE|os.O_APPEND|os.O_SYNC, 0644); err != nil {
logger.Warnf("open %s error: %s", stdoutPath, err)
} else if err := syscall.Dup2(int(stdout.Fd()), 1); err != nil {
logger.Warnf("redirect stdout error: %s", err)
}
// when console log is enabled, skip redirect
if console {
return
}
stdoutPath := path.Join(logDir, "daemon", "stdout.log")
if stdout, err := os.OpenFile(stdoutPath, os.O_WRONLY|os.O_CREATE|os.O_APPEND|os.O_SYNC, 0644); err != nil {
logger.Warnf("open %s error: %s", stdoutPath, err)
} else if err := syscall.Dup2(int(stdout.Fd()), 1); err != nil {
logger.Warnf("redirect stdout error: %s", err)
}
stderrPath := path.Join(logDir, "daemon", "stderr.log")
if stderr, err := os.OpenFile(stderrPath, os.O_WRONLY|os.O_CREATE|os.O_APPEND|os.O_SYNC, 0644); err != nil {
Expand Down

0 comments on commit 44cc065

Please sign in to comment.