Skip to content

Commit

Permalink
cgroup: make cgroup_path() not print double slashes
Browse files Browse the repository at this point in the history
While reimplementing cgroup_path(), 65dff75 ("cgroup: fix
cgroup_path() vs rename() race") introduced a bug where the path of a
non-root cgroup would have two slahses at the beginning, which is
caused by treating the root cgroup which has the name '/' like
non-root cgroups.

 $ grep systemd /proc/self/cgroup
 1:name=systemd://user/root/1

Fix it by special casing root cgroup case and not looping over it in
the normal path.

Signed-off-by: Tejun Heo <[email protected]>
Cc: Li Zefan <[email protected]>
  • Loading branch information
htejun committed Apr 14, 2013
1 parent 26d5bbe commit da1f296
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions kernel/cgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -1811,11 +1811,17 @@ int cgroup_path(const struct cgroup *cgrp, char *buf, int buflen)
int ret = -ENAMETOOLONG;
char *start;

if (!cgrp->parent) {
if (strlcpy(buf, "/", buflen) >= buflen)
return -ENAMETOOLONG;
return 0;
}

start = buf + buflen - 1;
*start = '\0';

rcu_read_lock();
while (cgrp) {
do {
const char *name = cgroup_name(cgrp);
int len;

Expand All @@ -1824,15 +1830,12 @@ int cgroup_path(const struct cgroup *cgrp, char *buf, int buflen)
goto out;
memcpy(start, name, len);

if (!cgrp->parent)
break;

if (--start < buf)
goto out;
*start = '/';

cgrp = cgrp->parent;
}
} while (cgrp->parent);
ret = 0;
memmove(buf, start, buf + buflen - start);
out:
Expand Down

0 comments on commit da1f296

Please sign in to comment.