From 35ec95d84f50f0f6b1326ee3a4fd720f6cfd1744 Mon Sep 17 00:00:00 2001 From: "Mark A. Grondona" Date: Thu, 31 Oct 2024 23:59:45 +0000 Subject: [PATCH] imp: cgroup: fix relative cgroup paths in containers Problem: Relative paths for cgroups in /proc/self/cgroup may contain leading `/..` when the IMP is run inside some containers. This is because the path is relative to the container's mount point, not the actual mount point of the cgroupfs. Just strip the leading /.. from paths during discovery of the current cgroup path from `/proc/self/cgroup`. This should only apply in containers and thus CI. --- src/imp/cgroup.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/imp/cgroup.c b/src/imp/cgroup.c index a86c2cb..8591164 100644 --- a/src/imp/cgroup.c +++ b/src/imp/cgroup.c @@ -44,6 +44,13 @@ #include "cgroup.h" #include "imp_log.h" +static char *remove_leading_dotdot (char *relpath) +{ + while (strncmp (relpath, "/..", 3) == 0) + relpath += 3; + return relpath; +} + /* * Look up the current cgroup relative path from /proc/self/cgroup. * @@ -80,6 +87,11 @@ static int cgroup_init_path (struct cgroup_info *cgroup) /* Nullify subsys, relpath is already nul-terminated at newline */ *(relpath++) = '\0'; + /* Remove leading /.. in relpath. This could be due to cgroup + * mounted in a container. + */ + relpath = remove_leading_dotdot (relpath); + /* If unified cgroups are being used, then stop when we find * subsys="". Otherwise stop at subsys="name=systemd": */