24 lines
460 B
Go
24 lines
460 B
Go
|
|
//go:build linux
|
||
|
|
|
||
|
|
package main
|
||
|
|
|
||
|
|
import (
|
||
|
|
"os"
|
||
|
|
"syscall"
|
||
|
|
)
|
||
|
|
|
||
|
|
func redirectStderr(f *os.File) {
|
||
|
|
if f == nil {
|
||
|
|
// Silence altogether if no debug file
|
||
|
|
null, err := os.OpenFile(os.DevNull, os.O_WRONLY, 0)
|
||
|
|
if err == nil {
|
||
|
|
syscall.Dup2(int(null.Fd()), int(os.Stderr.Fd()))
|
||
|
|
}
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
// Redirect fd 2 (stderr) to our debug file
|
||
|
|
// This captures C-level library noise (ALSA, PortAudio) into the log
|
||
|
|
syscall.Dup2(int(f.Fd()), int(os.Stderr.Fd()))
|
||
|
|
}
|