summaryrefslogtreecommitdiff
path: root/runtime/execdriver/native/term.go
blob: 0d5298d3887479b949291e1a15534dc0070ad147 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
   These types are wrappers around the libcontainer Terminal interface so that
   we can resuse the docker implementations where possible.
*/
package native

import (
	"github.com/dotcloud/docker/runtime/execdriver"
	"io"
	"os"
	"os/exec"
)

type dockerStdTerm struct {
	execdriver.StdConsole
	pipes *execdriver.Pipes
}

func (d *dockerStdTerm) Attach(cmd *exec.Cmd) error {
	return d.AttachPipes(cmd, d.pipes)
}

func (d *dockerStdTerm) SetMaster(master *os.File) {
	// do nothing
}

type dockerTtyTerm struct {
	execdriver.TtyConsole
	pipes *execdriver.Pipes
}

func (t *dockerTtyTerm) Attach(cmd *exec.Cmd) error {
	go io.Copy(t.pipes.Stdout, t.MasterPty)
	if t.pipes.Stdin != nil {
		go io.Copy(t.MasterPty, t.pipes.Stdin)
	}
	return nil
}

func (t *dockerTtyTerm) SetMaster(master *os.File) {
	t.MasterPty = master
}