From a6264acfa711e658c6ae914b81f06ecf9c05c51f Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Mon, 25 Mar 2013 18:43:25 -0700 Subject: [PATCH 1/4] Fix termcaps on the linux client Upstream-commit: 922a8648fc5724ad3ff38e2404d70442dc8f2264 Component: engine --- components/engine/container.go | 3 ++ components/engine/term/termios_linux.go | 62 ++++++++++++++++++------- 2 files changed, 49 insertions(+), 16 deletions(-) diff --git a/components/engine/container.go b/components/engine/container.go index 7e7077c123..7693f85a98 100644 --- a/components/engine/container.go +++ b/components/engine/container.go @@ -255,6 +255,9 @@ func (container *Container) Start() error { var err error if container.Config.Tty { + container.cmd.Env = append(container.Config.Env, + "TERM="+os.Getenv("TERM"), + ) err = container.startPty() } else { err = container.start() diff --git a/components/engine/term/termios_linux.go b/components/engine/term/termios_linux.go index 933ef84c4d..f018a58e63 100644 --- a/components/engine/term/termios_linux.go +++ b/components/engine/term/termios_linux.go @@ -1,10 +1,31 @@ package term import ( - "syscall" - "unsafe" + "os" + "syscall" + "unsafe" ) +// #include +// #include +/* +void MakeRaw() { + struct termios t; + + // FIXME: Handle errors? + ioctl(0, TCGETS, &t); + + t.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON); + t.c_oflag &= ~OPOST; + t.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN); + t.c_cflag &= ~(CSIZE | PARENB); + t.c_cflag |= CS8; + + ioctl(0, TCSETS, &t); +} +*/ +import "C" + const ( getTermios = syscall.TCGETS setTermios = syscall.TCSETS @@ -14,19 +35,28 @@ const ( // mode and returns the previous state of the terminal so that it can be // restored. func MakeRaw(fd int) (*State, error) { - var oldState State - if _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), uintptr(getTermios), uintptr(unsafe.Pointer(&oldState.termios)), 0, 0, 0); err != 0 { - return nil, err - } - newState := oldState.termios - newState.Iflag &^= ISTRIP | IXON | IXOFF - newState.Iflag |= ICRNL - newState.Oflag |= ONLCR - newState.Lflag &^= ECHO | ICANON | ISIG - if _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), uintptr(setTermios), uintptr(unsafe.Pointer(&newState)), 0, 0, 0); err != 0 { - return nil, err - } + fd = int(os.Stdin.Fd()) - return &oldState, nil -} \ No newline at end of file + var oldState State + if _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), syscall.TCGETS, uintptr(unsafe.Pointer(&oldState.termios)), 0, 0, 0); err != 0 { + return nil, err + } + C.MakeRaw() + return &oldState, nil + + // FIXME: post on goland issues this: very same as the C function bug non-working + + // newState := oldState.termios + + // newState.Iflag &^= (IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON) + // newState.Oflag &^= OPOST + // newState.Lflag &^= (ECHO | syscall.ECHONL | ICANON | ISIG | IEXTEN) + // newState.Cflag &^= (CSIZE | syscall.PARENB) + // newState.Cflag |= CS8 + + // if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), syscall.TCSETS, uintptr(unsafe.Pointer(&newState))); err != 0 { + // return nil, err + // } + // return &oldState, nil +} From 817a5a63f10670ab5347620e884d8f8f04257761 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Mon, 25 Mar 2013 18:43:25 -0700 Subject: [PATCH 2/4] Fix termcaps on the linux client Upstream-commit: 50bee2f8114ce562d63b08665f7371aa5a568b2c Component: engine --- components/engine/container.go | 3 ++ components/engine/term/termios_linux.go | 62 ++++++++++++++++++------- 2 files changed, 49 insertions(+), 16 deletions(-) diff --git a/components/engine/container.go b/components/engine/container.go index 7e7077c123..7693f85a98 100644 --- a/components/engine/container.go +++ b/components/engine/container.go @@ -255,6 +255,9 @@ func (container *Container) Start() error { var err error if container.Config.Tty { + container.cmd.Env = append(container.Config.Env, + "TERM="+os.Getenv("TERM"), + ) err = container.startPty() } else { err = container.start() diff --git a/components/engine/term/termios_linux.go b/components/engine/term/termios_linux.go index 933ef84c4d..f018a58e63 100644 --- a/components/engine/term/termios_linux.go +++ b/components/engine/term/termios_linux.go @@ -1,10 +1,31 @@ package term import ( - "syscall" - "unsafe" + "os" + "syscall" + "unsafe" ) +// #include +// #include +/* +void MakeRaw() { + struct termios t; + + // FIXME: Handle errors? + ioctl(0, TCGETS, &t); + + t.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON); + t.c_oflag &= ~OPOST; + t.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN); + t.c_cflag &= ~(CSIZE | PARENB); + t.c_cflag |= CS8; + + ioctl(0, TCSETS, &t); +} +*/ +import "C" + const ( getTermios = syscall.TCGETS setTermios = syscall.TCSETS @@ -14,19 +35,28 @@ const ( // mode and returns the previous state of the terminal so that it can be // restored. func MakeRaw(fd int) (*State, error) { - var oldState State - if _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), uintptr(getTermios), uintptr(unsafe.Pointer(&oldState.termios)), 0, 0, 0); err != 0 { - return nil, err - } - newState := oldState.termios - newState.Iflag &^= ISTRIP | IXON | IXOFF - newState.Iflag |= ICRNL - newState.Oflag |= ONLCR - newState.Lflag &^= ECHO | ICANON | ISIG - if _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), uintptr(setTermios), uintptr(unsafe.Pointer(&newState)), 0, 0, 0); err != 0 { - return nil, err - } + fd = int(os.Stdin.Fd()) - return &oldState, nil -} \ No newline at end of file + var oldState State + if _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), syscall.TCGETS, uintptr(unsafe.Pointer(&oldState.termios)), 0, 0, 0); err != 0 { + return nil, err + } + C.MakeRaw() + return &oldState, nil + + // FIXME: post on goland issues this: very same as the C function bug non-working + + // newState := oldState.termios + + // newState.Iflag &^= (IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON) + // newState.Oflag &^= OPOST + // newState.Lflag &^= (ECHO | syscall.ECHONL | ICANON | ISIG | IEXTEN) + // newState.Cflag &^= (CSIZE | syscall.PARENB) + // newState.Cflag |= CS8 + + // if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), syscall.TCSETS, uintptr(unsafe.Pointer(&newState))); err != 0 { + // return nil, err + // } + // return &oldState, nil +} From 06de045b6d6a2f793294a2b1bb2dc01450575874 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Mon, 25 Mar 2013 19:20:18 -0700 Subject: [PATCH 3/4] Force xterm as TERM in tty mode Upstream-commit: c85db1003be5d7cce4c5f94993980acc82db24d3 Component: engine --- components/engine/container.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/engine/container.go b/components/engine/container.go index 7693f85a98..d062262dfe 100644 --- a/components/engine/container.go +++ b/components/engine/container.go @@ -256,7 +256,7 @@ func (container *Container) Start() error { var err error if container.Config.Tty { container.cmd.Env = append(container.Config.Env, - "TERM="+os.Getenv("TERM"), + "TERM=xterm", ) err = container.startPty() } else { From cf76570924b3e39e74d09988096c13e05785c2ca Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Mon, 25 Mar 2013 19:31:20 -0700 Subject: [PATCH 4/4] MakeRaw on given fd instead of 0 Upstream-commit: 41a2954e4e3f00ef969b2b2ff8308ecc0d3bc673 Component: engine --- components/engine/term/termios_linux.go | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/components/engine/term/termios_linux.go b/components/engine/term/termios_linux.go index f018a58e63..09d632c303 100644 --- a/components/engine/term/termios_linux.go +++ b/components/engine/term/termios_linux.go @@ -1,7 +1,6 @@ package term import ( - "os" "syscall" "unsafe" ) @@ -9,11 +8,11 @@ import ( // #include // #include /* -void MakeRaw() { +void MakeRaw(int fd) { struct termios t; // FIXME: Handle errors? - ioctl(0, TCGETS, &t); + ioctl(fd, TCGETS, &t); t.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON); t.c_oflag &= ~OPOST; @@ -21,7 +20,7 @@ void MakeRaw() { t.c_cflag &= ~(CSIZE | PARENB); t.c_cflag |= CS8; - ioctl(0, TCSETS, &t); + ioctl(fd, TCSETS, &t); } */ import "C" @@ -35,14 +34,11 @@ const ( // mode and returns the previous state of the terminal so that it can be // restored. func MakeRaw(fd int) (*State, error) { - - fd = int(os.Stdin.Fd()) - var oldState State if _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), syscall.TCGETS, uintptr(unsafe.Pointer(&oldState.termios)), 0, 0, 0); err != 0 { return nil, err } - C.MakeRaw() + C.MakeRaw(C.int(fd)) return &oldState, nil // FIXME: post on goland issues this: very same as the C function bug non-working