diff options
author | Matthew Heon <matthew.heon@gmail.com> | 2018-02-27 22:52:28 -0500 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2018-03-01 21:17:51 +0000 |
commit | fa5f99effa7dd2ef9fbd5287b6225590b28713d1 (patch) | |
tree | 240a4696de8a499ed7489b67fcbdf4674ca87d19 /libpod/container.go | |
parent | 83d7ae6506f7aaf1f7d543412a148b4bf4cd6657 (diff) | |
download | podman-fa5f99effa7dd2ef9fbd5287b6225590b28713d1.tar.gz podman-fa5f99effa7dd2ef9fbd5287b6225590b28713d1.tar.bz2 podman-fa5f99effa7dd2ef9fbd5287b6225590b28713d1.zip |
Convert exec session tracking to use a dedicated struct
This will behave better if we need to add anything to it at a
later date - we can add fields to the struct without breaking
existing BoltDB databases.
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 | 45 |
1 files changed, 38 insertions, 7 deletions
diff --git a/libpod/container.go b/libpod/container.go index 83a45d379..8dee0ae2e 100644 --- a/libpod/container.go +++ b/libpod/container.go @@ -143,7 +143,14 @@ type containerState struct { 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"` + ExecSessions map[string]*ExecSession `json:"execSessions,omitempty"` +} + +// ExecSession contains information on an active exec session +type ExecSession struct { + ID string `json:"id"` + Command []string `json:"command"` + PID int `json:"pid"` } // ContainerConfig contains all information that was used to create the @@ -593,8 +600,27 @@ func (c *Container) PID() (int, error) { } // 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) { +func (c *Container) ExecSessions() ([]string, error) { + if !c.locked { + c.lock.Lock() + defer c.lock.Unlock() + + if err := c.syncContainer(); err != nil { + return nil, err + } + } + + ids := make([]string, 0, len(c.state.ExecSessions)) + for id := range c.state.ExecSessions { + ids = append(ids, id) + } + + return ids, nil +} + +// ExecSession retrieves detailed information on a single active exec session in +// a container +func (c *Container) ExecSession(id string) (*ExecSession, error) { if !c.locked { c.lock.Lock() defer c.lock.Unlock() @@ -604,12 +630,17 @@ func (c *Container) ExecSessions() (map[string]int, error) { } } - returnMap := make(map[string]int, len(c.state.ExecSessions)) - for k, v := range c.state.ExecSessions { - returnMap[k] = v + session, ok := c.state.ExecSessions[id] + if !ok { + return nil, errors.Wrapf(ErrNoSuchCtr, "no exec session with ID %s found in container %s", id, c.ID()) } - return returnMap, nil + returnSession := new(ExecSession) + returnSession.ID = session.ID + returnSession.Command = session.Command + returnSession.PID = session.PID + + return returnSession, nil } // Misc Accessors |