From 81088012475cef5fbc136af1767d9d5a7327ee66 Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Fri, 29 Mar 2019 12:51:37 -0400 Subject: Add locking to ensure events file is concurrency-safe Signed-off-by: Matthew Heon --- libpod/events/events.go | 8 ++++++++ 1 file changed, 8 insertions(+) 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 -- cgit v1.2.3-54-g00ecf