summaryrefslogtreecommitdiff
path: root/libpod/container.go
diff options
context:
space:
mode:
authorValentin Rothberg <rothberg@redhat.com>2021-09-29 11:16:33 +0200
committerValentin Rothberg <rothberg@redhat.com>2021-09-29 13:44:55 +0200
commit30bf31010e4a6ca4247eef293a4202f6775d6ec9 (patch)
tree441ffbd18ee85a3685cbf54f8d7be4d01adc9553 /libpod/container.go
parent98176f001863fd138025c48625eda5c5adb26972 (diff)
downloadpodman-30bf31010e4a6ca4247eef293a4202f6775d6ec9.tar.gz
podman-30bf31010e4a6ca4247eef293a4202f6775d6ec9.tar.bz2
podman-30bf31010e4a6ca4247eef293a4202f6775d6ec9.zip
libpod: add execSessionNoCopy
To avoid creating an expensive deep copy, create an internal function to access the exec session. [NO TESTS NEEDED] Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
Diffstat (limited to 'libpod/container.go')
-rw-r--r--libpod/container.go17
1 files changed, 14 insertions, 3 deletions
diff --git a/libpod/container.go b/libpod/container.go
index ffc577950..4d15c04c5 100644
--- a/libpod/container.go
+++ b/libpod/container.go
@@ -774,9 +774,9 @@ func (c *Container) ExecSessions() ([]string, error) {
return ids, nil
}
-// ExecSession retrieves detailed information on a single active exec session in
-// a container
-func (c *Container) ExecSession(id string) (*ExecSession, error) {
+// execSessionNoCopy returns the associated exec session to id.
+// Note that the session is not a deep copy.
+func (c *Container) execSessionNoCopy(id string) (*ExecSession, error) {
if !c.batched {
c.lock.Lock()
defer c.lock.Unlock()
@@ -791,6 +791,17 @@ func (c *Container) ExecSession(id string) (*ExecSession, error) {
return nil, errors.Wrapf(define.ErrNoSuchExecSession, "no exec session with ID %s found in container %s", id, c.ID())
}
+ return session, nil
+}
+
+// ExecSession retrieves detailed information on a single active exec session in
+// a container
+func (c *Container) ExecSession(id string) (*ExecSession, error) {
+ session, err := c.execSessionNoCopy(id)
+ if err != nil {
+ return nil, err
+ }
+
returnSession := new(ExecSession)
if err := JSONDeepCopy(session, returnSession); err != nil {
return nil, errors.Wrapf(err, "error copying contents of container %s exec session %s", c.ID(), session.ID())