Rename 'StdConfig' to 'StreamConfig'.

Docker-DCO-1.1-Signed-off-by: Vishnu Kannan <vishnuk@google.com> (github: vishh)
This commit is contained in:
Vishnu Kannan 2014-08-26 22:44:00 +00:00 committed by Michael Crosby
parent 4aa5da278f
commit 3a7e07355a
12 changed files with 61 additions and 67 deletions

View File

@ -127,7 +127,7 @@ func (daemon *Daemon) Attach(container *Container, stdin io.ReadCloser, stdinClo
if stdin != nil && container.Config.OpenStdin { if stdin != nil && container.Config.OpenStdin {
nJobs++ nJobs++
if cStdin, err := container.StdConfig.StdinPipe(); err != nil { if cStdin, err := container.StdinPipe(); err != nil {
errors <- err errors <- err
} else { } else {
go func() { go func() {
@ -163,7 +163,7 @@ func (daemon *Daemon) Attach(container *Container, stdin io.ReadCloser, stdinClo
} }
if stdout != nil { if stdout != nil {
nJobs++ nJobs++
if p, err := container.StdConfig.StdoutPipe(); err != nil { if p, err := container.StdoutPipe(); err != nil {
errors <- err errors <- err
} else { } else {
cStdout = p cStdout = p
@ -192,7 +192,7 @@ func (daemon *Daemon) Attach(container *Container, stdin io.ReadCloser, stdinClo
if stdinCloser != nil { if stdinCloser != nil {
defer stdinCloser.Close() defer stdinCloser.Close()
} }
if cStdout, err := container.StdConfig.StdoutPipe(); err != nil { if cStdout, err := container.StdoutPipe(); err != nil {
log.Errorf("attach: stdout pipe: %s", err) log.Errorf("attach: stdout pipe: %s", err)
} else { } else {
io.Copy(&utils.NopWriter{}, cStdout) io.Copy(&utils.NopWriter{}, cStdout)
@ -201,7 +201,7 @@ func (daemon *Daemon) Attach(container *Container, stdin io.ReadCloser, stdinClo
} }
if stderr != nil { if stderr != nil {
nJobs++ nJobs++
if p, err := container.StdConfig.StderrPipe(); err != nil { if p, err := container.StderrPipe(); err != nil {
errors <- err errors <- err
} else { } else {
cStderr = p cStderr = p
@ -231,7 +231,7 @@ func (daemon *Daemon) Attach(container *Container, stdin io.ReadCloser, stdinClo
defer stdinCloser.Close() defer stdinCloser.Close()
} }
if cStderr, err := container.StdConfig.StderrPipe(); err != nil { if cStderr, err := container.StderrPipe(); err != nil {
log.Errorf("attach: stdout pipe: %s", err) log.Errorf("attach: stdout pipe: %s", err)
} else { } else {
io.Copy(&utils.NopWriter{}, cStderr) io.Copy(&utils.NopWriter{}, cStderr)

View File

@ -41,7 +41,7 @@ var (
ErrContainerStartTimeout = errors.New("The container failed to start due to timed out.") ErrContainerStartTimeout = errors.New("The container failed to start due to timed out.")
) )
type StdConfig struct { type StreamConfig struct {
stdout *broadcastwriter.BroadcastWriter stdout *broadcastwriter.BroadcastWriter
stderr *broadcastwriter.BroadcastWriter stderr *broadcastwriter.BroadcastWriter
stdin io.ReadCloser stdin io.ReadCloser
@ -72,8 +72,8 @@ type Container struct {
Driver string Driver string
ExecDriver string ExecDriver string
command *execdriver.Command command *execdriver.Command
StdConfig StdConfig StreamConfig
daemon *Daemon daemon *Daemon
MountLabel, ProcessLabel string MountLabel, ProcessLabel string
@ -338,7 +338,7 @@ func (container *Container) Run() error {
} }
func (container *Container) Output() (output []byte, err error) { func (container *Container) Output() (output []byte, err error) {
pipe, err := container.StdConfig.StdoutPipe() pipe, err := container.StdoutPipe()
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -351,7 +351,7 @@ func (container *Container) Output() (output []byte, err error) {
return output, err return output, err
} }
// StdConfig.StdinPipe returns a WriteCloser which can be used to feed data // StreamConfig.StdinPipe returns a WriteCloser which can be used to feed data
// to the standard input of the container's active process. // to the standard input of the container's active process.
// Container.StdoutPipe and Container.StderrPipe each return a ReadCloser // Container.StdoutPipe and Container.StderrPipe each return a ReadCloser
// which can be used to retrieve the standard output (and error) generated // which can be used to retrieve the standard output (and error) generated
@ -359,31 +359,31 @@ func (container *Container) Output() (output []byte, err error) {
// copied and delivered to all StdoutPipe and StderrPipe consumers, using // copied and delivered to all StdoutPipe and StderrPipe consumers, using
// a kind of "broadcaster". // a kind of "broadcaster".
func (stdConfig *StdConfig) StdinPipe() (io.WriteCloser, error) { func (streamConfig *StreamConfig) StdinPipe() (io.WriteCloser, error) {
return stdConfig.stdinPipe, nil return streamConfig.stdinPipe, nil
} }
func (stdConfig *StdConfig) StdoutPipe() (io.ReadCloser, error) { func (streamConfig *StreamConfig) StdoutPipe() (io.ReadCloser, error) {
reader, writer := io.Pipe() reader, writer := io.Pipe()
stdConfig.stdout.AddWriter(writer, "") streamConfig.stdout.AddWriter(writer, "")
return utils.NewBufReader(reader), nil return utils.NewBufReader(reader), nil
} }
func (stdConfig *StdConfig) StderrPipe() (io.ReadCloser, error) { func (streamConfig *StreamConfig) StderrPipe() (io.ReadCloser, error) {
reader, writer := io.Pipe() reader, writer := io.Pipe()
stdConfig.stderr.AddWriter(writer, "") streamConfig.stderr.AddWriter(writer, "")
return utils.NewBufReader(reader), nil return utils.NewBufReader(reader), nil
} }
func (container *Container) StdoutLogPipe() io.ReadCloser { func (streamConfig *StreamConfig) StdoutLogPipe() io.ReadCloser {
reader, writer := io.Pipe() reader, writer := io.Pipe()
container.StdConfig.stdout.AddWriter(writer, "stdout") streamConfig.stdout.AddWriter(writer, "stdout")
return utils.NewBufReader(reader) return utils.NewBufReader(reader)
} }
func (container *Container) StderrLogPipe() io.ReadCloser { func (streamConfig *StreamConfig) StderrLogPipe() io.ReadCloser {
reader, writer := io.Pipe() reader, writer := io.Pipe()
container.StdConfig.stderr.AddWriter(writer, "stderr") streamConfig.stderr.AddWriter(writer, "stderr")
return utils.NewBufReader(reader) return utils.NewBufReader(reader)
} }
@ -1092,11 +1092,11 @@ func (container *Container) startLoggingToDisk() error {
return err return err
} }
if err := container.daemon.LogToDisk(container.StdConfig.stdout, pth, "stdout"); err != nil { if err := container.daemon.LogToDisk(container.stdout, pth, "stdout"); err != nil {
return err return err
} }
if err := container.daemon.LogToDisk(container.StdConfig.stderr, pth, "stderr"); err != nil { if err := container.daemon.LogToDisk(container.stderr, pth, "stderr"); err != nil {
return err return err
} }

View File

@ -195,13 +195,13 @@ func (daemon *Daemon) register(container *Container, updateSuffixarray bool) err
container.daemon = daemon container.daemon = daemon
// Attach to stdout and stderr // Attach to stdout and stderr
container.StdConfig.stderr = broadcastwriter.New() container.stderr = broadcastwriter.New()
container.StdConfig.stdout = broadcastwriter.New() container.stdout = broadcastwriter.New()
// Attach to stdin // Attach to stdin
if container.Config.OpenStdin { if container.Config.OpenStdin {
container.StdConfig.stdin, container.StdConfig.stdinPipe = io.Pipe() container.stdin, container.stdinPipe = io.Pipe()
} else { } else {
container.StdConfig.stdinPipe = utils.NopWriteCloser(ioutil.Discard) // Silently drop stdin container.stdinPipe = utils.NopWriteCloser(ioutil.Discard) // Silently drop stdin
} }
// done // done
daemon.containers.Add(container.ID, container) daemon.containers.Add(container.ID, container)

View File

@ -20,7 +20,7 @@ var (
ErrDriverNotFound = errors.New("The requested docker init has not been found") ErrDriverNotFound = errors.New("The requested docker init has not been found")
) )
type StartCallback func(*ProcessConfig) type StartCallback func(*ProcessConfig, int)
// Driver specific information based on // Driver specific information based on
// processes registered with the driver // processes registered with the driver
@ -84,14 +84,13 @@ type Mount struct {
type ProcessConfig struct { type ProcessConfig struct {
exec.Cmd `json:"-"` exec.Cmd `json:"-"`
Privileged bool `json:"privileged"` Privileged bool `json:"privileged"`
User string `json:"user"` User string `json:"user"`
Tty bool `json:"tty"` Tty bool `json:"tty"`
Entrypoint string `json:"entrypoint"` Entrypoint string `json:"entrypoint"`
Arguments []string `json:"arguments"` Arguments []string `json:"arguments"`
Terminal Terminal `json:"-"` // standard or tty terminal Terminal Terminal `json:"-"` // standard or tty terminal
ContainerPid int `json:"container_pid"` // the pid for the process inside a container Console string `json:"-"` // dev/console path
Console string `json:"-"` // dev/console path
} }
// Process wrapps an os/exec.Cmd to add more metadata // Process wrapps an os/exec.Cmd to add more metadata
@ -109,12 +108,6 @@ type Command struct {
AutoCreatedDevices []*devices.Device `json:"autocreated_devices"` AutoCreatedDevices []*devices.Device `json:"autocreated_devices"`
CapAdd []string `json:"cap_add"` CapAdd []string `json:"cap_add"`
CapDrop []string `json:"cap_drop"` CapDrop []string `json:"cap_drop"`
ContainerPid int `json:"container_pid"` // the pid for the process inside a container
ProcessConfig ProcessConfig `json:"process_config"` // Describes the init process of the container. ProcessConfig ProcessConfig `json:"process_config"` // Describes the init process of the container.
}
// Return the pid of the process
// If the process is nil -1 will be returned
func (processConfig *ProcessConfig) Pid() int {
return processConfig.ContainerPid
} }

View File

@ -184,10 +184,10 @@ func (d *driver) Run(c *execdriver.Command, pipes *execdriver.Pipes, startCallba
return -1, err return -1, err
} }
c.ProcessConfig.ContainerPid = pid c.ContainerPid = pid
if startCallback != nil { if startCallback != nil {
startCallback(&c.ProcessConfig) startCallback(&c.ProcessConfig, pid)
} }
<-waitLock <-waitLock

View File

@ -52,6 +52,7 @@ func TestLXCConfig(t *testing.T) {
Interface: nil, Interface: nil,
}, },
AllowedDevices: make([]*devices.Device, 0), AllowedDevices: make([]*devices.Device, 0),
ProcessConfig: execdriver.ProcessConfig{},
} }
p, err := driver.generateLXCConfig(command) p, err := driver.generateLXCConfig(command)
if err != nil { if err != nil {

View File

@ -121,8 +121,8 @@ func (d *driver) Run(c *execdriver.Command, pipes *execdriver.Pipes, startCallba
return &c.ProcessConfig.Cmd return &c.ProcessConfig.Cmd
}, func() { }, func() {
if startCallback != nil { if startCallback != nil {
c.ProcessConfig.ContainerPid = c.ProcessConfig.Process.Pid c.ContainerPid = c.ProcessConfig.Process.Pid
startCallback(&c.ProcessConfig) startCallback(&c.ProcessConfig, c.ContainerPid)
} }
}) })
} }

View File

@ -128,7 +128,7 @@ func (m *containerMonitor) Start() error {
return err return err
} }
pipes := execdriver.NewPipes(m.container.StdConfig.stdin, m.container.StdConfig.stdout, m.container.StdConfig.stderr, m.container.Config.OpenStdin) pipes := execdriver.NewPipes(m.container.stdin, m.container.stdout, m.container.stderr, m.container.Config.OpenStdin)
m.container.LogEvent("start") m.container.LogEvent("start")
@ -233,7 +233,7 @@ func (m *containerMonitor) shouldRestart(exitStatus int) bool {
// callback ensures that the container's state is properly updated after we // callback ensures that the container's state is properly updated after we
// received ack from the execution drivers // received ack from the execution drivers
func (m *containerMonitor) callback(processConfig *execdriver.ProcessConfig) { func (m *containerMonitor) callback(processConfig *execdriver.ProcessConfig, pid int) {
if processConfig.Tty { if processConfig.Tty {
// The callback is called after the process Start() // The callback is called after the process Start()
// so we are in the parent process. In TTY mode, stdin/out/err is the PtySlace // so we are in the parent process. In TTY mode, stdin/out/err is the PtySlace
@ -243,7 +243,7 @@ func (m *containerMonitor) callback(processConfig *execdriver.ProcessConfig) {
} }
} }
m.container.State.setRunning(processConfig.Pid()) m.container.State.setRunning(pid)
// signal that the process has started // signal that the process has started
// close channel only if not closed // close channel only if not closed
@ -269,16 +269,16 @@ func (m *containerMonitor) resetContainer(lock bool) {
} }
if container.Config.OpenStdin { if container.Config.OpenStdin {
if err := container.StdConfig.stdin.Close(); err != nil { if err := container.stdin.Close(); err != nil {
log.Errorf("%s: Error close stdin: %s", container.ID, err) log.Errorf("%s: Error close stdin: %s", container.ID, err)
} }
} }
if err := container.StdConfig.stdout.Clean(); err != nil { if err := container.stdout.Clean(); err != nil {
log.Errorf("%s: Error close stdout: %s", container.ID, err) log.Errorf("%s: Error close stdout: %s", container.ID, err)
} }
if err := container.StdConfig.stderr.Clean(); err != nil { if err := container.stderr.Clean(); err != nil {
log.Errorf("%s: Error close stderr: %s", container.ID, err) log.Errorf("%s: Error close stderr: %s", container.ID, err)
} }
@ -290,7 +290,7 @@ func (m *containerMonitor) resetContainer(lock bool) {
// Re-create a brand new stdin pipe once the container exited // Re-create a brand new stdin pipe once the container exited
if container.Config.OpenStdin { if container.Config.OpenStdin {
container.StdConfig.stdin, container.StdConfig.stdinPipe = io.Pipe() container.stdin, container.stdinPipe = io.Pipe()
} }
c := container.command.ProcessConfig.Cmd c := container.command.ProcessConfig.Cmd

View File

@ -467,7 +467,7 @@ func TestAttachDisconnect(t *testing.T) {
} }
// Try to avoid the timeout in destroy. Best effort, don't check error // Try to avoid the timeout in destroy. Best effort, don't check error
cStdin, _ := container.StdConfig.StdinPipe() cStdin, _ := container.StdinPipe()
cStdin.Close() cStdin.Close()
container.State.WaitStop(-1 * time.Second) container.State.WaitStop(-1 * time.Second)
} }

View File

@ -25,11 +25,11 @@ func TestRestartStdin(t *testing.T) {
} }
defer daemon.Destroy(container) defer daemon.Destroy(container)
stdin, err := container.StdConfig.StdinPipe() stdin, err := container.StdinPipe()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
stdout, err := container.StdConfig.StdoutPipe() stdout, err := container.StdoutPipe()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -55,11 +55,11 @@ func TestRestartStdin(t *testing.T) {
} }
// Restart and try again // Restart and try again
stdin, err = container.StdConfig.StdinPipe() stdin, err = container.StdinPipe()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
stdout, err = container.StdConfig.StdoutPipe() stdout, err = container.StdoutPipe()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -101,11 +101,11 @@ func TestStdin(t *testing.T) {
} }
defer daemon.Destroy(container) defer daemon.Destroy(container)
stdin, err := container.StdConfig.StdinPipe() stdin, err := container.StdinPipe()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
stdout, err := container.StdConfig.StdoutPipe() stdout, err := container.StdoutPipe()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -146,11 +146,11 @@ func TestTty(t *testing.T) {
} }
defer daemon.Destroy(container) defer daemon.Destroy(container)
stdin, err := container.StdConfig.StdinPipe() stdin, err := container.StdinPipe()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
stdout, err := container.StdConfig.StdoutPipe() stdout, err := container.StdoutPipe()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -611,7 +611,7 @@ func TestRestore(t *testing.T) {
} }
// Simulate a crash/manual quit of dockerd: process dies, states stays 'Running' // Simulate a crash/manual quit of dockerd: process dies, states stays 'Running'
cStdin, _ := container2.StdConfig.StdinPipe() cStdin, _ := container2.StdinPipe()
cStdin.Close() cStdin.Close()
if _, err := container2.State.WaitStop(2 * time.Second); err != nil { if _, err := container2.State.WaitStop(2 * time.Second); err != nil {
t.Fatal(err) t.Fatal(err)

View File

@ -84,11 +84,11 @@ func containerFileExists(eng *engine.Engine, id, dir string, t log.Fataler) bool
func containerAttach(eng *engine.Engine, id string, t log.Fataler) (io.WriteCloser, io.ReadCloser) { func containerAttach(eng *engine.Engine, id string, t log.Fataler) (io.WriteCloser, io.ReadCloser) {
c := getContainer(eng, id, t) c := getContainer(eng, id, t)
i, err := c.StdConfig.StdinPipe() i, err := c.StdinPipe()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
o, err := c.StdConfig.StdoutPipe() o, err := c.StdoutPipe()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -289,7 +289,7 @@ func runContainer(eng *engine.Engine, r *daemon.Daemon, args []string, t *testin
return "", err return "", err
} }
defer r.Destroy(container) defer r.Destroy(container)
stdout, err := container.StdConfig.StdoutPipe() stdout, err := container.StdoutPipe()
if err != nil { if err != nil {
return "", err return "", err
} }