From b2408baa8c867055b5b0f42b12ebe52f26cd56b0 Mon Sep 17 00:00:00 2001 From: Michael Wan Date: Mon, 3 Sep 2018 02:39:36 -0400 Subject: [PATCH] bugfix: set pid of stopped container to 0 Signed-off-by: Michael Wan --- daemon/mgr/container_state.go | 4 ++-- test/cli_stop_test.go | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/daemon/mgr/container_state.go b/daemon/mgr/container_state.go index 8f1cfc12e9..394a4221ab 100644 --- a/daemon/mgr/container_state.go +++ b/daemon/mgr/container_state.go @@ -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) @@ -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) diff --git a/test/cli_stop_test.go b/test/cli_stop_test.go index 3d3aba08b2..9d73cd6da1 100644 --- a/test/cli_stop_test.go +++ b/test/cli_stop_test.go @@ -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)) +}