From 2d1dd69d6d0b0771033c39bdd1d77ea5c7f1977e Mon Sep 17 00:00:00 2001 From: luckyevildev Date: Wed, 30 Oct 2024 14:37:01 +0300 Subject: [PATCH] Remove exit file from persistent storage Signed-off-by: luckyevildev --- libpod/container_internal.go | 14 ++++++++++++++ libpod/oci.go | 3 +++ libpod/oci_conmon_common.go | 4 ++++ libpod/oci_missing.go | 4 ++++ 4 files changed, 25 insertions(+) diff --git a/libpod/container_internal.go b/libpod/container_internal.go index c7efd18e4b..ec8d391d80 100644 --- a/libpod/container_internal.go +++ b/libpod/container_internal.go @@ -149,6 +149,10 @@ func (c *Container) exitFilePath() (string, error) { return c.ociRuntime.ExitFilePath(c) } +func (c *Container) persistExitFilePath() (string, error) { + return c.ociRuntime.PersistExitFilePath(c) +} + func (c *Container) oomFilePath() (string, error) { return c.ociRuntime.OOMFilePath(c) } @@ -759,6 +763,7 @@ func (c *Container) removeConmonFiles() error { // Remove the exit file so we don't leak memory in tmpfs exitFile, err := c.exitFilePath() + if err != nil { return err } @@ -775,6 +780,15 @@ func (c *Container) removeConmonFiles() error { return fmt.Errorf("removing container %s oom file: %w", c.ID(), err) } + // Remove exit file from persistent storage + persistExitFilePath, err := c.persistExitFilePath() + if err != nil { + return err + } + if err := os.Remove(persistExitFilePath); err != nil && !errors.Is(err, fs.ErrNotExist) { + return fmt.Errorf("removing container %s persist exit file: %w", c.ID(), err) + } + return nil } diff --git a/libpod/oci.go b/libpod/oci.go index e0d7406339..4f65b683c0 100644 --- a/libpod/oci.go +++ b/libpod/oci.go @@ -147,6 +147,9 @@ type OCIRuntime interface { //nolint:interfacebloat // This is the path to that file for a given container. ExitFilePath(ctr *Container) (string, error) + // PersistExitFilePath is the path to a container's persistent exit file. + PersistExitFilePath(ctr *Container) (string, error) + // OOMFilePath is the path to a container's oom file if it was oom killed. // An oom file is only created when the container is oom killed. The existence // of this file means that the container was oom killed. diff --git a/libpod/oci_conmon_common.go b/libpod/oci_conmon_common.go index 8aa103fb49..03c0c4a4fd 100644 --- a/libpod/oci_conmon_common.go +++ b/libpod/oci_conmon_common.go @@ -862,6 +862,10 @@ func (r *ConmonOCIRuntime) OOMFilePath(ctr *Container) (string, error) { return filepath.Join(r.persistDir, ctr.ID(), "oom"), nil } +func (r *ConmonOCIRuntime) PersistExitFilePath(ctr *Container) (string, error) { + return filepath.Join(r.persistDir, ctr.ID(), "exit"), nil +} + // RuntimeInfo provides information on the runtime. func (r *ConmonOCIRuntime) RuntimeInfo() (*define.ConmonInfo, *define.OCIRuntimeInfo, error) { runtimePackage := version.Package(r.path) diff --git a/libpod/oci_missing.go b/libpod/oci_missing.go index 98eb91ef8d..3bcb2d2eec 100644 --- a/libpod/oci_missing.go +++ b/libpod/oci_missing.go @@ -220,6 +220,10 @@ func (r *MissingRuntime) ExitFilePath(ctr *Container) (string, error) { return filepath.Join(r.exitsDir, ctr.ID()), nil } +func (r *MissingRuntime) PersistExitFilePath(ctr *Container) (string, error) { + return filepath.Join(r.persistDir, ctr.ID(), "exit"), nil +} + // OOMFilePath returns the oom file path for a container. // The oom file will only exist if the container was oom killed. func (r *MissingRuntime) OOMFilePath(ctr *Container) (string, error) {