Skip to content

Commit

Permalink
libct/cg/sd/v2: Destroy: remove cgroups recursively
Browse files Browse the repository at this point in the history
Currently, we can create subcgroup in a rootless container with systemd cgroupv2 on centos8.
But after the container exited, the container cgroup and its subcgroup will not be removed.

Fix this by removing all directories recursively.

Fixes: opencontainers#3225

Signed-off-by: Kang Chen <kongchen28@gmail.com>
  • Loading branch information
chenk008 committed Oct 1, 2021
1 parent e999e29 commit 7758d3f
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions libcontainer/cgroups/systemd/v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package systemd
import (
"fmt"
"math"
"os"
"path/filepath"
"strconv"
"strings"
Expand Down Expand Up @@ -301,9 +300,10 @@ func (m *unifiedManager) Destroy() error {
return err
}

// XXX this is probably not needed, systemd should handle it
err := os.Remove(m.path)
if err != nil && !os.IsNotExist(err) {
// systemd 239 do not remove sub-cgroups.
err := m.fsMgr.Destroy()
// fsMgr.Destroy has handled ErrNotExist
if err != nil {
return err
}

Expand Down

0 comments on commit 7758d3f

Please sign in to comment.