From fb39460944229839245f7fad35705dceaa054f99 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Fri, 29 Nov 2013 07:40:44 -0800 Subject: [PATCH] Add a GetPtyMaster() method to container to retrieve the pty from an other package. We could also have put ptyMaster public, but then we need to ignore it in json otherwise the Marshalling fails. I think it is cleaner that way. Upstream-commit: fbebe20bc69648c046e3818ca744ae246092a782 Component: engine --- components/engine/container.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/components/engine/container.go b/components/engine/container.go index 49cb33b536..3e5f8a8d74 100644 --- a/components/engine/container.go +++ b/components/engine/container.go @@ -24,6 +24,11 @@ import ( "time" ) +var ( + ErrNotATTY = errors.New("The PTY is not a file") + ErrNoTTY = errors.New("No PTY found") +) + type Container struct { sync.Mutex root string // Path to the "home" of the container, including metadata. @@ -1405,3 +1410,13 @@ func (container *Container) Exposes(p Port) bool { _, exists := container.Config.ExposedPorts[p] return exists } + +func (container *Container) GetPtyMaster() (*os.File, error) { + if container.ptyMaster == nil { + return nil, ErrNoTTY + } + if pty, ok := container.ptyMaster.(*os.File); ok { + return pty, nil + } + return nil, ErrNotATTY +}