From 04c9f86bdcf9f42deb09df76922a8c61205721a2 Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Wed, 8 Jul 2015 10:55:42 -0700 Subject: [PATCH] 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 --- daemon/container.go | 6 +++--- daemon/exec.go | 7 +++---- daemon/inspect.go | 1 - 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/daemon/container.go b/daemon/container.go index a06033c890..1290972267 100644 --- a/daemon/container.go +++ b/daemon/container.go @@ -835,13 +835,11 @@ func (container *Container) monitorExec(execConfig *execConfig, callback execdri err error exitCode int ) - pipes := execdriver.NewPipes(execConfig.StreamConfig.stdin, execConfig.StreamConfig.stdout, execConfig.StreamConfig.stderr, execConfig.OpenStdin) exitCode, err = container.daemon.Exec(container, execConfig, pipes, callback) if err != nil { 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) if execConfig.OpenStdin { 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) } } - + // 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 } diff --git a/daemon/exec.go b/daemon/exec.go index 71f042919f..e1cfcd7f66 100644 --- a/daemon/exec.go +++ b/daemon/exec.go @@ -21,7 +21,7 @@ type execConfig struct { ID string Running bool ExitCode int - ProcessConfig execdriver.ProcessConfig + ProcessConfig *execdriver.ProcessConfig StreamConfig OpenStdin bool OpenStderr bool @@ -128,7 +128,7 @@ func (d *Daemon) ContainerExecCreate(config *runconfig.ExecConfig) (string, erro user = container.Config.User } - processConfig := execdriver.ProcessConfig{ + processConfig := &execdriver.ProcessConfig{ Tty: config.Tty, Entrypoint: entrypoint, 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) } }() - select { case err := <-attachErr: 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) { - 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 if err != nil && exitStatus == 0 { diff --git a/daemon/inspect.go b/daemon/inspect.go index 73b394ca24..7e3edaef98 100644 --- a/daemon/inspect.go +++ b/daemon/inspect.go @@ -124,6 +124,5 @@ func (daemon *Daemon) ContainerExecInspect(id string) (*execConfig, error) { if err != nil { return nil, err } - return eConfig, nil }