Skip to content

Commit

Permalink
Merge pull request #2193 from HusterWan/zr/pid-fix
Browse files Browse the repository at this point in the history
bugfix: set pid of stopped container to 0
  • Loading branch information
fuweid authored Sep 3, 2018
2 parents bf1a13c + e52903a commit 4e03146
Show file tree
Hide file tree
Showing 2 changed files with 35 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
33 changes: 33 additions & 0 deletions test/cli_stop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,36 @@ 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("run", "-d", "--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))
}

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

command.PouchRun("run", "--name", name, busyboxImage, "echo", "hi").Assert(c, icmd.Success)
defer DelContainerForceMultyTime(c, name)

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 4e03146

Please sign in to comment.