diff --git a/speakeasy_unix.go b/speakeasy_unix.go index d99fda1..353034c 100644 --- a/speakeasy_unix.go +++ b/speakeasy_unix.go @@ -11,12 +11,13 @@ package speakeasy import ( "fmt" "os" + "os/exec" "os/signal" "strings" "syscall" ) -const sttyArg0 = "/bin/stty" +const sttyBin = "stty" var ( sttyArgvEOff = []string{"stty", "-echo"} @@ -64,7 +65,11 @@ func getPassword() (password string, err error) { // echoOff turns off the terminal echo. func echoOff(fd []uintptr) (int, error) { - pid, err := syscall.ForkExec(sttyArg0, sttyArgvEOff, &syscall.ProcAttr{Dir: "", Files: fd}) + path, err := exec.LookPath(sttyBin) + if err != nil { + return 0, fmt.Errorf("%s binary not found:\n\t%s", sttyBin, err) + } + pid, err := syscall.ForkExec(path, sttyArgvEOff, &syscall.ProcAttr{Dir: "", Files: fd}) if err != nil { return 0, fmt.Errorf("failed turning off console echo for password entry:\n\t%s", err) } @@ -74,7 +79,11 @@ func echoOff(fd []uintptr) (int, error) { // echoOn turns back on the terminal echo. func echoOn(fd []uintptr) { // Turn on the terminal echo. - pid, e := syscall.ForkExec(sttyArg0, sttyArgvEOn, &syscall.ProcAttr{Dir: "", Files: fd}) + path, err := exec.LookPath(sttyBin) + if err != nil { + return + } + pid, e := syscall.ForkExec(path, sttyArgvEOn, &syscall.ProcAttr{Dir: "", Files: fd}) if e == nil { syscall.Wait4(pid, nil, 0, nil) }