From 658926bd0fa8e15c75c4db1426f2b20307312870 Mon Sep 17 00:00:00 2001
From: Camber Huang <camber@poi.science>
Date: Mon, 9 May 2022 14:04:06 +0800
Subject: [PATCH] Fix build failure on riscv64 caused by missing syscall

On RISC-V 64-bit linux systems, syscall `dup2()` is not available, therefore
syscall.Dup2 will be undefined and gotop will fail to be built from soure.
This patch updates building target of logging/logging_{other,arm64} and
renames them based on syscall used.
---
 logging/{logging_other.go => logging_dup2.go} | 2 +-
 logging/{logging_arm64.go => logging_dup3.go} | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
 rename logging/{logging_other.go => logging_dup2.go} (67%)
 rename logging/{logging_arm64.go => logging_dup3.go} (73%)

--- a/logging/logging_other.go
+++ /dev/null
@@ -1,12 +0,0 @@
-// +build linux,!arm64 openbsd,!arm64 freebsd darwin
-
-package logging
-
-import (
-	"os"
-	"syscall"
-)
-
-func stderrToLogfile(logfile *os.File) {
-	syscall.Dup2(int(logfile.Fd()), 2)
-}
--- /dev/null
+++ b/logging/logging_dup2.go
@@ -0,0 +1,12 @@
+// +build linux,!arm64,!riscv64 openbsd,!arm64 freebsd darwin
+
+package logging
+
+import (
+	"os"
+	"syscall"
+)
+
+func stderrToLogfile(logfile *os.File) {
+	syscall.Dup2(int(logfile.Fd()), 2)
+}
--- a/logging/logging_arm64.go
+++ /dev/null
@@ -1,12 +0,0 @@
-// +build !freebsd,!darwin,arm64
-
-package logging
-
-import (
-	"os"
-	"syscall"
-)
-
-func stderrToLogfile(logfile *os.File) {
-	syscall.Dup3(int(logfile.Fd()), 2, 0)
-}
--- /dev/null
+++ b/logging/logging_dup3.go
@@ -0,0 +1,12 @@
+// +build !freebsd,!darwin,arm64 linux,riscv64
+
+package logging
+
+import (
+	"os"
+	"syscall"
+)
+
+func stderrToLogfile(logfile *os.File) {
+	syscall.Dup3(int(logfile.Fd()), 2, 0)
+}
