Skip to content

Commit

Permalink
Remove exit and oom from persist dir
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyevildev committed Oct 28, 2024
1 parent 19f7be8 commit 5ebc58c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
20 changes: 7 additions & 13 deletions libpod/container_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ func (c *Container) oomFilePath() (string, error) {
return c.ociRuntime.OOMFilePath(c)
}

func (c *Container) persistDir() (string, error) {
return c.ociRuntime.PersistDir(c)
}

// Wait for the container's exit file to appear.
// When it does, update our state based on it.
func (c *Container) waitForExitFileAndSync() error {
Expand Down Expand Up @@ -757,22 +761,12 @@ func (c *Container) removeConmonFiles() error {
return fmt.Errorf("removing container %s winsz file: %w", c.ID(), err)
}

// Remove the exit file so we don't leak memory in tmpfs
exitFile, err := c.exitFilePath()
if err != nil {
return err
}
if err := os.Remove(exitFile); err != nil && !os.IsNotExist(err) {
return fmt.Errorf("removing container %s exit file: %w", c.ID(), err)
}

// Remove the oom file
oomFile, err := c.oomFilePath()
persistDir, err := c.persistDir()
if err != nil {
return err
}
if err := os.Remove(oomFile); err != nil && !errors.Is(err, fs.ErrNotExist) {
return fmt.Errorf("removing container %s oom file: %w", c.ID(), err)
if err := os.RemoveAll(persistDir); err != nil && !errors.Is(err, fs.ErrNotExist) {
return fmt.Errorf("removing container %s persist dir with exit & oom files: %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 @@ -141,6 +141,9 @@ type OCIRuntime interface { //nolint:interfacebloat
// exec session in the given container.
// TODO: Probably should be made internal.
ExecAttachSocketPath(ctr *Container, sessionID string) (string, error)

// PersistDir is the path to a container's dir for oom & exit files.
PersistDir(ctr *Container) (string, error)
// ExitFilePath is the path to a container's exit file.
// All runtime implementations must create an exit file when containers
// exit, containing the exit code of the container (as a string).
Expand Down
9 changes: 9 additions & 0 deletions libpod/oci_conmon_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,15 @@ func (r *ConmonOCIRuntime) AttachSocketPath(ctr *Container) (string, error) {
return filepath.Join(ctr.bundlePath(), "attach"), nil
}

// PersistDir returns the persit dir containing oom & exit files for containers.
func (r *ConmonOCIRuntime) PersistDir(ctr *Container) (string, error) {
if ctr == nil {
return "", fmt.Errorf("must provide a valid container to get persist dir: %w", define.ErrInvalidArg)
}

return filepath.Join(r.persistDir, ctr.ID()), nil
}

// ExitFilePath is the path to a container's exit file.
func (r *ConmonOCIRuntime) ExitFilePath(ctr *Container) (string, error) {
if ctr == nil {
Expand Down

0 comments on commit 5ebc58c

Please sign in to comment.