Skip to content

Commit

Permalink
fixed interlock
Browse files Browse the repository at this point in the history
  • Loading branch information
ivcosla committed Aug 8, 2019
1 parent 3a6af1b commit 818a248
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 40 deletions.
34 changes: 0 additions & 34 deletions cmd/therealssh-cli/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"net"
"net/rpc"
"os"
"os/exec"
"os/signal"
"os/user"
"strings"
Expand Down Expand Up @@ -146,36 +145,3 @@ func Execute() {
log.Fatal(err)
}
}

func runInPTY() error {
c := exec.Command("sh")
ptmx, err := pty.Start(c)

// Make sure to close the pty at the end.
defer func() { _ = ptmx.Close() }() // Best effort.

// Handle pty size.
ch := make(chan os.Signal, 1)
signal.Notify(ch, syscall.SIGWINCH)
go func() {
for range ch {
if err := pty.InheritSize(os.Stdin, ptmx); err != nil {
log.Printf("error resizing pty: %s", err)
}
}
}()
ch <- syscall.SIGWINCH // Initial resize.

// Set stdin in raw mode.
oldState, err := terminal.MakeRaw(int(os.Stdin.Fd()))
if err != nil {
panic(err)
}
defer func() { _ = terminal.Restore(int(os.Stdin.Fd()), oldState) }() // Best effort.

// Copy stdin to the pty and the pty to stdout.
go func() { _, _ = io.Copy(ptmx, os.Stdin) }()
_, _ = io.Copy(os.Stdout, ptmx)

return nil
}
7 changes: 6 additions & 1 deletion internal/therealssh/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,12 @@ func (sshCh *SSHChannel) Run(command string) error {
return err
}

_, err = sshCh.Write(out)
go func() {
_, err = sshCh.Write(out)
if err != nil {
log.Warn("error writing to channel: ", err)
}
}()
return err
}

Expand Down
8 changes: 3 additions & 5 deletions internal/therealssh/pty_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,16 @@ func TestRunInPTY(t *testing.T) {
Y: 100,
},
}
res, err := ch.Request(RequestPTY, args.ToBinary())
_, err = ch.Request(RequestPTY, args.ToBinary())
require.NoError(t, err)
fmt.Println(res)

res, err = ch.Request(RequestExecWithoutShell, []byte("ls"))
_, err = ch.Request(RequestExecWithoutShell, []byte("ls"))
require.NoError(t, err)

b := make([]byte,6024)
_, err = ch.Read(b)
require.NoError(t, err)
fmt.Println(res)
fmt.Println("b: ", b)
require.Contains(t, string(b), "pty_test.go")
}

type MockAuthorizer struct {}
Expand Down

0 comments on commit 818a248

Please sign in to comment.