Skip to content

Commit

Permalink
Merge b08f1ba into b6a3797
Browse files Browse the repository at this point in the history
  • Loading branch information
jdef committed Sep 15, 2017
2 parents b6a3797 + b08f1ba commit 7148caa
Show file tree
Hide file tree
Showing 29 changed files with 18,946 additions and 7,163 deletions.
9 changes: 9 additions & 0 deletions api/v1/cmd/msh/msh.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package main
//

import (
"bytes"
"context"
"flag"
"fmt"
Expand Down Expand Up @@ -342,6 +343,7 @@ func tryInteractive(agentHost string, cid mesos.ContainerID) (err error) {

go func() {
<-ctx.Done()
//println("closing ttyd via ctx.Done")
ttyd.Close()
}()

Expand Down Expand Up @@ -396,11 +398,18 @@ func attachContainerInput(ctx context.Context, stdin io.Reader, winCh <-chan mes
input := make(chan []byte)
go func() {
defer close(input)
escape := []byte{0x10, 0x11} // CTRL-P, CTRL-Q
var last byte
for {
buf := make([]byte, 512) // not efficient to always do this
n, err := stdin.Read(buf)
if n > 0 {
if (last == escape[0] && buf[0] == escape[1]) || bytes.Index(buf, escape) > -1 {
//println("escape sequence detected")
return
}
buf = buf[:n]
last = buf[n-1]
select {
case input <- buf:
case <-ctx.Done():
Expand Down
24 changes: 17 additions & 7 deletions api/v1/cmd/msh/tty.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func ttyWinch(tty *ttyDevice) {
Columns: uint32(tty.original_winsize.ws_col),
}
go func() {
defer signal.Ignore(os.Signal(syscall.SIGWINCH))
defer signal.Reset(os.Signal(syscall.SIGWINCH))
for {
select {
case <-c:
Expand Down Expand Up @@ -195,13 +195,23 @@ func ttyWinch(tty *ttyDevice) {
}

func ttyTermReset(tty *ttyDevice) {
// cleanup properly upon SIGTERM
term := make(chan os.Signal, 1)
var (
// cleanup properly upon SIGTERM
term = make(chan os.Signal, 1)
done = make(chan struct{})
)
go func() {
<-term
tty.cleanups.unwind()
os.Exit(0)
select {
case <-term:
tty.cleanups.unwind()
os.Exit(0)
case <-done:
//println("stop waiting for SIGTERM")
}
}()
tty.cleanups.push(func() { signal.Ignore(os.Signal(syscall.SIGTERM)) })
tty.cleanups.push(func() {
signal.Reset(os.Signal(syscall.SIGTERM))
close(done) // stop waiting for a signal
})
signal.Notify(term, os.Signal(syscall.SIGTERM))
}

0 comments on commit 7148caa

Please sign in to comment.