summaryrefslogtreecommitdiff
path: root/libpod/container_internal_linux.go
blob: 41b8a86fc8cee9546e7da0e5d8237d598aa4ea42 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// +build linux

package libpod

import (
	"fmt"
	"path/filepath"

	"github.com/containerd/cgroups"
	"github.com/sirupsen/logrus"
)

// cleanupCgroup cleans up residual CGroups after container execution
// This is a no-op for the systemd cgroup driver
func (c *Container) cleanupCgroups() error {
	if !c.state.CgroupCreated {
		logrus.Debugf("Cgroups are not present, ignoring...")
		return nil
	}

	if c.runtime.config.CgroupManager == SystemdCgroupsManager {
		return nil
	}

	// Remove the base path of the container's cgroups
	path := filepath.Join(c.config.CgroupParent, fmt.Sprintf("libpod-%s", c.ID()))

	logrus.Debugf("Removing CGroup %s", path)

	cgroup, err := cgroups.Load(cgroups.V1, cgroups.StaticPath(path))
	if err != nil {
		// It's fine for the cgroup to not exist
		// We want it gone, it's gone
		if err == cgroups.ErrCgroupDeleted {
			return nil
		}

		return err
	}

	if err := cgroup.Delete(); err != nil {
		return err
	}

	c.state.CgroupCreated = false

	if c.valid {
		return c.save()
	}

	return nil
}