Skip to content

Commit

Permalink
Remove exit file from persistent storage
Browse files Browse the repository at this point in the history
Signed-off-by: luckyevildev <[email protected]>
  • Loading branch information
luckyevildev committed Oct 30, 2024
1 parent db6e837 commit 1f943ad
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
14 changes: 14 additions & 0 deletions libpod/container_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}

Expand Down
3 changes: 3 additions & 0 deletions libpod/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions libpod/oci_conmon_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1f943ad

Please sign in to comment.