mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Remove exec config from container after exit
This removes the exec config from the container after the command exits so that dead exec commands are not displayed in the container inspect. The commands are still kept on the daemon so that when you inspect the exec command, not the container, you are still able to get it's exit status. This also changes the ProcessConfig to a pointer. Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
f5ebcfe1dc
commit
04c9f86bdc
3 changed files with 6 additions and 8 deletions
|
@ -835,13 +835,11 @@ func (container *Container) monitorExec(execConfig *execConfig, callback execdri
|
||||||
err error
|
err error
|
||||||
exitCode int
|
exitCode int
|
||||||
)
|
)
|
||||||
|
|
||||||
pipes := execdriver.NewPipes(execConfig.StreamConfig.stdin, execConfig.StreamConfig.stdout, execConfig.StreamConfig.stderr, execConfig.OpenStdin)
|
pipes := execdriver.NewPipes(execConfig.StreamConfig.stdin, execConfig.StreamConfig.stdout, execConfig.StreamConfig.stderr, execConfig.OpenStdin)
|
||||||
exitCode, err = container.daemon.Exec(container, execConfig, pipes, callback)
|
exitCode, err = container.daemon.Exec(container, execConfig, pipes, callback)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Errorf("Error running command in existing container %s: %s", container.ID, err)
|
logrus.Errorf("Error running command in existing container %s: %s", container.ID, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
logrus.Debugf("Exec task in container %s exited with code %d", container.ID, exitCode)
|
logrus.Debugf("Exec task in container %s exited with code %d", container.ID, exitCode)
|
||||||
if execConfig.OpenStdin {
|
if execConfig.OpenStdin {
|
||||||
if err := execConfig.StreamConfig.stdin.Close(); err != nil {
|
if err := execConfig.StreamConfig.stdin.Close(); err != nil {
|
||||||
|
@ -859,7 +857,9 @@ func (container *Container) monitorExec(execConfig *execConfig, callback execdri
|
||||||
logrus.Errorf("Error closing terminal while running in container %s: %s", container.ID, err)
|
logrus.Errorf("Error closing terminal while running in container %s: %s", container.ID, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// remove the exec command from the container's store only and not the
|
||||||
|
// daemon's store so that the exec command can be inspected.
|
||||||
|
container.execCommands.Delete(execConfig.ID)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ type execConfig struct {
|
||||||
ID string
|
ID string
|
||||||
Running bool
|
Running bool
|
||||||
ExitCode int
|
ExitCode int
|
||||||
ProcessConfig execdriver.ProcessConfig
|
ProcessConfig *execdriver.ProcessConfig
|
||||||
StreamConfig
|
StreamConfig
|
||||||
OpenStdin bool
|
OpenStdin bool
|
||||||
OpenStderr bool
|
OpenStderr bool
|
||||||
|
@ -128,7 +128,7 @@ func (d *Daemon) ContainerExecCreate(config *runconfig.ExecConfig) (string, erro
|
||||||
user = container.Config.User
|
user = container.Config.User
|
||||||
}
|
}
|
||||||
|
|
||||||
processConfig := execdriver.ProcessConfig{
|
processConfig := &execdriver.ProcessConfig{
|
||||||
Tty: config.Tty,
|
Tty: config.Tty,
|
||||||
Entrypoint: entrypoint,
|
Entrypoint: entrypoint,
|
||||||
Arguments: args,
|
Arguments: args,
|
||||||
|
@ -221,7 +221,6 @@ func (d *Daemon) ContainerExecStart(execName string, stdin io.ReadCloser, stdout
|
||||||
execErr <- fmt.Errorf("Cannot run exec command %s in container %s: %s", execName, container.ID, err)
|
execErr <- fmt.Errorf("Cannot run exec command %s in container %s: %s", execName, container.ID, err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case err := <-attachErr:
|
case err := <-attachErr:
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -236,7 +235,7 @@ func (d *Daemon) ContainerExecStart(execName string, stdin io.ReadCloser, stdout
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Daemon) Exec(c *Container, execConfig *execConfig, pipes *execdriver.Pipes, startCallback execdriver.StartCallback) (int, error) {
|
func (d *Daemon) Exec(c *Container, execConfig *execConfig, pipes *execdriver.Pipes, startCallback execdriver.StartCallback) (int, error) {
|
||||||
exitStatus, err := d.execDriver.Exec(c.command, &execConfig.ProcessConfig, pipes, startCallback)
|
exitStatus, err := d.execDriver.Exec(c.command, execConfig.ProcessConfig, pipes, startCallback)
|
||||||
|
|
||||||
// On err, make sure we don't leave ExitCode at zero
|
// On err, make sure we don't leave ExitCode at zero
|
||||||
if err != nil && exitStatus == 0 {
|
if err != nil && exitStatus == 0 {
|
||||||
|
|
|
@ -124,6 +124,5 @@ func (daemon *Daemon) ContainerExecInspect(id string) (*execConfig, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return eConfig, nil
|
return eConfig, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue