mirror of
https://github.com/torvalds/linux.git
synced 2024-11-11 14:42:24 +00:00
cgroup: make cgroup_path() not print double slashes
While reimplementing cgroup_path(), 65dff759d2
("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 <tj@kernel.org>
Cc: Li Zefan <lizefan@huawei.com>
This commit is contained in:
parent
26d5bbe5ba
commit
da1f296fd2
@ -1811,11 +1811,17 @@ int cgroup_path(const struct cgroup *cgrp, char *buf, int buflen)
|
|||||||
int ret = -ENAMETOOLONG;
|
int ret = -ENAMETOOLONG;
|
||||||
char *start;
|
char *start;
|
||||||
|
|
||||||
|
if (!cgrp->parent) {
|
||||||
|
if (strlcpy(buf, "/", buflen) >= buflen)
|
||||||
|
return -ENAMETOOLONG;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
start = buf + buflen - 1;
|
start = buf + buflen - 1;
|
||||||
*start = '\0';
|
*start = '\0';
|
||||||
|
|
||||||
rcu_read_lock();
|
rcu_read_lock();
|
||||||
while (cgrp) {
|
do {
|
||||||
const char *name = cgroup_name(cgrp);
|
const char *name = cgroup_name(cgrp);
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
@ -1824,15 +1830,12 @@ int cgroup_path(const struct cgroup *cgrp, char *buf, int buflen)
|
|||||||
goto out;
|
goto out;
|
||||||
memcpy(start, name, len);
|
memcpy(start, name, len);
|
||||||
|
|
||||||
if (!cgrp->parent)
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (--start < buf)
|
if (--start < buf)
|
||||||
goto out;
|
goto out;
|
||||||
*start = '/';
|
*start = '/';
|
||||||
|
|
||||||
cgrp = cgrp->parent;
|
cgrp = cgrp->parent;
|
||||||
}
|
} while (cgrp->parent);
|
||||||
ret = 0;
|
ret = 0;
|
||||||
memmove(buf, start, buf + buflen - start);
|
memmove(buf, start, buf + buflen - start);
|
||||||
out:
|
out:
|
||||||
|
Loading…
Reference in New Issue
Block a user