Add and use libpod/Container.Terminal() helper

This just gets ctr.config.Spec.Process.Terminal with some null checks,
allowing several places that open-coded this to use the helper.

In particular, this helps the code in
pkg/domain/infra/abi/terminal.StartAttachCtr(), that used to do:
`ctr.Spec().Process.Terminal`, which looks fine, but actually causes
a deep json copy in the `ctr.Spec()` call that takes over 3 msec.

[NO NEW TESTS NEEDED] Just minor performance effects

Signed-off-by: Alexander Larsson <alexl@redhat.com>
This commit is contained in:
Alexander Larsson
2022-10-11 16:38:42 +02:00
parent 2062ab9db4
commit 1038f063e0
6 changed files with 17 additions and 13 deletions

View File

@ -680,6 +680,14 @@ func (c *Container) WorkingDir() string {
return "/"
}
// Terminal returns true if the container has a terminal
func (c *Container) Terminal() bool {
if c.config.Spec != nil && c.config.Spec.Process != nil {
return c.config.Spec.Process.Terminal
}
return false
}
// State Accessors
// Require locking