fix: dfget daemon console log invalid (#1275)

Signed-off-by: Jim Ma <majinjing3@gmail.com>
This commit is contained in:
Jim Ma 2022-04-24 11:59:49 +08:00 committed by Gaius
parent 7acb092706
commit 8fdf52cdc5
No known key found for this signature in database
GPG Key ID: 8B4E5D1290FA2FFB
1 changed files with 9 additions and 8 deletions

View File

@ -85,15 +85,16 @@ it supports container engine, wget and other downloading tools through proxy fun
// daemon will be launched by dfget command // daemon will be launched by dfget command
// redirect stdout and stderr to file for debugging // redirect stdout and stderr to file for debugging
func redirectStdoutAndStderr(console bool, logDir string) { func redirectStdoutAndStderr(console bool, logDir string) {
// when console log is enabled, skip redirect stdout // when console log is enabled, skip redirect
if !console { if console {
return
}
stdoutPath := path.Join(logDir, "daemon", "stdout.log") 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 { 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) logger.Warnf("open %s error: %s", stdoutPath, err)
} else if err := syscall.Dup2(int(stdout.Fd()), 1); err != nil { } else if err := syscall.Dup2(int(stdout.Fd()), 1); err != nil {
logger.Warnf("redirect stdout error: %s", err) logger.Warnf("redirect stdout error: %s", err)
} }
}
stderrPath := path.Join(logDir, "daemon", "stderr.log") 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 { if stderr, err := os.OpenFile(stderrPath, os.O_WRONLY|os.O_CREATE|os.O_APPEND|os.O_SYNC, 0644); err != nil {
logger.Warnf("open %s error: %s", stderrPath, err) logger.Warnf("open %s error: %s", stderrPath, err)