Skip to content

Commit 0ee1d49

Browse files
Merge pull request #25836 from TomSweeneyRedHat/dev/tsweeney/cleantmp
[v5.4-rhel] Remove persist directory when cleaning up Conmon files
2 parents a994a04 + 7b53a64 commit 0ee1d49

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

libpod/container_internal.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ func (c *Container) oomFilePath() (string, error) {
153153
return c.ociRuntime.OOMFilePath(c)
154154
}
155155

156+
func (c *Container) persistDirPath() (string, error) {
157+
return c.ociRuntime.PersistDirectoryPath(c)
158+
}
159+
156160
// Wait for the container's exit file to appear.
157161
// When it does, update our state based on it.
158162
func (c *Container) waitForExitFileAndSync() error {
@@ -766,13 +770,15 @@ func (c *Container) removeConmonFiles() error {
766770
return fmt.Errorf("removing container %s exit file: %w", c.ID(), err)
767771
}
768772

769-
// Remove the oom file
770-
oomFile, err := c.oomFilePath()
773+
// Remove the persist directory
774+
persistDir, err := c.persistDirPath()
771775
if err != nil {
772776
return err
773777
}
774-
if err := os.Remove(oomFile); err != nil && !errors.Is(err, fs.ErrNotExist) {
775-
return fmt.Errorf("removing container %s oom file: %w", c.ID(), err)
778+
if persistDir != "" {
779+
if err := os.RemoveAll(persistDir); err != nil && !errors.Is(err, fs.ErrNotExist) {
780+
return fmt.Errorf("removing container %s persist directory: %w", c.ID(), err)
781+
}
776782
}
777783

778784
return nil

libpod/oci.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,14 @@ type OCIRuntime interface { //nolint:interfacebloat
153153
// This is the path to that file for a given container.
154154
OOMFilePath(ctr *Container) (string, error)
155155

156+
// PersistDirectoryPath is the path to a container's persist directory.
157+
// Not all OCI runtime implementations will have a persist directory.
158+
// If they do, it may contain files such as the exit file and the OOM
159+
// file.
160+
// If the directory does not exist, the empty string and no error should
161+
// be returned.
162+
PersistDirectoryPath(ctr *Container) (string, error)
163+
156164
// RuntimeInfo returns verbose information about the runtime.
157165
RuntimeInfo() (*define.ConmonInfo, *define.OCIRuntimeInfo, error)
158166

libpod/oci_conmon_common.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,11 @@ func (r *ConmonOCIRuntime) OOMFilePath(ctr *Container) (string, error) {
862862
return filepath.Join(r.persistDir, ctr.ID(), "oom"), nil
863863
}
864864

865+
// PersistDirectoryPath is the path to the container's persist directory.
866+
func (r *ConmonOCIRuntime) PersistDirectoryPath(ctr *Container) (string, error) {
867+
return filepath.Join(r.persistDir, ctr.ID()), nil
868+
}
869+
865870
// RuntimeInfo provides information on the runtime.
866871
func (r *ConmonOCIRuntime) RuntimeInfo() (*define.ConmonInfo, *define.OCIRuntimeInfo, error) {
867872
runtimePackage := version.Package(r.path)

libpod/oci_missing.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,12 @@ func (r *MissingRuntime) OOMFilePath(ctr *Container) (string, error) {
226226
return filepath.Join(r.persistDir, ctr.ID(), "oom"), nil
227227
}
228228

229+
// PersistDirectoryPath is the path to the container's persist directory.
230+
// It may include files like the exit file and OOM file.
231+
func (r *MissingRuntime) PersistDirectoryPath(ctr *Container) (string, error) {
232+
return filepath.Join(r.persistDir, ctr.ID()), nil
233+
}
234+
229235
// RuntimeInfo returns information on the missing runtime
230236
func (r *MissingRuntime) RuntimeInfo() (*define.ConmonInfo, *define.OCIRuntimeInfo, error) {
231237
ocirt := define.OCIRuntimeInfo{

0 commit comments

Comments
 (0)