From 5252ab697c927d7b51109a1bb1a68d6a3dfc88b3 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Sat, 30 Mar 2013 09:05:53 -0700 Subject: [PATCH] Store the master ptys in order to close them when the process dies (#228) --- container.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/container.go b/container.go index d128ce98dd..7799ff8053 100644 --- a/container.go +++ b/container.go @@ -40,6 +40,10 @@ type Container struct { stdin io.ReadCloser stdinPipe io.WriteCloser + ptyStdinMaster io.Closer + ptyStdoutMaster io.Closer + ptyStderrMaster io.Closer + runtime *Runtime } @@ -151,12 +155,14 @@ func (container *Container) startPty() error { if err != nil { return err } + container.ptyStdoutMaster = stdoutMaster container.cmd.Stdout = stdoutSlave stderrMaster, stderrSlave, err := pty.Open() if err != nil { return err } + container.ptyStderrMaster = stderrMaster container.cmd.Stderr = stderrSlave // Copy the PTYs to our broadcasters @@ -181,6 +187,7 @@ func (container *Container) startPty() error { if err != nil { return err } + container.ptyStdinMaster = stdinMaster container.cmd.Stdin = stdinSlave // FIXME: The following appears to be broken. // "cannot set terminal process group (-1): Inappropriate ioctl for device" @@ -380,6 +387,23 @@ func (container *Container) monitor() { if err := container.stderr.Close(); err != nil { Debugf("%s: Error close stderr: %s", container.Id, err) } + + if container.ptyStdinMaster != nil { + if err := container.ptyStdinMaster.Close(); err != nil { + Debugf("%s: Error close pty stdin master: %s", container.Id, err) + } + } + if container.ptyStdoutMaster != nil { + if err := container.ptyStdoutMaster.Close(); err != nil { + Debugf("%s: Error close pty stdout master: %s", container.Id, err) + } + } + if container.ptyStderrMaster != nil { + if err := container.ptyStderrMaster.Close(); err != nil { + Debugf("%s: Error close pty stderr master: %s", container.Id, err) + } + } + if err := container.Unmount(); err != nil { log.Printf("%v: Failed to umount filesystem: %v", container.Id, err) }