Skip to content

Commit

Permalink
Fix #22 - search for stty in PATH (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
fiksn authored Sep 10, 2022
1 parent a4057f5 commit 760eaf8
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions speakeasy_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down

0 comments on commit 760eaf8

Please sign in to comment.