From 078a8e46c232edc732807e61f80ad7672f86f8dd Mon Sep 17 00:00:00 2001 From: Adam Lamar Date: Mon, 14 May 2018 22:45:32 -0600 Subject: [PATCH] Use syscall.Exec() on unix (#3) --- rungo.go | 12 ------------ rungo_unix.go | 10 ++++++++++ rungo_windows.go | 12 ++++++++++++ 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/rungo.go b/rungo.go index 85203aa..9ccdf9e 100644 --- a/rungo.go +++ b/rungo.go @@ -6,24 +6,12 @@ import ( "io" "net/http" "os" - "os/exec" "path/filepath" log "github.com/Sirupsen/logrus" "github.com/pkg/errors" ) -func runGo(binary, baseDir string, args []string) error { - goBinary := filepath.Join(baseDir, "go", "bin", binary) - cmd := exec.Command(goBinary, args...) - cmd.Stdin = os.Stdin - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr - - log.Debugf("Executing %q with arguments %v", goBinary, args) - return cmd.Run() -} - // Get the requested version, either from env variable or go-version file func findVersion() string { envVersion := findEnvVersion() diff --git a/rungo_unix.go b/rungo_unix.go index ece06ef..ab9ae47 100644 --- a/rungo_unix.go +++ b/rungo_unix.go @@ -8,11 +8,21 @@ import ( "io" "os" "path/filepath" + "syscall" log "github.com/Sirupsen/logrus" "github.com/pkg/errors" ) +func runGo(binary, baseDir string, args []string) error { + goBinary := filepath.Join(baseDir, "go", "bin", binary) + binaryWithArgs := append([]string{goBinary}, args...) + + log.Debugf("Executing %q with arguments %v", goBinary, args) + // generally won't return + return syscall.Exec(goBinary, binaryWithArgs, os.Environ()) +} + func extractFile(golangArchive, baseDir string) error { log.Debugf("Extracting %q", golangArchive) err := os.MkdirAll(baseDir, os.ModeDir|0755) diff --git a/rungo_windows.go b/rungo_windows.go index d23a8f1..f8f3a48 100644 --- a/rungo_windows.go +++ b/rungo_windows.go @@ -4,12 +4,24 @@ import ( "archive/zip" "io" "os" + "os/exec" "path/filepath" log "github.com/Sirupsen/logrus" "github.com/pkg/errors" ) +func runGo(binary, baseDir string, args []string) error { + goBinary := filepath.Join(baseDir, "go", "bin", binary) + cmd := exec.Command(goBinary, args...) + cmd.Stdin = os.Stdin + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + + log.Debugf("Executing %q with arguments %v", goBinary, args) + return cmd.Run() +} + func extractFile(golangArchive, baseDir string) error { log.Debugf("Extracting %q", golangArchive) err := os.MkdirAll(baseDir, os.ModeDir|0755)