Skip to content

Commit

Permalink
imp: cgroup: fix relative cgroup paths in containers
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
grondo committed Nov 1, 2024
1 parent 537cac2 commit d67ea07
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/imp/cgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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":
*/
Expand Down

0 comments on commit d67ea07

Please sign in to comment.