Use Dup2 library function instead of raw syscall

The Dup2 syscall does not exist on 64-bit arm Linux while its
replacement Dup3 does not exist on non-Linux systems.

Using the unix.Dup2 library function instead of raw syscalls
improves the portability across more platforms.
This commit is contained in:
Fredrik Fornwall 2016-09-07 22:21:58 +02:00 committed by Nick Craig-Wood
parent 54fdc6866e
commit 87db3cfad3
1 changed files with 3 additions and 2 deletions

View File

@ -7,12 +7,13 @@ package cmd
import (
"log"
"os"
"syscall"
"golang.org/x/sys/unix"
)
// redirectStderr to the file passed in
func redirectStderr(f *os.File) {
err := syscall.Dup2(int(f.Fd()), int(os.Stderr.Fd()))
err := unix.Dup2(int(f.Fd()), int(os.Stderr.Fd()))
if err != nil {
log.Fatalf("Failed to redirect stderr to file: %v", err)
}