From 5566ccb7aa0747005573f6f4f04f46552b75a394 Mon Sep 17 00:00:00 2001 From: Lei Jitang Date: Tue, 2 Feb 2016 21:05:01 -0500 Subject: [PATCH] Fix docker top a restarting container Signed-off-by: Lei Jitang --- daemon/exec.go | 4 ++-- daemon/top_unix.go | 3 +++ errors/daemon.go | 18 +++++++++--------- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/daemon/exec.go b/daemon/exec.go index 7772790d6e..1151a77c7b 100644 --- a/daemon/exec.go +++ b/daemon/exec.go @@ -53,7 +53,7 @@ func (d *Daemon) getExecConfig(name string) (*exec.Config, error) { return nil, derr.ErrorCodeExecPaused.WithArgs(container.ID) } if container.IsRestarting() { - return nil, derr.ErrorCodeExecRestarting.WithArgs(container.ID) + return nil, derr.ErrorCodeContainerRestarting.WithArgs(container.ID) } return ec, nil } @@ -80,7 +80,7 @@ func (d *Daemon) getActiveContainer(name string) (*container.Container, error) { return nil, derr.ErrorCodeExecPaused.WithArgs(name) } if container.IsRestarting() { - return nil, derr.ErrorCodeExecRestarting.WithArgs(name) + return nil, derr.ErrorCodeContainerRestarting.WithArgs(name) } return container, nil } diff --git a/daemon/top_unix.go b/daemon/top_unix.go index 22dac6f218..6d92592eb6 100644 --- a/daemon/top_unix.go +++ b/daemon/top_unix.go @@ -30,6 +30,9 @@ func (daemon *Daemon) ContainerTop(name string, psArgs string) (*types.Container return nil, derr.ErrorCodeNotRunning.WithArgs(name) } + if container.IsRestarting() { + return nil, derr.ErrorCodeContainerRestarting.WithArgs(name) + } pids, err := daemon.ExecutionDriver().GetPidsForContainer(container.ID) if err != nil { return nil, err diff --git a/errors/daemon.go b/errors/daemon.go index 78c4422ab1..2a11b4650e 100644 --- a/errors/daemon.go +++ b/errors/daemon.go @@ -715,6 +715,15 @@ var ( HTTPStatusCode: http.StatusConflict, }) + // ErrorCodeContainerRestarting is generated when an operation was made + // on a restarting container. + ErrorCodeContainerRestarting = errcode.Register(errGroup, errcode.ErrorDescriptor{ + Value: "CONTAINERRESTARTING", + Message: "Container %s is restarting, wait until the container is running", + Description: "An operation was made on a restarting container", + HTTPStatusCode: http.StatusConflict, + }) + // ErrorCodeNoExecID is generated when we try to get the info // on an exec but it can't be found. ErrorCodeNoExecID = errcode.Register(errGroup, errcode.ErrorDescriptor{ @@ -733,15 +742,6 @@ var ( HTTPStatusCode: http.StatusConflict, }) - // ErrorCodeExecRestarting is generated when we try to start an exec - // but the container is restarting. - ErrorCodeExecRestarting = errcode.Register(errGroup, errcode.ErrorDescriptor{ - Value: "EXECRESTARTING", - Message: "Container %s is restarting, wait until the container is running", - Description: "An attempt to start an 'exec' was made, but the owning container is restarting", - HTTPStatusCode: http.StatusConflict, - }) - // ErrorCodeExecRunning is generated when we try to start an exec // but its already running. ErrorCodeExecRunning = errcode.Register(errGroup, errcode.ErrorDescriptor{