summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@gmail.com>2018-01-12 16:25:42 -0500
committerAtomic Bot <atomic-devel@projectatomic.io>2018-01-14 12:27:33 +0000
commit3ab8eb2e9b4a760b89a7e7ff417b0b6e30f738aa (patch)
treeba90cb038579ebb59cd7e4241a12e090d46e951c
parent149640a4c86f604c2fc56a67df52ca8b64c76e83 (diff)
downloadpodman-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
-rw-r--r--libpod/container.go33
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
+}