From 21cddd72353dc6ce33665deb80daeede00ff7376 Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Wed, 15 Feb 2023 21:00:26 +0100 Subject: [PATCH] journald: remove initializeJournal() This was added as hack in commit 6b06e9b77c because the journald logs code was not able to handle an empty journal. But since commit 767947ab88 this is no longer the case, we correctly use the sd_journal API and know when the journal is empty. Therefore we no longer need this hack and it should be removed because it just adds overhead and an empty journal entry for no good reason. [NO NEW TESTS NEEDED] Signed-off-by: Paul Holzinger --- libpod/container_log_linux.go | 16 ---------------- libpod/container_log_unsupported.go | 4 ---- libpod/runtime_ctr.go | 6 +----- 3 files changed, 1 insertion(+), 25 deletions(-) diff --git a/libpod/container_log_linux.go b/libpod/container_log_linux.go index de5a66dee1..dc305fabfd 100644 --- a/libpod/container_log_linux.go +++ b/libpod/container_log_linux.go @@ -15,7 +15,6 @@ import ( "github.com/containers/podman/v4/libpod/events" "github.com/containers/podman/v4/libpod/logs" "github.com/containers/podman/v4/pkg/rootless" - "github.com/coreos/go-systemd/v22/journal" "github.com/coreos/go-systemd/v22/sdjournal" "github.com/sirupsen/logrus" ) @@ -32,21 +31,6 @@ func init() { logDrivers = append(logDrivers, define.JournaldLogging) } -// initializeJournal will write an empty string to the journal -// when a journal is created. This solves a problem when people -// attempt to read logs from a container that has never had stdout/stderr -func (c *Container) initializeJournal(ctx context.Context) error { - m := make(map[string]string) - m["SYSLOG_IDENTIFIER"] = "podman" - m["PODMAN_ID"] = c.ID() - history := events.History - m["PODMAN_EVENT"] = history.String() - container := events.Container - m["PODMAN_TYPE"] = container.String() - m["PODMAN_TIME"] = time.Now().Format(time.RFC3339Nano) - return journal.Send("", journal.PriInfo, m) -} - func (c *Container) readFromJournal(ctx context.Context, options *logs.LogOptions, logChannel chan *logs.LogLine, colorID int64) error { // We need the container's events in the same journal to guarantee // consistency, see #10323. diff --git a/libpod/container_log_unsupported.go b/libpod/container_log_unsupported.go index bb74a810d5..cdce820b4f 100644 --- a/libpod/container_log_unsupported.go +++ b/libpod/container_log_unsupported.go @@ -14,7 +14,3 @@ import ( func (c *Container) readFromJournal(_ context.Context, _ *logs.LogOptions, _ chan *logs.LogLine, colorID int64) error { return fmt.Errorf("journald logging only enabled with systemd on linux: %w", define.ErrOSNotSupported) } - -func (c *Container) initializeJournal(ctx context.Context) error { - return fmt.Errorf("journald logging only enabled with systemd on linux: %w", define.ErrOSNotSupported) -} diff --git a/libpod/runtime_ctr.go b/libpod/runtime_ctr.go index caa4a2c7a1..2ff9dfb280 100644 --- a/libpod/runtime_ctr.go +++ b/libpod/runtime_ctr.go @@ -541,12 +541,8 @@ func (r *Runtime) setupContainer(ctx context.Context, ctr *Container) (_ *Contai } switch ctr.config.LogDriver { - case define.NoLogging, define.PassthroughLogging: + case define.NoLogging, define.PassthroughLogging, define.JournaldLogging: break - case define.JournaldLogging: - if err := ctr.initializeJournal(ctx); err != nil { - return nil, fmt.Errorf("failed to initialize journal: %w", err) - } default: if ctr.config.LogPath == "" { ctr.config.LogPath = filepath.Join(ctr.config.StaticDir, "ctr.log")