Merge pull request #1002 from crosbymichael/stopped

Return 0 for pid if container is stopped
This commit is contained in:
Daniel, Dao Quang Minh 2016-08-25 18:18:32 +01:00 committed by GitHub
commit 91dd6d2452
2 changed files with 12 additions and 2 deletions

View File

@ -12,6 +12,7 @@ import (
"encoding/json" "encoding/json"
"github.com/opencontainers/runc/libcontainer"
"github.com/opencontainers/runc/libcontainer/utils" "github.com/opencontainers/runc/libcontainer/utils"
"github.com/urfave/cli" "github.com/urfave/cli"
) )
@ -130,10 +131,14 @@ func getContainers(context *cli.Context) ([]containerState, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
pid := state.BaseState.InitProcessPid
if containerStatus == libcontainer.Stopped {
pid = 0
}
bundle, annotations := utils.Annotations(state.Config.Labels) bundle, annotations := utils.Annotations(state.Config.Labels)
s = append(s, containerState{ s = append(s, containerState{
ID: state.BaseState.ID, ID: state.BaseState.ID,
InitProcessPid: state.BaseState.InitProcessPid, InitProcessPid: pid,
Status: containerStatus.String(), Status: containerStatus.String(),
Bundle: bundle, Bundle: bundle,
Created: state.BaseState.Created, Created: state.BaseState.Created,

View File

@ -7,6 +7,7 @@ import (
"os" "os"
"time" "time"
"github.com/opencontainers/runc/libcontainer"
"github.com/opencontainers/runc/libcontainer/utils" "github.com/opencontainers/runc/libcontainer/utils"
"github.com/urfave/cli" "github.com/urfave/cli"
) )
@ -55,11 +56,15 @@ instance of a container.`,
if err != nil { if err != nil {
return err return err
} }
pid := state.BaseState.InitProcessPid
if containerStatus == libcontainer.Stopped {
pid = 0
}
bundle, annotations := utils.Annotations(state.Config.Labels) bundle, annotations := utils.Annotations(state.Config.Labels)
cs := cState{ cs := cState{
Version: state.BaseState.Config.Version, Version: state.BaseState.Config.Version,
ID: state.BaseState.ID, ID: state.BaseState.ID,
InitProcessPid: state.BaseState.InitProcessPid, InitProcessPid: pid,
Status: containerStatus.String(), Status: containerStatus.String(),
Bundle: bundle, Bundle: bundle,
Rootfs: state.BaseState.Config.Rootfs, Rootfs: state.BaseState.Config.Rootfs,