From e9f251538363771530c0288cbdb2c1238da8cd7a Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Sun, 19 Feb 2023 22:06:32 +0100 Subject: [PATCH] cgroup: rmdir the entire systemd scope commit 7ea76174986bf5e19715a43cdffff1724ee27236 caused a regression on cgroup v1, and some directories that are created manually are not cleaned up on container termination causing a cgroup leak. Fix it by deleting the entire systemd scope directory instead of deleting only the final cgroup. Closes: https://github.com/containers/crun/issues/1144 Signed-off-by: Giuseppe Scrivano --- src/libcrun/cgroup-systemd.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/libcrun/cgroup-systemd.c b/src/libcrun/cgroup-systemd.c index 5335178967..4fc1c61dc7 100644 --- a/src/libcrun/cgroup-systemd.c +++ b/src/libcrun/cgroup-systemd.c @@ -955,6 +955,8 @@ static int libcrun_destroy_cgroup_systemd (struct libcrun_cgroup_status *cgroup_status, libcrun_error_t *err) { + cleanup_free char *path_to_scope = NULL; + char *tmp; int mode; int ret; @@ -970,7 +972,12 @@ libcrun_destroy_cgroup_systemd (struct libcrun_cgroup_status *cgroup_status, if (UNLIKELY (ret < 0)) crun_error_release (err); - return destroy_cgroup_path (cgroup_status->path, mode, err); + path_to_scope = xstrdup (cgroup_status->path); + tmp = strstr (path_to_scope, cgroup_status->scope); + if (tmp) + tmp[strlen(cgroup_status->scope)] = '\0'; + + return destroy_cgroup_path (path_to_scope, mode, err); } static int