term.go 824 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. These types are wrappers around the libcontainer Terminal interface so that
  3. we can resuse the docker implementations where possible.
  4. */
  5. package native
  6. import (
  7. "github.com/dotcloud/docker/daemon/execdriver"
  8. "io"
  9. "os"
  10. "os/exec"
  11. )
  12. type dockerStdTerm struct {
  13. execdriver.StdConsole
  14. pipes *execdriver.Pipes
  15. }
  16. func (d *dockerStdTerm) Attach(cmd *exec.Cmd) error {
  17. return d.AttachPipes(cmd, d.pipes)
  18. }
  19. func (d *dockerStdTerm) SetMaster(master *os.File) {
  20. // do nothing
  21. }
  22. type dockerTtyTerm struct {
  23. execdriver.TtyConsole
  24. pipes *execdriver.Pipes
  25. }
  26. func (t *dockerTtyTerm) Attach(cmd *exec.Cmd) error {
  27. go io.Copy(t.pipes.Stdout, t.MasterPty)
  28. if t.pipes.Stdin != nil {
  29. go io.Copy(t.MasterPty, t.pipes.Stdin)
  30. }
  31. return nil
  32. }
  33. func (t *dockerTtyTerm) SetMaster(master *os.File) {
  34. t.MasterPty = master
  35. }