From ff034a511980f536b303ccd4a6cc458be6d36182 Mon Sep 17 00:00:00 2001 From: Doug Davis Date: Sun, 24 Jan 2016 20:52:52 -0800 Subject: [PATCH] Remove the nullState Add a "createdState" in its place since I think that better describes what its used for. Signed-off-by: Doug Davis --- libcontainer/container.go | 9 +++++++-- libcontainer/container_linux_test.go | 2 +- libcontainer/factory_linux.go | 2 +- libcontainer/state_linux.go | 12 ++++++------ libcontainer/state_linux_test.go | 4 ++-- 5 files changed, 17 insertions(+), 12 deletions(-) diff --git a/libcontainer/container.go b/libcontainer/container.go index 051c8cf6..03c8c559 100644 --- a/libcontainer/container.go +++ b/libcontainer/container.go @@ -14,8 +14,11 @@ import ( type Status int const ( + // The container exists but has not been run yet + Created Status = iota + // The container exists and is running. - Running Status = iota + 1 + Running // The container exists, it is in the process of being paused. Pausing @@ -32,6 +35,8 @@ const ( func (s Status) String() string { switch s { + case Created: + return "created" case Running: return "running" case Pausing: @@ -43,7 +48,7 @@ func (s Status) String() string { case Destroyed: return "destroyed" default: - return "undefined" + return "unknown" } } diff --git a/libcontainer/container_linux_test.go b/libcontainer/container_linux_test.go index a66ea067..3af30bce 100644 --- a/libcontainer/container_linux_test.go +++ b/libcontainer/container_linux_test.go @@ -166,7 +166,7 @@ func TestGetContainerState(t *testing.T) { }, }, } - container.state = &nullState{c: container} + container.state = &createdState{c: container} state, err := container.State() if err != nil { t.Fatal(err) diff --git a/libcontainer/factory_linux.go b/libcontainer/factory_linux.go index eb2bb5fb..30ea7a73 100644 --- a/libcontainer/factory_linux.go +++ b/libcontainer/factory_linux.go @@ -202,7 +202,7 @@ func (l *LinuxFactory) Load(id string) (Container, error) { cgroupManager: l.NewCgroupsManager(state.Config.Cgroups, state.CgroupPaths), root: containerRoot, } - c.state = &nullState{c: c} + c.state = &createdState{c: c, s: Created} if err := c.refreshState(); err != nil { return nil, err } diff --git a/libcontainer/state_linux.go b/libcontainer/state_linux.go index fcd4e17d..fb71ef97 100644 --- a/libcontainer/state_linux.go +++ b/libcontainer/state_linux.go @@ -117,7 +117,7 @@ func (r *runningState) transition(s containerState) error { } r.c.state = s return nil - case *pausedState, *nullState: + case *pausedState: r.c.state = s return nil case *runningState: @@ -202,22 +202,22 @@ func (r *restoredState) destroy() error { return destroy(r.c) } -// nullState is used whenever a container is restored, loaded, or setting additional +// createdState is used whenever a container is restored, loaded, or setting additional // processes inside and it should not be destroyed when it is exiting. -type nullState struct { +type createdState struct { c *linuxContainer s Status } -func (n *nullState) status() Status { +func (n *createdState) status() Status { return n.s } -func (n *nullState) transition(s containerState) error { +func (n *createdState) transition(s containerState) error { n.c.state = s return nil } -func (n *nullState) destroy() error { +func (n *createdState) destroy() error { return nil } diff --git a/libcontainer/state_linux_test.go b/libcontainer/state_linux_test.go index 6281d6f4..417d9c22 100644 --- a/libcontainer/state_linux_test.go +++ b/libcontainer/state_linux_test.go @@ -69,9 +69,9 @@ func TestRestoredStateTransition(t *testing.T) { t.Fatal(err) } } - err := s.transition(&nullState{}) + err := s.transition(&createdState{}) if err == nil { - t.Fatal("transition to null state should fail") + t.Fatal("transition to created state should fail") } if !isStateTransitionError(err) { t.Fatal("expected stateTransitionError")