Skip to content
This repository has been archived by the owner on Aug 29, 2020. It is now read-only.

Commit

Permalink
Fix stderr redirection on arm64
Browse files Browse the repository at this point in the history
  • Loading branch information
cjbassi committed Dec 13, 2018
1 parent e81b4c1 commit c1e7986
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
7 changes: 4 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand All @@ -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)
}
Expand All @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions src/logging/logging_arm64.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package logging

import (
"os"
"syscall"
)

func StderrToLogfile(lf *os.File) {
syscall.Dup3(int(lf.Fd()), 2, 0)
}
12 changes: 12 additions & 0 deletions src/logging/logging_other.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// +build !arm64

package logging

import (
"os"
"syscall"
)

func StderrToLogfile(lf *os.File) {
syscall.Dup2(int(lf.Fd()), 2)
}

0 comments on commit c1e7986

Please sign in to comment.