Skip to content

Commit 2c30069

Browse files
chenk008kolyshkin
authored andcommitted
libct/cg/sd/v2: Destroy: remove cgroups recursively
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: #3225 Signed-off-by: Kang Chen <[email protected]> [kolyshkin: cherry picked from commit 7758d3f, changing the code to use cgroups.RemovePath().] Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent 02d2e1f commit 2c30069

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

  • libcontainer/cgroups/systemd

libcontainer/cgroups/systemd/v2.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package systemd
55
import (
66
"fmt"
77
"math"
8-
"os"
98
"path/filepath"
109
"strconv"
1110
"strings"
@@ -307,9 +306,10 @@ func (m *unifiedManager) Destroy() error {
307306
return err
308307
}
309308

310-
// XXX this is probably not needed, systemd should handle it
311-
err := os.Remove(m.path)
312-
if err != nil && !os.IsNotExist(err) {
309+
// systemd 239 do not remove sub-cgroups.
310+
err := cgroups.RemovePath(m.path)
311+
// cgroups.RemovePath has handled ErrNotExist
312+
if err != nil {
313313
return err
314314
}
315315

0 commit comments

Comments
 (0)