diff --git a/list.go b/list.go index c9610312..dc54ab15 100644 --- a/list.go +++ b/list.go @@ -12,6 +12,7 @@ import ( "encoding/json" + "github.com/opencontainers/runc/libcontainer" "github.com/opencontainers/runc/libcontainer/utils" "github.com/urfave/cli" ) @@ -130,10 +131,14 @@ func getContainers(context *cli.Context) ([]containerState, error) { if err != nil { return nil, err } + pid := state.BaseState.InitProcessPid + if containerStatus == libcontainer.Stopped { + pid = 0 + } bundle, annotations := utils.Annotations(state.Config.Labels) s = append(s, containerState{ ID: state.BaseState.ID, - InitProcessPid: state.BaseState.InitProcessPid, + InitProcessPid: pid, Status: containerStatus.String(), Bundle: bundle, Created: state.BaseState.Created, diff --git a/state.go b/state.go index 9bdb4af8..ddbb8c3f 100644 --- a/state.go +++ b/state.go @@ -7,6 +7,7 @@ import ( "os" "time" + "github.com/opencontainers/runc/libcontainer" "github.com/opencontainers/runc/libcontainer/utils" "github.com/urfave/cli" ) @@ -55,11 +56,15 @@ instance of a container.`, if err != nil { return err } + pid := state.BaseState.InitProcessPid + if containerStatus == libcontainer.Stopped { + pid = 0 + } bundle, annotations := utils.Annotations(state.Config.Labels) cs := cState{ Version: state.BaseState.Config.Version, ID: state.BaseState.ID, - InitProcessPid: state.BaseState.InitProcessPid, + InitProcessPid: pid, Status: containerStatus.String(), Bundle: bundle, Rootfs: state.BaseState.Config.Rootfs,