diff options
author | Matthew Heon <matthew.heon@gmail.com> | 2018-01-12 16:25:42 -0500 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2018-01-14 12:27:33 +0000 |
commit | 3ab8eb2e9b4a760b89a7e7ff417b0b6e30f738aa (patch) | |
tree | ba90cb038579ebb59cd7e4241a12e090d46e951c /libpod/container.go | |
parent | 149640a4c86f604c2fc56a67df52ca8b64c76e83 (diff) | |
download | podman-3ab8eb2e9b4a760b89a7e7ff417b0b6e30f738aa.tar.gz podman-3ab8eb2e9b4a760b89a7e7ff417b0b6e30f738aa.tar.bz2 podman-3ab8eb2e9b4a760b89a7e7ff417b0b6e30f738aa.zip |
Add Sync() function to updating ctr state in Batch()
Signed-off-by: Matthew Heon <matthew.heon@gmail.com>
Closes: #222
Approved by: rhatdan
Diffstat (limited to 'libpod/container.go')
-rw-r--r-- | libpod/container.go | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/libpod/container.go b/libpod/container.go index e26235e26..4fa0064c8 100644 --- a/libpod/container.go +++ b/libpod/container.go @@ -1351,6 +1351,9 @@ func (c *Container) StopTimeout() uint { // of Batch // Any error returned by the given batch function will be returned unmodified by // Batch +// As Batch normally disables updating the current state of the container, the +// Sync() function is provided to enable container state to be updated and +// checked within Batch. func (c *Container) Batch(batchFunc func(*Container) error) error { c.lock.Lock() defer c.lock.Unlock() @@ -1375,3 +1378,33 @@ func (c *Container) Batch(batchFunc func(*Container) error) error { return c.save() } + +// Sync updates the current state of the container, checking whether its state +// has changed +// Sync can only be used inside Batch() - otherwise, it will be done +// automatically. +// When called outside Batch(), Sync() is a no-op +func (c *Container) Sync() error { + if !c.locked { + return nil + } + + // If runc knows about the container, update its status in runc + // And then save back to disk + if (c.state.State != ContainerStateUnknown) && + (c.state.State != ContainerStateConfigured) { + oldState := c.state.State + // TODO: optionally replace this with a stat for the exit file + if err := c.runtime.ociRuntime.updateContainerStatus(c); err != nil { + return err + } + // Only save back to DB if state changed + if c.state.State != oldState { + if err := c.save(); err != nil { + return err + } + } + } + + return nil +} |