diff --git a/src/imp/cgroup.c b/src/imp/cgroup.c index 0a1c797..c19e783 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; +} + /* * Looks up the 'pids'[*] subsystem relative cgroup path in * /proc/PID/cgroups and prepends `cgroup_mount_dir` to get the @@ -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": */