summaryrefslogtreecommitdiff
path: root/libpod/events
diff options
context:
space:
mode:
authorPaul Holzinger <pholzing@redhat.com>2022-09-09 11:07:07 +0200
committerPaul Holzinger <pholzing@redhat.com>2022-09-12 18:05:11 +0200
commitc5bdb6afe741d34c32f779b6ef9508b6f1d05794 (patch)
treeaddc0b3a2b657e4fc4cd6de80f067f19c63609fc /libpod/events
parent5abc08df252037e2984a2b532f17ba78fdd876d4 (diff)
downloadpodman-c5bdb6afe741d34c32f779b6ef9508b6f1d05794.tar.gz
podman-c5bdb6afe741d34c32f779b6ef9508b6f1d05794.tar.bz2
podman-c5bdb6afe741d34c32f779b6ef9508b6f1d05794.zip
fix hang with podman events file logger
podman --events-backend file events --stream=false should never hang. The problem is that our tail library will wait for the file to be created which makes sense when we do not run with --stream=false. To fix this we can just always create the file when the logger is initialized. This would also help to report errors early on in case the file is not accessible. Fixes part one from #15688 Signed-off-by: Paul Holzinger <pholzing@redhat.com>
Diffstat (limited to 'libpod/events')
-rw-r--r--libpod/events/events_linux.go2
-rw-r--r--libpod/events/logfile.go18
2 files changed, 19 insertions, 1 deletions
diff --git a/libpod/events/events_linux.go b/libpod/events/events_linux.go
index e7801af5b..b11467aca 100644
--- a/libpod/events/events_linux.go
+++ b/libpod/events/events_linux.go
@@ -18,7 +18,7 @@ func NewEventer(options EventerOptions) (Eventer, error) {
}
return eventer, nil
case strings.ToUpper(LogFile.String()):
- return EventLogFile{options}, nil
+ return newLogFileEventer(options)
case strings.ToUpper(Null.String()):
return NewNullEventer(), nil
case strings.ToUpper(Memory.String()):
diff --git a/libpod/events/logfile.go b/libpod/events/logfile.go
index 519e16629..1b06e22e7 100644
--- a/libpod/events/logfile.go
+++ b/libpod/events/logfile.go
@@ -12,6 +12,7 @@ import (
"io/ioutil"
"os"
"path"
+ "path/filepath"
"time"
"github.com/containers/podman/v4/pkg/util"
@@ -27,6 +28,21 @@ type EventLogFile struct {
options EventerOptions
}
+// newLogFileEventer creates a new EventLogFile eventer
+func newLogFileEventer(options EventerOptions) (*EventLogFile, error) {
+ // Create events log dir
+ if err := os.MkdirAll(filepath.Dir(options.LogFilePath), 0700); err != nil {
+ return nil, fmt.Errorf("creating events dirs: %w", err)
+ }
+ // We have to make sure the file is created otherwise reading events will hang.
+ // https://github.com/containers/podman/issues/15688
+ fd, err := os.OpenFile(options.LogFilePath, os.O_RDONLY|os.O_CREATE, 0700)
+ if err != nil {
+ return nil, err
+ }
+ return &EventLogFile{options: options}, fd.Close()
+}
+
// Writes to the log file
func (e EventLogFile) Write(ee Event) error {
// We need to lock events file
@@ -108,6 +124,8 @@ func (e EventLogFile) Read(ctx context.Context, options ReadOptions) error {
}
}()
}
+ logrus.Debugf("Reading events from file %q", e.options.LogFilePath)
+
var line *tail.Line
var ok bool
for {