diff options
author | Matthew Heon <mheon@redhat.com> | 2019-04-25 16:23:09 -0400 |
---|---|---|
committer | Matthew Heon <mheon@redhat.com> | 2019-04-25 16:23:09 -0400 |
commit | 04d6ff058270006b98961e0f973ff6ee4c3ba8e8 (patch) | |
tree | a929615470ee8c220f95512f194054d145656be7 /libpod/events | |
parent | a01c62fcbde1afdc77aa05b71c3c84ddacf7fc55 (diff) | |
download | podman-04d6ff058270006b98961e0f973ff6ee4c3ba8e8.tar.gz podman-04d6ff058270006b98961e0f973ff6ee4c3ba8e8.tar.bz2 podman-04d6ff058270006b98961e0f973ff6ee4c3ba8e8.zip |
Add System event type and renumber, refresh events
Also, re-add locking to file eventer Write() to protect against
concurrent events.
Signed-off-by: Matthew Heon <mheon@redhat.com>
Diffstat (limited to 'libpod/events')
-rw-r--r-- | libpod/events/config.go | 9 | ||||
-rw-r--r-- | libpod/events/events.go | 10 | ||||
-rw-r--r-- | libpod/events/events_linux.go | 5 | ||||
-rw-r--r-- | libpod/events/logfile.go | 8 |
4 files changed, 31 insertions, 1 deletions
diff --git a/libpod/events/config.go b/libpod/events/config.go index d3b6d8c50..36387e835 100644 --- a/libpod/events/config.go +++ b/libpod/events/config.go @@ -84,6 +84,9 @@ const ( Image Type = "image" // Pod - event is related to pods Pod Type = "pod" + // System - event is related to Podman whole and not to any specific + // container/pod/image/volume + System Type = "system" // Volume - event is related to volumes Volume Type = "volume" @@ -123,8 +126,14 @@ const ( Pull Status = "pull" // Push ... Push Status = "push" + // Refresh indicates that the system refreshed the state after a + // reboot. + Refresh Status = "refresh" // Remove ... Remove Status = "remove" + // Renumber indicates that lock numbers were reallocated at user + // request. + Renumber Status = "renumber" // Restore ... Restore Status = "restore" // Save ... diff --git a/libpod/events/events.go b/libpod/events/events.go index e8c61faa0..533eccbb8 100644 --- a/libpod/events/events.go +++ b/libpod/events/events.go @@ -49,6 +49,8 @@ func (e *Event) ToHumanReadable() string { humanFormat = fmt.Sprintf("%s %s %s %s (image=%s, name=%s)", e.Time, e.Type, e.Status, e.ID, e.Image, e.Name) case Image: humanFormat = fmt.Sprintf("%s %s %s %s %s", e.Time, e.Type, e.Status, e.ID, e.Name) + case System: + humanFormat = fmt.Sprintf("%s %s %s", e.Time, e.Type, e.Status) case Volume: humanFormat = fmt.Sprintf("%s %s %s %s", e.Time, e.Type, e.Status, e.Name) } @@ -85,6 +87,8 @@ func StringToType(name string) (Type, error) { return Image, nil case Pod.String(): return Pod, nil + case System.String(): + return System, nil case Volume.String(): return Volume, nil } @@ -135,8 +139,14 @@ func StringToStatus(name string) (Status, error) { return Pull, nil case Push.String(): return Push, nil + case Refresh.String(): + return Refresh, nil case Remove.String(): return Remove, nil + case Renumber.String(): + return Renumber, nil + case Restore.String(): + return Restore, nil case Save.String(): return Save, nil case Start.String(): diff --git a/libpod/events/events_linux.go b/libpod/events/events_linux.go index d6898145c..da5d7965e 100644 --- a/libpod/events/events_linux.go +++ b/libpod/events/events_linux.go @@ -1,13 +1,16 @@ package events import ( - "github.com/pkg/errors" "strings" + + "github.com/pkg/errors" + "github.com/sirupsen/logrus" ) // NewEventer creates an eventer based on the eventer type func NewEventer(options EventerOptions) (Eventer, error) { var eventer Eventer + logrus.Debugf("Initializing event backend %s", options.EventerType) switch strings.ToUpper(options.EventerType) { case strings.ToUpper(Journald.String()): eventer = EventJournalD{options} diff --git a/libpod/events/logfile.go b/libpod/events/logfile.go index 3232b86d0..e5efc09bb 100644 --- a/libpod/events/logfile.go +++ b/libpod/events/logfile.go @@ -4,6 +4,7 @@ import ( "fmt" "os" + "github.com/containers/storage" "github.com/pkg/errors" ) @@ -15,6 +16,13 @@ type EventLogFile struct { // Writes to the log file func (e EventLogFile) Write(ee Event) error { + // We need to lock events file + lock, err := storage.GetLockfile(e.options.LogFilePath + ".lock") + if err != nil { + return err + } + lock.Lock() + defer lock.Unlock() f, err := os.OpenFile(e.options.LogFilePath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0700) if err != nil { return err |