Skip to content

Commit e52903a

Browse files
committed
bugfix: set pid of stopped container to 0
Signed-off-by: Michael Wan <[email protected]>
1 parent bf1a13c commit e52903a

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

daemon/mgr/container_state.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func (c *Container) SetStatusStopped(exitCode int64, errMsg string) {
105105
defer c.Unlock()
106106
c.State.Status = types.StatusStopped
107107
c.State.FinishedAt = time.Now().UTC().Format(utils.TimeLayout)
108-
c.State.Pid = -1
108+
c.State.Pid = 0
109109
c.State.ExitCode = exitCode
110110
c.State.Error = errMsg
111111
c.setStatusFlags(types.StatusStopped)
@@ -117,7 +117,7 @@ func (c *Container) SetStatusExited(exitCode int64, errMsg string) {
117117
defer c.Unlock()
118118
c.State.Status = types.StatusExited
119119
c.State.FinishedAt = time.Now().UTC().Format(utils.TimeLayout)
120-
c.State.Pid = -1
120+
c.State.Pid = 0
121121
c.State.ExitCode = exitCode
122122
c.State.Error = errMsg
123123
c.setStatusFlags(types.StatusExited)

test/cli_stop_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,36 @@ func (suite *PouchStopSuite) TestStopMultiContainers(c *check.C) {
126126
c.Assert(string(result[0].State.Status), check.Equals, "stopped")
127127

128128
}
129+
130+
// TestStopPidValue ensure stopped container's pid is 0
131+
func (suite *PouchStopSuite) TestStopPidValue(c *check.C) {
132+
name := "test-stop-pid-value"
133+
134+
command.PouchRun("run", "-d", "--name", name, busyboxImage, "top").Assert(c, icmd.Success)
135+
defer DelContainerForceMultyTime(c, name)
136+
137+
// test stop a created container
138+
command.PouchRun("stop", name).Assert(c, icmd.Success)
139+
140+
output := command.PouchRun("inspect", name).Stdout()
141+
result := []types.ContainerJSON{}
142+
if err := json.Unmarshal([]byte(output), &result); err != nil {
143+
c.Errorf("failed to decode inspect output: %v", err)
144+
}
145+
c.Assert(result[0].State.Pid, check.Equals, int64(0))
146+
}
147+
148+
// TestAutoStopPidValue ensure stopped container's pid is 0
149+
func (suite *PouchStopSuite) TestAutoStopPidValue(c *check.C) {
150+
name := "test-auto-stop-pid-value"
151+
152+
command.PouchRun("run", "--name", name, busyboxImage, "echo", "hi").Assert(c, icmd.Success)
153+
defer DelContainerForceMultyTime(c, name)
154+
155+
output := command.PouchRun("inspect", name).Stdout()
156+
result := []types.ContainerJSON{}
157+
if err := json.Unmarshal([]byte(output), &result); err != nil {
158+
c.Errorf("failed to decode inspect output: %v", err)
159+
}
160+
c.Assert(result[0].State.Pid, check.Equals, int64(0))
161+
}

0 commit comments

Comments
 (0)