Store the master ptys in order to close them when the process dies (#228)

This commit is contained in:
Guillaume J. Charmes 2013-03-30 09:05:53 -07:00
Родитель 41555f67e0
Коммит 5252ab697c
1 изменённых файлов: 24 добавлений и 0 удалений

Просмотреть файл

@ -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)
}