1
0
mirror of https://github.com/jhillyerd/inbucket.git synced 2025-12-19 02:27:03 +00:00

log: Fix another deadlock.

This commit is contained in:
James Hillyerd
2018-03-25 16:08:34 -07:00
parent 86c8ccf9ea
commit 2d09e94f87
2 changed files with 9 additions and 8 deletions

View File

@@ -3,8 +3,10 @@
package log
import (
"golang.org/x/sys/unix"
"log"
"os"
"golang.org/x/sys/unix"
)
// closeStdin will close stdin on Unix platforms - this is standard practice
@@ -12,20 +14,19 @@ import (
func closeStdin() {
if err := os.Stdin.Close(); err != nil {
// Not a fatal error
Errorf("Failed to close os.Stdin during log setup")
log.Printf("Failed to close os.Stdin during log setup")
}
}
// reassignStdout points stdout/stderr to our logfile on systems that support
// the Dup2 syscall per https://github.com/golang/go/issues/325
func reassignStdout() {
Tracef("Unix reassignStdout()")
if err := unix.Dup2(int(logf.Fd()), 1); err != nil {
// Not considered fatal
Errorf("Failed to re-assign stdout to logfile: %v", err)
log.Printf("Failed to re-assign stdout to logfile: %v", err)
}
if err := unix.Dup2(int(logf.Fd()), 2); err != nil {
// Not considered fatal
Errorf("Failed to re-assign stderr to logfile: %v", err)
log.Printf("Failed to re-assign stderr to logfile: %v", err)
}
}