From 2a0c949b9bab88f4e05d39b5e6d7db62bb39df11 Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Fri, 23 Feb 2018 15:28:56 -0500 Subject: Add tracking for container exec sessions to DB Signed-off-by: Matthew Heon Closes: #412 Approved by: baude --- libpod/container.go | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'libpod/container.go') diff --git a/libpod/container.go b/libpod/container.go index 42f13a992..83a45d379 100644 --- a/libpod/container.go +++ b/libpod/container.go @@ -141,6 +141,9 @@ type containerState struct { IPAddress string `json:"ipAddress"` // Subnet mask of container (if network namespace was created) SubnetMask string `json:"subnetMask"` + // ExecSessions contains active exec sessions for container + // Exec session ID is mapped to PID of exec process + ExecSessions map[string]int `json:"execSessions,omitempty"` } // ContainerConfig contains all information that was used to create the @@ -574,7 +577,8 @@ func (c *Container) OOMKilled() (bool, error) { } // PID returns the PID of the container -// An error is returned if the container is not running +// If the container is not running, a pid of 0 will be returned. No error will +// occur. func (c *Container) PID() (int, error) { if !c.locked { c.lock.Lock() @@ -588,6 +592,26 @@ func (c *Container) PID() (int, error) { return c.state.PID, nil } +// ExecSessions retrieves active exec sessions running in the container +// The result is a map from session ID to the PID of the exec process +func (c *Container) ExecSessions() (map[string]int, error) { + if !c.locked { + c.lock.Lock() + defer c.lock.Unlock() + + if err := c.syncContainer(); err != nil { + return nil, err + } + } + + returnMap := make(map[string]int, len(c.state.ExecSessions)) + for k, v := range c.state.ExecSessions { + returnMap[k] = v + } + + return returnMap, nil +} + // Misc Accessors // Most will require locking -- cgit v1.2.3-54-g00ecf