diff options
author | Matthew Heon <matthew.heon@gmail.com> | 2018-02-23 15:28:56 -0500 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2018-03-01 21:17:50 +0000 |
commit | 2a0c949b9bab88f4e05d39b5e6d7db62bb39df11 (patch) | |
tree | 35c75dcf96b4d571c29daafb54c6bc0c4be29c41 /libpod/container.go | |
parent | 920b66707ece354b8dbf00416b5a26abdee93a2f (diff) | |
download | podman-2a0c949b9bab88f4e05d39b5e6d7db62bb39df11.tar.gz podman-2a0c949b9bab88f4e05d39b5e6d7db62bb39df11.tar.bz2 podman-2a0c949b9bab88f4e05d39b5e6d7db62bb39df11.zip |
Add tracking for container exec sessions to DB
Signed-off-by: Matthew Heon <matthew.heon@gmail.com>
Closes: #412
Approved by: baude
Diffstat (limited to 'libpod/container.go')
-rw-r--r-- | libpod/container.go | 26 |
1 files changed, 25 insertions, 1 deletions
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 |