From 5a17d671a49d96195f85ffe83c1d1a0d94608f38 Mon Sep 17 00:00:00 2001 From: Jose Carlos Venegas Munoz Date: Fri, 16 Aug 2019 08:37:17 -0500 Subject: [PATCH] cgroups: container: check cgroup path before use it The container CgroupsPath is optional acording to OCI. If for some reason the runtime decide to not define one. just skip cgroup operations. This is going to be useful for upcoming, sandbox cgroup only cgroup managment feature. Signed-off-by: Jose Carlos Venegas Munoz --- virtcontainers/container.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/virtcontainers/container.go b/virtcontainers/container.go index c7da8abfdc..57fad6c6fc 100644 --- a/virtcontainers/container.go +++ b/virtcontainers/container.go @@ -1471,6 +1471,12 @@ func (c *Container) cgroupsCreate() (err error) { // cgroupsDelete deletes the cgroups on the host for the associated container func (c *Container) cgroupsDelete() error { + + if c.state.CgroupPath == "" { + c.Logger().Debug("container does not have host cgroups: nothing to update") + return nil + } + cgroup, err := cgroupsLoadFunc(cgroups.V1, cgroups.StaticPath(c.state.CgroupPath)) @@ -1506,6 +1512,11 @@ func (c *Container) cgroupsDelete() error { // cgroupsUpdate updates cgroups on the host for the associated container func (c *Container) cgroupsUpdate(resources specs.LinuxResources) error { + + if c.state.CgroupPath == "" { + c.Logger().Debug("container does not have host cgroups: nothing to update") + return nil + } cgroup, err := cgroupsLoadFunc(cgroups.V1, cgroups.StaticPath(c.state.CgroupPath)) if err != nil {