Skip to content

Commit

Permalink
bugfix: set pid of stopped container to 0
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Wan <[email protected]>
  • Loading branch information
HusterWan committed Sep 3, 2018
1 parent bf1a13c commit b2408ba
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions daemon/mgr/container_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (c *Container) SetStatusStopped(exitCode int64, errMsg string) {
defer c.Unlock()
c.State.Status = types.StatusStopped
c.State.FinishedAt = time.Now().UTC().Format(utils.TimeLayout)
c.State.Pid = -1
c.State.Pid = 0
c.State.ExitCode = exitCode
c.State.Error = errMsg
c.setStatusFlags(types.StatusStopped)
Expand All @@ -117,7 +117,7 @@ func (c *Container) SetStatusExited(exitCode int64, errMsg string) {
defer c.Unlock()
c.State.Status = types.StatusExited
c.State.FinishedAt = time.Now().UTC().Format(utils.TimeLayout)
c.State.Pid = -1
c.State.Pid = 0
c.State.ExitCode = exitCode
c.State.Error = errMsg
c.setStatusFlags(types.StatusExited)
Expand Down
18 changes: 18 additions & 0 deletions test/cli_stop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,21 @@ func (suite *PouchStopSuite) TestStopMultiContainers(c *check.C) {
c.Assert(string(result[0].State.Status), check.Equals, "stopped")

}

// TestStopPidValue ensure stopped container's pid is 0
func (suite *PouchStopSuite) TestStopPidValue(c *check.C) {
name := "test-stop-pid-value"

command.PouchRun("create", "--name", name, busyboxImage, "top").Assert(c, icmd.Success)
defer DelContainerForceMultyTime(c, name)

// test stop a created container
command.PouchRun("stop", name).Assert(c, icmd.Success)

output := command.PouchRun("inspect", name).Stdout()
result := []types.ContainerJSON{}
if err := json.Unmarshal([]byte(output), &result); err != nil {
c.Errorf("failed to decode inspect output: %v", err)
}
c.Assert(result[0].State.Pid, check.Equals, int64(0))
}

0 comments on commit b2408ba

Please sign in to comment.