Skip to content

Commit 4294d88

Browse files
committed
Return 0 for pid if container is stopped
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
1 parent 46d9535 commit 4294d88

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

list.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
"encoding/json"
1414

15+
"github.com/opencontainers/runc/libcontainer"
1516
"github.com/opencontainers/runc/libcontainer/utils"
1617
"github.com/urfave/cli"
1718
)
@@ -130,10 +131,14 @@ func getContainers(context *cli.Context) ([]containerState, error) {
130131
if err != nil {
131132
return nil, err
132133
}
134+
pid := state.BaseState.InitProcessPid
135+
if containerStatus == libcontainer.Stopped {
136+
pid = 0
137+
}
133138
bundle, annotations := utils.Annotations(state.Config.Labels)
134139
s = append(s, containerState{
135140
ID: state.BaseState.ID,
136-
InitProcessPid: state.BaseState.InitProcessPid,
141+
InitProcessPid: pid,
137142
Status: containerStatus.String(),
138143
Bundle: bundle,
139144
Created: state.BaseState.Created,

state.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"os"
88
"time"
99

10+
"github.com/opencontainers/runc/libcontainer"
1011
"github.com/opencontainers/runc/libcontainer/utils"
1112
"github.com/urfave/cli"
1213
)
@@ -55,11 +56,15 @@ instance of a container.`,
5556
if err != nil {
5657
return err
5758
}
59+
pid := state.BaseState.InitProcessPid
60+
if containerStatus == libcontainer.Stopped {
61+
pid = 0
62+
}
5863
bundle, annotations := utils.Annotations(state.Config.Labels)
5964
cs := cState{
6065
Version: state.BaseState.Config.Version,
6166
ID: state.BaseState.ID,
62-
InitProcessPid: state.BaseState.InitProcessPid,
67+
InitProcessPid: pid,
6368
Status: containerStatus.String(),
6469
Bundle: bundle,
6570
Rootfs: state.BaseState.Config.Rootfs,

0 commit comments

Comments
 (0)