mirror of
https://github.com/containers/podman.git
synced 2025-05-22 01:27:07 +08:00
Store Conmon's PID in our state and display in inspect
Signed-off-by: Matthew Heon <matthew.heon@pm.me>
This commit is contained in:
@ -168,6 +168,8 @@ type ContainerState struct {
|
|||||||
OOMKilled bool `json:"oomKilled,omitempty"`
|
OOMKilled bool `json:"oomKilled,omitempty"`
|
||||||
// PID is the PID of a running container
|
// PID is the PID of a running container
|
||||||
PID int `json:"pid,omitempty"`
|
PID int `json:"pid,omitempty"`
|
||||||
|
// ConmonPID is the PID of the container's conmon
|
||||||
|
ConmonPID int `json:"conmonPid,omitempty"`
|
||||||
// ExecSessions contains active exec sessions for container
|
// ExecSessions contains active exec sessions for container
|
||||||
// Exec session ID is mapped to PID of exec process
|
// Exec session ID is mapped to PID of exec process
|
||||||
ExecSessions map[string]*ExecSession `json:"execSessions,omitempty"`
|
ExecSessions map[string]*ExecSession `json:"execSessions,omitempty"`
|
||||||
@ -849,7 +851,7 @@ func (c *Container) OOMKilled() (bool, error) {
|
|||||||
return c.state.OOMKilled, nil
|
return c.state.OOMKilled, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// PID returns the PID of the container
|
// PID returns the PID of the container.
|
||||||
// If the container is not running, a pid of 0 will be returned. No error will
|
// If the container is not running, a pid of 0 will be returned. No error will
|
||||||
// occur.
|
// occur.
|
||||||
func (c *Container) PID() (int, error) {
|
func (c *Container) PID() (int, error) {
|
||||||
@ -865,6 +867,22 @@ func (c *Container) PID() (int, error) {
|
|||||||
return c.state.PID, nil
|
return c.state.PID, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ConmonPID Returns the PID of the container's conmon process.
|
||||||
|
// If the container is not running, a PID of 0 will be returned. No error will
|
||||||
|
// occur.
|
||||||
|
func (c *Container) ConmonPID() (int, error) {
|
||||||
|
if !c.batched {
|
||||||
|
c.lock.Lock()
|
||||||
|
defer c.lock.Unlock()
|
||||||
|
|
||||||
|
if err := c.syncContainer(); err != nil {
|
||||||
|
return -1, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.state.ConmonPID, nil
|
||||||
|
}
|
||||||
|
|
||||||
// ExecSessions retrieves active exec sessions running in the container
|
// ExecSessions retrieves active exec sessions running in the container
|
||||||
func (c *Container) ExecSessions() ([]string, error) {
|
func (c *Container) ExecSessions() ([]string, error) {
|
||||||
if !c.batched {
|
if !c.batched {
|
||||||
|
@ -145,6 +145,7 @@ type InspectContainerState struct {
|
|||||||
OOMKilled bool `json:"OOMKilled"`
|
OOMKilled bool `json:"OOMKilled"`
|
||||||
Dead bool `json:"Dead"`
|
Dead bool `json:"Dead"`
|
||||||
Pid int `json:"Pid"`
|
Pid int `json:"Pid"`
|
||||||
|
ConmonPid int `json:"ConmonPid,omitempty"`
|
||||||
ExitCode int32 `json:"ExitCode"`
|
ExitCode int32 `json:"ExitCode"`
|
||||||
Error string `json:"Error"` // TODO
|
Error string `json:"Error"` // TODO
|
||||||
StartedAt time.Time `json:"StartedAt"`
|
StartedAt time.Time `json:"StartedAt"`
|
||||||
@ -261,6 +262,7 @@ func (c *Container) getContainerInspectData(size bool, driverData *driver.Data)
|
|||||||
OOMKilled: runtimeInfo.OOMKilled,
|
OOMKilled: runtimeInfo.OOMKilled,
|
||||||
Dead: runtimeInfo.State.String() == "bad state",
|
Dead: runtimeInfo.State.String() == "bad state",
|
||||||
Pid: runtimeInfo.PID,
|
Pid: runtimeInfo.PID,
|
||||||
|
ConmonPid: runtimeInfo.ConmonPID,
|
||||||
ExitCode: runtimeInfo.ExitCode,
|
ExitCode: runtimeInfo.ExitCode,
|
||||||
Error: "", // can't get yet
|
Error: "", // can't get yet
|
||||||
StartedAt: runtimeInfo.StartedTime,
|
StartedAt: runtimeInfo.StartedTime,
|
||||||
|
@ -452,6 +452,7 @@ func (c *Container) teardownStorage() error {
|
|||||||
// It does not save the results - assumes the database will do that for us
|
// It does not save the results - assumes the database will do that for us
|
||||||
func resetState(state *ContainerState) error {
|
func resetState(state *ContainerState) error {
|
||||||
state.PID = 0
|
state.PID = 0
|
||||||
|
state.ConmonPID = 0
|
||||||
state.Mountpoint = ""
|
state.Mountpoint = ""
|
||||||
state.Mounted = false
|
state.Mounted = false
|
||||||
if state.State != define.ContainerStateExited {
|
if state.State != define.ContainerStateExited {
|
||||||
|
@ -446,6 +446,9 @@ func (r *OCIRuntime) createOCIContainer(ctr *Container, cgroupParent string, res
|
|||||||
return errors.Wrapf(define.ErrInternal, "container create failed")
|
return errors.Wrapf(define.ErrInternal, "container create failed")
|
||||||
}
|
}
|
||||||
ctr.state.PID = ss.si.Pid
|
ctr.state.PID = ss.si.Pid
|
||||||
|
if cmd.Process != nil {
|
||||||
|
ctr.state.ConmonPID = cmd.Process.Pid
|
||||||
|
}
|
||||||
case <-time.After(ContainerCreateTimeout):
|
case <-time.After(ContainerCreateTimeout):
|
||||||
return errors.Wrapf(define.ErrInternal, "container creation timeout")
|
return errors.Wrapf(define.ErrInternal, "container creation timeout")
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user