diff --git a/events.go b/events.go index 9777e4826..2d7b48954 100644 --- a/events.go +++ b/events.go @@ -116,7 +116,8 @@ information is displayed once every 5 seconds.`, if err != nil { return err } - if status == libcontainer.Destroyed { + if status == libcontainer.Stopped { + fatalf("container with id %s is not running", container.ID()) return fmt.Errorf("container with id %s is not running", container.ID()) } var ( diff --git a/libcontainer/container.go b/libcontainer/container.go index c394c40e2..5e081da5c 100644 --- a/libcontainer/container.go +++ b/libcontainer/container.go @@ -15,7 +15,7 @@ import ( type Status int const ( - // Created is the status that denotes the container exists but has not been run yet + // Created is the status that denotes the container exists but has not been run yet. Created Status = iota // Running is the status that denotes the container exists and is running. @@ -27,15 +27,8 @@ const ( // Paused is the status that denotes the container exists, but all its processes are paused. Paused - // Destroyed is the status that denotes the container does not exist. - Destroyed - // Stopped is the status that denotes the container does not have a created or running process. Stopped - - // Initialized is the status where the container has all the namespaces created but the user - // process has not been start. - Initialized ) func (s Status) String() string { @@ -48,12 +41,8 @@ func (s Status) String() string { return "pausing" case Paused: return "paused" - case Destroyed: - return "destroyed" case Stopped: return "stopped" - case Initialized: - return "initialized" default: return "unknown" } diff --git a/libcontainer/container_linux.go b/libcontainer/container_linux.go index 16f1385cb..81139c1ae 100644 --- a/libcontainer/container_linux.go +++ b/libcontainer/container_linux.go @@ -181,7 +181,7 @@ func (c *linuxContainer) Start(process *Process) error { if err != nil { return err } - doInit := status == Destroyed + doInit := status == Stopped parent, err := c.newParentProcess(process, doInit) if err != nil { return newSystemErrorWithCause(err, "creating new parent process") @@ -1038,8 +1038,8 @@ func (c *linuxContainer) refreshState() error { return err } switch t { - case Initialized: - return c.state.transition(&initializedState{c: c}) + case Created: + return c.state.transition(&createdState{c: c}) case Running: return c.state.transition(&runningState{c: c}) } @@ -1070,7 +1070,7 @@ func (c *linuxContainer) runType() (Status, error) { check := []byte("_LIBCONTAINER") for _, v := range bytes.Split(environ, []byte("\x00")) { if bytes.Contains(v, check) { - return Initialized, nil + return Created, nil } } return Running, nil diff --git a/libcontainer/factory_linux.go b/libcontainer/factory_linux.go index 95a784d05..cff080888 100644 --- a/libcontainer/factory_linux.go +++ b/libcontainer/factory_linux.go @@ -206,7 +206,7 @@ func (l *LinuxFactory) Load(id string) (Container, error) { root: containerRoot, created: state.Created, } - c.state = &createdState{c: c, s: Created} + c.state = &loadedState{c: c} if err := c.refreshState(); err != nil { return nil, err } diff --git a/libcontainer/state_linux.go b/libcontainer/state_linux.go index cd045b8ae..790af0819 100644 --- a/libcontainer/state_linux.go +++ b/libcontainer/state_linux.go @@ -77,7 +77,7 @@ type stoppedState struct { } func (b *stoppedState) status() Status { - return Destroyed + return Stopped } func (b *stoppedState) transition(s containerState) error { @@ -139,25 +139,25 @@ func (r *runningState) destroy() error { return destroy(r.c) } -type initializedState struct { +type createdState struct { c *linuxContainer } -func (i *initializedState) status() Status { - return Initialized +func (i *createdState) status() Status { + return Created } -func (i *initializedState) transition(s containerState) error { +func (i *createdState) transition(s containerState) error { switch s.(type) { case *runningState: i.c.state = s - case *initializedState: + case *createdState: return nil } return newStateTransitionError(i, s) } -func (i *initializedState) destroy() error { +func (i *createdState) destroy() error { return destroy(i.c) } @@ -226,23 +226,23 @@ func (r *restoredState) destroy() error { return destroy(r.c) } -// createdState is used whenever a container is restored, loaded, or setting additional +// loadedState is used whenever a container is restored, loaded, or setting additional // processes inside and it should not be destroyed when it is exiting. -type createdState struct { +type loadedState struct { c *linuxContainer s Status } -func (n *createdState) status() Status { +func (n *loadedState) status() Status { return n.s } -func (n *createdState) transition(s containerState) error { +func (n *loadedState) transition(s containerState) error { n.c.state = s return nil } -func (n *createdState) destroy() error { +func (n *loadedState) destroy() error { if err := n.c.refreshState(); err != nil { return err }