summaryrefslogtreecommitdiff
path: root/libpod/container_api.go
diff options
context:
space:
mode:
Diffstat (limited to 'libpod/container_api.go')
-rw-r--r--libpod/container_api.go22
1 files changed, 21 insertions, 1 deletions
diff --git a/libpod/container_api.go b/libpod/container_api.go
index 1e233109b..17cd68972 100644
--- a/libpod/container_api.go
+++ b/libpod/container_api.go
@@ -219,9 +219,16 @@ func (c *Container) Kill(signal uint) error {
func (c *Container) Exec(tty, privileged bool, env, cmd []string, user string) error {
var capList []string
+ locked := false
if !c.locked {
+ locked = true
+
c.lock.Lock()
- defer c.lock.Unlock()
+ defer func() {
+ if locked {
+ c.lock.Unlock()
+ }
+ }()
if err := c.syncContainer(); err != nil {
return err
@@ -309,8 +316,21 @@ func (c *Container) Exec(tty, privileged bool, env, cmd []string, user string) e
return errors.Wrapf(err, "error saving exec sessions %s for container %s", sessionID, c.ID())
}
+ // Unlock so other processes can use the container
+ c.lock.Unlock()
+ locked = false
+
waitErr := execCmd.Wait()
+ // Lock again
+ locked = true
+ c.lock.Lock()
+
+ // Sync the container again to pick up changes in state
+ if err := c.syncContainer(); err != nil {
+ return errors.Wrapf(err, "error syncing container %s state to remove exec session %s", c.ID(), sessionID)
+ }
+
// Remove the exec session from state
delete(c.state.ExecSessions, sessionID)
if err := c.save(); err != nil {