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 коммит произвёл Michael Crosby
Родитель 4aa5da278f
Коммит 3a7e07355a
12 изменённых файлов: 61 добавлений и 67 удалений

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

@ -127,7 +127,7 @@ func (daemon *Daemon) Attach(container *Container, stdin io.ReadCloser, stdinClo
if stdin != nil && container.Config.OpenStdin {
nJobs++
if cStdin, err := container.StdConfig.StdinPipe(); err != nil {
if cStdin, err := container.StdinPipe(); err != nil {
errors <- err
} else {
go func() {
@ -163,7 +163,7 @@ func (daemon *Daemon) Attach(container *Container, stdin io.ReadCloser, stdinClo
}
if stdout != nil {
nJobs++
if p, err := container.StdConfig.StdoutPipe(); err != nil {
if p, err := container.StdoutPipe(); err != nil {
errors <- err
} else {
cStdout = p
@ -192,7 +192,7 @@ func (daemon *Daemon) Attach(container *Container, stdin io.ReadCloser, stdinClo
if stdinCloser != nil {
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)
} else {
io.Copy(&utils.NopWriter{}, cStdout)
@ -201,7 +201,7 @@ func (daemon *Daemon) Attach(container *Container, stdin io.ReadCloser, stdinClo
}
if stderr != nil {
nJobs++
if p, err := container.StdConfig.StderrPipe(); err != nil {
if p, err := container.StderrPipe(); err != nil {
errors <- err
} else {
cStderr = p
@ -231,7 +231,7 @@ func (daemon *Daemon) Attach(container *Container, stdin io.ReadCloser, stdinClo
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)
} else {
io.Copy(&utils.NopWriter{}, cStderr)

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

@ -41,7 +41,7 @@ var (
ErrContainerStartTimeout = errors.New("The container failed to start due to timed out.")
)
type StdConfig struct {
type StreamConfig struct {
stdout *broadcastwriter.BroadcastWriter
stderr *broadcastwriter.BroadcastWriter
stdin io.ReadCloser
@ -72,8 +72,8 @@ type Container struct {
Driver string
ExecDriver string
command *execdriver.Command
StdConfig StdConfig
command *execdriver.Command
StreamConfig
daemon *Daemon
MountLabel, ProcessLabel string
@ -338,7 +338,7 @@ func (container *Container) Run() error {
}
func (container *Container) Output() (output []byte, err error) {
pipe, err := container.StdConfig.StdoutPipe()
pipe, err := container.StdoutPipe()
if err != nil {
return nil, err
}
@ -351,7 +351,7 @@ func (container *Container) Output() (output []byte, err error) {
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.
// Container.StdoutPipe and Container.StderrPipe each return a ReadCloser
// 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
// a kind of "broadcaster".
func (stdConfig *StdConfig) StdinPipe() (io.WriteCloser, error) {
return stdConfig.stdinPipe, nil
func (streamConfig *StreamConfig) StdinPipe() (io.WriteCloser, error) {
return streamConfig.stdinPipe, nil
}
func (stdConfig *StdConfig) StdoutPipe() (io.ReadCloser, error) {
func (streamConfig *StreamConfig) StdoutPipe() (io.ReadCloser, error) {
reader, writer := io.Pipe()
stdConfig.stdout.AddWriter(writer, "")
streamConfig.stdout.AddWriter(writer, "")
return utils.NewBufReader(reader), nil
}
func (stdConfig *StdConfig) StderrPipe() (io.ReadCloser, error) {
func (streamConfig *StreamConfig) StderrPipe() (io.ReadCloser, error) {
reader, writer := io.Pipe()
stdConfig.stderr.AddWriter(writer, "")
streamConfig.stderr.AddWriter(writer, "")
return utils.NewBufReader(reader), nil
}
func (container *Container) StdoutLogPipe() io.ReadCloser {
func (streamConfig *StreamConfig) StdoutLogPipe() io.ReadCloser {
reader, writer := io.Pipe()
container.StdConfig.stdout.AddWriter(writer, "stdout")
streamConfig.stdout.AddWriter(writer, "stdout")
return utils.NewBufReader(reader)
}
func (container *Container) StderrLogPipe() io.ReadCloser {
func (streamConfig *StreamConfig) StderrLogPipe() io.ReadCloser {
reader, writer := io.Pipe()
container.StdConfig.stderr.AddWriter(writer, "stderr")
streamConfig.stderr.AddWriter(writer, "stderr")
return utils.NewBufReader(reader)
}
@ -1092,11 +1092,11 @@ func (container *Container) startLoggingToDisk() error {
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
}
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
}

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

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

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

@ -20,7 +20,7 @@ var (
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
// processes registered with the driver
@ -84,14 +84,13 @@ type Mount struct {
type ProcessConfig struct {
exec.Cmd `json:"-"`
Privileged bool `json:"privileged"`
User string `json:"user"`
Tty bool `json:"tty"`
Entrypoint string `json:"entrypoint"`
Arguments []string `json:"arguments"`
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
Privileged bool `json:"privileged"`
User string `json:"user"`
Tty bool `json:"tty"`
Entrypoint string `json:"entrypoint"`
Arguments []string `json:"arguments"`
Terminal Terminal `json:"-"` // standard or tty terminal
Console string `json:"-"` // dev/console path
}
// Process wrapps an os/exec.Cmd to add more metadata
@ -109,12 +108,6 @@ type Command struct {
AutoCreatedDevices []*devices.Device `json:"autocreated_devices"`
CapAdd []string `json:"cap_add"`
CapDrop []string `json:"cap_drop"`
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
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.
}

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

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

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

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

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

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

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

@ -128,7 +128,7 @@ func (m *containerMonitor) Start() error {
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")
@ -233,7 +233,7 @@ func (m *containerMonitor) shouldRestart(exitStatus int) bool {
// callback ensures that the container's state is properly updated after we
// 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 {
// The callback is called after the process Start()
// 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
// close channel only if not closed
@ -269,16 +269,16 @@ func (m *containerMonitor) resetContainer(lock bool) {
}
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)
}
}
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)
}
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)
}
@ -290,7 +290,7 @@ func (m *containerMonitor) resetContainer(lock bool) {
// Re-create a brand new stdin pipe once the container exited
if container.Config.OpenStdin {
container.StdConfig.stdin, container.StdConfig.stdinPipe = io.Pipe()
container.stdin, container.stdinPipe = io.Pipe()
}
c := container.command.ProcessConfig.Cmd

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

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

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

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

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

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

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

@ -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) {
c := getContainer(eng, id, t)
i, err := c.StdConfig.StdinPipe()
i, err := c.StdinPipe()
if err != nil {
t.Fatal(err)
}
o, err := c.StdConfig.StdoutPipe()
o, err := c.StdoutPipe()
if err != nil {
t.Fatal(err)
}
@ -289,7 +289,7 @@ func runContainer(eng *engine.Engine, r *daemon.Daemon, args []string, t *testin
return "", err
}
defer r.Destroy(container)
stdout, err := container.StdConfig.StdoutPipe()
stdout, err := container.StdoutPipe()
if err != nil {
return "", err
}