mirror of
https://github.com/jhillyerd/inbucket.git
synced 2025-12-17 17:47:03 +00:00
log: Fix another deadlock.
This commit is contained in:
@@ -3,8 +3,10 @@
|
|||||||
package log
|
package log
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"golang.org/x/sys/unix"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
|
|
||||||
// closeStdin will close stdin on Unix platforms - this is standard practice
|
// closeStdin will close stdin on Unix platforms - this is standard practice
|
||||||
@@ -12,20 +14,19 @@ import (
|
|||||||
func closeStdin() {
|
func closeStdin() {
|
||||||
if err := os.Stdin.Close(); err != nil {
|
if err := os.Stdin.Close(); err != nil {
|
||||||
// Not a fatal error
|
// 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
|
// reassignStdout points stdout/stderr to our logfile on systems that support
|
||||||
// the Dup2 syscall per https://github.com/golang/go/issues/325
|
// the Dup2 syscall per https://github.com/golang/go/issues/325
|
||||||
func reassignStdout() {
|
func reassignStdout() {
|
||||||
Tracef("Unix reassignStdout()")
|
|
||||||
if err := unix.Dup2(int(logf.Fd()), 1); err != nil {
|
if err := unix.Dup2(int(logf.Fd()), 1); err != nil {
|
||||||
// Not considered fatal
|
// 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 {
|
if err := unix.Dup2(int(logf.Fd()), 2); err != nil {
|
||||||
// Not considered fatal
|
// Not considered fatal
|
||||||
Errorf("Failed to re-assign stderr to logfile: %v", err)
|
log.Printf("Failed to re-assign stderr to logfile: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
package log
|
package log
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -16,7 +17,6 @@ func closeStdin() {
|
|||||||
// reassignStdout points stdout/stderr to our logfile on systems that do not
|
// reassignStdout points stdout/stderr to our logfile on systems that do not
|
||||||
// support the Dup2 syscall
|
// support the Dup2 syscall
|
||||||
func reassignStdout() {
|
func reassignStdout() {
|
||||||
Tracef("Windows reassignStdout()")
|
|
||||||
if !stdOutsClosed {
|
if !stdOutsClosed {
|
||||||
// Close std* streams to prevent accidental output, they will be redirected to
|
// Close std* streams to prevent accidental output, they will be redirected to
|
||||||
// our logfile below
|
// our logfile below
|
||||||
@@ -24,11 +24,11 @@ func reassignStdout() {
|
|||||||
// Warning: this will hide panic() output, sorry Windows users
|
// Warning: this will hide panic() output, sorry Windows users
|
||||||
if err := os.Stderr.Close(); err != nil {
|
if err := os.Stderr.Close(); err != nil {
|
||||||
// Not considered fatal
|
// Not considered fatal
|
||||||
Errorf("Failed to close os.Stderr during log setup")
|
log.Printf("Failed to close os.Stderr during log setup")
|
||||||
}
|
}
|
||||||
if err := os.Stdin.Close(); err != nil {
|
if err := os.Stdin.Close(); err != nil {
|
||||||
// Not considered fatal
|
// Not considered fatal
|
||||||
Errorf("Failed to close os.Stdin during log setup")
|
log.Printf("Failed to close os.Stdin during log setup")
|
||||||
}
|
}
|
||||||
os.Stdout = logf
|
os.Stdout = logf
|
||||||
os.Stderr = logf
|
os.Stderr = logf
|
||||||
|
|||||||
Reference in New Issue
Block a user