Fix stderr redirection on arm64

This commit is contained in:
Caleb Bassi 2018-12-12 18:18:43 -08:00
parent e81b4c14c0
commit c1e7986ed0
3 changed files with 26 additions and 3 deletions

View File

@ -15,6 +15,7 @@ import (
"time"
"github.com/cjbassi/gotop/colorschemes"
"github.com/cjbassi/gotop/src/logging"
w "github.com/cjbassi/gotop/src/widgets"
ui "github.com/cjbassi/termui"
"github.com/docopt/docopt-go"
@ -349,7 +350,7 @@ func eventLoop() {
}
}
func logging() (*os.File, error) {
func setupLogging() (*os.File, error) {
// make the config directory
if err := os.MkdirAll(configDir, 0755); err != nil {
return nil, fmt.Errorf("failed to make the configuration directory: %v", err)
@ -369,7 +370,7 @@ func logging() (*os.File, error) {
}
func main() {
lf, err := logging()
lf, err := setupLogging()
if err != nil {
stderrLogger.Fatalf("failed to setup logging: %v", err)
}
@ -389,7 +390,7 @@ func main() {
}
defer ui.Close()
syscall.Dup2(int(lf.Fd()), 2) // redirect stderr to logfile
logging.StderrToLogfile(lf)
setupGrid()
ui.Render(ui.Body)

View File

@ -0,0 +1,10 @@
package logging
import (
"os"
"syscall"
)
func StderrToLogfile(lf *os.File) {
syscall.Dup3(int(lf.Fd()), 2, 0)
}

View File

@ -0,0 +1,12 @@
// +build !arm64
package logging
import (
"os"
"syscall"
)
func StderrToLogfile(lf *os.File) {
syscall.Dup2(int(lf.Fd()), 2)
}