From ce41cabd53122dd1cbffb77c0070c92653928529 Mon Sep 17 00:00:00 2001 From: Xiaodong Liu Date: Fri, 29 May 2020 11:48:54 +0800 Subject: [PATCH] solve the undefined: unix.Dup2 compile error on mips64le error in detail: go build ../internal/remote/output_interceptor_unix.go:41:2: undefined: unix.Dup2 ../internal/remote/output_interceptor_unix.go:42:2: undefined: unix.Dup2 there is Dup2 syscall on linux/amd64, linux/mips64le is Dup3 instead. Signed-off-by: Xiaodong Liu --- internal/remote/output_interceptor_darwin.go | 11 +++++++++++ internal/remote/output_interceptor_dragonfly.go | 11 +++++++++++ internal/remote/output_interceptor_freebsd.go | 11 +++++++++++ internal/remote/output_interceptor_linux.go | 12 ++++++++++++ internal/remote/output_interceptor_linux_mips64le.go | 12 ++++++++++++ internal/remote/output_interceptor_netbsd.go | 11 +++++++++++ internal/remote/output_interceptor_openbsd.go | 11 +++++++++++ internal/remote/output_interceptor_solaris.go | 11 +++++++++++ internal/remote/output_interceptor_unix.go | 7 ++----- 9 files changed, 92 insertions(+), 5 deletions(-) create mode 100644 internal/remote/output_interceptor_darwin.go create mode 100644 internal/remote/output_interceptor_dragonfly.go create mode 100644 internal/remote/output_interceptor_freebsd.go create mode 100644 internal/remote/output_interceptor_linux.go create mode 100644 internal/remote/output_interceptor_linux_mips64le.go create mode 100644 internal/remote/output_interceptor_netbsd.go create mode 100644 internal/remote/output_interceptor_openbsd.go create mode 100644 internal/remote/output_interceptor_solaris.go diff --git a/internal/remote/output_interceptor_darwin.go b/internal/remote/output_interceptor_darwin.go new file mode 100644 index 000000000..e3d09eadb --- /dev/null +++ b/internal/remote/output_interceptor_darwin.go @@ -0,0 +1,11 @@ +// +build darwin + +package remote + +import ( + "golang.org/x/sys/unix" +) + +func interceptorDupx(oldfd int, newfd int) { + unix.Dup2(oldfd, newfd) +} diff --git a/internal/remote/output_interceptor_dragonfly.go b/internal/remote/output_interceptor_dragonfly.go new file mode 100644 index 000000000..72d38686a --- /dev/null +++ b/internal/remote/output_interceptor_dragonfly.go @@ -0,0 +1,11 @@ +// +build dragonfly + +package remote + +import ( + "golang.org/x/sys/unix" +) + +func interceptorDupx(oldfd int, newfd int) { + unix.Dup2(oldfd, newfd) +} diff --git a/internal/remote/output_interceptor_freebsd.go b/internal/remote/output_interceptor_freebsd.go new file mode 100644 index 000000000..497d548d9 --- /dev/null +++ b/internal/remote/output_interceptor_freebsd.go @@ -0,0 +1,11 @@ +// +build freebsd + +package remote + +import ( + "golang.org/x/sys/unix" +) + +func interceptorDupx(oldfd int, newfd int) { + unix.Dup2(oldfd, newfd) +} diff --git a/internal/remote/output_interceptor_linux.go b/internal/remote/output_interceptor_linux.go new file mode 100644 index 000000000..29add0d33 --- /dev/null +++ b/internal/remote/output_interceptor_linux.go @@ -0,0 +1,12 @@ +// +build linux +// +build !mips64le + +package remote + +import ( + "golang.org/x/sys/unix" +) + +func interceptorDupx(oldfd int, newfd int) { + unix.Dup2(oldfd, newfd) +} diff --git a/internal/remote/output_interceptor_linux_mips64le.go b/internal/remote/output_interceptor_linux_mips64le.go new file mode 100644 index 000000000..09bd06260 --- /dev/null +++ b/internal/remote/output_interceptor_linux_mips64le.go @@ -0,0 +1,12 @@ +// +build linux +// +build mips64le + +package remote + +import ( + "golang.org/x/sys/unix" +) + +func interceptorDupx(oldfd int, newfd int) { + unix.Dup3(oldfd, newfd, 0) +} diff --git a/internal/remote/output_interceptor_netbsd.go b/internal/remote/output_interceptor_netbsd.go new file mode 100644 index 000000000..16ad6aeb2 --- /dev/null +++ b/internal/remote/output_interceptor_netbsd.go @@ -0,0 +1,11 @@ +// +build netbsd + +package remote + +import ( + "golang.org/x/sys/unix" +) + +func interceptorDupx(oldfd int, newfd int) { + unix.Dup2(oldfd, newfd) +} diff --git a/internal/remote/output_interceptor_openbsd.go b/internal/remote/output_interceptor_openbsd.go new file mode 100644 index 000000000..4275f8421 --- /dev/null +++ b/internal/remote/output_interceptor_openbsd.go @@ -0,0 +1,11 @@ +// +build openbsd + +package remote + +import ( + "golang.org/x/sys/unix" +) + +func interceptorDupx(oldfd int, newfd int) { + unix.Dup2(oldfd, newfd) +} diff --git a/internal/remote/output_interceptor_solaris.go b/internal/remote/output_interceptor_solaris.go new file mode 100644 index 000000000..882a38a9e --- /dev/null +++ b/internal/remote/output_interceptor_solaris.go @@ -0,0 +1,11 @@ +// +build solaris + +package remote + +import ( + "golang.org/x/sys/unix" +) + +func interceptorDupx(oldfd int, newfd int) { + unix.Dup2(oldfd, newfd) +} diff --git a/internal/remote/output_interceptor_unix.go b/internal/remote/output_interceptor_unix.go index 774967db6..80614d0ce 100644 --- a/internal/remote/output_interceptor_unix.go +++ b/internal/remote/output_interceptor_unix.go @@ -8,7 +8,6 @@ import ( "os" "github.com/nxadm/tail" - "golang.org/x/sys/unix" ) func NewOutputInterceptor() OutputInterceptor { @@ -36,10 +35,8 @@ func (interceptor *outputInterceptor) StartInterceptingOutput() error { return err } - // This might call Dup3 if the dup2 syscall is not available, e.g. on - // linux/arm64 or linux/riscv64 - unix.Dup2(int(interceptor.redirectFile.Fd()), 1) - unix.Dup2(int(interceptor.redirectFile.Fd()), 2) + interceptorDupx(int(interceptor.redirectFile.Fd()), 1) + interceptorDupx(int(interceptor.redirectFile.Fd()), 2) if interceptor.streamTarget != nil { interceptor.tailer, _ = tail.TailFile(interceptor.redirectFile.Name(), tail.Config{Follow: true})