Skip to content

Commit

Permalink
always assume copy from stdin
Browse files Browse the repository at this point in the history
  • Loading branch information
csquared committed Sep 15, 2015
1 parent dbcc7cf commit 95cc6ff
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
15 changes: 5 additions & 10 deletions client/processes.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strings"
"time"

"github.com/docker/docker/pkg/term"
"golang.org/x/crypto/ssh/terminal"
)

type Process struct {
Expand Down Expand Up @@ -47,7 +47,7 @@ func (c *Client) RunProcessAttached(app, process, command string, in io.Reader,

ch := make(chan int)

go copyWithExit(out, r, ch, raw)
go copyWithExit(out, r, ch)

err := c.Stream(fmt.Sprintf("/apps/%s/processes/%s/run", app, process), map[string]string{"Command": command}, in, w)

Expand Down Expand Up @@ -87,7 +87,7 @@ func (c *Client) StopProcess(app, id string) (*Process, error) {
return &process, nil
}

func copyWithExit(w io.Writer, r io.Reader, ch chan int, raw bool) {
func copyWithExit(w io.Writer, r io.Reader, ch chan int) {
buf := make([]byte, 1024)
isTerminalRaw := false

Expand All @@ -98,14 +98,9 @@ func copyWithExit(w io.Writer, r io.Reader, ch chan int, raw bool) {
break
}

// don't make the terminal raw until we've read some data
if raw && !isTerminalRaw {
if !isTerminalRaw {
fd := os.Stdin.Fd()
oldState, err := term.SetRawTerminal(fd)
if err != nil {
break
}
defer term.RestoreTerminal(fd, oldState)
terminal.MakeRaw(int(fd))
isTerminalRaw = true
}

Expand Down
7 changes: 7 additions & 0 deletions cmd/convox/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"regexp"
"strings"

"golang.org/x/crypto/ssh/terminal"

"github.com/codegangsta/cli"
"github.com/convox/rack/cmd/convox/stdcli"
)
Expand Down Expand Up @@ -36,6 +38,10 @@ func cmdRun(c *cli.Context) {
return
}

fd := os.Stdin.Fd()
stdinState, err := terminal.GetState(int(fd))
defer terminal.Restore(int(fd), stdinState)

_, app, err := stdcli.DirApp(c, ".")

if err != nil {
Expand All @@ -51,6 +57,7 @@ func cmdRun(c *cli.Context) {
ps := c.Args()[0]

code, err := rackClient(c).RunProcessAttached(app, ps, strings.Join(c.Args()[1:], " "), os.Stdin, os.Stdout, true)
terminal.Restore(int(fd), stdinState)

if err != nil {
stdcli.Error(err)
Expand Down

0 comments on commit 95cc6ff

Please sign in to comment.