2014-05-05 19:48:56 -04:00
|
|
|
package daemon
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
|
2015-05-05 16:25:05 -04:00
|
|
|
"github.com/docker/docker/pkg/stdcopy"
|
2014-05-05 19:48:56 -04:00
|
|
|
)
|
|
|
|
|
2015-05-05 16:25:05 -04:00
|
|
|
type ContainerAttachWithLogsConfig struct {
|
|
|
|
InStream io.ReadCloser
|
|
|
|
OutStream io.Writer
|
|
|
|
UseStdin, UseStdout, UseStderr bool
|
|
|
|
Logs, Stream bool
|
|
|
|
Multiplex bool
|
2014-07-30 04:16:23 -04:00
|
|
|
}
|
|
|
|
|
2015-05-05 16:25:05 -04:00
|
|
|
func (daemon *Daemon) ContainerAttachWithLogs(name string, c *ContainerAttachWithLogsConfig) error {
|
|
|
|
container, err := daemon.Get(name)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2014-05-05 19:48:56 -04:00
|
|
|
}
|
2014-12-04 16:12:29 -05:00
|
|
|
|
2015-05-05 16:25:05 -04:00
|
|
|
var errStream io.Writer
|
2014-12-04 16:12:29 -05:00
|
|
|
|
2015-05-05 16:25:05 -04:00
|
|
|
if !container.Config.Tty && c.Multiplex {
|
|
|
|
errStream = stdcopy.NewStdWriter(c.OutStream, stdcopy.Stderr)
|
|
|
|
c.OutStream = stdcopy.NewStdWriter(c.OutStream, stdcopy.Stdout)
|
|
|
|
} else {
|
|
|
|
errStream = c.OutStream
|
2014-12-04 16:12:29 -05:00
|
|
|
}
|
|
|
|
|
2015-05-05 16:25:05 -04:00
|
|
|
var stdin io.ReadCloser
|
|
|
|
var stdout, stderr io.Writer
|
2015-01-05 20:30:38 -05:00
|
|
|
|
2015-05-05 16:25:05 -04:00
|
|
|
if c.UseStdin {
|
|
|
|
stdin = c.InStream
|
|
|
|
}
|
|
|
|
if c.UseStdout {
|
|
|
|
stdout = c.OutStream
|
|
|
|
}
|
|
|
|
if c.UseStderr {
|
|
|
|
stderr = errStream
|
2014-12-04 16:12:29 -05:00
|
|
|
}
|
|
|
|
|
2015-05-05 16:25:05 -04:00
|
|
|
return container.AttachWithLogs(stdin, stdout, stderr, c.Logs, c.Stream)
|
|
|
|
}
|
2014-12-04 16:12:29 -05:00
|
|
|
|
2015-05-05 16:25:05 -04:00
|
|
|
type ContainerWsAttachWithLogsConfig struct {
|
|
|
|
InStream io.ReadCloser
|
|
|
|
OutStream, ErrStream io.Writer
|
|
|
|
Logs, Stream bool
|
2014-05-05 19:48:56 -04:00
|
|
|
}
|
2015-03-29 17:17:23 -04:00
|
|
|
|
2015-05-05 16:25:05 -04:00
|
|
|
func (daemon *Daemon) ContainerWsAttachWithLogs(name string, c *ContainerWsAttachWithLogsConfig) error {
|
|
|
|
container, err := daemon.Get(name)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2015-03-29 17:17:23 -04:00
|
|
|
}
|
2015-05-05 16:25:05 -04:00
|
|
|
|
|
|
|
return container.AttachWithLogs(c.InStream, c.OutStream, c.ErrStream, c.Logs, c.Stream)
|
2015-03-29 17:17:23 -04:00
|
|
|
}
|