summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2019-03-29 12:16:00 -0700
committerGitHub <noreply@github.com>2019-03-29 12:16:00 -0700
commit053156534381ed394fa9e13a5c2f5e7115c6b6c7 (patch)
treee1442651b7b4c20a321256b179272c8ef0e7c388
parentf4d90a96cb7eabde3d999390619aae683e05b00e (diff)
parent81088012475cef5fbc136af1767d9d5a7327ee66 (diff)
downloadpodman-053156534381ed394fa9e13a5c2f5e7115c6b6c7.tar.gz
podman-053156534381ed394fa9e13a5c2f5e7115c6b6c7.tar.bz2
podman-053156534381ed394fa9e13a5c2f5e7115c6b6c7.zip
Merge pull request #2800 from mheon/lock_events_file
Add locking to ensure events file is concurrency-safe
-rw-r--r--libpod/events/events.go8
1 files changed, 8 insertions, 0 deletions
diff --git a/libpod/events/events.go b/libpod/events/events.go
index 7db36653e..fad129eff 100644
--- a/libpod/events/events.go
+++ b/libpod/events/events.go
@@ -6,6 +6,7 @@ import (
"os"
"time"
+ "github.com/containers/storage"
"github.com/pkg/errors"
)
@@ -122,6 +123,13 @@ func NewEvent(status Status) Event {
// Write will record the event to the given path
func (e *Event) Write(path string) error {
+ // We need to lock events file
+ lock, err := storage.GetLockfile(path + ".lock")
+ if err != nil {
+ return err
+ }
+ lock.Lock()
+ defer lock.Unlock()
f, err := os.OpenFile(path, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0700)
if err != nil {
return err