Browse code

Fix docker top a restarting container

Signed-off-by: Lei Jitang <leijitang@huawei.com>

Lei Jitang authored on 2016/02/03 11:05:01
Showing 3 changed files
... ...
@@ -53,7 +53,7 @@ func (d *Daemon) getExecConfig(name string) (*exec.Config, error) {
53 53
 				return nil, derr.ErrorCodeExecPaused.WithArgs(container.ID)
54 54
 			}
55 55
 			if container.IsRestarting() {
56
-				return nil, derr.ErrorCodeExecRestarting.WithArgs(container.ID)
56
+				return nil, derr.ErrorCodeContainerRestarting.WithArgs(container.ID)
57 57
 			}
58 58
 			return ec, nil
59 59
 		}
... ...
@@ -80,7 +80,7 @@ func (d *Daemon) getActiveContainer(name string) (*container.Container, error) {
80 80
 		return nil, derr.ErrorCodeExecPaused.WithArgs(name)
81 81
 	}
82 82
 	if container.IsRestarting() {
83
-		return nil, derr.ErrorCodeExecRestarting.WithArgs(name)
83
+		return nil, derr.ErrorCodeContainerRestarting.WithArgs(name)
84 84
 	}
85 85
 	return container, nil
86 86
 }
... ...
@@ -30,6 +30,9 @@ func (daemon *Daemon) ContainerTop(name string, psArgs string) (*types.Container
30 30
 		return nil, derr.ErrorCodeNotRunning.WithArgs(name)
31 31
 	}
32 32
 
33
+	if container.IsRestarting() {
34
+		return nil, derr.ErrorCodeContainerRestarting.WithArgs(name)
35
+	}
33 36
 	pids, err := daemon.ExecutionDriver().GetPidsForContainer(container.ID)
34 37
 	if err != nil {
35 38
 		return nil, err
... ...
@@ -715,6 +715,15 @@ var (
715 715
 		HTTPStatusCode: http.StatusConflict,
716 716
 	})
717 717
 
718
+	// ErrorCodeContainerRestarting is generated when an operation was made
719
+	// on a restarting container.
720
+	ErrorCodeContainerRestarting = errcode.Register(errGroup, errcode.ErrorDescriptor{
721
+		Value:          "CONTAINERRESTARTING",
722
+		Message:        "Container %s is restarting, wait until the container is running",
723
+		Description:    "An operation was made on a restarting container",
724
+		HTTPStatusCode: http.StatusConflict,
725
+	})
726
+
718 727
 	// ErrorCodeNoExecID is generated when we try to get the info
719 728
 	// on an exec but it can't be found.
720 729
 	ErrorCodeNoExecID = errcode.Register(errGroup, errcode.ErrorDescriptor{
... ...
@@ -733,15 +742,6 @@ var (
733 733
 		HTTPStatusCode: http.StatusConflict,
734 734
 	})
735 735
 
736
-	// ErrorCodeExecRestarting is generated when we try to start an exec
737
-	// but the container is restarting.
738
-	ErrorCodeExecRestarting = errcode.Register(errGroup, errcode.ErrorDescriptor{
739
-		Value:          "EXECRESTARTING",
740
-		Message:        "Container %s is restarting, wait until the container is running",
741
-		Description:    "An attempt to start an 'exec' was made, but the owning container is restarting",
742
-		HTTPStatusCode: http.StatusConflict,
743
-	})
744
-
745 736
 	// ErrorCodeExecRunning is generated when we try to start an exec
746 737
 	// but its already running.
747 738
 	ErrorCodeExecRunning = errcode.Register(errGroup, errcode.ErrorDescriptor{